Coverage Report

Created: 2026-10-28 08:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ghostpdl/base/gxdtfill.h
Line
Count
Source
1
/* Copyright (C) 2001-2023 Artifex Software, Inc.
2
   All Rights Reserved.
3
4
   This software is provided AS-IS with no warranty, either express or
5
   implied.
6
7
   This software is distributed under license and may not be copied,
8
   modified or distributed except as expressly authorized under the terms
9
   of the license contained in the file LICENSE in this distribution.
10
11
   Refer to licensing information at http://www.artifex.com or contact
12
   Artifex Software, Inc.,  39 Mesa Street, Suite 108A, San Francisco,
13
   CA 94129, USA, for further information.
14
*/
15
16
17
/* Configurable algorithm for filling a trapezoid */
18
19
/*
20
 * Since we need several statically defined variants of this agorithm,
21
 * we store it in .h file and include several times into gdevddrw.c and
22
 * into gxfill.h . Configuration flags (macros) are :
23
 *
24
 *   GX_FILL_TRAPEZOID - a name of method
25
 *   CONTIGUOUS_FILL   - prevent dropouts in narrow trapezoids
26
 *   SWAP_AXES         - assume swapped axes
27
 *   FILL_DIRECT       - See LOOP_FILL_RECTANGLE_DIRECT.
28
 *   LINEAR_COLOR      - Fill with a linear color.
29
 *   EDGE_TYPE         - a type of edge structure.
30
 *   FILL_ATTRS        - operation attributes.
31
 */
32
33
/*
34
 * Fill a trapezoid.  left.start => left.end and right.start => right.end
35
 * define the sides; ybot and ytop define the top and bottom.  Requires:
36
 *      {left,right}->start.y <= ybot <= ytop <= {left,right}->end.y.
37
 * Lines where left.x >= right.x will not be drawn.  Thanks to Paul Haeberli
38
 * for an early floating point version of this algorithm.
39
 */
40
41
/*
42
 * With CONTIGUOUS_FILL is off,
43
 * this algorithm paints pixels, which centers fall between
44
 * the left and the right side of the trapezoid, excluding the
45
 * right side (see PLRM3, 7.5. Scan conversion details).
46
 * Particularly 0-width trapezoids are not painted.
47
 *
48
 * Similarly, it paints pixels, which centers
49
 * fall between ybot and ytop, excluding ytop.
50
 * Particularly 0-height trapezoids are not painted.
51
 *
52
 * With CONTIGUOUS_FILL is on, it paints a contigous area,
53
 * adding a minimal number of pixels outside the trapezoid.
54
 * Particularly it may paint pixels on the right and on the top sides,
55
 * if they are necessary for the contiguity.
56
 *
57
 * With LINEAR_COLOR returns 1 if the gradient arithmetics overflows..
58
 */
59
60
/*
61
We must paint pixels with index i such that
62
63
    Xl <= i + 0.5 < Xr
64
65
The condition is is equivalent to
66
67
    Xl - 0.5 <= i < Xr - 0.5
68
69
which is equivalent to
70
71
    (is_integer(Xl - 0.5) ? Xl - 0.5 : ceil(Xl - 0.5)) <= i <
72
    (is_integer(Xr - 0.5) ? Xr - 0.5 : floor(Xr - 0.5) + 1)
73
74
(the last '+1" happens due to the strong comparizon '<')
75
which is equivalent to
76
77
    ceil(Xl - 0.5) <= i < ceil(Xr - 0.5)
78
79
trap_line represents the intersection coordinate as a rational value :
80
81
    Xl = xl + e - fl
82
    Xr = xr + e - fr
83
84
Where 'e' is 'fixed_epsilon', 0.5 is 'fixed_half', and fl == l.fx / l.h, fr == - r.fx / r.h,
85
e <= fl < 0, e <= fr < 0.
86
Let
87
88
    xl' := xl + 0.5
89
    xr' := xr + 0.5
90
91
Then
92
93
    xl = xl' - 0.5
94
    xr = xr' - 0.5
95
96
    Xl = xl' - 0.5 + e - fl
97
    Xr = xr' - 0.5 + e - fr
98
99
    ceil(xl' - 0.5 + e - fl - 0.5) <= i < ceil(xr' - 0.5 + e - fr - 0.5)
100
101
which is equivalent to
102
103
    ceil(xl' + e - fl) - 1 <= i < ceil(xr' + e - fr) - 1
104
105
which is equivalent to
106
107
    (is_integer(xl' + e - fl) ? xl' + e - fl - 1 : ceil(xl' + e - fl) - 1) <= i <
108
    (is_integer(xr' + e - fr) ? xr' + e - fr - 1 : ceil(xr' + e - fr) - 1)
109
110
which is equivalent to
111
112
    (is_integer(xl' + e - fl) ? xl' + e - fl - 1 : floor(xl' + e - fl)) <= i <
113
    (is_integer(xr' + e - fr) ? xr' + e - fr - 1 : floor(xr' + e - fr))
114
115
which is equivalent to
116
117
    (is_integer(xl') && e == fl ? xl' - 1 : floor(xl' + e - fl)) <= i <
118
    (is_integer(xr') && e == fr ? xr' - 1 : floor(xr' + e - fr))
119
120
Note that e != fl ==> floor(xl' + e - fl) == floor(xl')  due to e - fl < LeastSignificantBit(xl') ;
121
          e == fl ==> floor(xl' + e - fl) == floor(xl')  due to e - fl == 0;
122
123
thus the condition is is equivalent to
124
125
    (is_integer(xl') && e == fl ? xl' - 1 : floor(xl')) <= i <
126
    (is_integer(xr') && e == fr ? xr' - 1 : floor(xr'))
127
128
It is computed with the macro 'rational_floor'.
129
130
*/
131
132
#if defined(GX_FILL_TRAPEZOID) && defined(EDGE_TYPE)
133
134
GX_FILL_TRAPEZOID (gx_device * dev, const EDGE_TYPE * left,
135
    const EDGE_TYPE * right, fixed ybot, fixed ytop, int flags,
136
    const gx_device_color * pdevc, FILL_ATTRS fa)
137
140M
{
138
140M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
140M
    const fixed ymax = fixed_pixround(ytop);
140
141
140M
    if (ymin >= ymax)
142
31.7M
        return 0;    /* no scan lines to sample */
143
108M
    {
144
108M
        int iy = fixed2int_var(ymin);
145
108M
        const int iy1 = fixed2int_var(ymax);
146
108M
        trap_line l, r;
147
108M
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
108M
        const fixed
152
108M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
108M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
108M
        const fixed /* partial pixel offset to first line to sample */
155
108M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
108M
        fixed fxl;
157
108M
        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
85.2M
            dev_proc_fill_rectangle((*fill_rect)) =
179
85.2M
                dev_proc(dev, fill_rectangle);
180
# endif
181
182
108M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
108M
        l.h = left->end.y - left->start.y;
185
108M
        if (l.h == 0)
186
0
           return 0;
187
108M
        r.h = right->end.y - right->start.y;
188
108M
        if (r.h == 0)
189
0
           return 0;
190
108M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
108M
        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
108M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
882M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
882M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
108M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
220M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
220M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
#if LINEAR_COLOR
210
#   define FILL_TRAP_RECT(x,y,w,h)\
211
60.7M
        (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den))
212
#else
213
#   define FILL_TRAP_RECT(x,y,w,h)\
214
1.10G
        (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
108M
#define YMULT_QUO(ys, tl)\
228
154M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
154M
   fixed_mult_quo(ys, tl.df, tl.h))
230
231
#if CONTIGUOUS_FILL
232
/*
233
 * If left and right boundary round to same pixel index,
234
 * we would not paing the scan and would get a dropout.
235
 * Check for this case and choose one of two pixels
236
 * which is closer to the "axis". We need to exclude
237
 * 'peak' because it would paint an excessive pixel.
238
 */
239
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \
240
0
    if (ixl == ixr) \
241
0
        if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\
242
0
            fixed x = int2fixed(ixl) + fixed_half;\
243
0
            if (x - l.x < r.x - x)\
244
0
                ++ixr;\
245
0
            else\
246
0
                --ixl;\
247
0
        }
248
249
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\
250
0
    if (adj1 < adj2) {\
251
0
        if (iy - ry > 1) {\
252
0
            code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\
253
0
            if (code < 0)\
254
0
                goto xit;\
255
0
            ry = iy - 1;\
256
0
        }\
257
0
        adj1 = adj2 = (adj2 + adj2) / 2;\
258
0
    }
259
260
#else
261
2.23G
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
2.03G
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
#endif
264
108M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
27.0M
            l.di = 0, l.df = 0;
267
27.0M
            fxl = 0;
268
81.5M
        } else {
269
81.5M
            compute_dx(&l, dxl, ysl);
270
81.5M
            fxl = YMULT_QUO(ysl, l);
271
81.5M
            l.x += fxl;
272
81.5M
        }
273
108M
        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
26.2M
                if (l.di == 0 && l.df == 0) {
278
12.1M
                    rxl = fixed2int_var(l.x);
279
12.1M
                    rxr = fixed2int_var(r.x);
280
12.1M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
12.1M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
12.1M
                    goto xit;
283
12.1M
                }
284
14.1M
#     endif
285
14.1M
            r.di = 0, r.df = 0;
286
14.1M
        }
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
77.6M
        else if (dxr == dxl && fxl != 0) {
292
7.55M
            if (l.di == 0)
293
2.16M
                r.di = 0, r.df = l.df;
294
5.39M
            else
295
5.39M
                compute_dx(&r, dxr, ysr);
296
7.55M
            if (ysr == ysl && r.h == l.h)
297
4.99M
                r.x += fxl;
298
2.56M
            else
299
2.56M
                r.x += YMULT_QUO(ysr, r);
300
70.1M
        } else {
301
70.1M
            compute_dx(&r, dxr, ysr);
302
70.1M
            r.x += YMULT_QUO(ysr, r);
303
70.1M
        }
304
        /* Compute one line's worth of dx/dy. */
305
73.1M
        compute_ldx(&l, ysl);
306
73.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
96.4M
        l.x += fixed_epsilon;
310
96.4M
        r.x += fixed_epsilon;
311
# if LINEAR_COLOR
312
#     ifdef DEBUG
313
                if (check_gradient_overflow(left, right)) {
314
                    /* The caller must care of.
315
                       Checking it here looses some performance with triangles. */
316
                    return_error(gs_error_unregistered);
317
                }
318
#     endif
319
            lg.c = lgc;
320
            lg.f = lgf;
321
            lg.num = lgnum;
322
            rg.c = rgc;
323
            rg.f = rgf;
324
            rg.num = rgnum;
325
            xg.c = xgc;
326
            xg.f = xgf;
327
            xg.num = xgnum;
328
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
23.3M
            if (code < 0)
330
0
                return code;
331
23.3M
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
23.3M
            if (code < 0)
333
0
                return code;
334
335
23.3M
# endif
336
337
23.3M
#define rational_floor(tl)\
338
5.50G
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
23.3M
#define STEP_LINE(ix, tl)\
340
5.28G
  tl.x += tl.ldi;\
341
5.28G
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
5.31G
  ix = rational_floor(tl)
343
344
96.4M
        rxl = rational_floor(l);
345
96.4M
        rxr = rational_floor(r);
346
96.4M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
2.74G
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
#     if LINEAR_COLOR
349
538M
                if (rxl != rxr) {
350
60.7M
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
60.7M
                    if (code < 0)
352
0
                        goto xit;
353
60.7M
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
60.7M
                    if (code < 0)
355
17
                        goto xit;
356
60.7M
                }
357
538M
                if (++iy == iy1)
358
23.3M
                    break;
359
515M
                STEP_LINE(rxl, l);
360
515M
                STEP_LINE(rxr, r);
361
515M
                step_gradient(&lg, num_components);
362
515M
                step_gradient(&rg, num_components);
363
#     else
364
                register int ixl, ixr;
365
366
2.12G
                STEP_LINE(ixl, l);
367
2.12G
                STEP_LINE(ixr, r);
368
2.12G
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
2.12G
                if (ixl != rxl || ixr != rxr) {
370
1.01G
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
1.01G
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
1.01G
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
1.01G
                    if (code < 0)
374
0
                        goto xit;
375
1.01G
                    rxl = ixl, rxr = ixr, ry = iy;
376
1.01G
                }
377
#     endif
378
515M
        }
379
# if !LINEAR_COLOR
380
73.1M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
23.3M
            code = 0;
383
23.3M
# endif
384
23.3M
#undef STEP_LINE
385
23.3M
#undef SET_MINIMAL_WIDTH
386
23.3M
#undef CONNECT_RECTANGLES
387
23.3M
#undef FILL_TRAP_RECT
388
23.3M
#undef FILL_TRAP_RECT_DIRECT
389
23.3M
#undef FILL_TRAP_RECT_INRECT
390
23.3M
#undef YMULT_QUO
391
108M
xit:  if (code < 0 && FILL_DIRECT)
392
17
            return_error(code);
393
108M
        return_if_interrupt(dev->memory);
394
108M
        return code;
395
108M
    }
396
108M
}
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.69M
{
138
1.69M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
1.69M
    const fixed ymax = fixed_pixround(ytop);
140
141
1.69M
    if (ymin >= ymax)
142
91.4k
        return 0;    /* no scan lines to sample */
143
1.60M
    {
144
1.60M
        int iy = fixed2int_var(ymin);
145
1.60M
        const int iy1 = fixed2int_var(ymax);
146
1.60M
        trap_line l, r;
147
1.60M
        register int rxl, rxr;
148
1.60M
#if !LINEAR_COLOR
149
1.60M
        int ry;
150
1.60M
#endif
151
1.60M
        const fixed
152
1.60M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
1.60M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
1.60M
        const fixed /* partial pixel offset to first line to sample */
155
1.60M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
1.60M
        fixed fxl;
157
1.60M
        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.60M
            gx_color_index cindex = pdevc->colors.pure;
178
1.60M
            dev_proc_fill_rectangle((*fill_rect)) =
179
1.60M
                dev_proc(dev, fill_rectangle);
180
1.60M
# endif
181
182
1.60M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
1.60M
        l.h = left->end.y - left->start.y;
185
1.60M
        if (l.h == 0)
186
0
           return 0;
187
1.60M
        r.h = right->end.y - right->start.y;
188
1.60M
        if (r.h == 0)
189
0
           return 0;
190
1.60M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
1.60M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
1.60M
#if !LINEAR_COLOR
193
1.60M
        ry = iy;
194
1.60M
#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.60M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
1.60M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
1.60M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
1.60M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
1.60M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
1.60M
   (*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.60M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
1.60M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
1.60M
#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.60M
#define YMULT_QUO(ys, tl)\
228
1.60M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
1.60M
   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.60M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
1.60M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
1.60M
#endif
264
1.60M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
155k
            l.di = 0, l.df = 0;
267
155k
            fxl = 0;
268
1.44M
        } else {
269
1.44M
            compute_dx(&l, dxl, ysl);
270
1.44M
            fxl = YMULT_QUO(ysl, l);
271
1.44M
            l.x += fxl;
272
1.44M
        }
273
1.60M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
144k
#     if !LINEAR_COLOR
277
144k
                if (l.di == 0 && l.df == 0) {
278
130k
                    rxl = fixed2int_var(l.x);
279
130k
                    rxr = fixed2int_var(r.x);
280
130k
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
130k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
130k
                    goto xit;
283
130k
                }
284
13.7k
#     endif
285
13.7k
            r.di = 0, r.df = 0;
286
13.7k
        }
287
        /*
288
         * The test for fxl != 0 is required because the right edge might
289
         * cross some pixel centers even if the left edge doesn't.
290
         */
291
1.45M
        else if (dxr == dxl && fxl != 0) {
292
1.15M
            if (l.di == 0)
293
569k
                r.di = 0, r.df = l.df;
294
581k
            else
295
581k
                compute_dx(&r, dxr, ysr);
296
1.15M
            if (ysr == ysl && r.h == l.h)
297
1.15M
                r.x += fxl;
298
60
            else
299
60
                r.x += YMULT_QUO(ysr, r);
300
1.15M
        } else {
301
308k
            compute_dx(&r, dxr, ysr);
302
308k
            r.x += YMULT_QUO(ysr, r);
303
308k
        }
304
        /* Compute one line's worth of dx/dy. */
305
1.47M
        compute_ldx(&l, ysl);
306
1.47M
        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.47M
        l.x += fixed_epsilon;
310
1.47M
        r.x += fixed_epsilon;
311
# if LINEAR_COLOR
312
#     ifdef DEBUG
313
                if (check_gradient_overflow(left, right)) {
314
                    /* The caller must care of.
315
                       Checking it here looses some performance with triangles. */
316
                    return_error(gs_error_unregistered);
317
                }
318
#     endif
319
            lg.c = lgc;
320
            lg.f = lgf;
321
            lg.num = lgnum;
322
            rg.c = rgc;
323
            rg.f = rgf;
324
            rg.num = rgnum;
325
            xg.c = xgc;
326
            xg.f = xgf;
327
            xg.num = xgnum;
328
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
            if (code < 0)
330
                return code;
331
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
            if (code < 0)
333
                return code;
334
335
# endif
336
337
1.47M
#define rational_floor(tl)\
338
1.47M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
1.47M
#define STEP_LINE(ix, tl)\
340
1.47M
  tl.x += tl.ldi;\
341
1.47M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
1.47M
  ix = rational_floor(tl)
343
344
1.47M
        rxl = rational_floor(l);
345
1.47M
        rxr = rational_floor(r);
346
1.47M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
171M
        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
170M
                register int ixl, ixr;
365
366
170M
                STEP_LINE(ixl, l);
367
170M
                STEP_LINE(ixr, r);
368
170M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
170M
                if (ixl != rxl || ixr != rxr) {
370
24.6M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
24.6M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
24.6M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
24.6M
                    if (code < 0)
374
0
                        goto xit;
375
24.6M
                    rxl = ixl, rxr = ixr, ry = iy;
376
24.6M
                }
377
170M
#     endif
378
170M
        }
379
1.47M
# if !LINEAR_COLOR
380
1.47M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
1.47M
#undef STEP_LINE
385
1.47M
#undef SET_MINIMAL_WIDTH
386
1.47M
#undef CONNECT_RECTANGLES
387
1.47M
#undef FILL_TRAP_RECT
388
1.47M
#undef FILL_TRAP_RECT_DIRECT
389
1.47M
#undef FILL_TRAP_RECT_INRECT
390
1.47M
#undef YMULT_QUO
391
1.60M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
1.60M
        return_if_interrupt(dev->memory);
394
1.60M
        return code;
395
1.60M
    }
396
1.60M
}
gdevddrw.c:gx_fill_trapezoid_as_nd
Line
Count
Source
137
2.53M
{
138
2.53M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
2.53M
    const fixed ymax = fixed_pixround(ytop);
140
141
2.53M
    if (ymin >= ymax)
142
30.0k
        return 0;    /* no scan lines to sample */
143
2.50M
    {
144
2.50M
        int iy = fixed2int_var(ymin);
145
2.50M
        const int iy1 = fixed2int_var(ymax);
146
2.50M
        trap_line l, r;
147
2.50M
        register int rxl, rxr;
148
2.50M
#if !LINEAR_COLOR
149
2.50M
        int ry;
150
2.50M
#endif
151
2.50M
        const fixed
152
2.50M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
2.50M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
2.50M
        const fixed /* partial pixel offset to first line to sample */
155
2.50M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
2.50M
        fixed fxl;
157
2.50M
        int code;
158
# if CONTIGUOUS_FILL
159
            const bool peak0 = ((flags & 1) != 0);
160
            const bool peak1 = ((flags & 2) != 0);
161
            int peak_y0 = ybot + fixed_half;
162
            int peak_y1 = ytop - fixed_half;
163
# endif
164
# if LINEAR_COLOR
165
            int num_components = dev->color_info.num_components;
166
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
            trap_gradient lg, rg, xg;
176
# else
177
2.50M
            gx_color_index cindex = pdevc->colors.pure;
178
2.50M
            dev_proc_fill_rectangle((*fill_rect)) =
179
2.50M
                dev_proc(dev, fill_rectangle);
180
2.50M
# endif
181
182
2.50M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
2.50M
        l.h = left->end.y - left->start.y;
185
2.50M
        if (l.h == 0)
186
0
           return 0;
187
2.50M
        r.h = right->end.y - right->start.y;
188
2.50M
        if (r.h == 0)
189
0
           return 0;
190
2.50M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
2.50M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
2.50M
#if !LINEAR_COLOR
193
2.50M
        ry = iy;
194
2.50M
#endif
195
196
/*
197
 * Free variables of FILL_TRAP_RECT:
198
 *  SWAP_AXES, pdevc, dev, fa
199
 * Free variables of FILL_TRAP_RECT_DIRECT:
200
 *  SWAP_AXES, fill_rect, dev, cindex
201
 */
202
2.50M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
2.50M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
2.50M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
2.50M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
2.50M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
2.50M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
#if LINEAR_COLOR
210
#   define FILL_TRAP_RECT(x,y,w,h)\
211
        (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den))
212
#else
213
2.50M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
2.50M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
2.50M
#endif
216
217
        /* Compute the dx/dy ratios. */
218
219
        /*
220
         * Compute the x offsets at the first scan line to sample.  We need
221
         * to be careful in computing ys# * dx#f {/,%} h# because the
222
         * multiplication may overflow.  We know that all the quantities
223
         * involved are non-negative, and that ys# is usually less than 1 (as
224
         * a fixed, of course); this gives us a cheap conservative check for
225
         * overflow in the multiplication.
226
         */
227
2.50M
#define YMULT_QUO(ys, tl)\
228
2.50M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
2.50M
   fixed_mult_quo(ys, tl.df, tl.h))
230
231
#if CONTIGUOUS_FILL
232
/*
233
 * If left and right boundary round to same pixel index,
234
 * we would not paing the scan and would get a dropout.
235
 * Check for this case and choose one of two pixels
236
 * which is closer to the "axis". We need to exclude
237
 * 'peak' because it would paint an excessive pixel.
238
 */
239
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \
240
    if (ixl == ixr) \
241
        if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\
242
            fixed x = int2fixed(ixl) + fixed_half;\
243
            if (x - l.x < r.x - x)\
244
                ++ixr;\
245
            else\
246
                --ixl;\
247
        }
248
249
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\
250
    if (adj1 < adj2) {\
251
        if (iy - ry > 1) {\
252
            code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\
253
            if (code < 0)\
254
                goto xit;\
255
            ry = iy - 1;\
256
        }\
257
        adj1 = adj2 = (adj2 + adj2) / 2;\
258
    }
259
260
#else
261
2.50M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
2.50M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
2.50M
#endif
264
2.50M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
539k
            l.di = 0, l.df = 0;
267
539k
            fxl = 0;
268
1.96M
        } else {
269
1.96M
            compute_dx(&l, dxl, ysl);
270
1.96M
            fxl = YMULT_QUO(ysl, l);
271
1.96M
            l.x += fxl;
272
1.96M
        }
273
2.50M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
504k
#     if !LINEAR_COLOR
277
504k
                if (l.di == 0 && l.df == 0) {
278
480k
                    rxl = fixed2int_var(l.x);
279
480k
                    rxr = fixed2int_var(r.x);
280
480k
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
480k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
480k
                    goto xit;
283
480k
                }
284
24.4k
#     endif
285
24.4k
            r.di = 0, r.df = 0;
286
24.4k
        }
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
2.00M
        else if (dxr == dxl && fxl != 0) {
292
373k
            if (l.di == 0)
293
204k
                r.di = 0, r.df = l.df;
294
168k
            else
295
168k
                compute_dx(&r, dxr, ysr);
296
373k
            if (ysr == ysl && r.h == l.h)
297
372k
                r.x += fxl;
298
252
            else
299
252
                r.x += YMULT_QUO(ysr, r);
300
1.63M
        } else {
301
1.63M
            compute_dx(&r, dxr, ysr);
302
1.63M
            r.x += YMULT_QUO(ysr, r);
303
1.63M
        }
304
        /* Compute one line's worth of dx/dy. */
305
2.02M
        compute_ldx(&l, ysl);
306
2.02M
        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
2.02M
        l.x += fixed_epsilon;
310
2.02M
        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
2.02M
#define rational_floor(tl)\
338
2.02M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
2.02M
#define STEP_LINE(ix, tl)\
340
2.02M
  tl.x += tl.ldi;\
341
2.02M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
2.02M
  ix = rational_floor(tl)
343
344
2.02M
        rxl = rational_floor(l);
345
2.02M
        rxr = rational_floor(r);
346
2.02M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
164M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
#     if LINEAR_COLOR
349
                if (rxl != rxr) {
350
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
                    if (code < 0)
352
                        goto xit;
353
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
                    if (code < 0)
355
                        goto xit;
356
                }
357
                if (++iy == iy1)
358
                    break;
359
                STEP_LINE(rxl, l);
360
                STEP_LINE(rxr, r);
361
                step_gradient(&lg, num_components);
362
                step_gradient(&rg, num_components);
363
#     else
364
162M
                register int ixl, ixr;
365
366
162M
                STEP_LINE(ixl, l);
367
162M
                STEP_LINE(ixr, r);
368
162M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
162M
                if (ixl != rxl || ixr != rxr) {
370
113M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
113M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
113M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
113M
                    if (code < 0)
374
0
                        goto xit;
375
113M
                    rxl = ixl, rxr = ixr, ry = iy;
376
113M
                }
377
162M
#     endif
378
162M
        }
379
2.02M
# if !LINEAR_COLOR
380
2.02M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
2.02M
#undef STEP_LINE
385
2.02M
#undef SET_MINIMAL_WIDTH
386
2.02M
#undef CONNECT_RECTANGLES
387
2.02M
#undef FILL_TRAP_RECT
388
2.02M
#undef FILL_TRAP_RECT_DIRECT
389
2.02M
#undef FILL_TRAP_RECT_INRECT
390
2.02M
#undef YMULT_QUO
391
2.50M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
2.50M
        return_if_interrupt(dev->memory);
394
2.50M
        return code;
395
2.50M
    }
396
2.50M
}
gdevddrw.c:gx_fill_trapezoid_ns_fd
Line
Count
Source
137
29.4M
{
138
29.4M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
29.4M
    const fixed ymax = fixed_pixround(ytop);
140
141
29.4M
    if (ymin >= ymax)
142
1.54M
        return 0;    /* no scan lines to sample */
143
27.9M
    {
144
27.9M
        int iy = fixed2int_var(ymin);
145
27.9M
        const int iy1 = fixed2int_var(ymax);
146
27.9M
        trap_line l, r;
147
27.9M
        register int rxl, rxr;
148
27.9M
#if !LINEAR_COLOR
149
27.9M
        int ry;
150
27.9M
#endif
151
27.9M
        const fixed
152
27.9M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
27.9M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
27.9M
        const fixed /* partial pixel offset to first line to sample */
155
27.9M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
27.9M
        fixed fxl;
157
27.9M
        int code;
158
# if CONTIGUOUS_FILL
159
            const bool peak0 = ((flags & 1) != 0);
160
            const bool peak1 = ((flags & 2) != 0);
161
            int peak_y0 = ybot + fixed_half;
162
            int peak_y1 = ytop - fixed_half;
163
# endif
164
# if LINEAR_COLOR
165
            int num_components = dev->color_info.num_components;
166
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
            trap_gradient lg, rg, xg;
176
# else
177
27.9M
            gx_color_index cindex = pdevc->colors.pure;
178
27.9M
            dev_proc_fill_rectangle((*fill_rect)) =
179
27.9M
                dev_proc(dev, fill_rectangle);
180
27.9M
# endif
181
182
27.9M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
27.9M
        l.h = left->end.y - left->start.y;
185
27.9M
        if (l.h == 0)
186
0
           return 0;
187
27.9M
        r.h = right->end.y - right->start.y;
188
27.9M
        if (r.h == 0)
189
0
           return 0;
190
27.9M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
27.9M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
27.9M
#if !LINEAR_COLOR
193
27.9M
        ry = iy;
194
27.9M
#endif
195
196
/*
197
 * Free variables of FILL_TRAP_RECT:
198
 *  SWAP_AXES, pdevc, dev, fa
199
 * Free variables of FILL_TRAP_RECT_DIRECT:
200
 *  SWAP_AXES, fill_rect, dev, cindex
201
 */
202
27.9M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
27.9M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
27.9M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
27.9M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
27.9M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
27.9M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
#if LINEAR_COLOR
210
#   define FILL_TRAP_RECT(x,y,w,h)\
211
        (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den))
212
#else
213
27.9M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
27.9M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
27.9M
#endif
216
217
        /* Compute the dx/dy ratios. */
218
219
        /*
220
         * Compute the x offsets at the first scan line to sample.  We need
221
         * to be careful in computing ys# * dx#f {/,%} h# because the
222
         * multiplication may overflow.  We know that all the quantities
223
         * involved are non-negative, and that ys# is usually less than 1 (as
224
         * a fixed, of course); this gives us a cheap conservative check for
225
         * overflow in the multiplication.
226
         */
227
27.9M
#define YMULT_QUO(ys, tl)\
228
27.9M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
27.9M
   fixed_mult_quo(ys, tl.df, tl.h))
230
231
#if CONTIGUOUS_FILL
232
/*
233
 * If left and right boundary round to same pixel index,
234
 * we would not paing the scan and would get a dropout.
235
 * Check for this case and choose one of two pixels
236
 * which is closer to the "axis". We need to exclude
237
 * 'peak' because it would paint an excessive pixel.
238
 */
239
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \
240
    if (ixl == ixr) \
241
        if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\
242
            fixed x = int2fixed(ixl) + fixed_half;\
243
            if (x - l.x < r.x - x)\
244
                ++ixr;\
245
            else\
246
                --ixl;\
247
        }
248
249
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\
250
    if (adj1 < adj2) {\
251
        if (iy - ry > 1) {\
252
            code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\
253
            if (code < 0)\
254
                goto xit;\
255
            ry = iy - 1;\
256
        }\
257
        adj1 = adj2 = (adj2 + adj2) / 2;\
258
    }
259
260
#else
261
27.9M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
27.9M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
27.9M
#endif
264
27.9M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
10.2M
            l.di = 0, l.df = 0;
267
10.2M
            fxl = 0;
268
17.6M
        } else {
269
17.6M
            compute_dx(&l, dxl, ysl);
270
17.6M
            fxl = YMULT_QUO(ysl, l);
271
17.6M
            l.x += fxl;
272
17.6M
        }
273
27.9M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
10.4M
#     if !LINEAR_COLOR
277
10.4M
                if (l.di == 0 && l.df == 0) {
278
5.91M
                    rxl = fixed2int_var(l.x);
279
5.91M
                    rxr = fixed2int_var(r.x);
280
5.91M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
5.91M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
5.91M
                    goto xit;
283
5.91M
                }
284
4.50M
#     endif
285
4.50M
            r.di = 0, r.df = 0;
286
4.50M
        }
287
        /*
288
         * The test for fxl != 0 is required because the right edge might
289
         * cross some pixel centers even if the left edge doesn't.
290
         */
291
17.4M
        else if (dxr == dxl && fxl != 0) {
292
1.94M
            if (l.di == 0)
293
569k
                r.di = 0, r.df = l.df;
294
1.37M
            else
295
1.37M
                compute_dx(&r, dxr, ysr);
296
1.94M
            if (ysr == ysl && r.h == l.h)
297
1.18M
                r.x += fxl;
298
766k
            else
299
766k
                r.x += YMULT_QUO(ysr, r);
300
15.5M
        } else {
301
15.5M
            compute_dx(&r, dxr, ysr);
302
15.5M
            r.x += YMULT_QUO(ysr, r);
303
15.5M
        }
304
        /* Compute one line's worth of dx/dy. */
305
21.9M
        compute_ldx(&l, ysl);
306
21.9M
        compute_ldx(&r, ysr);
307
        /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding
308
           when the rational part is zero. Now add it back to get xl', xr' */
309
21.9M
        l.x += fixed_epsilon;
310
21.9M
        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
21.9M
#define rational_floor(tl)\
338
21.9M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
21.9M
#define STEP_LINE(ix, tl)\
340
21.9M
  tl.x += tl.ldi;\
341
21.9M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
21.9M
  ix = rational_floor(tl)
343
344
21.9M
        rxl = rational_floor(l);
345
21.9M
        rxr = rational_floor(r);
346
21.9M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
716M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
#     if LINEAR_COLOR
349
                if (rxl != rxr) {
350
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
                    if (code < 0)
352
                        goto xit;
353
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
                    if (code < 0)
355
                        goto xit;
356
                }
357
                if (++iy == iy1)
358
                    break;
359
                STEP_LINE(rxl, l);
360
                STEP_LINE(rxr, r);
361
                step_gradient(&lg, num_components);
362
                step_gradient(&rg, num_components);
363
#     else
364
694M
                register int ixl, ixr;
365
366
694M
                STEP_LINE(ixl, l);
367
694M
                STEP_LINE(ixr, r);
368
694M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
694M
                if (ixl != rxl || ixr != rxr) {
370
165M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
165M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
165M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
165M
                    if (code < 0)
374
0
                        goto xit;
375
165M
                    rxl = ixl, rxr = ixr, ry = iy;
376
165M
                }
377
694M
#     endif
378
694M
        }
379
21.9M
# if !LINEAR_COLOR
380
21.9M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
21.9M
#undef STEP_LINE
385
21.9M
#undef SET_MINIMAL_WIDTH
386
21.9M
#undef CONNECT_RECTANGLES
387
21.9M
#undef FILL_TRAP_RECT
388
21.9M
#undef FILL_TRAP_RECT_DIRECT
389
21.9M
#undef FILL_TRAP_RECT_INRECT
390
21.9M
#undef YMULT_QUO
391
27.9M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
27.9M
        return_if_interrupt(dev->memory);
394
27.9M
        return code;
395
27.9M
    }
396
27.9M
}
gdevddrw.c:gx_fill_trapezoid_ns_nd
Line
Count
Source
137
71.4M
{
138
71.4M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
71.4M
    const fixed ymax = fixed_pixround(ytop);
140
141
71.4M
    if (ymin >= ymax)
142
18.2M
        return 0;    /* no scan lines to sample */
143
53.2M
    {
144
53.2M
        int iy = fixed2int_var(ymin);
145
53.2M
        const int iy1 = fixed2int_var(ymax);
146
53.2M
        trap_line l, r;
147
53.2M
        register int rxl, rxr;
148
53.2M
#if !LINEAR_COLOR
149
53.2M
        int ry;
150
53.2M
#endif
151
53.2M
        const fixed
152
53.2M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
53.2M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
53.2M
        const fixed /* partial pixel offset to first line to sample */
155
53.2M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
53.2M
        fixed fxl;
157
53.2M
        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
53.2M
            gx_color_index cindex = pdevc->colors.pure;
178
53.2M
            dev_proc_fill_rectangle((*fill_rect)) =
179
53.2M
                dev_proc(dev, fill_rectangle);
180
53.2M
# endif
181
182
53.2M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
53.2M
        l.h = left->end.y - left->start.y;
185
53.2M
        if (l.h == 0)
186
0
           return 0;
187
53.2M
        r.h = right->end.y - right->start.y;
188
53.2M
        if (r.h == 0)
189
0
           return 0;
190
53.2M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
53.2M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
53.2M
#if !LINEAR_COLOR
193
53.2M
        ry = iy;
194
53.2M
#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
53.2M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
53.2M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
53.2M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
53.2M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
53.2M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
53.2M
   (*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
53.2M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
53.2M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
53.2M
#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
53.2M
#define YMULT_QUO(ys, tl)\
228
53.2M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
53.2M
   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
53.2M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
53.2M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
53.2M
#endif
264
53.2M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
11.4M
            l.di = 0, l.df = 0;
267
11.4M
            fxl = 0;
268
41.7M
        } else {
269
41.7M
            compute_dx(&l, dxl, ysl);
270
41.7M
            fxl = YMULT_QUO(ysl, l);
271
41.7M
            l.x += fxl;
272
41.7M
        }
273
53.2M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
15.2M
#     if !LINEAR_COLOR
277
15.2M
                if (l.di == 0 && l.df == 0) {
278
5.60M
                    rxl = fixed2int_var(l.x);
279
5.60M
                    rxr = fixed2int_var(r.x);
280
5.60M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
5.60M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
5.60M
                    goto xit;
283
5.60M
                }
284
9.61M
#     endif
285
9.61M
            r.di = 0, r.df = 0;
286
9.61M
        }
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
38.0M
        else if (dxr == dxl && fxl != 0) {
292
2.27M
            if (l.di == 0)
293
267k
                r.di = 0, r.df = l.df;
294
2.01M
            else
295
2.01M
                compute_dx(&r, dxr, ysr);
296
2.27M
            if (ysr == ysl && r.h == l.h)
297
1.30M
                r.x += fxl;
298
971k
            else
299
971k
                r.x += YMULT_QUO(ysr, r);
300
35.7M
        } else {
301
35.7M
            compute_dx(&r, dxr, ysr);
302
35.7M
            r.x += YMULT_QUO(ysr, r);
303
35.7M
        }
304
        /* Compute one line's worth of dx/dy. */
305
47.6M
        compute_ldx(&l, ysl);
306
47.6M
        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
47.6M
        l.x += fixed_epsilon;
310
47.6M
        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
47.6M
#define rational_floor(tl)\
338
47.6M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
47.6M
#define STEP_LINE(ix, tl)\
340
47.6M
  tl.x += tl.ldi;\
341
47.6M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
47.6M
  ix = rational_floor(tl)
343
344
47.6M
        rxl = rational_floor(l);
345
47.6M
        rxr = rational_floor(r);
346
47.6M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
1.14G
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
#     if LINEAR_COLOR
349
                if (rxl != rxr) {
350
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
                    if (code < 0)
352
                        goto xit;
353
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
                    if (code < 0)
355
                        goto xit;
356
                }
357
                if (++iy == iy1)
358
                    break;
359
                STEP_LINE(rxl, l);
360
                STEP_LINE(rxr, r);
361
                step_gradient(&lg, num_components);
362
                step_gradient(&rg, num_components);
363
#     else
364
1.10G
                register int ixl, ixr;
365
366
1.10G
                STEP_LINE(ixl, l);
367
1.10G
                STEP_LINE(ixr, r);
368
1.10G
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
1.10G
                if (ixl != rxl || ixr != rxr) {
370
713M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
713M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
713M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
713M
                    if (code < 0)
374
0
                        goto xit;
375
713M
                    rxl = ixl, rxr = ixr, ry = iy;
376
713M
                }
377
1.10G
#     endif
378
1.10G
        }
379
47.6M
# if !LINEAR_COLOR
380
47.6M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
47.6M
#undef STEP_LINE
385
47.6M
#undef SET_MINIMAL_WIDTH
386
47.6M
#undef CONNECT_RECTANGLES
387
47.6M
#undef FILL_TRAP_RECT
388
47.6M
#undef FILL_TRAP_RECT_DIRECT
389
47.6M
#undef FILL_TRAP_RECT_INRECT
390
47.6M
#undef YMULT_QUO
391
53.2M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
53.2M
        return_if_interrupt(dev->memory);
394
53.2M
        return code;
395
53.2M
    }
396
53.2M
}
gdevddrw.c:gx_fill_trapezoid_as_lc
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
285k
        return 0;    /* no scan lines to sample */
143
827k
    {
144
827k
        int iy = fixed2int_var(ymin);
145
827k
        const int iy1 = fixed2int_var(ymax);
146
827k
        trap_line l, r;
147
827k
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
827k
        const fixed
152
827k
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
827k
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
827k
        const fixed /* partial pixel offset to first line to sample */
155
827k
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
827k
        fixed fxl;
157
827k
        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
827k
# if LINEAR_COLOR
165
827k
            int num_components = dev->color_info.num_components;
166
827k
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
827k
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
827k
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
827k
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
827k
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
827k
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
827k
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
827k
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
827k
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
827k
            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
827k
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
827k
        l.h = left->end.y - left->start.y;
185
827k
        if (l.h == 0)
186
0
           return 0;
187
827k
        r.h = right->end.y - right->start.y;
188
827k
        if (r.h == 0)
189
0
           return 0;
190
827k
        l.x = x0l + (fixed_half - fixed_epsilon);
191
827k
        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
827k
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
827k
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
827k
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
827k
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
827k
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
827k
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
827k
#if LINEAR_COLOR
210
827k
#   define FILL_TRAP_RECT(x,y,w,h)\
211
827k
        (!(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
827k
#define YMULT_QUO(ys, tl)\
228
827k
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
827k
   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
827k
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
827k
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
827k
#endif
264
827k
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
452k
            l.di = 0, l.df = 0;
267
452k
            fxl = 0;
268
452k
        } else {
269
375k
            compute_dx(&l, dxl, ysl);
270
375k
            fxl = YMULT_QUO(ysl, l);
271
375k
            l.x += fxl;
272
375k
        }
273
827k
        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
456k
            r.di = 0, r.df = 0;
286
456k
        }
287
        /*
288
         * The test for fxl != 0 is required because the right edge might
289
         * cross some pixel centers even if the left edge doesn't.
290
         */
291
370k
        else if (dxr == dxl && fxl != 0) {
292
171k
            if (l.di == 0)
293
79.7k
                r.di = 0, r.df = l.df;
294
91.6k
            else
295
91.6k
                compute_dx(&r, dxr, ysr);
296
171k
            if (ysr == ysl && r.h == l.h)
297
171k
                r.x += fxl;
298
89
            else
299
89
                r.x += YMULT_QUO(ysr, r);
300
199k
        } else {
301
199k
            compute_dx(&r, dxr, ysr);
302
199k
            r.x += YMULT_QUO(ysr, r);
303
199k
        }
304
        /* Compute one line's worth of dx/dy. */
305
827k
        compute_ldx(&l, ysl);
306
827k
        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
827k
        l.x += fixed_epsilon;
310
827k
        r.x += fixed_epsilon;
311
827k
# 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
827k
            lg.c = lgc;
320
827k
            lg.f = lgf;
321
827k
            lg.num = lgnum;
322
827k
            rg.c = rgc;
323
827k
            rg.f = rgf;
324
827k
            rg.num = rgnum;
325
827k
            xg.c = xgc;
326
827k
            xg.f = xgf;
327
827k
            xg.num = xgnum;
328
827k
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
827k
            if (code < 0)
330
0
                return code;
331
827k
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
827k
            if (code < 0)
333
0
                return code;
334
335
827k
# endif
336
337
827k
#define rational_floor(tl)\
338
827k
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
827k
#define STEP_LINE(ix, tl)\
340
827k
  tl.x += tl.ldi;\
341
827k
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
827k
  ix = rational_floor(tl)
343
344
827k
        rxl = rational_floor(l);
345
827k
        rxr = rational_floor(r);
346
827k
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
32.9M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
32.9M
#     if LINEAR_COLOR
349
32.9M
                if (rxl != rxr) {
350
19.9M
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
19.9M
                    if (code < 0)
352
0
                        goto xit;
353
19.9M
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
19.9M
                    if (code < 0)
355
4
                        goto xit;
356
19.9M
                }
357
32.9M
                if (++iy == iy1)
358
827k
                    break;
359
32.1M
                STEP_LINE(rxl, l);
360
32.1M
                STEP_LINE(rxr, r);
361
32.1M
                step_gradient(&lg, num_components);
362
32.1M
                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
32.1M
        }
379
# if !LINEAR_COLOR
380
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
827k
            code = 0;
383
827k
# endif
384
827k
#undef STEP_LINE
385
827k
#undef SET_MINIMAL_WIDTH
386
827k
#undef CONNECT_RECTANGLES
387
827k
#undef FILL_TRAP_RECT
388
827k
#undef FILL_TRAP_RECT_DIRECT
389
827k
#undef FILL_TRAP_RECT_INRECT
390
827k
#undef YMULT_QUO
391
827k
xit:  if (code < 0 && FILL_DIRECT)
392
4
            return_error(code);
393
827k
        return_if_interrupt(dev->memory);
394
827k
        return code;
395
827k
    }
396
827k
}
gdevddrw.c:gx_fill_trapezoid_ns_lc
Line
Count
Source
137
34.1M
{
138
34.1M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
34.1M
    const fixed ymax = fixed_pixround(ytop);
140
141
34.1M
    if (ymin >= ymax)
142
11.6M
        return 0;    /* no scan lines to sample */
143
22.5M
    {
144
22.5M
        int iy = fixed2int_var(ymin);
145
22.5M
        const int iy1 = fixed2int_var(ymax);
146
22.5M
        trap_line l, r;
147
22.5M
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
22.5M
        const fixed
152
22.5M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
22.5M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
22.5M
        const fixed /* partial pixel offset to first line to sample */
155
22.5M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
22.5M
        fixed fxl;
157
22.5M
        int code;
158
# if CONTIGUOUS_FILL
159
            const bool peak0 = ((flags & 1) != 0);
160
            const bool peak1 = ((flags & 2) != 0);
161
            int peak_y0 = ybot + fixed_half;
162
            int peak_y1 = ytop - fixed_half;
163
# endif
164
22.5M
# if LINEAR_COLOR
165
22.5M
            int num_components = dev->color_info.num_components;
166
22.5M
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
22.5M
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
22.5M
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
22.5M
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
22.5M
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
22.5M
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
22.5M
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
22.5M
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
22.5M
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
22.5M
            trap_gradient lg, rg, xg;
176
# else
177
            gx_color_index cindex = pdevc->colors.pure;
178
            dev_proc_fill_rectangle((*fill_rect)) =
179
                dev_proc(dev, fill_rectangle);
180
# endif
181
182
22.5M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
22.5M
        l.h = left->end.y - left->start.y;
185
22.5M
        if (l.h == 0)
186
0
           return 0;
187
22.5M
        r.h = right->end.y - right->start.y;
188
22.5M
        if (r.h == 0)
189
0
           return 0;
190
22.5M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
22.5M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
#if !LINEAR_COLOR
193
        ry = iy;
194
#endif
195
196
/*
197
 * Free variables of FILL_TRAP_RECT:
198
 *  SWAP_AXES, pdevc, dev, fa
199
 * Free variables of FILL_TRAP_RECT_DIRECT:
200
 *  SWAP_AXES, fill_rect, dev, cindex
201
 */
202
22.5M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
22.5M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
22.5M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
22.5M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
22.5M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
22.5M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
22.5M
#if LINEAR_COLOR
210
22.5M
#   define FILL_TRAP_RECT(x,y,w,h)\
211
22.5M
        (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den))
212
#else
213
#   define FILL_TRAP_RECT(x,y,w,h)\
214
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
#endif
216
217
        /* Compute the dx/dy ratios. */
218
219
        /*
220
         * Compute the x offsets at the first scan line to sample.  We need
221
         * to be careful in computing ys# * dx#f {/,%} h# because the
222
         * multiplication may overflow.  We know that all the quantities
223
         * involved are non-negative, and that ys# is usually less than 1 (as
224
         * a fixed, of course); this gives us a cheap conservative check for
225
         * overflow in the multiplication.
226
         */
227
22.5M
#define YMULT_QUO(ys, tl)\
228
22.5M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
22.5M
   fixed_mult_quo(ys, tl.df, tl.h))
230
231
#if CONTIGUOUS_FILL
232
/*
233
 * If left and right boundary round to same pixel index,
234
 * we would not paing the scan and would get a dropout.
235
 * Check for this case and choose one of two pixels
236
 * which is closer to the "axis". We need to exclude
237
 * 'peak' because it would paint an excessive pixel.
238
 */
239
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \
240
    if (ixl == ixr) \
241
        if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\
242
            fixed x = int2fixed(ixl) + fixed_half;\
243
            if (x - l.x < r.x - x)\
244
                ++ixr;\
245
            else\
246
                --ixl;\
247
        }
248
249
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\
250
    if (adj1 < adj2) {\
251
        if (iy - ry > 1) {\
252
            code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\
253
            if (code < 0)\
254
                goto xit;\
255
            ry = iy - 1;\
256
        }\
257
        adj1 = adj2 = (adj2 + adj2) / 2;\
258
    }
259
260
#else
261
22.5M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
22.5M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
22.5M
#endif
264
22.5M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
4.20M
            l.di = 0, l.df = 0;
267
4.20M
            fxl = 0;
268
18.3M
        } else {
269
18.3M
            compute_dx(&l, dxl, ysl);
270
18.3M
            fxl = YMULT_QUO(ysl, l);
271
18.3M
            l.x += fxl;
272
18.3M
        }
273
22.5M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
#     if !LINEAR_COLOR
277
                if (l.di == 0 && l.df == 0) {
278
                    rxl = fixed2int_var(l.x);
279
                    rxr = fixed2int_var(r.x);
280
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
                    goto xit;
283
                }
284
#     endif
285
4.19M
            r.di = 0, r.df = 0;
286
4.19M
        }
287
        /*
288
         * The test for fxl != 0 is required because the right edge might
289
         * cross some pixel centers even if the left edge doesn't.
290
         */
291
18.3M
        else if (dxr == dxl && fxl != 0) {
292
1.63M
            if (l.di == 0)
293
469k
                r.di = 0, r.df = l.df;
294
1.16M
            else
295
1.16M
                compute_dx(&r, dxr, ysr);
296
1.63M
            if (ysr == ysl && r.h == l.h)
297
810k
                r.x += fxl;
298
824k
            else
299
824k
                r.x += YMULT_QUO(ysr, r);
300
16.7M
        } else {
301
16.7M
            compute_dx(&r, dxr, ysr);
302
16.7M
            r.x += YMULT_QUO(ysr, r);
303
16.7M
        }
304
        /* Compute one line's worth of dx/dy. */
305
22.5M
        compute_ldx(&l, ysl);
306
22.5M
        compute_ldx(&r, ysr);
307
        /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding
308
           when the rational part is zero. Now add it back to get xl', xr' */
309
22.5M
        l.x += fixed_epsilon;
310
22.5M
        r.x += fixed_epsilon;
311
22.5M
# if LINEAR_COLOR
312
#     ifdef DEBUG
313
                if (check_gradient_overflow(left, right)) {
314
                    /* The caller must care of.
315
                       Checking it here looses some performance with triangles. */
316
                    return_error(gs_error_unregistered);
317
                }
318
#     endif
319
22.5M
            lg.c = lgc;
320
22.5M
            lg.f = lgf;
321
22.5M
            lg.num = lgnum;
322
22.5M
            rg.c = rgc;
323
22.5M
            rg.f = rgf;
324
22.5M
            rg.num = rgnum;
325
22.5M
            xg.c = xgc;
326
22.5M
            xg.f = xgf;
327
22.5M
            xg.num = xgnum;
328
22.5M
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
22.5M
            if (code < 0)
330
0
                return code;
331
22.5M
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
22.5M
            if (code < 0)
333
0
                return code;
334
335
22.5M
# endif
336
337
22.5M
#define rational_floor(tl)\
338
22.5M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
22.5M
#define STEP_LINE(ix, tl)\
340
22.5M
  tl.x += tl.ldi;\
341
22.5M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
22.5M
  ix = rational_floor(tl)
343
344
22.5M
        rxl = rational_floor(l);
345
22.5M
        rxr = rational_floor(r);
346
22.5M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
505M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
505M
#     if LINEAR_COLOR
349
505M
                if (rxl != rxr) {
350
40.7M
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
40.7M
                    if (code < 0)
352
0
                        goto xit;
353
40.7M
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
40.7M
                    if (code < 0)
355
13
                        goto xit;
356
40.7M
                }
357
505M
                if (++iy == iy1)
358
22.5M
                    break;
359
483M
                STEP_LINE(rxl, l);
360
483M
                STEP_LINE(rxr, r);
361
483M
                step_gradient(&lg, num_components);
362
483M
                step_gradient(&rg, num_components);
363
#     else
364
                register int ixl, ixr;
365
366
                STEP_LINE(ixl, l);
367
                STEP_LINE(ixr, r);
368
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
                if (ixl != rxl || ixr != rxr) {
370
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
                    if (code < 0)
374
                        goto xit;
375
                    rxl = ixl, rxr = ixr, ry = iy;
376
                }
377
#     endif
378
483M
        }
379
# if !LINEAR_COLOR
380
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
22.5M
            code = 0;
383
22.5M
# endif
384
22.5M
#undef STEP_LINE
385
22.5M
#undef SET_MINIMAL_WIDTH
386
22.5M
#undef CONNECT_RECTANGLES
387
22.5M
#undef FILL_TRAP_RECT
388
22.5M
#undef FILL_TRAP_RECT_DIRECT
389
22.5M
#undef FILL_TRAP_RECT_INRECT
390
22.5M
#undef YMULT_QUO
391
22.5M
xit:  if (code < 0 && FILL_DIRECT)
392
13
            return_error(code);
393
22.5M
        return_if_interrupt(dev->memory);
394
22.5M
        return code;
395
22.5M
    }
396
22.5M
}
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