MCPcopy Create free account
hub / github.com/LibreSprite/LibreSprite / floodfill

Function floodfill

src/doc/algorithm/floodfill.cpp:342–422  ·  view source on GitHub ↗

floodfill: * Fills an enclosed area (starting at point x, y) with the specified color. */

Source from the content-addressed store, hash-verified

340 * Fills an enclosed area (starting at point x, y) with the specified color.
341 */
342void 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?

Callers 1

transformPointMethod · 0.85

Calls 8

get_pixelFunction · 0.85
flooderFunction · 0.85
check_flood_lineFunction · 0.85
y2Method · 0.80
widthMethod · 0.45
heightMethod · 0.45
pixelFormatMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected