bitbank2 / JPEGDEC

An optimized JPEG decoder suitable for microcontrollers and PCs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't run example code esp32_jpeg.ino

Orel-A opened this issue · comments

I've been trying to run the example code but unfortunatly the library "bb_spi_lcd" has changed its API, thus the code won't run without modifications.
What I've been trying:

//#include <SD.h>
#include <bb_spi_lcd.h>
#include "JPEGDEC.h"
//#include "test_images/gray_road.h"
//#include "test_images/f6t.h"
#include "desert.h"

// Janzen Hub
#define CS_PIN -1
#define DC_PIN 2
#define LED_PIN -1
#define BUILTIN_SDCARD 0
#define RESET_PIN 4
#define MISO_PIN -1
#define MOSI_PIN 23
#define SCK_PIN 18

JPEGDEC jpeg;
SPILCD lcd;

//uint8_t ucTXBuf[1024];
static uint8_t *ucTXBuf;

//File file;
// pixel drawing callback
int drawMCU(JPEGDRAW *pDraw)
{
  int iCount = pDraw->iWidth * pDraw->iHeight;
//  Serial.printf("Draw pos = %d,%d. size = %d x %d\n", pDraw->x, pDraw->y, pDraw->iWidth, pDraw->iHeight);
  spilcdSetPosition(&lcd, pDraw->x, pDraw->y, pDraw->iWidth, pDraw->iHeight, 1);
spilcdWriteDataBlock(&lcd, (uint8_t *)pDraw->pPixels, iCount*2, 1);
  //memcpy(ucTXBuf, pDraw->pPixels, iCount*sizeof(uint16_t));
  //spilcdWriteDataBlock(&lcd, iCount*2, DRAW_WITH_DMA);  
  return 1;
} /* drawMCU() */

void setup()
{
char szTemp[128];

  Serial.begin(115200);
//  spilcdSetTXBuffer(ucTXBuf, sizeof(ucTXBuf));
  ucTXBuf = spilcdGetDMABuffer();
  spilcdInit(&lcd, LCD_ST7789_240, 0, 40000000, CS_PIN, DC_PIN, RESET_PIN, LED_PIN, MISO_PIN, MOSI_PIN, SCK_PIN);

//  if (!SD.begin(SDCARD_CS))
//  {
//    Serial.println("SD Init Fail!");
//  }
//  else
//  {
//    sprintf(szTemp, "SD Card Type: %d Size: %d MB", SD.cardType(), (int)(SD.cardSize() / 1024 / 1024));
//    Serial.println(szTemp);
//  }
} /* setup() */
void loop() {
long lTime;

  //spilcdFill(0,1);

  if (jpeg.openFLASH((uint8_t *)desert, sizeof(desert), drawMCU))
  {
    Serial.println("Successfully opened JPEG image");
    Serial.printf("Image size: %d x %d, orientation: %d, bpp: %d\n", jpeg.getWidth(),
      jpeg.getHeight(), jpeg.getOrientation(), jpeg.getBpp());
    if (jpeg.hasThumb())
       Serial.printf("Thumbnail present: %d x %d\n", jpeg.getThumbWidth(), jpeg.getThumbHeight());
    jpeg.setPixelType(RGB565_BIG_ENDIAN);
    lTime = micros();
    if (jpeg.decode(0,0,0))
    {
      lTime = micros() - lTime;
      Serial.printf("Successfully decoded image in %d us\n", (int)lTime);
    }
    jpeg.close();
  }
  
  delay(10000);
}

The TFT won't display anything howver I do get the message "Successfully decoded image in 72377 us".
Ultimatly it would be more helpful if there was an example with TFT_eSPI which is more widely used...

The library https://github.com/moononournation/Arduino_GFX has a nice example. Closing this