[Q] Setting image's colors palette

Howdy,

I’m having trouble creating an image with a given color palette. I haven’t
find any example of how to create/set the palette for an image, so I
guess I’m missing something. Here is what I do :

PhImage_t *icon;
PgColor_t palette[256];

// set palette
int j=0;
for(int i=0;i<256;i++,j+=3)
palette = PgRGB(BePalette[j],BePalette[j+1],BePalette[j+2]);

PgSetPalette(palette,
0,
0,
256,
Pg_PALSET_SOFT,
PtCRC((char *)palette,sizeof(PgColor_t)*256));

// create image
icon = PhCreateImage(NULL,
kLargeIconWidth,
kLargeIconHeight,
Pg_IMAGE_PALETTE_BYTE,
palette,
256,
0);

icon->image_tag = PtCRC(icon->image,icon->bpl * icon->size.h);

memcpy(icon->image,kLargeIconBits,kLargeIconWidth * kLargeIconHeight);

When I display the image, it look ok, except for that the colors are not
correct, so I suppose that the palette is not set or not used.

Thanks for any help.

Regards,

jean-louis

Hi Jean-Louis,

I have spoken to the developer and he has a few questions

How are you displaying the image?

PgDrawImagemx or PgDrawPhImagemx? If you are using PgDrawImagemx then you
nees to call PgSetPalette first, if your using PgDrawPhImagemx then
there might be a bug with PhCreateImage…you can try putting the palette
in the PhImage_t your returning from PhCreateImage. (PhImage_t structure
should be documented).

Let me know if this works …
Hope this helps
Thanks
Brenda

Jean-Louis Villecroze <jlv@kirilla.com> wrote:

Howdy,

I’m having trouble creating an image with a given color palette. I haven’t
find any example of how to create/set the palette for an image, so I
guess I’m missing something. Here is what I do :

PhImage_t *icon;
PgColor_t palette[256];

// set palette
int j=0;
for(int i=0;i<256;i++,j+=3)
palette > = PgRGB(BePalette[j],BePalette[j+1],BePalette[j+2]);

PgSetPalette(palette,
0,
0,
256,
Pg_PALSET_SOFT,
PtCRC((char *)palette,sizeof(PgColor_t)*256));

// create image
icon = PhCreateImage(NULL,
kLargeIconWidth,
kLargeIconHeight,
Pg_IMAGE_PALETTE_BYTE,
palette,
256,
0);

icon->image_tag = PtCRC(icon->image,icon->bpl * icon->size.h);

memcpy(icon->image,kLargeIconBits,kLargeIconWidth * kLargeIconHeight);

When I display the image, it look ok, except for that the colors are not
correct, so I suppose that the palette is not set or not used.

Thanks for any help.

Regards,

jean-louis

Also make sure you are not freeing the palette before it gets drawn.

Regards
Brenda


Gui Group <gui@qnx.com> wrote:

Hi Jean-Louis,

I have spoken to the developer and he has a few questions

How are you displaying the image?

PgDrawImagemx or PgDrawPhImagemx? If you are using PgDrawImagemx then you
nees to call PgSetPalette first, if your using PgDrawPhImagemx then
there might be a bug with PhCreateImage…you can try putting the palette
in the PhImage_t your returning from PhCreateImage. (PhImage_t structure
should be documented).

Let me know if this works …
Hope this helps
Thanks
Brenda

Jean-Louis Villecroze <> jlv@kirilla.com> > wrote:

Howdy,

I’m having trouble creating an image with a given color palette. I haven’t
find any example of how to create/set the palette for an image, so I
guess I’m missing something. Here is what I do :

PhImage_t *icon;
PgColor_t palette[256];

// set palette
int j=0;
for(int i=0;i<256;i++,j+=3)
palette > = PgRGB(BePalette[j],BePalette[j+1],BePalette[j+2]);

PgSetPalette(palette,
0,
0,
256,
Pg_PALSET_SOFT,
PtCRC((char *)palette,sizeof(PgColor_t)*256));

// create image
icon = PhCreateImage(NULL,
kLargeIconWidth,
kLargeIconHeight,
Pg_IMAGE_PALETTE_BYTE,
palette,
256,
0);

icon->image_tag = PtCRC(icon->image,icon->bpl * icon->size.h);

memcpy(icon->image,kLargeIconBits,kLargeIconWidth * kLargeIconHeight);

When I display the image, it look ok, except for that the colors are not
correct, so I suppose that the palette is not set or not used.

Thanks for any help.

Regards,

jean-louis