简体   繁体   English

如何将256色转换为最接近的RGB颜色?

[英]How to convert an 256 color to the closest matching RGB color?

I am upgrading an SVGA-driven GUI Software to Qt-driven one. 我正在将SVGA驱动的GUI软件升级为Qt驱动的GUI软件。 One of the problems is to do the color conversion. 问题之一是进行颜色转换。 As SVGA uses 256 color model, and Qt uses RGB color model(actually it supports other models too; but i am using RGB).Hence i need a linear mapping of 256 Color to equivalent RGB Color. 由于SVGA使用256色模型,而Qt使用RGB颜色模型(实际上它也支持其他模型;但是我使用RGB),因此我需要将256色线性映射到等效的RGB颜色。

Is there any formula to do this ? 有什么公式可以做到这一点吗?

Note:I am using C/C++ as my build language. 注意:我正在使用C / C ++作为构建语言。

You need to work out what palette is being used. 您需要确定正在使用的调色板。 This should be encoded in the application. 这应该在应用程序中进行编码。 A palette is an array of 256 RGB values. 调色板是256个RGB值的数组。 To use a colour you use the array index (a single byte). 要使用颜色,请使用数组索引(单个字节)。 Once you have the palette information, you have the linear mapping that you're after. 掌握了调色板信息后,便有了所需的线性映射。

There is a default palette in VGA modes. VGA模式下有一个默认调色板。 Most programs will set their own, but either way the palette information resides on the graphics card. 大多数程序将设置自己的程序,但是无论哪种方式调色板信息都将驻留在图形卡上。 You should be able to query it, but I can't help you with that. 您应该可以查询它,但是我不能为您提供帮助。 The last time I wrote any code to do this was about 15 years ago when we all knew what memory addresses to write to for various graphics operations. 我上一次编写任何代码来执行此操作的时间大约是15年前,当时我们都知道对于各种图形操作应写入哪些内存地址。

Another way to find out the palette: If you are able to modify that application to write a bunch of pixels, simply draw a 16x16 block containing all 256 colour values, get a screenshot and then recover the palette from that. 查找调色板的另一种方法:如果能够修改该应用程序以写入一堆像素,只需绘制一个包含所有256个颜色值的16x16块,获取屏幕截图,然后从中恢复调色板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM