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