38a479a52d04168577ff5c3374d7a8ddab89cd04
[reactos.git] / subsys / win32k / dib / dib32bpp.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 VOID DIB_32BPP_PutPixel(PSURFOBJ SurfObj, LONG x, LONG y, ULONG c)
12 {
13   PBYTE byteaddr = SurfObj->pvScan0 + y * SurfObj->lDelta;
14   PDWORD addr = (PDWORD)byteaddr + x;
15
16   *addr = c;
17 }
18
19 ULONG DIB_32BPP_GetPixel(PSURFOBJ SurfObj, LONG x, LONG y)
20 {
21   PBYTE byteaddr = SurfObj->pvScan0 + y * SurfObj->lDelta;
22   PDWORD addr = (PDWORD)byteaddr + x;
23
24   return (ULONG)(*addr);
25 }
26
27 VOID DIB_32BPP_HLine(PSURFOBJ SurfObj, LONG x1, LONG x2, LONG y, ULONG c)
28 {
29   PBYTE byteaddr = SurfObj->pvScan0 + y * SurfObj->lDelta;
30   PDWORD addr = (PDWORD)byteaddr + x1;
31   LONG cx = x1;
32
33   while(cx < x2) {
34     *addr = (DWORD)c;
35     ++addr;
36     ++cx;
37   }
38 }
39
40 VOID DIB_32BPP_VLine(PSURFOBJ SurfObj, LONG x, LONG y1, LONG y2, ULONG c)
41 {
42   PBYTE byteaddr = SurfObj->pvScan0 + y1 * SurfObj->lDelta;
43   PDWORD addr = (PDWORD)byteaddr + x;
44   LONG lDelta = SurfObj->lDelta / sizeof(DWORD);
45
46   byteaddr = (PBYTE)addr;
47   while(y1++ < y2) {
48     *addr = (DWORD)c;
49
50     addr += lDelta;
51   }
52 }
53
54 BOOLEAN DIB_32BPP_BitBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
55                          SURFGDI *DestGDI,  SURFGDI *SourceGDI,
56                          PRECTL  DestRect,  POINTL  *SourcePoint,
57                          XLATEOBJ *ColorTranslation)
58 {
59   ULONG     i, j, sx, sy, xColor, f1;
60   PBYTE    SourceBits, DestBits, SourceLine, DestLine;
61   PBYTE    SourceBits_4BPP, SourceLine_4BPP;
62
63   DestBits = DestSurf->pvScan0 + (DestRect->top * DestSurf->lDelta) + 4 * DestRect->left;
64
65   switch(SourceGDI->BitsPerPixel)
66   {
67     case 1:
68       sx = SourcePoint->x;
69       sy = SourcePoint->y;
70
71       for (j=DestRect->top; j<DestRect->bottom; j++)
72       {
73         sx = SourcePoint->x;
74         for (i=DestRect->left; i<DestRect->right; i++)
75         {
76           if(DIB_1BPP_GetPixel(SourceSurf, sx, sy) == 0)
77           {
78             DIB_32BPP_PutPixel(DestSurf, i, j, XLATEOBJ_iXlate(ColorTranslation, 0));
79           } else {
80             DIB_32BPP_PutPixel(DestSurf, i, j, XLATEOBJ_iXlate(ColorTranslation, 1));
81           }
82           sx++;
83         }
84         sy++;
85       }
86       break;
87
88     case 4:
89       SourceBits_4BPP = SourceSurf->pvScan0 + (SourcePoint->y * SourceSurf->lDelta) + (SourcePoint->x >> 1);
90
91       for (j=DestRect->top; j<DestRect->bottom; j++)
92       {
93         SourceLine_4BPP = SourceBits_4BPP;
94         sx = SourcePoint->x;
95         f1 = sx & 1;
96
97         for (i=DestRect->left; i<DestRect->right; i++)
98         {
99           xColor = XLATEOBJ_iXlate(ColorTranslation,
100               (*SourceLine_4BPP & altnotmask[sx&1]) >> (4 * (1-(sx & 1))));
101           DIB_32BPP_PutPixel(DestSurf, i, j, xColor);
102           if(f1 == 1) { SourceLine_4BPP++; f1 = 0; } else { f1 = 1; }
103           sx++;
104         }
105
106         SourceBits_4BPP += SourceSurf->lDelta;
107       }
108       break;
109
110     case 8:
111       SourceLine = SourceSurf->pvScan0 + (SourcePoint->y * SourceSurf->lDelta) + SourcePoint->x;
112       DestLine = DestBits;
113
114       for (j = DestRect->top; j < DestRect->bottom; j++)
115       {
116         SourceBits = SourceLine;
117         DestBits = DestLine;
118
119         for (i = DestRect->left; i < DestRect->right; i++)
120         {
121           xColor = *SourceBits;
122           *((PDWORD) DestBits) = (DWORD)XLATEOBJ_iXlate(ColorTranslation, xColor);
123           SourceBits += 1;
124           DestBits += 4;
125         }
126
127         SourceLine += SourceSurf->lDelta;
128         DestLine += DestSurf->lDelta;
129       }
130       break;
131
132     case 16:
133       SourceLine = SourceSurf->pvScan0 + (SourcePoint->y * SourceSurf->lDelta) + 2 * SourcePoint->x;
134       DestLine = DestBits;
135
136       for (j = DestRect->top; j < DestRect->bottom; j++)
137       {
138         SourceBits = SourceLine;
139         DestBits = DestLine;
140
141         for (i = DestRect->left; i < DestRect->right; i++)
142         {
143           xColor = *((PWORD) SourceBits);
144           *((PDWORD) DestBits) = (DWORD)XLATEOBJ_iXlate(ColorTranslation, xColor);
145           SourceBits += 2;
146           DestBits += 4;
147         }
148
149         SourceLine += SourceSurf->lDelta;
150         DestLine += DestSurf->lDelta;
151       }
152       break;
153
154     case 24:
155       SourceLine = SourceSurf->pvScan0 + (SourcePoint->y * SourceSurf->lDelta) + 3 * SourcePoint->x;
156       DestLine = DestBits;
157
158       for (j = DestRect->top; j < DestRect->bottom; j++)
159       {
160         SourceBits = SourceLine;
161         DestBits = DestLine;
162
163         for (i = DestRect->left; i < DestRect->right; i++)
164         {
165           xColor = (*(SourceBits + 2) << 0x10) +
166              (*(SourceBits + 1) << 0x08) +
167              (*(SourceBits));
168           *((PDWORD)DestBits) = (DWORD)XLATEOBJ_iXlate(ColorTranslation, xColor);
169           SourceBits += 3;
170           DestBits += 4;
171         }
172
173         SourceLine += SourceSurf->lDelta;
174         DestLine += DestSurf->lDelta;
175       }
176       break;
177
178     case 32:
179       if (NULL == ColorTranslation || 0 != (ColorTranslation->flXlate & XO_TRIVIAL))
180       {
181         SourceBits = SourceSurf->pvScan0 + (SourcePoint->y * SourceSurf->lDelta) + 4 * SourcePoint->x;
182         for (j = DestRect->top; j < DestRect->bottom; j++)
183         {
184           RtlCopyMemory(DestBits, SourceBits, 4 * (DestRect->right - DestRect->left));
185           SourceBits += SourceSurf->lDelta;
186           DestBits += DestSurf->lDelta;
187         }
188       }
189       else
190       {
191         /* FIXME */
192         DPRINT1("DIB_32BPP_Bitblt: Unhandled ColorTranslation for 32 -> 32 copy");
193         return FALSE;
194       }
195       break;
196
197     default:
198       DbgPrint("DIB_32BPP_Bitblt: Unhandled Source BPP: %u\n", SourceGDI->BitsPerPixel);
199       return FALSE;
200   }
201
202   return TRUE;
203 }