Can someone help me to understand how I can use the datatypes.library to open/load images & sounds in memory and recognize them (to know what it is, ex jpg, bmp, png, raw, iff, mp3, wav, ogg, etc ...)
Thank you to all peoples that helped me for DataTYPES.
Here is the functions that now work perfectly under Amiga OS 4.1u2: (Corto, you can put it in your tutorial page if you want)
@freddix You might have more luck on utilitybase.com althought datatypes are a bit of a black art, due to lack of documentation (your best bet is finding some code that does what you want).
DataTypesBase=(struct Library *)IExec->OpenLibrary("datatypes.library",52); if (DataTypesBase!=0) { IDataTypes=(struct DataTypesIFace *)IExec->GetInterface(DataTypesBase,"main",1,NULL); if (IDataTypes!=0) { DTFile=IDataTypes->NewDTObject("file_name", DTA_GroupID,GID_PICTURE, PDTA_DestMode,PMODE_V43, TAG_DONE); if (DTFile!=0) { IDataTypes->GetDTAttrs(DTFile,PDTA_BitMap,&bm,TAG_DONE); // bm points to a bitmap containing the picture if (bm!=0) { } /* if */ IDataTypes->DisposeDTObject(DTFile); DTFile=0; bm=0; } /* if */ else ; IExec->DropInterface((struct Interface *)IDataTypes); } /* if */ else printf("ERROR: Can't open datatypes main interface\n"); IExec->CloseLibrary(DataTypesBase); } /* if */ else printf("ERROR: Can't open datatypes.library v52\n");
Edited by TSK on 2010/8/27 16:18:52
Rock lobster bit me - so I'm here forever X1000 + AmigaOS 4.1 FE "Anyone can build a fast CPU. The trick is to build a fast system." - Seymour Cray
You can then open the file and handle it as per the base type dth_GroupID.
Check the AutoDocs for datatypes.library AND the AutoDocs for the base classes (picture_dtc etc) to find out how to get data out of them. If you have any more specific questions ask here or UtilityBase (UtilityBase is usually a better place for programming questions)
- load images and sounds I never tried with sounds but you can read the articles I wrote in french about pictures here on gurumed.net
- get the initial format name I don't know why (datatypes goal is to add an abstraction layer) but in my opinion, you will certainly be forced to read the header of the file and identify it manually.
I don't know why (datatypes goal is to add an abstraction layer) but in my opinion, you will certainly be forced to read the header of the file and identify it manually.
It's what I planed to do ;)
@Corto & Others : Thank you for these informations. Will check all of these tomorrow :p
Kindest Regards, AmiDARK.
All we have to decide is what to do with the time that is given to us.
IIRC, the current sound datatype can't handle anything better than 8-bit stereo sound. Someone made a new one that was much more flexible, but I don't think that it was ever adopted as standard (it's on os4depot, IIRC).
Datatypes is yet another area that could use an overhaul. Streaming data, generating thumbnails, etc., and most importantly, and easier to use API.
@Hans In fact, I took a "fast" look at what friends sent upper. I've found that Corto sample : http://www.gurumed.net/index.php/R%C3 ... ge_en_tant_que_buffer_RGB if exactly what I need ( load an image in memory ). More to this, Corto is French like me so it's easier for me to learn from this sample.
I'll keep your advice concerning audio in mind before doing any tests concerning audio.
Kindest Regards, AmiDARK.
All we have to decide is what to do with the time that is given to us.
IIRC, the current sound datatype can't handle anything better than 8-bit stereo sound.
That's not true any more, it has supported 16-bit sound since OS4.1u1.
Quote:
Datatypes is yet another area that could use an overhaul. Streaming data, generating thumbnails, etc., and most importantly, and easier to use API.
It needs a bit of an update in some areas, but nothing too major. It would be nice if more apps supported them - pictures are well supported, sounds less so, and anything else gets no support from apps whatsoever (actually NetSurf supports reading text through Datatypes in specific circumstances - first app other than Multiview that I know of able to use text datatypes). Text datatypes really do need an update - although IFF FTXT is supposed to be Formatted TeXT, there's very little formatting apparently supported, and this impacts what can be put on the clipboard too (copying a table with all the formatting intact is impossible).
IIRC, the current sound datatype can't handle anything better than 8-bit stereo sound.
That's not true any more, it has supported 16-bit sound since OS4.1u1.
Oh, I didn't know that. I'm going to have to take a closer look at that. I still have that unfinished animation datatype project sitting on my hard-drive. No time to work on it though.
(actually NetSurf supports reading text through Datatypes in specific circumstances - first app other than Multiview that I know of able to use text datatypes).
CodeBench uses the text.datatype too.
Simon
Comments made in any post are personal opinion, and are in no-way representative of any commercial entity unless specifically stated as such. ---- http://codebench.co.uk
That's not true any more, it has supported 16-bit sound since OS4.1u1.
I had no idea that there was a new sound.datatype in 4.1 update 1.
Just looked in datatypes/soundclass.h and found this: /* (UBYTE) The actual bitrate of the sample. 8, 16 or 32. New in 53.2 */ #define SDTA_BitsPerSample (SDTA_Dummy + 18)
DataTypesBase = IExec->OpenLibrary( "datatypes.library", 43 ); if ( DataTypesBase ){ dto = IDataTypes->NewDTObject( FileName, DTA_GroupID, GID_PICTURE, PDTA_DestMode, PMODE_V43, PDTA_Remap, FALSE, TAG_END ); if ( dto ){ nb = IDataTypes->GetDTAttrs( dto, PDTA_BitMapHeader, (ULONG)&bmh, TAG_END ); if( nb == 1 ){ int resread; printf( "Dimensions : %dx%dx%d\n", bmh->bmh_Width, bmh->bmh_Height, bmh->bmh_Depth ); /* Allocation de la structure Picture et du buffer m?moire */ pt = AllocPicture( bmh->bmh_Width, bmh->bmh_Height, ( 3 + Alpha ) * 8 ); if ( pt ){ bpa.MethodID = PDTM_READPIXELARRAY; bpa.pbpa_PixelData = pt->Pixels; bpa.pbpa_PixelFormat = Alpha?PBPAFMT_RGBA:PBPAFMT_RGB; bpa.pbpa_PixelArrayMod = bmh->bmh_Width * ( 3 + Alpha ); bpa.pbpa_Left = 0; bpa.pbpa_Top = 0; bpa.pbpa_Width = bmh->bmh_Width; bpa.pbpa_Height = bmh->bmh_Height; resread = IDataTypes->DoDTMethodA( dto, (Msg)&bpa ); }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" ); } IDataTypes->DisposeDTObject( dto ); }else{ printf( "Echec dans le chargement du fichier\n" ); } IExec->CloseLibrary( DataTypesBase ); }else{ printf( "Impossible d'ouvrir la datatypes.library ver 43+\n" ); } return pt; }
And when I compile, I get this error : Quote:
AmiDARK:Shared/AmigaOS4/AmigaOS_DataTypes.c: In function 'AllocPicture': AmiDARK:Shared/AmigaOS4/AmigaOS_DataTypes.c:44: warning: return from incompatible pointer type AmiDARK:Shared/AmigaOS4/AmigaOS_DataTypes.c: In function 'LoadPicture': AmiDARK:Shared/AmigaOS4/AmigaOS_DataTypes.c:77: warning: assignment from incompatible pointer type AmiDARK:Shared/AmigaOS4/AmigaOS_DataTypes.c:87: warning: dereferencing type-punned pointer will break strict-aliasing rules AmiDARK:Shared/AmigaOS4/AmigaOS_DataTypes.c:87: warning: passing argument 3 of 'IDataTypes->DoDTMethodA' from incompatible pointer type AmiDARK:Shared/AmigaOS4/AmigaOS_DataTypes.c:87: error: too few arguments to function 'IDataTypes->DoDTMethodA' AmiDARK:Shared/AmigaOS4/AmigaOS_DataTypes.c:102: warning: return from incompatible pointer type
I've checked the DoDTMethodA and it need more arg: ULONG DoDTMethodA( Object *, struct Window *, struct Requester *, Msg/Data ) Why Requester ?
AmiDARK:Shared/AmigaOS4/AmigaOS_DataTypes.c: In function 'AllocPicture': AmiDARK:Shared/AmigaOS4/AmigaOS_DataTypes.c:44: warning: return from incompatible pointer type AmiDARK:Shared/AmigaOS4/AmigaOS_DataTypes.c: In function 'LoadPicture': AmiDARK:Shared/AmigaOS4/AmigaOS_DataTypes.c:80: warning: assignment from incompatible pointer type AmiDARK:Shared/AmigaOS4/AmigaOS_DataTypes.c:90: warning: dereferencing type-punned pointer will break strict-aliasing rules AmiDARK:Shared/AmigaOS4/AmigaOS_DataTypes.c:105: warning: return from incompatible pointer type AmiDE_3D.c: At top level: AmiDARK:Shared/Sound/Sound.c:15: warning: 'DELoadSound' defined but not used AmiDARK:Shared/Sound/Sound.c:45: warning: 'DEDeleteSound' defined but not used gcc -mcrt=newlib -O3 -Wall -gstabs -DMINIGL -o AmiDE_3D.exe.debug AmiDE_3D.o -lm -lGL -lGLUT -lglpng -lpng -lz AmiDE_3D.o: In function `LoadPicture': AmiDARK:Shared/AmigaOS4/AmigaOS_DataTypes.c:69: undefined reference to `IDataTypes' AmiDARK:Shared/AmigaOS4/AmigaOS_DataTypes.c:69: undefined reference to `IDataTypes' AmiDARK:Shared/AmigaOS4/AmigaOS_DataTypes.c:74: undefined reference to `IDataTypes' AmiDARK:Shared/AmigaOS4/AmigaOS_DataTypes.c:97: undefined reference to `IDataTypes' AmiDARK:Shared/AmigaOS4/AmigaOS_DataTypes.c:90: undefined reference to `IDataTypes' make: *** [AmiDE_3D.exe] Error 1
Why ?
Regards, AmiDARK.
All we have to decide is what to do with the time that is given to us.
That will be so useful. I scan kanji , and edit them in ImageFX to remove the stroke numbers etc, and use BME to convert to dr2d to use them in pagestream. It would be very useful to view them via multiview instead of having to load them inro pagestream, or Drawstudio to view them.
Also you haven't opened the interface of the datatypes library. You have to open it too. IDataTypes is not defined and opened in your program. Check my example earlier in this thread.
You can give null to struct Requester *.
Rock lobster bit me - so I'm here forever X1000 + AmigaOS 4.1 FE "Anyone can build a fast CPU. The trick is to build a fast system." - Seymour Cray
Because it's OS3 code? I don't know where I got it, but I found the same code in my programming examples directory with OS4 specific additions to make it compile for OS4. The errors you see seem to be more related to OS4 interfaces than bugs in the code. Maybe someone else will recognize the code and tell us where the OS4 version is located.
DataTypesBase = IExec->OpenLibrary( "datatypes.library", 43 );
if ( DataTypesBase ){
IDataTypes = ( struct DataTypesIFace *)IExec->GetInterface( DataTypesBase, "main", 1, NULL );
if ( IDataTypes != 0 ){
dto = ( Object *)IDataTypes->NewDTObject( FileName, DTA_GroupID, GID_PICTURE, PDTA_DestMode, PMODE_V43, TAG_DONE );
if ( dto ){
nb = IDataTypes->GetDTAttrs( dto, PDTA_BitMapHeader, (ULONG)&bmh, TAG_DONE );
if( nb == 1 ){
int resread;
printf( "Dimensions : %dx%dx%d\n", bmh->bmh_Width, bmh->bmh_Height, bmh->bmh_Depth );
/* Allocation de la structure Picture et du buffer m?moire */
pt = AllocPicture( bmh->bmh_Width, bmh->bmh_Height, ( 3 + Alpha ) * 8 );
if ( pt ){
bpa.MethodID = PDTM_READPIXELARRAY;
bpa.pbpa_PixelData = pt->Pixels;
bpa.pbpa_PixelFormat = Alpha?PBPAFMT_RGBA:PBPAFMT_RGB;
bpa.pbpa_PixelArrayMod = bmh->bmh_Width * ( 3 + Alpha );
bpa.pbpa_Left = 0;
bpa.pbpa_Top = 0;
bpa.pbpa_Width = bmh->bmh_Width;
bpa.pbpa_Height = bmh->bmh_Height;
// resread = IDataTypes->DoDTMethodA( dto, NullWindow, NullRequester, (Msg)&bpa );
resread = IDataTypes->DoDTMethod( dto, NullStructPTR, NullStructPTR, (Msg)&bpa );
}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" );
}
IDataTypes->DisposeDTObject( dto );
}else{
printf( "Echec dans le chargement du fichier\n" );
}
}else{
printf( "Echec dans l'ouverture de l'interface DataTypes" );
}
IExec->CloseLibrary( DataTypesBase );
}else{
printf( "Impossible d'ouvrir la datatypes.library ver 43+\n" );
}
return pt;
}
And now, program compiles but I get a warning that stress me a bit. Can someone enlight this problem ?
Quote:
AmiDARK:Shared/AmigaOS4/AmigaOS_DataTypes.c: In function 'LoadPicture': AmiDARK:Shared/AmigaOS4/AmigaOS_DataTypes.c:91: warning: dereferencing type-punned pointer will break strict-aliasing rules
EDIT : More to this, as additional note.. My GCC crash at compilation 1 times on 2.. I can compile it once and then if I try to compile it again, GCC crash with an ISI error ( Instruction Storage Error ) and gream reaper ... If I do a "soft reset". it crash at 1st compilation. If I turn off and on Amiga. I can compile one and after next one crash.
All we have to decide is what to do with the time that is given to us.
Someone made a new one that was much more flexible, but I don't think that it was ever adopted as standard (it's on os4depot, IIRC).
I talked about shared objects around SDL_image, here is another example of what could be consolidated.
Quote:
Datatypes is yet another area that could use an overhaul. Streaming data, generating thumbnails, etc., and most importantly, and easier to use API.
Hans
I fully agree, I wrote articles to understand details about datatypes. I only explored pictures and it took many hours and several articles. The concept is great but the implementation suffers of legacy ...