396 | 109M | } Unexecuted instantiation: gx_fill_trapezoid_cf_fd Unexecuted instantiation: gx_fill_trapezoid_cf_nd gdevddrw.c:gx_fill_trapezoid_as_fd Line | Count | Source | 137 | 1.59M | { | 138 | 1.59M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 1.59M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 1.59M | if (ymin >= ymax) | 142 | 98.5k | return 0; /* no scan lines to sample */ | 143 | 1.50M | { | 144 | 1.50M | int iy = fixed2int_var(ymin); | 145 | 1.50M | const int iy1 = fixed2int_var(ymax); | 146 | 1.50M | trap_line l, r; | 147 | 1.50M | register int rxl, rxr; | 148 | 1.50M | #if !LINEAR_COLOR | 149 | 1.50M | int ry; | 150 | 1.50M | #endif | 151 | 1.50M | const fixed | 152 | 1.50M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 1.50M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 1.50M | const fixed /* partial pixel offset to first line to sample */ | 155 | 1.50M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 1.50M | fixed fxl; | 157 | 1.50M | int code; | 158 | | # if CONTIGUOUS_FILL | 159 | | const bool peak0 = ((flags & 1) != 0); | 160 | | const bool peak1 = ((flags & 2) != 0); | 161 | | int peak_y0 = ybot + fixed_half; | 162 | | int peak_y1 = ytop - fixed_half; | 163 | | # endif | 164 | | # if LINEAR_COLOR | 165 | | int num_components = dev->color_info.num_components; | 166 | | frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 167 | | int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 168 | | int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 169 | | frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 170 | | int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 171 | | int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 172 | | frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 173 | | int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 174 | | int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 175 | | trap_gradient lg, rg, xg; | 176 | | # else | 177 | 1.50M | gx_color_index cindex = pdevc->colors.pure; | 178 | 1.50M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 1.50M | dev_proc(dev, fill_rectangle); | 180 | 1.50M | # endif | 181 | | | 182 | 1.50M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 1.50M | l.h = left->end.y - left->start.y; | 185 | 1.50M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 1.50M | r.h = right->end.y - right->start.y; | 188 | 1.50M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 1.50M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 1.50M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 1.50M | #if !LINEAR_COLOR | 193 | 1.50M | ry = iy; | 194 | 1.50M | #endif | 195 | | | 196 | | /* | 197 | | * Free variables of FILL_TRAP_RECT: | 198 | | * SWAP_AXES, pdevc, dev, fa | 199 | | * Free variables of FILL_TRAP_RECT_DIRECT: | 200 | | * SWAP_AXES, fill_rect, dev, cindex | 201 | | */ | 202 | 1.50M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 1.50M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 1.50M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 1.50M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 1.50M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 1.50M | (*fill_rect)(dev, x, y, w, h, cindex)) | 208 | | | 209 | | #if LINEAR_COLOR | 210 | | # define FILL_TRAP_RECT(x,y,w,h)\ | 211 | | (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den)) | 212 | | #else | 213 | 1.50M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 1.50M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 1.50M | #endif | 216 | | | 217 | | /* Compute the dx/dy ratios. */ | 218 | | | 219 | | /* | 220 | | * Compute the x offsets at the first scan line to sample. We need | 221 | | * to be careful in computing ys# * dx#f {/,%} h# because the | 222 | | * multiplication may overflow. We know that all the quantities | 223 | | * involved are non-negative, and that ys# is usually less than 1 (as | 224 | | * a fixed, of course); this gives us a cheap conservative check for | 225 | | * overflow in the multiplication. | 226 | | */ | 227 | 1.50M | #define YMULT_QUO(ys, tl)\ | 228 | 1.50M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 1.50M | fixed_mult_quo(ys, tl.df, tl.h)) | 230 | | | 231 | | #if CONTIGUOUS_FILL | 232 | | /* | 233 | | * If left and right boundary round to same pixel index, | 234 | | * we would not paing the scan and would get a dropout. | 235 | | * Check for this case and choose one of two pixels | 236 | | * which is closer to the "axis". We need to exclude | 237 | | * 'peak' because it would paint an excessive pixel. | 238 | | */ | 239 | | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \ | 240 | | if (ixl == ixr) \ | 241 | | if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\ | 242 | | fixed x = int2fixed(ixl) + fixed_half;\ | 243 | | if (x - l.x < r.x - x)\ | 244 | | ++ixr;\ | 245 | | else\ | 246 | | --ixl;\ | 247 | | } | 248 | | | 249 | | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\ | 250 | | if (adj1 < adj2) {\ | 251 | | if (iy - ry > 1) {\ | 252 | | code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\ | 253 | | if (code < 0)\ | 254 | | goto xit;\ | 255 | | ry = iy - 1;\ | 256 | | }\ | 257 | | adj1 = adj2 = (adj2 + adj2) / 2;\ | 258 | | } | 259 | | | 260 | | #else | 261 | 1.50M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 1.50M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 1.50M | #endif | 264 | 1.50M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 278k | l.di = 0, l.df = 0; | 267 | 278k | fxl = 0; | 268 | 1.22M | } else { | 269 | 1.22M | compute_dx(&l, dxl, ysl); | 270 | 1.22M | fxl = YMULT_QUO(ysl, l); | 271 | 1.22M | l.x += fxl; | 272 | 1.22M | } | 273 | 1.50M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 266k | # if !LINEAR_COLOR | 277 | 266k | if (l.di == 0 && l.df == 0) { | 278 | 247k | rxl = fixed2int_var(l.x); | 279 | 247k | rxr = fixed2int_var(r.x); | 280 | 247k | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 247k | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 247k | goto xit; | 283 | 247k | } | 284 | 18.3k | # endif | 285 | 18.3k | r.di = 0, r.df = 0; | 286 | 18.3k | } | 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.23M | else if (dxr == dxl && fxl != 0) { | 292 | 928k | if (l.di == 0) | 293 | 452k | r.di = 0, r.df = l.df; | 294 | 476k | else | 295 | 476k | compute_dx(&r, dxr, ysr); | 296 | 928k | if (ysr == ysl && r.h == l.h) | 297 | 928k | r.x += fxl; | 298 | 92 | else | 299 | 92 | r.x += YMULT_QUO(ysr, r); | 300 | 928k | } else { | 301 | 305k | compute_dx(&r, dxr, ysr); | 302 | 305k | r.x += YMULT_QUO(ysr, r); | 303 | 305k | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 1.25M | compute_ldx(&l, ysl); | 306 | 1.25M | compute_ldx(&r, ysr); | 307 | | /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding | 308 | | when the rational part is zero. Now add it back to get xl', xr' */ | 309 | 1.25M | l.x += fixed_epsilon; | 310 | 1.25M | r.x += fixed_epsilon; | 311 | | # if LINEAR_COLOR | 312 | | # ifdef DEBUG | 313 | | if (check_gradient_overflow(left, right)) { | 314 | | /* The caller must care of. | 315 | | Checking it here looses some performance with triangles. */ | 316 | | return_error(gs_error_unregistered); | 317 | | } | 318 | | # endif | 319 | | lg.c = lgc; | 320 | | lg.f = lgf; | 321 | | lg.num = lgnum; | 322 | | rg.c = rgc; | 323 | | rg.f = rgf; | 324 | | rg.num = rgnum; | 325 | | xg.c = xgc; | 326 | | xg.f = xgf; | 327 | | xg.num = xgnum; | 328 | | code = init_gradient(&lg, fa, left, right, &l, ymin, num_components); | 329 | | if (code < 0) | 330 | | return code; | 331 | | code = init_gradient(&rg, fa, right, left, &r, ymin, num_components); | 332 | | if (code < 0) | 333 | | return code; | 334 | | | 335 | | # endif | 336 | | | 337 | 1.25M | #define rational_floor(tl)\ | 338 | 1.25M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 1.25M | #define STEP_LINE(ix, tl)\ | 340 | 1.25M | tl.x += tl.ldi;\ | 341 | 1.25M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 1.25M | ix = rational_floor(tl) | 343 | | | 344 | 1.25M | rxl = rational_floor(l); | 345 | 1.25M | rxr = rational_floor(r); | 346 | 1.25M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 164M | 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 | 163M | register int ixl, ixr; | 365 | | | 366 | 163M | STEP_LINE(ixl, l); | 367 | 163M | STEP_LINE(ixr, r); | 368 | 163M | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 163M | if (ixl != rxl || ixr != rxr) { | 370 | 22.7M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 22.7M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 22.7M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 22.7M | if (code < 0) | 374 | 0 | goto xit; | 375 | 22.7M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 22.7M | } | 377 | 163M | # endif | 378 | 163M | } | 379 | 1.25M | # if !LINEAR_COLOR | 380 | 1.25M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 1.25M | #undef STEP_LINE | 385 | 1.25M | #undef SET_MINIMAL_WIDTH | 386 | 1.25M | #undef CONNECT_RECTANGLES | 387 | 1.25M | #undef FILL_TRAP_RECT | 388 | 1.25M | #undef FILL_TRAP_RECT_DIRECT | 389 | 1.25M | #undef FILL_TRAP_RECT_INRECT | 390 | 1.25M | #undef YMULT_QUO | 391 | 1.50M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 1.50M | return_if_interrupt(dev->memory); | 394 | 1.50M | return code; | 395 | 1.50M | } | 396 | 1.50M | } |
gdevddrw.c:gx_fill_trapezoid_as_nd Line | Count | Source | 137 | 2.07M | { | 138 | 2.07M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 2.07M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 2.07M | if (ymin >= ymax) | 142 | 24.4k | return 0; /* no scan lines to sample */ | 143 | 2.05M | { | 144 | 2.05M | int iy = fixed2int_var(ymin); | 145 | 2.05M | const int iy1 = fixed2int_var(ymax); | 146 | 2.05M | trap_line l, r; | 147 | 2.05M | register int rxl, rxr; | 148 | 2.05M | #if !LINEAR_COLOR | 149 | 2.05M | int ry; | 150 | 2.05M | #endif | 151 | 2.05M | const fixed | 152 | 2.05M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 2.05M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 2.05M | const fixed /* partial pixel offset to first line to sample */ | 155 | 2.05M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 2.05M | fixed fxl; | 157 | 2.05M | int code; | 158 | | # if CONTIGUOUS_FILL | 159 | | const bool peak0 = ((flags & 1) != 0); | 160 | | const bool peak1 = ((flags & 2) != 0); | 161 | | int peak_y0 = ybot + fixed_half; | 162 | | int peak_y1 = ytop - fixed_half; | 163 | | # endif | 164 | | # if LINEAR_COLOR | 165 | | int num_components = dev->color_info.num_components; | 166 | | frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 167 | | int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 168 | | int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 169 | | frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 170 | | int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 171 | | int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 172 | | frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 173 | | int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 174 | | int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 175 | | trap_gradient lg, rg, xg; | 176 | | # else | 177 | 2.05M | gx_color_index cindex = pdevc->colors.pure; | 178 | 2.05M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 2.05M | dev_proc(dev, fill_rectangle); | 180 | 2.05M | # endif | 181 | | | 182 | 2.05M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 2.05M | l.h = left->end.y - left->start.y; | 185 | 2.05M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 2.05M | r.h = right->end.y - right->start.y; | 188 | 2.05M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 2.05M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 2.05M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 2.05M | #if !LINEAR_COLOR | 193 | 2.05M | ry = iy; | 194 | 2.05M | #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.05M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 2.05M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 2.05M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 2.05M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 2.05M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 2.05M | (*fill_rect)(dev, x, y, w, h, cindex)) | 208 | | | 209 | | #if LINEAR_COLOR | 210 | | # define FILL_TRAP_RECT(x,y,w,h)\ | 211 | | (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den)) | 212 | | #else | 213 | 2.05M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 2.05M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 2.05M | #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.05M | #define YMULT_QUO(ys, tl)\ | 228 | 2.05M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 2.05M | 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.05M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 2.05M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 2.05M | #endif | 264 | 2.05M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 422k | l.di = 0, l.df = 0; | 267 | 422k | fxl = 0; | 268 | 1.62M | } else { | 269 | 1.62M | compute_dx(&l, dxl, ysl); | 270 | 1.62M | fxl = YMULT_QUO(ysl, l); | 271 | 1.62M | l.x += fxl; | 272 | 1.62M | } | 273 | 2.05M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 403k | # if !LINEAR_COLOR | 277 | 403k | if (l.di == 0 && l.df == 0) { | 278 | 382k | rxl = fixed2int_var(l.x); | 279 | 382k | rxr = fixed2int_var(r.x); | 280 | 382k | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 382k | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 382k | goto xit; | 283 | 382k | } | 284 | 21.0k | # endif | 285 | 21.0k | r.di = 0, r.df = 0; | 286 | 21.0k | } | 287 | | /* | 288 | | * The test for fxl != 0 is required because the right edge might | 289 | | * cross some pixel centers even if the left edge doesn't. | 290 | | */ | 291 | 1.64M | else if (dxr == dxl && fxl != 0) { | 292 | 321k | if (l.di == 0) | 293 | 186k | r.di = 0, r.df = l.df; | 294 | 135k | else | 295 | 135k | compute_dx(&r, dxr, ysr); | 296 | 321k | if (ysr == ysl && r.h == l.h) | 297 | 321k | r.x += fxl; | 298 | 187 | else | 299 | 187 | r.x += YMULT_QUO(ysr, r); | 300 | 1.32M | } else { | 301 | 1.32M | compute_dx(&r, dxr, ysr); | 302 | 1.32M | r.x += YMULT_QUO(ysr, r); | 303 | 1.32M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 1.66M | compute_ldx(&l, ysl); | 306 | 1.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 | 1.66M | l.x += fixed_epsilon; | 310 | 1.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 | 1.66M | #define rational_floor(tl)\ | 338 | 1.66M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 1.66M | #define STEP_LINE(ix, tl)\ | 340 | 1.66M | tl.x += tl.ldi;\ | 341 | 1.66M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 1.66M | ix = rational_floor(tl) | 343 | | | 344 | 1.66M | rxl = rational_floor(l); | 345 | 1.66M | rxr = rational_floor(r); | 346 | 1.66M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 167M | 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 | 165M | register int ixl, ixr; | 365 | | | 366 | 165M | STEP_LINE(ixl, l); | 367 | 165M | STEP_LINE(ixr, r); | 368 | 165M | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 165M | if (ixl != rxl || ixr != rxr) { | 370 | 117M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 117M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 117M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 117M | if (code < 0) | 374 | 0 | goto xit; | 375 | 117M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 117M | } | 377 | 165M | # endif | 378 | 165M | } | 379 | 1.66M | # if !LINEAR_COLOR | 380 | 1.66M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 1.66M | #undef STEP_LINE | 385 | 1.66M | #undef SET_MINIMAL_WIDTH | 386 | 1.66M | #undef CONNECT_RECTANGLES | 387 | 1.66M | #undef FILL_TRAP_RECT | 388 | 1.66M | #undef FILL_TRAP_RECT_DIRECT | 389 | 1.66M | #undef FILL_TRAP_RECT_INRECT | 390 | 1.66M | #undef YMULT_QUO | 391 | 2.05M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 2.05M | return_if_interrupt(dev->memory); | 394 | 2.05M | return code; | 395 | 2.05M | } | 396 | 2.05M | } |
gdevddrw.c:gx_fill_trapezoid_ns_fd Line | Count | Source | 137 | 30.3M | { | 138 | 30.3M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 30.3M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 30.3M | if (ymin >= ymax) | 142 | 1.93M | return 0; /* no scan lines to sample */ | 143 | 28.3M | { | 144 | 28.3M | int iy = fixed2int_var(ymin); | 145 | 28.3M | const int iy1 = fixed2int_var(ymax); | 146 | 28.3M | trap_line l, r; | 147 | 28.3M | register int rxl, rxr; | 148 | 28.3M | #if !LINEAR_COLOR | 149 | 28.3M | int ry; | 150 | 28.3M | #endif | 151 | 28.3M | const fixed | 152 | 28.3M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 28.3M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 28.3M | const fixed /* partial pixel offset to first line to sample */ | 155 | 28.3M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 28.3M | fixed fxl; | 157 | 28.3M | 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 | 28.3M | gx_color_index cindex = pdevc->colors.pure; | 178 | 28.3M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 28.3M | dev_proc(dev, fill_rectangle); | 180 | 28.3M | # endif | 181 | | | 182 | 28.3M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 28.3M | l.h = left->end.y - left->start.y; | 185 | 28.3M | if (l.h == 0) | 186 | 6 | return 0; | 187 | 28.3M | r.h = right->end.y - right->start.y; | 188 | 28.3M | if (r.h == 0) | 189 | 6 | return 0; | 190 | 28.3M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 28.3M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 28.3M | #if !LINEAR_COLOR | 193 | 28.3M | ry = iy; | 194 | 28.3M | #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 | 28.3M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 28.3M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 28.3M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 28.3M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 28.3M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 28.3M | (*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 | 28.3M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 28.3M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 28.3M | #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 | 28.3M | #define YMULT_QUO(ys, tl)\ | 228 | 28.3M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 28.3M | 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 | 28.3M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 28.3M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 28.3M | #endif | 264 | 28.3M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 10.7M | l.di = 0, l.df = 0; | 267 | 10.7M | fxl = 0; | 268 | 17.5M | } else { | 269 | 17.5M | compute_dx(&l, dxl, ysl); | 270 | 17.5M | fxl = YMULT_QUO(ysl, l); | 271 | 17.5M | l.x += fxl; | 272 | 17.5M | } | 273 | 28.3M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 10.9M | # if !LINEAR_COLOR | 277 | 10.9M | if (l.di == 0 && l.df == 0) { | 278 | 6.13M | rxl = fixed2int_var(l.x); | 279 | 6.13M | rxr = fixed2int_var(r.x); | 280 | 6.13M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 6.13M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 6.13M | goto xit; | 283 | 6.13M | } | 284 | 4.81M | # endif | 285 | 4.81M | r.di = 0, r.df = 0; | 286 | 4.81M | } | 287 | | /* | 288 | | * The test for fxl != 0 is required because the right edge might | 289 | | * cross some pixel centers even if the left edge doesn't. | 290 | | */ | 291 | 17.4M | else if (dxr == dxl && fxl != 0) { | 292 | 1.92M | if (l.di == 0) | 293 | 570k | r.di = 0, r.df = l.df; | 294 | 1.34M | else | 295 | 1.34M | compute_dx(&r, dxr, ysr); | 296 | 1.92M | if (ysr == ysl && r.h == l.h) | 297 | 1.21M | r.x += fxl; | 298 | 709k | else | 299 | 709k | r.x += YMULT_QUO(ysr, r); | 300 | 15.4M | } else { | 301 | 15.4M | compute_dx(&r, dxr, ysr); | 302 | 15.4M | r.x += YMULT_QUO(ysr, r); | 303 | 15.4M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 22.2M | compute_ldx(&l, ysl); | 306 | 22.2M | compute_ldx(&r, ysr); | 307 | | /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding | 308 | | when the rational part is zero. Now add it back to get xl', xr' */ | 309 | 22.2M | l.x += fixed_epsilon; | 310 | 22.2M | r.x += fixed_epsilon; | 311 | | # if LINEAR_COLOR | 312 | | # ifdef DEBUG | 313 | | if (check_gradient_overflow(left, right)) { | 314 | | /* The caller must care of. | 315 | | Checking it here looses some performance with triangles. */ | 316 | | return_error(gs_error_unregistered); | 317 | | } | 318 | | # endif | 319 | | lg.c = lgc; | 320 | | lg.f = lgf; | 321 | | lg.num = lgnum; | 322 | | rg.c = rgc; | 323 | | rg.f = rgf; | 324 | | rg.num = rgnum; | 325 | | xg.c = xgc; | 326 | | xg.f = xgf; | 327 | | xg.num = xgnum; | 328 | | code = init_gradient(&lg, fa, left, right, &l, ymin, num_components); | 329 | | if (code < 0) | 330 | | return code; | 331 | | code = init_gradient(&rg, fa, right, left, &r, ymin, num_components); | 332 | | if (code < 0) | 333 | | return code; | 334 | | | 335 | | # endif | 336 | | | 337 | 22.2M | #define rational_floor(tl)\ | 338 | 22.2M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 22.2M | #define STEP_LINE(ix, tl)\ | 340 | 22.2M | tl.x += tl.ldi;\ | 341 | 22.2M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 22.2M | ix = rational_floor(tl) | 343 | | | 344 | 22.2M | rxl = rational_floor(l); | 345 | 22.2M | rxr = rational_floor(r); | 346 | 22.2M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 810M | 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 | 787M | register int ixl, ixr; | 365 | | | 366 | 787M | STEP_LINE(ixl, l); | 367 | 787M | STEP_LINE(ixr, r); | 368 | 787M | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 787M | if (ixl != rxl || ixr != rxr) { | 370 | 183M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 183M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 183M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 183M | if (code < 0) | 374 | 0 | goto xit; | 375 | 183M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 183M | } | 377 | 787M | # endif | 378 | 787M | } | 379 | 22.2M | # if !LINEAR_COLOR | 380 | 22.2M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 22.2M | #undef STEP_LINE | 385 | 22.2M | #undef SET_MINIMAL_WIDTH | 386 | 22.2M | #undef CONNECT_RECTANGLES | 387 | 22.2M | #undef FILL_TRAP_RECT | 388 | 22.2M | #undef FILL_TRAP_RECT_DIRECT | 389 | 22.2M | #undef FILL_TRAP_RECT_INRECT | 390 | 22.2M | #undef YMULT_QUO | 391 | 28.3M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 28.3M | return_if_interrupt(dev->memory); | 394 | 28.3M | return code; | 395 | 28.3M | } | 396 | 28.3M | } |
gdevddrw.c:gx_fill_trapezoid_ns_nd Line | Count | Source | 137 | 67.8M | { | 138 | 67.8M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 67.8M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 67.8M | if (ymin >= ymax) | 142 | 16.4M | return 0; /* no scan lines to sample */ | 143 | 51.3M | { | 144 | 51.3M | int iy = fixed2int_var(ymin); | 145 | 51.3M | const int iy1 = fixed2int_var(ymax); | 146 | 51.3M | trap_line l, r; | 147 | 51.3M | register int rxl, rxr; | 148 | 51.3M | #if !LINEAR_COLOR | 149 | 51.3M | int ry; | 150 | 51.3M | #endif | 151 | 51.3M | const fixed | 152 | 51.3M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 51.3M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 51.3M | const fixed /* partial pixel offset to first line to sample */ | 155 | 51.3M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 51.3M | fixed fxl; | 157 | 51.3M | 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.3M | gx_color_index cindex = pdevc->colors.pure; | 178 | 51.3M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 51.3M | dev_proc(dev, fill_rectangle); | 180 | 51.3M | # endif | 181 | | | 182 | 51.3M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 51.3M | l.h = left->end.y - left->start.y; | 185 | 51.3M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 51.3M | r.h = right->end.y - right->start.y; | 188 | 51.3M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 51.3M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 51.3M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 51.3M | #if !LINEAR_COLOR | 193 | 51.3M | ry = iy; | 194 | 51.3M | #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.3M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 51.3M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 51.3M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 51.3M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 51.3M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 51.3M | (*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.3M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 51.3M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 51.3M | #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.3M | #define YMULT_QUO(ys, tl)\ | 228 | 51.3M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 51.3M | 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.3M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 51.3M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 51.3M | #endif | 264 | 51.3M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 11.4M | l.di = 0, l.df = 0; | 267 | 11.4M | fxl = 0; | 268 | 39.9M | } else { | 269 | 39.9M | compute_dx(&l, dxl, ysl); | 270 | 39.9M | fxl = YMULT_QUO(ysl, l); | 271 | 39.9M | l.x += fxl; | 272 | 39.9M | } | 273 | 51.3M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 14.8M | # if !LINEAR_COLOR | 277 | 14.8M | if (l.di == 0 && l.df == 0) { | 278 | 5.77M | rxl = fixed2int_var(l.x); | 279 | 5.77M | rxr = fixed2int_var(r.x); | 280 | 5.77M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 5.77M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 5.77M | goto xit; | 283 | 5.77M | } | 284 | 9.05M | # endif | 285 | 9.05M | r.di = 0, r.df = 0; | 286 | 9.05M | } | 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 | 2.33M | if (l.di == 0) | 293 | 270k | r.di = 0, r.df = l.df; | 294 | 2.06M | else | 295 | 2.06M | compute_dx(&r, dxr, ysr); | 296 | 2.33M | if (ysr == ysl && r.h == l.h) | 297 | 1.38M | r.x += fxl; | 298 | 947k | else | 299 | 947k | r.x += YMULT_QUO(ysr, r); | 300 | 34.2M | } else { | 301 | 34.2M | compute_dx(&r, dxr, ysr); | 302 | 34.2M | r.x += YMULT_QUO(ysr, r); | 303 | 34.2M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 45.5M | compute_ldx(&l, ysl); | 306 | 45.5M | 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 | 45.5M | l.x += fixed_epsilon; | 310 | 45.5M | 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 | 45.5M | #define rational_floor(tl)\ | 338 | 45.5M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 45.5M | #define STEP_LINE(ix, tl)\ | 340 | 45.5M | tl.x += tl.ldi;\ | 341 | 45.5M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 45.5M | ix = rational_floor(tl) | 343 | | | 344 | 45.5M | rxl = rational_floor(l); | 345 | 45.5M | rxr = rational_floor(r); | 346 | 45.5M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 1.18G | while (LINEAR_COLOR ? 1 : ++iy != iy1) { | 348 | | # if LINEAR_COLOR | 349 | | if (rxl != rxr) { | 350 | | code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components); | 351 | | if (code < 0) | 352 | | goto xit; | 353 | | code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1); | 354 | | if (code < 0) | 355 | | goto xit; | 356 | | } | 357 | | if (++iy == iy1) | 358 | | break; | 359 | | STEP_LINE(rxl, l); | 360 | | STEP_LINE(rxr, r); | 361 | | step_gradient(&lg, num_components); | 362 | | step_gradient(&rg, num_components); | 363 | | # else | 364 | 1.13G | register int ixl, ixr; | 365 | | | 366 | 1.13G | STEP_LINE(ixl, l); | 367 | 1.13G | STEP_LINE(ixr, r); | 368 | 1.13G | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 1.13G | if (ixl != rxl || ixr != rxr) { | 370 | 741M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 741M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 741M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 741M | if (code < 0) | 374 | 0 | goto xit; | 375 | 741M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 741M | } | 377 | 1.13G | # endif | 378 | 1.13G | } | 379 | 45.5M | # if !LINEAR_COLOR | 380 | 45.5M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 45.5M | #undef STEP_LINE | 385 | 45.5M | #undef SET_MINIMAL_WIDTH | 386 | 45.5M | #undef CONNECT_RECTANGLES | 387 | 45.5M | #undef FILL_TRAP_RECT | 388 | 45.5M | #undef FILL_TRAP_RECT_DIRECT | 389 | 45.5M | #undef FILL_TRAP_RECT_INRECT | 390 | 45.5M | #undef YMULT_QUO | 391 | 51.3M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 51.3M | return_if_interrupt(dev->memory); | 394 | 51.3M | return code; | 395 | 51.3M | } | 396 | 51.3M | } |
gdevddrw.c:gx_fill_trapezoid_as_lc Line | Count | Source | 137 | 1.28M | { | 138 | 1.28M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 1.28M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 1.28M | if (ymin >= ymax) | 142 | 256k | return 0; /* no scan lines to sample */ | 143 | 1.03M | { | 144 | 1.03M | int iy = fixed2int_var(ymin); | 145 | 1.03M | const int iy1 = fixed2int_var(ymax); | 146 | 1.03M | trap_line l, r; | 147 | 1.03M | register int rxl, rxr; | 148 | | #if !LINEAR_COLOR | 149 | | int ry; | 150 | | #endif | 151 | 1.03M | const fixed | 152 | 1.03M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 1.03M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 1.03M | const fixed /* partial pixel offset to first line to sample */ | 155 | 1.03M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 1.03M | fixed fxl; | 157 | 1.03M | 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 | 1.03M | # if LINEAR_COLOR | 165 | 1.03M | int num_components = dev->color_info.num_components; | 166 | 1.03M | frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 167 | 1.03M | int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 168 | 1.03M | int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 169 | 1.03M | frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 170 | 1.03M | int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 171 | 1.03M | int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 172 | 1.03M | frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 173 | 1.03M | int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 174 | 1.03M | int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 175 | 1.03M | 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 | 1.03M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 1.03M | l.h = left->end.y - left->start.y; | 185 | 1.03M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 1.03M | r.h = right->end.y - right->start.y; | 188 | 1.03M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 1.03M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 1.03M | 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 | 1.03M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 1.03M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 1.03M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 1.03M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 1.03M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 1.03M | (*fill_rect)(dev, x, y, w, h, cindex)) | 208 | | | 209 | 1.03M | #if LINEAR_COLOR | 210 | 1.03M | # define FILL_TRAP_RECT(x,y,w,h)\ | 211 | 1.03M | (!(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 | 1.03M | #define YMULT_QUO(ys, tl)\ | 228 | 1.03M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 1.03M | fixed_mult_quo(ys, tl.df, tl.h)) | 230 | | | 231 | | #if CONTIGUOUS_FILL | 232 | | /* | 233 | | * If left and right boundary round to same pixel index, | 234 | | * we would not paing the scan and would get a dropout. | 235 | | * Check for this case and choose one of two pixels | 236 | | * which is closer to the "axis". We need to exclude | 237 | | * 'peak' because it would paint an excessive pixel. | 238 | | */ | 239 | | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \ | 240 | | if (ixl == ixr) \ | 241 | | if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\ | 242 | | fixed x = int2fixed(ixl) + fixed_half;\ | 243 | | if (x - l.x < r.x - x)\ | 244 | | ++ixr;\ | 245 | | else\ | 246 | | --ixl;\ | 247 | | } | 248 | | | 249 | | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\ | 250 | | if (adj1 < adj2) {\ | 251 | | if (iy - ry > 1) {\ | 252 | | code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\ | 253 | | if (code < 0)\ | 254 | | goto xit;\ | 255 | | ry = iy - 1;\ | 256 | | }\ | 257 | | adj1 = adj2 = (adj2 + adj2) / 2;\ | 258 | | } | 259 | | | 260 | | #else | 261 | 1.03M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 1.03M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 1.03M | #endif | 264 | 1.03M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 612k | l.di = 0, l.df = 0; | 267 | 612k | fxl = 0; | 268 | 612k | } else { | 269 | 417k | compute_dx(&l, dxl, ysl); | 270 | 417k | fxl = YMULT_QUO(ysl, l); | 271 | 417k | l.x += fxl; | 272 | 417k | } | 273 | 1.03M | 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 | 616k | r.di = 0, r.df = 0; | 286 | 616k | } | 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 | 413k | else if (dxr == dxl && fxl != 0) { | 292 | 194k | if (l.di == 0) | 293 | 87.4k | r.di = 0, r.df = l.df; | 294 | 107k | else | 295 | 107k | compute_dx(&r, dxr, ysr); | 296 | 194k | if (ysr == ysl && r.h == l.h) | 297 | 194k | r.x += fxl; | 298 | 139 | else | 299 | 139 | r.x += YMULT_QUO(ysr, r); | 300 | 219k | } else { | 301 | 219k | compute_dx(&r, dxr, ysr); | 302 | 219k | r.x += YMULT_QUO(ysr, r); | 303 | 219k | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 1.03M | compute_ldx(&l, ysl); | 306 | 1.03M | compute_ldx(&r, ysr); | 307 | | /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding | 308 | | when the rational part is zero. Now add it back to get xl', xr' */ | 309 | 1.03M | l.x += fixed_epsilon; | 310 | 1.03M | r.x += fixed_epsilon; | 311 | 1.03M | # 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 | 1.03M | lg.c = lgc; | 320 | 1.03M | lg.f = lgf; | 321 | 1.03M | lg.num = lgnum; | 322 | 1.03M | rg.c = rgc; | 323 | 1.03M | rg.f = rgf; | 324 | 1.03M | rg.num = rgnum; | 325 | 1.03M | xg.c = xgc; | 326 | 1.03M | xg.f = xgf; | 327 | 1.03M | xg.num = xgnum; | 328 | 1.03M | code = init_gradient(&lg, fa, left, right, &l, ymin, num_components); | 329 | 1.03M | if (code < 0) | 330 | 0 | return code; | 331 | 1.03M | code = init_gradient(&rg, fa, right, left, &r, ymin, num_components); | 332 | 1.03M | if (code < 0) | 333 | 0 | return code; | 334 | | | 335 | 1.03M | # endif | 336 | | | 337 | 1.03M | #define rational_floor(tl)\ | 338 | 1.03M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 1.03M | #define STEP_LINE(ix, tl)\ | 340 | 1.03M | tl.x += tl.ldi;\ | 341 | 1.03M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 1.03M | ix = rational_floor(tl) | 343 | | | 344 | 1.03M | rxl = rational_floor(l); | 345 | 1.03M | rxr = rational_floor(r); | 346 | 1.03M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 36.1M | while (LINEAR_COLOR ? 1 : ++iy != iy1) { | 348 | 36.1M | # if LINEAR_COLOR | 349 | 36.1M | if (rxl != rxr) { | 350 | 24.7M | code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components); | 351 | 24.7M | if (code < 0) | 352 | 0 | goto xit; | 353 | 24.7M | code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1); | 354 | 24.7M | if (code < 0) | 355 | 4 | goto xit; | 356 | 24.7M | } | 357 | 36.1M | if (++iy == iy1) | 358 | 1.03M | break; | 359 | 35.1M | STEP_LINE(rxl, l); | 360 | 35.1M | STEP_LINE(rxr, r); | 361 | 35.1M | step_gradient(&lg, num_components); | 362 | 35.1M | 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 | 35.1M | } | 379 | | # if !LINEAR_COLOR | 380 | | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | 1.03M | code = 0; | 383 | 1.03M | # endif | 384 | 1.03M | #undef STEP_LINE | 385 | 1.03M | #undef SET_MINIMAL_WIDTH | 386 | 1.03M | #undef CONNECT_RECTANGLES | 387 | 1.03M | #undef FILL_TRAP_RECT | 388 | 1.03M | #undef FILL_TRAP_RECT_DIRECT | 389 | 1.03M | #undef FILL_TRAP_RECT_INRECT | 390 | 1.03M | #undef YMULT_QUO | 391 | 1.03M | xit: if (code < 0 && FILL_DIRECT) | 392 | 4 | return_error(code); | 393 | 1.03M | return_if_interrupt(dev->memory); | 394 | 1.03M | return code; | 395 | 1.03M | } | 396 | 1.03M | } |
gdevddrw.c:gx_fill_trapezoid_ns_lc Line | Count | Source | 137 | 39.3M | { | 138 | 39.3M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 39.3M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 39.3M | if (ymin >= ymax) | 142 | 13.7M | return 0; /* no scan lines to sample */ | 143 | 25.5M | { | 144 | 25.5M | int iy = fixed2int_var(ymin); | 145 | 25.5M | const int iy1 = fixed2int_var(ymax); | 146 | 25.5M | trap_line l, r; | 147 | 25.5M | register int rxl, rxr; | 148 | | #if !LINEAR_COLOR | 149 | | int ry; | 150 | | #endif | 151 | 25.5M | const fixed | 152 | 25.5M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 25.5M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 25.5M | const fixed /* partial pixel offset to first line to sample */ | 155 | 25.5M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 25.5M | fixed fxl; | 157 | 25.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 | 25.5M | # if LINEAR_COLOR | 165 | 25.5M | int num_components = dev->color_info.num_components; | 166 | 25.5M | frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 167 | 25.5M | int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 168 | 25.5M | int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 169 | 25.5M | frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 170 | 25.5M | int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 171 | 25.5M | int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 172 | 25.5M | frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 173 | 25.5M | int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 174 | 25.5M | int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 175 | 25.5M | 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 | 25.5M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 25.5M | l.h = left->end.y - left->start.y; | 185 | 25.5M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 25.5M | r.h = right->end.y - right->start.y; | 188 | 25.5M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 25.5M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 25.5M | 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 | 25.5M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 25.5M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 25.5M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 25.5M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 25.5M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 25.5M | (*fill_rect)(dev, x, y, w, h, cindex)) | 208 | | | 209 | 25.5M | #if LINEAR_COLOR | 210 | 25.5M | # define FILL_TRAP_RECT(x,y,w,h)\ | 211 | 25.5M | (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den)) | 212 | | #else | 213 | | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | | (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 | 25.5M | #define YMULT_QUO(ys, tl)\ | 228 | 25.5M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 25.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 | 25.5M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 25.5M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 25.5M | #endif | 264 | 25.5M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 4.83M | l.di = 0, l.df = 0; | 267 | 4.83M | fxl = 0; | 268 | 20.7M | } else { | 269 | 20.7M | compute_dx(&l, dxl, ysl); | 270 | 20.7M | fxl = YMULT_QUO(ysl, l); | 271 | 20.7M | l.x += fxl; | 272 | 20.7M | } | 273 | 25.5M | 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 | 4.82M | r.di = 0, r.df = 0; | 286 | 4.82M | } | 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 | 20.7M | else if (dxr == dxl && fxl != 0) { | 292 | 1.76M | if (l.di == 0) | 293 | 494k | r.di = 0, r.df = l.df; | 294 | 1.27M | else | 295 | 1.27M | compute_dx(&r, dxr, ysr); | 296 | 1.76M | if (ysr == ysl && r.h == l.h) | 297 | 895k | r.x += fxl; | 298 | 873k | else | 299 | 873k | r.x += YMULT_QUO(ysr, r); | 300 | 18.9M | } else { | 301 | 18.9M | compute_dx(&r, dxr, ysr); | 302 | 18.9M | r.x += YMULT_QUO(ysr, r); | 303 | 18.9M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 25.5M | compute_ldx(&l, ysl); | 306 | 25.5M | 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 | 25.5M | l.x += fixed_epsilon; | 310 | 25.5M | r.x += fixed_epsilon; | 311 | 25.5M | # 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 | 25.5M | lg.c = lgc; | 320 | 25.5M | lg.f = lgf; | 321 | 25.5M | lg.num = lgnum; | 322 | 25.5M | rg.c = rgc; | 323 | 25.5M | rg.f = rgf; | 324 | 25.5M | rg.num = rgnum; | 325 | 25.5M | xg.c = xgc; | 326 | 25.5M | xg.f = xgf; | 327 | 25.5M | xg.num = xgnum; | 328 | 25.5M | code = init_gradient(&lg, fa, left, right, &l, ymin, num_components); | 329 | 25.5M | if (code < 0) | 330 | 0 | return code; | 331 | 25.5M | code = init_gradient(&rg, fa, right, left, &r, ymin, num_components); | 332 | 25.5M | if (code < 0) | 333 | 0 | return code; | 334 | | | 335 | 25.5M | # endif | 336 | | | 337 | 25.5M | #define rational_floor(tl)\ | 338 | 25.5M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 25.5M | #define STEP_LINE(ix, tl)\ | 340 | 25.5M | tl.x += tl.ldi;\ | 341 | 25.5M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 25.5M | ix = rational_floor(tl) | 343 | | | 344 | 25.5M | rxl = rational_floor(l); | 345 | 25.5M | rxr = rational_floor(r); | 346 | 25.5M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 521M | while (LINEAR_COLOR ? 1 : ++iy != iy1) { | 348 | 521M | # if LINEAR_COLOR | 349 | 521M | if (rxl != rxr) { | 350 | 51.9M | code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components); | 351 | 51.9M | if (code < 0) | 352 | 0 | goto xit; | 353 | 51.9M | code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1); | 354 | 51.9M | if (code < 0) | 355 | 13 | goto xit; | 356 | 51.9M | } | 357 | 521M | if (++iy == iy1) | 358 | 25.5M | break; | 359 | 495M | STEP_LINE(rxl, l); | 360 | 495M | STEP_LINE(rxr, r); | 361 | 495M | step_gradient(&lg, num_components); | 362 | 495M | 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 | 495M | } | 379 | | # if !LINEAR_COLOR | 380 | | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | 25.5M | code = 0; | 383 | 25.5M | # endif | 384 | 25.5M | #undef STEP_LINE | 385 | 25.5M | #undef SET_MINIMAL_WIDTH | 386 | 25.5M | #undef CONNECT_RECTANGLES | 387 | 25.5M | #undef FILL_TRAP_RECT | 388 | 25.5M | #undef FILL_TRAP_RECT_DIRECT | 389 | 25.5M | #undef FILL_TRAP_RECT_INRECT | 390 | 25.5M | #undef YMULT_QUO | 391 | 25.5M | xit: if (code < 0 && FILL_DIRECT) | 392 | 13 | return_error(code); | 393 | 25.5M | return_if_interrupt(dev->memory); | 394 | 25.5M | return code; | 395 | 25.5M | } | 396 | 25.5M | } |
|