Coverage Report

Created: 2026-09-14 07:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ghostpdl/base/gxdtfill.h
Line
Count
Source
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
17
/* Configurable algorithm for filling a trapezoid */
18
19
/*
20
 * Since we need several statically defined variants of this agorithm,
21
 * we store it in .h file and include several times into gdevddrw.c and
22
 * into gxfill.h . Configuration flags (macros) are :
23
 *
24
 *   GX_FILL_TRAPEZOID - a name of method
25
 *   CONTIGUOUS_FILL   - prevent dropouts in narrow trapezoids
26
 *   SWAP_AXES         - assume swapped axes
27
 *   FILL_DIRECT       - See LOOP_FILL_RECTANGLE_DIRECT.
28
 *   LINEAR_COLOR      - Fill with a linear color.
29
 *   EDGE_TYPE         - a type of edge structure.
30
 *   FILL_ATTRS        - operation attributes.
31
 */
32
33
/*
34
 * Fill a trapezoid.  left.start => left.end and right.start => right.end
35
 * define the sides; ybot and ytop define the top and bottom.  Requires:
36
 *      {left,right}->start.y <= ybot <= ytop <= {left,right}->end.y.
37
 * Lines where left.x >= right.x will not be drawn.  Thanks to Paul Haeberli
38
 * for an early floating point version of this algorithm.
39
 */
40
41
/*
42
 * With CONTIGUOUS_FILL is off,
43
 * this algorithm paints pixels, which centers fall between
44
 * the left and the right side of the trapezoid, excluding the
45
 * right side (see PLRM3, 7.5. Scan conversion details).
46
 * Particularly 0-width trapezoids are not painted.
47
 *
48
 * Similarly, it paints pixels, which centers
49
 * fall between ybot and ytop, excluding ytop.
50
 * Particularly 0-height trapezoids are not painted.
51
 *
52
 * With CONTIGUOUS_FILL is on, it paints a contigous area,
53
 * adding a minimal number of pixels outside the trapezoid.
54
 * Particularly it may paint pixels on the right and on the top sides,
55
 * if they are necessary for the contiguity.
56
 *
57
 * With LINEAR_COLOR returns 1 if the gradient arithmetics overflows..
58
 */
59
60
/*
61
We must paint pixels with index i such that
62
63
    Xl <= i + 0.5 < Xr
64
65
The condition is is equivalent to
66
67
    Xl - 0.5 <= i < Xr - 0.5
68
69
which is equivalent to
70
71
    (is_integer(Xl - 0.5) ? Xl - 0.5 : ceil(Xl - 0.5)) <= i <
72
    (is_integer(Xr - 0.5) ? Xr - 0.5 : floor(Xr - 0.5) + 1)
73
74
(the last '+1" happens due to the strong comparizon '<')
75
which is equivalent to
76
77
    ceil(Xl - 0.5) <= i < ceil(Xr - 0.5)
78
79
trap_line represents the intersection coordinate as a rational value :
80
81
    Xl = xl + e - fl
82
    Xr = xr + e - fr
83
84
Where 'e' is 'fixed_epsilon', 0.5 is 'fixed_half', and fl == l.fx / l.h, fr == - r.fx / r.h,
85
e <= fl < 0, e <= fr < 0.
86
Let
87
88
    xl' := xl + 0.5
89
    xr' := xr + 0.5
90
91
Then
92
93
    xl = xl' - 0.5
94
    xr = xr' - 0.5
95
96
    Xl = xl' - 0.5 + e - fl
97
    Xr = xr' - 0.5 + e - fr
98
99
    ceil(xl' - 0.5 + e - fl - 0.5) <= i < ceil(xr' - 0.5 + e - fr - 0.5)
100
101
which is equivalent to
102
103
    ceil(xl' + e - fl) - 1 <= i < ceil(xr' + e - fr) - 1
104
105
which is equivalent to
106
107
    (is_integer(xl' + e - fl) ? xl' + e - fl - 1 : ceil(xl' + e - fl) - 1) <= i <
108
    (is_integer(xr' + e - fr) ? xr' + e - fr - 1 : ceil(xr' + e - fr) - 1)
109
110
which is equivalent to
111
112
    (is_integer(xl' + e - fl) ? xl' + e - fl - 1 : floor(xl' + e - fl)) <= i <
113
    (is_integer(xr' + e - fr) ? xr' + e - fr - 1 : floor(xr' + e - fr))
114
115
which is equivalent to
116
117
    (is_integer(xl') && e == fl ? xl' - 1 : floor(xl' + e - fl)) <= i <
118
    (is_integer(xr') && e == fr ? xr' - 1 : floor(xr' + e - fr))
119
120
Note that e != fl ==> floor(xl' + e - fl) == floor(xl')  due to e - fl < LeastSignificantBit(xl') ;
121
          e == fl ==> floor(xl' + e - fl) == floor(xl')  due to e - fl == 0;
122
123
thus the condition is is equivalent to
124
125
    (is_integer(xl') && e == fl ? xl' - 1 : floor(xl')) <= i <
126
    (is_integer(xr') && e == fr ? xr' - 1 : floor(xr'))
127
128
It is computed with the macro 'rational_floor'.
129
130
*/
131
132
#if defined(GX_FILL_TRAPEZOID) && defined(EDGE_TYPE)
133
134
GX_FILL_TRAPEZOID (gx_device * dev, const EDGE_TYPE * left,
135
    const EDGE_TYPE * right, fixed ybot, fixed ytop, int flags,
136
    const gx_device_color * pdevc, FILL_ATTRS fa)
137
123M
{
138
123M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
123M
    const fixed ymax = fixed_pixround(ytop);
140
141
123M
    if (ymin >= ymax)
142
27.7M
        return 0;    /* no scan lines to sample */
143
95.3M
    {
144
95.3M
        int iy = fixed2int_var(ymin);
145
95.3M
        const int iy1 = fixed2int_var(ymax);
146
95.3M
        trap_line l, r;
147
95.3M
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
95.3M
        const fixed
152
95.3M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
95.3M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
95.3M
        const fixed /* partial pixel offset to first line to sample */
155
95.3M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
95.3M
        fixed fxl;
157
95.3M
        int code;
158
# if CONTIGUOUS_FILL
159
            const bool peak0 = ((flags & 1) != 0);
160
            const bool peak1 = ((flags & 2) != 0);
161
0
            int peak_y0 = ybot + fixed_half;
162
0
            int peak_y1 = ytop - fixed_half;
163
# endif
164
# if LINEAR_COLOR
165
            int num_components = dev->color_info.num_components;
166
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
            trap_gradient lg, rg, xg;
176
# else
177
            gx_color_index cindex = pdevc->colors.pure;
178
71.5M
            dev_proc_fill_rectangle((*fill_rect)) =
179
71.5M
                dev_proc(dev, fill_rectangle);
180
# endif
181
182
95.3M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
95.3M
        l.h = left->end.y - left->start.y;
185
95.3M
        if (l.h == 0)
186
0
           return 0;
187
95.3M
        r.h = right->end.y - right->start.y;
188
95.3M
        if (r.h == 0)
189
0
           return 0;
190
95.3M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
95.3M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
#if !LINEAR_COLOR
193
        ry = iy;
194
#endif
195
196
/*
197
 * Free variables of FILL_TRAP_RECT:
198
 *  SWAP_AXES, pdevc, dev, fa
199
 * Free variables of FILL_TRAP_RECT_DIRECT:
200
 *  SWAP_AXES, fill_rect, dev, cindex
201
 */
202
95.3M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
846M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
846M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
95.3M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
226M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
226M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
#if LINEAR_COLOR
210
#   define FILL_TRAP_RECT(x,y,w,h)\
211
57.4M
        (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den))
212
#else
213
#   define FILL_TRAP_RECT(x,y,w,h)\
214
1.07G
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
#endif
216
217
        /* Compute the dx/dy ratios. */
218
219
        /*
220
         * Compute the x offsets at the first scan line to sample.  We need
221
         * to be careful in computing ys# * dx#f {/,%} h# because the
222
         * multiplication may overflow.  We know that all the quantities
223
         * involved are non-negative, and that ys# is usually less than 1 (as
224
         * a fixed, of course); this gives us a cheap conservative check for
225
         * overflow in the multiplication.
226
         */
227
95.3M
#define YMULT_QUO(ys, tl)\
228
135M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
135M
   fixed_mult_quo(ys, tl.df, tl.h))
230
231
#if CONTIGUOUS_FILL
232
/*
233
 * If left and right boundary round to same pixel index,
234
 * we would not paing the scan and would get a dropout.
235
 * Check for this case and choose one of two pixels
236
 * which is closer to the "axis". We need to exclude
237
 * 'peak' because it would paint an excessive pixel.
238
 */
239
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \
240
0
    if (ixl == ixr) \
241
0
        if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\
242
0
            fixed x = int2fixed(ixl) + fixed_half;\
243
0
            if (x - l.x < r.x - x)\
244
0
                ++ixr;\
245
0
            else\
246
0
                --ixl;\
247
0
        }
248
249
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\
250
0
    if (adj1 < adj2) {\
251
0
        if (iy - ry > 1) {\
252
0
            code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\
253
0
            if (code < 0)\
254
0
                goto xit;\
255
0
            ry = iy - 1;\
256
0
        }\
257
0
        adj1 = adj2 = (adj2 + adj2) / 2;\
258
0
    }
259
260
#else
261
2.18G
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
2.00G
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
#endif
264
95.3M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
23.7M
            l.di = 0, l.df = 0;
267
23.7M
            fxl = 0;
268
71.5M
        } else {
269
71.5M
            compute_dx(&l, dxl, ysl);
270
71.5M
            fxl = YMULT_QUO(ysl, l);
271
71.5M
            l.x += fxl;
272
71.5M
        }
273
95.3M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
#     if !LINEAR_COLOR
277
22.4M
                if (l.di == 0 && l.df == 0) {
278
10.1M
                    rxl = fixed2int_var(l.x);
279
10.1M
                    rxr = fixed2int_var(r.x);
280
10.1M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
10.1M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
10.1M
                    goto xit;
283
10.1M
                }
284
12.2M
#     endif
285
12.2M
            r.di = 0, r.df = 0;
286
12.2M
        }
287
        /*
288
         * The test for fxl != 0 is required because the right edge might
289
         * cross some pixel centers even if the left edge doesn't.
290
         */
291
68.1M
        else if (dxr == dxl && fxl != 0) {
292
6.67M
            if (l.di == 0)
293
1.92M
                r.di = 0, r.df = l.df;
294
4.74M
            else
295
4.74M
                compute_dx(&r, dxr, ysr);
296
6.67M
            if (ysr == ysl && r.h == l.h)
297
4.47M
                r.x += fxl;
298
2.20M
            else
299
2.20M
                r.x += YMULT_QUO(ysr, r);
300
61.5M
        } else {
301
61.5M
            compute_dx(&r, dxr, ysr);
302
61.5M
            r.x += YMULT_QUO(ysr, r);
303
61.5M
        }
304
        /* Compute one line's worth of dx/dy. */
305
61.4M
        compute_ldx(&l, ysl);
306
61.4M
        compute_ldx(&r, ysr);
307
        /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding
308
           when the rational part is zero. Now add it back to get xl', xr' */
309
85.1M
        l.x += fixed_epsilon;
310
85.1M
        r.x += fixed_epsilon;
311
# if LINEAR_COLOR
312
#     ifdef DEBUG
313
                if (check_gradient_overflow(left, right)) {
314
                    /* The caller must care of.
315
                       Checking it here looses some performance with triangles. */
316
                    return_error(gs_error_unregistered);
317
                }
318
#     endif
319
            lg.c = lgc;
320
            lg.f = lgf;
321
            lg.num = lgnum;
322
            rg.c = rgc;
323
            rg.f = rgf;
324
            rg.num = rgnum;
325
            xg.c = xgc;
326
            xg.f = xgf;
327
            xg.num = xgnum;
328
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
23.7M
            if (code < 0)
330
0
                return code;
331
23.7M
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
23.7M
            if (code < 0)
333
0
                return code;
334
335
23.7M
# endif
336
337
23.7M
#define rational_floor(tl)\
338
5.38G
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
23.7M
#define STEP_LINE(ix, tl)\
340
5.18G
  tl.x += tl.ldi;\
341
5.18G
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
5.21G
  ix = rational_floor(tl)
343
344
85.1M
        rxl = rational_floor(l);
345
85.1M
        rxr = rational_floor(r);
346
85.1M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
2.67G
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
#     if LINEAR_COLOR
349
532M
                if (rxl != rxr) {
350
57.4M
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
57.4M
                    if (code < 0)
352
0
                        goto xit;
353
57.4M
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
57.4M
                    if (code < 0)
355
17
                        goto xit;
356
57.4M
                }
357
532M
                if (++iy == iy1)
358
23.7M
                    break;
359
508M
                STEP_LINE(rxl, l);
360
508M
                STEP_LINE(rxr, r);
361
508M
                step_gradient(&lg, num_components);
362
508M
                step_gradient(&rg, num_components);
363
#     else
364
                register int ixl, ixr;
365
366
2.08G
                STEP_LINE(ixl, l);
367
2.08G
                STEP_LINE(ixr, r);
368
2.08G
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
2.08G
                if (ixl != rxl || ixr != rxr) {
370
1.00G
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
1.00G
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
1.00G
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
1.00G
                    if (code < 0)
374
0
                        goto xit;
375
1.00G
                    rxl = ixl, rxr = ixr, ry = iy;
376
1.00G
                }
377
#     endif
378
508M
        }
379
# if !LINEAR_COLOR
380
61.4M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
23.7M
            code = 0;
383
23.7M
# endif
384
23.7M
#undef STEP_LINE
385
23.7M
#undef SET_MINIMAL_WIDTH
386
23.7M
#undef CONNECT_RECTANGLES
387
23.7M
#undef FILL_TRAP_RECT
388
23.7M
#undef FILL_TRAP_RECT_DIRECT
389
23.7M
#undef FILL_TRAP_RECT_INRECT
390
23.7M
#undef YMULT_QUO
391
95.3M
xit:  if (code < 0 && FILL_DIRECT)
392
17
            return_error(code);
393
95.3M
        return_if_interrupt(dev->memory);
394
95.3M
        return code;
395
95.3M
    }
396
95.3M
}
Unexecuted instantiation: gx_fill_trapezoid_cf_fd
Unexecuted instantiation: gx_fill_trapezoid_cf_nd
gdevddrw.c:gx_fill_trapezoid_as_fd
Line
Count
Source
137
1.32M
{
138
1.32M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
1.32M
    const fixed ymax = fixed_pixround(ytop);
140
141
1.32M
    if (ymin >= ymax)
142
77.4k
        return 0;    /* no scan lines to sample */
143
1.24M
    {
144
1.24M
        int iy = fixed2int_var(ymin);
145
1.24M
        const int iy1 = fixed2int_var(ymax);
146
1.24M
        trap_line l, r;
147
1.24M
        register int rxl, rxr;
148
1.24M
#if !LINEAR_COLOR
149
1.24M
        int ry;
150
1.24M
#endif
151
1.24M
        const fixed
152
1.24M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
1.24M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
1.24M
        const fixed /* partial pixel offset to first line to sample */
155
1.24M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
1.24M
        fixed fxl;
157
1.24M
        int code;
158
# if CONTIGUOUS_FILL
159
            const bool peak0 = ((flags & 1) != 0);
160
            const bool peak1 = ((flags & 2) != 0);
161
            int peak_y0 = ybot + fixed_half;
162
            int peak_y1 = ytop - fixed_half;
163
# endif
164
# if LINEAR_COLOR
165
            int num_components = dev->color_info.num_components;
166
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
            trap_gradient lg, rg, xg;
176
# else
177
1.24M
            gx_color_index cindex = pdevc->colors.pure;
178
1.24M
            dev_proc_fill_rectangle((*fill_rect)) =
179
1.24M
                dev_proc(dev, fill_rectangle);
180
1.24M
# endif
181
182
1.24M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
1.24M
        l.h = left->end.y - left->start.y;
185
1.24M
        if (l.h == 0)
186
0
           return 0;
187
1.24M
        r.h = right->end.y - right->start.y;
188
1.24M
        if (r.h == 0)
189
0
           return 0;
190
1.24M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
1.24M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
1.24M
#if !LINEAR_COLOR
193
1.24M
        ry = iy;
194
1.24M
#endif
195
196
/*
197
 * Free variables of FILL_TRAP_RECT:
198
 *  SWAP_AXES, pdevc, dev, fa
199
 * Free variables of FILL_TRAP_RECT_DIRECT:
200
 *  SWAP_AXES, fill_rect, dev, cindex
201
 */
202
1.24M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
1.24M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
1.24M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
1.24M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
1.24M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
1.24M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
#if LINEAR_COLOR
210
#   define FILL_TRAP_RECT(x,y,w,h)\
211
        (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den))
212
#else
213
1.24M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
1.24M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
1.24M
#endif
216
217
        /* Compute the dx/dy ratios. */
218
219
        /*
220
         * Compute the x offsets at the first scan line to sample.  We need
221
         * to be careful in computing ys# * dx#f {/,%} h# because the
222
         * multiplication may overflow.  We know that all the quantities
223
         * involved are non-negative, and that ys# is usually less than 1 (as
224
         * a fixed, of course); this gives us a cheap conservative check for
225
         * overflow in the multiplication.
226
         */
227
1.24M
#define YMULT_QUO(ys, tl)\
228
1.24M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
1.24M
   fixed_mult_quo(ys, tl.df, tl.h))
230
231
#if CONTIGUOUS_FILL
232
/*
233
 * If left and right boundary round to same pixel index,
234
 * we would not paing the scan and would get a dropout.
235
 * Check for this case and choose one of two pixels
236
 * which is closer to the "axis". We need to exclude
237
 * 'peak' because it would paint an excessive pixel.
238
 */
239
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \
240
    if (ixl == ixr) \
241
        if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\
242
            fixed x = int2fixed(ixl) + fixed_half;\
243
            if (x - l.x < r.x - x)\
244
                ++ixr;\
245
            else\
246
                --ixl;\
247
        }
248
249
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\
250
    if (adj1 < adj2) {\
251
        if (iy - ry > 1) {\
252
            code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\
253
            if (code < 0)\
254
                goto xit;\
255
            ry = iy - 1;\
256
        }\
257
        adj1 = adj2 = (adj2 + adj2) / 2;\
258
    }
259
260
#else
261
1.24M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
1.24M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
1.24M
#endif
264
1.24M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
151k
            l.di = 0, l.df = 0;
267
151k
            fxl = 0;
268
1.09M
        } else {
269
1.09M
            compute_dx(&l, dxl, ysl);
270
1.09M
            fxl = YMULT_QUO(ysl, l);
271
1.09M
            l.x += fxl;
272
1.09M
        }
273
1.24M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
141k
#     if !LINEAR_COLOR
277
141k
                if (l.di == 0 && l.df == 0) {
278
127k
                    rxl = fixed2int_var(l.x);
279
127k
                    rxr = fixed2int_var(r.x);
280
127k
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
127k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
127k
                    goto xit;
283
127k
                }
284
14.0k
#     endif
285
14.0k
            r.di = 0, r.df = 0;
286
14.0k
        }
287
        /*
288
         * The test for fxl != 0 is required because the right edge might
289
         * cross some pixel centers even if the left edge doesn't.
290
         */
291
1.10M
        else if (dxr == dxl && fxl != 0) {
292
825k
            if (l.di == 0)
293
405k
                r.di = 0, r.df = l.df;
294
420k
            else
295
420k
                compute_dx(&r, dxr, ysr);
296
825k
            if (ysr == ysl && r.h == l.h)
297
825k
                r.x += fxl;
298
58
            else
299
58
                r.x += YMULT_QUO(ysr, r);
300
825k
        } else {
301
279k
            compute_dx(&r, dxr, ysr);
302
279k
            r.x += YMULT_QUO(ysr, r);
303
279k
        }
304
        /* Compute one line's worth of dx/dy. */
305
1.11M
        compute_ldx(&l, ysl);
306
1.11M
        compute_ldx(&r, ysr);
307
        /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding
308
           when the rational part is zero. Now add it back to get xl', xr' */
309
1.11M
        l.x += fixed_epsilon;
310
1.11M
        r.x += fixed_epsilon;
311
# if LINEAR_COLOR
312
#     ifdef DEBUG
313
                if (check_gradient_overflow(left, right)) {
314
                    /* The caller must care of.
315
                       Checking it here looses some performance with triangles. */
316
                    return_error(gs_error_unregistered);
317
                }
318
#     endif
319
            lg.c = lgc;
320
            lg.f = lgf;
321
            lg.num = lgnum;
322
            rg.c = rgc;
323
            rg.f = rgf;
324
            rg.num = rgnum;
325
            xg.c = xgc;
326
            xg.f = xgf;
327
            xg.num = xgnum;
328
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
            if (code < 0)
330
                return code;
331
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
            if (code < 0)
333
                return code;
334
335
# endif
336
337
1.11M
#define rational_floor(tl)\
338
1.11M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
1.11M
#define STEP_LINE(ix, tl)\
340
1.11M
  tl.x += tl.ldi;\
341
1.11M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
1.11M
  ix = rational_floor(tl)
343
344
1.11M
        rxl = rational_floor(l);
345
1.11M
        rxr = rational_floor(r);
346
1.11M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
162M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
#     if LINEAR_COLOR
349
                if (rxl != rxr) {
350
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
                    if (code < 0)
352
                        goto xit;
353
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
                    if (code < 0)
355
                        goto xit;
356
                }
357
                if (++iy == iy1)
358
                    break;
359
                STEP_LINE(rxl, l);
360
                STEP_LINE(rxr, r);
361
                step_gradient(&lg, num_components);
362
                step_gradient(&rg, num_components);
363
#     else
364
160M
                register int ixl, ixr;
365
366
160M
                STEP_LINE(ixl, l);
367
160M
                STEP_LINE(ixr, r);
368
160M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
160M
                if (ixl != rxl || ixr != rxr) {
370
21.5M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
21.5M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
21.5M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
21.5M
                    if (code < 0)
374
0
                        goto xit;
375
21.5M
                    rxl = ixl, rxr = ixr, ry = iy;
376
21.5M
                }
377
160M
#     endif
378
160M
        }
379
1.11M
# if !LINEAR_COLOR
380
1.11M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
1.11M
#undef STEP_LINE
385
1.11M
#undef SET_MINIMAL_WIDTH
386
1.11M
#undef CONNECT_RECTANGLES
387
1.11M
#undef FILL_TRAP_RECT
388
1.11M
#undef FILL_TRAP_RECT_DIRECT
389
1.11M
#undef FILL_TRAP_RECT_INRECT
390
1.11M
#undef YMULT_QUO
391
1.24M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
1.24M
        return_if_interrupt(dev->memory);
394
1.24M
        return code;
395
1.24M
    }
396
1.24M
}
gdevddrw.c:gx_fill_trapezoid_as_nd
Line
Count
Source
137
1.92M
{
138
1.92M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
1.92M
    const fixed ymax = fixed_pixround(ytop);
140
141
1.92M
    if (ymin >= ymax)
142
22.3k
        return 0;    /* no scan lines to sample */
143
1.90M
    {
144
1.90M
        int iy = fixed2int_var(ymin);
145
1.90M
        const int iy1 = fixed2int_var(ymax);
146
1.90M
        trap_line l, r;
147
1.90M
        register int rxl, rxr;
148
1.90M
#if !LINEAR_COLOR
149
1.90M
        int ry;
150
1.90M
#endif
151
1.90M
        const fixed
152
1.90M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
1.90M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
1.90M
        const fixed /* partial pixel offset to first line to sample */
155
1.90M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
1.90M
        fixed fxl;
157
1.90M
        int code;
158
# if CONTIGUOUS_FILL
159
            const bool peak0 = ((flags & 1) != 0);
160
            const bool peak1 = ((flags & 2) != 0);
161
            int peak_y0 = ybot + fixed_half;
162
            int peak_y1 = ytop - fixed_half;
163
# endif
164
# if LINEAR_COLOR
165
            int num_components = dev->color_info.num_components;
166
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
            trap_gradient lg, rg, xg;
176
# else
177
1.90M
            gx_color_index cindex = pdevc->colors.pure;
178
1.90M
            dev_proc_fill_rectangle((*fill_rect)) =
179
1.90M
                dev_proc(dev, fill_rectangle);
180
1.90M
# endif
181
182
1.90M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
1.90M
        l.h = left->end.y - left->start.y;
185
1.90M
        if (l.h == 0)
186
0
           return 0;
187
1.90M
        r.h = right->end.y - right->start.y;
188
1.90M
        if (r.h == 0)
189
0
           return 0;
190
1.90M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
1.90M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
1.90M
#if !LINEAR_COLOR
193
1.90M
        ry = iy;
194
1.90M
#endif
195
196
/*
197
 * Free variables of FILL_TRAP_RECT:
198
 *  SWAP_AXES, pdevc, dev, fa
199
 * Free variables of FILL_TRAP_RECT_DIRECT:
200
 *  SWAP_AXES, fill_rect, dev, cindex
201
 */
202
1.90M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
1.90M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
1.90M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
1.90M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
1.90M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
1.90M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
#if LINEAR_COLOR
210
#   define FILL_TRAP_RECT(x,y,w,h)\
211
        (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den))
212
#else
213
1.90M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
1.90M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
1.90M
#endif
216
217
        /* Compute the dx/dy ratios. */
218
219
        /*
220
         * Compute the x offsets at the first scan line to sample.  We need
221
         * to be careful in computing ys# * dx#f {/,%} h# because the
222
         * multiplication may overflow.  We know that all the quantities
223
         * involved are non-negative, and that ys# is usually less than 1 (as
224
         * a fixed, of course); this gives us a cheap conservative check for
225
         * overflow in the multiplication.
226
         */
227
1.90M
#define YMULT_QUO(ys, tl)\
228
1.90M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
1.90M
   fixed_mult_quo(ys, tl.df, tl.h))
230
231
#if CONTIGUOUS_FILL
232
/*
233
 * If left and right boundary round to same pixel index,
234
 * we would not paing the scan and would get a dropout.
235
 * Check for this case and choose one of two pixels
236
 * which is closer to the "axis". We need to exclude
237
 * 'peak' because it would paint an excessive pixel.
238
 */
239
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \
240
    if (ixl == ixr) \
241
        if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\
242
            fixed x = int2fixed(ixl) + fixed_half;\
243
            if (x - l.x < r.x - x)\
244
                ++ixr;\
245
            else\
246
                --ixl;\
247
        }
248
249
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\
250
    if (adj1 < adj2) {\
251
        if (iy - ry > 1) {\
252
            code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\
253
            if (code < 0)\
254
                goto xit;\
255
            ry = iy - 1;\
256
        }\
257
        adj1 = adj2 = (adj2 + adj2) / 2;\
258
    }
259
260
#else
261
1.90M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
1.90M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
1.90M
#endif
264
1.90M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
354k
            l.di = 0, l.df = 0;
267
354k
            fxl = 0;
268
1.55M
        } else {
269
1.55M
            compute_dx(&l, dxl, ysl);
270
1.55M
            fxl = YMULT_QUO(ysl, l);
271
1.55M
            l.x += fxl;
272
1.55M
        }
273
1.90M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
334k
#     if !LINEAR_COLOR
277
334k
                if (l.di == 0 && l.df == 0) {
278
317k
                    rxl = fixed2int_var(l.x);
279
317k
                    rxr = fixed2int_var(r.x);
280
317k
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
317k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
317k
                    goto xit;
283
317k
                }
284
17.0k
#     endif
285
17.0k
            r.di = 0, r.df = 0;
286
17.0k
        }
287
        /*
288
         * The test for fxl != 0 is required because the right edge might
289
         * cross some pixel centers even if the left edge doesn't.
290
         */
291
1.57M
        else if (dxr == dxl && fxl != 0) {
292
309k
            if (l.di == 0)
293
174k
                r.di = 0, r.df = l.df;
294
134k
            else
295
134k
                compute_dx(&r, dxr, ysr);
296
309k
            if (ysr == ysl && r.h == l.h)
297
309k
                r.x += fxl;
298
186
            else
299
186
                r.x += YMULT_QUO(ysr, r);
300
1.26M
        } else {
301
1.26M
            compute_dx(&r, dxr, ysr);
302
1.26M
            r.x += YMULT_QUO(ysr, r);
303
1.26M
        }
304
        /* Compute one line's worth of dx/dy. */
305
1.58M
        compute_ldx(&l, ysl);
306
1.58M
        compute_ldx(&r, ysr);
307
        /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding
308
           when the rational part is zero. Now add it back to get xl', xr' */
309
1.58M
        l.x += fixed_epsilon;
310
1.58M
        r.x += fixed_epsilon;
311
# if LINEAR_COLOR
312
#     ifdef DEBUG
313
                if (check_gradient_overflow(left, right)) {
314
                    /* The caller must care of.
315
                       Checking it here looses some performance with triangles. */
316
                    return_error(gs_error_unregistered);
317
                }
318
#     endif
319
            lg.c = lgc;
320
            lg.f = lgf;
321
            lg.num = lgnum;
322
            rg.c = rgc;
323
            rg.f = rgf;
324
            rg.num = rgnum;
325
            xg.c = xgc;
326
            xg.f = xgf;
327
            xg.num = xgnum;
328
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
            if (code < 0)
330
                return code;
331
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
            if (code < 0)
333
                return code;
334
335
# endif
336
337
1.58M
#define rational_floor(tl)\
338
1.58M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
1.58M
#define STEP_LINE(ix, tl)\
340
1.58M
  tl.x += tl.ldi;\
341
1.58M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
1.58M
  ix = rational_floor(tl)
343
344
1.58M
        rxl = rational_floor(l);
345
1.58M
        rxr = rational_floor(r);
346
1.58M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
157M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
#     if LINEAR_COLOR
349
                if (rxl != rxr) {
350
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
                    if (code < 0)
352
                        goto xit;
353
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
                    if (code < 0)
355
                        goto xit;
356
                }
357
                if (++iy == iy1)
358
                    break;
359
                STEP_LINE(rxl, l);
360
                STEP_LINE(rxr, r);
361
                step_gradient(&lg, num_components);
362
                step_gradient(&rg, num_components);
363
#     else
364
156M
                register int ixl, ixr;
365
366
156M
                STEP_LINE(ixl, l);
367
156M
                STEP_LINE(ixr, r);
368
156M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
156M
                if (ixl != rxl || ixr != rxr) {
370
111M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
111M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
111M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
111M
                    if (code < 0)
374
0
                        goto xit;
375
111M
                    rxl = ixl, rxr = ixr, ry = iy;
376
111M
                }
377
156M
#     endif
378
156M
        }
379
1.58M
# if !LINEAR_COLOR
380
1.58M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
1.58M
#undef STEP_LINE
385
1.58M
#undef SET_MINIMAL_WIDTH
386
1.58M
#undef CONNECT_RECTANGLES
387
1.58M
#undef FILL_TRAP_RECT
388
1.58M
#undef FILL_TRAP_RECT_DIRECT
389
1.58M
#undef FILL_TRAP_RECT_INRECT
390
1.58M
#undef YMULT_QUO
391
1.90M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
1.90M
        return_if_interrupt(dev->memory);
394
1.90M
        return code;
395
1.90M
    }
396
1.90M
}
gdevddrw.c:gx_fill_trapezoid_ns_fd
Line
Count
Source
137
26.3M
{
138
26.3M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
26.3M
    const fixed ymax = fixed_pixround(ytop);
140
141
26.3M
    if (ymin >= ymax)
142
1.46M
        return 0;    /* no scan lines to sample */
143
24.8M
    {
144
24.8M
        int iy = fixed2int_var(ymin);
145
24.8M
        const int iy1 = fixed2int_var(ymax);
146
24.8M
        trap_line l, r;
147
24.8M
        register int rxl, rxr;
148
24.8M
#if !LINEAR_COLOR
149
24.8M
        int ry;
150
24.8M
#endif
151
24.8M
        const fixed
152
24.8M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
24.8M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
24.8M
        const fixed /* partial pixel offset to first line to sample */
155
24.8M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
24.8M
        fixed fxl;
157
24.8M
        int code;
158
# if CONTIGUOUS_FILL
159
            const bool peak0 = ((flags & 1) != 0);
160
            const bool peak1 = ((flags & 2) != 0);
161
            int peak_y0 = ybot + fixed_half;
162
            int peak_y1 = ytop - fixed_half;
163
# endif
164
# if LINEAR_COLOR
165
            int num_components = dev->color_info.num_components;
166
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
            trap_gradient lg, rg, xg;
176
# else
177
24.8M
            gx_color_index cindex = pdevc->colors.pure;
178
24.8M
            dev_proc_fill_rectangle((*fill_rect)) =
179
24.8M
                dev_proc(dev, fill_rectangle);
180
24.8M
# endif
181
182
24.8M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
24.8M
        l.h = left->end.y - left->start.y;
185
24.8M
        if (l.h == 0)
186
0
           return 0;
187
24.8M
        r.h = right->end.y - right->start.y;
188
24.8M
        if (r.h == 0)
189
0
           return 0;
190
24.8M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
24.8M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
24.8M
#if !LINEAR_COLOR
193
24.8M
        ry = iy;
194
24.8M
#endif
195
196
/*
197
 * Free variables of FILL_TRAP_RECT:
198
 *  SWAP_AXES, pdevc, dev, fa
199
 * Free variables of FILL_TRAP_RECT_DIRECT:
200
 *  SWAP_AXES, fill_rect, dev, cindex
201
 */
202
24.8M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
24.8M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
24.8M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
24.8M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
24.8M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
24.8M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
#if LINEAR_COLOR
210
#   define FILL_TRAP_RECT(x,y,w,h)\
211
        (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den))
212
#else
213
24.8M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
24.8M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
24.8M
#endif
216
217
        /* Compute the dx/dy ratios. */
218
219
        /*
220
         * Compute the x offsets at the first scan line to sample.  We need
221
         * to be careful in computing ys# * dx#f {/,%} h# because the
222
         * multiplication may overflow.  We know that all the quantities
223
         * involved are non-negative, and that ys# is usually less than 1 (as
224
         * a fixed, of course); this gives us a cheap conservative check for
225
         * overflow in the multiplication.
226
         */
227
24.8M
#define YMULT_QUO(ys, tl)\
228
24.8M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
24.8M
   fixed_mult_quo(ys, tl.df, tl.h))
230
231
#if CONTIGUOUS_FILL
232
/*
233
 * If left and right boundary round to same pixel index,
234
 * we would not paing the scan and would get a dropout.
235
 * Check for this case and choose one of two pixels
236
 * which is closer to the "axis". We need to exclude
237
 * 'peak' because it would paint an excessive pixel.
238
 */
239
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \
240
    if (ixl == ixr) \
241
        if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\
242
            fixed x = int2fixed(ixl) + fixed_half;\
243
            if (x - l.x < r.x - x)\
244
                ++ixr;\
245
            else\
246
                --ixl;\
247
        }
248
249
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\
250
    if (adj1 < adj2) {\
251
        if (iy - ry > 1) {\
252
            code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\
253
            if (code < 0)\
254
                goto xit;\
255
            ry = iy - 1;\
256
        }\
257
        adj1 = adj2 = (adj2 + adj2) / 2;\
258
    }
259
260
#else
261
24.8M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
24.8M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
24.8M
#endif
264
24.8M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
9.62M
            l.di = 0, l.df = 0;
267
9.62M
            fxl = 0;
268
15.2M
        } else {
269
15.2M
            compute_dx(&l, dxl, ysl);
270
15.2M
            fxl = YMULT_QUO(ysl, l);
271
15.2M
            l.x += fxl;
272
15.2M
        }
273
24.8M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
9.79M
#     if !LINEAR_COLOR
277
9.79M
                if (l.di == 0 && l.df == 0) {
278
5.46M
                    rxl = fixed2int_var(l.x);
279
5.46M
                    rxr = fixed2int_var(r.x);
280
5.46M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
5.46M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
5.46M
                    goto xit;
283
5.46M
                }
284
4.33M
#     endif
285
4.33M
            r.di = 0, r.df = 0;
286
4.33M
        }
287
        /*
288
         * The test for fxl != 0 is required because the right edge might
289
         * cross some pixel centers even if the left edge doesn't.
290
         */
291
15.0M
        else if (dxr == dxl && fxl != 0) {
292
1.55M
            if (l.di == 0)
293
504k
                r.di = 0, r.df = l.df;
294
1.05M
            else
295
1.05M
                compute_dx(&r, dxr, ysr);
296
1.55M
            if (ysr == ysl && r.h == l.h)
297
1.03M
                r.x += fxl;
298
528k
            else
299
528k
                r.x += YMULT_QUO(ysr, r);
300
13.5M
        } else {
301
13.5M
            compute_dx(&r, dxr, ysr);
302
13.5M
            r.x += YMULT_QUO(ysr, r);
303
13.5M
        }
304
        /* Compute one line's worth of dx/dy. */
305
19.4M
        compute_ldx(&l, ysl);
306
19.4M
        compute_ldx(&r, ysr);
307
        /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding
308
           when the rational part is zero. Now add it back to get xl', xr' */
309
19.4M
        l.x += fixed_epsilon;
310
19.4M
        r.x += fixed_epsilon;
311
# if LINEAR_COLOR
312
#     ifdef DEBUG
313
                if (check_gradient_overflow(left, right)) {
314
                    /* The caller must care of.
315
                       Checking it here looses some performance with triangles. */
316
                    return_error(gs_error_unregistered);
317
                }
318
#     endif
319
            lg.c = lgc;
320
            lg.f = lgf;
321
            lg.num = lgnum;
322
            rg.c = rgc;
323
            rg.f = rgf;
324
            rg.num = rgnum;
325
            xg.c = xgc;
326
            xg.f = xgf;
327
            xg.num = xgnum;
328
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
            if (code < 0)
330
                return code;
331
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
            if (code < 0)
333
                return code;
334
335
# endif
336
337
19.4M
#define rational_floor(tl)\
338
19.4M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
19.4M
#define STEP_LINE(ix, tl)\
340
19.4M
  tl.x += tl.ldi;\
341
19.4M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
19.4M
  ix = rational_floor(tl)
343
344
19.4M
        rxl = rational_floor(l);
345
19.4M
        rxr = rational_floor(r);
346
19.4M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
724M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
#     if LINEAR_COLOR
349
                if (rxl != rxr) {
350
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
                    if (code < 0)
352
                        goto xit;
353
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
                    if (code < 0)
355
                        goto xit;
356
                }
357
                if (++iy == iy1)
358
                    break;
359
                STEP_LINE(rxl, l);
360
                STEP_LINE(rxr, r);
361
                step_gradient(&lg, num_components);
362
                step_gradient(&rg, num_components);
363
#     else
364
704M
                register int ixl, ixr;
365
366
704M
                STEP_LINE(ixl, l);
367
704M
                STEP_LINE(ixr, r);
368
704M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
704M
                if (ixl != rxl || ixr != rxr) {
370
178M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
178M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
178M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
178M
                    if (code < 0)
374
0
                        goto xit;
375
178M
                    rxl = ixl, rxr = ixr, ry = iy;
376
178M
                }
377
704M
#     endif
378
704M
        }
379
19.4M
# if !LINEAR_COLOR
380
19.4M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
19.4M
#undef STEP_LINE
385
19.4M
#undef SET_MINIMAL_WIDTH
386
19.4M
#undef CONNECT_RECTANGLES
387
19.4M
#undef FILL_TRAP_RECT
388
19.4M
#undef FILL_TRAP_RECT_DIRECT
389
19.4M
#undef FILL_TRAP_RECT_INRECT
390
19.4M
#undef YMULT_QUO
391
24.8M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
24.8M
        return_if_interrupt(dev->memory);
394
24.8M
        return code;
395
24.8M
    }
396
24.8M
}
gdevddrw.c:gx_fill_trapezoid_ns_nd
Line
Count
Source
137
57.8M
{
138
57.8M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
57.8M
    const fixed ymax = fixed_pixround(ytop);
140
141
57.8M
    if (ymin >= ymax)
142
14.2M
        return 0;    /* no scan lines to sample */
143
43.5M
    {
144
43.5M
        int iy = fixed2int_var(ymin);
145
43.5M
        const int iy1 = fixed2int_var(ymax);
146
43.5M
        trap_line l, r;
147
43.5M
        register int rxl, rxr;
148
43.5M
#if !LINEAR_COLOR
149
43.5M
        int ry;
150
43.5M
#endif
151
43.5M
        const fixed
152
43.5M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
43.5M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
43.5M
        const fixed /* partial pixel offset to first line to sample */
155
43.5M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
43.5M
        fixed fxl;
157
43.5M
        int code;
158
# if CONTIGUOUS_FILL
159
            const bool peak0 = ((flags & 1) != 0);
160
            const bool peak1 = ((flags & 2) != 0);
161
            int peak_y0 = ybot + fixed_half;
162
            int peak_y1 = ytop - fixed_half;
163
# endif
164
# if LINEAR_COLOR
165
            int num_components = dev->color_info.num_components;
166
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
            trap_gradient lg, rg, xg;
176
# else
177
43.5M
            gx_color_index cindex = pdevc->colors.pure;
178
43.5M
            dev_proc_fill_rectangle((*fill_rect)) =
179
43.5M
                dev_proc(dev, fill_rectangle);
180
43.5M
# endif
181
182
43.5M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
43.5M
        l.h = left->end.y - left->start.y;
185
43.5M
        if (l.h == 0)
186
0
           return 0;
187
43.5M
        r.h = right->end.y - right->start.y;
188
43.5M
        if (r.h == 0)
189
0
           return 0;
190
43.5M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
43.5M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
43.5M
#if !LINEAR_COLOR
193
43.5M
        ry = iy;
194
43.5M
#endif
195
196
/*
197
 * Free variables of FILL_TRAP_RECT:
198
 *  SWAP_AXES, pdevc, dev, fa
199
 * Free variables of FILL_TRAP_RECT_DIRECT:
200
 *  SWAP_AXES, fill_rect, dev, cindex
201
 */
202
43.5M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
43.5M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
43.5M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
43.5M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
43.5M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
43.5M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
#if LINEAR_COLOR
210
#   define FILL_TRAP_RECT(x,y,w,h)\
211
        (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den))
212
#else
213
43.5M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
43.5M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
43.5M
#endif
216
217
        /* Compute the dx/dy ratios. */
218
219
        /*
220
         * Compute the x offsets at the first scan line to sample.  We need
221
         * to be careful in computing ys# * dx#f {/,%} h# because the
222
         * multiplication may overflow.  We know that all the quantities
223
         * involved are non-negative, and that ys# is usually less than 1 (as
224
         * a fixed, of course); this gives us a cheap conservative check for
225
         * overflow in the multiplication.
226
         */
227
43.5M
#define YMULT_QUO(ys, tl)\
228
43.5M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
43.5M
   fixed_mult_quo(ys, tl.df, tl.h))
230
231
#if CONTIGUOUS_FILL
232
/*
233
 * If left and right boundary round to same pixel index,
234
 * we would not paing the scan and would get a dropout.
235
 * Check for this case and choose one of two pixels
236
 * which is closer to the "axis". We need to exclude
237
 * 'peak' because it would paint an excessive pixel.
238
 */
239
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \
240
    if (ixl == ixr) \
241
        if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\
242
            fixed x = int2fixed(ixl) + fixed_half;\
243
            if (x - l.x < r.x - x)\
244
                ++ixr;\
245
            else\
246
                --ixl;\
247
        }
248
249
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\
250
    if (adj1 < adj2) {\
251
        if (iy - ry > 1) {\
252
            code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\
253
            if (code < 0)\
254
                goto xit;\
255
            ry = iy - 1;\
256
        }\
257
        adj1 = adj2 = (adj2 + adj2) / 2;\
258
    }
259
260
#else
261
43.5M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
43.5M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
43.5M
#endif
264
43.5M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
8.91M
            l.di = 0, l.df = 0;
267
8.91M
            fxl = 0;
268
34.6M
        } else {
269
34.6M
            compute_dx(&l, dxl, ysl);
270
34.6M
            fxl = YMULT_QUO(ysl, l);
271
34.6M
            l.x += fxl;
272
34.6M
        }
273
43.5M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
12.1M
#     if !LINEAR_COLOR
277
12.1M
                if (l.di == 0 && l.df == 0) {
278
4.25M
                    rxl = fixed2int_var(l.x);
279
4.25M
                    rxr = fixed2int_var(r.x);
280
4.25M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
4.25M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
4.25M
                    goto xit;
283
4.25M
                }
284
7.92M
#     endif
285
7.92M
            r.di = 0, r.df = 0;
286
7.92M
        }
287
        /*
288
         * The test for fxl != 0 is required because the right edge might
289
         * cross some pixel centers even if the left edge doesn't.
290
         */
291
31.3M
        else if (dxr == dxl && fxl != 0) {
292
2.06M
            if (l.di == 0)
293
245k
                r.di = 0, r.df = l.df;
294
1.81M
            else
295
1.81M
                compute_dx(&r, dxr, ysr);
296
2.06M
            if (ysr == ysl && r.h == l.h)
297
1.24M
                r.x += fxl;
298
815k
            else
299
815k
                r.x += YMULT_QUO(ysr, r);
300
29.3M
        } else {
301
29.3M
            compute_dx(&r, dxr, ysr);
302
29.3M
            r.x += YMULT_QUO(ysr, r);
303
29.3M
        }
304
        /* Compute one line's worth of dx/dy. */
305
39.2M
        compute_ldx(&l, ysl);
306
39.2M
        compute_ldx(&r, ysr);
307
        /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding
308
           when the rational part is zero. Now add it back to get xl', xr' */
309
39.2M
        l.x += fixed_epsilon;
310
39.2M
        r.x += fixed_epsilon;
311
# if LINEAR_COLOR
312
#     ifdef DEBUG
313
                if (check_gradient_overflow(left, right)) {
314
                    /* The caller must care of.
315
                       Checking it here looses some performance with triangles. */
316
                    return_error(gs_error_unregistered);
317
                }
318
#     endif
319
            lg.c = lgc;
320
            lg.f = lgf;
321
            lg.num = lgnum;
322
            rg.c = rgc;
323
            rg.f = rgf;
324
            rg.num = rgnum;
325
            xg.c = xgc;
326
            xg.f = xgf;
327
            xg.num = xgnum;
328
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
            if (code < 0)
330
                return code;
331
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
            if (code < 0)
333
                return code;
334
335
# endif
336
337
39.2M
#define rational_floor(tl)\
338
39.2M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
39.2M
#define STEP_LINE(ix, tl)\
340
39.2M
  tl.x += tl.ldi;\
341
39.2M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
39.2M
  ix = rational_floor(tl)
343
344
39.2M
        rxl = rational_floor(l);
345
39.2M
        rxr = rational_floor(r);
346
39.2M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
1.10G
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
#     if LINEAR_COLOR
349
                if (rxl != rxr) {
350
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
                    if (code < 0)
352
                        goto xit;
353
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
                    if (code < 0)
355
                        goto xit;
356
                }
357
                if (++iy == iy1)
358
                    break;
359
                STEP_LINE(rxl, l);
360
                STEP_LINE(rxr, r);
361
                step_gradient(&lg, num_components);
362
                step_gradient(&rg, num_components);
363
#     else
364
1.06G
                register int ixl, ixr;
365
366
1.06G
                STEP_LINE(ixl, l);
367
1.06G
                STEP_LINE(ixr, r);
368
1.06G
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
1.06G
                if (ixl != rxl || ixr != rxr) {
370
689M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
689M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
689M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
689M
                    if (code < 0)
374
0
                        goto xit;
375
689M
                    rxl = ixl, rxr = ixr, ry = iy;
376
689M
                }
377
1.06G
#     endif
378
1.06G
        }
379
39.2M
# if !LINEAR_COLOR
380
39.2M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
39.2M
#undef STEP_LINE
385
39.2M
#undef SET_MINIMAL_WIDTH
386
39.2M
#undef CONNECT_RECTANGLES
387
39.2M
#undef FILL_TRAP_RECT
388
39.2M
#undef FILL_TRAP_RECT_DIRECT
389
39.2M
#undef FILL_TRAP_RECT_INRECT
390
39.2M
#undef YMULT_QUO
391
43.5M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
43.5M
        return_if_interrupt(dev->memory);
394
43.5M
        return code;
395
43.5M
    }
396
43.5M
}
gdevddrw.c:gx_fill_trapezoid_as_lc
Line
Count
Source
137
1.15M
{
138
1.15M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
1.15M
    const fixed ymax = fixed_pixround(ytop);
140
141
1.15M
    if (ymin >= ymax)
142
254k
        return 0;    /* no scan lines to sample */
143
902k
    {
144
902k
        int iy = fixed2int_var(ymin);
145
902k
        const int iy1 = fixed2int_var(ymax);
146
902k
        trap_line l, r;
147
902k
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
902k
        const fixed
152
902k
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
902k
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
902k
        const fixed /* partial pixel offset to first line to sample */
155
902k
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
902k
        fixed fxl;
157
902k
        int code;
158
# if CONTIGUOUS_FILL
159
            const bool peak0 = ((flags & 1) != 0);
160
            const bool peak1 = ((flags & 2) != 0);
161
            int peak_y0 = ybot + fixed_half;
162
            int peak_y1 = ytop - fixed_half;
163
# endif
164
902k
# if LINEAR_COLOR
165
902k
            int num_components = dev->color_info.num_components;
166
902k
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
902k
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
902k
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
902k
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
902k
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
902k
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
902k
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
902k
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
902k
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
902k
            trap_gradient lg, rg, xg;
176
# else
177
            gx_color_index cindex = pdevc->colors.pure;
178
            dev_proc_fill_rectangle((*fill_rect)) =
179
                dev_proc(dev, fill_rectangle);
180
# endif
181
182
902k
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
902k
        l.h = left->end.y - left->start.y;
185
902k
        if (l.h == 0)
186
0
           return 0;
187
902k
        r.h = right->end.y - right->start.y;
188
902k
        if (r.h == 0)
189
0
           return 0;
190
902k
        l.x = x0l + (fixed_half - fixed_epsilon);
191
902k
        r.x = x0r + (fixed_half - fixed_epsilon);
192
#if !LINEAR_COLOR
193
        ry = iy;
194
#endif
195
196
/*
197
 * Free variables of FILL_TRAP_RECT:
198
 *  SWAP_AXES, pdevc, dev, fa
199
 * Free variables of FILL_TRAP_RECT_DIRECT:
200
 *  SWAP_AXES, fill_rect, dev, cindex
201
 */
202
902k
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
902k
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
902k
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
902k
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
902k
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
902k
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
902k
#if LINEAR_COLOR
210
902k
#   define FILL_TRAP_RECT(x,y,w,h)\
211
902k
        (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den))
212
#else
213
#   define FILL_TRAP_RECT(x,y,w,h)\
214
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
#endif
216
217
        /* Compute the dx/dy ratios. */
218
219
        /*
220
         * Compute the x offsets at the first scan line to sample.  We need
221
         * to be careful in computing ys# * dx#f {/,%} h# because the
222
         * multiplication may overflow.  We know that all the quantities
223
         * involved are non-negative, and that ys# is usually less than 1 (as
224
         * a fixed, of course); this gives us a cheap conservative check for
225
         * overflow in the multiplication.
226
         */
227
902k
#define YMULT_QUO(ys, tl)\
228
902k
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
902k
   fixed_mult_quo(ys, tl.df, tl.h))
230
231
#if CONTIGUOUS_FILL
232
/*
233
 * If left and right boundary round to same pixel index,
234
 * we would not paing the scan and would get a dropout.
235
 * Check for this case and choose one of two pixels
236
 * which is closer to the "axis". We need to exclude
237
 * 'peak' because it would paint an excessive pixel.
238
 */
239
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \
240
    if (ixl == ixr) \
241
        if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\
242
            fixed x = int2fixed(ixl) + fixed_half;\
243
            if (x - l.x < r.x - x)\
244
                ++ixr;\
245
            else\
246
                --ixl;\
247
        }
248
249
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\
250
    if (adj1 < adj2) {\
251
        if (iy - ry > 1) {\
252
            code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\
253
            if (code < 0)\
254
                goto xit;\
255
            ry = iy - 1;\
256
        }\
257
        adj1 = adj2 = (adj2 + adj2) / 2;\
258
    }
259
260
#else
261
902k
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
902k
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
902k
#endif
264
902k
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
465k
            l.di = 0, l.df = 0;
267
465k
            fxl = 0;
268
465k
        } else {
269
437k
            compute_dx(&l, dxl, ysl);
270
437k
            fxl = YMULT_QUO(ysl, l);
271
437k
            l.x += fxl;
272
437k
        }
273
902k
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
#     if !LINEAR_COLOR
277
                if (l.di == 0 && l.df == 0) {
278
                    rxl = fixed2int_var(l.x);
279
                    rxr = fixed2int_var(r.x);
280
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
                    goto xit;
283
                }
284
#     endif
285
469k
            r.di = 0, r.df = 0;
286
469k
        }
287
        /*
288
         * The test for fxl != 0 is required because the right edge might
289
         * cross some pixel centers even if the left edge doesn't.
290
         */
291
432k
        else if (dxr == dxl && fxl != 0) {
292
197k
            if (l.di == 0)
293
82.7k
                r.di = 0, r.df = l.df;
294
114k
            else
295
114k
                compute_dx(&r, dxr, ysr);
296
197k
            if (ysr == ysl && r.h == l.h)
297
197k
                r.x += fxl;
298
88
            else
299
88
                r.x += YMULT_QUO(ysr, r);
300
235k
        } else {
301
235k
            compute_dx(&r, dxr, ysr);
302
235k
            r.x += YMULT_QUO(ysr, r);
303
235k
        }
304
        /* Compute one line's worth of dx/dy. */
305
902k
        compute_ldx(&l, ysl);
306
902k
        compute_ldx(&r, ysr);
307
        /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding
308
           when the rational part is zero. Now add it back to get xl', xr' */
309
902k
        l.x += fixed_epsilon;
310
902k
        r.x += fixed_epsilon;
311
902k
# if LINEAR_COLOR
312
#     ifdef DEBUG
313
                if (check_gradient_overflow(left, right)) {
314
                    /* The caller must care of.
315
                       Checking it here looses some performance with triangles. */
316
                    return_error(gs_error_unregistered);
317
                }
318
#     endif
319
902k
            lg.c = lgc;
320
902k
            lg.f = lgf;
321
902k
            lg.num = lgnum;
322
902k
            rg.c = rgc;
323
902k
            rg.f = rgf;
324
902k
            rg.num = rgnum;
325
902k
            xg.c = xgc;
326
902k
            xg.f = xgf;
327
902k
            xg.num = xgnum;
328
902k
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
902k
            if (code < 0)
330
0
                return code;
331
902k
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
902k
            if (code < 0)
333
0
                return code;
334
335
902k
# endif
336
337
902k
#define rational_floor(tl)\
338
902k
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
902k
#define STEP_LINE(ix, tl)\
340
902k
  tl.x += tl.ldi;\
341
902k
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
902k
  ix = rational_floor(tl)
343
344
902k
        rxl = rational_floor(l);
345
902k
        rxr = rational_floor(r);
346
902k
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
25.7M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
25.7M
#     if LINEAR_COLOR
349
25.7M
                if (rxl != rxr) {
350
17.8M
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
17.8M
                    if (code < 0)
352
0
                        goto xit;
353
17.8M
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
17.8M
                    if (code < 0)
355
4
                        goto xit;
356
17.8M
                }
357
25.7M
                if (++iy == iy1)
358
902k
                    break;
359
24.8M
                STEP_LINE(rxl, l);
360
24.8M
                STEP_LINE(rxr, r);
361
24.8M
                step_gradient(&lg, num_components);
362
24.8M
                step_gradient(&rg, num_components);
363
#     else
364
                register int ixl, ixr;
365
366
                STEP_LINE(ixl, l);
367
                STEP_LINE(ixr, r);
368
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
                if (ixl != rxl || ixr != rxr) {
370
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
                    if (code < 0)
374
                        goto xit;
375
                    rxl = ixl, rxr = ixr, ry = iy;
376
                }
377
#     endif
378
24.8M
        }
379
# if !LINEAR_COLOR
380
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
902k
            code = 0;
383
902k
# endif
384
902k
#undef STEP_LINE
385
902k
#undef SET_MINIMAL_WIDTH
386
902k
#undef CONNECT_RECTANGLES
387
902k
#undef FILL_TRAP_RECT
388
902k
#undef FILL_TRAP_RECT_DIRECT
389
902k
#undef FILL_TRAP_RECT_INRECT
390
902k
#undef YMULT_QUO
391
902k
xit:  if (code < 0 && FILL_DIRECT)
392
4
            return_error(code);
393
902k
        return_if_interrupt(dev->memory);
394
902k
        return code;
395
902k
    }
396
902k
}
gdevddrw.c:gx_fill_trapezoid_ns_lc
Line
Count
Source
137
34.5M
{
138
34.5M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
34.5M
    const fixed ymax = fixed_pixround(ytop);
140
141
34.5M
    if (ymin >= ymax)
142
11.6M
        return 0;    /* no scan lines to sample */
143
22.8M
    {
144
22.8M
        int iy = fixed2int_var(ymin);
145
22.8M
        const int iy1 = fixed2int_var(ymax);
146
22.8M
        trap_line l, r;
147
22.8M
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
22.8M
        const fixed
152
22.8M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
22.8M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
22.8M
        const fixed /* partial pixel offset to first line to sample */
155
22.8M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
22.8M
        fixed fxl;
157
22.8M
        int code;
158
# if CONTIGUOUS_FILL
159
            const bool peak0 = ((flags & 1) != 0);
160
            const bool peak1 = ((flags & 2) != 0);
161
            int peak_y0 = ybot + fixed_half;
162
            int peak_y1 = ytop - fixed_half;
163
# endif
164
22.8M
# if LINEAR_COLOR
165
22.8M
            int num_components = dev->color_info.num_components;
166
22.8M
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
22.8M
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
22.8M
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
22.8M
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
22.8M
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
22.8M
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
22.8M
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
22.8M
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
22.8M
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
22.8M
            trap_gradient lg, rg, xg;
176
# else
177
            gx_color_index cindex = pdevc->colors.pure;
178
            dev_proc_fill_rectangle((*fill_rect)) =
179
                dev_proc(dev, fill_rectangle);
180
# endif
181
182
22.8M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
22.8M
        l.h = left->end.y - left->start.y;
185
22.8M
        if (l.h == 0)
186
0
           return 0;
187
22.8M
        r.h = right->end.y - right->start.y;
188
22.8M
        if (r.h == 0)
189
0
           return 0;
190
22.8M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
22.8M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
#if !LINEAR_COLOR
193
        ry = iy;
194
#endif
195
196
/*
197
 * Free variables of FILL_TRAP_RECT:
198
 *  SWAP_AXES, pdevc, dev, fa
199
 * Free variables of FILL_TRAP_RECT_DIRECT:
200
 *  SWAP_AXES, fill_rect, dev, cindex
201
 */
202
22.8M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
22.8M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
22.8M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
22.8M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
22.8M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
22.8M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
22.8M
#if LINEAR_COLOR
210
22.8M
#   define FILL_TRAP_RECT(x,y,w,h)\
211
22.8M
        (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den))
212
#else
213
#   define FILL_TRAP_RECT(x,y,w,h)\
214
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
#endif
216
217
        /* Compute the dx/dy ratios. */
218
219
        /*
220
         * Compute the x offsets at the first scan line to sample.  We need
221
         * to be careful in computing ys# * dx#f {/,%} h# because the
222
         * multiplication may overflow.  We know that all the quantities
223
         * involved are non-negative, and that ys# is usually less than 1 (as
224
         * a fixed, of course); this gives us a cheap conservative check for
225
         * overflow in the multiplication.
226
         */
227
22.8M
#define YMULT_QUO(ys, tl)\
228
22.8M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
22.8M
   fixed_mult_quo(ys, tl.df, tl.h))
230
231
#if CONTIGUOUS_FILL
232
/*
233
 * If left and right boundary round to same pixel index,
234
 * we would not paing the scan and would get a dropout.
235
 * Check for this case and choose one of two pixels
236
 * which is closer to the "axis". We need to exclude
237
 * 'peak' because it would paint an excessive pixel.
238
 */
239
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \
240
    if (ixl == ixr) \
241
        if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\
242
            fixed x = int2fixed(ixl) + fixed_half;\
243
            if (x - l.x < r.x - x)\
244
                ++ixr;\
245
            else\
246
                --ixl;\
247
        }
248
249
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\
250
    if (adj1 < adj2) {\
251
        if (iy - ry > 1) {\
252
            code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\
253
            if (code < 0)\
254
                goto xit;\
255
            ry = iy - 1;\
256
        }\
257
        adj1 = adj2 = (adj2 + adj2) / 2;\
258
    }
259
260
#else
261
22.8M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
22.8M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
22.8M
#endif
264
22.8M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
4.24M
            l.di = 0, l.df = 0;
267
4.24M
            fxl = 0;
268
18.6M
        } else {
269
18.6M
            compute_dx(&l, dxl, ysl);
270
18.6M
            fxl = YMULT_QUO(ysl, l);
271
18.6M
            l.x += fxl;
272
18.6M
        }
273
22.8M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
#     if !LINEAR_COLOR
277
                if (l.di == 0 && l.df == 0) {
278
                    rxl = fixed2int_var(l.x);
279
                    rxr = fixed2int_var(r.x);
280
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
                    goto xit;
283
                }
284
#     endif
285
4.24M
            r.di = 0, r.df = 0;
286
4.24M
        }
287
        /*
288
         * The test for fxl != 0 is required because the right edge might
289
         * cross some pixel centers even if the left edge doesn't.
290
         */
291
18.6M
        else if (dxr == dxl && fxl != 0) {
292
1.72M
            if (l.di == 0)
293
516k
                r.di = 0, r.df = l.df;
294
1.20M
            else
295
1.20M
                compute_dx(&r, dxr, ysr);
296
1.72M
            if (ysr == ysl && r.h == l.h)
297
858k
                r.x += fxl;
298
861k
            else
299
861k
                r.x += YMULT_QUO(ysr, r);
300
16.9M
        } else {
301
16.9M
            compute_dx(&r, dxr, ysr);
302
16.9M
            r.x += YMULT_QUO(ysr, r);
303
16.9M
        }
304
        /* Compute one line's worth of dx/dy. */
305
22.8M
        compute_ldx(&l, ysl);
306
22.8M
        compute_ldx(&r, ysr);
307
        /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding
308
           when the rational part is zero. Now add it back to get xl', xr' */
309
22.8M
        l.x += fixed_epsilon;
310
22.8M
        r.x += fixed_epsilon;
311
22.8M
# if LINEAR_COLOR
312
#     ifdef DEBUG
313
                if (check_gradient_overflow(left, right)) {
314
                    /* The caller must care of.
315
                       Checking it here looses some performance with triangles. */
316
                    return_error(gs_error_unregistered);
317
                }
318
#     endif
319
22.8M
            lg.c = lgc;
320
22.8M
            lg.f = lgf;
321
22.8M
            lg.num = lgnum;
322
22.8M
            rg.c = rgc;
323
22.8M
            rg.f = rgf;
324
22.8M
            rg.num = rgnum;
325
22.8M
            xg.c = xgc;
326
22.8M
            xg.f = xgf;
327
22.8M
            xg.num = xgnum;
328
22.8M
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
22.8M
            if (code < 0)
330
0
                return code;
331
22.8M
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
22.8M
            if (code < 0)
333
0
                return code;
334
335
22.8M
# endif
336
337
22.8M
#define rational_floor(tl)\
338
22.8M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
22.8M
#define STEP_LINE(ix, tl)\
340
22.8M
  tl.x += tl.ldi;\
341
22.8M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
22.8M
  ix = rational_floor(tl)
343
344
22.8M
        rxl = rational_floor(l);
345
22.8M
        rxr = rational_floor(r);
346
22.8M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
506M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
506M
#     if LINEAR_COLOR
349
506M
                if (rxl != rxr) {
350
39.5M
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
39.5M
                    if (code < 0)
352
0
                        goto xit;
353
39.5M
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
39.5M
                    if (code < 0)
355
13
                        goto xit;
356
39.5M
                }
357
506M
                if (++iy == iy1)
358
22.8M
                    break;
359
483M
                STEP_LINE(rxl, l);
360
483M
                STEP_LINE(rxr, r);
361
483M
                step_gradient(&lg, num_components);
362
483M
                step_gradient(&rg, num_components);
363
#     else
364
                register int ixl, ixr;
365
366
                STEP_LINE(ixl, l);
367
                STEP_LINE(ixr, r);
368
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
                if (ixl != rxl || ixr != rxr) {
370
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
                    if (code < 0)
374
                        goto xit;
375
                    rxl = ixl, rxr = ixr, ry = iy;
376
                }
377
#     endif
378
483M
        }
379
# if !LINEAR_COLOR
380
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
22.8M
            code = 0;
383
22.8M
# endif
384
22.8M
#undef STEP_LINE
385
22.8M
#undef SET_MINIMAL_WIDTH
386
22.8M
#undef CONNECT_RECTANGLES
387
22.8M
#undef FILL_TRAP_RECT
388
22.8M
#undef FILL_TRAP_RECT_DIRECT
389
22.8M
#undef FILL_TRAP_RECT_INRECT
390
22.8M
#undef YMULT_QUO
391
22.8M
xit:  if (code < 0 && FILL_DIRECT)
392
13
            return_error(code);
393
22.8M
        return_if_interrupt(dev->memory);
394
22.8M
        return code;
395
22.8M
    }
396
22.8M
}
397
398
#undef GX_FILL_TRAPEZOID
399
#undef CONTIGUOUS_FILL
400
#undef SWAP_AXES
401
#undef FLAGS_TYPE
402
403
#else
404
int dummy;
405
#endif