manmatha.roy
manmatha.roy

Reputation: 571

How to convert an 256 color to the closest matching RGB color?

I am upgrading an SVGA-driven GUI Software to Qt-driven one. 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.

Is there any formula to do this ?

Note:I am using C/C++ as my build language.

Upvotes: 1

Views: 1646

Answers (1)

paddy
paddy

Reputation: 63481

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. 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. 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.

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.

Upvotes: 2

Related Questions