thelastoutpostworkshop / AnimatedGIF340_240

Animated GIF on a 320x240 LCD Display (ILI9341) with the ESP32
https://youtu.be/omUWkUqFYrQ
MIT License
3 stars 0 forks source link

AnimatedGIF340_240 for 1.14" ST7789V Display #1

Open GarnetUngar opened 4 days ago

GarnetUngar commented 4 days ago
#include <bb_spi_lcd.h>
#include <AnimatedGIF.h>

// Master Animated GIF on a 320x240 SPI LCD Screen
// Youtube Tutorial: https://youtu.be/omUWkUqFYrQ
// Tested with Espressif ESP32 Arduino Core v3.0.2, 3.0.3
// Using ESP32-S3 with 8MB of PSRAM
// See also the Tutorial on how to create ESP32 custom partitions:
//
#include "esp_flash.h"
#include "esp_partition.h"

#include <bb_spi_lcd.h>  // gif_files\hud_a.h: No such file or directory
                         // Tested on version 2.5.4, 2.6.0
#include <AnimatedGIF.h> // Install this library with the Arduino IDE Library Manager
                         // Tested on version 2.1.1

// GIF files
#include "hud_a.h"                 //GIF size in FLASH memory is 1.7MB
#include "x_wing.h"                //GIF size in FLASH memory is 0.9MB
#include "death_star.h"            //GIF size in FLASH memory is 1.7MB
#include "star_destroyer.h"        //GIF size in FLASH memory is 1MB
#include "star_destroyer_planet.h" //GIF size in FLASH memory is 2.3MB
#include "scanner.h"               //GIF size in FLASH memory is 1.1MB
#include "star_trek_hud.h"         //GIF size in FLASH memory is 1.6MB
#include "Sickbay_11_26.h"
#include "jedi_battle.h"           //GIF size in FLASH memory is 3.3MB (use partitions.csv for this one, if you your ESP32 board has 4MB Flash size)

BB_SPI_LCD tft; // Main object for the display driver

// GIF to display
#define GifData Sickbay_11_26 // Change image to display (image name in gif_files\[image header file].h)

void setup()
{
  Serial.begin(115200);
 spilcdInit(&_lcd, LCD_ST7789, FLAGS_INVERT, 40000000, 15, 2, -1, 21, 12, 13, 14, 1); // Cheap Yellow Display 2 USB (2.8 w/resistive touch, 2 USB ports)
 spilcdSetOrientation(&_lcd, LCD_ORIENTATION_270);

 tft.fillScreen(TFT_BLACK);

  AnimatedGIF *gif;
  gif = openGif((uint8_t *)GifData, sizeof(GifData));
  if (gif == NULL)
  {
    Serial.println("Cannot open GIF");
    while (true)
    {
      //  no need to continue
    }
  }

  while (true)
  {
    gif->playFrame(true, NULL);
  }
}

void loop()
{
  delay(1);
}

// Open Gif and allocate memory
AnimatedGIF *openGif(uint8_t *gifdata, size_t gifsize)
{
  AnimatedGIF *gif;
  gif = (AnimatedGIF *)malloc(sizeof(AnimatedGIF));
  if (gif == NULL)
  {
    Serial.println("Not RAM Enough memory for GIF structure");
    return NULL;
  }

  gif->begin(GIF_PALETTE_RGB565_BE); // Set the cooked output type we want (compatible with SPI LCDs)

  if (gif->open(gifdata, gifsize, GIFDraw))
  {
    Serial.printf("Successfully opened GIF; Canvas size = %d x %d\n", gif->getCanvasWidth(), gif->getCanvasHeight());
    Serial.printf("GIF memory size is %ld (%2.2f MB)", gifsize, (float)gifsize / (1024 * 1024));
    gif->setDrawType(GIF_DRAW_COOKED); // We want the Animated GIF library to generate ready-made pixels
    if (gif->allocFrameBuf(GIFAlloc) != GIF_SUCCESS)
    {
      Serial.println("Not Enough RAM memory for frame buffer");
      return NULL;
    }
    return gif;
  }
  else
  {
    printGifErrorMessage(gif->getLastError());
    return NULL;
  }
}

//
// The memory management functions are needed to keep operating system
// dependencies out of the core library code
//
// memory allocation callback function
void *GIFAlloc(uint32_t u32Size)
{
  return malloc(u32Size);
} /* GIFAlloc() */
// memory free callback function
void GIFFree(void *p)
{
  free(p);
}

// Draw callback from the AnimatedGIF decoder
void GIFDraw(GIFDRAW *pDraw)
{
  if (pDraw->y == 0)
  { // set the memory window (once per frame) when the first line is rendered
    tft.setAddrWindow(pDraw->iX, pDraw->iY, pDraw->iWidth, pDraw->iHeight);
  }
  // For all other lines, just push the pixels to the display. We requested 'COOKED'big-endian RGB565 and
  tft.pushPixels((uint16_t *)pDraw->pPixels, pDraw->iWidth);
}

// Get human-readable error related to GIF
void printGifErrorMessage(int errorCode)
{
  switch (errorCode)
  {
  case GIF_DECODE_ERROR:
    Serial.println("GIF Decoding Error");
    break;
  case GIF_TOO_WIDE:
    Serial.println("GIF Too Wide");
    break;
  case GIF_INVALID_PARAMETER:
    Serial.println("Invalid Parameter for gif open");
    break;
  case GIF_UNSUPPORTED_FEATURE:
    Serial.println("Unsupported feature in GIF");
    break;
  case GIF_FILE_NOT_OPEN:
    Serial.println("GIF File not open");
    break;
  case GIF_EARLY_EOF:
    Serial.println("GIF early end of file");
    break;
  case GIF_EMPTY_FRAME:
    Serial.println("GIF with empty frame");
    break;
  case GIF_BAD_FILE:
    Serial.println("GIF bad file");
    break;
  case GIF_ERROR_MEMORY:
    Serial.println("GIF memory Error");
    break;
  default:
    Serial.println("Unknown Error");
    break;
  }
}
GarnetUngar commented 3 days ago

270 is the closest, the image is all there, but it is chopped up and rearranged in a weird way.

GarnetUngar commented 3 days ago

20241129_164809.jpg

GarnetUngar commented 3 days ago

Hold on, still have to try 180

GarnetUngar commented 3 days ago

180 no good

thelastoutpostworkshop commented 3 days ago

is there any other GIF you could try ?

thelastoutpostworkshop commented 3 days ago

270 seams to be good the axis seams to be reversed, you could try : tft.begin(LCD_ST7789_135, FLAGS_FLIPX, 40000000, TFT_CS, TFT_DC, TFT_RST, TFT_BL, TFT_MISO, TFT_DIN, TFT_CLK);

GarnetUngar commented 3 days ago

That resulted in a slightly different slicing up of the image. Now converting a new gif file to try...

GarnetUngar commented 3 days ago

I downloaded a 240x135 gif and converted it to a .h file, but got this error: C:\Users\Griselda Grumpy\Documents\Arduino\AnimatedGIF340_240\AnimatedGIF340_240_for_ST7789v_version_2\AnimatedGIF340_240_for_ST7789v_version_2\AnimatedGIF340_240_for_ST7789v_version_2.ino: In function 'void setup()': C:\Users\Griselda Grumpy\Documents\Arduino\AnimatedGIF340_240\AnimatedGIF340_240_for_ST7789v_version_2\AnimatedGIF340_240_for_ST7789v_version_2\AnimatedGIF340_240_for_ST7789v_version_2.ino:40:22: error: request for member 'h' in 'QvSe', which is of non-class type 'const uint8_t [349406]' {aka 'const unsigned char [349406]'} 40 | #define GifData QvSe.h // Change image to display (image name in gif_files[image header file].h) | ^ C:\Users\Griselda Grumpy\Documents\Arduino\AnimatedGIF340_240\AnimatedGIF340_240_for_ST7789v_version_2\AnimatedGIF340_240_for_ST7789v_version_2\AnimatedGIF340_240_for_ST7789v_version_2.ino:50:28: note: in expansion of macro 'GifData' 50 | gif = openGif((uint8_t )GifData, sizeof(GifData)); | ^~~ C:\Users\Griselda Grumpy\Documents\Arduino\AnimatedGIF340_240\AnimatedGIF340_240_for_ST7789v_version_2\AnimatedGIF340_240_for_ST7789v_version_2\AnimatedGIF340_240_for_ST7789v_version_2.ino:40:22: error: request for member 'h' in 'QvSe', which is of non-class type 'const uint8_t [349406]' {aka 'const unsigned char [349406]'} 40 | #define GifData QvSe.h // Change image to display (image name in gif_files[image header file].h) | ^ C:\Users\Griselda Grumpy\Documents\Arduino\AnimatedGIF340_240\AnimatedGIF340_240_for_ST7789v_version_2\AnimatedGIF340_240_for_ST7789v_version_2\AnimatedGIF340_240_for_ST7789v_version_2.ino:50:44: note: in expansion of macro 'GifData' 50 | gif = openGif((uint8_t )GifData, sizeof(GifData)); | ^~~

exit status 1

Compilation error: request for member 'h' in 'QvSe', which is of non-class type 'const uint8_t [349406]' {aka 'const unsigned char [349406]'}

I looked at the code for that .h file and the only difference seems to be this line: GIF, Compression=LZW, Size: 240 x 135, 7-Bpp

where all the other gifs say 8-Bpp

thelastoutpostworkshop commented 3 days ago

zip the original gif you tried and post it here, i will give it a try

GarnetUngar commented 3 days ago

QvSe.zip

thelastoutpostworkshop commented 3 days ago

no i mean the .h file of the gif you tried before, the one that got scrambled

GarnetUngar commented 3 days ago

Sorry, I think you mean this one: Sickbay_11_26.zip

GarnetUngar commented 3 days ago

You are a science fiction fan, recognize it?

thelastoutpostworkshop commented 3 days ago

star trek

GarnetUngar commented 3 days ago

yep

GarnetUngar commented 3 days ago

This is bizarre. I got the new gif to work, but it mixed with the old one ?!?https://github.com/user-attachments/assets/ac95e9e2-ff49-42a5-86cc-aa6762424322

thelastoutpostworkshop commented 3 days ago

it's working fine on my side. There is clearly a bug in the bb_spi_lcd library with the ST7789_135 and if I look at the code, the bug will still appear with a version that is not "V"

GarnetUngar commented 3 days ago

Bug spray?

thelastoutpostworkshop commented 2 days ago

We could use another graphic library (TFT_eSPI), that could support your display, it involved more steps though because this library requires editing configuration files in the library, not in the sketch.

GarnetUngar commented 2 days ago

I'm sorry this is such a pain, and again, I so appreciate all your time and expertise. Could we try using the TFT_eSPI library?

GarnetUngar commented 2 days ago

Just curious, I think you are Quebecois? I grew up in Montreal but have been in exile in the USA for many years...

GarnetUngar commented 2 hours ago

Thank you so much for all your help. Should I look elsewhere at this point, or do you have more time for me? Thanks again!