Some fixes.
[cake.git] / rom / graphics / bltrastportbitmap.c
blob08b01139d153bd997719a2fcd550a387c6cef9ca
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Blit the content of a rastport into a bitmap
6 Lang: english
7 */
8 #include <aros/debug.h>
9 #include <proto/graphics.h>
11 #include "graphics_intern.h"
12 #include "gfxfuncsupport.h"
14 /*****************************************************************************
16 NAME */
17 #include <clib/graphics_protos.h>
19 AROS_LH9(void, BltRastPortBitMap,
21 /* SYNOPSIS */
22 AROS_LHA(struct RastPort *, srcRastPort, A0),
23 AROS_LHA(LONG , xSrc , D0),
24 AROS_LHA(LONG , ySrc , D1),
25 AROS_LHA(struct BitMap * , destBitMap , A1),
26 AROS_LHA(LONG , xDest , D2),
27 AROS_LHA(LONG , yDest , D3),
28 AROS_LHA(ULONG , xSize , D4),
29 AROS_LHA(ULONG , ySize , D5),
30 AROS_LHA(ULONG , minterm , D6),
32 /* LOCATION */
33 struct GfxBase *, GfxBase, 196, Graphics)
35 /* FUNCTION
36 Copies the content of the rast port into the bitmap.
37 Takes cliprects into consideration.
39 INPUTS
40 srcRastPort - Copy from this RastPort.
41 xSrc, ySrc - This is the upper left corner of the area to copy.
42 destBitMap - Destination BitMap.
43 xDest, yDest - Upper left corner where to place the copy
44 xSize, ySize - The size of the area to copy
45 minterm - How to copy. See BltBitMap() for an explanation.
47 RESULT
49 NOTES
50 This functions isn't part of AmigaOS3.1
52 EXAMPLE
54 BUGS
56 SEE ALSO
58 INTERNALS
60 HISTORY
62 *****************************************************************************/
64 AROS_LIBFUNC_INIT
65 struct Layer * srcLayer;
67 FIX_GFXCOORD(xSrc);
68 FIX_GFXCOORD(ySrc);
69 FIX_GFXCOORD(xDest);
70 FIX_GFXCOORD(yDest);
72 if (NULL == (srcLayer = srcRastPort->Layer)) {
74 * Rastport without a layer is a screen.
76 BltBitMap(srcRastPort->BitMap,
77 xSrc,
78 ySrc,
79 destBitMap,
80 xDest,
81 yDest,
82 xSize,
83 ySize,
84 minterm,
85 ~0,
86 NULL);
87 } else {
88 struct BitMap * srcBM = srcRastPort->BitMap;
89 struct ClipRect * srcCR;
90 int area = xSize * ySize;
91 UBYTE useminterm = 0;
92 ULONG bltMask = 0xFFFFFFFF;
94 LockLayerRom(srcLayer);
95 srcCR = srcLayer->ClipRect;
97 while (NULL != srcCR &&
98 area > 0) {
100 * Is the current cliprect withing the
101 * required region?
103 LONG crX0, crX1, crY0, crY1;
104 /* cr?? have to be coordinates related to the rastport */
105 crX0 = srcCR->bounds.MinX - srcLayer->bounds.MinX;
106 crX1 = srcCR->bounds.MaxX - srcLayer->bounds.MinX;
107 crY0 = srcCR->bounds.MinY - srcLayer->bounds.MinY;
108 crY1 = srcCR->bounds.MaxY - srcLayer->bounds.MinY;
110 /* the only case that must not happen is that
111 this ClipRect is outside the source area. */
113 if (!(crX0 > (xSrc+xSize-1) ||
114 crX1 < xSrc ||
115 crY0 > (ySrc+ySize-1) ||
116 crY1 < ySrc)) {
117 ULONG MinX, MinY;
118 ULONG bltSrcX, bltSrcY, bltDestX, bltDestY, bltWidth, bltHeight;
119 ULONG SrcOffsetX;
121 /* this cliprect contains bitmap data that need to be copied */
123 * get the pointer to the bitmap structure and fill out
124 * the rectangle structure that shows which part we mean to copy
126 if (NULL != srcCR->BitMap) {
127 if (0 == (srcLayer->Flags & LAYERSUPER)) {
128 /* no superbitmap */
129 SrcOffsetX = ALIGN_OFFSET(srcCR->bounds.MinX);
131 if (xSrc >= crX0) {
132 bltSrcX = xSrc - crX0 + SrcOffsetX;
133 bltDestX = 0;
134 } else {
135 bltSrcX = SrcOffsetX;
136 bltDestX = crX0 - xSrc;
139 if (ySrc > crY0) {
140 bltSrcY = ySrc - crY0;
141 bltDestY = 0;
142 } else {
143 bltSrcY = 0;
144 bltDestY = crY0 - ySrc;
147 srcBM = srcCR->BitMap;
148 } else {
149 /* with superbitmap */
150 if (xSrc >= crX0) {
151 bltSrcX = xSrc - srcLayer->Scroll_X;
152 bltDestX = 0;
153 } else {
154 bltSrcX = crX0 - srcLayer->Scroll_X;
155 bltDestX = crX0 - xSrc;
158 if (ySrc >= crY0) {
159 bltSrcY = ySrc - srcLayer->Scroll_Y;
160 bltDestX = 0;
161 } else {
162 bltSrcY = crY0 - srcLayer->Scroll_Y;
163 bltDestY = crY0 - ySrc;
166 srcBM = srcCR->BitMap;
169 } else {
170 /* this part of the layer is not hidden. */
171 /* The source bitmap is the bitmap of the rastport */
172 srcBM = srcRastPort->BitMap;
174 /* xSrc and ySrc are relative to the rastport of the window
175 * or layer - here we have to make them absolute to the
176 * screen's rastport
179 if (xSrc <= crX0) {
180 bltSrcX = srcCR->bounds.MinX;
181 bltDestX = crX0 - xSrc;
182 } else {
183 bltSrcX = xSrc + srcLayer->bounds.MinX;
184 bltDestX = 0;
187 if (ySrc <= crY0) {
188 bltSrcY = srcCR->bounds.MinY;
189 bltDestY = crY0 - ySrc;
190 } else {
191 bltSrcY = ySrc + srcLayer->bounds.MinY;
192 bltDestY = 0;
196 if (crX0 > xSrc)
197 MinX = crX0 - xSrc;
198 else
199 MinX = 0;
201 if (crX1 < (xSrc+xSize-1))
202 bltWidth = crX1 - xSrc - MinX + 1;
203 else
204 bltWidth = xSize - 1 - MinX + 1;
206 if (crY0 > ySrc)
207 MinY = crY0 - ySrc;
208 else
209 MinY = 0;
211 if (crY1 < (ySrc+ySize-1))
212 bltHeight = crY1 - ySrc - MinY + 1;
213 else
214 bltHeight = ySize - 1 - MinY + 1;
216 if ((0 != (srcLayer->Flags & LAYERSIMPLE) &&
217 (NULL != srcCR->lobs ||
218 0 != (srcCR->Flags & CR_NEEDS_NO_CONCEALED_RASTERS))))
219 useminterm = 0x0; /* clear this area in the destination */
220 else
221 useminterm = minterm;
225 * Finally blit from the srcBM to the
226 * destBM
228 BltBitMap(srcBM,
229 bltSrcX,
230 bltSrcY,
231 destBitMap,
232 bltDestX,
233 bltDestY,
234 bltWidth,
235 bltHeight,
236 useminterm,
237 bltMask,
238 NULL);
239 area -= (bltWidth * bltHeight);
241 srcCR = srcCR->Next;
243 UnlockLayerRom(srcLayer);
245 ReturnVoid("BltRastPortBitMap");
247 AROS_LIBFUNC_EXIT
248 } /* BltBitMapRastPort */