[WIN32SS]
[reactos.git] / reactos / subsystems / win32 / win32k / diblib / DibLib_BitBlt.h
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 pjPattern = pjPatBase + pBltData->siPat.ptOrig.x * _DEST_BPP / 8;
48 _CALCSHIFT(_DEST_BPP, &jPatShift, pBltData->siPat.ptOrig.x);
49 cPatLines = pBltData->ulPatHeight - pBltData->siPat.ptOrig.y;
50 cPatRows = pBltData->ulPatWidth - pBltData->siPat.ptOrig.x;
51 #endif
52 pjDestBase = pBltData->siDst.pjBase;
53 #if __USES_SOURCE
54 pjSrcBase = pBltData->siSrc.pjBase;
55 #endif
56
57 /* Loop all lines */
58 cLines = pBltData->ulHeight;
59 while (cLines--)
60 {
61 /* Set current bit pointers and shifts */
62 pjDest = pjDestBase;
63 _CALCSHIFT(_DEST_BPP, &jDstShift, pBltData->siDst.ptOrig.x);
64 #if __USES_SOURCE
65 pjSource = pjSrcBase;
66 _CALCSHIFT(_SOURCE_BPP, &jSrcShift, pBltData->siSrc.ptOrig.x);
67 #endif
68 #if __USES_MASK
69 pjMask = pjMaskBase;
70 _CALCSHIFT_1(&jMskShift, pBltData->siMsk.ptOrig.x);
71 #endif
72
73 /* Loop all rows */
74 cRows = pBltData->ulWidth;
75 while (cRows--)
76 {
77 #if __USES_MASK
78 /* Read the mask color and go to the next mask pixel */
79 jMaskBit = _ReadPixel_1(pjMask, jMskShift);
80 _NextPixel(1, &pjMask, &jMskShift);
81 #endif
82 #if __USES_PATTERN
83 /* Read the pattern color and go to the next pattern pixel */
84 ulPattern = _ReadPixel(_DEST_BPP, pjPattern, jPatShift);
85 _NextPixel(_DEST_BPP, &pjPattern, &jPatShift);
86
87 /* Check if this was the last pixel in the pattern */
88 if (--cPatRows == 0)
89 {
90 /* Restart pattern from x = 0 */
91 pjPattern = pjPatBase;
92 _SHIFT(_DEST_BPP, jPatShift = (_DEST_BPP == 1) ? 7 : 4;)
93 cPatRows = pBltData->ulPatWidth;
94 }
95 #endif
96 #if __USES_SOURCE
97 /* Read the pattern color, xlate it and go to the next pixel */
98 ulSource = _ReadPixel(_SOURCE_BPP, pjSource, jSrcShift);
99 ulSource = _DibXlate(pBltData, ulSource);
100 _NextPixel(_SOURCE_BPP, &pjSource, &jSrcShift);
101 #endif
102 #if __USES_DEST
103 ulDest = _ReadPixel(_DEST_BPP, pjDest, jDstShift);
104 #endif
105 /* Apply the ROP operation on the colors */
106 ulDest = _DibDoRop(pBltData, jMaskBit, ulDest, ulSource, ulPattern);
107
108 /* Write the pixel and go to the next dest pixel */
109 _WritePixel(pjDest, jDstShift, ulDest);
110 _NextPixel(_DEST_BPP, &pjDest, &jDstShift);
111 }
112
113 pjDestBase += pBltData->siDst.cjAdvanceY;
114 #if __USES_SOURCE
115 pjSrcBase += pBltData->siSrc.cjAdvanceY;
116 #endif
117 #if __USES_PATTERN
118 /* Go to the next pattern line */
119 pjPatBase += pBltData->siPat.cjAdvanceY;
120
121 /* Check if this was the last line in the pattern */
122 if (--cPatLines == 0)
123 {
124 /* Restart pattern from y = 0 */
125 pjPatBase = pBltData->siPat.pjBase;
126 cPatLines = pBltData->ulPatHeight;
127 }
128 #endif
129 }
130 }
131
132 #endif // manual
133
134 #undef _DibFunction
135 #undef __FUNCTIONNAME2