Bodmer / TJpg_Decoder

Jpeg decoder library based on Tiny JPEG Decompressor
Other
227 stars 43 forks source link

dynamic sprite loading with setCallback #25

Closed don41382 closed 3 years ago

don41382 commented 3 years ago

Hi,

I am trying to load multiple sprite images. My problem is that TJpgDec.setCallback(...) set's the callback globaly. So when I am trying to call:

TJpgDec.setCallback([](int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t* bitmap) { 
  sprites[id].pushImage(x, y, w, h, bitmap);
  return true;
});

This doesn't work, because I can't access the id variable inside the lambda function. If I define it with captures, the signature of SketchCallback is working anymore.

Do you have any idea how to accomplish this? Thanks for you help in advance!

Bodmer commented 3 years ago

I think the simplest solution is to keep the callback as a function in the sketch then have a global id variable that selects which Sprite instance is to be used. I do not know where this labmda id is so unfortunately this is not something I can help with.