C code generated ARGB files

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
shahar

C code generated ARGB files

Post by shahar »

I generate millions of ARGB files using a C code and I need them in a "light" .jpg format as-well.
At the moment I use GraphicConverter (http://www.lemkesoft.com/) but as my ARGB files are piling up and getting bigger too I would like to run the conversion from the command line on the machine they are generated on.
The files have no header, they are produced on an Intel machine so their byte order is Little-Endian. Their color depth is 24 (or 32) and their format is ARGB (in GraphicConverter I have to check the "Interlaced" option to get the correct result).
For instance:
A file 1337x750 weighs 4011000 bytes which is 1337 x 750 x 4 (four 0-255 integers, one for each component - A, R, G, B in that order).

What should be the correct convert line in order to get it right?
This doesn't work:

Code: Select all

convert -size 1337x750 -depth 32 rgb:snap.02000.x.argb snap.02000.x.jpg
convert: Unexpected end-of-file `snap.02000.x.argb': No such file or directory.
neither does this:

Code: Select all

convert -size 1337x750 -depth 32 argb:snap.02000.x.argb snap.02000.x.jpg
convert: unable to open image `argb:snap.02000.x.argb': No such file or directory.
convert: missing an image filename `snap.02000.x.jpg'.
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: C code generated ARGB files

Post by Drarakel »

You have to specify the color channel depth, not the overall image depth. And you should also choose how to handle the transparency (e.g. by flattening over a background color) - as JPG can't store transparency.

Apart from that, I don't think that there's a raw ARGB format in ImageMagick (or is it?). But you can use one of the other raw 4-channel formats and rearrange the channels with some workarounds.
You could use "-color-matrix":

Code: Select all

convert -depth 8 -size 1337x750 rgba:snap.02000.x.argb -color-matrix "0 1 0 0, 0 0 1 0, 0 0 0 1, 1 0 0 0" -background white -flatten snap.02000.x.jpg
Or you could separate the channels and change the order with image sequence operations, e.g. like that:

Code: Select all

convert -depth 8 -size 1337x750 rgba:snap.02000.x.argb -channel All -separate -clone 0 -delete 0 -combine -channel BA -negate +channel -background white -flatten snap.02000.x.jpg
(The handling of the alpha channel complicates matters in this case. I tested some other file formats and operations, but there was always some obstacle.. Maybe someone else knows a more simple commandline.)
shahar

Re: C code generated ARGB files

Post by shahar »

I get this:

Code: Select all

convert: unrecognized option `-color-matrix'.
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: C code generated ARGB files

Post by Drarakel »

Did you also try the second commandline?

And: You probably have an old version of ImageMagick. (What exact version?)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: C code generated ARGB files

Post by fmw42 »

shahar wrote:I get this:

Code: Select all

convert: unrecognized option `-color-matrix'.

On older versions of IM, use -recolor with a 3x3 matrix
shahar

Re: C code generated ARGB files

Post by shahar »

I use ImageMagick-6.6.3-7 on linux which is a rather new version from what I gather.

I did try the other command and ended up with a completely black jpg file.
I will note though, that when using the rgba filter without the -color-matrix rearrangement I the correct picture with the exception that blue colors are interchanged with yellow.

Any ideas why -color-matrix is not recognized?
shahar

Re: C code generated ARGB files

Post by shahar »

Well, I feel kinda stupid!

Code: Select all

which convert
revealed I was indeed using an old version of ImageMagick that I was not even aware was installed on the system I am using.
I work on some remote supercomputer which is not very well maintained.

The -color-matrix option worked perfectly! Thanks.
Post Reply