将调色板图像转换为RGB字节缓冲区 [英] Convert Palette image to RGB byte buffer

查看:178
本文介绍了将调色板图像转换为RGB字节缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是可用于将调色板图像缓冲区(包括位图信息)转换为RGB缓冲区的任何算法. c ++

Is any algorithm available for converting palette image buffer(including bitmap information) to RGB buffer. c++

推荐答案

没有这样的事情,因为任务本身太琐碎了.我并不是说这一定很容易;一个问题是性能.这完全取决于您使用的库和数据格式.

知道格式并可以访问输入和输出缓冲区后,您只需1)一次读取像素,2)获取调色板值,3)每个像素,在调色板表中查找颜色(无论是哪种格式), 4)计算输出像素的RGB值,5)写入输出.

如果需要,可将其称为算法" :-).

如何创建输出缓冲区和访问输入缓冲区,如何压缩数据(是必需的)—都取决于您使用的图像库,对位图类型的支持等.大多数库都具有"GetPixel"/"SetPixel"方法之类的东西,但是,它们的速度实在是太慢了.您需要访问缓冲区并使用指针.

—SA
There is no such thing because the task itself is too trivial. I don''t say it has to be easy though; one issue is performance. It all depends on library and data format you use.

Once you know the format and have access to input and output buffer, you just 1) read pixels one by one, 2) get palette value, 3) for each pixel, lookup for the color in palette table (whatever format it is), 4) calculate RGB value for an output pixel, 5) write to output.

Call it "algorithm" if you want :-).

How you create output buffer and access input buffer, how you compress data (is so required) — it all depends on the imaging library you use, support of bitmap types, etc. Most libraries have something like "GetPixel"/"SetPixel" methods, but, chances are, they are prohibitively slow. You need to access the buffers and use pointers.

—SA


我解决了这个问题,如下所示:

I solved this problem as shown below:

ULONG ulPixelDataSize = Height * Width * 3;
RGBQUAD* pRGB = new RGBQUAD[nNumColors];// Color table filled in pRGB.
BYTE* pbyPixelData = new BYTE[width * height];// Pixel data filled in pbyPixelData.

BYTE byNewSamplesPerPixel = 3;
BYTE* pbyRgbBuffer = new BYTE[ulPixelDataSize];
for( int nBufferIndex = 0; nBufferIndex < Height * Width; ++nBufferIndex )

{

    int nColouIndex = pbyPixelData[nBufferIndex];

    memcpy( pbyRgbBuffer + ( nBufferIndex * byNewSamplesPerPixel ), reinterpret_cast<BYTE*>( &( pRGB[nColouIndex] )), byNewSamplesPerPixel );
}



感谢您的支持和宝贵的意见.
如果可以比此问题更高的性能来解决此问题,那就更好了.



Thank you for the support and valuable comments.
It will be better if this problem can be resolved with higher performance than this one.


这篇关于将调色板图像转换为RGB字节缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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