Coverage Report

Created: 2025-06-10 07:27

/src/ghostpdl/base/gxdtfill.h
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) 2001-2023 Artifex Software, Inc.
2
   All Rights Reserved.
3
4
   This software is provided AS-IS with no warranty, either express or
5
   implied.
6
7
   This software is distributed under license and may not be copied,
8
   modified or distributed except as expressly authorized under the terms
9
   of the license contained in the file LICENSE in this distribution.
10
11
   Refer to licensing information at http://www.artifex.com or contact
12
   Artifex Software, Inc.,  39 Mesa Street, Suite 108A, San Francisco,
13
   CA 94129, USA, for further information.
14
*/
15
16
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
23.6M
{
138
23.6M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
23.6M
    const fixed ymax = fixed_pixround(ytop);
140
141
23.6M
    if (ymin >= ymax)
142
5.19M
        return 0;    /* no scan lines to sample */
143
18.4M
    {
144
18.4M
        int iy = fixed2int_var(ymin);
145
18.4M
        const int iy1 = fixed2int_var(ymax);
146
18.4M
        trap_line l, r;
147
18.4M
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
18.4M
        const fixed
152
18.4M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
18.4M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
18.4M
        const fixed /* partial pixel offset to first line to sample */
155
18.4M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
18.4M
        fixed fxl;
157
18.4M
        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
18.3M
            dev_proc_fill_rectangle((*fill_rect)) =
179
18.3M
                dev_proc(dev, fill_rectangle);
180
# endif
181
182
18.4M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
18.4M
        l.h = left->end.y - left->start.y;
185
18.4M
        if (l.h == 0)
186
3
           return 0;
187
18.4M
        r.h = right->end.y - right->start.y;
188
18.4M
        if (r.h == 0)
189
3
           return 0;
190
18.4M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
18.4M
        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
18.4M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
551M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
551M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
18.4M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
66.2M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
66.2M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
#if LINEAR_COLOR
210
#   define FILL_TRAP_RECT(x,y,w,h)\
211
307k
        (!(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
617M
        (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
18.4M
#define YMULT_QUO(ys, tl)\
228
25.3M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
25.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
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
1.86G
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
1.19G
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
#endif
264
18.4M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
4.82M
            l.di = 0, l.df = 0;
267
4.82M
            fxl = 0;
268
13.5M
        } else {
269
13.5M
            compute_dx(&l, dxl, ysl);
270
13.5M
            fxl = YMULT_QUO(ysl, l);
271
13.5M
            l.x += fxl;
272
13.5M
        }
273
18.4M
        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
5.40M
                if (l.di == 0 && l.df == 0) {
278
3.20M
                    rxl = fixed2int_var(l.x);
279
3.20M
                    rxr = fixed2int_var(r.x);
280
3.20M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
3.20M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
3.20M
                    goto xit;
283
3.20M
                }
284
2.19M
#     endif
285
2.19M
            r.di = 0, r.df = 0;
286
2.19M
        }
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
13.0M
        else if (dxr == dxl && fxl != 0) {
292
1.70M
            if (l.di == 0)
293
443k
                r.di = 0, r.df = l.df;
294
1.26M
            else
295
1.26M
                compute_dx(&r, dxr, ysr);
296
1.70M
            if (ysr == ysl && r.h == l.h)
297
1.20M
                r.x += fxl;
298
496k
            else
299
496k
                r.x += YMULT_QUO(ysr, r);
300
11.2M
        } else {
301
11.2M
            compute_dx(&r, dxr, ysr);
302
11.2M
            r.x += YMULT_QUO(ysr, r);
303
11.2M
        }
304
        /* Compute one line's worth of dx/dy. */
305
15.1M
        compute_ldx(&l, ysl);
306
15.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
15.1M
        l.x += fixed_epsilon;
310
15.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
5.61k
            if (code < 0)
330
0
                return code;
331
5.61k
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
5.61k
            if (code < 0)
333
0
                return code;
334
335
5.61k
# endif
336
337
5.61k
#define rational_floor(tl)\
338
3.72G
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
5.61k
#define STEP_LINE(ix, tl)\
340
3.69G
  tl.x += tl.ldi;\
341
3.69G
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
3.69G
  ix = rational_floor(tl)
343
344
15.1M
        rxl = rational_floor(l);
345
15.1M
        rxr = rational_floor(r);
346
15.1M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
1.86G
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
#     if LINEAR_COLOR
349
365k
                if (rxl != rxr) {
350
307k
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
307k
                    if (code < 0)
352
0
                        goto xit;
353
307k
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
307k
                    if (code < 0)
355
0
                        goto xit;
356
307k
                }
357
365k
                if (++iy == iy1)
358
5.61k
                    break;
359
360k
                STEP_LINE(rxl, l);
360
360k
                STEP_LINE(rxr, r);
361
360k
                step_gradient(&lg, num_components);
362
360k
                step_gradient(&rg, num_components);
363
#     else
364
                register int ixl, ixr;
365
366
1.84G
                STEP_LINE(ixl, l);
367
1.84G
                STEP_LINE(ixr, r);
368
1.84G
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
1.84G
                if (ixl != rxl || ixr != rxr) {
370
599M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
599M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
599M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
599M
                    if (code < 0)
374
0
                        goto xit;
375
599M
                    rxl = ixl, rxr = ixr, ry = iy;
376
599M
                }
377
#     endif
378
360k
        }
379
# if !LINEAR_COLOR
380
15.1M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
5.61k
            code = 0;
383
5.61k
# endif
384
5.61k
#undef STEP_LINE
385
5.61k
#undef SET_MINIMAL_WIDTH
386
5.61k
#undef CONNECT_RECTANGLES
387
5.61k
#undef FILL_TRAP_RECT
388
5.61k
#undef FILL_TRAP_RECT_DIRECT
389
5.61k
#undef FILL_TRAP_RECT_INRECT
390
5.61k
#undef YMULT_QUO
391
18.4M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
18.4M
        return_if_interrupt(dev->memory);
394
18.4M
        return code;
395
18.4M
    }
396
18.4M
}
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
628k
{
138
628k
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
628k
    const fixed ymax = fixed_pixround(ytop);
140
141
628k
    if (ymin >= ymax)
142
18.6k
        return 0;    /* no scan lines to sample */
143
609k
    {
144
609k
        int iy = fixed2int_var(ymin);
145
609k
        const int iy1 = fixed2int_var(ymax);
146
609k
        trap_line l, r;
147
609k
        register int rxl, rxr;
148
609k
#if !LINEAR_COLOR
149
609k
        int ry;
150
609k
#endif
151
609k
        const fixed
152
609k
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
609k
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
609k
        const fixed /* partial pixel offset to first line to sample */
155
609k
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
609k
        fixed fxl;
157
609k
        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
609k
            gx_color_index cindex = pdevc->colors.pure;
178
609k
            dev_proc_fill_rectangle((*fill_rect)) =
179
609k
                dev_proc(dev, fill_rectangle);
180
609k
# endif
181
182
609k
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
609k
        l.h = left->end.y - left->start.y;
185
609k
        if (l.h == 0)
186
0
           return 0;
187
609k
        r.h = right->end.y - right->start.y;
188
609k
        if (r.h == 0)
189
0
           return 0;
190
609k
        l.x = x0l + (fixed_half - fixed_epsilon);
191
609k
        r.x = x0r + (fixed_half - fixed_epsilon);
192
609k
#if !LINEAR_COLOR
193
609k
        ry = iy;
194
609k
#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
609k
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
609k
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
609k
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
609k
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
609k
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
609k
   (*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
609k
#   define FILL_TRAP_RECT(x,y,w,h)\
214
609k
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
609k
#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
609k
#define YMULT_QUO(ys, tl)\
228
609k
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
609k
   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
609k
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
609k
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
609k
#endif
264
609k
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
118k
            l.di = 0, l.df = 0;
267
118k
            fxl = 0;
268
491k
        } else {
269
491k
            compute_dx(&l, dxl, ysl);
270
491k
            fxl = YMULT_QUO(ysl, l);
271
491k
            l.x += fxl;
272
491k
        }
273
609k
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
97.6k
#     if !LINEAR_COLOR
277
97.6k
                if (l.di == 0 && l.df == 0) {
278
92.8k
                    rxl = fixed2int_var(l.x);
279
92.8k
                    rxr = fixed2int_var(r.x);
280
92.8k
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
92.8k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
92.8k
                    goto xit;
283
92.8k
                }
284
4.79k
#     endif
285
4.79k
            r.di = 0, r.df = 0;
286
4.79k
        }
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
512k
        else if (dxr == dxl && fxl != 0) {
292
281k
            if (l.di == 0)
293
150k
                r.di = 0, r.df = l.df;
294
131k
            else
295
131k
                compute_dx(&r, dxr, ysr);
296
281k
            if (ysr == ysl && r.h == l.h)
297
281k
                r.x += fxl;
298
0
            else
299
0
                r.x += YMULT_QUO(ysr, r);
300
281k
        } else {
301
230k
            compute_dx(&r, dxr, ysr);
302
230k
            r.x += YMULT_QUO(ysr, r);
303
230k
        }
304
        /* Compute one line's worth of dx/dy. */
305
516k
        compute_ldx(&l, ysl);
306
516k
        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
516k
        l.x += fixed_epsilon;
310
516k
        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
516k
#define rational_floor(tl)\
338
516k
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
516k
#define STEP_LINE(ix, tl)\
340
516k
  tl.x += tl.ldi;\
341
516k
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
516k
  ix = rational_floor(tl)
343
344
516k
        rxl = rational_floor(l);
345
516k
        rxr = rational_floor(r);
346
516k
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
59.7M
        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
59.2M
                register int ixl, ixr;
365
366
59.2M
                STEP_LINE(ixl, l);
367
59.2M
                STEP_LINE(ixr, r);
368
59.2M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
59.2M
                if (ixl != rxl || ixr != rxr) {
370
16.1M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
16.1M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
16.1M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
16.1M
                    if (code < 0)
374
0
                        goto xit;
375
16.1M
                    rxl = ixl, rxr = ixr, ry = iy;
376
16.1M
                }
377
59.2M
#     endif
378
59.2M
        }
379
516k
# if !LINEAR_COLOR
380
516k
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
516k
#undef STEP_LINE
385
516k
#undef SET_MINIMAL_WIDTH
386
516k
#undef CONNECT_RECTANGLES
387
516k
#undef FILL_TRAP_RECT
388
516k
#undef FILL_TRAP_RECT_DIRECT
389
516k
#undef FILL_TRAP_RECT_INRECT
390
516k
#undef YMULT_QUO
391
609k
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
609k
        return_if_interrupt(dev->memory);
394
609k
        return code;
395
609k
    }
396
609k
}
gdevddrw.c:gx_fill_trapezoid_as_nd
Line
Count
Source
137
967k
{
138
967k
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
967k
    const fixed ymax = fixed_pixround(ytop);
140
141
967k
    if (ymin >= ymax)
142
9.94k
        return 0;    /* no scan lines to sample */
143
957k
    {
144
957k
        int iy = fixed2int_var(ymin);
145
957k
        const int iy1 = fixed2int_var(ymax);
146
957k
        trap_line l, r;
147
957k
        register int rxl, rxr;
148
957k
#if !LINEAR_COLOR
149
957k
        int ry;
150
957k
#endif
151
957k
        const fixed
152
957k
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
957k
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
957k
        const fixed /* partial pixel offset to first line to sample */
155
957k
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
957k
        fixed fxl;
157
957k
        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
957k
            gx_color_index cindex = pdevc->colors.pure;
178
957k
            dev_proc_fill_rectangle((*fill_rect)) =
179
957k
                dev_proc(dev, fill_rectangle);
180
957k
# endif
181
182
957k
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
957k
        l.h = left->end.y - left->start.y;
185
957k
        if (l.h == 0)
186
0
           return 0;
187
957k
        r.h = right->end.y - right->start.y;
188
957k
        if (r.h == 0)
189
0
           return 0;
190
957k
        l.x = x0l + (fixed_half - fixed_epsilon);
191
957k
        r.x = x0r + (fixed_half - fixed_epsilon);
192
957k
#if !LINEAR_COLOR
193
957k
        ry = iy;
194
957k
#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
957k
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
957k
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
957k
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
957k
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
957k
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
957k
   (*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
957k
#   define FILL_TRAP_RECT(x,y,w,h)\
214
957k
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
957k
#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
957k
#define YMULT_QUO(ys, tl)\
228
957k
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
957k
   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
957k
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
957k
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
957k
#endif
264
957k
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
163k
            l.di = 0, l.df = 0;
267
163k
            fxl = 0;
268
793k
        } else {
269
793k
            compute_dx(&l, dxl, ysl);
270
793k
            fxl = YMULT_QUO(ysl, l);
271
793k
            l.x += fxl;
272
793k
        }
273
957k
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
147k
#     if !LINEAR_COLOR
277
147k
                if (l.di == 0 && l.df == 0) {
278
138k
                    rxl = fixed2int_var(l.x);
279
138k
                    rxr = fixed2int_var(r.x);
280
138k
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
138k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
138k
                    goto xit;
283
138k
                }
284
8.77k
#     endif
285
8.77k
            r.di = 0, r.df = 0;
286
8.77k
        }
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
810k
        else if (dxr == dxl && fxl != 0) {
292
99.8k
            if (l.di == 0)
293
54.7k
                r.di = 0, r.df = l.df;
294
45.0k
            else
295
45.0k
                compute_dx(&r, dxr, ysr);
296
99.8k
            if (ysr == ysl && r.h == l.h)
297
99.7k
                r.x += fxl;
298
30
            else
299
30
                r.x += YMULT_QUO(ysr, r);
300
710k
        } else {
301
710k
            compute_dx(&r, dxr, ysr);
302
710k
            r.x += YMULT_QUO(ysr, r);
303
710k
        }
304
        /* Compute one line's worth of dx/dy. */
305
818k
        compute_ldx(&l, ysl);
306
818k
        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
818k
        l.x += fixed_epsilon;
310
818k
        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
818k
#define rational_floor(tl)\
338
818k
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
818k
#define STEP_LINE(ix, tl)\
340
818k
  tl.x += tl.ldi;\
341
818k
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
818k
  ix = rational_floor(tl)
343
344
818k
        rxl = rational_floor(l);
345
818k
        rxr = rational_floor(r);
346
818k
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
175M
        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
174M
                register int ixl, ixr;
365
366
174M
                STEP_LINE(ixl, l);
367
174M
                STEP_LINE(ixr, r);
368
174M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
174M
                if (ixl != rxl || ixr != rxr) {
370
139M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
139M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
139M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
139M
                    if (code < 0)
374
0
                        goto xit;
375
139M
                    rxl = ixl, rxr = ixr, ry = iy;
376
139M
                }
377
174M
#     endif
378
174M
        }
379
818k
# if !LINEAR_COLOR
380
818k
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
818k
#undef STEP_LINE
385
818k
#undef SET_MINIMAL_WIDTH
386
818k
#undef CONNECT_RECTANGLES
387
818k
#undef FILL_TRAP_RECT
388
818k
#undef FILL_TRAP_RECT_DIRECT
389
818k
#undef FILL_TRAP_RECT_INRECT
390
818k
#undef YMULT_QUO
391
957k
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
957k
        return_if_interrupt(dev->memory);
394
957k
        return code;
395
957k
    }
396
957k
}
gdevddrw.c:gx_fill_trapezoid_ns_fd
Line
Count
Source
137
6.06M
{
138
6.06M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
6.06M
    const fixed ymax = fixed_pixround(ytop);
140
141
6.06M
    if (ymin >= ymax)
142
1.04M
        return 0;    /* no scan lines to sample */
143
5.02M
    {
144
5.02M
        int iy = fixed2int_var(ymin);
145
5.02M
        const int iy1 = fixed2int_var(ymax);
146
5.02M
        trap_line l, r;
147
5.02M
        register int rxl, rxr;
148
5.02M
#if !LINEAR_COLOR
149
5.02M
        int ry;
150
5.02M
#endif
151
5.02M
        const fixed
152
5.02M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
5.02M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
5.02M
        const fixed /* partial pixel offset to first line to sample */
155
5.02M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
5.02M
        fixed fxl;
157
5.02M
        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
5.02M
            gx_color_index cindex = pdevc->colors.pure;
178
5.02M
            dev_proc_fill_rectangle((*fill_rect)) =
179
5.02M
                dev_proc(dev, fill_rectangle);
180
5.02M
# endif
181
182
5.02M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
5.02M
        l.h = left->end.y - left->start.y;
185
5.02M
        if (l.h == 0)
186
3
           return 0;
187
5.02M
        r.h = right->end.y - right->start.y;
188
5.02M
        if (r.h == 0)
189
3
           return 0;
190
5.02M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
5.02M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
5.02M
#if !LINEAR_COLOR
193
5.02M
        ry = iy;
194
5.02M
#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
5.02M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
5.02M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
5.02M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
5.02M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
5.02M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
5.02M
   (*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
5.02M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
5.02M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
5.02M
#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
5.02M
#define YMULT_QUO(ys, tl)\
228
5.02M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
5.02M
   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
5.02M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
5.02M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
5.02M
#endif
264
5.02M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
1.72M
            l.di = 0, l.df = 0;
267
1.72M
            fxl = 0;
268
3.29M
        } else {
269
3.29M
            compute_dx(&l, dxl, ysl);
270
3.29M
            fxl = YMULT_QUO(ysl, l);
271
3.29M
            l.x += fxl;
272
3.29M
        }
273
5.02M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
1.76M
#     if !LINEAR_COLOR
277
1.76M
                if (l.di == 0 && l.df == 0) {
278
1.31M
                    rxl = fixed2int_var(l.x);
279
1.31M
                    rxr = fixed2int_var(r.x);
280
1.31M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
1.31M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
1.31M
                    goto xit;
283
1.31M
                }
284
456k
#     endif
285
456k
            r.di = 0, r.df = 0;
286
456k
        }
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
3.25M
        else if (dxr == dxl && fxl != 0) {
292
552k
            if (l.di == 0)
293
94.0k
                r.di = 0, r.df = l.df;
294
458k
            else
295
458k
                compute_dx(&r, dxr, ysr);
296
552k
            if (ysr == ysl && r.h == l.h)
297
211k
                r.x += fxl;
298
341k
            else
299
341k
                r.x += YMULT_QUO(ysr, r);
300
2.70M
        } else {
301
2.70M
            compute_dx(&r, dxr, ysr);
302
2.70M
            r.x += YMULT_QUO(ysr, r);
303
2.70M
        }
304
        /* Compute one line's worth of dx/dy. */
305
3.70M
        compute_ldx(&l, ysl);
306
3.70M
        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
3.70M
        l.x += fixed_epsilon;
310
3.70M
        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
3.70M
#define rational_floor(tl)\
338
3.70M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
3.70M
#define STEP_LINE(ix, tl)\
340
3.70M
  tl.x += tl.ldi;\
341
3.70M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
3.70M
  ix = rational_floor(tl)
343
344
3.70M
        rxl = rational_floor(l);
345
3.70M
        rxr = rational_floor(r);
346
3.70M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
1.15G
        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.15G
                register int ixl, ixr;
365
366
1.15G
                STEP_LINE(ixl, l);
367
1.15G
                STEP_LINE(ixr, r);
368
1.15G
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
1.15G
                if (ixl != rxl || ixr != rxr) {
370
44.5M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
44.5M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
44.5M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
44.5M
                    if (code < 0)
374
0
                        goto xit;
375
44.5M
                    rxl = ixl, rxr = ixr, ry = iy;
376
44.5M
                }
377
1.15G
#     endif
378
1.15G
        }
379
3.70M
# if !LINEAR_COLOR
380
3.70M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
3.70M
#undef STEP_LINE
385
3.70M
#undef SET_MINIMAL_WIDTH
386
3.70M
#undef CONNECT_RECTANGLES
387
3.70M
#undef FILL_TRAP_RECT
388
3.70M
#undef FILL_TRAP_RECT_DIRECT
389
3.70M
#undef FILL_TRAP_RECT_INRECT
390
3.70M
#undef YMULT_QUO
391
5.02M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
5.02M
        return_if_interrupt(dev->memory);
394
5.02M
        return code;
395
5.02M
    }
396
5.02M
}
gdevddrw.c:gx_fill_trapezoid_ns_nd
Line
Count
Source
137
15.9M
{
138
15.9M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
15.9M
    const fixed ymax = fixed_pixround(ytop);
140
141
15.9M
    if (ymin >= ymax)
142
4.12M
        return 0;    /* no scan lines to sample */
143
11.8M
    {
144
11.8M
        int iy = fixed2int_var(ymin);
145
11.8M
        const int iy1 = fixed2int_var(ymax);
146
11.8M
        trap_line l, r;
147
11.8M
        register int rxl, rxr;
148
11.8M
#if !LINEAR_COLOR
149
11.8M
        int ry;
150
11.8M
#endif
151
11.8M
        const fixed
152
11.8M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
11.8M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
11.8M
        const fixed /* partial pixel offset to first line to sample */
155
11.8M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
11.8M
        fixed fxl;
157
11.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
11.8M
            gx_color_index cindex = pdevc->colors.pure;
178
11.8M
            dev_proc_fill_rectangle((*fill_rect)) =
179
11.8M
                dev_proc(dev, fill_rectangle);
180
11.8M
# endif
181
182
11.8M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
11.8M
        l.h = left->end.y - left->start.y;
185
11.8M
        if (l.h == 0)
186
0
           return 0;
187
11.8M
        r.h = right->end.y - right->start.y;
188
11.8M
        if (r.h == 0)
189
0
           return 0;
190
11.8M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
11.8M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
11.8M
#if !LINEAR_COLOR
193
11.8M
        ry = iy;
194
11.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
11.8M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
11.8M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
11.8M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
11.8M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
11.8M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
11.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
11.8M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
11.8M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
11.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
11.8M
#define YMULT_QUO(ys, tl)\
228
11.8M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
11.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
11.8M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
11.8M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
11.8M
#endif
264
11.8M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
2.81M
            l.di = 0, l.df = 0;
267
2.81M
            fxl = 0;
268
8.99M
        } else {
269
8.99M
            compute_dx(&l, dxl, ysl);
270
8.99M
            fxl = YMULT_QUO(ysl, l);
271
8.99M
            l.x += fxl;
272
8.99M
        }
273
11.8M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
3.38M
#     if !LINEAR_COLOR
277
3.38M
                if (l.di == 0 && l.df == 0) {
278
1.66M
                    rxl = fixed2int_var(l.x);
279
1.66M
                    rxr = fixed2int_var(r.x);
280
1.66M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
1.66M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
1.66M
                    goto xit;
283
1.66M
                }
284
1.72M
#     endif
285
1.72M
            r.di = 0, r.df = 0;
286
1.72M
        }
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
8.42M
        else if (dxr == dxl && fxl != 0) {
292
768k
            if (l.di == 0)
293
143k
                r.di = 0, r.df = l.df;
294
625k
            else
295
625k
                compute_dx(&r, dxr, ysr);
296
768k
            if (ysr == ysl && r.h == l.h)
297
613k
                r.x += fxl;
298
155k
            else
299
155k
                r.x += YMULT_QUO(ysr, r);
300
7.65M
        } else {
301
7.65M
            compute_dx(&r, dxr, ysr);
302
7.65M
            r.x += YMULT_QUO(ysr, r);
303
7.65M
        }
304
        /* Compute one line's worth of dx/dy. */
305
10.1M
        compute_ldx(&l, ysl);
306
10.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
10.1M
        l.x += fixed_epsilon;
310
10.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
10.1M
#define rational_floor(tl)\
338
10.1M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
10.1M
#define STEP_LINE(ix, tl)\
340
10.1M
  tl.x += tl.ldi;\
341
10.1M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
10.1M
  ix = rational_floor(tl)
343
344
10.1M
        rxl = rational_floor(l);
345
10.1M
        rxr = rational_floor(r);
346
10.1M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
469M
        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
459M
                register int ixl, ixr;
365
366
459M
                STEP_LINE(ixl, l);
367
459M
                STEP_LINE(ixr, r);
368
459M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
459M
                if (ixl != rxl || ixr != rxr) {
370
399M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
399M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
399M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
399M
                    if (code < 0)
374
0
                        goto xit;
375
399M
                    rxl = ixl, rxr = ixr, ry = iy;
376
399M
                }
377
459M
#     endif
378
459M
        }
379
10.1M
# if !LINEAR_COLOR
380
10.1M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
10.1M
#undef STEP_LINE
385
10.1M
#undef SET_MINIMAL_WIDTH
386
10.1M
#undef CONNECT_RECTANGLES
387
10.1M
#undef FILL_TRAP_RECT
388
10.1M
#undef FILL_TRAP_RECT_DIRECT
389
10.1M
#undef FILL_TRAP_RECT_INRECT
390
10.1M
#undef YMULT_QUO
391
11.8M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
11.8M
        return_if_interrupt(dev->memory);
394
11.8M
        return code;
395
11.8M
    }
396
11.8M
}
gdevddrw.c:gx_fill_trapezoid_as_lc
Line
Count
Source
137
1.44k
{
138
1.44k
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
1.44k
    const fixed ymax = fixed_pixround(ytop);
140
141
1.44k
    if (ymin >= ymax)
142
14
        return 0;    /* no scan lines to sample */
143
1.42k
    {
144
1.42k
        int iy = fixed2int_var(ymin);
145
1.42k
        const int iy1 = fixed2int_var(ymax);
146
1.42k
        trap_line l, r;
147
1.42k
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
1.42k
        const fixed
152
1.42k
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
1.42k
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
1.42k
        const fixed /* partial pixel offset to first line to sample */
155
1.42k
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
1.42k
        fixed fxl;
157
1.42k
        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
1.42k
# if LINEAR_COLOR
165
1.42k
            int num_components = dev->color_info.num_components;
166
1.42k
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
1.42k
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
1.42k
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
1.42k
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
1.42k
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
1.42k
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
1.42k
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
1.42k
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
1.42k
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
1.42k
            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
1.42k
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
1.42k
        l.h = left->end.y - left->start.y;
185
1.42k
        if (l.h == 0)
186
0
           return 0;
187
1.42k
        r.h = right->end.y - right->start.y;
188
1.42k
        if (r.h == 0)
189
0
           return 0;
190
1.42k
        l.x = x0l + (fixed_half - fixed_epsilon);
191
1.42k
        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
1.42k
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
1.42k
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
1.42k
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
1.42k
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
1.42k
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
1.42k
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
1.42k
#if LINEAR_COLOR
210
1.42k
#   define FILL_TRAP_RECT(x,y,w,h)\
211
1.42k
        (!(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
1.42k
#define YMULT_QUO(ys, tl)\
228
1.42k
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
1.42k
   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.42k
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
1.42k
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
1.42k
#endif
264
1.42k
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
84
            l.di = 0, l.df = 0;
267
84
            fxl = 0;
268
1.34k
        } else {
269
1.34k
            compute_dx(&l, dxl, ysl);
270
1.34k
            fxl = YMULT_QUO(ysl, l);
271
1.34k
            l.x += fxl;
272
1.34k
        }
273
1.42k
        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
112
            r.di = 0, r.df = 0;
286
112
        }
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.31k
        else if (dxr == dxl && fxl != 0) {
292
868
            if (l.di == 0)
293
427
                r.di = 0, r.df = l.df;
294
441
            else
295
441
                compute_dx(&r, dxr, ysr);
296
868
            if (ysr == ysl && r.h == l.h)
297
868
                r.x += fxl;
298
0
            else
299
0
                r.x += YMULT_QUO(ysr, r);
300
868
        } else {
301
448
            compute_dx(&r, dxr, ysr);
302
448
            r.x += YMULT_QUO(ysr, r);
303
448
        }
304
        /* Compute one line's worth of dx/dy. */
305
1.42k
        compute_ldx(&l, ysl);
306
1.42k
        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.42k
        l.x += fixed_epsilon;
310
1.42k
        r.x += fixed_epsilon;
311
1.42k
# 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
1.42k
            lg.c = lgc;
320
1.42k
            lg.f = lgf;
321
1.42k
            lg.num = lgnum;
322
1.42k
            rg.c = rgc;
323
1.42k
            rg.f = rgf;
324
1.42k
            rg.num = rgnum;
325
1.42k
            xg.c = xgc;
326
1.42k
            xg.f = xgf;
327
1.42k
            xg.num = xgnum;
328
1.42k
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
1.42k
            if (code < 0)
330
0
                return code;
331
1.42k
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
1.42k
            if (code < 0)
333
0
                return code;
334
335
1.42k
# endif
336
337
1.42k
#define rational_floor(tl)\
338
1.42k
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
1.42k
#define STEP_LINE(ix, tl)\
340
1.42k
  tl.x += tl.ldi;\
341
1.42k
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
1.42k
  ix = rational_floor(tl)
343
344
1.42k
        rxl = rational_floor(l);
345
1.42k
        rxr = rational_floor(r);
346
1.42k
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
44.4k
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
44.4k
#     if LINEAR_COLOR
349
44.4k
                if (rxl != rxr) {
350
39.9k
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
39.9k
                    if (code < 0)
352
0
                        goto xit;
353
39.9k
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
39.9k
                    if (code < 0)
355
0
                        goto xit;
356
39.9k
                }
357
44.4k
                if (++iy == iy1)
358
1.42k
                    break;
359
42.9k
                STEP_LINE(rxl, l);
360
42.9k
                STEP_LINE(rxr, r);
361
42.9k
                step_gradient(&lg, num_components);
362
42.9k
                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
42.9k
        }
379
# if !LINEAR_COLOR
380
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
1.42k
            code = 0;
383
1.42k
# endif
384
1.42k
#undef STEP_LINE
385
1.42k
#undef SET_MINIMAL_WIDTH
386
1.42k
#undef CONNECT_RECTANGLES
387
1.42k
#undef FILL_TRAP_RECT
388
1.42k
#undef FILL_TRAP_RECT_DIRECT
389
1.42k
#undef FILL_TRAP_RECT_INRECT
390
1.42k
#undef YMULT_QUO
391
1.42k
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
1.42k
        return_if_interrupt(dev->memory);
394
1.42k
        return code;
395
1.42k
    }
396
1.42k
}
gdevddrw.c:gx_fill_trapezoid_ns_lc
Line
Count
Source
137
4.25k
{
138
4.25k
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
4.25k
    const fixed ymax = fixed_pixround(ytop);
140
141
4.25k
    if (ymin >= ymax)
142
70
        return 0;    /* no scan lines to sample */
143
4.18k
    {
144
4.18k
        int iy = fixed2int_var(ymin);
145
4.18k
        const int iy1 = fixed2int_var(ymax);
146
4.18k
        trap_line l, r;
147
4.18k
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
4.18k
        const fixed
152
4.18k
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
4.18k
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
4.18k
        const fixed /* partial pixel offset to first line to sample */
155
4.18k
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
4.18k
        fixed fxl;
157
4.18k
        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
4.18k
# if LINEAR_COLOR
165
4.18k
            int num_components = dev->color_info.num_components;
166
4.18k
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
4.18k
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
4.18k
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
4.18k
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
4.18k
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
4.18k
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
4.18k
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
4.18k
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
4.18k
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
4.18k
            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
4.18k
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
4.18k
        l.h = left->end.y - left->start.y;
185
4.18k
        if (l.h == 0)
186
0
           return 0;
187
4.18k
        r.h = right->end.y - right->start.y;
188
4.18k
        if (r.h == 0)
189
0
           return 0;
190
4.18k
        l.x = x0l + (fixed_half - fixed_epsilon);
191
4.18k
        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
4.18k
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
4.18k
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
4.18k
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
4.18k
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
4.18k
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
4.18k
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
4.18k
#if LINEAR_COLOR
210
4.18k
#   define FILL_TRAP_RECT(x,y,w,h)\
211
4.18k
        (!(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
4.18k
#define YMULT_QUO(ys, tl)\
228
4.18k
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
4.18k
   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
4.18k
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
4.18k
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
4.18k
#endif
264
4.18k
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
164
            l.di = 0, l.df = 0;
267
164
            fxl = 0;
268
4.02k
        } else {
269
4.02k
            compute_dx(&l, dxl, ysl);
270
4.02k
            fxl = YMULT_QUO(ysl, l);
271
4.02k
            l.x += fxl;
272
4.02k
        }
273
4.18k
        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
160
            r.di = 0, r.df = 0;
286
160
        }
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
4.02k
        else if (dxr == dxl && fxl != 0) {
292
1.12k
            if (l.di == 0)
293
497
                r.di = 0, r.df = l.df;
294
627
            else
295
627
                compute_dx(&r, dxr, ysr);
296
1.12k
            if (ysr == ysl && r.h == l.h)
297
1.12k
                r.x += fxl;
298
0
            else
299
0
                r.x += YMULT_QUO(ysr, r);
300
2.90k
        } else {
301
2.90k
            compute_dx(&r, dxr, ysr);
302
2.90k
            r.x += YMULT_QUO(ysr, r);
303
2.90k
        }
304
        /* Compute one line's worth of dx/dy. */
305
4.18k
        compute_ldx(&l, ysl);
306
4.18k
        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
4.18k
        l.x += fixed_epsilon;
310
4.18k
        r.x += fixed_epsilon;
311
4.18k
# 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
4.18k
            lg.c = lgc;
320
4.18k
            lg.f = lgf;
321
4.18k
            lg.num = lgnum;
322
4.18k
            rg.c = rgc;
323
4.18k
            rg.f = rgf;
324
4.18k
            rg.num = rgnum;
325
4.18k
            xg.c = xgc;
326
4.18k
            xg.f = xgf;
327
4.18k
            xg.num = xgnum;
328
4.18k
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
4.18k
            if (code < 0)
330
0
                return code;
331
4.18k
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
4.18k
            if (code < 0)
333
0
                return code;
334
335
4.18k
# endif
336
337
4.18k
#define rational_floor(tl)\
338
4.18k
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
4.18k
#define STEP_LINE(ix, tl)\
340
4.18k
  tl.x += tl.ldi;\
341
4.18k
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
4.18k
  ix = rational_floor(tl)
343
344
4.18k
        rxl = rational_floor(l);
345
4.18k
        rxr = rational_floor(r);
346
4.18k
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
321k
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
321k
#     if LINEAR_COLOR
349
321k
                if (rxl != rxr) {
350
267k
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
267k
                    if (code < 0)
352
0
                        goto xit;
353
267k
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
267k
                    if (code < 0)
355
0
                        goto xit;
356
267k
                }
357
321k
                if (++iy == iy1)
358
4.18k
                    break;
359
317k
                STEP_LINE(rxl, l);
360
317k
                STEP_LINE(rxr, r);
361
317k
                step_gradient(&lg, num_components);
362
317k
                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
317k
        }
379
# if !LINEAR_COLOR
380
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
4.18k
            code = 0;
383
4.18k
# endif
384
4.18k
#undef STEP_LINE
385
4.18k
#undef SET_MINIMAL_WIDTH
386
4.18k
#undef CONNECT_RECTANGLES
387
4.18k
#undef FILL_TRAP_RECT
388
4.18k
#undef FILL_TRAP_RECT_DIRECT
389
4.18k
#undef FILL_TRAP_RECT_INRECT
390
4.18k
#undef YMULT_QUO
391
4.18k
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
4.18k
        return_if_interrupt(dev->memory);
394
4.18k
        return code;
395
4.18k
    }
396
4.18k
}
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