- Add support for 8-bit and 32-bit displays
[reactos.git] / reactos / subsys / win32k / dib / dib8bpp.c
1 #undef WIN32_LEAN_AND_MEAN
2 #include <windows.h>
3 #include <stdlib.h>
4 #include <win32k/bitmaps.h>
5 #include <win32k/debug.h>
6 #include <debug.h>
7 #include <ddk/winddi.h>
8 #include "../eng/objects.h"
9 #include "dib.h"
10
11 VOID DIB_8BPP_PutPixel(PSURFOBJ SurfObj, LONG x, LONG y, ULONG c)
12 {
13 PBYTE byteaddr = SurfObj->pvScan0 + y * SurfObj->lDelta + x;
14
15 *byteaddr = c;
16 }
17
18 ULONG DIB_8BPP_GetPixel(PSURFOBJ SurfObj, LONG x, LONG y)
19 {
20 PBYTE byteaddr = SurfObj->pvScan0 + y * SurfObj->lDelta + x;
21
22 return (ULONG)(*byteaddr);
23 }
24
25 VOID DIB_8BPP_HLine(PSURFOBJ SurfObj, LONG x1, LONG x2, LONG y, ULONG c)
26 {
27 PBYTE byteaddr = SurfObj->pvScan0 + y * SurfObj->lDelta;
28 PBYTE addr = byteaddr + x1;
29 LONG cx = x1;
30
31 while(cx < x2) {
32 *addr = c;
33 ++addr;
34 ++cx;
35 }
36 }
37
38 VOID DIB_8BPP_VLine(PSURFOBJ SurfObj, LONG x, LONG y1, LONG y2, ULONG c)
39 {
40 PBYTE byteaddr = SurfObj->pvScan0 + y1 * SurfObj->lDelta;
41 PBYTE addr = byteaddr + x;
42 LONG lDelta = SurfObj->lDelta;
43
44 byteaddr = addr;
45 while(y1++ < y2) {
46 *addr = c;
47
48 addr += lDelta;
49 }
50 }
51
52 BOOLEAN DIB_8BPP_BitBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
53 SURFGDI *DestGDI, SURFGDI *SourceGDI,
54 PRECTL DestRect, POINTL *SourcePoint,
55 XLATEOBJ *ColorTranslation)
56 {
57 ULONG i, j, sx, sy, xColor, f1;
58 PBYTE SourceBits, DestBits, SourceLine, DestLine;
59 PBYTE SourceBits_4BPP, SourceLine_4BPP;
60
61 DestBits = DestSurf->pvScan0 + (DestRect->top * DestSurf->lDelta) + DestRect->left;
62
63 switch(SourceGDI->BitsPerPixel)
64 {
65 case 1:
66 sx = SourcePoint->x;
67 sy = SourcePoint->y;
68
69 for (j=DestRect->top; j<DestRect->bottom; j++)
70 {
71 sx = SourcePoint->x;
72 for (i=DestRect->left; i<DestRect->right; i++)
73 {
74 if(DIB_1BPP_GetPixel(SourceSurf, sx, sy) == 0)
75 {
76 DIB_8BPP_PutPixel(DestSurf, i, j, XLATEOBJ_iXlate(ColorTranslation, 0));
77 } else {
78 DIB_8BPP_PutPixel(DestSurf, i, j, XLATEOBJ_iXlate(ColorTranslation, 1));
79 }
80 sx++;
81 }
82 sy++;
83 }
84 break;
85
86 case 4:
87 SourceBits_4BPP = SourceSurf->pvScan0 + (SourcePoint->y * SourceSurf->lDelta) + (SourcePoint->x >> 1);
88
89 for (j=DestRect->top; j<DestRect->bottom; j++)
90 {
91 SourceLine_4BPP = SourceBits_4BPP;
92 sx = SourcePoint->x;
93 f1 = sx & 1;
94
95 for (i=DestRect->left; i<DestRect->right; i++)
96 {
97 xColor = XLATEOBJ_iXlate(ColorTranslation,
98 (*SourceLine_4BPP & altnotmask[sx&1]) >> (4 * (1-(sx & 1))));
99 DIB_8BPP_PutPixel(DestSurf, i, j, xColor);
100 if(f1 == 1) { SourceLine_4BPP++; f1 = 0; } else { f1 = 1; }
101 sx++;
102 }
103
104 SourceBits_4BPP += SourceSurf->lDelta;
105 }
106 break;
107
108 case 8:
109 if (NULL == ColorTranslation || 0 != (ColorTranslation->flXlate & XO_TRIVIAL))
110 {
111 SourceBits = SourceSurf->pvScan0 + (SourcePoint->y * SourceSurf->lDelta) + SourcePoint->x;
112 for (j = DestRect->top; j < DestRect->bottom; j++)
113 {
114 RtlCopyMemory(DestBits, SourceBits, DestRect->right - DestRect->left);
115 SourceBits += SourceSurf->lDelta;
116 DestBits += DestSurf->lDelta;
117 }
118 }
119 else
120 {
121 /* FIXME */
122 DPRINT1("DIB_8BPP_Bitblt: Unhandled ColorTranslation for 32 -> 32 copy");
123 return FALSE;
124 }
125 break;
126
127 case 16:
128 SourceLine = SourceSurf->pvScan0 + (SourcePoint->y * SourceSurf->lDelta) + 2 * SourcePoint->x;
129 DestLine = DestBits;
130
131 for (j = DestRect->top; j < DestRect->bottom; j++)
132 {
133 SourceBits = SourceLine;
134 DestBits = DestLine;
135
136 for (i = DestRect->left; i < DestRect->right; i++)
137 {
138 xColor = *((PWORD) SourceBits);
139 *DestBits = XLATEOBJ_iXlate(ColorTranslation, xColor);
140 SourceBits += 2;
141 DestBits += 1;
142 }
143
144 SourceLine += SourceSurf->lDelta;
145 DestLine += DestSurf->lDelta;
146 }
147 break;
148
149 case 24:
150 SourceLine = SourceSurf->pvScan0 + (SourcePoint->y * SourceSurf->lDelta) + 3 * SourcePoint->x;
151 DestLine = DestBits;
152
153 for (j = DestRect->top; j < DestRect->bottom; j++)
154 {
155 SourceBits = SourceLine;
156 DestBits = DestLine;
157
158 for (i = DestRect->left; i < DestRect->right; i++)
159 {
160 xColor = (*(SourceBits + 2) << 0x10) +
161 (*(SourceBits + 1) << 0x08) +
162 (*(SourceBits));
163 *DestBits = XLATEOBJ_iXlate(ColorTranslation, xColor);
164 SourceBits += 3;
165 DestBits += 1;
166 }
167
168 SourceLine += SourceSurf->lDelta;
169 DestLine += DestSurf->lDelta;
170 }
171 break;
172
173 case 32:
174 SourceLine = SourceSurf->pvScan0 + (SourcePoint->y * SourceSurf->lDelta) + 4 * SourcePoint->x;
175 DestLine = DestBits;
176
177 for (j = DestRect->top; j < DestRect->bottom; j++)
178 {
179 SourceBits = SourceLine;
180 DestBits = DestLine;
181
182 for (i = DestRect->left; i < DestRect->right; i++)
183 {
184 xColor = *((PDWORD) SourceBits);
185 *DestBits = XLATEOBJ_iXlate(ColorTranslation, xColor);
186 SourceBits += 4;
187 DestBits += 1;
188 }
189
190 SourceLine += SourceSurf->lDelta;
191 DestLine += DestSurf->lDelta;
192 }
193 break;
194
195 default:
196 DbgPrint("DIB_8BPP_Bitblt: Unhandled Source BPP: %u\n", SourceGDI->BitsPerPixel);
197 return FALSE;
198 }
199
200 return TRUE;
201 }