Initial support for 1BPP
[reactos.git] / reactos / subsys / win32k / dib / dib4bpp.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 PFN_DIB_PutPixel DIB_4BPP_PutPixel(PSURFOBJ SurfObj, LONG x, LONG y, ULONG c)
12 {
13 unsigned char *vp;
14 unsigned char mask;
15 PBYTE addr = SurfObj->pvBits;
16
17 addr += (x>>1) + y * SurfObj->lDelta;
18 *addr = (*addr & notmask[x&1]) | (c << ((1-(x&1))<<2));
19 }
20
21 PFN_DIB_GetPixel DIB_4BPP_GetPixel(PSURFOBJ SurfObj, LONG x, LONG y)
22 {
23 PBYTE addr = SurfObj->pvBits;
24
25 return (PFN_DIB_GetPixel)((addr[(x>>1) + y * SurfObj->lDelta] >> ((1-(x&1))<<2) ) & 0x0f);
26 }
27
28 PFN_DIB_HLine DIB_4BPP_HLine(PSURFOBJ SurfObj, LONG x1, LONG x2, LONG y, ULONG c)
29 {
30 PBYTE addr = SurfObj->pvBits + (x1>>1) + y * SurfObj->lDelta;
31 LONG cx = x1;
32
33 while(cx <= x2) {
34 *addr = (*addr & notmask[x1&1]) | (c << ((1-(x1&1))<<2));
35 if((++x1 & 1) == 0)
36 ++addr;
37 ++cx;
38 }
39 }
40
41 PFN_DIB_VLine DIB_4BPP_VLine(PSURFOBJ SurfObj, LONG x, LONG y1, LONG y2, ULONG c)
42 {
43 PBYTE addr = SurfObj->pvBits;
44 int lDelta = SurfObj->lDelta;
45
46 addr += (x>>1) + y1 * lDelta;
47 while(y1++ <= y2) {
48 *addr = (*addr & notmask[x&1]) | (c << ((1-(x&1))<<2));
49 addr += lDelta;
50 }
51 }
52
53 BOOLEAN DIB_To_4BPP_Bitblt( SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
54 SURFGDI *DestGDI, SURFGDI *SourceGDI,
55 PRECTL DestRect, POINTL *SourcePoint,
56 ULONG Delta, XLATEOBJ *ColorTranslation)
57 {
58 ULONG i, j, sx, sy, f1, f2, xColor;
59 PBYTE SourceBits_24BPP, SourceLine_24BPP;
60 PBYTE DestBits, DestLine, SourceBits_4BPP, SourceBits_8BPP, SourceLine_4BPP, SourceLine_8BPP;
61 PWORD SourceBits_16BPP, SourceLine_16BPP;
62 PDWORD SourceBits_32BPP, SourceLine_32BPP;
63
64 DestBits = DestSurf->pvBits + (DestRect->left>>1) + DestRect->top * DestSurf->lDelta;
65
66 switch(SourceGDI->BitsPerPixel)
67 {
68 case 1:
69 sx = SourcePoint->x;
70 sy = SourcePoint->y;
71
72 for (j=DestRect->top; j<DestRect->bottom; j++)
73 {
74 sx = SourcePoint->x;
75 for (i=DestRect->left; i<DestRect->right; i++)
76 {
77 if(DIB_1BPP_GetPixel(SourceSurf, sx, sy) == 0)
78 {
79 DIB_4BPP_PutPixel(DestSurf, i, j, XLATEOBJ_iXlate(ColorTranslation, 0));
80 } else {
81 DIB_4BPP_PutPixel(DestSurf, i, j, XLATEOBJ_iXlate(ColorTranslation, 1));
82 }
83 sx++;
84 }
85 sy++;
86 }
87 break;
88
89 case 4:
90 SourceBits_4BPP = SourceSurf->pvBits + (SourcePoint->y * SourceSurf->lDelta) + SourcePoint->x;
91
92 for (j=DestRect->top; j<DestRect->bottom; j++)
93 {
94 SourceLine_4BPP = SourceBits_4BPP;
95 DestLine = DestBits;
96 sx = SourcePoint->x;
97 f1 = sx & 1;
98 f2 = DestRect->left & 1;
99
100 // FIXME: handle odd begin pixel
101
102 for (i=DestRect->left; i<DestRect->right; i++)
103 {
104 if(f1 == 1) { SourceLine_4BPP++; f1 = 0; } else { f1 = 1; }
105 if(f2 == 1) { DestLine++; f2 = 0; } else { f2 = 1; *DestLine = *SourceLine_4BPP; }
106 sx++;
107 }
108
109 // FIXME: handle odd end pixel
110
111 SourceBits_4BPP += SourceSurf->lDelta;
112 DestBits += DestSurf->lDelta;
113 }
114 break;
115
116 case 8:
117 SourceBits_8BPP = SourceSurf->pvBits + (SourcePoint->y * SourceSurf->lDelta) + SourcePoint->x;
118
119 for (j=DestRect->top; j<DestRect->bottom; j++)
120 {
121 SourceLine_8BPP = SourceBits_8BPP;
122 DestLine = DestBits;
123 sx = SourcePoint->x;
124 f1 = sx & 1;
125 f2 = DestRect->left & 1;
126
127 for (i=DestRect->left; i<DestRect->right; i++)
128 {
129 *DestLine = (*DestLine & notmask[i&1]) |
130 ((XLATEOBJ_iXlate(ColorTranslation, *SourceLine_8BPP)) << ((4 * (1-(sx & 1)))));
131 if(f2 == 1) { DestLine++; f2 = 0; } else { f2 = 1; }
132 SourceLine_8BPP++;
133 sx++;
134 }
135
136 SourceBits_8BPP += SourceSurf->lDelta;
137 DestBits += DestSurf->lDelta;
138 }
139 break;
140
141 case 24:
142 SourceBits_24BPP = SourceSurf->pvBits + (SourcePoint->y * SourceSurf->lDelta) + SourcePoint->x * 3;
143
144 for (j=DestRect->top; j<DestRect->bottom; j++)
145 {
146 SourceLine_24BPP = SourceBits_24BPP;
147 DestLine = DestBits;
148 sx = SourcePoint->x;
149 f1 = sx & 1;
150 f2 = DestRect->left & 1;
151
152 for (i=DestRect->left; i<DestRect->right; i++)
153 {
154 xColor = (*(SourceLine_24BPP + 2) << 0x10) +
155 (*(SourceLine_24BPP + 1) << 0x08) +
156 (*(SourceLine_24BPP));
157 *DestLine = (*DestLine & notmask[i&1]) |
158 ((XLATEOBJ_iXlate(ColorTranslation, xColor)) << ((4 * (1-(sx & 1)))));
159 if(f2 == 1) { DestLine++; f2 = 0; } else { f2 = 1; }
160 SourceLine_24BPP+=3;
161 sx++;
162 }
163
164 SourceBits_24BPP += SourceSurf->lDelta;
165 DestBits += DestSurf->lDelta;
166 }
167 break;
168
169 default:
170 DbgPrint("DIB_4BPP_Bitblt: Unhandled Source BPP: %u\n", SourceGDI->BitsPerPixel);
171 return FALSE;
172 }
173
174 return TRUE;
175 }