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_transparent_PNG.ino (2945B)
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 // The example png is encoded as ARGB 8 bits per pixel with indexed colour 6 // It was created using GIMP and has a transparent background area. 7 8 // Image files can be converted to arrays using the tool here: 9 // https://notisrac.github.io/FileToCArray/ 10 // To use this tool: 11 // 1. Drag and drop PNG image file on "Browse..." button 12 // 2. Tick box "Treat as binary" 13 // 3. Click "Convert" 14 // 4. Click "Save as file" and move the header file to sketch folder 15 // (alternatively use the "Copy to clipboard" and paste into a new tab) 16 // 5. Open the sketch in IDE 17 // 6. Include the header file containing the array (SpongeBob.h in this example) 18 19 // Include the PNG decoder library, available via the IDE library manager 20 #include <PNGdec.h> 21 22 // Include image array 23 #include "SpongeBob.h" 24 25 PNG png; // PNG decoder instance 26 27 #define MAX_IMAGE_WIDTH 240 // Sets rendering line buffer lengths, adjust for your images 28 29 // Include the TFT library - see https://github.com/Bodmer/TFT_eSPI for library information 30 #include "SPI.h" 31 #include <TFT_eSPI.h> // Hardware-specific library 32 TFT_eSPI tft = TFT_eSPI(); // Invoke custom library 33 34 // Position variables must be global (PNGdec does not handle position coordinates) 35 int16_t xpos = 0; 36 int16_t ypos = 0; 37 38 //==================================================================================== 39 // Setup 40 //==================================================================================== 41 void setup() 42 { 43 Serial.begin(115200); 44 Serial.println("\n\n Using the PNGdec library"); 45 46 // Initialise the TFT 47 tft.begin(); 48 tft.fillScreen(TFT_BLACK); 49 50 Serial.println("\r\nInitialisation done."); 51 } 52 53 //==================================================================================== 54 // Loop 55 //==================================================================================== 56 void loop() 57 { 58 uint16_t pngw = 0, pngh = 0; // To store width and height of image 59 60 int16_t rc = png.openFLASH((uint8_t *)bob, sizeof(bob), pngDraw); 61 62 if (rc == PNG_SUCCESS) { 63 Serial.println("Successfully opened png file"); 64 pngw = png.getWidth(); 65 pngh = png.getHeight(); 66 Serial.printf("Image metrics: (%d x %d), %d bpp, pixel type: %d\n", pngw, pngh, png.getBpp(), png.getPixelType()); 67 68 tft.startWrite(); 69 uint32_t dt = millis(); 70 rc = png.decode(NULL, 0); 71 tft.endWrite(); 72 Serial.print(millis() - dt); Serial.println("ms"); 73 tft.endWrite(); 74 75 // png.close(); // Required for files, not needed for FLASH arrays 76 } 77 78 delay(250); 79 80 // Randomly change position 81 xpos = random(tft.width() - pngw); 82 ypos = random(tft.height() - pngh); 83 84 // Fill screen with a random colour at random intervals 85 if (random(100) < 20) tft.fillScreen(random(0x10000)); 86 }