Welcome to part 2 of the TamsPalm pnoJpegLib tutorial – in case you missed part 1, it is right here!
Step 3: include JPEG resources
pilrc users can include JPEG resources via the data keyword – for us PODS users, this is a bit more difficult. First, create a subdirectory in the /rsc folder of your project. Then, open AppResources.xrd and add a resource. Uncheck the Show only common resources checkbox, and create a resource of any of the ” types. A window will pop up – you can enter a custom creator ID and the target file there(via Windows Open File dialog – choose All Files and click the JPEG file).
The PODS will then bind the file(it must be smaller than 64k) into the PRC at compile time!
For all resource HTML junkies, here is a sample of the resulting code. The HTML delimeters were replaced with () to make the post compatible with WordPress:
(RES_TYPE) 'tmgn' (/RES_TYPE)
(DATA_FILE) "./jpegs/lvl10.jpg" (/DATA_FILE)
Step 4: move JPEG data to a PalmOS bitmap
Now that the raw JPEG data is waiting in a resource, its time to decompress it. This code shows how to do it – the work happens in the read call:
//Prepare JPG lib
pnoJpeg2Bmp2DoubleDensity(jpgrefnum,jpgData,&jpgV3); //For HiRes only
h is a handle to a resource which can easily be obtained with DmGetResource – don’t forget to free it after use. The Bmp2DoubleDensity code is needed only on HiRes handhelds – leaving it out/drawing the jpegData bitmap creates weird results. The pointer can then be reused with a different resource or can be left in memory for reuse when you need to decompress the image once again.
On my Treo 680, decompressing a small 320×320 image takes next to no time – excessive buffering probably wont pay out here. Also, your monitor’s display is no assessment of quality for setting the correct compression factor – use your handheld’s screen and an application like RescoViewer.
Step 5: draw the bitmap
Now, we’re basically done. You have your (V3) bitmap – so do what you want with it!
The steps outlined above took me quite some time to figure out – feel free to benefit from my experiences! If you have any comments, just post them here. Commenting on TamsPalm is free and anonymous!