Page 1 of 1

How do you create a new image handler?

Posted: Thu Apr 07, 2005 3:34 am
by fishjie
I would like to manipulate ppm images, but wxwidgets currently does not support this image format. so i'd like to write my own image handler, which shouldn't be so hard for ppm images since its ppm is a pretty simple and straightforward image format.

However, I'm not sure how to go about this. I'm guessing I need to override the wxImageHandler::LoadFile(wxImage* image, wxInputStream& stream, bool verbose=true, int index=0) so that it can load a ppm image. I'm guessing the function would need to copy all the pixel values in the ppm image over into the wximage object - correct?
However, I'm not sure exactly how the image data is stored in a wximage - is just giving it an array of pixels sufficient?

I haven't been able to find any tutorials on this so any help would be nice.

Posted: Thu Apr 07, 2005 4:50 am
by mjs
Currently, the pixels in a wxImage are stored as 8 bit RGB that can be accessed through GetData() and 8 bit Alpha (GetAlpha()).

The steps for loading would be:

1. read image properties (width/height/depth)
2. allocate memory (RGB and optionally ALPHA) with malloc()
3. read RGB and optionally ALPHA
4. set image data (RGB) with SetData(rgb_buffer)
5. set image alpha channel with SetAlpha(alpha_buffer)

Please don't forget to fill the other functions with "life" too.

Regards,
Mark