views:

166

answers:

3

I'm working on a program that creates thumbnails of JPEG images on the fly. Now I was thinking: since a JPEG image is built from 8x8-pixel blocks (Wikipedia has a great explanation), would it be possible to skip part of the decoding?

Let's say that my thumbnails are at least 8 times smaller than the original image. We could then map each 8x8 block in the input file to 1 pixel in the decoding output, by including only the constant term of the discrete cosine transform. Most of the image data can be discarded right away, and need not be processed. Moreover, the memory usage is reduced by a factor of 64.

I don't want to implement this from scratch; that'll easily take a week. Is there any code out there that can do this?

If not, is this because this approach isn't worthwhile, or simply because nobody has thought of it yet?

+2  A: 

I think that djpeg's scale feature does something like this.

It can scale an 8x8 block to any size between 1 and 16 pixels.

"This is interesting because different spatial size output can be retrieved directly from the JPEG (DCT) data without separate full decode and spatial resample."

rjmunro
Exactly what I was looking for, and it's in a suitably licensed mainstream library too. Thank you!
Thomas
A: 

The project I'm working on currently uses ImageGen which does all kinds of image resizing on the fly - this may pay for itself if the feature list matches what you want. Otherwise I guess that you're looking to implement a lossy file compression on images, which must have been done before!

amelvin
+2  A: 

According to this answer, EPEG from Enlightenment did exactly this, by collecting the DCT coefficients to scale the image down by a factor of 8. Here is the current home of EPEG.

jleedev
I wish I could accept two answers, but alas, there can be only one. Upvoted nonetheless.
Thomas