396 | 186M | } 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.75M | { | 138 | 3.75M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 3.75M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 3.75M | if (ymin >= ymax) | 142 | 199k | return 0; /* no scan lines to sample */ | 143 | 3.55M | { | 144 | 3.55M | int iy = fixed2int_var(ymin); | 145 | 3.55M | const int iy1 = fixed2int_var(ymax); | 146 | 3.55M | trap_line l, r; | 147 | 3.55M | register int rxl, rxr; | 148 | 3.55M | #if !LINEAR_COLOR | 149 | 3.55M | int ry; | 150 | 3.55M | #endif | 151 | 3.55M | const fixed | 152 | 3.55M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 3.55M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 3.55M | const fixed /* partial pixel offset to first line to sample */ | 155 | 3.55M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 3.55M | fixed fxl; | 157 | 3.55M | 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.55M | gx_color_index cindex = pdevc->colors.pure; | 178 | 3.55M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 3.55M | dev_proc(dev, fill_rectangle); | 180 | 3.55M | # endif | 181 | | | 182 | 3.55M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 3.55M | l.h = left->end.y - left->start.y; | 185 | 3.55M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 3.55M | r.h = right->end.y - right->start.y; | 188 | 3.55M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 3.55M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 3.55M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 3.55M | #if !LINEAR_COLOR | 193 | 3.55M | ry = iy; | 194 | 3.55M | #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.55M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 3.55M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 3.55M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 3.55M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 3.55M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 3.55M | (*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.55M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 3.55M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 3.55M | #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.55M | #define YMULT_QUO(ys, tl)\ | 228 | 3.55M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 3.55M | 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.55M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 3.55M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 3.55M | #endif | 264 | 3.55M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 1.04M | l.di = 0, l.df = 0; | 267 | 1.04M | fxl = 0; | 268 | 2.50M | } else { | 269 | 2.50M | compute_dx(&l, dxl, ysl); | 270 | 2.50M | fxl = YMULT_QUO(ysl, l); | 271 | 2.50M | l.x += fxl; | 272 | 2.50M | } | 273 | 3.55M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 952k | # if !LINEAR_COLOR | 277 | 952k | if (l.di == 0 && l.df == 0) { | 278 | 888k | rxl = fixed2int_var(l.x); | 279 | 888k | rxr = fixed2int_var(r.x); | 280 | 888k | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 888k | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 888k | goto xit; | 283 | 888k | } | 284 | 64.6k | # endif | 285 | 64.6k | r.di = 0, r.df = 0; | 286 | 64.6k | } | 287 | | /* | 288 | | * The test for fxl != 0 is required because the right edge might | 289 | | * cross some pixel centers even if the left edge doesn't. | 290 | | */ | 291 | 2.60M | else if (dxr == dxl && fxl != 0) { | 292 | 1.41M | if (l.di == 0) | 293 | 749k | r.di = 0, r.df = l.df; | 294 | 665k | else | 295 | 665k | compute_dx(&r, dxr, ysr); | 296 | 1.41M | if (ysr == ysl && r.h == l.h) | 297 | 1.41M | r.x += fxl; | 298 | 179 | else | 299 | 179 | r.x += YMULT_QUO(ysr, r); | 300 | 1.41M | } else { | 301 | 1.18M | compute_dx(&r, dxr, ysr); | 302 | 1.18M | r.x += YMULT_QUO(ysr, r); | 303 | 1.18M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 2.66M | compute_ldx(&l, ysl); | 306 | 2.66M | compute_ldx(&r, ysr); | 307 | | /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding | 308 | | when the rational part is zero. Now add it back to get xl', xr' */ | 309 | 2.66M | l.x += fixed_epsilon; | 310 | 2.66M | 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.66M | #define rational_floor(tl)\ | 338 | 2.66M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 2.66M | #define STEP_LINE(ix, tl)\ | 340 | 2.66M | tl.x += tl.ldi;\ | 341 | 2.66M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 2.66M | ix = rational_floor(tl) | 343 | | | 344 | 2.66M | rxl = rational_floor(l); | 345 | 2.66M | rxr = rational_floor(r); | 346 | 2.66M | 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.6M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 54.6M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 54.6M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 54.6M | if (code < 0) | 374 | 0 | goto xit; | 375 | 54.6M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 54.6M | } | 377 | 257M | # endif | 378 | 257M | } | 379 | 2.66M | # if !LINEAR_COLOR | 380 | 2.66M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 2.66M | #undef STEP_LINE | 385 | 2.66M | #undef SET_MINIMAL_WIDTH | 386 | 2.66M | #undef CONNECT_RECTANGLES | 387 | 2.66M | #undef FILL_TRAP_RECT | 388 | 2.66M | #undef FILL_TRAP_RECT_DIRECT | 389 | 2.66M | #undef FILL_TRAP_RECT_INRECT | 390 | 2.66M | #undef YMULT_QUO | 391 | 3.55M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 3.55M | return_if_interrupt(dev->memory); | 394 | 3.55M | return code; | 395 | 3.55M | } | 396 | 3.55M | } |
gdevddrw.c:gx_fill_trapezoid_as_nd Line | Count | Source | 137 | 5.04M | { | 138 | 5.04M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 5.04M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 5.04M | if (ymin >= ymax) | 142 | 61.6k | return 0; /* no scan lines to sample */ | 143 | 4.97M | { | 144 | 4.97M | int iy = fixed2int_var(ymin); | 145 | 4.97M | const int iy1 = fixed2int_var(ymax); | 146 | 4.97M | trap_line l, r; | 147 | 4.97M | register int rxl, rxr; | 148 | 4.97M | #if !LINEAR_COLOR | 149 | 4.97M | int ry; | 150 | 4.97M | #endif | 151 | 4.97M | const fixed | 152 | 4.97M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 4.97M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 4.97M | const fixed /* partial pixel offset to first line to sample */ | 155 | 4.97M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 4.97M | fixed fxl; | 157 | 4.97M | 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 | 4.97M | gx_color_index cindex = pdevc->colors.pure; | 178 | 4.97M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 4.97M | dev_proc(dev, fill_rectangle); | 180 | 4.97M | # endif | 181 | | | 182 | 4.97M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 4.97M | l.h = left->end.y - left->start.y; | 185 | 4.97M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 4.97M | r.h = right->end.y - right->start.y; | 188 | 4.97M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 4.97M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 4.97M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 4.97M | #if !LINEAR_COLOR | 193 | 4.97M | ry = iy; | 194 | 4.97M | #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 | 4.97M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 4.97M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 4.97M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 4.97M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 4.97M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 4.97M | (*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 | 4.97M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 4.97M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 4.97M | #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 | 4.97M | #define YMULT_QUO(ys, tl)\ | 228 | 4.97M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 4.97M | 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 | 4.97M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 4.97M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 4.97M | #endif | 264 | 4.97M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 1.02M | l.di = 0, l.df = 0; | 267 | 1.02M | fxl = 0; | 268 | 3.95M | } else { | 269 | 3.95M | compute_dx(&l, dxl, ysl); | 270 | 3.95M | fxl = YMULT_QUO(ysl, l); | 271 | 3.95M | l.x += fxl; | 272 | 3.95M | } | 273 | 4.97M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 916k | # if !LINEAR_COLOR | 277 | 916k | if (l.di == 0 && l.df == 0) { | 278 | 869k | rxl = fixed2int_var(l.x); | 279 | 869k | rxr = fixed2int_var(r.x); | 280 | 869k | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 869k | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 869k | goto xit; | 283 | 869k | } | 284 | 46.7k | # endif | 285 | 46.7k | r.di = 0, r.df = 0; | 286 | 46.7k | } | 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.06M | else if (dxr == dxl && fxl != 0) { | 292 | 549k | if (l.di == 0) | 293 | 318k | r.di = 0, r.df = l.df; | 294 | 231k | else | 295 | 231k | compute_dx(&r, dxr, ysr); | 296 | 549k | if (ysr == ysl && r.h == l.h) | 297 | 549k | r.x += fxl; | 298 | 296 | else | 299 | 296 | r.x += YMULT_QUO(ysr, r); | 300 | 3.51M | } else { | 301 | 3.51M | compute_dx(&r, dxr, ysr); | 302 | 3.51M | r.x += YMULT_QUO(ysr, r); | 303 | 3.51M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 4.11M | compute_ldx(&l, ysl); | 306 | 4.11M | 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.11M | l.x += fixed_epsilon; | 310 | 4.11M | 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.11M | #define rational_floor(tl)\ | 338 | 4.11M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 4.11M | #define STEP_LINE(ix, tl)\ | 340 | 4.11M | tl.x += tl.ldi;\ | 341 | 4.11M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 4.11M | ix = rational_floor(tl) | 343 | | | 344 | 4.11M | rxl = rational_floor(l); | 345 | 4.11M | rxr = rational_floor(r); | 346 | 4.11M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 666M | 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 | 662M | register int ixl, ixr; | 365 | | | 366 | 662M | STEP_LINE(ixl, l); | 367 | 662M | STEP_LINE(ixr, r); | 368 | 662M | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 662M | if (ixl != rxl || ixr != rxr) { | 370 | 518M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 518M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 518M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 518M | if (code < 0) | 374 | 0 | goto xit; | 375 | 518M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 518M | } | 377 | 662M | # endif | 378 | 662M | } | 379 | 4.11M | # if !LINEAR_COLOR | 380 | 4.11M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 4.11M | #undef STEP_LINE | 385 | 4.11M | #undef SET_MINIMAL_WIDTH | 386 | 4.11M | #undef CONNECT_RECTANGLES | 387 | 4.11M | #undef FILL_TRAP_RECT | 388 | 4.11M | #undef FILL_TRAP_RECT_DIRECT | 389 | 4.11M | #undef FILL_TRAP_RECT_INRECT | 390 | 4.11M | #undef YMULT_QUO | 391 | 4.97M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 4.97M | return_if_interrupt(dev->memory); | 394 | 4.97M | return code; | 395 | 4.97M | } | 396 | 4.97M | } |
gdevddrw.c:gx_fill_trapezoid_ns_fd Line | Count | Source | 137 | 67.3M | { | 138 | 67.3M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 67.3M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 67.3M | if (ymin >= ymax) | 142 | 7.18M | return 0; /* no scan lines to sample */ | 143 | 60.1M | { | 144 | 60.1M | int iy = fixed2int_var(ymin); | 145 | 60.1M | const int iy1 = fixed2int_var(ymax); | 146 | 60.1M | trap_line l, r; | 147 | 60.1M | register int rxl, rxr; | 148 | 60.1M | #if !LINEAR_COLOR | 149 | 60.1M | int ry; | 150 | 60.1M | #endif | 151 | 60.1M | const fixed | 152 | 60.1M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 60.1M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 60.1M | const fixed /* partial pixel offset to first line to sample */ | 155 | 60.1M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 60.1M | fixed fxl; | 157 | 60.1M | int code; | 158 | | # if CONTIGUOUS_FILL | 159 | | const bool peak0 = ((flags & 1) != 0); | 160 | | const bool peak1 = ((flags & 2) != 0); | 161 | | int peak_y0 = ybot + fixed_half; | 162 | | int peak_y1 = ytop - fixed_half; | 163 | | # endif | 164 | | # if LINEAR_COLOR | 165 | | int num_components = dev->color_info.num_components; | 166 | | frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 167 | | int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 168 | | int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 169 | | frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 170 | | int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 171 | | int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 172 | | frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 173 | | int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 174 | | int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 175 | | trap_gradient lg, rg, xg; | 176 | | # else | 177 | 60.1M | gx_color_index cindex = pdevc->colors.pure; | 178 | 60.1M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 60.1M | dev_proc(dev, fill_rectangle); | 180 | 60.1M | # endif | 181 | | | 182 | 60.1M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 60.1M | l.h = left->end.y - left->start.y; | 185 | 60.1M | if (l.h == 0) | 186 | 12 | return 0; | 187 | 60.1M | r.h = right->end.y - right->start.y; | 188 | 60.1M | if (r.h == 0) | 189 | 12 | return 0; | 190 | 60.1M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 60.1M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 60.1M | #if !LINEAR_COLOR | 193 | 60.1M | ry = iy; | 194 | 60.1M | #endif | 195 | | | 196 | | /* | 197 | | * Free variables of FILL_TRAP_RECT: | 198 | | * SWAP_AXES, pdevc, dev, fa | 199 | | * Free variables of FILL_TRAP_RECT_DIRECT: | 200 | | * SWAP_AXES, fill_rect, dev, cindex | 201 | | */ | 202 | 60.1M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 60.1M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 60.1M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 60.1M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 60.1M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 60.1M | (*fill_rect)(dev, x, y, w, h, cindex)) | 208 | | | 209 | | #if LINEAR_COLOR | 210 | | # define FILL_TRAP_RECT(x,y,w,h)\ | 211 | | (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den)) | 212 | | #else | 213 | 60.1M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 60.1M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 60.1M | #endif | 216 | | | 217 | | /* Compute the dx/dy ratios. */ | 218 | | | 219 | | /* | 220 | | * Compute the x offsets at the first scan line to sample. We need | 221 | | * to be careful in computing ys# * dx#f {/,%} h# because the | 222 | | * multiplication may overflow. We know that all the quantities | 223 | | * involved are non-negative, and that ys# is usually less than 1 (as | 224 | | * a fixed, of course); this gives us a cheap conservative check for | 225 | | * overflow in the multiplication. | 226 | | */ | 227 | 60.1M | #define YMULT_QUO(ys, tl)\ | 228 | 60.1M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 60.1M | fixed_mult_quo(ys, tl.df, tl.h)) | 230 | | | 231 | | #if CONTIGUOUS_FILL | 232 | | /* | 233 | | * If left and right boundary round to same pixel index, | 234 | | * we would not paing the scan and would get a dropout. | 235 | | * Check for this case and choose one of two pixels | 236 | | * which is closer to the "axis". We need to exclude | 237 | | * 'peak' because it would paint an excessive pixel. | 238 | | */ | 239 | | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \ | 240 | | if (ixl == ixr) \ | 241 | | if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\ | 242 | | fixed x = int2fixed(ixl) + fixed_half;\ | 243 | | if (x - l.x < r.x - x)\ | 244 | | ++ixr;\ | 245 | | else\ | 246 | | --ixl;\ | 247 | | } | 248 | | | 249 | | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\ | 250 | | if (adj1 < adj2) {\ | 251 | | if (iy - ry > 1) {\ | 252 | | code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\ | 253 | | if (code < 0)\ | 254 | | goto xit;\ | 255 | | ry = iy - 1;\ | 256 | | }\ | 257 | | adj1 = adj2 = (adj2 + adj2) / 2;\ | 258 | | } | 259 | | | 260 | | #else | 261 | 60.1M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 60.1M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 60.1M | #endif | 264 | 60.1M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 23.4M | l.di = 0, l.df = 0; | 267 | 23.4M | fxl = 0; | 268 | 36.7M | } else { | 269 | 36.7M | compute_dx(&l, dxl, ysl); | 270 | 36.7M | fxl = YMULT_QUO(ysl, l); | 271 | 36.7M | l.x += fxl; | 272 | 36.7M | } | 273 | 60.1M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 23.5M | # if !LINEAR_COLOR | 277 | 23.5M | if (l.di == 0 && l.df == 0) { | 278 | 12.7M | rxl = fixed2int_var(l.x); | 279 | 12.7M | rxr = fixed2int_var(r.x); | 280 | 12.7M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 12.7M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 12.7M | goto xit; | 283 | 12.7M | } | 284 | 10.7M | # endif | 285 | 10.7M | r.di = 0, r.df = 0; | 286 | 10.7M | } | 287 | | /* | 288 | | * The test for fxl != 0 is required because the right edge might | 289 | | * cross some pixel centers even if the left edge doesn't. | 290 | | */ | 291 | 36.5M | else if (dxr == dxl && fxl != 0) { | 292 | 3.58M | if (l.di == 0) | 293 | 910k | r.di = 0, r.df = l.df; | 294 | 2.67M | else | 295 | 2.67M | compute_dx(&r, dxr, ysr); | 296 | 3.58M | if (ysr == ysl && r.h == l.h) | 297 | 2.20M | r.x += fxl; | 298 | 1.38M | else | 299 | 1.38M | r.x += YMULT_QUO(ysr, r); | 300 | 32.9M | } else { | 301 | 32.9M | compute_dx(&r, dxr, ysr); | 302 | 32.9M | r.x += YMULT_QUO(ysr, r); | 303 | 32.9M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 47.3M | compute_ldx(&l, ysl); | 306 | 47.3M | compute_ldx(&r, ysr); | 307 | | /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding | 308 | | when the rational part is zero. Now add it back to get xl', xr' */ | 309 | 47.3M | l.x += fixed_epsilon; | 310 | 47.3M | r.x += fixed_epsilon; | 311 | | # if LINEAR_COLOR | 312 | | # ifdef DEBUG | 313 | | if (check_gradient_overflow(left, right)) { | 314 | | /* The caller must care of. | 315 | | Checking it here looses some performance with triangles. */ | 316 | | return_error(gs_error_unregistered); | 317 | | } | 318 | | # endif | 319 | | lg.c = lgc; | 320 | | lg.f = lgf; | 321 | | lg.num = lgnum; | 322 | | rg.c = rgc; | 323 | | rg.f = rgf; | 324 | | rg.num = rgnum; | 325 | | xg.c = xgc; | 326 | | xg.f = xgf; | 327 | | xg.num = xgnum; | 328 | | code = init_gradient(&lg, fa, left, right, &l, ymin, num_components); | 329 | | if (code < 0) | 330 | | return code; | 331 | | code = init_gradient(&rg, fa, right, left, &r, ymin, num_components); | 332 | | if (code < 0) | 333 | | return code; | 334 | | | 335 | | # endif | 336 | | | 337 | 47.3M | #define rational_floor(tl)\ | 338 | 47.3M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 47.3M | #define STEP_LINE(ix, tl)\ | 340 | 47.3M | tl.x += tl.ldi;\ | 341 | 47.3M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 47.3M | ix = rational_floor(tl) | 343 | | | 344 | 47.3M | rxl = rational_floor(l); | 345 | 47.3M | rxr = rational_floor(r); | 346 | 47.3M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 2.95G | 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.90G | register int ixl, ixr; | 365 | | | 366 | 2.90G | STEP_LINE(ixl, l); | 367 | 2.90G | STEP_LINE(ixr, r); | 368 | 2.90G | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 2.90G | if (ixl != rxl || ixr != rxr) { | 370 | 424M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 424M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 424M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 424M | if (code < 0) | 374 | 0 | goto xit; | 375 | 424M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 424M | } | 377 | 2.90G | # endif | 378 | 2.90G | } | 379 | 47.3M | # if !LINEAR_COLOR | 380 | 47.3M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 47.3M | #undef STEP_LINE | 385 | 47.3M | #undef SET_MINIMAL_WIDTH | 386 | 47.3M | #undef CONNECT_RECTANGLES | 387 | 47.3M | #undef FILL_TRAP_RECT | 388 | 47.3M | #undef FILL_TRAP_RECT_DIRECT | 389 | 47.3M | #undef FILL_TRAP_RECT_INRECT | 390 | 47.3M | #undef YMULT_QUO | 391 | 60.1M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 60.1M | return_if_interrupt(dev->memory); | 394 | 60.1M | return code; | 395 | 60.1M | } | 396 | 60.1M | } |
gdevddrw.c:gx_fill_trapezoid_ns_nd Line | Count | Source | 137 | 95.0M | { | 138 | 95.0M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 95.0M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 95.0M | if (ymin >= ymax) | 142 | 25.4M | return 0; /* no scan lines to sample */ | 143 | 69.5M | { | 144 | 69.5M | int iy = fixed2int_var(ymin); | 145 | 69.5M | const int iy1 = fixed2int_var(ymax); | 146 | 69.5M | trap_line l, r; | 147 | 69.5M | register int rxl, rxr; | 148 | 69.5M | #if !LINEAR_COLOR | 149 | 69.5M | int ry; | 150 | 69.5M | #endif | 151 | 69.5M | const fixed | 152 | 69.5M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 69.5M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 69.5M | const fixed /* partial pixel offset to first line to sample */ | 155 | 69.5M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 69.5M | fixed fxl; | 157 | 69.5M | int code; | 158 | | # if CONTIGUOUS_FILL | 159 | | const bool peak0 = ((flags & 1) != 0); | 160 | | const bool peak1 = ((flags & 2) != 0); | 161 | | int peak_y0 = ybot + fixed_half; | 162 | | int peak_y1 = ytop - fixed_half; | 163 | | # endif | 164 | | # if LINEAR_COLOR | 165 | | int num_components = dev->color_info.num_components; | 166 | | frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 167 | | int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 168 | | int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 169 | | frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 170 | | int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 171 | | int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 172 | | frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 173 | | int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 174 | | int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 175 | | trap_gradient lg, rg, xg; | 176 | | # else | 177 | 69.5M | gx_color_index cindex = pdevc->colors.pure; | 178 | 69.5M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 69.5M | dev_proc(dev, fill_rectangle); | 180 | 69.5M | # endif | 181 | | | 182 | 69.5M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 69.5M | l.h = left->end.y - left->start.y; | 185 | 69.5M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 69.5M | r.h = right->end.y - right->start.y; | 188 | 69.5M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 69.5M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 69.5M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 69.5M | #if !LINEAR_COLOR | 193 | 69.5M | ry = iy; | 194 | 69.5M | #endif | 195 | | | 196 | | /* | 197 | | * Free variables of FILL_TRAP_RECT: | 198 | | * SWAP_AXES, pdevc, dev, fa | 199 | | * Free variables of FILL_TRAP_RECT_DIRECT: | 200 | | * SWAP_AXES, fill_rect, dev, cindex | 201 | | */ | 202 | 69.5M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 69.5M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 69.5M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 69.5M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 69.5M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 69.5M | (*fill_rect)(dev, x, y, w, h, cindex)) | 208 | | | 209 | | #if LINEAR_COLOR | 210 | | # define FILL_TRAP_RECT(x,y,w,h)\ | 211 | | (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den)) | 212 | | #else | 213 | 69.5M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 69.5M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 69.5M | #endif | 216 | | | 217 | | /* Compute the dx/dy ratios. */ | 218 | | | 219 | | /* | 220 | | * Compute the x offsets at the first scan line to sample. We need | 221 | | * to be careful in computing ys# * dx#f {/,%} h# because the | 222 | | * multiplication may overflow. We know that all the quantities | 223 | | * involved are non-negative, and that ys# is usually less than 1 (as | 224 | | * a fixed, of course); this gives us a cheap conservative check for | 225 | | * overflow in the multiplication. | 226 | | */ | 227 | 69.5M | #define YMULT_QUO(ys, tl)\ | 228 | 69.5M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 69.5M | fixed_mult_quo(ys, tl.df, tl.h)) | 230 | | | 231 | | #if CONTIGUOUS_FILL | 232 | | /* | 233 | | * If left and right boundary round to same pixel index, | 234 | | * we would not paing the scan and would get a dropout. | 235 | | * Check for this case and choose one of two pixels | 236 | | * which is closer to the "axis". We need to exclude | 237 | | * 'peak' because it would paint an excessive pixel. | 238 | | */ | 239 | | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \ | 240 | | if (ixl == ixr) \ | 241 | | if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\ | 242 | | fixed x = int2fixed(ixl) + fixed_half;\ | 243 | | if (x - l.x < r.x - x)\ | 244 | | ++ixr;\ | 245 | | else\ | 246 | | --ixl;\ | 247 | | } | 248 | | | 249 | | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\ | 250 | | if (adj1 < adj2) {\ | 251 | | if (iy - ry > 1) {\ | 252 | | code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\ | 253 | | if (code < 0)\ | 254 | | goto xit;\ | 255 | | ry = iy - 1;\ | 256 | | }\ | 257 | | adj1 = adj2 = (adj2 + adj2) / 2;\ | 258 | | } | 259 | | | 260 | | #else | 261 | 69.5M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 69.5M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 69.5M | #endif | 264 | 69.5M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 16.6M | l.di = 0, l.df = 0; | 267 | 16.6M | fxl = 0; | 268 | 52.9M | } else { | 269 | 52.9M | compute_dx(&l, dxl, ysl); | 270 | 52.9M | fxl = YMULT_QUO(ysl, l); | 271 | 52.9M | l.x += fxl; | 272 | 52.9M | } | 273 | 69.5M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 21.5M | # if !LINEAR_COLOR | 277 | 21.5M | if (l.di == 0 && l.df == 0) { | 278 | 8.84M | rxl = fixed2int_var(l.x); | 279 | 8.84M | rxr = fixed2int_var(r.x); | 280 | 8.84M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 8.84M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 8.84M | goto xit; | 283 | 8.84M | } | 284 | 12.7M | # endif | 285 | 12.7M | r.di = 0, r.df = 0; | 286 | 12.7M | } | 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 | 47.9M | else if (dxr == dxl && fxl != 0) { | 292 | 3.68M | if (l.di == 0) | 293 | 519k | r.di = 0, r.df = l.df; | 294 | 3.16M | else | 295 | 3.16M | compute_dx(&r, dxr, ysr); | 296 | 3.68M | if (ysr == ysl && r.h == l.h) | 297 | 2.59M | r.x += fxl; | 298 | 1.09M | else | 299 | 1.09M | r.x += YMULT_QUO(ysr, r); | 300 | 44.3M | } else { | 301 | 44.3M | compute_dx(&r, dxr, ysr); | 302 | 44.3M | r.x += YMULT_QUO(ysr, r); | 303 | 44.3M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 60.7M | compute_ldx(&l, ysl); | 306 | 60.7M | compute_ldx(&r, ysr); | 307 | | /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding | 308 | | when the rational part is zero. Now add it back to get xl', xr' */ | 309 | 60.7M | l.x += fixed_epsilon; | 310 | 60.7M | r.x += fixed_epsilon; | 311 | | # if LINEAR_COLOR | 312 | | # ifdef DEBUG | 313 | | if (check_gradient_overflow(left, right)) { | 314 | | /* The caller must care of. | 315 | | Checking it here looses some performance with triangles. */ | 316 | | return_error(gs_error_unregistered); | 317 | | } | 318 | | # endif | 319 | | lg.c = lgc; | 320 | | lg.f = lgf; | 321 | | lg.num = lgnum; | 322 | | rg.c = rgc; | 323 | | rg.f = rgf; | 324 | | rg.num = rgnum; | 325 | | xg.c = xgc; | 326 | | xg.f = xgf; | 327 | | xg.num = xgnum; | 328 | | code = init_gradient(&lg, fa, left, right, &l, ymin, num_components); | 329 | | if (code < 0) | 330 | | return code; | 331 | | code = init_gradient(&rg, fa, right, left, &r, ymin, num_components); | 332 | | if (code < 0) | 333 | | return code; | 334 | | | 335 | | # endif | 336 | | | 337 | 60.7M | #define rational_floor(tl)\ | 338 | 60.7M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 60.7M | #define STEP_LINE(ix, tl)\ | 340 | 60.7M | tl.x += tl.ldi;\ | 341 | 60.7M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 60.7M | ix = rational_floor(tl) | 343 | | | 344 | 60.7M | rxl = rational_floor(l); | 345 | 60.7M | rxr = rational_floor(r); | 346 | 60.7M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 2.28G | 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.22G | register int ixl, ixr; | 365 | | | 366 | 2.22G | STEP_LINE(ixl, l); | 367 | 2.22G | STEP_LINE(ixr, r); | 368 | 2.22G | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 2.22G | if (ixl != rxl || ixr != rxr) { | 370 | 1.72G | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 1.72G | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 1.72G | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 1.72G | if (code < 0) | 374 | 0 | goto xit; | 375 | 1.72G | rxl = ixl, rxr = ixr, ry = iy; | 376 | 1.72G | } | 377 | 2.22G | # endif | 378 | 2.22G | } | 379 | 60.7M | # if !LINEAR_COLOR | 380 | 60.7M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 60.7M | #undef STEP_LINE | 385 | 60.7M | #undef SET_MINIMAL_WIDTH | 386 | 60.7M | #undef CONNECT_RECTANGLES | 387 | 60.7M | #undef FILL_TRAP_RECT | 388 | 60.7M | #undef FILL_TRAP_RECT_DIRECT | 389 | 60.7M | #undef FILL_TRAP_RECT_INRECT | 390 | 60.7M | #undef YMULT_QUO | 391 | 69.5M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 69.5M | return_if_interrupt(dev->memory); | 394 | 69.5M | return code; | 395 | 69.5M | } | 396 | 69.5M | } |
gdevddrw.c:gx_fill_trapezoid_as_lc Line | Count | Source | 137 | 3.24M | { | 138 | 3.24M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 3.24M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 3.24M | if (ymin >= ymax) | 142 | 355k | return 0; /* no scan lines to sample */ | 143 | 2.88M | { | 144 | 2.88M | int iy = fixed2int_var(ymin); | 145 | 2.88M | const int iy1 = fixed2int_var(ymax); | 146 | 2.88M | trap_line l, r; | 147 | 2.88M | register int rxl, rxr; | 148 | | #if !LINEAR_COLOR | 149 | | int ry; | 150 | | #endif | 151 | 2.88M | const fixed | 152 | 2.88M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 2.88M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 2.88M | const fixed /* partial pixel offset to first line to sample */ | 155 | 2.88M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 2.88M | fixed fxl; | 157 | 2.88M | 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.88M | # if LINEAR_COLOR | 165 | 2.88M | int num_components = dev->color_info.num_components; | 166 | 2.88M | frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 167 | 2.88M | int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 168 | 2.88M | int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 169 | 2.88M | frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 170 | 2.88M | int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 171 | 2.88M | int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 172 | 2.88M | frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 173 | 2.88M | int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 174 | 2.88M | int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 175 | 2.88M | 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.88M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 2.88M | l.h = left->end.y - left->start.y; | 185 | 2.88M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 2.88M | r.h = right->end.y - right->start.y; | 188 | 2.88M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 2.88M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 2.88M | 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.88M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 2.88M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 2.88M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 2.88M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 2.88M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 2.88M | (*fill_rect)(dev, x, y, w, h, cindex)) | 208 | | | 209 | 2.88M | #if LINEAR_COLOR | 210 | 2.88M | # define FILL_TRAP_RECT(x,y,w,h)\ | 211 | 2.88M | (!(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.88M | #define YMULT_QUO(ys, tl)\ | 228 | 2.88M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 2.88M | 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.88M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 2.88M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 2.88M | #endif | 264 | 2.88M | 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.20M | compute_dx(&l, dxl, ysl); | 270 | 1.20M | fxl = YMULT_QUO(ysl, l); | 271 | 1.20M | l.x += fxl; | 272 | 1.20M | } | 273 | 2.88M | 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.20M | else if (dxr == dxl && fxl != 0) { | 292 | 717k | if (l.di == 0) | 293 | 246k | r.di = 0, r.df = l.df; | 294 | 470k | else | 295 | 470k | compute_dx(&r, dxr, ysr); | 296 | 717k | if (ysr == ysl && r.h == l.h) | 297 | 717k | r.x += fxl; | 298 | 282 | else | 299 | 282 | r.x += YMULT_QUO(ysr, r); | 300 | 717k | } 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.88M | compute_ldx(&l, ysl); | 306 | 2.88M | 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.88M | l.x += fixed_epsilon; | 310 | 2.88M | r.x += fixed_epsilon; | 311 | 2.88M | # 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.88M | lg.c = lgc; | 320 | 2.88M | lg.f = lgf; | 321 | 2.88M | lg.num = lgnum; | 322 | 2.88M | rg.c = rgc; | 323 | 2.88M | rg.f = rgf; | 324 | 2.88M | rg.num = rgnum; | 325 | 2.88M | xg.c = xgc; | 326 | 2.88M | xg.f = xgf; | 327 | 2.88M | xg.num = xgnum; | 328 | 2.88M | code = init_gradient(&lg, fa, left, right, &l, ymin, num_components); | 329 | 2.88M | if (code < 0) | 330 | 0 | return code; | 331 | 2.88M | code = init_gradient(&rg, fa, right, left, &r, ymin, num_components); | 332 | 2.88M | if (code < 0) | 333 | 0 | return code; | 334 | | | 335 | 2.88M | # endif | 336 | | | 337 | 2.88M | #define rational_floor(tl)\ | 338 | 2.88M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 2.88M | #define STEP_LINE(ix, tl)\ | 340 | 2.88M | tl.x += tl.ldi;\ | 341 | 2.88M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 2.88M | ix = rational_floor(tl) | 343 | | | 344 | 2.88M | rxl = rational_floor(l); | 345 | 2.88M | rxr = rational_floor(r); | 346 | 2.88M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 82.2M | while (LINEAR_COLOR ? 1 : ++iy != iy1) { | 348 | 82.2M | # if LINEAR_COLOR | 349 | 82.2M | if (rxl != rxr) { | 350 | 50.4M | code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components); | 351 | 50.4M | if (code < 0) | 352 | 0 | goto xit; | 353 | 50.4M | code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1); | 354 | 50.4M | if (code < 0) | 355 | 5 | goto xit; | 356 | 50.4M | } | 357 | 82.2M | if (++iy == iy1) | 358 | 2.88M | break; | 359 | 79.4M | STEP_LINE(rxl, l); | 360 | 79.4M | STEP_LINE(rxr, r); | 361 | 79.4M | step_gradient(&lg, num_components); | 362 | 79.4M | step_gradient(&rg, num_components); | 363 | | # else | 364 | | register int ixl, ixr; | 365 | | | 366 | | STEP_LINE(ixl, l); | 367 | | STEP_LINE(ixr, r); | 368 | | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | | if (ixl != rxl || ixr != rxr) { | 370 | | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | | if (code < 0) | 374 | | goto xit; | 375 | | rxl = ixl, rxr = ixr, ry = iy; | 376 | | } | 377 | | # endif | 378 | 79.4M | } | 379 | | # if !LINEAR_COLOR | 380 | | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | 2.88M | code = 0; | 383 | 2.88M | # endif | 384 | 2.88M | #undef STEP_LINE | 385 | 2.88M | #undef SET_MINIMAL_WIDTH | 386 | 2.88M | #undef CONNECT_RECTANGLES | 387 | 2.88M | #undef FILL_TRAP_RECT | 388 | 2.88M | #undef FILL_TRAP_RECT_DIRECT | 389 | 2.88M | #undef FILL_TRAP_RECT_INRECT | 390 | 2.88M | #undef YMULT_QUO | 391 | 2.88M | xit: if (code < 0 && FILL_DIRECT) | 392 | 5 | return_error(code); | 393 | 2.88M | return_if_interrupt(dev->memory); | 394 | 2.88M | return code; | 395 | 2.88M | } | 396 | 2.88M | } |
gdevddrw.c:gx_fill_trapezoid_ns_lc Line | Count | Source | 137 | 74.9M | { | 138 | 74.9M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 74.9M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 74.9M | if (ymin >= ymax) | 142 | 30.0M | return 0; /* no scan lines to sample */ | 143 | 44.9M | { | 144 | 44.9M | int iy = fixed2int_var(ymin); | 145 | 44.9M | const int iy1 = fixed2int_var(ymax); | 146 | 44.9M | trap_line l, r; | 147 | 44.9M | register int rxl, rxr; | 148 | | #if !LINEAR_COLOR | 149 | | int ry; | 150 | | #endif | 151 | 44.9M | const fixed | 152 | 44.9M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 44.9M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 44.9M | const fixed /* partial pixel offset to first line to sample */ | 155 | 44.9M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 44.9M | fixed fxl; | 157 | 44.9M | 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.9M | # if LINEAR_COLOR | 165 | 44.9M | int num_components = dev->color_info.num_components; | 166 | 44.9M | frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 167 | 44.9M | int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 168 | 44.9M | int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 169 | 44.9M | frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 170 | 44.9M | int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 171 | 44.9M | int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 172 | 44.9M | frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 173 | 44.9M | int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 174 | 44.9M | int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 175 | 44.9M | 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.9M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 44.9M | l.h = left->end.y - left->start.y; | 185 | 44.9M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 44.9M | r.h = right->end.y - right->start.y; | 188 | 44.9M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 44.9M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 44.9M | 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.9M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 44.9M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 44.9M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 44.9M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 44.9M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 44.9M | (*fill_rect)(dev, x, y, w, h, cindex)) | 208 | | | 209 | 44.9M | #if LINEAR_COLOR | 210 | 44.9M | # define FILL_TRAP_RECT(x,y,w,h)\ | 211 | 44.9M | (!(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.9M | #define YMULT_QUO(ys, tl)\ | 228 | 44.9M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 44.9M | 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.9M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 44.9M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 44.9M | #endif | 264 | 44.9M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 9.47M | l.di = 0, l.df = 0; | 267 | 9.47M | fxl = 0; | 268 | 35.5M | } else { | 269 | 35.5M | compute_dx(&l, dxl, ysl); | 270 | 35.5M | fxl = YMULT_QUO(ysl, l); | 271 | 35.5M | l.x += fxl; | 272 | 35.5M | } | 273 | 44.9M | 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.43M | r.di = 0, r.df = 0; | 286 | 9.43M | } | 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.5M | else if (dxr == dxl && fxl != 0) { | 292 | 2.27M | if (l.di == 0) | 293 | 709k | r.di = 0, r.df = l.df; | 294 | 1.57M | else | 295 | 1.57M | compute_dx(&r, dxr, ysr); | 296 | 2.27M | if (ysr == ysl && r.h == l.h) | 297 | 1.52M | r.x += fxl; | 298 | 755k | else | 299 | 755k | r.x += YMULT_QUO(ysr, r); | 300 | 33.2M | } else { | 301 | 33.2M | compute_dx(&r, dxr, ysr); | 302 | 33.2M | r.x += YMULT_QUO(ysr, r); | 303 | 33.2M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 44.9M | compute_ldx(&l, ysl); | 306 | 44.9M | compute_ldx(&r, ysr); | 307 | | /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding | 308 | | when the rational part is zero. Now add it back to get xl', xr' */ | 309 | 44.9M | l.x += fixed_epsilon; | 310 | 44.9M | r.x += fixed_epsilon; | 311 | 44.9M | # 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.9M | lg.c = lgc; | 320 | 44.9M | lg.f = lgf; | 321 | 44.9M | lg.num = lgnum; | 322 | 44.9M | rg.c = rgc; | 323 | 44.9M | rg.f = rgf; | 324 | 44.9M | rg.num = rgnum; | 325 | 44.9M | xg.c = xgc; | 326 | 44.9M | xg.f = xgf; | 327 | 44.9M | xg.num = xgnum; | 328 | 44.9M | code = init_gradient(&lg, fa, left, right, &l, ymin, num_components); | 329 | 44.9M | if (code < 0) | 330 | 0 | return code; | 331 | 44.9M | code = init_gradient(&rg, fa, right, left, &r, ymin, num_components); | 332 | 44.9M | if (code < 0) | 333 | 0 | return code; | 334 | | | 335 | 44.9M | # endif | 336 | | | 337 | 44.9M | #define rational_floor(tl)\ | 338 | 44.9M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 44.9M | #define STEP_LINE(ix, tl)\ | 340 | 44.9M | tl.x += tl.ldi;\ | 341 | 44.9M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 44.9M | ix = rational_floor(tl) | 343 | | | 344 | 44.9M | rxl = rational_floor(l); | 345 | 44.9M | rxr = rational_floor(r); | 346 | 44.9M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 429M | while (LINEAR_COLOR ? 1 : ++iy != iy1) { | 348 | 429M | # if LINEAR_COLOR | 349 | 429M | if (rxl != rxr) { | 350 | 102M | code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components); | 351 | 102M | if (code < 0) | 352 | 0 | goto xit; | 353 | 102M | code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1); | 354 | 102M | if (code < 0) | 355 | 15 | goto xit; | 356 | 102M | } | 357 | 429M | if (++iy == iy1) | 358 | 44.9M | break; | 359 | 384M | STEP_LINE(rxl, l); | 360 | 384M | STEP_LINE(rxr, r); | 361 | 384M | step_gradient(&lg, num_components); | 362 | 384M | 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 | 384M | } | 379 | | # if !LINEAR_COLOR | 380 | | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | 44.9M | code = 0; | 383 | 44.9M | # endif | 384 | 44.9M | #undef STEP_LINE | 385 | 44.9M | #undef SET_MINIMAL_WIDTH | 386 | 44.9M | #undef CONNECT_RECTANGLES | 387 | 44.9M | #undef FILL_TRAP_RECT | 388 | 44.9M | #undef FILL_TRAP_RECT_DIRECT | 389 | 44.9M | #undef FILL_TRAP_RECT_INRECT | 390 | 44.9M | #undef YMULT_QUO | 391 | 44.9M | xit: if (code < 0 && FILL_DIRECT) | 392 | 15 | return_error(code); | 393 | 44.9M | return_if_interrupt(dev->memory); | 394 | 44.9M | return code; | 395 | 44.9M | } | 396 | 44.9M | } |
|