将调色板图像转换为RGB字节缓冲区

编程入门 行业动态 更新时间:2024-10-11 15:13:46
本文介绍了将调色板图像转换为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字节缓冲区

本文发布于:2023-10-31 10:03:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545759.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:调色板   缓冲区   转换为   字节   图像

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!