Copy msimg32
[reactos.git] / reactos / subsys / win32k / dib / dib4bpp.c
1 /*
2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id$ */
20 #include <w32k.h>
21
22 VOID
23 DIB_4BPP_PutPixel(SURFOBJ *SurfObj, LONG x, LONG y, ULONG c)
24 {
25 PBYTE addr = SurfObj->pvScan0 + (x>>1) + y * SurfObj->lDelta;
26 *addr = (*addr & notmask[x&1]) | (c << ((1-(x&1))<<2));
27 }
28
29 ULONG
30 DIB_4BPP_GetPixel(SURFOBJ *SurfObj, LONG x, LONG y)
31 {
32 PBYTE addr = SurfObj->pvScan0 + (x>>1) + y * SurfObj->lDelta;
33 return (*addr >> ((1-(x&1))<<2)) & 0x0f;
34 }
35
36 VOID
37 DIB_4BPP_HLine(SURFOBJ *SurfObj, LONG x1, LONG x2, LONG y, ULONG c)
38 {
39 PBYTE addr = SurfObj->pvScan0 + (x1>>1) + y * SurfObj->lDelta;
40 LONG cx = x1;
41
42 while(cx < x2) {
43 *addr = (*addr & notmask[x1&1]) | (c << ((1-(x1&1))<<2));
44 if((++x1 & 1) == 0)
45 ++addr;
46 ++cx;
47 }
48 }
49
50 VOID
51 DIB_4BPP_VLine(SURFOBJ *SurfObj, LONG x, LONG y1, LONG y2, ULONG c)
52 {
53 PBYTE addr = SurfObj->pvScan0;
54 int lDelta = SurfObj->lDelta;
55
56 addr += (x>>1) + y1 * lDelta;
57 while(y1++ < y2) {
58 *addr = (*addr & notmask[x&1]) | (c << ((1-(x&1))<<2));
59 addr += lDelta;
60 }
61 }
62
63 BOOLEAN
64 DIB_4BPP_BitBltSrcCopy(PBLTINFO BltInfo)
65 {
66 LONG i, j, sx, sy, f2, xColor;
67 PBYTE SourceBits_24BPP, SourceLine_24BPP;
68 PBYTE DestBits, DestLine, SourceBits_8BPP, SourceLine_8BPP;
69 PBYTE SourceBits, SourceLine;
70
71 DestBits = BltInfo->DestSurface->pvScan0 +
72 (BltInfo->DestRect.left >> 1) +
73 BltInfo->DestRect.top * BltInfo->DestSurface->lDelta;
74
75 switch (BltInfo->SourceSurface->iBitmapFormat)
76 {
77 case BMF_1BPP:
78 sx = BltInfo->SourcePoint.x;
79 sy = BltInfo->SourcePoint.y;
80
81 for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++)
82 {
83 sx = BltInfo->SourcePoint.x;
84 for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++)
85 {
86 if(DIB_1BPP_GetPixel(BltInfo->SourceSurface, sx, sy) == 0)
87 {
88 DIB_4BPP_PutPixel(BltInfo->DestSurface, i, j, XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, 0));
89 } else {
90 DIB_4BPP_PutPixel(BltInfo->DestSurface, i, j, XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, 1));
91 }
92 sx++;
93 }
94 sy++;
95 }
96 break;
97
98 case BMF_4BPP:
99 sy = BltInfo->SourcePoint.y;
100
101 for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++)
102 {
103 sx = BltInfo->SourcePoint.x;
104
105 for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++)
106 {
107 if (NULL != BltInfo->XlateSourceToDest)
108 {
109 DIB_4BPP_PutPixel(BltInfo->DestSurface, i, j, XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, DIB_4BPP_GetPixel(BltInfo->SourceSurface, sx, sy)));
110 }
111 else
112 {
113 DIB_4BPP_PutPixel(BltInfo->DestSurface, i, j, DIB_4BPP_GetPixel(BltInfo->SourceSurface, sx, sy));
114 }
115 sx++;
116 }
117 sy++;
118 }
119 break;
120
121 case BMF_8BPP:
122 SourceBits_8BPP = BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + BltInfo->SourcePoint.x;
123
124 for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++)
125 {
126 SourceLine_8BPP = SourceBits_8BPP;
127 DestLine = DestBits;
128 f2 = BltInfo->DestRect.left & 1;
129
130 for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++)
131 {
132 *DestLine = (*DestLine & notmask[f2]) |
133 ((XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, *SourceLine_8BPP)) << ((4 * (1 - f2))));
134 if(f2 == 1) { DestLine++; f2 = 0; } else { f2 = 1; }
135 SourceLine_8BPP++;
136 }
137
138 SourceBits_8BPP += BltInfo->SourceSurface->lDelta;
139 DestBits += BltInfo->DestSurface->lDelta;
140 }
141 break;
142
143 case BMF_16BPP:
144 SourceLine = BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + 2 * BltInfo->SourcePoint.x;
145 DestLine = DestBits;
146
147 for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
148 {
149 SourceBits = SourceLine;
150 DestBits = DestLine;
151 f2 = BltInfo->DestRect.left & 1;
152
153 for (i = BltInfo->DestRect.left; i < BltInfo->DestRect.right; i++)
154 {
155 xColor = *((PWORD) SourceBits);
156 *DestBits = (*DestBits & notmask[f2]) |
157 ((XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, xColor)) << ((4 * (1 - f2))));
158 if(f2 == 1) { DestBits++; f2 = 0; } else { f2 = 1; }
159 SourceBits += 2;
160 }
161
162 SourceLine += BltInfo->SourceSurface->lDelta;
163 DestLine += BltInfo->DestSurface->lDelta;
164 }
165 break;
166
167 case BMF_24BPP:
168 SourceBits_24BPP = BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + BltInfo->SourcePoint.x * 3;
169
170 for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++)
171 {
172 SourceLine_24BPP = SourceBits_24BPP;
173 DestLine = DestBits;
174 f2 = BltInfo->DestRect.left & 1;
175
176 for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++)
177 {
178 xColor = (*(SourceLine_24BPP + 2) << 0x10) +
179 (*(SourceLine_24BPP + 1) << 0x08) +
180 (*(SourceLine_24BPP));
181 *DestLine = (*DestLine & notmask[f2]) |
182 ((XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, xColor)) << ((4 * (1 - f2))));
183 if(f2 == 1) { DestLine++; f2 = 0; } else { f2 = 1; }
184 SourceLine_24BPP+=3;
185 }
186
187 SourceBits_24BPP += BltInfo->SourceSurface->lDelta;
188 DestBits += BltInfo->DestSurface->lDelta;
189 }
190 break;
191
192 case BMF_32BPP:
193 SourceLine = BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + 4 * BltInfo->SourcePoint.x;
194 DestLine = DestBits;
195
196 for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
197 {
198 SourceBits = SourceLine;
199 DestBits = DestLine;
200 f2 = BltInfo->DestRect.left & 1;
201
202 for (i = BltInfo->DestRect.left; i < BltInfo->DestRect.right; i++)
203 {
204 xColor = *((PDWORD) SourceBits);
205 *DestBits = (*DestBits & notmask[f2]) |
206 ((XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, xColor)) << ((4 * (1 - f2))));
207 if(f2 == 1) { DestBits++; f2 = 0; } else { f2 = 1; }
208 SourceBits += 4;
209 }
210
211 SourceLine += BltInfo->SourceSurface->lDelta;
212 DestLine += BltInfo->DestSurface->lDelta;
213 }
214 break;
215
216 default:
217 DbgPrint("DIB_4BPP_Bitblt: Unhandled Source BPP: %u\n", BitsPerFormat(BltInfo->SourceSurface->iBitmapFormat));
218 return FALSE;
219 }
220 return(TRUE);
221 }
222
223 BOOLEAN
224 DIB_4BPP_BitBlt(PBLTINFO BltInfo)
225 {
226 ULONG DestX, DestY;
227 ULONG SourceX, SourceY;
228 ULONG PatternY = 0;
229 ULONG Dest, Source = 0, Pattern = 0;
230 BOOLEAN UsesSource;
231 BOOLEAN UsesPattern;
232 PULONG DestBits;
233 LONG RoundedRight;
234 static const ULONG ExpandSolidColor[16] =
235 {
236 0x00000000 /* 0 */,
237 0x11111111 /* 1 */,
238 0x22222222 /* 2 */,
239 0x33333333 /* 3 */,
240 0x44444444 /* 4 */,
241 0x55555555 /* 5 */,
242 0x66666666 /* 6 */,
243 0x77777777 /* 7 */,
244 0x88888888 /* 8 */,
245 0x99999999 /* 9 */,
246 0xAAAAAAAA /* 10 */,
247 0xBBBBBBBB /* 11 */,
248 0xCCCCCCCC /* 12 */,
249 0xDDDDDDDD /* 13 */,
250 0xEEEEEEEE /* 14 */,
251 0xFFFFFFFF /* 15 */,
252 };
253
254 UsesSource = ROP_USES_SOURCE(BltInfo->Rop4);
255 UsesPattern = ROP_USES_PATTERN(BltInfo->Rop4);
256
257 SourceY = BltInfo->SourcePoint.y;
258 RoundedRight = BltInfo->DestRect.right -
259 ((BltInfo->DestRect.right - BltInfo->DestRect.left) & 0x7);
260
261 if (UsesPattern)
262 {
263 if (BltInfo->PatternSurface)
264 {
265 PatternY = (BltInfo->DestRect.top + BltInfo->BrushOrigin.y) %
266 BltInfo->PatternSurface->sizlBitmap.cy;
267 }
268 else
269 {
270 Pattern = ExpandSolidColor[BltInfo->Brush->iSolidColor];
271 }
272 }
273
274 for (DestY = BltInfo->DestRect.top; DestY < BltInfo->DestRect.bottom; DestY++)
275 {
276 DestBits = (PULONG)(
277 BltInfo->DestSurface->pvScan0 +
278 (BltInfo->DestRect.left >> 1) +
279 DestY * BltInfo->DestSurface->lDelta);
280 SourceX = BltInfo->SourcePoint.x;
281 DestX = BltInfo->DestRect.left;
282
283 if (DestX & 0x1)
284 {
285 Dest = DIB_4BPP_GetPixel(BltInfo->DestSurface, DestX, DestY);
286
287 if (UsesSource)
288 {
289 Source = DIB_GetSource(BltInfo->SourceSurface, SourceX, SourceY, BltInfo->XlateSourceToDest);
290 }
291
292 if (BltInfo->PatternSurface)
293 {
294 Pattern = DIB_GetSource(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY, BltInfo->XlatePatternToDest);
295 }
296
297 DIB_4BPP_PutPixel(BltInfo->DestSurface, DestX, DestY, DIB_DoRop(BltInfo->Rop4, Dest, Source, Pattern) & 0xF);
298
299 DestX++;
300 SourceX++;
301 DestBits = (PULONG)((ULONG_PTR)DestBits + 1);
302 }
303
304 for (; DestX < RoundedRight; DestX += 8, SourceX += 8, DestBits++)
305 {
306 Dest = *DestBits;
307 if (UsesSource)
308 {
309 Source =
310 (DIB_GetSource(BltInfo->SourceSurface, SourceX + 1, SourceY, BltInfo->XlateSourceToDest)) |
311 (DIB_GetSource(BltInfo->SourceSurface, SourceX + 0, SourceY, BltInfo->XlateSourceToDest) << 4) |
312 (DIB_GetSource(BltInfo->SourceSurface, SourceX + 3, SourceY, BltInfo->XlateSourceToDest) << 8) |
313 (DIB_GetSource(BltInfo->SourceSurface, SourceX + 2, SourceY, BltInfo->XlateSourceToDest) << 12) |
314 (DIB_GetSource(BltInfo->SourceSurface, SourceX + 5, SourceY, BltInfo->XlateSourceToDest) << 16) |
315 (DIB_GetSource(BltInfo->SourceSurface, SourceX + 4, SourceY, BltInfo->XlateSourceToDest) << 20) |
316 (DIB_GetSource(BltInfo->SourceSurface, SourceX + 7, SourceY, BltInfo->XlateSourceToDest) << 24) |
317 (DIB_GetSource(BltInfo->SourceSurface, SourceX + 6, SourceY, BltInfo->XlateSourceToDest) << 28);
318 }
319 if (BltInfo->PatternSurface)
320 {
321 Pattern = DIB_GetSource(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x + 1) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY, BltInfo->XlatePatternToDest);
322 Pattern |= DIB_GetSource(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x + 0) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY, BltInfo->XlatePatternToDest) << 4;
323 Pattern |= DIB_GetSource(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x + 3) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY, BltInfo->XlatePatternToDest) << 8;
324 Pattern |= DIB_GetSource(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x + 2) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY, BltInfo->XlatePatternToDest) << 12;
325 Pattern |= DIB_GetSource(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x + 5) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY, BltInfo->XlatePatternToDest) << 16;
326 Pattern |= DIB_GetSource(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x + 4) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY, BltInfo->XlatePatternToDest) << 20;
327 Pattern |= DIB_GetSource(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x + 7) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY, BltInfo->XlatePatternToDest) << 24;
328 Pattern |= DIB_GetSource(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x + 6) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY, BltInfo->XlatePatternToDest) << 28;
329 }
330 *DestBits = DIB_DoRop(BltInfo->Rop4, Dest, Source, Pattern);
331 }
332
333 /* Process the rest of pixel on the line */
334 for (; DestX < BltInfo->DestRect.right; DestX++, SourceX++)
335 {
336 Dest = DIB_4BPP_GetPixel(BltInfo->DestSurface, DestX, DestY);
337 if (UsesSource)
338 {
339 Source = DIB_GetSource(BltInfo->SourceSurface, SourceX, SourceY, BltInfo->XlateSourceToDest);
340 }
341 if (BltInfo->PatternSurface)
342 {
343 Pattern = DIB_GetSource(BltInfo->PatternSurface, (DestX + BltInfo->BrushOrigin.x) % BltInfo->PatternSurface->sizlBitmap.cx, PatternY, BltInfo->XlatePatternToDest);
344 }
345 DIB_4BPP_PutPixel(BltInfo->DestSurface, DestX, DestY, DIB_DoRop(BltInfo->Rop4, Dest, Source, Pattern) & 0xF);
346 }
347
348 SourceY++;
349 if (BltInfo->PatternSurface)
350 {
351 PatternY++;
352 PatternY %= BltInfo->PatternSurface->sizlBitmap.cy;
353 }
354 }
355
356 return TRUE;
357 }
358
359 BOOLEAN DIB_4BPP_StretchBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
360 RECTL* DestRect, RECTL *SourceRect,
361 POINTL* MaskOrigin, POINTL BrushOrigin,
362 CLIPOBJ *ClipRegion, XLATEOBJ *ColorTranslation,
363 ULONG Mode)
364 {
365 DbgPrint("DIB_4BPP_StretchBlt: Source BPP: %u\n", BitsPerFormat(SourceSurf->iBitmapFormat));
366 return FALSE;
367 }
368
369 BOOLEAN
370 DIB_4BPP_TransparentBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
371 RECTL* DestRect, POINTL *SourcePoint,
372 XLATEOBJ *ColorTranslation, ULONG iTransColor)
373 {
374 return FALSE;
375 }
376
377 /* EOF */