Minor fixes to comments.
[AROS.git] / rom / graphics / bltrastportbitmap.c
blob1fda09d3ccc6d34f87751b49e8ca02a3a3076887
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Blit the content of a rastport into a bitmap
6 Lang: english
7 */
9 #include <aros/debug.h>
10 #include <proto/graphics.h>
12 #include "graphics_intern.h"
13 #include "gfxfuncsupport.h"
15 void BltRastPortBitMap(struct RastPort *srcRastPort, WORD xSrc, WORD ySrc,
16 struct BitMap *destBitMap, WORD xDest, WORD yDest,
17 WORD xSize, WORD ySize, ULONG minterm,
18 struct GfxBase *GfxBase)
20 struct Layer * srcLayer;
22 FIX_GFXCOORD(xSrc);
23 FIX_GFXCOORD(ySrc);
24 FIX_GFXCOORD(xDest);
25 FIX_GFXCOORD(yDest);
27 if (NULL == (srcLayer = srcRastPort->Layer)) {
29 * Rastport without a layer is a screen.
31 BltBitMap(srcRastPort->BitMap,
32 xSrc,
33 ySrc,
34 destBitMap,
35 xDest,
36 yDest,
37 xSize,
38 ySize,
39 minterm,
40 ~0,
41 NULL);
42 } else {
43 struct BitMap * srcBM = srcRastPort->BitMap;
44 struct ClipRect * srcCR;
45 int area = xSize * ySize;
46 UBYTE useminterm = 0;
47 ULONG bltMask = 0xFFFFFFFF;
49 LockLayerRom(srcLayer);
50 srcCR = srcLayer->ClipRect;
52 while (NULL != srcCR &&
53 area > 0) {
55 * Is the current cliprect withing the
56 * required region?
58 WORD crX0, crX1, crY0, crY1;
59 /* cr?? have to be coordinates related to the rastport */
60 crX0 = srcCR->bounds.MinX - srcLayer->bounds.MinX;
61 crX1 = srcCR->bounds.MaxX - srcLayer->bounds.MinX;
62 crY0 = srcCR->bounds.MinY - srcLayer->bounds.MinY;
63 crY1 = srcCR->bounds.MaxY - srcLayer->bounds.MinY;
65 /* the only case that must not happen is that
66 this ClipRect is outside the source area. */
68 if (!(crX0 > (xSrc+xSize-1) ||
69 crX1 < xSrc ||
70 crY0 > (ySrc+ySize-1) ||
71 crY1 < ySrc)) {
72 WORD MinX, MinY;
73 WORD bltSrcX, bltSrcY, bltDestX, bltDestY, bltWidth, bltHeight;
74 WORD SrcOffsetX;
76 /* this cliprect contains bitmap data that need to be copied */
77 /*
78 * get the pointer to the bitmap structure and fill out
79 * the rectangle structure that shows which part we mean to copy
81 if (NULL != srcCR->BitMap) {
82 if (0 == (srcLayer->Flags & LAYERSUPER)) {
83 /* no superbitmap */
84 SrcOffsetX = ALIGN_OFFSET(srcCR->bounds.MinX);
86 if (xSrc >= crX0) {
87 bltSrcX = xSrc - crX0 + SrcOffsetX;
88 bltDestX = 0;
89 } else {
90 bltSrcX = SrcOffsetX;
91 bltDestX = crX0 - xSrc;
94 if (ySrc > crY0) {
95 bltSrcY = ySrc - crY0;
96 bltDestY = 0;
97 } else {
98 bltSrcY = 0;
99 bltDestY = crY0 - ySrc;
102 srcBM = srcCR->BitMap;
103 } else {
104 /* with superbitmap */
105 if (xSrc >= crX0) {
106 bltSrcX = xSrc - srcLayer->Scroll_X;
107 bltDestX = 0;
108 } else {
109 bltSrcX = crX0 - srcLayer->Scroll_X;
110 bltDestX = crX0 - xSrc;
113 if (ySrc >= crY0) {
114 bltSrcY = ySrc - srcLayer->Scroll_Y;
115 bltDestY = 0;
116 } else {
117 bltSrcY = crY0 - srcLayer->Scroll_Y;
118 bltDestY = crY0 - ySrc;
121 srcBM = srcCR->BitMap;
124 } else {
125 /* this part of the layer is not hidden. */
126 /* The source bitmap is the bitmap of the rastport */
127 srcBM = srcRastPort->BitMap;
129 /* xSrc and ySrc are relative to the rastport of the window
130 * or layer - here we have to make them absolute to the
131 * screen's rastport
134 if (xSrc <= crX0) {
135 bltSrcX = srcCR->bounds.MinX;
136 bltDestX = crX0 - xSrc;
137 } else {
138 bltSrcX = xSrc + srcLayer->bounds.MinX;
139 bltDestX = 0;
142 if (ySrc <= crY0) {
143 bltSrcY = srcCR->bounds.MinY;
144 bltDestY = crY0 - ySrc;
145 } else {
146 bltSrcY = ySrc + srcLayer->bounds.MinY;
147 bltDestY = 0;
151 if (crX0 > xSrc)
152 MinX = crX0 - xSrc;
153 else
154 MinX = 0;
156 if (crX1 < (xSrc+xSize-1))
157 bltWidth = crX1 - xSrc - MinX + 1;
158 else
159 bltWidth = xSize - 1 - MinX + 1;
161 if (crY0 > ySrc)
162 MinY = crY0 - ySrc;
163 else
164 MinY = 0;
166 if (crY1 < (ySrc+ySize-1))
167 bltHeight = crY1 - ySrc - MinY + 1;
168 else
169 bltHeight = ySize - 1 - MinY + 1;
171 if ((0 != (srcLayer->Flags & LAYERSIMPLE) &&
172 (NULL != srcCR->lobs ||
173 0 != (srcCR->Flags & CR_NEEDS_NO_CONCEALED_RASTERS))))
174 useminterm = 0x0; /* clear this area in the destination */
175 else
176 useminterm = minterm;
180 * Finally blit from the srcBM to the
181 * destBM
183 BltBitMap(srcBM,
184 bltSrcX,
185 bltSrcY,
186 destBitMap,
187 bltDestX,
188 bltDestY,
189 bltWidth,
190 bltHeight,
191 useminterm,
192 bltMask,
193 NULL);
194 area -= (bltWidth * bltHeight);
196 srcCR = srcCR->Next;
198 UnlockLayerRom(srcLayer);
200 ReturnVoid("BltRastPortBitMap");