In doing quite a bit of work with a PocketPC home automation client, I needed a way to display user-defined images in the device.
I found some very good and useful code out there in CodeProject and was able to combine them (with some modifications and enhancements) into group of very useful libraries.
I won't go into too many details, as I've basically taken Chris Maunder's DibSectionLite and added methods to load using Davide Pizzolato's CXImage classes. You can find their original libraries and documentation on this site. No point in replicating it here.
Most of the work was in taking the original CXImage library and modifying it to make it compile on the PocketPC (Using eVC 3.0) This required a few
code. I opted to return
The next step was debugging the PNG code. Since the PNG library uses function pointers, it turns out that eVC modifies the signature between a debug and release build. The stack becomes corrupt upon return unless the signature for these functions are modified as below:
#if defined (_WIN32_WCE) && !defined (_DEBUG)
#define _CDECL_MODE_ __cdecl
static void _CDECL_MODE_ user_write_data(png_structp png_ptr,
Finally, I modified DibSectionLite to include:
- All the suggested fixes posted on CodeProject (including 16, 24 bit images)
- Cropping. I have a floorplan image I need to pan around on the screen, cropping is quite fast when displaying only a portion of the image.
Save now take a
CString.. Useful for memory images (
- Loading images via
You can add support and shrink/expand you executable size based on these defines as well as the ones in
#define DIBSECTION_SUPPORT_BMP 1
#define DIBSECTION_SUPPORT_GIF 1 #define DIBSECTION_SUPPORT_JPG 1
#define DIBSECTION_SUPPORT_PNG 1
#define DIBSECTION_SUPPORT_ICO 1
#define DIBSECTION_SUPPORT_TGA 1
#define DIBSECTION_SUPPORT_PCX 1
#define DIBSECTION_SUPPORT_JBG 1
New methods for loading are as follows:
BOOL LoadPNG(LPCTSTR lpszFileName);
BOOL LoadJPG(LPCTSTR lpszFileName);
BOOL LoadBMP(LPCTSTR lpszFileName);
BOOL LoadGIF(LPCTSTR lpszFileName);
BOOL LoadMNG(LPCTSTR lpszFileName);
BOOL LoadICO(LPCTSTR lpszFileName);
BOOL LoadTIF(LPCTSTR lpszFileName);
BOOL LoadTGA(LPCTSTR lpszFileName);
BOOL LoadPCX(LPCTSTR lpszFileName);
BOOL LoadWBMP(LPCTSTR lpszFileName);
BOOL LoadWMF(LPCTSTR lpszFileName);
BOOL LoadJ2K(LPCTSTR lpszFileName);
BOOL LoadJBG(LPCTSTR lpszFileName);
The code unravels and builds as a bunch of .LIB
You can compile and build the PocketPCTest app for your device. It is nothing fancy. Simply an exerciser. Uncomment the line in PocketPCTestView.cpp as needed.
The test app includes a definition of:
in the header.
void CPocketPCTestView::OnDraw(CDC* pDC)
CPocketPCTestDoc* pDoc = GetDocument();
And to load:
That's about it. I didn't really spend much time with making J2K, TIF, and WBMP work. I'll update the article if someone gets them working.
Chris and Davide, as well as those that have contributed to their articles. Many thanks! I hope some of these changes/fixes might make it back into your original libraries so us PocketPC developers can use your code 'out of the box'.