Coverage Report

Created: 2025-06-10 07:27

/src/ghostpdl/base/gxdtfill.h
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) 2001-2023 Artifex Software, Inc.
2
   All Rights Reserved.
3
4
   This software is provided AS-IS with no warranty, either express or
5
   implied.
6
7
   This software is distributed under license and may not be copied,
8
   modified or distributed except as expressly authorized under the terms
9
   of the license contained in the file LICENSE in this distribution.
10
11
   Refer to licensing information at http://www.artifex.com or contact
12
   Artifex Software, Inc.,  39 Mesa Street, Suite 108A, San Francisco,
13
   CA 94129, USA, for further information.
14
*/
15
16
17
/* Configurable algorithm for filling a trapezoid */
18
19
/*
20
 * Since we need several statically defined variants of this agorithm,
21
 * we store it in .h file and include several times into gdevddrw.c and
22
 * into gxfill.h . Configuration flags (macros) are :
23
 *
24
 *   GX_FILL_TRAPEZOID - a name of method
25
 *   CONTIGUOUS_FILL   - prevent dropouts in narrow trapezoids
26
 *   SWAP_AXES         - assume swapped axes
27
 *   FILL_DIRECT       - See LOOP_FILL_RECTANGLE_DIRECT.
28
 *   LINEAR_COLOR      - Fill with a linear color.
29
 *   EDGE_TYPE         - a type of edge structure.
30
 *   FILL_ATTRS        - operation attributes.
31
 */
32
33
/*
34
 * Fill a trapezoid.  left.start => left.end and right.start => right.end
35
 * define the sides; ybot and ytop define the top and bottom.  Requires:
36
 *      {left,right}->start.y <= ybot <= ytop <= {left,right}->end.y.
37
 * Lines where left.x >= right.x will not be drawn.  Thanks to Paul Haeberli
38
 * for an early floating point version of this algorithm.
39
 */
40
41
/*
42
 * With CONTIGUOUS_FILL is off,
43
 * this algorithm paints pixels, which centers fall between
44
 * the left and the right side of the trapezoid, excluding the
45
 * right side (see PLRM3, 7.5. Scan conversion details).
46
 * Particularly 0-width trapezoids are not painted.
47
 *
48
 * Similarly, it paints pixels, which centers
49
 * fall between ybot and ytop, excluding ytop.
50
 * Particularly 0-height trapezoids are not painted.
51
 *
52
 * With CONTIGUOUS_FILL is on, it paints a contigous area,
53
 * adding a minimal number of pixels outside the trapezoid.
54
 * Particularly it may paint pixels on the right and on the top sides,
55
 * if they are necessary for the contiguity.
56
 *
57
 * With LINEAR_COLOR returns 1 if the gradient arithmetics overflows..
58
 */
59
60
/*
61
We must paint pixels with index i such that
62
63
    Xl <= i + 0.5 < Xr
64
65
The condition is is equivalent to
66
67
    Xl - 0.5 <= i < Xr - 0.5
68
69
which is equivalent to
70
71
    (is_integer(Xl - 0.5) ? Xl - 0.5 : ceil(Xl - 0.5)) <= i <
72
    (is_integer(Xr - 0.5) ? Xr - 0.5 : floor(Xr - 0.5) + 1)
73
74
(the last '+1" happens due to the strong comparizon '<')
75
which is equivalent to
76
77
    ceil(Xl - 0.5) <= i < ceil(Xr - 0.5)
78
79
trap_line represents the intersection coordinate as a rational value :
80
81
    Xl = xl + e - fl
82
    Xr = xr + e - fr
83
84
Where 'e' is 'fixed_epsilon', 0.5 is 'fixed_half', and fl == l.fx / l.h, fr == - r.fx / r.h,
85
e <= fl < 0, e <= fr < 0.
86
Let
87
88
    xl' := xl + 0.5
89
    xr' := xr + 0.5
90
91
Then
92
93
    xl = xl' - 0.5
94
    xr = xr' - 0.5
95
96
    Xl = xl' - 0.5 + e - fl
97
    Xr = xr' - 0.5 + e - fr
98
99
    ceil(xl' - 0.5 + e - fl - 0.5) <= i < ceil(xr' - 0.5 + e - fr - 0.5)
100
101
which is equivalent to
102
103
    ceil(xl' + e - fl) - 1 <= i < ceil(xr' + e - fr) - 1
104
105
which is equivalent to
106
107
    (is_integer(xl' + e - fl) ? xl' + e - fl - 1 : ceil(xl' + e - fl) - 1) <= i <
108
    (is_integer(xr' + e - fr) ? xr' + e - fr - 1 : ceil(xr' + e - fr) - 1)
109
110
which is equivalent to
111
112
    (is_integer(xl' + e - fl) ? xl' + e - fl - 1 : floor(xl' + e - fl)) <= i <
113
    (is_integer(xr' + e - fr) ? xr' + e - fr - 1 : floor(xr' + e - fr))
114
115
which is equivalent to
116
117
    (is_integer(xl') && e == fl ? xl' - 1 : floor(xl' + e - fl)) <= i <
118
    (is_integer(xr') && e == fr ? xr' - 1 : floor(xr' + e - fr))
119
120
Note that e != fl ==> floor(xl' + e - fl) == floor(xl')  due to e - fl < LeastSignificantBit(xl') ;
121
          e == fl ==> floor(xl' + e - fl) == floor(xl')  due to e - fl == 0;
122
123
thus the condition is is equivalent to
124
125
    (is_integer(xl') && e == fl ? xl' - 1 : floor(xl')) <= i <
126
    (is_integer(xr') && e == fr ? xr' - 1 : floor(xr'))
127
128
It is computed with the macro 'rational_floor'.
129
130
*/
131
132
#if defined(GX_FILL_TRAPEZOID) && defined(EDGE_TYPE)
133
134
GX_FILL_TRAPEZOID (gx_device * dev, const EDGE_TYPE * left,
135
    const EDGE_TYPE * right, fixed ybot, fixed ytop, int flags,
136
    const gx_device_color * pdevc, FILL_ATTRS fa)
137
191M
{
138
191M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
191M
    const fixed ymax = fixed_pixround(ytop);
140
141
191M
    if (ymin >= ymax)
142
55.5M
        return 0;    /* no scan lines to sample */
143
136M
    {
144
136M
        int iy = fixed2int_var(ymin);
145
136M
        const int iy1 = fixed2int_var(ymax);
146
136M
        trap_line l, r;
147
136M
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
136M
        const fixed
152
136M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
136M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
136M
        const fixed /* partial pixel offset to first line to sample */
155
136M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
136M
        fixed fxl;
157
136M
        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
92.9M
            dev_proc_fill_rectangle((*fill_rect)) =
179
92.9M
                dev_proc(dev, fill_rectangle);
180
# endif
181
182
136M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
136M
        l.h = left->end.y - left->start.y;
185
136M
        if (l.h == 0)
186
12
           return 0;
187
136M
        r.h = right->end.y - right->start.y;
188
136M
        if (r.h == 0)
189
12
           return 0;
190
136M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
136M
        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
136M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
1.54G
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
1.54G
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
136M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
395M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
395M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
#if LINEAR_COLOR
210
#   define FILL_TRAP_RECT(x,y,w,h)\
211
122M
        (!(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.94G
        (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
136M
#define YMULT_QUO(ys, tl)\
228
184M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
184M
   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
4.27G
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
3.69G
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
#endif
264
136M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
38.5M
            l.di = 0, l.df = 0;
267
38.5M
            fxl = 0;
268
97.7M
        } else {
269
97.7M
            compute_dx(&l, dxl, ysl);
270
97.7M
            fxl = YMULT_QUO(ysl, l);
271
97.7M
            l.x += fxl;
272
97.7M
        }
273
136M
        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
32.4M
                if (l.di == 0 && l.df == 0) {
278
17.0M
                    rxl = fixed2int_var(l.x);
279
17.0M
                    rxr = fixed2int_var(r.x);
280
17.0M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
17.0M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
17.0M
                    goto xit;
283
17.0M
                }
284
15.4M
#     endif
285
15.4M
            r.di = 0, r.df = 0;
286
15.4M
        }
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
93.3M
        else if (dxr == dxl && fxl != 0) {
292
9.01M
            if (l.di == 0)
293
2.47M
                r.di = 0, r.df = l.df;
294
6.53M
            else
295
6.53M
                compute_dx(&r, dxr, ysr);
296
9.01M
            if (ysr == ysl && r.h == l.h)
297
6.26M
                r.x += fxl;
298
2.75M
            else
299
2.75M
                r.x += YMULT_QUO(ysr, r);
300
84.3M
        } else {
301
84.3M
            compute_dx(&r, dxr, ysr);
302
84.3M
            r.x += YMULT_QUO(ysr, r);
303
84.3M
        }
304
        /* Compute one line's worth of dx/dy. */
305
75.9M
        compute_ldx(&l, ysl);
306
75.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
119M
        l.x += fixed_epsilon;
310
119M
        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
43.3M
            if (code < 0)
330
0
                return code;
331
43.3M
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
43.3M
            if (code < 0)
333
0
                return code;
334
335
43.3M
# endif
336
337
43.3M
#define rational_floor(tl)\
338
9.40G
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
43.3M
#define STEP_LINE(ix, tl)\
340
9.12G
  tl.x += tl.ldi;\
341
9.12G
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
9.16G
  ix = rational_floor(tl)
343
344
119M
        rxl = rational_floor(l);
345
119M
        rxr = rational_floor(r);
346
119M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
4.68G
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
#     if LINEAR_COLOR
349
464M
                if (rxl != rxr) {
350
122M
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
122M
                    if (code < 0)
352
0
                        goto xit;
353
122M
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
122M
                    if (code < 0)
355
17
                        goto xit;
356
122M
                }
357
464M
                if (++iy == iy1)
358
43.3M
                    break;
359
420M
                STEP_LINE(rxl, l);
360
420M
                STEP_LINE(rxr, r);
361
420M
                step_gradient(&lg, num_components);
362
420M
                step_gradient(&rg, num_components);
363
#     else
364
                register int ixl, ixr;
365
366
4.14G
                STEP_LINE(ixl, l);
367
4.14G
                STEP_LINE(ixr, r);
368
4.14G
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
4.14G
                if (ixl != rxl || ixr != rxr) {
370
1.84G
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
1.84G
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
1.84G
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
1.84G
                    if (code < 0)
374
0
                        goto xit;
375
1.84G
                    rxl = ixl, rxr = ixr, ry = iy;
376
1.84G
                }
377
#     endif
378
420M
        }
379
# if !LINEAR_COLOR
380
75.9M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
43.3M
            code = 0;
383
43.3M
# endif
384
43.3M
#undef STEP_LINE
385
43.3M
#undef SET_MINIMAL_WIDTH
386
43.3M
#undef CONNECT_RECTANGLES
387
43.3M
#undef FILL_TRAP_RECT
388
43.3M
#undef FILL_TRAP_RECT_DIRECT
389
43.3M
#undef FILL_TRAP_RECT_INRECT
390
43.3M
#undef YMULT_QUO
391
136M
xit:  if (code < 0 && FILL_DIRECT)
392
17
            return_error(code);
393
136M
        return_if_interrupt(dev->memory);
394
136M
        return code;
395
136M
    }
396
136M
}
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.86M
{
138
2.86M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
2.86M
    const fixed ymax = fixed_pixround(ytop);
140
141
2.86M
    if (ymin >= ymax)
142
132k
        return 0;    /* no scan lines to sample */
143
2.73M
    {
144
2.73M
        int iy = fixed2int_var(ymin);
145
2.73M
        const int iy1 = fixed2int_var(ymax);
146
2.73M
        trap_line l, r;
147
2.73M
        register int rxl, rxr;
148
2.73M
#if !LINEAR_COLOR
149
2.73M
        int ry;
150
2.73M
#endif
151
2.73M
        const fixed
152
2.73M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
2.73M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
2.73M
        const fixed /* partial pixel offset to first line to sample */
155
2.73M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
2.73M
        fixed fxl;
157
2.73M
        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.73M
            gx_color_index cindex = pdevc->colors.pure;
178
2.73M
            dev_proc_fill_rectangle((*fill_rect)) =
179
2.73M
                dev_proc(dev, fill_rectangle);
180
2.73M
# endif
181
182
2.73M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
2.73M
        l.h = left->end.y - left->start.y;
185
2.73M
        if (l.h == 0)
186
0
           return 0;
187
2.73M
        r.h = right->end.y - right->start.y;
188
2.73M
        if (r.h == 0)
189
0
           return 0;
190
2.73M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
2.73M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
2.73M
#if !LINEAR_COLOR
193
2.73M
        ry = iy;
194
2.73M
#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.73M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
2.73M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
2.73M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
2.73M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
2.73M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
2.73M
   (*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.73M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
2.73M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
2.73M
#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.73M
#define YMULT_QUO(ys, tl)\
228
2.73M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
2.73M
   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.73M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
2.73M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
2.73M
#endif
264
2.73M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
936k
            l.di = 0, l.df = 0;
267
936k
            fxl = 0;
268
1.79M
        } else {
269
1.79M
            compute_dx(&l, dxl, ysl);
270
1.79M
            fxl = YMULT_QUO(ysl, l);
271
1.79M
            l.x += fxl;
272
1.79M
        }
273
2.73M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
824k
#     if !LINEAR_COLOR
277
824k
                if (l.di == 0 && l.df == 0) {
278
769k
                    rxl = fixed2int_var(l.x);
279
769k
                    rxr = fixed2int_var(r.x);
280
769k
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
769k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
769k
                    goto xit;
283
769k
                }
284
55.0k
#     endif
285
55.0k
            r.di = 0, r.df = 0;
286
55.0k
        }
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.90M
        else if (dxr == dxl && fxl != 0) {
292
839k
            if (l.di == 0)
293
441k
                r.di = 0, r.df = l.df;
294
397k
            else
295
397k
                compute_dx(&r, dxr, ysr);
296
839k
            if (ysr == ysl && r.h == l.h)
297
839k
                r.x += fxl;
298
87
            else
299
87
                r.x += YMULT_QUO(ysr, r);
300
1.06M
        } else {
301
1.06M
            compute_dx(&r, dxr, ysr);
302
1.06M
            r.x += YMULT_QUO(ysr, r);
303
1.06M
        }
304
        /* Compute one line's worth of dx/dy. */
305
1.96M
        compute_ldx(&l, ysl);
306
1.96M
        compute_ldx(&r, ysr);
307
        /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding
308
           when the rational part is zero. Now add it back to get xl', xr' */
309
1.96M
        l.x += fixed_epsilon;
310
1.96M
        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.96M
#define rational_floor(tl)\
338
1.96M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
1.96M
#define STEP_LINE(ix, tl)\
340
1.96M
  tl.x += tl.ldi;\
341
1.96M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
1.96M
  ix = rational_floor(tl)
343
344
1.96M
        rxl = rational_floor(l);
345
1.96M
        rxr = rational_floor(r);
346
1.96M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
214M
        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
212M
                register int ixl, ixr;
365
366
212M
                STEP_LINE(ixl, l);
367
212M
                STEP_LINE(ixr, r);
368
212M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
212M
                if (ixl != rxl || ixr != rxr) {
370
40.1M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
40.1M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
40.1M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
40.1M
                    if (code < 0)
374
0
                        goto xit;
375
40.1M
                    rxl = ixl, rxr = ixr, ry = iy;
376
40.1M
                }
377
212M
#     endif
378
212M
        }
379
1.96M
# if !LINEAR_COLOR
380
1.96M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
1.96M
#undef STEP_LINE
385
1.96M
#undef SET_MINIMAL_WIDTH
386
1.96M
#undef CONNECT_RECTANGLES
387
1.96M
#undef FILL_TRAP_RECT
388
1.96M
#undef FILL_TRAP_RECT_DIRECT
389
1.96M
#undef FILL_TRAP_RECT_INRECT
390
1.96M
#undef YMULT_QUO
391
2.73M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
2.73M
        return_if_interrupt(dev->memory);
394
2.73M
        return code;
395
2.73M
    }
396
2.73M
}
gdevddrw.c:gx_fill_trapezoid_as_nd
Line
Count
Source
137
3.61M
{
138
3.61M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
3.61M
    const fixed ymax = fixed_pixround(ytop);
140
141
3.61M
    if (ymin >= ymax)
142
46.1k
        return 0;    /* no scan lines to sample */
143
3.56M
    {
144
3.56M
        int iy = fixed2int_var(ymin);
145
3.56M
        const int iy1 = fixed2int_var(ymax);
146
3.56M
        trap_line l, r;
147
3.56M
        register int rxl, rxr;
148
3.56M
#if !LINEAR_COLOR
149
3.56M
        int ry;
150
3.56M
#endif
151
3.56M
        const fixed
152
3.56M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
3.56M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
3.56M
        const fixed /* partial pixel offset to first line to sample */
155
3.56M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
3.56M
        fixed fxl;
157
3.56M
        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
3.56M
            gx_color_index cindex = pdevc->colors.pure;
178
3.56M
            dev_proc_fill_rectangle((*fill_rect)) =
179
3.56M
                dev_proc(dev, fill_rectangle);
180
3.56M
# endif
181
182
3.56M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
3.56M
        l.h = left->end.y - left->start.y;
185
3.56M
        if (l.h == 0)
186
0
           return 0;
187
3.56M
        r.h = right->end.y - right->start.y;
188
3.56M
        if (r.h == 0)
189
0
           return 0;
190
3.56M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
3.56M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
3.56M
#if !LINEAR_COLOR
193
3.56M
        ry = iy;
194
3.56M
#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.56M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
3.56M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
3.56M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
3.56M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
3.56M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
3.56M
   (*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
3.56M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
3.56M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
3.56M
#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.56M
#define YMULT_QUO(ys, tl)\
228
3.56M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
3.56M
   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.56M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
3.56M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
3.56M
#endif
264
3.56M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
785k
            l.di = 0, l.df = 0;
267
785k
            fxl = 0;
268
2.78M
        } else {
269
2.78M
            compute_dx(&l, dxl, ysl);
270
2.78M
            fxl = YMULT_QUO(ysl, l);
271
2.78M
            l.x += fxl;
272
2.78M
        }
273
3.56M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
685k
#     if !LINEAR_COLOR
277
685k
                if (l.di == 0 && l.df == 0) {
278
653k
                    rxl = fixed2int_var(l.x);
279
653k
                    rxr = fixed2int_var(r.x);
280
653k
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
653k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
653k
                    goto xit;
283
653k
                }
284
32.1k
#     endif
285
32.1k
            r.di = 0, r.df = 0;
286
32.1k
        }
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.88M
        else if (dxr == dxl && fxl != 0) {
292
428k
            if (l.di == 0)
293
257k
                r.di = 0, r.df = l.df;
294
171k
            else
295
171k
                compute_dx(&r, dxr, ysr);
296
428k
            if (ysr == ysl && r.h == l.h)
297
427k
                r.x += fxl;
298
266
            else
299
266
                r.x += YMULT_QUO(ysr, r);
300
2.45M
        } else {
301
2.45M
            compute_dx(&r, dxr, ysr);
302
2.45M
            r.x += YMULT_QUO(ysr, r);
303
2.45M
        }
304
        /* Compute one line's worth of dx/dy. */
305
2.91M
        compute_ldx(&l, ysl);
306
2.91M
        compute_ldx(&r, ysr);
307
        /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding
308
           when the rational part is zero. Now add it back to get xl', xr' */
309
2.91M
        l.x += fixed_epsilon;
310
2.91M
        r.x += fixed_epsilon;
311
# if LINEAR_COLOR
312
#     ifdef DEBUG
313
                if (check_gradient_overflow(left, right)) {
314
                    /* The caller must care of.
315
                       Checking it here looses some performance with triangles. */
316
                    return_error(gs_error_unregistered);
317
                }
318
#     endif
319
            lg.c = lgc;
320
            lg.f = lgf;
321
            lg.num = lgnum;
322
            rg.c = rgc;
323
            rg.f = rgf;
324
            rg.num = rgnum;
325
            xg.c = xgc;
326
            xg.f = xgf;
327
            xg.num = xgnum;
328
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
            if (code < 0)
330
                return code;
331
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
            if (code < 0)
333
                return code;
334
335
# endif
336
337
2.91M
#define rational_floor(tl)\
338
2.91M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
2.91M
#define STEP_LINE(ix, tl)\
340
2.91M
  tl.x += tl.ldi;\
341
2.91M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
2.91M
  ix = rational_floor(tl)
343
344
2.91M
        rxl = rational_floor(l);
345
2.91M
        rxr = rational_floor(r);
346
2.91M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
392M
        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
389M
                register int ixl, ixr;
365
366
389M
                STEP_LINE(ixl, l);
367
389M
                STEP_LINE(ixr, r);
368
389M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
389M
                if (ixl != rxl || ixr != rxr) {
370
295M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
295M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
295M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
295M
                    if (code < 0)
374
0
                        goto xit;
375
295M
                    rxl = ixl, rxr = ixr, ry = iy;
376
295M
                }
377
389M
#     endif
378
389M
        }
379
2.91M
# if !LINEAR_COLOR
380
2.91M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
2.91M
#undef STEP_LINE
385
2.91M
#undef SET_MINIMAL_WIDTH
386
2.91M
#undef CONNECT_RECTANGLES
387
2.91M
#undef FILL_TRAP_RECT
388
2.91M
#undef FILL_TRAP_RECT_DIRECT
389
2.91M
#undef FILL_TRAP_RECT_INRECT
390
2.91M
#undef YMULT_QUO
391
3.56M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
3.56M
        return_if_interrupt(dev->memory);
394
3.56M
        return code;
395
3.56M
    }
396
3.56M
}
gdevddrw.c:gx_fill_trapezoid_ns_fd
Line
Count
Source
137
39.7M
{
138
39.7M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
39.7M
    const fixed ymax = fixed_pixround(ytop);
140
141
39.7M
    if (ymin >= ymax)
142
6.67M
        return 0;    /* no scan lines to sample */
143
33.1M
    {
144
33.1M
        int iy = fixed2int_var(ymin);
145
33.1M
        const int iy1 = fixed2int_var(ymax);
146
33.1M
        trap_line l, r;
147
33.1M
        register int rxl, rxr;
148
33.1M
#if !LINEAR_COLOR
149
33.1M
        int ry;
150
33.1M
#endif
151
33.1M
        const fixed
152
33.1M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
33.1M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
33.1M
        const fixed /* partial pixel offset to first line to sample */
155
33.1M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
33.1M
        fixed fxl;
157
33.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
33.1M
            gx_color_index cindex = pdevc->colors.pure;
178
33.1M
            dev_proc_fill_rectangle((*fill_rect)) =
179
33.1M
                dev_proc(dev, fill_rectangle);
180
33.1M
# endif
181
182
33.1M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
33.1M
        l.h = left->end.y - left->start.y;
185
33.1M
        if (l.h == 0)
186
12
           return 0;
187
33.1M
        r.h = right->end.y - right->start.y;
188
33.1M
        if (r.h == 0)
189
12
           return 0;
190
33.1M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
33.1M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
33.1M
#if !LINEAR_COLOR
193
33.1M
        ry = iy;
194
33.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
33.1M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
33.1M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
33.1M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
33.1M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
33.1M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
33.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
33.1M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
33.1M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
33.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
33.1M
#define YMULT_QUO(ys, tl)\
228
33.1M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
33.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
33.1M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
33.1M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
33.1M
#endif
264
33.1M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
13.5M
            l.di = 0, l.df = 0;
267
13.5M
            fxl = 0;
268
19.5M
        } else {
269
19.5M
            compute_dx(&l, dxl, ysl);
270
19.5M
            fxl = YMULT_QUO(ysl, l);
271
19.5M
            l.x += fxl;
272
19.5M
        }
273
33.1M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
13.7M
#     if !LINEAR_COLOR
277
13.7M
                if (l.di == 0 && l.df == 0) {
278
9.34M
                    rxl = fixed2int_var(l.x);
279
9.34M
                    rxr = fixed2int_var(r.x);
280
9.34M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
9.34M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
9.34M
                    goto xit;
283
9.34M
                }
284
4.39M
#     endif
285
4.39M
            r.di = 0, r.df = 0;
286
4.39M
        }
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.3M
        else if (dxr == dxl && fxl != 0) {
292
2.63M
            if (l.di == 0)
293
594k
                r.di = 0, r.df = l.df;
294
2.04M
            else
295
2.04M
                compute_dx(&r, dxr, ysr);
296
2.63M
            if (ysr == ysl && r.h == l.h)
297
1.43M
                r.x += fxl;
298
1.20M
            else
299
1.20M
                r.x += YMULT_QUO(ysr, r);
300
16.7M
        } else {
301
16.7M
            compute_dx(&r, dxr, ysr);
302
16.7M
            r.x += YMULT_QUO(ysr, r);
303
16.7M
        }
304
        /* Compute one line's worth of dx/dy. */
305
23.7M
        compute_ldx(&l, ysl);
306
23.7M
        compute_ldx(&r, ysr);
307
        /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding
308
           when the rational part is zero. Now add it back to get xl', xr' */
309
23.7M
        l.x += fixed_epsilon;
310
23.7M
        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
23.7M
#define rational_floor(tl)\
338
23.7M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
23.7M
#define STEP_LINE(ix, tl)\
340
23.7M
  tl.x += tl.ldi;\
341
23.7M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
23.7M
  ix = rational_floor(tl)
343
344
23.7M
        rxl = rational_floor(l);
345
23.7M
        rxr = rational_floor(r);
346
23.7M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
1.94G
        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.92G
                register int ixl, ixr;
365
366
1.92G
                STEP_LINE(ixl, l);
367
1.92G
                STEP_LINE(ixr, r);
368
1.92G
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
1.92G
                if (ixl != rxl || ixr != rxr) {
370
319M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
319M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
319M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
319M
                    if (code < 0)
374
0
                        goto xit;
375
319M
                    rxl = ixl, rxr = ixr, ry = iy;
376
319M
                }
377
1.92G
#     endif
378
1.92G
        }
379
23.7M
# if !LINEAR_COLOR
380
23.7M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
23.7M
#undef STEP_LINE
385
23.7M
#undef SET_MINIMAL_WIDTH
386
23.7M
#undef CONNECT_RECTANGLES
387
23.7M
#undef FILL_TRAP_RECT
388
23.7M
#undef FILL_TRAP_RECT_DIRECT
389
23.7M
#undef FILL_TRAP_RECT_INRECT
390
23.7M
#undef YMULT_QUO
391
33.1M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
33.1M
        return_if_interrupt(dev->memory);
394
33.1M
        return code;
395
33.1M
    }
396
33.1M
}
gdevddrw.c:gx_fill_trapezoid_ns_nd
Line
Count
Source
137
74.1M
{
138
74.1M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
74.1M
    const fixed ymax = fixed_pixround(ytop);
140
141
74.1M
    if (ymin >= ymax)
142
20.6M
        return 0;    /* no scan lines to sample */
143
53.5M
    {
144
53.5M
        int iy = fixed2int_var(ymin);
145
53.5M
        const int iy1 = fixed2int_var(ymax);
146
53.5M
        trap_line l, r;
147
53.5M
        register int rxl, rxr;
148
53.5M
#if !LINEAR_COLOR
149
53.5M
        int ry;
150
53.5M
#endif
151
53.5M
        const fixed
152
53.5M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
53.5M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
53.5M
        const fixed /* partial pixel offset to first line to sample */
155
53.5M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
53.5M
        fixed fxl;
157
53.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
53.5M
            gx_color_index cindex = pdevc->colors.pure;
178
53.5M
            dev_proc_fill_rectangle((*fill_rect)) =
179
53.5M
                dev_proc(dev, fill_rectangle);
180
53.5M
# endif
181
182
53.5M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
53.5M
        l.h = left->end.y - left->start.y;
185
53.5M
        if (l.h == 0)
186
0
           return 0;
187
53.5M
        r.h = right->end.y - right->start.y;
188
53.5M
        if (r.h == 0)
189
0
           return 0;
190
53.5M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
53.5M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
53.5M
#if !LINEAR_COLOR
193
53.5M
        ry = iy;
194
53.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
53.5M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
53.5M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
53.5M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
53.5M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
53.5M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
53.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
53.5M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
53.5M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
53.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
53.5M
#define YMULT_QUO(ys, tl)\
228
53.5M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
53.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
53.5M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
53.5M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
53.5M
#endif
264
53.5M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
12.7M
            l.di = 0, l.df = 0;
267
12.7M
            fxl = 0;
268
40.8M
        } else {
269
40.8M
            compute_dx(&l, dxl, ysl);
270
40.8M
            fxl = YMULT_QUO(ysl, l);
271
40.8M
            l.x += fxl;
272
40.8M
        }
273
53.5M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
17.2M
#     if !LINEAR_COLOR
277
17.2M
                if (l.di == 0 && l.df == 0) {
278
6.26M
                    rxl = fixed2int_var(l.x);
279
6.26M
                    rxr = fixed2int_var(r.x);
280
6.26M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
6.26M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
6.26M
                    goto xit;
283
6.26M
                }
284
10.9M
#     endif
285
10.9M
            r.di = 0, r.df = 0;
286
10.9M
        }
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.3M
        else if (dxr == dxl && fxl != 0) {
292
2.56M
            if (l.di == 0)
293
340k
                r.di = 0, r.df = l.df;
294
2.22M
            else
295
2.22M
                compute_dx(&r, dxr, ysr);
296
2.56M
            if (ysr == ysl && r.h == l.h)
297
1.69M
                r.x += fxl;
298
864k
            else
299
864k
                r.x += YMULT_QUO(ysr, r);
300
33.7M
        } else {
301
33.7M
            compute_dx(&r, dxr, ysr);
302
33.7M
            r.x += YMULT_QUO(ysr, r);
303
33.7M
        }
304
        /* Compute one line's worth of dx/dy. */
305
47.3M
        compute_ldx(&l, ysl);
306
47.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
47.3M
        l.x += fixed_epsilon;
310
47.3M
        r.x += fixed_epsilon;
311
# if LINEAR_COLOR
312
#     ifdef DEBUG
313
                if (check_gradient_overflow(left, right)) {
314
                    /* The caller must care of.
315
                       Checking it here looses some performance with triangles. */
316
                    return_error(gs_error_unregistered);
317
                }
318
#     endif
319
            lg.c = lgc;
320
            lg.f = lgf;
321
            lg.num = lgnum;
322
            rg.c = rgc;
323
            rg.f = rgf;
324
            rg.num = rgnum;
325
            xg.c = xgc;
326
            xg.f = xgf;
327
            xg.num = xgnum;
328
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
            if (code < 0)
330
                return code;
331
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
            if (code < 0)
333
                return code;
334
335
# endif
336
337
47.3M
#define rational_floor(tl)\
338
47.3M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
47.3M
#define STEP_LINE(ix, tl)\
340
47.3M
  tl.x += tl.ldi;\
341
47.3M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
47.3M
  ix = rational_floor(tl)
343
344
47.3M
        rxl = rational_floor(l);
345
47.3M
        rxr = rational_floor(r);
346
47.3M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
1.66G
        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.61G
                register int ixl, ixr;
365
366
1.61G
                STEP_LINE(ixl, l);
367
1.61G
                STEP_LINE(ixr, r);
368
1.61G
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
1.61G
                if (ixl != rxl || ixr != rxr) {
370
1.19G
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
1.19G
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
1.19G
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
1.19G
                    if (code < 0)
374
0
                        goto xit;
375
1.19G
                    rxl = ixl, rxr = ixr, ry = iy;
376
1.19G
                }
377
1.61G
#     endif
378
1.61G
        }
379
47.3M
# if !LINEAR_COLOR
380
47.3M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
47.3M
#undef STEP_LINE
385
47.3M
#undef SET_MINIMAL_WIDTH
386
47.3M
#undef CONNECT_RECTANGLES
387
47.3M
#undef FILL_TRAP_RECT
388
47.3M
#undef FILL_TRAP_RECT_DIRECT
389
47.3M
#undef FILL_TRAP_RECT_INRECT
390
47.3M
#undef YMULT_QUO
391
53.5M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
53.5M
        return_if_interrupt(dev->memory);
394
53.5M
        return code;
395
53.5M
    }
396
53.5M
}
gdevddrw.c:gx_fill_trapezoid_as_lc
Line
Count
Source
137
2.64M
{
138
2.64M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
2.64M
    const fixed ymax = fixed_pixround(ytop);
140
141
2.64M
    if (ymin >= ymax)
142
391k
        return 0;    /* no scan lines to sample */
143
2.25M
    {
144
2.25M
        int iy = fixed2int_var(ymin);
145
2.25M
        const int iy1 = fixed2int_var(ymax);
146
2.25M
        trap_line l, r;
147
2.25M
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
2.25M
        const fixed
152
2.25M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
2.25M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
2.25M
        const fixed /* partial pixel offset to first line to sample */
155
2.25M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
2.25M
        fixed fxl;
157
2.25M
        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
2.25M
# if LINEAR_COLOR
165
2.25M
            int num_components = dev->color_info.num_components;
166
2.25M
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
2.25M
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
2.25M
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
2.25M
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
2.25M
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
2.25M
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
2.25M
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
2.25M
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
2.25M
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
2.25M
            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
2.25M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
2.25M
        l.h = left->end.y - left->start.y;
185
2.25M
        if (l.h == 0)
186
0
           return 0;
187
2.25M
        r.h = right->end.y - right->start.y;
188
2.25M
        if (r.h == 0)
189
0
           return 0;
190
2.25M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
2.25M
        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
2.25M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
2.25M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
2.25M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
2.25M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
2.25M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
2.25M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
2.25M
#if LINEAR_COLOR
210
2.25M
#   define FILL_TRAP_RECT(x,y,w,h)\
211
2.25M
        (!(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
2.25M
#define YMULT_QUO(ys, tl)\
228
2.25M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
2.25M
   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.25M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
2.25M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
2.25M
#endif
264
2.25M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
1.25M
            l.di = 0, l.df = 0;
267
1.25M
            fxl = 0;
268
1.25M
        } else {
269
994k
            compute_dx(&l, dxl, ysl);
270
994k
            fxl = YMULT_QUO(ysl, l);
271
994k
            l.x += fxl;
272
994k
        }
273
2.25M
        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.25M
            r.di = 0, r.df = 0;
286
1.25M
        }
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
993k
        else if (dxr == dxl && fxl != 0) {
292
570k
            if (l.di == 0)
293
210k
                r.di = 0, r.df = l.df;
294
359k
            else
295
359k
                compute_dx(&r, dxr, ysr);
296
570k
            if (ysr == ysl && r.h == l.h)
297
570k
                r.x += fxl;
298
98
            else
299
98
                r.x += YMULT_QUO(ysr, r);
300
570k
        } else {
301
423k
            compute_dx(&r, dxr, ysr);
302
423k
            r.x += YMULT_QUO(ysr, r);
303
423k
        }
304
        /* Compute one line's worth of dx/dy. */
305
2.25M
        compute_ldx(&l, ysl);
306
2.25M
        compute_ldx(&r, ysr);
307
        /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding
308
           when the rational part is zero. Now add it back to get xl', xr' */
309
2.25M
        l.x += fixed_epsilon;
310
2.25M
        r.x += fixed_epsilon;
311
2.25M
# 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
2.25M
            lg.c = lgc;
320
2.25M
            lg.f = lgf;
321
2.25M
            lg.num = lgnum;
322
2.25M
            rg.c = rgc;
323
2.25M
            rg.f = rgf;
324
2.25M
            rg.num = rgnum;
325
2.25M
            xg.c = xgc;
326
2.25M
            xg.f = xgf;
327
2.25M
            xg.num = xgnum;
328
2.25M
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
2.25M
            if (code < 0)
330
0
                return code;
331
2.25M
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
2.25M
            if (code < 0)
333
0
                return code;
334
335
2.25M
# endif
336
337
2.25M
#define rational_floor(tl)\
338
2.25M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
2.25M
#define STEP_LINE(ix, tl)\
340
2.25M
  tl.x += tl.ldi;\
341
2.25M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
2.25M
  ix = rational_floor(tl)
343
344
2.25M
        rxl = rational_floor(l);
345
2.25M
        rxr = rational_floor(r);
346
2.25M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
58.7M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
58.7M
#     if LINEAR_COLOR
349
58.7M
                if (rxl != rxr) {
350
38.3M
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
38.3M
                    if (code < 0)
352
0
                        goto xit;
353
38.3M
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
38.3M
                    if (code < 0)
355
4
                        goto xit;
356
38.3M
                }
357
58.7M
                if (++iy == iy1)
358
2.25M
                    break;
359
56.5M
                STEP_LINE(rxl, l);
360
56.5M
                STEP_LINE(rxr, r);
361
56.5M
                step_gradient(&lg, num_components);
362
56.5M
                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
56.5M
        }
379
# if !LINEAR_COLOR
380
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
2.25M
            code = 0;
383
2.25M
# endif
384
2.25M
#undef STEP_LINE
385
2.25M
#undef SET_MINIMAL_WIDTH
386
2.25M
#undef CONNECT_RECTANGLES
387
2.25M
#undef FILL_TRAP_RECT
388
2.25M
#undef FILL_TRAP_RECT_DIRECT
389
2.25M
#undef FILL_TRAP_RECT_INRECT
390
2.25M
#undef YMULT_QUO
391
2.25M
xit:  if (code < 0 && FILL_DIRECT)
392
4
            return_error(code);
393
2.25M
        return_if_interrupt(dev->memory);
394
2.25M
        return code;
395
2.25M
    }
396
2.25M
}
gdevddrw.c:gx_fill_trapezoid_ns_lc
Line
Count
Source
137
68.7M
{
138
68.7M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
68.7M
    const fixed ymax = fixed_pixround(ytop);
140
141
68.7M
    if (ymin >= ymax)
142
27.6M
        return 0;    /* no scan lines to sample */
143
41.0M
    {
144
41.0M
        int iy = fixed2int_var(ymin);
145
41.0M
        const int iy1 = fixed2int_var(ymax);
146
41.0M
        trap_line l, r;
147
41.0M
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
41.0M
        const fixed
152
41.0M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
41.0M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
41.0M
        const fixed /* partial pixel offset to first line to sample */
155
41.0M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
41.0M
        fixed fxl;
157
41.0M
        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
41.0M
# if LINEAR_COLOR
165
41.0M
            int num_components = dev->color_info.num_components;
166
41.0M
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
41.0M
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
41.0M
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
41.0M
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
41.0M
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
41.0M
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
41.0M
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
41.0M
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
41.0M
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
41.0M
            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
41.0M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
41.0M
        l.h = left->end.y - left->start.y;
185
41.0M
        if (l.h == 0)
186
0
           return 0;
187
41.0M
        r.h = right->end.y - right->start.y;
188
41.0M
        if (r.h == 0)
189
0
           return 0;
190
41.0M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
41.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
41.0M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
41.0M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
41.0M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
41.0M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
41.0M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
41.0M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
41.0M
#if LINEAR_COLOR
210
41.0M
#   define FILL_TRAP_RECT(x,y,w,h)\
211
41.0M
        (!(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
41.0M
#define YMULT_QUO(ys, tl)\
228
41.0M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
41.0M
   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
41.0M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
41.0M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
41.0M
#endif
264
41.0M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
9.19M
            l.di = 0, l.df = 0;
267
9.19M
            fxl = 0;
268
31.8M
        } else {
269
31.8M
            compute_dx(&l, dxl, ysl);
270
31.8M
            fxl = YMULT_QUO(ysl, l);
271
31.8M
            l.x += fxl;
272
31.8M
        }
273
41.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
                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
9.16M
            r.di = 0, r.df = 0;
286
9.16M
        }
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
31.8M
        else if (dxr == dxl && fxl != 0) {
292
1.97M
            if (l.di == 0)
293
629k
                r.di = 0, r.df = l.df;
294
1.34M
            else
295
1.34M
                compute_dx(&r, dxr, ysr);
296
1.97M
            if (ysr == ysl && r.h == l.h)
297
1.29M
                r.x += fxl;
298
685k
            else
299
685k
                r.x += YMULT_QUO(ysr, r);
300
29.9M
        } else {
301
29.9M
            compute_dx(&r, dxr, ysr);
302
29.9M
            r.x += YMULT_QUO(ysr, r);
303
29.9M
        }
304
        /* Compute one line's worth of dx/dy. */
305
41.0M
        compute_ldx(&l, ysl);
306
41.0M
        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
41.0M
        l.x += fixed_epsilon;
310
41.0M
        r.x += fixed_epsilon;
311
41.0M
# 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
41.0M
            lg.c = lgc;
320
41.0M
            lg.f = lgf;
321
41.0M
            lg.num = lgnum;
322
41.0M
            rg.c = rgc;
323
41.0M
            rg.f = rgf;
324
41.0M
            rg.num = rgnum;
325
41.0M
            xg.c = xgc;
326
41.0M
            xg.f = xgf;
327
41.0M
            xg.num = xgnum;
328
41.0M
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
41.0M
            if (code < 0)
330
0
                return code;
331
41.0M
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
41.0M
            if (code < 0)
333
0
                return code;
334
335
41.0M
# endif
336
337
41.0M
#define rational_floor(tl)\
338
41.0M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
41.0M
#define STEP_LINE(ix, tl)\
340
41.0M
  tl.x += tl.ldi;\
341
41.0M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
41.0M
  ix = rational_floor(tl)
343
344
41.0M
        rxl = rational_floor(l);
345
41.0M
        rxr = rational_floor(r);
346
41.0M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
405M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
405M
#     if LINEAR_COLOR
349
405M
                if (rxl != rxr) {
350
84.5M
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
84.5M
                    if (code < 0)
352
0
                        goto xit;
353
84.5M
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
84.5M
                    if (code < 0)
355
13
                        goto xit;
356
84.5M
                }
357
405M
                if (++iy == iy1)
358
41.0M
                    break;
359
364M
                STEP_LINE(rxl, l);
360
364M
                STEP_LINE(rxr, r);
361
364M
                step_gradient(&lg, num_components);
362
364M
                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
364M
        }
379
# if !LINEAR_COLOR
380
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
41.0M
            code = 0;
383
41.0M
# endif
384
41.0M
#undef STEP_LINE
385
41.0M
#undef SET_MINIMAL_WIDTH
386
41.0M
#undef CONNECT_RECTANGLES
387
41.0M
#undef FILL_TRAP_RECT
388
41.0M
#undef FILL_TRAP_RECT_DIRECT
389
41.0M
#undef FILL_TRAP_RECT_INRECT
390
41.0M
#undef YMULT_QUO
391
41.0M
xit:  if (code < 0 && FILL_DIRECT)
392
13
            return_error(code);
393
41.0M
        return_if_interrupt(dev->memory);
394
41.0M
        return code;
395
41.0M
    }
396
41.0M
}
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