Color space conversion
From Attie's Wiki
(Difference between revisions)
(Created page with "==RGB565 to RGB888== A really nasty little app to convert between RAW RGB565 → RGB888. Useful for dumping a 16-bit linux framebuffer! <source lang="c"> #include <stdio.h>...") |
m (→RGB565 to RGB888) |
||
Line 1: | Line 1: | ||
+ | ==GStreamer== | ||
+ | For a list of available formats, see: [http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-videoconvert.html GStreamer Docs] | ||
+ | <source lang="bash"> | ||
+ | IN_FILE="screenshot.raw" | ||
+ | IN_FORMAT="RGB16" | ||
+ | IN_WIDTH="1024" | ||
+ | IN_HEIGHT="600" | ||
+ | |||
+ | OUT_FILE="screenshot.png" | ||
+ | |||
+ | gst-launch-1.0 -v filesrc "location=${IN_FILE}" blocksize=$(stat "${IN_FILE}" -c%s) ! \ | ||
+ | video/x-raw,format=${IN_FORMAT},width=${IN_WIDTH},height=${IN_HEIGHT},framerate=1/1 ! \ | ||
+ | videoconvert ! \ | ||
+ | video/x-raw,format=RGB,framerate=1/1 ! \ | ||
+ | pngenc ! \ | ||
+ | filesink "location=${OUT_FILE}" | ||
+ | </source> | ||
+ | |||
==RGB565 to RGB888== | ==RGB565 to RGB888== | ||
A really nasty little app to convert between RAW RGB565 → RGB888. Useful for dumping a 16-bit linux framebuffer! | A really nasty little app to convert between RAW RGB565 → RGB888. Useful for dumping a 16-bit linux framebuffer! |
Revision as of 16:49, 1 February 2016
GStreamer
For a list of available formats, see: GStreamer Docs
IN_FILE="screenshot.raw" IN_FORMAT="RGB16" IN_WIDTH="1024" IN_HEIGHT="600" OUT_FILE="screenshot.png" gst-launch-1.0 -v filesrc "location=${IN_FILE}" blocksize=$(stat "${IN_FILE}" -c%s) ! \ video/x-raw,format=${IN_FORMAT},width=${IN_WIDTH},height=${IN_HEIGHT},framerate=1/1 ! \ videoconvert ! \ video/x-raw,format=RGB,framerate=1/1 ! \ pngenc ! \ filesink "location=${OUT_FILE}"
RGB565 to RGB888
A really nasty little app to convert between RAW RGB565 → RGB888. Useful for dumping a 16-bit linux framebuffer!
#include <stdio.h> #include <stdlib.h> /* xxxx xxxx xxxx xxxx rrrr rggg gggb bbbb */ void write_red(int fdout, char *pixel) { char b; b = pixel[1]; b &= 0b11111000; write(fdout, &b, 1); } void write_green(int fdout, char *pixel) { char b, b2; b = pixel[1]; b <<= 5; b2 = pixel[0]; b2 >>= 3; b2 &= 0b00011100; b |= b2; b &= 0b11111100; write(fdout, &b, 1); } void write_blue(int fdout, char *pixel) { char b; b = pixel[0]; b <<= 3; b &= 0b11111000; write(fdout, &b, 1); } int main(int argc, char *argv[]) { char pixel[2]; int fdin; int fdout; fdin = fileno(stdin); fdout = fileno(stdout); while (read(fdin, pixel, 2) == 2) { write_red(fdout, pixel); write_green(fdout, pixel); write_blue(fdout, pixel); } return 0; }