[WIN32K]
[reactos.git] / reactos / subsystems / win32 / win32k / dib / dib.c
1 /*
2 * PROJECT: Win32 subsystem
3 * LICENSE: See COPYING in the top level directory
4 * FILE: subsystems/win32/win32k/dib/dib.c
5 * PURPOSE: ROP handling, function pointer arrays, misc
6 * PROGRAMMERS: Ge van Geldorp
7 */
8
9
10 #include <win32k.h>
11
12 #define NDEBUG
13 #include <debug.h>
14
15 /* Static data */
16
17 unsigned char notmask[2] = { 0x0f, 0xf0 };
18 unsigned char altnotmask[2] = { 0xf0, 0x0f };
19
20 DIB_FUNCTIONS DibFunctionsForBitmapFormat[] =
21 {
22 /* 0 */
23 {
24 Dummy_PutPixel, Dummy_GetPixel, Dummy_HLine, Dummy_VLine,
25 Dummy_BitBlt, Dummy_BitBlt, Dummy_StretchBlt, Dummy_TransparentBlt,
26 Dummy_ColorFill, Dummy_AlphaBlend
27 },
28 /* BMF_1BPP */
29 {
30 DIB_1BPP_PutPixel, DIB_1BPP_GetPixel, DIB_1BPP_HLine, DIB_1BPP_VLine,
31 DIB_1BPP_BitBlt, DIB_1BPP_BitBltSrcCopy, DIB_XXBPP_StretchBlt,
32 DIB_1BPP_TransparentBlt, DIB_1BPP_ColorFill, DIB_XXBPP_AlphaBlend
33 },
34 /* BMF_4BPP */
35 {
36 DIB_4BPP_PutPixel, DIB_4BPP_GetPixel, DIB_4BPP_HLine, DIB_4BPP_VLine,
37 DIB_4BPP_BitBlt, DIB_4BPP_BitBltSrcCopy, DIB_XXBPP_StretchBlt,
38 DIB_4BPP_TransparentBlt, DIB_4BPP_ColorFill, DIB_XXBPP_AlphaBlend
39 },
40 /* BMF_8BPP */
41 {
42 DIB_8BPP_PutPixel, DIB_8BPP_GetPixel, DIB_8BPP_HLine, DIB_8BPP_VLine,
43 DIB_8BPP_BitBlt, DIB_8BPP_BitBltSrcCopy, DIB_XXBPP_StretchBlt,
44 DIB_8BPP_TransparentBlt, DIB_8BPP_ColorFill, DIB_XXBPP_AlphaBlend
45 },
46 /* BMF_16BPP */
47 {
48 DIB_16BPP_PutPixel, DIB_16BPP_GetPixel, DIB_16BPP_HLine, DIB_16BPP_VLine,
49 DIB_16BPP_BitBlt, DIB_16BPP_BitBltSrcCopy, DIB_XXBPP_StretchBlt,
50 DIB_16BPP_TransparentBlt, DIB_16BPP_ColorFill, DIB_XXBPP_AlphaBlend
51 },
52 /* BMF_24BPP */
53 {
54 DIB_24BPP_PutPixel, DIB_24BPP_GetPixel, DIB_24BPP_HLine, DIB_24BPP_VLine,
55 DIB_24BPP_BitBlt, DIB_24BPP_BitBltSrcCopy, DIB_XXBPP_StretchBlt,
56 DIB_24BPP_TransparentBlt, DIB_24BPP_ColorFill, DIB_24BPP_AlphaBlend
57 },
58 /* BMF_32BPP */
59 {
60 DIB_32BPP_PutPixel, DIB_32BPP_GetPixel, DIB_32BPP_HLine, DIB_32BPP_VLine,
61 DIB_32BPP_BitBlt, DIB_32BPP_BitBltSrcCopy, DIB_XXBPP_StretchBlt,
62 DIB_32BPP_TransparentBlt, DIB_32BPP_ColorFill, DIB_32BPP_AlphaBlend
63 },
64 /* BMF_4RLE */
65 {
66 Dummy_PutPixel, Dummy_GetPixel, Dummy_HLine, Dummy_VLine,
67 Dummy_BitBlt, Dummy_BitBlt, Dummy_StretchBlt, Dummy_TransparentBlt,
68 Dummy_ColorFill, Dummy_AlphaBlend
69 },
70 /* BMF_8RLE */
71 {
72 Dummy_PutPixel, Dummy_GetPixel, Dummy_HLine, Dummy_VLine,
73 Dummy_BitBlt, Dummy_BitBlt, Dummy_StretchBlt, Dummy_TransparentBlt,
74 Dummy_ColorFill, Dummy_AlphaBlend
75 },
76 /* BMF_JPEG */
77 {
78 Dummy_PutPixel, Dummy_GetPixel, Dummy_HLine, Dummy_VLine,
79 Dummy_BitBlt, Dummy_BitBlt, Dummy_StretchBlt, Dummy_TransparentBlt,
80 Dummy_ColorFill, Dummy_AlphaBlend
81 },
82 /* BMF_PNG */
83 {
84 Dummy_PutPixel, Dummy_GetPixel, Dummy_HLine, Dummy_VLine,
85 Dummy_BitBlt, Dummy_BitBlt, Dummy_StretchBlt, Dummy_TransparentBlt,
86 Dummy_ColorFill, Dummy_AlphaBlend
87 }
88 };
89
90
91 ULONG
92 DIB_DoRop(ULONG Rop, ULONG Dest, ULONG Source, ULONG Pattern)
93 {
94 ULONG ResultNibble;
95 ULONG Result = 0;
96 ULONG i;
97 static const ULONG ExpandDest[16] =
98 {
99 0x55555555 /* 0000 */,
100 0x555555AA /* 0001 */,
101 0x5555AA55 /* 0010 */,
102 0x5555AAAA /* 0011 */,
103 0x55AA5555 /* 0100 */,
104 0x55AA55AA /* 0101 */,
105 0x55AAAA55 /* 0110 */,
106 0x55AAAAAA /* 0111 */,
107 0xAA555555 /* 1000 */,
108 0xAA5555AA /* 1001 */,
109 0xAA55AA55 /* 1010 */,
110 0xAA55AAAA /* 1011 */,
111 0xAAAA5555 /* 1100 */,
112 0xAAAA55AA /* 1101 */,
113 0xAAAAAA55 /* 1110 */,
114 0xAAAAAAAA /* 1111 */,
115 };
116 static const ULONG ExpandSource[16] =
117 {
118 0x33333333 /* 0000 */,
119 0x333333CC /* 0001 */,
120 0x3333CC33 /* 0010 */,
121 0x3333CCCC /* 0011 */,
122 0x33CC3333 /* 0100 */,
123 0x33CC33CC /* 0101 */,
124 0x33CCCC33 /* 0110 */,
125 0x33CCCCCC /* 0111 */,
126 0xCC333333 /* 1000 */,
127 0xCC3333CC /* 1001 */,
128 0xCC33CC33 /* 1010 */,
129 0xCC33CCCC /* 1011 */,
130 0xCCCC3333 /* 1100 */,
131 0xCCCC33CC /* 1101 */,
132 0xCCCCCC33 /* 1110 */,
133 0xCCCCCCCC /* 1111 */,
134 };
135 static const ULONG ExpandPattern[16] =
136 {
137 0x0F0F0F0F /* 0000 */,
138 0x0F0F0FF0 /* 0001 */,
139 0x0F0FF00F /* 0010 */,
140 0x0F0FF0F0 /* 0011 */,
141 0x0FF00F0F /* 0100 */,
142 0x0FF00FF0 /* 0101 */,
143 0x0FF0F00F /* 0110 */,
144 0x0FF0F0F0 /* 0111 */,
145 0xF00F0F0F /* 1000 */,
146 0xF00F0FF0 /* 1001 */,
147 0xF00FF00F /* 1010 */,
148 0xF00FF0F0 /* 1011 */,
149 0xF0F00F0F /* 1100 */,
150 0xF0F00FF0 /* 1101 */,
151 0xF0F0F00F /* 1110 */,
152 0xF0F0F0F0 /* 1111 */,
153 };
154
155 Rop &=0xFF;
156 switch(Rop)
157 {
158
159 /* Optimized code for the various named rop codes. */
160 case R3_OPINDEX_NOOP: return(Dest);
161 case R3_OPINDEX_BLACKNESS: return(0);
162 case R3_OPINDEX_NOTSRCERASE: return(~(Dest | Source));
163 case R3_OPINDEX_NOTSRCCOPY: return(~Source);
164 case R3_OPINDEX_SRCERASE: return((~Dest) & Source);
165 case R3_OPINDEX_DSTINVERT: return(~Dest);
166 case R3_OPINDEX_PATINVERT: return(Dest ^ Pattern);
167 case R3_OPINDEX_SRCINVERT: return(Dest ^ Source);
168 case R3_OPINDEX_SRCAND: return(Dest & Source);
169 case R3_OPINDEX_MERGEPAINT: return(Dest | (~Source));
170 case R3_OPINDEX_SRCPAINT: return(Dest | Source);
171 case R3_OPINDEX_MERGECOPY: return(Source & Pattern);
172 case R3_OPINDEX_SRCCOPY: return(Source);
173 case R3_OPINDEX_PATCOPY: return(Pattern);
174 case R3_OPINDEX_PATPAINT: return(Dest | (~Source) | Pattern);
175 case R3_OPINDEX_WHITENESS: return(0xFFFFFFFF);
176 }
177
178 /* Expand the ROP operation to all four bytes */
179 Rop |= (Rop << 24) | (Rop << 16) | (Rop << 8);
180 /* Do the operation on four bits simultaneously. */
181 Result = 0;
182 for (i = 0; i < 6; i++)
183 {
184 ResultNibble = Rop & ExpandDest[Dest & 0xF] & ExpandSource[Source & 0xF] & ExpandPattern[Pattern & 0xF];
185 Result |= (((ResultNibble & 0xFF000000) ? 0x8 : 0x0) | ((ResultNibble & 0x00FF0000) ? 0x4 : 0x0) |
186 ((ResultNibble & 0x0000FF00) ? 0x2 : 0x0) | ((ResultNibble & 0x000000FF) ? 0x1 : 0x0)) << (i * 4);
187 Dest >>= 4;
188 Source >>= 4;
189 Pattern >>= 4;
190 }
191 return(Result);
192 }
193
194 VOID Dummy_PutPixel(SURFOBJ* SurfObj, LONG x, LONG y, ULONG c)
195 {
196 return;
197 }
198
199 ULONG Dummy_GetPixel(SURFOBJ* SurfObj, LONG x, LONG y)
200 {
201 return 0;
202 }
203
204 VOID Dummy_HLine(SURFOBJ* SurfObj, LONG x1, LONG x2, LONG y, ULONG c)
205 {
206 return;
207 }
208
209 VOID Dummy_VLine(SURFOBJ* SurfObj, LONG x, LONG y1, LONG y2, ULONG c)
210 {
211 return;
212 }
213
214 BOOLEAN Dummy_BitBlt(PBLTINFO BltInfo)
215 {
216 return FALSE;
217 }
218
219 BOOLEAN Dummy_StretchBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
220 SURFOBJ *PatternSurface, SURFOBJ *MaskSurf,
221 RECTL* DestRect, RECTL *SourceRect,
222 POINTL* MaskOrigin, BRUSHOBJ* Brush,
223 POINTL* BrushOrign,
224 XLATEOBJ *ColorTranslation,
225 ROP4 Rop)
226 {
227 return FALSE;
228 }
229
230 BOOLEAN Dummy_TransparentBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
231 RECTL* DestRect, RECTL *SourceRect,
232 XLATEOBJ *ColorTranslation, ULONG iTransColor)
233 {
234 return FALSE;
235 }
236
237 BOOLEAN Dummy_ColorFill(SURFOBJ* Dest, RECTL* DestRect, ULONG Color)
238 {
239 return FALSE;
240 }
241
242
243 BOOLEAN
244 Dummy_AlphaBlend(SURFOBJ* Dest, SURFOBJ* Source, RECTL* DestRect,
245 RECTL* SourceRect, CLIPOBJ* ClipRegion,
246 XLATEOBJ* ColorTranslation, BLENDOBJ* BlendObj)
247 {
248 return FALSE;
249 }
250
251 /* EOF */