Coverage Report

Created: 2025-06-10 07:26

/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
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
8.62M
        return 0;    /* no scan lines to sample */
143
23.7M
    {
144
23.7M
        int iy = fixed2int_var(ymin);
145
23.7M
        const int iy1 = fixed2int_var(ymax);
146
23.7M
        trap_line l, r;
147
23.7M
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
23.7M
        const fixed
152
23.7M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
23.7M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
23.7M
        const fixed /* partial pixel offset to first line to sample */
155
23.7M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
23.7M
        fixed fxl;
157
23.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
23.6M
            dev_proc_fill_rectangle((*fill_rect)) =
179
23.6M
                dev_proc(dev, fill_rectangle);
180
# endif
181
182
23.7M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
23.7M
        l.h = left->end.y - left->start.y;
185
23.7M
        if (l.h == 0)
186
0
           return 0;
187
23.7M
        r.h = right->end.y - right->start.y;
188
23.7M
        if (r.h == 0)
189
0
           return 0;
190
23.7M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
23.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
23.7M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
256M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
256M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
23.7M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
33.8M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
33.8M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
#if LINEAR_COLOR
210
#   define FILL_TRAP_RECT(x,y,w,h)\
211
236k
        (!(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
289M
        (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
23.7M
#define YMULT_QUO(ys, tl)\
228
33.1M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
33.1M
   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.11G
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
532M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
#endif
264
23.7M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
6.38M
            l.di = 0, l.df = 0;
267
6.38M
            fxl = 0;
268
17.3M
        } else {
269
17.3M
            compute_dx(&l, dxl, ysl);
270
17.3M
            fxl = YMULT_QUO(ysl, l);
271
17.3M
            l.x += fxl;
272
17.3M
        }
273
23.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
7.04M
                if (l.di == 0 && l.df == 0) {
278
3.92M
                    rxl = fixed2int_var(l.x);
279
3.92M
                    rxr = fixed2int_var(r.x);
280
3.92M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
3.92M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
3.92M
                    goto xit;
283
3.92M
                }
284
3.12M
#     endif
285
3.12M
            r.di = 0, r.df = 0;
286
3.12M
        }
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
16.6M
        else if (dxr == dxl && fxl != 0) {
292
1.37M
            if (l.di == 0)
293
207k
                r.di = 0, r.df = l.df;
294
1.16M
            else
295
1.16M
                compute_dx(&r, dxr, ysr);
296
1.37M
            if (ysr == ysl && r.h == l.h)
297
855k
                r.x += fxl;
298
519k
            else
299
519k
                r.x += YMULT_QUO(ysr, r);
300
15.2M
        } else {
301
15.2M
            compute_dx(&r, dxr, ysr);
302
15.2M
            r.x += YMULT_QUO(ysr, r);
303
15.2M
        }
304
        /* Compute one line's worth of dx/dy. */
305
19.7M
        compute_ldx(&l, ysl);
306
19.7M
        compute_ldx(&r, ysr);
307
        /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding
308
           when the rational part is zero. Now add it back to get xl', xr' */
309
19.7M
        l.x += fixed_epsilon;
310
19.7M
        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
4.20k
            if (code < 0)
330
0
                return code;
331
4.20k
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
4.20k
            if (code < 0)
333
0
                return code;
334
335
4.20k
# endif
336
337
4.20k
#define rational_floor(tl)\
338
2.22G
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
4.20k
#define STEP_LINE(ix, tl)\
340
2.18G
  tl.x += tl.ldi;\
341
2.18G
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
2.18G
  ix = rational_floor(tl)
343
344
19.7M
        rxl = rational_floor(l);
345
19.7M
        rxr = rational_floor(r);
346
19.7M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
1.11G
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
#     if LINEAR_COLOR
349
280k
                if (rxl != rxr) {
350
236k
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
236k
                    if (code < 0)
352
0
                        goto xit;
353
236k
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
236k
                    if (code < 0)
355
0
                        goto xit;
356
236k
                }
357
280k
                if (++iy == iy1)
358
4.20k
                    break;
359
276k
                STEP_LINE(rxl, l);
360
276k
                STEP_LINE(rxr, r);
361
276k
                step_gradient(&lg, num_components);
362
276k
                step_gradient(&rg, num_components);
363
#     else
364
                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
266M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
266M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
266M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
266M
                    if (code < 0)
374
0
                        goto xit;
375
266M
                    rxl = ixl, rxr = ixr, ry = iy;
376
266M
                }
377
#     endif
378
276k
        }
379
# if !LINEAR_COLOR
380
19.7M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
4.20k
            code = 0;
383
4.20k
# endif
384
4.20k
#undef STEP_LINE
385
4.20k
#undef SET_MINIMAL_WIDTH
386
4.20k
#undef CONNECT_RECTANGLES
387
4.20k
#undef FILL_TRAP_RECT
388
4.20k
#undef FILL_TRAP_RECT_DIRECT
389
4.20k
#undef FILL_TRAP_RECT_INRECT
390
4.20k
#undef YMULT_QUO
391
23.7M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
23.7M
        return_if_interrupt(dev->memory);
394
23.7M
        return code;
395
23.7M
    }
396
23.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.35M
{
138
1.35M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
1.35M
    const fixed ymax = fixed_pixround(ytop);
140
141
1.35M
    if (ymin >= ymax)
142
64.5k
        return 0;    /* no scan lines to sample */
143
1.28M
    {
144
1.28M
        int iy = fixed2int_var(ymin);
145
1.28M
        const int iy1 = fixed2int_var(ymax);
146
1.28M
        trap_line l, r;
147
1.28M
        register int rxl, rxr;
148
1.28M
#if !LINEAR_COLOR
149
1.28M
        int ry;
150
1.28M
#endif
151
1.28M
        const fixed
152
1.28M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
1.28M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
1.28M
        const fixed /* partial pixel offset to first line to sample */
155
1.28M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
1.28M
        fixed fxl;
157
1.28M
        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.28M
            gx_color_index cindex = pdevc->colors.pure;
178
1.28M
            dev_proc_fill_rectangle((*fill_rect)) =
179
1.28M
                dev_proc(dev, fill_rectangle);
180
1.28M
# endif
181
182
1.28M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
1.28M
        l.h = left->end.y - left->start.y;
185
1.28M
        if (l.h == 0)
186
0
           return 0;
187
1.28M
        r.h = right->end.y - right->start.y;
188
1.28M
        if (r.h == 0)
189
0
           return 0;
190
1.28M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
1.28M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
1.28M
#if !LINEAR_COLOR
193
1.28M
        ry = iy;
194
1.28M
#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.28M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
1.28M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
1.28M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
1.28M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
1.28M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
1.28M
   (*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.28M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
1.28M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
1.28M
#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.28M
#define YMULT_QUO(ys, tl)\
228
1.28M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
1.28M
   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.28M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
1.28M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
1.28M
#endif
264
1.28M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
601k
            l.di = 0, l.df = 0;
267
601k
            fxl = 0;
268
687k
        } else {
269
687k
            compute_dx(&l, dxl, ysl);
270
687k
            fxl = YMULT_QUO(ysl, l);
271
687k
            l.x += fxl;
272
687k
        }
273
1.28M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
496k
#     if !LINEAR_COLOR
277
496k
                if (l.di == 0 && l.df == 0) {
278
478k
                    rxl = fixed2int_var(l.x);
279
478k
                    rxr = fixed2int_var(r.x);
280
478k
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
478k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
478k
                    goto xit;
283
478k
                }
284
18.5k
#     endif
285
18.5k
            r.di = 0, r.df = 0;
286
18.5k
        }
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
791k
        else if (dxr == dxl && fxl != 0) {
292
120k
            if (l.di == 0)
293
46.9k
                r.di = 0, r.df = l.df;
294
73.6k
            else
295
73.6k
                compute_dx(&r, dxr, ysr);
296
120k
            if (ysr == ysl && r.h == l.h)
297
120k
                r.x += fxl;
298
1
            else
299
1
                r.x += YMULT_QUO(ysr, r);
300
671k
        } else {
301
671k
            compute_dx(&r, dxr, ysr);
302
671k
            r.x += YMULT_QUO(ysr, r);
303
671k
        }
304
        /* Compute one line's worth of dx/dy. */
305
810k
        compute_ldx(&l, ysl);
306
810k
        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
810k
        l.x += fixed_epsilon;
310
810k
        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
810k
#define rational_floor(tl)\
338
810k
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
810k
#define STEP_LINE(ix, tl)\
340
810k
  tl.x += tl.ldi;\
341
810k
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
810k
  ix = rational_floor(tl)
343
344
810k
        rxl = rational_floor(l);
345
810k
        rxr = rational_floor(r);
346
810k
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
92.0M
        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
91.2M
                register int ixl, ixr;
365
366
91.2M
                STEP_LINE(ixl, l);
367
91.2M
                STEP_LINE(ixr, r);
368
91.2M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
91.2M
                if (ixl != rxl || ixr != rxr) {
370
4.71M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
4.71M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
4.71M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
4.71M
                    if (code < 0)
374
0
                        goto xit;
375
4.71M
                    rxl = ixl, rxr = ixr, ry = iy;
376
4.71M
                }
377
91.2M
#     endif
378
91.2M
        }
379
810k
# if !LINEAR_COLOR
380
810k
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
810k
#undef STEP_LINE
385
810k
#undef SET_MINIMAL_WIDTH
386
810k
#undef CONNECT_RECTANGLES
387
810k
#undef FILL_TRAP_RECT
388
810k
#undef FILL_TRAP_RECT_DIRECT
389
810k
#undef FILL_TRAP_RECT_INRECT
390
810k
#undef YMULT_QUO
391
1.28M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
1.28M
        return_if_interrupt(dev->memory);
394
1.28M
        return code;
395
1.28M
    }
396
1.28M
}
gdevddrw.c:gx_fill_trapezoid_as_nd
Line
Count
Source
137
599k
{
138
599k
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
599k
    const fixed ymax = fixed_pixround(ytop);
140
141
599k
    if (ymin >= ymax)
142
4.79k
        return 0;    /* no scan lines to sample */
143
595k
    {
144
595k
        int iy = fixed2int_var(ymin);
145
595k
        const int iy1 = fixed2int_var(ymax);
146
595k
        trap_line l, r;
147
595k
        register int rxl, rxr;
148
595k
#if !LINEAR_COLOR
149
595k
        int ry;
150
595k
#endif
151
595k
        const fixed
152
595k
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
595k
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
595k
        const fixed /* partial pixel offset to first line to sample */
155
595k
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
595k
        fixed fxl;
157
595k
        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
595k
            gx_color_index cindex = pdevc->colors.pure;
178
595k
            dev_proc_fill_rectangle((*fill_rect)) =
179
595k
                dev_proc(dev, fill_rectangle);
180
595k
# endif
181
182
595k
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
595k
        l.h = left->end.y - left->start.y;
185
595k
        if (l.h == 0)
186
0
           return 0;
187
595k
        r.h = right->end.y - right->start.y;
188
595k
        if (r.h == 0)
189
0
           return 0;
190
595k
        l.x = x0l + (fixed_half - fixed_epsilon);
191
595k
        r.x = x0r + (fixed_half - fixed_epsilon);
192
595k
#if !LINEAR_COLOR
193
595k
        ry = iy;
194
595k
#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
595k
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
595k
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
595k
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
595k
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
595k
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
595k
   (*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
595k
#   define FILL_TRAP_RECT(x,y,w,h)\
214
595k
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
595k
#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
595k
#define YMULT_QUO(ys, tl)\
228
595k
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
595k
   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
595k
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
595k
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
595k
#endif
264
595k
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
160k
            l.di = 0, l.df = 0;
267
160k
            fxl = 0;
268
434k
        } else {
269
434k
            compute_dx(&l, dxl, ysl);
270
434k
            fxl = YMULT_QUO(ysl, l);
271
434k
            l.x += fxl;
272
434k
        }
273
595k
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
153k
#     if !LINEAR_COLOR
277
153k
                if (l.di == 0 && l.df == 0) {
278
150k
                    rxl = fixed2int_var(l.x);
279
150k
                    rxr = fixed2int_var(r.x);
280
150k
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
150k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
150k
                    goto xit;
283
150k
                }
284
3.19k
#     endif
285
3.19k
            r.di = 0, r.df = 0;
286
3.19k
        }
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
441k
        else if (dxr == dxl && fxl != 0) {
292
69.8k
            if (l.di == 0)
293
41.3k
                r.di = 0, r.df = l.df;
294
28.5k
            else
295
28.5k
                compute_dx(&r, dxr, ysr);
296
69.8k
            if (ysr == ysl && r.h == l.h)
297
69.7k
                r.x += fxl;
298
122
            else
299
122
                r.x += YMULT_QUO(ysr, r);
300
371k
        } else {
301
371k
            compute_dx(&r, dxr, ysr);
302
371k
            r.x += YMULT_QUO(ysr, r);
303
371k
        }
304
        /* Compute one line's worth of dx/dy. */
305
444k
        compute_ldx(&l, ysl);
306
444k
        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
444k
        l.x += fixed_epsilon;
310
444k
        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
444k
#define rational_floor(tl)\
338
444k
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
444k
#define STEP_LINE(ix, tl)\
340
444k
  tl.x += tl.ldi;\
341
444k
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
444k
  ix = rational_floor(tl)
343
344
444k
        rxl = rational_floor(l);
345
444k
        rxr = rational_floor(r);
346
444k
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
60.5M
        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
60.0M
                register int ixl, ixr;
365
366
60.0M
                STEP_LINE(ixl, l);
367
60.0M
                STEP_LINE(ixr, r);
368
60.0M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
60.0M
                if (ixl != rxl || ixr != rxr) {
370
43.2M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
43.2M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
43.2M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
43.2M
                    if (code < 0)
374
0
                        goto xit;
375
43.2M
                    rxl = ixl, rxr = ixr, ry = iy;
376
43.2M
                }
377
60.0M
#     endif
378
60.0M
        }
379
444k
# if !LINEAR_COLOR
380
444k
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
444k
#undef STEP_LINE
385
444k
#undef SET_MINIMAL_WIDTH
386
444k
#undef CONNECT_RECTANGLES
387
444k
#undef FILL_TRAP_RECT
388
444k
#undef FILL_TRAP_RECT_DIRECT
389
444k
#undef FILL_TRAP_RECT_INRECT
390
444k
#undef YMULT_QUO
391
595k
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
595k
        return_if_interrupt(dev->memory);
394
595k
        return code;
395
595k
    }
396
595k
}
gdevddrw.c:gx_fill_trapezoid_ns_fd
Line
Count
Source
137
15.4M
{
138
15.4M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
15.4M
    const fixed ymax = fixed_pixround(ytop);
140
141
15.4M
    if (ymin >= ymax)
142
4.67M
        return 0;    /* no scan lines to sample */
143
10.7M
    {
144
10.7M
        int iy = fixed2int_var(ymin);
145
10.7M
        const int iy1 = fixed2int_var(ymax);
146
10.7M
        trap_line l, r;
147
10.7M
        register int rxl, rxr;
148
10.7M
#if !LINEAR_COLOR
149
10.7M
        int ry;
150
10.7M
#endif
151
10.7M
        const fixed
152
10.7M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
10.7M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
10.7M
        const fixed /* partial pixel offset to first line to sample */
155
10.7M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
10.7M
        fixed fxl;
157
10.7M
        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
10.7M
            gx_color_index cindex = pdevc->colors.pure;
178
10.7M
            dev_proc_fill_rectangle((*fill_rect)) =
179
10.7M
                dev_proc(dev, fill_rectangle);
180
10.7M
# endif
181
182
10.7M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
10.7M
        l.h = left->end.y - left->start.y;
185
10.7M
        if (l.h == 0)
186
0
           return 0;
187
10.7M
        r.h = right->end.y - right->start.y;
188
10.7M
        if (r.h == 0)
189
0
           return 0;
190
10.7M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
10.7M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
10.7M
#if !LINEAR_COLOR
193
10.7M
        ry = iy;
194
10.7M
#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
10.7M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
10.7M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
10.7M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
10.7M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
10.7M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
10.7M
   (*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
10.7M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
10.7M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
10.7M
#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
10.7M
#define YMULT_QUO(ys, tl)\
228
10.7M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
10.7M
   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
10.7M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
10.7M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
10.7M
#endif
264
10.7M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
3.70M
            l.di = 0, l.df = 0;
267
3.70M
            fxl = 0;
268
7.09M
        } else {
269
7.09M
            compute_dx(&l, dxl, ysl);
270
7.09M
            fxl = YMULT_QUO(ysl, l);
271
7.09M
            l.x += fxl;
272
7.09M
        }
273
10.7M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
3.68M
#     if !LINEAR_COLOR
277
3.68M
                if (l.di == 0 && l.df == 0) {
278
2.41M
                    rxl = fixed2int_var(l.x);
279
2.41M
                    rxr = fixed2int_var(r.x);
280
2.41M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
2.41M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
2.41M
                    goto xit;
283
2.41M
                }
284
1.26M
#     endif
285
1.26M
            r.di = 0, r.df = 0;
286
1.26M
        }
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
7.11M
        else if (dxr == dxl && fxl != 0) {
292
404k
            if (l.di == 0)
293
60.3k
                r.di = 0, r.df = l.df;
294
343k
            else
295
343k
                compute_dx(&r, dxr, ysr);
296
404k
            if (ysr == ysl && r.h == l.h)
297
213k
                r.x += fxl;
298
190k
            else
299
190k
                r.x += YMULT_QUO(ysr, r);
300
6.70M
        } else {
301
6.70M
            compute_dx(&r, dxr, ysr);
302
6.70M
            r.x += YMULT_QUO(ysr, r);
303
6.70M
        }
304
        /* Compute one line's worth of dx/dy. */
305
8.37M
        compute_ldx(&l, ysl);
306
8.37M
        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
8.37M
        l.x += fixed_epsilon;
310
8.37M
        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
8.37M
#define rational_floor(tl)\
338
8.37M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
8.37M
#define STEP_LINE(ix, tl)\
340
8.37M
  tl.x += tl.ldi;\
341
8.37M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
8.37M
  ix = rational_floor(tl)
343
344
8.37M
        rxl = rational_floor(l);
345
8.37M
        rxr = rational_floor(r);
346
8.37M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
481M
        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
473M
                register int ixl, ixr;
365
366
473M
                STEP_LINE(ixl, l);
367
473M
                STEP_LINE(ixr, r);
368
473M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
473M
                if (ixl != rxl || ixr != rxr) {
370
17.0M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
17.0M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
17.0M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
17.0M
                    if (code < 0)
374
0
                        goto xit;
375
17.0M
                    rxl = ixl, rxr = ixr, ry = iy;
376
17.0M
                }
377
473M
#     endif
378
473M
        }
379
8.37M
# if !LINEAR_COLOR
380
8.37M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
8.37M
#undef STEP_LINE
385
8.37M
#undef SET_MINIMAL_WIDTH
386
8.37M
#undef CONNECT_RECTANGLES
387
8.37M
#undef FILL_TRAP_RECT
388
8.37M
#undef FILL_TRAP_RECT_DIRECT
389
8.37M
#undef FILL_TRAP_RECT_INRECT
390
8.37M
#undef YMULT_QUO
391
10.7M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
10.7M
        return_if_interrupt(dev->memory);
394
10.7M
        return code;
395
10.7M
    }
396
10.7M
}
gdevddrw.c:gx_fill_trapezoid_ns_nd
Line
Count
Source
137
14.9M
{
138
14.9M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
14.9M
    const fixed ymax = fixed_pixround(ytop);
140
141
14.9M
    if (ymin >= ymax)
142
3.87M
        return 0;    /* no scan lines to sample */
143
11.0M
    {
144
11.0M
        int iy = fixed2int_var(ymin);
145
11.0M
        const int iy1 = fixed2int_var(ymax);
146
11.0M
        trap_line l, r;
147
11.0M
        register int rxl, rxr;
148
11.0M
#if !LINEAR_COLOR
149
11.0M
        int ry;
150
11.0M
#endif
151
11.0M
        const fixed
152
11.0M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
11.0M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
11.0M
        const fixed /* partial pixel offset to first line to sample */
155
11.0M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
11.0M
        fixed fxl;
157
11.0M
        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.0M
            gx_color_index cindex = pdevc->colors.pure;
178
11.0M
            dev_proc_fill_rectangle((*fill_rect)) =
179
11.0M
                dev_proc(dev, fill_rectangle);
180
11.0M
# endif
181
182
11.0M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
11.0M
        l.h = left->end.y - left->start.y;
185
11.0M
        if (l.h == 0)
186
0
           return 0;
187
11.0M
        r.h = right->end.y - right->start.y;
188
11.0M
        if (r.h == 0)
189
0
           return 0;
190
11.0M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
11.0M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
11.0M
#if !LINEAR_COLOR
193
11.0M
        ry = iy;
194
11.0M
#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.0M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
11.0M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
11.0M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
11.0M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
11.0M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
11.0M
   (*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.0M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
11.0M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
11.0M
#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.0M
#define YMULT_QUO(ys, tl)\
228
11.0M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
11.0M
   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.0M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
11.0M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
11.0M
#endif
264
11.0M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
1.92M
            l.di = 0, l.df = 0;
267
1.92M
            fxl = 0;
268
9.10M
        } else {
269
9.10M
            compute_dx(&l, dxl, ysl);
270
9.10M
            fxl = YMULT_QUO(ysl, l);
271
9.10M
            l.x += fxl;
272
9.10M
        }
273
11.0M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
2.71M
#     if !LINEAR_COLOR
277
2.71M
                if (l.di == 0 && l.df == 0) {
278
886k
                    rxl = fixed2int_var(l.x);
279
886k
                    rxr = fixed2int_var(r.x);
280
886k
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
886k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
886k
                    goto xit;
283
886k
                }
284
1.82M
#     endif
285
1.82M
            r.di = 0, r.df = 0;
286
1.82M
        }
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.30M
        else if (dxr == dxl && fxl != 0) {
292
778k
            if (l.di == 0)
293
58.0k
                r.di = 0, r.df = l.df;
294
720k
            else
295
720k
                compute_dx(&r, dxr, ysr);
296
778k
            if (ysr == ysl && r.h == l.h)
297
449k
                r.x += fxl;
298
328k
            else
299
328k
                r.x += YMULT_QUO(ysr, r);
300
7.52M
        } else {
301
7.52M
            compute_dx(&r, dxr, ysr);
302
7.52M
            r.x += YMULT_QUO(ysr, r);
303
7.52M
        }
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
475M
        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
465M
                register int ixl, ixr;
365
366
465M
                STEP_LINE(ixl, l);
367
465M
                STEP_LINE(ixr, r);
368
465M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
465M
                if (ixl != rxl || ixr != rxr) {
370
201M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
201M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
201M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
201M
                    if (code < 0)
374
0
                        goto xit;
375
201M
                    rxl = ixl, rxr = ixr, ry = iy;
376
201M
                }
377
465M
#     endif
378
465M
        }
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.0M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
11.0M
        return_if_interrupt(dev->memory);
394
11.0M
        return code;
395
11.0M
    }
396
11.0M
}
gdevddrw.c:gx_fill_trapezoid_as_lc
Line
Count
Source
137
1.08k
{
138
1.08k
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
1.08k
    const fixed ymax = fixed_pixround(ytop);
140
141
1.08k
    if (ymin >= ymax)
142
16
        return 0;    /* no scan lines to sample */
143
1.06k
    {
144
1.06k
        int iy = fixed2int_var(ymin);
145
1.06k
        const int iy1 = fixed2int_var(ymax);
146
1.06k
        trap_line l, r;
147
1.06k
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
1.06k
        const fixed
152
1.06k
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
1.06k
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
1.06k
        const fixed /* partial pixel offset to first line to sample */
155
1.06k
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
1.06k
        fixed fxl;
157
1.06k
        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.06k
# if LINEAR_COLOR
165
1.06k
            int num_components = dev->color_info.num_components;
166
1.06k
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
1.06k
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
1.06k
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
1.06k
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
1.06k
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
1.06k
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
1.06k
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
1.06k
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
1.06k
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
1.06k
            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.06k
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
1.06k
        l.h = left->end.y - left->start.y;
185
1.06k
        if (l.h == 0)
186
0
           return 0;
187
1.06k
        r.h = right->end.y - right->start.y;
188
1.06k
        if (r.h == 0)
189
0
           return 0;
190
1.06k
        l.x = x0l + (fixed_half - fixed_epsilon);
191
1.06k
        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.06k
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
1.06k
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
1.06k
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
1.06k
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
1.06k
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
1.06k
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
1.06k
#if LINEAR_COLOR
210
1.06k
#   define FILL_TRAP_RECT(x,y,w,h)\
211
1.06k
        (!(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.06k
#define YMULT_QUO(ys, tl)\
228
1.06k
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
1.06k
   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.06k
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
1.06k
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
1.06k
#endif
264
1.06k
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
66
            l.di = 0, l.df = 0;
267
66
            fxl = 0;
268
1.00k
        } else {
269
1.00k
            compute_dx(&l, dxl, ysl);
270
1.00k
            fxl = YMULT_QUO(ysl, l);
271
1.00k
            l.x += fxl;
272
1.00k
        }
273
1.06k
        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
84
            r.di = 0, r.df = 0;
286
84
        }
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
984
        else if (dxr == dxl && fxl != 0) {
292
633
            if (l.di == 0)
293
286
                r.di = 0, r.df = l.df;
294
347
            else
295
347
                compute_dx(&r, dxr, ysr);
296
633
            if (ysr == ysl && r.h == l.h)
297
633
                r.x += fxl;
298
0
            else
299
0
                r.x += YMULT_QUO(ysr, r);
300
633
        } else {
301
351
            compute_dx(&r, dxr, ysr);
302
351
            r.x += YMULT_QUO(ysr, r);
303
351
        }
304
        /* Compute one line's worth of dx/dy. */
305
1.06k
        compute_ldx(&l, ysl);
306
1.06k
        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.06k
        l.x += fixed_epsilon;
310
1.06k
        r.x += fixed_epsilon;
311
1.06k
# 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.06k
            lg.c = lgc;
320
1.06k
            lg.f = lgf;
321
1.06k
            lg.num = lgnum;
322
1.06k
            rg.c = rgc;
323
1.06k
            rg.f = rgf;
324
1.06k
            rg.num = rgnum;
325
1.06k
            xg.c = xgc;
326
1.06k
            xg.f = xgf;
327
1.06k
            xg.num = xgnum;
328
1.06k
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
1.06k
            if (code < 0)
330
0
                return code;
331
1.06k
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
1.06k
            if (code < 0)
333
0
                return code;
334
335
1.06k
# endif
336
337
1.06k
#define rational_floor(tl)\
338
1.06k
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
1.06k
#define STEP_LINE(ix, tl)\
340
1.06k
  tl.x += tl.ldi;\
341
1.06k
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
1.06k
  ix = rational_floor(tl)
343
344
1.06k
        rxl = rational_floor(l);
345
1.06k
        rxr = rational_floor(r);
346
1.06k
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
36.5k
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
36.5k
#     if LINEAR_COLOR
349
36.5k
                if (rxl != rxr) {
350
33.0k
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
33.0k
                    if (code < 0)
352
0
                        goto xit;
353
33.0k
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
33.0k
                    if (code < 0)
355
0
                        goto xit;
356
33.0k
                }
357
36.5k
                if (++iy == iy1)
358
1.06k
                    break;
359
35.4k
                STEP_LINE(rxl, l);
360
35.4k
                STEP_LINE(rxr, r);
361
35.4k
                step_gradient(&lg, num_components);
362
35.4k
                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
35.4k
        }
379
# if !LINEAR_COLOR
380
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
1.06k
            code = 0;
383
1.06k
# endif
384
1.06k
#undef STEP_LINE
385
1.06k
#undef SET_MINIMAL_WIDTH
386
1.06k
#undef CONNECT_RECTANGLES
387
1.06k
#undef FILL_TRAP_RECT
388
1.06k
#undef FILL_TRAP_RECT_DIRECT
389
1.06k
#undef FILL_TRAP_RECT_INRECT
390
1.06k
#undef YMULT_QUO
391
1.06k
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
1.06k
        return_if_interrupt(dev->memory);
394
1.06k
        return code;
395
1.06k
    }
396
1.06k
}
gdevddrw.c:gx_fill_trapezoid_ns_lc
Line
Count
Source
137
3.20k
{
138
3.20k
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
3.20k
    const fixed ymax = fixed_pixround(ytop);
140
141
3.20k
    if (ymin >= ymax)
142
66
        return 0;    /* no scan lines to sample */
143
3.13k
    {
144
3.13k
        int iy = fixed2int_var(ymin);
145
3.13k
        const int iy1 = fixed2int_var(ymax);
146
3.13k
        trap_line l, r;
147
3.13k
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
3.13k
        const fixed
152
3.13k
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
3.13k
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
3.13k
        const fixed /* partial pixel offset to first line to sample */
155
3.13k
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
3.13k
        fixed fxl;
157
3.13k
        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
3.13k
# if LINEAR_COLOR
165
3.13k
            int num_components = dev->color_info.num_components;
166
3.13k
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
3.13k
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
3.13k
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
3.13k
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
3.13k
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
3.13k
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
3.13k
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
3.13k
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
3.13k
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
3.13k
            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
3.13k
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
3.13k
        l.h = left->end.y - left->start.y;
185
3.13k
        if (l.h == 0)
186
0
           return 0;
187
3.13k
        r.h = right->end.y - right->start.y;
188
3.13k
        if (r.h == 0)
189
0
           return 0;
190
3.13k
        l.x = x0l + (fixed_half - fixed_epsilon);
191
3.13k
        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
3.13k
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
3.13k
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
3.13k
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
3.13k
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
3.13k
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
3.13k
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
3.13k
#if LINEAR_COLOR
210
3.13k
#   define FILL_TRAP_RECT(x,y,w,h)\
211
3.13k
        (!(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
3.13k
#define YMULT_QUO(ys, tl)\
228
3.13k
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
3.13k
   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
3.13k
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
3.13k
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
3.13k
#endif
264
3.13k
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
125
            l.di = 0, l.df = 0;
267
125
            fxl = 0;
268
3.01k
        } else {
269
3.01k
            compute_dx(&l, dxl, ysl);
270
3.01k
            fxl = YMULT_QUO(ysl, l);
271
3.01k
            l.x += fxl;
272
3.01k
        }
273
3.13k
        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
122
            r.di = 0, r.df = 0;
286
122
        }
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.01k
        else if (dxr == dxl && fxl != 0) {
292
822
            if (l.di == 0)
293
337
                r.di = 0, r.df = l.df;
294
485
            else
295
485
                compute_dx(&r, dxr, ysr);
296
822
            if (ysr == ysl && r.h == l.h)
297
822
                r.x += fxl;
298
0
            else
299
0
                r.x += YMULT_QUO(ysr, r);
300
2.19k
        } else {
301
2.19k
            compute_dx(&r, dxr, ysr);
302
2.19k
            r.x += YMULT_QUO(ysr, r);
303
2.19k
        }
304
        /* Compute one line's worth of dx/dy. */
305
3.13k
        compute_ldx(&l, ysl);
306
3.13k
        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.13k
        l.x += fixed_epsilon;
310
3.13k
        r.x += fixed_epsilon;
311
3.13k
# 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
3.13k
            lg.c = lgc;
320
3.13k
            lg.f = lgf;
321
3.13k
            lg.num = lgnum;
322
3.13k
            rg.c = rgc;
323
3.13k
            rg.f = rgf;
324
3.13k
            rg.num = rgnum;
325
3.13k
            xg.c = xgc;
326
3.13k
            xg.f = xgf;
327
3.13k
            xg.num = xgnum;
328
3.13k
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
3.13k
            if (code < 0)
330
0
                return code;
331
3.13k
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
3.13k
            if (code < 0)
333
0
                return code;
334
335
3.13k
# endif
336
337
3.13k
#define rational_floor(tl)\
338
3.13k
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
3.13k
#define STEP_LINE(ix, tl)\
340
3.13k
  tl.x += tl.ldi;\
341
3.13k
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
3.13k
  ix = rational_floor(tl)
343
344
3.13k
        rxl = rational_floor(l);
345
3.13k
        rxr = rational_floor(r);
346
3.13k
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
244k
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
244k
#     if LINEAR_COLOR
349
244k
                if (rxl != rxr) {
350
203k
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
203k
                    if (code < 0)
352
0
                        goto xit;
353
203k
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
203k
                    if (code < 0)
355
0
                        goto xit;
356
203k
                }
357
244k
                if (++iy == iy1)
358
3.13k
                    break;
359
241k
                STEP_LINE(rxl, l);
360
241k
                STEP_LINE(rxr, r);
361
241k
                step_gradient(&lg, num_components);
362
241k
                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
241k
        }
379
# if !LINEAR_COLOR
380
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
3.13k
            code = 0;
383
3.13k
# endif
384
3.13k
#undef STEP_LINE
385
3.13k
#undef SET_MINIMAL_WIDTH
386
3.13k
#undef CONNECT_RECTANGLES
387
3.13k
#undef FILL_TRAP_RECT
388
3.13k
#undef FILL_TRAP_RECT_DIRECT
389
3.13k
#undef FILL_TRAP_RECT_INRECT
390
3.13k
#undef YMULT_QUO
391
3.13k
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
3.13k
        return_if_interrupt(dev->memory);
394
3.13k
        return code;
395
3.13k
    }
396
3.13k
}
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