[WIN32K, GENDIB]
[reactos.git] / 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_1BPP_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_4BPP_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_8BPP_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_16BPP_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 /* Ignore alpha channel in Pattern */
155 Pattern &= 0x00ffffff ;
156
157 /* Optimized code for the various named rop codes. */
158 switch (Rop)
159 {
160 case ROP3_TO_ROP4(BLACKNESS): return(0);
161 case ROP3_TO_ROP4(NOTSRCERASE): return(~(Dest | Source));
162 case ROP3_TO_ROP4(NOTSRCCOPY): return(~Source);
163 case ROP3_TO_ROP4(SRCERASE): return((~Dest) & Source);
164 case ROP3_TO_ROP4(DSTINVERT): return(~Dest);
165 case ROP3_TO_ROP4(PATINVERT): return(Dest ^ Pattern);
166 case ROP3_TO_ROP4(SRCINVERT): return(Dest ^ Source);
167 case ROP3_TO_ROP4(SRCAND): return(Dest & Source);
168 case ROP3_TO_ROP4(MERGEPAINT): return(Dest | (~Source));
169 case ROP3_TO_ROP4(SRCPAINT): return(Dest | Source);
170 case ROP3_TO_ROP4(MERGECOPY): return(Source & Pattern);
171 case ROP3_TO_ROP4(SRCCOPY): return(Source);
172 case ROP3_TO_ROP4(PATCOPY): return(Pattern);
173 case ROP3_TO_ROP4(PATPAINT): return(Dest | (~Source) | Pattern);
174 case ROP3_TO_ROP4(WHITENESS): return(0xFFFFFFFF);
175 }
176 /* Expand the ROP operation to all four bytes */
177 Rop &= 0xFF;
178 Rop |= (Rop << 24) | (Rop << 16) | (Rop << 8);
179 /* Do the operation on four bits simultaneously. */
180 Result = 0;
181 for (i = 0; i < 8; i++)
182 {
183 ResultNibble = Rop & ExpandDest[Dest & 0xF] & ExpandSource[Source & 0xF] & ExpandPattern[Pattern & 0xF];
184 Result |= (((ResultNibble & 0xFF000000) ? 0x8 : 0x0) | ((ResultNibble & 0x00FF0000) ? 0x4 : 0x0) |
185 ((ResultNibble & 0x0000FF00) ? 0x2 : 0x0) | ((ResultNibble & 0x000000FF) ? 0x1 : 0x0)) << (i * 4);
186 Dest >>= 4;
187 Source >>= 4;
188 Pattern >>= 4;
189 }
190 return(Result);
191 }
192
193 VOID Dummy_PutPixel(SURFOBJ* SurfObj, LONG x, LONG y, ULONG c)
194 {
195 return;
196 }
197
198 ULONG Dummy_GetPixel(SURFOBJ* SurfObj, LONG x, LONG y)
199 {
200 return 0;
201 }
202
203 VOID Dummy_HLine(SURFOBJ* SurfObj, LONG x1, LONG x2, LONG y, ULONG c)
204 {
205 return;
206 }
207
208 VOID Dummy_VLine(SURFOBJ* SurfObj, LONG x, LONG y1, LONG y2, ULONG c)
209 {
210 return;
211 }
212
213 BOOLEAN Dummy_BitBlt(PBLTINFO BltInfo)
214 {
215 return FALSE;
216 }
217
218 BOOLEAN Dummy_StretchBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
219 SURFOBJ *PatternSurface, SURFOBJ *MaskSurf,
220 RECTL* DestRect, RECTL *SourceRect,
221 POINTL* MaskOrigin, BRUSHOBJ* Brush,
222 POINTL* BrushOrign,
223 XLATEOBJ *ColorTranslation,
224 ROP4 Rop)
225 {
226 return FALSE;
227 }
228
229 BOOLEAN Dummy_TransparentBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
230 RECTL* DestRect, RECTL *SourceRect,
231 XLATEOBJ *ColorTranslation, ULONG iTransColor)
232 {
233 return FALSE;
234 }
235
236 BOOLEAN Dummy_ColorFill(SURFOBJ* Dest, RECTL* DestRect, ULONG Color)
237 {
238 return FALSE;
239 }
240
241
242 BOOLEAN
243 Dummy_AlphaBlend(SURFOBJ* Dest, SURFOBJ* Source, RECTL* DestRect,
244 RECTL* SourceRect, CLIPOBJ* ClipRegion,
245 XLATEOBJ* ColorTranslation, BLENDOBJ* BlendObj)
246 {
247 return FALSE;
248 }
249
250 /* EOF */