Getting color information from indexed images?

ignore that code
RGBQUAD pal[256];
memmove(pal,(void*)((int)GetBufferFromResource(obj_shptst_a)+54),256*sizeof(RGBQUAD));

for(int p = 0;p<256;p++){
cout<<(int)pal[p].rgbRed;
cout<<" “;
cout<<(int)pal[p].rgbGreen;
cout<<” ";
cout<<(int)pal[p].rgbBlue;
cout<<endl;
}
this is even better :PFrom: @Omar_Eshmawi
To: sdl at lists.libsdl.org
Date: Sun, 16 May 2010 23:08:00 -0700
Subject: Re: [SDL] getting palettes from windows resources

I thought I would post this in case it peaked anyone’s interests. Maybe that of others who like using windows resources compiled into the executable. For one thing the resources themselves were custom resources (declared by naming a resource any made up type name) and that alone made them more difficult to work with to fill out the bmiColors member. and those random palettes I got before I think were because I didn’t even set the bmiColors member of a bitmapinfo, and I looked in the source for SDL_Bitmaps or SDL_Bitmap.c or whatever it’s called and it looks like it too does stuff with bitmapinfo structures. but it didn’t fill things out with my custom resources because they were so raw or whatever, they weren’t even BITMAP resources just custom. so this code worked for bitmaps
BITMAPINFO * bmi;
bmi = (BITMAPINFO*)malloc(sizeof(BITMAPINFOHEADER)+256sizeof(RGBQUAD));
memmove(bmi,(void((int)GetBufferFromResource(obj_shptst_a)+14),sizeof(BITMAPINFOHEADER)+256
sizeof(RGBQUAD));

for(int p = 0;p<256;p++){
cout<<(int)bmi->bmiColors[p].rgbRed;
cout<<" “;
cout<<(int)bmi->bmiColors[p].rgbGreen;
cout<<” ";
cout<<(int)bmi->bmiColors[p].rgbBlue;
cout<<endl;
}
and um, it’s hard to explain and I’m probably not doing a great job as I don’t understand it too well myself, but that memmove function sort of does the trick, and the colors are messed up because maybe the resource is misaligned or something since after much fiddling around adding some offset to the resource seems to do the trick. I didn’t bother figuring out the mechanics of it, it’s probably +sizeof(something) but tests showed that 14 seems to usually do the trick with 8bit palettized bitmaps. I know this probably all looks unnecessary as opposed to just using files or whatever, but it’s nice to have multiple options right? It’s not too big a deal but I figured it was worth mentioning, (+I had a heck of a time trying to figure it out !).
/source if you feel like checking it out
http://www.speedyshare.com/files/22475796/example_palette.zip
From: @Omar_Eshmawi
To: sdl at lists.libsdl.org
Date: Sat, 8 May 2010 15:24:09 -0700
Subject: Re: [SDL] getting color information from indexed images?

ahh I see now, I was afraid of that. well at least now I know what my problem was, well thank you donny, you’ve been very helpful! :slight_smile:

cheers

-omar

Date: Thu, 6 May 2010 01:08:36 -0400
From: donny.viszneki at gmail.com
To: sdl at lists.libsdl.org
Subject: Re: [SDL] getting color information from indexed images?

Sorry, I was unable to do the test because it contains MSWindows-only
code, and I don’t have MSWindows :frowning:

Does your project require MSWindows-only code? I kind of suspect that
your bug might be caused by not actually getting what you think you’re
getting from the MSWindows APIs you’re using.

Okay, so I took out the Windows-specific stuff and I replaced a call
to your LoadBMP_Resource() function with a call to SDL_LoadBMP().

What I got for the palette is different from what you got for the palette:

donny at donny-desktop:~/palette/example_palette$ ./a.out
255 255 255
0 0 0
255 0 0
255 14 14
255 28 28
255 42 42
255 55 55
255 69 69
255 83 83
255 97 97
255 111 111
255 125 125
255 138 138
255 152 152
255 166 166
255 180 180
6 0 255
19 13 255
32 26 255
45 40 255
57 53 255
70 66 255
83 79 255
96 92 255
109 106 255
122 119 255
135 132 255
148 145 255
160 158 255
173 172 255
186 185 255
199 198 255
0 255 18
15 255 32
29 255 45
44 255 59
58 255 72
73 255 86
87 255 99
102 255 113
116 255 126
131 255 140
145 255 153
160 255 167
174 255 180
189 255 194
203 255 207
218 255 221
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 255 0

This information is confirmed by a look at resources/test.bmp. Here is
a screenshot:
http://codebad.com/d/omars-palette.png

I suspect that those old MSWindows APIs are fitting your image into
their own 256 color palette. IIRC MSWindows used to have a different
palette for each application that used an indexed color mode, and
switching focus between different application windows would result in
other applications’ windows on your screen looking funny when the
palette changed.

Try factoring out your MSWindows APIs as much as possible. Your
applications will be more portable and you’ll have access to more of
the source code you are invoking and therefore be able to troubleshoot
more effectively :slight_smile:

Sorry I took so long to check out your ZIP file. I have been moving
into a new apartment and replacing the carpet and painting the walls
:open_mouth:

On Wed, May 5, 2010 at 10:08 PM, Omar Eshmawi <@Omar_Eshmawi> wrote:

so… it would be nice to get some confirmation on whether anyone could ever
solve my problem or not?
I remember putting up 3 links to my example program that sam and donny
conveyed request for. But I never got a reply as to whether you guys were
able to figure it out or not? Please let me know if you want me to reupload
it.


From: @Omar_Eshmawi
To: sdl at lists.libsdl.org
Date: Sun, 25 Apr 2010 13:58:54 -0700
Subject: Re: [SDL] getting color information from indexed images?

haha, good

Date: Sun, 25 Apr 2010 01:39:08 -0400
From: donny.viszneki at gmail.com
To: sdl at lists.libsdl.org
Subject: Re: [SDL] getting color information from indexed images?

Looks like SpeedyShare worked quite speedily!

On Sun, Apr 25, 2010 at 1:38 AM, Donny Viszneki <donny.viszneki at gmail.com> wrote:

That’s weird, that is my email address.

If I had the root password for my server I would give you an FTP
account, but I need to get a hard drive out of an older machine and I
can’t even find it…

I’ll try one of your other links

On Sat, Apr 24, 2010 at 11:15 PM, Omar Eshmawi <@Omar_Eshmawi> wrote:

is this your email? donny.viszneki at gmail.com
because I keep getting notifications of failure in my inbox

Date: Sat, 24 Apr 2010 05:14:33 -0400
From: donny.viszneki at gmail.com
To: sdl at lists.libsdl.org
Subject: Re: [SDL] getting color information from indexed images?

Still waiting for that attachment :slight_smile:

On Fri, Apr 23, 2010 at 8:11 PM, Omar Eshmawi <@Omar_Eshmawi> wrote:

http://www.speedyshare.com/files/22093997/example_palette.zip
http://www.mediafire.com/?lozmdzmjyz0
http://www.megaupload.com/?d=E064R1JK
at first I tried to attach it, but I suppose you can’t send messages
larger
than 40 kb to the mailing list
and @donny I’ll send you the attachment just to be safe


Hotmail is redefining busy with tools for the New Busy. Get more
from
your
inbox. See how.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


http://codebad.com/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


The New Busy is not the old busy. Search, chat and e-mail from your
inbox.
Get started.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


http://codebad.com/


http://codebad.com/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


The New Busy think 9 to 5 is a cute idea. Combine multiple calendars with
Hotmail. Get busy.


The New Busy is not the too busy. Combine all your e-mail accounts with
Hotmail. Get busy.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


http://codebad.com/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

The New Busy think 9 to 5 is a cute idea. Combine multiple calendars with Hotmail. Get busy.
The New Busy think 9 to 5 is a cute idea. Combine multiple calendars with Hotmail. Get busy.


The New Busy is not the too busy. Combine all your e-mail accounts with Hotmail.
http://www.windowslive.com/campaign/thenewbusy?tile=multiaccount&ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_4

also works with .gif images and custom resources if RGBTRIPLE is used instead and blue and red members are flipped
RGBTRIPLE pal[256];
memmove(pal,(void*)((int)GetBufferFromResource(obj_shptst_a)+13),256*sizeof(RGBTRIPLE));

for(int p = 0;p<256;p++){
cout<<(int)pal[p].rgbtBlue;
cout<<" “;
cout<<(int)pal[p].rgbtGreen;
cout<<” ";
cout<<(int)pal[p].rgbtRed;
cout<<endl;
}From: @Omar_Eshmawi
To: sdl at lists.libsdl.org
Date: Sun, 16 May 2010 23:22:14 -0700
Subject: Re: [SDL] getting palettes from windows resources

ignore that code
RGBQUAD pal[256];
memmove(pal,(void*)((int)GetBufferFromResource(obj_shptst_a)+54),256*sizeof(RGBQUAD));

for(int p = 0;p<256;p++){
cout<<(int)pal[p].rgbRed;
cout<<" “;
cout<<(int)pal[p].rgbGreen;
cout<<” ";
cout<<(int)pal[p].rgbBlue;
cout<<endl;
}
this is even better :stuck_out_tongue:

From: @Omar_Eshmawi
To: sdl at lists.libsdl.org
Date: Sun, 16 May 2010 23:08:00 -0700
Subject: Re: [SDL] getting palettes from windows resources

I thought I would post this in case it peaked anyone’s interests. Maybe that of others who like using windows resources compiled into the executable. For one thing the resources themselves were custom resources (declared by naming a resource any made up type name) and that alone made them more difficult to work with to fill out the bmiColors member. and those random palettes I got before I think were because I didn’t even set the bmiColors member of a bitmapinfo, and I looked in the source for SDL_Bitmaps or SDL_Bitmap.c or whatever it’s called and it looks like it too does stuff with bitmapinfo structures. but it didn’t fill things out with my custom resources because they were so raw or whatever, they weren’t even BITMAP resources just custom. so this code worked for bitmaps
BITMAPINFO * bmi;
bmi = (BITMAPINFO*)malloc(sizeof(BITMAPINFOHEADER)+256sizeof(RGBQUAD));
memmove(bmi,(void((int)GetBufferFromResource(obj_shptst_a)+14),sizeof(BITMAPINFOHEADER)+256
sizeof(RGBQUAD));

for(int p = 0;p<256;p++){
cout<<(int)bmi->bmiColors[p].rgbRed;
cout<<" “;
cout<<(int)bmi->bmiColors[p].rgbGreen;
cout<<” ";
cout<<(int)bmi->bmiColors[p].rgbBlue;
cout<<endl;
}
and um, it’s hard to explain and I’m probably not doing a great job as I don’t understand it too well myself, but that memmove function sort of does the trick, and the colors are messed up because maybe the resource is misaligned or something since after much fiddling around adding some offset to the resource seems to do the trick. I didn’t bother figuring out the mechanics of it, it’s probably +sizeof(something) but tests showed that 14 seems to usually do the trick with 8bit palettized bitmaps. I know this probably all looks unnecessary as opposed to just using files or whatever, but it’s nice to have multiple options right? It’s not too big a deal but I figured it was worth mentioning, (+I had a heck of a time trying to figure it out !).
/source if you feel like checking it out
http://www.speedyshare.com/files/22475796/example_palette.zip
From: @Omar_Eshmawi
To: sdl at lists.libsdl.org
Date: Sat, 8 May 2010 15:24:09 -0700
Subject: Re: [SDL] getting color information from indexed images?

ahh I see now, I was afraid of that. well at least now I know what my problem was, well thank you donny, you’ve been very helpful! :slight_smile:

cheers

-omar

Date: Thu, 6 May 2010 01:08:36 -0400
From: donny.viszneki at gmail.com
To: sdl at lists.libsdl.org
Subject: Re: [SDL] getting color information from indexed images?

Sorry, I was unable to do the test because it contains MSWindows-only
code, and I don’t have MSWindows :frowning:

Does your project require MSWindows-only code? I kind of suspect that
your bug might be caused by not actually getting what you think you’re
getting from the MSWindows APIs you’re using.

Okay, so I took out the Windows-specific stuff and I replaced a call
to your LoadBMP_Resource() function with a call to SDL_LoadBMP().

What I got for the palette is different from what you got for the palette:

donny at donny-desktop:~/palette/example_palette$ ./a.out
255 255 255
0 0 0
255 0 0
255 14 14
255 28 28
255 42 42
255 55 55
255 69 69
255 83 83
255 97 97
255 111 111
255 125 125
255 138 138
255 152 152
255 166 166
255 180 180
6 0 255
19 13 255
32 26 255
45 40 255
57 53 255
70 66 255
83 79 255
96 92 255
109 106 255
122 119 255
135 132 255
148 145 255
160 158 255
173 172 255
186 185 255
199 198 255
0 255 18
15 255 32
29 255 45
44 255 59
58 255 72
73 255 86
87 255 99
102 255 113
116 255 126
131 255 140
145 255 153
160 255 167
174 255 180
189 255 194
203 255 207
218 255 221
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 0 216
255 255 0

This information is confirmed by a look at resources/test.bmp. Here is
a screenshot:
http://codebad.com/d/omars-palette.png

I suspect that those old MSWindows APIs are fitting your image into
their own 256 color palette. IIRC MSWindows used to have a different
palette for each application that used an indexed color mode, and
switching focus between different application windows would result in
other applications’ windows on your screen looking funny when the
palette changed.

Try factoring out your MSWindows APIs as much as possible. Your
applications will be more portable and you’ll have access to more of
the source code you are invoking and therefore be able to troubleshoot
more effectively :slight_smile:

Sorry I took so long to check out your ZIP file. I have been moving
into a new apartment and replacing the carpet and painting the walls
:open_mouth:

On Wed, May 5, 2010 at 10:08 PM, Omar Eshmawi <@Omar_Eshmawi> wrote:

so… it would be nice to get some confirmation on whether anyone could ever
solve my problem or not?
I remember putting up 3 links to my example program that sam and donny
conveyed request for. But I never got a reply as to whether you guys were
able to figure it out or not? Please let me know if you want me to reupload
it.


From: @Omar_Eshmawi
To: sdl at lists.libsdl.org
Date: Sun, 25 Apr 2010 13:58:54 -0700
Subject: Re: [SDL] getting color information from indexed images?

haha, good

Date: Sun, 25 Apr 2010 01:39:08 -0400
From: donny.viszneki at gmail.com
To: sdl at lists.libsdl.org
Subject: Re: [SDL] getting color information from indexed images?

Looks like SpeedyShare worked quite speedily!

On Sun, Apr 25, 2010 at 1:38 AM, Donny Viszneki <donny.viszneki at gmail.com> wrote:

That’s weird, that is my email address.

If I had the root password for my server I would give you an FTP
account, but I need to get a hard drive out of an older machine and I
can’t even find it…

I’ll try one of your other links

On Sat, Apr 24, 2010 at 11:15 PM, Omar Eshmawi <@Omar_Eshmawi> wrote:

is this your email? donny.viszneki at gmail.com
because I keep getting notifications of failure in my inbox

Date: Sat, 24 Apr 2010 05:14:33 -0400
From: donny.viszneki at gmail.com
To: sdl at lists.libsdl.org
Subject: Re: [SDL] getting color information from indexed images?

Still waiting for that attachment :slight_smile:

On Fri, Apr 23, 2010 at 8:11 PM, Omar Eshmawi <@Omar_Eshmawi> wrote:

http://www.speedyshare.com/files/22093997/example_palette.zip
http://www.mediafire.com/?lozmdzmjyz0
http://www.megaupload.com/?d=E064R1JK
at first I tried to attach it, but I suppose you can’t send messages
larger
than 40 kb to the mailing list
and @donny I’ll send you the attachment just to be safe


Hotmail is redefining busy with tools for the New Busy. Get more
from
your
inbox. See how.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


http://codebad.com/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


The New Busy is not the old busy. Search, chat and e-mail from your
inbox.
Get started.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


http://codebad.com/


http://codebad.com/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


The New Busy think 9 to 5 is a cute idea. Combine multiple calendars with
Hotmail. Get busy.


The New Busy is not the too busy. Combine all your e-mail accounts with
Hotmail. Get busy.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


http://codebad.com/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

The New Busy think 9 to 5 is a cute idea. Combine multiple calendars with Hotmail. Get busy.
The New Busy think 9 to 5 is a cute idea. Combine multiple calendars with Hotmail. Get busy.
The New Busy is not the too busy. Combine all your e-mail accounts with Hotmail. Get busy.


The New Busy think 9 to 5 is a cute idea. Combine multiple calendars with Hotmail.
http://www.windowslive.com/campaign/thenewbusy?tile=multicalendar&ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_5