Home
Developer Resources
QNX RTOS v4
QNX RTOS v4 Knowledge Base

QNX RTOS v4 Knowledge Base

Foundry27
Foundry27
QNX RTOS v4 project
Resources

QNX RTOS v4 Knowledge Base

Title Creating image palletes
Ref. No. QNX.000009896
Category(ies) Development
Issue We are having difficulties figuring out how image palletes can be created. We have located a selection of palettes in /qnx4/photon/palette, but we do not know how to create one on our own.

Could you point us in the direction of a tool or utility for this?
Is there a way of extracting a palette from a particular image format?

Solution Here is the solution for you:

Create a (truecolor) image in photoshop that is 256 pixels (or as many colors as you want) by 1 pixel high.

Save it as a 'raw' format image. This simply dumps the pixels to a binary file in RGBRGB format.

Next, you need to write a little program that converts that data into a photon palette that might look something like this:

Note: this code won't compile.

/************code**************/
void main(){
x09unsigned chr r, g, b;
x09PgColor_t rgb;
x09int  in, out;
x09
x09in = open("input palette file", O_RDONLY);
x09out = open("output photon palette",O_WRONLY);
x09while(read(in, &r, 1) != -1 && read(in, &g, 1) != -1 && read(in, &b, 1) != -1){
x09x09rgb = PgRGB(r, g, b);
x09x09write(out, &color, sizeof(PgColor_t));
x09}
x09close(in);
x09close(out);
}
/*************************************/

Add more error checking and command line parameter parsing if you are going to use this many times.