396 | 189M | } 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 | 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 | 78.1k | return 0; /* no scan lines to sample */ | 143 | 2.00M | { | 144 | 2.00M | int iy = fixed2int_var(ymin); | 145 | 2.00M | const int iy1 = fixed2int_var(ymax); | 146 | 2.00M | trap_line l, r; | 147 | 2.00M | register int rxl, rxr; | 148 | 2.00M | #if !LINEAR_COLOR | 149 | 2.00M | int ry; | 150 | 2.00M | #endif | 151 | 2.00M | const fixed | 152 | 2.00M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 2.00M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 2.00M | const fixed /* partial pixel offset to first line to sample */ | 155 | 2.00M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 2.00M | fixed fxl; | 157 | 2.00M | 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.00M | gx_color_index cindex = pdevc->colors.pure; | 178 | 2.00M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 2.00M | dev_proc(dev, fill_rectangle); | 180 | 2.00M | # endif | 181 | | | 182 | 2.00M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 2.00M | l.h = left->end.y - left->start.y; | 185 | 2.00M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 2.00M | r.h = right->end.y - right->start.y; | 188 | 2.00M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 2.00M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 2.00M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 2.00M | #if !LINEAR_COLOR | 193 | 2.00M | ry = iy; | 194 | 2.00M | #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.00M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 2.00M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 2.00M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 2.00M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 2.00M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 2.00M | (*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.00M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 2.00M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 2.00M | #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.00M | #define YMULT_QUO(ys, tl)\ | 228 | 2.00M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 2.00M | 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.00M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 2.00M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 2.00M | #endif | 264 | 2.00M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 529k | l.di = 0, l.df = 0; | 267 | 529k | fxl = 0; | 268 | 1.47M | } else { | 269 | 1.47M | compute_dx(&l, dxl, ysl); | 270 | 1.47M | fxl = YMULT_QUO(ysl, l); | 271 | 1.47M | l.x += fxl; | 272 | 1.47M | } | 273 | 2.00M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 509k | # if !LINEAR_COLOR | 277 | 509k | if (l.di == 0 && l.df == 0) { | 278 | 490k | rxl = fixed2int_var(l.x); | 279 | 490k | rxr = fixed2int_var(r.x); | 280 | 490k | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 490k | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 490k | goto xit; | 283 | 490k | } | 284 | 18.6k | # endif | 285 | 18.6k | r.di = 0, r.df = 0; | 286 | 18.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 | 1.49M | else if (dxr == dxl && fxl != 0) { | 292 | 1.12M | if (l.di == 0) | 293 | 577k | r.di = 0, r.df = l.df; | 294 | 551k | else | 295 | 551k | compute_dx(&r, dxr, ysr); | 296 | 1.12M | if (ysr == ysl && r.h == l.h) | 297 | 1.12M | r.x += fxl; | 298 | 110 | else | 299 | 110 | r.x += YMULT_QUO(ysr, r); | 300 | 1.12M | } else { | 301 | 362k | compute_dx(&r, dxr, ysr); | 302 | 362k | r.x += YMULT_QUO(ysr, r); | 303 | 362k | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 1.51M | compute_ldx(&l, ysl); | 306 | 1.51M | 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.51M | l.x += fixed_epsilon; | 310 | 1.51M | 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.51M | #define rational_floor(tl)\ | 338 | 1.51M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 1.51M | #define STEP_LINE(ix, tl)\ | 340 | 1.51M | tl.x += tl.ldi;\ | 341 | 1.51M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 1.51M | ix = rational_floor(tl) | 343 | | | 344 | 1.51M | rxl = rational_floor(l); | 345 | 1.51M | rxr = rational_floor(r); | 346 | 1.51M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 178M | 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 | 177M | register int ixl, ixr; | 365 | | | 366 | 177M | STEP_LINE(ixl, l); | 367 | 177M | STEP_LINE(ixr, r); | 368 | 177M | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 177M | if (ixl != rxl || ixr != rxr) { | 370 | 30.1M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 30.1M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 30.1M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 30.1M | if (code < 0) | 374 | 0 | goto xit; | 375 | 30.1M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 30.1M | } | 377 | 177M | # endif | 378 | 177M | } | 379 | 1.51M | # if !LINEAR_COLOR | 380 | 1.51M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 1.51M | #undef STEP_LINE | 385 | 1.51M | #undef SET_MINIMAL_WIDTH | 386 | 1.51M | #undef CONNECT_RECTANGLES | 387 | 1.51M | #undef FILL_TRAP_RECT | 388 | 1.51M | #undef FILL_TRAP_RECT_DIRECT | 389 | 1.51M | #undef FILL_TRAP_RECT_INRECT | 390 | 1.51M | #undef YMULT_QUO | 391 | 2.00M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 2.00M | return_if_interrupt(dev->memory); | 394 | 2.00M | return code; | 395 | 2.00M | } | 396 | 2.00M | } |
gdevddrw.c:gx_fill_trapezoid_as_nd Line | Count | Source | 137 | 2.40M | { | 138 | 2.40M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 2.40M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 2.40M | if (ymin >= ymax) | 142 | 30.1k | return 0; /* no scan lines to sample */ | 143 | 2.37M | { | 144 | 2.37M | int iy = fixed2int_var(ymin); | 145 | 2.37M | const int iy1 = fixed2int_var(ymax); | 146 | 2.37M | trap_line l, r; | 147 | 2.37M | register int rxl, rxr; | 148 | 2.37M | #if !LINEAR_COLOR | 149 | 2.37M | int ry; | 150 | 2.37M | #endif | 151 | 2.37M | const fixed | 152 | 2.37M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 2.37M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 2.37M | const fixed /* partial pixel offset to first line to sample */ | 155 | 2.37M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 2.37M | fixed fxl; | 157 | 2.37M | 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.37M | gx_color_index cindex = pdevc->colors.pure; | 178 | 2.37M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 2.37M | dev_proc(dev, fill_rectangle); | 180 | 2.37M | # endif | 181 | | | 182 | 2.37M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 2.37M | l.h = left->end.y - left->start.y; | 185 | 2.37M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 2.37M | r.h = right->end.y - right->start.y; | 188 | 2.37M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 2.37M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 2.37M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 2.37M | #if !LINEAR_COLOR | 193 | 2.37M | ry = iy; | 194 | 2.37M | #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.37M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 2.37M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 2.37M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 2.37M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 2.37M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 2.37M | (*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.37M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 2.37M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 2.37M | #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.37M | #define YMULT_QUO(ys, tl)\ | 228 | 2.37M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 2.37M | 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.37M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 2.37M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 2.37M | #endif | 264 | 2.37M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 628k | l.di = 0, l.df = 0; | 267 | 628k | fxl = 0; | 268 | 1.74M | } else { | 269 | 1.74M | compute_dx(&l, dxl, ysl); | 270 | 1.74M | fxl = YMULT_QUO(ysl, l); | 271 | 1.74M | l.x += fxl; | 272 | 1.74M | } | 273 | 2.37M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 586k | # if !LINEAR_COLOR | 277 | 586k | if (l.di == 0 && l.df == 0) { | 278 | 568k | rxl = fixed2int_var(l.x); | 279 | 568k | rxr = fixed2int_var(r.x); | 280 | 568k | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 568k | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 568k | goto xit; | 283 | 568k | } | 284 | 18.2k | # endif | 285 | 18.2k | r.di = 0, r.df = 0; | 286 | 18.2k | } | 287 | | /* | 288 | | * The test for fxl != 0 is required because the right edge might | 289 | | * cross some pixel centers even if the left edge doesn't. | 290 | | */ | 291 | 1.78M | else if (dxr == dxl && fxl != 0) { | 292 | 370k | if (l.di == 0) | 293 | 221k | r.di = 0, r.df = l.df; | 294 | 149k | else | 295 | 149k | compute_dx(&r, dxr, ysr); | 296 | 370k | if (ysr == ysl && r.h == l.h) | 297 | 369k | r.x += fxl; | 298 | 216 | else | 299 | 216 | r.x += YMULT_QUO(ysr, r); | 300 | 1.41M | } else { | 301 | 1.41M | compute_dx(&r, dxr, ysr); | 302 | 1.41M | r.x += YMULT_QUO(ysr, r); | 303 | 1.41M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 1.80M | compute_ldx(&l, ysl); | 306 | 1.80M | 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.80M | l.x += fixed_epsilon; | 310 | 1.80M | 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.80M | #define rational_floor(tl)\ | 338 | 1.80M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 1.80M | #define STEP_LINE(ix, tl)\ | 340 | 1.80M | tl.x += tl.ldi;\ | 341 | 1.80M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 1.80M | ix = rational_floor(tl) | 343 | | | 344 | 1.80M | rxl = rational_floor(l); | 345 | 1.80M | rxr = rational_floor(r); | 346 | 1.80M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 245M | 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 | 243M | register int ixl, ixr; | 365 | | | 366 | 243M | STEP_LINE(ixl, l); | 367 | 243M | STEP_LINE(ixr, r); | 368 | 243M | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 243M | if (ixl != rxl || ixr != rxr) { | 370 | 183M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 183M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 183M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 183M | if (code < 0) | 374 | 0 | goto xit; | 375 | 183M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 183M | } | 377 | 243M | # endif | 378 | 243M | } | 379 | 1.80M | # if !LINEAR_COLOR | 380 | 1.80M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 1.80M | #undef STEP_LINE | 385 | 1.80M | #undef SET_MINIMAL_WIDTH | 386 | 1.80M | #undef CONNECT_RECTANGLES | 387 | 1.80M | #undef FILL_TRAP_RECT | 388 | 1.80M | #undef FILL_TRAP_RECT_DIRECT | 389 | 1.80M | #undef FILL_TRAP_RECT_INRECT | 390 | 1.80M | #undef YMULT_QUO | 391 | 2.37M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 2.37M | return_if_interrupt(dev->memory); | 394 | 2.37M | return code; | 395 | 2.37M | } | 396 | 2.37M | } |
gdevddrw.c:gx_fill_trapezoid_ns_fd Line | Count | Source | 137 | 84.0M | { | 138 | 84.0M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 84.0M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 84.0M | if (ymin >= ymax) | 142 | 11.8M | return 0; /* no scan lines to sample */ | 143 | 72.2M | { | 144 | 72.2M | int iy = fixed2int_var(ymin); | 145 | 72.2M | const int iy1 = fixed2int_var(ymax); | 146 | 72.2M | trap_line l, r; | 147 | 72.2M | register int rxl, rxr; | 148 | 72.2M | #if !LINEAR_COLOR | 149 | 72.2M | int ry; | 150 | 72.2M | #endif | 151 | 72.2M | const fixed | 152 | 72.2M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 72.2M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 72.2M | const fixed /* partial pixel offset to first line to sample */ | 155 | 72.2M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 72.2M | fixed fxl; | 157 | 72.2M | int code; | 158 | | # if CONTIGUOUS_FILL | 159 | | const bool peak0 = ((flags & 1) != 0); | 160 | | const bool peak1 = ((flags & 2) != 0); | 161 | | int peak_y0 = ybot + fixed_half; | 162 | | int peak_y1 = ytop - fixed_half; | 163 | | # endif | 164 | | # if LINEAR_COLOR | 165 | | int num_components = dev->color_info.num_components; | 166 | | frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 167 | | int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 168 | | int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 169 | | frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 170 | | int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 171 | | int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 172 | | frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 173 | | int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 174 | | int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 175 | | trap_gradient lg, rg, xg; | 176 | | # else | 177 | 72.2M | gx_color_index cindex = pdevc->colors.pure; | 178 | 72.2M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 72.2M | dev_proc(dev, fill_rectangle); | 180 | 72.2M | # endif | 181 | | | 182 | 72.2M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 72.2M | l.h = left->end.y - left->start.y; | 185 | 72.2M | if (l.h == 0) | 186 | 12 | return 0; | 187 | 72.2M | r.h = right->end.y - right->start.y; | 188 | 72.2M | if (r.h == 0) | 189 | 12 | return 0; | 190 | 72.2M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 72.2M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 72.2M | #if !LINEAR_COLOR | 193 | 72.2M | ry = iy; | 194 | 72.2M | #endif | 195 | | | 196 | | /* | 197 | | * Free variables of FILL_TRAP_RECT: | 198 | | * SWAP_AXES, pdevc, dev, fa | 199 | | * Free variables of FILL_TRAP_RECT_DIRECT: | 200 | | * SWAP_AXES, fill_rect, dev, cindex | 201 | | */ | 202 | 72.2M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 72.2M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 72.2M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 72.2M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 72.2M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 72.2M | (*fill_rect)(dev, x, y, w, h, cindex)) | 208 | | | 209 | | #if LINEAR_COLOR | 210 | | # define FILL_TRAP_RECT(x,y,w,h)\ | 211 | | (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den)) | 212 | | #else | 213 | 72.2M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 72.2M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 72.2M | #endif | 216 | | | 217 | | /* Compute the dx/dy ratios. */ | 218 | | | 219 | | /* | 220 | | * Compute the x offsets at the first scan line to sample. We need | 221 | | * to be careful in computing ys# * dx#f {/,%} h# because the | 222 | | * multiplication may overflow. We know that all the quantities | 223 | | * involved are non-negative, and that ys# is usually less than 1 (as | 224 | | * a fixed, of course); this gives us a cheap conservative check for | 225 | | * overflow in the multiplication. | 226 | | */ | 227 | 72.2M | #define YMULT_QUO(ys, tl)\ | 228 | 72.2M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 72.2M | fixed_mult_quo(ys, tl.df, tl.h)) | 230 | | | 231 | | #if CONTIGUOUS_FILL | 232 | | /* | 233 | | * If left and right boundary round to same pixel index, | 234 | | * we would not paing the scan and would get a dropout. | 235 | | * Check for this case and choose one of two pixels | 236 | | * which is closer to the "axis". We need to exclude | 237 | | * 'peak' because it would paint an excessive pixel. | 238 | | */ | 239 | | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \ | 240 | | if (ixl == ixr) \ | 241 | | if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\ | 242 | | fixed x = int2fixed(ixl) + fixed_half;\ | 243 | | if (x - l.x < r.x - x)\ | 244 | | ++ixr;\ | 245 | | else\ | 246 | | --ixl;\ | 247 | | } | 248 | | | 249 | | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\ | 250 | | if (adj1 < adj2) {\ | 251 | | if (iy - ry > 1) {\ | 252 | | code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\ | 253 | | if (code < 0)\ | 254 | | goto xit;\ | 255 | | ry = iy - 1;\ | 256 | | }\ | 257 | | adj1 = adj2 = (adj2 + adj2) / 2;\ | 258 | | } | 259 | | | 260 | | #else | 261 | 72.2M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 72.2M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 72.2M | #endif | 264 | 72.2M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 35.4M | l.di = 0, l.df = 0; | 267 | 35.4M | fxl = 0; | 268 | 36.7M | } else { | 269 | 36.7M | compute_dx(&l, dxl, ysl); | 270 | 36.7M | fxl = YMULT_QUO(ysl, l); | 271 | 36.7M | l.x += fxl; | 272 | 36.7M | } | 273 | 72.2M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 35.6M | # if !LINEAR_COLOR | 277 | 35.6M | if (l.di == 0 && l.df == 0) { | 278 | 29.7M | rxl = fixed2int_var(l.x); | 279 | 29.7M | rxr = fixed2int_var(r.x); | 280 | 29.7M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 29.7M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 29.7M | goto xit; | 283 | 29.7M | } | 284 | 5.90M | # endif | 285 | 5.90M | r.di = 0, r.df = 0; | 286 | 5.90M | } | 287 | | /* | 288 | | * The test for fxl != 0 is required because the right edge might | 289 | | * cross some pixel centers even if the left edge doesn't. | 290 | | */ | 291 | 36.5M | else if (dxr == dxl && fxl != 0) { | 292 | 4.79M | if (l.di == 0) | 293 | 1.74M | r.di = 0, r.df = l.df; | 294 | 3.04M | else | 295 | 3.04M | compute_dx(&r, dxr, ysr); | 296 | 4.79M | if (ysr == ysl && r.h == l.h) | 297 | 1.40M | r.x += fxl; | 298 | 3.38M | else | 299 | 3.38M | r.x += YMULT_QUO(ysr, r); | 300 | 31.7M | } else { | 301 | 31.7M | compute_dx(&r, dxr, ysr); | 302 | 31.7M | r.x += YMULT_QUO(ysr, r); | 303 | 31.7M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 42.4M | compute_ldx(&l, ysl); | 306 | 42.4M | 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 | 42.4M | l.x += fixed_epsilon; | 310 | 42.4M | 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 | 42.4M | #define rational_floor(tl)\ | 338 | 42.4M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 42.4M | #define STEP_LINE(ix, tl)\ | 340 | 42.4M | tl.x += tl.ldi;\ | 341 | 42.4M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 42.4M | ix = rational_floor(tl) | 343 | | | 344 | 42.4M | rxl = rational_floor(l); | 345 | 42.4M | rxr = rational_floor(r); | 346 | 42.4M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 1.30G | 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.25G | register int ixl, ixr; | 365 | | | 366 | 1.25G | STEP_LINE(ixl, l); | 367 | 1.25G | STEP_LINE(ixr, r); | 368 | 1.25G | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 1.25G | if (ixl != rxl || ixr != rxr) { | 370 | 300M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 300M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 300M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 300M | if (code < 0) | 374 | 0 | goto xit; | 375 | 300M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 300M | } | 377 | 1.25G | # endif | 378 | 1.25G | } | 379 | 42.4M | # if !LINEAR_COLOR | 380 | 42.4M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 42.4M | #undef STEP_LINE | 385 | 42.4M | #undef SET_MINIMAL_WIDTH | 386 | 42.4M | #undef CONNECT_RECTANGLES | 387 | 42.4M | #undef FILL_TRAP_RECT | 388 | 42.4M | #undef FILL_TRAP_RECT_DIRECT | 389 | 42.4M | #undef FILL_TRAP_RECT_INRECT | 390 | 42.4M | #undef YMULT_QUO | 391 | 72.2M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 72.2M | return_if_interrupt(dev->memory); | 394 | 72.2M | return code; | 395 | 72.2M | } | 396 | 72.2M | } |
gdevddrw.c:gx_fill_trapezoid_ns_nd Line | Count | Source | 137 | 104M | { | 138 | 104M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 104M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 104M | if (ymin >= ymax) | 142 | 22.0M | return 0; /* no scan lines to sample */ | 143 | 82.1M | { | 144 | 82.1M | int iy = fixed2int_var(ymin); | 145 | 82.1M | const int iy1 = fixed2int_var(ymax); | 146 | 82.1M | trap_line l, r; | 147 | 82.1M | register int rxl, rxr; | 148 | 82.1M | #if !LINEAR_COLOR | 149 | 82.1M | int ry; | 150 | 82.1M | #endif | 151 | 82.1M | const fixed | 152 | 82.1M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 82.1M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 82.1M | const fixed /* partial pixel offset to first line to sample */ | 155 | 82.1M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 82.1M | fixed fxl; | 157 | 82.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 | 82.1M | gx_color_index cindex = pdevc->colors.pure; | 178 | 82.1M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 82.1M | dev_proc(dev, fill_rectangle); | 180 | 82.1M | # endif | 181 | | | 182 | 82.1M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 82.1M | l.h = left->end.y - left->start.y; | 185 | 82.1M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 82.1M | r.h = right->end.y - right->start.y; | 188 | 82.1M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 82.1M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 82.1M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 82.1M | #if !LINEAR_COLOR | 193 | 82.1M | ry = iy; | 194 | 82.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 | 82.1M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 82.1M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 82.1M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 82.1M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 82.1M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 82.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 | 82.1M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 82.1M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 82.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 | 82.1M | #define YMULT_QUO(ys, tl)\ | 228 | 82.1M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 82.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 | 82.1M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 82.1M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 82.1M | #endif | 264 | 82.1M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 48.0M | l.di = 0, l.df = 0; | 267 | 48.0M | fxl = 0; | 268 | 48.0M | } else { | 269 | 34.1M | compute_dx(&l, dxl, ysl); | 270 | 34.1M | fxl = YMULT_QUO(ysl, l); | 271 | 34.1M | l.x += fxl; | 272 | 34.1M | } | 273 | 82.1M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 51.9M | # if !LINEAR_COLOR | 277 | 51.9M | if (l.di == 0 && l.df == 0) { | 278 | 42.2M | rxl = fixed2int_var(l.x); | 279 | 42.2M | rxr = fixed2int_var(r.x); | 280 | 42.2M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 42.2M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 42.2M | goto xit; | 283 | 42.2M | } | 284 | 9.69M | # endif | 285 | 9.69M | r.di = 0, r.df = 0; | 286 | 9.69M | } | 287 | | /* | 288 | | * The test for fxl != 0 is required because the right edge might | 289 | | * cross some pixel centers even if the left edge doesn't. | 290 | | */ | 291 | 30.1M | else if (dxr == dxl && fxl != 0) { | 292 | 2.88M | if (l.di == 0) | 293 | 849k | r.di = 0, r.df = l.df; | 294 | 2.03M | else | 295 | 2.03M | compute_dx(&r, dxr, ysr); | 296 | 2.88M | if (ysr == ysl && r.h == l.h) | 297 | 1.10M | r.x += fxl; | 298 | 1.77M | else | 299 | 1.77M | r.x += YMULT_QUO(ysr, r); | 300 | 27.2M | } else { | 301 | 27.2M | compute_dx(&r, dxr, ysr); | 302 | 27.2M | r.x += YMULT_QUO(ysr, r); | 303 | 27.2M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 39.8M | compute_ldx(&l, ysl); | 306 | 39.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 | 39.8M | l.x += fixed_epsilon; | 310 | 39.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 | 39.8M | #define rational_floor(tl)\ | 338 | 39.8M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 39.8M | #define STEP_LINE(ix, tl)\ | 340 | 39.8M | tl.x += tl.ldi;\ | 341 | 39.8M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 39.8M | ix = rational_floor(tl) | 343 | | | 344 | 39.8M | rxl = rational_floor(l); | 345 | 39.8M | rxr = rational_floor(r); | 346 | 39.8M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 888M | 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 | 848M | register int ixl, ixr; | 365 | | | 366 | 848M | STEP_LINE(ixl, l); | 367 | 848M | STEP_LINE(ixr, r); | 368 | 848M | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 848M | if (ixl != rxl || ixr != rxr) { | 370 | 715M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 715M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 715M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 715M | if (code < 0) | 374 | 0 | goto xit; | 375 | 715M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 715M | } | 377 | 848M | # endif | 378 | 848M | } | 379 | 39.8M | # if !LINEAR_COLOR | 380 | 39.8M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 39.8M | #undef STEP_LINE | 385 | 39.8M | #undef SET_MINIMAL_WIDTH | 386 | 39.8M | #undef CONNECT_RECTANGLES | 387 | 39.8M | #undef FILL_TRAP_RECT | 388 | 39.8M | #undef FILL_TRAP_RECT_DIRECT | 389 | 39.8M | #undef FILL_TRAP_RECT_INRECT | 390 | 39.8M | #undef YMULT_QUO | 391 | 82.1M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 82.1M | return_if_interrupt(dev->memory); | 394 | 82.1M | return code; | 395 | 82.1M | } | 396 | 82.1M | } |
gdevddrw.c:gx_fill_trapezoid_as_lc Line | Count | Source | 137 | 1.95M | { | 138 | 1.95M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 1.95M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 1.95M | if (ymin >= ymax) | 142 | 296k | return 0; /* no scan lines to sample */ | 143 | 1.66M | { | 144 | 1.66M | int iy = fixed2int_var(ymin); | 145 | 1.66M | const int iy1 = fixed2int_var(ymax); | 146 | 1.66M | trap_line l, r; | 147 | 1.66M | register int rxl, rxr; | 148 | | #if !LINEAR_COLOR | 149 | | int ry; | 150 | | #endif | 151 | 1.66M | const fixed | 152 | 1.66M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 1.66M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 1.66M | const fixed /* partial pixel offset to first line to sample */ | 155 | 1.66M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 1.66M | fixed fxl; | 157 | 1.66M | int code; | 158 | | # if CONTIGUOUS_FILL | 159 | | const bool peak0 = ((flags & 1) != 0); | 160 | | const bool peak1 = ((flags & 2) != 0); | 161 | | int peak_y0 = ybot + fixed_half; | 162 | | int peak_y1 = ytop - fixed_half; | 163 | | # endif | 164 | 1.66M | # if LINEAR_COLOR | 165 | 1.66M | int num_components = dev->color_info.num_components; | 166 | 1.66M | frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 167 | 1.66M | int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 168 | 1.66M | int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 169 | 1.66M | frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 170 | 1.66M | int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 171 | 1.66M | int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 172 | 1.66M | frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 173 | 1.66M | int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 174 | 1.66M | int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 175 | 1.66M | trap_gradient lg, rg, xg; | 176 | | # else | 177 | | gx_color_index cindex = pdevc->colors.pure; | 178 | | dev_proc_fill_rectangle((*fill_rect)) = | 179 | | dev_proc(dev, fill_rectangle); | 180 | | # endif | 181 | | | 182 | 1.66M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 1.66M | l.h = left->end.y - left->start.y; | 185 | 1.66M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 1.66M | r.h = right->end.y - right->start.y; | 188 | 1.66M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 1.66M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 1.66M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | | #if !LINEAR_COLOR | 193 | | ry = iy; | 194 | | #endif | 195 | | | 196 | | /* | 197 | | * Free variables of FILL_TRAP_RECT: | 198 | | * SWAP_AXES, pdevc, dev, fa | 199 | | * Free variables of FILL_TRAP_RECT_DIRECT: | 200 | | * SWAP_AXES, fill_rect, dev, cindex | 201 | | */ | 202 | 1.66M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 1.66M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 1.66M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 1.66M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 1.66M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 1.66M | (*fill_rect)(dev, x, y, w, h, cindex)) | 208 | | | 209 | 1.66M | #if LINEAR_COLOR | 210 | 1.66M | # define FILL_TRAP_RECT(x,y,w,h)\ | 211 | 1.66M | (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den)) | 212 | | #else | 213 | | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | | #endif | 216 | | | 217 | | /* Compute the dx/dy ratios. */ | 218 | | | 219 | | /* | 220 | | * Compute the x offsets at the first scan line to sample. We need | 221 | | * to be careful in computing ys# * dx#f {/,%} h# because the | 222 | | * multiplication may overflow. We know that all the quantities | 223 | | * involved are non-negative, and that ys# is usually less than 1 (as | 224 | | * a fixed, of course); this gives us a cheap conservative check for | 225 | | * overflow in the multiplication. | 226 | | */ | 227 | 1.66M | #define YMULT_QUO(ys, tl)\ | 228 | 1.66M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 1.66M | 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.66M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 1.66M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 1.66M | #endif | 264 | 1.66M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 1.29M | l.di = 0, l.df = 0; | 267 | 1.29M | fxl = 0; | 268 | 1.29M | } else { | 269 | 364k | compute_dx(&l, dxl, ysl); | 270 | 364k | fxl = YMULT_QUO(ysl, l); | 271 | 364k | l.x += fxl; | 272 | 364k | } | 273 | 1.66M | 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.30M | r.di = 0, r.df = 0; | 286 | 1.30M | } | 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 | 356k | else if (dxr == dxl && fxl != 0) { | 292 | 183k | if (l.di == 0) | 293 | 74.8k | r.di = 0, r.df = l.df; | 294 | 108k | else | 295 | 108k | compute_dx(&r, dxr, ysr); | 296 | 183k | if (ysr == ysl && r.h == l.h) | 297 | 183k | r.x += fxl; | 298 | 177 | else | 299 | 177 | r.x += YMULT_QUO(ysr, r); | 300 | 183k | } else { | 301 | 172k | compute_dx(&r, dxr, ysr); | 302 | 172k | r.x += YMULT_QUO(ysr, r); | 303 | 172k | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 1.66M | compute_ldx(&l, ysl); | 306 | 1.66M | compute_ldx(&r, ysr); | 307 | | /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding | 308 | | when the rational part is zero. Now add it back to get xl', xr' */ | 309 | 1.66M | l.x += fixed_epsilon; | 310 | 1.66M | r.x += fixed_epsilon; | 311 | 1.66M | # if LINEAR_COLOR | 312 | | # ifdef DEBUG | 313 | | if (check_gradient_overflow(left, right)) { | 314 | | /* The caller must care of. | 315 | | Checking it here looses some performance with triangles. */ | 316 | | return_error(gs_error_unregistered); | 317 | | } | 318 | | # endif | 319 | 1.66M | lg.c = lgc; | 320 | 1.66M | lg.f = lgf; | 321 | 1.66M | lg.num = lgnum; | 322 | 1.66M | rg.c = rgc; | 323 | 1.66M | rg.f = rgf; | 324 | 1.66M | rg.num = rgnum; | 325 | 1.66M | xg.c = xgc; | 326 | 1.66M | xg.f = xgf; | 327 | 1.66M | xg.num = xgnum; | 328 | 1.66M | code = init_gradient(&lg, fa, left, right, &l, ymin, num_components); | 329 | 1.66M | if (code < 0) | 330 | 0 | return code; | 331 | 1.66M | code = init_gradient(&rg, fa, right, left, &r, ymin, num_components); | 332 | 1.66M | if (code < 0) | 333 | 0 | return code; | 334 | | | 335 | 1.66M | # endif | 336 | | | 337 | 1.66M | #define rational_floor(tl)\ | 338 | 1.66M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 1.66M | #define STEP_LINE(ix, tl)\ | 340 | 1.66M | tl.x += tl.ldi;\ | 341 | 1.66M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 1.66M | ix = rational_floor(tl) | 343 | | | 344 | 1.66M | rxl = rational_floor(l); | 345 | 1.66M | rxr = rational_floor(r); | 346 | 1.66M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 28.4M | while (LINEAR_COLOR ? 1 : ++iy != iy1) { | 348 | 28.4M | # if LINEAR_COLOR | 349 | 28.4M | if (rxl != rxr) { | 350 | 18.3M | code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components); | 351 | 18.3M | if (code < 0) | 352 | 0 | goto xit; | 353 | 18.3M | code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1); | 354 | 18.3M | if (code < 0) | 355 | 5 | goto xit; | 356 | 18.3M | } | 357 | 28.4M | if (++iy == iy1) | 358 | 1.66M | break; | 359 | 26.8M | STEP_LINE(rxl, l); | 360 | 26.8M | STEP_LINE(rxr, r); | 361 | 26.8M | step_gradient(&lg, num_components); | 362 | 26.8M | step_gradient(&rg, num_components); | 363 | | # else | 364 | | register int ixl, ixr; | 365 | | | 366 | | STEP_LINE(ixl, l); | 367 | | STEP_LINE(ixr, r); | 368 | | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | | if (ixl != rxl || ixr != rxr) { | 370 | | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | | if (code < 0) | 374 | | goto xit; | 375 | | rxl = ixl, rxr = ixr, ry = iy; | 376 | | } | 377 | | # endif | 378 | 26.8M | } | 379 | | # if !LINEAR_COLOR | 380 | | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | 1.66M | code = 0; | 383 | 1.66M | # endif | 384 | 1.66M | #undef STEP_LINE | 385 | 1.66M | #undef SET_MINIMAL_WIDTH | 386 | 1.66M | #undef CONNECT_RECTANGLES | 387 | 1.66M | #undef FILL_TRAP_RECT | 388 | 1.66M | #undef FILL_TRAP_RECT_DIRECT | 389 | 1.66M | #undef FILL_TRAP_RECT_INRECT | 390 | 1.66M | #undef YMULT_QUO | 391 | 1.66M | xit: if (code < 0 && FILL_DIRECT) | 392 | 5 | return_error(code); | 393 | 1.66M | return_if_interrupt(dev->memory); | 394 | 1.66M | return code; | 395 | 1.66M | } | 396 | 1.66M | } |
gdevddrw.c:gx_fill_trapezoid_ns_lc Line | Count | Source | 137 | 40.2M | { | 138 | 40.2M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 40.2M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 40.2M | if (ymin >= ymax) | 142 | 11.0M | return 0; /* no scan lines to sample */ | 143 | 29.1M | { | 144 | 29.1M | int iy = fixed2int_var(ymin); | 145 | 29.1M | const int iy1 = fixed2int_var(ymax); | 146 | 29.1M | trap_line l, r; | 147 | 29.1M | register int rxl, rxr; | 148 | | #if !LINEAR_COLOR | 149 | | int ry; | 150 | | #endif | 151 | 29.1M | const fixed | 152 | 29.1M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 29.1M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 29.1M | const fixed /* partial pixel offset to first line to sample */ | 155 | 29.1M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 29.1M | fixed fxl; | 157 | 29.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 | 29.1M | # if LINEAR_COLOR | 165 | 29.1M | int num_components = dev->color_info.num_components; | 166 | 29.1M | frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 167 | 29.1M | int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 168 | 29.1M | int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 169 | 29.1M | frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 170 | 29.1M | int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 171 | 29.1M | int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 172 | 29.1M | frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 173 | 29.1M | int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 174 | 29.1M | int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 175 | 29.1M | 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 | 29.1M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 29.1M | l.h = left->end.y - left->start.y; | 185 | 29.1M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 29.1M | r.h = right->end.y - right->start.y; | 188 | 29.1M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 29.1M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 29.1M | 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 | 29.1M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 29.1M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 29.1M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 29.1M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 29.1M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 29.1M | (*fill_rect)(dev, x, y, w, h, cindex)) | 208 | | | 209 | 29.1M | #if LINEAR_COLOR | 210 | 29.1M | # define FILL_TRAP_RECT(x,y,w,h)\ | 211 | 29.1M | (!(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 | 29.1M | #define YMULT_QUO(ys, tl)\ | 228 | 29.1M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 29.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 | 29.1M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 29.1M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 29.1M | #endif | 264 | 29.1M | 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 | 19.0M | } else { | 269 | 19.0M | compute_dx(&l, dxl, ysl); | 270 | 19.0M | fxl = YMULT_QUO(ysl, l); | 271 | 19.0M | l.x += fxl; | 272 | 19.0M | } | 273 | 29.1M | 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 | 10.1M | r.di = 0, r.df = 0; | 286 | 10.1M | } | 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 | 19.0M | else if (dxr == dxl && fxl != 0) { | 292 | 581k | if (l.di == 0) | 293 | 152k | r.di = 0, r.df = l.df; | 294 | 429k | else | 295 | 429k | compute_dx(&r, dxr, ysr); | 296 | 581k | if (ysr == ysl && r.h == l.h) | 297 | 390k | r.x += fxl; | 298 | 191k | else | 299 | 191k | 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 | 29.1M | compute_ldx(&l, ysl); | 306 | 29.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 | 29.1M | l.x += fixed_epsilon; | 310 | 29.1M | r.x += fixed_epsilon; | 311 | 29.1M | # 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 | 29.1M | lg.c = lgc; | 320 | 29.1M | lg.f = lgf; | 321 | 29.1M | lg.num = lgnum; | 322 | 29.1M | rg.c = rgc; | 323 | 29.1M | rg.f = rgf; | 324 | 29.1M | rg.num = rgnum; | 325 | 29.1M | xg.c = xgc; | 326 | 29.1M | xg.f = xgf; | 327 | 29.1M | xg.num = xgnum; | 328 | 29.1M | code = init_gradient(&lg, fa, left, right, &l, ymin, num_components); | 329 | 29.1M | if (code < 0) | 330 | 0 | return code; | 331 | 29.1M | code = init_gradient(&rg, fa, right, left, &r, ymin, num_components); | 332 | 29.1M | if (code < 0) | 333 | 0 | return code; | 334 | | | 335 | 29.1M | # endif | 336 | | | 337 | 29.1M | #define rational_floor(tl)\ | 338 | 29.1M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 29.1M | #define STEP_LINE(ix, tl)\ | 340 | 29.1M | tl.x += tl.ldi;\ | 341 | 29.1M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 29.1M | ix = rational_floor(tl) | 343 | | | 344 | 29.1M | rxl = rational_floor(l); | 345 | 29.1M | rxr = rational_floor(r); | 346 | 29.1M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 160M | while (LINEAR_COLOR ? 1 : ++iy != iy1) { | 348 | 160M | # if LINEAR_COLOR | 349 | 160M | if (rxl != rxr) { | 350 | 54.8M | code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components); | 351 | 54.8M | if (code < 0) | 352 | 0 | goto xit; | 353 | 54.8M | code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1); | 354 | 54.8M | if (code < 0) | 355 | 15 | goto xit; | 356 | 54.8M | } | 357 | 160M | if (++iy == iy1) | 358 | 29.1M | break; | 359 | 131M | STEP_LINE(rxl, l); | 360 | 131M | STEP_LINE(rxr, r); | 361 | 131M | step_gradient(&lg, num_components); | 362 | 131M | 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 | 131M | } | 379 | | # if !LINEAR_COLOR | 380 | | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | 29.1M | code = 0; | 383 | 29.1M | # endif | 384 | 29.1M | #undef STEP_LINE | 385 | 29.1M | #undef SET_MINIMAL_WIDTH | 386 | 29.1M | #undef CONNECT_RECTANGLES | 387 | 29.1M | #undef FILL_TRAP_RECT | 388 | 29.1M | #undef FILL_TRAP_RECT_DIRECT | 389 | 29.1M | #undef FILL_TRAP_RECT_INRECT | 390 | 29.1M | #undef YMULT_QUO | 391 | 29.1M | xit: if (code < 0 && FILL_DIRECT) | 392 | 15 | return_error(code); | 393 | 29.1M | return_if_interrupt(dev->memory); | 394 | 29.1M | return code; | 395 | 29.1M | } | 396 | 29.1M | } |
|