How do you create a new image handler?

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
Earned a small fee
Earned a small fee
Posts: 12
Joined: Wed Mar 16, 2005 11:41 pm

How do you create a new image handler?

Post by fishjie » Thu Apr 07, 2005 3:34 am

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.

Experienced Solver
Experienced Solver
Posts: 93
Joined: Wed Feb 09, 2005 3:53 am

Post by mjs » Thu Apr 07, 2005 4:50 am

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.


Post Reply