Convert a 32-bit ARGB BMP to PNG

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?".
gnuwtey

Convert a 32-bit ARGB BMP to PNG

Post by gnuwtey »

I'm currently trying to use ImageMagick to mass-convert a bunch of 32-bit ARGB BMP's that were generated by a C source file into PNG's, simply because the transparencies for BMP's don't work in Java. (I then learned that they don't usually work anywhere.)

I've tried the regular command:

Code: Select all

convert 0001.bmp 0001.png
but the image that comes out has white where transparency should be. I've also tried the "-alpha on" and "-alpha copy" options, and they come with the same result.

Why is this the case? Is there an option that I'm missing? I've searched the rest of the forums and the stuff that I found doesn't seem to help.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert a 32-bit ARGB BMP to PNG

Post by fmw42 »

What version of IM are you using? I seem to recall there might have been an update for ARGB BMP not too long ago?

From the changelog:

2009-04-25 6.5.1-9 Cristy <quetzlzacatenango@image...>
Generate BMP 32-bit ARGB format for images with transparency (reference viewtopic.php?f=3&t=13633).
gnuwtey

Re: Convert a 32-bit ARGB BMP to PNG

Post by gnuwtey »

I'm using "6.6.0 Q16".

And I'm not trying to generate the BMP's, I'm trying to read them and keep the alpha while converting. (I generated them using a C++ file that split them from a GIMP ARGB image, if that helps.)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert a 32-bit ARGB BMP to PNG

Post by fmw42 »

Only thing I can recommend is post a link to one of them so that the IM folks can check it out and others can try to convert it as well.
gnuwtey

Re: Convert a 32-bit ARGB BMP to PNG

Post by gnuwtey »

Alright, here is one of them: Image

It's a 32-bit ARGB BMP file. When viewing in GIMP, the parts that appear white in this preview are actually transparent.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert a 32-bit ARGB BMP to PNG

Post by fmw42 »

I downloaded your image and looked at its verbose info:

identify -verbose info:
Image: 0236.bmp
Format: BMP (Microsoft Windows bitmap image)
Class: DirectClass
Geometry: 16x16+0+0
Resolution: 33.47x33.47
Print size: 0.47804x0.47804
Units: PixelsPerCentimeter
Type: Palette <----- should say PaletteMatte if it has transparency
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
Channel statistics:
Red:
min: 88 (0.345098)
max: 255 (1)
mean: 216.484 (0.848958)
standard deviation: 46.8667 (0.183791)
kurtosis: -0.257781
skewness: -0.956338
Green:
min: 56 (0.219608)
max: 255 (1)
mean: 197.68 (0.775214)
standard deviation: 65.9651 (0.258687)
kurtosis: -0.954318
skewness: -0.697506
Blue:
min: 64 (0.25098)
max: 255 (1)
mean: 191.211 (0.749847)
standard deviation: 67.8843 (0.266213)
kurtosis: -1.38859
skewness: -0.390263
...


There is no alpha channel in this image.

But you can change the white to transparent via:

convert 0236.bmp -transparent white 0236_trans.png
Last edited by fmw42 on 2010-03-26T19:17:25-07:00, edited 1 time in total.
gnuwtey

Re: Convert a 32-bit ARGB BMP to PNG

Post by gnuwtey »

fmw42 wrote:There is no alpha channel in this image.
So that leaves me wondering why GIMP reads the first 8 bits of the 4-byte word as an alpha channel. (And I can't really convert the white because some of the pixels are already ffffff, and I don't want to sift through almost 3000 images looking for a few dead pixels.)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert a 32-bit ARGB BMP to PNG

Post by fmw42 »

I am on a Mac. If I open it in Photoshop CS (old), Debabelizer or Preview, it does not show an alpha channel. but if I open it in GraphicConverter, it shows as 24-bit rgb with 8-bit alpha.

So I would say that there is some issue with this format that so many readers do not recognize it properly including IM.

I would pass this on to the Bugs forum and have the IM folks check it out.
gnuwtey

Re: Convert a 32-bit ARGB BMP to PNG

Post by gnuwtey »

fmw42 wrote:I would pass this on to the Bugs forum and have the IM folks check it out.
Alright. I did some more research and it turns out that ARGB32 isn't quite a standard with BMP's yet. But I'll check with the IM people and see if they can do anything about it. (Perhaps another option under the formats?)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert a 32-bit ARGB BMP to PNG

Post by fmw42 »

gnuwtey wrote:
fmw42 wrote:I would pass this on to the Bugs forum and have the IM folks check it out.
Alright. I did some more research and it turns out that ARGB32 isn't quite a standard with BMP's yet. But I'll check with the IM people and see if they can do anything about it. (Perhaps another option under the formats?)

Then post to the Developers forum
gnuwtey

Re: Convert a 32-bit ARGB BMP to PNG

Post by gnuwtey »

fmw42 wrote:Then post to the Developers forum
Argh. I was going to, but then I posted it under "bugs" instead. I'll put another one in Developers.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert a 32-bit ARGB BMP to PNG

Post by fmw42 »

suggest you see if you can find any documentation about the format and point the IM folks to that. It might help speed things up for them.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Convert a 32-bit ARGB BMP to PNG

Post by el_supremo »

I've looked at the sample file. It has a standard V3 bitmap header with the biBitCount field set to 32. The documentation that comes with my Microsoft compiler says that when biBitCount is 32, the remaining image data is formatted like this:
"Each DWORD in the bitmap array represents the relative intensities of blue, green, and red, respectively, for a pixel. The high byte in each DWORD is not used."
i.e. there is no alpha channel even though there's room for it.

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
gnuwtey

Re: Convert a 32-bit ARGB BMP to PNG

Post by gnuwtey »

el_supremo wrote:i.e. there is no alpha channel even though there's room for it.
So would the solution be to use a V4 or V5 header, which does create an alpha channel? (and if even those don't create it, I wouldn't know what. According to Wikipedia, there has been an ARGB32 standard since Windows XP, but I have no idea how to use it.)

All I want to do is to convert it into PNG...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert a 32-bit ARGB BMP to PNG

Post by fmw42 »

As I mentioned above:

You can change the white to transparent via:

convert 0236.bmp -transparent white 0236_trans.png

or if there is white in the interior to the image, you can do

convert 0236.bmp -fill none -draw "matte 0,0 floodfill" 0236_trans.png


see http://www.imagemagick.org/Usage/draw/#matte
Post Reply