[SDL] getting color information from indexed images?

Omar Eshmawi neo_storm at live.com
Tue Apr 20 21:19:51 PDT 2010



I think the images don't use their own palette but the colors are 
rounded to a generic palette, because a color 24,255,0 was read out as 
36,255,0.

This is pretty rotten, what would be the point of using
 a palette, if images didn't actually keep their own palettes? Andreas 
the thing you sent helped me figure some of that out. the scolor 
vaiables did the same thing but the dcolor ones from the SDL_gfx example
 seem to find the color of the pixel given x and y positions, but only 
relative to that generic palette. But I was hoping I'd find a way to 
turn this into something that grabbed colors from the index, which it's 
not really doing.... 


Is there no way to read palettes from 
images with the sdl libraries??
Date: Tue, 20 Apr 2010 08:34:08 -0700
From: aschiffler at ferzkopp.net
To: neo_storm at live.com
Subject: Re: [SDL] getting color information from indexed images?






  


Check out the code from SDL_gfx that handles index images. 

   
http://sdlgfx.svn.sourceforge.net/viewvc/sdlgfx/SDL_gfxPrimitives.c?revision=21&view=markup

line

263 to 273.



On 4/20/10 8:14 AM, Omar Eshmawi wrote:

  hello

I've been having a hard time recently coming to understand the
functionality of surfaces with SDL or successfully utilizing them how I
want to.
  

so basically from what I've read combined with what I know about
indexed images, it SEEMs as though the sdl_color pointer in a surface's
format's palette (surface->format->palette->colors) should
point to some kind of information relative to the colors defined in an
image's palette. All the references online point to the usage of the
pointer such that colors[n] refers to a color in an image's palette
with the index of n. Which would inherit from it's type the Uint8
members r, g, b.(and unused). However my tests to see what values come
out for r, g, and b when I print them out respectively for their
respective color indexes are confusing me. And either I am doing it
wrong, or I am not understanding the functionality of palettes in
sdl_surfaces.
  

  

  

so let's assume I create a surface from a loaded 8 bit indexed bitmap
of 256 colors.
  

  

img = loadbmp(etc);
  

  

now considering that upon testing how a Uint8 variable alone prints
out...
  

  

Uint8 jimbo;
  

.
  

.
  

.
  

.
  

jimbo = 111;
  

cout<<jimbo;//prints out weird character e.g. ¨
  

so scratch that and
  

cout<<(int)jimbo;//prints out 111;
  

  

that if img->format->palette->colors[0].r is printed out it
would give me the red intensity of the color with that index for that
image
  

  

cout<<(int)img->format->palette->colors[0].r;//this
color in my bitmap equals 168, 0, 255 so I expect this line of code to
print 168 but prints 0 instead.
  

  

not only that but more behavior follows that makes me question if this
even does what I think it does.....
  

  

for(int i = 0;i<256;i++)
  

{
  

  

cout<<(int)img->format->palette->colors[i].r<<"
"<<(int)img->format->palette->colors[i].g<<"
"<<(int)img->format->palette->colors[i].b;
  

cout<<endl;
  

  

  

  

}
  

  

resulted with very unexpected results 

r g b //starting with colors[0]
  

0 0 0
  

0 0 85
  

0 0 170
  

0 0 255
  

0 36 0
  

0 36 85
  

0 36 170
  

0 36 255
  

0 73 0
  

0 73 85
  

0 73 170
  

0 73 255
  

0 109 0
  

0 109 85
  

0 109 170
  

0 109 255
  

0 146 0
  

0 146 85
  

0 146 170
  

0 146 255
  

0 182 0
  

0 182 85
  

0 182 170
  

0 182 255
  

0 219 0
  

0 219 85
  

0 219 170
  

0 219 255
  

0 255 0
  

0 255 85
  

0 255 170
  

0 255 255
  

36 0 0
  

36 0 85
  

36 0 170
  

36 0 255
  

36 36 0
  

36 36 85
  

36 36 170
  

36 36 255
  

36 73 0
  

36 73 85
  

36 73 170
  

36 73 255
  

36 109 0
  

36 109 85
  

36 109 170
  

36 109 255
  

36 146 0
  

36 146 85
  

36 146 170
  

36 146 255
  

36 182 0
  

36 182 85
  

36 182 170
  

36 182 255
  

36 219 0
  

36 219 85
  

36 219 170
  

36 219 255
  

36 255 0
  

36 255 85
  

36 255 170
  

36 255 255
  

73 0 0
  

73 0 85
  

73 0 170
  

73 0 255
  

73 36 0
  

73 36 85
  

73 36 170
  

73 36 255
  

73 73 0
  

73 73 85
  

73 73 170
  

73 73 255
  

73 109 0
  

73 109 85
  

73 109 170
  

73 109 255
  

73 146 0
  

73 146 85
  

73 146 170
  

73 146 255
  

73 182 0
  

73 182 85
  

73 182 170
  

73 182 255
  

73 219 0
  

73 219 85
  

73 219 170
  

73 219 255
  

73 255 0
  

73 255 85
  

73 255 170
  

73 255 255
  

109 0 0
  

109 0 85
  

109 0 170
  

109 0 255
  

109 36 0
  

109 36 85
  

109 36 170
  

109 36 255
  

109 73 0
  

109 73 85
  

109 73 170
  

109 73 255
  

109 109 0
  

109 109 85
  

109 109 170
  

109 109 255
  

109 146 0
  

109 146 85
  

109 146 170
  

109 146 255
  

109 182 0
  

109 182 85
  

109 182 170
  

109 182 255
  

109 219 0
  

109 219 85
  

109 219 170
  

109 219 255
  

109 255 0
  

109 255 85
  

109 255 170
  

109 255 255
  

146 0 0
  

146 0 85
  

146 0 170
  

146 0 255
  

146 36 0
  

146 36 85
  

146 36 170
  

146 36 255
  

146 73 0
  

146 73 85
  

146 73 170
  

146 73 255
  

146 109 0
  

146 109 85
  

146 109 170
  

146 109 255
  

146 146 0
  

146 146 85
  

146 146 170
  

146 146 255
  

146 182 0
  

146 182 85
  

146 182 170
  

146 182 255
  

146 219 0
  

146 219 85
  

146 219 170
  

146 219 255
  

146 255 0
  

146 255 85
  

146 255 170
  

146 255 255
  

182 0 0
  

182 0 85
  

182 0 170
  

182 0 255
  

182 36 0
  

182 36 85
  

182 36 170
  

182 36 255
  

182 73 0
  

182 73 85
  

182 73 170
  

182 73 255
  

182 109 0
  

182 109 85
  

182 109 170
  

182 109 255
  

182 146 0
  

182 146 85
  

182 146 170
  

182 146 255
  

182 182 0
  

182 182 85
  

182 182 170
  

182 182 255
  

182 219 0
  

182 219 85
  

182 219 170
  

182 219 255
  

182 255 0
  

182 255 85
  

182 255 170
  

182 255 255
  

219 0 0
  

219 0 85
  

219 0 170
  

219 0 255
  

219 36 0
  

219 36 85
  

219 36 170
  

219 36 255
  

219 73 0
  

219 73 85
  

219 73 170
  

219 73 255
  

219 109 0
  

219 109 85
  

219 109 170
  

219 109 255
  

219 146 0
  

219 146 85
  

219 146 170
  

219 146 255
  

219 182 0
  

219 182 85
  

219 182 170
  

219 182 255
  

219 219 0
  

219 219 85
  

219 219 170
  

219 219 255
  

219 255 0
  

219 255 85
  

219 255 170
  

219 255 255
  

255 0 0
  

255 0 85
  

255 0 170
  

255 0 255
  

255 36 0
  

255 36 85
  

255 36 170
  

255 36 255
  

255 73 0
  

255 73 85
  

255 73 170
  

255 73 255
  

255 109 0
  

255 109 85
  

255 109 170
  

255 109 255
  

255 146 0
  

255 146 85
  

255 146 170
  

255 146 255
  

255 182 0
  

255 182 85
  

255 182 170
  

255 182 255
  

255 219 0
  

255 219 85
  

255 219 170
  

255 219 255
  

255 255 0
  

255 255 85
  

255 255 170
  

255 255 255
  

  

  

  

and these values don't resemble the colors in my bitmap at all because
for one thing I specificaly remember having a bunch (like 50) of the
colors in the middle of the palette just be black, 0, 0, 0
  

  

  

  

  

and actually was similar when I tried doing it to a suface pointer I
call screen.
  

screen->format etc...
  

which points to my window I guess(screen = setvideomode(etc))
  

  

r g b
  

0 0 0
  

0 0 85
  

0 0 170
  

0 0 255
  

0 36 0
  

0 36 85
  

0 36 170
  

0 36 255
  

0 73 0
  

0 73 85
  

0 73 170
  

0 73 255
  

0 109 0
  

0 109 85
  

0 109 170
  

0 109 255
  

0 146 0
  

0 146 85
  

0 146 170
  

0 146 255
  

0 182 0
  

0 182 85
  

0 182 170
  

0 182 255
  

0 219 0
  

0 219 85
  

0 219 170
  

0 219 255
  

0 255 0
  

0 255 85
  

0 255 170
  

0 255 255
  

36 0 0
  

36 0 85
  

36 0 170
  

36 0 255
  

36 36 0
  

36 36 85
  

36 36 170
  

36 36 255
  

36 73 0
  

36 73 85
  

36 73 170
  

36 73 255
  

36 109 0
  

36 109 85
  

36 109 170
  

36 109 255
  

36 146 0
  

36 146 85
  

36 146 170
  

36 146 255
  

36 182 0
  

36 182 85
  

36 182 170
  

36 182 255
  

36 219 0
  

36 219 85
  

36 219 170
  

36 219 255
  

36 255 0
  

36 255 85
  

36 255 170
  

36 255 255
  

73 0 0
  

73 0 85
  

73 0 170
  

73 0 255
  

73 36 0
  

73 36 85
  

73 36 170
  

73 36 255
  

73 73 0
  

73 73 85
  

73 73 170
  

73 73 255
  

73 109 0
  

73 109 85
  

73 109 170
  

73 109 255
  

73 146 0
  

73 146 85
  

73 146 170
  

73 146 255
  

73 182 0
  

73 182 85
  

73 182 170
  

73 182 255
  

73 219 0
  

73 219 85
  

73 219 170
  

73 219 255
  

73 255 0
  

73 255 85
  

73 255 170
  

73 255 255
  

109 0 0
  

109 0 85
  

109 0 170
  

109 0 255
  

109 36 0
  

109 36 85
  

109 36 170
  

109 36 255
  

109 73 0
  

109 73 85
  

109 73 170
  

109 73 255
  

109 109 0
  

109 109 85
  

109 109 170
  

109 109 255
  

109 146 0
  

109 146 85
  

109 146 170
  

109 146 255
  

109 182 0
  

109 182 85
  

109 182 170
  

109 182 255
  

109 219 0
  

109 219 85
  

109 219 170
  

109 219 255
  

109 255 0
  

109 255 85
  

109 255 170
  

109 255 255
  

146 0 0
  

146 0 85
  

146 0 170
  

146 0 255
  

146 36 0
  

146 36 85
  

146 36 170
  

146 36 255
  

146 73 0
  

146 73 85
  

146 73 170
  

146 73 255
  

146 109 0
  

146 109 85
  

146 109 170
  

146 109 255
  

146 146 0
  

146 146 85
  

146 146 170
  

146 146 255
  

146 182 0
  

146 182 85
  

146 182 170
  

146 182 255
  

146 219 0
  

146 219 85
  

146 219 170
  

146 219 255
  

146 255 0
  

146 255 85
  

146 255 170
  

146 255 255
  

182 0 0
  

182 0 85
  

182 0 170
  

182 0 255
  

182 36 0
  

182 36 85
  

182 36 170
  

182 36 255
  

182 73 0
  

182 73 85
  

182 73 170
  

182 73 255
  

182 109 0
  

182 109 85
  

182 109 170
  

182 109 255
  

182 146 0
  

182 146 85
  

182 146 170
  

182 146 255
  

182 182 0
  

182 182 85
  

182 182 170
  

182 182 255
  

182 219 0
  

182 219 85
  

182 219 170
  

182 219 255
  

182 255 0
  

182 255 85
  

182 255 170
  

182 255 255
  

219 0 0
  

219 0 85
  

219 0 170
  

219 0 255
  

219 36 0
  

219 36 85
  

219 36 170
  

219 36 255
  

219 73 0
  

219 73 85
  

219 73 170
  

219 73 255
  

219 109 0
  

219 109 85
  

219 109 170
  

219 109 255
  

219 146 0
  

219 146 85
  

219 146 170
  

219 146 255
  

219 182 0
  

219 182 85
  

219 182 170
  

219 182 255
  

219 219 0
  

219 219 85
  

219 219 170
  

219 219 255
  

219 255 0
  

219 255 85
  

219 255 170
  

219 255 255
  

255 0 0
  

255 0 85
  

255 0 170
  

255 0 255
  

255 36 0
  

255 36 85
  

255 36 170
  

255 36 255
  

255 73 0
  

255 73 85
  

255 73 170
  

255 73 255
  

255 109 0
  

255 109 85
  

255 109 170
  

255 109 255
  

255 146 0
  

255 146 85
  

255 146 170
  

255 146 255
  

255 182 0
  

255 182 85
  

255 182 170
  

255 182 255
  

255 219 0
  

255 219 85
  

255 219 170
  

255 219 255
  

255 255 0
  

255 255 85
  

255 255 170
  

255 255 255
  

  

So now these results make me consider if I even accurately accessed my
images palette, or if something is in the way of that, or if its not
even supposed to do what it looks like it should do.

  

this feels like some sort of default palette where the color spectrum
is represented as squarely as possible and I'm trying to get the
palette of a specific image to show.

  

If there is more information I could reveal you think would be helpful
in ascertaining the problem please let me know, thank you

  

  The New Busy think 9 to 5 is a cute idea. Combine multiple
calendars with Hotmail. Get busy.
  
_______________________________________________
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
  


 		 	   		  
_________________________________________________________________
Hotmail is redefining busy with tools for the New Busy. Get more from your inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20100420/a95780db/attachment.htm>


More information about the SDL mailing list