WIN32K code cleanup.
[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: dib4bpp.c,v 1.13 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_4BPP_PutPixel(PSURFOBJ SurfObj, LONG x, LONG y, ULONG c)
32 {
33 PBYTE addr = SurfObj->pvScan0;
34
35 addr += (x>>1) + y * SurfObj->lDelta;
36 *addr = (*addr & notmask[x&1]) | (c << ((1-(x&1))<<2));
37 }
38
39 ULONG
40 DIB_4BPP_GetPixel(PSURFOBJ SurfObj, LONG x, LONG y)
41 {
42 PBYTE addr = SurfObj->pvScan0;
43
44 return (addr[(x>>1) + y * SurfObj->lDelta] >> ((1-(x&1))<<2) ) & 0x0f;
45 }
46
47 VOID
48 DIB_4BPP_HLine(PSURFOBJ SurfObj, LONG x1, LONG x2, LONG y, ULONG c)
49 {
50 PBYTE addr = SurfObj->pvScan0 + (x1>>1) + y * SurfObj->lDelta;
51 LONG cx = x1;
52
53 while(cx < x2) {
54 *addr = (*addr & notmask[x1&1]) | (c << ((1-(x1&1))<<2));
55 if((++x1 & 1) == 0)
56 ++addr;
57 ++cx;
58 }
59 }
60
61 VOID
62 DIB_4BPP_VLine(PSURFOBJ SurfObj, LONG x, LONG y1, LONG y2, ULONG c)
63 {
64 PBYTE addr = SurfObj->pvScan0;
65 int lDelta = SurfObj->lDelta;
66
67 addr += (x>>1) + y1 * lDelta;
68 while(y1++ < y2) {
69 *addr = (*addr & notmask[x&1]) | (c << ((1-(x&1))<<2));
70 addr += lDelta;
71 }
72 }
73
74 BOOLEAN
75 DIB_4BPP_BitBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
76 SURFGDI *DestGDI, SURFGDI *SourceGDI,
77 PRECTL DestRect, POINTL *SourcePoint,
78 XLATEOBJ *ColorTranslation)
79 {
80 LONG i, j, sx, sy, f1, f2, xColor;
81 PBYTE SourceBits_24BPP, SourceLine_24BPP;
82 PBYTE DestBits, DestLine, SourceBits_8BPP, SourceLine_8BPP;
83 PBYTE SourceBits, SourceLine;
84
85 DestBits = DestSurf->pvScan0 + (DestRect->left>>1) + DestRect->top * DestSurf->lDelta;
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_4BPP_PutPixel(DestSurf, i, j, XLATEOBJ_iXlate(ColorTranslation, 0));
101 } else {
102 DIB_4BPP_PutPixel(DestSurf, i, j, XLATEOBJ_iXlate(ColorTranslation, 1));
103 }
104 sx++;
105 }
106 sy++;
107 }
108 break;
109
110 case 4:
111 sy = SourcePoint->y;
112
113 for (j=DestRect->top; j<DestRect->bottom; j++)
114 {
115 sx = SourcePoint->x;
116
117 for (i=DestRect->left; i<DestRect->right; i++)
118 {
119 DIB_4BPP_PutPixel(DestSurf, i, j, XLATEOBJ_iXlate(ColorTranslation, DIB_4BPP_GetPixel(SourceSurf, sx, sy)));
120 sx++;
121 }
122 sy++;
123 }
124 break;
125
126 case 8:
127 SourceBits_8BPP = SourceSurf->pvScan0 + (SourcePoint->y * SourceSurf->lDelta) + SourcePoint->x;
128
129 for (j=DestRect->top; j<DestRect->bottom; j++)
130 {
131 SourceLine_8BPP = SourceBits_8BPP;
132 DestLine = DestBits;
133 f2 = DestRect->left & 1;
134
135 for (i=DestRect->left; i<DestRect->right; i++)
136 {
137 *DestLine = (*DestLine & notmask[i&1]) |
138 ((XLATEOBJ_iXlate(ColorTranslation, *SourceLine_8BPP)) << ((4 * (1-(i & 1)))));
139 if(f2 == 1) { DestLine++; f2 = 0; } else { f2 = 1; }
140 SourceLine_8BPP++;
141 }
142
143 SourceBits_8BPP += SourceSurf->lDelta;
144 DestBits += DestSurf->lDelta;
145 }
146 break;
147
148 case 16:
149 SourceLine = SourceSurf->pvScan0 + (SourcePoint->y * SourceSurf->lDelta) + 2 * SourcePoint->x;
150 DestLine = DestBits;
151
152 for (j = DestRect->top; j < DestRect->bottom; j++)
153 {
154 SourceBits = SourceLine;
155 DestBits = DestLine;
156 f2 = DestRect->left & 1;
157
158 for (i = DestRect->left; i < DestRect->right; i++)
159 {
160 xColor = *((PWORD) SourceBits);
161 *DestBits = (*DestBits & notmask[i&1]) |
162 ((XLATEOBJ_iXlate(ColorTranslation, xColor)) << ((4 * (1-(i & 1)))));
163 if(f2 == 1) { DestBits++; f2 = 0; } else { f2 = 1; }
164 SourceBits += 2;
165 }
166
167 SourceLine += SourceSurf->lDelta;
168 DestLine += DestSurf->lDelta;
169 }
170 break;
171
172 case 24:
173 SourceBits_24BPP = SourceSurf->pvScan0 + (SourcePoint->y * SourceSurf->lDelta) + SourcePoint->x * 3;
174
175 for (j=DestRect->top; j<DestRect->bottom; j++)
176 {
177 SourceLine_24BPP = SourceBits_24BPP;
178 DestLine = DestBits;
179 f2 = DestRect->left & 1;
180
181 for (i=DestRect->left; i<DestRect->right; i++)
182 {
183 xColor = (*(SourceLine_24BPP + 2) << 0x10) +
184 (*(SourceLine_24BPP + 1) << 0x08) +
185 (*(SourceLine_24BPP));
186 *DestLine = (*DestLine & notmask[i&1]) |
187 ((XLATEOBJ_iXlate(ColorTranslation, xColor)) << ((4 * (1-(i & 1)))));
188 if(f2 == 1) { DestLine++; f2 = 0; } else { f2 = 1; }
189 SourceLine_24BPP+=3;
190 }
191
192 SourceBits_24BPP += SourceSurf->lDelta;
193 DestBits += 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 f2 = DestRect->left & 1;
206
207 for (i = DestRect->left; i < DestRect->right; i++)
208 {
209 xColor = *((PDWORD) SourceBits);
210 *DestBits = (*DestBits & notmask[i&1]) |
211 ((XLATEOBJ_iXlate(ColorTranslation, xColor)) << ((4 * (1-(i & 1)))));
212 if(f2 == 1) { DestBits++; f2 = 0; } else { f2 = 1; }
213 SourceBits += 4;
214 }
215
216 SourceLine += SourceSurf->lDelta;
217 DestLine += DestSurf->lDelta;
218 }
219 break;
220
221 default:
222 DbgPrint("DIB_4BPP_Bitblt: Unhandled Source BPP: %u\n", SourceGDI->BitsPerPixel);
223 return FALSE;
224 }
225
226 return TRUE;
227 }
228 /* EOF */