website logo
Auteur
avatar
AmiDARK

Forum » » Création-Développement » » [AOS4] [Sample] - Utiliser les datatypes d'images


Posté : 01-09-2010 23:10 icone du post

1. Utiliser AmigaSYS_OpenDataTypes(); au commencement de votre programme pour ouvrir la DataType.library et l'interface
2. Utiliser AmigaSYS_CloseDataTypes(); à la fin de votre programme pour fermer l'interface et la librairie DataTypes.

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 );
}
}


3. Ce code génère automatiquement une image en 32 bits ( RGBA )
Utiliser directement LoadPicture( APTR FileName ); pour charger une image en mémoire en tant que buffer RGBA qui peut être utilisée par exemple pour créer une texture sous MiniGL :p

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;
}


Ce code fonctionne parfaitement chez moi avec l'Amiga OS 4.1u2. Corto, tu peux l'ajouter en tutorial là où tu as déjà les tutoriaux pour les DataTypes :p

@ +
AmiDARK.

Message édité par : AmiDARK / 02-09-2010 13:15

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