Reputation: 33
I am using a Raspberry Pi 3B+ and Imagemagick 6.9.7-4 Q16 arm 20170114 to convert a file to RGB565 and display it on a 480x320 screen (The image pixel dimensions are also 480x320) by writing it to the framebuffer. I'm using the following convert command:
convert dmi.jpg +flip -strip -define bmp:subtype=RGB565 bmp2:out.bmp
The expected filesize is 307,200 bytes. The actual filesize is coming in slightly higher due to the header data. Currently I am using dd to remove X number of bytes from the start of the file to make the file 307,200.
E.g. if the filesize is 307,338, I'm running the following command:
dd bs=138 skip=1 if=out.bmp of=out.trimmed.bmp
Once the file is trimmed and has a filesize of 307,200 I can write the file to the framebuffer
cat out.trimmed.bmp > /dev/fb1
Does anyone have any insight on how to update the convert command to simply omit the header data? I would like to cut out the middle steps and simply use Imagemagick to write directly to the framebuffer.
convert dmi.jpg +flip -strip -define bmp:subtype=RGB565 bmp2:/dev/fb1
I have attempted the following commands, but they all create a file that is much larger than my required filesize of 307,200.
convert dmi.jpg +flip -strip -define bmp:subtype=RGB565 rgb:0-rgb.bmp
convert dmi.jpg +flip -strip -define bmp:subtype=RGB565 rgba:0-rgba.bmp
convert dmi.jpg +flip -strip -define bmp:subtype=RGB565 dib:0-dib.bmp
I have tested fbi (fim) (framebuffer imageviewer) to do this and the program is not ideal for my needs. I have also tested ffmpeg to do the conversion, but it's resource heavy and slow.
Thank You!
Upvotes: 2
Views: 2393
Reputation: 207345
Improved Answer
Rather than guessing how big the (variable) header is, it is probably simpler to just take the tail-end of the file. So, if you know your frame buffer is 480x320 and 2 bytes per pixel, i.e. RGB565, use:
convert dmi.jpg +flip -strip -define bmp:subtype=RGB565 bmp2:- | tail -c $((480*320*2)) > /dev/fb1
That arithmetic expression is admittedly a bash-ism
, but Raspbian has bash
anyway, and it can be replaced with:
convert dmi.jpg +flip -strip -define bmp:subtype=RGB565 bmp2:- | tail -c 307200 > /dev/fb1
Original Answer
Like this:
convert dmi.jpg +flip -strip -define bmp:subtype=RGB565 bmp2:- | dd bs=138 skip=1 > /dev/fb1
Explanation:
bmp2:-
will make ImageMagick write a BMP2 on stdout
. By default, dd
will read stdin
and write stdout
which is then redirected to the framebuffer.
Upvotes: 2