Coverage Report

Created: 2025-06-10 06:56

/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
7.96M
        return 0;    /* no scan lines to sample */
143
15.6M
    {
144
15.6M
        int iy = fixed2int_var(ymin);
145
15.6M
        const int iy1 = fixed2int_var(ymax);
146
15.6M
        trap_line l, r;
147
15.6M
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
15.6M
        const fixed
152
15.6M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
15.6M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
15.6M
        const fixed /* partial pixel offset to first line to sample */
155
15.6M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
15.6M
        fixed fxl;
157
15.6M
        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
8.54M
            dev_proc_fill_rectangle((*fill_rect)) =
179
8.54M
                dev_proc(dev, fill_rectangle);
180
# endif
181
182
15.6M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
15.6M
        l.h = left->end.y - left->start.y;
185
15.6M
        if (l.h == 0)
186
0
           return 0;
187
15.6M
        r.h = right->end.y - right->start.y;
188
15.6M
        if (r.h == 0)
189
0
           return 0;
190
15.6M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
15.6M
        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
15.6M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
115M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
115M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
15.6M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
15.6M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
5.77M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
#if LINEAR_COLOR
210
#   define FILL_TRAP_RECT(x,y,w,h)\
211
11.2M
        (!(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
120M
        (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
15.6M
#define YMULT_QUO(ys, tl)\
228
22.6M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
22.6M
   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
151M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
224M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
#endif
264
15.6M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
3.79M
            l.di = 0, l.df = 0;
267
3.79M
            fxl = 0;
268
11.9M
        } else {
269
11.9M
            compute_dx(&l, dxl, ysl);
270
11.9M
            fxl = YMULT_QUO(ysl, l);
271
11.9M
            l.x += fxl;
272
11.9M
        }
273
15.6M
        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
3.41M
                if (l.di == 0 && l.df == 0) {
278
1.37M
                    rxl = fixed2int_var(l.x);
279
1.37M
                    rxr = fixed2int_var(r.x);
280
1.37M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
1.37M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
1.37M
                    goto xit;
283
1.37M
                }
284
2.03M
#     endif
285
2.03M
            r.di = 0, r.df = 0;
286
2.03M
        }
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
11.0M
        else if (dxr == dxl && fxl != 0) {
292
470k
            if (l.di == 0)
293
120k
                r.di = 0, r.df = l.df;
294
350k
            else
295
350k
                compute_dx(&r, dxr, ysr);
296
470k
            if (ysr == ysl && r.h == l.h)
297
339k
                r.x += fxl;
298
131k
            else
299
131k
                r.x += YMULT_QUO(ysr, r);
300
10.6M
        } else {
301
10.6M
            compute_dx(&r, dxr, ysr);
302
10.6M
            r.x += YMULT_QUO(ysr, r);
303
10.6M
        }
304
        /* Compute one line's worth of dx/dy. */
305
7.16M
        compute_ldx(&l, ysl);
306
7.16M
        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
14.3M
        l.x += fixed_epsilon;
310
14.3M
        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
7.14M
            if (code < 0)
330
0
                return code;
331
7.14M
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
7.14M
            if (code < 0)
333
0
                return code;
334
335
7.14M
# endif
336
337
7.14M
#define rational_floor(tl)\
338
403M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
7.14M
#define STEP_LINE(ix, tl)\
340
368M
  tl.x += tl.ldi;\
341
368M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
375M
  ix = rational_floor(tl)
343
344
14.3M
        rxl = rational_floor(l);
345
14.3M
        rxr = rational_floor(r);
346
14.3M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
198M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
#     if LINEAR_COLOR
349
55.3M
                if (rxl != rxr) {
350
11.2M
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
11.2M
                    if (code < 0)
352
0
                        goto xit;
353
11.2M
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
11.2M
                    if (code < 0)
355
0
                        goto xit;
356
11.2M
                }
357
55.3M
                if (++iy == iy1)
358
7.14M
                    break;
359
48.1M
                STEP_LINE(rxl, l);
360
48.1M
                STEP_LINE(rxr, r);
361
48.1M
                step_gradient(&lg, num_components);
362
48.1M
                step_gradient(&rg, num_components);
363
#     else
364
                register int ixl, ixr;
365
366
135M
                STEP_LINE(ixl, l);
367
135M
                STEP_LINE(ixr, r);
368
135M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
135M
                if (ixl != rxl || ixr != rxr) {
370
112M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
112M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
112M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
112M
                    if (code < 0)
374
0
                        goto xit;
375
112M
                    rxl = ixl, rxr = ixr, ry = iy;
376
112M
                }
377
#     endif
378
48.1M
        }
379
# if !LINEAR_COLOR
380
7.16M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
7.14M
            code = 0;
383
7.14M
# endif
384
7.14M
#undef STEP_LINE
385
7.14M
#undef SET_MINIMAL_WIDTH
386
7.14M
#undef CONNECT_RECTANGLES
387
7.14M
#undef FILL_TRAP_RECT
388
7.14M
#undef FILL_TRAP_RECT_DIRECT
389
7.14M
#undef FILL_TRAP_RECT_INRECT
390
7.14M
#undef YMULT_QUO
391
15.6M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
15.6M
        return_if_interrupt(dev->memory);
394
15.6M
        return code;
395
15.6M
    }
396
15.6M
}
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
80.2k
{
138
80.2k
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
80.2k
    const fixed ymax = fixed_pixround(ytop);
140
141
80.2k
    if (ymin >= ymax)
142
5.12k
        return 0;    /* no scan lines to sample */
143
75.1k
    {
144
75.1k
        int iy = fixed2int_var(ymin);
145
75.1k
        const int iy1 = fixed2int_var(ymax);
146
75.1k
        trap_line l, r;
147
75.1k
        register int rxl, rxr;
148
75.1k
#if !LINEAR_COLOR
149
75.1k
        int ry;
150
75.1k
#endif
151
75.1k
        const fixed
152
75.1k
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
75.1k
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
75.1k
        const fixed /* partial pixel offset to first line to sample */
155
75.1k
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
75.1k
        fixed fxl;
157
75.1k
        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
75.1k
            gx_color_index cindex = pdevc->colors.pure;
178
75.1k
            dev_proc_fill_rectangle((*fill_rect)) =
179
75.1k
                dev_proc(dev, fill_rectangle);
180
75.1k
# endif
181
182
75.1k
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
75.1k
        l.h = left->end.y - left->start.y;
185
75.1k
        if (l.h == 0)
186
0
           return 0;
187
75.1k
        r.h = right->end.y - right->start.y;
188
75.1k
        if (r.h == 0)
189
0
           return 0;
190
75.1k
        l.x = x0l + (fixed_half - fixed_epsilon);
191
75.1k
        r.x = x0r + (fixed_half - fixed_epsilon);
192
75.1k
#if !LINEAR_COLOR
193
75.1k
        ry = iy;
194
75.1k
#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
75.1k
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
75.1k
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
75.1k
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
75.1k
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
75.1k
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
75.1k
   (*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
75.1k
#   define FILL_TRAP_RECT(x,y,w,h)\
214
75.1k
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
75.1k
#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
75.1k
#define YMULT_QUO(ys, tl)\
228
75.1k
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
75.1k
   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
75.1k
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
75.1k
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
75.1k
#endif
264
75.1k
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
25.7k
            l.di = 0, l.df = 0;
267
25.7k
            fxl = 0;
268
49.3k
        } else {
269
49.3k
            compute_dx(&l, dxl, ysl);
270
49.3k
            fxl = YMULT_QUO(ysl, l);
271
49.3k
            l.x += fxl;
272
49.3k
        }
273
75.1k
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
28.8k
#     if !LINEAR_COLOR
277
28.8k
                if (l.di == 0 && l.df == 0) {
278
23.5k
                    rxl = fixed2int_var(l.x);
279
23.5k
                    rxr = fixed2int_var(r.x);
280
23.5k
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
23.5k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
23.5k
                    goto xit;
283
23.5k
                }
284
5.30k
#     endif
285
5.30k
            r.di = 0, r.df = 0;
286
5.30k
        }
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
46.2k
        else if (dxr == dxl && fxl != 0) {
292
23.7k
            if (l.di == 0)
293
11.2k
                r.di = 0, r.df = l.df;
294
12.4k
            else
295
12.4k
                compute_dx(&r, dxr, ysr);
296
23.7k
            if (ysr == ysl && r.h == l.h)
297
23.7k
                r.x += fxl;
298
2
            else
299
2
                r.x += YMULT_QUO(ysr, r);
300
23.7k
        } else {
301
22.5k
            compute_dx(&r, dxr, ysr);
302
22.5k
            r.x += YMULT_QUO(ysr, r);
303
22.5k
        }
304
        /* Compute one line's worth of dx/dy. */
305
51.5k
        compute_ldx(&l, ysl);
306
51.5k
        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
51.5k
        l.x += fixed_epsilon;
310
51.5k
        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
51.5k
#define rational_floor(tl)\
338
51.5k
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
51.5k
#define STEP_LINE(ix, tl)\
340
51.5k
  tl.x += tl.ldi;\
341
51.5k
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
51.5k
  ix = rational_floor(tl)
343
344
51.5k
        rxl = rational_floor(l);
345
51.5k
        rxr = rational_floor(r);
346
51.5k
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
2.69M
        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
2.64M
                register int ixl, ixr;
365
366
2.64M
                STEP_LINE(ixl, l);
367
2.64M
                STEP_LINE(ixr, r);
368
2.64M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
2.64M
                if (ixl != rxl || ixr != rxr) {
370
642k
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
642k
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
642k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
642k
                    if (code < 0)
374
0
                        goto xit;
375
642k
                    rxl = ixl, rxr = ixr, ry = iy;
376
642k
                }
377
2.64M
#     endif
378
2.64M
        }
379
51.5k
# if !LINEAR_COLOR
380
51.5k
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
51.5k
#undef STEP_LINE
385
51.5k
#undef SET_MINIMAL_WIDTH
386
51.5k
#undef CONNECT_RECTANGLES
387
51.5k
#undef FILL_TRAP_RECT
388
51.5k
#undef FILL_TRAP_RECT_DIRECT
389
51.5k
#undef FILL_TRAP_RECT_INRECT
390
51.5k
#undef YMULT_QUO
391
75.1k
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
75.1k
        return_if_interrupt(dev->memory);
394
75.1k
        return code;
395
75.1k
    }
396
75.1k
}
gdevddrw.c:gx_fill_trapezoid_as_nd
Line
Count
Source
137
376k
{
138
376k
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
376k
    const fixed ymax = fixed_pixround(ytop);
140
141
376k
    if (ymin >= ymax)
142
3.89k
        return 0;    /* no scan lines to sample */
143
372k
    {
144
372k
        int iy = fixed2int_var(ymin);
145
372k
        const int iy1 = fixed2int_var(ymax);
146
372k
        trap_line l, r;
147
372k
        register int rxl, rxr;
148
372k
#if !LINEAR_COLOR
149
372k
        int ry;
150
372k
#endif
151
372k
        const fixed
152
372k
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
372k
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
372k
        const fixed /* partial pixel offset to first line to sample */
155
372k
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
372k
        fixed fxl;
157
372k
        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
372k
            gx_color_index cindex = pdevc->colors.pure;
178
372k
            dev_proc_fill_rectangle((*fill_rect)) =
179
372k
                dev_proc(dev, fill_rectangle);
180
372k
# endif
181
182
372k
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
372k
        l.h = left->end.y - left->start.y;
185
372k
        if (l.h == 0)
186
0
           return 0;
187
372k
        r.h = right->end.y - right->start.y;
188
372k
        if (r.h == 0)
189
0
           return 0;
190
372k
        l.x = x0l + (fixed_half - fixed_epsilon);
191
372k
        r.x = x0r + (fixed_half - fixed_epsilon);
192
372k
#if !LINEAR_COLOR
193
372k
        ry = iy;
194
372k
#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
372k
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
372k
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
372k
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
372k
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
372k
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
372k
   (*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
372k
#   define FILL_TRAP_RECT(x,y,w,h)\
214
372k
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
372k
#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
372k
#define YMULT_QUO(ys, tl)\
228
372k
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
372k
   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
372k
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
372k
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
372k
#endif
264
372k
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
104k
            l.di = 0, l.df = 0;
267
104k
            fxl = 0;
268
267k
        } else {
269
267k
            compute_dx(&l, dxl, ysl);
270
267k
            fxl = YMULT_QUO(ysl, l);
271
267k
            l.x += fxl;
272
267k
        }
273
372k
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
100k
#     if !LINEAR_COLOR
277
100k
                if (l.di == 0 && l.df == 0) {
278
97.0k
                    rxl = fixed2int_var(l.x);
279
97.0k
                    rxr = fixed2int_var(r.x);
280
97.0k
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
97.0k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
97.0k
                    goto xit;
283
97.0k
                }
284
3.88k
#     endif
285
3.88k
            r.di = 0, r.df = 0;
286
3.88k
        }
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
271k
        else if (dxr == dxl && fxl != 0) {
292
56.1k
            if (l.di == 0)
293
33.2k
                r.di = 0, r.df = l.df;
294
22.9k
            else
295
22.9k
                compute_dx(&r, dxr, ysr);
296
56.1k
            if (ysr == ysl && r.h == l.h)
297
56.0k
                r.x += fxl;
298
79
            else
299
79
                r.x += YMULT_QUO(ysr, r);
300
215k
        } else {
301
215k
            compute_dx(&r, dxr, ysr);
302
215k
            r.x += YMULT_QUO(ysr, r);
303
215k
        }
304
        /* Compute one line's worth of dx/dy. */
305
275k
        compute_ldx(&l, ysl);
306
275k
        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
275k
        l.x += fixed_epsilon;
310
275k
        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
275k
#define rational_floor(tl)\
338
275k
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
275k
#define STEP_LINE(ix, tl)\
340
275k
  tl.x += tl.ldi;\
341
275k
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
275k
  ix = rational_floor(tl)
343
344
275k
        rxl = rational_floor(l);
345
275k
        rxr = rational_floor(r);
346
275k
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
19.1M
        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
18.8M
                register int ixl, ixr;
365
366
18.8M
                STEP_LINE(ixl, l);
367
18.8M
                STEP_LINE(ixr, r);
368
18.8M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
18.8M
                if (ixl != rxl || ixr != rxr) {
370
11.6M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
11.6M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
11.6M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
11.6M
                    if (code < 0)
374
0
                        goto xit;
375
11.6M
                    rxl = ixl, rxr = ixr, ry = iy;
376
11.6M
                }
377
18.8M
#     endif
378
18.8M
        }
379
275k
# if !LINEAR_COLOR
380
275k
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
275k
#undef STEP_LINE
385
275k
#undef SET_MINIMAL_WIDTH
386
275k
#undef CONNECT_RECTANGLES
387
275k
#undef FILL_TRAP_RECT
388
275k
#undef FILL_TRAP_RECT_DIRECT
389
275k
#undef FILL_TRAP_RECT_INRECT
390
275k
#undef YMULT_QUO
391
372k
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
372k
        return_if_interrupt(dev->memory);
394
372k
        return code;
395
372k
    }
396
372k
}
gdevddrw.c:gx_fill_trapezoid_ns_fd
Line
Count
Source
137
1.11M
{
138
1.11M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
1.11M
    const fixed ymax = fixed_pixround(ytop);
140
141
1.11M
    if (ymin >= ymax)
142
103k
        return 0;    /* no scan lines to sample */
143
1.01M
    {
144
1.01M
        int iy = fixed2int_var(ymin);
145
1.01M
        const int iy1 = fixed2int_var(ymax);
146
1.01M
        trap_line l, r;
147
1.01M
        register int rxl, rxr;
148
1.01M
#if !LINEAR_COLOR
149
1.01M
        int ry;
150
1.01M
#endif
151
1.01M
        const fixed
152
1.01M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
1.01M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
1.01M
        const fixed /* partial pixel offset to first line to sample */
155
1.01M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
1.01M
        fixed fxl;
157
1.01M
        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.01M
            gx_color_index cindex = pdevc->colors.pure;
178
1.01M
            dev_proc_fill_rectangle((*fill_rect)) =
179
1.01M
                dev_proc(dev, fill_rectangle);
180
1.01M
# endif
181
182
1.01M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
1.01M
        l.h = left->end.y - left->start.y;
185
1.01M
        if (l.h == 0)
186
0
           return 0;
187
1.01M
        r.h = right->end.y - right->start.y;
188
1.01M
        if (r.h == 0)
189
0
           return 0;
190
1.01M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
1.01M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
1.01M
#if !LINEAR_COLOR
193
1.01M
        ry = iy;
194
1.01M
#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.01M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
1.01M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
1.01M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
1.01M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
1.01M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
1.01M
   (*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.01M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
1.01M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
1.01M
#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.01M
#define YMULT_QUO(ys, tl)\
228
1.01M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
1.01M
   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.01M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
1.01M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
1.01M
#endif
264
1.01M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
582k
            l.di = 0, l.df = 0;
267
582k
            fxl = 0;
268
582k
        } else {
269
428k
            compute_dx(&l, dxl, ysl);
270
428k
            fxl = YMULT_QUO(ysl, l);
271
428k
            l.x += fxl;
272
428k
        }
273
1.01M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
620k
#     if !LINEAR_COLOR
277
620k
                if (l.di == 0 && l.df == 0) {
278
513k
                    rxl = fixed2int_var(l.x);
279
513k
                    rxr = fixed2int_var(r.x);
280
513k
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
513k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
513k
                    goto xit;
283
513k
                }
284
106k
#     endif
285
106k
            r.di = 0, r.df = 0;
286
106k
        }
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
390k
        else if (dxr == dxl && fxl != 0) {
292
65.3k
            if (l.di == 0)
293
15.5k
                r.di = 0, r.df = l.df;
294
49.8k
            else
295
49.8k
                compute_dx(&r, dxr, ysr);
296
65.3k
            if (ysr == ysl && r.h == l.h)
297
48.3k
                r.x += fxl;
298
16.9k
            else
299
16.9k
                r.x += YMULT_QUO(ysr, r);
300
325k
        } else {
301
325k
            compute_dx(&r, dxr, ysr);
302
325k
            r.x += YMULT_QUO(ysr, r);
303
325k
        }
304
        /* Compute one line's worth of dx/dy. */
305
497k
        compute_ldx(&l, ysl);
306
497k
        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
497k
        l.x += fixed_epsilon;
310
497k
        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
497k
#define rational_floor(tl)\
338
497k
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
497k
#define STEP_LINE(ix, tl)\
340
497k
  tl.x += tl.ldi;\
341
497k
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
497k
  ix = rational_floor(tl)
343
344
497k
        rxl = rational_floor(l);
345
497k
        rxr = rational_floor(r);
346
497k
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
5.68M
        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
5.18M
                register int ixl, ixr;
365
366
5.18M
                STEP_LINE(ixl, l);
367
5.18M
                STEP_LINE(ixr, r);
368
5.18M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
5.18M
                if (ixl != rxl || ixr != rxr) {
370
4.04M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
4.04M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
4.04M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
4.04M
                    if (code < 0)
374
0
                        goto xit;
375
4.04M
                    rxl = ixl, rxr = ixr, ry = iy;
376
4.04M
                }
377
5.18M
#     endif
378
5.18M
        }
379
497k
# if !LINEAR_COLOR
380
497k
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
497k
#undef STEP_LINE
385
497k
#undef SET_MINIMAL_WIDTH
386
497k
#undef CONNECT_RECTANGLES
387
497k
#undef FILL_TRAP_RECT
388
497k
#undef FILL_TRAP_RECT_DIRECT
389
497k
#undef FILL_TRAP_RECT_INRECT
390
497k
#undef YMULT_QUO
391
1.01M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
1.01M
        return_if_interrupt(dev->memory);
394
1.01M
        return code;
395
1.01M
    }
396
1.01M
}
gdevddrw.c:gx_fill_trapezoid_ns_nd
Line
Count
Source
137
10.2M
{
138
10.2M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
10.2M
    const fixed ymax = fixed_pixround(ytop);
140
141
10.2M
    if (ymin >= ymax)
142
3.17M
        return 0;    /* no scan lines to sample */
143
7.08M
    {
144
7.08M
        int iy = fixed2int_var(ymin);
145
7.08M
        const int iy1 = fixed2int_var(ymax);
146
7.08M
        trap_line l, r;
147
7.08M
        register int rxl, rxr;
148
7.08M
#if !LINEAR_COLOR
149
7.08M
        int ry;
150
7.08M
#endif
151
7.08M
        const fixed
152
7.08M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
7.08M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
7.08M
        const fixed /* partial pixel offset to first line to sample */
155
7.08M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
7.08M
        fixed fxl;
157
7.08M
        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
7.08M
            gx_color_index cindex = pdevc->colors.pure;
178
7.08M
            dev_proc_fill_rectangle((*fill_rect)) =
179
7.08M
                dev_proc(dev, fill_rectangle);
180
7.08M
# endif
181
182
7.08M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
7.08M
        l.h = left->end.y - left->start.y;
185
7.08M
        if (l.h == 0)
186
0
           return 0;
187
7.08M
        r.h = right->end.y - right->start.y;
188
7.08M
        if (r.h == 0)
189
0
           return 0;
190
7.08M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
7.08M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
7.08M
#if !LINEAR_COLOR
193
7.08M
        ry = iy;
194
7.08M
#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
7.08M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
7.08M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
7.08M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
7.08M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
7.08M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
7.08M
   (*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
7.08M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
7.08M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
7.08M
#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
7.08M
#define YMULT_QUO(ys, tl)\
228
7.08M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
7.08M
   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
7.08M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
7.08M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
7.08M
#endif
264
7.08M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
1.88M
            l.di = 0, l.df = 0;
267
1.88M
            fxl = 0;
268
5.20M
        } else {
269
5.20M
            compute_dx(&l, dxl, ysl);
270
5.20M
            fxl = YMULT_QUO(ysl, l);
271
5.20M
            l.x += fxl;
272
5.20M
        }
273
7.08M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
2.66M
#     if !LINEAR_COLOR
277
2.66M
                if (l.di == 0 && l.df == 0) {
278
745k
                    rxl = fixed2int_var(l.x);
279
745k
                    rxr = fixed2int_var(r.x);
280
745k
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
745k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
745k
                    goto xit;
283
745k
                }
284
1.92M
#     endif
285
1.92M
            r.di = 0, r.df = 0;
286
1.92M
        }
287
        /*
288
         * The test for fxl != 0 is required because the right edge might
289
         * cross some pixel centers even if the left edge doesn't.
290
         */
291
4.41M
        else if (dxr == dxl && fxl != 0) {
292
101k
            if (l.di == 0)
293
7.35k
                r.di = 0, r.df = l.df;
294
94.2k
            else
295
94.2k
                compute_dx(&r, dxr, ysr);
296
101k
            if (ysr == ysl && r.h == l.h)
297
67.5k
                r.x += fxl;
298
34.0k
            else
299
34.0k
                r.x += YMULT_QUO(ysr, r);
300
4.31M
        } else {
301
4.31M
            compute_dx(&r, dxr, ysr);
302
4.31M
            r.x += YMULT_QUO(ysr, r);
303
4.31M
        }
304
        /* Compute one line's worth of dx/dy. */
305
6.33M
        compute_ldx(&l, ysl);
306
6.33M
        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
6.33M
        l.x += fixed_epsilon;
310
6.33M
        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
6.33M
#define rational_floor(tl)\
338
6.33M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
6.33M
#define STEP_LINE(ix, tl)\
340
6.33M
  tl.x += tl.ldi;\
341
6.33M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
6.33M
  ix = rational_floor(tl)
343
344
6.33M
        rxl = rational_floor(l);
345
6.33M
        rxr = rational_floor(r);
346
6.33M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
115M
        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
109M
                register int ixl, ixr;
365
366
109M
                STEP_LINE(ixl, l);
367
109M
                STEP_LINE(ixr, r);
368
109M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
109M
                if (ixl != rxl || ixr != rxr) {
370
96.0M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
96.0M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
96.0M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
96.0M
                    if (code < 0)
374
0
                        goto xit;
375
96.0M
                    rxl = ixl, rxr = ixr, ry = iy;
376
96.0M
                }
377
109M
#     endif
378
109M
        }
379
6.33M
# if !LINEAR_COLOR
380
6.33M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
6.33M
#undef STEP_LINE
385
6.33M
#undef SET_MINIMAL_WIDTH
386
6.33M
#undef CONNECT_RECTANGLES
387
6.33M
#undef FILL_TRAP_RECT
388
6.33M
#undef FILL_TRAP_RECT_DIRECT
389
6.33M
#undef FILL_TRAP_RECT_INRECT
390
6.33M
#undef YMULT_QUO
391
7.08M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
7.08M
        return_if_interrupt(dev->memory);
394
7.08M
        return code;
395
7.08M
    }
396
7.08M
}
gdevddrw.c:gx_fill_trapezoid_as_lc
Line
Count
Source
137
181k
{
138
181k
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
181k
    const fixed ymax = fixed_pixround(ytop);
140
141
181k
    if (ymin >= ymax)
142
1.70k
        return 0;    /* no scan lines to sample */
143
180k
    {
144
180k
        int iy = fixed2int_var(ymin);
145
180k
        const int iy1 = fixed2int_var(ymax);
146
180k
        trap_line l, r;
147
180k
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
180k
        const fixed
152
180k
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
180k
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
180k
        const fixed /* partial pixel offset to first line to sample */
155
180k
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
180k
        fixed fxl;
157
180k
        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
180k
# if LINEAR_COLOR
165
180k
            int num_components = dev->color_info.num_components;
166
180k
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
180k
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
180k
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
180k
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
180k
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
180k
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
180k
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
180k
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
180k
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
180k
            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
180k
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
180k
        l.h = left->end.y - left->start.y;
185
180k
        if (l.h == 0)
186
0
           return 0;
187
180k
        r.h = right->end.y - right->start.y;
188
180k
        if (r.h == 0)
189
0
           return 0;
190
180k
        l.x = x0l + (fixed_half - fixed_epsilon);
191
180k
        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
180k
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
180k
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
180k
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
180k
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
180k
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
180k
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
180k
#if LINEAR_COLOR
210
180k
#   define FILL_TRAP_RECT(x,y,w,h)\
211
180k
        (!(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
180k
#define YMULT_QUO(ys, tl)\
228
180k
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
180k
   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
180k
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
180k
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
180k
#endif
264
180k
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
102k
            l.di = 0, l.df = 0;
267
102k
            fxl = 0;
268
102k
        } else {
269
78.1k
            compute_dx(&l, dxl, ysl);
270
78.1k
            fxl = YMULT_QUO(ysl, l);
271
78.1k
            l.x += fxl;
272
78.1k
        }
273
180k
        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
103k
            r.di = 0, r.df = 0;
286
103k
        }
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
76.5k
        else if (dxr == dxl && fxl != 0) {
292
38.6k
            if (l.di == 0)
293
19.3k
                r.di = 0, r.df = l.df;
294
19.2k
            else
295
19.2k
                compute_dx(&r, dxr, ysr);
296
38.6k
            if (ysr == ysl && r.h == l.h)
297
38.6k
                r.x += fxl;
298
2
            else
299
2
                r.x += YMULT_QUO(ysr, r);
300
38.6k
        } else {
301
37.9k
            compute_dx(&r, dxr, ysr);
302
37.9k
            r.x += YMULT_QUO(ysr, r);
303
37.9k
        }
304
        /* Compute one line's worth of dx/dy. */
305
180k
        compute_ldx(&l, ysl);
306
180k
        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
180k
        l.x += fixed_epsilon;
310
180k
        r.x += fixed_epsilon;
311
180k
# 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
180k
            lg.c = lgc;
320
180k
            lg.f = lgf;
321
180k
            lg.num = lgnum;
322
180k
            rg.c = rgc;
323
180k
            rg.f = rgf;
324
180k
            rg.num = rgnum;
325
180k
            xg.c = xgc;
326
180k
            xg.f = xgf;
327
180k
            xg.num = xgnum;
328
180k
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
180k
            if (code < 0)
330
0
                return code;
331
180k
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
180k
            if (code < 0)
333
0
                return code;
334
335
180k
# endif
336
337
180k
#define rational_floor(tl)\
338
180k
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
180k
#define STEP_LINE(ix, tl)\
340
180k
  tl.x += tl.ldi;\
341
180k
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
180k
  ix = rational_floor(tl)
343
344
180k
        rxl = rational_floor(l);
345
180k
        rxr = rational_floor(r);
346
180k
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
1.86M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
1.86M
#     if LINEAR_COLOR
349
1.86M
                if (rxl != rxr) {
350
1.66M
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
1.66M
                    if (code < 0)
352
0
                        goto xit;
353
1.66M
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
1.66M
                    if (code < 0)
355
0
                        goto xit;
356
1.66M
                }
357
1.86M
                if (++iy == iy1)
358
180k
                    break;
359
1.68M
                STEP_LINE(rxl, l);
360
1.68M
                STEP_LINE(rxr, r);
361
1.68M
                step_gradient(&lg, num_components);
362
1.68M
                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
1.68M
        }
379
# if !LINEAR_COLOR
380
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
180k
            code = 0;
383
180k
# endif
384
180k
#undef STEP_LINE
385
180k
#undef SET_MINIMAL_WIDTH
386
180k
#undef CONNECT_RECTANGLES
387
180k
#undef FILL_TRAP_RECT
388
180k
#undef FILL_TRAP_RECT_DIRECT
389
180k
#undef FILL_TRAP_RECT_INRECT
390
180k
#undef YMULT_QUO
391
180k
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
180k
        return_if_interrupt(dev->memory);
394
180k
        return code;
395
180k
    }
396
180k
}
gdevddrw.c:gx_fill_trapezoid_ns_lc
Line
Count
Source
137
11.6M
{
138
11.6M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
11.6M
    const fixed ymax = fixed_pixround(ytop);
140
141
11.6M
    if (ymin >= ymax)
142
4.67M
        return 0;    /* no scan lines to sample */
143
6.96M
    {
144
6.96M
        int iy = fixed2int_var(ymin);
145
6.96M
        const int iy1 = fixed2int_var(ymax);
146
6.96M
        trap_line l, r;
147
6.96M
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
6.96M
        const fixed
152
6.96M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
6.96M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
6.96M
        const fixed /* partial pixel offset to first line to sample */
155
6.96M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
6.96M
        fixed fxl;
157
6.96M
        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
6.96M
# if LINEAR_COLOR
165
6.96M
            int num_components = dev->color_info.num_components;
166
6.96M
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
6.96M
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
6.96M
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
6.96M
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
6.96M
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
6.96M
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
6.96M
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
6.96M
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
6.96M
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
6.96M
            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
6.96M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
6.96M
        l.h = left->end.y - left->start.y;
185
6.96M
        if (l.h == 0)
186
0
           return 0;
187
6.96M
        r.h = right->end.y - right->start.y;
188
6.96M
        if (r.h == 0)
189
0
           return 0;
190
6.96M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
6.96M
        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
6.96M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
6.96M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
6.96M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
6.96M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
6.96M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
6.96M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
6.96M
#if LINEAR_COLOR
210
6.96M
#   define FILL_TRAP_RECT(x,y,w,h)\
211
6.96M
        (!(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
6.96M
#define YMULT_QUO(ys, tl)\
228
6.96M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
6.96M
   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
6.96M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
6.96M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
6.96M
#endif
264
6.96M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
1.09M
            l.di = 0, l.df = 0;
267
1.09M
            fxl = 0;
268
5.87M
        } else {
269
5.87M
            compute_dx(&l, dxl, ysl);
270
5.87M
            fxl = YMULT_QUO(ysl, l);
271
5.87M
            l.x += fxl;
272
5.87M
        }
273
6.96M
        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
1.09M
            r.di = 0, r.df = 0;
286
1.09M
        }
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
5.87M
        else if (dxr == dxl && fxl != 0) {
292
185k
            if (l.di == 0)
293
34.1k
                r.di = 0, r.df = l.df;
294
151k
            else
295
151k
                compute_dx(&r, dxr, ysr);
296
185k
            if (ysr == ysl && r.h == l.h)
297
105k
                r.x += fxl;
298
80.2k
            else
299
80.2k
                r.x += YMULT_QUO(ysr, r);
300
5.68M
        } else {
301
5.68M
            compute_dx(&r, dxr, ysr);
302
5.68M
            r.x += YMULT_QUO(ysr, r);
303
5.68M
        }
304
        /* Compute one line's worth of dx/dy. */
305
6.96M
        compute_ldx(&l, ysl);
306
6.96M
        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
6.96M
        l.x += fixed_epsilon;
310
6.96M
        r.x += fixed_epsilon;
311
6.96M
# 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
6.96M
            lg.c = lgc;
320
6.96M
            lg.f = lgf;
321
6.96M
            lg.num = lgnum;
322
6.96M
            rg.c = rgc;
323
6.96M
            rg.f = rgf;
324
6.96M
            rg.num = rgnum;
325
6.96M
            xg.c = xgc;
326
6.96M
            xg.f = xgf;
327
6.96M
            xg.num = xgnum;
328
6.96M
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
6.96M
            if (code < 0)
330
0
                return code;
331
6.96M
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
6.96M
            if (code < 0)
333
0
                return code;
334
335
6.96M
# endif
336
337
6.96M
#define rational_floor(tl)\
338
6.96M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
6.96M
#define STEP_LINE(ix, tl)\
340
6.96M
  tl.x += tl.ldi;\
341
6.96M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
6.96M
  ix = rational_floor(tl)
343
344
6.96M
        rxl = rational_floor(l);
345
6.96M
        rxr = rational_floor(r);
346
6.96M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
53.4M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
53.4M
#     if LINEAR_COLOR
349
53.4M
                if (rxl != rxr) {
350
9.57M
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
9.57M
                    if (code < 0)
352
0
                        goto xit;
353
9.57M
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
9.57M
                    if (code < 0)
355
0
                        goto xit;
356
9.57M
                }
357
53.4M
                if (++iy == iy1)
358
6.96M
                    break;
359
46.4M
                STEP_LINE(rxl, l);
360
46.4M
                STEP_LINE(rxr, r);
361
46.4M
                step_gradient(&lg, num_components);
362
46.4M
                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
46.4M
        }
379
# if !LINEAR_COLOR
380
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
6.96M
            code = 0;
383
6.96M
# endif
384
6.96M
#undef STEP_LINE
385
6.96M
#undef SET_MINIMAL_WIDTH
386
6.96M
#undef CONNECT_RECTANGLES
387
6.96M
#undef FILL_TRAP_RECT
388
6.96M
#undef FILL_TRAP_RECT_DIRECT
389
6.96M
#undef FILL_TRAP_RECT_INRECT
390
6.96M
#undef YMULT_QUO
391
6.96M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
6.96M
        return_if_interrupt(dev->memory);
394
6.96M
        return code;
395
6.96M
    }
396
6.96M
}
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