xref: /reactos/win32ss/gdi/diblib/DibLib_BitBlt.h (revision 40462c92)
1 
2 #if __USES_SOLID_BRUSH
3 #undef __USES_PATTERN
4 #define __USES_PATTERN 0
5 #endif
6 
7 #define _DibFunction __DIB_FUNCTION_NAME(__FUNCTIONNAME, _SOURCE_BPP, _DEST_BPP)
8 #define _ReadPixel(bpp, pj, jShift) __PASTE(_ReadPixel_, bpp)(pj, jShift)
9 #define _WritePixel(pj, jShift, c) __PASTE(_WritePixel_, _DEST_BPP)(pj, jShift, c)
10 #define _NextPixel(bpp, ppj, pjShift) __PASTE(_NextPixel_, bpp)(ppj, pjShift)
11 #define _SHIFT(bpp, x) __PASTE(_SHIFT_, bpp)(x)
12 #define _CALCSHIFT(bpp, pshift, x) __PASTE(_CALCSHIFT_, bpp)(pshift, x)
13 
14 #if (__PASTE(_DibFunction, _manual) != 1)
15 
16 VOID
17 FASTCALL
18 _DibFunction(PBLTDATA pBltData)
19 {
20     ULONG cRows, cLines, ulDest;
21     PBYTE pjDest, pjDestBase;
22     _SHIFT(_DEST_BPP, BYTE jDstShift;)
23 #if __USES_MASK
24     PBYTE pjMask, pjMaskBase;
25     BYTE jMaskBit, jMskShift;
26 #endif
27 #if __USES_SOURCE
28     PBYTE pjSource, pjSrcBase;
29     ULONG ulSource;
30     _SHIFT(_SOURCE_BPP, BYTE jSrcShift;)
31 #endif
32 #if __USES_PATTERN
33     PBYTE pjPattern, pjPatBase;
34     ULONG ulPattern, cPatRows, cPatLines;
35     _SHIFT(_DEST_BPP, BYTE jPatShift;)
36 #endif
37 #if __USES_SOLID_BRUSH
38     ULONG ulPattern = pBltData->ulSolidColor;
39 #endif
40 
41 #if __USES_MASK
42     pjMaskBase = pBltData->siMsk.pjBase;
43 #endif
44 #if __USES_PATTERN
45     pjPatBase = pBltData->siPat.pjBase;
46     pjPatBase += pBltData->siPat.ptOrig.y * pBltData->siPat.lDelta;
47     cPatLines = pBltData->ulPatHeight - pBltData->siPat.ptOrig.y;
48 #endif
49     pjDestBase = pBltData->siDst.pjBase;
50 #if __USES_SOURCE
51     pjSrcBase = pBltData->siSrc.pjBase;
52 #endif
53 
54     /* Loop all lines */
55     cLines = pBltData->ulHeight;
56     while (cLines--)
57     {
58         /* Set current bit pointers and shifts */
59         pjDest = pjDestBase;
60         _CALCSHIFT(_DEST_BPP, &jDstShift, pBltData->siDst.ptOrig.x);
61 #if __USES_SOURCE
62         pjSource = pjSrcBase;
63         _CALCSHIFT(_SOURCE_BPP, &jSrcShift, pBltData->siSrc.ptOrig.x);
64 #endif
65 #if __USES_MASK
66         pjMask = pjMaskBase;
67         _CALCSHIFT_1(&jMskShift, pBltData->siMsk.ptOrig.x);
68 #endif
69 #if __USES_PATTERN
70         pjPattern = pjPatBase + pBltData->siPat.ptOrig.x * _DEST_BPP / 8;
71         _CALCSHIFT(_DEST_BPP, &jPatShift, pBltData->siPat.ptOrig.x);
72         cPatRows = pBltData->ulPatWidth - pBltData->siPat.ptOrig.x;
73 #endif
74 
75         /* Loop all rows */
76         cRows = pBltData->ulWidth;
77         while (cRows--)
78         {
79 #if __USES_MASK
80             /* Read the mask color and go to the next mask pixel */
81             jMaskBit = _ReadPixel_1(pjMask, jMskShift);
82             _NextPixel(1, &pjMask, &jMskShift);
83 #endif
84 #if __USES_PATTERN
85             /* Read the pattern color and go to the next pattern pixel */
86             ulPattern = _ReadPixel(_DEST_BPP, pjPattern, jPatShift);
87             _NextPixel(_DEST_BPP, &pjPattern, &jPatShift);
88 
89             /* Check if this was the last pixel in the pattern */
90             if (--cPatRows == 0)
91             {
92                 /* Restart pattern from x = 0 */
93                 pjPattern = pjPatBase;
94                 _SHIFT(_DEST_BPP, jPatShift = (_DEST_BPP == 1) ? 7 : 4;)
95                 cPatRows = pBltData->ulPatWidth;
96             }
97 #endif
98 #if __USES_SOURCE
99             /* Read the pattern color, xlate it and go to the next pixel */
100             ulSource = _ReadPixel(_SOURCE_BPP, pjSource, jSrcShift);
101             ulSource = _DibXlate(pBltData, ulSource);
102             _NextPixel(_SOURCE_BPP, &pjSource, &jSrcShift);
103 #endif
104 #if __USES_DEST
105             ulDest = _ReadPixel(_DEST_BPP, pjDest, jDstShift);
106 #endif
107             /* Apply the ROP operation on the colors */
108             ulDest = _DibDoRop(pBltData, jMaskBit, ulDest, ulSource, ulPattern);
109 
110             /* Write the pixel and go to the next dest pixel */
111             _WritePixel(pjDest, jDstShift, ulDest);
112             _NextPixel(_DEST_BPP, &pjDest, &jDstShift);
113         }
114 
115         pjDestBase += pBltData->siDst.cjAdvanceY;
116 #if __USES_SOURCE
117         pjSrcBase += pBltData->siSrc.cjAdvanceY;
118 #endif
119 #if __USES_PATTERN
120         /* Go to the next pattern line */
121         pjPatBase += pBltData->siPat.cjAdvanceY;
122 
123         /* Check if this was the last line in the pattern */
124         if (--cPatLines == 0)
125         {
126             /* Restart pattern from y = 0 */
127             pjPatBase = pBltData->siPat.pjBase;
128             cPatLines = pBltData->ulPatHeight;
129         }
130 #endif
131     }
132 }
133 
134 #endif // manual
135 
136 #undef _DibFunction
137 #undef __FUNCTIONNAME2
138