- Move GDI drivers and win32k.sys from system32\drivers to system32
[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 LONG Delta, XLATEOBJ *ColorTranslation)
57 {
58 LONG 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 sy = SourcePoint->y;
91
92 for (j=DestRect->top; j<DestRect->bottom; j++)
93 {
94 sx = SourcePoint->x;
95
96 for (i=DestRect->left; i<DestRect->right; i++)
97 {
98 DIB_4BPP_PutPixel(DestSurf, i, j, XLATEOBJ_iXlate(ColorTranslation, DIB_4BPP_GetPixel(SourceSurf, sx, sy)));
99 sx++;
100 }
101 sy++;
102 }
103 break;
104
105 case 8:
106 SourceBits_8BPP = SourceSurf->pvBits + (SourcePoint->y * SourceSurf->lDelta) + SourcePoint->x;
107
108 for (j=DestRect->top; j<DestRect->bottom; j++)
109 {
110 SourceLine_8BPP = SourceBits_8BPP;
111 DestLine = DestBits;
112 sx = SourcePoint->x;
113 f1 = sx & 1;
114 f2 = DestRect->left & 1;
115
116 for (i=DestRect->left; i<DestRect->right; i++)
117 {
118 *DestLine = (*DestLine & notmask[i&1]) |
119 ((XLATEOBJ_iXlate(ColorTranslation, *SourceLine_8BPP)) << ((4 * (1-(sx & 1)))));
120 if(f2 == 1) { DestLine++; f2 = 0; } else { f2 = 1; }
121 SourceLine_8BPP++;
122 sx++;
123 }
124
125 SourceBits_8BPP += SourceSurf->lDelta;
126 DestBits += DestSurf->lDelta;
127 }
128 break;
129
130 case 24:
131 SourceBits_24BPP = SourceSurf->pvBits + (SourcePoint->y * SourceSurf->lDelta) + SourcePoint->x * 3;
132
133 for (j=DestRect->top; j<DestRect->bottom; j++)
134 {
135 SourceLine_24BPP = SourceBits_24BPP;
136 DestLine = DestBits;
137 sx = SourcePoint->x;
138 f1 = sx & 1;
139 f2 = DestRect->left & 1;
140
141 for (i=DestRect->left; i<DestRect->right; i++)
142 {
143 xColor = (*(SourceLine_24BPP + 2) << 0x10) +
144 (*(SourceLine_24BPP + 1) << 0x08) +
145 (*(SourceLine_24BPP));
146 *DestLine = (*DestLine & notmask[i&1]) |
147 ((XLATEOBJ_iXlate(ColorTranslation, xColor)) << ((4 * (1-(sx & 1)))));
148 if(f2 == 1) { DestLine++; f2 = 0; } else { f2 = 1; }
149 SourceLine_24BPP+=3;
150 sx++;
151 }
152
153 SourceBits_24BPP += SourceSurf->lDelta;
154 DestBits += DestSurf->lDelta;
155 }
156 break;
157
158 default:
159 DbgPrint("DIB_4BPP_Bitblt: Unhandled Source BPP: %u\n", SourceGDI->BitsPerPixel);
160 return FALSE;
161 }
162
163 return TRUE;
164 }