Scale Image in Byte Array

I’ve been playing around with MIDP a bit and I’ve run into some problems because of the limited amount of heap space available (200K).

I’ve got a JPEG Image in a byte array and I’m wondering if there is a way to scale it down without
creating an Image object first?

My first thought was to just loop through the array and take out some bytes. :o But I doubt that will work. :slight_smile:

Thanks,

Drew

um, jpeg? I thought most MIDP devices only supported png ???

Some of the newer devices support JPEG.

The problem is once you decompress these images, they are huge with respect to the size of the heap.

Drew

hmm,

Well without writing your own jpeg decoder, the eziest solution I can see is to break the big image down into tiles, load in each tile, create the rescaled version, garbage the old tile, load in the next tile, repeat.

Jpeg is a very complex format, just dropping random bytes is likely to get you garbage pretty fast.

I’d strongly suggest you preprocess the image to be the size you want before you compress it.

You could scale a JPEG image by the fixed amount of 1/8 in each dimension very quickly. You still need to do the Huffman decode… but you can avoid all the fancy stuff and just take the base colour for each 8x8 block. I don’t know enough about the data structure to say exactly how that’s done, but I do know it is possible.