PNG image texture format for color 3

I have a 128x128 PNG image. When I read its IHDR slice using libpng, it shows that the image is of color type 3. The problem is that I cannot find somewhere what the texture format for this color type should be. I want to draw this image using OpenGL. But without the right texture format, the image color is not what it should be. And also, if any link can be provided where I can read in detail about this issue, we will be very grateful.

I use this method to adjust the texture format for other types of colors

inline void GetPNGtextureInfo (int color_type,GLuint *format) { switch (color_type) { case PNG_COLOR_TYPE_GRAY: *format = GL_LUMINANCE; break; case PNG_COLOR_TYPE_GRAY_ALPHA: *format = GL_LUMINANCE_ALPHA; break; case PNG_COLOR_TYPE_RGB: *format = GL_RGB; break; case PNG_COLOR_TYPE_RGB_ALPHA: *format = GL_RGBA; break; default: break; } } 
+1
source share
1 answer

A palette is just an array of colors, and image data is just indices in that array.

So, if you want to convert an image to an RGB image, select a new buffer large enough for your image in this format, and fill it by taking the pointer for a pixel from the original image, index the palette with this value, and save the RGB value that you get into the target image.

You can find a GL fragrance that supports the texture palette and can load them directly, but hardware support is less common these days, and all the chances are all you do is unload the driver, convert your texture to 24-bit .

For example, OpenGL ES supports some types of palette texture using the glCompressedTexImage2D() function, but it is possible that this will simply entail a load on the implementation to convert these textures into something that the hardware can handle.

If you have no problems with storage, I would prefer offline conversion (i.e. first save your images as 24-bit), but this is not technically difficult in any case.

+1
source

All Articles