396 | 23.7M | } Unexecuted instantiation: gx_fill_trapezoid_cf_fd Unexecuted instantiation: gx_fill_trapezoid_cf_nd gdevddrw.c:gx_fill_trapezoid_as_fd Line | Count | Source | 137 | 1.35M | { | 138 | 1.35M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 1.35M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 1.35M | if (ymin >= ymax) | 142 | 64.5k | return 0; /* no scan lines to sample */ | 143 | 1.28M | { | 144 | 1.28M | int iy = fixed2int_var(ymin); | 145 | 1.28M | const int iy1 = fixed2int_var(ymax); | 146 | 1.28M | trap_line l, r; | 147 | 1.28M | register int rxl, rxr; | 148 | 1.28M | #if !LINEAR_COLOR | 149 | 1.28M | int ry; | 150 | 1.28M | #endif | 151 | 1.28M | const fixed | 152 | 1.28M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 1.28M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 1.28M | const fixed /* partial pixel offset to first line to sample */ | 155 | 1.28M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 1.28M | fixed fxl; | 157 | 1.28M | int code; | 158 | | # if CONTIGUOUS_FILL | 159 | | const bool peak0 = ((flags & 1) != 0); | 160 | | const bool peak1 = ((flags & 2) != 0); | 161 | | int peak_y0 = ybot + fixed_half; | 162 | | int peak_y1 = ytop - fixed_half; | 163 | | # endif | 164 | | # if LINEAR_COLOR | 165 | | int num_components = dev->color_info.num_components; | 166 | | frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 167 | | int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 168 | | int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 169 | | frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 170 | | int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 171 | | int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 172 | | frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 173 | | int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 174 | | int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 175 | | trap_gradient lg, rg, xg; | 176 | | # else | 177 | 1.28M | gx_color_index cindex = pdevc->colors.pure; | 178 | 1.28M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 1.28M | dev_proc(dev, fill_rectangle); | 180 | 1.28M | # endif | 181 | | | 182 | 1.28M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 1.28M | l.h = left->end.y - left->start.y; | 185 | 1.28M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 1.28M | r.h = right->end.y - right->start.y; | 188 | 1.28M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 1.28M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 1.28M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 1.28M | #if !LINEAR_COLOR | 193 | 1.28M | ry = iy; | 194 | 1.28M | #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.28M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 1.28M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 1.28M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 1.28M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 1.28M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 1.28M | (*fill_rect)(dev, x, y, w, h, cindex)) | 208 | | | 209 | | #if LINEAR_COLOR | 210 | | # define FILL_TRAP_RECT(x,y,w,h)\ | 211 | | (!(w) ? 0 : dev_proc(dev, fill_linear_color_scanline)(dev, fa, x, y, w, xg.c, xg.f, xg.num, xg.den)) | 212 | | #else | 213 | 1.28M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 1.28M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 1.28M | #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.28M | #define YMULT_QUO(ys, tl)\ | 228 | 1.28M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 1.28M | 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.28M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 1.28M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 1.28M | #endif | 264 | 1.28M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 601k | l.di = 0, l.df = 0; | 267 | 601k | fxl = 0; | 268 | 687k | } else { | 269 | 687k | compute_dx(&l, dxl, ysl); | 270 | 687k | fxl = YMULT_QUO(ysl, l); | 271 | 687k | l.x += fxl; | 272 | 687k | } | 273 | 1.28M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 496k | # if !LINEAR_COLOR | 277 | 496k | if (l.di == 0 && l.df == 0) { | 278 | 478k | rxl = fixed2int_var(l.x); | 279 | 478k | rxr = fixed2int_var(r.x); | 280 | 478k | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 478k | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 478k | goto xit; | 283 | 478k | } | 284 | 18.5k | # endif | 285 | 18.5k | r.di = 0, r.df = 0; | 286 | 18.5k | } | 287 | | /* | 288 | | * The test for fxl != 0 is required because the right edge might | 289 | | * cross some pixel centers even if the left edge doesn't. | 290 | | */ | 291 | 791k | else if (dxr == dxl && fxl != 0) { | 292 | 120k | if (l.di == 0) | 293 | 46.9k | r.di = 0, r.df = l.df; | 294 | 73.6k | else | 295 | 73.6k | compute_dx(&r, dxr, ysr); | 296 | 120k | if (ysr == ysl && r.h == l.h) | 297 | 120k | r.x += fxl; | 298 | 1 | else | 299 | 1 | r.x += YMULT_QUO(ysr, r); | 300 | 671k | } else { | 301 | 671k | compute_dx(&r, dxr, ysr); | 302 | 671k | r.x += YMULT_QUO(ysr, r); | 303 | 671k | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 810k | compute_ldx(&l, ysl); | 306 | 810k | compute_ldx(&r, ysr); | 307 | | /* We subtracted fixed_epsilon from l.x, r.x to simplify rounding | 308 | | when the rational part is zero. Now add it back to get xl', xr' */ | 309 | 810k | l.x += fixed_epsilon; | 310 | 810k | r.x += fixed_epsilon; | 311 | | # 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 | 810k | #define rational_floor(tl)\ | 338 | 810k | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 810k | #define STEP_LINE(ix, tl)\ | 340 | 810k | tl.x += tl.ldi;\ | 341 | 810k | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 810k | ix = rational_floor(tl) | 343 | | | 344 | 810k | rxl = rational_floor(l); | 345 | 810k | rxr = rational_floor(r); | 346 | 810k | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 92.0M | 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 | 91.2M | register int ixl, ixr; | 365 | | | 366 | 91.2M | STEP_LINE(ixl, l); | 367 | 91.2M | STEP_LINE(ixr, r); | 368 | 91.2M | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 91.2M | if (ixl != rxl || ixr != rxr) { | 370 | 4.71M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 4.71M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 4.71M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 4.71M | if (code < 0) | 374 | 0 | goto xit; | 375 | 4.71M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 4.71M | } | 377 | 91.2M | # endif | 378 | 91.2M | } | 379 | 810k | # if !LINEAR_COLOR | 380 | 810k | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 810k | #undef STEP_LINE | 385 | 810k | #undef SET_MINIMAL_WIDTH | 386 | 810k | #undef CONNECT_RECTANGLES | 387 | 810k | #undef FILL_TRAP_RECT | 388 | 810k | #undef FILL_TRAP_RECT_DIRECT | 389 | 810k | #undef FILL_TRAP_RECT_INRECT | 390 | 810k | #undef YMULT_QUO | 391 | 1.28M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 1.28M | return_if_interrupt(dev->memory); | 394 | 1.28M | return code; | 395 | 1.28M | } | 396 | 1.28M | } |
gdevddrw.c:gx_fill_trapezoid_as_nd Line | Count | Source | 137 | 599k | { | 138 | 599k | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 599k | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 599k | if (ymin >= ymax) | 142 | 4.79k | return 0; /* no scan lines to sample */ | 143 | 595k | { | 144 | 595k | int iy = fixed2int_var(ymin); | 145 | 595k | const int iy1 = fixed2int_var(ymax); | 146 | 595k | trap_line l, r; | 147 | 595k | register int rxl, rxr; | 148 | 595k | #if !LINEAR_COLOR | 149 | 595k | int ry; | 150 | 595k | #endif | 151 | 595k | const fixed | 152 | 595k | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 595k | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 595k | const fixed /* partial pixel offset to first line to sample */ | 155 | 595k | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 595k | fixed fxl; | 157 | 595k | 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 | 595k | gx_color_index cindex = pdevc->colors.pure; | 178 | 595k | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 595k | dev_proc(dev, fill_rectangle); | 180 | 595k | # endif | 181 | | | 182 | 595k | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 595k | l.h = left->end.y - left->start.y; | 185 | 595k | if (l.h == 0) | 186 | 0 | return 0; | 187 | 595k | r.h = right->end.y - right->start.y; | 188 | 595k | if (r.h == 0) | 189 | 0 | return 0; | 190 | 595k | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 595k | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 595k | #if !LINEAR_COLOR | 193 | 595k | ry = iy; | 194 | 595k | #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 | 595k | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 595k | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 595k | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 595k | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 595k | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 595k | (*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 | 595k | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 595k | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 595k | #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 | 595k | #define YMULT_QUO(ys, tl)\ | 228 | 595k | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 595k | 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 | 595k | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 595k | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 595k | #endif | 264 | 595k | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 160k | l.di = 0, l.df = 0; | 267 | 160k | fxl = 0; | 268 | 434k | } else { | 269 | 434k | compute_dx(&l, dxl, ysl); | 270 | 434k | fxl = YMULT_QUO(ysl, l); | 271 | 434k | l.x += fxl; | 272 | 434k | } | 273 | 595k | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 153k | # if !LINEAR_COLOR | 277 | 153k | if (l.di == 0 && l.df == 0) { | 278 | 150k | rxl = fixed2int_var(l.x); | 279 | 150k | rxr = fixed2int_var(r.x); | 280 | 150k | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 150k | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 150k | goto xit; | 283 | 150k | } | 284 | 3.19k | # endif | 285 | 3.19k | r.di = 0, r.df = 0; | 286 | 3.19k | } | 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 | 441k | else if (dxr == dxl && fxl != 0) { | 292 | 69.8k | if (l.di == 0) | 293 | 41.3k | r.di = 0, r.df = l.df; | 294 | 28.5k | else | 295 | 28.5k | compute_dx(&r, dxr, ysr); | 296 | 69.8k | if (ysr == ysl && r.h == l.h) | 297 | 69.7k | r.x += fxl; | 298 | 122 | else | 299 | 122 | r.x += YMULT_QUO(ysr, r); | 300 | 371k | } else { | 301 | 371k | compute_dx(&r, dxr, ysr); | 302 | 371k | r.x += YMULT_QUO(ysr, r); | 303 | 371k | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 444k | compute_ldx(&l, ysl); | 306 | 444k | 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 | 444k | l.x += fixed_epsilon; | 310 | 444k | 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 | 444k | #define rational_floor(tl)\ | 338 | 444k | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 444k | #define STEP_LINE(ix, tl)\ | 340 | 444k | tl.x += tl.ldi;\ | 341 | 444k | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 444k | ix = rational_floor(tl) | 343 | | | 344 | 444k | rxl = rational_floor(l); | 345 | 444k | rxr = rational_floor(r); | 346 | 444k | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 60.5M | 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 | 60.0M | register int ixl, ixr; | 365 | | | 366 | 60.0M | STEP_LINE(ixl, l); | 367 | 60.0M | STEP_LINE(ixr, r); | 368 | 60.0M | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 60.0M | if (ixl != rxl || ixr != rxr) { | 370 | 43.2M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 43.2M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 43.2M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 43.2M | if (code < 0) | 374 | 0 | goto xit; | 375 | 43.2M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 43.2M | } | 377 | 60.0M | # endif | 378 | 60.0M | } | 379 | 444k | # if !LINEAR_COLOR | 380 | 444k | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 444k | #undef STEP_LINE | 385 | 444k | #undef SET_MINIMAL_WIDTH | 386 | 444k | #undef CONNECT_RECTANGLES | 387 | 444k | #undef FILL_TRAP_RECT | 388 | 444k | #undef FILL_TRAP_RECT_DIRECT | 389 | 444k | #undef FILL_TRAP_RECT_INRECT | 390 | 444k | #undef YMULT_QUO | 391 | 595k | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 595k | return_if_interrupt(dev->memory); | 394 | 595k | return code; | 395 | 595k | } | 396 | 595k | } |
gdevddrw.c:gx_fill_trapezoid_ns_fd Line | Count | Source | 137 | 15.4M | { | 138 | 15.4M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 15.4M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 15.4M | if (ymin >= ymax) | 142 | 4.67M | return 0; /* no scan lines to sample */ | 143 | 10.7M | { | 144 | 10.7M | int iy = fixed2int_var(ymin); | 145 | 10.7M | const int iy1 = fixed2int_var(ymax); | 146 | 10.7M | trap_line l, r; | 147 | 10.7M | register int rxl, rxr; | 148 | 10.7M | #if !LINEAR_COLOR | 149 | 10.7M | int ry; | 150 | 10.7M | #endif | 151 | 10.7M | const fixed | 152 | 10.7M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 10.7M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 10.7M | const fixed /* partial pixel offset to first line to sample */ | 155 | 10.7M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 10.7M | fixed fxl; | 157 | 10.7M | int code; | 158 | | # if CONTIGUOUS_FILL | 159 | | const bool peak0 = ((flags & 1) != 0); | 160 | | const bool peak1 = ((flags & 2) != 0); | 161 | | int peak_y0 = ybot + fixed_half; | 162 | | int peak_y1 = ytop - fixed_half; | 163 | | # endif | 164 | | # 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 | 10.7M | gx_color_index cindex = pdevc->colors.pure; | 178 | 10.7M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 10.7M | dev_proc(dev, fill_rectangle); | 180 | 10.7M | # endif | 181 | | | 182 | 10.7M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 10.7M | l.h = left->end.y - left->start.y; | 185 | 10.7M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 10.7M | r.h = right->end.y - right->start.y; | 188 | 10.7M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 10.7M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 10.7M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 10.7M | #if !LINEAR_COLOR | 193 | 10.7M | ry = iy; | 194 | 10.7M | #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 | 10.7M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 10.7M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 10.7M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 10.7M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 10.7M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 10.7M | (*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 | 10.7M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 10.7M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 10.7M | #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 | 10.7M | #define YMULT_QUO(ys, tl)\ | 228 | 10.7M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 10.7M | fixed_mult_quo(ys, tl.df, tl.h)) | 230 | | | 231 | | #if CONTIGUOUS_FILL | 232 | | /* | 233 | | * If left and right boundary round to same pixel index, | 234 | | * we would not paing the scan and would get a dropout. | 235 | | * Check for this case and choose one of two pixels | 236 | | * which is closer to the "axis". We need to exclude | 237 | | * 'peak' because it would paint an excessive pixel. | 238 | | */ | 239 | | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \ | 240 | | if (ixl == ixr) \ | 241 | | if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\ | 242 | | fixed x = int2fixed(ixl) + fixed_half;\ | 243 | | if (x - l.x < r.x - x)\ | 244 | | ++ixr;\ | 245 | | else\ | 246 | | --ixl;\ | 247 | | } | 248 | | | 249 | | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\ | 250 | | if (adj1 < adj2) {\ | 251 | | if (iy - ry > 1) {\ | 252 | | code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\ | 253 | | if (code < 0)\ | 254 | | goto xit;\ | 255 | | ry = iy - 1;\ | 256 | | }\ | 257 | | adj1 = adj2 = (adj2 + adj2) / 2;\ | 258 | | } | 259 | | | 260 | | #else | 261 | 10.7M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 10.7M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 10.7M | #endif | 264 | 10.7M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 3.70M | l.di = 0, l.df = 0; | 267 | 3.70M | fxl = 0; | 268 | 7.09M | } else { | 269 | 7.09M | compute_dx(&l, dxl, ysl); | 270 | 7.09M | fxl = YMULT_QUO(ysl, l); | 271 | 7.09M | l.x += fxl; | 272 | 7.09M | } | 273 | 10.7M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 3.68M | # if !LINEAR_COLOR | 277 | 3.68M | if (l.di == 0 && l.df == 0) { | 278 | 2.41M | rxl = fixed2int_var(l.x); | 279 | 2.41M | rxr = fixed2int_var(r.x); | 280 | 2.41M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 2.41M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 2.41M | goto xit; | 283 | 2.41M | } | 284 | 1.26M | # endif | 285 | 1.26M | r.di = 0, r.df = 0; | 286 | 1.26M | } | 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 | 7.11M | else if (dxr == dxl && fxl != 0) { | 292 | 404k | if (l.di == 0) | 293 | 60.3k | r.di = 0, r.df = l.df; | 294 | 343k | else | 295 | 343k | compute_dx(&r, dxr, ysr); | 296 | 404k | if (ysr == ysl && r.h == l.h) | 297 | 213k | r.x += fxl; | 298 | 190k | else | 299 | 190k | r.x += YMULT_QUO(ysr, r); | 300 | 6.70M | } else { | 301 | 6.70M | compute_dx(&r, dxr, ysr); | 302 | 6.70M | r.x += YMULT_QUO(ysr, r); | 303 | 6.70M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 8.37M | compute_ldx(&l, ysl); | 306 | 8.37M | 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 | 8.37M | l.x += fixed_epsilon; | 310 | 8.37M | 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 | 8.37M | #define rational_floor(tl)\ | 338 | 8.37M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 8.37M | #define STEP_LINE(ix, tl)\ | 340 | 8.37M | tl.x += tl.ldi;\ | 341 | 8.37M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 8.37M | ix = rational_floor(tl) | 343 | | | 344 | 8.37M | rxl = rational_floor(l); | 345 | 8.37M | rxr = rational_floor(r); | 346 | 8.37M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 481M | 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 | 473M | register int ixl, ixr; | 365 | | | 366 | 473M | STEP_LINE(ixl, l); | 367 | 473M | STEP_LINE(ixr, r); | 368 | 473M | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 473M | if (ixl != rxl || ixr != rxr) { | 370 | 17.0M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 17.0M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 17.0M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 17.0M | if (code < 0) | 374 | 0 | goto xit; | 375 | 17.0M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 17.0M | } | 377 | 473M | # endif | 378 | 473M | } | 379 | 8.37M | # if !LINEAR_COLOR | 380 | 8.37M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 8.37M | #undef STEP_LINE | 385 | 8.37M | #undef SET_MINIMAL_WIDTH | 386 | 8.37M | #undef CONNECT_RECTANGLES | 387 | 8.37M | #undef FILL_TRAP_RECT | 388 | 8.37M | #undef FILL_TRAP_RECT_DIRECT | 389 | 8.37M | #undef FILL_TRAP_RECT_INRECT | 390 | 8.37M | #undef YMULT_QUO | 391 | 10.7M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 10.7M | return_if_interrupt(dev->memory); | 394 | 10.7M | return code; | 395 | 10.7M | } | 396 | 10.7M | } |
gdevddrw.c:gx_fill_trapezoid_ns_nd Line | Count | Source | 137 | 14.9M | { | 138 | 14.9M | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 14.9M | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 14.9M | if (ymin >= ymax) | 142 | 3.87M | return 0; /* no scan lines to sample */ | 143 | 11.0M | { | 144 | 11.0M | int iy = fixed2int_var(ymin); | 145 | 11.0M | const int iy1 = fixed2int_var(ymax); | 146 | 11.0M | trap_line l, r; | 147 | 11.0M | register int rxl, rxr; | 148 | 11.0M | #if !LINEAR_COLOR | 149 | 11.0M | int ry; | 150 | 11.0M | #endif | 151 | 11.0M | const fixed | 152 | 11.0M | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 11.0M | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 11.0M | const fixed /* partial pixel offset to first line to sample */ | 155 | 11.0M | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 11.0M | fixed fxl; | 157 | 11.0M | 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 | 11.0M | gx_color_index cindex = pdevc->colors.pure; | 178 | 11.0M | dev_proc_fill_rectangle((*fill_rect)) = | 179 | 11.0M | dev_proc(dev, fill_rectangle); | 180 | 11.0M | # endif | 181 | | | 182 | 11.0M | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 11.0M | l.h = left->end.y - left->start.y; | 185 | 11.0M | if (l.h == 0) | 186 | 0 | return 0; | 187 | 11.0M | r.h = right->end.y - right->start.y; | 188 | 11.0M | if (r.h == 0) | 189 | 0 | return 0; | 190 | 11.0M | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 11.0M | r.x = x0r + (fixed_half - fixed_epsilon); | 192 | 11.0M | #if !LINEAR_COLOR | 193 | 11.0M | ry = iy; | 194 | 11.0M | #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 | 11.0M | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 11.0M | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 11.0M | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 11.0M | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 11.0M | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 11.0M | (*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 | 11.0M | # define FILL_TRAP_RECT(x,y,w,h)\ | 214 | 11.0M | (FILL_DIRECT ? FILL_TRAP_RECT_DIRECT(x,y,w,h) : FILL_TRAP_RECT_INDIRECT(x,y,w,h)) | 215 | 11.0M | #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 | 11.0M | #define YMULT_QUO(ys, tl)\ | 228 | 11.0M | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 11.0M | 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 | 11.0M | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 11.0M | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 11.0M | #endif | 264 | 11.0M | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 1.92M | l.di = 0, l.df = 0; | 267 | 1.92M | fxl = 0; | 268 | 9.10M | } else { | 269 | 9.10M | compute_dx(&l, dxl, ysl); | 270 | 9.10M | fxl = YMULT_QUO(ysl, l); | 271 | 9.10M | l.x += fxl; | 272 | 9.10M | } | 273 | 11.0M | if (fixed_floor(r.x) == fixed_pixround(x1r)) { | 274 | | /* Right edge is vertical. If both are vertical, */ | 275 | | /* we have a rectangle. */ | 276 | 2.71M | # if !LINEAR_COLOR | 277 | 2.71M | if (l.di == 0 && l.df == 0) { | 278 | 886k | rxl = fixed2int_var(l.x); | 279 | 886k | rxr = fixed2int_var(r.x); | 280 | 886k | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 281 | 886k | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy1 - ry); | 282 | 886k | goto xit; | 283 | 886k | } | 284 | 1.82M | # endif | 285 | 1.82M | r.di = 0, r.df = 0; | 286 | 1.82M | } | 287 | | /* | 288 | | * The test for fxl != 0 is required because the right edge might | 289 | | * cross some pixel centers even if the left edge doesn't. | 290 | | */ | 291 | 8.30M | else if (dxr == dxl && fxl != 0) { | 292 | 778k | if (l.di == 0) | 293 | 58.0k | r.di = 0, r.df = l.df; | 294 | 720k | else | 295 | 720k | compute_dx(&r, dxr, ysr); | 296 | 778k | if (ysr == ysl && r.h == l.h) | 297 | 449k | r.x += fxl; | 298 | 328k | else | 299 | 328k | r.x += YMULT_QUO(ysr, r); | 300 | 7.52M | } else { | 301 | 7.52M | compute_dx(&r, dxr, ysr); | 302 | 7.52M | r.x += YMULT_QUO(ysr, r); | 303 | 7.52M | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 10.1M | compute_ldx(&l, ysl); | 306 | 10.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 | 10.1M | l.x += fixed_epsilon; | 310 | 10.1M | r.x += fixed_epsilon; | 311 | | # if LINEAR_COLOR | 312 | | # ifdef DEBUG | 313 | | if (check_gradient_overflow(left, right)) { | 314 | | /* The caller must care of. | 315 | | Checking it here looses some performance with triangles. */ | 316 | | return_error(gs_error_unregistered); | 317 | | } | 318 | | # endif | 319 | | lg.c = lgc; | 320 | | lg.f = lgf; | 321 | | lg.num = lgnum; | 322 | | rg.c = rgc; | 323 | | rg.f = rgf; | 324 | | rg.num = rgnum; | 325 | | xg.c = xgc; | 326 | | xg.f = xgf; | 327 | | xg.num = xgnum; | 328 | | code = init_gradient(&lg, fa, left, right, &l, ymin, num_components); | 329 | | if (code < 0) | 330 | | return code; | 331 | | code = init_gradient(&rg, fa, right, left, &r, ymin, num_components); | 332 | | if (code < 0) | 333 | | return code; | 334 | | | 335 | | # endif | 336 | | | 337 | 10.1M | #define rational_floor(tl)\ | 338 | 10.1M | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 10.1M | #define STEP_LINE(ix, tl)\ | 340 | 10.1M | tl.x += tl.ldi;\ | 341 | 10.1M | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 10.1M | ix = rational_floor(tl) | 343 | | | 344 | 10.1M | rxl = rational_floor(l); | 345 | 10.1M | rxr = rational_floor(r); | 346 | 10.1M | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 475M | 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 | 465M | register int ixl, ixr; | 365 | | | 366 | 465M | STEP_LINE(ixl, l); | 367 | 465M | STEP_LINE(ixr, r); | 368 | 465M | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | 465M | if (ixl != rxl || ixr != rxr) { | 370 | 201M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | 201M | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | 201M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | 201M | if (code < 0) | 374 | 0 | goto xit; | 375 | 201M | rxl = ixl, rxr = ixr, ry = iy; | 376 | 201M | } | 377 | 465M | # endif | 378 | 465M | } | 379 | 10.1M | # if !LINEAR_COLOR | 380 | 10.1M | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | | code = 0; | 383 | | # endif | 384 | 10.1M | #undef STEP_LINE | 385 | 10.1M | #undef SET_MINIMAL_WIDTH | 386 | 10.1M | #undef CONNECT_RECTANGLES | 387 | 10.1M | #undef FILL_TRAP_RECT | 388 | 10.1M | #undef FILL_TRAP_RECT_DIRECT | 389 | 10.1M | #undef FILL_TRAP_RECT_INRECT | 390 | 10.1M | #undef YMULT_QUO | 391 | 11.0M | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 11.0M | return_if_interrupt(dev->memory); | 394 | 11.0M | return code; | 395 | 11.0M | } | 396 | 11.0M | } |
gdevddrw.c:gx_fill_trapezoid_as_lc Line | Count | Source | 137 | 1.08k | { | 138 | 1.08k | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 1.08k | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 1.08k | if (ymin >= ymax) | 142 | 16 | return 0; /* no scan lines to sample */ | 143 | 1.06k | { | 144 | 1.06k | int iy = fixed2int_var(ymin); | 145 | 1.06k | const int iy1 = fixed2int_var(ymax); | 146 | 1.06k | trap_line l, r; | 147 | 1.06k | register int rxl, rxr; | 148 | | #if !LINEAR_COLOR | 149 | | int ry; | 150 | | #endif | 151 | 1.06k | const fixed | 152 | 1.06k | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 1.06k | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 1.06k | const fixed /* partial pixel offset to first line to sample */ | 155 | 1.06k | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 1.06k | fixed fxl; | 157 | 1.06k | 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.06k | # if LINEAR_COLOR | 165 | 1.06k | int num_components = dev->color_info.num_components; | 166 | 1.06k | frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 167 | 1.06k | int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 168 | 1.06k | int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 169 | 1.06k | frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 170 | 1.06k | int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 171 | 1.06k | int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 172 | 1.06k | frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 173 | 1.06k | int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 174 | 1.06k | int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 175 | 1.06k | 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.06k | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 1.06k | l.h = left->end.y - left->start.y; | 185 | 1.06k | if (l.h == 0) | 186 | 0 | return 0; | 187 | 1.06k | r.h = right->end.y - right->start.y; | 188 | 1.06k | if (r.h == 0) | 189 | 0 | return 0; | 190 | 1.06k | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 1.06k | 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.06k | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 1.06k | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 1.06k | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 1.06k | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 1.06k | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 1.06k | (*fill_rect)(dev, x, y, w, h, cindex)) | 208 | | | 209 | 1.06k | #if LINEAR_COLOR | 210 | 1.06k | # define FILL_TRAP_RECT(x,y,w,h)\ | 211 | 1.06k | (!(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.06k | #define YMULT_QUO(ys, tl)\ | 228 | 1.06k | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 1.06k | 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.06k | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 1.06k | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 1.06k | #endif | 264 | 1.06k | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 66 | l.di = 0, l.df = 0; | 267 | 66 | fxl = 0; | 268 | 1.00k | } else { | 269 | 1.00k | compute_dx(&l, dxl, ysl); | 270 | 1.00k | fxl = YMULT_QUO(ysl, l); | 271 | 1.00k | l.x += fxl; | 272 | 1.00k | } | 273 | 1.06k | 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 | 84 | r.di = 0, r.df = 0; | 286 | 84 | } | 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 | 984 | else if (dxr == dxl && fxl != 0) { | 292 | 633 | if (l.di == 0) | 293 | 286 | r.di = 0, r.df = l.df; | 294 | 347 | else | 295 | 347 | compute_dx(&r, dxr, ysr); | 296 | 633 | if (ysr == ysl && r.h == l.h) | 297 | 633 | r.x += fxl; | 298 | 0 | else | 299 | 0 | r.x += YMULT_QUO(ysr, r); | 300 | 633 | } else { | 301 | 351 | compute_dx(&r, dxr, ysr); | 302 | 351 | r.x += YMULT_QUO(ysr, r); | 303 | 351 | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 1.06k | compute_ldx(&l, ysl); | 306 | 1.06k | 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.06k | l.x += fixed_epsilon; | 310 | 1.06k | r.x += fixed_epsilon; | 311 | 1.06k | # 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.06k | lg.c = lgc; | 320 | 1.06k | lg.f = lgf; | 321 | 1.06k | lg.num = lgnum; | 322 | 1.06k | rg.c = rgc; | 323 | 1.06k | rg.f = rgf; | 324 | 1.06k | rg.num = rgnum; | 325 | 1.06k | xg.c = xgc; | 326 | 1.06k | xg.f = xgf; | 327 | 1.06k | xg.num = xgnum; | 328 | 1.06k | code = init_gradient(&lg, fa, left, right, &l, ymin, num_components); | 329 | 1.06k | if (code < 0) | 330 | 0 | return code; | 331 | 1.06k | code = init_gradient(&rg, fa, right, left, &r, ymin, num_components); | 332 | 1.06k | if (code < 0) | 333 | 0 | return code; | 334 | | | 335 | 1.06k | # endif | 336 | | | 337 | 1.06k | #define rational_floor(tl)\ | 338 | 1.06k | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 1.06k | #define STEP_LINE(ix, tl)\ | 340 | 1.06k | tl.x += tl.ldi;\ | 341 | 1.06k | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 1.06k | ix = rational_floor(tl) | 343 | | | 344 | 1.06k | rxl = rational_floor(l); | 345 | 1.06k | rxr = rational_floor(r); | 346 | 1.06k | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 36.5k | while (LINEAR_COLOR ? 1 : ++iy != iy1) { | 348 | 36.5k | # if LINEAR_COLOR | 349 | 36.5k | if (rxl != rxr) { | 350 | 33.0k | code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components); | 351 | 33.0k | if (code < 0) | 352 | 0 | goto xit; | 353 | 33.0k | code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1); | 354 | 33.0k | if (code < 0) | 355 | 0 | goto xit; | 356 | 33.0k | } | 357 | 36.5k | if (++iy == iy1) | 358 | 1.06k | break; | 359 | 35.4k | STEP_LINE(rxl, l); | 360 | 35.4k | STEP_LINE(rxr, r); | 361 | 35.4k | step_gradient(&lg, num_components); | 362 | 35.4k | step_gradient(&rg, num_components); | 363 | | # else | 364 | | register int ixl, ixr; | 365 | | | 366 | | STEP_LINE(ixl, l); | 367 | | STEP_LINE(ixr, r); | 368 | | SET_MINIMAL_WIDTH(ixl, ixr, l, r); | 369 | | if (ixl != rxl || ixr != rxr) { | 370 | | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, rxr, ixl, FILL_TRAP_RECT); | 371 | | CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, ixr, rxl, FILL_TRAP_RECT); | 372 | | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 373 | | if (code < 0) | 374 | | goto xit; | 375 | | rxl = ixl, rxr = ixr, ry = iy; | 376 | | } | 377 | | # endif | 378 | 35.4k | } | 379 | | # if !LINEAR_COLOR | 380 | | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | 1.06k | code = 0; | 383 | 1.06k | # endif | 384 | 1.06k | #undef STEP_LINE | 385 | 1.06k | #undef SET_MINIMAL_WIDTH | 386 | 1.06k | #undef CONNECT_RECTANGLES | 387 | 1.06k | #undef FILL_TRAP_RECT | 388 | 1.06k | #undef FILL_TRAP_RECT_DIRECT | 389 | 1.06k | #undef FILL_TRAP_RECT_INRECT | 390 | 1.06k | #undef YMULT_QUO | 391 | 1.06k | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 1.06k | return_if_interrupt(dev->memory); | 394 | 1.06k | return code; | 395 | 1.06k | } | 396 | 1.06k | } |
gdevddrw.c:gx_fill_trapezoid_ns_lc Line | Count | Source | 137 | 3.20k | { | 138 | 3.20k | const fixed ymin = fixed_pixround(ybot) + fixed_half; | 139 | 3.20k | const fixed ymax = fixed_pixround(ytop); | 140 | | | 141 | 3.20k | if (ymin >= ymax) | 142 | 66 | return 0; /* no scan lines to sample */ | 143 | 3.13k | { | 144 | 3.13k | int iy = fixed2int_var(ymin); | 145 | 3.13k | const int iy1 = fixed2int_var(ymax); | 146 | 3.13k | trap_line l, r; | 147 | 3.13k | register int rxl, rxr; | 148 | | #if !LINEAR_COLOR | 149 | | int ry; | 150 | | #endif | 151 | 3.13k | const fixed | 152 | 3.13k | x0l = left->start.x, x1l = left->end.x, x0r = right->start.x, | 153 | 3.13k | x1r = right->end.x, dxl = x1l - x0l, dxr = x1r - x0r; | 154 | 3.13k | const fixed /* partial pixel offset to first line to sample */ | 155 | 3.13k | ysl = ymin - left->start.y, ysr = ymin - right->start.y; | 156 | 3.13k | fixed fxl; | 157 | 3.13k | 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 | 3.13k | # if LINEAR_COLOR | 165 | 3.13k | int num_components = dev->color_info.num_components; | 166 | 3.13k | frac31 lgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 167 | 3.13k | int32_t lgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 168 | 3.13k | int32_t lgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 169 | 3.13k | frac31 rgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 170 | 3.13k | int32_t rgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 171 | 3.13k | int32_t rgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 172 | 3.13k | frac31 xgc[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 173 | 3.13k | int32_t xgf[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 174 | 3.13k | int32_t xgnum[GX_DEVICE_COLOR_MAX_COMPONENTS]; | 175 | 3.13k | 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 | 3.13k | if_debug2m('z', dev->memory, "[z]y=[%d,%d]\n", iy, iy1); | 183 | | | 184 | 3.13k | l.h = left->end.y - left->start.y; | 185 | 3.13k | if (l.h == 0) | 186 | 0 | return 0; | 187 | 3.13k | r.h = right->end.y - right->start.y; | 188 | 3.13k | if (r.h == 0) | 189 | 0 | return 0; | 190 | 3.13k | l.x = x0l + (fixed_half - fixed_epsilon); | 191 | 3.13k | 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 | 3.13k | #define FILL_TRAP_RECT_INDIRECT(x,y,w,h)\ | 203 | 3.13k | (SWAP_AXES ? gx_fill_rectangle_device_rop(y, x, h, w, pdevc, dev, fa) :\ | 204 | 3.13k | gx_fill_rectangle_device_rop(x, y, w, h, pdevc, dev, fa)) | 205 | 3.13k | #define FILL_TRAP_RECT_DIRECT(x,y,w,h)\ | 206 | 3.13k | (SWAP_AXES ? (*fill_rect)(dev, y, x, h, w, cindex) :\ | 207 | 3.13k | (*fill_rect)(dev, x, y, w, h, cindex)) | 208 | | | 209 | 3.13k | #if LINEAR_COLOR | 210 | 3.13k | # define FILL_TRAP_RECT(x,y,w,h)\ | 211 | 3.13k | (!(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 | 3.13k | #define YMULT_QUO(ys, tl)\ | 228 | 3.13k | (ys < fixed_1 && tl.df < YMULT_LIMIT ? ys * tl.df / tl.h :\ | 229 | 3.13k | fixed_mult_quo(ys, tl.df, tl.h)) | 230 | | | 231 | | #if CONTIGUOUS_FILL | 232 | | /* | 233 | | * If left and right boundary round to same pixel index, | 234 | | * we would not paing the scan and would get a dropout. | 235 | | * Check for this case and choose one of two pixels | 236 | | * which is closer to the "axis". We need to exclude | 237 | | * 'peak' because it would paint an excessive pixel. | 238 | | */ | 239 | | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) \ | 240 | | if (ixl == ixr) \ | 241 | | if ((!peak0 || iy >= peak_y0) && (!peak1 || iy <= peak_y1)) {\ | 242 | | fixed x = int2fixed(ixl) + fixed_half;\ | 243 | | if (x - l.x < r.x - x)\ | 244 | | ++ixr;\ | 245 | | else\ | 246 | | --ixl;\ | 247 | | } | 248 | | | 249 | | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill)\ | 250 | | if (adj1 < adj2) {\ | 251 | | if (iy - ry > 1) {\ | 252 | | code = fill(rxl, ry, rxr - rxl, iy - ry - 1);\ | 253 | | if (code < 0)\ | 254 | | goto xit;\ | 255 | | ry = iy - 1;\ | 256 | | }\ | 257 | | adj1 = adj2 = (adj2 + adj2) / 2;\ | 258 | | } | 259 | | | 260 | | #else | 261 | 3.13k | #define SET_MINIMAL_WIDTH(ixl, ixr, l, r) DO_NOTHING | 262 | 3.13k | #define CONNECT_RECTANGLES(ixl, ixr, rxl, rxr, iy, ry, adj1, adj2, fill) DO_NOTHING | 263 | 3.13k | #endif | 264 | 3.13k | if (fixed_floor(l.x) == fixed_pixround(x1l)) { | 265 | | /* Left edge is vertical, we don't need to increment. */ | 266 | 125 | l.di = 0, l.df = 0; | 267 | 125 | fxl = 0; | 268 | 3.01k | } else { | 269 | 3.01k | compute_dx(&l, dxl, ysl); | 270 | 3.01k | fxl = YMULT_QUO(ysl, l); | 271 | 3.01k | l.x += fxl; | 272 | 3.01k | } | 273 | 3.13k | 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 | 122 | r.di = 0, r.df = 0; | 286 | 122 | } | 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.01k | else if (dxr == dxl && fxl != 0) { | 292 | 822 | if (l.di == 0) | 293 | 337 | r.di = 0, r.df = l.df; | 294 | 485 | else | 295 | 485 | compute_dx(&r, dxr, ysr); | 296 | 822 | if (ysr == ysl && r.h == l.h) | 297 | 822 | r.x += fxl; | 298 | 0 | else | 299 | 0 | r.x += YMULT_QUO(ysr, r); | 300 | 2.19k | } else { | 301 | 2.19k | compute_dx(&r, dxr, ysr); | 302 | 2.19k | r.x += YMULT_QUO(ysr, r); | 303 | 2.19k | } | 304 | | /* Compute one line's worth of dx/dy. */ | 305 | 3.13k | compute_ldx(&l, ysl); | 306 | 3.13k | 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.13k | l.x += fixed_epsilon; | 310 | 3.13k | r.x += fixed_epsilon; | 311 | 3.13k | # 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 | 3.13k | lg.c = lgc; | 320 | 3.13k | lg.f = lgf; | 321 | 3.13k | lg.num = lgnum; | 322 | 3.13k | rg.c = rgc; | 323 | 3.13k | rg.f = rgf; | 324 | 3.13k | rg.num = rgnum; | 325 | 3.13k | xg.c = xgc; | 326 | 3.13k | xg.f = xgf; | 327 | 3.13k | xg.num = xgnum; | 328 | 3.13k | code = init_gradient(&lg, fa, left, right, &l, ymin, num_components); | 329 | 3.13k | if (code < 0) | 330 | 0 | return code; | 331 | 3.13k | code = init_gradient(&rg, fa, right, left, &r, ymin, num_components); | 332 | 3.13k | if (code < 0) | 333 | 0 | return code; | 334 | | | 335 | 3.13k | # endif | 336 | | | 337 | 3.13k | #define rational_floor(tl)\ | 338 | 3.13k | fixed2int_var(fixed_is_int(tl.x) && tl.xf == -tl.h ? tl.x - fixed_1 : tl.x) | 339 | 3.13k | #define STEP_LINE(ix, tl)\ | 340 | 3.13k | tl.x += tl.ldi;\ | 341 | 3.13k | if ( (tl.xf += tl.ldf) >= 0 ) tl.xf -= tl.h, tl.x++;\ | 342 | 3.13k | ix = rational_floor(tl) | 343 | | | 344 | 3.13k | rxl = rational_floor(l); | 345 | 3.13k | rxr = rational_floor(r); | 346 | 3.13k | SET_MINIMAL_WIDTH(rxl, rxr, l, r); | 347 | 244k | while (LINEAR_COLOR ? 1 : ++iy != iy1) { | 348 | 244k | # if LINEAR_COLOR | 349 | 244k | if (rxl != rxr) { | 350 | 203k | code = set_x_gradient(&xg, &lg, &rg, &l, &r, rxl, rxr, num_components); | 351 | 203k | if (code < 0) | 352 | 0 | goto xit; | 353 | 203k | code = FILL_TRAP_RECT(rxl, iy, rxr - rxl, 1); | 354 | 203k | if (code < 0) | 355 | 0 | goto xit; | 356 | 203k | } | 357 | 244k | if (++iy == iy1) | 358 | 3.13k | break; | 359 | 241k | STEP_LINE(rxl, l); | 360 | 241k | STEP_LINE(rxr, r); | 361 | 241k | step_gradient(&lg, num_components); | 362 | 241k | 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 | 241k | } | 379 | | # if !LINEAR_COLOR | 380 | | code = FILL_TRAP_RECT(rxl, ry, rxr - rxl, iy - ry); | 381 | | # else | 382 | 3.13k | code = 0; | 383 | 3.13k | # endif | 384 | 3.13k | #undef STEP_LINE | 385 | 3.13k | #undef SET_MINIMAL_WIDTH | 386 | 3.13k | #undef CONNECT_RECTANGLES | 387 | 3.13k | #undef FILL_TRAP_RECT | 388 | 3.13k | #undef FILL_TRAP_RECT_DIRECT | 389 | 3.13k | #undef FILL_TRAP_RECT_INRECT | 390 | 3.13k | #undef YMULT_QUO | 391 | 3.13k | xit: if (code < 0 && FILL_DIRECT) | 392 | 0 | return_error(code); | 393 | 3.13k | return_if_interrupt(dev->memory); | 394 | 3.13k | return code; | 395 | 3.13k | } | 396 | 3.13k | } |
|