notmasteryet / jpgjs

JPEG/DCT data decoder
Other
237 stars 57 forks source link

Feature Request: Scaling on Decode #39

Open GordoRank opened 9 years ago

GordoRank commented 9 years ago

From having a brief look through your code it looks as though it should be possible to implement basic scaling on decode in the manner in which libjpeg version 8+ does... Basically by changing the DCT block size from 8x8 to something else (1x1, 4x4, 16x16 etc) so that only the DCT coefficients necessary for the desired size are decoded, effectively scaling the image.

My suggestion is to allow the parser to to be initialized with optional width/height parameters. Obviously the output size will not always be the same as the input values but the next largest possible size for the given jpeg image.

My rationale for this is that for our particular use case we have to deal with some very large images that are only ever intended to be displayed at a far lower resolution than the source files. In which case jpg.js is just too slow to be useful and a lot of processing time is used decoding data which only gets stripped in the resize/resample process before display.

Implementing this should dramatically speed up the process in such cases

A document describing exactly what I am suggesting can be found here:

http://jpegclub.org/temp/Evolution_of_JPEG.doc

I would love to know your thoughts on the matter..