Hi,
Is there a way to use images with indexed colors (palettes) with Panda3D?
To be more precise, here’s what I want to do:
I have a texture composition pipeline, where multiple sub images are blended together (on the CPU) to create a single RGBA image, which then is used as texture for the GPU.
Currently I do this using PNM images. The code is roughly like this:
# self.baseImage is the target PNM
# blendInfos holds tuples of (blendImage, region)
# region describes the area of the blend
# blendImage is a PNM I want to blend in
for blendImage, region in blendInfos:
self.baseImage.blendSubImage(blendImage, region.xPos, region.yPos, 0,0, region.xSize, region.ySize)
# move final image into a gpu Texture
self.baseTexture.load(self.baseImage)
Now, I’d like some of the source images to be palette images. I’d like to have multiple palettes which should be used during image blending to turn the index image into RGB or RGBA.
Something like this (pseudo-code):
# self.baseImage is the target PNM (using full RGBA color resolution)
# blendInfos holds tuples of (blendImage, palette, region), palette may be None
# region describes the area of the blend
# blendImage is a PNM I want to blend in
for blendImage, palette, region in blendInfos:
if palette:
# blend, using the palette
self.baseImage.blendPalettizedSubImage(blendImage, palette, region.xPos, region.yPos, 0,0, region.xSize, region.ySize)
else:
# do a "regular" blend
self.baseImage.blendSubImage(blendImage, region.xPos, region.yPos, 0,0, region.xSize, region.ySize)
# move final image into a gpu Texture
self.baseTexture.load(self.baseImage)
Is there a way to achieve this behavior with PNM Images or some other part of Panda3D?
Of course I could use the PIL for the paletted images, but I’d rather not bring in another library.
If worse comes to worse I’m prepared to modify the PNM library to include what I need.
Cneers,
Erik