bitbank2 / JPEGDEC

An optimized JPEG decoder for Arduino
Apache License 2.0
366 stars 47 forks source link

Calling decode twice or more = garbled output? #20

Closed mrcodetastic closed 3 years ago

mrcodetastic commented 3 years ago

Hi Larry,

Fantastic library I must say.

I was testing this decoding some small icons, and I noticed that if I call decode twice (or more) then I get garbage. I want to do this in order to duplicate a jpg in my display output (long story).

The colors get screwed up more and more with each subsequent decode. Is this expected behaviour?

Example pseudocode:

        if (jpeg.open(jpegfile, TickerJPEG::drawMCU))
        {

             if (jpeg.decode(0, 0, 0))
              {
                  Sprintln(F("Successfully decoded JPEG."));
              }  

              if (jpeg.decode(10, 10, 0))
              {
                  Sprintln(F("Successfully decoded JPEG."));
              }  

}

I don't particulary want to open and close the jpg decoder file stream each time etc.

bitbank2 commented 3 years ago

There are internal functions to do what you want (JPEGInit, JPEGParseInfo), but the best way is to close and reopen the file. It didn't occur to me that anyone would want to decode the same file again without re-opening it because you already have the pixel data. I suppose I could add a "JPEGRewind" function to do what you want. If you're repeatedly working with small icons, why not keep them in RAM? The JPEG decoder structure needs about 17.5K. Do you have RAM to spare?

mrcodetastic commented 3 years ago

Hi Larry. No need to do any further work on the library! I've actually decided to use the excellent animated GIF decoder instead, so problem solved :-)