Coverage Report

Created: 2026-02-14 07:09

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