bitbank2 / JPEGDEC

An optimized JPEG decoder for Arduino

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

have JPEG_DRAW_CALLBACK to draw on specific screen

felipetrentin opened this issue · comments

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:

  • adding a screen pointer as parameter and using std::bind
int JPEGDrawScreen(JPEGDRAW *pDraw, Adafruit_ST7789 *screen)
{
  screen->dmaWait(); // Wait for prior writePixels() to finish
  screen->setAddrWindow(pDraw->x, pDraw->y, pDraw->iWidth, pDraw->iHeight);
  screen->writePixels(pDraw->pPixels, pDraw->iWidth * pDraw->iHeight, true, false); // Use DMA, big-endian
  return 1;
} /* JPEGDraw() */

then actually draw with
jpeg.openRAM((uint8_t *) imgBuf, datasize, (JPEG_DRAW_CALLBACK *) bind(&JPEGDrawScreen, std::placeholders::_1, screen))

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*)'}

  • using lambda functions.

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++ ;)

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.