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