grayscale image

Hi, I have an image size of 256x256 in 8bit graycale.
How can I display this onto the screen?
do I use PgDrawImage()? but this takes RGB format I think.
Thanks

No PgDrawImage can display an image loaded by PxLoadImage which will take care of the conversion and building the palette.

If you do not use PxLoadImage you can create your own pallette and supply it to PgDrawImage, the function can handle multiple format as documentated in the PhImage_t page.

if I want to use PxLoadImage, do I have to pick one type of image file format (like jpg, bmp, gif etc) and convert all the 8bit grayscale to that format? coverting a 8bit grayscale to 24bit RGB is fairly easy, and making shared memory to video card to write those bits and passing the pointer to that share memory to PgDrawImage to blit the image a better solution?

If the image in the file is already black and white you don’t have anything to do, PxLoadImage will take care of everything.

Otherwise will need to take the PhImage_t you go fromPxLoadImage and convert it into another PhImage_t with the PALETTE_BYTE type, create the palette and then use PgDrawImage to display it.

In both cases it’s better to have the image in shared memory. That is documented.

I don’t have a image file. I am calculating the grayscale on the fly and putting them to a 256x256 int array. I could write this to a file and open it with PxLoadImage, but I would like to just be able to draw this grayscale array to the screen. How can I do this then?

Create a PtLabel and attach it a PhImage_t which points to your image, make sure you specify the palette for the PhImage. The palette is 256 byte and should be filled with something like:

for( i = 0; i< 256 ; i ++ )
{
palettei] = PgGrey(i);
}

Make sure you allocate the image file of PhImage in share memory with PgShmemCreate() for better performance.

Thanks~ I have used PhCreatImage with my own palette with PgGrey and it work nicely.
^____^