bitbank2 / JPEGDEC

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

have JPEG_DRAW_CALLBACK to draw on specific screen #51

Closed felipetrentin closed 1 year ago

felipetrentin commented 1 year ago

this isn't a problem with the library itself rather than a misunderstanding of my part.

I'm doing a project which has 3 Adafruit_ST7789 screens. I've been trying to create a generic callback instead of having identical callbacks like JPEGDrawScreen_0 JPEGDrawScreen_1 etc...

what i've tried so far:

and i get error: invalid cast from type 'std::_Bind_helper<false, int (*)(jpeg_draw_tag*, Adafruit_ST7789*), const std::_Placeholder<1>&, Adafruit_ST7789*&>::type' {aka 'std::_Bind<int (*(std::_Placeholder<1>, Adafruit_ST7789*))(jpeg_draw_tag*, Adafruit_ST7789*)>'} to type 'int (*)(JPEGDRAW*)' {aka 'int (*)(jpeg_draw_tag*)'}

in both I ran into similar issues, jpeg.openRAM has JPEG_DRAW_CALLBACK that is incompatible with lambda and bind functions. Is there any way to do this other than having multiple callbacks?

Keep in mind that i'm still learning C++ ;)

bitbank2 commented 1 year ago

Your situation is why I added a "User pointer" to the JPEGDRAW structure. Use the setUserPointer(void *p) method (before you call decode) to pass a pointer to whatever info you need in your Draw callback. It's the pDraw->pUser variable.