Page 1 of 1

convert bgra to png complains of no file, but file exists

Posted: 2019-09-18T16:47:07-07:00
by DDR
Hello. I'm trying to convert a raw bgra-formatted image to a png on Ubuntu.

The natural command to try is

Code: Select all

convert -size 800x480 -depth 8 /tmp/screenshot.bgra /tmp/screenshot.png
but this does not work, claiming

Code: Select all

convert-im6.q16: unexpected end-of-file `/tmp/screenshot.rgba': No such file or directory @ error/rgb.c/ReadRGBImage/243.
convert-im6.q16: no images defined `/tmp/screenshot.png' @ error/convert.c/ConvertImageCommand/3258.
Running identify yields the same rather unhelpful error.

Code: Select all

$ identify -size 800x480 -depth 8 /tmp/screenshot.bgra
identify-im6.q16: unexpected end-of-file `/tmp/screenshot.bgra': No such file or directory @ error/bgr.c/ReadBGRImage/244.
Now, at this point, I know you're thinking I'm a fool who couldn't find his image if it were in the directory in front of him. However,

Code: Select all

$ ls -la /tmp/screenshot.bgra
-rw-rw-r-- 1 david david 25165824 Sep 18 16:00 /tmp/screenshot.bgra
says it is there, and it's full of data, and it imports into Gimp just fine if I rename it to screenshot.data.

If I run

Code: Select all

convert -size 800x4 -depth 8 /tmp/screenshot.bgra /tmp/screenshot.png
then I get several hundred very short .png images, which isn't what I expected at all. I think I've missed something fairly fundamental, but I don't know where. :(

I have uploaded the sample input and output to https://filebin.net/e1bbejly48gmktnn/sc ... t=fdwiigio, which should be valid until 2019-09-14.

Thank you.

Re: convert bgra to png complains of no file, but file exists

Posted: 2019-09-18T17:03:59-07:00
by snibgo
What is in your screenshot.bgra? You suggest it has 800x480 pixels, with 4 channels, 1 byte/channel/pixel. So that would be 1536000 bytes. But your file is much larger at 25 MB.

EDIT: This works without complaint:

Code: Select all

magick -size 4096x1536 -depth 8 screenshot.bgra x.png
The result looks bad because I probably mis-guessed the actual dimensions.

Re: convert bgra to png complains of no file, but file exists

Posted: 2019-09-18T18:45:50-07:00
by DDR
Hm, upon further investigation, it seems what I was getting out of my source - "cat /dev/fb0" - was an 800xlots image, not the 800x480 image I was expecting. The first 800x480 pixels were good - which was why Gimp could open them - but the rest was garbage which was confusing ImageMagick. I've amended the source command to "cat /dev/fb0 | head --bytes=1536000" which works fine. :D

Thank you for your help, snibgo.

Re: convert bgra to png complains of no file, but file exists

Posted: 2019-09-19T06:53:05-07:00
by snibgo
Yes, that works:

Code: Select all

head --bytes=1536000 screenshot.bgra | magick -size 800x480 -depth 8 BGRA:- out.png