bitbank2 / JPEGDEC

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

callback function not called on ESP32 #35

Closed palmerabollo closed 2 years ago

palmerabollo commented 2 years ago

Hi,

I'm using JPEGDEC to decode a jpeg file in a ESP32.

I have defined the following callback function:

int callback_jpeg(JPEGDRAW *pDraw) {
  Serial.println("CALLBACK");
  return 1;
}

And I'm passing it to jpeg.open, that reads the image from a file.

JPEGDEC jpeg;
File file = SPIFFS.open(TMP_IMAGE_PATH, "r");
boolean decoded = jpeg.open(file, callback_jpeg); // callback function registered here
if (decoded) {
  Serial.printf("Image size: %d x %d", jpeg.getWidth(), jpeg.getHeight());
}

The image is successfully decoded because I see this output:

Image size: 1280 x 960

However, the callback function is never called (I don't see the "CALLBACK" output). What could be the reason? It should be supported according to https://github.com/bitbank2/JPEGDEC#the-callback-functions= but I am not able to get it to work.

Thank you for your time!

bitbank2 commented 2 years ago

From your example, you haven't invoked the decoder. Opening the file just parses the header. You need to call decode() to get the decoder to run. Please see the example code.

palmerabollo commented 2 years ago

Thanks, it worked. I could have been looking at it for days...