1 /* Copyright (C) 2001-2012 Artifex Software, Inc.
2    All Rights Reserved.
3 
4    This software is provided AS-IS with no warranty, either express or
5    implied.
6 
7    This software is distributed under license and may not be copied,
8    modified or distributed except as expressly authorized under the terms
9    of the license contained in the file LICENSE in this distribution.
10 
11    Refer to licensing information at http://www.artifex.com or contact
12    Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134, San Rafael,
13    CA  94903, U.S.A., +1(415)492-9861, for further information.
14 */
15 
16 
17 /* This file is repeatedly included by gsroprun.c to 'autogenerate' many
18  * different versions of roprun code. DO NOT USE THIS FILE EXCEPT FROM
19  * gsroprun.c.
20  */
21 
22 /* Set the following defines as appropriate on entry:
23  *   TEMPLATE_NAME (Compulsory)  The name of the function to generate
24  *   SPECIFIC_ROP  (Optional)    If set, the function will base its decision
25  *                               about whether to provide S and T upon
26  *                               this value.
27  *   SPECIFIC_CODE (Optional)    If set, this should expand out to code to
28  *                               perform the rop. Will be invoked as:
29  *                               SPECIFIC_ROP(OUT,D,S,T)
30  *   S_CONST       (Optional)    If set, S will be taken to be constant, else
31  *                               S will be read from a pointer.
32  *   T_CONST       (Optional)    If set, T will be taken to be constant, else
33  *                               T will be read from a pointer.
34  *   S_1BIT        (Optional)    If set, the code will cope with S maybe
35  *                               being a pointer to a 1 bit bitmap to choose
36  *                               between scolors[0] and [1]. If set to 1, the
37  *                               code will assume that this is the case.
38  *   T_1BIT        (Optional)    If set, the code will cope with T maybe
39  *                               being a pointer to a 1 bit bitmap to choose
40  *                               between scolors[0] and [1]. If set to 1, the
41  *                               code will assume that this is the case.
42  *   S_TRANS       (Optional)    If set, the code will cope with S maybe
43  *                               being transparent. If set to 1, the code
44  *                               will assume that this is the case.
45  *   T_TRANS       (Optional)    If set, the code will cope with T maybe
46  *                               being transparent. If set to 1, the code
47  *                               will assume that this is the case.
48  */
49 
50 #ifdef SPECIFIC_ROP
51 #if rop3_uses_S(SPECIFIC_ROP)
52 #define S_USED
53 #endif
54 #if rop3_uses_T(SPECIFIC_ROP)
55 #define T_USED
56 #endif
57 #else /* !SPECIFIC_ROP */
58 #define S_USED
59 #define T_USED
60 #endif /* SPECIFIC_ROP */
61 
62 #ifndef S_USED
63 #undef S_1BIT
64 #endif /* defined(S_USED) */
65 #ifndef T_USED
66 #undef T_1BIT
67 #endif /* defined(T_USED) */
68 
69 #define GET24(ptr)\
70   (((rop_operand)(ptr)[0] << 16) | ((rop_operand)(ptr)[1] << 8) | (ptr)[2])
71 #define PUT24(ptr, pixel)\
72   (ptr)[0] = (byte)((pixel) >> 16),\
73   (ptr)[1] = (byte)((uint)(pixel) >> 8),\
74   (ptr)[2] = (byte)(pixel)
75 
76 #if defined(S_USED) && !defined(S_CONST)
77 #define FETCH_S      do { S = GET24(s); s += 3; } while (0==1)
78 #else /* !defined(S_USED) || defined(S_CONST) */
79 #define FETCH_S
80 #endif /* !defined(S_USED) || defined(S_CONST) */
81 
82 #if defined(T_USED) && !defined(T_CONST)
83 #define FETCH_T      do { T = GET24(t); t += 3; } while (0 == 1)
84 #else /* !defined(T_USED) || defined(T_CONST) */
85 #define FETCH_T
86 #endif /* !defined(T_USED) || defined(T_CONST) */
87 
TEMPLATE_NAME(rop_run_op * op,byte * d,int len)88 static void TEMPLATE_NAME(rop_run_op *op, byte *d, int len)
89 {
90 #ifndef SPECIFIC_CODE
91     rop_proc     proc = rop_proc_table[lop_rop(op->rop)];
92 #define SPECIFIC_CODE(OUT_, D_,S_,T_) OUT_ = proc(D_,S_,T_)
93 #endif /* !defined(SPECIFIC_CODE) */
94 #ifdef S_USED
95 #ifdef S_CONST
96     rop_operand  S = op->s.c;
97 #else /* !defined(S_CONST) */
98     const byte  *s = op->s.b.ptr;
99 #endif /* !defined(S_CONST) */
100 #ifdef S_TRANS
101 #if S_TRANS
102     const rop_operand  strans = 0xFFFFFF;
103 #else /* !S_TRANS */
104     const rop_operand  strans = (op->rop & lop_S_transparent ? 0xFFFFFF : -1);
105 #endif /* !S_TRANS */
106 #endif /* defined(S_TRANS) */
107 #ifdef S_1BIT
108     int          sroll;
109     rop_operand  sc[2];
110 #endif /* S_1BIT */
111 #else /* !defined(S_USED) */
112 #define S 0
113 #undef S_CONST
114 #endif /* !defined(S_USED) */
115 #ifdef T_USED
116 #ifdef T_CONST
117     rop_operand  T = op->t.c;
118 #else /* !defined(T_CONST) */
119     const byte  *t = op->t.b.ptr;
120 #endif /* !defined(T_CONST) */
121 #ifdef T_TRANS
122 #if T_TRANS
123     const rop_operand  ttrans = 0xFFFFFF;
124 #else /* !T_TRANS */
125     const rop_operand  ttrans = (op->rop & lop_T_transparent ? 0xFFFFFF : -1);
126 #endif /* !T_TRANS */
127 #endif /* defined(T_TRANS) */
128 #ifdef T_1BIT
129     int          troll;
130     rop_operand  tc[2];
131 #endif /* T_TRANS */
132 #else /* !defined(T_USED) */
133 #define T 0
134 #undef T_CONST
135 #endif /* !defined(T_USED) */
136 
137 #if defined(S_TRANS) && defined(S_CONST)
138     if (S == strans)
139         return;
140 #endif
141 
142 #if defined(T_TRANS) && defined(T_CONST)
143     if (T == ttrans)
144         return;
145 #endif
146 
147 #ifdef S_1BIT
148 #if S_1BIT
149     if (op->flags & rop_s_1bit) {
150 #endif /* S_1BIT */
151         s = op->s.b.ptr + (op->s.b.pos>>3);
152         sroll = 8-(op->s.b.pos & 7);
153         sc[0] = GET24(&op->scolors[0]);
154         sc[1] = GET24(&op->scolors[3]);
155 #if S_1BIT
156     } else
157         sroll = 0;
158 #endif /* S_1BIT */
159 #endif /* defined(S_1BIT) */
160 #ifdef T_1BIT
161 #if T_1BIT
162     if (op->flags & rop_t_1bit) {
163 #endif /* T_1BIT */
164         t = op->t.b.ptr + (op->t.b.pos>>3);
165         troll = 8-(op->t.b.pos & 7);
166         tc[0] = GET24(&op->tcolors[0]);
167         tc[1] = GET24(&op->tcolors[3]);
168 #if T_1BIT
169     } else
170         troll = 0;
171 #endif /* T_1BIT */
172 #endif /* defined(T_1BIT) */
173     do {
174 #if defined(S_USED) && !defined(S_CONST)
175         rop_operand S;
176 #endif /* defined(S_USED) && !defined(S_CONST) */
177 #if defined(T_USED) && !defined(T_CONST)
178         rop_operand T;
179 #endif /* defined(T_USED) && !defined(T_CONST) */
180 #if defined(S_1BIT) && !S_1BIT
181         if (sroll == 0) {
182 #endif /* defined(S_1BIT) && !S_1BIT */
183 #if !defined(S_1BIT) || !S_1BIT
184             FETCH_S;
185 #endif /* !defined(S_1BIT) || !S_1BIT */
186 #if defined(S_1BIT) && !S_1BIT
187         } else
188 #endif /* defined(S_1BIT) && !S_1BIT */
189         {
190 #ifdef S_1BIT
191             --sroll;
192             S = sc[(*s >> sroll) & 1];
193             if (sroll == 0) {
194                 sroll = 8;
195                 s++;
196             }
197 #endif /* S_1BIT */
198         }
199 #if defined(T_1BIT) && !T_1BIT
200         if (troll == 0) {
201 #endif /* defined(T_1BIT) && !T_1BIT */
202 #if !defined(T_1BIT) || !T_1BIT
203             FETCH_T;
204 #endif /* defined(T_1BIT) && !T_1BIT */
205 #if defined(T_1BIT) && !T_1BIT
206         } else
207 #endif /* defined(T_1BIT) && !T_1BIT */
208         {
209 #ifdef T_1BIT
210             --troll;
211             T = tc[(*t >> troll) & 1];
212             if (troll == 0) {
213                 troll = 8;
214                 t++;
215             }
216 #endif /* T_1BIT */
217         }
218         if (1
219 #if defined(S_TRANS) && !defined(S_CONST)
220             && (S != strans)
221 #endif /* defined(S_TRANS) && !defined(S_CONST) */
222 #if defined(T_TRANS) && !defined(T_CONST)
223             && (T != ttrans)
224 #endif /* defined(T_TRANS) && !defined(T_TRANS) */
225             ) {
226             rop_operand D;
227             SPECIFIC_CODE(D, GET24(d), S, T);
228             PUT24(d, D);
229         }
230         d += 3;
231     }
232     while (--len);
233 }
234 
235 #undef GET24
236 #undef PUT24
237 #undef FETCH_S
238 #undef FETCH_T
239 #undef S
240 #undef S_1BIT
241 #undef S_USED
242 #undef S_CONST
243 #undef S_TRANS
244 #undef SPECIFIC_CODE
245 #undef SPECIFIC_ROP
246 #undef T
247 #undef T_1BIT
248 #undef T_USED
249 #undef T_CONST
250 #undef T_TRANS
251 #undef TEMPLATE_NAME
252