DIB Engine: implement most engine functions
[wine/hacks.git] / dlls / winedib.drv / primitives_rop2.c
blobb23e919fd55c6fa4e4285373cf111414e2dc5298
1 /*
2 * DIB Engine ROP2 Primitives
4 * Copyright 2008 Huw Davies
5 * Copyright 2008 Massimo Del Fedele
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include "dibdrv.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(dibdrv);
29 /* ------------------------------------------------------------*/
30 /* BASIC ROP HELPER */
33 * Decompose the 16 ROP2s into an expression of the form
35 * D = (D & A) ^ X
37 * Where A and X depend only on P (and so can be precomputed).
39 * A X
41 * R2_BLACK 0 0 0
42 * R2_NOTMERGEPEN ~(D | P) ~P ~P
43 * R2_MASKNOTPEN ~P & D ~P 0
44 * R2_NOTCOPYPEN ~P 0 ~P
45 * R2_MASKPENNOT P & ~D P P
46 * R2_NOT ~D 1 1
47 * R2_XORPEN P ^ D 1 P
48 * R2_NOTMASKPEN ~(P & D) P 1
49 * R2_MASKPEN P & D P 0
50 * R2_NOTXORPEN ~(P ^ D) 1 ~P
51 * R2_NOP D 1 0
52 * R2_MERGENOTPEN ~P | D P ~P
53 * R2_COPYPEN P 0 P
54 * R2_MERGEPENNOT P | ~D ~P 1
55 * R2_MERGEPEN P | D ~P P
56 * R2_WHITE 1 0 1
60 /* A = (P & A1) | (~P & A2) */
61 #define ZERO {0, 0}
62 #define ONE {0xffffffff, 0xffffffff}
63 #define P {0xffffffff, 0}
64 #define NOT_P {0, 0xffffffff}
66 static const DWORD rop2_and_array[16][2] =
68 ZERO, NOT_P, NOT_P, ZERO,
69 P, ONE, ONE, P,
70 P, ONE, ONE, P,
71 ZERO, NOT_P, NOT_P, ZERO
74 /* X = (P & X1) | (~P & X2) */
75 static const DWORD rop2_xor_array[16][2] =
77 ZERO, NOT_P, ZERO, NOT_P,
78 P, ONE, P, ONE,
79 ZERO, NOT_P, ZERO, NOT_P,
80 P, ONE, P, ONE
83 #undef NOT_P
84 #undef P
85 #undef ONE
86 #undef ZERO
88 void _DIBDRV_CalcAndXorMasks(INT rop, DWORD color, DWORD *and, DWORD *xor)
90 /* NB The ROP2 codes start at one and the arrays are zero-based */
91 rop = (rop - 1) & 0x0f;
92 *and = (color & rop2_and_array[rop][0]) | ((~color) & rop2_and_array[rop][1]);
93 *xor = (color & rop2_xor_array[rop][0]) | ((~color) & rop2_xor_array[rop][1]);
96 /* ------------------------------------------------------------*/
97 /* ROP PIXEL FUNCTIONS */
99 inline void _DIBDRV_rop32(DWORD *ptr, DWORD and, DWORD xor)
101 *ptr = (*ptr & and) ^ xor;
104 inline void _DIBDRV_rop16(WORD *ptr, WORD and, WORD xor)
106 *ptr = (*ptr & and) ^ xor;
109 inline void _DIBDRV_rop8(BYTE *ptr, BYTE and, BYTE xor)
111 *ptr = (*ptr & and) ^ xor;