[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Trouble with PixelArray



On 19/02/12 09:00 AM, Erik Grahn J. wrote:
Hey all,

I'm writing something where I load 4-colour indexed PNG images (8x8 tiles) with a simple greyscale palette (four entries, in order: black, dark grey, light grey, white) off disk. I then intend to recolour these in different ways by replacing the palette indices using PixelArray.replace, but I'm kind of getting stuck because I'm not getting the palette values I want from the file.

In the 8-bit PNG, my four greyscale colours are unquestionably palette indices 0-3 (I have verified this with a hex editor even, they are the first four values in the PLTE chunk) but when I turn my surface into a PixelArray and print it, it looks like this:

	PixelArray(
	  [0, 0, 86, 127, 127, 0, 0, 0]
	  [0, 86, 127, 86, 86, 86, 0, 0]
	  [86, 127, 86, 86, 41, 86, 86, 0]
	  [86, 127, 86, 86, 41, 86, 86, 0]
	  [86, 127, 86, 86, 41, 86, 86, 0]
	  [86, 127, 86, 41, 41, 86, 86, 0]
	  [0, 86, 127, 86, 86, 86, 0, 0]
	  [0, 0, 86, 86, 86, 0, 0, 0]
	)

So instead of the values I want (0, 1, 2, 3), I'm getting 0, 41, 86 and 127. I have no idea where it gets these numbers from. Possibly a conversion to some internal default palette somewhere? I have tried calling set_palette on the surface to no avail -- same results.

Any help would be super appreciated.


Hi,

I am at a loss here. When I load a grayscale PNG, or BMP, file I don't get an 8 bit palette surface. Instead it is 24 bit. Something may have changed in SDL_image or libpng. If so, there is nothing that can be done about it (unless someone volunteers to rewrite imageext.c to not use SDL_image).

Lenard Lindstrom