In the past few days I have tested displaying BMPX files with Alpha Mask. In the process I've discovered a few things.
After several attempts to display transparent bmpx images I suspected there might be something wrong in the way
that the datatypes library handles reading from the picture datatype as 'RGBA' but it has no problem with 'ARGB' such
as with png datatype. Transparent png images using 'ARGB' display perfectly. So I came up with a "Direct Read"
function to read the data in the bmpx file directly then display it on screen. That method worked perfectly as well.
I found these few lines in the PNG picture datatype which seems to confirm my belief there's something wrong here!
case PNG_COLOR_TYPE_RGB_ALPHA:
png.png_depth = 32;
#if 0
png.png_format = PBPAFMT_RGBA;
#else
/* FIXME: PBPAFMT_RGBA not supported by picture.datatype, therefore using PBPAFMT_ARGB */
png.png_format = PBPAFMT_ARGB;
png_set_swap_alpha(png.png_ptr);
#endif
So I proved that "Direct Read" works. It's interesting that I use 'RGBA' to encode the bmpx file but
Writing to the datatype (WRITEPIXELARRAY) works fine as well. After Save_BMPX programs such as
PixelFormer, GIMP and maybe Photoshop CS4/5 display the file as Transparent BMPX.
For example, when reading from the datatype as 'ARGB' all the Alpha values are changed to 'FF' (255).
When I change to reading from the datatype as 'RGBA' (wherein lies the problem) and using 'ARGB' to
display the image I get a skewed blue-ish but transparent image! In this case Read 'RGBA' - Display 'ARGB'
distorts the Blue values transforming them into, you guessed it 'FF' (255). Using 'RGBA' it can't read the
fourth value, either Alpha or Blue, whichever is indicated. I hope that all makes sense.
This is my Direct Read Method that works well for my graphics program:
if(picType == "bmp")
{
BPTR fileHandle = Open(fname, MODE_OLDFILE); //MODE_OLDFILE
Seek(fileHandle,54,OFFSET_BEGINNING);
Read(fileHandle,bitmapImage,(in_pic->Width*4*in_pic->Height)); //BGRA
UBYTE tempRGB;
int imageIdx = 0;
for (imageIdx = 0;imageIdx < (in_pic->Width*4*in_pic->Height);imageIdx+=4)
{
tempRGB = bitmapImage[imageIdx]; //blue
bitmapImage[imageIdx] = bitmapImage[imageIdx + 3]; //alpha
bitmapImage[imageIdx + 3] = tempRGB; //blue
tempRGB = bitmapImage[imageIdx+1]; //green
bitmapImage[imageIdx+1] = bitmapImage[imageIdx + 2]; //red
bitmapImage[imageIdx + 2] = tempRGB; //green
}
Flip_Vertical(bitmapImage, in_pic->Width, in_pic->Height, 4);
Close(fileHandle);
}
showImage(bitmapImage, bitmapInfoHeader, fname, isIcon);
So, in the next few days I will fix up what I have for the BMPX picture datatype.
It Loads and Saves BMP files correctly but it currently can't load an alpha mask.
Maybe I can fix the problem with alpha transparency in a future update along with support for OS/2 bitmaps. :-)