Coverage Report

Created: 2025-06-10 07:19

/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
22.3M
{
138
22.3M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
22.3M
    const fixed ymax = fixed_pixround(ytop);
140
141
22.3M
    if (ymin >= ymax)
142
5.18M
        return 0;    /* no scan lines to sample */
143
17.1M
    {
144
17.1M
        int iy = fixed2int_var(ymin);
145
17.1M
        const int iy1 = fixed2int_var(ymax);
146
17.1M
        trap_line l, r;
147
17.1M
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
17.1M
        const fixed
152
17.1M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
17.1M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
17.1M
        const fixed /* partial pixel offset to first line to sample */
155
17.1M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
17.1M
        fixed fxl;
157
17.1M
        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
16.4M
            dev_proc_fill_rectangle((*fill_rect)) =
179
16.4M
                dev_proc(dev, fill_rectangle);
180
# endif
181
182
17.1M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
17.1M
        l.h = left->end.y - left->start.y;
185
17.1M
        if (l.h == 0)
186
0
           return 0;
187
17.1M
        r.h = right->end.y - right->start.y;
188
17.1M
        if (r.h == 0)
189
0
           return 0;
190
17.1M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
17.1M
        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
17.1M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
497M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
497M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
17.1M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
17.2M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
17.2M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
#if LINEAR_COLOR
210
#   define FILL_TRAP_RECT(x,y,w,h)\
211
4.31M
        (!(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
514M
        (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
17.1M
#define YMULT_QUO(ys, tl)\
228
25.1M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
25.1M
   fixed_mult_quo(ys, tl.df, tl.h))
230
231
#if CONTIGUOUS_FILL
232
/*
233
 * If left and right boundary round to same pixel index,
234
 * we would not paing the scan and would get a dropout.
235
 * Check for this case and choose one of two pixels
236
 * which is closer to the "axis". We need to exclude
237
 * 'peak' because it would paint an excessive pixel.
238
 */
239
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \
240
0
    if (ixl == ixr) \
241
0
        if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\
242
0
            fixed x = int2fixed(ixl) + fixed_half;\
243
0
            if (x - l.x < r.x - x)\
244
0
                ++ixr;\
245
0
            else\
246
0
                --ixl;\
247
0
        }
248
249
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\
250
0
    if (adj1 < adj2) {\
251
0
        if (iy - ry > 1) {\
252
0
            code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\
253
0
            if (code < 0)\
254
0
                goto xit;\
255
0
            ry = iy - 1;\
256
0
        }\
257
0
        adj1 = adj2 = (adj2 + adj2) / 2;\
258
0
    }
259
260
#else
261
616M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
996M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
#endif
264
17.1M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
4.05M
            l.di = 0, l.df = 0;
267
4.05M
            fxl = 0;
268
13.1M
        } else {
269
13.1M
            compute_dx(&l, dxl, ysl);
270
13.1M
            fxl = YMULT_QUO(ysl, l);
271
13.1M
            l.x += fxl;
272
13.1M
        }
273
17.1M
        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
4.17M
                if (l.di == 0 && l.df == 0) {
278
2.63M
                    rxl = fixed2int_var(l.x);
279
2.63M
                    rxr = fixed2int_var(r.x);
280
2.63M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
2.63M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
2.63M
                    goto xit;
283
2.63M
                }
284
1.54M
#     endif
285
1.54M
            r.di = 0, r.df = 0;
286
1.54M
        }
287
        /*
288
         * The test for fxl != 0 is required because the right edge might
289
         * cross some pixel centers even if the left edge doesn't.
290
         */
291
12.8M
        else if (dxr == dxl && fxl != 0) {
292
1.09M
            if (l.di == 0)
293
288k
                r.di = 0, r.df = l.df;
294
805k
            else
295
805k
                compute_dx(&r, dxr, ysr);
296
1.09M
            if (ysr == ysl && r.h == l.h)
297
784k
                r.x += fxl;
298
308k
            else
299
308k
                r.x += YMULT_QUO(ysr, r);
300
11.7M
        } else {
301
11.7M
            compute_dx(&r, dxr, ysr);
302
11.7M
            r.x += YMULT_QUO(ysr, r);
303
11.7M
        }
304
        /* Compute one line's worth of dx/dy. */
305
13.7M
        compute_ldx(&l, ysl);
306
13.7M
        compute_ldx(&r, ysr);
307
        /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding
308
           when the rational part is zero. Now add it back to get xl', xr' */
309
14.5M
        l.x += fixed_epsilon;
310
14.5M
        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
782k
            if (code < 0)
330
0
                return code;
331
782k
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
782k
            if (code < 0)
333
0
                return code;
334
335
782k
# endif
336
337
782k
#define rational_floor(tl)\
338
1.24G
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
782k
#define STEP_LINE(ix, tl)\
340
1.21G
  tl.x += tl.ldi;\
341
1.21G
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
1.21G
  ix = rational_floor(tl)
343
344
14.5M
        rxl = rational_floor(l);
345
14.5M
        rxr = rational_floor(r);
346
14.5M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
621M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
#     if LINEAR_COLOR
349
7.74M
                if (rxl != rxr) {
350
4.31M
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
4.31M
                    if (code < 0)
352
0
                        goto xit;
353
4.31M
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
4.31M
                    if (code < 0)
355
0
                        goto xit;
356
4.31M
                }
357
7.74M
                if (++iy == iy1)
358
782k
                    break;
359
6.96M
                STEP_LINE(rxl, l);
360
6.96M
                STEP_LINE(rxr, r);
361
6.96M
                step_gradient(&lg, num_components);
362
6.96M
                step_gradient(&rg, num_components);
363
#     else
364
                register int ixl, ixr;
365
366
599M
                STEP_LINE(ixl, l);
367
599M
                STEP_LINE(ixr, r);
368
599M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
599M
                if (ixl != rxl || ixr != rxr) {
370
498M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
498M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
498M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
498M
                    if (code < 0)
374
0
                        goto xit;
375
498M
                    rxl = ixl, rxr = ixr, ry = iy;
376
498M
                }
377
#     endif
378
6.96M
        }
379
# if !LINEAR_COLOR
380
13.7M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
782k
            code = 0;
383
782k
# endif
384
782k
#undef STEP_LINE
385
782k
#undef SET_MINIMAL_WIDTH
386
782k
#undef CONNECT_RECTANGLES
387
782k
#undef FILL_TRAP_RECT
388
782k
#undef FILL_TRAP_RECT_DIRECT
389
782k
#undef FILL_TRAP_RECT_INRECT
390
782k
#undef YMULT_QUO
391
17.1M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
17.1M
        return_if_interrupt(dev->memory);
394
17.1M
        return code;
395
17.1M
    }
396
17.1M
}
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
180k
{
138
180k
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
180k
    const fixed ymax = fixed_pixround(ytop);
140
141
180k
    if (ymin >= ymax)
142
5.15k
        return 0;    /* no scan lines to sample */
143
174k
    {
144
174k
        int iy = fixed2int_var(ymin);
145
174k
        const int iy1 = fixed2int_var(ymax);
146
174k
        trap_line l, r;
147
174k
        register int rxl, rxr;
148
174k
#if !LINEAR_COLOR
149
174k
        int ry;
150
174k
#endif
151
174k
        const fixed
152
174k
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
174k
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
174k
        const fixed /* partial pixel offset to first line to sample */
155
174k
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
174k
        fixed fxl;
157
174k
        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
174k
            gx_color_index cindex = pdevc->colors.pure;
178
174k
            dev_proc_fill_rectangle((*fill_rect)) =
179
174k
                dev_proc(dev, fill_rectangle);
180
174k
# endif
181
182
174k
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
174k
        l.h = left->end.y - left->start.y;
185
174k
        if (l.h == 0)
186
0
           return 0;
187
174k
        r.h = right->end.y - right->start.y;
188
174k
        if (r.h == 0)
189
0
           return 0;
190
174k
        l.x = x0l + (fixed_half - fixed_epsilon);
191
174k
        r.x = x0r + (fixed_half - fixed_epsilon);
192
174k
#if !LINEAR_COLOR
193
174k
        ry = iy;
194
174k
#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
174k
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
174k
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
174k
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
174k
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
174k
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
174k
   (*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
174k
#   define FILL_TRAP_RECT(x,y,w,h)\
214
174k
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
174k
#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
174k
#define YMULT_QUO(ys, tl)\
228
174k
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
174k
   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
174k
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
174k
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
174k
#endif
264
174k
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
13.4k
            l.di = 0, l.df = 0;
267
13.4k
            fxl = 0;
268
161k
        } else {
269
161k
            compute_dx(&l, dxl, ysl);
270
161k
            fxl = YMULT_QUO(ysl, l);
271
161k
            l.x += fxl;
272
161k
        }
273
174k
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
13.1k
#     if !LINEAR_COLOR
277
13.1k
                if (l.di == 0 && l.df == 0) {
278
12.1k
                    rxl = fixed2int_var(l.x);
279
12.1k
                    rxr = fixed2int_var(r.x);
280
12.1k
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
12.1k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
12.1k
                    goto xit;
283
12.1k
                }
284
958
#     endif
285
958
            r.di = 0, r.df = 0;
286
958
        }
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
161k
        else if (dxr == dxl && fxl != 0) {
292
131k
            if (l.di == 0)
293
69.5k
                r.di = 0, r.df = l.df;
294
62.4k
            else
295
62.4k
                compute_dx(&r, dxr, ysr);
296
131k
            if (ysr == ysl && r.h == l.h)
297
131k
                r.x += fxl;
298
5
            else
299
5
                r.x += YMULT_QUO(ysr, r);
300
131k
        } else {
301
29.8k
            compute_dx(&r, dxr, ysr);
302
29.8k
            r.x += YMULT_QUO(ysr, r);
303
29.8k
        }
304
        /* Compute one line's worth of dx/dy. */
305
162k
        compute_ldx(&l, ysl);
306
162k
        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
162k
        l.x += fixed_epsilon;
310
162k
        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
162k
#define rational_floor(tl)\
338
162k
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
162k
#define STEP_LINE(ix, tl)\
340
162k
  tl.x += tl.ldi;\
341
162k
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
162k
  ix = rational_floor(tl)
343
344
162k
        rxl = rational_floor(l);
345
162k
        rxr = rational_floor(r);
346
162k
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
6.37M
        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
6.21M
                register int ixl, ixr;
365
366
6.21M
                STEP_LINE(ixl, l);
367
6.21M
                STEP_LINE(ixr, r);
368
6.21M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
6.21M
                if (ixl != rxl || ixr != rxr) {
370
2.72M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
2.72M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
2.72M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
2.72M
                    if (code < 0)
374
0
                        goto xit;
375
2.72M
                    rxl = ixl, rxr = ixr, ry = iy;
376
2.72M
                }
377
6.21M
#     endif
378
6.21M
        }
379
162k
# if !LINEAR_COLOR
380
162k
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
162k
#undef STEP_LINE
385
162k
#undef SET_MINIMAL_WIDTH
386
162k
#undef CONNECT_RECTANGLES
387
162k
#undef FILL_TRAP_RECT
388
162k
#undef FILL_TRAP_RECT_DIRECT
389
162k
#undef FILL_TRAP_RECT_INRECT
390
162k
#undef YMULT_QUO
391
174k
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
174k
        return_if_interrupt(dev->memory);
394
174k
        return code;
395
174k
    }
396
174k
}
gdevddrw.c:gx_fill_trapezoid_as_nd
Line
Count
Source
137
1.01M
{
138
1.01M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
1.01M
    const fixed ymax = fixed_pixround(ytop);
140
141
1.01M
    if (ymin >= ymax)
142
19.8k
        return 0;    /* no scan lines to sample */
143
995k
    {
144
995k
        int iy = fixed2int_var(ymin);
145
995k
        const int iy1 = fixed2int_var(ymax);
146
995k
        trap_line l, r;
147
995k
        register int rxl, rxr;
148
995k
#if !LINEAR_COLOR
149
995k
        int ry;
150
995k
#endif
151
995k
        const fixed
152
995k
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
995k
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
995k
        const fixed /* partial pixel offset to first line to sample */
155
995k
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
995k
        fixed fxl;
157
995k
        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
995k
            gx_color_index cindex = pdevc->colors.pure;
178
995k
            dev_proc_fill_rectangle((*fill_rect)) =
179
995k
                dev_proc(dev, fill_rectangle);
180
995k
# endif
181
182
995k
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
995k
        l.h = left->end.y - left->start.y;
185
995k
        if (l.h == 0)
186
0
           return 0;
187
995k
        r.h = right->end.y - right->start.y;
188
995k
        if (r.h == 0)
189
0
           return 0;
190
995k
        l.x = x0l + (fixed_half - fixed_epsilon);
191
995k
        r.x = x0r + (fixed_half - fixed_epsilon);
192
995k
#if !LINEAR_COLOR
193
995k
        ry = iy;
194
995k
#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
995k
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
995k
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
995k
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
995k
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
995k
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
995k
   (*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
995k
#   define FILL_TRAP_RECT(x,y,w,h)\
214
995k
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
995k
#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
995k
#define YMULT_QUO(ys, tl)\
228
995k
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
995k
   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
995k
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
995k
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
995k
#endif
264
995k
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
275k
            l.di = 0, l.df = 0;
267
275k
            fxl = 0;
268
719k
        } else {
269
719k
            compute_dx(&l, dxl, ysl);
270
719k
            fxl = YMULT_QUO(ysl, l);
271
719k
            l.x += fxl;
272
719k
        }
273
995k
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
209k
#     if !LINEAR_COLOR
277
209k
                if (l.di == 0 && l.df == 0) {
278
199k
                    rxl = fixed2int_var(l.x);
279
199k
                    rxr = fixed2int_var(r.x);
280
199k
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
199k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
199k
                    goto xit;
283
199k
                }
284
9.75k
#     endif
285
9.75k
            r.di = 0, r.df = 0;
286
9.75k
        }
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
785k
        else if (dxr == dxl && fxl != 0) {
292
91.3k
            if (l.di == 0)
293
40.7k
                r.di = 0, r.df = l.df;
294
50.5k
            else
295
50.5k
                compute_dx(&r, dxr, ysr);
296
91.3k
            if (ysr == ysl && r.h == l.h)
297
91.3k
                r.x += fxl;
298
24
            else
299
24
                r.x += YMULT_QUO(ysr, r);
300
694k
        } else {
301
694k
            compute_dx(&r, dxr, ysr);
302
694k
            r.x += YMULT_QUO(ysr, r);
303
694k
        }
304
        /* Compute one line's worth of dx/dy. */
305
795k
        compute_ldx(&l, ysl);
306
795k
        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
795k
        l.x += fixed_epsilon;
310
795k
        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
795k
#define rational_floor(tl)\
338
795k
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
795k
#define STEP_LINE(ix, tl)\
340
795k
  tl.x += tl.ldi;\
341
795k
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
795k
  ix = rational_floor(tl)
343
344
795k
        rxl = rational_floor(l);
345
795k
        rxr = rational_floor(r);
346
795k
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
100M
        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
99.7M
                register int ixl, ixr;
365
366
99.7M
                STEP_LINE(ixl, l);
367
99.7M
                STEP_LINE(ixr, r);
368
99.7M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
99.7M
                if (ixl != rxl || ixr != rxr) {
370
77.2M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
77.2M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
77.2M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
77.2M
                    if (code < 0)
374
0
                        goto xit;
375
77.2M
                    rxl = ixl, rxr = ixr, ry = iy;
376
77.2M
                }
377
99.7M
#     endif
378
99.7M
        }
379
795k
# if !LINEAR_COLOR
380
795k
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
795k
#undef STEP_LINE
385
795k
#undef SET_MINIMAL_WIDTH
386
795k
#undef CONNECT_RECTANGLES
387
795k
#undef FILL_TRAP_RECT
388
795k
#undef FILL_TRAP_RECT_DIRECT
389
795k
#undef FILL_TRAP_RECT_INRECT
390
795k
#undef YMULT_QUO
391
995k
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
995k
        return_if_interrupt(dev->memory);
394
995k
        return code;
395
995k
    }
396
995k
}
gdevddrw.c:gx_fill_trapezoid_ns_fd
Line
Count
Source
137
1.97M
{
138
1.97M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
1.97M
    const fixed ymax = fixed_pixround(ytop);
140
141
1.97M
    if (ymin >= ymax)
142
153k
        return 0;    /* no scan lines to sample */
143
1.82M
    {
144
1.82M
        int iy = fixed2int_var(ymin);
145
1.82M
        const int iy1 = fixed2int_var(ymax);
146
1.82M
        trap_line l, r;
147
1.82M
        register int rxl, rxr;
148
1.82M
#if !LINEAR_COLOR
149
1.82M
        int ry;
150
1.82M
#endif
151
1.82M
        const fixed
152
1.82M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
1.82M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
1.82M
        const fixed /* partial pixel offset to first line to sample */
155
1.82M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
1.82M
        fixed fxl;
157
1.82M
        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.82M
            gx_color_index cindex = pdevc->colors.pure;
178
1.82M
            dev_proc_fill_rectangle((*fill_rect)) =
179
1.82M
                dev_proc(dev, fill_rectangle);
180
1.82M
# endif
181
182
1.82M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
1.82M
        l.h = left->end.y - left->start.y;
185
1.82M
        if (l.h == 0)
186
0
           return 0;
187
1.82M
        r.h = right->end.y - right->start.y;
188
1.82M
        if (r.h == 0)
189
0
           return 0;
190
1.82M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
1.82M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
1.82M
#if !LINEAR_COLOR
193
1.82M
        ry = iy;
194
1.82M
#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.82M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
1.82M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
1.82M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
1.82M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
1.82M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
1.82M
   (*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.82M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
1.82M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
1.82M
#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.82M
#define YMULT_QUO(ys, tl)\
228
1.82M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
1.82M
   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.82M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
1.82M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
1.82M
#endif
264
1.82M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
689k
            l.di = 0, l.df = 0;
267
689k
            fxl = 0;
268
1.13M
        } else {
269
1.13M
            compute_dx(&l, dxl, ysl);
270
1.13M
            fxl = YMULT_QUO(ysl, l);
271
1.13M
            l.x += fxl;
272
1.13M
        }
273
1.82M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
706k
#     if !LINEAR_COLOR
277
706k
                if (l.di == 0 && l.df == 0) {
278
605k
                    rxl = fixed2int_var(l.x);
279
605k
                    rxr = fixed2int_var(r.x);
280
605k
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
605k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
605k
                    goto xit;
283
605k
                }
284
100k
#     endif
285
100k
            r.di = 0, r.df = 0;
286
100k
        }
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.11M
        else if (dxr == dxl && fxl != 0) {
292
197k
            if (l.di == 0)
293
39.8k
                r.di = 0, r.df = l.df;
294
157k
            else
295
157k
                compute_dx(&r, dxr, ysr);
296
197k
            if (ysr == ysl && r.h == l.h)
297
126k
                r.x += fxl;
298
71.5k
            else
299
71.5k
                r.x += YMULT_QUO(ysr, r);
300
922k
        } else {
301
922k
            compute_dx(&r, dxr, ysr);
302
922k
            r.x += YMULT_QUO(ysr, r);
303
922k
        }
304
        /* Compute one line's worth of dx/dy. */
305
1.22M
        compute_ldx(&l, ysl);
306
1.22M
        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.22M
        l.x += fixed_epsilon;
310
1.22M
        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.22M
#define rational_floor(tl)\
338
1.22M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
1.22M
#define STEP_LINE(ix, tl)\
340
1.22M
  tl.x += tl.ldi;\
341
1.22M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
1.22M
  ix = rational_floor(tl)
343
344
1.22M
        rxl = rational_floor(l);
345
1.22M
        rxr = rational_floor(r);
346
1.22M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
16.7M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
#     if LINEAR_COLOR
349
                if (rxl != rxr) {
350
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
                    if (code < 0)
352
                        goto xit;
353
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
                    if (code < 0)
355
                        goto xit;
356
                }
357
                if (++iy == iy1)
358
                    break;
359
                STEP_LINE(rxl, l);
360
                STEP_LINE(rxr, r);
361
                step_gradient(&lg, num_components);
362
                step_gradient(&rg, num_components);
363
#     else
364
15.5M
                register int ixl, ixr;
365
366
15.5M
                STEP_LINE(ixl, l);
367
15.5M
                STEP_LINE(ixr, r);
368
15.5M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
15.5M
                if (ixl != rxl || ixr != rxr) {
370
12.5M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
12.5M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
12.5M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
12.5M
                    if (code < 0)
374
0
                        goto xit;
375
12.5M
                    rxl = ixl, rxr = ixr, ry = iy;
376
12.5M
                }
377
15.5M
#     endif
378
15.5M
        }
379
1.22M
# if !LINEAR_COLOR
380
1.22M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
1.22M
#undef STEP_LINE
385
1.22M
#undef SET_MINIMAL_WIDTH
386
1.22M
#undef CONNECT_RECTANGLES
387
1.22M
#undef FILL_TRAP_RECT
388
1.22M
#undef FILL_TRAP_RECT_DIRECT
389
1.22M
#undef FILL_TRAP_RECT_INRECT
390
1.22M
#undef YMULT_QUO
391
1.82M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
1.82M
        return_if_interrupt(dev->memory);
394
1.82M
        return code;
395
1.82M
    }
396
1.82M
}
gdevddrw.c:gx_fill_trapezoid_ns_nd
Line
Count
Source
137
17.9M
{
138
17.9M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
17.9M
    const fixed ymax = fixed_pixround(ytop);
140
141
17.9M
    if (ymin >= ymax)
142
4.58M
        return 0;    /* no scan lines to sample */
143
13.4M
    {
144
13.4M
        int iy = fixed2int_var(ymin);
145
13.4M
        const int iy1 = fixed2int_var(ymax);
146
13.4M
        trap_line l, r;
147
13.4M
        register int rxl, rxr;
148
13.4M
#if !LINEAR_COLOR
149
13.4M
        int ry;
150
13.4M
#endif
151
13.4M
        const fixed
152
13.4M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
13.4M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
13.4M
        const fixed /* partial pixel offset to first line to sample */
155
13.4M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
13.4M
        fixed fxl;
157
13.4M
        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
13.4M
            gx_color_index cindex = pdevc->colors.pure;
178
13.4M
            dev_proc_fill_rectangle((*fill_rect)) =
179
13.4M
                dev_proc(dev, fill_rectangle);
180
13.4M
# endif
181
182
13.4M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
13.4M
        l.h = left->end.y - left->start.y;
185
13.4M
        if (l.h == 0)
186
0
           return 0;
187
13.4M
        r.h = right->end.y - right->start.y;
188
13.4M
        if (r.h == 0)
189
0
           return 0;
190
13.4M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
13.4M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
13.4M
#if !LINEAR_COLOR
193
13.4M
        ry = iy;
194
13.4M
#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
13.4M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
13.4M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
13.4M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
13.4M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
13.4M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
13.4M
   (*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
13.4M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
13.4M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
13.4M
#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
13.4M
#define YMULT_QUO(ys, tl)\
228
13.4M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
13.4M
   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
13.4M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
13.4M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
13.4M
#endif
264
13.4M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
2.86M
            l.di = 0, l.df = 0;
267
2.86M
            fxl = 0;
268
10.5M
        } else {
269
10.5M
            compute_dx(&l, dxl, ysl);
270
10.5M
            fxl = YMULT_QUO(ysl, l);
271
10.5M
            l.x += fxl;
272
10.5M
        }
273
13.4M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
3.25M
#     if !LINEAR_COLOR
277
3.25M
                if (l.di == 0 && l.df == 0) {
278
1.82M
                    rxl = fixed2int_var(l.x);
279
1.82M
                    rxr = fixed2int_var(r.x);
280
1.82M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
1.82M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
1.82M
                    goto xit;
283
1.82M
                }
284
1.43M
#     endif
285
1.43M
            r.di = 0, r.df = 0;
286
1.43M
        }
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
10.1M
        else if (dxr == dxl && fxl != 0) {
292
615k
            if (l.di == 0)
293
116k
                r.di = 0, r.df = l.df;
294
499k
            else
295
499k
                compute_dx(&r, dxr, ysr);
296
615k
            if (ysr == ysl && r.h == l.h)
297
392k
                r.x += fxl;
298
222k
            else
299
222k
                r.x += YMULT_QUO(ysr, r);
300
9.54M
        } else {
301
9.54M
            compute_dx(&r, dxr, ysr);
302
9.54M
            r.x += YMULT_QUO(ysr, r);
303
9.54M
        }
304
        /* Compute one line's worth of dx/dy. */
305
11.5M
        compute_ldx(&l, ysl);
306
11.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
11.5M
        l.x += fixed_epsilon;
310
11.5M
        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
11.5M
#define rational_floor(tl)\
338
11.5M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
11.5M
#define STEP_LINE(ix, tl)\
340
11.5M
  tl.x += tl.ldi;\
341
11.5M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
11.5M
  ix = rational_floor(tl)
343
344
11.5M
        rxl = rational_floor(l);
345
11.5M
        rxr = rational_floor(r);
346
11.5M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
489M
        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
478M
                register int ixl, ixr;
365
366
478M
                STEP_LINE(ixl, l);
367
478M
                STEP_LINE(ixr, r);
368
478M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
478M
                if (ixl != rxl || ixr != rxr) {
370
405M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
405M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
405M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
405M
                    if (code < 0)
374
0
                        goto xit;
375
405M
                    rxl = ixl, rxr = ixr, ry = iy;
376
405M
                }
377
478M
#     endif
378
478M
        }
379
11.5M
# if !LINEAR_COLOR
380
11.5M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
11.5M
#undef STEP_LINE
385
11.5M
#undef SET_MINIMAL_WIDTH
386
11.5M
#undef CONNECT_RECTANGLES
387
11.5M
#undef FILL_TRAP_RECT
388
11.5M
#undef FILL_TRAP_RECT_DIRECT
389
11.5M
#undef FILL_TRAP_RECT_INRECT
390
11.5M
#undef YMULT_QUO
391
13.4M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
13.4M
        return_if_interrupt(dev->memory);
394
13.4M
        return code;
395
13.4M
    }
396
13.4M
}
gdevddrw.c:gx_fill_trapezoid_as_lc
Line
Count
Source
137
61.6k
{
138
61.6k
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
61.6k
    const fixed ymax = fixed_pixround(ytop);
140
141
61.6k
    if (ymin >= ymax)
142
1.20k
        return 0;    /* no scan lines to sample */
143
60.4k
    {
144
60.4k
        int iy = fixed2int_var(ymin);
145
60.4k
        const int iy1 = fixed2int_var(ymax);
146
60.4k
        trap_line l, r;
147
60.4k
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
60.4k
        const fixed
152
60.4k
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
60.4k
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
60.4k
        const fixed /* partial pixel offset to first line to sample */
155
60.4k
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
60.4k
        fixed fxl;
157
60.4k
        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
60.4k
# if LINEAR_COLOR
165
60.4k
            int num_components = dev->color_info.num_components;
166
60.4k
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
60.4k
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
60.4k
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
60.4k
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
60.4k
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
60.4k
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
60.4k
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
60.4k
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
60.4k
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
60.4k
            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
60.4k
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
60.4k
        l.h = left->end.y - left->start.y;
185
60.4k
        if (l.h == 0)
186
0
           return 0;
187
60.4k
        r.h = right->end.y - right->start.y;
188
60.4k
        if (r.h == 0)
189
0
           return 0;
190
60.4k
        l.x = x0l + (fixed_half - fixed_epsilon);
191
60.4k
        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
60.4k
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
60.4k
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
60.4k
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
60.4k
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
60.4k
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
60.4k
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
60.4k
#if LINEAR_COLOR
210
60.4k
#   define FILL_TRAP_RECT(x,y,w,h)\
211
60.4k
        (!(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
60.4k
#define YMULT_QUO(ys, tl)\
228
60.4k
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
60.4k
   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
60.4k
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
60.4k
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
60.4k
#endif
264
60.4k
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
33.8k
            l.di = 0, l.df = 0;
267
33.8k
            fxl = 0;
268
33.8k
        } else {
269
26.5k
            compute_dx(&l, dxl, ysl);
270
26.5k
            fxl = YMULT_QUO(ysl, l);
271
26.5k
            l.x += fxl;
272
26.5k
        }
273
60.4k
        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
33.3k
            r.di = 0, r.df = 0;
286
33.3k
        }
287
        /*
288
         * The test for fxl != 0 is required because the right edge might
289
         * cross some pixel centers even if the left edge doesn't.
290
         */
291
27.1k
        else if (dxr == dxl && fxl != 0) {
292
15.6k
            if (l.di == 0)
293
7.61k
                r.di = 0, r.df = l.df;
294
8.00k
            else
295
8.00k
                compute_dx(&r, dxr, ysr);
296
15.6k
            if (ysr == ysl && r.h == l.h)
297
15.6k
                r.x += fxl;
298
0
            else
299
0
                r.x += YMULT_QUO(ysr, r);
300
15.6k
        } else {
301
11.5k
            compute_dx(&r, dxr, ysr);
302
11.5k
            r.x += YMULT_QUO(ysr, r);
303
11.5k
        }
304
        /* Compute one line's worth of dx/dy. */
305
60.4k
        compute_ldx(&l, ysl);
306
60.4k
        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
60.4k
        l.x += fixed_epsilon;
310
60.4k
        r.x += fixed_epsilon;
311
60.4k
# 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
60.4k
            lg.c = lgc;
320
60.4k
            lg.f = lgf;
321
60.4k
            lg.num = lgnum;
322
60.4k
            rg.c = rgc;
323
60.4k
            rg.f = rgf;
324
60.4k
            rg.num = rgnum;
325
60.4k
            xg.c = xgc;
326
60.4k
            xg.f = xgf;
327
60.4k
            xg.num = xgnum;
328
60.4k
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
60.4k
            if (code < 0)
330
0
                return code;
331
60.4k
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
60.4k
            if (code < 0)
333
0
                return code;
334
335
60.4k
# endif
336
337
60.4k
#define rational_floor(tl)\
338
60.4k
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
60.4k
#define STEP_LINE(ix, tl)\
340
60.4k
  tl.x += tl.ldi;\
341
60.4k
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
60.4k
  ix = rational_floor(tl)
343
344
60.4k
        rxl = rational_floor(l);
345
60.4k
        rxr = rational_floor(r);
346
60.4k
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
1.58M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
1.58M
#     if LINEAR_COLOR
349
1.58M
                if (rxl != rxr) {
350
1.52M
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
1.52M
                    if (code < 0)
352
0
                        goto xit;
353
1.52M
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
1.52M
                    if (code < 0)
355
0
                        goto xit;
356
1.52M
                }
357
1.58M
                if (++iy == iy1)
358
60.4k
                    break;
359
1.52M
                STEP_LINE(rxl, l);
360
1.52M
                STEP_LINE(rxr, r);
361
1.52M
                step_gradient(&lg, num_components);
362
1.52M
                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.52M
        }
379
# if !LINEAR_COLOR
380
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
60.4k
            code = 0;
383
60.4k
# endif
384
60.4k
#undef STEP_LINE
385
60.4k
#undef SET_MINIMAL_WIDTH
386
60.4k
#undef CONNECT_RECTANGLES
387
60.4k
#undef FILL_TRAP_RECT
388
60.4k
#undef FILL_TRAP_RECT_DIRECT
389
60.4k
#undef FILL_TRAP_RECT_INRECT
390
60.4k
#undef YMULT_QUO
391
60.4k
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
60.4k
        return_if_interrupt(dev->memory);
394
60.4k
        return code;
395
60.4k
    }
396
60.4k
}
gdevddrw.c:gx_fill_trapezoid_ns_lc
Line
Count
Source
137
1.14M
{
138
1.14M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
1.14M
    const fixed ymax = fixed_pixround(ytop);
140
141
1.14M
    if (ymin >= ymax)
142
422k
        return 0;    /* no scan lines to sample */
143
721k
    {
144
721k
        int iy = fixed2int_var(ymin);
145
721k
        const int iy1 = fixed2int_var(ymax);
146
721k
        trap_line l, r;
147
721k
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
721k
        const fixed
152
721k
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
721k
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
721k
        const fixed /* partial pixel offset to first line to sample */
155
721k
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
721k
        fixed fxl;
157
721k
        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
721k
# if LINEAR_COLOR
165
721k
            int num_components = dev->color_info.num_components;
166
721k
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
721k
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
721k
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
721k
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
721k
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
721k
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
721k
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
721k
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
721k
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
721k
            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
721k
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
721k
        l.h = left->end.y - left->start.y;
185
721k
        if (l.h == 0)
186
0
           return 0;
187
721k
        r.h = right->end.y - right->start.y;
188
721k
        if (r.h == 0)
189
0
           return 0;
190
721k
        l.x = x0l + (fixed_half - fixed_epsilon);
191
721k
        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
721k
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
721k
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
721k
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
721k
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
721k
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
721k
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
721k
#if LINEAR_COLOR
210
721k
#   define FILL_TRAP_RECT(x,y,w,h)\
211
721k
        (!(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
721k
#define YMULT_QUO(ys, tl)\
228
721k
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
721k
   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
721k
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
721k
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
721k
#endif
264
721k
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
168k
            l.di = 0, l.df = 0;
267
168k
            fxl = 0;
268
553k
        } else {
269
553k
            compute_dx(&l, dxl, ysl);
270
553k
            fxl = YMULT_QUO(ysl, l);
271
553k
            l.x += fxl;
272
553k
        }
273
721k
        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
169k
            r.di = 0, r.df = 0;
286
169k
        }
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
552k
        else if (dxr == dxl && fxl != 0) {
292
41.6k
            if (l.di == 0)
293
14.0k
                r.di = 0, r.df = l.df;
294
27.6k
            else
295
27.6k
                compute_dx(&r, dxr, ysr);
296
41.6k
            if (ysr == ysl && r.h == l.h)
297
27.3k
                r.x += fxl;
298
14.3k
            else
299
14.3k
                r.x += YMULT_QUO(ysr, r);
300
510k
        } else {
301
510k
            compute_dx(&r, dxr, ysr);
302
510k
            r.x += YMULT_QUO(ysr, r);
303
510k
        }
304
        /* Compute one line's worth of dx/dy. */
305
721k
        compute_ldx(&l, ysl);
306
721k
        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
721k
        l.x += fixed_epsilon;
310
721k
        r.x += fixed_epsilon;
311
721k
# 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
721k
            lg.c = lgc;
320
721k
            lg.f = lgf;
321
721k
            lg.num = lgnum;
322
721k
            rg.c = rgc;
323
721k
            rg.f = rgf;
324
721k
            rg.num = rgnum;
325
721k
            xg.c = xgc;
326
721k
            xg.f = xgf;
327
721k
            xg.num = xgnum;
328
721k
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
721k
            if (code < 0)
330
0
                return code;
331
721k
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
721k
            if (code < 0)
333
0
                return code;
334
335
721k
# endif
336
337
721k
#define rational_floor(tl)\
338
721k
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
721k
#define STEP_LINE(ix, tl)\
340
721k
  tl.x += tl.ldi;\
341
721k
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
721k
  ix = rational_floor(tl)
343
344
721k
        rxl = rational_floor(l);
345
721k
        rxr = rational_floor(r);
346
721k
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
6.15M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
6.15M
#     if LINEAR_COLOR
349
6.15M
                if (rxl != rxr) {
350
2.78M
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
2.78M
                    if (code < 0)
352
0
                        goto xit;
353
2.78M
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
2.78M
                    if (code < 0)
355
0
                        goto xit;
356
2.78M
                }
357
6.15M
                if (++iy == iy1)
358
721k
                    break;
359
5.43M
                STEP_LINE(rxl, l);
360
5.43M
                STEP_LINE(rxr, r);
361
5.43M
                step_gradient(&lg, num_components);
362
5.43M
                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
5.43M
        }
379
# if !LINEAR_COLOR
380
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
721k
            code = 0;
383
721k
# endif
384
721k
#undef STEP_LINE
385
721k
#undef SET_MINIMAL_WIDTH
386
721k
#undef CONNECT_RECTANGLES
387
721k
#undef FILL_TRAP_RECT
388
721k
#undef FILL_TRAP_RECT_DIRECT
389
721k
#undef FILL_TRAP_RECT_INRECT
390
721k
#undef YMULT_QUO
391
721k
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
721k
        return_if_interrupt(dev->memory);
394
721k
        return code;
395
721k
    }
396
721k
}
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