PNG image texture format for color type 3

╄→гoц情女王★ 提交于 2019-12-14 02:39:00

问题


I have a PNG image of 128x128 dimension. When I read its IHDR chunk with libpng it shows that the image has color type 3. The problem is I cant find anywhere what should be the texture format for this color type. I want to draw this image with OpenGL. But without correct texture format the image color is not what it should be. And also If any reference could be provided where I can read detail about this matter will be greatly appreciated.

I use this method to set texture format for other color types

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:


The palette is just an array of colours, and the image data is just indices into that array.

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

You may find a flavour of GL which has support for paletted textures, and can load them directly, but hardware support is less common these days, and the chances are all you're doing is offloading work to the driver, which will convert your texture to 24-bit.

For example, OpenGL ES supports some types of palettised texture through the glCompressedTexImage2D() function, but it's entirely possible that this will simply place a burden on the implementation to convert those textures to something the hardware can handle.

Unless you have storage space concerns, I'd favour offline conversion (i.e. save your images out as 24-bit in the first place), but it's not technically difficult either way.



来源:https://stackoverflow.com/questions/14373099/png-image-texture-format-for-color-type-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!