I found a problem earlier today with Soya.Image's handling of indexed
images. The short version is that it treats indexed images as if they
were greyscale, in such a way that if you had an 4-color palette of red,
green, yellow, and blue, this image would be seen as #000000, #010101,
#020202, and #030303.
You can test this bug by loading an indexed image with soya.Image, then
converting it to a PIL object and running a .show() on it. It's not
running a conversion to greyscale, it's actually interpreting it as
greyscale.
I haven't done anything to fix this being displayed as textures yet, but
I have done the first step of saving the color palette as
soya.Image.palette (a char buffer = x*y*3 in length) which is tested and
used to build an indexed PIL image. This patch can be tested by the
same method as above; instead of showing it as greyscale, this
"1-channel" image will display as in color with a PIL object .show()
This patch is useful, but not needed, for loading texture maps (see
upcomming patch). A texture-map load function can revert to the pixel's
index color (vs greyscale) when a material for that index # is not
found. It can also be used to build/edit a texture map from within Soya.
A future patch should either export indexed images to OpenGL as such,
convert them to RGB "on the fly", or raise an error when an indexed
image is assigned as a material texture.
Index: image.pyx
===================================================================
RCS file: /cvs/soya/soya/model/image.pyx,v
retrieving revision 1.14
diff -r1.14 image.pyx
37,38c37,39
< if pil_image.mode == "RGB" : image.nb_color = 3
< elif pil_image.mode == "RGBA": image.nb_color = 4
---
> image.palette = None
> if pil_image.mode == "RGBA": image.nb_color = 4
> elif pil_image.mode == "RGB" : image.nb_color = 3
40c41,43
< elif pil_image.mode == "P" : image.nb_color = 1 # XXX Palette may not be
monochrome
---
> elif pil_image.mode == "P" : # XXX Palette may not be monochrome
> image.nb_color = 1
> image.palette = pil_image.palette.palette
190c193
< if self.nb_color == 1: return PIL.Image.fromstring("L" , (self.width,
self.height), self.pixels)
---
> if self.nb_color == 4: return PIL.Image.fromstring("RGBA", (self.width,
> self.height), self.pixels)
192,193c195,200
< elif self.nb_color == 4: return PIL.Image.fromstring("RGBA", (self.width,
self.height), self.pixels)
<
---
> elif self.nb_color == 1:
> if self.palette == None: return PIL.Image.fromstring("L", (self.width,
> self.height), self.pixels)
> else :
> pimage = PIL.Image.fromstring("P", (self.width, self.height),
> self.pixels)
> pimage.putpalette(self.palette)
> return pimage
_______________________________________________
Soya-user mailing list
[email protected]
https://mail.gna.org/listinfo/soya-user