acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
Flash_PNG.ino (2903B)
1 2 // This example renders a png file that is stored in a FLASH array 3 // using the PNGdec library (available via library manager). 4 5 // Image files can be converted to arrays using the tool here: 6 // https://notisrac.github.io/FileToCArray/ 7 // To use this tool: 8 // 1. Drag and drop file on "Browse..." button 9 // 2. Tick box "Treat as binary" 10 // 3. Click "Convert" 11 // 4. Click "Save as file" and move the header file to sketch folder 12 // 5. Open the sketch in IDE 13 // 6. Include the header file containing the array (panda.h in this example) 14 15 // Include the PNG decoder library 16 #include <PNGdec.h> 17 #include "panda.h" // Image is stored here in an 8 bit array 18 19 PNG png; // PNG decoder inatance 20 21 #define MAX_IMAGE_WIDTH 240 // Adjust for your images 22 23 int16_t xpos = 0; 24 int16_t ypos = 0; 25 26 // Include the TFT library https://github.com/Bodmer/TFT_eSPI 27 #include "SPI.h" 28 #include <TFT_eSPI.h> // Hardware-specific library 29 TFT_eSPI tft = TFT_eSPI(); // Invoke custom library 30 31 //==================================================================================== 32 // Setup 33 //==================================================================================== 34 void setup() 35 { 36 Serial.begin(115200); 37 Serial.println("\n\n Using the PNGdec library"); 38 39 // Initialise the TFT 40 tft.begin(); 41 tft.fillScreen(TFT_BLACK); 42 43 Serial.println("\r\nInitialisation done."); 44 } 45 46 //==================================================================================== 47 // Loop 48 //==================================================================================== 49 void loop() 50 { 51 int16_t rc = png.openFLASH((uint8_t *)panda, sizeof(panda), pngDraw); 52 if (rc == PNG_SUCCESS) { 53 Serial.println("Successfully opened png file"); 54 Serial.printf("image specs: (%d x %d), %d bpp, pixel type: %d\n", png.getWidth(), png.getHeight(), png.getBpp(), png.getPixelType()); 55 tft.startWrite(); 56 uint32_t dt = millis(); 57 rc = png.decode(NULL, 0); 58 Serial.print(millis() - dt); Serial.println("ms"); 59 tft.endWrite(); 60 // png.close(); // not needed for memory->memory decode 61 } 62 delay(3000); 63 tft.fillScreen(random(0x10000)); 64 } 65 66 67 //=========================================v========================================== 68 // pngDraw 69 //==================================================================================== 70 // This next function will be called during decoding of the png file to 71 // render each image line to the TFT. If you use a different TFT library 72 // you will need to adapt this function to suit. 73 // Callback function to draw pixels to the display 74 void pngDraw(PNGDRAW *pDraw) { 75 uint16_t lineBuffer[MAX_IMAGE_WIDTH]; 76 png.getLineAsRGB565(pDraw, lineBuffer, PNG_RGB565_BIG_ENDIAN, 0xffffffff); 77 tft.pushImage(xpos, ypos + pDraw->y, pDraw->iWidth, 1, lineBuffer); 78 }