396 | 76.8M | } 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.61M | { | 138 | 1.61M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 1.61M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 1.61M | if (ymin >= ymax) | 142 | 84.3k | return 0; /* no scan lines to sample */ | 143 | 1.53M | { | 144 | 1.53M | int iy = fixed2int_var(ymin); | 145 | 1.53M | const int iy1 = fixed2int_var(ymax); | 146 | 1.53M | trap_line l, r; | 147 | 1.53M | register int rxl, rxr; | 148 | 1.53M | #if !LINEAR_COLOR | 149 | 1.53M | int ry; | 150 | 1.53M | #endif | 151 | 1.53M | const fixed | 152 | 1.53M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 1.53M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 1.53M | const fixed /* partial pixel offset to first line to sample */ | 155 | 1.53M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 1.53M | fixed fxl; | 157 | 1.53M | 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.53M | gx_color_index cindex = pdevc->colors.pure; | 178 | 1.53M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 1.53M | dev_proc(dev, fill_rectangle); | 180 | 1.53M | # endif | 181 | | | 182 | 1.53M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 1.53M | l.h = left->end.y - left->start.y; | 185 | 1.53M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 1.53M | r.h = right->end.y - right->start.y; | 188 | 1.53M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 1.53M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 1.53M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 1.53M | #if !LINEAR_COLOR | 193 | 1.53M | ry = iy; | 194 | 1.53M | #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.53M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 1.53M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 1.53M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 1.53M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 1.53M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 1.53M | (*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.53M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 1.53M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 1.53M | #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.53M | #define YMULT_QUO(ys, tl)\ | 228 | 1.53M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 1.53M | 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.53M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 1.53M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 1.53M | #endif | 264 | 1.53M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 262k | l.di = 0, l.df = 0; | 267 | 262k | fxl = 0; | 268 | 1.26M | } else { | 269 | 1.26M | compute_dx(&l, dxl, ysl); | 270 | 1.26M | fxl = YMULT_QUO(ysl, l); | 271 | 1.26M | l.x += fxl; | 272 | 1.26M | } | 273 | 1.53M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 249k | # if !LINEAR_COLOR | 277 | 249k | if (l.di == 0 && l.df == 0) { | 278 | 232k | rxl = fixed2int_var(l.x); | 279 | 232k | rxr = fixed2int_var(r.x); | 280 | 232k | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 232k | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 232k | goto xit; | 283 | 232k | } | 284 | 16.3k | # endif | 285 | 16.3k | r.di = 0, r.df = 0; | 286 | 16.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.28M | else if (dxr == dxl && fxl != 0) { | 292 | 968k | if (l.di == 0) | 293 | 476k | r.di = 0, r.df = l.df; | 294 | 491k | else | 295 | 491k | compute_dx(&r, dxr, ysr); | 296 | 968k | if (ysr == ysl && r.h == l.h) | 297 | 968k | r.x += fxl; | 298 | 102 | else | 299 | 102 | r.x += YMULT_QUO(ysr, r); | 300 | 968k | } else { | 301 | 312k | compute_dx(&r, dxr, ysr); | 302 | 312k | r.x += YMULT_QUO(ysr, r); | 303 | 312k | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 1.29M | compute_ldx(&l, ysl); | 306 | 1.29M | 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.29M | l.x += fixed_epsilon; | 310 | 1.29M | 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.29M | #define rational_floor(tl)\ | 338 | 1.29M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 1.29M | #define STEP_LINE(ix, tl)\ | 340 | 1.29M | tl.x += tl.ldi;\ | 341 | 1.29M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 1.29M | ix = rational_floor(tl) | 343 | | | 344 | 1.29M | rxl = rational_floor(l); | 345 | 1.29M | rxr = rational_floor(r); | 346 | 1.29M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 177M | 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 | 176M | register int ixl, ixr; | 365 | | | 366 | 176M | STEP_LINE(ixl, l); | 367 | 176M | STEP_LINE(ixr, r); | 368 | 176M | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 176M | if (ixl != rxl || ixr != rxr) { | 370 | 30.3M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 30.3M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 30.3M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 30.3M | if (code < 0) | 374 | 0 | goto xit; | 375 | 30.3M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 30.3M | } | 377 | 176M | # endif | 378 | 176M | } | 379 | 1.29M | # if !LINEAR_COLOR | 380 | 1.29M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 1.29M | #undef STEP_LINE | 385 | 1.29M | #undef SET_MINIMAL_WIDTH | 386 | 1.29M | #undef CONNECT_RECTANGLES | 387 | 1.29M | #undef FILL_TRAP_RECT | 388 | 1.29M | #undef FILL_TRAP_RECT_DIRECT | 389 | 1.29M | #undef FILL_TRAP_RECT_INRECT | 390 | 1.29M | #undef YMULT_QUO | 391 | 1.53M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 1.53M | return_if_interrupt(dev->memory); | 394 | 1.53M | return code; | 395 | 1.53M | } | 396 | 1.53M | } |
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 | 23.3k | 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 | 358k | l.di = 0, l.df = 0; | 267 | 358k | fxl = 0; | 268 | 1.69M | } else { | 269 | 1.69M | compute_dx(&l, dxl, ysl); | 270 | 1.69M | fxl = YMULT_QUO(ysl, l); | 271 | 1.69M | l.x += fxl; | 272 | 1.69M | } | 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 | 332k | # if !LINEAR_COLOR | 277 | 332k | if (l.di == 0 && l.df == 0) { | 278 | 321k | rxl = fixed2int_var(l.x); | 279 | 321k | rxr = fixed2int_var(r.x); | 280 | 321k | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 321k | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 321k | goto xit; | 283 | 321k | } | 284 | 11.5k | # endif | 285 | 11.5k | r.di = 0, r.df = 0; | 286 | 11.5k | } | 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.71M | else if (dxr == dxl && fxl != 0) { | 292 | 330k | if (l.di == 0) | 293 | 191k | r.di = 0, r.df = l.df; | 294 | 138k | else | 295 | 138k | compute_dx(&r, dxr, ysr); | 296 | 330k | if (ysr == ysl && r.h == l.h) | 297 | 329k | r.x += fxl; | 298 | 186 | else | 299 | 186 | r.x += YMULT_QUO(ysr, r); | 300 | 1.38M | } else { | 301 | 1.38M | compute_dx(&r, dxr, ysr); | 302 | 1.38M | r.x += YMULT_QUO(ysr, r); | 303 | 1.38M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 1.73M | compute_ldx(&l, ysl); | 306 | 1.73M | 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.73M | l.x += fixed_epsilon; | 310 | 1.73M | 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.73M | #define rational_floor(tl)\ | 338 | 1.73M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 1.73M | #define STEP_LINE(ix, tl)\ | 340 | 1.73M | tl.x += tl.ldi;\ | 341 | 1.73M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 1.73M | ix = rational_floor(tl) | 343 | | | 344 | 1.73M | rxl = rational_floor(l); | 345 | 1.73M | rxr = rational_floor(r); | 346 | 1.73M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 177M | 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 | 175M | register int ixl, ixr; | 365 | | | 366 | 175M | STEP_LINE(ixl, l); | 367 | 175M | STEP_LINE(ixr, r); | 368 | 175M | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 175M | if (ixl != rxl || ixr != rxr) { | 370 | 126M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 126M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 126M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 126M | if (code < 0) | 374 | 0 | goto xit; | 375 | 126M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 126M | } | 377 | 175M | # endif | 378 | 175M | } | 379 | 1.73M | # if !LINEAR_COLOR | 380 | 1.73M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 1.73M | #undef STEP_LINE | 385 | 1.73M | #undef SET_MINIMAL_WIDTH | 386 | 1.73M | #undef CONNECT_RECTANGLES | 387 | 1.73M | #undef FILL_TRAP_RECT | 388 | 1.73M | #undef FILL_TRAP_RECT_DIRECT | 389 | 1.73M | #undef FILL_TRAP_RECT_INRECT | 390 | 1.73M | #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 | 29.5M | { | 138 | 29.5M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 29.5M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 29.5M | if (ymin >= ymax) | 142 | 1.94M | return 0; /* no scan lines to sample */ | 143 | 27.5M | { | 144 | 27.5M | int iy = fixed2int_var(ymin); | 145 | 27.5M | const int iy1 = fixed2int_var(ymax); | 146 | 27.5M | trap_line l, r; | 147 | 27.5M | register int rxl, rxr; | 148 | 27.5M | #if !LINEAR_COLOR | 149 | 27.5M | int ry; | 150 | 27.5M | #endif | 151 | 27.5M | const fixed | 152 | 27.5M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 27.5M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 27.5M | const fixed /* partial pixel offset to first line to sample */ | 155 | 27.5M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 27.5M | fixed fxl; | 157 | 27.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 | 27.5M | gx_color_index cindex = pdevc->colors.pure; | 178 | 27.5M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 27.5M | dev_proc(dev, fill_rectangle); | 180 | 27.5M | # endif | 181 | | | 182 | 27.5M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 27.5M | l.h = left->end.y - left->start.y; | 185 | 27.5M | if (l.h == 0) | 186 | 12 | return 0; | 187 | 27.5M | r.h = right->end.y - right->start.y; | 188 | 27.5M | if (r.h == 0) | 189 | 12 | return 0; | 190 | 27.5M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 27.5M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 27.5M | #if !LINEAR_COLOR | 193 | 27.5M | ry = iy; | 194 | 27.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 | 27.5M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 27.5M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 27.5M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 27.5M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 27.5M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 27.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 | 27.5M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 27.5M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 27.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 | 27.5M | #define YMULT_QUO(ys, tl)\ | 228 | 27.5M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 27.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 | 27.5M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 27.5M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 27.5M | #endif | 264 | 27.5M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 10.1M | l.di = 0, l.df = 0; | 267 | 10.1M | fxl = 0; | 268 | 17.4M | } else { | 269 | 17.4M | compute_dx(&l, dxl, ysl); | 270 | 17.4M | fxl = YMULT_QUO(ysl, l); | 271 | 17.4M | l.x += fxl; | 272 | 17.4M | } | 273 | 27.5M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 10.2M | # if !LINEAR_COLOR | 277 | 10.2M | if (l.di == 0 && l.df == 0) { | 278 | 5.44M | rxl = fixed2int_var(l.x); | 279 | 5.44M | rxr = fixed2int_var(r.x); | 280 | 5.44M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 5.44M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 5.44M | goto xit; | 283 | 5.44M | } | 284 | 4.84M | # endif | 285 | 4.84M | r.di = 0, r.df = 0; | 286 | 4.84M | } | 287 | | /* | 288 | | * The test for fxl != 0 is required because the right edge might | 289 | | * cross some pixel centers even if the left edge doesn't. | 290 | | */ | 291 | 17.2M | else if (dxr == dxl && fxl != 0) { | 292 | 2.19M | if (l.di == 0) | 293 | 589k | r.di = 0, r.df = l.df; | 294 | 1.60M | else | 295 | 1.60M | compute_dx(&r, dxr, ysr); | 296 | 2.19M | if (ysr == ysl && r.h == l.h) | 297 | 1.27M | r.x += fxl; | 298 | 924k | else | 299 | 924k | r.x += YMULT_QUO(ysr, r); | 300 | 15.0M | } else { | 301 | 15.0M | compute_dx(&r, dxr, ysr); | 302 | 15.0M | r.x += YMULT_QUO(ysr, r); | 303 | 15.0M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 22.1M | compute_ldx(&l, ysl); | 306 | 22.1M | compute_ldx(&r, ysr); | 307 | | /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding | 308 | | when the rational part is zero. Now add it back to get xl', xr' */ | 309 | 22.1M | l.x += fixed_epsilon; | 310 | 22.1M | r.x += fixed_epsilon; | 311 | | # if LINEAR_COLOR | 312 | | # ifdef DEBUG | 313 | | if (check_gradient_overflow(left, right)) { | 314 | | /* The caller must care of. | 315 | | Checking it here looses some performance with triangles. */ | 316 | | return_error(gs_error_unregistered); | 317 | | } | 318 | | # endif | 319 | | lg.c = lgc; | 320 | | lg.f = lgf; | 321 | | lg.num = lgnum; | 322 | | rg.c = rgc; | 323 | | rg.f = rgf; | 324 | | rg.num = rgnum; | 325 | | xg.c = xgc; | 326 | | xg.f = xgf; | 327 | | xg.num = xgnum; | 328 | | code = init_gradient(&lg, fa, left, right, &l, ymin, num_components); | 329 | | if (code < 0) | 330 | | return code; | 331 | | code = init_gradient(&rg, fa, right, left, &r, ymin, num_components); | 332 | | if (code < 0) | 333 | | return code; | 334 | | | 335 | | # endif | 336 | | | 337 | 22.1M | #define rational_floor(tl)\ | 338 | 22.1M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 22.1M | #define STEP_LINE(ix, tl)\ | 340 | 22.1M | tl.x += tl.ldi;\ | 341 | 22.1M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 22.1M | ix = rational_floor(tl) | 343 | | | 344 | 22.1M | rxl = rational_floor(l); | 345 | 22.1M | rxr = rational_floor(r); | 346 | 22.1M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 879M | 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 | 857M | register int ixl, ixr; | 365 | | | 366 | 857M | STEP_LINE(ixl, l); | 367 | 857M | STEP_LINE(ixr, r); | 368 | 857M | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 857M | if (ixl != rxl || ixr != rxr) { | 370 | 204M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 204M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 204M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 204M | if (code < 0) | 374 | 0 | goto xit; | 375 | 204M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 204M | } | 377 | 857M | # endif | 378 | 857M | } | 379 | 22.1M | # if !LINEAR_COLOR | 380 | 22.1M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 22.1M | #undef STEP_LINE | 385 | 22.1M | #undef SET_MINIMAL_WIDTH | 386 | 22.1M | #undef CONNECT_RECTANGLES | 387 | 22.1M | #undef FILL_TRAP_RECT | 388 | 22.1M | #undef FILL_TRAP_RECT_DIRECT | 389 | 22.1M | #undef FILL_TRAP_RECT_INRECT | 390 | 22.1M | #undef YMULT_QUO | 391 | 27.5M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 27.5M | return_if_interrupt(dev->memory); | 394 | 27.5M | return code; | 395 | 27.5M | } | 396 | 27.5M | } |
gdevddrw.c:gx_fill_trapezoid_ns_nd Line | Count | Source | 137 | 42.6M | { | 138 | 42.6M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 42.6M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 42.6M | if (ymin >= ymax) | 142 | 11.4M | return 0; /* no scan lines to sample */ | 143 | 31.1M | { | 144 | 31.1M | int iy = fixed2int_var(ymin); | 145 | 31.1M | const int iy1 = fixed2int_var(ymax); | 146 | 31.1M | trap_line l, r; | 147 | 31.1M | register int rxl, rxr; | 148 | 31.1M | #if !LINEAR_COLOR | 149 | 31.1M | int ry; | 150 | 31.1M | #endif | 151 | 31.1M | const fixed | 152 | 31.1M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 31.1M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 31.1M | const fixed /* partial pixel offset to first line to sample */ | 155 | 31.1M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 31.1M | fixed fxl; | 157 | 31.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 | 31.1M | gx_color_index cindex = pdevc->colors.pure; | 178 | 31.1M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 31.1M | dev_proc(dev, fill_rectangle); | 180 | 31.1M | # endif | 181 | | | 182 | 31.1M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 31.1M | l.h = left->end.y - left->start.y; | 185 | 31.1M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 31.1M | r.h = right->end.y - right->start.y; | 188 | 31.1M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 31.1M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 31.1M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 31.1M | #if !LINEAR_COLOR | 193 | 31.1M | ry = iy; | 194 | 31.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 | 31.1M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 31.1M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 31.1M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 31.1M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 31.1M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 31.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 | 31.1M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 31.1M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 31.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 | 31.1M | #define YMULT_QUO(ys, tl)\ | 228 | 31.1M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 31.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 | 31.1M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 31.1M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 31.1M | #endif | 264 | 31.1M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 7.64M | l.di = 0, l.df = 0; | 267 | 7.64M | fxl = 0; | 268 | 23.5M | } else { | 269 | 23.5M | compute_dx(&l, dxl, ysl); | 270 | 23.5M | fxl = YMULT_QUO(ysl, l); | 271 | 23.5M | l.x += fxl; | 272 | 23.5M | } | 273 | 31.1M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 11.0M | # if !LINEAR_COLOR | 277 | 11.0M | if (l.di == 0 && l.df == 0) { | 278 | 3.29M | rxl = fixed2int_var(l.x); | 279 | 3.29M | rxr = fixed2int_var(r.x); | 280 | 3.29M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 3.29M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 3.29M | goto xit; | 283 | 3.29M | } | 284 | 7.79M | # endif | 285 | 7.79M | r.di = 0, r.df = 0; | 286 | 7.79M | } | 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.0M | else if (dxr == dxl && fxl != 0) { | 292 | 1.78M | if (l.di == 0) | 293 | 211k | r.di = 0, r.df = l.df; | 294 | 1.57M | else | 295 | 1.57M | compute_dx(&r, dxr, ysr); | 296 | 1.78M | if (ysr == ysl && r.h == l.h) | 297 | 1.03M | r.x += fxl; | 298 | 750k | else | 299 | 750k | r.x += YMULT_QUO(ysr, r); | 300 | 18.3M | } else { | 301 | 18.3M | compute_dx(&r, dxr, ysr); | 302 | 18.3M | r.x += YMULT_QUO(ysr, r); | 303 | 18.3M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 27.8M | compute_ldx(&l, ysl); | 306 | 27.8M | 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 | 27.8M | l.x += fixed_epsilon; | 310 | 27.8M | 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 | 27.8M | #define rational_floor(tl)\ | 338 | 27.8M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 27.8M | #define STEP_LINE(ix, tl)\ | 340 | 27.8M | tl.x += tl.ldi;\ | 341 | 27.8M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 27.8M | ix = rational_floor(tl) | 343 | | | 344 | 27.8M | rxl = rational_floor(l); | 345 | 27.8M | rxr = rational_floor(r); | 346 | 27.8M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 1.08G | 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.06G | register int ixl, ixr; | 365 | | | 366 | 1.06G | STEP_LINE(ixl, l); | 367 | 1.06G | STEP_LINE(ixr, r); | 368 | 1.06G | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 1.06G | if (ixl != rxl || ixr != rxr) { | 370 | 712M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 712M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 712M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 712M | if (code < 0) | 374 | 0 | goto xit; | 375 | 712M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 712M | } | 377 | 1.06G | # endif | 378 | 1.06G | } | 379 | 27.8M | # if !LINEAR_COLOR | 380 | 27.8M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 27.8M | #undef STEP_LINE | 385 | 27.8M | #undef SET_MINIMAL_WIDTH | 386 | 27.8M | #undef CONNECT_RECTANGLES | 387 | 27.8M | #undef FILL_TRAP_RECT | 388 | 27.8M | #undef FILL_TRAP_RECT_DIRECT | 389 | 27.8M | #undef FILL_TRAP_RECT_INRECT | 390 | 27.8M | #undef YMULT_QUO | 391 | 31.1M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 31.1M | return_if_interrupt(dev->memory); | 394 | 31.1M | return code; | 395 | 31.1M | } | 396 | 31.1M | } |
gdevddrw.c:gx_fill_trapezoid_as_lc Line | Count | Source | 137 | 1.06M | { | 138 | 1.06M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 1.06M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 1.06M | if (ymin >= ymax) | 142 | 255k | return 0; /* no scan lines to sample */ | 143 | 810k | { | 144 | 810k | int iy = fixed2int_var(ymin); | 145 | 810k | const int iy1 = fixed2int_var(ymax); | 146 | 810k | trap_line l, r; | 147 | 810k | register int rxl, rxr; | 148 | | #if !LINEAR_COLOR | 149 | | int ry; | 150 | | #endif | 151 | 810k | const fixed | 152 | 810k | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 810k | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 810k | const fixed /* partial pixel offset to first line to sample */ | 155 | 810k | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 810k | fixed fxl; | 157 | 810k | 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 | 810k | # if LINEAR_COLOR | 165 | 810k | int num_components = dev->color_info.num_components; | 166 | 810k | frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 167 | 810k | int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 168 | 810k | int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 169 | 810k | frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 170 | 810k | int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 171 | 810k | int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 172 | 810k | frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 173 | 810k | int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 174 | 810k | int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 175 | 810k | 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 | 810k | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 810k | l.h = left->end.y - left->start.y; | 185 | 810k | if (l.h == 0) | 186 | 0 | return 0; | 187 | 810k | r.h = right->end.y - right->start.y; | 188 | 810k | if (r.h == 0) | 189 | 0 | return 0; | 190 | 810k | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 810k | 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 | 810k | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 810k | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 810k | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 810k | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 810k | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 810k | (*fill_rect)(dev, x, y, w, h, cindex)) | 208 | | | 209 | 810k | #if LINEAR_COLOR | 210 | 810k | # define FILL_TRAP_RECT(x,y,w,h)\ | 211 | 810k | (!(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 | 810k | #define YMULT_QUO(ys, tl)\ | 228 | 810k | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 810k | 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 | 810k | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 810k | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 810k | #endif | 264 | 810k | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 499k | l.di = 0, l.df = 0; | 267 | 499k | fxl = 0; | 268 | 499k | } else { | 269 | 311k | compute_dx(&l, dxl, ysl); | 270 | 311k | fxl = YMULT_QUO(ysl, l); | 271 | 311k | l.x += fxl; | 272 | 311k | } | 273 | 810k | 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 | 503k | r.di = 0, r.df = 0; | 286 | 503k | } | 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 | 307k | else if (dxr == dxl && fxl != 0) { | 292 | 150k | if (l.di == 0) | 293 | 70.5k | r.di = 0, r.df = l.df; | 294 | 79.7k | else | 295 | 79.7k | compute_dx(&r, dxr, ysr); | 296 | 150k | if (ysr == ysl && r.h == l.h) | 297 | 150k | r.x += fxl; | 298 | 166 | else | 299 | 166 | r.x += YMULT_QUO(ysr, r); | 300 | 157k | } else { | 301 | 157k | compute_dx(&r, dxr, ysr); | 302 | 157k | r.x += YMULT_QUO(ysr, r); | 303 | 157k | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 810k | compute_ldx(&l, ysl); | 306 | 810k | 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 | 810k | l.x += fixed_epsilon; | 310 | 810k | r.x += fixed_epsilon; | 311 | 810k | # 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 | 810k | lg.c = lgc; | 320 | 810k | lg.f = lgf; | 321 | 810k | lg.num = lgnum; | 322 | 810k | rg.c = rgc; | 323 | 810k | rg.f = rgf; | 324 | 810k | rg.num = rgnum; | 325 | 810k | xg.c = xgc; | 326 | 810k | xg.f = xgf; | 327 | 810k | xg.num = xgnum; | 328 | 810k | code = init_gradient(&lg, fa, left, right, &l, ymin, num_components); | 329 | 810k | if (code < 0) | 330 | 0 | return code; | 331 | 810k | code = init_gradient(&rg, fa, right, left, &r, ymin, num_components); | 332 | 810k | if (code < 0) | 333 | 0 | return code; | 334 | | | 335 | 810k | # endif | 336 | | | 337 | 810k | #define rational_floor(tl)\ | 338 | 810k | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 810k | #define STEP_LINE(ix, tl)\ | 340 | 810k | tl.x += tl.ldi;\ | 341 | 810k | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 810k | ix = rational_floor(tl) | 343 | | | 344 | 810k | rxl = rational_floor(l); | 345 | 810k | rxr = rational_floor(r); | 346 | 810k | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 27.9M | while (LINEAR_COLOR ? 1 : ++iy != iy1) { | 348 | 27.9M | # if LINEAR_COLOR | 349 | 27.9M | if (rxl != rxr) { | 350 | 18.4M | code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components); | 351 | 18.4M | if (code < 0) | 352 | 0 | goto xit; | 353 | 18.4M | code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1); | 354 | 18.4M | if (code < 0) | 355 | 4 | goto xit; | 356 | 18.4M | } | 357 | 27.9M | if (++iy == iy1) | 358 | 810k | break; | 359 | 27.1M | STEP_LINE(rxl, l); | 360 | 27.1M | STEP_LINE(rxr, r); | 361 | 27.1M | step_gradient(&lg, num_components); | 362 | 27.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 | 27.1M | } | 379 | | # if !LINEAR_COLOR | 380 | | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | 810k | code = 0; | 383 | 810k | # endif | 384 | 810k | #undef STEP_LINE | 385 | 810k | #undef SET_MINIMAL_WIDTH | 386 | 810k | #undef CONNECT_RECTANGLES | 387 | 810k | #undef FILL_TRAP_RECT | 388 | 810k | #undef FILL_TRAP_RECT_DIRECT | 389 | 810k | #undef FILL_TRAP_RECT_INRECT | 390 | 810k | #undef YMULT_QUO | 391 | 810k | xit: if (code < 0 && FILL_DIRECT) | 392 | 4 | return_error(code); | 393 | 810k | return_if_interrupt(dev->memory); | 394 | 810k | return code; | 395 | 810k | } | 396 | 810k | } |
gdevddrw.c:gx_fill_trapezoid_ns_lc Line | Count | Source | 137 | 22.2M | { | 138 | 22.2M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 22.2M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 22.2M | if (ymin >= ymax) | 142 | 8.51M | return 0; /* no scan lines to sample */ | 143 | 13.7M | { | 144 | 13.7M | int iy = fixed2int_var(ymin); | 145 | 13.7M | const int iy1 = fixed2int_var(ymax); | 146 | 13.7M | trap_line l, r; | 147 | 13.7M | register int rxl, rxr; | 148 | | #if !LINEAR_COLOR | 149 | | int ry; | 150 | | #endif | 151 | 13.7M | const fixed | 152 | 13.7M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 13.7M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 13.7M | const fixed /* partial pixel offset to first line to sample */ | 155 | 13.7M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 13.7M | fixed fxl; | 157 | 13.7M | int code; | 158 | | # if CONTIGUOUS_FILL | 159 | | const bool peak0 = ((flags & 1) != 0); | 160 | | const bool peak1 = ((flags & 2) != 0); | 161 | | int peak_y0 = ybot + fixed_half; | 162 | | int peak_y1 = ytop - fixed_half; | 163 | | # endif | 164 | 13.7M | # if LINEAR_COLOR | 165 | 13.7M | int num_components = dev->color_info.num_components; | 166 | 13.7M | frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 167 | 13.7M | int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 168 | 13.7M | int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 169 | 13.7M | frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 170 | 13.7M | int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 171 | 13.7M | int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 172 | 13.7M | frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 173 | 13.7M | int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 174 | 13.7M | int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 175 | 13.7M | 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 | 13.7M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 13.7M | l.h = left->end.y - left->start.y; | 185 | 13.7M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 13.7M | r.h = right->end.y - right->start.y; | 188 | 13.7M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 13.7M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 13.7M | 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 | 13.7M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 13.7M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 13.7M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 13.7M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 13.7M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 13.7M | (*fill_rect)(dev, x, y, w, h, cindex)) | 208 | | | 209 | 13.7M | #if LINEAR_COLOR | 210 | 13.7M | # define FILL_TRAP_RECT(x,y,w,h)\ | 211 | 13.7M | (!(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 | 13.7M | #define YMULT_QUO(ys, tl)\ | 228 | 13.7M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 13.7M | fixed_mult_quo(ys, tl.df, tl.h)) | 230 | | | 231 | | #if CONTIGUOUS_FILL | 232 | | /* | 233 | | * If left and right boundary round to same pixel index, | 234 | | * we would not paing the scan and would get a dropout. | 235 | | * Check for this case and choose one of two pixels | 236 | | * which is closer to the "axis". We need to exclude | 237 | | * 'peak' because it would paint an excessive pixel. | 238 | | */ | 239 | | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \ | 240 | | if (ixl == ixr) \ | 241 | | if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\ | 242 | | fixed x = int2fixed(ixl) + fixed_half;\ | 243 | | if (x - l.x < r.x - x)\ | 244 | | ++ixr;\ | 245 | | else\ | 246 | | --ixl;\ | 247 | | } | 248 | | | 249 | | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\ | 250 | | if (adj1 < adj2) {\ | 251 | | if (iy - ry > 1) {\ | 252 | | code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\ | 253 | | if (code < 0)\ | 254 | | goto xit;\ | 255 | | ry = iy - 1;\ | 256 | | }\ | 257 | | adj1 = adj2 = (adj2 + adj2) / 2;\ | 258 | | } | 259 | | | 260 | | #else | 261 | 13.7M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 13.7M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 13.7M | #endif | 264 | 13.7M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 3.39M | l.di = 0, l.df = 0; | 267 | 3.39M | fxl = 0; | 268 | 10.3M | } else { | 269 | 10.3M | compute_dx(&l, dxl, ysl); | 270 | 10.3M | fxl = YMULT_QUO(ysl, l); | 271 | 10.3M | l.x += fxl; | 272 | 10.3M | } | 273 | 13.7M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | | # if !LINEAR_COLOR | 277 | | if (l.di == 0 && l.df == 0) { | 278 | | rxl = fixed2int_var(l.x); | 279 | | rxr = fixed2int_var(r.x); | 280 | | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | | goto xit; | 283 | | } | 284 | | # endif | 285 | 3.38M | r.di = 0, r.df = 0; | 286 | 3.38M | } | 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 | 10.3M | else if (dxr == dxl && fxl != 0) { | 292 | 520k | if (l.di == 0) | 293 | 113k | r.di = 0, r.df = l.df; | 294 | 407k | else | 295 | 407k | compute_dx(&r, dxr, ysr); | 296 | 520k | if (ysr == ysl && r.h == l.h) | 297 | 337k | r.x += fxl; | 298 | 182k | else | 299 | 182k | r.x += YMULT_QUO(ysr, r); | 300 | 9.83M | } else { | 301 | 9.83M | compute_dx(&r, dxr, ysr); | 302 | 9.83M | r.x += YMULT_QUO(ysr, r); | 303 | 9.83M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 13.7M | compute_ldx(&l, ysl); | 306 | 13.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 | 13.7M | l.x += fixed_epsilon; | 310 | 13.7M | r.x += fixed_epsilon; | 311 | 13.7M | # 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 | 13.7M | lg.c = lgc; | 320 | 13.7M | lg.f = lgf; | 321 | 13.7M | lg.num = lgnum; | 322 | 13.7M | rg.c = rgc; | 323 | 13.7M | rg.f = rgf; | 324 | 13.7M | rg.num = rgnum; | 325 | 13.7M | xg.c = xgc; | 326 | 13.7M | xg.f = xgf; | 327 | 13.7M | xg.num = xgnum; | 328 | 13.7M | code = init_gradient(&lg, fa, left, right, &l, ymin, num_components); | 329 | 13.7M | if (code < 0) | 330 | 0 | return code; | 331 | 13.7M | code = init_gradient(&rg, fa, right, left, &r, ymin, num_components); | 332 | 13.7M | if (code < 0) | 333 | 0 | return code; | 334 | | | 335 | 13.7M | # endif | 336 | | | 337 | 13.7M | #define rational_floor(tl)\ | 338 | 13.7M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 13.7M | #define STEP_LINE(ix, tl)\ | 340 | 13.7M | tl.x += tl.ldi;\ | 341 | 13.7M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 13.7M | ix = rational_floor(tl) | 343 | | | 344 | 13.7M | rxl = rational_floor(l); | 345 | 13.7M | rxr = rational_floor(r); | 346 | 13.7M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 112M | while (LINEAR_COLOR ? 1 : ++iy != iy1) { | 348 | 112M | # if LINEAR_COLOR | 349 | 112M | if (rxl != rxr) { | 350 | 28.0M | code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components); | 351 | 28.0M | if (code < 0) | 352 | 0 | goto xit; | 353 | 28.0M | code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1); | 354 | 28.0M | if (code < 0) | 355 | 13 | goto xit; | 356 | 28.0M | } | 357 | 112M | if (++iy == iy1) | 358 | 13.7M | break; | 359 | 98.2M | STEP_LINE(rxl, l); | 360 | 98.2M | STEP_LINE(rxr, r); | 361 | 98.2M | step_gradient(&lg, num_components); | 362 | 98.2M | 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 | 98.2M | } | 379 | | # if !LINEAR_COLOR | 380 | | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | 13.7M | code = 0; | 383 | 13.7M | # endif | 384 | 13.7M | #undef STEP_LINE | 385 | 13.7M | #undef SET_MINIMAL_WIDTH | 386 | 13.7M | #undef CONNECT_RECTANGLES | 387 | 13.7M | #undef FILL_TRAP_RECT | 388 | 13.7M | #undef FILL_TRAP_RECT_DIRECT | 389 | 13.7M | #undef FILL_TRAP_RECT_INRECT | 390 | 13.7M | #undef YMULT_QUO | 391 | 13.7M | xit: if (code < 0 && FILL_DIRECT) | 392 | 13 | return_error(code); | 393 | 13.7M | return_if_interrupt(dev->memory); | 394 | 13.7M | return code; | 395 | 13.7M | } | 396 | 13.7M | } |
|