2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
6 /* Supported Attributes (Init (new), Set, Get)
9 ..G struct BitMapHeader bmhd;
10 ISG struct BitMap *SrcBM;
11 ISG struct BitMap *ClassBM;
13 ..G struct BitMap *DestBM;
15 IS. struct Screen *DestScreen;
16 ..G struct ColorRegister ColMap[256];
17 ..G UBYTE ColTable[256];
18 ..G UBYTE ColTable2[256];
22 I.. UBYTE SparseTable[256];
35 #include <exec/types.h>
36 #include <exec/memory.h>
37 #include <dos/dostags.h>
38 #include <graphics/gfxbase.h>
39 #include <graphics/rpattr.h>
40 #include <intuition/imageclass.h>
41 #include <intuition/icclass.h>
42 #include <intuition/gadgetclass.h>
43 #include <intuition/cghooks.h>
44 #include <datatypes/datatypesclass.h>
45 #include <datatypes/pictureclass.h>
46 #include <cybergraphx/cybergraphics.h>
48 #include <clib/alib_protos.h>
49 #include <proto/exec.h>
50 #include <proto/dos.h>
51 #include <proto/intuition.h>
52 #include <proto/graphics.h>
53 #include <proto/utility.h>
54 #include <proto/iffparse.h>
55 #include <proto/layers.h>
56 #include <proto/datatypes.h>
57 #include <proto/cybergraphics.h>
60 #include "compilerspecific.h"
68 #include "pictureclass.h"
70 #include "colorhandling.h"
79 /**************************************************************************************************/
81 const IPTR SupportedMethods
[] =
104 // DTM_CLEARSELECTED,
109 PDTM_WRITEPIXELARRAY
,
116 /**************************************************************************************************/
118 STATIC IPTR
DT_SetMethod(struct IClass
*cl
, struct Gadget
*g
, struct opSet
*msg
);
120 /**************************************************************************************************/
122 IPTR
NotifyAttrChanges(Object
* o
, VOID
* ginfo
, ULONG flags
, Tag tag1
, ...)
124 AROS_SLOWSTACKTAGS_PRE(tag1
)
125 retval
= DoMethod(o
, OM_NOTIFY
, AROS_SLOWSTACKTAGS_ARG(tag1
), (IPTR
) ginfo
, flags
);
126 AROS_SLOWSTACKTAGS_POST
129 /**************************************************************************************************/
131 STATIC
struct Gadget
*DT_NewMethod(struct IClass
*cl
, Object
*o
, struct opSet
*msg
)
134 struct TagItem
*attrs
= msg
->ops_AttrList
;
136 struct Picture_Data
*pd
;
138 #if 0 /* DTA_SourceType is handled by subclasses */
142 sourcetype
= GetTagData(DTA_SourceType
, DTST_FILE
, attrs
);
143 handle
= GetTagData(DTA_Handle
, NULL
, attrs
);
145 if( sourcetype
== DTST_RAM
&& handle
== NULL
)
147 D(bug("picture.datatype/OM_NEW: Creating an empty object\n"));
149 else if( !(sourcetype
==DTST_CLIPBOARD
|| sourcetype
==DTST_FILE
) )
151 D(bug("picture.datatype/OM_NEW: wrong DTA_SourceType\n"));
152 SetIoErr(ERROR_OBJECT_WRONG_TYPE
);
157 g
= (struct Gadget
*) DoSuperMethodA(cl
, o
, (Msg
) msg
);
162 D(bug("picture.datatype/OM_NEW: Created object 0x%lx\n", (long)g
));
164 /* initialize our class structure with zeros (or FALSE for BOOL's) */
165 pd
= (struct Picture_Data
*) INST_DATA(cl
, g
);
166 memset(pd
, 0, sizeof(struct Picture_Data
));
168 /* initialize some non-zero values */
169 pd
->Precision
= PRECISION_IMAGE
;
170 pd
->ModeID
= INVALID_ID
;
172 pd
->SrcPixelFormat
= -1;
173 pd
->DitherQuality
= 0;
175 pd
->DestMode
= 1; /* needs to be changed to FALSE after Multiview adaptation */
177 /* Prefs overrides default, but application overrides Prefs */
179 while((ti
=NextTagItem(&attrs
)))
184 pd
->Precision
= (ULONG
) ti
->ti_Data
;
185 DGS(bug("picture.datatype/OM_NEW: Tag ID OBP_Precision: %ld\n", (long)pd
->Precision
));
189 pd
->Remap
= (BOOL
) ti
->ti_Data
;
190 DGS(bug("picture.datatype/OM_NEW: Tag ID PDTA_Remap: %ld\n", (long)pd
->Remap
));
194 pd
->NumSparse
= (UWORD
) ti
->ti_Data
;
195 DGS(bug("picture.datatype/OM_NEW: Tag ID PDTA_NumSparse: %ld\n", (long)pd
->NumSparse
));
198 case PDTA_SparseTable
:
199 DGS(bug("picture.datatype/OM_NEW: Tag ID PDTA_SparseTable\n"));
200 if(!(pd
->NumSparse
&& ti
->ti_Data
))
204 CopyMem((APTR
) ti
->ti_Data
, (APTR
) pd
->SparseTable
, pd
->NumSparse
);
210 pd
->DelayRead
= (BOOL
) ti
->ti_Data
;
211 DGS(bug("picture.datatype/OM_NEW: Tag ID PDTA_DelayRead: %ld\n", (long)pd
->DelayRead
));
217 D(bug("picture.datatype/OM_NEW: Setting attributes\n"));
218 DT_SetMethod(cl
, g
, msg
);
223 /**************************************************************************************************/
225 STATIC IPTR
DT_DisposeMethod(struct IClass
*cl
, Object
*o
, Msg msg
)
227 struct Picture_Data
*pd
;
232 pd
= (struct Picture_Data
*) INST_DATA(cl
, o
);
240 RetVal
+= DoSuperMethodA(cl
, o
, msg
);
245 /**************************************************************************************************/
247 STATIC IPTR
DT_SetMethod(struct IClass
*cl
, struct Gadget
*g
, struct opSet
*msg
)
249 struct Picture_Data
*pd
;
250 struct TagItem
*tl
= msg
->ops_AttrList
;
255 pd
=(struct Picture_Data
*) INST_DATA(cl
, g
);
258 while((ti
=NextTagItem(&tl
)))
262 case DTA_VisibleHoriz
:
263 case DTA_VisibleVert
:
268 pd
->ModeID
= (ULONG
) ti
->ti_Data
;
269 DGS(bug("picture.datatype/OM_SET: Tag PDTA_ModeID: 0x%lx\n", (long)pd
->ModeID
));
272 case PDTA_ClassBitMap
:
273 pd
->KeepSrcBM
= TRUE
;
274 DGS(bug("picture.datatype/OM_GET: Tag PDTA_ClassBitMap: Handled as PDTA_BitMap\n"));
276 pd
->SrcBM
= (struct BitMap
*) ti
->ti_Data
;
277 DGS(bug("picture.datatype/OM_SET: Tag PDTA_BitMap: 0x%lx\n", (long)pd
->SrcBM
));
281 pd
->DestScreen
= (struct Screen
*) ti
->ti_Data
;
282 DGS(bug("picture.datatype/OM_SET: Tag PDTA_Screen: 0x%lx\n", (long)pd
->DestScreen
));
286 pd
->NumColors
= (UWORD
) ti
->ti_Data
;
287 DGS(bug("picture.datatype/OM_SET: Tag PDTA_NumColors: %ld\n", (long)pd
->NumColors
));
294 DGS(bug("picture.datatype/OM_SET: Tag PDTA_Grab\n"));
295 ThePoint
= (Point
*) ti
->ti_Data
;
300 pd
->Grab
.x
= ThePoint
->x
;
301 pd
->Grab
.y
= ThePoint
->y
;
305 case PDTA_SourceMode
:
306 DGS(bug("picture.datatype/OM_SET: Tag PDTA_SourceMode (ignored): %ld\n", (long)ti
->ti_Data
));
310 pd
->DestMode
= (BOOL
) ti
->ti_Data
;
311 DGS(bug("picture.datatype/OM_SET: Tag PDTA_DestMode: %ld\n", (long)pd
->DestMode
));
314 case PDTA_FreeSourceBitMap
:
315 pd
->FreeSource
= (BOOL
) ti
->ti_Data
;
316 DGS(bug("picture.datatype/OM_SET: Tag PDTA_FreeSourceBitMap: %ld\n", (long)pd
->FreeSource
));
319 case PDTA_UseFriendBitMap
:
320 pd
->UseFriendBM
= (BOOL
) ti
->ti_Data
;
321 DGS(bug("picture.datatype/OM_SET: Tag PDTA_UseFriendBitMap: %ld\n", (long)pd
->UseFriendBM
));
324 case PDTA_MaxDitherPens
:
325 pd
->MaxDitherPens
= (UWORD
) ti
->ti_Data
;
326 DGS(bug("picture.datatype/OM_SET: Tag PDTA_MaxDitherPens: %ld\n", (long)pd
->MaxDitherPens
));
329 case PDTA_DitherQuality
:
330 pd
->DitherQuality
= (UWORD
) ti
->ti_Data
;
331 DGS(bug("picture.datatype/OM_SET: Tag PDTA_DitherQuality: %ld\n", (long)pd
->DitherQuality
));
334 case PDTA_ScaleQuality
:
335 pd
->ScaleQuality
= (UWORD
) ti
->ti_Data
;
336 DGS(bug("picture.datatype/OM_SET: Tag PDTA_ScaleQuality: %ld\n", (long)pd
->ScaleQuality
));
340 pd
->Remap
= (BOOL
) ti
->ti_Data
;
341 DGS(bug("picture.datatype/OM_SET: Tag ID PDTA_Remap: %ld\n", (long)pd
->Remap
));
345 case PDTA_DelayedRead
:
346 pd
->DelayedRead
= (BOOL
) ti
->ti_Data
;
347 DGS(bug("picture.datatype/OM_SET: Tag PDTA_DelayedRead: %ld\n", (long)pd
->DelayedRead
));
359 for(i
=0; i
<NumAttribs
; i
++)
361 if(ti
->ti_Tag
==KnownAttribs
[i
])
365 DGS(bug("picture.datatype/OM_SET: Tag %s: 0x%lx (%ld)\n", AttribNames
[i
], (long)ti
->ti_Data
, (long)ti
->ti_Data
));
371 DGS(bug("picture.datatype/OM_SET: Tag ID 0x%lx: 0x%lx\n", (long)ti
->ti_Tag
, (long)ti
->ti_Data
));
381 DoMethod((Object
*) g
, GM_LAYOUT
, msg
->ops_GInfo
, TRUE
);
385 /* Do not call the SuperMethod if you come from OM_NEW! */
386 if(!(msg
->MethodID
== OM_NEW
))
388 RetVal
+= (IPTR
) DoSuperMethodA(cl
, (Object
*) g
, (Msg
) msg
);
396 if(OCLASS((Object
*) g
) == cl
)
399 rp
=ObtainGIRPort(msg
->ops_GInfo
);
402 DoMethod((Object
*) g
, GM_RENDER
, (IPTR
) msg
->ops_GInfo
, (IPTR
) rp
, GREDRAW_UPDATE
);
407 #if 0 /* stegerg: ?? */
408 if(msg
->MethodID
== OM_UPDATE
)
410 DoMethod((Object
*) g
, OM_NOTIFY
, msg
->ops_AttrList
, msg
->ops_GInfo
, 0);
418 /**************************************************************************************************/
420 STATIC IPTR
DT_GetMethod(struct IClass
*cl
, struct Gadget
*g
, struct opGet
*msg
)
422 struct Picture_Data
*pd
;
424 pd
=(struct Picture_Data
*) INST_DATA(cl
, g
);
426 switch(msg
->opg_AttrID
)
429 DGS(bug("picture.datatype/OM_GET: Tag PDTA_ModeID: 0x%lx\n", (long)pd
->ModeID
));
430 *(msg
->opg_Storage
)=pd
->ModeID
;
433 case PDTA_BitMapHeader
:
434 DGS(bug("picture.datatype/OM_GET: Tag PDTA_BitMapHeader: 0x%lx\n", (long)&pd
->bmhd
));
435 *(msg
->opg_Storage
)=(IPTR
) &pd
->bmhd
;
438 case PDTA_ClassBitMap
:
439 DGS(bug("picture.datatype/OM_GET: Tag PDTA_ClassBitMap: Handled as PDTA_BitMap\n"));
442 ConvertChunky2Bitmap( pd
);
443 DGS(bug("picture.datatype/OM_GET: Tag PDTA_BitMap: 0x%lx\n", (long)pd
->SrcBM
));
444 *(msg
->opg_Storage
)=(IPTR
) pd
->SrcBM
;
447 case PDTA_DestBitMap
:
448 DGS(bug("picture.datatype/OM_GET: Tag PDTA_DestBitMap: 0x%lx\n", (long)pd
->DestBM
));
449 *(msg
->opg_Storage
)=(IPTR
) pd
->DestBM
;
453 CreateMaskPlane( pd
);
454 DGS(bug("picture.datatype/OM_GET: Tag PDTA_MaskPlane: 0x%lx\n", (long)pd
->MaskPlane
));
455 *(msg
->opg_Storage
)=(IPTR
) pd
->MaskPlane
;
459 DGS(bug("picture.datatype/OM_GET: Tag PDTA_Screen: 0x%lx\n", (long)pd
->DestScreen
));
460 *(msg
->opg_Storage
)=(IPTR
) pd
->DestScreen
;
463 case PDTA_ColorRegisters
:
464 DGS(bug("picture.datatype/OM_GET: Tag PDTA_ColorRegisters: 0x%lx\n", (long)&pd
->ColMap
));
465 *(msg
->opg_Storage
)=(IPTR
) &pd
->ColMap
;
469 DGS(bug("picture.datatype/OM_GET: Tag PDTA_CRegs: 0x%lx\n", (long)&pd
->SrcColRegs
));
470 *(msg
->opg_Storage
)=(IPTR
) &pd
->SrcColRegs
;
474 DGS(bug("picture.datatype/OM_GET: Tag PDTA_GRegs: 0x%lx\n", (long)&pd
->DestColRegs
));
475 *(msg
->opg_Storage
)=(IPTR
) &pd
->DestColRegs
;
478 case PDTA_AllocatedPens
:
479 DGS(bug("picture.datatype/OM_GET: Tag PDTA_AllocatedPens: Handled by PDTA_ColorTable2\n"));
480 case PDTA_ColorTable2
:
481 DGS(bug("picture.datatype/OM_GET: Tag PDTA_ColorTable2: Handled by PDTA_ColorTable\n"));
482 case PDTA_ColorTable
:
483 DGS(bug("picture.datatype/OM_GET: Tag PDTA_ColorTable: 0x%lx\n", (long)&pd
->ColTable
));
484 *(msg
->opg_Storage
)=(IPTR
) &pd
->ColTable
;
488 DGS(bug("picture.datatype/OM_GET: Tag PDTA_NumColors: %ld\n", (long)pd
->NumColors
));
489 *(msg
->opg_Storage
)=(IPTR
) pd
->NumColors
;
493 DGS(bug("picture.datatype/OM_GET: Tag PDTA_NumAlloc: %ld\n", (long)pd
->NumAlloc
));
494 *(msg
->opg_Storage
)=(IPTR
) pd
->NumAlloc
;
498 DGS(bug("picture.datatype/OM_GET: Tag PDTA_Grab: 0x%lx\n", (long)&pd
->Grab
));
499 *(msg
->opg_Storage
)=(IPTR
) &pd
->Grab
;
502 case PDTA_SourceMode
:
503 DGS(bug("picture.datatype/OM_GET: Tag PDTA_SourceMode: 0x%lx\n", (long)PMODE_V43
));
504 *(msg
->opg_Storage
)=(IPTR
) PMODE_V43
;
508 DGS(bug("picture.datatype/OM_GET: Tag PDTA_DestMode: 0x%lx\n", (long)pd
->DestMode
));
509 *(msg
->opg_Storage
)=(IPTR
) pd
->DestMode
;
512 case PDTA_FreeSourceBitMap
:
513 DGS(bug("picture.datatype/OM_GET: Tag PDTA_FreeSourceBitMap: 0x%lx\n", (long)pd
->FreeSource
));
514 *(msg
->opg_Storage
)=(IPTR
) pd
->FreeSource
;
517 case PDTA_UseFriendBitMap
:
518 DGS(bug("picture.datatype/OM_GET: Tag PDTA_UseFriendBitMap: 0x%lx\n", (long)pd
->UseFriendBM
));
519 *(msg
->opg_Storage
)=(IPTR
) pd
->UseFriendBM
;
522 case PDTA_MaxDitherPens
:
523 DGS(bug("picture.datatype/OM_GET: Tag PDTA_MaxDitherPens: 0x%lx\n", (long)pd
->MaxDitherPens
));
524 *(msg
->opg_Storage
)=(IPTR
) pd
->MaxDitherPens
;
527 case PDTA_DitherQuality
:
528 DGS(bug("picture.datatype/OM_GET: Tag PDTA_DitherQuality: 0x%lx\n", (long)pd
->DitherQuality
));
529 *(msg
->opg_Storage
)=(IPTR
) pd
->DitherQuality
;
532 case PDTA_ScaleQuality
:
533 DGS(bug("picture.datatype/OM_GET: Tag PDTA_ScaleQuality: 0x%lx\n", (long)pd
->ScaleQuality
));
534 *(msg
->opg_Storage
)=(IPTR
) pd
->ScaleQuality
;
538 case PDTA_DelayedRead
:
539 DGS(bug("picture.datatype/OM_GET: Tag PDTA_DelayedRead: 0x%lx\n", (long)pd
->DelayedRead
));
540 *(msg
->opg_Storage
)=(IPTR
) pd
->DelayedRead
;
545 DGS(bug("picture.datatype/OM_GET: Tag DTA_Methods: 0x%lx\n", (long)SupportedMethods
));
546 *(msg
->opg_Storage
)=(IPTR
) SupportedMethods
;
558 for(i
=0; i
<NumAttribs
; i
++)
560 if(msg
->opg_AttrID
==KnownAttribs
[i
])
564 DGS(bug("picture.datatype/OM_GET: Tag ID: %s\n", AttribNames
[i
]));
570 DGS(bug("picture.datatype/OM_GET: Tag ID: 0x%lx\n", msg
->opg_AttrID
));
574 return(DoSuperMethodA(cl
, (Object
*) g
, (Msg
) msg
));
576 } /* switch AttrID */
580 /**************************************************************************************************/
581 static void render_on_rastport(struct Picture_Data
*pd
, struct Gadget
*g
, LONG SrcX
, LONG SrcY
, struct RastPort
* destRP
,
582 LONG DestX
, LONG DestY
, LONG SizeX
, LONG SizeY
)
585 struct BitMapHeader
* bmhd
;
587 depth
= (ULONG
) GetBitMapAttr(destRP
->BitMap
, BMA_DEPTH
);
588 GetDTAttrs((Object
*) g
, PDTA_BitMapHeader
, (IPTR
)&bmhd
, TAG_DONE
);
590 if ((depth
>= 15) && (bmhd
->bmh_Masking
== mskHasAlpha
))
592 /* Transparency on high color rast port with alpha channel in picture */
593 struct RastPort srcRP
;
594 ULONG
* img
= (ULONG
*) AllocVec(SizeX
* SizeY
* 4, MEMF_ANY
);
597 InitRastPort(&srcRP
);
598 srcRP
.BitMap
= pd
->DestBM
;
600 ReadPixelArray(img
, 0, 0, SizeX
* 4, &srcRP
, SrcX
, SrcY
, SizeX
, SizeY
, RECTFMT_ARGB
);
602 WritePixelArrayAlpha(img
, 0, 0, SizeX
* 4, destRP
, DestX
, DestY
, SizeX
, SizeY
, 0xffffffff);
608 if ((bmhd
->bmh_Masking
== mskHasMask
) || (bmhd
->bmh_Masking
== mskHasTransparentColor
))
610 /* Transparency with mask */
613 GetDTAttrs((Object
*) g
, PDTA_MaskPlane
, (IPTR
)&mask
, TAG_DONE
);
616 BltMaskBitMapRastPort(pd
->DestBM
,
629 /* All other cases */
630 BltBitMapRastPort( pd
->DestBM
,
643 /**************************************************************************************************/
645 STATIC IPTR
DT_Render(struct IClass
*cl
, struct Gadget
*g
, struct gpRender
*msg
)
647 struct Picture_Data
*pd
;
648 struct DTSpecialInfo
*si
;
651 IPTR TopVert
, TopHoriz
;
653 long SrcX
, SrcY
, DestX
, DestY
, SizeX
, SizeY
;
655 pd
= (struct Picture_Data
*) INST_DATA(cl
, g
);
656 si
= (struct DTSpecialInfo
*) g
->SpecialInfo
;
660 D(bug("picture.datatype/GM_RENDER: No layout done yet !\n"));
664 if(si
->si_Flags
& DTSIF_LAYOUT
)
666 D(bug("picture.datatype/GM_RENDER: In layout process !\n"));
670 if(!(GetDTAttrs((Object
*) g
, DTA_Domain
, (IPTR
) &domain
,
671 DTA_TopHoriz
, (IPTR
) &TopHoriz
,
672 DTA_TopVert
, (IPTR
) &TopVert
,
675 D(bug("picture.datatype/GM_RENDER: Couldn't get dimensions\n"));
679 ObtainSemaphore(&(si
->si_Lock
));
680 D(bug("picture.datatype/GM_RENDER: Domain: left %ld top %ld width %ld height %ld\n", domain
->Left
, domain
->Top
, domain
->Width
, domain
->Height
));
681 D(bug("picture.datatype/GM_RENDER: TopHoriz %ld TopVert %ld Width %ld Height %ld\n", (long)TopHoriz
, (long)TopVert
, (long)pd
->DestWidth
, (long)pd
->DestHeight
));
685 SrcX
= MIN( TopHoriz
, pd
->DestWidth
);
686 SrcY
= MIN( TopVert
, pd
->DestHeight
);
687 DestX
= domain
->Left
;
689 SizeX
= MIN( pd
->DestWidth
- SrcX
, domain
->Width
);
690 SizeY
= MIN( pd
->DestHeight
- SrcY
, domain
->Height
);
691 D(bug("picture.datatype/GM_RENDER: SizeX/Y %ld/%ld\n SrcX/Y %ld/%ld DestX/Y %ld/%ld\n",
692 SizeX
, SizeY
, SrcX
, SrcY
, DestX
, DestY
));
694 render_on_rastport(pd
, g
, SrcX
, SrcY
, msg
->gpr_RPort
, DestX
, DestY
, SizeX
, SizeY
);
698 D(bug("picture.datatype/GM_RENDER: No destination picture present !\n"));
701 ReleaseSemaphore(&(si
->si_Lock
));
706 /**************************************************************************************************/
708 STATIC IPTR
DT_GoActiveMethod(struct IClass
*cl
, struct Gadget
*g
, struct gpInput
*msg
)
710 struct DTSpecialInfo
*dtsi
= (struct DTSpecialInfo
*)g
->SpecialInfo
;
711 struct Picture_Data
*pd
= INST_DATA(cl
, g
);
712 IPTR retval
= GMR_NOREUSE
;
714 if (!AttemptSemaphore(&dtsi
->si_Lock
))
719 if (dtsi
->si_Flags
& DTSIF_DRAGSELECT
)
721 ReleaseSemaphore(&dtsi
->si_Lock
);
723 return DoSuperMethodA(cl
, (Object
*)g
, (Msg
)msg
);
725 else if (msg
->gpi_IEvent
&& !(dtsi
->si_Flags
& DTSIF_LAYOUT
))
729 GetDTAttrs((Object
*)g
, DTA_TopVert
, (IPTR
)&topv
,
730 DTA_TopHoriz
, (IPTR
)&toph
,
733 pd
->ClickX
= msg
->gpi_Mouse
.X
+ (LONG
)toph
;
734 pd
->ClickY
= msg
->gpi_Mouse
.Y
+ (LONG
)topv
;
736 retval
= GMR_MEACTIVE
;
739 ReleaseSemaphore(&dtsi
->si_Lock
);
744 STATIC IPTR
DT_HandleInputMethod(struct IClass
*cl
, struct Gadget
*g
, struct gpInput
*msg
)
746 struct DTSpecialInfo
*dtsi
= (struct DTSpecialInfo
*)g
->SpecialInfo
;
747 struct Picture_Data
*pd
= INST_DATA(cl
, g
);
748 IPTR retval
= GMR_MEACTIVE
;
750 if (!AttemptSemaphore(&dtsi
->si_Lock
))
755 if (dtsi
->si_Flags
& DTSIF_DRAGSELECT
)
757 ReleaseSemaphore(&dtsi
->si_Lock
);
758 return DoSuperMethodA(cl
, (Object
*)g
, (Msg
)msg
);
761 if (dtsi
->si_Flags
& DTSIF_LAYOUT
)
763 ReleaseSemaphore(&dtsi
->si_Lock
);
767 switch(msg
->gpi_IEvent
->ie_Class
)
769 case IECLASS_RAWMOUSE
:
770 switch(msg
->gpi_IEvent
->ie_Code
)
773 retval
= GMR_NOREUSE
;
776 case IECODE_NOBUTTON
:
778 IPTR toph
, totalh
, visibleh
;
779 IPTR topv
, totalv
, visiblev
;
780 LONG newtoph
, newtopv
;
782 GetDTAttrs((Object
*)g
, DTA_TopVert
, (IPTR
) &topv
,
783 DTA_TotalVert
, (IPTR
) &totalv
,
784 DTA_VisibleVert
, (IPTR
) &visiblev
,
785 DTA_TopHoriz
, (IPTR
) &toph
,
786 DTA_TotalHoriz
, (IPTR
) &totalh
,
787 DTA_VisibleHoriz
, (IPTR
) &visibleh
,
790 newtoph
= pd
->ClickX
- msg
->gpi_Mouse
.X
;
791 newtopv
= pd
->ClickY
- msg
->gpi_Mouse
.Y
;
793 if (newtoph
+ (LONG
)visibleh
> (LONG
)totalh
) newtoph
= (LONG
)totalh
- (LONG
)visibleh
;
794 if (newtoph
< 0) newtoph
= 0;
796 if (newtopv
+ (LONG
)visiblev
> (LONG
)totalv
) newtopv
= (LONG
)totalv
- (LONG
)visiblev
;
797 if (newtopv
< 0) newtopv
= 0;
799 if ((newtoph
!= (LONG
)toph
) || (newtopv
!= (LONG
)topv
))
801 NotifyAttrChanges((Object
*) g
, msg
->gpi_GInfo
, 0,
803 DTA_TopHoriz
, newtoph
,
804 DTA_TopVert
, newtopv
,
815 ReleaseSemaphore(&dtsi
->si_Lock
);
820 /**************************************************************************************************/
822 STATIC IPTR
DT_Layout(struct IClass
*cl
, struct Gadget
*g
, struct gpLayout
*msg
)
826 D(bug("picture.datatype/GM_LAYOUT: Initial %d\n", (int)msg
->gpl_Initial
));
827 NotifyAttrChanges((Object
*) g
, msg
->gpl_GInfo
, 0,
832 RetVal
=DoSuperMethodA(cl
, (Object
*) g
, (Msg
) msg
);
834 RetVal
+= (IPTR
) DoAsyncLayout((Object
*) g
, msg
);
839 /**************************************************************************************************/
841 STATIC IPTR
DT_AsyncLayout(struct IClass
*cl
, struct Gadget
*g
, struct gpLayout
*msg
)
843 struct Picture_Data
*pd
;
844 struct DTSpecialInfo
*si
;
845 ULONG SrcWidth
, SrcHeight
;
846 unsigned int SrcDepth
;
849 pd
= (struct Picture_Data
*) INST_DATA(cl
, g
);
850 si
= (struct DTSpecialInfo
*) g
->SpecialInfo
;
852 SrcWidth
= pd
->bmhd
.bmh_Width
;
853 SrcHeight
= pd
->bmhd
.bmh_Height
;
854 SrcDepth
= pd
->bmhd
.bmh_Depth
;
855 D(bug("picture.datatype/DTM_ASYNCLAYOUT: Source Width %ld Height %ld Depth %ld\n", SrcWidth
, SrcHeight
, (long)SrcDepth
));
856 D(bug("picture.datatype/DTM_ASYNCLAYOUT: Masking %d Transparent %d Initial %d Layouted %d\n", (int)pd
->bmhd
.bmh_Masking
, (int)pd
->bmhd
.bmh_Transparent
, (int)msg
->gpl_Initial
, (int)pd
->Layouted
));
858 if( !SrcWidth
|| !SrcHeight
|| !SrcDepth
)
860 D(bug("picture.datatype/DTM_ASYNCLAYOUT: Neccessary fields in BitMapHeader not set !\n"));
864 if( !pd
->SrcBuffer
&& !pd
->SrcBM
)
866 D(bug("picture.datatype/DTM_ASYNCLAYOUT: No source picture given !\n"));
870 ObtainSemaphore( &(si
->si_Lock
) ); /* lock object data */
873 if( msg
->gpl_Initial
| !pd
->Layouted
) /* we need to do it just once at startup or after scaling */
878 /* determine destination screen depth */
879 if( !pd
->DestScreen
&& msg
->gpl_GInfo
)
881 pd
->DestScreen
= msg
->gpl_GInfo
->gi_Screen
;
883 if( !pd
->DestScreen
)
885 D(bug("picture.datatype/DTM_ASYNCLAYOUT: No screen given !\n"));
886 ReleaseSemaphore(&si
->si_Lock
); /* unlock object data */
889 pd
->DestDepth
= GetBitMapAttr( pd
->DestScreen
->RastPort
.BitMap
, BMA_DEPTH
);
893 #if 0 // stegerg: CHECKME
894 if( pd
->SrcDepth
> 8 )
896 D(bug("picture.datatype/DTM_ASYNCLAYOUT: Remap=FALSE option only for colormapped source !\n"));
897 ReleaseSemaphore(&si
->si_Lock
); /* unlock object data */
903 D(bug("picture.datatype/DTM_ASYNCLAYOUT: Scaling doesn't work with Remap=FALSE !\n"));
904 ReleaseSemaphore(&si
->si_Lock
); /* unlock object data */
907 #if 0 // stegerg: CHECKME
908 pd
->DestScreen
= NULL
;
910 pd
->DestDepth
= SrcDepth
;
913 if( pd
->DestDepth
> 8 )
915 pd
->TrueColorDest
= TRUE
;
918 D(bug("picture.datatype/DTM_ASYNCLAYOUT: Forcing colormapped dest depth of 8 instead of %ld\n", (long)pd
->DestDepth
));
920 pd
->TrueColorDest
= FALSE
;
925 pd
->TrueColorDest
= FALSE
;
928 /* allocate destination Bitmap */
932 pd
->DestWidth
= SrcWidth
;
933 pd
->DestHeight
= SrcHeight
;
935 D(bug("picture.datatype/DTM_ASYNCLAYOUT: Destination Width %ld Height %ld Depth %ld\n", pd
->DestWidth
, pd
->DestHeight
, (long)pd
->DestDepth
));
936 if( !AllocDestBM( pd
) )
938 D(bug("picture.datatype/DTM_ASYNCLAYOUT: Didn't get dest BM !\n"));
939 ReleaseSemaphore(&si
->si_Lock
); /* unlock object data */
943 /* remap picture depending on the source/dest color case */
944 if( pd
->TrueColorSrc
)
948 D(bug("picture.datatype/DTM_ASYNCLAYOUT: Bitmap source only possible with up to 8 bits !\n"));
949 ReleaseSemaphore(&si
->si_Lock
); /* unlock object data */
952 if( pd
->TrueColorDest
)
954 success
= ConvertTC2TC( pd
);
958 success
= ConvertTC2CM( pd
);
961 else /* if(pd->TrueColorSrc) */
965 if( !ConvertBitmap2Chunky( pd
) )
967 ReleaseSemaphore(&si
->si_Lock
); /* unlock object data */
971 if( pd
->TrueColorDest
)
973 success
= ConvertCM2TC( pd
);
977 success
= ConvertCM2CM( pd
);
979 } /* else(pd->TrueColorSrc) */
981 /* free source, if asked */
984 CreateMaskPlane( pd
);
990 D(bug("picture.datatype/DTM_ASYNCLAYOUT: Initial layout done\n"));
991 } /* if( msg->gpl_Initial | !pd->Layouted ) */
993 ReleaseSemaphore( &si
->si_Lock
); /* unlock object data */
996 D(bug("picture.datatype/DTM_ASYNCLAYOUT: Layout failed during remapping !\n"));
1001 struct IBox
*domain
;
1008 if(!(GetDTAttrs((Object
*) g
, DTA_Domain
, (IPTR
) &domain
,
1009 DTA_ObjName
, (IPTR
) &Title
,
1010 DTA_NominalHoriz
, (IPTR
) &Width
,
1011 DTA_NominalVert
, (IPTR
) &Height
,
1018 si
->si_VertUnit
= 1;
1019 si
->si_VisVert
= domain
->Height
;
1020 si
->si_TotVert
= Height
;
1022 si
->si_HorizUnit
= 1;
1023 si
->si_VisHoriz
= domain
->Width
;
1024 si
->si_TotHoriz
= Width
;
1027 NotifyAttrChanges((Object
*) g
, msg
->gpl_GInfo
, 0,
1030 DTA_VisibleVert
, domain
->Height
,
1031 DTA_TotalVert
, Height
,
1032 DTA_NominalVert
, Height
,
1035 DTA_VisibleHoriz
, domain
->Width
,
1036 DTA_TotalHoriz
, Width
,
1037 DTA_NominalHoriz
, Width
,
1040 DTA_Title
, (IPTR
) Title
,
1044 D(bug("picture.datatype/DTM_ASYNCLAYOUT: NotifyAttrChanges done, Layouted %d\n", (int)pd
->Layouted
));
1049 /**************************************************************************************************/
1051 STATIC IPTR
DT_ProcLayout(struct IClass
*cl
, struct Gadget
*g
, struct gpLayout
*msg
)
1053 NotifyAttrChanges((Object
*) g
, msg
->gpl_GInfo
, 0,
1058 DoSuperMethodA(cl
, (Object
*) g
, (Msg
) msg
);
1060 return DT_AsyncLayout(cl
, g
, msg
);
1063 /**************************************************************************************************/
1065 STATIC IPTR
PDT_WritePixelArray(struct IClass
*cl
, struct Gadget
*g
, struct pdtBlitPixelArray
*msg
)
1067 struct Picture_Data
*pd
;
1072 pd
= (struct Picture_Data
*) INST_DATA(cl
, g
);
1074 /* Do some checks first */
1075 pixelformat
= (long)msg
->pbpa_PixelFormat
;
1076 if ( pixelformat
!= pd
->SrcPixelFormat
) /* This also checks for pd->SrcBuffer */
1078 if( !pd
->SrcBuffer
)
1080 /* Initial call: Set new pixel format and allocate Chunky or RGB buffer */
1083 D(bug("picture.datatype/DTM_WRITEPIXELARRAY: Not possible in bitmap mode !\n"));
1086 if( !pd
->bmhd
.bmh_Width
|| !pd
->bmhd
.bmh_Height
|| !pd
->bmhd
.bmh_Depth
)
1088 D(bug("picture.datatype/DTM_WRITEPIXELARRAY: BitMapHeader not set !\n"));
1092 switch( pixelformat
)
1095 InitGreyColTable( pd
);
1102 InitRGBColTable( pd
);
1104 pd
->TrueColorSrc
= TRUE
;
1107 InitRGBColTable( pd
);
1109 pd
->TrueColorSrc
= TRUE
;
1112 InitRGBColTable( pd
);
1114 pd
->TrueColorSrc
= TRUE
;
1117 D(bug("picture.datatype/DTM_WRITEPIXELARRAY: Unknown PixelFormat mode %d !\n", pixelformat
));
1120 if( !AllocSrcBuffer( pd
, pd
->bmhd
.bmh_Width
, pd
->bmhd
.bmh_Height
, pixelformat
, pixelbytes
) )
1122 D(bug("picture.datatype/DTM_WRITEPIXELARRAY: Initialized SrcBuffer 0x%lx, PixelFormat %ld\n", (long)pd
->SrcBuffer
, pd
->SrcPixelFormat
));
1123 D(bug("picture.datatype/DTM_WRITEPIXELARRAY: Width %ld WidthBytes %ld Height %ld\n", pd
->SrcWidth
, pd
->SrcWidthBytes
, pd
->SrcHeight
));
1125 #if 0 /* fill chunky buffer with something colorful, works only with PBPAFMT_RGB */
1126 if( pixelformat
== PBPAFMT_RGB
)
1129 long Width
= pd
->SrcWidth
;
1130 long WidthBytes
= pd
->SrcWidthBytes
;
1131 long Height
= pd
->SrcHeight
;
1133 for (y
=0; y
<Height
; y
++)
1135 for (x
=0; x
<Width
; x
++)
1137 pd
->SrcBuffer
[x
*pixelbytes
+y
*WidthBytes
+0] = x
*256/Width
;
1138 pd
->SrcBuffer
[x
*pixelbytes
+y
*WidthBytes
+1] = y
*256/Height
;
1139 pd
->SrcBuffer
[x
*pixelbytes
+y
*WidthBytes
+2] =
1140 ( (Width
-x
)*256/Width
+ (Height
-y
)*256/Height
)/2;
1147 else /* if(!pd->SrcBuffer) */
1149 D(bug("picture.datatype/DTM_WRITEPIXELARRAY: PixelFormat mismatch !\n"));
1152 } /* if(pixelformat != pd->SrcPixelFormat) */
1154 /* Copy picture data */
1159 ULONG srcwidth
, numbytes
;
1160 ULONG srcmod
, destmod
;
1162 /* Now copy the new source data to the ChunkyBuffer line by line */
1163 pixelbytes
= pd
->SrcPixelBytes
;
1164 srcmod
= msg
->pbpa_PixelArrayMod
;
1165 srcstart
= msg
->pbpa_PixelData
;
1166 srcwidth
= msg
->pbpa_Width
;
1167 destmod
= pd
->SrcWidthBytes
;
1168 deststart
= pd
->SrcBuffer
+ msg
->pbpa_Left
* pixelbytes
+ msg
->pbpa_Top
* destmod
;
1169 lines
= msg
->pbpa_Height
;
1170 numbytes
= srcwidth
* pixelbytes
;
1171 /* simply copy data */
1172 for( line
=0; line
<lines
; line
++ )
1174 // D(bug("picture.datatype/DTM_WRITEPIXELARRAY: COPY src 0x%lx dest 0x%lx bytes %ld\n", (long)srcstart, (long)deststart, numbytes));
1175 CopyMem((APTR
) srcstart
, (APTR
) deststart
, numbytes
);
1177 deststart
+= destmod
;
1181 pd
->Layouted
= FALSE
; /* re-layout required */
1185 /**************************************************************************************************/
1187 STATIC IPTR
PDT_ReadPixelArray(struct IClass
*cl
, struct Gadget
*g
, struct pdtBlitPixelArray
*msg
)
1189 struct Picture_Data
*pd
;
1194 pd
= (struct Picture_Data
*) INST_DATA(cl
, g
);
1196 /* Do some checks first */
1199 D(bug("picture.datatype/DTM_READPIXELARRAY: Wrong DestMode\n"));
1205 ConvertBitmap2Chunky(pd
);
1210 D(bug("picture.datatype/DTM_READPIXELARRAY: No source buffer\n"));
1213 pixelformat
= (long)msg
->pbpa_PixelFormat
;
1214 D(bug("picture.datatype/DTM_READPIXELARRAY: Source/Dest Pixelformat %d / %ld\n", pixelformat
, pd
->SrcPixelFormat
));
1216 if ( pixelformat
== pd
->SrcPixelFormat
)
1218 /* Copy picture data, as source pixmode = dest pixmode */
1222 long srcmod
, destmod
;
1223 long destwidth
, numbytes
;
1225 /* Now copy the new source data to the ChunkyBuffer line by line */
1226 pixelbytes
= pd
->SrcPixelBytes
;
1227 srcmod
= pd
->SrcWidthBytes
;
1228 srcstart
= pd
->SrcBuffer
+ msg
->pbpa_Left
* pixelbytes
+ msg
->pbpa_Top
* srcmod
;
1229 destmod
= msg
->pbpa_PixelArrayMod
;
1230 deststart
= msg
->pbpa_PixelData
;
1231 destwidth
= msg
->pbpa_Width
;
1232 lines
= msg
->pbpa_Height
;
1233 numbytes
= destwidth
* pixelbytes
;
1235 /* simply copy data */
1236 for( line
=0; line
<lines
; line
++ )
1238 // D(bug("picture.datatype/DTM_READPIXELARRAY: COPY src 0x%lx dest 0x%lx bytes %ld\n", (long)srcstart, (long)deststart, numbytes));
1239 CopyMem((APTR
) srcstart
, (APTR
) deststart
, numbytes
);
1241 deststart
+= destmod
;
1244 else if ( pixelformat
== PBPAFMT_RGB
|| pixelformat
== PBPAFMT_RGBA
|| pixelformat
== PBPAFMT_ARGB
)
1246 /* Copy picture data pixel by pixel (this is not fast, but compatible :-) */
1247 UBYTE r
=0, g
=0, b
=0, a
=0xff;
1254 long srcmod
, destmod
;
1257 /* Now copy the new source data to the ChunkyBuffer line by line */
1258 srcpixelformat
= pd
->SrcPixelFormat
;
1259 srcmod
= pd
->SrcWidthBytes
;
1260 srcstart
= pd
->SrcBuffer
+ msg
->pbpa_Left
* pd
->SrcPixelBytes
+ msg
->pbpa_Top
* srcmod
;
1261 destmod
= msg
->pbpa_PixelArrayMod
;
1262 deststart
= msg
->pbpa_PixelData
;
1263 colregs
= pd
->SrcColRegs
;
1265 for( line
=0; line
<msg
->pbpa_Height
; line
++ )
1268 destptr
= deststart
;
1269 for( x
=0; x
<pd
->SrcWidth
; x
++ )
1271 switch( srcpixelformat
)
1275 col
= 3 * (*srcptr
++);
1276 r
= colregs
[col
++] >> 24;
1277 g
= colregs
[col
++] >> 24;
1278 b
= colregs
[col
] >> 24;
1294 if( pixelformat
== PBPAFMT_ARGB
)
1299 if( pixelformat
== PBPAFMT_RGBA
)
1303 deststart
+= destmod
;
1308 D(bug("picture.datatype/DTM_READPIXELARRAY: Source/Dest Pixelformat mismatch (not yet supported)\n"));
1314 /**************************************************************************************************/
1316 STATIC IPTR
PDT_Scale(struct IClass
*cl
, struct Gadget
*g
, struct pdtScale
*msg
)
1318 struct Picture_Data
*pd
;
1319 ULONG xscale
, yscale
;
1320 struct DTSpecialInfo
*si
;
1322 pd
= (struct Picture_Data
*) INST_DATA(cl
, g
);
1323 si
= (struct DTSpecialInfo
*) g
->SpecialInfo
;
1325 ObtainSemaphore( &(si
->si_Lock
) ); /* lock object data */
1326 D(bug("picture.datatype/PDTM_SCALE: newwidth %ld newheight %ld flags %08lx\n", msg
->ps_NewWidth
, msg
->ps_NewHeight
, msg
->ps_Flags
));
1328 pd
->DestWidth
= msg
->ps_NewWidth
;
1329 pd
->DestHeight
= msg
->ps_NewHeight
;
1331 /* FIXME: PDT_Scale() set bmh_Width/bmh_Height to new size yes or no? */
1332 pd
->bmhd
.bmh_Width
= msg
->ps_NewWidth
;
1333 pd
->bmhd
.bmh_Height
= msg
->ps_NewHeight
;
1335 if( pd
->SrcWidth
== pd
->DestWidth
&& pd
->SrcHeight
== pd
->DestHeight
)
1340 xscale
= (pd
->SrcWidth
<< 16) / pd
->DestWidth
;
1341 yscale
= (pd
->SrcHeight
<< 16) / pd
->DestHeight
;
1343 if( msg
->ps_Flags
& PScale_KeepAspect
)
1345 xscale
= yscale
= MAX(xscale
, yscale
);
1346 pd
->DestWidth
= (pd
->SrcWidth
<< 16) / xscale
;
1347 pd
->DestHeight
= (pd
->SrcHeight
<< 16) / yscale
;
1350 pd
->XScale
= xscale
;
1351 pd
->YScale
= yscale
;
1352 D(bug("picture.datatype/PDTM_SCALE: srcwidth %ld srcheight %ld destwidth %ld destheight %ld xscale %06lx yscale %06lx\n", pd
->SrcWidth
, pd
->SrcHeight
, pd
->DestWidth
, pd
->DestHeight
, pd
->XScale
, pd
->YScale
));
1354 SetDTAttrs((Object
*) g
, NULL
, NULL
,
1355 DTA_NominalHoriz
, pd
->DestWidth
,
1356 DTA_NominalVert
, pd
->DestHeight
,
1358 pd
->Layouted
= FALSE
; /* re-layout required */
1360 ReleaseSemaphore( &si
->si_Lock
); /* unlock object data */
1364 /**************************************************************************************************/
1366 STATIC IPTR
DT_FrameBox(struct IClass
*cl
, struct Gadget
*g
, struct dtFrameBox
*msg
)
1368 struct Picture_Data
*pd
;
1369 ULONG Width
, Height
, Depth
;
1372 pd
=(struct Picture_Data
*) INST_DATA(cl
, g
);
1376 Width
=pd
->bmhd
.bmh_Width
;
1377 Height
=pd
->bmhd
.bmh_Height
;
1378 Depth
=pd
->bmhd
.bmh_Depth
;
1380 D(bug("picture.datatype/DTM_FRAMEBOX: Width %ld\n", (long) Width
));
1381 D(bug("picture.datatype/DTM_FRAMEBOX: Height %ld\n", (long) Height
));
1382 D(bug("picture.datatype/DTM_FRAMEBOX: Depth %ld\n", (long) Depth
));
1384 /* FIXME: DT_FrameBox implementation may need to be checked */
1386 /* It is not really clear/documented what's the correct thing to do
1387 here. And what effect FRAMEF_SPECIFY has *here*. The demo sources on
1388 the Amiga Dev CD 2.1 are conflicting.
1390 ClipView source on Amiga Dev CD 2.1 uses ContentsInfo and FRAMEF_SPECIFY
1391 and (!) uninitialized FrameInfo. So accessing FrameInfo here would crash.
1393 Most other sources on the Dev CD set both ContentsInfo and FrameInfo
1394 to the same struct. Without using FRAMEF_SPECIFY.
1396 Another source (Reference/Amiga_Mail_Vol2/IV-101/dtpic.c) uses FrameInfo
1397 and NULLs ContentsInfo and no FRAMEF_SPECIFY. */
1400 if(msg
->dtf_ContentsInfo
)
1402 msg
->dtf_ContentsInfo
->fri_Dimensions
.Height
= Height
;
1403 msg
->dtf_ContentsInfo
->fri_Dimensions
.Width
= Width
;
1404 msg
->dtf_ContentsInfo
->fri_Dimensions
.Depth
= Depth
;
1405 msg
->dtf_ContentsInfo
->fri_Flags
= FIF_SCROLLABLE
;
1410 if(msg
->dtf_FrameInfo
)
1412 msg
->dtf_FrameInfo
->fri_Dimensions
.Height
= Height
;
1413 msg
->dtf_FrameInfo
->fri_Dimensions
.Width
= Width
;
1414 msg
->dtf_FrameInfo
->fri_Dimensions
.Depth
= Depth
;
1415 msg
->dtf_FrameInfo
->fri_Flags
= FIF_SCROLLABLE
;
1424 /**************************************************************************************************/
1426 STATIC IPTR
DT_ObtainDrawInfo(struct IClass
*cl
, struct Gadget
*g
, struct opSet
*msg
)
1428 struct Picture_Data
*pd
;
1431 pd
= (struct Picture_Data
*) INST_DATA(cl
, g
);
1435 if( !pd
->UseAsImage
)
1437 RetVal
= DoMethod( (Object
*)g
, DTM_PROCLAYOUT
, (IPTR
) NULL
, 1L );
1440 pd
->UseAsImage
= TRUE
;
1441 D(bug("picture.datatype/DTM_OBTAINDRAWINFO: Switched to image mode\n"));
1448 /**************************************************************************************************/
1450 STATIC IPTR
DT_Draw(struct IClass
*cl
, struct Gadget
*g
, struct dtDraw
*msg
)
1452 struct Picture_Data
*pd
;
1455 pd
=(struct Picture_Data
*) INST_DATA(cl
, g
);
1459 if( pd
->UseAsImage
&& pd
->DestBM
)
1461 long SrcX
, SrcY
, DestX
, DestY
, SizeX
, SizeY
;
1463 SrcX
= MIN( msg
->dtd_TopHoriz
, pd
->DestWidth
);
1464 SrcY
= MIN( msg
->dtd_TopVert
, pd
->DestHeight
);
1465 DestX
= msg
->dtd_Left
;
1466 DestY
= msg
->dtd_Top
;
1467 SizeX
= MIN( pd
->DestWidth
- SrcX
, msg
->dtd_Width
);
1468 SizeY
= MIN( pd
->DestHeight
- SrcY
, msg
->dtd_Height
);
1469 D(bug("picture.datatype/DTM_DRAW: SizeX/Y %ld/%ld SrcX/Y %ld/%ld DestX/Y %ld/%ld\n",
1470 SizeX
, SizeY
, SrcX
, SrcY
, DestX
, DestY
));
1472 render_on_rastport(pd
, g
, SrcX
, SrcY
, msg
->dtd_RPort
, DestX
, DestY
, SizeX
, SizeY
);
1473 D(bug("picture.datatype/DTM_DRAW: Switched to image mode\n"));
1480 /**************************************************************************************************/
1482 STATIC IPTR
DT_Print(struct IClass
*cl
, Object
*o
, struct dtPrint
*msg
)
1485 struct IODRPReq
*pio
= &msg
->dtp_PIO
->iodrp
;
1486 struct RastPort
*rp
= NULL
;
1487 struct TagItem
*tag
, *tags
= msg
->dtp_AttrList
;
1488 IPTR w
= 0, h
= 0, th
= 0, tw
= 0;
1489 struct GadgetInfo
*gi
= msg
->dtp_GInfo
;
1491 GetDTAttrs(o
, DTA_NominalHoriz
, &w
, DTA_NominalVert
, &h
, TAG_DONE
);
1492 GetDTAttrs(o
, DTA_TopHoriz
, &tw
, DTA_TopVert
, &th
, TAG_DONE
);
1494 if (w
== 0 || h
== 0)
1497 RetVal
= PDERR_CANCEL
;
1499 pio
->io_Command
= PRD_DUMPRPORT
;
1502 pio
->io_SrcWidth
= w
;
1503 pio
->io_SrcHeight
= h
;
1504 pio
->io_DestCols
= 0;
1505 pio
->io_DestRows
= 0;
1506 pio
->io_Special
= 0;
1508 while ((tag
= NextTagItem(&tags
))) {
1509 switch (tag
->ti_Tag
) {
1510 case DTA_DestCols
: pio
->io_DestCols
= (LONG
)tag
->ti_Data
; break;
1511 case DTA_DestRows
: pio
->io_DestRows
= (LONG
)tag
->ti_Data
; break;
1512 case DTA_RastPort
: rp
= (struct RastPort
*)tag
->ti_Data
; break;
1513 case DTA_Special
: pio
->io_Special
= (UWORD
)tag
->ti_Data
; break;
1517 tags
= msg
->dtp_AttrList
;
1520 /* Print from supplied (non colormap) rastport */
1521 D(bug("%s: Print from RastPort %p\n", __func__
, rp
));
1522 pio
->io_RastPort
= rp
;
1523 pio
->io_ColorMap
= NULL
;
1524 pio
->io_Modes
= INVALID_ID
;
1525 RetVal
= DoIO((struct IORequest
*)pio
);
1527 /* Print as Gadget */
1530 D(bug("%s: Print from Gadget %p on Screen %p\n", __func__
, gi
, gi
->gi_Screen
));
1531 if ((s
= gi
->gi_Screen
)) {
1532 if ((pio
->io_Modes
= GetVPModeID(&s
->ViewPort
)) != INVALID_ID
) {
1533 pio
->io_ColorMap
= s
->ViewPort
.ColorMap
;
1534 if ((pio
->io_RastPort
= ObtainGIRPort(gi
))) {
1535 RetVal
= DoIO((struct IORequest
*)pio
);
1536 ReleaseGIRPort(pio
->io_RastPort
);
1538 D(bug("%s: Can't obtain GI RastPort\n", __func__
));
1541 D(bug("%s: No valid Screen mode\n", __func__
));
1545 /* Print as a 24-bit color image */
1546 struct RastPort baseRP
;
1549 D(bug("%s: Printing as image\n", __func__
));
1553 pio
->io_ColorMap
= NULL
;
1554 pio
->io_Modes
= INVALID_ID
;
1555 pio
->io_RastPort
= rp
;
1557 /* Maybe we should do strip printing to save memory?
1559 * Too bad native AOS's PostScript driver doesn't
1562 * Well, if 24 bit color fails, try 12 bit (4096 color),
1563 * and if that fails, just do black & white.
1565 if ((bm
= AllocBitMap(w
, h
, 24, 0, NULL
)) ||
1566 (bm
= AllocBitMap(w
, h
, 12, 0, NULL
)) ||
1567 (bm
= AllocBitMap(w
, h
, 1, 0, NULL
))) {
1568 struct Layer_Info
*li
;
1570 D(bug("%s: Printing with Depth %d bitmap\n", __func__
, GetBitMapAttr(bm
, BMA_DEPTH
)));
1571 if ((li
= NewLayerInfo())) {
1572 struct Layer
*layer
;
1573 if ((layer
= CreateUpfrontLayer(li
, bm
, 0, 0, w
, h
, 0, NULL
))) {
1576 if ((drawInfo
= ObtainDTDrawInfo(o
, tags
))) {
1577 if (DrawDTObject(rp
, o
, 0, 0, w
, h
, th
, tw
, tags
)) {
1578 RetVal
= DoIO((struct IORequest
*)pio
);
1580 D(bug("%s: Can't draw object to printer RastPort\n", __func__
));
1582 ReleaseDTDrawInfo(o
, drawInfo
);
1584 D(bug("%s: Can't obtain DTDrawInfo\n", __func__
));
1586 DeleteLayer(0, layer
);
1588 D(bug("%s: Can't allocate %dx%d layer\n", __func__
, w
, h
));
1590 DisposeLayerInfo(li
);
1592 D(bug("%s: Can't allocate LayerInfo\n", __func__
));
1596 D(bug("%s: Can't allocate a bitmap\n", __func__
));
1603 /**************************************************************************************************/
1605 STATIC IPTR
DT_Write(struct IClass
*cl
, Object
*o
, struct dtWrite
*msg
)
1607 bug("picture.datatype/DTM_Write fh %d mode %d\n", msg
->dtw_FileHandle
, msg
->dtw_Mode
);
1608 if (msg
->dtw_FileHandle
== BNULL
)
1610 // Multiview calls DTM_Write with NULL filehandle to check
1611 // if RAW mode is supported.
1615 bug("picture.datatype/DTM_Write not implemented\n");
1620 /**************************************************************************************************/
1622 STATIC IPTR
DT_ReleaseDrawInfo(struct IClass
*cl
, struct Gadget
*g
, struct dtReleaseDrawInfo
*msg
)
1624 struct Picture_Data
*pd
;
1627 pd
= (struct Picture_Data
*) INST_DATA(cl
, g
);
1631 if( pd
->UseAsImage
)
1633 pd
->UseAsImage
= FALSE
;
1640 /**************************************************************************************************/
1643 ASM ULONG
DT_Dispatcher(register __a0
struct IClass
*cl
, register __a2 Object
*o
, register __a1 Msg msg
)
1651 #endif /* MYDEBUG */
1653 putreg(REG_A4
, (long) cl
->cl_Dispatcher
.h_SubEntry
); /* Small Data */
1657 switch(msg
->MethodID
)
1661 D(bug("picture.datatype/DT_Dispatcher: Method OM_NEW\n"));
1662 RetVal
=(IPTR
) DT_NewMethod(cl
, o
, (struct opSet
*) msg
);
1668 // DGS(bug("picture.datatype/DT_Dispatcher: Method OM_GET\n"));
1669 RetVal
=(IPTR
) DT_GetMethod(cl
, (struct Gadget
*) o
, (struct opGet
*) msg
);
1676 DGS(bug("picture.datatype/DT_Dispatcher: Method %s\n", (msg
->MethodID
==OM_UPDATE
) ? "OM_UPDATE" : "OM_SET"));
1677 RetVal
=(IPTR
) DT_SetMethod(cl
, (struct Gadget
*) o
, (struct opSet
*) msg
);
1683 D(bug("picture.datatype/DT_Dispatcher: Method OM_DISPOSE\n"));
1684 RetVal
=(IPTR
) DT_DisposeMethod(cl
, o
, (Msg
) msg
);
1690 D(bug("picture.datatype/DT_Dispatcher: Method GM_LAYOUT\n"));
1691 RetVal
=(IPTR
) DT_Layout(cl
, (struct Gadget
*) o
, (struct gpLayout
*) msg
);
1697 D(bug("picture.datatype/DT_Dispatcher: Method GM_GOACTIVE\n"));
1698 RetVal
= DT_GoActiveMethod(cl
, (struct Gadget
*)o
, (struct gpInput
*)msg
);
1702 case GM_HANDLEINPUT
:
1704 D(bug("picture.datatype/DT_Dispatcher: Method GM_HANDLEINPUT\n"));
1705 RetVal
= DT_HandleInputMethod(cl
, (struct Gadget
*)o
, (struct gpInput
*)msg
);
1709 case DTM_PROCLAYOUT
:
1711 D(bug("picture.datatype/DT_Dispatcher: Method DTM_PROCLAYOUT\n"));
1712 RetVal
=(IPTR
) DT_ProcLayout(cl
, (struct Gadget
*) o
, (struct gpLayout
*) msg
);
1716 case DTM_ASYNCLAYOUT
:
1718 D(bug("picture.datatype/DT_Dispatcher: Method DTM_ASYNCLAYOUT\n"));
1719 RetVal
=(IPTR
) DT_AsyncLayout(cl
, (struct Gadget
*) o
, (struct gpLayout
*) msg
);
1725 D(bug("picture.datatype/DT_Dispatcher: Method GM_RENDER\n"));
1726 RetVal
=(IPTR
) DT_Render(cl
, (struct Gadget
*) o
, (struct gpRender
*) msg
);
1732 D(bug("picture.datatype/DT_Dispatcher: Method DTM_FRAMEBOX\n"));
1733 RetVal
=(IPTR
) DT_FrameBox(cl
, (struct Gadget
*) o
, (struct dtFrameBox
*) msg
);
1737 case DTM_OBTAINDRAWINFO
:
1739 D(bug("picture.datatype/DT_Dispatcher: Method DTM_OBTAINDRAWINFO\n"));
1740 RetVal
=(IPTR
) DT_ObtainDrawInfo(cl
, (struct Gadget
*) o
, (struct opSet
*) msg
);
1746 D(bug("picture.datatype/DT_Dispatcher: Method DTM_PRINT\n"));
1747 RetVal
=(IPTR
) DT_Print(cl
, o
, (struct dtPrint
*) msg
);
1753 D(bug("picture.datatype/DT_Dispatcher: Method DTM_DRAW\n"));
1754 RetVal
=(IPTR
) DT_Draw(cl
, (struct Gadget
*) o
, (struct dtDraw
*) msg
);
1758 case DTM_RELEASEDRAWINFO
:
1760 D(bug("picture.datatype/DT_Dispatcher: Method DTM_RELEASEDRAWINFO\n"));
1761 RetVal
=(IPTR
) DT_ReleaseDrawInfo(cl
, (struct Gadget
*) o
, (struct dtReleaseDrawInfo
*) msg
);
1765 case PDTM_WRITEPIXELARRAY
:
1767 // D(bug("picture.datatype/DT_Dispatcher: Method PDTM_WRITEPIXELARRAY\n"));
1768 RetVal
=(IPTR
) PDT_WritePixelArray(cl
, (struct Gadget
*) o
, (struct pdtBlitPixelArray
*) msg
);
1772 case PDTM_READPIXELARRAY
:
1774 // D(bug("picture.datatype/DT_Dispatcher: Method PDTM_READPIXELARRAY\n"));
1775 RetVal
=(IPTR
) PDT_ReadPixelArray(cl
, (struct Gadget
*) o
, (struct pdtBlitPixelArray
*) msg
);
1781 D(bug("picture.datatype/DT_Dispatcher: Method PDTM_SCALE\n"));
1782 RetVal
=(IPTR
) PDT_Scale(cl
, (struct Gadget
*) o
, (struct pdtScale
*) msg
);
1789 for(i
=0; i
<NumMethods
; i
++)
1791 if(msg
->MethodID
==KnownMethods
[i
])
1795 D(bug("picture.datatype/DT_Dispatcher: Method %s\n", MethodNames
[i
]));
1801 D(bug("picture.datatype/DT_Dispatcher: Method 0x%lx\n", (unsigned long) msg
->MethodID
));
1803 #endif /* MYDEBUG */
1804 RetVal
=DoSuperMethodA(cl
, o
, (Msg
) msg
);
1812 /**************************************************************************************************/
1814 struct IClass
*DT_MakeClass(struct Library
*picturebase
)
1816 struct IClass
*cl
= MakeClass("picture.datatype", DATATYPESCLASS
, NULL
, sizeof(struct Picture_Data
), 0);
1820 cl
->cl_Dispatcher
.h_Entry
= (HOOKFUNC
) DT_Dispatcher
;
1821 cl
->cl_Dispatcher
.h_SubEntry
= (HOOKFUNC
) getreg(REG_A4
);
1822 cl
->cl_UserData
= (IPTR
) picturebase
; /* Required by datatypes */
1827 #endif /* !__AROS__ */
1829 /**************************************************************************************************/