Page 1 of 2

Convert a 32-bit ARGB BMP to PNG

Posted: 2010-03-26T18:08:45-07:00
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.

Re: Convert a 32-bit ARGB BMP to PNG

Posted: 2010-03-26T18:13:47-07:00
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).

Re: Convert a 32-bit ARGB BMP to PNG

Posted: 2010-03-26T18:53:56-07:00
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.)

Re: Convert a 32-bit ARGB BMP to PNG

Posted: 2010-03-26T19:04:57-07:00
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.

Re: Convert a 32-bit ARGB BMP to PNG

Posted: 2010-03-26T19:09:14-07:00
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.

Re: Convert a 32-bit ARGB BMP to PNG

Posted: 2010-03-26T19:12:53-07:00
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

Re: Convert a 32-bit ARGB BMP to PNG

Posted: 2010-03-26T19:17:20-07:00
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.)

Re: Convert a 32-bit ARGB BMP to PNG

Posted: 2010-03-26T19:25:04-07:00
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.

Re: Convert a 32-bit ARGB BMP to PNG

Posted: 2010-03-26T19:27:21-07:00
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?)

Re: Convert a 32-bit ARGB BMP to PNG

Posted: 2010-03-26T19:31:46-07:00
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

Re: Convert a 32-bit ARGB BMP to PNG

Posted: 2010-03-26T19:32:33-07:00
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.

Re: Convert a 32-bit ARGB BMP to PNG

Posted: 2010-03-26T19:34:21-07:00
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.

Re: Convert a 32-bit ARGB BMP to PNG

Posted: 2010-03-26T20:00:47-07:00
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

Re: Convert a 32-bit ARGB BMP to PNG

Posted: 2010-03-26T20:02:32-07:00
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...

Re: Convert a 32-bit ARGB BMP to PNG

Posted: 2010-03-26T20:17:44-07:00
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