Coverage Report

Created: 2022-10-31 07:00

/src/ghostpdl/base/gxdtfill.h
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) 2001-2021 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.,  1305 Grant Avenue - Suite 200, Novato,
13
   CA 94945, U.S.A., +1(415)492-9861, 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
57.7M
{
138
57.7M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
57.7M
    const fixed ymax = fixed_pixround(ytop);
140
141
57.7M
    if (ymin >= ymax)
142
13.6M
        return 0;    /* no scan lines to sample */
143
44.0M
    {
144
44.0M
        int iy = fixed2int_var(ymin);
145
44.0M
        const int iy1 = fixed2int_var(ymax);
146
44.0M
        trap_line l, r;
147
44.0M
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
44.0M
        const fixed
152
44.0M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
44.0M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
44.0M
        const fixed /* partial pixel offset to first line to sample */
155
44.0M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
44.0M
        fixed fxl;
157
44.0M
        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
40.4M
            dev_proc_fill_rectangle((*fill_rect)) =
179
40.4M
                dev_proc(dev, fill_rectangle);
180
# endif
181
182
44.0M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
44.0M
        l.h = left->end.y - left->start.y;
185
44.0M
        if (l.h == 0)
186
0
           return 0;
187
44.0M
        r.h = right->end.y - right->start.y;
188
44.0M
        if (r.h == 0)
189
0
           return 0;
190
44.0M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
44.0M
        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
44.0M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
718M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
718M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
44.0M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
119M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
119M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
#if LINEAR_COLOR
210
#   define FILL_TRAP_RECT(x,y,w,h)\
211
11.9M
        (!(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
837M
        (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
44.0M
#define YMULT_QUO(ys, tl)\
228
62.7M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
62.7M
   fixed_mult_quo(ys, tl.df, tl.h))
230
231
#if CONTIGUOUS_FILL
232
/*
233
 * If left and right boundary round to same pixel index,
234
 * we would not paing the scan and would get a dropout.
235
 * Check for this case and choose one of two pixels
236
 * which is closer to the "axis". We need to exclude
237
 * 'peak' because it would paint an excessive pixel.
238
 */
239
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \
240
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.31G
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
1.59G
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
#endif
264
44.0M
        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
32.6M
        } else {
269
32.6M
            compute_dx(&l, dxl, ysl);
270
32.6M
            fxl = YMULT_QUO(ysl, l);
271
32.6M
            l.x += fxl;
272
32.6M
        }
273
44.0M
        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
11.0M
                if (l.di == 0 && l.df == 0) {
278
7.06M
                    rxl = fixed2int_var(l.x);
279
7.06M
                    rxr = fixed2int_var(r.x);
280
7.06M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
7.06M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
7.06M
                    goto xit;
283
7.06M
                }
284
3.99M
#     endif
285
3.99M
            r.di = 0, r.df = 0;
286
3.99M
        }
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
32.0M
        else if (dxr == dxl && fxl != 0) {
292
2.65M
            if (l.di == 0)
293
666k
                r.di = 0, r.df = l.df;
294
1.98M
            else
295
1.98M
                compute_dx(&r, dxr, ysr);
296
2.65M
            if (ysr == ysl && r.h == l.h)
297
2.01M
                r.x += fxl;
298
636k
            else
299
636k
                r.x += YMULT_QUO(ysr, r);
300
29.4M
        } else {
301
29.4M
            compute_dx(&r, dxr, ysr);
302
29.4M
            r.x += YMULT_QUO(ysr, r);
303
29.4M
        }
304
        /* Compute one line's worth of dx/dy. */
305
33.3M
        compute_ldx(&l, ysl);
306
33.3M
        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
37.0M
        l.x += fixed_epsilon;
310
37.0M
        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
3.66M
            if (code < 0)
330
0
                return code;
331
3.66M
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
3.66M
            if (code < 0)
333
0
                return code;
334
335
3.66M
# endif
336
337
3.66M
#define rational_floor(tl)\
338
4.67G
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
3.66M
#define STEP_LINE(ix, tl)\
340
4.60G
  tl.x += tl.ldi;\
341
4.60G
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
4.60G
  ix = rational_floor(tl)
343
344
37.0M
        rxl = rational_floor(l);
345
37.0M
        rxr = rational_floor(r);
346
37.0M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
2.33G
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
#     if LINEAR_COLOR
349
31.7M
                if (rxl != rxr) {
350
11.9M
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
11.9M
                    if (code < 0)
352
0
                        goto xit;
353
11.9M
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
11.9M
                    if (code < 0)
355
0
                        goto xit;
356
11.9M
                }
357
31.7M
                if (++iy == iy1)
358
3.66M
                    break;
359
28.0M
                STEP_LINE(rxl, l);
360
28.0M
                STEP_LINE(rxr, r);
361
28.0M
                step_gradient(&lg, num_components);
362
28.0M
                step_gradient(&rg, num_components);
363
#     else
364
                register int ixl, ixr;
365
366
2.27G
                STEP_LINE(ixl, l);
367
2.27G
                STEP_LINE(ixr, r);
368
2.27G
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
2.27G
                if (ixl != rxl || ixr != rxr) {
370
797M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
797M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
797M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
797M
                    if (code < 0)
374
0
                        goto xit;
375
797M
                    rxl = ixl, rxr = ixr, ry = iy;
376
797M
                }
377
#     endif
378
28.0M
        }
379
# if !LINEAR_COLOR
380
33.3M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
3.66M
            code = 0;
383
3.66M
# endif
384
3.66M
#undef STEP_LINE
385
3.66M
#undef SET_MINIMAL_WIDTH
386
3.66M
#undef CONNECT_RECTANGLES
387
3.66M
#undef FILL_TRAP_RECT
388
3.66M
#undef FILL_TRAP_RECT_DIRECT
389
3.66M
#undef FILL_TRAP_RECT_INRECT
390
3.66M
#undef YMULT_QUO
391
44.0M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
44.0M
        return_if_interrupt(dev->memory);
394
44.0M
        return code;
395
44.0M
    }
396
44.0M
}
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
949k
{
138
949k
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
949k
    const fixed ymax = fixed_pixround(ytop);
140
141
949k
    if (ymin >= ymax)
142
48.1k
        return 0;    /* no scan lines to sample */
143
901k
    {
144
901k
        int iy = fixed2int_var(ymin);
145
901k
        const int iy1 = fixed2int_var(ymax);
146
901k
        trap_line l, r;
147
901k
        register int rxl, rxr;
148
901k
#if !LINEAR_COLOR
149
901k
        int ry;
150
901k
#endif
151
901k
        const fixed
152
901k
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
901k
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
901k
        const fixed /* partial pixel offset to first line to sample */
155
901k
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
901k
        fixed fxl;
157
901k
        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
901k
            gx_color_index cindex = pdevc->colors.pure;
178
901k
            dev_proc_fill_rectangle((*fill_rect)) =
179
901k
                dev_proc(dev, fill_rectangle);
180
901k
# endif
181
182
901k
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
901k
        l.h = left->end.y - left->start.y;
185
901k
        if (l.h == 0)
186
0
           return 0;
187
901k
        r.h = right->end.y - right->start.y;
188
901k
        if (r.h == 0)
189
0
           return 0;
190
901k
        l.x = x0l + (fixed_half - fixed_epsilon);
191
901k
        r.x = x0r + (fixed_half - fixed_epsilon);
192
901k
#if !LINEAR_COLOR
193
901k
        ry = iy;
194
901k
#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
901k
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
901k
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
901k
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
901k
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
901k
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
901k
   (*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
901k
#   define FILL_TRAP_RECT(x,y,w,h)\
214
901k
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
901k
#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
901k
#define YMULT_QUO(ys, tl)\
228
901k
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
901k
   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
901k
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
901k
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
901k
#endif
264
901k
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
142k
            l.di = 0, l.df = 0;
267
142k
            fxl = 0;
268
758k
        } else {
269
758k
            compute_dx(&l, dxl, ysl);
270
758k
            fxl = YMULT_QUO(ysl, l);
271
758k
            l.x += fxl;
272
758k
        }
273
901k
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
122k
#     if !LINEAR_COLOR
277
122k
                if (l.di == 0 && l.df == 0) {
278
115k
                    rxl = fixed2int_var(l.x);
279
115k
                    rxr = fixed2int_var(r.x);
280
115k
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
115k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
115k
                    goto xit;
283
115k
                }
284
7.31k
#     endif
285
7.31k
            r.di = 0, r.df = 0;
286
7.31k
        }
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
778k
        else if (dxr == dxl && fxl != 0) {
292
532k
            if (l.di == 0)
293
248k
                r.di = 0, r.df = l.df;
294
283k
            else
295
283k
                compute_dx(&r, dxr, ysr);
296
532k
            if (ysr == ysl && r.h == l.h)
297
532k
                r.x += fxl;
298
0
            else
299
0
                r.x += YMULT_QUO(ysr, r);
300
532k
        } else {
301
246k
            compute_dx(&r, dxr, ysr);
302
246k
            r.x += YMULT_QUO(ysr, r);
303
246k
        }
304
        /* Compute one line's worth of dx/dy. */
305
785k
        compute_ldx(&l, ysl);
306
785k
        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
785k
        l.x += fixed_epsilon;
310
785k
        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
785k
#define rational_floor(tl)\
338
785k
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
785k
#define STEP_LINE(ix, tl)\
340
785k
  tl.x += tl.ldi;\
341
785k
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
785k
  ix = rational_floor(tl)
343
344
785k
        rxl = rational_floor(l);
345
785k
        rxr = rational_floor(r);
346
785k
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
35.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
34.9M
                register int ixl, ixr;
365
366
34.9M
                STEP_LINE(ixl, l);
367
34.9M
                STEP_LINE(ixr, r);
368
34.9M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
34.9M
                if (ixl != rxl || ixr != rxr) {
370
22.3M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
22.3M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
22.3M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
22.3M
                    if (code < 0)
374
0
                        goto xit;
375
22.3M
                    rxl = ixl, rxr = ixr, ry = iy;
376
22.3M
                }
377
34.9M
#     endif
378
34.9M
        }
379
785k
# if !LINEAR_COLOR
380
785k
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
785k
#undef STEP_LINE
385
785k
#undef SET_MINIMAL_WIDTH
386
785k
#undef CONNECT_RECTANGLES
387
785k
#undef FILL_TRAP_RECT
388
785k
#undef FILL_TRAP_RECT_DIRECT
389
785k
#undef FILL_TRAP_RECT_INRECT
390
785k
#undef YMULT_QUO
391
901k
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
901k
        return_if_interrupt(dev->memory);
394
901k
        return code;
395
901k
    }
396
901k
}
gdevddrw.c:gx_fill_trapezoid_as_nd
Line
Count
Source
137
1.80M
{
138
1.80M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
1.80M
    const fixed ymax = fixed_pixround(ytop);
140
141
1.80M
    if (ymin >= ymax)
142
26.2k
        return 0;    /* no scan lines to sample */
143
1.78M
    {
144
1.78M
        int iy = fixed2int_var(ymin);
145
1.78M
        const int iy1 = fixed2int_var(ymax);
146
1.78M
        trap_line l, r;
147
1.78M
        register int rxl, rxr;
148
1.78M
#if !LINEAR_COLOR
149
1.78M
        int ry;
150
1.78M
#endif
151
1.78M
        const fixed
152
1.78M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
1.78M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
1.78M
        const fixed /* partial pixel offset to first line to sample */
155
1.78M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
1.78M
        fixed fxl;
157
1.78M
        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.78M
            gx_color_index cindex = pdevc->colors.pure;
178
1.78M
            dev_proc_fill_rectangle((*fill_rect)) =
179
1.78M
                dev_proc(dev, fill_rectangle);
180
1.78M
# endif
181
182
1.78M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
1.78M
        l.h = left->end.y - left->start.y;
185
1.78M
        if (l.h == 0)
186
0
           return 0;
187
1.78M
        r.h = right->end.y - right->start.y;
188
1.78M
        if (r.h == 0)
189
0
           return 0;
190
1.78M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
1.78M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
1.78M
#if !LINEAR_COLOR
193
1.78M
        ry = iy;
194
1.78M
#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.78M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
1.78M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
1.78M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
1.78M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
1.78M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
1.78M
   (*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.78M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
1.78M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
1.78M
#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.78M
#define YMULT_QUO(ys, tl)\
228
1.78M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
1.78M
   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.78M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
1.78M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
1.78M
#endif
264
1.78M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
463k
            l.di = 0, l.df = 0;
267
463k
            fxl = 0;
268
1.31M
        } else {
269
1.31M
            compute_dx(&l, dxl, ysl);
270
1.31M
            fxl = YMULT_QUO(ysl, l);
271
1.31M
            l.x += fxl;
272
1.31M
        }
273
1.78M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
416k
#     if !LINEAR_COLOR
277
416k
                if (l.di == 0 && l.df == 0) {
278
392k
                    rxl = fixed2int_var(l.x);
279
392k
                    rxr = fixed2int_var(r.x);
280
392k
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
392k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
392k
                    goto xit;
283
392k
                }
284
23.9k
#     endif
285
23.9k
            r.di = 0, r.df = 0;
286
23.9k
        }
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.36M
        else if (dxr == dxl && fxl != 0) {
292
112k
            if (l.di == 0)
293
62.3k
                r.di = 0, r.df = l.df;
294
49.8k
            else
295
49.8k
                compute_dx(&r, dxr, ysr);
296
112k
            if (ysr == ysl && r.h == l.h)
297
112k
                r.x += fxl;
298
88
            else
299
88
                r.x += YMULT_QUO(ysr, r);
300
1.25M
        } else {
301
1.25M
            compute_dx(&r, dxr, ysr);
302
1.25M
            r.x += YMULT_QUO(ysr, r);
303
1.25M
        }
304
        /* Compute one line's worth of dx/dy. */
305
1.39M
        compute_ldx(&l, ysl);
306
1.39M
        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.39M
        l.x += fixed_epsilon;
310
1.39M
        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.39M
#define rational_floor(tl)\
338
1.39M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
1.39M
#define STEP_LINE(ix, tl)\
340
1.39M
  tl.x += tl.ldi;\
341
1.39M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
1.39M
  ix = rational_floor(tl)
343
344
1.39M
        rxl = rational_floor(l);
345
1.39M
        rxr = rational_floor(r);
346
1.39M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
227M
        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
226M
                register int ixl, ixr;
365
366
226M
                STEP_LINE(ixl, l);
367
226M
                STEP_LINE(ixr, r);
368
226M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
226M
                if (ixl != rxl || ixr != rxr) {
370
175M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
175M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
175M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
175M
                    if (code < 0)
374
0
                        goto xit;
375
175M
                    rxl = ixl, rxr = ixr, ry = iy;
376
175M
                }
377
226M
#     endif
378
226M
        }
379
1.39M
# if !LINEAR_COLOR
380
1.39M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
1.39M
#undef STEP_LINE
385
1.39M
#undef SET_MINIMAL_WIDTH
386
1.39M
#undef CONNECT_RECTANGLES
387
1.39M
#undef FILL_TRAP_RECT
388
1.39M
#undef FILL_TRAP_RECT_DIRECT
389
1.39M
#undef FILL_TRAP_RECT_INRECT
390
1.39M
#undef YMULT_QUO
391
1.78M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
1.78M
        return_if_interrupt(dev->memory);
394
1.78M
        return code;
395
1.78M
    }
396
1.78M
}
gdevddrw.c:gx_fill_trapezoid_ns_fd
Line
Count
Source
137
9.39M
{
138
9.39M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
9.39M
    const fixed ymax = fixed_pixround(ytop);
140
141
9.39M
    if (ymin >= ymax)
142
1.19M
        return 0;    /* no scan lines to sample */
143
8.19M
    {
144
8.19M
        int iy = fixed2int_var(ymin);
145
8.19M
        const int iy1 = fixed2int_var(ymax);
146
8.19M
        trap_line l, r;
147
8.19M
        register int rxl, rxr;
148
8.19M
#if !LINEAR_COLOR
149
8.19M
        int ry;
150
8.19M
#endif
151
8.19M
        const fixed
152
8.19M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
8.19M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
8.19M
        const fixed /* partial pixel offset to first line to sample */
155
8.19M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
8.19M
        fixed fxl;
157
8.19M
        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
8.19M
            gx_color_index cindex = pdevc->colors.pure;
178
8.19M
            dev_proc_fill_rectangle((*fill_rect)) =
179
8.19M
                dev_proc(dev, fill_rectangle);
180
8.19M
# endif
181
182
8.19M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
8.19M
        l.h = left->end.y - left->start.y;
185
8.19M
        if (l.h == 0)
186
0
           return 0;
187
8.19M
        r.h = right->end.y - right->start.y;
188
8.19M
        if (r.h == 0)
189
0
           return 0;
190
8.19M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
8.19M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
8.19M
#if !LINEAR_COLOR
193
8.19M
        ry = iy;
194
8.19M
#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
8.19M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
8.19M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
8.19M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
8.19M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
8.19M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
8.19M
   (*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
8.19M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
8.19M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
8.19M
#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
8.19M
#define YMULT_QUO(ys, tl)\
228
8.19M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
8.19M
   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
8.19M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
8.19M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
8.19M
#endif
264
8.19M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
3.04M
            l.di = 0, l.df = 0;
267
3.04M
            fxl = 0;
268
5.14M
        } else {
269
5.14M
            compute_dx(&l, dxl, ysl);
270
5.14M
            fxl = YMULT_QUO(ysl, l);
271
5.14M
            l.x += fxl;
272
5.14M
        }
273
8.19M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
3.08M
#     if !LINEAR_COLOR
277
3.08M
                if (l.di == 0 && l.df == 0) {
278
1.98M
                    rxl = fixed2int_var(l.x);
279
1.98M
                    rxr = fixed2int_var(r.x);
280
1.98M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
1.98M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
1.98M
                    goto xit;
283
1.98M
                }
284
1.09M
#     endif
285
1.09M
            r.di = 0, r.df = 0;
286
1.09M
        }
287
        /*
288
         * The test for fxl != 0 is required because the right edge might
289
         * cross some pixel centers even if the left edge doesn't.
290
         */
291
5.10M
        else if (dxr == dxl && fxl != 0) {
292
716k
            if (l.di == 0)
293
199k
                r.di = 0, r.df = l.df;
294
516k
            else
295
516k
                compute_dx(&r, dxr, ysr);
296
716k
            if (ysr == ysl && r.h == l.h)
297
475k
                r.x += fxl;
298
240k
            else
299
240k
                r.x += YMULT_QUO(ysr, r);
300
4.39M
        } else {
301
4.39M
            compute_dx(&r, dxr, ysr);
302
4.39M
            r.x += YMULT_QUO(ysr, r);
303
4.39M
        }
304
        /* Compute one line's worth of dx/dy. */
305
6.20M
        compute_ldx(&l, ysl);
306
6.20M
        compute_ldx(&r, ysr);
307
        /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding
308
           when the rational part is zero. Now add it back to get xl', xr' */
309
6.20M
        l.x += fixed_epsilon;
310
6.20M
        r.x += fixed_epsilon;
311
# if LINEAR_COLOR
312
#     ifdef DEBUG
313
                if (check_gradient_overflow(left, right)) {
314
                    /* The caller must care of.
315
                       Checking it here looses some performance with triangles. */
316
                    return_error(gs_error_unregistered);
317
                }
318
#     endif
319
            lg.c = lgc;
320
            lg.f = lgf;
321
            lg.num = lgnum;
322
            rg.c = rgc;
323
            rg.f = rgf;
324
            rg.num = rgnum;
325
            xg.c = xgc;
326
            xg.f = xgf;
327
            xg.num = xgnum;
328
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
            if (code < 0)
330
                return code;
331
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
            if (code < 0)
333
                return code;
334
335
# endif
336
337
6.20M
#define rational_floor(tl)\
338
6.20M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
6.20M
#define STEP_LINE(ix, tl)\
340
6.20M
  tl.x += tl.ldi;\
341
6.20M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
6.20M
  ix = rational_floor(tl)
343
344
6.20M
        rxl = rational_floor(l);
345
6.20M
        rxr = rational_floor(r);
346
6.20M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
1.41G
        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.40G
                register int ixl, ixr;
365
366
1.40G
                STEP_LINE(ixl, l);
367
1.40G
                STEP_LINE(ixr, r);
368
1.40G
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
1.40G
                if (ixl != rxl || ixr != rxr) {
370
88.1M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
88.1M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
88.1M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
88.1M
                    if (code < 0)
374
0
                        goto xit;
375
88.1M
                    rxl = ixl, rxr = ixr, ry = iy;
376
88.1M
                }
377
1.40G
#     endif
378
1.40G
        }
379
6.20M
# if !LINEAR_COLOR
380
6.20M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
6.20M
#undef STEP_LINE
385
6.20M
#undef SET_MINIMAL_WIDTH
386
6.20M
#undef CONNECT_RECTANGLES
387
6.20M
#undef FILL_TRAP_RECT
388
6.20M
#undef FILL_TRAP_RECT_DIRECT
389
6.20M
#undef FILL_TRAP_RECT_INRECT
390
6.20M
#undef YMULT_QUO
391
8.19M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
8.19M
        return_if_interrupt(dev->memory);
394
8.19M
        return code;
395
8.19M
    }
396
8.19M
}
gdevddrw.c:gx_fill_trapezoid_ns_nd
Line
Count
Source
137
39.4M
{
138
39.4M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
39.4M
    const fixed ymax = fixed_pixround(ytop);
140
141
39.4M
    if (ymin >= ymax)
142
9.87M
        return 0;    /* no scan lines to sample */
143
29.5M
    {
144
29.5M
        int iy = fixed2int_var(ymin);
145
29.5M
        const int iy1 = fixed2int_var(ymax);
146
29.5M
        trap_line l, r;
147
29.5M
        register int rxl, rxr;
148
29.5M
#if !LINEAR_COLOR
149
29.5M
        int ry;
150
29.5M
#endif
151
29.5M
        const fixed
152
29.5M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
29.5M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
29.5M
        const fixed /* partial pixel offset to first line to sample */
155
29.5M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
29.5M
        fixed fxl;
157
29.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
# 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
29.5M
            gx_color_index cindex = pdevc->colors.pure;
178
29.5M
            dev_proc_fill_rectangle((*fill_rect)) =
179
29.5M
                dev_proc(dev, fill_rectangle);
180
29.5M
# endif
181
182
29.5M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
29.5M
        l.h = left->end.y - left->start.y;
185
29.5M
        if (l.h == 0)
186
0
           return 0;
187
29.5M
        r.h = right->end.y - right->start.y;
188
29.5M
        if (r.h == 0)
189
0
           return 0;
190
29.5M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
29.5M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
29.5M
#if !LINEAR_COLOR
193
29.5M
        ry = iy;
194
29.5M
#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
29.5M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
29.5M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
29.5M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
29.5M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
29.5M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
29.5M
   (*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
29.5M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
29.5M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
29.5M
#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
29.5M
#define YMULT_QUO(ys, tl)\
228
29.5M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
29.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
29.5M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
29.5M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
29.5M
#endif
264
29.5M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
6.87M
            l.di = 0, l.df = 0;
267
6.87M
            fxl = 0;
268
22.6M
        } else {
269
22.6M
            compute_dx(&l, dxl, ysl);
270
22.6M
            fxl = YMULT_QUO(ysl, l);
271
22.6M
            l.x += fxl;
272
22.6M
        }
273
29.5M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
7.44M
#     if !LINEAR_COLOR
277
7.44M
                if (l.di == 0 && l.df == 0) {
278
4.57M
                    rxl = fixed2int_var(l.x);
279
4.57M
                    rxr = fixed2int_var(r.x);
280
4.57M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
4.57M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
4.57M
                    goto xit;
283
4.57M
                }
284
2.86M
#     endif
285
2.86M
            r.di = 0, r.df = 0;
286
2.86M
        }
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
22.0M
        else if (dxr == dxl && fxl != 0) {
292
1.04M
            if (l.di == 0)
293
98.0k
                r.di = 0, r.df = l.df;
294
942k
            else
295
942k
                compute_dx(&r, dxr, ysr);
296
1.04M
            if (ysr == ysl && r.h == l.h)
297
731k
                r.x += fxl;
298
309k
            else
299
309k
                r.x += YMULT_QUO(ysr, r);
300
21.0M
        } else {
301
21.0M
            compute_dx(&r, dxr, ysr);
302
21.0M
            r.x += YMULT_QUO(ysr, r);
303
21.0M
        }
304
        /* Compute one line's worth of dx/dy. */
305
24.9M
        compute_ldx(&l, ysl);
306
24.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
24.9M
        l.x += fixed_epsilon;
310
24.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
24.9M
#define rational_floor(tl)\
338
24.9M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
24.9M
#define STEP_LINE(ix, tl)\
340
24.9M
  tl.x += tl.ldi;\
341
24.9M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
24.9M
  ix = rational_floor(tl)
343
344
24.9M
        rxl = rational_floor(l);
345
24.9M
        rxr = rational_floor(r);
346
24.9M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
631M
        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
606M
                register int ixl, ixr;
365
366
606M
                STEP_LINE(ixl, l);
367
606M
                STEP_LINE(ixr, r);
368
606M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
606M
                if (ixl != rxl || ixr != rxr) {
370
511M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
511M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
511M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
511M
                    if (code < 0)
374
0
                        goto xit;
375
511M
                    rxl = ixl, rxr = ixr, ry = iy;
376
511M
                }
377
606M
#     endif
378
606M
        }
379
24.9M
# if !LINEAR_COLOR
380
24.9M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
24.9M
#undef STEP_LINE
385
24.9M
#undef SET_MINIMAL_WIDTH
386
24.9M
#undef CONNECT_RECTANGLES
387
24.9M
#undef FILL_TRAP_RECT
388
24.9M
#undef FILL_TRAP_RECT_DIRECT
389
24.9M
#undef FILL_TRAP_RECT_INRECT
390
24.9M
#undef YMULT_QUO
391
29.5M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
29.5M
        return_if_interrupt(dev->memory);
394
29.5M
        return code;
395
29.5M
    }
396
29.5M
}
gdevddrw.c:gx_fill_trapezoid_as_lc
Line
Count
Source
137
182k
{
138
182k
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
182k
    const fixed ymax = fixed_pixround(ytop);
140
141
182k
    if (ymin >= ymax)
142
1.47k
        return 0;    /* no scan lines to sample */
143
180k
    {
144
180k
        int iy = fixed2int_var(ymin);
145
180k
        const int iy1 = fixed2int_var(ymax);
146
180k
        trap_line l, r;
147
180k
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
180k
        const fixed
152
180k
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
180k
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
180k
        const fixed /* partial pixel offset to first line to sample */
155
180k
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
180k
        fixed fxl;
157
180k
        int code;
158
# if CONTIGUOUS_FILL
159
            const bool peak0 = ((flags & 1) != 0);
160
            const bool peak1 = ((flags & 2) != 0);
161
            int peak_y0 = ybot + fixed_half;
162
            int peak_y1 = ytop - fixed_half;
163
# endif
164
180k
# if LINEAR_COLOR
165
180k
            int num_components = dev->color_info.num_components;
166
180k
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
180k
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
180k
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
180k
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
180k
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
180k
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
180k
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
180k
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
180k
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
180k
            trap_gradient lg, rg, xg;
176
# else
177
            gx_color_index cindex = pdevc->colors.pure;
178
            dev_proc_fill_rectangle((*fill_rect)) =
179
                dev_proc(dev, fill_rectangle);
180
# endif
181
182
180k
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
180k
        l.h = left->end.y - left->start.y;
185
180k
        if (l.h == 0)
186
0
           return 0;
187
180k
        r.h = right->end.y - right->start.y;
188
180k
        if (r.h == 0)
189
0
           return 0;
190
180k
        l.x = x0l + (fixed_half - fixed_epsilon);
191
180k
        r.x = x0r + (fixed_half - fixed_epsilon);
192
#if !LINEAR_COLOR
193
        ry = iy;
194
#endif
195
196
/*
197
 * Free variables of FILL_TRAP_RECT:
198
 *  SWAP_AXES, pdevc, dev, fa
199
 * Free variables of FILL_TRAP_RECT_DIRECT:
200
 *  SWAP_AXES, fill_rect, dev, cindex
201
 */
202
180k
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
180k
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
180k
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
180k
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
180k
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
180k
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
180k
#if LINEAR_COLOR
210
180k
#   define FILL_TRAP_RECT(x,y,w,h)\
211
180k
        (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den))
212
#else
213
#   define FILL_TRAP_RECT(x,y,w,h)\
214
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
#endif
216
217
        /* Compute the dx/dy ratios. */
218
219
        /*
220
         * Compute the x offsets at the first scan line to sample.  We need
221
         * to be careful in computing ys# * dx#f {/,%} h# because the
222
         * multiplication may overflow.  We know that all the quantities
223
         * involved are non-negative, and that ys# is usually less than 1 (as
224
         * a fixed, of course); this gives us a cheap conservative check for
225
         * overflow in the multiplication.
226
         */
227
180k
#define YMULT_QUO(ys, tl)\
228
180k
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
180k
   fixed_mult_quo(ys, tl.df, tl.h))
230
231
#if CONTIGUOUS_FILL
232
/*
233
 * If left and right boundary round to same pixel index,
234
 * we would not paing the scan and would get a dropout.
235
 * Check for this case and choose one of two pixels
236
 * which is closer to the "axis". We need to exclude
237
 * 'peak' because it would paint an excessive pixel.
238
 */
239
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \
240
    if (ixl == ixr) \
241
        if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\
242
            fixed x = int2fixed(ixl) + fixed_half;\
243
            if (x - l.x < r.x - x)\
244
                ++ixr;\
245
            else\
246
                --ixl;\
247
        }
248
249
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\
250
    if (adj1 < adj2) {\
251
        if (iy - ry > 1) {\
252
            code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\
253
            if (code < 0)\
254
                goto xit;\
255
            ry = iy - 1;\
256
        }\
257
        adj1 = adj2 = (adj2 + adj2) / 2;\
258
    }
259
260
#else
261
180k
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
180k
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
180k
#endif
264
180k
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
84.5k
            l.di = 0, l.df = 0;
267
84.5k
            fxl = 0;
268
96.3k
        } else {
269
96.3k
            compute_dx(&l, dxl, ysl);
270
96.3k
            fxl = YMULT_QUO(ysl, l);
271
96.3k
            l.x += fxl;
272
96.3k
        }
273
180k
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
#     if !LINEAR_COLOR
277
                if (l.di == 0 && l.df == 0) {
278
                    rxl = fixed2int_var(l.x);
279
                    rxr = fixed2int_var(r.x);
280
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
                    goto xit;
283
                }
284
#     endif
285
83.7k
            r.di = 0, r.df = 0;
286
83.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
97.0k
        else if (dxr == dxl && fxl != 0) {
292
50.7k
            if (l.di == 0)
293
25.2k
                r.di = 0, r.df = l.df;
294
25.4k
            else
295
25.4k
                compute_dx(&r, dxr, ysr);
296
50.7k
            if (ysr == ysl && r.h == l.h)
297
50.7k
                r.x += fxl;
298
0
            else
299
0
                r.x += YMULT_QUO(ysr, r);
300
50.7k
        } else {
301
46.3k
            compute_dx(&r, dxr, ysr);
302
46.3k
            r.x += YMULT_QUO(ysr, r);
303
46.3k
        }
304
        /* Compute one line's worth of dx/dy. */
305
180k
        compute_ldx(&l, ysl);
306
180k
        compute_ldx(&r, ysr);
307
        /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding
308
           when the rational part is zero. Now add it back to get xl', xr' */
309
180k
        l.x += fixed_epsilon;
310
180k
        r.x += fixed_epsilon;
311
180k
# if LINEAR_COLOR
312
#     ifdef DEBUG
313
                if (check_gradient_overflow(left, right)) {
314
                    /* The caller must care of.
315
                       Checking it here looses some performance with triangles. */
316
                    return_error(gs_error_unregistered);
317
                }
318
#     endif
319
180k
            lg.c = lgc;
320
180k
            lg.f = lgf;
321
180k
            lg.num = lgnum;
322
180k
            rg.c = rgc;
323
180k
            rg.f = rgf;
324
180k
            rg.num = rgnum;
325
180k
            xg.c = xgc;
326
180k
            xg.f = xgf;
327
180k
            xg.num = xgnum;
328
180k
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
180k
            if (code < 0)
330
0
                return code;
331
180k
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
180k
            if (code < 0)
333
0
                return code;
334
335
180k
# endif
336
337
180k
#define rational_floor(tl)\
338
180k
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
180k
#define STEP_LINE(ix, tl)\
340
180k
  tl.x += tl.ldi;\
341
180k
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
180k
  ix = rational_floor(tl)
343
344
180k
        rxl = rational_floor(l);
345
180k
        rxr = rational_floor(r);
346
180k
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
4.91M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
4.91M
#     if LINEAR_COLOR
349
4.91M
                if (rxl != rxr) {
350
4.02M
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
4.02M
                    if (code < 0)
352
0
                        goto xit;
353
4.02M
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
4.02M
                    if (code < 0)
355
0
                        goto xit;
356
4.02M
                }
357
4.91M
                if (++iy == iy1)
358
180k
                    break;
359
4.73M
                STEP_LINE(rxl, l);
360
4.73M
                STEP_LINE(rxr, r);
361
4.73M
                step_gradient(&lg, num_components);
362
4.73M
                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
4.73M
        }
379
# if !LINEAR_COLOR
380
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
180k
            code = 0;
383
180k
# endif
384
180k
#undef STEP_LINE
385
180k
#undef SET_MINIMAL_WIDTH
386
180k
#undef CONNECT_RECTANGLES
387
180k
#undef FILL_TRAP_RECT
388
180k
#undef FILL_TRAP_RECT_DIRECT
389
180k
#undef FILL_TRAP_RECT_INRECT
390
180k
#undef YMULT_QUO
391
180k
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
180k
        return_if_interrupt(dev->memory);
394
180k
        return code;
395
180k
    }
396
180k
}
gdevddrw.c:gx_fill_trapezoid_ns_lc
Line
Count
Source
137
5.99M
{
138
5.99M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
5.99M
    const fixed ymax = fixed_pixround(ytop);
140
141
5.99M
    if (ymin >= ymax)
142
2.51M
        return 0;    /* no scan lines to sample */
143
3.47M
    {
144
3.47M
        int iy = fixed2int_var(ymin);
145
3.47M
        const int iy1 = fixed2int_var(ymax);
146
3.47M
        trap_line l, r;
147
3.47M
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
3.47M
        const fixed
152
3.47M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
3.47M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
3.47M
        const fixed /* partial pixel offset to first line to sample */
155
3.47M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
3.47M
        fixed fxl;
157
3.47M
        int code;
158
# if CONTIGUOUS_FILL
159
            const bool peak0 = ((flags & 1) != 0);
160
            const bool peak1 = ((flags & 2) != 0);
161
            int peak_y0 = ybot + fixed_half;
162
            int peak_y1 = ytop - fixed_half;
163
# endif
164
3.47M
# if LINEAR_COLOR
165
3.47M
            int num_components = dev->color_info.num_components;
166
3.47M
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
3.47M
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
3.47M
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
3.47M
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
3.47M
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
3.47M
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
3.47M
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
3.47M
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
3.47M
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
3.47M
            trap_gradient lg, rg, xg;
176
# else
177
            gx_color_index cindex = pdevc->colors.pure;
178
            dev_proc_fill_rectangle((*fill_rect)) =
179
                dev_proc(dev, fill_rectangle);
180
# endif
181
182
3.47M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
3.47M
        l.h = left->end.y - left->start.y;
185
3.47M
        if (l.h == 0)
186
0
           return 0;
187
3.47M
        r.h = right->end.y - right->start.y;
188
3.47M
        if (r.h == 0)
189
0
           return 0;
190
3.47M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
3.47M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
#if !LINEAR_COLOR
193
        ry = iy;
194
#endif
195
196
/*
197
 * Free variables of FILL_TRAP_RECT:
198
 *  SWAP_AXES, pdevc, dev, fa
199
 * Free variables of FILL_TRAP_RECT_DIRECT:
200
 *  SWAP_AXES, fill_rect, dev, cindex
201
 */
202
3.47M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
3.47M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
3.47M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
3.47M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
3.47M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
3.47M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
3.47M
#if LINEAR_COLOR
210
3.47M
#   define FILL_TRAP_RECT(x,y,w,h)\
211
3.47M
        (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den))
212
#else
213
#   define FILL_TRAP_RECT(x,y,w,h)\
214
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
#endif
216
217
        /* Compute the dx/dy ratios. */
218
219
        /*
220
         * Compute the x offsets at the first scan line to sample.  We need
221
         * to be careful in computing ys# * dx#f {/,%} h# because the
222
         * multiplication may overflow.  We know that all the quantities
223
         * involved are non-negative, and that ys# is usually less than 1 (as
224
         * a fixed, of course); this gives us a cheap conservative check for
225
         * overflow in the multiplication.
226
         */
227
3.47M
#define YMULT_QUO(ys, tl)\
228
3.47M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
3.47M
   fixed_mult_quo(ys, tl.df, tl.h))
230
231
#if CONTIGUOUS_FILL
232
/*
233
 * If left and right boundary round to same pixel index,
234
 * we would not paing the scan and would get a dropout.
235
 * Check for this case and choose one of two pixels
236
 * which is closer to the "axis". We need to exclude
237
 * 'peak' because it would paint an excessive pixel.
238
 */
239
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \
240
    if (ixl == ixr) \
241
        if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\
242
            fixed x = int2fixed(ixl) + fixed_half;\
243
            if (x - l.x < r.x - x)\
244
                ++ixr;\
245
            else\
246
                --ixl;\
247
        }
248
249
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\
250
    if (adj1 < adj2) {\
251
        if (iy - ry > 1) {\
252
            code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\
253
            if (code < 0)\
254
                goto xit;\
255
            ry = iy - 1;\
256
        }\
257
        adj1 = adj2 = (adj2 + adj2) / 2;\
258
    }
259
260
#else
261
3.47M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
3.47M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
3.47M
#endif
264
3.47M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
847k
            l.di = 0, l.df = 0;
267
847k
            fxl = 0;
268
2.63M
        } else {
269
2.63M
            compute_dx(&l, dxl, ysl);
270
2.63M
            fxl = YMULT_QUO(ysl, l);
271
2.63M
            l.x += fxl;
272
2.63M
        }
273
3.47M
        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
841k
            r.di = 0, r.df = 0;
286
841k
        }
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.63M
        else if (dxr == dxl && fxl != 0) {
292
197k
            if (l.di == 0)
293
32.5k
                r.di = 0, r.df = l.df;
294
165k
            else
295
165k
                compute_dx(&r, dxr, ysr);
296
197k
            if (ysr == ysl && r.h == l.h)
297
111k
                r.x += fxl;
298
86.3k
            else
299
86.3k
                r.x += YMULT_QUO(ysr, r);
300
2.44M
        } else {
301
2.44M
            compute_dx(&r, dxr, ysr);
302
2.44M
            r.x += YMULT_QUO(ysr, r);
303
2.44M
        }
304
        /* Compute one line's worth of dx/dy. */
305
3.47M
        compute_ldx(&l, ysl);
306
3.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
3.47M
        l.x += fixed_epsilon;
310
3.47M
        r.x += fixed_epsilon;
311
3.47M
# if LINEAR_COLOR
312
#     ifdef DEBUG
313
                if (check_gradient_overflow(left, right)) {
314
                    /* The caller must care of.
315
                       Checking it here looses some performance with triangles. */
316
                    return_error(gs_error_unregistered);
317
                }
318
#     endif
319
3.47M
            lg.c = lgc;
320
3.47M
            lg.f = lgf;
321
3.47M
            lg.num = lgnum;
322
3.47M
            rg.c = rgc;
323
3.47M
            rg.f = rgf;
324
3.47M
            rg.num = rgnum;
325
3.47M
            xg.c = xgc;
326
3.47M
            xg.f = xgf;
327
3.47M
            xg.num = xgnum;
328
3.47M
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
3.47M
            if (code < 0)
330
0
                return code;
331
3.47M
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
3.47M
            if (code < 0)
333
0
                return code;
334
335
3.47M
# endif
336
337
3.47M
#define rational_floor(tl)\
338
3.47M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
3.47M
#define STEP_LINE(ix, tl)\
340
3.47M
  tl.x += tl.ldi;\
341
3.47M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
3.47M
  ix = rational_floor(tl)
343
344
3.47M
        rxl = rational_floor(l);
345
3.47M
        rxr = rational_floor(r);
346
3.47M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
26.8M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
26.8M
#     if LINEAR_COLOR
349
26.8M
                if (rxl != rxr) {
350
7.96M
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
7.96M
                    if (code < 0)
352
0
                        goto xit;
353
7.96M
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
7.96M
                    if (code < 0)
355
0
                        goto xit;
356
7.96M
                }
357
26.8M
                if (++iy == iy1)
358
3.47M
                    break;
359
23.3M
                STEP_LINE(rxl, l);
360
23.3M
                STEP_LINE(rxr, r);
361
23.3M
                step_gradient(&lg, num_components);
362
23.3M
                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
23.3M
        }
379
# if !LINEAR_COLOR
380
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
3.47M
            code = 0;
383
3.47M
# endif
384
3.47M
#undef STEP_LINE
385
3.47M
#undef SET_MINIMAL_WIDTH
386
3.47M
#undef CONNECT_RECTANGLES
387
3.47M
#undef FILL_TRAP_RECT
388
3.47M
#undef FILL_TRAP_RECT_DIRECT
389
3.47M
#undef FILL_TRAP_RECT_INRECT
390
3.47M
#undef YMULT_QUO
391
3.47M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
3.47M
        return_if_interrupt(dev->memory);
394
3.47M
        return code;
395
3.47M
    }
396
3.47M
}
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