acidportal- 😈 Worlds smallest Evil Portal on a LilyGo T-QT |
git clone git://git.acid.vegas/acidportal.git |
Log | Files | Refs | Archive | README | LICENSE |
screenshotToConsole.ino (7614B)
1 // Include code in this tab and call screenshotToConsole() this dumps an 2 // image off the screen and sends it to a PC via the serial port in a Run 3 // Length Encoded format for viewing with a "ILIScreenshotViewer" utility. 4 5 // The PC "ILIScreenshotViewer" is part of the ILI9241_due library in the 6 // Tools folder, that library can be found here: 7 // https://github.com/marekburiak/ILI9341_Due 8 9 // Converted by Bodmer to operate with the TFT_ILI9341_ESP library: 10 // https://github.com/Bodmer/TFT_ILI9341_ESP 11 12 /* 13 The functions below have been adapted from the ILI9341_due library, the file 14 header from the .cpp source file is included below: 15 16 ILI9341_due_.cpp - Arduino Due library for interfacing with ILI9341-based TFTs 17 18 Copyright (c) 2014 Marek Buriak 19 20 This library is based on ILI9341_t3 library from Paul Stoffregen 21 (https://github.com/PaulStoffregen/ILI9341_t3), Adafruit_ILI9341 22 and Adafruit_GFX libraries from Limor Fried/Ladyada 23 (https://github.com/adafruit/Adafruit_ILI9341). 24 25 This file is part of the Arduino ILI9341_due library. 26 Sources for this library can be found at https://github.com/marekburiak/ILI9341_Due. 27 28 ILI9341_due is free software: you can redistribute it and/or modify 29 it under the terms of the GNU Lesser General Public License as published by 30 the Free Software Foundation, either version 2.1 of the License, or 31 (at your option) any later version. 32 33 ILI9341_due is distributed in the hope that it will be useful, 34 but WITHOUT ANY WARRANTY; without even the implied warranty of 35 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 36 GNU Lesser General Public License for more details: 37 <http://www.gnu.org/licenses/>. 38 39 */ 40 //==================================================================================== 41 42 void screenshotToConsole() 43 { 44 uint8_t e = 0; 45 uint8_t lastColor[3]; 46 uint8_t color[3]; 47 uint32_t sameColorPixelCount = 0; 48 uint16_t sameColorPixelCount16 = 0; 49 uint32_t sameColorStartIndex = 0; 50 uint32_t totalImageDataLength = 0; 51 52 // delay(1000); 53 54 // Header text 55 Serial.println((eye[e].tft.width() - 1)); 56 Serial.println((eye[e].tft.height() - 1)); 57 Serial.println(F("==== PIXEL DATA START ====")); 58 59 // Get first pixel to prime the Run Length Encoded 60 // Function format is: tft.readRectRGB( x, y, width, height, buffer); 61 // color is a pointer to a buffer that the RGB 8 bit values are piped into 62 // the buffer size must be >= (width * height * 3) bytes 63 eye[e].tft.readRectRGB(0, 0, 1, 1, color); // 1 x 1 so reading 1 pixel at 0,0 64 65 lastColor[0] = color[0]; // Red 66 lastColor[1] = color[1]; // Green 67 lastColor[2] = color[2]; // Blue 68 69 printHex8(color, 3); //Send color of the first pixel to serial port 70 totalImageDataLength += 6; 71 sameColorStartIndex = 0; 72 73 for (uint32_t py = 0; py < (eye[e].tft.height() - 1); py++) 74 { 75 for (uint32_t px = 0; px < (eye[e].tft.width() - 1); px++) 76 { 77 uint32_t i = px + eye[e].tft.width() * py; 78 yield(); 79 if (i) 80 { 81 eye[e].tft.readRectRGB(px, py, 1, 1, color); 82 83 if (color[0] != lastColor[0] || 84 color[1] != lastColor[1] || 85 color[2] != lastColor[2]) 86 { 87 sameColorPixelCount = i - sameColorStartIndex; 88 if (sameColorPixelCount > 65535) 89 { 90 sameColorPixelCount16 = 65535; 91 printHex16(&sameColorPixelCount16, 1); 92 printHex8(lastColor, 3); 93 totalImageDataLength += 10; 94 sameColorPixelCount16 = sameColorPixelCount - 65535; 95 } 96 else 97 sameColorPixelCount16 = sameColorPixelCount; 98 printHex16(&sameColorPixelCount16, 1); 99 printHex8(color, 3); 100 totalImageDataLength += 10; 101 102 sameColorStartIndex = i; 103 lastColor[0] = color[0]; 104 lastColor[1] = color[1]; 105 lastColor[2] = color[2]; 106 } 107 } 108 } 109 } 110 sameColorPixelCount = (uint32_t)eye[e].tft.width() * (uint32_t)eye[e].tft.height() - sameColorStartIndex; 111 if (sameColorPixelCount > 65535) 112 { 113 sameColorPixelCount16 = 65535; 114 printHex16(&sameColorPixelCount16, 1); 115 printHex8(lastColor, 3); 116 totalImageDataLength += 10; 117 sameColorPixelCount16 = sameColorPixelCount - 65535; 118 } 119 else 120 sameColorPixelCount16 = sameColorPixelCount; 121 printHex16(&sameColorPixelCount16, 1); 122 totalImageDataLength += 4; 123 printHex32(&totalImageDataLength, 1); 124 125 // Footer text 126 Serial.println(); 127 Serial.println(F("==== PIXEL DATA END ====")); 128 Serial.print(F("Total Image Data Length: ")); 129 Serial.println(totalImageDataLength); 130 } 131 132 void printHex8(uint8_t *data, uint8_t length) // prints 8-bit data in hex 133 { 134 char tmp[length * 2 + 1]; 135 byte first; 136 byte second; 137 for (int i = 0; i < length; i++) { 138 first = (data[i] >> 4) & 0x0f; 139 second = data[i] & 0x0f; 140 // base for converting single digit numbers to ASCII is 48 141 // base for 10-16 to become upper-case characters A-F is 55 142 // note: difference is 7 143 tmp[i * 2] = first + 48; 144 tmp[i * 2 + 1] = second + 48; 145 if (first > 9) tmp[i * 2] += 7; 146 if (second > 9) tmp[i * 2 + 1] += 7; 147 } 148 tmp[length * 2] = 0; 149 Serial.print(tmp); 150 } 151 152 void printHex16(uint16_t *data, uint8_t length) // prints 8-bit data in hex 153 { 154 char tmp[length * 4 + 1]; 155 byte first; 156 byte second; 157 byte third; 158 byte fourth; 159 for (int i = 0; i < length; i++) { 160 first = (data[i] >> 12) & 0x0f; 161 second = (data[i] >> 8) & 0x0f; 162 third = (data[i] >> 4) & 0x0f; 163 fourth = data[i] & 0x0f; 164 //Serial << first << " " << second << " " << third << " " << fourth << endl; 165 // base for converting single digit numbers to ASCII is 48 166 // base for 10-16 to become upper-case characters A-F is 55 167 // note: difference is 7 168 tmp[i * 4] = first + 48; 169 tmp[i * 4 + 1] = second + 48; 170 tmp[i * 4 + 2] = third + 48; 171 tmp[i * 4 + 3] = fourth + 48; 172 //tmp[i*5+4] = 32; // add trailing space 173 if (first > 9) tmp[i * 4] += 7; 174 if (second > 9) tmp[i * 4 + 1] += 7; 175 if (third > 9) tmp[i * 4 + 2] += 7; 176 if (fourth > 9) tmp[i * 4 + 3] += 7; 177 } 178 tmp[length * 4] = 0; 179 Serial.print(tmp); 180 } 181 182 void printHex32(uint32_t *data, uint8_t length) // prints 8-bit data in hex 183 { 184 char tmp[length * 8 + 1]; 185 byte dataByte[8]; 186 for (int i = 0; i < length; i++) { 187 dataByte[0] = (data[i] >> 28) & 0x0f; 188 dataByte[1] = (data[i] >> 24) & 0x0f; 189 dataByte[2] = (data[i] >> 20) & 0x0f; 190 dataByte[3] = (data[i] >> 16) & 0x0f; 191 dataByte[4] = (data[i] >> 12) & 0x0f; 192 dataByte[5] = (data[i] >> 8) & 0x0f; 193 dataByte[6] = (data[i] >> 4) & 0x0f; 194 dataByte[7] = data[i] & 0x0f; 195 //Serial << first << " " << second << " " << third << " " << fourth << endl; 196 // base for converting single digit numbers to ASCII is 48 197 // base for 10-16 to become upper-case characters A-F is 55 198 // note: difference is 7 199 tmp[i * 4] = dataByte[0] + 48; 200 tmp[i * 4 + 1] = dataByte[1] + 48; 201 tmp[i * 4 + 2] = dataByte[2] + 48; 202 tmp[i * 4 + 3] = dataByte[3] + 48; 203 tmp[i * 4 + 4] = dataByte[4] + 48; 204 tmp[i * 4 + 5] = dataByte[5] + 48; 205 tmp[i * 4 + 6] = dataByte[6] + 48; 206 tmp[i * 4 + 7] = dataByte[7] + 48; 207 //tmp[i*5+4] = 32; // add trailing space 208 if (dataByte[0] > 9) tmp[i * 4] += 7; 209 if (dataByte[1] > 9) tmp[i * 4 + 1] += 7; 210 if (dataByte[2] > 9) tmp[i * 4 + 2] += 7; 211 if (dataByte[3] > 9) tmp[i * 4 + 3] += 7; 212 if (dataByte[4] > 9) tmp[i * 4 + 4] += 7; 213 if (dataByte[5] > 9) tmp[i * 4 + 5] += 7; 214 if (dataByte[6] > 9) tmp[i * 4 + 6] += 7; 215 if (dataByte[7] > 9) tmp[i * 4 + 7] += 7; 216 } 217 tmp[length * 8] = 0; 218 Serial.print(tmp); 219 } 220