From aa579a4415f10842e52094c236f4b8d20cc1535d Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 25 Oct 2014 01:56:52 +0200 Subject: whoops + support all endiannesses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/scrotty.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src') 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 #include #include +#include #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]); } -- cgit v1.2.3-70-g09d2