Hi,

I noticed that the alpha component in the BMP file (when RGBA or BGRA) is not 
being preserved in the image. I would like to proposed the following small 
change to correct this problem. Instead of ignoring the alpha component, I 
first check if the bytesPerPixel == 4 bytes. If so, then I simply copy the row 
alpha to the image alpha component.

Does that make sense? Or am I not following the BMP standard?


Code:

    if (dib.bitsPerPixel >= 16)
    {
        unsigned char* imgp = imageBuffer;
        for (int i = 0; i < dib.height; ++i)
        {
            // read row
            unsigned char* rowp = &*rowBuffer.begin();
            fin.read((char*) rowp, rowBuffer.size());

            // copy to image buffer, swap/unpack BGR to RGB(A)
            for (unsigned int j = 0; j < bytesPerRow; j += bytesPerPixel)
            {
                if (dib.bitsPerPixel == 16)
                {
                    // 16-bit RGB -> 24-bit RGB
                    unsigned short rgb16 = (rowp[1] << 8) | rowp[0];
                    if (swap)
                        osg::swapBytes2((char*) &rgb16);

                    imgp[0] = (rgb16 & redMask) >> redShift;
                    imgp[1] = (rgb16 & greenMask) >> greenShift;
                    imgp[2] = (rgb16 & blueMask) >> blueShift;

                    // expand range
                    imgp[0] <<= (8-redMaskWidth);
                    imgp[1] <<= (8-greenMaskWidth);
                    imgp[2] <<= (8-blueMaskWidth);
                }
                else
                {
                    // BGR -> RGB(A)
                    imgp[0] = rowp[2];
                    imgp[1] = rowp[1];
                    imgp[2] = rowp[0];
                    if (imageBytesPerPixel == 4)
                    {
                        // ********* THIS IS MY CHANGE*******
                        if( bytesPerPixel == 4 )
                        {
                            imgp[3] = rowp[3];
                        }
                        else
                        {
                            imgp[3] = 0xFF;
                        }
                    }
                }
                imgp += imageBytesPerPixel;
                rowp += bytesPerPixel;
            }
        }
    }




Regards,

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=34271#34271





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to