/src/ghostpdl/base/gdevddrw.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright (C) 2001-2023 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., 39 Mesa Street, Suite 108A, San Francisco, |
13 | | CA 94129, USA, for further information. |
14 | | */ |
15 | | |
16 | | /* Default polygon and image drawing device procedures */ |
17 | | #include "math_.h" |
18 | | #include "memory_.h" |
19 | | #include "stdint_.h" |
20 | | #include "gx.h" |
21 | | #include "gpcheck.h" |
22 | | #include "gserrors.h" |
23 | | #include "gsrect.h" |
24 | | #include "gxfixed.h" |
25 | | #include "gxmatrix.h" |
26 | | #include "gxdcolor.h" |
27 | | #include "gxdevice.h" |
28 | | #include "gxiparam.h" |
29 | | #include "gxgstate.h" |
30 | | #include "gxhldevc.h" |
31 | | #include "gdevddrw.h" |
32 | | /* |
33 | | #include "gxdtfill.h" - Do not remove this comment. |
34 | | "gxdtfill.h" is included below. |
35 | | */ |
36 | | |
37 | | #define SWAP(a, b, t)\ |
38 | 73.4M | (t = a, a = b, b = t) |
39 | | |
40 | | /* ---------------- Polygon and line drawing ---------------- */ |
41 | | |
42 | | /* Define the 'remainder' analogue of fixed_mult_quo. */ |
43 | | static fixed |
44 | | fixed_mult_rem(fixed a, fixed b, fixed c) |
45 | 38.9M | { |
46 | | /* All kinds of truncation may happen here, but it's OK. */ |
47 | 38.9M | return a * b - fixed_mult_quo(a, b, c) * c; |
48 | 38.9M | } |
49 | | |
50 | | /* |
51 | | * The trapezoid fill algorithm uses trap_line structures to keep track of |
52 | | * the left and right edges during the Bresenham loop. |
53 | | */ |
54 | | typedef struct trap_line_s { |
55 | | /* |
56 | | * h is the y extent of the line (edge.end.y - edge.start.y). |
57 | | * We know h > 0. |
58 | | */ |
59 | | fixed h; |
60 | | /* |
61 | | * The dx/dy ratio for the line is di + df/h. |
62 | | * (The quotient refers to the l.s.b. of di, not fixed_1.) |
63 | | * We know 0 <= df < h. |
64 | | */ |
65 | | int di; |
66 | | fixed df; |
67 | | /* |
68 | | * The intersection of the line with a scan line is x + xf/h + 1. |
69 | | * (The 1 refers to the least significant bit of x, not fixed_1; |
70 | | * similarly, the quotient refers to the l.s.b. of x.) |
71 | | * We know -h <= xf < 0. |
72 | | * |
73 | | * This rational value preciselly represents the mathematical line |
74 | | * (with no machine arithmetic error). |
75 | | * |
76 | | * Note that the fractional part is negative to simplify |
77 | | * some conditions in the Bresenham algorithm. |
78 | | * Due to that some expressions are inobvious. |
79 | | * We believe that it's a kind of archaic |
80 | | * for the modern hyperthreading architecture, |
81 | | * we still keep it because the code passed a huge testing |
82 | | * on various platforms. |
83 | | */ |
84 | | fixed x, xf; |
85 | | /* |
86 | | * We increment (x,xf) by (ldi,ldf) after each scan line. |
87 | | * (ldi,ldf) is just (di,df) converted to fixed point. |
88 | | * We know 0 <= ldf < h. |
89 | | */ |
90 | | fixed ldi, ldf; |
91 | | } trap_line; |
92 | | |
93 | | /* |
94 | | * The linear color trapezoid fill algorithm uses trap_color structures to keep track of |
95 | | * the color change during the Bresenham loop. |
96 | | */ |
97 | | typedef struct trap_gradient_s { |
98 | | frac31 *c; /* integer part of the color in frac32 units. */ |
99 | | int32_t *f; /* the fraction part numerator */ |
100 | | int32_t *num; /* the gradient numerator */ |
101 | | int32_t den; /* color gradient denominator */ |
102 | | } trap_gradient; |
103 | | |
104 | | /* |
105 | | * Compute the di and df members of a trap_line structure. The x extent |
106 | | * (edge.end.x - edge.start.x) is a parameter; the y extent (h member) |
107 | | * has already been set. Also adjust x for the initial y. |
108 | | */ |
109 | | static inline void |
110 | | compute_dx(trap_line *tl, fixed xd, fixed ys) |
111 | 220M | { |
112 | 220M | fixed h = tl->h; |
113 | 220M | int di; |
114 | | |
115 | 220M | if (xd >= 0) { |
116 | 89.6M | if (xd < h) |
117 | 39.6M | tl->di = 0, tl->df = xd; |
118 | 49.9M | else { |
119 | 49.9M | tl->di = di = (int)(xd / h); |
120 | 49.9M | tl->df = xd - di * h; |
121 | 49.9M | tl->x += ys * di; |
122 | 49.9M | } |
123 | 130M | } else { |
124 | 130M | if ((tl->df = xd + h) >= 0 /* xd >= -h */) |
125 | 81.2M | tl->di = -1, tl->x -= ys; |
126 | 49.6M | else { |
127 | 49.6M | tl->di = di = (int)((xd + 1) / h - 1); |
128 | 49.6M | tl->df = xd - di * h; |
129 | 49.6M | tl->x += ys * di; |
130 | 49.6M | } |
131 | 130M | } |
132 | 220M | } |
133 | | |
134 | 670M | #define YMULT_LIMIT (max_fixed / fixed_1) |
135 | | |
136 | | /* Compute ldi, ldf, and xf similarly. */ |
137 | | static inline void |
138 | | compute_ldx(trap_line *tl, fixed ys) |
139 | 275M | { |
140 | 275M | int di = tl->di; |
141 | 275M | fixed df = tl->df; |
142 | 275M | fixed h = tl->h; |
143 | | |
144 | 275M | if ( df < YMULT_LIMIT ) { |
145 | 275M | if ( df == 0 ) /* vertical edge, worth checking for */ |
146 | 63.0M | tl->ldi = int2fixed(di), tl->ldf = 0, tl->xf = -h; |
147 | 212M | else { |
148 | 212M | tl->ldi = int2fixed(di) + int2fixed(df) / h; |
149 | 212M | tl->ldf = int2fixed(df) % h; |
150 | 212M | tl->xf = |
151 | 212M | (ys < fixed_1 ? ys * df % h : fixed_mult_rem(ys, df, h)) - h; |
152 | 212M | } |
153 | 275M | } |
154 | 147k | else { |
155 | 147k | tl->ldi = int2fixed(di) + fixed_mult_quo(fixed_1, df, h); |
156 | 147k | tl->ldf = fixed_mult_rem(fixed_1, df, h); |
157 | 147k | tl->xf = fixed_mult_rem(ys, df, h) - h; |
158 | 147k | } |
159 | 275M | } |
160 | | |
161 | | static inline int |
162 | | init_gradient(trap_gradient *g, const gs_fill_attributes *fa, |
163 | | const gs_linear_color_edge *e, const gs_linear_color_edge *e1, |
164 | | const trap_line *l, fixed ybot, int num_components) |
165 | 93.7M | { |
166 | 93.7M | int i; |
167 | 93.7M | int64_t c; |
168 | 93.7M | int32_t d; |
169 | | |
170 | 93.7M | if (e->c1 == NULL || e->c0 == NULL) |
171 | 7.70M | g->den = 0; /* A wedge - the color is axial along another edge. */ |
172 | 86.0M | else { |
173 | 86.0M | bool ends_from_fa = (e1->c1 == NULL || e1->c0 == NULL); |
174 | | |
175 | 86.0M | if (ends_from_fa) |
176 | 7.70M | g->den = fa->yend - fa->ystart; |
177 | 78.3M | else { |
178 | 78.3M | g->den = e->end.y - e->start.y; |
179 | 78.3M | if (g->den != l->h) |
180 | 0 | return_error(gs_error_unregistered); /* Must not happen. */ |
181 | 78.3M | } |
182 | 330M | for (i = 0; i < num_components; i++) { |
183 | 244M | g->num[i] = e->c1[i] - e->c0[i]; |
184 | 244M | c = (int64_t)g->num[i] * (uint32_t)(ybot - |
185 | 244M | (ends_from_fa ? fa->ystart : e->start.y)); |
186 | 244M | d = (int32_t)(c / g->den); |
187 | 244M | g->c[i] = e->c0[i] + d; |
188 | 244M | c -= (int64_t)d * g->den; |
189 | 244M | if (c < 0) { |
190 | 68.7M | g->c[i]--; |
191 | 68.7M | c += g->den; |
192 | 68.7M | } |
193 | 244M | g->f[i] = (int32_t)c; |
194 | 244M | } |
195 | 86.0M | } |
196 | 93.7M | return 0; |
197 | 93.7M | } |
198 | | |
199 | | static inline void |
200 | | step_gradient(trap_gradient *g, int num_components) |
201 | 917M | { |
202 | 917M | int i; |
203 | | |
204 | 917M | if (g->den == 0) |
205 | 102M | return; |
206 | 2.98G | for (i = 0; i < num_components; i++) { |
207 | 2.16G | int64_t fc = g->f[i] + (int64_t)g->num[i] * fixed_1; |
208 | 2.16G | int32_t fc32; |
209 | | |
210 | 2.16G | g->c[i] += (int32_t)(fc / g->den); |
211 | 2.16G | fc32 = (int32_t)(fc - fc / g->den * g->den); |
212 | 2.16G | if (fc32 < 0) { |
213 | 625M | fc32 += g->den; |
214 | 625M | g->c[i]--; |
215 | 625M | } |
216 | 2.16G | g->f[i] = fc32; |
217 | 2.16G | } |
218 | 814M | } |
219 | | |
220 | | static inline bool |
221 | | check_gradient_overflow(const gs_linear_color_edge *le, const gs_linear_color_edge *re) |
222 | 76.9M | { |
223 | 76.9M | if (le->c1 == NULL || re->c1 == NULL) { |
224 | | /* A wedge doesn't use a gradient by X. */ |
225 | 8.67M | return false; |
226 | 68.2M | } else { |
227 | | /* Check whether set_x_gradient, fill_linear_color_scanline can overflow. |
228 | | |
229 | | dev_proc(dev, fill_linear_color_scanline) can perform its computation in 32-bit fractions, |
230 | | so we assume it never overflows. Devices which implement it with no this |
231 | | assumption must implement the check in gx_default_fill_linear_color_trapezoid, |
232 | | gx_default_fill_linear_color_triangle with a function other than this one. |
233 | | |
234 | | Since set_x_gradient perform computations in int64_t, which provides 63 bits |
235 | | while multiplying a 32-bits color value to a coordinate, |
236 | | we must restrict the X span with 63 - 32 = 31 bits. |
237 | | */ |
238 | 68.2M | int32_t xl = min(le->start.x, le->end.x); |
239 | 68.2M | int32_t xr = min(re->start.x, re->end.x); |
240 | | /* The pixel span boundaries : */ |
241 | 68.2M | return arith_rshift_1(xr) - arith_rshift_1(xl) >= 0x3FFFFFFE; |
242 | 68.2M | } |
243 | 76.9M | } |
244 | | |
245 | | static inline int |
246 | | set_x_gradient_nowedge(trap_gradient *xg, const trap_gradient *lg, const trap_gradient *rg, |
247 | | const trap_line *l, const trap_line *r, int il, int ir, int num_components) |
248 | 61.6M | { |
249 | | /* Ignoring the ending coordinats fractions, |
250 | | so the gridient is slightly shifted to the left (in <1 'fixed' unit). */ |
251 | 61.6M | int32_t xl = l->x - (l->xf == -l->h ? 1 : 0) - fixed_half; /* Revert the GX_FILL_TRAPEZOID shift. */ |
252 | 61.6M | int32_t xr = r->x - (r->xf == -r->h ? 1 : 0) - fixed_half; /* Revert the GX_FILL_TRAPEZOID shift. */ |
253 | | /* The pixel span boundaries : */ |
254 | 61.6M | int32_t x0 = int2fixed(il) + fixed_half; /* Shift to the pixel center. */ |
255 | 61.6M | int32_t x1 = int2fixed(ir) - fixed_half; /* The center of the last pixel to paint. */ |
256 | 61.6M | int i; |
257 | | |
258 | | # ifdef DEBUG |
259 | | if (arith_rshift_1(xr) - arith_rshift_1(xl) >= 0x3FFFFFFE) /* Can overflow ? */ |
260 | | return_error(gs_error_unregistered); /* Must not happen. */ |
261 | | # endif |
262 | | /* We cannot compute the color of the 'ir' pixel |
263 | | because it can overflow 'c1' due to the pixel ir center |
264 | | may be greater that r->x . |
265 | | Therefore we base the proportion on the pixel index ir-1 (see comment to 'x1'). |
266 | | Debugged with CET 12-14O.PS SpecialTestJ02Test12. |
267 | | */ |
268 | 61.6M | xg->den = fixed2int(x1 - x0); |
269 | 61.6M | if (xg->den <= 0) { |
270 | | /* The span contains a single pixel, will construct a degenerate gradient. */ |
271 | 31.1M | xg->den = 1; /* Safety (against zerodivide). */ |
272 | 31.1M | } |
273 | 233M | for (i = 0; i < num_components; i++) { |
274 | | /* Ignoring the ending colors fractions, |
275 | | so the color gets a slightly smaller value |
276 | | (in <1 'frac31' unit), but it's not important due to |
277 | | the further conversion to [0, 1 << cinfo->comp_bits[j]], |
278 | | which drops the fraction anyway. */ |
279 | 171M | int32_t cl = lg->c[i]; |
280 | 171M | int32_t cr = rg->c[i]; |
281 | 171M | int32_t c0 = (int32_t)(cl + ((int64_t)cr - cl) * (x0 - xl) / (xr - xl)); |
282 | 171M | int32_t c1 = (int32_t)(cl + ((int64_t)cr - cl) * (x1 - xl) / (xr - xl)); |
283 | | |
284 | 171M | xg->c[i] = c0; |
285 | 171M | xg->f[i] = 0; /* Insufficient bits to compute it better. |
286 | | The color so the color gets a slightly smaller value |
287 | | (in <1 'frac31' unit), but it's not important due to |
288 | | the further conversion to [0, 1 << cinfo->comp_bits[j]], |
289 | | which drops the fraction anyway. |
290 | | So setting 0 appears pretty good and fast. */ |
291 | 171M | xg->num[i] = c1 - c0; |
292 | 171M | } |
293 | 61.6M | return 0; |
294 | 61.6M | } |
295 | | |
296 | | static inline int |
297 | | set_x_gradient(trap_gradient *xg, const trap_gradient *lg, const trap_gradient *rg, |
298 | | const trap_line *l, const trap_line *r, int il, int ir, int num_components) |
299 | 130M | { |
300 | 130M | if (lg->den == 0 || rg->den == 0) { |
301 | | /* A wedge doesn't use a gradient by X. */ |
302 | 69.3M | int i; |
303 | | |
304 | 69.3M | xg->den = 1; |
305 | 270M | for (i = 0; i < num_components; i++) { |
306 | 201M | xg->c[i] = (lg->den == 0 ? rg->c[i] : lg->c[i]); |
307 | 201M | xg->f[i] = 0; /* Compatible to set_x_gradient_nowedge. */ |
308 | 201M | xg->num[i] = 0; |
309 | 201M | } |
310 | 69.3M | return 0; |
311 | 69.3M | } else |
312 | 61.6M | return set_x_gradient_nowedge(xg, lg, rg, l, r, il, ir, num_components); |
313 | 130M | } |
314 | | |
315 | | /* |
316 | | * Fill a trapezoid. |
317 | | * Since we need several statically defined variants of this algorithm, |
318 | | * we stored it in gxdtfill.h and include it configuring with |
319 | | * macros defined here. |
320 | | */ |
321 | 4.61G | #define LINEAR_COLOR 0 /* Common for shading variants. */ |
322 | | #define EDGE_TYPE gs_fixed_edge /* Common for non-shading variants. */ |
323 | | #define FILL_ATTRS gs_logical_operation_t /* Common for non-shading variants. */ |
324 | | |
325 | | #define GX_FILL_TRAPEZOID static int gx_fill_trapezoid_as_fd |
326 | | #define CONTIGUOUS_FILL 0 |
327 | 49.9M | #define SWAP_AXES 1 |
328 | 49.9M | #define FILL_DIRECT 1 |
329 | | #include "gxdtfill.h" |
330 | | #undef GX_FILL_TRAPEZOID |
331 | | #undef CONTIGUOUS_FILL |
332 | | #undef SWAP_AXES |
333 | | #undef FILL_DIRECT |
334 | | |
335 | | #define GX_FILL_TRAPEZOID static int gx_fill_trapezoid_as_nd |
336 | | #define CONTIGUOUS_FILL 0 |
337 | 306M | #define SWAP_AXES 1 |
338 | 306M | #define FILL_DIRECT 0 |
339 | | #include "gxdtfill.h" |
340 | | #undef GX_FILL_TRAPEZOID |
341 | | #undef CONTIGUOUS_FILL |
342 | | #undef SWAP_AXES |
343 | | #undef FILL_DIRECT |
344 | | |
345 | | #define GX_FILL_TRAPEZOID static int gx_fill_trapezoid_ns_fd |
346 | | #define CONTIGUOUS_FILL 0 |
347 | 543M | #define SWAP_AXES 0 |
348 | 543M | #define FILL_DIRECT 1 |
349 | | #include "gxdtfill.h" |
350 | | #undef GX_FILL_TRAPEZOID |
351 | | #undef CONTIGUOUS_FILL |
352 | | #undef SWAP_AXES |
353 | | #undef FILL_DIRECT |
354 | | |
355 | | #define GX_FILL_TRAPEZOID static int gx_fill_trapezoid_ns_nd |
356 | | #define CONTIGUOUS_FILL 0 |
357 | 1.27G | #define SWAP_AXES 0 |
358 | 1.27G | #define FILL_DIRECT 0 |
359 | | #include "gxdtfill.h" |
360 | | #undef GX_FILL_TRAPEZOID |
361 | | #undef CONTIGUOUS_FILL |
362 | | #undef SWAP_AXES |
363 | | #undef FILL_DIRECT |
364 | | |
365 | | #define GX_FILL_TRAPEZOID int gx_fill_trapezoid_cf_fd |
366 | | #define CONTIGUOUS_FILL 1 |
367 | 0 | #define SWAP_AXES 0 |
368 | 0 | #define FILL_DIRECT 1 |
369 | | #include "gxdtfill.h" |
370 | | #undef GX_FILL_TRAPEZOID |
371 | | #undef CONTIGUOUS_FILL |
372 | | #undef SWAP_AXES |
373 | | #undef FILL_DIRECT |
374 | | |
375 | | #define GX_FILL_TRAPEZOID int gx_fill_trapezoid_cf_nd |
376 | | #define CONTIGUOUS_FILL 1 |
377 | 0 | #define SWAP_AXES 0 |
378 | 0 | #define FILL_DIRECT 0 |
379 | | #include "gxdtfill.h" |
380 | | #undef GX_FILL_TRAPEZOID |
381 | | #undef CONTIGUOUS_FILL |
382 | | #undef SWAP_AXES |
383 | | #undef FILL_DIRECT |
384 | | |
385 | | #undef EDGE_TYPE |
386 | | #undef LINEAR_COLOR |
387 | | #undef FILL_ATTRS |
388 | | |
389 | 505M | #define LINEAR_COLOR 1 /* Common for shading variants. */ |
390 | | #define EDGE_TYPE gs_linear_color_edge /* Common for shading variants. */ |
391 | | #define FILL_ATTRS const gs_fill_attributes * /* Common for non-shading variants. */ |
392 | | |
393 | | #define GX_FILL_TRAPEZOID static int gx_fill_trapezoid_ns_lc |
394 | | #define CONTIGUOUS_FILL 0 |
395 | | #define SWAP_AXES 0 |
396 | 13 | #define FILL_DIRECT 1 |
397 | | #include "gxdtfill.h" |
398 | | #undef GX_FILL_TRAPEZOID |
399 | | #undef CONTIGUOUS_FILL |
400 | | #undef SWAP_AXES |
401 | | #undef FILL_DIRECT |
402 | | |
403 | | #define GX_FILL_TRAPEZOID static int gx_fill_trapezoid_as_lc |
404 | | #define CONTIGUOUS_FILL 0 |
405 | | #define SWAP_AXES 1 |
406 | 4 | #define FILL_DIRECT 1 |
407 | | #include "gxdtfill.h" |
408 | | #undef GX_FILL_TRAPEZOID |
409 | | #undef CONTIGUOUS_FILL |
410 | | #undef SWAP_AXES |
411 | | #undef FILL_DIRECT |
412 | | |
413 | | #undef EDGE_TYPE |
414 | | #undef LINEAR_COLOR |
415 | | #undef FILL_ATTRS |
416 | | |
417 | | int |
418 | | gx_default_fill_trapezoid(gx_device * dev, const gs_fixed_edge * left, |
419 | | const gs_fixed_edge * right, fixed ybot, fixed ytop, bool swap_axes, |
420 | | const gx_device_color * pdevc, gs_logical_operation_t lop) |
421 | 219M | { |
422 | 219M | bool fill_direct = color_writes_pure(pdevc, lop); |
423 | | |
424 | 219M | if (swap_axes) { |
425 | 16.8M | if (dev->width != 0 && dev->non_strict_bounds == 0) |
426 | 16.7M | { |
427 | | /* Some devices init max->width to be int_max, which overflows when converted to fixed. */ |
428 | 16.7M | int dw = dev->width > max_int_in_fixed ? max_int_in_fixed : dev->width; |
429 | 16.7M | if (ytop < 0) |
430 | 2.57M | return 0; |
431 | 14.2M | if (ybot < 0) |
432 | 2.27k | ybot = 0; |
433 | 14.2M | dw = int2fixed(dw); |
434 | 14.2M | if (ybot > dw) |
435 | 6.16M | return 0; |
436 | 8.04M | if (ytop > dw) |
437 | 35.4k | ytop = dw; |
438 | 8.04M | } |
439 | | |
440 | 8.12M | if (fill_direct) |
441 | 4.05M | return gx_fill_trapezoid_as_fd(dev, left, right, ybot, ytop, 0, pdevc, lop); |
442 | 4.07M | else |
443 | 4.07M | return gx_fill_trapezoid_as_nd(dev, left, right, ybot, ytop, 0, pdevc, lop); |
444 | 202M | } else { |
445 | 202M | if (dev->height != 0 && dev->non_strict_bounds == 0) |
446 | 197M | { |
447 | | /* Some devices init max->height to be int_max, which overflows when converted to fixed. */ |
448 | 197M | int dh = dev->height > max_int_in_fixed ? max_int_in_fixed : dev->height; |
449 | 197M | if (ytop < 0) |
450 | 26.7M | return 0; |
451 | 171M | if (ybot < 0) |
452 | 411k | ybot = 0; |
453 | 171M | dh = int2fixed(dh); |
454 | 171M | if (ybot > dh) |
455 | 38.7M | return 0; |
456 | 132M | if (ytop > dh) |
457 | 471k | ytop = dh; |
458 | 132M | } |
459 | | |
460 | 136M | if (fill_direct) |
461 | 52.3M | return gx_fill_trapezoid_ns_fd(dev, left, right, ybot, ytop, 0, pdevc, lop); |
462 | 84.4M | else |
463 | 84.4M | return gx_fill_trapezoid_ns_nd(dev, left, right, ybot, ytop, 0, pdevc, lop); |
464 | 136M | } |
465 | 219M | } |
466 | | |
467 | | static inline int |
468 | | fill_linear_color_trapezoid_nocheck(gx_device *dev, const gs_fill_attributes *fa, |
469 | | const gs_linear_color_edge *le, const gs_linear_color_edge *re) |
470 | 76.9M | { |
471 | 76.9M | fixed y02 = max(le->start.y, re->start.y), ymin = max(y02, fa->clip->p.y); |
472 | 76.9M | fixed y13 = min(le->end.y, re->end.y), ymax = min(y13, fa->clip->q.y); |
473 | 76.9M | int code; |
474 | | |
475 | 76.9M | code = (fa->swap_axes ? gx_fill_trapezoid_as_lc : gx_fill_trapezoid_ns_lc)(dev, |
476 | 76.9M | le, re, ymin, ymax, 0, NULL, fa); |
477 | 76.9M | if (code < 0) |
478 | 17 | return code; |
479 | 76.9M | return !code; |
480 | 76.9M | } |
481 | | |
482 | | /* Fill a trapezoid with a linear color. |
483 | | [p0 : p1] - left edge, from bottom to top. |
484 | | [p2 : p3] - right edge, from bottom to top. |
485 | | The filled area is within Y-spans of both edges. |
486 | | |
487 | | This implemetation actually handles a bilinear color, |
488 | | in which the generatrix keeps a parallelizm to the X axis. |
489 | | In general a bilinear function doesn't keep the generatrix parallelizm, |
490 | | so the caller must decompose/approximate such functions. |
491 | | |
492 | | Return values : |
493 | | 1 - success; |
494 | | 0 - Too big. The area isn't filled. The client must decompose the area. |
495 | | <0 - error. |
496 | | */ |
497 | | int |
498 | | gx_default_fill_linear_color_trapezoid(gx_device *dev, const gs_fill_attributes *fa, |
499 | | const gs_fixed_point *p0, const gs_fixed_point *p1, |
500 | | const gs_fixed_point *p2, const gs_fixed_point *p3, |
501 | | const frac31 *c0, const frac31 *c1, |
502 | | const frac31 *c2, const frac31 *c3) |
503 | 11.8M | { |
504 | 11.8M | gs_linear_color_edge le, re; |
505 | | |
506 | 11.8M | le.start = *p0; |
507 | 11.8M | le.end = *p1; |
508 | 11.8M | le.c0 = c0; |
509 | 11.8M | le.c1 = c1; |
510 | 11.8M | le.clip_x = fa->clip->p.x; |
511 | 11.8M | re.start = *p2; |
512 | 11.8M | re.end = *p3; |
513 | 11.8M | re.c0 = c2; |
514 | 11.8M | re.c1 = c3; |
515 | 11.8M | re.clip_x = fa->clip->q.x; |
516 | 11.8M | if (check_gradient_overflow(&le, &re)) |
517 | 0 | return 0; |
518 | 11.8M | return fill_linear_color_trapezoid_nocheck(dev, fa, &le, &re); |
519 | 11.8M | } |
520 | | |
521 | | static inline int |
522 | | fill_linear_color_triangle(gx_device *dev, const gs_fill_attributes *fa, |
523 | | const gs_fixed_point *p0, const gs_fixed_point *p1, |
524 | | const gs_fixed_point *p2, |
525 | | const frac31 *c0, const frac31 *c1, const frac31 *c2) |
526 | 35.7M | { /* p0 must be the lowest vertex. */ |
527 | 35.7M | int code; |
528 | 35.7M | gs_linear_color_edge e0, e1, e2; |
529 | | |
530 | 35.7M | if (p0->y == p1->y) |
531 | 1.38M | return gx_default_fill_linear_color_trapezoid(dev, fa, p0, p2, p1, p2, c0, c2, c1, c2); |
532 | 34.3M | if (p1->y == p2->y) |
533 | 1.81M | return gx_default_fill_linear_color_trapezoid(dev, fa, p0, p2, p0, p1, c0, c2, c0, c1); |
534 | 32.5M | e0.start = *p0; |
535 | 32.5M | e0.end = *p2; |
536 | 32.5M | e0.c0 = c0; |
537 | 32.5M | e0.c1 = c2; |
538 | 32.5M | e0.clip_x = fa->clip->p.x; |
539 | 32.5M | e1.start = *p0; |
540 | 32.5M | e1.end = *p1; |
541 | 32.5M | e1.c0 = c0; |
542 | 32.5M | e1.c1 = c1; |
543 | 32.5M | e1.clip_x = fa->clip->q.x; |
544 | 32.5M | if (p0->y < p1->y && p1->y < p2->y) { |
545 | 15.8M | e2.start = *p1; |
546 | 15.8M | e2.end = *p2; |
547 | 15.8M | e2.c0 = c1; |
548 | 15.8M | e2.c1 = c2; |
549 | 15.8M | e2.clip_x = fa->clip->q.x; |
550 | 15.8M | if (check_gradient_overflow(&e0, &e1)) |
551 | 0 | return 0; |
552 | 15.8M | if (check_gradient_overflow(&e0, &e2)) |
553 | 0 | return 0; |
554 | 15.8M | code = fill_linear_color_trapezoid_nocheck(dev, fa, &e0, &e1); |
555 | 15.8M | if (code <= 0) /* Sic! */ |
556 | 0 | return code; |
557 | 15.8M | return fill_linear_color_trapezoid_nocheck(dev, fa, &e0, &e2); |
558 | 16.6M | } else { /* p0->y < p2->y && p2->y < p1->y */ |
559 | 16.6M | e2.start = *p2; |
560 | 16.6M | e2.end = *p1; |
561 | 16.6M | e2.c0 = c2; |
562 | 16.6M | e2.c1 = c1; |
563 | 16.6M | e2.clip_x = fa->clip->q.x; |
564 | 16.6M | if (check_gradient_overflow(&e0, &e1)) |
565 | 0 | return 0; |
566 | 16.6M | if (check_gradient_overflow(&e2, &e1)) |
567 | 0 | return 0; |
568 | 16.6M | code = fill_linear_color_trapezoid_nocheck(dev, fa, &e0, &e1); |
569 | 16.6M | if (code <= 0) /* Sic! */ |
570 | 0 | return code; |
571 | 16.6M | return fill_linear_color_trapezoid_nocheck(dev, fa, &e2, &e1); |
572 | 16.6M | } |
573 | 32.5M | } |
574 | | |
575 | | /* Fill a triangle with a linear color. */ |
576 | | int |
577 | | gx_default_fill_linear_color_triangle(gx_device *dev, const gs_fill_attributes *fa, |
578 | | const gs_fixed_point *p0, const gs_fixed_point *p1, |
579 | | const gs_fixed_point *p2, |
580 | | const frac31 *c0, const frac31 *c1, const frac31 *c2) |
581 | 35.7M | { |
582 | 35.7M | fixed dx1 = p1->x - p0->x, dy1 = p1->y - p0->y; |
583 | 35.7M | fixed dx2 = p2->x - p0->x, dy2 = p2->y - p0->y; |
584 | | |
585 | 35.7M | if ((int64_t)dx1 * dy2 < (int64_t)dx2 * dy1) { |
586 | 17.2M | const gs_fixed_point *p = p1; |
587 | 17.2M | const frac31 *c = c1; |
588 | | |
589 | 17.2M | p1 = p2; |
590 | 17.2M | p2 = p; |
591 | 17.2M | c1 = c2; |
592 | 17.2M | c2 = c; |
593 | 17.2M | } |
594 | 35.7M | if (p0->y <= p1->y && p0->y <= p2->y) |
595 | 16.6M | return fill_linear_color_triangle(dev, fa, p0, p1, p2, c0, c1, c2); |
596 | 19.1M | if (p1->y <= p0->y && p1->y <= p2->y) |
597 | 9.88M | return fill_linear_color_triangle(dev, fa, p1, p2, p0, c1, c2, c0); |
598 | 9.21M | else |
599 | 9.21M | return fill_linear_color_triangle(dev, fa, p2, p0, p1, c2, c0, c1); |
600 | 19.1M | } |
601 | | |
602 | | /* Fill a parallelogram whose points are p, p+a, p+b, and p+a+b. */ |
603 | | /* We should swap axes to get best accuracy, but we don't. */ |
604 | | /* We must be very careful to follow the center-of-pixel rule in all cases. */ |
605 | | int |
606 | | gx_default_fill_parallelogram(gx_device * dev, |
607 | | fixed px, fixed py, fixed ax, fixed ay, fixed bx, fixed by, |
608 | | const gx_device_color * pdevc, gs_logical_operation_t lop) |
609 | 81.6M | { |
610 | 81.6M | fixed t; |
611 | 81.6M | fixed qx, qy, ym; |
612 | 81.6M | dev_proc_fill_trapezoid((*fill_trapezoid)); |
613 | 81.6M | gs_fixed_edge left, right; |
614 | 81.6M | int code; |
615 | | |
616 | | /* Make a special fast check for rectangles. */ |
617 | 81.6M | if (PARALLELOGRAM_IS_RECT(ax, ay, bx, by)) { |
618 | 6.53M | gs_int_rect r; |
619 | | |
620 | 6.53M | INT_RECT_FROM_PARALLELOGRAM(&r, px, py, ax, ay, bx, by); |
621 | 6.53M | return gx_fill_rectangle_device_rop(r.p.x, r.p.y, r.q.x - r.p.x, |
622 | 6.53M | r.q.y - r.p.y, pdevc, dev, lop); |
623 | 6.53M | } |
624 | | /* |
625 | | * Not a rectangle. Ensure that the 'a' line is to the left of |
626 | | * the 'b' line. Testing ax <= bx is neither sufficient nor |
627 | | * necessary: in general, we need to compare the slopes. |
628 | | */ |
629 | | /* Ensure ay >= 0, by >= 0. */ |
630 | 75.1M | if (ay < 0) |
631 | 44.6M | px += ax, py += ay, ax = -ax, ay = -ay; |
632 | 75.1M | if (by < 0) |
633 | 16.6M | px += bx, py += by, bx = -bx, by = -by; |
634 | 75.1M | qx = px + ax + bx; |
635 | 75.1M | if ((ax ^ bx) < 0) { /* In this case, the test ax <= bx is sufficient. */ |
636 | 46.1M | if (ax > bx) |
637 | 9.48M | SWAP(ax, bx, t), SWAP(ay, by, t); |
638 | 46.1M | } else { /* |
639 | | * Compare the slopes. We know that ay >= 0, by >= 0, |
640 | | * and ax and bx have the same sign; the lines are in the |
641 | | * correct order iff |
642 | | * ay/ax >= by/bx, or |
643 | | * ay*bx >= by*ax |
644 | | * Eventually we can probably find a better way to test this, |
645 | | * without using floating point. |
646 | | */ |
647 | 29.0M | if ((double)ay * bx < (double)by * ax) |
648 | 14.7M | SWAP(ax, bx, t), SWAP(ay, by, t); |
649 | 29.0M | } |
650 | 75.1M | fill_trapezoid = dev_proc(dev, fill_trapezoid); |
651 | 75.1M | qy = py + ay + by; |
652 | 75.1M | left.start.x = right.start.x = px; |
653 | 75.1M | left.start.y = right.start.y = py; |
654 | 75.1M | left.end.x = px + ax; |
655 | 75.1M | left.end.y = py + ay; |
656 | 75.1M | right.end.x = px + bx; |
657 | 75.1M | right.end.y = py + by; |
658 | 75.1M | #define ROUNDED_SAME(p1, p2)\ |
659 | 225M | (fixed_pixround(p1) == fixed_pixround(p2)) |
660 | 75.1M | if (ay < by) { |
661 | 32.7M | if (!ROUNDED_SAME(py, left.end.y)) { |
662 | 4.61M | code = (*fill_trapezoid) (dev, &left, &right, py, left.end.y, |
663 | 4.61M | false, pdevc, lop); |
664 | 4.61M | if (code < 0) |
665 | 0 | return code; |
666 | 4.61M | } |
667 | 32.7M | left.start = left.end; |
668 | 32.7M | left.end.x = qx, left.end.y = qy; |
669 | 32.7M | ym = right.end.y; |
670 | 32.7M | if (!ROUNDED_SAME(left.start.y, ym)) { |
671 | 17.6M | code = (*fill_trapezoid) (dev, &left, &right, left.start.y, ym, |
672 | 17.6M | false, pdevc, lop); |
673 | 17.6M | if (code < 0) |
674 | 0 | return code; |
675 | 17.6M | } |
676 | 32.7M | right.start = right.end; |
677 | 32.7M | right.end.x = qx, right.end.y = qy; |
678 | 42.4M | } else { |
679 | 42.4M | if (!ROUNDED_SAME(py, right.end.y)) { |
680 | 6.25M | code = (*fill_trapezoid) (dev, &left, &right, py, right.end.y, |
681 | 6.25M | false, pdevc, lop); |
682 | 6.25M | if (code < 0) |
683 | 0 | return code; |
684 | 6.25M | } |
685 | 42.4M | right.start = right.end; |
686 | 42.4M | right.end.x = qx, right.end.y = qy; |
687 | 42.4M | ym = left.end.y; |
688 | 42.4M | if (!ROUNDED_SAME(right.start.y, ym)) { |
689 | 23.9M | code = (*fill_trapezoid) (dev, &left, &right, right.start.y, ym, |
690 | 23.9M | false, pdevc, lop); |
691 | 23.9M | if (code < 0) |
692 | 0 | return code; |
693 | 23.9M | } |
694 | 42.4M | left.start = left.end; |
695 | 42.4M | left.end.x = qx, left.end.y = qy; |
696 | 42.4M | } |
697 | 75.1M | if (!ROUNDED_SAME(ym, qy)) |
698 | 10.8M | return (*fill_trapezoid) (dev, &left, &right, ym, qy, |
699 | 10.8M | false, pdevc, lop); |
700 | 64.2M | else |
701 | 64.2M | return 0; |
702 | 75.1M | #undef ROUNDED_SAME |
703 | 75.1M | } |
704 | | |
705 | | /* Fill a triangle whose points are p, p+a, and p+b. */ |
706 | | /* We should swap axes to get best accuracy, but we don't. */ |
707 | | int |
708 | | gx_default_fill_triangle(gx_device * dev, |
709 | | fixed px, fixed py, fixed ax, fixed ay, fixed bx, fixed by, |
710 | | const gx_device_color * pdevc, gs_logical_operation_t lop) |
711 | 3.45M | { |
712 | 3.45M | fixed t; |
713 | 3.45M | fixed ym; |
714 | | |
715 | 3.45M | dev_proc_fill_trapezoid((*fill_trapezoid)) = |
716 | 3.45M | dev_proc(dev, fill_trapezoid); |
717 | 3.45M | gs_fixed_edge left, right; |
718 | 3.45M | int code; |
719 | | |
720 | | /* Ensure ay >= 0, by >= 0. */ |
721 | 3.45M | if (ay < 0) |
722 | 11.3k | px += ax, py += ay, bx -= ax, by -= ay, ax = -ax, ay = -ay; |
723 | 3.45M | if (by < 0) |
724 | 7.07k | px += bx, py += by, ax -= bx, ay -= by, bx = -bx, by = -by; |
725 | | /* Ensure ay <= by. */ |
726 | 3.45M | if (ay > by) |
727 | 8.43k | SWAP(ax, bx, t), SWAP(ay, by, t); |
728 | | /* |
729 | | * Make a special check for a flat bottom or top, |
730 | | * which we can handle with a single call on fill_trapezoid. |
731 | | */ |
732 | 3.45M | left.start.x = right.start.x = px; |
733 | 3.45M | left.start.y = right.start.y = py; |
734 | 3.45M | if (ay == 0) { |
735 | | /* Flat top */ |
736 | 1.52M | if (ax < 0) |
737 | 1.15k | left.start.x = px + ax; |
738 | 1.52M | else |
739 | 1.52M | right.start.x = px + ax; |
740 | 1.52M | left.end.x = right.end.x = px + bx; |
741 | 1.52M | left.end.y = right.end.y = py + by; |
742 | 1.52M | ym = py; |
743 | 1.92M | } else if (ay == by) { |
744 | | /* Flat bottom */ |
745 | 1.47M | if (ax < bx) |
746 | 1.46M | left.end.x = px + ax, right.end.x = px + bx; |
747 | 10.6k | else |
748 | 10.6k | left.end.x = px + bx, right.end.x = px + ax; |
749 | 1.47M | left.end.y = right.end.y = py + by; |
750 | 1.47M | ym = py; |
751 | 1.47M | } else { |
752 | 452k | ym = py + ay; |
753 | 452k | if (fixed_mult_quo(bx, ay, by) < ax) { |
754 | | /* The 'b' line is to the left of the 'a' line. */ |
755 | 64.9k | left.end.x = px + bx, left.end.y = py + by; |
756 | 64.9k | right.end.x = px + ax, right.end.y = py + ay; |
757 | 64.9k | code = (*fill_trapezoid) (dev, &left, &right, py, ym, |
758 | 64.9k | false, pdevc, lop); |
759 | 64.9k | right.start = right.end; |
760 | 64.9k | right.end = left.end; |
761 | 387k | } else { |
762 | | /* The 'a' line is to the left of the 'b' line. */ |
763 | 387k | left.end.x = px + ax, left.end.y = py + ay; |
764 | 387k | right.end.x = px + bx, right.end.y = py + by; |
765 | 387k | code = (*fill_trapezoid) (dev, &left, &right, py, ym, |
766 | 387k | false, pdevc, lop); |
767 | 387k | left.start = left.end; |
768 | 387k | left.end = right.end; |
769 | 387k | } |
770 | 452k | if (code < 0) |
771 | 0 | return code; |
772 | 452k | } |
773 | 3.45M | return (*fill_trapezoid) (dev, &left, &right, ym, right.end.y, |
774 | 3.45M | false, pdevc, lop); |
775 | 3.45M | } |
776 | | |
777 | | /* Draw a one-pixel-wide line. */ |
778 | | int |
779 | | gx_default_draw_thin_line(gx_device * dev, |
780 | | fixed fx0, fixed fy0, fixed fx1, fixed fy1, |
781 | | const gx_device_color * pdevc, gs_logical_operation_t lop, |
782 | | fixed adjustx, fixed adjusty) |
783 | 28.6M | { |
784 | 28.6M | int ix, iy, itox, itoy; |
785 | 28.6M | int epsilon; |
786 | | |
787 | 28.6M | return_if_interrupt(dev->memory); |
788 | | |
789 | | /* This function was updated in revision 10391 to fix problems with |
790 | | * mispositioned thin lines. This introduced a regression (see bug |
791 | | * 691030). The code was then reworked to behave in what we believe is |
792 | | * the correct manner, but this causes unacceptable problems with PCL |
793 | | * output. While the current PCL work is underway, we have therefore |
794 | | * amended this code to take note of the fill adjust values; if non- |
795 | | * zero (i.e. postscript) we do "the correct thing". If zero, we do |
796 | | * what we used to. |
797 | | * |
798 | | * The one case where this doesn't work is in the case where our PCL |
799 | | * implementation thickens lines slightly to try and approximate HP |
800 | | * printer behaviour. Here we do use a non-zero fill_adjust and hence |
801 | | * have differences; tests show that these are acceptable though. |
802 | | * |
803 | | * It is hoped that this difference in behaviour will be short lived. |
804 | | */ |
805 | | |
806 | 28.6M | epsilon = ((adjustx | adjusty) == 0 ? fixed_epsilon : 0); |
807 | | |
808 | 28.6M | { |
809 | 28.6M | fixed h = fy1 - fy0; |
810 | 28.6M | fixed w = fx1 - fx0; |
811 | 28.6M | fixed tf; |
812 | 28.6M | bool swap_axes; |
813 | 28.6M | gs_fixed_edge left, right; |
814 | | |
815 | 28.6M | if ((w < 0 ? -w : w) <= (h < 0 ? -h : h)) { |
816 | | /* A "mostly-vertical" line */ |
817 | 16.6M | if (h < 0) |
818 | 7.11M | SWAP(fx0, fx1, tf), SWAP(fy0, fy1, tf), |
819 | 7.11M | h = -h; |
820 | | /* So we are plotting a trapezoid with horizontal thin edges. |
821 | | * If we are drawing a non-axis aligned trap, then we check |
822 | | * for whether a triangular extension area on the end covers an |
823 | | * additional pixel centre; if so, we fill an extra pixel. |
824 | | * If we are drawing an axis aligned trap and fill adjust is 0, |
825 | | * then we shouldn't need to do this. |
826 | | * If we are drawing an axis aligned trap, and fill adjust is non |
827 | | * zero, then perform the check, but with a "butt cap" rather than |
828 | | * a "triangle cap" region. |
829 | | * See bug 687721 and bug 693212 for this history of this. |
830 | | */ |
831 | 16.6M | if (w == 0 && adjusty) { |
832 | 775k | int deltay; |
833 | 775k | deltay = int2fixed(fixed2int_var(fy1)) + fixed_half -fy1; |
834 | | |
835 | 775k | if ((deltay > 0) && (deltay <= fixed_half)) |
836 | 351k | { |
837 | 351k | int c = gx_fill_rectangle_device_rop(fixed2int_var(fx1), |
838 | 351k | fixed2int_var(fy1), |
839 | 351k | 1,1,pdevc,dev,lop); |
840 | 351k | if (c < 0) return c; |
841 | 351k | } |
842 | 775k | deltay = int2fixed(fixed2int_var(fy0)) + fixed_half -fy0; |
843 | | |
844 | 775k | if ((deltay < 0) && (deltay >= -fixed_half)) |
845 | 424k | { |
846 | 424k | int c = gx_fill_rectangle_device_rop(fixed2int_var(fx0), |
847 | 424k | fixed2int_var(fy0), |
848 | 424k | 1,1,pdevc,dev,lop); |
849 | 424k | if (c < 0) return c; |
850 | 424k | } |
851 | 15.8M | } else if (w != 0) { |
852 | 15.8M | int deltax, deltay; |
853 | 15.8M | deltay = int2fixed(fixed2int_var(fy1)) + fixed_half -fy1; |
854 | 15.8M | deltax = int2fixed(fixed2int_var(fx1)) + fixed_half -fx1; |
855 | | |
856 | 15.8M | if (deltax < 0) deltax=-deltax; |
857 | 15.8M | if ((deltay > 0) && (deltay <= fixed_half) && |
858 | 15.8M | (deltay+deltax <= fixed_half)) |
859 | 4.01M | { |
860 | 4.01M | int c = gx_fill_rectangle_device_rop(fixed2int_var(fx1), |
861 | 4.01M | fixed2int_var(fy1), |
862 | 4.01M | 1,1,pdevc,dev,lop); |
863 | 4.01M | if (c < 0) return c; |
864 | 4.01M | } |
865 | 15.8M | deltay = int2fixed(fixed2int_var(fy0)) + fixed_half -fy0; |
866 | 15.8M | deltax = int2fixed(fixed2int_var(fx0)) + fixed_half -fx0; |
867 | | |
868 | 15.8M | if (deltax < 0) deltax=-deltax; |
869 | 15.8M | if ((deltay < 0) && (deltay >= -fixed_half) && |
870 | 15.8M | (-deltay+deltax <= fixed_half)) |
871 | 3.88M | { |
872 | 3.88M | int c = gx_fill_rectangle_device_rop(fixed2int_var(fx0), |
873 | 3.88M | fixed2int_var(fy0), |
874 | 3.88M | 1,1,pdevc,dev,lop); |
875 | 3.88M | if (c < 0) return c; |
876 | 3.88M | } |
877 | 15.8M | } |
878 | | /* Can we treat it as a vertical rectangle? */ |
879 | 16.6M | ix = fixed2int_var(fx0-epsilon); |
880 | 16.6M | itox = fixed2int_var(fx1-epsilon); |
881 | 16.6M | if (itox == ix) { |
882 | | /* Figure out the start/height, allowing for our "covers |
883 | | * centre of pixel" rule. */ |
884 | 5.34M | iy = fixed2int_var(fy0+fixed_half-fixed_epsilon); |
885 | 5.34M | itoy = fixed2int_var(fy1+fixed_half-fixed_epsilon); |
886 | 5.34M | itoy = itoy - iy; |
887 | 5.34M | if (itoy <= 0) { |
888 | | /* Zero height; drawing this as a trapezoid wouldn't |
889 | | * fill any pixels, so just exit. */ |
890 | 758k | return 0; |
891 | 758k | } |
892 | 4.58M | return gx_fill_rectangle_device_rop(ix, iy, 1, itoy, |
893 | 5.34M | pdevc, dev, lop); |
894 | 5.34M | } |
895 | 11.3M | left.start.x = fx0 - fixed_half + fixed_epsilon - epsilon; |
896 | 11.3M | right.start.x = left.start.x + fixed_1; |
897 | 11.3M | left.end.x = fx1 - fixed_half + fixed_epsilon - epsilon; |
898 | 11.3M | right.end.x = left.end.x + fixed_1; |
899 | 11.3M | left.start.y = right.start.y = fy0; |
900 | 11.3M | left.end.y = right.end.y = fy1; |
901 | 11.3M | swap_axes = false; |
902 | 11.9M | } else { |
903 | | /* A "mostly-horizontal" line */ |
904 | 11.9M | if (w < 0) |
905 | 5.39M | SWAP(fx0, fx1, tf), SWAP(fy0, fy1, tf), |
906 | 5.39M | w = -w; |
907 | | /* So we are plotting a trapezoid with vertical thin edges |
908 | | * Check for whether a triangular extension area on the end |
909 | | * covers an additional pixel centre. */ |
910 | 11.9M | if (h == 0 && adjustx) { |
911 | 3.30M | int deltax; |
912 | 3.30M | deltax = int2fixed(fixed2int_var(fx1)) + fixed_half -fx1; |
913 | | |
914 | 3.30M | if ((deltax > 0) && (deltax <= fixed_half)) |
915 | 1.37M | { |
916 | 1.37M | int c = gx_fill_rectangle_device_rop(fixed2int_var(fx1), |
917 | 1.37M | fixed2int_var(fy1), |
918 | 1.37M | 1,1,pdevc,dev,lop); |
919 | 1.37M | if (c < 0) return c; |
920 | 1.37M | } |
921 | 3.30M | deltax = int2fixed(fixed2int_var(fx0)) + fixed_half -fx0; |
922 | | |
923 | 3.30M | if ((deltax < 0) && (deltax >= -fixed_half)) |
924 | 1.38M | { |
925 | 1.38M | int c = gx_fill_rectangle_device_rop(fixed2int_var(fx0), |
926 | 1.38M | fixed2int_var(fy0), |
927 | 1.38M | 1,1,pdevc,dev,lop); |
928 | 1.38M | if (c < 0) return c; |
929 | 1.38M | } |
930 | 8.65M | } else if (h != 0) { |
931 | 8.65M | int deltax, deltay; |
932 | 8.65M | deltax = int2fixed(fixed2int_var(fx1)) + fixed_half -fx1; |
933 | 8.65M | deltay = int2fixed(fixed2int_var(fy1)) + fixed_half -fy1; |
934 | | |
935 | 8.65M | if (deltay < 0) deltay=-deltay; |
936 | 8.65M | if ((deltax > 0) && (deltax <= fixed_half) && |
937 | 8.65M | (deltax+deltay <= fixed_half)) |
938 | 2.15M | { |
939 | 2.15M | int c = gx_fill_rectangle_device_rop(fixed2int_var(fx1), |
940 | 2.15M | fixed2int_var(fy1), |
941 | 2.15M | 1,1,pdevc,dev,lop); |
942 | 2.15M | if (c < 0) return c; |
943 | 2.15M | } |
944 | 8.65M | deltax = int2fixed(fixed2int_var(fx0)) + fixed_half -fx0; |
945 | 8.65M | deltay = int2fixed(fixed2int_var(fy0)) + fixed_half -fy0; |
946 | | |
947 | 8.65M | if (deltay < 0) deltay=-deltay; |
948 | 8.65M | if ((deltax < 0) && (deltax >= -fixed_half) && |
949 | 8.65M | (-deltax+deltay <= fixed_half)) |
950 | 2.14M | { |
951 | 2.14M | int c = gx_fill_rectangle_device_rop(fixed2int_var(fx0), |
952 | 2.14M | fixed2int_var(fy0), |
953 | 2.14M | 1,1,pdevc,dev,lop); |
954 | 2.14M | if (c < 0) return c; |
955 | 2.14M | } |
956 | 8.65M | } |
957 | | /* Can we treat this as a horizontal rectangle? */ |
958 | 11.9M | iy = fixed2int_var(fy0 - epsilon); |
959 | 11.9M | itoy = fixed2int_var(fy1 - epsilon); |
960 | 11.9M | if (itoy == iy) { |
961 | | /* Figure out the start/width, allowing for our "covers |
962 | | * centre of pixel" rule. */ |
963 | 5.20M | ix = fixed2int_var(fx0+fixed_half-fixed_epsilon); |
964 | 5.20M | itox = fixed2int_var(fx1+fixed_half-fixed_epsilon); |
965 | 5.20M | itox = itox - ix; |
966 | 5.20M | if (itox <= 0) { |
967 | | /* Zero width; drawing this as a trapezoid wouldn't |
968 | | * fill any pixels, so just exit. */ |
969 | 1.03M | return 0; |
970 | 1.03M | } |
971 | 4.16M | return gx_fill_rectangle_device_rop(ix, iy, itox, 1, |
972 | 5.20M | pdevc, dev, lop); |
973 | 5.20M | } |
974 | 6.75M | left.start.x = fy0 - fixed_half + fixed_epsilon - epsilon; |
975 | 6.75M | right.start.x = left.start.x + fixed_1; |
976 | 6.75M | left.end.x = fy1 - fixed_half + fixed_epsilon - epsilon; |
977 | 6.75M | right.end.x = left.end.x + fixed_1; |
978 | 6.75M | left.start.y = right.start.y = fx0; |
979 | 6.75M | left.end.y = right.end.y = fx1; |
980 | 6.75M | swap_axes = true; |
981 | 6.75M | } |
982 | 18.0M | return (*dev_proc(dev, fill_trapezoid)) (dev, &left, &right, |
983 | 18.0M | left.start.y, left.end.y, |
984 | 18.0M | swap_axes, pdevc, lop); |
985 | 28.6M | } |
986 | 28.6M | } |
987 | | |
988 | | /* ---------------- Image drawing ---------------- */ |
989 | | |
990 | | /* GC structures for image enumerator */ |
991 | | public_st_gx_image_enum_common(); |
992 | | |
993 | | static |
994 | 36 | ENUM_PTRS_WITH(image_enum_common_enum_ptrs, gx_image_enum_common_t *eptr) |
995 | 12 | return 0; |
996 | 12 | case 0: return ENUM_OBJ(gx_device_enum_ptr(eptr->dev)); |
997 | 36 | ENUM_PTR(1,gx_image_enum_common_t,pgs); |
998 | 36 | ENUM_PTRS_END |
999 | | |
1000 | 12 | static RELOC_PTRS_WITH(image_enum_common_reloc_ptrs, gx_image_enum_common_t *eptr) |
1001 | 12 | { |
1002 | 12 | eptr->dev = gx_device_reloc_ptr(eptr->dev, gcst); |
1003 | 12 | RELOC_PTR(gx_image_enum_common_t,pgs); |
1004 | 12 | } |
1005 | 12 | RELOC_PTRS_END |
1006 | | |
1007 | | int |
1008 | | gx_default_begin_typed_image(gx_device * dev, |
1009 | | const gs_gstate * pgs, const gs_matrix * pmat, |
1010 | | const gs_image_common_t * pic, const gs_int_rect * prect, |
1011 | | const gx_drawing_color * pdcolor, const gx_clip_path * pcpath, |
1012 | | gs_memory_t * memory, gx_image_enum_common_t ** pinfo) |
1013 | 2.28M | { |
1014 | 2.28M | return (*pic->type->begin_typed_image) |
1015 | 2.28M | (dev, pgs, pmat, pic, prect, pdcolor, pcpath, memory, pinfo); |
1016 | 2.28M | } |
1017 | | |
1018 | | int |
1019 | | gx_default_fillpage(gx_device *dev, gs_gstate * pgs, gx_device_color *pdevc) |
1020 | 2.98M | { |
1021 | 2.98M | bool hl_color_available = gx_hld_is_hl_color_available(pgs, pdevc); |
1022 | 2.98M | int code = 0; |
1023 | | |
1024 | | /* Fill the page directly, ignoring clipping. */ |
1025 | | /* Use the default RasterOp. */ |
1026 | 2.98M | if (hl_color_available) { |
1027 | 11.0k | gs_fixed_rect rect; |
1028 | | |
1029 | 11.0k | rect.p.x = rect.p.y = 0; |
1030 | 11.0k | rect.q.x = int2fixed(dev->width); |
1031 | 11.0k | rect.q.y = int2fixed(dev->height); |
1032 | 11.0k | code = dev_proc(dev, fill_rectangle_hl_color)(dev, |
1033 | 11.0k | &rect, (const gs_gstate *)pgs, pdevc, NULL); |
1034 | 11.0k | } |
1035 | 2.98M | if (!hl_color_available || code == gs_error_rangecheck) |
1036 | 2.96M | code = gx_fill_rectangle_device_rop(0, 0, dev->width, dev->height, pdevc, dev, lop_default); |
1037 | 2.98M | return code; |
1038 | 2.98M | } |