[YAROTOWS] Reintegrate the branch. For a brighter future.
[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 ULONG
91 DIB_DoRop(ULONG Rop, ULONG Dest, ULONG Source, ULONG Pattern)
92 {
93 ULONG ResultNibble;
94 ULONG Result;
95 ULONG i;
96 static const ULONG ExpandDest[16] =
97 {
98 0x55555555 /* 0000 */,
99 0x555555AA /* 0001 */,
100 0x5555AA55 /* 0010 */,
101 0x5555AAAA /* 0011 */,
102 0x55AA5555 /* 0100 */,
103 0x55AA55AA /* 0101 */,
104 0x55AAAA55 /* 0110 */,
105 0x55AAAAAA /* 0111 */,
106 0xAA555555 /* 1000 */,
107 0xAA5555AA /* 1001 */,
108 0xAA55AA55 /* 1010 */,
109 0xAA55AAAA /* 1011 */,
110 0xAAAA5555 /* 1100 */,
111 0xAAAA55AA /* 1101 */,
112 0xAAAAAA55 /* 1110 */,
113 0xAAAAAAAA /* 1111 */,
114 };
115 static const ULONG ExpandSource[16] =
116 {
117 0x33333333 /* 0000 */,
118 0x333333CC /* 0001 */,
119 0x3333CC33 /* 0010 */,
120 0x3333CCCC /* 0011 */,
121 0x33CC3333 /* 0100 */,
122 0x33CC33CC /* 0101 */,
123 0x33CCCC33 /* 0110 */,
124 0x33CCCCCC /* 0111 */,
125 0xCC333333 /* 1000 */,
126 0xCC3333CC /* 1001 */,
127 0xCC33CC33 /* 1010 */,
128 0xCC33CCCC /* 1011 */,
129 0xCCCC3333 /* 1100 */,
130 0xCCCC33CC /* 1101 */,
131 0xCCCCCC33 /* 1110 */,
132 0xCCCCCCCC /* 1111 */,
133 };
134 static const ULONG ExpandPattern[16] =
135 {
136 0x0F0F0F0F /* 0000 */,
137 0x0F0F0FF0 /* 0001 */,
138 0x0F0FF00F /* 0010 */,
139 0x0F0FF0F0 /* 0011 */,
140 0x0FF00F0F /* 0100 */,
141 0x0FF00FF0 /* 0101 */,
142 0x0FF0F00F /* 0110 */,
143 0x0FF0F0F0 /* 0111 */,
144 0xF00F0F0F /* 1000 */,
145 0xF00F0FF0 /* 1001 */,
146 0xF00FF00F /* 1010 */,
147 0xF00FF0F0 /* 1011 */,
148 0xF0F00F0F /* 1100 */,
149 0xF0F00FF0 /* 1101 */,
150 0xF0F0F00F /* 1110 */,
151 0xF0F0F0F0 /* 1111 */,
152 };
153
154 /* Optimized code for the various named rop codes. */
155 switch (Rop)
156 {
157 case ROP3_TO_ROP4(BLACKNESS): return(0);
158 case ROP3_TO_ROP4(NOTSRCERASE): return(~(Dest | Source));
159 case ROP3_TO_ROP4(NOTSRCCOPY): return(~Source);
160 case ROP3_TO_ROP4(SRCERASE): return((~Dest) & Source);
161 case ROP3_TO_ROP4(DSTINVERT): return(~Dest);
162 case ROP3_TO_ROP4(PATINVERT): return(Dest ^ Pattern);
163 case ROP3_TO_ROP4(SRCINVERT): return(Dest ^ Source);
164 case ROP3_TO_ROP4(SRCAND): return(Dest & Source);
165 case ROP3_TO_ROP4(MERGEPAINT): return(Dest | (~Source));
166 case ROP3_TO_ROP4(SRCPAINT): return(Dest | Source);
167 case ROP3_TO_ROP4(MERGECOPY): return(Source & Pattern);
168 case ROP3_TO_ROP4(SRCCOPY): return(Source);
169 case ROP3_TO_ROP4(PATCOPY): return(Pattern);
170 case ROP3_TO_ROP4(PATPAINT): return(Dest | (~Source) | Pattern);
171 case ROP3_TO_ROP4(WHITENESS): return(0xFFFFFFFF);
172 }
173 /* Expand the ROP operation to all four bytes */
174 Rop &= 0xFF;
175 Rop |= (Rop << 24) | (Rop << 16) | (Rop << 8);
176 /* Do the operation on four bits simultaneously. */
177 Result = 0;
178 for (i = 0; i < 8; i++)
179 {
180 ResultNibble = Rop & ExpandDest[Dest & 0xF] & ExpandSource[Source & 0xF] & ExpandPattern[Pattern & 0xF];
181 Result |= (((ResultNibble & 0xFF000000) ? 0x8 : 0x0) | ((ResultNibble & 0x00FF0000) ? 0x4 : 0x0) |
182 ((ResultNibble & 0x0000FF00) ? 0x2 : 0x0) | ((ResultNibble & 0x000000FF) ? 0x1 : 0x0)) << (i * 4);
183 Dest >>= 4;
184 Source >>= 4;
185 Pattern >>= 4;
186 }
187 return(Result);
188 }
189
190 VOID Dummy_PutPixel(SURFOBJ* SurfObj, LONG x, LONG y, ULONG c)
191 {
192 return;
193 }
194
195 ULONG Dummy_GetPixel(SURFOBJ* SurfObj, LONG x, LONG y)
196 {
197 return 0;
198 }
199
200 VOID Dummy_HLine(SURFOBJ* SurfObj, LONG x1, LONG x2, LONG y, ULONG c)
201 {
202 return;
203 }
204
205 VOID Dummy_VLine(SURFOBJ* SurfObj, LONG x, LONG y1, LONG y2, ULONG c)
206 {
207 return;
208 }
209
210 BOOLEAN Dummy_BitBlt(PBLTINFO BltInfo)
211 {
212 return FALSE;
213 }
214
215 BOOLEAN Dummy_StretchBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
216 SURFOBJ *PatternSurface, SURFOBJ *MaskSurf,
217 RECTL* DestRect, RECTL *SourceRect,
218 POINTL* MaskOrigin, BRUSHOBJ* Brush,
219 POINTL* BrushOrign,
220 XLATEOBJ *ColorTranslation,
221 ROP4 Rop)
222 {
223 return FALSE;
224 }
225
226 BOOLEAN Dummy_TransparentBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
227 RECTL* DestRect, RECTL *SourceRect,
228 XLATEOBJ *ColorTranslation, ULONG iTransColor)
229 {
230 return FALSE;
231 }
232
233 BOOLEAN Dummy_ColorFill(SURFOBJ* Dest, RECTL* DestRect, ULONG Color)
234 {
235 return FALSE;
236 }
237
238
239 BOOLEAN
240 Dummy_AlphaBlend(SURFOBJ* Dest, SURFOBJ* Source, RECTL* DestRect,
241 RECTL* SourceRect, CLIPOBJ* ClipRegion,
242 XLATEOBJ* ColorTranslation, BLENDOBJ* BlendObj)
243 {
244 return FALSE;
245 }
246
247 /* EOF */