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