Color space conversion
From Attie's Wiki
(Difference between revisions)
m (→RGB565 to RGB888) |
m (Attie moved page Color space convertion to Color space conversion: spelling mistake) |
||
(One intermediate revision by one user not shown) | |||
Line 2: | Line 2: | ||
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] | 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"> | <source lang="bash"> | ||
− | IN_FILE=" | + | #!/bin/bash |
+ | |||
+ | IN_FILE="${1}" | ||
IN_FORMAT="RGB16" | IN_FORMAT="RGB16" | ||
IN_WIDTH="1024" | IN_WIDTH="1024" | ||
IN_HEIGHT="600" | IN_HEIGHT="600" | ||
− | OUT_FILE=" | + | OUT_FILE="$(echo "${IN_FILE}" | sed -re 's/\.[^\.]*//').png" |
gst-launch-1.0 -v filesrc "location=${IN_FILE}" blocksize=$(stat "${IN_FILE}" -c%s) ! \ | 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> | </source> | ||
Latest revision as of 16:53, 1 February 2016
[edit] GStreamer
For a list of available formats, see: GStreamer Docs
#!/bin/bash IN_FILE="${1}" IN_FORMAT="RGB16" IN_WIDTH="1024" IN_HEIGHT="600" OUT_FILE="$(echo "${IN_FILE}" | sed -re 's/\.[^\.]*//').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}"
[edit] 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; }