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

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
DDR
Posts: 2
Joined: 2019-09-18T16:24:34-07:00
Authentication code: 1152

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

Post by DDR » 2019-09-18T16:47:07-07:00

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.

snibgo
Posts: 12142
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo » 2019-09-18T17:03:59-07:00

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.
snibgo's IM pages: im.snibgo.com

DDR
Posts: 2
Joined: 2019-09-18T16:24:34-07:00
Authentication code: 1152

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

Post by DDR » 2019-09-18T18:45:50-07:00

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.

snibgo
Posts: 12142
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo » 2019-09-19T06:53:05-07:00

Yes, that works:

Code: Select all

head --bytes=1536000 screenshot.bgra | magick -size 800x480 -depth 8 BGRA:- out.png
snibgo's IM pages: im.snibgo.com

Post Reply