Read 32bit bmp weird

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.
wizard29
Posts: 58
Joined: 2014-03-21T00:40:16-07:00
Authentication code: 6789
Location: Russia, Saint Petersburg
Contact:

Read 32bit bmp weird

Post by wizard29 »

Hi.
I read a 32bit bmp file. As result, I have a transparent image and RGB values is correct.
However, the source file contains an opaque image.
Maybe I am doing somthing wrong, but in case of a 24bit bmp image file the result is OK.
Looks like a bug.

I use IM 6.9.0 + Magick++.

Code: Select all

Magick::Image image;
try
{
    image.read(utf8FileName);
    image.colorSpace(Magick::sRGBColorspace);
    image.type(Magick::TrueColorMatteType);
    size_t height = image.rows();
    size_t width = image.columns();
    for (size_t i = 0; i < height; ++i)
    {
        const Magick::PixelPacket* pRow = image.getConstPixels(0, i, width, 1);
        for (size_t j = 0; j < width; ++j)
        {
            std::cout<<static_cast<unsigned char>(pRow->opacity);//always 255 in case of a 32 bit bmp file, but 0 in case of a 24bit bmp file.
            ++pRow;
        }
    }        
}
catch (const Magick::Exception& e)
{
    std::cout<<e.what();
}
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Read 32bit bmp weird

Post by snibgo »

You should provide sample input files that show the problem. You can upload to somewhere like dropbox.com and paste the URLs here.
snibgo's IM pages: im.snibgo.com
wizard29
Posts: 58
Joined: 2014-03-21T00:40:16-07:00
Authentication code: 6789
Location: Russia, Saint Petersburg
Contact:

Re: Read 32bit bmp weird

Post by wizard29 »

snibgo wrote:You should provide sample input files that show the problem. You can upload to somewhere like dropbox.com and paste the URLs here.
32bitbmp
same16bitbmp
Last edited by wizard29 on 2014-12-08T08:32:50-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Read 32bit bmp weird

Post by snibgo »

I can't see those files without signing in to Google.
snibgo's IM pages: im.snibgo.com
wizard29
Posts: 58
Joined: 2014-03-21T00:40:16-07:00
Authentication code: 6789
Location: Russia, Saint Petersburg
Contact:

Re: Read 32bit bmp weird

Post by wizard29 »

snibgo wrote:I can't see those files without signing in to Google.
I am sorry.
I fixed share settings for this links. You can try to download again.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Read 32bit bmp weird

Post by snibgo »

Where did 32bit.bmp come from? According to "identify", all the pixels have alpha=0, which is fully transparent.
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Read 32bit bmp weird

Post by magick »

We can reproduce the problem you posted and have a patch in ImageMagick 6.9.0-1 Beta available by sometime tomorrow. Thanks.
wizard29
Posts: 58
Joined: 2014-03-21T00:40:16-07:00
Authentication code: 6789
Location: Russia, Saint Petersburg
Contact:

Re: Read 32bit bmp weird

Post by wizard29 »

snibgo wrote:Where did 32bit.bmp come from? According to "identify", all the pixels have alpha=0, which is fully transparent.
I used the CS6 to save an image as bmp with 32bit settings.
wizard29
Posts: 58
Joined: 2014-03-21T00:40:16-07:00
Authentication code: 6789
Location: Russia, Saint Petersburg
Contact:

Re: Read 32bit bmp weird

Post by wizard29 »

For above images now works good. But does not work for CS, CSwithAlpha and IM, IMwithAlpha images.
The IM and IMwithAlpha images are files created via the IM Magick::Image::write call. Before the fix it worked fine.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Read 32bit bmp weird

Post by magick »

Looks like your original BMP image has the alpha channel backwards. It likely has a 1-alpha channel instead of alpha. Track down the BMP specification and see what it says about 32 bit alpha. Is 0 transparent or opaque?
wizard29
Posts: 58
Joined: 2014-03-21T00:40:16-07:00
Authentication code: 6789
Location: Russia, Saint Petersburg
Contact:

Re: Read 32bit bmp weird

Post by wizard29 »

Maybe you are right, but I add some semi-transparent areas on some images (CSwithAlpha, IMwithAlpha). But CSwithAlpha image looks absolutely transparent after reading and IMwithAlpha has inverted alpha.
wizard29
Posts: 58
Joined: 2014-03-21T00:40:16-07:00
Authentication code: 6789
Location: Russia, Saint Petersburg
Contact:

Re: Read 32bit bmp weird

Post by wizard29 »

You right it is correct behaviour you described. But:

Code: Select all

...
    std::cout<<static_cast<unsigned char>(pRow->opacity);//always 255 in case of the CSwithAlpha file, but 0 in case of the 32bitbmp file.
...
wizard29
Posts: 58
Joined: 2014-03-21T00:40:16-07:00
Authentication code: 6789
Location: Russia, Saint Petersburg
Contact:

Re: Read 32bit bmp weird

Post by wizard29 »

Thanks a lot, since the 17184 revision it works correct.
wizard29
Posts: 58
Joined: 2014-03-21T00:40:16-07:00
Authentication code: 6789
Location: Russia, Saint Petersburg
Contact:

Re: Read 32bit bmp weird

Post by wizard29 »

But the 32bitbmp is absolutely transparent again.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Read 32bit bmp weird

Post by magick »

Right. We reverted until we see the specification. For 32-bit BMP, is alpha 0, transparent or opaque. Sometimes image generators get it wrong and you'll see a complete transparent image where it should be opaque.
Post Reply