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:

(RAW_RESOURCE RESOURCE_ID="1010")
(RES_TYPE) 'tmgn' (/RES_TYPE)
(DATA_FILE) "./jpegs/lvl10.jpg" (/DATA_FILE)
(/RAW_RESOURCE)

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
BitmapPtr jpgData=NULL;
BitmapPtrV3 jpgV3;
if(jpgenable)
{
pnoJpeg2LoadFromHandle(jpgrefnum,jpgp,h);
pnoJpeg2SetGrayscale(jpgrefnum,jpgp,false);
pnoJpeg2SetScaleFactor(jpgrefnum,jpgp,1);
pnoJpeg2Read(jpgrefnum,jpgp,&jpgData);
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!

Related posts:

  1. pnoJpegLib and PODS – the tutorial – Part 1
  2. On distorted bitmaps
  3. PODS 1.2 and bitmaps is a catastrophe!!!
  4. Creating Multi-Segment applications with PODS
  5. Compiling FontBucket with PODS Part 2

3 Responses to “pnoJpegLib and PODS – the tutorial – Part 2”

  1. Very interesting article, Tam! I will have to download the lib and give it a go!

  2. Hi Ryan,
    have fun!

    If you need me to “bind” the resources for you, I can do it any time so that you can then use them in OnBoardC!

    Best regards
    Tam HAnna

  3. I just use PilRC for my non-standard resources when I get the chance. It works in a relatively small space so I just place the pilrc executable on the sd card and run when needed through drive mode and an availiable PC. (It is a bit slow, but it gets the job done!)

    Thanks for the offer, though!

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting

© 2013 TamsPalm - the Palm OS / web OS Blog Suffusion theme by Sayontan Sinha