//
// JPEG thumbnail decode test
//
// This example sketch decodes an EXIF thumbnail image
// embedded in a 12 megapixel photo taken on a mobile phone
//
// It's written to run on an ESP32 connected to a ILI9341 LCD
// although it can certainly be compiled on other target MCUs and displays
//
#include <bb_spi_lcd.h>
#include "JPEGDEC.h"
#include "../test_images/thumb_test.h"
// These pin definitions are for a custom ESP32
// board. Please change them to match the display
// and board you're using
int i = 0;
#define WIDTH 320
#define HEIGHT 240
#define CS_PIN 15
#define DC_PIN 2
#define LED_PIN -1
#define RESET_PIN 12
#define MISO_PIN 16
#define MOSI_PIN 13
#define SCK_PIN 14
// Static instance of the JPEGDEC structure. It requires about
// 17.5K of RAM. You can allocate it dynamically too. Internally it
// does not allocate or free any memory; all memory management decisions
// are left to you
JPEGDEC jpeg;
// The LCD display library instance
SPILCD lcd;
//
// Pixel drawing callback
// called once for each set of MCUs (minimum coded units).
// JPEGDEC will try to send as many pixels as it can per call.
// In this case, it's as many as can fit in
// the internal 4K pixel buffer. This allows it to run more
// efficiently than calling this for every MCU. For this demo, the
// MCUs are only 4x4 pixels each since we ask to decode the image
// at 1/4 size
//
void setup()
{
Serial.begin(115200);
while (!Serial) {};
spilcdInit(&lcd, LCD_ILI9341, FLAGS_NONE, 40000000, CS_PIN, DC_PIN, RESET_PIN, LED_PIN, MISO_PIN, MOSI_PIN, SCK_PIN,1 );
//
spilcdSetOrientation(&lcd, LCD_ORIENTATION_90);
spilcdFill(&lcd, 0, DRAW_TO_LCD); // erase display to black
spilcdWriteString(&lcd, 46,0,(char *)"JPEG Thumbnail test", 0x7e0,0,FONT_12x16, DRAW_TO_LCD);
delay(4000);
} /* setup() */
void loop() {
long lTime;
char szTemp[64];
i = i++;
// Open a large JPEG image stored in FLASH memory (included as thumb_test.h)
// This image is 12 megapixels, but has a 320x240 embedded thumbnail in it
for (int x=0; x<WIDTH-1; x+=20)
{
spilcdDrawLine(&lcd, x, 0, WIDTH-1-x, HEIGHT-1, 0xffe0, DRAW_TO_LCD);
} // for x
spilcdScroll(&lcd, i+5,0xffe0, draw_to_lcd );
delay(10000); // repeat every 10 seconds
}