How to convert a PNG to BGR 565 format using ImageMagick -
i'm trying use image magick convert png file bgr 565 bitmap image. i've done fair amount of research , haven't been able come answer. can me out?
compile c program , install in search path "rgbtobgr565"
/* rgbtobgr565 - convert 24-bit rgb pixels 16-bit bgr565 pixels written in 2016 glenn randers-pehrson <glennrp@users.sf.net> extent possible under law, author has dedicated copyright , related , neighboring rights software public domain worldwide. software distributed without warranty. see <http://creativecommons.org/publicdomain/zero/1.0/>. use imagemagick or graphicsmagick convert 24-bit rgb pixels 16-bit bgr565 pixels, e.g., magick file.png -depth 8 rgb:- | rgbtobgr565 > file.bgr565 note 16-bit pixels written in network byte order (most significant byte first), blue in significant bits , red in least significant bits. changlog: jan 2017: changed bgr565 int unsigned short (suggested steven valsesia) */ #include <stdio.h> int main() { int red,green,blue; unsigned short bgr565; while (1) { red=getchar(); if (red == eof) return (0); green=getchar(); if (green == eof) return (1); blue=getchar(); if (blue == eof) return (1); bgr565 = (unsigned short)(red * 31.0 / 255.0) | (unsigned short)(green * 63.0 / 255.0) << 5 | (unsigned short)(blue * 31.0 / 255.0) << 11; putchar((bgr565 >> 8) & 0xff); putchar(bgr565 & 0xff); } }
then run
magick file.png -depth 8 rgb:- | rgbtobgr565 > file.bgr565
for completeness, here program converting bgr565 pixels rgb:
/* bgr565torgb - convert 16-bit bgr565 pixels 24-bit rgb pixels written in 2016 glenn randers-pehrson <glennrp@users.sf.net> extent possible under law, author has dedicated copyright , related , neighboring rights software public domain worldwide. software distributed without warranty. see <http://creativecommons.org/publicdomain/zero/1.0/>. use imagemagick or graphicsmagick convert 16-bit bgr565 pixels 24-bit rgb pixels, e.g., bgr565torgb < file.bgr565 > file.rgb magick -size wxh -depth 8 file.rgb file.png */ #include <stdio.h> int main() { int rgbhi,rgblo,red,green,blue; while (1) { rgbhi=getchar(); if (rgbhi == eof) return (0); rgblo=getchar(); if (rgblo == eof) return (1); putchar((rgblo & 0x1f) << 3 | (rgblo & 0x14) >> 3 ); putchar((rgbhi & 0x07) << 5 | (rgblo & 0xe0) >> 3 | (rgbhi & 0x06) >> 1); putchar((rgbhi & 0xe0) | (rgbhi >> 5) & 0x07); } }
Comments
Post a Comment