Deleted prefs as preparation for renaming of prefs-aros
[cake.git] / workbench / classes / gadgets / colorwheel / bmbmrp.c
blobfea047d62eae7f4d11ab71e30fe742d5f167255d
1 /*
2 * $Id$
4 * :ts=4
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 /******************************************************************************/
31 struct LayerMsg
33 struct Layer * Layer;
34 struct Rectangle Bounds;
35 LONG OffsetX;
36 LONG OffsetY;
39 struct BltArgs
41 struct Hook Hook;
42 struct BitMap MaskBitMap;
43 struct BitMap * SrcBitMap;
44 WORD SrcX,SrcY;
45 WORD DstX,DstY;
46 WORD SizeX,SizeY;
47 UBYTE MinTerm;
48 struct Library * GfxBase;
51 /* This routine is called for every single clipping
52 * region in the destination RastPort.
54 STATIC VOID
55 FillRoutine(
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;
62 WORD SrcX,SrcY;
63 WORD DstX,DstY;
64 WORD SizeX,SizeY;
66 Args = Hook->h_Data;
67 GfxBase = Args->GfxBase;
69 SrcX = Args->SrcX;
70 SrcY = Args->SrcY;
72 /* If this is a layered RastPort, adjust for the
73 * region offset.
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);
94 VOID
95 NewBltMaskBitMapRastPort(
96 struct BitMap * srcbm,
97 WORD srcx,
98 WORD srcy,
99 struct RastPort * destrp,
100 WORD destx,
101 WORD desty,
102 WORD sizex,
103 WORD sizey,
104 UBYTE minterm,
105 PLANEPTR bltmask,
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);
112 return;
115 /* Valid parameters? */
116 if(srcbm != NULL && destrp != NULL && bltmask != NULL && sizex > 0 && sizey > 0)
118 struct Rectangle Bounds;
119 struct BltArgs Args;
120 LONG Depth,i;
122 /* Set up the hook and copy most parameters to
123 * temporary storage.
125 Args.Hook.h_Entry = (HOOKFUNC)FillRoutine;
126 Args.Hook.h_Data = &Args;
127 Args.SrcBitMap = srcbm;
128 Args.SrcX = srcx;
129 Args.SrcY = srcy;
130 Args.DstX = destx;
131 Args.DstY = desty;
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. */
152 Bounds.MinX = destx;
153 Bounds.MaxX = destx + sizex - 1;
154 Bounds.MinY = desty;
155 Bounds.MaxY = desty + sizey - 1;
157 /* Do the blitter operation. */
158 DoHookClipRects(&Args.Hook,destrp,&Bounds);
162 /****************************************************************************/