396 | 86.0k | } 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.05k | { | 138 | 1.05k | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 1.05k | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 1.05k | if (ymin >= ymax) | 142 | 4 | return 0; /* no scan lines to sample */ | 143 | 1.05k | { | 144 | 1.05k | int iy = fixed2int_var(ymin); | 145 | 1.05k | const int iy1 = fixed2int_var(ymax); | 146 | 1.05k | trap_line l, r; | 147 | 1.05k | register int rxl, rxr; | 148 | 1.05k | #if !LINEAR_COLOR | 149 | 1.05k | int ry; | 150 | 1.05k | #endif | 151 | 1.05k | const fixed | 152 | 1.05k | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 1.05k | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 1.05k | const fixed /* partial pixel offset to first line to sample */ | 155 | 1.05k | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 1.05k | fixed fxl; | 157 | 1.05k | 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.05k | gx_color_index cindex = pdevc->colors.pure; | 178 | 1.05k | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 1.05k | dev_proc(dev, fill_rectangle); | 180 | 1.05k | # endif | 181 | | | 182 | 1.05k | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 1.05k | l.h = left->end.y - left->start.y; | 185 | 1.05k | if (l.h == 0) | 186 | 0 | return 0; | 187 | 1.05k | r.h = right->end.y - right->start.y; | 188 | 1.05k | if (r.h == 0) | 189 | 0 | return 0; | 190 | 1.05k | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 1.05k | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 1.05k | #if !LINEAR_COLOR | 193 | 1.05k | ry = iy; | 194 | 1.05k | #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.05k | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 1.05k | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 1.05k | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 1.05k | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 1.05k | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 1.05k | (*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.05k | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 1.05k | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 1.05k | #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.05k | #define YMULT_QUO(ys, tl)\ | 228 | 1.05k | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 1.05k | 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.05k | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 1.05k | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 1.05k | #endif | 264 | 1.05k | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 0 | l.di = 0, l.df = 0; | 267 | 0 | fxl = 0; | 268 | 1.05k | } else { | 269 | 1.05k | compute_dx(&l, dxl, ysl); | 270 | 1.05k | fxl = YMULT_QUO(ysl, l); | 271 | 1.05k | l.x += fxl; | 272 | 1.05k | } | 273 | 1.05k | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 0 | # if !LINEAR_COLOR | 277 | 0 | if (l.di == 0 && l.df == 0) { | 278 | 0 | rxl = fixed2int_var(l.x); | 279 | 0 | rxr = fixed2int_var(r.x); | 280 | 0 | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 0 | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 0 | goto xit; | 283 | 0 | } | 284 | 0 | # endif | 285 | 0 | r.di = 0, r.df = 0; | 286 | 0 | } | 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.05k | else if (dxr == dxl && fxl != 0) { | 292 | 935 | if (l.di == 0) | 293 | 485 | r.di = 0, r.df = l.df; | 294 | 450 | else | 295 | 450 | compute_dx(&r, dxr, ysr); | 296 | 935 | if (ysr == ysl && r.h == l.h) | 297 | 935 | r.x += fxl; | 298 | 0 | else | 299 | 0 | r.x += YMULT_QUO(ysr, r); | 300 | 935 | } else { | 301 | 118 | compute_dx(&r, dxr, ysr); | 302 | 118 | r.x += YMULT_QUO(ysr, r); | 303 | 118 | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 1.05k | compute_ldx(&l, ysl); | 306 | 1.05k | 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.05k | l.x += fixed_epsilon; | 310 | 1.05k | 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.05k | #define rational_floor(tl)\ | 338 | 1.05k | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 1.05k | #define STEP_LINE(ix, tl)\ | 340 | 1.05k | tl.x += tl.ldi;\ | 341 | 1.05k | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 1.05k | ix = rational_floor(tl) | 343 | | | 344 | 1.05k | rxl = rational_floor(l); | 345 | 1.05k | rxr = rational_floor(r); | 346 | 1.05k | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 1.12M | 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.12M | register int ixl, ixr; | 365 | | | 366 | 1.12M | STEP_LINE(ixl, l); | 367 | 1.12M | STEP_LINE(ixr, r); | 368 | 1.12M | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 1.12M | if (ixl != rxl || ixr != rxr) { | 370 | 458k | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 458k | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 458k | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 458k | if (code < 0) | 374 | 0 | goto xit; | 375 | 458k | rxl = ixl, rxr = ixr, ry = iy; | 376 | 458k | } | 377 | 1.12M | # endif | 378 | 1.12M | } | 379 | 1.05k | # if !LINEAR_COLOR | 380 | 1.05k | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 1.05k | #undef STEP_LINE | 385 | 1.05k | #undef SET_MINIMAL_WIDTH | 386 | 1.05k | #undef CONNECT_RECTANGLES | 387 | 1.05k | #undef FILL_TRAP_RECT | 388 | 1.05k | #undef FILL_TRAP_RECT_DIRECT | 389 | 1.05k | #undef FILL_TRAP_RECT_INRECT | 390 | 1.05k | #undef YMULT_QUO | 391 | 1.05k | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 1.05k | return_if_interrupt(dev->memory); | 394 | 1.05k | return code; | 395 | 1.05k | } | 396 | 1.05k | } |
gdevddrw.c:gx_fill_trapezoid_as_nd Line | Count | Source | 137 | 264 | { | 138 | 264 | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 264 | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 264 | if (ymin >= ymax) | 142 | 0 | return 0; /* no scan lines to sample */ | 143 | 264 | { | 144 | 264 | int iy = fixed2int_var(ymin); | 145 | 264 | const int iy1 = fixed2int_var(ymax); | 146 | 264 | trap_line l, r; | 147 | 264 | register int rxl, rxr; | 148 | 264 | #if !LINEAR_COLOR | 149 | 264 | int ry; | 150 | 264 | #endif | 151 | 264 | const fixed | 152 | 264 | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 264 | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 264 | const fixed /* partial pixel offset to first line to sample */ | 155 | 264 | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 264 | fixed fxl; | 157 | 264 | 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 | 264 | gx_color_index cindex = pdevc->colors.pure; | 178 | 264 | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 264 | dev_proc(dev, fill_rectangle); | 180 | 264 | # endif | 181 | | | 182 | 264 | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 264 | l.h = left->end.y - left->start.y; | 185 | 264 | if (l.h == 0) | 186 | 0 | return 0; | 187 | 264 | r.h = right->end.y - right->start.y; | 188 | 264 | if (r.h == 0) | 189 | 0 | return 0; | 190 | 264 | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 264 | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 264 | #if !LINEAR_COLOR | 193 | 264 | ry = iy; | 194 | 264 | #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 | 264 | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 264 | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 264 | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 264 | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 264 | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 264 | (*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 | 264 | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 264 | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 264 | #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 | 264 | #define YMULT_QUO(ys, tl)\ | 228 | 264 | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 264 | 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 | 264 | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 264 | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 264 | #endif | 264 | 264 | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 264 | l.di = 0, l.df = 0; | 267 | 264 | fxl = 0; | 268 | 264 | } else { | 269 | 0 | compute_dx(&l, dxl, ysl); | 270 | 0 | fxl = YMULT_QUO(ysl, l); | 271 | 0 | l.x += fxl; | 272 | 0 | } | 273 | 264 | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 264 | # if !LINEAR_COLOR | 277 | 264 | if (l.di == 0 && l.df == 0) { | 278 | 264 | rxl = fixed2int_var(l.x); | 279 | 264 | rxr = fixed2int_var(r.x); | 280 | 264 | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 264 | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 264 | goto xit; | 283 | 264 | } | 284 | 0 | # endif | 285 | 0 | r.di = 0, r.df = 0; | 286 | 0 | } | 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 | 0 | else if (dxr == dxl && fxl != 0) { | 292 | 0 | if (l.di == 0) | 293 | 0 | r.di = 0, r.df = l.df; | 294 | 0 | else | 295 | 0 | compute_dx(&r, dxr, ysr); | 296 | 0 | if (ysr == ysl && r.h == l.h) | 297 | 0 | r.x += fxl; | 298 | 0 | else | 299 | 0 | r.x += YMULT_QUO(ysr, r); | 300 | 0 | } else { | 301 | 0 | compute_dx(&r, dxr, ysr); | 302 | 0 | r.x += YMULT_QUO(ysr, r); | 303 | 0 | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 0 | compute_ldx(&l, ysl); | 306 | 0 | 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 | 0 | l.x += fixed_epsilon; | 310 | 0 | 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 | 0 | #define rational_floor(tl)\ | 338 | 0 | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 0 | #define STEP_LINE(ix, tl)\ | 340 | 0 | tl.x += tl.ldi;\ | 341 | 0 | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 0 | ix = rational_floor(tl) | 343 | |
| 344 | 0 | rxl = rational_floor(l); | 345 | 0 | rxr = rational_floor(r); | 346 | 0 | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 0 | 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 | 0 | register int ixl, ixr; | 365 | |
| 366 | 0 | STEP_LINE(ixl, l); | 367 | 0 | STEP_LINE(ixr, r); | 368 | 0 | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 0 | if (ixl != rxl || ixr != rxr) { | 370 | 0 | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 0 | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 0 | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 0 | if (code < 0) | 374 | 0 | goto xit; | 375 | 0 | rxl = ixl, rxr = ixr, ry = iy; | 376 | 0 | } | 377 | 0 | # endif | 378 | 0 | } | 379 | 0 | # if !LINEAR_COLOR | 380 | 0 | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 0 | #undef STEP_LINE | 385 | 0 | #undef SET_MINIMAL_WIDTH | 386 | 0 | #undef CONNECT_RECTANGLES | 387 | 0 | #undef FILL_TRAP_RECT | 388 | 0 | #undef FILL_TRAP_RECT_DIRECT | 389 | 0 | #undef FILL_TRAP_RECT_INRECT | 390 | 0 | #undef YMULT_QUO | 391 | 264 | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 264 | return_if_interrupt(dev->memory); | 394 | 264 | return code; | 395 | 264 | } | 396 | 264 | } |
gdevddrw.c:gx_fill_trapezoid_ns_fd Line | Count | Source | 137 | 83.3k | { | 138 | 83.3k | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 83.3k | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 83.3k | if (ymin >= ymax) | 142 | 0 | return 0; /* no scan lines to sample */ | 143 | 83.3k | { | 144 | 83.3k | int iy = fixed2int_var(ymin); | 145 | 83.3k | const int iy1 = fixed2int_var(ymax); | 146 | 83.3k | trap_line l, r; | 147 | 83.3k | register int rxl, rxr; | 148 | 83.3k | #if !LINEAR_COLOR | 149 | 83.3k | int ry; | 150 | 83.3k | #endif | 151 | 83.3k | const fixed | 152 | 83.3k | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 83.3k | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 83.3k | const fixed /* partial pixel offset to first line to sample */ | 155 | 83.3k | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 83.3k | fixed fxl; | 157 | 83.3k | 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 | 83.3k | gx_color_index cindex = pdevc->colors.pure; | 178 | 83.3k | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 83.3k | dev_proc(dev, fill_rectangle); | 180 | 83.3k | # endif | 181 | | | 182 | 83.3k | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 83.3k | l.h = left->end.y - left->start.y; | 185 | 83.3k | if (l.h == 0) | 186 | 0 | return 0; | 187 | 83.3k | r.h = right->end.y - right->start.y; | 188 | 83.3k | if (r.h == 0) | 189 | 0 | return 0; | 190 | 83.3k | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 83.3k | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 83.3k | #if !LINEAR_COLOR | 193 | 83.3k | ry = iy; | 194 | 83.3k | #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 | 83.3k | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 83.3k | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 83.3k | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 83.3k | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 83.3k | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 83.3k | (*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 | 83.3k | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 83.3k | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 83.3k | #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 | 83.3k | #define YMULT_QUO(ys, tl)\ | 228 | 83.3k | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 83.3k | 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 | 83.3k | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 83.3k | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 83.3k | #endif | 264 | 83.3k | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 35.5k | l.di = 0, l.df = 0; | 267 | 35.5k | fxl = 0; | 268 | 47.8k | } else { | 269 | 47.8k | compute_dx(&l, dxl, ysl); | 270 | 47.8k | fxl = YMULT_QUO(ysl, l); | 271 | 47.8k | l.x += fxl; | 272 | 47.8k | } | 273 | 83.3k | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 34.3k | # if !LINEAR_COLOR | 277 | 34.3k | if (l.di == 0 && l.df == 0) { | 278 | 30.6k | rxl = fixed2int_var(l.x); | 279 | 30.6k | rxr = fixed2int_var(r.x); | 280 | 30.6k | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 30.6k | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 30.6k | goto xit; | 283 | 30.6k | } | 284 | 3.60k | # endif | 285 | 3.60k | r.di = 0, r.df = 0; | 286 | 3.60k | } | 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 | 49.0k | else if (dxr == dxl && fxl != 0) { | 292 | 5.69k | if (l.di == 0) | 293 | 2.66k | r.di = 0, r.df = l.df; | 294 | 3.02k | else | 295 | 3.02k | compute_dx(&r, dxr, ysr); | 296 | 5.69k | if (ysr == ysl && r.h == l.h) | 297 | 4.09k | r.x += fxl; | 298 | 1.59k | else | 299 | 1.59k | r.x += YMULT_QUO(ysr, r); | 300 | 43.3k | } else { | 301 | 43.3k | compute_dx(&r, dxr, ysr); | 302 | 43.3k | r.x += YMULT_QUO(ysr, r); | 303 | 43.3k | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 52.6k | compute_ldx(&l, ysl); | 306 | 52.6k | 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 | 52.6k | l.x += fixed_epsilon; | 310 | 52.6k | 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 | 52.6k | #define rational_floor(tl)\ | 338 | 52.6k | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 52.6k | #define STEP_LINE(ix, tl)\ | 340 | 52.6k | tl.x += tl.ldi;\ | 341 | 52.6k | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 52.6k | ix = rational_floor(tl) | 343 | | | 344 | 52.6k | rxl = rational_floor(l); | 345 | 52.6k | rxr = rational_floor(r); | 346 | 52.6k | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 9.41M | 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 | 9.36M | register int ixl, ixr; | 365 | | | 366 | 9.36M | STEP_LINE(ixl, l); | 367 | 9.36M | STEP_LINE(ixr, r); | 368 | 9.36M | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 9.36M | if (ixl != rxl || ixr != rxr) { | 370 | 5.35M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 5.35M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 5.35M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 5.35M | if (code < 0) | 374 | 0 | goto xit; | 375 | 5.35M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 5.35M | } | 377 | 9.36M | # endif | 378 | 9.36M | } | 379 | 52.6k | # if !LINEAR_COLOR | 380 | 52.6k | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 52.6k | #undef STEP_LINE | 385 | 52.6k | #undef SET_MINIMAL_WIDTH | 386 | 52.6k | #undef CONNECT_RECTANGLES | 387 | 52.6k | #undef FILL_TRAP_RECT | 388 | 52.6k | #undef FILL_TRAP_RECT_DIRECT | 389 | 52.6k | #undef FILL_TRAP_RECT_INRECT | 390 | 52.6k | #undef YMULT_QUO | 391 | 83.3k | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 83.3k | return_if_interrupt(dev->memory); | 394 | 83.3k | return code; | 395 | 83.3k | } | 396 | 83.3k | } |
gdevddrw.c:gx_fill_trapezoid_ns_nd Line | Count | Source | 137 | 1.39k | { | 138 | 1.39k | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 1.39k | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 1.39k | if (ymin >= ymax) | 142 | 0 | return 0; /* no scan lines to sample */ | 143 | 1.39k | { | 144 | 1.39k | int iy = fixed2int_var(ymin); | 145 | 1.39k | const int iy1 = fixed2int_var(ymax); | 146 | 1.39k | trap_line l, r; | 147 | 1.39k | register int rxl, rxr; | 148 | 1.39k | #if !LINEAR_COLOR | 149 | 1.39k | int ry; | 150 | 1.39k | #endif | 151 | 1.39k | const fixed | 152 | 1.39k | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 1.39k | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 1.39k | const fixed /* partial pixel offset to first line to sample */ | 155 | 1.39k | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 1.39k | fixed fxl; | 157 | 1.39k | 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.39k | gx_color_index cindex = pdevc->colors.pure; | 178 | 1.39k | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 1.39k | dev_proc(dev, fill_rectangle); | 180 | 1.39k | # endif | 181 | | | 182 | 1.39k | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 1.39k | l.h = left->end.y - left->start.y; | 185 | 1.39k | if (l.h == 0) | 186 | 0 | return 0; | 187 | 1.39k | r.h = right->end.y - right->start.y; | 188 | 1.39k | if (r.h == 0) | 189 | 0 | return 0; | 190 | 1.39k | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 1.39k | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 1.39k | #if !LINEAR_COLOR | 193 | 1.39k | ry = iy; | 194 | 1.39k | #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.39k | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 1.39k | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 1.39k | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 1.39k | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 1.39k | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 1.39k | (*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.39k | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 1.39k | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 1.39k | #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.39k | #define YMULT_QUO(ys, tl)\ | 228 | 1.39k | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 1.39k | 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.39k | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 1.39k | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 1.39k | #endif | 264 | 1.39k | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 984 | l.di = 0, l.df = 0; | 267 | 984 | fxl = 0; | 268 | 984 | } else { | 269 | 409 | compute_dx(&l, dxl, ysl); | 270 | 409 | fxl = YMULT_QUO(ysl, l); | 271 | 409 | l.x += fxl; | 272 | 409 | } | 273 | 1.39k | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 1.00k | # if !LINEAR_COLOR | 277 | 1.00k | if (l.di == 0 && l.df == 0) { | 278 | 940 | rxl = fixed2int_var(l.x); | 279 | 940 | rxr = fixed2int_var(r.x); | 280 | 940 | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 940 | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 940 | goto xit; | 283 | 940 | } | 284 | 65 | # endif | 285 | 65 | r.di = 0, r.df = 0; | 286 | 65 | } | 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 | 388 | else if (dxr == dxl && fxl != 0) { | 292 | 0 | if (l.di == 0) | 293 | 0 | r.di = 0, r.df = l.df; | 294 | 0 | else | 295 | 0 | compute_dx(&r, dxr, ysr); | 296 | 0 | if (ysr == ysl && r.h == l.h) | 297 | 0 | r.x += fxl; | 298 | 0 | else | 299 | 0 | r.x += YMULT_QUO(ysr, r); | 300 | 388 | } else { | 301 | 388 | compute_dx(&r, dxr, ysr); | 302 | 388 | r.x += YMULT_QUO(ysr, r); | 303 | 388 | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 453 | compute_ldx(&l, ysl); | 306 | 453 | 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 | 453 | l.x += fixed_epsilon; | 310 | 453 | 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 | 453 | #define rational_floor(tl)\ | 338 | 453 | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 453 | #define STEP_LINE(ix, tl)\ | 340 | 453 | tl.x += tl.ldi;\ | 341 | 453 | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 453 | ix = rational_floor(tl) | 343 | | | 344 | 453 | rxl = rational_floor(l); | 345 | 453 | rxr = rational_floor(r); | 346 | 453 | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 10.3k | 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 | 9.88k | register int ixl, ixr; | 365 | | | 366 | 9.88k | STEP_LINE(ixl, l); | 367 | 9.88k | STEP_LINE(ixr, r); | 368 | 9.88k | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 9.88k | if (ixl != rxl || ixr != rxr) { | 370 | 6.72k | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 6.72k | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 6.72k | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 6.72k | if (code < 0) | 374 | 0 | goto xit; | 375 | 6.72k | rxl = ixl, rxr = ixr, ry = iy; | 376 | 6.72k | } | 377 | 9.88k | # endif | 378 | 9.88k | } | 379 | 453 | # if !LINEAR_COLOR | 380 | 453 | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 453 | #undef STEP_LINE | 385 | 453 | #undef SET_MINIMAL_WIDTH | 386 | 453 | #undef CONNECT_RECTANGLES | 387 | 453 | #undef FILL_TRAP_RECT | 388 | 453 | #undef FILL_TRAP_RECT_DIRECT | 389 | 453 | #undef FILL_TRAP_RECT_INRECT | 390 | 453 | #undef YMULT_QUO | 391 | 1.39k | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 1.39k | return_if_interrupt(dev->memory); | 394 | 1.39k | return code; | 395 | 1.39k | } | 396 | 1.39k | } |
Unexecuted instantiation: gdevddrw.c:gx_fill_trapezoid_as_lc Unexecuted instantiation: gdevddrw.c:gx_fill_trapezoid_ns_lc |