floodfill: * Fills an enclosed area (starting at point x, y) with the specified color. */
| 340 | * Fills an enclosed area (starting at point x, y) with the specified color. |
| 341 | */ |
| 342 | void floodfill(const Image* image, |
| 343 | const Mask* mask, |
| 344 | int x, int y, |
| 345 | const gfx::Rect& bounds, |
| 346 | int tolerance, bool contiguous, |
| 347 | void* data, |
| 348 | AlgoHLine proc) |
| 349 | { |
| 350 | // Make sure we have a valid starting point |
| 351 | if ((x < 0) || (x >= image->width()) || |
| 352 | (y < 0) || (y >= image->height())) |
| 353 | return; |
| 354 | |
| 355 | // What color to replace? |
| 356 | color_t src_color = get_pixel(image, x, y); |
| 357 | |
| 358 | // Non-contiguous case, we replace colors in the whole image. |
| 359 | if (!contiguous) { |
| 360 | switch (image->pixelFormat()) { |
| 361 | case IMAGE_RGB: |
| 362 | replace_color<RgbTraits>(image, bounds, src_color, tolerance, data, proc); |
| 363 | break; |
| 364 | case IMAGE_GRAYSCALE: |
| 365 | replace_color<GrayscaleTraits>(image, bounds, src_color, tolerance, data, proc); |
| 366 | break; |
| 367 | case IMAGE_INDEXED: |
| 368 | replace_color<IndexedTraits>(image, bounds, src_color, tolerance, data, proc); |
| 369 | break; |
| 370 | } |
| 371 | return; |
| 372 | } |
| 373 | |
| 374 | /* set up the list of flooded segments */ |
| 375 | flood_buf.resize(image->height()); |
| 376 | flood_count = image->height(); |
| 377 | FLOODED_LINE* p = (FLOODED_LINE*)&flood_buf[0]; |
| 378 | for (int c=0; c<flood_count; c++) { |
| 379 | p[c].flags = 0; |
| 380 | p[c].lpos = SHRT_MAX; |
| 381 | p[c].rpos = SHRT_MIN; |
| 382 | p[c].y = y; |
| 383 | p[c].next = 0; |
| 384 | } |
| 385 | |
| 386 | // Start up the flood algorithm |
| 387 | flooder(image, mask, x, y, bounds, src_color, tolerance, data, proc); |
| 388 | |
| 389 | // Continue as long as there are some segments still to test |
| 390 | bool done; |
| 391 | do { |
| 392 | done = true; |
| 393 | |
| 394 | // For each line on the screen |
| 395 | for (int c=0; c<flood_count; c++) { |
| 396 | |
| 397 | p = FLOOD_LINE(c); |
| 398 | |
| 399 | // Check below the segment? |
no test coverage detected