website logo
Auteur
avatar
AmiDARK

Forum » » Création-Développement » » Datatype, Bitmap et canal Alpha : ReadPixelArray ?


Posté : 02-04-2013 19:43 icone du post

Voici ma fonction interne dans l'AmiDARK Engine pour charger une image en utilisant un DataType :

[quote]// ******************************************************************************* ********************************
/* Chargement d'une image en utilisant les DataTypes */
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;
#if defined( __amigaos4__ )
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 );
#else
dto = NewDTObject( (STRPTR)FileName,
DTA_SourceType, DTST_FILE,
DTA_GroupID, GID_PICTURE,
PDTA_DestMode, PMODE_V43,
PDTA_Remap, TRUE,
OBP_Precision, PRECISION_EXACT,
TAG_DONE );
#endif
if ( dto != 0 ){
#if defined( __amigaos4__ )
nb = IIntuition->GetAttrs( dto, PDTA_BitMapHeader, &bmh, TAG_DONE );
#else
nb = GetDTAttrs( dto, PDTA_BitMapHeader, &bmh, TAG_DONE );
#endif
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;
#if defined( __amigaos4__ )
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
AvailMethod = GetDTMethods( dto );
if ( FindMethod( AvailMethod, PDTM_READPIXELARRAY ) != 0 ){
bpa.MethodID = PDTM_READPIXELARRAY;
resread = DoMethodA( dto, bpaptr );
}else{
DebugMessage( debugDEImage, "Method PDTM_READPIXELARRAY not compatible with object.", 0 );
}
#endif
}else{
DebugMessage( debugDEImage, "Cannot allocate memory for internal picture structure.\n", 0 );
}
}else{
DebugMessage( debugDEImage, "Informations cannot be read from image file.\n", 0 );
}
#if defined( __amigaos4__ )
IIntuition->DisposeObject( dto );
#else
DisposeObject( dto );
#endif
}else{
DebugMessage( debugDEImage, "Unable to load the image file.\n", 0 );
}
return pt;
}
[/quote]

Si cela peut t'aider....

Cet article provient de Le site des utilisateurs francophones actuels et futurs d'AmigaOS 4.x
https://amiga-ng.org/viewtopic.php?topic=1514&forum=14