PNG图像纹理格式为颜色类型3 [英] PNG image texture format for color type 3

查看:1047
本文介绍了PNG图像纹理格式为颜色类型3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个128x128尺寸的PNG图片。当我用libpng读取它的IHDR块时,它显示图像具有颜色类型3.问题是我不能找到任何地方应该是这种颜色类型的纹理格式。我想用OpenGL绘制这个图像。但是没有正确的纹理格式,图像颜色不是它应该是什么。并且如果任何参考可以提供,我可以阅读关于这件事的细节将非常感谢。

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;
  }
}


推荐答案

调色板只是一个颜色数组,图像数据只是该数组中的索引。

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

因此,如果你想将图像转换为RGB图像,缓冲区足够大,您的图像以该格式填充,并通过从源图像获取像素的索引,用该值索引调色板,并将您获得的RGB值存储到目标图像中。

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.

您可能会发现GL的风味,它支持调色纹理,并且可以直接加载它们,但是硬件支持在这些时候并不常见,而且你所做的只是卸载工作

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.

例如,OpenGL ES通过 glCompressedTexImage2D()支持一些类型的调色纹理, )函数,但是这完全可能会对实现造成负担,将这些纹理转换为硬件可以处理的东西。

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.

除非你有存储空间的关注,我倾向于离线转换(ie保存您的图像作为24位在第一),但它不是技术上困难的任何一种方式。

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.

这篇关于PNG图像纹理格式为颜色类型3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆