396 | 180M | } 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 | 3.63M | { | 138 | 3.63M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 3.63M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 3.63M | if (ymin >= ymax) | 142 | 193k | return 0; /* no scan lines to sample */ | 143 | 3.44M | { | 144 | 3.44M | int iy = fixed2int_var(ymin); | 145 | 3.44M | const int iy1 = fixed2int_var(ymax); | 146 | 3.44M | trap_line l, r; | 147 | 3.44M | register int rxl, rxr; | 148 | 3.44M | #if !LINEAR_COLOR | 149 | 3.44M | int ry; | 150 | 3.44M | #endif | 151 | 3.44M | const fixed | 152 | 3.44M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 3.44M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 3.44M | const fixed /* partial pixel offset to first line to sample */ | 155 | 3.44M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 3.44M | fixed fxl; | 157 | 3.44M | int code; | 158 | | # if CONTIGUOUS_FILL | 159 | | const bool peak0 = ((flags & 1) != 0); | 160 | | const bool peak1 = ((flags & 2) != 0); | 161 | | int peak_y0 = ybot + fixed_half; | 162 | | int peak_y1 = ytop - fixed_half; | 163 | | # endif | 164 | | # if LINEAR_COLOR | 165 | | int num_components = dev->color_info.num_components; | 166 | | frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 167 | | int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 168 | | int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 169 | | frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 170 | | int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 171 | | int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 172 | | frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 173 | | int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 174 | | int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 175 | | trap_gradient lg, rg, xg; | 176 | | # else | 177 | 3.44M | gx_color_index cindex = pdevc->colors.pure; | 178 | 3.44M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 3.44M | dev_proc(dev, fill_rectangle); | 180 | 3.44M | # endif | 181 | | | 182 | 3.44M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 3.44M | l.h = left->end.y - left->start.y; | 185 | 3.44M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 3.44M | r.h = right->end.y - right->start.y; | 188 | 3.44M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 3.44M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 3.44M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 3.44M | #if !LINEAR_COLOR | 193 | 3.44M | ry = iy; | 194 | 3.44M | #endif | 195 | | | 196 | | /* | 197 | | * Free variables of FILL_TRAP_RECT: | 198 | | * SWAP_AXES, pdevc, dev, fa | 199 | | * Free variables of FILL_TRAP_RECT_DIRECT: | 200 | | * SWAP_AXES, fill_rect, dev, cindex | 201 | | */ | 202 | 3.44M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 3.44M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 3.44M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 3.44M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 3.44M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 3.44M | (*fill_rect)(dev, x, y, w, h, cindex)) | 208 | | | 209 | | #if LINEAR_COLOR | 210 | | # define FILL_TRAP_RECT(x,y,w,h)\ | 211 | | (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den)) | 212 | | #else | 213 | 3.44M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 3.44M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 3.44M | #endif | 216 | | | 217 | | /* Compute the dx/dy ratios. */ | 218 | | | 219 | | /* | 220 | | * Compute the x offsets at the first scan line to sample. We need | 221 | | * to be careful in computing ys# * dx#f {/,%} h# because the | 222 | | * multiplication may overflow. We know that all the quantities | 223 | | * involved are non-negative, and that ys# is usually less than 1 (as | 224 | | * a fixed, of course); this gives us a cheap conservative check for | 225 | | * overflow in the multiplication. | 226 | | */ | 227 | 3.44M | #define YMULT_QUO(ys, tl)\ | 228 | 3.44M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 3.44M | fixed_mult_quo(ys, tl.df, tl.h)) | 230 | | | 231 | | #if CONTIGUOUS_FILL | 232 | | /* | 233 | | * If left and right boundary round to same pixel index, | 234 | | * we would not paing the scan and would get a dropout. | 235 | | * Check for this case and choose one of two pixels | 236 | | * which is closer to the "axis". We need to exclude | 237 | | * 'peak' because it would paint an excessive pixel. | 238 | | */ | 239 | | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \ | 240 | | if (ixl == ixr) \ | 241 | | if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\ | 242 | | fixed x = int2fixed(ixl) + fixed_half;\ | 243 | | if (x - l.x < r.x - x)\ | 244 | | ++ixr;\ | 245 | | else\ | 246 | | --ixl;\ | 247 | | } | 248 | | | 249 | | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\ | 250 | | if (adj1 < adj2) {\ | 251 | | if (iy - ry > 1) {\ | 252 | | code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\ | 253 | | if (code < 0)\ | 254 | | goto xit;\ | 255 | | ry = iy - 1;\ | 256 | | }\ | 257 | | adj1 = adj2 = (adj2 + adj2) / 2;\ | 258 | | } | 259 | | | 260 | | #else | 261 | 3.44M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 3.44M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 3.44M | #endif | 264 | 3.44M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 963k | l.di = 0, l.df = 0; | 267 | 963k | fxl = 0; | 268 | 2.48M | } else { | 269 | 2.48M | compute_dx(&l, dxl, ysl); | 270 | 2.48M | fxl = YMULT_QUO(ysl, l); | 271 | 2.48M | l.x += fxl; | 272 | 2.48M | } | 273 | 3.44M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 868k | # if !LINEAR_COLOR | 277 | 868k | if (l.di == 0 && l.df == 0) { | 278 | 805k | rxl = fixed2int_var(l.x); | 279 | 805k | rxr = fixed2int_var(r.x); | 280 | 805k | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 805k | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 805k | goto xit; | 283 | 805k | } | 284 | 63.2k | # endif | 285 | 63.2k | r.di = 0, r.df = 0; | 286 | 63.2k | } | 287 | | /* | 288 | | * The test for fxl != 0 is required because the right edge might | 289 | | * cross some pixel centers even if the left edge doesn't. | 290 | | */ | 291 | 2.57M | else if (dxr == dxl && fxl != 0) { | 292 | 1.40M | if (l.di == 0) | 293 | 746k | r.di = 0, r.df = l.df; | 294 | 661k | else | 295 | 661k | compute_dx(&r, dxr, ysr); | 296 | 1.40M | if (ysr == ysl && r.h == l.h) | 297 | 1.40M | r.x += fxl; | 298 | 183 | else | 299 | 183 | r.x += YMULT_QUO(ysr, r); | 300 | 1.40M | } else { | 301 | 1.16M | compute_dx(&r, dxr, ysr); | 302 | 1.16M | r.x += YMULT_QUO(ysr, r); | 303 | 1.16M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 2.63M | compute_ldx(&l, ysl); | 306 | 2.63M | compute_ldx(&r, ysr); | 307 | | /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding | 308 | | when the rational part is zero. Now add it back to get xl', xr' */ | 309 | 2.63M | l.x += fixed_epsilon; | 310 | 2.63M | r.x += fixed_epsilon; | 311 | | # if LINEAR_COLOR | 312 | | # ifdef DEBUG | 313 | | if (check_gradient_overflow(left, right)) { | 314 | | /* The caller must care of. | 315 | | Checking it here looses some performance with triangles. */ | 316 | | return_error(gs_error_unregistered); | 317 | | } | 318 | | # endif | 319 | | lg.c = lgc; | 320 | | lg.f = lgf; | 321 | | lg.num = lgnum; | 322 | | rg.c = rgc; | 323 | | rg.f = rgf; | 324 | | rg.num = rgnum; | 325 | | xg.c = xgc; | 326 | | xg.f = xgf; | 327 | | xg.num = xgnum; | 328 | | code = init_gradient(&lg, fa, left, right, &l, ymin, num_components); | 329 | | if (code < 0) | 330 | | return code; | 331 | | code = init_gradient(&rg, fa, right, left, &r, ymin, num_components); | 332 | | if (code < 0) | 333 | | return code; | 334 | | | 335 | | # endif | 336 | | | 337 | 2.63M | #define rational_floor(tl)\ | 338 | 2.63M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 2.63M | #define STEP_LINE(ix, tl)\ | 340 | 2.63M | tl.x += tl.ldi;\ | 341 | 2.63M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 2.63M | ix = rational_floor(tl) | 343 | | | 344 | 2.63M | rxl = rational_floor(l); | 345 | 2.63M | rxr = rational_floor(r); | 346 | 2.63M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 260M | 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 | 257M | register int ixl, ixr; | 365 | | | 366 | 257M | STEP_LINE(ixl, l); | 367 | 257M | STEP_LINE(ixr, r); | 368 | 257M | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 257M | if (ixl != rxl || ixr != rxr) { | 370 | 54.7M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 54.7M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 54.7M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 54.7M | if (code < 0) | 374 | 0 | goto xit; | 375 | 54.7M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 54.7M | } | 377 | 257M | # endif | 378 | 257M | } | 379 | 2.63M | # if !LINEAR_COLOR | 380 | 2.63M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 2.63M | #undef STEP_LINE | 385 | 2.63M | #undef SET_MINIMAL_WIDTH | 386 | 2.63M | #undef CONNECT_RECTANGLES | 387 | 2.63M | #undef FILL_TRAP_RECT | 388 | 2.63M | #undef FILL_TRAP_RECT_DIRECT | 389 | 2.63M | #undef FILL_TRAP_RECT_INRECT | 390 | 2.63M | #undef YMULT_QUO | 391 | 3.44M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 3.44M | return_if_interrupt(dev->memory); | 394 | 3.44M | return code; | 395 | 3.44M | } | 396 | 3.44M | } |
gdevddrw.c:gx_fill_trapezoid_as_nd Line | Count | Source | 137 | 5.17M | { | 138 | 5.17M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 5.17M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 5.17M | if (ymin >= ymax) | 142 | 62.3k | return 0; /* no scan lines to sample */ | 143 | 5.11M | { | 144 | 5.11M | int iy = fixed2int_var(ymin); | 145 | 5.11M | const int iy1 = fixed2int_var(ymax); | 146 | 5.11M | trap_line l, r; | 147 | 5.11M | register int rxl, rxr; | 148 | 5.11M | #if !LINEAR_COLOR | 149 | 5.11M | int ry; | 150 | 5.11M | #endif | 151 | 5.11M | const fixed | 152 | 5.11M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 5.11M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 5.11M | const fixed /* partial pixel offset to first line to sample */ | 155 | 5.11M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 5.11M | fixed fxl; | 157 | 5.11M | 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 | 5.11M | gx_color_index cindex = pdevc->colors.pure; | 178 | 5.11M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 5.11M | dev_proc(dev, fill_rectangle); | 180 | 5.11M | # endif | 181 | | | 182 | 5.11M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 5.11M | l.h = left->end.y - left->start.y; | 185 | 5.11M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 5.11M | r.h = right->end.y - right->start.y; | 188 | 5.11M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 5.11M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 5.11M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 5.11M | #if !LINEAR_COLOR | 193 | 5.11M | ry = iy; | 194 | 5.11M | #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 | 5.11M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 5.11M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 5.11M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 5.11M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 5.11M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 5.11M | (*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 | 5.11M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 5.11M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 5.11M | #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 | 5.11M | #define YMULT_QUO(ys, tl)\ | 228 | 5.11M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 5.11M | 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 | 5.11M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 5.11M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 5.11M | #endif | 264 | 5.11M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 1.05M | l.di = 0, l.df = 0; | 267 | 1.05M | fxl = 0; | 268 | 4.05M | } else { | 269 | 4.05M | compute_dx(&l, dxl, ysl); | 270 | 4.05M | fxl = YMULT_QUO(ysl, l); | 271 | 4.05M | l.x += fxl; | 272 | 4.05M | } | 273 | 5.11M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 937k | # if !LINEAR_COLOR | 277 | 937k | if (l.di == 0 && l.df == 0) { | 278 | 887k | rxl = fixed2int_var(l.x); | 279 | 887k | rxr = fixed2int_var(r.x); | 280 | 887k | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 887k | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 887k | goto xit; | 283 | 887k | } | 284 | 49.4k | # endif | 285 | 49.4k | r.di = 0, r.df = 0; | 286 | 49.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 | 4.17M | else if (dxr == dxl && fxl != 0) { | 292 | 565k | if (l.di == 0) | 293 | 333k | r.di = 0, r.df = l.df; | 294 | 231k | else | 295 | 231k | compute_dx(&r, dxr, ysr); | 296 | 565k | if (ysr == ysl && r.h == l.h) | 297 | 565k | r.x += fxl; | 298 | 278 | else | 299 | 278 | r.x += YMULT_QUO(ysr, r); | 300 | 3.60M | } else { | 301 | 3.60M | compute_dx(&r, dxr, ysr); | 302 | 3.60M | r.x += YMULT_QUO(ysr, r); | 303 | 3.60M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 4.22M | compute_ldx(&l, ysl); | 306 | 4.22M | 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 | 4.22M | l.x += fixed_epsilon; | 310 | 4.22M | 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 | 4.22M | #define rational_floor(tl)\ | 338 | 4.22M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 4.22M | #define STEP_LINE(ix, tl)\ | 340 | 4.22M | tl.x += tl.ldi;\ | 341 | 4.22M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 4.22M | ix = rational_floor(tl) | 343 | | | 344 | 4.22M | rxl = rational_floor(l); | 345 | 4.22M | rxr = rational_floor(r); | 346 | 4.22M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 654M | 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 | 650M | register int ixl, ixr; | 365 | | | 366 | 650M | STEP_LINE(ixl, l); | 367 | 650M | STEP_LINE(ixr, r); | 368 | 650M | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 650M | if (ixl != rxl || ixr != rxr) { | 370 | 509M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 509M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 509M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 509M | if (code < 0) | 374 | 0 | goto xit; | 375 | 509M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 509M | } | 377 | 650M | # endif | 378 | 650M | } | 379 | 4.22M | # if !LINEAR_COLOR | 380 | 4.22M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 4.22M | #undef STEP_LINE | 385 | 4.22M | #undef SET_MINIMAL_WIDTH | 386 | 4.22M | #undef CONNECT_RECTANGLES | 387 | 4.22M | #undef FILL_TRAP_RECT | 388 | 4.22M | #undef FILL_TRAP_RECT_DIRECT | 389 | 4.22M | #undef FILL_TRAP_RECT_INRECT | 390 | 4.22M | #undef YMULT_QUO | 391 | 5.11M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 5.11M | return_if_interrupt(dev->memory); | 394 | 5.11M | return code; | 395 | 5.11M | } | 396 | 5.11M | } |
gdevddrw.c:gx_fill_trapezoid_ns_fd Line | Count | Source | 137 | 58.4M | { | 138 | 58.4M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 58.4M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 58.4M | if (ymin >= ymax) | 142 | 6.81M | return 0; /* no scan lines to sample */ | 143 | 51.6M | { | 144 | 51.6M | int iy = fixed2int_var(ymin); | 145 | 51.6M | const int iy1 = fixed2int_var(ymax); | 146 | 51.6M | trap_line l, r; | 147 | 51.6M | register int rxl, rxr; | 148 | 51.6M | #if !LINEAR_COLOR | 149 | 51.6M | int ry; | 150 | 51.6M | #endif | 151 | 51.6M | const fixed | 152 | 51.6M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 51.6M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 51.6M | const fixed /* partial pixel offset to first line to sample */ | 155 | 51.6M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 51.6M | fixed fxl; | 157 | 51.6M | 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 | 51.6M | gx_color_index cindex = pdevc->colors.pure; | 178 | 51.6M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 51.6M | dev_proc(dev, fill_rectangle); | 180 | 51.6M | # endif | 181 | | | 182 | 51.6M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 51.6M | l.h = left->end.y - left->start.y; | 185 | 51.6M | if (l.h == 0) | 186 | 12 | return 0; | 187 | 51.6M | r.h = right->end.y - right->start.y; | 188 | 51.6M | if (r.h == 0) | 189 | 12 | return 0; | 190 | 51.6M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 51.6M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 51.6M | #if !LINEAR_COLOR | 193 | 51.6M | ry = iy; | 194 | 51.6M | #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 | 51.6M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 51.6M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 51.6M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 51.6M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 51.6M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 51.6M | (*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 | 51.6M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 51.6M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 51.6M | #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 | 51.6M | #define YMULT_QUO(ys, tl)\ | 228 | 51.6M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 51.6M | 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 | 51.6M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 51.6M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 51.6M | #endif | 264 | 51.6M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 20.8M | l.di = 0, l.df = 0; | 267 | 20.8M | fxl = 0; | 268 | 30.8M | } else { | 269 | 30.8M | compute_dx(&l, dxl, ysl); | 270 | 30.8M | fxl = YMULT_QUO(ysl, l); | 271 | 30.8M | l.x += fxl; | 272 | 30.8M | } | 273 | 51.6M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 20.9M | # if !LINEAR_COLOR | 277 | 20.9M | if (l.di == 0 && l.df == 0) { | 278 | 12.5M | rxl = fixed2int_var(l.x); | 279 | 12.5M | rxr = fixed2int_var(r.x); | 280 | 12.5M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 12.5M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 12.5M | goto xit; | 283 | 12.5M | } | 284 | 8.46M | # endif | 285 | 8.46M | r.di = 0, r.df = 0; | 286 | 8.46M | } | 287 | | /* | 288 | | * The test for fxl != 0 is required because the right edge might | 289 | | * cross some pixel centers even if the left edge doesn't. | 290 | | */ | 291 | 30.6M | else if (dxr == dxl && fxl != 0) { | 292 | 3.54M | if (l.di == 0) | 293 | 912k | r.di = 0, r.df = l.df; | 294 | 2.63M | else | 295 | 2.63M | compute_dx(&r, dxr, ysr); | 296 | 3.54M | if (ysr == ysl && r.h == l.h) | 297 | 2.14M | r.x += fxl; | 298 | 1.40M | else | 299 | 1.40M | r.x += YMULT_QUO(ysr, r); | 300 | 27.1M | } else { | 301 | 27.1M | compute_dx(&r, dxr, ysr); | 302 | 27.1M | r.x += YMULT_QUO(ysr, r); | 303 | 27.1M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 39.1M | compute_ldx(&l, ysl); | 306 | 39.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 | 39.1M | l.x += fixed_epsilon; | 310 | 39.1M | 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.1M | #define rational_floor(tl)\ | 338 | 39.1M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 39.1M | #define STEP_LINE(ix, tl)\ | 340 | 39.1M | tl.x += tl.ldi;\ | 341 | 39.1M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 39.1M | ix = rational_floor(tl) | 343 | | | 344 | 39.1M | rxl = rational_floor(l); | 345 | 39.1M | rxr = rational_floor(r); | 346 | 39.1M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 2.91G | 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 | 2.87G | register int ixl, ixr; | 365 | | | 366 | 2.87G | STEP_LINE(ixl, l); | 367 | 2.87G | STEP_LINE(ixr, r); | 368 | 2.87G | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 2.87G | if (ixl != rxl || ixr != rxr) { | 370 | 426M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 426M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 426M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 426M | if (code < 0) | 374 | 0 | goto xit; | 375 | 426M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 426M | } | 377 | 2.87G | # endif | 378 | 2.87G | } | 379 | 39.1M | # if !LINEAR_COLOR | 380 | 39.1M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 39.1M | #undef STEP_LINE | 385 | 39.1M | #undef SET_MINIMAL_WIDTH | 386 | 39.1M | #undef CONNECT_RECTANGLES | 387 | 39.1M | #undef FILL_TRAP_RECT | 388 | 39.1M | #undef FILL_TRAP_RECT_DIRECT | 389 | 39.1M | #undef FILL_TRAP_RECT_INRECT | 390 | 39.1M | #undef YMULT_QUO | 391 | 51.6M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 51.6M | return_if_interrupt(dev->memory); | 394 | 51.6M | return code; | 395 | 51.6M | } | 396 | 51.6M | } |
gdevddrw.c:gx_fill_trapezoid_ns_nd Line | Count | Source | 137 | 99.0M | { | 138 | 99.0M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 99.0M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 99.0M | if (ymin >= ymax) | 142 | 26.8M | return 0; /* no scan lines to sample */ | 143 | 72.2M | { | 144 | 72.2M | int iy = fixed2int_var(ymin); | 145 | 72.2M | const int iy1 = fixed2int_var(ymax); | 146 | 72.2M | trap_line l, r; | 147 | 72.2M | register int rxl, rxr; | 148 | 72.2M | #if !LINEAR_COLOR | 149 | 72.2M | int ry; | 150 | 72.2M | #endif | 151 | 72.2M | const fixed | 152 | 72.2M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 72.2M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 72.2M | const fixed /* partial pixel offset to first line to sample */ | 155 | 72.2M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 72.2M | fixed fxl; | 157 | 72.2M | int code; | 158 | | # if CONTIGUOUS_FILL | 159 | | const bool peak0 = ((flags & 1) != 0); | 160 | | const bool peak1 = ((flags & 2) != 0); | 161 | | int peak_y0 = ybot + fixed_half; | 162 | | int peak_y1 = ytop - fixed_half; | 163 | | # endif | 164 | | # if LINEAR_COLOR | 165 | | int num_components = dev->color_info.num_components; | 166 | | frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 167 | | int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 168 | | int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 169 | | frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 170 | | int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 171 | | int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 172 | | frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 173 | | int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 174 | | int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 175 | | trap_gradient lg, rg, xg; | 176 | | # else | 177 | 72.2M | gx_color_index cindex = pdevc->colors.pure; | 178 | 72.2M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 72.2M | dev_proc(dev, fill_rectangle); | 180 | 72.2M | # endif | 181 | | | 182 | 72.2M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 72.2M | l.h = left->end.y - left->start.y; | 185 | 72.2M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 72.2M | r.h = right->end.y - right->start.y; | 188 | 72.2M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 72.2M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 72.2M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 72.2M | #if !LINEAR_COLOR | 193 | 72.2M | ry = iy; | 194 | 72.2M | #endif | 195 | | | 196 | | /* | 197 | | * Free variables of FILL_TRAP_RECT: | 198 | | * SWAP_AXES, pdevc, dev, fa | 199 | | * Free variables of FILL_TRAP_RECT_DIRECT: | 200 | | * SWAP_AXES, fill_rect, dev, cindex | 201 | | */ | 202 | 72.2M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 72.2M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 72.2M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 72.2M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 72.2M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 72.2M | (*fill_rect)(dev, x, y, w, h, cindex)) | 208 | | | 209 | | #if LINEAR_COLOR | 210 | | # define FILL_TRAP_RECT(x,y,w,h)\ | 211 | | (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den)) | 212 | | #else | 213 | 72.2M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 72.2M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 72.2M | #endif | 216 | | | 217 | | /* Compute the dx/dy ratios. */ | 218 | | | 219 | | /* | 220 | | * Compute the x offsets at the first scan line to sample. We need | 221 | | * to be careful in computing ys# * dx#f {/,%} h# because the | 222 | | * multiplication may overflow. We know that all the quantities | 223 | | * involved are non-negative, and that ys# is usually less than 1 (as | 224 | | * a fixed, of course); this gives us a cheap conservative check for | 225 | | * overflow in the multiplication. | 226 | | */ | 227 | 72.2M | #define YMULT_QUO(ys, tl)\ | 228 | 72.2M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 72.2M | fixed_mult_quo(ys, tl.df, tl.h)) | 230 | | | 231 | | #if CONTIGUOUS_FILL | 232 | | /* | 233 | | * If left and right boundary round to same pixel index, | 234 | | * we would not paing the scan and would get a dropout. | 235 | | * Check for this case and choose one of two pixels | 236 | | * which is closer to the "axis". We need to exclude | 237 | | * 'peak' because it would paint an excessive pixel. | 238 | | */ | 239 | | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \ | 240 | | if (ixl == ixr) \ | 241 | | if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\ | 242 | | fixed x = int2fixed(ixl) + fixed_half;\ | 243 | | if (x - l.x < r.x - x)\ | 244 | | ++ixr;\ | 245 | | else\ | 246 | | --ixl;\ | 247 | | } | 248 | | | 249 | | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\ | 250 | | if (adj1 < adj2) {\ | 251 | | if (iy - ry > 1) {\ | 252 | | code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\ | 253 | | if (code < 0)\ | 254 | | goto xit;\ | 255 | | ry = iy - 1;\ | 256 | | }\ | 257 | | adj1 = adj2 = (adj2 + adj2) / 2;\ | 258 | | } | 259 | | | 260 | | #else | 261 | 72.2M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 72.2M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 72.2M | #endif | 264 | 72.2M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 17.3M | l.di = 0, l.df = 0; | 267 | 17.3M | fxl = 0; | 268 | 54.8M | } else { | 269 | 54.8M | compute_dx(&l, dxl, ysl); | 270 | 54.8M | fxl = YMULT_QUO(ysl, l); | 271 | 54.8M | l.x += fxl; | 272 | 54.8M | } | 273 | 72.2M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 22.6M | # if !LINEAR_COLOR | 277 | 22.6M | if (l.di == 0 && l.df == 0) { | 278 | 9.05M | rxl = fixed2int_var(l.x); | 279 | 9.05M | rxr = fixed2int_var(r.x); | 280 | 9.05M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 9.05M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 9.05M | goto xit; | 283 | 9.05M | } | 284 | 13.6M | # endif | 285 | 13.6M | r.di = 0, r.df = 0; | 286 | 13.6M | } | 287 | | /* | 288 | | * The test for fxl != 0 is required because the right edge might | 289 | | * cross some pixel centers even if the left edge doesn't. | 290 | | */ | 291 | 49.5M | else if (dxr == dxl && fxl != 0) { | 292 | 3.75M | if (l.di == 0) | 293 | 518k | r.di = 0, r.df = l.df; | 294 | 3.23M | else | 295 | 3.23M | compute_dx(&r, dxr, ysr); | 296 | 3.75M | if (ysr == ysl && r.h == l.h) | 297 | 2.57M | r.x += fxl; | 298 | 1.17M | else | 299 | 1.17M | r.x += YMULT_QUO(ysr, r); | 300 | 45.7M | } else { | 301 | 45.7M | compute_dx(&r, dxr, ysr); | 302 | 45.7M | r.x += YMULT_QUO(ysr, r); | 303 | 45.7M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 63.1M | compute_ldx(&l, ysl); | 306 | 63.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 | 63.1M | l.x += fixed_epsilon; | 310 | 63.1M | 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 | 63.1M | #define rational_floor(tl)\ | 338 | 63.1M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 63.1M | #define STEP_LINE(ix, tl)\ | 340 | 63.1M | tl.x += tl.ldi;\ | 341 | 63.1M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 63.1M | ix = rational_floor(tl) | 343 | | | 344 | 63.1M | rxl = rational_floor(l); | 345 | 63.1M | rxr = rational_floor(r); | 346 | 63.1M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 2.26G | 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 | 2.20G | register int ixl, ixr; | 365 | | | 366 | 2.20G | STEP_LINE(ixl, l); | 367 | 2.20G | STEP_LINE(ixr, r); | 368 | 2.20G | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 2.20G | if (ixl != rxl || ixr != rxr) { | 370 | 1.69G | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 1.69G | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 1.69G | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 1.69G | if (code < 0) | 374 | 0 | goto xit; | 375 | 1.69G | rxl = ixl, rxr = ixr, ry = iy; | 376 | 1.69G | } | 377 | 2.20G | # endif | 378 | 2.20G | } | 379 | 63.1M | # if !LINEAR_COLOR | 380 | 63.1M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 63.1M | #undef STEP_LINE | 385 | 63.1M | #undef SET_MINIMAL_WIDTH | 386 | 63.1M | #undef CONNECT_RECTANGLES | 387 | 63.1M | #undef FILL_TRAP_RECT | 388 | 63.1M | #undef FILL_TRAP_RECT_DIRECT | 389 | 63.1M | #undef FILL_TRAP_RECT_INRECT | 390 | 63.1M | #undef YMULT_QUO | 391 | 72.2M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 72.2M | return_if_interrupt(dev->memory); | 394 | 72.2M | return code; | 395 | 72.2M | } | 396 | 72.2M | } |
gdevddrw.c:gx_fill_trapezoid_as_lc Line | Count | Source | 137 | 3.25M | { | 138 | 3.25M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 3.25M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 3.25M | if (ymin >= ymax) | 142 | 353k | return 0; /* no scan lines to sample */ | 143 | 2.89M | { | 144 | 2.89M | int iy = fixed2int_var(ymin); | 145 | 2.89M | const int iy1 = fixed2int_var(ymax); | 146 | 2.89M | trap_line l, r; | 147 | 2.89M | register int rxl, rxr; | 148 | | #if !LINEAR_COLOR | 149 | | int ry; | 150 | | #endif | 151 | 2.89M | const fixed | 152 | 2.89M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 2.89M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 2.89M | const fixed /* partial pixel offset to first line to sample */ | 155 | 2.89M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 2.89M | fixed fxl; | 157 | 2.89M | int code; | 158 | | # if CONTIGUOUS_FILL | 159 | | const bool peak0 = ((flags & 1) != 0); | 160 | | const bool peak1 = ((flags & 2) != 0); | 161 | | int peak_y0 = ybot + fixed_half; | 162 | | int peak_y1 = ytop - fixed_half; | 163 | | # endif | 164 | 2.89M | # if LINEAR_COLOR | 165 | 2.89M | int num_components = dev->color_info.num_components; | 166 | 2.89M | frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 167 | 2.89M | int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 168 | 2.89M | int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 169 | 2.89M | frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 170 | 2.89M | int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 171 | 2.89M | int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 172 | 2.89M | frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 173 | 2.89M | int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 174 | 2.89M | int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 175 | 2.89M | trap_gradient lg, rg, xg; | 176 | | # else | 177 | | gx_color_index cindex = pdevc->colors.pure; | 178 | | dev_proc_fill_rectangle((*fill_rect)) = | 179 | | dev_proc(dev, fill_rectangle); | 180 | | # endif | 181 | | | 182 | 2.89M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 2.89M | l.h = left->end.y - left->start.y; | 185 | 2.89M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 2.89M | r.h = right->end.y - right->start.y; | 188 | 2.89M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 2.89M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 2.89M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | | #if !LINEAR_COLOR | 193 | | ry = iy; | 194 | | #endif | 195 | | | 196 | | /* | 197 | | * Free variables of FILL_TRAP_RECT: | 198 | | * SWAP_AXES, pdevc, dev, fa | 199 | | * Free variables of FILL_TRAP_RECT_DIRECT: | 200 | | * SWAP_AXES, fill_rect, dev, cindex | 201 | | */ | 202 | 2.89M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 2.89M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 2.89M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 2.89M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 2.89M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 2.89M | (*fill_rect)(dev, x, y, w, h, cindex)) | 208 | | | 209 | 2.89M | #if LINEAR_COLOR | 210 | 2.89M | # define FILL_TRAP_RECT(x,y,w,h)\ | 211 | 2.89M | (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den)) | 212 | | #else | 213 | | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | | #endif | 216 | | | 217 | | /* Compute the dx/dy ratios. */ | 218 | | | 219 | | /* | 220 | | * Compute the x offsets at the first scan line to sample. We need | 221 | | * to be careful in computing ys# * dx#f {/,%} h# because the | 222 | | * multiplication may overflow. We know that all the quantities | 223 | | * involved are non-negative, and that ys# is usually less than 1 (as | 224 | | * a fixed, of course); this gives us a cheap conservative check for | 225 | | * overflow in the multiplication. | 226 | | */ | 227 | 2.89M | #define YMULT_QUO(ys, tl)\ | 228 | 2.89M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 2.89M | fixed_mult_quo(ys, tl.df, tl.h)) | 230 | | | 231 | | #if CONTIGUOUS_FILL | 232 | | /* | 233 | | * If left and right boundary round to same pixel index, | 234 | | * we would not paing the scan and would get a dropout. | 235 | | * Check for this case and choose one of two pixels | 236 | | * which is closer to the "axis". We need to exclude | 237 | | * 'peak' because it would paint an excessive pixel. | 238 | | */ | 239 | | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \ | 240 | | if (ixl == ixr) \ | 241 | | if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\ | 242 | | fixed x = int2fixed(ixl) + fixed_half;\ | 243 | | if (x - l.x < r.x - x)\ | 244 | | ++ixr;\ | 245 | | else\ | 246 | | --ixl;\ | 247 | | } | 248 | | | 249 | | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\ | 250 | | if (adj1 < adj2) {\ | 251 | | if (iy - ry > 1) {\ | 252 | | code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\ | 253 | | if (code < 0)\ | 254 | | goto xit;\ | 255 | | ry = iy - 1;\ | 256 | | }\ | 257 | | adj1 = adj2 = (adj2 + adj2) / 2;\ | 258 | | } | 259 | | | 260 | | #else | 261 | 2.89M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 2.89M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 2.89M | #endif | 264 | 2.89M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 1.68M | l.di = 0, l.df = 0; | 267 | 1.68M | fxl = 0; | 268 | 1.68M | } else { | 269 | 1.21M | compute_dx(&l, dxl, ysl); | 270 | 1.21M | fxl = YMULT_QUO(ysl, l); | 271 | 1.21M | l.x += fxl; | 272 | 1.21M | } | 273 | 2.89M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | | # if !LINEAR_COLOR | 277 | | if (l.di == 0 && l.df == 0) { | 278 | | rxl = fixed2int_var(l.x); | 279 | | rxr = fixed2int_var(r.x); | 280 | | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | | goto xit; | 283 | | } | 284 | | # endif | 285 | 1.68M | r.di = 0, r.df = 0; | 286 | 1.68M | } | 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.21M | else if (dxr == dxl && fxl != 0) { | 292 | 721k | if (l.di == 0) | 293 | 249k | r.di = 0, r.df = l.df; | 294 | 472k | else | 295 | 472k | compute_dx(&r, dxr, ysr); | 296 | 721k | if (ysr == ysl && r.h == l.h) | 297 | 721k | r.x += fxl; | 298 | 272 | else | 299 | 272 | r.x += YMULT_QUO(ysr, r); | 300 | 721k | } else { | 301 | 489k | compute_dx(&r, dxr, ysr); | 302 | 489k | r.x += YMULT_QUO(ysr, r); | 303 | 489k | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 2.89M | compute_ldx(&l, ysl); | 306 | 2.89M | compute_ldx(&r, ysr); | 307 | | /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding | 308 | | when the rational part is zero. Now add it back to get xl', xr' */ | 309 | 2.89M | l.x += fixed_epsilon; | 310 | 2.89M | r.x += fixed_epsilon; | 311 | 2.89M | # if LINEAR_COLOR | 312 | | # ifdef DEBUG | 313 | | if (check_gradient_overflow(left, right)) { | 314 | | /* The caller must care of. | 315 | | Checking it here looses some performance with triangles. */ | 316 | | return_error(gs_error_unregistered); | 317 | | } | 318 | | # endif | 319 | 2.89M | lg.c = lgc; | 320 | 2.89M | lg.f = lgf; | 321 | 2.89M | lg.num = lgnum; | 322 | 2.89M | rg.c = rgc; | 323 | 2.89M | rg.f = rgf; | 324 | 2.89M | rg.num = rgnum; | 325 | 2.89M | xg.c = xgc; | 326 | 2.89M | xg.f = xgf; | 327 | 2.89M | xg.num = xgnum; | 328 | 2.89M | code = init_gradient(&lg, fa, left, right, &l, ymin, num_components); | 329 | 2.89M | if (code < 0) | 330 | 0 | return code; | 331 | 2.89M | code = init_gradient(&rg, fa, right, left, &r, ymin, num_components); | 332 | 2.89M | if (code < 0) | 333 | 0 | return code; | 334 | | | 335 | 2.89M | # endif | 336 | | | 337 | 2.89M | #define rational_floor(tl)\ | 338 | 2.89M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 2.89M | #define STEP_LINE(ix, tl)\ | 340 | 2.89M | tl.x += tl.ldi;\ | 341 | 2.89M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 2.89M | ix = rational_floor(tl) | 343 | | | 344 | 2.89M | rxl = rational_floor(l); | 345 | 2.89M | rxr = rational_floor(r); | 346 | 2.89M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 81.7M | while (LINEAR_COLOR ? 1 : ++iy != iy1) { | 348 | 81.7M | # if LINEAR_COLOR | 349 | 81.7M | if (rxl != rxr) { | 350 | 50.2M | code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components); | 351 | 50.2M | if (code < 0) | 352 | 0 | goto xit; | 353 | 50.2M | code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1); | 354 | 50.2M | if (code < 0) | 355 | 5 | goto xit; | 356 | 50.2M | } | 357 | 81.7M | if (++iy == iy1) | 358 | 2.89M | break; | 359 | 78.8M | STEP_LINE(rxl, l); | 360 | 78.8M | STEP_LINE(rxr, r); | 361 | 78.8M | step_gradient(&lg, num_components); | 362 | 78.8M | step_gradient(&rg, num_components); | 363 | | # else | 364 | | register int ixl, ixr; | 365 | | | 366 | | STEP_LINE(ixl, l); | 367 | | STEP_LINE(ixr, r); | 368 | | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | | if (ixl != rxl || ixr != rxr) { | 370 | | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | | if (code < 0) | 374 | | goto xit; | 375 | | rxl = ixl, rxr = ixr, ry = iy; | 376 | | } | 377 | | # endif | 378 | 78.8M | } | 379 | | # if !LINEAR_COLOR | 380 | | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | 2.89M | code = 0; | 383 | 2.89M | # endif | 384 | 2.89M | #undef STEP_LINE | 385 | 2.89M | #undef SET_MINIMAL_WIDTH | 386 | 2.89M | #undef CONNECT_RECTANGLES | 387 | 2.89M | #undef FILL_TRAP_RECT | 388 | 2.89M | #undef FILL_TRAP_RECT_DIRECT | 389 | 2.89M | #undef FILL_TRAP_RECT_INRECT | 390 | 2.89M | #undef YMULT_QUO | 391 | 2.89M | xit: if (code < 0 && FILL_DIRECT) | 392 | 5 | return_error(code); | 393 | 2.89M | return_if_interrupt(dev->memory); | 394 | 2.89M | return code; | 395 | 2.89M | } | 396 | 2.89M | } |
gdevddrw.c:gx_fill_trapezoid_ns_lc Line | Count | Source | 137 | 74.5M | { | 138 | 74.5M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 74.5M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 74.5M | if (ymin >= ymax) | 142 | 29.8M | return 0; /* no scan lines to sample */ | 143 | 44.6M | { | 144 | 44.6M | int iy = fixed2int_var(ymin); | 145 | 44.6M | const int iy1 = fixed2int_var(ymax); | 146 | 44.6M | trap_line l, r; | 147 | 44.6M | register int rxl, rxr; | 148 | | #if !LINEAR_COLOR | 149 | | int ry; | 150 | | #endif | 151 | 44.6M | const fixed | 152 | 44.6M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 44.6M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 44.6M | const fixed /* partial pixel offset to first line to sample */ | 155 | 44.6M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 44.6M | fixed fxl; | 157 | 44.6M | 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 | 44.6M | # if LINEAR_COLOR | 165 | 44.6M | int num_components = dev->color_info.num_components; | 166 | 44.6M | frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 167 | 44.6M | int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 168 | 44.6M | int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 169 | 44.6M | frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 170 | 44.6M | int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 171 | 44.6M | int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 172 | 44.6M | frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 173 | 44.6M | int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 174 | 44.6M | int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 175 | 44.6M | 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 | 44.6M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 44.6M | l.h = left->end.y - left->start.y; | 185 | 44.6M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 44.6M | r.h = right->end.y - right->start.y; | 188 | 44.6M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 44.6M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 44.6M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | | #if !LINEAR_COLOR | 193 | | ry = iy; | 194 | | #endif | 195 | | | 196 | | /* | 197 | | * Free variables of FILL_TRAP_RECT: | 198 | | * SWAP_AXES, pdevc, dev, fa | 199 | | * Free variables of FILL_TRAP_RECT_DIRECT: | 200 | | * SWAP_AXES, fill_rect, dev, cindex | 201 | | */ | 202 | 44.6M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 44.6M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 44.6M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 44.6M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 44.6M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 44.6M | (*fill_rect)(dev, x, y, w, h, cindex)) | 208 | | | 209 | 44.6M | #if LINEAR_COLOR | 210 | 44.6M | # define FILL_TRAP_RECT(x,y,w,h)\ | 211 | 44.6M | (!(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 | 44.6M | #define YMULT_QUO(ys, tl)\ | 228 | 44.6M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 44.6M | 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 | 44.6M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 44.6M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 44.6M | #endif | 264 | 44.6M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 9.41M | l.di = 0, l.df = 0; | 267 | 9.41M | fxl = 0; | 268 | 35.2M | } else { | 269 | 35.2M | compute_dx(&l, dxl, ysl); | 270 | 35.2M | fxl = YMULT_QUO(ysl, l); | 271 | 35.2M | l.x += fxl; | 272 | 35.2M | } | 273 | 44.6M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | | # if !LINEAR_COLOR | 277 | | if (l.di == 0 && l.df == 0) { | 278 | | rxl = fixed2int_var(l.x); | 279 | | rxr = fixed2int_var(r.x); | 280 | | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | | goto xit; | 283 | | } | 284 | | # endif | 285 | 9.37M | r.di = 0, r.df = 0; | 286 | 9.37M | } | 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 | 35.3M | else if (dxr == dxl && fxl != 0) { | 292 | 2.19M | if (l.di == 0) | 293 | 688k | r.di = 0, r.df = l.df; | 294 | 1.50M | else | 295 | 1.50M | compute_dx(&r, dxr, ysr); | 296 | 2.19M | if (ysr == ysl && r.h == l.h) | 297 | 1.47M | r.x += fxl; | 298 | 718k | else | 299 | 718k | r.x += YMULT_QUO(ysr, r); | 300 | 33.1M | } else { | 301 | 33.1M | compute_dx(&r, dxr, ysr); | 302 | 33.1M | r.x += YMULT_QUO(ysr, r); | 303 | 33.1M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 44.6M | compute_ldx(&l, ysl); | 306 | 44.6M | compute_ldx(&r, ysr); | 307 | | /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding | 308 | | when the rational part is zero. Now add it back to get xl', xr' */ | 309 | 44.6M | l.x += fixed_epsilon; | 310 | 44.6M | r.x += fixed_epsilon; | 311 | 44.6M | # 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 | 44.6M | lg.c = lgc; | 320 | 44.6M | lg.f = lgf; | 321 | 44.6M | lg.num = lgnum; | 322 | 44.6M | rg.c = rgc; | 323 | 44.6M | rg.f = rgf; | 324 | 44.6M | rg.num = rgnum; | 325 | 44.6M | xg.c = xgc; | 326 | 44.6M | xg.f = xgf; | 327 | 44.6M | xg.num = xgnum; | 328 | 44.6M | code = init_gradient(&lg, fa, left, right, &l, ymin, num_components); | 329 | 44.6M | if (code < 0) | 330 | 0 | return code; | 331 | 44.6M | code = init_gradient(&rg, fa, right, left, &r, ymin, num_components); | 332 | 44.6M | if (code < 0) | 333 | 0 | return code; | 334 | | | 335 | 44.6M | # endif | 336 | | | 337 | 44.6M | #define rational_floor(tl)\ | 338 | 44.6M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 44.6M | #define STEP_LINE(ix, tl)\ | 340 | 44.6M | tl.x += tl.ldi;\ | 341 | 44.6M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 44.6M | ix = rational_floor(tl) | 343 | | | 344 | 44.6M | rxl = rational_floor(l); | 345 | 44.6M | rxr = rational_floor(r); | 346 | 44.6M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 413M | while (LINEAR_COLOR ? 1 : ++iy != iy1) { | 348 | 413M | # if LINEAR_COLOR | 349 | 413M | if (rxl != rxr) { | 350 | 103M | code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components); | 351 | 103M | if (code < 0) | 352 | 0 | goto xit; | 353 | 103M | code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1); | 354 | 103M | if (code < 0) | 355 | 15 | goto xit; | 356 | 103M | } | 357 | 413M | if (++iy == iy1) | 358 | 44.6M | break; | 359 | 369M | STEP_LINE(rxl, l); | 360 | 369M | STEP_LINE(rxr, r); | 361 | 369M | step_gradient(&lg, num_components); | 362 | 369M | 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 | 369M | } | 379 | | # if !LINEAR_COLOR | 380 | | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | 44.6M | code = 0; | 383 | 44.6M | # endif | 384 | 44.6M | #undef STEP_LINE | 385 | 44.6M | #undef SET_MINIMAL_WIDTH | 386 | 44.6M | #undef CONNECT_RECTANGLES | 387 | 44.6M | #undef FILL_TRAP_RECT | 388 | 44.6M | #undef FILL_TRAP_RECT_DIRECT | 389 | 44.6M | #undef FILL_TRAP_RECT_INRECT | 390 | 44.6M | #undef YMULT_QUO | 391 | 44.6M | xit: if (code < 0 && FILL_DIRECT) | 392 | 15 | return_error(code); | 393 | 44.6M | return_if_interrupt(dev->memory); | 394 | 44.6M | return code; | 395 | 44.6M | } | 396 | 44.6M | } |
|