Getpixel and colorkey

Hi,

I’ve saved an image in PNG, JPEG and BMP formats using The Gimp.
In an SDL program, I read the pixel at (0,0) which, in the standard that I’ve set up, defines the colorkey of the image I read.
To do that I use the “getpixel” routine from the WiKi page of SDL.

Then, I set the colorkey using SDL_SetColorKey.

What happens is the following:

  • it works perfectly with BMP, but not with PNG and JPEG on an Intel processor
  • it works perfectly with PNG and JPEG, but not with BMP on a Power PC (G4) processor.

I’ve discovered that actually the colorkey was endian-reversed, if I may say, in the JPEG and PNG versions of the image.

Anyone knows about that fact ?
Last note: I’m using SDL_image for loading all my images.

Julien._____________________________________________________________________________
Envoyez avec Yahoo! Mail. Une boite mail plus intelligente http://mail.yahoo.fr

Hi,

I’ve saved an image in PNG, JPEG and BMP formats using The Gimp.
In an SDL program, I read the pixel at (0,0) which, in the standard that I’ve set up, defines the colorkey of the image I read.
To do that I use the “getpixel” routine from the WiKi page of SDL.

Then, I set the colorkey using SDL_SetColorKey.

What happens is the following:

  • it works perfectly with BMP, but not with PNG and JPEG on an Intel processor
  • it works perfectly with PNG and JPEG, but not with BMP on a Power PC (G4) processor.

Colorkeying in JPEG’s going to be difficult, because the compression is lossy.
The pixels you have before you save the JPEG will likely be a little
different from the pixels you get when you load it back up.

I’ve discovered that actually the colorkey was endian-reversed, if I may say, in the JPEG and PNG versions of the image.

Is your getpixel() checking endianness? Are you using the appropriate
method for getting the pixel based on the loaded surface’s format/bpp?

Good luck!

-bill!
“Tux Paint” - free children’s drawing software for Windows / Mac OS X / Linux!
Download it today! http://www.tuxpaint.org/On Tue, Aug 19, 2008 at 05:07:57PM +0000, julien CLEMENT wrote:

— En date de?: Mar 19.8.08, Bill Kendrick a ?crit?:

?: “SDL”

Hi,

I’ve saved an image in PNG, JPEG and BMP formats
using The Gimp.
In an SDL program, I read the pixel at (0,0) which, in
the standard that I’ve set up, defines the colorkey of
the image I read.
To do that I use the “getpixel” routine from
the WiKi page of SDL.

Then, I set the colorkey using SDL_SetColorKey.

What happens is the following:

  • it works perfectly with BMP, but not with PNG and
    JPEG on an Intel processor
  • it works perfectly with PNG and JPEG, but not with
    BMP on a Power PC (G4) processor.

Colorkeying in JPEG’s going to be difficult, because
the compression is lossy.
The pixels you have before you save the JPEG will likely be
a little
different from the pixels you get when you load it back up.
Yes, I know, it’s due to compression.

I’ve discovered that actually the colorkey was
endian-reversed, if I may say, in the JPEG and PNG versions
of the image.

Is your getpixel() checking endianness? Are you using the
appropriate
method for getting the pixel based on the loaded
surface
’s format/bpp?
Yes, it is the getpixel function from the SDL website. Endianness seems to matter only in 24bpp, and that’s the depth of the loaded image.
I’m calling getpixel() correctly and setting the colorkey in the right manner (I guess).
When I get the hex value of that transparent color on The Gimp, I get, for instance, 0x88ff00.
When I do print the value of the pixel read with getpixel(), I get 0x00ff88. getpixel() do check for endianness.

Thanks to you,

Julien> De: Bill Kendrick

Objet: Re: [SDL] getpixel and colorkey
Date: Mardi 19 Ao?t 2008, 20h42
On Tue, Aug 19, 2008 at 05:07:57PM +0000, julien CLEMENT wrote:

Good luck!

-bill!
“Tux Paint” - free children’s drawing
software for Windows / Mac OS X / Linux!
Download it today! http://www.tuxpaint.org/


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

  _____________________________________________________________________________ 

Envoyez avec Yahoo! Mail. Une boite mail plus intelligente http://mail.yahoo.fr

Hello !

I’ve saved an image in PNG, JPEG and BMP formats using The Gimp.
In an SDL program, I read the pixel at (0,0) which, in the standard that I’ve set up, defines the colorkey of the image I read.
To do that I use the “getpixel” routine from the WiKi page of SDL.

Then, I set the colorkey using SDL_SetColorKey.

What happens is the following:

  • it works perfectly with BMP, but not with PNG and JPEG on an Intel processor
  • it works perfectly with PNG and JPEG, but not with BMP on a Power PC (G4) processor.

I’ve discovered that actually the colorkey was endian-reversed, if I may say, in the JPEG and PNG versions of the image.

Anyone knows about that fact ?
Last note: I’m using SDL_image for loading all my images.

Please put together a small compilable testcase
that shows your problem. Also add an example JPEG, PNG
and BMP file to it.

CU