Hi Grzegorz,
Here is my personal function to load images (using datatypes) in the AmiDARK Engine.
It work with PNG using alpha transparency ( RGBA 32bits images ).
Code: Select all
struct MyPicture * LoadPicture( APTR FileName ){
struct MyPicture *pt = NULL;
Object *dto = NULL;
ULONG nb;
ULONG * AvailMethod = NULL;
struct BitMapHeader *bmh;
struct pdtBlitPixelArray bpa;
void * bpaptr = &bpa;
if ( !FileName ) return NULL;
dto = IDataTypes->NewDTObject( (STRPTR)FileName,
DTA_SourceType, DTST_FILE,
DTA_GroupID, GID_PICTURE,
PDTA_DestMode, PMODE_V43,
PDTA_Remap, TRUE,
OBP_Precision, PRECISION_EXACT,
TAG_DONE );
if ( dto != 0 ){
nb = IIntuition->GetAttrs( dto, PDTA_BitMapHeader, &bmh, TAG_DONE );
if( nb != 0 ){
int resread;
/* Allocation de la structure Picture et du buffer mémoire */
pt = AllocPicture32( bmh->bmh_Width, bmh->bmh_Height );
if ( pt != NULL ){
bpa.pbpa_PixelData = pt->Pixels;
bpa.pbpa_PixelFormat = PBPAFMT_RGBA;
bpa.pbpa_PixelArrayMod = bmh->bmh_Width * 4;
bpa.pbpa_Left = 0;
bpa.pbpa_Top = 0;
bpa.pbpa_Width = bmh->bmh_Width;
bpa.pbpa_Height = bmh->bmh_Height;
AvailMethod = IDataTypes->GetDTMethods( dto );
if ( IDataTypes->FindMethod( AvailMethod, PDTM_READPIXELARRAY ) != 0 ){
bpa.MethodID = PDTM_READPIXELARRAY;
resread = IIntuition->IDoMethodA( dto, bpaptr );
}else{
DebugMessage( debugDEImage, "Method PDTM_READPIXELARRAY not compatible with object.\n", 0 );
}
}else{
DebugMessage( debugDEImage, "Cannot allocate memory for internal picture structure.\n", 0 );
}
}else{
DebugMessage( debugDEImage, "Informations cannot be read from image file.\n", 0 );
}
IIntuition->DisposeObject( dto );
}else{
DebugMessage( debugDEImage, "Unable to load the image file.\n", 0 );
}
return pt;
MyPicture structure is :
Code: Select all
struct MyPicture{
int Width;
int Height;
int Depth;
unsigned char *Pixels;
};
and I setup my image buffer this way :
Code: Select all
struct MyPicture * AllocPicture32( int Width, int Height ){
struct MyPicture *pt = NULL;
pt = (struct MyPicture *)MyAllocVec( sizeof( struct MyPicture ), MEMF_ANY|MEMF_CLEAR );
if ( pt ){
pt->Pixels = MyAllocVec( Width * ( Height + 1 ) * 4, MEMF_ANY );
pt->Width = Width;
pt->Height = Height;
pt->Depth = 32;
if ( pt->Pixels == NULL ){
MyFreeVec( pt );
pt = NULL;
}
}
return pt;
}
I use IIntuition->IDoMethodA( dto, bpaptr ) to uncompress the image in my memory buffer as raw RGBA 32 bits pixels maps
it allow me to set how the image is decoded using : bpa.pbpa_PixelFormat = PBPAFMT_RGBA;
I force Depth to 32 in the Buffer allocation in the function AllocPicture32( int Width, int Height ). It ensure that the information is correctly given.
I think you will always get 24 bits for image even if there is an alpha 8 bits channel (it's something I remind to have heard when I worked on DataType system :p)
I'm currently working on understanding bltBitMapTags functions and it seem to be used this way :
Code: Select all
void myBltBitMap2BitMap( struct BitMap * srcBitMap, int xStart, int yStart, struct BitMap * tgtBitMap, int xStartT, int yStartT, int Width, int Height, BOOL Transparency ){
IGraphics->BltBitMapTags( BLITA_SrcType, BLITT_BITMAP, BLITA_Source, srcBitMap,
BLITA_SrcX, xStart, BLITA_SrcY, yStart,
BLITA_DestType, BLITT_BITMAP, BLITA_Dest, tgtBitMap,
BLITA_DestX, xStartT, BLITA_DestY, yStartT,
BLITA_Width, Width, BLITA_Height, Height,
BLITA_AlphaMask, Transparency, TAG_END );
}
if you use 2 bitmap structures for sources & target.
My function is untested because I'm currently working on these bltBitMap functions these days :p
I hope it helped you.
Kindest Regards,
AmiDARK