396 | 152M | } Unexecuted instantiation: gx_fill_trapezoid_cf_fd Unexecuted instantiation: gx_fill_trapezoid_cf_nd gdevddrw.c:gx_fill_trapezoid_as_fd Line | Count | Source | 137 | 3.14M | { | 138 | 3.14M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 3.14M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 3.14M | if (ymin >= ymax) | 142 | 172k | return 0; /* no scan lines to sample */ | 143 | 2.96M | { | 144 | 2.96M | int iy = fixed2int_var(ymin); | 145 | 2.96M | const int iy1 = fixed2int_var(ymax); | 146 | 2.96M | trap_line l, r; | 147 | 2.96M | register int rxl, rxr; | 148 | 2.96M | #if !LINEAR_COLOR | 149 | 2.96M | int ry; | 150 | 2.96M | #endif | 151 | 2.96M | const fixed | 152 | 2.96M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 2.96M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 2.96M | const fixed /* partial pixel offset to first line to sample */ | 155 | 2.96M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 2.96M | fixed fxl; | 157 | 2.96M | 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.96M | gx_color_index cindex = pdevc->colors.pure; | 178 | 2.96M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 2.96M | dev_proc(dev, fill_rectangle); | 180 | 2.96M | # endif | 181 | | | 182 | 2.96M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 2.96M | l.h = left->end.y - left->start.y; | 185 | 2.96M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 2.96M | r.h = right->end.y - right->start.y; | 188 | 2.96M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 2.96M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 2.96M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 2.96M | #if !LINEAR_COLOR | 193 | 2.96M | ry = iy; | 194 | 2.96M | #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.96M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 2.96M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 2.96M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 2.96M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 2.96M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 2.96M | (*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.96M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 2.96M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 2.96M | #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.96M | #define YMULT_QUO(ys, tl)\ | 228 | 2.96M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 2.96M | 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.96M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 2.96M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 2.96M | #endif | 264 | 2.96M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 843k | l.di = 0, l.df = 0; | 267 | 843k | fxl = 0; | 268 | 2.12M | } else { | 269 | 2.12M | compute_dx(&l, dxl, ysl); | 270 | 2.12M | fxl = YMULT_QUO(ysl, l); | 271 | 2.12M | l.x += fxl; | 272 | 2.12M | } | 273 | 2.96M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 788k | # if !LINEAR_COLOR | 277 | 788k | if (l.di == 0 && l.df == 0) { | 278 | 740k | rxl = fixed2int_var(l.x); | 279 | 740k | rxr = fixed2int_var(r.x); | 280 | 740k | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 740k | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 740k | goto xit; | 283 | 740k | } | 284 | 47.8k | # endif | 285 | 47.8k | r.di = 0, r.df = 0; | 286 | 47.8k | } | 287 | | /* | 288 | | * The test for fxl != 0 is required because the right edge might | 289 | | * cross some pixel centers even if the left edge doesn't. | 290 | | */ | 291 | 2.17M | else if (dxr == dxl && fxl != 0) { | 292 | 1.37M | if (l.di == 0) | 293 | 736k | r.di = 0, r.df = l.df; | 294 | 638k | else | 295 | 638k | compute_dx(&r, dxr, ysr); | 296 | 1.37M | if (ysr == ysl && r.h == l.h) | 297 | 1.37M | r.x += fxl; | 298 | 137 | else | 299 | 137 | r.x += YMULT_QUO(ysr, r); | 300 | 1.37M | } else { | 301 | 804k | compute_dx(&r, dxr, ysr); | 302 | 804k | r.x += YMULT_QUO(ysr, r); | 303 | 804k | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 2.22M | compute_ldx(&l, ysl); | 306 | 2.22M | compute_ldx(&r, ysr); | 307 | | /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding | 308 | | when the rational part is zero. Now add it back to get xl', xr' */ | 309 | 2.22M | l.x += fixed_epsilon; | 310 | 2.22M | r.x += fixed_epsilon; | 311 | | # if LINEAR_COLOR | 312 | | # ifdef DEBUG | 313 | | if (check_gradient_overflow(left, right)) { | 314 | | /* The caller must care of. | 315 | | Checking it here looses some performance with triangles. */ | 316 | | return_error(gs_error_unregistered); | 317 | | } | 318 | | # endif | 319 | | lg.c = lgc; | 320 | | lg.f = lgf; | 321 | | lg.num = lgnum; | 322 | | rg.c = rgc; | 323 | | rg.f = rgf; | 324 | | rg.num = rgnum; | 325 | | xg.c = xgc; | 326 | | xg.f = xgf; | 327 | | xg.num = xgnum; | 328 | | code = init_gradient(&lg, fa, left, right, &l, ymin, num_components); | 329 | | if (code < 0) | 330 | | return code; | 331 | | code = init_gradient(&rg, fa, right, left, &r, ymin, num_components); | 332 | | if (code < 0) | 333 | | return code; | 334 | | | 335 | | # endif | 336 | | | 337 | 2.22M | #define rational_floor(tl)\ | 338 | 2.22M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 2.22M | #define STEP_LINE(ix, tl)\ | 340 | 2.22M | tl.x += tl.ldi;\ | 341 | 2.22M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 2.22M | ix = rational_floor(tl) | 343 | | | 344 | 2.22M | rxl = rational_floor(l); | 345 | 2.22M | rxr = rational_floor(r); | 346 | 2.22M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 243M | 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 | 241M | register int ixl, ixr; | 365 | | | 366 | 241M | STEP_LINE(ixl, l); | 367 | 241M | STEP_LINE(ixr, r); | 368 | 241M | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 241M | if (ixl != rxl || ixr != rxr) { | 370 | 47.4M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 47.4M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 47.4M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 47.4M | if (code < 0) | 374 | 0 | goto xit; | 375 | 47.4M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 47.4M | } | 377 | 241M | # endif | 378 | 241M | } | 379 | 2.22M | # if !LINEAR_COLOR | 380 | 2.22M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 2.22M | #undef STEP_LINE | 385 | 2.22M | #undef SET_MINIMAL_WIDTH | 386 | 2.22M | #undef CONNECT_RECTANGLES | 387 | 2.22M | #undef FILL_TRAP_RECT | 388 | 2.22M | #undef FILL_TRAP_RECT_DIRECT | 389 | 2.22M | #undef FILL_TRAP_RECT_INRECT | 390 | 2.22M | #undef YMULT_QUO | 391 | 2.96M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 2.96M | return_if_interrupt(dev->memory); | 394 | 2.96M | return code; | 395 | 2.96M | } | 396 | 2.96M | } |
gdevddrw.c:gx_fill_trapezoid_as_nd Line | Count | Source | 137 | 4.29M | { | 138 | 4.29M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 4.29M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 4.29M | if (ymin >= ymax) | 142 | 54.9k | return 0; /* no scan lines to sample */ | 143 | 4.24M | { | 144 | 4.24M | int iy = fixed2int_var(ymin); | 145 | 4.24M | const int iy1 = fixed2int_var(ymax); | 146 | 4.24M | trap_line l, r; | 147 | 4.24M | register int rxl, rxr; | 148 | 4.24M | #if !LINEAR_COLOR | 149 | 4.24M | int ry; | 150 | 4.24M | #endif | 151 | 4.24M | const fixed | 152 | 4.24M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 4.24M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 4.24M | const fixed /* partial pixel offset to first line to sample */ | 155 | 4.24M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 4.24M | fixed fxl; | 157 | 4.24M | int code; | 158 | | # if CONTIGUOUS_FILL | 159 | | const bool peak0 = ((flags & 1) != 0); | 160 | | const bool peak1 = ((flags & 2) != 0); | 161 | | int peak_y0 = ybot + fixed_half; | 162 | | int peak_y1 = ytop - fixed_half; | 163 | | # endif | 164 | | # if LINEAR_COLOR | 165 | | int num_components = dev->color_info.num_components; | 166 | | frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 167 | | int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 168 | | int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 169 | | frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 170 | | int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 171 | | int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 172 | | frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 173 | | int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 174 | | int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 175 | | trap_gradient lg, rg, xg; | 176 | | # else | 177 | 4.24M | gx_color_index cindex = pdevc->colors.pure; | 178 | 4.24M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 4.24M | dev_proc(dev, fill_rectangle); | 180 | 4.24M | # endif | 181 | | | 182 | 4.24M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 4.24M | l.h = left->end.y - left->start.y; | 185 | 4.24M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 4.24M | r.h = right->end.y - right->start.y; | 188 | 4.24M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 4.24M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 4.24M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 4.24M | #if !LINEAR_COLOR | 193 | 4.24M | ry = iy; | 194 | 4.24M | #endif | 195 | | | 196 | | /* | 197 | | * Free variables of FILL_TRAP_RECT: | 198 | | * SWAP_AXES, pdevc, dev, fa | 199 | | * Free variables of FILL_TRAP_RECT_DIRECT: | 200 | | * SWAP_AXES, fill_rect, dev, cindex | 201 | | */ | 202 | 4.24M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 4.24M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 4.24M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 4.24M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 4.24M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 4.24M | (*fill_rect)(dev, x, y, w, h, cindex)) | 208 | | | 209 | | #if LINEAR_COLOR | 210 | | # define FILL_TRAP_RECT(x,y,w,h)\ | 211 | | (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den)) | 212 | | #else | 213 | 4.24M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 4.24M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 4.24M | #endif | 216 | | | 217 | | /* Compute the dx/dy ratios. */ | 218 | | | 219 | | /* | 220 | | * Compute the x offsets at the first scan line to sample. We need | 221 | | * to be careful in computing ys# * dx#f {/,%} h# because the | 222 | | * multiplication may overflow. We know that all the quantities | 223 | | * involved are non-negative, and that ys# is usually less than 1 (as | 224 | | * a fixed, of course); this gives us a cheap conservative check for | 225 | | * overflow in the multiplication. | 226 | | */ | 227 | 4.24M | #define YMULT_QUO(ys, tl)\ | 228 | 4.24M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 4.24M | fixed_mult_quo(ys, tl.df, tl.h)) | 230 | | | 231 | | #if CONTIGUOUS_FILL | 232 | | /* | 233 | | * If left and right boundary round to same pixel index, | 234 | | * we would not paing the scan and would get a dropout. | 235 | | * Check for this case and choose one of two pixels | 236 | | * which is closer to the "axis". We need to exclude | 237 | | * 'peak' because it would paint an excessive pixel. | 238 | | */ | 239 | | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \ | 240 | | if (ixl == ixr) \ | 241 | | if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\ | 242 | | fixed x = int2fixed(ixl) + fixed_half;\ | 243 | | if (x - l.x < r.x - x)\ | 244 | | ++ixr;\ | 245 | | else\ | 246 | | --ixl;\ | 247 | | } | 248 | | | 249 | | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\ | 250 | | if (adj1 < adj2) {\ | 251 | | if (iy - ry > 1) {\ | 252 | | code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\ | 253 | | if (code < 0)\ | 254 | | goto xit;\ | 255 | | ry = iy - 1;\ | 256 | | }\ | 257 | | adj1 = adj2 = (adj2 + adj2) / 2;\ | 258 | | } | 259 | | | 260 | | #else | 261 | 4.24M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 4.24M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 4.24M | #endif | 264 | 4.24M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 918k | l.di = 0, l.df = 0; | 267 | 918k | fxl = 0; | 268 | 3.32M | } else { | 269 | 3.32M | compute_dx(&l, dxl, ysl); | 270 | 3.32M | fxl = YMULT_QUO(ysl, l); | 271 | 3.32M | l.x += fxl; | 272 | 3.32M | } | 273 | 4.24M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 815k | # if !LINEAR_COLOR | 277 | 815k | if (l.di == 0 && l.df == 0) { | 278 | 774k | rxl = fixed2int_var(l.x); | 279 | 774k | rxr = fixed2int_var(r.x); | 280 | 774k | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 774k | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 774k | goto xit; | 283 | 774k | } | 284 | 40.6k | # endif | 285 | 40.6k | r.di = 0, r.df = 0; | 286 | 40.6k | } | 287 | | /* | 288 | | * The test for fxl != 0 is required because the right edge might | 289 | | * cross some pixel centers even if the left edge doesn't. | 290 | | */ | 291 | 3.42M | else if (dxr == dxl && fxl != 0) { | 292 | 482k | if (l.di == 0) | 293 | 286k | r.di = 0, r.df = l.df; | 294 | 196k | else | 295 | 196k | compute_dx(&r, dxr, ysr); | 296 | 482k | if (ysr == ysl && r.h == l.h) | 297 | 482k | r.x += fxl; | 298 | 268 | else | 299 | 268 | r.x += YMULT_QUO(ysr, r); | 300 | 2.94M | } else { | 301 | 2.94M | compute_dx(&r, dxr, ysr); | 302 | 2.94M | r.x += YMULT_QUO(ysr, r); | 303 | 2.94M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 3.46M | compute_ldx(&l, ysl); | 306 | 3.46M | 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 | 3.46M | l.x += fixed_epsilon; | 310 | 3.46M | 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 | 3.46M | #define rational_floor(tl)\ | 338 | 3.46M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 3.46M | #define STEP_LINE(ix, tl)\ | 340 | 3.46M | tl.x += tl.ldi;\ | 341 | 3.46M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 3.46M | ix = rational_floor(tl) | 343 | | | 344 | 3.46M | rxl = rational_floor(l); | 345 | 3.46M | rxr = rational_floor(r); | 346 | 3.46M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 498M | 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 | 494M | register int ixl, ixr; | 365 | | | 366 | 494M | STEP_LINE(ixl, l); | 367 | 494M | STEP_LINE(ixr, r); | 368 | 494M | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 494M | if (ixl != rxl || ixr != rxr) { | 370 | 381M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 381M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 381M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 381M | if (code < 0) | 374 | 0 | goto xit; | 375 | 381M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 381M | } | 377 | 494M | # endif | 378 | 494M | } | 379 | 3.46M | # if !LINEAR_COLOR | 380 | 3.46M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 3.46M | #undef STEP_LINE | 385 | 3.46M | #undef SET_MINIMAL_WIDTH | 386 | 3.46M | #undef CONNECT_RECTANGLES | 387 | 3.46M | #undef FILL_TRAP_RECT | 388 | 3.46M | #undef FILL_TRAP_RECT_DIRECT | 389 | 3.46M | #undef FILL_TRAP_RECT_INRECT | 390 | 3.46M | #undef YMULT_QUO | 391 | 4.24M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 4.24M | return_if_interrupt(dev->memory); | 394 | 4.24M | return code; | 395 | 4.24M | } | 396 | 4.24M | } |
gdevddrw.c:gx_fill_trapezoid_ns_fd Line | Count | Source | 137 | 42.7M | { | 138 | 42.7M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 42.7M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 42.7M | if (ymin >= ymax) | 142 | 4.91M | return 0; /* no scan lines to sample */ | 143 | 37.8M | { | 144 | 37.8M | int iy = fixed2int_var(ymin); | 145 | 37.8M | const int iy1 = fixed2int_var(ymax); | 146 | 37.8M | trap_line l, r; | 147 | 37.8M | register int rxl, rxr; | 148 | 37.8M | #if !LINEAR_COLOR | 149 | 37.8M | int ry; | 150 | 37.8M | #endif | 151 | 37.8M | const fixed | 152 | 37.8M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 37.8M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 37.8M | const fixed /* partial pixel offset to first line to sample */ | 155 | 37.8M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 37.8M | fixed fxl; | 157 | 37.8M | 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 | 37.8M | gx_color_index cindex = pdevc->colors.pure; | 178 | 37.8M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 37.8M | dev_proc(dev, fill_rectangle); | 180 | 37.8M | # endif | 181 | | | 182 | 37.8M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 37.8M | l.h = left->end.y - left->start.y; | 185 | 37.8M | if (l.h == 0) | 186 | 12 | return 0; | 187 | 37.8M | r.h = right->end.y - right->start.y; | 188 | 37.8M | if (r.h == 0) | 189 | 12 | return 0; | 190 | 37.8M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 37.8M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 37.8M | #if !LINEAR_COLOR | 193 | 37.8M | ry = iy; | 194 | 37.8M | #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 | 37.8M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 37.8M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 37.8M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 37.8M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 37.8M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 37.8M | (*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 | 37.8M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 37.8M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 37.8M | #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 | 37.8M | #define YMULT_QUO(ys, tl)\ | 228 | 37.8M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 37.8M | 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 | 37.8M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 37.8M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 37.8M | #endif | 264 | 37.8M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 15.8M | l.di = 0, l.df = 0; | 267 | 15.8M | fxl = 0; | 268 | 22.0M | } else { | 269 | 22.0M | compute_dx(&l, dxl, ysl); | 270 | 22.0M | fxl = YMULT_QUO(ysl, l); | 271 | 22.0M | l.x += fxl; | 272 | 22.0M | } | 273 | 37.8M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 16.0M | # if !LINEAR_COLOR | 277 | 16.0M | if (l.di == 0 && l.df == 0) { | 278 | 10.4M | rxl = fixed2int_var(l.x); | 279 | 10.4M | rxr = fixed2int_var(r.x); | 280 | 10.4M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 10.4M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 10.4M | goto xit; | 283 | 10.4M | } | 284 | 5.53M | # endif | 285 | 5.53M | r.di = 0, r.df = 0; | 286 | 5.53M | } | 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 | 21.8M | else if (dxr == dxl && fxl != 0) { | 292 | 3.35M | if (l.di == 0) | 293 | 922k | r.di = 0, r.df = l.df; | 294 | 2.42M | else | 295 | 2.42M | compute_dx(&r, dxr, ysr); | 296 | 3.35M | if (ysr == ysl && r.h == l.h) | 297 | 2.06M | r.x += fxl; | 298 | 1.28M | else | 299 | 1.28M | r.x += YMULT_QUO(ysr, r); | 300 | 18.4M | } else { | 301 | 18.4M | compute_dx(&r, dxr, ysr); | 302 | 18.4M | r.x += YMULT_QUO(ysr, r); | 303 | 18.4M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 27.3M | compute_ldx(&l, ysl); | 306 | 27.3M | compute_ldx(&r, ysr); | 307 | | /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding | 308 | | when the rational part is zero. Now add it back to get xl', xr' */ | 309 | 27.3M | l.x += fixed_epsilon; | 310 | 27.3M | r.x += fixed_epsilon; | 311 | | # if LINEAR_COLOR | 312 | | # ifdef DEBUG | 313 | | if (check_gradient_overflow(left, right)) { | 314 | | /* The caller must care of. | 315 | | Checking it here looses some performance with triangles. */ | 316 | | return_error(gs_error_unregistered); | 317 | | } | 318 | | # endif | 319 | | lg.c = lgc; | 320 | | lg.f = lgf; | 321 | | lg.num = lgnum; | 322 | | rg.c = rgc; | 323 | | rg.f = rgf; | 324 | | rg.num = rgnum; | 325 | | xg.c = xgc; | 326 | | xg.f = xgf; | 327 | | xg.num = xgnum; | 328 | | code = init_gradient(&lg, fa, left, right, &l, ymin, num_components); | 329 | | if (code < 0) | 330 | | return code; | 331 | | code = init_gradient(&rg, fa, right, left, &r, ymin, num_components); | 332 | | if (code < 0) | 333 | | return code; | 334 | | | 335 | | # endif | 336 | | | 337 | 27.3M | #define rational_floor(tl)\ | 338 | 27.3M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 27.3M | #define STEP_LINE(ix, tl)\ | 340 | 27.3M | tl.x += tl.ldi;\ | 341 | 27.3M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 27.3M | ix = rational_floor(tl) | 343 | | | 344 | 27.3M | rxl = rational_floor(l); | 345 | 27.3M | rxr = rational_floor(r); | 346 | 27.3M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 2.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 | 2.15G | register int ixl, ixr; | 365 | | | 366 | 2.15G | STEP_LINE(ixl, l); | 367 | 2.15G | STEP_LINE(ixr, r); | 368 | 2.15G | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 2.15G | if (ixl != rxl || ixr != rxr) { | 370 | 408M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 408M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 408M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 408M | if (code < 0) | 374 | 0 | goto xit; | 375 | 408M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 408M | } | 377 | 2.15G | # endif | 378 | 2.15G | } | 379 | 27.3M | # if !LINEAR_COLOR | 380 | 27.3M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 27.3M | #undef STEP_LINE | 385 | 27.3M | #undef SET_MINIMAL_WIDTH | 386 | 27.3M | #undef CONNECT_RECTANGLES | 387 | 27.3M | #undef FILL_TRAP_RECT | 388 | 27.3M | #undef FILL_TRAP_RECT_DIRECT | 389 | 27.3M | #undef FILL_TRAP_RECT_INRECT | 390 | 27.3M | #undef YMULT_QUO | 391 | 37.8M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 37.8M | return_if_interrupt(dev->memory); | 394 | 37.8M | return code; | 395 | 37.8M | } | 396 | 37.8M | } |
gdevddrw.c:gx_fill_trapezoid_ns_nd Line | Count | Source | 137 | 88.3M | { | 138 | 88.3M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 88.3M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 88.3M | if (ymin >= ymax) | 142 | 23.7M | return 0; /* no scan lines to sample */ | 143 | 64.6M | { | 144 | 64.6M | int iy = fixed2int_var(ymin); | 145 | 64.6M | const int iy1 = fixed2int_var(ymax); | 146 | 64.6M | trap_line l, r; | 147 | 64.6M | register int rxl, rxr; | 148 | 64.6M | #if !LINEAR_COLOR | 149 | 64.6M | int ry; | 150 | 64.6M | #endif | 151 | 64.6M | const fixed | 152 | 64.6M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 64.6M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 64.6M | const fixed /* partial pixel offset to first line to sample */ | 155 | 64.6M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 64.6M | fixed fxl; | 157 | 64.6M | int code; | 158 | | # if CONTIGUOUS_FILL | 159 | | const bool peak0 = ((flags & 1) != 0); | 160 | | const bool peak1 = ((flags & 2) != 0); | 161 | | int peak_y0 = ybot + fixed_half; | 162 | | int peak_y1 = ytop - fixed_half; | 163 | | # endif | 164 | | # if LINEAR_COLOR | 165 | | int num_components = dev->color_info.num_components; | 166 | | frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 167 | | int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 168 | | int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 169 | | frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 170 | | int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 171 | | int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 172 | | frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 173 | | int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 174 | | int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 175 | | trap_gradient lg, rg, xg; | 176 | | # else | 177 | 64.6M | gx_color_index cindex = pdevc->colors.pure; | 178 | 64.6M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 64.6M | dev_proc(dev, fill_rectangle); | 180 | 64.6M | # endif | 181 | | | 182 | 64.6M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 64.6M | l.h = left->end.y - left->start.y; | 185 | 64.6M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 64.6M | r.h = right->end.y - right->start.y; | 188 | 64.6M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 64.6M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 64.6M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 64.6M | #if !LINEAR_COLOR | 193 | 64.6M | ry = iy; | 194 | 64.6M | #endif | 195 | | | 196 | | /* | 197 | | * Free variables of FILL_TRAP_RECT: | 198 | | * SWAP_AXES, pdevc, dev, fa | 199 | | * Free variables of FILL_TRAP_RECT_DIRECT: | 200 | | * SWAP_AXES, fill_rect, dev, cindex | 201 | | */ | 202 | 64.6M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 64.6M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 64.6M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 64.6M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 64.6M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 64.6M | (*fill_rect)(dev, x, y, w, h, cindex)) | 208 | | | 209 | | #if LINEAR_COLOR | 210 | | # define FILL_TRAP_RECT(x,y,w,h)\ | 211 | | (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den)) | 212 | | #else | 213 | 64.6M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 64.6M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 64.6M | #endif | 216 | | | 217 | | /* Compute the dx/dy ratios. */ | 218 | | | 219 | | /* | 220 | | * Compute the x offsets at the first scan line to sample. We need | 221 | | * to be careful in computing ys# * dx#f {/,%} h# because the | 222 | | * multiplication may overflow. We know that all the quantities | 223 | | * involved are non-negative, and that ys# is usually less than 1 (as | 224 | | * a fixed, of course); this gives us a cheap conservative check for | 225 | | * overflow in the multiplication. | 226 | | */ | 227 | 64.6M | #define YMULT_QUO(ys, tl)\ | 228 | 64.6M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 64.6M | fixed_mult_quo(ys, tl.df, tl.h)) | 230 | | | 231 | | #if CONTIGUOUS_FILL | 232 | | /* | 233 | | * If left and right boundary round to same pixel index, | 234 | | * we would not paing the scan and would get a dropout. | 235 | | * Check for this case and choose one of two pixels | 236 | | * which is closer to the "axis". We need to exclude | 237 | | * 'peak' because it would paint an excessive pixel. | 238 | | */ | 239 | | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \ | 240 | | if (ixl == ixr) \ | 241 | | if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\ | 242 | | fixed x = int2fixed(ixl) + fixed_half;\ | 243 | | if (x - l.x < r.x - x)\ | 244 | | ++ixr;\ | 245 | | else\ | 246 | | --ixl;\ | 247 | | } | 248 | | | 249 | | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\ | 250 | | if (adj1 < adj2) {\ | 251 | | if (iy - ry > 1) {\ | 252 | | code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\ | 253 | | if (code < 0)\ | 254 | | goto xit;\ | 255 | | ry = iy - 1;\ | 256 | | }\ | 257 | | adj1 = adj2 = (adj2 + adj2) / 2;\ | 258 | | } | 259 | | | 260 | | #else | 261 | 64.6M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 64.6M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 64.6M | #endif | 264 | 64.6M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 15.6M | l.di = 0, l.df = 0; | 267 | 15.6M | fxl = 0; | 268 | 49.0M | } else { | 269 | 49.0M | compute_dx(&l, dxl, ysl); | 270 | 49.0M | fxl = YMULT_QUO(ysl, l); | 271 | 49.0M | l.x += fxl; | 272 | 49.0M | } | 273 | 64.6M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 20.2M | # if !LINEAR_COLOR | 277 | 20.2M | if (l.di == 0 && l.df == 0) { | 278 | 8.31M | rxl = fixed2int_var(l.x); | 279 | 8.31M | rxr = fixed2int_var(r.x); | 280 | 8.31M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 8.31M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 8.31M | goto xit; | 283 | 8.31M | } | 284 | 11.9M | # endif | 285 | 11.9M | r.di = 0, r.df = 0; | 286 | 11.9M | } | 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 | 44.3M | else if (dxr == dxl && fxl != 0) { | 292 | 3.32M | if (l.di == 0) | 293 | 424k | r.di = 0, r.df = l.df; | 294 | 2.90M | else | 295 | 2.90M | compute_dx(&r, dxr, ysr); | 296 | 3.32M | if (ysr == ysl && r.h == l.h) | 297 | 2.20M | r.x += fxl; | 298 | 1.12M | else | 299 | 1.12M | r.x += YMULT_QUO(ysr, r); | 300 | 41.0M | } else { | 301 | 41.0M | compute_dx(&r, dxr, ysr); | 302 | 41.0M | r.x += YMULT_QUO(ysr, r); | 303 | 41.0M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 56.3M | compute_ldx(&l, ysl); | 306 | 56.3M | compute_ldx(&r, ysr); | 307 | | /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding | 308 | | when the rational part is zero. Now add it back to get xl', xr' */ | 309 | 56.3M | l.x += fixed_epsilon; | 310 | 56.3M | r.x += fixed_epsilon; | 311 | | # if LINEAR_COLOR | 312 | | # ifdef DEBUG | 313 | | if (check_gradient_overflow(left, right)) { | 314 | | /* The caller must care of. | 315 | | Checking it here looses some performance with triangles. */ | 316 | | return_error(gs_error_unregistered); | 317 | | } | 318 | | # endif | 319 | | lg.c = lgc; | 320 | | lg.f = lgf; | 321 | | lg.num = lgnum; | 322 | | rg.c = rgc; | 323 | | rg.f = rgf; | 324 | | rg.num = rgnum; | 325 | | xg.c = xgc; | 326 | | xg.f = xgf; | 327 | | xg.num = xgnum; | 328 | | code = init_gradient(&lg, fa, left, right, &l, ymin, num_components); | 329 | | if (code < 0) | 330 | | return code; | 331 | | code = init_gradient(&rg, fa, right, left, &r, ymin, num_components); | 332 | | if (code < 0) | 333 | | return code; | 334 | | | 335 | | # endif | 336 | | | 337 | 56.3M | #define rational_floor(tl)\ | 338 | 56.3M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 56.3M | #define STEP_LINE(ix, tl)\ | 340 | 56.3M | tl.x += tl.ldi;\ | 341 | 56.3M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 56.3M | ix = rational_floor(tl) | 343 | | | 344 | 56.3M | rxl = rational_floor(l); | 345 | 56.3M | rxr = rational_floor(r); | 346 | 56.3M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 1.92G | 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.86G | register int ixl, ixr; | 365 | | | 366 | 1.86G | STEP_LINE(ixl, l); | 367 | 1.86G | STEP_LINE(ixr, r); | 368 | 1.86G | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 1.86G | if (ixl != rxl || ixr != rxr) { | 370 | 1.41G | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 1.41G | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 1.41G | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 1.41G | if (code < 0) | 374 | 0 | goto xit; | 375 | 1.41G | rxl = ixl, rxr = ixr, ry = iy; | 376 | 1.41G | } | 377 | 1.86G | # endif | 378 | 1.86G | } | 379 | 56.3M | # if !LINEAR_COLOR | 380 | 56.3M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 56.3M | #undef STEP_LINE | 385 | 56.3M | #undef SET_MINIMAL_WIDTH | 386 | 56.3M | #undef CONNECT_RECTANGLES | 387 | 56.3M | #undef FILL_TRAP_RECT | 388 | 56.3M | #undef FILL_TRAP_RECT_DIRECT | 389 | 56.3M | #undef FILL_TRAP_RECT_INRECT | 390 | 56.3M | #undef YMULT_QUO | 391 | 64.6M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 64.6M | return_if_interrupt(dev->memory); | 394 | 64.6M | return code; | 395 | 64.6M | } | 396 | 64.6M | } |
gdevddrw.c:gx_fill_trapezoid_as_lc Line | Count | Source | 137 | 3.15M | { | 138 | 3.15M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 3.15M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 3.15M | if (ymin >= ymax) | 142 | 508k | return 0; /* no scan lines to sample */ | 143 | 2.64M | { | 144 | 2.64M | int iy = fixed2int_var(ymin); | 145 | 2.64M | const int iy1 = fixed2int_var(ymax); | 146 | 2.64M | trap_line l, r; | 147 | 2.64M | register int rxl, rxr; | 148 | | #if !LINEAR_COLOR | 149 | | int ry; | 150 | | #endif | 151 | 2.64M | const fixed | 152 | 2.64M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 2.64M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 2.64M | const fixed /* partial pixel offset to first line to sample */ | 155 | 2.64M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 2.64M | fixed fxl; | 157 | 2.64M | int code; | 158 | | # if CONTIGUOUS_FILL | 159 | | const bool peak0 = ((flags & 1) != 0); | 160 | | const bool peak1 = ((flags & 2) != 0); | 161 | | int peak_y0 = ybot + fixed_half; | 162 | | int peak_y1 = ytop - fixed_half; | 163 | | # endif | 164 | 2.64M | # if LINEAR_COLOR | 165 | 2.64M | int num_components = dev->color_info.num_components; | 166 | 2.64M | frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 167 | 2.64M | int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 168 | 2.64M | int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 169 | 2.64M | frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 170 | 2.64M | int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 171 | 2.64M | int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 172 | 2.64M | frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 173 | 2.64M | int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 174 | 2.64M | int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 175 | 2.64M | trap_gradient lg, rg, xg; | 176 | | # else | 177 | | gx_color_index cindex = pdevc->colors.pure; | 178 | | dev_proc_fill_rectangle((*fill_rect)) = | 179 | | dev_proc(dev, fill_rectangle); | 180 | | # endif | 181 | | | 182 | 2.64M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 2.64M | l.h = left->end.y - left->start.y; | 185 | 2.64M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 2.64M | r.h = right->end.y - right->start.y; | 188 | 2.64M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 2.64M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 2.64M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | | #if !LINEAR_COLOR | 193 | | ry = iy; | 194 | | #endif | 195 | | | 196 | | /* | 197 | | * Free variables of FILL_TRAP_RECT: | 198 | | * SWAP_AXES, pdevc, dev, fa | 199 | | * Free variables of FILL_TRAP_RECT_DIRECT: | 200 | | * SWAP_AXES, fill_rect, dev, cindex | 201 | | */ | 202 | 2.64M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 2.64M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 2.64M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 2.64M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 2.64M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 2.64M | (*fill_rect)(dev, x, y, w, h, cindex)) | 208 | | | 209 | 2.64M | #if LINEAR_COLOR | 210 | 2.64M | # define FILL_TRAP_RECT(x,y,w,h)\ | 211 | 2.64M | (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den)) | 212 | | #else | 213 | | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | | #endif | 216 | | | 217 | | /* Compute the dx/dy ratios. */ | 218 | | | 219 | | /* | 220 | | * Compute the x offsets at the first scan line to sample. We need | 221 | | * to be careful in computing ys# * dx#f {/,%} h# because the | 222 | | * multiplication may overflow. We know that all the quantities | 223 | | * involved are non-negative, and that ys# is usually less than 1 (as | 224 | | * a fixed, of course); this gives us a cheap conservative check for | 225 | | * overflow in the multiplication. | 226 | | */ | 227 | 2.64M | #define YMULT_QUO(ys, tl)\ | 228 | 2.64M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 2.64M | 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.64M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 2.64M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 2.64M | #endif | 264 | 2.64M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 1.42M | l.di = 0, l.df = 0; | 267 | 1.42M | fxl = 0; | 268 | 1.42M | } 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 | 2.64M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | | # if !LINEAR_COLOR | 277 | | if (l.di == 0 && l.df == 0) { | 278 | | rxl = fixed2int_var(l.x); | 279 | | rxr = fixed2int_var(r.x); | 280 | | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | | goto xit; | 283 | | } | 284 | | # endif | 285 | 1.42M | r.di = 0, r.df = 0; | 286 | 1.42M | } | 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.22M | else if (dxr == dxl && fxl != 0) { | 292 | 786k | if (l.di == 0) | 293 | 222k | r.di = 0, r.df = l.df; | 294 | 564k | else | 295 | 564k | compute_dx(&r, dxr, ysr); | 296 | 786k | if (ysr == ysl && r.h == l.h) | 297 | 786k | r.x += fxl; | 298 | 197 | else | 299 | 197 | r.x += YMULT_QUO(ysr, r); | 300 | 786k | } else { | 301 | 440k | compute_dx(&r, dxr, ysr); | 302 | 440k | r.x += YMULT_QUO(ysr, r); | 303 | 440k | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 2.64M | compute_ldx(&l, ysl); | 306 | 2.64M | compute_ldx(&r, ysr); | 307 | | /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding | 308 | | when the rational part is zero. Now add it back to get xl', xr' */ | 309 | 2.64M | l.x += fixed_epsilon; | 310 | 2.64M | r.x += fixed_epsilon; | 311 | 2.64M | # if LINEAR_COLOR | 312 | | # ifdef DEBUG | 313 | | if (check_gradient_overflow(left, right)) { | 314 | | /* The caller must care of. | 315 | | Checking it here looses some performance with triangles. */ | 316 | | return_error(gs_error_unregistered); | 317 | | } | 318 | | # endif | 319 | 2.64M | lg.c = lgc; | 320 | 2.64M | lg.f = lgf; | 321 | 2.64M | lg.num = lgnum; | 322 | 2.64M | rg.c = rgc; | 323 | 2.64M | rg.f = rgf; | 324 | 2.64M | rg.num = rgnum; | 325 | 2.64M | xg.c = xgc; | 326 | 2.64M | xg.f = xgf; | 327 | 2.64M | xg.num = xgnum; | 328 | 2.64M | code = init_gradient(&lg, fa, left, right, &l, ymin, num_components); | 329 | 2.64M | if (code < 0) | 330 | 0 | return code; | 331 | 2.64M | code = init_gradient(&rg, fa, right, left, &r, ymin, num_components); | 332 | 2.64M | if (code < 0) | 333 | 0 | return code; | 334 | | | 335 | 2.64M | # endif | 336 | | | 337 | 2.64M | #define rational_floor(tl)\ | 338 | 2.64M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 2.64M | #define STEP_LINE(ix, tl)\ | 340 | 2.64M | tl.x += tl.ldi;\ | 341 | 2.64M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 2.64M | ix = rational_floor(tl) | 343 | | | 344 | 2.64M | rxl = rational_floor(l); | 345 | 2.64M | rxr = rational_floor(r); | 346 | 2.64M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 80.2M | while (LINEAR_COLOR ? 1 : ++iy != iy1) { | 348 | 80.2M | # if LINEAR_COLOR | 349 | 80.2M | if (rxl != rxr) { | 350 | 46.7M | code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components); | 351 | 46.7M | if (code < 0) | 352 | 0 | goto xit; | 353 | 46.7M | code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1); | 354 | 46.7M | if (code < 0) | 355 | 4 | goto xit; | 356 | 46.7M | } | 357 | 80.2M | if (++iy == iy1) | 358 | 2.64M | break; | 359 | 77.5M | STEP_LINE(rxl, l); | 360 | 77.5M | STEP_LINE(rxr, r); | 361 | 77.5M | step_gradient(&lg, num_components); | 362 | 77.5M | 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 | 77.5M | } | 379 | | # if !LINEAR_COLOR | 380 | | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | 2.64M | code = 0; | 383 | 2.64M | # endif | 384 | 2.64M | #undef STEP_LINE | 385 | 2.64M | #undef SET_MINIMAL_WIDTH | 386 | 2.64M | #undef CONNECT_RECTANGLES | 387 | 2.64M | #undef FILL_TRAP_RECT | 388 | 2.64M | #undef FILL_TRAP_RECT_DIRECT | 389 | 2.64M | #undef FILL_TRAP_RECT_INRECT | 390 | 2.64M | #undef YMULT_QUO | 391 | 2.64M | xit: if (code < 0 && FILL_DIRECT) | 392 | 4 | return_error(code); | 393 | 2.64M | return_if_interrupt(dev->memory); | 394 | 2.64M | return code; | 395 | 2.64M | } | 396 | 2.64M | } |
gdevddrw.c:gx_fill_trapezoid_ns_lc Line | Count | Source | 137 | 65.3M | { | 138 | 65.3M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 65.3M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 65.3M | if (ymin >= ymax) | 142 | 25.6M | return 0; /* no scan lines to sample */ | 143 | 39.6M | { | 144 | 39.6M | int iy = fixed2int_var(ymin); | 145 | 39.6M | const int iy1 = fixed2int_var(ymax); | 146 | 39.6M | trap_line l, r; | 147 | 39.6M | register int rxl, rxr; | 148 | | #if !LINEAR_COLOR | 149 | | int ry; | 150 | | #endif | 151 | 39.6M | const fixed | 152 | 39.6M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 39.6M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 39.6M | const fixed /* partial pixel offset to first line to sample */ | 155 | 39.6M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 39.6M | fixed fxl; | 157 | 39.6M | int code; | 158 | | # if CONTIGUOUS_FILL | 159 | | const bool peak0 = ((flags & 1) != 0); | 160 | | const bool peak1 = ((flags & 2) != 0); | 161 | | int peak_y0 = ybot + fixed_half; | 162 | | int peak_y1 = ytop - fixed_half; | 163 | | # endif | 164 | 39.6M | # if LINEAR_COLOR | 165 | 39.6M | int num_components = dev->color_info.num_components; | 166 | 39.6M | frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 167 | 39.6M | int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 168 | 39.6M | int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 169 | 39.6M | frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 170 | 39.6M | int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 171 | 39.6M | int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 172 | 39.6M | frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 173 | 39.6M | int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 174 | 39.6M | int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 175 | 39.6M | trap_gradient lg, rg, xg; | 176 | | # else | 177 | | gx_color_index cindex = pdevc->colors.pure; | 178 | | dev_proc_fill_rectangle((*fill_rect)) = | 179 | | dev_proc(dev, fill_rectangle); | 180 | | # endif | 181 | | | 182 | 39.6M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 39.6M | l.h = left->end.y - left->start.y; | 185 | 39.6M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 39.6M | r.h = right->end.y - right->start.y; | 188 | 39.6M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 39.6M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 39.6M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | | #if !LINEAR_COLOR | 193 | | ry = iy; | 194 | | #endif | 195 | | | 196 | | /* | 197 | | * Free variables of FILL_TRAP_RECT: | 198 | | * SWAP_AXES, pdevc, dev, fa | 199 | | * Free variables of FILL_TRAP_RECT_DIRECT: | 200 | | * SWAP_AXES, fill_rect, dev, cindex | 201 | | */ | 202 | 39.6M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 39.6M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 39.6M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 39.6M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 39.6M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 39.6M | (*fill_rect)(dev, x, y, w, h, cindex)) | 208 | | | 209 | 39.6M | #if LINEAR_COLOR | 210 | 39.6M | # define FILL_TRAP_RECT(x,y,w,h)\ | 211 | 39.6M | (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den)) | 212 | | #else | 213 | | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | | #endif | 216 | | | 217 | | /* Compute the dx/dy ratios. */ | 218 | | | 219 | | /* | 220 | | * Compute the x offsets at the first scan line to sample. We need | 221 | | * to be careful in computing ys# * dx#f {/,%} h# because the | 222 | | * multiplication may overflow. We know that all the quantities | 223 | | * involved are non-negative, and that ys# is usually less than 1 (as | 224 | | * a fixed, of course); this gives us a cheap conservative check for | 225 | | * overflow in the multiplication. | 226 | | */ | 227 | 39.6M | #define YMULT_QUO(ys, tl)\ | 228 | 39.6M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 39.6M | fixed_mult_quo(ys, tl.df, tl.h)) | 230 | | | 231 | | #if CONTIGUOUS_FILL | 232 | | /* | 233 | | * If left and right boundary round to same pixel index, | 234 | | * we would not paing the scan and would get a dropout. | 235 | | * Check for this case and choose one of two pixels | 236 | | * which is closer to the "axis". We need to exclude | 237 | | * 'peak' because it would paint an excessive pixel. | 238 | | */ | 239 | | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \ | 240 | | if (ixl == ixr) \ | 241 | | if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\ | 242 | | fixed x = int2fixed(ixl) + fixed_half;\ | 243 | | if (x - l.x < r.x - x)\ | 244 | | ++ixr;\ | 245 | | else\ | 246 | | --ixl;\ | 247 | | } | 248 | | | 249 | | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\ | 250 | | if (adj1 < adj2) {\ | 251 | | if (iy - ry > 1) {\ | 252 | | code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\ | 253 | | if (code < 0)\ | 254 | | goto xit;\ | 255 | | ry = iy - 1;\ | 256 | | }\ | 257 | | adj1 = adj2 = (adj2 + adj2) / 2;\ | 258 | | } | 259 | | | 260 | | #else | 261 | 39.6M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 39.6M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 39.6M | #endif | 264 | 39.6M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 8.41M | l.di = 0, l.df = 0; | 267 | 8.41M | fxl = 0; | 268 | 31.2M | } else { | 269 | 31.2M | compute_dx(&l, dxl, ysl); | 270 | 31.2M | fxl = YMULT_QUO(ysl, l); | 271 | 31.2M | l.x += fxl; | 272 | 31.2M | } | 273 | 39.6M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | | # if !LINEAR_COLOR | 277 | | if (l.di == 0 && l.df == 0) { | 278 | | rxl = fixed2int_var(l.x); | 279 | | rxr = fixed2int_var(r.x); | 280 | | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | | goto xit; | 283 | | } | 284 | | # endif | 285 | 8.38M | r.di = 0, r.df = 0; | 286 | 8.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 | 31.2M | else if (dxr == dxl && fxl != 0) { | 292 | 2.17M | if (l.di == 0) | 293 | 848k | r.di = 0, r.df = l.df; | 294 | 1.32M | else | 295 | 1.32M | compute_dx(&r, dxr, ysr); | 296 | 2.17M | if (ysr == ysl && r.h == l.h) | 297 | 1.55M | r.x += fxl; | 298 | 621k | else | 299 | 621k | r.x += YMULT_QUO(ysr, r); | 300 | 29.0M | } else { | 301 | 29.0M | compute_dx(&r, dxr, ysr); | 302 | 29.0M | r.x += YMULT_QUO(ysr, r); | 303 | 29.0M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 39.6M | compute_ldx(&l, ysl); | 306 | 39.6M | compute_ldx(&r, ysr); | 307 | | /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding | 308 | | when the rational part is zero. Now add it back to get xl', xr' */ | 309 | 39.6M | l.x += fixed_epsilon; | 310 | 39.6M | r.x += fixed_epsilon; | 311 | 39.6M | # if LINEAR_COLOR | 312 | | # ifdef DEBUG | 313 | | if (check_gradient_overflow(left, right)) { | 314 | | /* The caller must care of. | 315 | | Checking it here looses some performance with triangles. */ | 316 | | return_error(gs_error_unregistered); | 317 | | } | 318 | | # endif | 319 | 39.6M | lg.c = lgc; | 320 | 39.6M | lg.f = lgf; | 321 | 39.6M | lg.num = lgnum; | 322 | 39.6M | rg.c = rgc; | 323 | 39.6M | rg.f = rgf; | 324 | 39.6M | rg.num = rgnum; | 325 | 39.6M | xg.c = xgc; | 326 | 39.6M | xg.f = xgf; | 327 | 39.6M | xg.num = xgnum; | 328 | 39.6M | code = init_gradient(&lg, fa, left, right, &l, ymin, num_components); | 329 | 39.6M | if (code < 0) | 330 | 0 | return code; | 331 | 39.6M | code = init_gradient(&rg, fa, right, left, &r, ymin, num_components); | 332 | 39.6M | if (code < 0) | 333 | 0 | return code; | 334 | | | 335 | 39.6M | # endif | 336 | | | 337 | 39.6M | #define rational_floor(tl)\ | 338 | 39.6M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 39.6M | #define STEP_LINE(ix, tl)\ | 340 | 39.6M | tl.x += tl.ldi;\ | 341 | 39.6M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 39.6M | ix = rational_floor(tl) | 343 | | | 344 | 39.6M | rxl = rational_floor(l); | 345 | 39.6M | rxr = rational_floor(r); | 346 | 39.6M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 409M | while (LINEAR_COLOR ? 1 : ++iy != iy1) { | 348 | 409M | # if LINEAR_COLOR | 349 | 409M | if (rxl != rxr) { | 350 | 91.5M | code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components); | 351 | 91.5M | if (code < 0) | 352 | 0 | goto xit; | 353 | 91.5M | code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1); | 354 | 91.5M | if (code < 0) | 355 | 13 | goto xit; | 356 | 91.5M | } | 357 | 409M | if (++iy == iy1) | 358 | 39.6M | break; | 359 | 369M | STEP_LINE(rxl, l); | 360 | 369M | STEP_LINE(rxr, r); | 361 | 369M | step_gradient(&lg, num_components); | 362 | 369M | step_gradient(&rg, num_components); | 363 | | # else | 364 | | register int ixl, ixr; | 365 | | | 366 | | STEP_LINE(ixl, l); | 367 | | STEP_LINE(ixr, r); | 368 | | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | | if (ixl != rxl || ixr != rxr) { | 370 | | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | | if (code < 0) | 374 | | goto xit; | 375 | | rxl = ixl, rxr = ixr, ry = iy; | 376 | | } | 377 | | # endif | 378 | 369M | } | 379 | | # if !LINEAR_COLOR | 380 | | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | 39.6M | code = 0; | 383 | 39.6M | # endif | 384 | 39.6M | #undef STEP_LINE | 385 | 39.6M | #undef SET_MINIMAL_WIDTH | 386 | 39.6M | #undef CONNECT_RECTANGLES | 387 | 39.6M | #undef FILL_TRAP_RECT | 388 | 39.6M | #undef FILL_TRAP_RECT_DIRECT | 389 | 39.6M | #undef FILL_TRAP_RECT_INRECT | 390 | 39.6M | #undef YMULT_QUO | 391 | 39.6M | xit: if (code < 0 && FILL_DIRECT) | 392 | 13 | return_error(code); | 393 | 39.6M | return_if_interrupt(dev->memory); | 394 | 39.6M | return code; | 395 | 39.6M | } | 396 | 39.6M | } |
|