diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-10-25 01:56:52 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-10-25 01:56:52 +0200 |
commit | aa579a4415f10842e52094c236f4b8d20cc1535d (patch) | |
tree | ca05ea51f48b89efdd52adaffb82bafb00cc36e6 | |
parent | m (diff) | |
download | scrotty-aa579a4415f10842e52094c236f4b8d20cc1535d.tar.gz scrotty-aa579a4415f10842e52094c236f4b8d20cc1535d.tar.bz2 scrotty-aa579a4415f10842e52094c236f4b8d20cc1535d.tar.xz |
whoops + support all endiannesses
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rwxr-xr-x | doc/concept | 5 | ||||
-rw-r--r-- | src/scrotty.c | 13 |
2 files changed, 11 insertions, 7 deletions
diff --git a/doc/concept b/doc/concept index 6cdb3fb..a88ebae 100755 --- a/doc/concept +++ b/doc/concept @@ -31,8 +31,9 @@ while [ -e /dev/fb$f ]; do echo P3 cat /sys/class/graphics/fb$f/virtual_size | sed -e 's/,/ /' echo 255 - cat /dev/fb$f | od -t u1 -v | cut -d ' ' -f 1 --complement | - sed -e 's/\([0-9]\+\) \+\([0-9]\+\) \+\([0-9]\+\) \+\([0-9]\+\)/\3 \2 \1/g' + (echo 'ibase=16;'; cat /dev/fb$f | od -t x4 -v | cut -d ' ' -f 1 --complement | + sed -e 's/\(..\)\(..\)\(..\)\(..\)\( \|$\)/\2 \3 \4 /g' | + sed -e 's/ /\n/g' | sed -e '/^$/d' -e 'y/abcedf/ABCEDF/') | bc ) | convert /dev/stdin $pathname (( f++ )) done diff --git a/src/scrotty.c b/src/scrotty.c index 730d32f..021372f 100644 --- a/src/scrotty.c +++ b/src/scrotty.c @@ -24,6 +24,7 @@ #include <fcntl.h> #include <string.h> #include <stdlib.h> +#include <stdint.h> #ifndef PATH_MAX @@ -95,7 +96,7 @@ static int save_pnm(const char* fbpath, int fbno, long width, long height, int f /* The PNM image should begin with `P3\n%{width} %{height}\n%{colour max=255}\n`. ('\n' and ' ' can be exchanged at will.) */ - fprintf(file, "P3\n%l %l255\n", width, height); + fprintf(file, "P3\n%li %li\n255\n", width, height); /* Convert raw framebuffer data into an PNM image. */ for (off = 0;;) @@ -110,10 +111,12 @@ static int save_pnm(const char* fbpath, int fbno, long width, long height, int f /* Convert read pixels. */ for (off = 0; off < got; off += 4) { - /* A pixel in the framebuffer is formatted as `%{blue}%{green}%{red}%{x}` in binary. */ - r = buf[off + 2] & 255; - g = buf[off + 1] & 255; - b = buf[off + 0] & 255; + /* A pixel in the framebuffer is formatted as `%{blue}%{green}%{red}%{x}` + in big-endian binary, or `%{x}%{red}%{green}%{blue}` in little-endian binary. */ + uint32_t* pixel = (uint32_t*)(buf + off); + r = (*pixel >> 16) & 255; + g = (*pixel >> 8) & 255; + b = (*pixel >> 0) & 255; /* A pixel in the PNM image is formatted as `%{red} %{green} %{blue} ` in text. */ fprintf(file, "%s%s%s", inttable[r], inttable[g], inttable[b]); } |