1 /* Copyright (C) 2001-2019 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.,  1305 Grant Avenue - Suite 200, Novato,
13    CA 94945, 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  */
43 
44 #if defined(TEMPLATE_NAME)
45 
46 #ifdef SPECIFIC_ROP
47 #if rop3_uses_S(SPECIFIC_ROP)
48 #define S_USED
49 #endif
50 #if rop3_uses_T(SPECIFIC_ROP)
51 #define T_USED
52 #endif
53 #else /* !SPECIFIC_ROP */
54 #define S_USED
55 #define T_USED
56 #endif /* SPECIFIC_ROP */
57 
58 #ifndef S_USED
59 #undef S_1BIT
60 #endif /* defined(S_USED) */
61 #ifndef T_USED
62 #undef T_1BIT
63 #endif /* defined(T_USED) */
64 
65 #define GET24(ptr)\
66   (((rop_operand)(ptr)[0] << 16) | ((rop_operand)(ptr)[1] << 8) | (ptr)[2])
67 #define PUT24(ptr, pixel)\
68   (ptr)[0] = (byte)((pixel) >> 16),\
69   (ptr)[1] = (byte)((uint)(pixel) >> 8),\
70   (ptr)[2] = (byte)(pixel)
71 
72 #if defined(S_USED) && !defined(S_CONST)
73 #define FETCH_S      do { S = GET24(s); s += 3; } while (0==1)
74 #else /* !defined(S_USED) || defined(S_CONST) */
75 #define FETCH_S
76 #endif /* !defined(S_USED) || defined(S_CONST) */
77 
78 #if defined(T_USED) && !defined(T_CONST)
79 #define FETCH_T      do { T = GET24(t); t += 3; } while (0 == 1)
80 #else /* !defined(T_USED) || defined(T_CONST) */
81 #define FETCH_T
82 #endif /* !defined(T_USED) || defined(T_CONST) */
83 
TEMPLATE_NAME(rop_run_op * op,byte * d,int len)84 static void TEMPLATE_NAME(rop_run_op *op, byte *d, int len)
85 {
86 #ifndef SPECIFIC_CODE
87     rop_proc     proc = rop_proc_table[lop_rop(op->rop)];
88 #define SPECIFIC_CODE(OUT_, D_,S_,T_) OUT_ = proc(D_,S_,T_)
89 #endif /* !defined(SPECIFIC_CODE) */
90 #ifdef S_USED
91 #ifdef S_CONST
92     rop_operand  S = op->s.c;
93 #else /* !defined(S_CONST) */
94     const byte  *s = op->s.b.ptr;
95 #endif /* !defined(S_CONST) */
96 #ifdef S_1BIT
97     int          sroll;
98     rop_operand  sc[2];
99 #endif /* S_1BIT */
100 #else /* !defined(S_USED) */
101 #define S 0
102 #undef S_CONST
103 #endif /* !defined(S_USED) */
104 #ifdef T_USED
105 #ifdef T_CONST
106     rop_operand  T = op->t.c;
107 #else /* !defined(T_CONST) */
108     const byte  *t = op->t.b.ptr;
109 #endif /* !defined(T_CONST) */
110 #ifdef T_1BIT
111     int          troll;
112     rop_operand  tc[2];
113 #endif /* T_1BIT */
114 #else /* !defined(T_USED) */
115 #define T 0
116 #undef T_CONST
117 #endif /* !defined(T_USED) */
118 
119 #ifdef S_1BIT
120 #if S_1BIT == MAYBE
121     if (op->flags & rop_s_1bit) {
122 #endif /* S_1BIT == MAYBE */
123         s += op->s.b.pos>>3;
124         sroll = 8-(op->s.b.pos & 7);
125         sc[0] = ((const gx_color_index *)op->scolors)[0];
126         sc[1] = ((const gx_color_index *)op->scolors)[1];
127 #if S_1BIT == MAYBE
128     } else
129         sroll = 0;
130 #endif /* S_1BIT == MAYBE */
131 #endif /* defined(S_1BIT) */
132 #ifdef T_1BIT
133 #if T_1BIT == MAYBE
134     if (op->flags & rop_t_1bit) {
135 #endif /* T_1BIT == MAYBE */
136         t += op->t.b.pos>>3;
137         troll = 8-(op->t.b.pos & 7);
138         tc[0] = ((const gx_color_index *)op->tcolors)[0];
139         tc[1] = ((const gx_color_index *)op->tcolors)[1];
140 #if T_1BIT == MAYBE
141     } else
142         troll = 0;
143 #endif /* T_1BIT == MAYBE */
144 #endif /* defined(T_1BIT) */
145     do {
146 #if defined(S_USED) && !defined(S_CONST)
147         rop_operand S;
148 #endif /* defined(S_USED) && !defined(S_CONST) */
149 #if defined(T_USED) && !defined(T_CONST)
150         rop_operand T;
151 #endif /* defined(T_USED) && !defined(T_CONST) */
152 #if defined(S_1BIT) && S_1BIT == MAYBE
153         if (sroll == 0) {
154 #endif /* defined(S_1BIT) && S_1BIT == MAYBE */
155 #if !defined(S_1BIT) || S_1BIT == MAYBE
156             FETCH_S;
157 #endif /* !defined(S_1BIT) || S_1BIT == MAYBE */
158 #if defined(S_1BIT) && S_1BIT == MAYBE
159         } else
160 #endif /* defined(S_1BIT) && S_1BIT == MAYBE */
161         {
162 #ifdef S_1BIT
163             --sroll;
164             S = sc[(*s >> sroll) & 1];
165             if (sroll == 0) {
166                 sroll = 8;
167                 s++;
168             }
169 #endif /* S_1BIT */
170         }
171 #if defined(T_1BIT) && T_1BIT == MAYBE
172         if (troll == 0) {
173 #endif /* defined(T_1BIT) && T_1BIT == MAYBE */
174 #if !defined(T_1BIT) || T_1BIT == MAYBE
175             FETCH_T;
176 #endif /* defined(T_1BIT) && T_1BIT == MAYBE */
177 #if defined(T_1BIT) && T_1BIT == MAYBE
178         } else
179 #endif /* defined(T_1BIT) && T_1BIT == MAYBE */
180         {
181 #ifdef T_1BIT
182             --troll;
183             T = tc[(*t >> troll) & 1];
184             if (troll == 0) {
185                 troll = 8;
186                 t++;
187             }
188 #endif /* T_1BIT */
189         }
190         {
191             rop_operand D;
192             SPECIFIC_CODE(D, GET24(d), S, T);
193             PUT24(d, D);
194         }
195         d += 3;
196     }
197     while (--len);
198 }
199 
200 #undef GET24
201 #undef PUT24
202 #undef FETCH_S
203 #undef FETCH_T
204 #undef S
205 #undef S_1BIT
206 #undef S_USED
207 #undef S_CONST
208 #undef SPECIFIC_CODE
209 #undef SPECIFIC_ROP
210 #undef T
211 #undef T_1BIT
212 #undef T_USED
213 #undef T_CONST
214 #undef TEMPLATE_NAME
215 
216 #else
217 int dummy;
218 #endif
219