6 * Smart replacement for graphics.library/BltMaskBitMapRastPort
7 * Copyright © 1997 by Olaf Barthel, All Rights Reserved
9 * Compile with (SAS/C 6.58):
11 * sc link nostartup data=faronly strmerge nostkchk
12 * nodebug opttime optimize bmbmrp.c
15 #include <graphics/rastport.h>
16 #include <hardware/blit.h>
17 #include <utility/hooks.h>
19 #include <proto/graphics.h>
20 #include <proto/layers.h>
22 #include "CompilerSpecific.h"
24 /****************************************************************************/
26 #define MINTERM_B_EQUALS_C (ABC|ANBNC|NABC|NANBNC)
27 #define NUM_ELEMENTS(t) (sizeof(t) / sizeof(t[0]))
29 /******************************************************************************/
34 struct Rectangle Bounds
;
42 struct BitMap MaskBitMap
;
43 struct BitMap
* SrcBitMap
;
48 struct Library
* GfxBase
;
51 /* This routine is called for every single clipping
52 * region in the destination RastPort.
56 REG(a0
, struct Hook
* Hook
),
57 REG(a1
, struct LayerMsg
* Bounds
),
58 REG(a2
, struct RastPort
* RPort
) )
60 struct Library
* GfxBase
;
61 struct BltArgs
* Args
;
67 GfxBase
= Args
->GfxBase
;
72 /* If this is a layered RastPort, adjust for the
75 if(Bounds
->Layer
!= NULL
)
77 SrcX
+= Bounds
->OffsetX
- Args
->DstX
;
78 SrcY
+= Bounds
->OffsetY
- Args
->DstY
;
81 /* Calculate position and size of the
82 * rectangle to fill in.
84 DstX
= Bounds
->Bounds
.MinX
;
85 DstY
= Bounds
->Bounds
.MinY
;
86 SizeX
= Bounds
->Bounds
.MaxX
- Bounds
->Bounds
.MinX
+ 1;
87 SizeY
= Bounds
->Bounds
.MaxY
- Bounds
->Bounds
.MinY
+ 1;
89 BltBitMap( Args
->SrcBitMap
, SrcX
,SrcY
,RPort
->BitMap
,DstX
,DstY
,SizeX
,SizeY
,MINTERM_B_EQUALS_C
,RPort
->Mask
,NULL
);
90 BltBitMap(&Args
->MaskBitMap
,SrcX
,SrcY
,RPort
->BitMap
,DstX
,DstY
,SizeX
,SizeY
,Args
->MinTerm
, RPort
->Mask
,NULL
);
91 BltBitMap( Args
->SrcBitMap
, SrcX
,SrcY
,RPort
->BitMap
,DstX
,DstY
,SizeX
,SizeY
,MINTERM_B_EQUALS_C
,RPort
->Mask
,NULL
);
95 NewBltMaskBitMapRastPort(
96 struct BitMap
* srcbm
,
99 struct RastPort
* destrp
,
106 struct Library
* GfxBase
,
107 struct Library
* LayersBase
)
109 if( ! ( GetBitMapAttr( destrp
->BitMap
, BMA_FLAGS
) & BMF_INTERLEAVED
) )
111 BltMaskBitMapRastPort(srcbm
, srcx
, srcy
, destrp
, destx
,desty
, sizex
,sizey
, minterm
,bltmask
);
115 /* Valid parameters? */
116 if(srcbm
!= NULL
&& destrp
!= NULL
&& bltmask
!= NULL
&& sizex
> 0 && sizey
> 0)
118 struct Rectangle Bounds
;
122 /* Set up the hook and copy most parameters to
125 Args
.Hook
.h_Entry
= (HOOKFUNC
)FillRoutine
;
126 Args
.Hook
.h_Data
= &Args
;
127 Args
.SrcBitMap
= srcbm
;
132 Args
.MinTerm
= minterm
;
133 Args
.GfxBase
= GfxBase
;
135 /* Initialize the mask bitmap. */
136 Depth
= GetBitMapAttr(srcbm
,BMA_DEPTH
);
137 if(Depth
> NUM_ELEMENTS(Args
.MaskBitMap
.Planes
))
138 Depth
= NUM_ELEMENTS(Args
.MaskBitMap
.Planes
);
140 /* Set the mask bitmap up to match the size and
141 * dimensions of the source bitmap.
143 bzero((char*)&Args
.MaskBitMap
,sizeof( struct BitMap
) );
144 InitBitMap(&Args
.MaskBitMap
,Depth
,
145 GetBitMapAttr(srcbm
,BMA_WIDTH
),
146 GetBitMapAttr(srcbm
,BMA_HEIGHT
));
148 for(i
= 0 ; i
< Depth
; i
++)
149 Args
.MaskBitMap
.Planes
[i
] = bltmask
;
151 /* Restrict blitter operations to the given rectangle. */
153 Bounds
.MaxX
= destx
+ sizex
- 1;
155 Bounds
.MaxY
= desty
+ sizey
- 1;
157 /* Do the blitter operation. */
158 DoHookClipRects(&Args
.Hook
,destrp
,&Bounds
);
162 /****************************************************************************/