Created
November 3, 2015 10:20
-
-
Save Hermann-SW/c28500a332f29b891b6a to your computer and use it in GitHub Desktop.
Convert Arduino ILI9341_due library "tft.screenshotToConsole()" Serial console output to .ppm picture file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
hex2ppm.c -- this is a hack. | |
(Arduino ILI9341_due library ILIScreenshotViewer is Windows only) | |
Just copy the hex line from Serial console to eg. "scr.hex" file. | |
Then "hex2ppm src.hex > src.ppm" (followed by ppmtojpeg if needed). | |
Sample "tft.screenshotToConsole();" output in serial console window: | |
==== PIXEL DATA START ==== | |
0000000002 ... 1D4D0D4013F000015B8 | |
==== PIXEL DATA END ==== | |
Total Image Data Length: 5560 | |
encoding: | |
0000000002 ... D4D0D4013F000015B8 | |
RRGGBBLLLL ... RRGGBBLLLL>totlen< | |
*/ | |
#include <stdio.h> | |
#include <string.h> | |
#include <assert.h> | |
int main(int argc, char *argv[]) | |
{ | |
FILE *src = (argc==1) ? stdin : fopen(argv[1], "r"); | |
char *ep, buf[]="0123456789"; | |
unsigned r,g,b,c,i,t=0; | |
assert(src != NULL); | |
printf("P3\n320 240\n255\n"); | |
while ( (1 == fread(buf, 10, 1, src)) && (isxdigit(buf[8])) ) | |
{ | |
c = strtoul(buf+6, &ep, 16); | |
buf[6]='\0'; | |
b = strtoul(buf+4, &ep, 16); | |
buf[4]='\0'; | |
g = strtoul(buf+2, &ep, 16); | |
buf[2]='\0'; | |
r = strtoul(buf, &ep, 16); | |
memset(buf, '\0', 10); | |
for(i=0; i<c; ++i) { printf("%u %u %u ", r, g, b); } | |
t += c; | |
} | |
assert(t == 320*240); | |
t = ftell(src); | |
i = strtoul(buf, &ep, 16); | |
assert( (t >= i+8) && (t <= i+10)); | |
fclose(src); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mentioned first in this Arduino forum posting:
http://forum.arduino.cc/index.php?topic=265806.msg2445130#msg2445130
hextoppm.c can be used to create animated .gif together with ppmtogif and gifsicle as well:
https://twitter.com/HermannSW/status/659466093698916352