bitbank2 / JPEGDEC

An optimized JPEG decoder suitable for microcontrollers and PCs.
Apache License 2.0
390 stars 46 forks source link

Is it possible to "pause" and "resume" decoding? #4

Closed C47D closed 4 years ago

C47D commented 4 years ago

Hi,

We were using tjpgd as JPEG decoder on a LVGL project and wondered if we could use JPEGDEC instead. Currently we decode the whole image in one step, but we have to dynamically allocate memory for the decoded image data. So I wonder if it's possible to pause the decoding of the image by returning an specific value on the draw callback, and then continue the decoding afterwards, this would allow is to allocate memory only for some MCUs and not the whole image.

I'm not well versed on JPEG decompressing but as far as I understand (correct me if I'm wrong) we would need to store the DC offset of the previous MCU to decompress the next one, so my question is pausing and resuming the decoding is possible?

bitbank2 commented 4 years ago

The code can't be paused in its current form, but your particular case doesn't sound like it needs that. When you open the file, you have full knowledge of the image size and subsampling option. If you're interested in capturing a small window of the image, you know how much memory to allocate because you're choosing the window size. You can tell my library to deliver a single MCU at a time (setMaxOutputSize(1)) and then your draw code will just save the ones that it wants. Each draw call includes the x/y position of the MCU on the main image. Does that make sense? The possible MCU sizes decoded are: 8x8, 16x8, 8x16 and 16x16 (depending on the subsampling option).