;------------------------------------------------------- ; ; First code by Erwan Fouret (C)opyRight 1997 ; For the MethodBBLib ; ;------------------------------------------------------- ; ; New code by Xavier Nuel and Erwan Fouret ; (C)opyRight BadDolls Production 17/03/1998 ; ; DTPictureLoad V1.2 ; ; Need the MethodBBLib from Erwan Fouret (c) 1997 ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Do what you want with this code !!! ; Please, send any improvements to : ; ; erwan.fouret@wanadoo.fr ; or/and xn.baddolls@a2points.com ; ;------------------------------------------------------- ; ; Display a picture with DataType... ; ; Copy this picture in a Chunky Buffer in FAST memory... ; Then copy the picture from Fast to an usable BitMap. ; ___________________ ;; ;; ;; Affiche une image via les DataTypes... ;; ;; Controle si le datatype ouvre un bitmap Interleave ou non. ;; ;; Copie l'image dans un tampon Chunky en memoire Fast... ;; Et copie l'image depuis la Fast dans un BitMap utilisable !!! ;; ;; ; ; ;################## IMPORTANT #################### ; ; ; Include the resident 'blitzlibs:amigalibs.res' ; ; in 'Compiler->Compiler Options...' ; ; ; ;################################################# ; WBStartup NoCli WbToScreen 0 ShowScreen 0 ; ; Liste des Constantes... ; ;***** utility/tagitem.h ***** #TAG_USER=(1 LSL 31) ;***** datatypes/datatypesclass.h ***** #DTA_Dummy =(#TAG_USER+$1000) #DTA_LayoutProc=(#DTA_Dummy+27) #DTA_GroupID =(#DTA_Dummy+31) #DTA_SourceType=(#DTA_Dummy+101) #DTM_FrameBox =$601 #DTM_PROCLAYOUT=$602 #DTST_FILE =2 NEWTYPE.dimStruct Width_.l Height_.l Depth_.l End NEWTYPE NEWTYPE.FrameInfo fri_PropertyFlags.l ; /* DisplayInfo (graphics/displayinfo.h) */ fri_Resolution.Point ; /* DisplayInfo */ fri_RedBits.b fri_GreenBits.b fri_BlueBits.b fri_Dimensions.dimStruct *fri_Screen.Screen *fri_ColorMap.ColorMap fri_Flags.l End NEWTYPE NEWTYPE.dtFrameBox MethodID.l *dtf_GInfo.GadgetInfo *dtf_ContentsInfo.FrameInfo ; /* Input */ *dtf_FrameInfo.FrameInfo ; /* Output */ dtf_SizeFrameInfo.l dtf_FrameFlags.l End NEWTYPE ;***** datatypes/datatypes.h ***** NEWTYPE.DataTypeHeader *dth_Name.b *dth_BaseName.b *dth_Pattern.b *dth_Mask.w dth_GroupID.l dth_ID.l dth_MaskLen.w dth_Pad.w dth_Flags.w dth_Priority.w End NEWTYPE NEWTYPE.DataType dtn_Node1.Node dtn_Node2.Node *dtn_Header.DataTypeHeader dtn_ToolList.List *dtn_FunctionName.b *dtn_AttrList.TagItem dtn_Length.l End NEWTYPE #DTF_TYPE_MASK=$000F #GID_PICTURE=$70696374 #DTMSG_TYPE_OFFSET=2100 ;***** datatypes/pictureclass.h **** NEWTYPE.BitMapHeader bmh_Width.w bmh_Height.w bmh_Left.w bmh_Top.w bmh_Depth.b bmh_Masking.b bmh_Compression.b bmh_Pad.b bmh_Transparent.w bmh_XAspect.b bmh_YAspect.b bmh_PageWidth.w bmh_PageHeight.w End NEWTYPE #PDTA_ModeID =(#DTA_Dummy+200) #PDTA_BitMapHeader =(#DTA_Dummy+201) #PDTA_BitMap =(#DTA_Dummy+202) #PDTA_ColorRegisters =(#DTA_Dummy+203) #PDTA_CRegs =(#DTA_Dummy+204) #PDTA_NumColors =(#DTA_Dummy+209) #PDTA_Remap =(#DTA_Dummy+211) ; ; List of DefType... ; DEFTYPE.BitMapHeader *bmhd DEFTYPE.l *cregs,numcolors,ModeID DEFTYPE.dtFrameBox dtf DEFTYPE.FrameInfo fri DEFTYPE.gpLayout gpl DEFTYPE.Screen *scr DEFTYPE.BitMap *bm DEFTYPE.DataTypeHeader *dth DEFTYPE.DataType *dtn Dim attrs.TagItem(15) Dim scrtag.TagItem(15) Window 1,0,0,WBWidth,250,$100F,"DTPictureLoad V1.2 (C)BadDolls Production",1,2 CatchDosErrs .Begin ; ; TagList ; attrs(1)\ti_Tag = #DTA_SourceType,#DTST_FILE attrs(2)\ti_Tag = #DTA_GroupID,#GID_PICTURE attrs(3)\ti_Tag = #PDTA_Remap,0 attrs(4)\ti_Tag = #TAG_DONE,0 ; ; Open FileRequester... ; Use Window 1 name$=RTEZLoadFile("Charger une image",GetFileName(name$)) If name$="" Free Window 1 End EndIf If Exists(name$)=0 Err$="What's your file ?!!?" Gosub ErrHandler Goto Begin EndIf InnerCls 0 WLocate 0,0 Print name$,":" NPrint "" NPrint "" ; ; Get info from the Datatype Header ; lock.l=Lock_(&name$,#ACCESS_READ) If lock=0 Err$="Enable to lock the file..."+Chr$(10) Gosub ErrHandler Goto Begin EndIf *dtn=ObtainDataTypeA_(#DTST_FILE,lock,0) If *dtn=0 Err$="Enable to read the header..." UnLock_ lock Gosub ErrHandler Goto Begin EndIf *dth=*dtn\dtn_Header MaxLen buff$=6 ; ; Print the localised string... ; NPrint "Description: ",Peek$(*dth\dth_Name) NPrint " Base name: ",Peek$(*dth\dth_BaseName) NPrint " Type: ",Peek$(GetDTString_((*dth\dth_Flags & #DTF_TYPE_MASK) + #DTMSG_TYPE_OFFSET)) NPrint " Group: ",Peek$(GetDTString_(*dth\dth_GroupID)) NPrint " ID: ",Peek$(IDtoStr_(*dth\dth_ID,&buff$)) ; ; Check if GroupID is 'pict' (UnLocalized string) ; GroupID$=Left$(Peek$(&*dth\dth_GroupID),4) UnLock_ lock If GroupID$<>"pict" Err$= name$+" isn't a picture..." ReleaseDataType_ *dtn Gosub ErrHandler Goto Begin EndIf NPrint "" NPrint "Please wait while decoding picture..." ; ; Create the DataType Object ; *obj.b=NewDTObjectA_(&name$,attrs(1)) If *obj=0 Err$="Error when creating the DT Object..." Gosub ErrHandler Goto Begin EndIf dtf\MethodID=#DTM_FrameBox dtf\dtf_ContentsInfo=&fri,&fri,SizeOf.FrameInfo DoMethodA *obj,&dtf gpl\MethodID=#DTM_PROCLAYOUT gpl\gpl_GInfo=0 gpl\gpl_Initial=1 DoMethodA *obj,&gpl GetAttr_ #PDTA_ModeID,*obj,&ModeID GetAttr_ #PDTA_CRegs,*obj,&*cregs GetAttr_ #PDTA_NumColors,*obj,&numcolors GetAttr_ #PDTA_BitMapHeader,*obj,&*bmhd GetAttr_ #PDTA_BitMap,*obj,&*bm Wbtm.w=*bmhd\bmh_Width Hbtm.w=*bmhd\bmh_Height Dbtm.b=*bmhd\bmh_Depth NPrint "" NPrint " ModeID: ",ModeID NPrint " Btm Width: ",Wbtm NPrint " Btm Height: ",Hbtm NPrint " Btm Depth: ",Dbtm NPrint " Nb Colors: ",numcolors ReleaseDataType_ *dtn NPrint "" ; ; Init the Palette and store the RGB values... ; InitPalette 0,numcolors For i.l=0 To numcolors-1 j.l=i*12 j+*cregs r.l=Peek.b(j ) MOD 256 g.l=Peek.b(j+4) MOD 256 b.l=Peek.b(j+8) MOD 256 AGAPalRGB 0,i,r,g,b Next ; ;------------------------------------------------------- ; ; Now, we'll make a STANDARD USABLE Bitmap ;-) ; ; I hope there are enough comments... ; ; ; 1/ Allocate the Rastports ; NPrint "... Allocate RastPorts" *TempRast.RastPort=AllocMem_(SizeOf.RastPort,#MEMF_ANY|#MEMF_CLEAR) *TempRst2.RastPort=AllocMem_(SizeOf.RastPort,#MEMF_ANY|#MEMF_CLEAR) If *TempRast=0 OR *TempRst2=0 Err$="Not enough MEM for allocate a RastPort" DisposeDTObject_ *obj Gosub ErrHandler Goto Begin EndIf ; ; 2/ Init the RastPort and Set its BitMap ; InitRastPort_ *TempRast InitRastPort_ *TempRst2 *bm2=AllocBitMap_(((Wbtm+15) LSL 4) LSR 1,1,Dbtm,#BMF_CLEAR,0) *TempRst2\Layer=0 *TempRst2\_BitMap=*bm2 *TempRast\_BitMap=*bm ; ; 3/ Allocate a Chunky Buffer in Fast :-) ; NPrint "... Allocate Chunky Buffer in FAST mem" SizeFast.l=(((Wbtm+15) LSL 4) LSR 4)*Hbtm *FastChunky.l=AllocMem_(SizeFast,#MEMF_FAST|#MEMF_CLEAR) If *FastChunky=0 Err$="Not enough FAST mem for allocate a Chunky Buffer" DisposeDTObject_ *obj FreeMem_ *TempRast,SizeOf.RastPort FreeMem_ *TempRst2,SizeOf.RastPort Gosub ErrHandler Goto Begin EndIf ; ; 4/ Write the Chunky Buffer ; NPrint "... Write the Chunky Buffer" Count.l=ReadPixelArray8_(*TempRast,0,0,Wbtm-1,Hbtm-1,*FastChunky,*TempRst2) DisposeDTObject_ *obj ; ; 5/ Open a Standard BitMap ; NPrint "... Open a Standard BitMap" MemNeed.l=(Wbtm*Hbtm*Dbtm) LSR 3 If ChipFree