Coverage Report

Created: 2026-08-08 08:00

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
128M
{
138
128M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
128M
    const fixed ymax = fixed_pixround(ytop);
140
141
128M
    if (ymin >= ymax)
142
28.3M
        return 0;    /* no scan lines to sample */
143
99.7M
    {
144
99.7M
        int iy = fixed2int_var(ymin);
145
99.7M
        const int iy1 = fixed2int_var(ymax);
146
99.7M
        trap_line l, r;
147
99.7M
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
99.7M
        const fixed
152
99.7M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
99.7M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
99.7M
        const fixed /* partial pixel offset to first line to sample */
155
99.7M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
99.7M
        fixed fxl;
157
99.7M
        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
77.6M
            dev_proc_fill_rectangle((*fill_rect)) =
179
77.6M
                dev_proc(dev, fill_rectangle);
180
# endif
181
182
99.7M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
99.7M
        l.h = left->end.y - left->start.y;
185
99.7M
        if (l.h == 0)
186
0
           return 0;
187
99.7M
        r.h = right->end.y - right->start.y;
188
99.7M
        if (r.h == 0)
189
4
           return 0;
190
99.7M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
99.7M
        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
99.7M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
873M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
873M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
99.7M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
200M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
200M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
#if LINEAR_COLOR
210
#   define FILL_TRAP_RECT(x,y,w,h)\
211
53.6M
        (!(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
99.7M
#define YMULT_QUO(ys, tl)\
228
141M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
141M
   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.20G
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
1.99G
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
#endif
264
99.7M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
24.8M
            l.di = 0, l.df = 0;
267
24.8M
            fxl = 0;
268
74.9M
        } else {
269
74.9M
            compute_dx(&l, dxl, ysl);
270
74.9M
            fxl = YMULT_QUO(ysl, l);
271
74.9M
            l.x += fxl;
272
74.9M
        }
273
99.7M
        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
23.9M
                if (l.di == 0 && l.df == 0) {
278
10.6M
                    rxl = fixed2int_var(l.x);
279
10.6M
                    rxr = fixed2int_var(r.x);
280
10.6M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
10.6M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
10.6M
                    goto xit;
283
10.6M
                }
284
13.3M
#     endif
285
13.3M
            r.di = 0, r.df = 0;
286
13.3M
        }
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
71.4M
        else if (dxr == dxl && fxl != 0) {
292
6.97M
            if (l.di == 0)
293
1.88M
                r.di = 0, r.df = l.df;
294
5.08M
            else
295
5.08M
                compute_dx(&r, dxr, ysr);
296
6.97M
            if (ysr == ysl && r.h == l.h)
297
4.40M
                r.x += fxl;
298
2.56M
            else
299
2.56M
                r.x += YMULT_QUO(ysr, r);
300
64.4M
        } else {
301
64.4M
            compute_dx(&r, dxr, ysr);
302
64.4M
            r.x += YMULT_QUO(ysr, r);
303
64.4M
        }
304
        /* Compute one line's worth of dx/dy. */
305
66.9M
        compute_ldx(&l, ysl);
306
66.9M
        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
89.1M
        l.x += fixed_epsilon;
310
89.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
22.1M
            if (code < 0)
330
0
                return code;
331
22.1M
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
22.1M
            if (code < 0)
333
0
                return code;
334
335
22.1M
# endif
336
337
22.1M
#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
22.1M
#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.20G
  ix = rational_floor(tl)
343
344
89.1M
        rxl = rational_floor(l);
345
89.1M
        rxr = rational_floor(r);
346
89.1M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
2.67G
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
#     if LINEAR_COLOR
349
503M
                if (rxl != rxr) {
350
53.6M
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
53.6M
                    if (code < 0)
352
0
                        goto xit;
353
53.6M
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
53.6M
                    if (code < 0)
355
17
                        goto xit;
356
53.6M
                }
357
503M
                if (++iy == iy1)
358
22.1M
                    break;
359
481M
                STEP_LINE(rxl, l);
360
481M
                STEP_LINE(rxr, r);
361
481M
                step_gradient(&lg, num_components);
362
481M
                step_gradient(&rg, num_components);
363
#     else
364
                register int ixl, ixr;
365
366
2.10G
                STEP_LINE(ixl, l);
367
2.10G
                STEP_LINE(ixr, r);
368
2.10G
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
2.10G
                if (ixl != rxl || ixr != rxr) {
370
996M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
996M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
996M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
996M
                    if (code < 0)
374
0
                        goto xit;
375
996M
                    rxl = ixl, rxr = ixr, ry = iy;
376
996M
                }
377
#     endif
378
481M
        }
379
# if !LINEAR_COLOR
380
66.9M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
22.1M
            code = 0;
383
22.1M
# endif
384
22.1M
#undef STEP_LINE
385
22.1M
#undef SET_MINIMAL_WIDTH
386
22.1M
#undef CONNECT_RECTANGLES
387
22.1M
#undef FILL_TRAP_RECT
388
22.1M
#undef FILL_TRAP_RECT_DIRECT
389
22.1M
#undef FILL_TRAP_RECT_INRECT
390
22.1M
#undef YMULT_QUO
391
99.7M
xit:  if (code < 0 && FILL_DIRECT)
392
17
            return_error(code);
393
99.7M
        return_if_interrupt(dev->memory);
394
99.7M
        return code;
395
99.7M
    }
396
99.7M
}
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.43M
{
138
1.43M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
1.43M
    const fixed ymax = fixed_pixround(ytop);
140
141
1.43M
    if (ymin >= ymax)
142
83.8k
        return 0;    /* no scan lines to sample */
143
1.34M
    {
144
1.34M
        int iy = fixed2int_var(ymin);
145
1.34M
        const int iy1 = fixed2int_var(ymax);
146
1.34M
        trap_line l, r;
147
1.34M
        register int rxl, rxr;
148
1.34M
#if !LINEAR_COLOR
149
1.34M
        int ry;
150
1.34M
#endif
151
1.34M
        const fixed
152
1.34M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
1.34M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
1.34M
        const fixed /* partial pixel offset to first line to sample */
155
1.34M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
1.34M
        fixed fxl;
157
1.34M
        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.34M
            gx_color_index cindex = pdevc->colors.pure;
178
1.34M
            dev_proc_fill_rectangle((*fill_rect)) =
179
1.34M
                dev_proc(dev, fill_rectangle);
180
1.34M
# endif
181
182
1.34M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
1.34M
        l.h = left->end.y - left->start.y;
185
1.34M
        if (l.h == 0)
186
0
           return 0;
187
1.34M
        r.h = right->end.y - right->start.y;
188
1.34M
        if (r.h == 0)
189
0
           return 0;
190
1.34M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
1.34M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
1.34M
#if !LINEAR_COLOR
193
1.34M
        ry = iy;
194
1.34M
#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.34M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
1.34M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
1.34M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
1.34M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
1.34M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
1.34M
   (*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.34M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
1.34M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
1.34M
#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.34M
#define YMULT_QUO(ys, tl)\
228
1.34M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
1.34M
   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.34M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
1.34M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
1.34M
#endif
264
1.34M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
231k
            l.di = 0, l.df = 0;
267
231k
            fxl = 0;
268
1.11M
        } else {
269
1.11M
            compute_dx(&l, dxl, ysl);
270
1.11M
            fxl = YMULT_QUO(ysl, l);
271
1.11M
            l.x += fxl;
272
1.11M
        }
273
1.34M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
218k
#     if !LINEAR_COLOR
277
218k
                if (l.di == 0 && l.df == 0) {
278
205k
                    rxl = fixed2int_var(l.x);
279
205k
                    rxr = fixed2int_var(r.x);
280
205k
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
205k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
205k
                    goto xit;
283
205k
                }
284
13.7k
#     endif
285
13.7k
            r.di = 0, r.df = 0;
286
13.7k
        }
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.12M
        else if (dxr == dxl && fxl != 0) {
292
831k
            if (l.di == 0)
293
405k
                r.di = 0, r.df = l.df;
294
426k
            else
295
426k
                compute_dx(&r, dxr, ysr);
296
831k
            if (ysr == ysl && r.h == l.h)
297
831k
                r.x += fxl;
298
57
            else
299
57
                r.x += YMULT_QUO(ysr, r);
300
831k
        } else {
301
297k
            compute_dx(&r, dxr, ysr);
302
297k
            r.x += YMULT_QUO(ysr, r);
303
297k
        }
304
        /* Compute one line's worth of dx/dy. */
305
1.14M
        compute_ldx(&l, ysl);
306
1.14M
        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.14M
        l.x += fixed_epsilon;
310
1.14M
        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.14M
#define rational_floor(tl)\
338
1.14M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
1.14M
#define STEP_LINE(ix, tl)\
340
1.14M
  tl.x += tl.ldi;\
341
1.14M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
1.14M
  ix = rational_floor(tl)
343
344
1.14M
        rxl = rational_floor(l);
345
1.14M
        rxr = rational_floor(r);
346
1.14M
        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
161M
                register int ixl, ixr;
365
366
161M
                STEP_LINE(ixl, l);
367
161M
                STEP_LINE(ixr, r);
368
161M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
161M
                if (ixl != rxl || ixr != rxr) {
370
21.7M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
21.7M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
21.7M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
21.7M
                    if (code < 0)
374
0
                        goto xit;
375
21.7M
                    rxl = ixl, rxr = ixr, ry = iy;
376
21.7M
                }
377
161M
#     endif
378
161M
        }
379
1.14M
# if !LINEAR_COLOR
380
1.14M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
1.14M
#undef STEP_LINE
385
1.14M
#undef SET_MINIMAL_WIDTH
386
1.14M
#undef CONNECT_RECTANGLES
387
1.14M
#undef FILL_TRAP_RECT
388
1.14M
#undef FILL_TRAP_RECT_DIRECT
389
1.14M
#undef FILL_TRAP_RECT_INRECT
390
1.14M
#undef YMULT_QUO
391
1.34M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
1.34M
        return_if_interrupt(dev->memory);
394
1.34M
        return code;
395
1.34M
    }
396
1.34M
}
gdevddrw.c:gx_fill_trapezoid_as_nd
Line
Count
Source
137
2.15M
{
138
2.15M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
2.15M
    const fixed ymax = fixed_pixround(ytop);
140
141
2.15M
    if (ymin >= ymax)
142
22.8k
        return 0;    /* no scan lines to sample */
143
2.13M
    {
144
2.13M
        int iy = fixed2int_var(ymin);
145
2.13M
        const int iy1 = fixed2int_var(ymax);
146
2.13M
        trap_line l, r;
147
2.13M
        register int rxl, rxr;
148
2.13M
#if !LINEAR_COLOR
149
2.13M
        int ry;
150
2.13M
#endif
151
2.13M
        const fixed
152
2.13M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
2.13M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
2.13M
        const fixed /* partial pixel offset to first line to sample */
155
2.13M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
2.13M
        fixed fxl;
157
2.13M
        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
2.13M
            gx_color_index cindex = pdevc->colors.pure;
178
2.13M
            dev_proc_fill_rectangle((*fill_rect)) =
179
2.13M
                dev_proc(dev, fill_rectangle);
180
2.13M
# endif
181
182
2.13M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
2.13M
        l.h = left->end.y - left->start.y;
185
2.13M
        if (l.h == 0)
186
0
           return 0;
187
2.13M
        r.h = right->end.y - right->start.y;
188
2.13M
        if (r.h == 0)
189
0
           return 0;
190
2.13M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
2.13M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
2.13M
#if !LINEAR_COLOR
193
2.13M
        ry = iy;
194
2.13M
#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
2.13M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
2.13M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
2.13M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
2.13M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
2.13M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
2.13M
   (*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
2.13M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
2.13M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
2.13M
#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
2.13M
#define YMULT_QUO(ys, tl)\
228
2.13M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
2.13M
   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
2.13M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
2.13M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
2.13M
#endif
264
2.13M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
382k
            l.di = 0, l.df = 0;
267
382k
            fxl = 0;
268
1.74M
        } else {
269
1.74M
            compute_dx(&l, dxl, ysl);
270
1.74M
            fxl = YMULT_QUO(ysl, l);
271
1.74M
            l.x += fxl;
272
1.74M
        }
273
2.13M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
360k
#     if !LINEAR_COLOR
277
360k
                if (l.di == 0 && l.df == 0) {
278
341k
                    rxl = fixed2int_var(l.x);
279
341k
                    rxr = fixed2int_var(r.x);
280
341k
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
341k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
341k
                    goto xit;
283
341k
                }
284
19.3k
#     endif
285
19.3k
            r.di = 0, r.df = 0;
286
19.3k
        }
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.77M
        else if (dxr == dxl && fxl != 0) {
292
324k
            if (l.di == 0)
293
186k
                r.di = 0, r.df = l.df;
294
138k
            else
295
138k
                compute_dx(&r, dxr, ysr);
296
324k
            if (ysr == ysl && r.h == l.h)
297
324k
                r.x += fxl;
298
186
            else
299
186
                r.x += YMULT_QUO(ysr, r);
300
1.44M
        } else {
301
1.44M
            compute_dx(&r, dxr, ysr);
302
1.44M
            r.x += YMULT_QUO(ysr, r);
303
1.44M
        }
304
        /* Compute one line's worth of dx/dy. */
305
1.79M
        compute_ldx(&l, ysl);
306
1.79M
        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.79M
        l.x += fixed_epsilon;
310
1.79M
        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.79M
#define rational_floor(tl)\
338
1.79M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
1.79M
#define STEP_LINE(ix, tl)\
340
1.79M
  tl.x += tl.ldi;\
341
1.79M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
1.79M
  ix = rational_floor(tl)
343
344
1.79M
        rxl = rational_floor(l);
345
1.79M
        rxr = rational_floor(r);
346
1.79M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
164M
        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
162M
                register int ixl, ixr;
365
366
162M
                STEP_LINE(ixl, l);
367
162M
                STEP_LINE(ixr, r);
368
162M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
162M
                if (ixl != rxl || ixr != rxr) {
370
114M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
114M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
114M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
114M
                    if (code < 0)
374
0
                        goto xit;
375
114M
                    rxl = ixl, rxr = ixr, ry = iy;
376
114M
                }
377
162M
#     endif
378
162M
        }
379
1.79M
# if !LINEAR_COLOR
380
1.79M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
1.79M
#undef STEP_LINE
385
1.79M
#undef SET_MINIMAL_WIDTH
386
1.79M
#undef CONNECT_RECTANGLES
387
1.79M
#undef FILL_TRAP_RECT
388
1.79M
#undef FILL_TRAP_RECT_DIRECT
389
1.79M
#undef FILL_TRAP_RECT_INRECT
390
1.79M
#undef YMULT_QUO
391
2.13M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
2.13M
        return_if_interrupt(dev->memory);
394
2.13M
        return code;
395
2.13M
    }
396
2.13M
}
gdevddrw.c:gx_fill_trapezoid_ns_fd
Line
Count
Source
137
29.3M
{
138
29.3M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
29.3M
    const fixed ymax = fixed_pixround(ytop);
140
141
29.3M
    if (ymin >= ymax)
142
1.74M
        return 0;    /* no scan lines to sample */
143
27.5M
    {
144
27.5M
        int iy = fixed2int_var(ymin);
145
27.5M
        const int iy1 = fixed2int_var(ymax);
146
27.5M
        trap_line l, r;
147
27.5M
        register int rxl, rxr;
148
27.5M
#if !LINEAR_COLOR
149
27.5M
        int ry;
150
27.5M
#endif
151
27.5M
        const fixed
152
27.5M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
27.5M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
27.5M
        const fixed /* partial pixel offset to first line to sample */
155
27.5M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
27.5M
        fixed fxl;
157
27.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
27.5M
            gx_color_index cindex = pdevc->colors.pure;
178
27.5M
            dev_proc_fill_rectangle((*fill_rect)) =
179
27.5M
                dev_proc(dev, fill_rectangle);
180
27.5M
# endif
181
182
27.5M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
27.5M
        l.h = left->end.y - left->start.y;
185
27.5M
        if (l.h == 0)
186
0
           return 0;
187
27.5M
        r.h = right->end.y - right->start.y;
188
27.5M
        if (r.h == 0)
189
4
           return 0;
190
27.5M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
27.5M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
27.5M
#if !LINEAR_COLOR
193
27.5M
        ry = iy;
194
27.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
27.5M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
27.5M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
27.5M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
27.5M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
27.5M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
27.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
27.5M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
27.5M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
27.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
27.5M
#define YMULT_QUO(ys, tl)\
228
27.5M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
27.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
27.5M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
27.5M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
27.5M
#endif
264
27.5M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
9.98M
            l.di = 0, l.df = 0;
267
9.98M
            fxl = 0;
268
17.5M
        } else {
269
17.5M
            compute_dx(&l, dxl, ysl);
270
17.5M
            fxl = YMULT_QUO(ysl, l);
271
17.5M
            l.x += fxl;
272
17.5M
        }
273
27.5M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
10.1M
#     if !LINEAR_COLOR
277
10.1M
                if (l.di == 0 && l.df == 0) {
278
5.40M
                    rxl = fixed2int_var(l.x);
279
5.40M
                    rxr = fixed2int_var(r.x);
280
5.40M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
5.40M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
5.40M
                    goto xit;
283
5.40M
                }
284
4.74M
#     endif
285
4.74M
            r.di = 0, r.df = 0;
286
4.74M
        }
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
17.4M
        else if (dxr == dxl && fxl != 0) {
292
1.85M
            if (l.di == 0)
293
504k
                r.di = 0, r.df = l.df;
294
1.34M
            else
295
1.34M
                compute_dx(&r, dxr, ysr);
296
1.85M
            if (ysr == ysl && r.h == l.h)
297
1.03M
                r.x += fxl;
298
812k
            else
299
812k
                r.x += YMULT_QUO(ysr, r);
300
15.5M
        } else {
301
15.5M
            compute_dx(&r, dxr, ysr);
302
15.5M
            r.x += YMULT_QUO(ysr, r);
303
15.5M
        }
304
        /* Compute one line's worth of dx/dy. */
305
22.1M
        compute_ldx(&l, ysl);
306
22.1M
        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.1M
        l.x += fixed_epsilon;
310
22.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
            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
22.1M
#define rational_floor(tl)\
338
22.1M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
22.1M
#define STEP_LINE(ix, tl)\
340
22.1M
  tl.x += tl.ldi;\
341
22.1M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
22.1M
  ix = rational_floor(tl)
343
344
22.1M
        rxl = rational_floor(l);
345
22.1M
        rxr = rational_floor(r);
346
22.1M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
716M
        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
694M
                register int ixl, ixr;
365
366
694M
                STEP_LINE(ixl, l);
367
694M
                STEP_LINE(ixr, r);
368
694M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
694M
                if (ixl != rxl || ixr != rxr) {
370
149M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
149M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
149M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
149M
                    if (code < 0)
374
0
                        goto xit;
375
149M
                    rxl = ixl, rxr = ixr, ry = iy;
376
149M
                }
377
694M
#     endif
378
694M
        }
379
22.1M
# if !LINEAR_COLOR
380
22.1M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
22.1M
#undef STEP_LINE
385
22.1M
#undef SET_MINIMAL_WIDTH
386
22.1M
#undef CONNECT_RECTANGLES
387
22.1M
#undef FILL_TRAP_RECT
388
22.1M
#undef FILL_TRAP_RECT_DIRECT
389
22.1M
#undef FILL_TRAP_RECT_INRECT
390
22.1M
#undef YMULT_QUO
391
27.5M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
27.5M
        return_if_interrupt(dev->memory);
394
27.5M
        return code;
395
27.5M
    }
396
27.5M
}
gdevddrw.c:gx_fill_trapezoid_ns_nd
Line
Count
Source
137
61.7M
{
138
61.7M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
61.7M
    const fixed ymax = fixed_pixround(ytop);
140
141
61.7M
    if (ymin >= ymax)
142
15.1M
        return 0;    /* no scan lines to sample */
143
46.5M
    {
144
46.5M
        int iy = fixed2int_var(ymin);
145
46.5M
        const int iy1 = fixed2int_var(ymax);
146
46.5M
        trap_line l, r;
147
46.5M
        register int rxl, rxr;
148
46.5M
#if !LINEAR_COLOR
149
46.5M
        int ry;
150
46.5M
#endif
151
46.5M
        const fixed
152
46.5M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
46.5M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
46.5M
        const fixed /* partial pixel offset to first line to sample */
155
46.5M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
46.5M
        fixed fxl;
157
46.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
46.5M
            gx_color_index cindex = pdevc->colors.pure;
178
46.5M
            dev_proc_fill_rectangle((*fill_rect)) =
179
46.5M
                dev_proc(dev, fill_rectangle);
180
46.5M
# endif
181
182
46.5M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
46.5M
        l.h = left->end.y - left->start.y;
185
46.5M
        if (l.h == 0)
186
0
           return 0;
187
46.5M
        r.h = right->end.y - right->start.y;
188
46.5M
        if (r.h == 0)
189
0
           return 0;
190
46.5M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
46.5M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
46.5M
#if !LINEAR_COLOR
193
46.5M
        ry = iy;
194
46.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
46.5M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
46.5M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
46.5M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
46.5M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
46.5M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
46.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
46.5M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
46.5M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
46.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
46.5M
#define YMULT_QUO(ys, tl)\
228
46.5M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
46.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
46.5M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
46.5M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
46.5M
#endif
264
46.5M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
9.85M
            l.di = 0, l.df = 0;
267
9.85M
            fxl = 0;
268
36.7M
        } else {
269
36.7M
            compute_dx(&l, dxl, ysl);
270
36.7M
            fxl = YMULT_QUO(ysl, l);
271
36.7M
            l.x += fxl;
272
36.7M
        }
273
46.5M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
13.2M
#     if !LINEAR_COLOR
277
13.2M
                if (l.di == 0 && l.df == 0) {
278
4.71M
                    rxl = fixed2int_var(l.x);
279
4.71M
                    rxr = fixed2int_var(r.x);
280
4.71M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
4.71M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
4.71M
                    goto xit;
283
4.71M
                }
284
8.54M
#     endif
285
8.54M
            r.di = 0, r.df = 0;
286
8.54M
        }
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
33.3M
        else if (dxr == dxl && fxl != 0) {
292
2.22M
            if (l.di == 0)
293
253k
                r.di = 0, r.df = l.df;
294
1.97M
            else
295
1.97M
                compute_dx(&r, dxr, ysr);
296
2.22M
            if (ysr == ysl && r.h == l.h)
297
1.27M
                r.x += fxl;
298
949k
            else
299
949k
                r.x += YMULT_QUO(ysr, r);
300
31.0M
        } else {
301
31.0M
            compute_dx(&r, dxr, ysr);
302
31.0M
            r.x += YMULT_QUO(ysr, r);
303
31.0M
        }
304
        /* Compute one line's worth of dx/dy. */
305
41.8M
        compute_ldx(&l, ysl);
306
41.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
41.8M
        l.x += fixed_epsilon;
310
41.8M
        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
41.8M
#define rational_floor(tl)\
338
41.8M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
41.8M
#define STEP_LINE(ix, tl)\
340
41.8M
  tl.x += tl.ldi;\
341
41.8M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
41.8M
  ix = rational_floor(tl)
343
344
41.8M
        rxl = rational_floor(l);
345
41.8M
        rxr = rational_floor(r);
346
41.8M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
1.13G
        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.09G
                register int ixl, ixr;
365
366
1.09G
                STEP_LINE(ixl, l);
367
1.09G
                STEP_LINE(ixr, r);
368
1.09G
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
1.09G
                if (ixl != rxl || ixr != rxr) {
370
709M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
709M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
709M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
709M
                    if (code < 0)
374
0
                        goto xit;
375
709M
                    rxl = ixl, rxr = ixr, ry = iy;
376
709M
                }
377
1.09G
#     endif
378
1.09G
        }
379
41.8M
# if !LINEAR_COLOR
380
41.8M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
41.8M
#undef STEP_LINE
385
41.8M
#undef SET_MINIMAL_WIDTH
386
41.8M
#undef CONNECT_RECTANGLES
387
41.8M
#undef FILL_TRAP_RECT
388
41.8M
#undef FILL_TRAP_RECT_DIRECT
389
41.8M
#undef FILL_TRAP_RECT_INRECT
390
41.8M
#undef YMULT_QUO
391
46.5M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
46.5M
        return_if_interrupt(dev->memory);
394
46.5M
        return code;
395
46.5M
    }
396
46.5M
}
gdevddrw.c:gx_fill_trapezoid_as_lc
Line
Count
Source
137
1.02M
{
138
1.02M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
1.02M
    const fixed ymax = fixed_pixround(ytop);
140
141
1.02M
    if (ymin >= ymax)
142
234k
        return 0;    /* no scan lines to sample */
143
789k
    {
144
789k
        int iy = fixed2int_var(ymin);
145
789k
        const int iy1 = fixed2int_var(ymax);
146
789k
        trap_line l, r;
147
789k
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
789k
        const fixed
152
789k
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
789k
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
789k
        const fixed /* partial pixel offset to first line to sample */
155
789k
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
789k
        fixed fxl;
157
789k
        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
789k
# if LINEAR_COLOR
165
789k
            int num_components = dev->color_info.num_components;
166
789k
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
789k
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
789k
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
789k
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
789k
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
789k
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
789k
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
789k
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
789k
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
789k
            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
789k
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
789k
        l.h = left->end.y - left->start.y;
185
789k
        if (l.h == 0)
186
0
           return 0;
187
789k
        r.h = right->end.y - right->start.y;
188
789k
        if (r.h == 0)
189
0
           return 0;
190
789k
        l.x = x0l + (fixed_half - fixed_epsilon);
191
789k
        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
789k
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
789k
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
789k
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
789k
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
789k
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
789k
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
789k
#if LINEAR_COLOR
210
789k
#   define FILL_TRAP_RECT(x,y,w,h)\
211
789k
        (!(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
789k
#define YMULT_QUO(ys, tl)\
228
789k
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
789k
   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
789k
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
789k
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
789k
#endif
264
789k
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
438k
            l.di = 0, l.df = 0;
267
438k
            fxl = 0;
268
438k
        } else {
269
351k
            compute_dx(&l, dxl, ysl);
270
351k
            fxl = YMULT_QUO(ysl, l);
271
351k
            l.x += fxl;
272
351k
        }
273
789k
        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
443k
            r.di = 0, r.df = 0;
286
443k
        }
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
346k
        else if (dxr == dxl && fxl != 0) {
292
164k
            if (l.di == 0)
293
74.6k
                r.di = 0, r.df = l.df;
294
89.6k
            else
295
89.6k
                compute_dx(&r, dxr, ysr);
296
164k
            if (ysr == ysl && r.h == l.h)
297
164k
                r.x += fxl;
298
88
            else
299
88
                r.x += YMULT_QUO(ysr, r);
300
182k
        } else {
301
182k
            compute_dx(&r, dxr, ysr);
302
182k
            r.x += YMULT_QUO(ysr, r);
303
182k
        }
304
        /* Compute one line's worth of dx/dy. */
305
789k
        compute_ldx(&l, ysl);
306
789k
        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
789k
        l.x += fixed_epsilon;
310
789k
        r.x += fixed_epsilon;
311
789k
# 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
789k
            lg.c = lgc;
320
789k
            lg.f = lgf;
321
789k
            lg.num = lgnum;
322
789k
            rg.c = rgc;
323
789k
            rg.f = rgf;
324
789k
            rg.num = rgnum;
325
789k
            xg.c = xgc;
326
789k
            xg.f = xgf;
327
789k
            xg.num = xgnum;
328
789k
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
789k
            if (code < 0)
330
0
                return code;
331
789k
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
789k
            if (code < 0)
333
0
                return code;
334
335
789k
# endif
336
337
789k
#define rational_floor(tl)\
338
789k
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
789k
#define STEP_LINE(ix, tl)\
340
789k
  tl.x += tl.ldi;\
341
789k
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
789k
  ix = rational_floor(tl)
343
344
789k
        rxl = rational_floor(l);
345
789k
        rxr = rational_floor(r);
346
789k
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
23.1M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
23.1M
#     if LINEAR_COLOR
349
23.1M
                if (rxl != rxr) {
350
16.6M
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
16.6M
                    if (code < 0)
352
0
                        goto xit;
353
16.6M
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
16.6M
                    if (code < 0)
355
4
                        goto xit;
356
16.6M
                }
357
23.1M
                if (++iy == iy1)
358
789k
                    break;
359
22.3M
                STEP_LINE(rxl, l);
360
22.3M
                STEP_LINE(rxr, r);
361
22.3M
                step_gradient(&lg, num_components);
362
22.3M
                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
22.3M
        }
379
# if !LINEAR_COLOR
380
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
789k
            code = 0;
383
789k
# endif
384
789k
#undef STEP_LINE
385
789k
#undef SET_MINIMAL_WIDTH
386
789k
#undef CONNECT_RECTANGLES
387
789k
#undef FILL_TRAP_RECT
388
789k
#undef FILL_TRAP_RECT_DIRECT
389
789k
#undef FILL_TRAP_RECT_INRECT
390
789k
#undef YMULT_QUO
391
789k
xit:  if (code < 0 && FILL_DIRECT)
392
4
            return_error(code);
393
789k
        return_if_interrupt(dev->memory);
394
789k
        return code;
395
789k
    }
396
789k
}
gdevddrw.c:gx_fill_trapezoid_ns_lc
Line
Count
Source
137
32.3M
{
138
32.3M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
32.3M
    const fixed ymax = fixed_pixround(ytop);
140
141
32.3M
    if (ymin >= ymax)
142
11.0M
        return 0;    /* no scan lines to sample */
143
21.3M
    {
144
21.3M
        int iy = fixed2int_var(ymin);
145
21.3M
        const int iy1 = fixed2int_var(ymax);
146
21.3M
        trap_line l, r;
147
21.3M
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
21.3M
        const fixed
152
21.3M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
21.3M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
21.3M
        const fixed /* partial pixel offset to first line to sample */
155
21.3M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
21.3M
        fixed fxl;
157
21.3M
        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
21.3M
# if LINEAR_COLOR
165
21.3M
            int num_components = dev->color_info.num_components;
166
21.3M
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
21.3M
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
21.3M
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
21.3M
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
21.3M
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
21.3M
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
21.3M
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
21.3M
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
21.3M
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
21.3M
            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
21.3M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
21.3M
        l.h = left->end.y - left->start.y;
185
21.3M
        if (l.h == 0)
186
0
           return 0;
187
21.3M
        r.h = right->end.y - right->start.y;
188
21.3M
        if (r.h == 0)
189
0
           return 0;
190
21.3M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
21.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
21.3M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
21.3M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
21.3M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
21.3M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
21.3M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
21.3M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
21.3M
#if LINEAR_COLOR
210
21.3M
#   define FILL_TRAP_RECT(x,y,w,h)\
211
21.3M
        (!(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
21.3M
#define YMULT_QUO(ys, tl)\
228
21.3M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
21.3M
   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
21.3M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
21.3M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
21.3M
#endif
264
21.3M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
3.93M
            l.di = 0, l.df = 0;
267
3.93M
            fxl = 0;
268
17.4M
        } else {
269
17.4M
            compute_dx(&l, dxl, ysl);
270
17.4M
            fxl = YMULT_QUO(ysl, l);
271
17.4M
            l.x += fxl;
272
17.4M
        }
273
21.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
                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
3.93M
            r.di = 0, r.df = 0;
286
3.93M
        }
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
17.4M
        else if (dxr == dxl && fxl != 0) {
292
1.57M
            if (l.di == 0)
293
460k
                r.di = 0, r.df = l.df;
294
1.11M
            else
295
1.11M
                compute_dx(&r, dxr, ysr);
296
1.57M
            if (ysr == ysl && r.h == l.h)
297
768k
                r.x += fxl;
298
807k
            else
299
807k
                r.x += YMULT_QUO(ysr, r);
300
15.8M
        } else {
301
15.8M
            compute_dx(&r, dxr, ysr);
302
15.8M
            r.x += YMULT_QUO(ysr, r);
303
15.8M
        }
304
        /* Compute one line's worth of dx/dy. */
305
21.3M
        compute_ldx(&l, ysl);
306
21.3M
        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
21.3M
        l.x += fixed_epsilon;
310
21.3M
        r.x += fixed_epsilon;
311
21.3M
# 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
21.3M
            lg.c = lgc;
320
21.3M
            lg.f = lgf;
321
21.3M
            lg.num = lgnum;
322
21.3M
            rg.c = rgc;
323
21.3M
            rg.f = rgf;
324
21.3M
            rg.num = rgnum;
325
21.3M
            xg.c = xgc;
326
21.3M
            xg.f = xgf;
327
21.3M
            xg.num = xgnum;
328
21.3M
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
21.3M
            if (code < 0)
330
0
                return code;
331
21.3M
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
21.3M
            if (code < 0)
333
0
                return code;
334
335
21.3M
# endif
336
337
21.3M
#define rational_floor(tl)\
338
21.3M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
21.3M
#define STEP_LINE(ix, tl)\
340
21.3M
  tl.x += tl.ldi;\
341
21.3M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
21.3M
  ix = rational_floor(tl)
343
344
21.3M
        rxl = rational_floor(l);
345
21.3M
        rxr = rational_floor(r);
346
21.3M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
480M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
480M
#     if LINEAR_COLOR
349
480M
                if (rxl != rxr) {
350
36.9M
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
36.9M
                    if (code < 0)
352
0
                        goto xit;
353
36.9M
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
36.9M
                    if (code < 0)
355
13
                        goto xit;
356
36.9M
                }
357
480M
                if (++iy == iy1)
358
21.3M
                    break;
359
458M
                STEP_LINE(rxl, l);
360
458M
                STEP_LINE(rxr, r);
361
458M
                step_gradient(&lg, num_components);
362
458M
                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
458M
        }
379
# if !LINEAR_COLOR
380
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
21.3M
            code = 0;
383
21.3M
# endif
384
21.3M
#undef STEP_LINE
385
21.3M
#undef SET_MINIMAL_WIDTH
386
21.3M
#undef CONNECT_RECTANGLES
387
21.3M
#undef FILL_TRAP_RECT
388
21.3M
#undef FILL_TRAP_RECT_DIRECT
389
21.3M
#undef FILL_TRAP_RECT_INRECT
390
21.3M
#undef YMULT_QUO
391
21.3M
xit:  if (code < 0 && FILL_DIRECT)
392
13
            return_error(code);
393
21.3M
        return_if_interrupt(dev->memory);
394
21.3M
        return code;
395
21.3M
    }
396
21.3M
}
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