Pages vues depuis 25/07/2007 : 25 264 921
Index du forum »» Création-Développement »» [AOS4] [Sample] - Utiliser les datatypes d'images
int AmigaSYS_OpenDataTypes( void ){
int Success = 0;
DataTypesBase = IExec->OpenLibrary( "datatypes.library", 52 );
if ( DataTypesBase ){
IDataTypes = ( struct DataTypesIFace *)IExec->GetInterface( DataTypesBase, "main", 1, NULL );
if ( IDataTypes != 0 ){
Success = 1;
}
}
return Success;
}
void AmigaSYS_CloseDataTypes( void ){
if ( IDataTypes != 0 ){
IExec->DropInterface( ( struct Interface * )IDataTypes );
}
if ( DataTypesBase != 0 ){
IExec->CloseLibrary( DataTypesBase );
}
}
struct MyPicture * AllocPicture32( int Width, int Height ){
struct MyPicture *pt = NULL;
pt = (struct MyPicture *)IExec->AllocVec( sizeof( struct MyPicture ), MEMF_ANY|MEMF_CLEAR );
if ( pt ){
pt->Pixels = IExec->AllocVec( Width * ( Height + 1 ) * 4, MEMF_ANY );
pt->Width = Width;
pt->Height = Height;
pt->Depth = 32;
if ( pt->Pixels == NULL ){
IExec->FreeVec( pt );
pt = NULL;
}
}
return pt;
}
void FreePicture( struct MyPicture *pt ){
if ( pt ){
IExec->FreeVec( pt->Pixels );
pt->Pixels = NULL;
IExec->FreeVec( pt );
}
}
struct MyPicture * LoadPicture( APTR FileName ){
struct MyPicture *pt = NULL;
Object *dto = NULL;
ULONG nb;
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;
ULONG * AvailMethod = IDataTypes->GetDTMethods( dto );
if ( IDataTypes->FindMethod( AvailMethod, PDTM_READPIXELARRAY ) != 0 ){
bpa.MethodID = PDTM_READPIXELARRAY;
resread = IIntuition->IDoMethodA( dto, bpaptr );
}else{
printf( "Method PDTM_READPIXELARRAY not compatible with object" );
}
}else{
printf( "Impossible d'allouer de la mémoire pour la structure Picture\n" );
}
}else{
printf( "Impossible de lire les informations de l'image\n" );
}
IIntuition->DisposeObject( dto );
}else{
printf( "Echec dans le chargement du fichier\n" );
}
return pt;
}