DIB coder

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Locked
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

DIB coder

Post by el_supremo »

I've written a test program which does a screen capture, creates a DIB and then uses MagickReadImageBlob to load the image into IM from whence I can save the file in whatever format I like. The screen capture DIB has 32 bits per pixel, no compression and a standard 40 byte info header.
However, I ran into a problem whereby the saved image created this way has matte set and when viewed in PSP X the vast majority of the image is just the transparent background. OTOH, just to be awkward, Windows Picture and Fax Viewer ignores the matte setting and shows the full screen image.
If I change the program so that it writes a test.bmp file consisting of a BMP file header followed by the DIB (exactly as was given to MagickReadImageBlob) and then use "convert test.bmp testa.bmp" the output file is a normal BMP with no matte even though convert sees precisely the same info.
I used SetLogEventMask to create debugging output which shows that the DIB coder handles the image from MagickReadImageBlob whereas the BMP coder handles it when doing a convert and they obviously interpret the image in slightly different ways.
In the bmp.c coder the matte is set like this:

Code: Select all

image->matte=bmp_info.alpha_mask != 0 ? MagickTrue : MagickFalse;
and alpha_mask can be non-zero *only if* the BMP info header is more than 40 bytes long.
The dib.c coder only handles 40 byte info headers - it throws an exception for any other size - and sets the matte like this:

Code: Select all

image->matte=dib_info.bits_per_pixel == 32 ? MagickTrue : MagickFalse;
The MSDN info that came with my Visual C++.net compiler does not have any mention of matte or transparency when it describes the 40 byte DIB info header not even when there are 32 bits per pixel. It appears that it is an error for the DIB coder to set the matte under any condition and perhaps that statement should be removed?
In the meantime, in my program I have added a MagickSetImageMatte call after the MagickReadImageBlob to force the matte off.

Pete

Locked