Coverage Report

Created: 2026-07-24 07:44

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
119M
{
138
119M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
119M
    const fixed ymax = fixed_pixround(ytop);
140
141
119M
    if (ymin >= ymax)
142
27.2M
        return 0;    /* no scan lines to sample */
143
92.4M
    {
144
92.4M
        int iy = fixed2int_var(ymin);
145
92.4M
        const int iy1 = fixed2int_var(ymax);
146
92.4M
        trap_line l, r;
147
92.4M
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
92.4M
        const fixed
152
92.4M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
92.4M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
92.4M
        const fixed /* partial pixel offset to first line to sample */
155
92.4M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
92.4M
        fixed fxl;
157
92.4M
        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
70.5M
            dev_proc_fill_rectangle((*fill_rect)) =
179
70.5M
                dev_proc(dev, fill_rectangle);
180
# endif
181
182
92.4M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
92.4M
        l.h = left->end.y - left->start.y;
185
92.4M
        if (l.h == 0)
186
0
           return 0;
187
92.4M
        r.h = right->end.y - right->start.y;
188
92.4M
        if (r.h == 0)
189
0
           return 0;
190
92.4M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
92.4M
        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
92.4M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
865M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
865M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
92.4M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
196M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
196M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
#if LINEAR_COLOR
210
#   define FILL_TRAP_RECT(x,y,w,h)\
211
51.5M
        (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den))
212
#else
213
#   define FILL_TRAP_RECT(x,y,w,h)\
214
1.06G
        (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
92.4M
#define YMULT_QUO(ys, tl)\
228
131M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
131M
   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.19G
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
1.98G
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
#endif
264
92.4M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
22.9M
            l.di = 0, l.df = 0;
267
22.9M
            fxl = 0;
268
69.5M
        } else {
269
69.5M
            compute_dx(&l, dxl, ysl);
270
69.5M
            fxl = YMULT_QUO(ysl, l);
271
69.5M
            l.x += fxl;
272
69.5M
        }
273
92.4M
        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
21.9M
                if (l.di == 0 && l.df == 0) {
278
10.1M
                    rxl = fixed2int_var(l.x);
279
10.1M
                    rxr = fixed2int_var(r.x);
280
10.1M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
10.1M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
10.1M
                    goto xit;
283
10.1M
                }
284
11.8M
#     endif
285
11.8M
            r.di = 0, r.df = 0;
286
11.8M
        }
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
66.1M
        else if (dxr == dxl && fxl != 0) {
292
6.59M
            if (l.di == 0)
293
1.85M
                r.di = 0, r.df = l.df;
294
4.73M
            else
295
4.73M
                compute_dx(&r, dxr, ysr);
296
6.59M
            if (ysr == ysl && r.h == l.h)
297
4.35M
                r.x += fxl;
298
2.24M
            else
299
2.24M
                r.x += YMULT_QUO(ysr, r);
300
59.5M
        } else {
301
59.5M
            compute_dx(&r, dxr, ysr);
302
59.5M
            r.x += YMULT_QUO(ysr, r);
303
59.5M
        }
304
        /* Compute one line's worth of dx/dy. */
305
60.4M
        compute_ldx(&l, ysl);
306
60.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
82.3M
        l.x += fixed_epsilon;
310
82.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
21.9M
            if (code < 0)
330
0
                return code;
331
21.9M
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
21.9M
            if (code < 0)
333
0
                return code;
334
335
21.9M
# endif
336
337
21.9M
#define rational_floor(tl)\
338
5.34G
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
21.9M
#define STEP_LINE(ix, tl)\
340
5.15G
  tl.x += tl.ldi;\
341
5.15G
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
5.17G
  ix = rational_floor(tl)
343
344
82.3M
        rxl = rational_floor(l);
345
82.3M
        rxr = rational_floor(r);
346
82.3M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
2.65G
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
#     if LINEAR_COLOR
349
499M
                if (rxl != rxr) {
350
51.5M
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
51.5M
                    if (code < 0)
352
0
                        goto xit;
353
51.5M
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
51.5M
                    if (code < 0)
355
17
                        goto xit;
356
51.5M
                }
357
499M
                if (++iy == iy1)
358
21.9M
                    break;
359
478M
                STEP_LINE(rxl, l);
360
478M
                STEP_LINE(rxr, r);
361
478M
                step_gradient(&lg, num_components);
362
478M
                step_gradient(&rg, num_components);
363
#     else
364
                register int ixl, ixr;
365
366
2.09G
                STEP_LINE(ixl, l);
367
2.09G
                STEP_LINE(ixr, r);
368
2.09G
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
2.09G
                if (ixl != rxl || ixr != rxr) {
370
991M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
991M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
991M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
991M
                    if (code < 0)
374
0
                        goto xit;
375
991M
                    rxl = ixl, rxr = ixr, ry = iy;
376
991M
                }
377
#     endif
378
478M
        }
379
# if !LINEAR_COLOR
380
60.4M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
21.9M
            code = 0;
383
21.9M
# endif
384
21.9M
#undef STEP_LINE
385
21.9M
#undef SET_MINIMAL_WIDTH
386
21.9M
#undef CONNECT_RECTANGLES
387
21.9M
#undef FILL_TRAP_RECT
388
21.9M
#undef FILL_TRAP_RECT_DIRECT
389
21.9M
#undef FILL_TRAP_RECT_INRECT
390
21.9M
#undef YMULT_QUO
391
92.4M
xit:  if (code < 0 && FILL_DIRECT)
392
17
            return_error(code);
393
92.4M
        return_if_interrupt(dev->memory);
394
92.4M
        return code;
395
92.4M
    }
396
92.4M
}
Unexecuted instantiation: gx_fill_trapezoid_cf_fd
Unexecuted instantiation: gx_fill_trapezoid_cf_nd
gdevddrw.c:gx_fill_trapezoid_as_fd
Line
Count
Source
137
1.41M
{
138
1.41M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
1.41M
    const fixed ymax = fixed_pixround(ytop);
140
141
1.41M
    if (ymin >= ymax)
142
81.1k
        return 0;    /* no scan lines to sample */
143
1.33M
    {
144
1.33M
        int iy = fixed2int_var(ymin);
145
1.33M
        const int iy1 = fixed2int_var(ymax);
146
1.33M
        trap_line l, r;
147
1.33M
        register int rxl, rxr;
148
1.33M
#if !LINEAR_COLOR
149
1.33M
        int ry;
150
1.33M
#endif
151
1.33M
        const fixed
152
1.33M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
1.33M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
1.33M
        const fixed /* partial pixel offset to first line to sample */
155
1.33M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
1.33M
        fixed fxl;
157
1.33M
        int code;
158
# if CONTIGUOUS_FILL
159
            const bool peak0 = ((flags & 1) != 0);
160
            const bool peak1 = ((flags & 2) != 0);
161
            int peak_y0 = ybot + fixed_half;
162
            int peak_y1 = ytop - fixed_half;
163
# endif
164
# if LINEAR_COLOR
165
            int num_components = dev->color_info.num_components;
166
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
            trap_gradient lg, rg, xg;
176
# else
177
1.33M
            gx_color_index cindex = pdevc->colors.pure;
178
1.33M
            dev_proc_fill_rectangle((*fill_rect)) =
179
1.33M
                dev_proc(dev, fill_rectangle);
180
1.33M
# endif
181
182
1.33M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
1.33M
        l.h = left->end.y - left->start.y;
185
1.33M
        if (l.h == 0)
186
0
           return 0;
187
1.33M
        r.h = right->end.y - right->start.y;
188
1.33M
        if (r.h == 0)
189
0
           return 0;
190
1.33M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
1.33M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
1.33M
#if !LINEAR_COLOR
193
1.33M
        ry = iy;
194
1.33M
#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.33M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
1.33M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
1.33M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
1.33M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
1.33M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
1.33M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
#if LINEAR_COLOR
210
#   define FILL_TRAP_RECT(x,y,w,h)\
211
        (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den))
212
#else
213
1.33M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
1.33M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
1.33M
#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.33M
#define YMULT_QUO(ys, tl)\
228
1.33M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
1.33M
   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.33M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
1.33M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
1.33M
#endif
264
1.33M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
227k
            l.di = 0, l.df = 0;
267
227k
            fxl = 0;
268
1.10M
        } else {
269
1.10M
            compute_dx(&l, dxl, ysl);
270
1.10M
            fxl = YMULT_QUO(ysl, l);
271
1.10M
            l.x += fxl;
272
1.10M
        }
273
1.33M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
215k
#     if !LINEAR_COLOR
277
215k
                if (l.di == 0 && l.df == 0) {
278
202k
                    rxl = fixed2int_var(l.x);
279
202k
                    rxr = fixed2int_var(r.x);
280
202k
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
202k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
202k
                    goto xit;
283
202k
                }
284
13.4k
#     endif
285
13.4k
            r.di = 0, r.df = 0;
286
13.4k
        }
287
        /*
288
         * The test for fxl != 0 is required because the right edge might
289
         * cross some pixel centers even if the left edge doesn't.
290
         */
291
1.11M
        else if (dxr == dxl && fxl != 0) {
292
835k
            if (l.di == 0)
293
407k
                r.di = 0, r.df = l.df;
294
427k
            else
295
427k
                compute_dx(&r, dxr, ysr);
296
835k
            if (ysr == ysl && r.h == l.h)
297
835k
                r.x += fxl;
298
57
            else
299
57
                r.x += YMULT_QUO(ysr, r);
300
835k
        } else {
301
280k
            compute_dx(&r, dxr, ysr);
302
280k
            r.x += YMULT_QUO(ysr, r);
303
280k
        }
304
        /* Compute one line's worth of dx/dy. */
305
1.12M
        compute_ldx(&l, ysl);
306
1.12M
        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.12M
        l.x += fixed_epsilon;
310
1.12M
        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.12M
#define rational_floor(tl)\
338
1.12M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
1.12M
#define STEP_LINE(ix, tl)\
340
1.12M
  tl.x += tl.ldi;\
341
1.12M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
1.12M
  ix = rational_floor(tl)
343
344
1.12M
        rxl = rational_floor(l);
345
1.12M
        rxr = rational_floor(r);
346
1.12M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
162M
        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
161M
                register int ixl, ixr;
365
366
161M
                STEP_LINE(ixl, l);
367
161M
                STEP_LINE(ixr, r);
368
161M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
161M
                if (ixl != rxl || ixr != rxr) {
370
21.7M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
21.7M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
21.7M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
21.7M
                    if (code < 0)
374
0
                        goto xit;
375
21.7M
                    rxl = ixl, rxr = ixr, ry = iy;
376
21.7M
                }
377
161M
#     endif
378
161M
        }
379
1.12M
# if !LINEAR_COLOR
380
1.12M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
1.12M
#undef STEP_LINE
385
1.12M
#undef SET_MINIMAL_WIDTH
386
1.12M
#undef CONNECT_RECTANGLES
387
1.12M
#undef FILL_TRAP_RECT
388
1.12M
#undef FILL_TRAP_RECT_DIRECT
389
1.12M
#undef FILL_TRAP_RECT_INRECT
390
1.12M
#undef YMULT_QUO
391
1.33M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
1.33M
        return_if_interrupt(dev->memory);
394
1.33M
        return code;
395
1.33M
    }
396
1.33M
}
gdevddrw.c:gx_fill_trapezoid_as_nd
Line
Count
Source
137
1.89M
{
138
1.89M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
1.89M
    const fixed ymax = fixed_pixround(ytop);
140
141
1.89M
    if (ymin >= ymax)
142
22.3k
        return 0;    /* no scan lines to sample */
143
1.87M
    {
144
1.87M
        int iy = fixed2int_var(ymin);
145
1.87M
        const int iy1 = fixed2int_var(ymax);
146
1.87M
        trap_line l, r;
147
1.87M
        register int rxl, rxr;
148
1.87M
#if !LINEAR_COLOR
149
1.87M
        int ry;
150
1.87M
#endif
151
1.87M
        const fixed
152
1.87M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
1.87M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
1.87M
        const fixed /* partial pixel offset to first line to sample */
155
1.87M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
1.87M
        fixed fxl;
157
1.87M
        int code;
158
# if CONTIGUOUS_FILL
159
            const bool peak0 = ((flags & 1) != 0);
160
            const bool peak1 = ((flags & 2) != 0);
161
            int peak_y0 = ybot + fixed_half;
162
            int peak_y1 = ytop - fixed_half;
163
# endif
164
# if LINEAR_COLOR
165
            int num_components = dev->color_info.num_components;
166
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
            trap_gradient lg, rg, xg;
176
# else
177
1.87M
            gx_color_index cindex = pdevc->colors.pure;
178
1.87M
            dev_proc_fill_rectangle((*fill_rect)) =
179
1.87M
                dev_proc(dev, fill_rectangle);
180
1.87M
# endif
181
182
1.87M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
1.87M
        l.h = left->end.y - left->start.y;
185
1.87M
        if (l.h == 0)
186
0
           return 0;
187
1.87M
        r.h = right->end.y - right->start.y;
188
1.87M
        if (r.h == 0)
189
0
           return 0;
190
1.87M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
1.87M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
1.87M
#if !LINEAR_COLOR
193
1.87M
        ry = iy;
194
1.87M
#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.87M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
1.87M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
1.87M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
1.87M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
1.87M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
1.87M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
#if LINEAR_COLOR
210
#   define FILL_TRAP_RECT(x,y,w,h)\
211
        (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den))
212
#else
213
1.87M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
1.87M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
1.87M
#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.87M
#define YMULT_QUO(ys, tl)\
228
1.87M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
1.87M
   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.87M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
1.87M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
1.87M
#endif
264
1.87M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
355k
            l.di = 0, l.df = 0;
267
355k
            fxl = 0;
268
1.52M
        } else {
269
1.52M
            compute_dx(&l, dxl, ysl);
270
1.52M
            fxl = YMULT_QUO(ysl, l);
271
1.52M
            l.x += fxl;
272
1.52M
        }
273
1.87M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
336k
#     if !LINEAR_COLOR
277
336k
                if (l.di == 0 && l.df == 0) {
278
319k
                    rxl = fixed2int_var(l.x);
279
319k
                    rxr = fixed2int_var(r.x);
280
319k
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
319k
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
319k
                    goto xit;
283
319k
                }
284
17.0k
#     endif
285
17.0k
            r.di = 0, r.df = 0;
286
17.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.54M
        else if (dxr == dxl && fxl != 0) {
292
302k
            if (l.di == 0)
293
174k
                r.di = 0, r.df = l.df;
294
128k
            else
295
128k
                compute_dx(&r, dxr, ysr);
296
302k
            if (ysr == ysl && r.h == l.h)
297
302k
                r.x += fxl;
298
186
            else
299
186
                r.x += YMULT_QUO(ysr, r);
300
1.23M
        } else {
301
1.23M
            compute_dx(&r, dxr, ysr);
302
1.23M
            r.x += YMULT_QUO(ysr, r);
303
1.23M
        }
304
        /* Compute one line's worth of dx/dy. */
305
1.55M
        compute_ldx(&l, ysl);
306
1.55M
        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.55M
        l.x += fixed_epsilon;
310
1.55M
        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.55M
#define rational_floor(tl)\
338
1.55M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
1.55M
#define STEP_LINE(ix, tl)\
340
1.55M
  tl.x += tl.ldi;\
341
1.55M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
1.55M
  ix = rational_floor(tl)
343
344
1.55M
        rxl = rational_floor(l);
345
1.55M
        rxr = rational_floor(r);
346
1.55M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
161M
        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
159M
                register int ixl, ixr;
365
366
159M
                STEP_LINE(ixl, l);
367
159M
                STEP_LINE(ixr, r);
368
159M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
159M
                if (ixl != rxl || ixr != rxr) {
370
114M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
114M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
114M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
114M
                    if (code < 0)
374
0
                        goto xit;
375
114M
                    rxl = ixl, rxr = ixr, ry = iy;
376
114M
                }
377
159M
#     endif
378
159M
        }
379
1.55M
# if !LINEAR_COLOR
380
1.55M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
1.55M
#undef STEP_LINE
385
1.55M
#undef SET_MINIMAL_WIDTH
386
1.55M
#undef CONNECT_RECTANGLES
387
1.55M
#undef FILL_TRAP_RECT
388
1.55M
#undef FILL_TRAP_RECT_DIRECT
389
1.55M
#undef FILL_TRAP_RECT_INRECT
390
1.55M
#undef YMULT_QUO
391
1.87M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
1.87M
        return_if_interrupt(dev->memory);
394
1.87M
        return code;
395
1.87M
    }
396
1.87M
}
gdevddrw.c:gx_fill_trapezoid_ns_fd
Line
Count
Source
137
25.4M
{
138
25.4M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
25.4M
    const fixed ymax = fixed_pixround(ytop);
140
141
25.4M
    if (ymin >= ymax)
142
1.71M
        return 0;    /* no scan lines to sample */
143
23.7M
    {
144
23.7M
        int iy = fixed2int_var(ymin);
145
23.7M
        const int iy1 = fixed2int_var(ymax);
146
23.7M
        trap_line l, r;
147
23.7M
        register int rxl, rxr;
148
23.7M
#if !LINEAR_COLOR
149
23.7M
        int ry;
150
23.7M
#endif
151
23.7M
        const fixed
152
23.7M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
23.7M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
23.7M
        const fixed /* partial pixel offset to first line to sample */
155
23.7M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
23.7M
        fixed fxl;
157
23.7M
        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
23.7M
            gx_color_index cindex = pdevc->colors.pure;
178
23.7M
            dev_proc_fill_rectangle((*fill_rect)) =
179
23.7M
                dev_proc(dev, fill_rectangle);
180
23.7M
# endif
181
182
23.7M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
23.7M
        l.h = left->end.y - left->start.y;
185
23.7M
        if (l.h == 0)
186
0
           return 0;
187
23.7M
        r.h = right->end.y - right->start.y;
188
23.7M
        if (r.h == 0)
189
0
           return 0;
190
23.7M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
23.7M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
23.7M
#if !LINEAR_COLOR
193
23.7M
        ry = iy;
194
23.7M
#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
23.7M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
23.7M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
23.7M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
23.7M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
23.7M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
23.7M
   (*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
23.7M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
23.7M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
23.7M
#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
23.7M
#define YMULT_QUO(ys, tl)\
228
23.7M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
23.7M
   fixed_mult_quo(ys, tl.df, tl.h))
230
231
#if CONTIGUOUS_FILL
232
/*
233
 * If left and right boundary round to same pixel index,
234
 * we would not paing the scan and would get a dropout.
235
 * Check for this case and choose one of two pixels
236
 * which is closer to the "axis". We need to exclude
237
 * 'peak' because it would paint an excessive pixel.
238
 */
239
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \
240
    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
23.7M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
23.7M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
23.7M
#endif
264
23.7M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
9.04M
            l.di = 0, l.df = 0;
267
9.04M
            fxl = 0;
268
14.7M
        } else {
269
14.7M
            compute_dx(&l, dxl, ysl);
270
14.7M
            fxl = YMULT_QUO(ysl, l);
271
14.7M
            l.x += fxl;
272
14.7M
        }
273
23.7M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
9.21M
#     if !LINEAR_COLOR
277
9.21M
                if (l.di == 0 && l.df == 0) {
278
5.29M
                    rxl = fixed2int_var(l.x);
279
5.29M
                    rxr = fixed2int_var(r.x);
280
5.29M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
5.29M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
5.29M
                    goto xit;
283
5.29M
                }
284
3.91M
#     endif
285
3.91M
            r.di = 0, r.df = 0;
286
3.91M
        }
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
14.5M
        else if (dxr == dxl && fxl != 0) {
292
1.63M
            if (l.di == 0)
293
505k
                r.di = 0, r.df = l.df;
294
1.12M
            else
295
1.12M
                compute_dx(&r, dxr, ysr);
296
1.63M
            if (ysr == ysl && r.h == l.h)
297
1.04M
                r.x += fxl;
298
588k
            else
299
588k
                r.x += YMULT_QUO(ysr, r);
300
12.9M
        } else {
301
12.9M
            compute_dx(&r, dxr, ysr);
302
12.9M
            r.x += YMULT_QUO(ysr, r);
303
12.9M
        }
304
        /* Compute one line's worth of dx/dy. */
305
18.4M
        compute_ldx(&l, ysl);
306
18.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
18.4M
        l.x += fixed_epsilon;
310
18.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
18.4M
#define rational_floor(tl)\
338
18.4M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
18.4M
#define STEP_LINE(ix, tl)\
340
18.4M
  tl.x += tl.ldi;\
341
18.4M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
18.4M
  ix = rational_floor(tl)
343
344
18.4M
        rxl = rational_floor(l);
345
18.4M
        rxr = rational_floor(r);
346
18.4M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
712M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
#     if LINEAR_COLOR
349
                if (rxl != rxr) {
350
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
                    if (code < 0)
352
                        goto xit;
353
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
                    if (code < 0)
355
                        goto xit;
356
                }
357
                if (++iy == iy1)
358
                    break;
359
                STEP_LINE(rxl, l);
360
                STEP_LINE(rxr, r);
361
                step_gradient(&lg, num_components);
362
                step_gradient(&rg, num_components);
363
#     else
364
694M
                register int ixl, ixr;
365
366
694M
                STEP_LINE(ixl, l);
367
694M
                STEP_LINE(ixr, r);
368
694M
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
694M
                if (ixl != rxl || ixr != rxr) {
370
149M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
149M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
149M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
149M
                    if (code < 0)
374
0
                        goto xit;
375
149M
                    rxl = ixl, rxr = ixr, ry = iy;
376
149M
                }
377
694M
#     endif
378
694M
        }
379
18.4M
# if !LINEAR_COLOR
380
18.4M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
18.4M
#undef STEP_LINE
385
18.4M
#undef SET_MINIMAL_WIDTH
386
18.4M
#undef CONNECT_RECTANGLES
387
18.4M
#undef FILL_TRAP_RECT
388
18.4M
#undef FILL_TRAP_RECT_DIRECT
389
18.4M
#undef FILL_TRAP_RECT_INRECT
390
18.4M
#undef YMULT_QUO
391
23.7M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
23.7M
        return_if_interrupt(dev->memory);
394
23.7M
        return code;
395
23.7M
    }
396
23.7M
}
gdevddrw.c:gx_fill_trapezoid_ns_nd
Line
Count
Source
137
57.8M
{
138
57.8M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
57.8M
    const fixed ymax = fixed_pixround(ytop);
140
141
57.8M
    if (ymin >= ymax)
142
14.2M
        return 0;    /* no scan lines to sample */
143
43.5M
    {
144
43.5M
        int iy = fixed2int_var(ymin);
145
43.5M
        const int iy1 = fixed2int_var(ymax);
146
43.5M
        trap_line l, r;
147
43.5M
        register int rxl, rxr;
148
43.5M
#if !LINEAR_COLOR
149
43.5M
        int ry;
150
43.5M
#endif
151
43.5M
        const fixed
152
43.5M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
43.5M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
43.5M
        const fixed /* partial pixel offset to first line to sample */
155
43.5M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
43.5M
        fixed fxl;
157
43.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
43.5M
            gx_color_index cindex = pdevc->colors.pure;
178
43.5M
            dev_proc_fill_rectangle((*fill_rect)) =
179
43.5M
                dev_proc(dev, fill_rectangle);
180
43.5M
# endif
181
182
43.5M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
43.5M
        l.h = left->end.y - left->start.y;
185
43.5M
        if (l.h == 0)
186
0
           return 0;
187
43.5M
        r.h = right->end.y - right->start.y;
188
43.5M
        if (r.h == 0)
189
0
           return 0;
190
43.5M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
43.5M
        r.x = x0r + (fixed_half - fixed_epsilon);
192
43.5M
#if !LINEAR_COLOR
193
43.5M
        ry = iy;
194
43.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
43.5M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
43.5M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
43.5M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
43.5M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
43.5M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
43.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
43.5M
#   define FILL_TRAP_RECT(x,y,w,h)\
214
43.5M
        (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h))
215
43.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
43.5M
#define YMULT_QUO(ys, tl)\
228
43.5M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
43.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
43.5M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
43.5M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
43.5M
#endif
264
43.5M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
8.95M
            l.di = 0, l.df = 0;
267
8.95M
            fxl = 0;
268
34.6M
        } else {
269
34.6M
            compute_dx(&l, dxl, ysl);
270
34.6M
            fxl = YMULT_QUO(ysl, l);
271
34.6M
            l.x += fxl;
272
34.6M
        }
273
43.5M
        if (fixed_floor(r.x) == fixed_pixround(x1r)) {
274
            /* Right edge is vertical.  If both are vertical, */
275
            /* we have a rectangle. */
276
12.2M
#     if !LINEAR_COLOR
277
12.2M
                if (l.di == 0 && l.df == 0) {
278
4.29M
                    rxl = fixed2int_var(l.x);
279
4.29M
                    rxr = fixed2int_var(r.x);
280
4.29M
                    SET_MINIMAL_WIDTH(rxl, rxr, l, r);
281
4.29M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry);
282
4.29M
                    goto xit;
283
4.29M
                }
284
7.92M
#     endif
285
7.92M
            r.di = 0, r.df = 0;
286
7.92M
        }
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.3M
        else if (dxr == dxl && fxl != 0) {
292
2.11M
            if (l.di == 0)
293
247k
                r.di = 0, r.df = l.df;
294
1.86M
            else
295
1.86M
                compute_dx(&r, dxr, ysr);
296
2.11M
            if (ysr == ysl && r.h == l.h)
297
1.26M
                r.x += fxl;
298
846k
            else
299
846k
                r.x += YMULT_QUO(ysr, r);
300
29.2M
        } else {
301
29.2M
            compute_dx(&r, dxr, ysr);
302
29.2M
            r.x += YMULT_QUO(ysr, r);
303
29.2M
        }
304
        /* Compute one line's worth of dx/dy. */
305
39.2M
        compute_ldx(&l, ysl);
306
39.2M
        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.2M
        l.x += fixed_epsilon;
310
39.2M
        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.2M
#define rational_floor(tl)\
338
39.2M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
39.2M
#define STEP_LINE(ix, tl)\
340
39.2M
  tl.x += tl.ldi;\
341
39.2M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
39.2M
  ix = rational_floor(tl)
343
344
39.2M
        rxl = rational_floor(l);
345
39.2M
        rxr = rational_floor(r);
346
39.2M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
1.12G
        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.08G
                register int ixl, ixr;
365
366
1.08G
                STEP_LINE(ixl, l);
367
1.08G
                STEP_LINE(ixr, r);
368
1.08G
                SET_MINIMAL_WIDTH(ixl, ixr, l, r);
369
1.08G
                if (ixl != rxl || ixr != rxr) {
370
706M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT);
371
706M
                    CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT);
372
706M
                    code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
373
706M
                    if (code < 0)
374
0
                        goto xit;
375
706M
                    rxl = ixl, rxr = ixr, ry = iy;
376
706M
                }
377
1.08G
#     endif
378
1.08G
        }
379
39.2M
# if !LINEAR_COLOR
380
39.2M
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
            code = 0;
383
# endif
384
39.2M
#undef STEP_LINE
385
39.2M
#undef SET_MINIMAL_WIDTH
386
39.2M
#undef CONNECT_RECTANGLES
387
39.2M
#undef FILL_TRAP_RECT
388
39.2M
#undef FILL_TRAP_RECT_DIRECT
389
39.2M
#undef FILL_TRAP_RECT_INRECT
390
39.2M
#undef YMULT_QUO
391
43.5M
xit:  if (code < 0 && FILL_DIRECT)
392
0
            return_error(code);
393
43.5M
        return_if_interrupt(dev->memory);
394
43.5M
        return code;
395
43.5M
    }
396
43.5M
}
gdevddrw.c:gx_fill_trapezoid_as_lc
Line
Count
Source
137
977k
{
138
977k
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
977k
    const fixed ymax = fixed_pixround(ytop);
140
141
977k
    if (ymin >= ymax)
142
233k
        return 0;    /* no scan lines to sample */
143
744k
    {
144
744k
        int iy = fixed2int_var(ymin);
145
744k
        const int iy1 = fixed2int_var(ymax);
146
744k
        trap_line l, r;
147
744k
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
744k
        const fixed
152
744k
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
744k
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
744k
        const fixed /* partial pixel offset to first line to sample */
155
744k
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
744k
        fixed fxl;
157
744k
        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
744k
# if LINEAR_COLOR
165
744k
            int num_components = dev->color_info.num_components;
166
744k
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
744k
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
744k
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
744k
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
744k
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
744k
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
744k
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
744k
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
744k
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
744k
            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
744k
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
744k
        l.h = left->end.y - left->start.y;
185
744k
        if (l.h == 0)
186
0
           return 0;
187
744k
        r.h = right->end.y - right->start.y;
188
744k
        if (r.h == 0)
189
0
           return 0;
190
744k
        l.x = x0l + (fixed_half - fixed_epsilon);
191
744k
        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
744k
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
744k
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
744k
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
744k
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
744k
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
744k
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
744k
#if LINEAR_COLOR
210
744k
#   define FILL_TRAP_RECT(x,y,w,h)\
211
744k
        (!(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
744k
#define YMULT_QUO(ys, tl)\
228
744k
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
744k
   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
744k
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
744k
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
744k
#endif
264
744k
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
423k
            l.di = 0, l.df = 0;
267
423k
            fxl = 0;
268
423k
        } else {
269
321k
            compute_dx(&l, dxl, ysl);
270
321k
            fxl = YMULT_QUO(ysl, l);
271
321k
            l.x += fxl;
272
321k
        }
273
744k
        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
428k
            r.di = 0, r.df = 0;
286
428k
        }
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
316k
        else if (dxr == dxl && fxl != 0) {
292
149k
            if (l.di == 0)
293
67.9k
                r.di = 0, r.df = l.df;
294
81.6k
            else
295
81.6k
                compute_dx(&r, dxr, ysr);
296
149k
            if (ysr == ysl && r.h == l.h)
297
149k
                r.x += fxl;
298
88
            else
299
88
                r.x += YMULT_QUO(ysr, r);
300
166k
        } else {
301
166k
            compute_dx(&r, dxr, ysr);
302
166k
            r.x += YMULT_QUO(ysr, r);
303
166k
        }
304
        /* Compute one line's worth of dx/dy. */
305
744k
        compute_ldx(&l, ysl);
306
744k
        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
744k
        l.x += fixed_epsilon;
310
744k
        r.x += fixed_epsilon;
311
744k
# 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
744k
            lg.c = lgc;
320
744k
            lg.f = lgf;
321
744k
            lg.num = lgnum;
322
744k
            rg.c = rgc;
323
744k
            rg.f = rgf;
324
744k
            rg.num = rgnum;
325
744k
            xg.c = xgc;
326
744k
            xg.f = xgf;
327
744k
            xg.num = xgnum;
328
744k
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
744k
            if (code < 0)
330
0
                return code;
331
744k
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
744k
            if (code < 0)
333
0
                return code;
334
335
744k
# endif
336
337
744k
#define rational_floor(tl)\
338
744k
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
744k
#define STEP_LINE(ix, tl)\
340
744k
  tl.x += tl.ldi;\
341
744k
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
744k
  ix = rational_floor(tl)
343
344
744k
        rxl = rational_floor(l);
345
744k
        rxr = rational_floor(r);
346
744k
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
22.1M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
22.1M
#     if LINEAR_COLOR
349
22.1M
                if (rxl != rxr) {
350
15.8M
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
15.8M
                    if (code < 0)
352
0
                        goto xit;
353
15.8M
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
15.8M
                    if (code < 0)
355
4
                        goto xit;
356
15.8M
                }
357
22.1M
                if (++iy == iy1)
358
744k
                    break;
359
21.4M
                STEP_LINE(rxl, l);
360
21.4M
                STEP_LINE(rxr, r);
361
21.4M
                step_gradient(&lg, num_components);
362
21.4M
                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
21.4M
        }
379
# if !LINEAR_COLOR
380
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
744k
            code = 0;
383
744k
# endif
384
744k
#undef STEP_LINE
385
744k
#undef SET_MINIMAL_WIDTH
386
744k
#undef CONNECT_RECTANGLES
387
744k
#undef FILL_TRAP_RECT
388
744k
#undef FILL_TRAP_RECT_DIRECT
389
744k
#undef FILL_TRAP_RECT_INRECT
390
744k
#undef YMULT_QUO
391
744k
xit:  if (code < 0 && FILL_DIRECT)
392
4
            return_error(code);
393
744k
        return_if_interrupt(dev->memory);
394
744k
        return code;
395
744k
    }
396
744k
}
gdevddrw.c:gx_fill_trapezoid_ns_lc
Line
Count
Source
137
32.0M
{
138
32.0M
    const fixed ymin = fixed_pixround(ybot) + fixed_half;
139
32.0M
    const fixed ymax = fixed_pixround(ytop);
140
141
32.0M
    if (ymin >= ymax)
142
10.9M
        return 0;    /* no scan lines to sample */
143
21.1M
    {
144
21.1M
        int iy = fixed2int_var(ymin);
145
21.1M
        const int iy1 = fixed2int_var(ymax);
146
21.1M
        trap_line l, r;
147
21.1M
        register int rxl, rxr;
148
#if !LINEAR_COLOR
149
        int ry;
150
#endif
151
21.1M
        const fixed
152
21.1M
            x0l = left->start.x, x1l = left->end.x, x0r = right->start.x,
153
21.1M
            x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r;
154
21.1M
        const fixed /* partial pixel offset to first line to sample */
155
21.1M
            ysl = ymin - left->start.y, ysr = ymin - right->start.y;
156
21.1M
        fixed fxl;
157
21.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
21.1M
# if LINEAR_COLOR
165
21.1M
            int num_components = dev->color_info.num_components;
166
21.1M
            frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
167
21.1M
            int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
168
21.1M
            int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
169
21.1M
            frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
170
21.1M
            int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
171
21.1M
            int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
172
21.1M
            frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS];
173
21.1M
            int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS];
174
21.1M
            int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS];
175
21.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
21.1M
        if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1);
183
184
21.1M
        l.h = left->end.y - left->start.y;
185
21.1M
        if (l.h == 0)
186
0
           return 0;
187
21.1M
        r.h = right->end.y - right->start.y;
188
21.1M
        if (r.h == 0)
189
0
           return 0;
190
21.1M
        l.x = x0l + (fixed_half - fixed_epsilon);
191
21.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
21.1M
#define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\
203
21.1M
  (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\
204
21.1M
   gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa))
205
21.1M
#define FILL_TRAP_RECT_DIRECT(x,y,w,h)\
206
21.1M
  (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\
207
21.1M
   (*fill_rect)(dev, x, y, w, h, cindex))
208
209
21.1M
#if LINEAR_COLOR
210
21.1M
#   define FILL_TRAP_RECT(x,y,w,h)\
211
21.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
21.1M
#define YMULT_QUO(ys, tl)\
228
21.1M
  (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\
229
21.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
21.1M
#define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING
262
21.1M
#define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING
263
21.1M
#endif
264
21.1M
        if (fixed_floor(l.x) == fixed_pixround(x1l)) {
265
            /* Left edge is vertical, we don't need to increment. */
266
3.91M
            l.di = 0, l.df = 0;
267
3.91M
            fxl = 0;
268
17.2M
        } else {
269
17.2M
            compute_dx(&l, dxl, ysl);
270
17.2M
            fxl = YMULT_QUO(ysl, l);
271
17.2M
            l.x += fxl;
272
17.2M
        }
273
21.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
3.90M
            r.di = 0, r.df = 0;
286
3.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
17.2M
        else if (dxr == dxl && fxl != 0) {
292
1.56M
            if (l.di == 0)
293
456k
                r.di = 0, r.df = l.df;
294
1.10M
            else
295
1.10M
                compute_dx(&r, dxr, ysr);
296
1.56M
            if (ysr == ysl && r.h == l.h)
297
755k
                r.x += fxl;
298
807k
            else
299
807k
                r.x += YMULT_QUO(ysr, r);
300
15.6M
        } else {
301
15.6M
            compute_dx(&r, dxr, ysr);
302
15.6M
            r.x += YMULT_QUO(ysr, r);
303
15.6M
        }
304
        /* Compute one line's worth of dx/dy. */
305
21.1M
        compute_ldx(&l, ysl);
306
21.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
21.1M
        l.x += fixed_epsilon;
310
21.1M
        r.x += fixed_epsilon;
311
21.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
21.1M
            lg.c = lgc;
320
21.1M
            lg.f = lgf;
321
21.1M
            lg.num = lgnum;
322
21.1M
            rg.c = rgc;
323
21.1M
            rg.f = rgf;
324
21.1M
            rg.num = rgnum;
325
21.1M
            xg.c = xgc;
326
21.1M
            xg.f = xgf;
327
21.1M
            xg.num = xgnum;
328
21.1M
            code = init_gradient(&lg, fa, left, right, &l, ymin, num_components);
329
21.1M
            if (code < 0)
330
0
                return code;
331
21.1M
            code = init_gradient(&rg, fa, right, left, &r, ymin, num_components);
332
21.1M
            if (code < 0)
333
0
                return code;
334
335
21.1M
# endif
336
337
21.1M
#define rational_floor(tl)\
338
21.1M
  fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x)
339
21.1M
#define STEP_LINE(ix, tl)\
340
21.1M
  tl.x += tl.ldi;\
341
21.1M
  if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\
342
21.1M
  ix = rational_floor(tl)
343
344
21.1M
        rxl = rational_floor(l);
345
21.1M
        rxr = rational_floor(r);
346
21.1M
        SET_MINIMAL_WIDTH(rxl, rxr, l, r);
347
477M
        while (LINEAR_COLOR ? 1 : ++iy != iy1) {
348
477M
#     if LINEAR_COLOR
349
477M
                if (rxl != rxr) {
350
35.7M
                    code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components);
351
35.7M
                    if (code < 0)
352
0
                        goto xit;
353
35.7M
                    code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1);
354
35.7M
                    if (code < 0)
355
13
                        goto xit;
356
35.7M
                }
357
477M
                if (++iy == iy1)
358
21.1M
                    break;
359
456M
                STEP_LINE(rxl, l);
360
456M
                STEP_LINE(rxr, r);
361
456M
                step_gradient(&lg, num_components);
362
456M
                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
456M
        }
379
# if !LINEAR_COLOR
380
            code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry);
381
# else
382
21.1M
            code = 0;
383
21.1M
# endif
384
21.1M
#undef STEP_LINE
385
21.1M
#undef SET_MINIMAL_WIDTH
386
21.1M
#undef CONNECT_RECTANGLES
387
21.1M
#undef FILL_TRAP_RECT
388
21.1M
#undef FILL_TRAP_RECT_DIRECT
389
21.1M
#undef FILL_TRAP_RECT_INRECT
390
21.1M
#undef YMULT_QUO
391
21.1M
xit:  if (code < 0 && FILL_DIRECT)
392
13
            return_error(code);
393
21.1M
        return_if_interrupt(dev->memory);
394
21.1M
        return code;
395
21.1M
    }
396
21.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