From 8a9ab2515168ab8dbabd5dd86d82097774e0f924 Mon Sep 17 00:00:00 2001 From: Bill Kendrick Date: Fri, 19 Nov 2021 14:06:28 -0800 Subject: [PATCH 1/3] Updated Icelandic translation h/t Sveinn --- src/po/is.po | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/po/is.po b/src/po/is.po index 5c2338d39..b2bf74c5c 100644 --- a/src/po/is.po +++ b/src/po/is.po @@ -10,7 +10,7 @@ msgstr "" "Project-Id-Version: tuxpaint\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-11-07 20:32-0800\n" -"PO-Revision-Date: 2021-10-28 08:50+0000\n" +"PO-Revision-Date: 2021-11-19 08:50+0000\n" "Last-Translator: Sveinn í Felli \n" "Language-Team: Icelandic\n" "Language: is\n" @@ -1180,7 +1180,6 @@ msgid "Lightning" msgstr "Elding" #: ../../magic/src/lightning.c:88 -#, fuzzy #| msgid "Click, drag, and release to a lightning bolt between two points." msgid "Click, drag, and release to draw a lightning bolt between two points." msgstr "" @@ -1415,16 +1414,13 @@ msgstr "" #: ../../magic/src/reflection.c:110 msgid "Reflection" -msgstr "" +msgstr "Endurkast" #: ../../magic/src/reflection.c:120 -#, fuzzy #| msgid "" #| "Click and drag the mouse to add a mosaic effect to parts of your picture." msgid "Click and drag the mouse around to add a reflection to your picture." -msgstr "" -"Smelltu og dragðu músina til að bæta við tígulsteina-áhrifum á hluta " -"myndarinnar." +msgstr "Smelltu og dragðu músina til að bæta speglun í myndina." #: ../../magic/src/ripples.c:103 msgid "Ripples" From e06ead84c500c1803ee73f81d7d788597de4df79 Mon Sep 17 00:00:00 2001 From: Bill Kendrick Date: Sat, 20 Nov 2021 00:14:18 -0800 Subject: [PATCH 2/3] WIP More work on queue-based flood Fill --- src/fill.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/fill.c b/src/fill.c index 7db89ae9d..c9be1c271 100644 --- a/src/fill.c +++ b/src/fill.c @@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA (See COPYING.txt) - Last updated: November 17, 2021 + Last updated: November 20, 2021 $Id$ */ @@ -92,6 +92,7 @@ void add_to_queue(int x1, int x2, int y, int yd); int remove_from_queue(int * x1, int * x2, int * y, int * yd); void cleanup_queue(void); void track_extents_and_progbar(int x, int y, int * extent_x1, int * extent_y1, int * extent_x2, int * extent_y2, SDL_Surface * screen, SDL_Surface * canvas); +double Inside(SDL_Surface * last, SDL_Surface * canvas, Uint32 old_colr, int x, int y, int * outside, double * in_line, Uint32 * px_colr); #endif #ifdef USE_QUEUE @@ -242,9 +243,24 @@ Uint32 blend(SDL_Surface * canvas, Uint32 draw_colr, Uint32 old_colr, double pct return SDL_MapRGB(canvas->format, new_r, new_g, new_b); } +#ifdef USE_QUEUE +double Inside(SDL_Surface * last, SDL_Surface * canvas, Uint32 old_colr, int x, int y, int * outside, double * in_line, Uint32 * px_colr) { + *px_colr = getpixels[last->format->BytesPerPixel] (last, x, y); + *in_line = colors_close(canvas, *px_colr, old_colr); + + if (*in_line < COLOR_MATCH_WIDE && *outside < WIDE_MATCH_THRESHOLD) { + *outside = (*outside + 1); + return(1); + } + return(0); +} +#endif + void simulate_flood_fill(SDL_Surface * screen, SDL_Surface * last, SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr, int * extent_x1, int * extent_y1, int * extent_x2, int * extent_y2, Uint8 * touched) { #ifdef USE_QUEUE - int x1, x2, dy; + int x1, x2, dy, outside; + double in_line; + Uint32 px_colr; /* "Same" color? No need to fill */ if (!would_flood_fill(canvas, cur_colr, old_colr)) @@ -266,13 +282,15 @@ void simulate_flood_fill(SDL_Surface * screen, SDL_Surface * last, SDL_Surface * /* Do the work (possibly queuing more, as we go) */ while (remove_from_queue(&x1, &x2, &y, &dy)) { + printf("From queue: (%d -> %d, %d) %d\n", x1, x2, y, dy); x = x1; - if (Inside(x, y)) + outside = 0; + if (Inside(last, canvas, old_colr, x, y, &outside, &in_line, &px_colr)) { - while (Inside(x - 1, y)) + while (Inside(last, canvas, old_colr, x - 1, y, &outside, &in_line, &px_colr)) { - Set(x - 1, y); + putpixels[canvas->format->BytesPerPixel] (canvas, x - 1, y, blend(canvas, cur_colr, px_colr, (1.0 - in_line))); track_extents_and_progbar(x - 1, y, extent_x1, extent_y1, extent_x2, extent_y2, screen, canvas); x = x - 1; @@ -282,9 +300,10 @@ void simulate_flood_fill(SDL_Surface * screen, SDL_Surface * last, SDL_Surface * if (x < x1) add_to_queue(x, x1 - 1, y - dy, -dy); + outside = 0; while (x1 < x2) { - Set(x1, y); + putpixels[canvas->format->BytesPerPixel] (canvas, x1, y, blend(canvas, cur_colr, px_colr, (1.0 - in_line))); track_extents_and_progbar(x1, y, extent_x1, extent_y1, extent_x2, extent_y2, screen, canvas); x1 = x1 + 1; @@ -295,7 +314,8 @@ void simulate_flood_fill(SDL_Surface * screen, SDL_Surface * last, SDL_Surface * if (x1 - 1 > x2) add_to_queue(x2 + 1, x1 - 1, y - dy, -dy); - while (x1 < x2 && !Inside(x1, y)) + outside = 0; + while (x1 < x2 && !Inside(last, canvas, old_colr, x1, y, &outside, &in_line, &px_colr)) x1++; x = x1; From 5cfc185d77edd075e4ba3d3bb3255aa6c6185869 Mon Sep 17 00:00:00 2001 From: Bill Kendrick Date: Sat, 20 Nov 2021 01:17:17 -0800 Subject: [PATCH 3/3] Globalized a ton of stuff, able to queue-ify flood fill The queue grows ever large, and should shrink itself once as the queue gets consumed. In the meantime, it seems to help. At 3000x2000, with starters/mosaic.svg cut into four via Panels magic tool, I get a VERY complicated drawing, which no longer causes a crash. (It crashed for me, even after some other improvements -- globalizing many of the unchanging args to the recursive function, calling the progress bar animation and sound effects calls less frequently -- helped prevent crashing for me with that starter image as-is.) --- docs/CHANGES.txt | 11 +- src/fill.c | 329 ++++++++++++++++++++++------------------------- 2 files changed, 161 insertions(+), 179 deletions(-) diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index 8e7073d40..c1120b2db 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -197,10 +197,13 @@ $Id$ (e.g., when returning from the "Open" dialog). (Closes https://sourceforge.net/p/tuxpaint/feature-requests/186/) - * WIP - Attempt to void crashing (by blowing up the stack) when doing - a flood-fill of a complicated shape on a large canvas - (e.g., `tuxpaint --3000x2000` with `starters/mosaic.svg`). - (h/t Yang for reporting, and Pere for confirming) + * Avoid possibility of crashing when doing a flood-fill of a + complicated shape on a large canvas (e.g., `tuxpaint --3000x2000` + with `starters/mosaic.svg` + + Replace recursion with a queue (span filling method) + + Call the progress bar animation updates and playsound() function + less frequently + h/t Yang for reporting & Pere for confirming * Ports & Building ---------------- diff --git a/src/fill.c b/src/fill.c index c9be1c271..1b2d575e8 100644 --- a/src/fill.c +++ b/src/fill.c @@ -59,43 +59,35 @@ /* How many pixels can we allow a wide match before stopping? */ #define WIDE_MATCH_THRESHOLD 3 - -// #define USE_QUEUE - -#ifdef USE_QUEUE - -/* Queue for span filling - (https://en.wikipedia.org/wiki/Flood_fill#Span_Filling) -*/ +// #define DEBUG #define QUEUE_SIZE_CHUNK 1024 typedef struct queue_s { - int x1, x2, y, yd; + int x, y, y_outside; } queue_t; queue_t * queue; int queue_size = 0, queue_start = 0, queue_end = 0; -static unsigned char progbar_anim = 0; - -#endif /* Local function prototypes: */ +SDL_Surface * global_screen, * global_last, * global_canvas; +Uint32 global_old_colr, global_cur_colr; +Uint8 * global_touched; +int global_extent_x1, global_extent_y1, global_extent_x2, global_extent_y2; +int global_prog_anim; + double colors_close(SDL_Surface * canvas, Uint32 c1, Uint32 c2); Uint32 blend(SDL_Surface * canvas, Uint32 draw_colr, Uint32 old_colr, double pct); -void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Surface * last, SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr, int * x1, int * y1, int * x2, int * y2, Uint8 * touched, int y_outside); +void simulate_flood_fill_outside_check(int x, int y, int y_outside); void draw_brush_fill_single(SDL_Surface * canvas, int x, int y, Uint32 draw_color, Uint8 * touched); -#ifdef USE_QUEUE -void init_queue(void); -void add_to_queue(int x1, int x2, int y, int yd); -int remove_from_queue(int * x1, int * x2, int * y, int * yd); -void cleanup_queue(void); -void track_extents_and_progbar(int x, int y, int * extent_x1, int * extent_y1, int * extent_x2, int * extent_y2, SDL_Surface * screen, SDL_Surface * canvas); -double Inside(SDL_Surface * last, SDL_Surface * canvas, Uint32 old_colr, int x, int y, int * outside, double * in_line, Uint32 * px_colr); -#endif -#ifdef USE_QUEUE +void init_queue(void); +void add_to_queue(int x, int y, int y_outside); +int remove_from_queue(int * x, int * y, int * y_outside); +void cleanup_queue(void); + void init_queue(void) { queue_size = 0; queue_start = 0; @@ -111,7 +103,7 @@ void init_queue(void) { queue_size = QUEUE_SIZE_CHUNK; } -void add_to_queue(int x1, int x2, int y, int yd) { +void add_to_queue(int x, int y, int y_outside) { /* Reallocate if we need more space */ if (queue_end + 1 > queue_size) { @@ -123,28 +115,46 @@ void add_to_queue(int x1, int x2, int y, int yd) { return; } queue_size += QUEUE_SIZE_CHUNK; +#ifdef DEBUG + printf("queue_size = %d\n", queue_size); + fflush(stdout); +#endif queue = tmp; } - queue[queue_end].x1 = x1; - queue[queue_end].x2 = x2; + queue[queue_end].x = x; queue[queue_end].y = y; - queue[queue_end].yd = yd; + queue[queue_end].y_outside = y_outside; queue_end++; + +#ifdef DEBUG + if (queue_end % 100 == 0) + { + printf("queue_end = %d\n", queue_end); + fflush(stdout); + } +#endif } -int remove_from_queue(int * x1, int * x2, int * y, int * yd) { +int remove_from_queue(int * x, int * y, int * y_outside) { if (queue_start == queue_end) return 0; - *x1 = queue[queue_start].x1; - *x2 = queue[queue_start].x2; + *x = queue[queue_start].x; *y = queue[queue_start].y; - *yd = queue[queue_start].yd; + *y_outside = queue[queue_start].y_outside; queue_start++; +#ifdef DEBUG + if (queue_start % 100 == 0) + { + printf("queue_start = %d\n", queue_start); + fflush(stdout); + } +#endif + return 1; } @@ -157,27 +167,6 @@ void cleanup_queue(void) { queue_end = 0; } -void track_extents_and_progbar(int x, int y, int * extent_x1, int * extent_y1, int * extent_x2, int * extent_y2, SDL_Surface * screen, SDL_Surface * canvas) { - if (x < *extent_x1) - *extent_x1 = x; - if (x > *extent_x2) - *extent_x2 = x; - - if (y < *extent_y1) - *extent_y1 = y; - if (y > *extent_y2) - *extent_y2 = y; - - progbar_anim++; - if ((progbar_anim % 4) == 0) - { - show_progress_bar(screen); - playsound(canvas, 1, SND_FILL, 1, x, SNDDIST_NEAR); - } -} - -#endif - /* Returns how similar colors 'c1' and 'c2' are */ double colors_close(SDL_Surface * canvas, Uint32 c1, Uint32 c2) @@ -243,116 +232,64 @@ Uint32 blend(SDL_Surface * canvas, Uint32 draw_colr, Uint32 old_colr, double pct return SDL_MapRGB(canvas->format, new_r, new_g, new_b); } -#ifdef USE_QUEUE -double Inside(SDL_Surface * last, SDL_Surface * canvas, Uint32 old_colr, int x, int y, int * outside, double * in_line, Uint32 * px_colr) { - *px_colr = getpixels[last->format->BytesPerPixel] (last, x, y); - *in_line = colors_close(canvas, *px_colr, old_colr); - - if (*in_line < COLOR_MATCH_WIDE && *outside < WIDE_MATCH_THRESHOLD) { - *outside = (*outside + 1); - return(1); - } - return(0); -} -#endif - void simulate_flood_fill(SDL_Surface * screen, SDL_Surface * last, SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr, int * extent_x1, int * extent_y1, int * extent_x2, int * extent_y2, Uint8 * touched) { -#ifdef USE_QUEUE - int x1, x2, dy, outside; - double in_line; - Uint32 px_colr; + int y_outside; - /* "Same" color? No need to fill */ - if (!would_flood_fill(canvas, cur_colr, old_colr)) - return; - - if (x < 0 || x >= canvas->w || y < 0 || y >= canvas->h) - return; - - /* Don't re-visit the same pixel */ - if (touched && touched[(y * canvas->w) + x]) - return; + /* Get ready */ + global_screen = screen; + global_last = last; + global_canvas = canvas; + global_old_colr = old_colr; + global_cur_colr = cur_colr; + global_touched = touched; + global_extent_x1 = x; + global_extent_y1 = y; + global_extent_x2 = x; + global_extent_y2 = y; + global_prog_anim = 0; /* Queue up the first things to work on: */ init_queue(); - - add_to_queue(x, x, y, 1); - add_to_queue(x, x, y - 1, -1); + add_to_queue(x, y, 0); /* Do the work (possibly queuing more, as we go) */ - while (remove_from_queue(&x1, &x2, &y, &dy)) + while (remove_from_queue(&x, &y, &y_outside)) { - printf("From queue: (%d -> %d, %d) %d\n", x1, x2, y, dy); - x = x1; - - outside = 0; - if (Inside(last, canvas, old_colr, x, y, &outside, &in_line, &px_colr)) - { - while (Inside(last, canvas, old_colr, x - 1, y, &outside, &in_line, &px_colr)) - { - putpixels[canvas->format->BytesPerPixel] (canvas, x - 1, y, blend(canvas, cur_colr, px_colr, (1.0 - in_line))); - track_extents_and_progbar(x - 1, y, extent_x1, extent_y1, extent_x2, extent_y2, screen, canvas); - - x = x - 1; - } - } - - if (x < x1) - add_to_queue(x, x1 - 1, y - dy, -dy); - - outside = 0; - while (x1 < x2) - { - putpixels[canvas->format->BytesPerPixel] (canvas, x1, y, blend(canvas, cur_colr, px_colr, (1.0 - in_line))); - track_extents_and_progbar(x1, y, extent_x1, extent_y1, extent_x2, extent_y2, screen, canvas); - - x1 = x1 + 1; - } - - add_to_queue(x, x1 - 1, y + dy, dy); - - if (x1 - 1 > x2) - add_to_queue(x2 + 1, x1 - 1, y - dy, -dy); - - outside = 0; - while (x1 < x2 && !Inside(last, canvas, old_colr, x1, y, &outside, &in_line, &px_colr)) - x1++; - - x = x1; + simulate_flood_fill_outside_check(x, y, y_outside); } - cleanup_queue(); -#else - simulate_flood_fill_outside_check(screen, last, canvas, x, y, cur_colr, old_colr, extent_x1, extent_y1, extent_x2, extent_y2, touched, 0); -#endif + + *extent_x1 = global_extent_x1; + *extent_y1 = global_extent_y1; + *extent_x2 = global_extent_x2; + *extent_y2 = global_extent_y2; } -void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Surface * last, SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr, int * x1, int * y1, int * x2, int * y2, Uint8 * touched, int y_outside) +void simulate_flood_fill_outside_check(int x, int y, int y_outside) { - int fillL, fillR, narrowFillL, narrowFillR, i, outside; + int fillL, fillR, narrowFillL, narrowFillR, i, outside, just_queued; double in_line, closeness; - static unsigned char prog_anim; Uint32 px_colr; Uint8 touch_byt; /* "Same" color? No need to fill */ - if (!would_flood_fill(canvas, cur_colr, old_colr)) + if (!would_flood_fill(global_canvas, global_cur_colr, global_old_colr)) return; - if (x < 0 || x >= canvas->w || y < 0 || y >= canvas->h) + if (x < 0 || x >= global_canvas->w || y < 0 || y >= global_canvas->h) return; /* Don't re-visit the same pixel */ - if (touched && touched[(y * canvas->w) + x]) + if (global_touched && global_touched[(y * global_canvas->w) + x]) return; - if (y < *y1) + if (y < global_extent_y1) { - *y1 = y; + global_extent_y1 = y; } - if (y > *y2) + if (y > global_extent_y2) { - *y2 = y; + global_extent_y2 = y; } @@ -361,18 +298,28 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Surface * last, narrowFillL = x; narrowFillR = x; - prog_anim++; - if ((prog_anim % 4) == 0) + global_prog_anim++; + if ((global_prog_anim % 8) == 0) { - show_progress_bar(screen); - playsound(canvas, 1, SND_FILL, 1, x, SNDDIST_NEAR); + show_progress_bar(global_screen); + } + if ((global_prog_anim % 800) == 1) /* Always lay sound _once_ */ + playsound(global_canvas, 1, SND_FILL, 1, x, SNDDIST_NEAR); + +#ifdef DEBUG + if (global_prog_anim % 100 == 0) + { + SDL_BlitSurface(global_canvas, NULL, global_screen, NULL); + SDL_Flip(global_screen); + } +#endif /* Find left side, filling along the way */ - px_colr = getpixels[last->format->BytesPerPixel] (last, fillL /* - 1 */, y); - in_line = colors_close(canvas, px_colr, old_colr); + px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, fillL /* - 1 */, y); + in_line = colors_close(global_canvas, px_colr, global_old_colr); outside = 0; while (in_line < COLOR_MATCH_WIDE && outside < WIDE_MATCH_THRESHOLD) { @@ -382,23 +329,23 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Surface * last, narrowFillL = fillL; } - if (touched != NULL) { + if (global_touched != NULL) { touch_byt = (255 - ((Uint8) (in_line * 85))); if (touch_byt == 0) touch_byt = 1; - touched[(y * canvas->w) + fillL] = touch_byt; + global_touched[(y * global_canvas->w) + fillL] = touch_byt; } - px_colr = getpixels[last->format->BytesPerPixel] (last, fillL, y); - putpixels[canvas->format->BytesPerPixel] (canvas, fillL, y, blend(canvas, cur_colr, px_colr, (1.0 - in_line))); + px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, fillL, y); + putpixels[global_canvas->format->BytesPerPixel] (global_canvas, fillL, y, blend(global_canvas, global_cur_colr, px_colr, (1.0 - in_line))); fillL--; - px_colr = getpixels[last->format->BytesPerPixel] (last, fillL, y); + px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, fillL, y); if (fillL >= 0) { - in_line = colors_close(canvas, px_colr, old_colr); + in_line = colors_close(global_canvas, px_colr, global_old_colr); } else { @@ -408,23 +355,23 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Surface * last, if (fillL >= 0) { - if (touched != NULL) + if (global_touched != NULL) { touch_byt = (255 - ((Uint8) (in_line * 85))); if (touch_byt == 0) touch_byt = 1; - touched[(y * canvas->w) + fillL] = touch_byt; + global_touched[(y * global_canvas->w) + fillL] = touch_byt; } - px_colr = getpixels[last->format->BytesPerPixel] (last, fillL, y); - putpixels[canvas->format->BytesPerPixel] (canvas, fillL, y, blend(canvas, cur_colr, px_colr, (1.0 - in_line))); + px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, fillL, y); + putpixels[global_canvas->format->BytesPerPixel] (global_canvas, fillL, y, blend(global_canvas, global_cur_colr, px_colr, (1.0 - in_line))); } - if (fillL < *x1) + if (fillL < global_extent_x1) { - *x1 = fillL; + global_extent_x1 = fillL; } fillL++; @@ -432,8 +379,8 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Surface * last, /* Find right side, filling along the way */ - px_colr = getpixels[last->format->BytesPerPixel] (last, fillR + 1, y); - in_line = colors_close(canvas, px_colr, old_colr); + px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, fillR + 1, y); + in_line = colors_close(global_canvas, px_colr, global_old_colr); outside = 0; while (in_line < COLOR_MATCH_WIDE && outside < WIDE_MATCH_THRESHOLD) { @@ -443,23 +390,23 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Surface * last, narrowFillR = fillR; } - if (touched != NULL) { + if (global_touched != NULL) { touch_byt = (255 - ((Uint8) (in_line * 85))); if (touch_byt == 0) touch_byt = 1; - touched[(y * canvas->w) + fillR] = touch_byt; + global_touched[(y * global_canvas->w) + fillR] = touch_byt; } - px_colr = getpixels[last->format->BytesPerPixel] (last, fillR, y); - putpixels[canvas->format->BytesPerPixel] (canvas, fillR, y, blend(canvas, cur_colr, px_colr, (1.0 - in_line))); + px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, fillR, y); + putpixels[global_canvas->format->BytesPerPixel] (global_canvas, fillR, y, blend(global_canvas, global_cur_colr, px_colr, (1.0 - in_line))); fillR++; - px_colr = getpixels[last->format->BytesPerPixel] (last, fillR, y); + px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, fillR, y); - if (fillR < canvas->w) + if (fillR < global_canvas->w) { - in_line = colors_close(canvas, px_colr, old_colr); + in_line = colors_close(global_canvas, px_colr, global_old_colr); } else { @@ -467,35 +414,36 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Surface * last, } } - if (fillR < canvas->w) + if (fillR < global_canvas->w) { - if (touched != NULL) + if (global_touched != NULL) { touch_byt = (255 - ((Uint8) (in_line * 85))); if (touch_byt == 0) touch_byt = 1; - touched[(y * canvas->w) + fillR] = touch_byt; + global_touched[(y * global_canvas->w) + fillR] = touch_byt; } - px_colr = getpixels[last->format->BytesPerPixel] (last, fillR, y); - putpixels[canvas->format->BytesPerPixel] (canvas, fillR, y, blend(canvas, cur_colr, px_colr, (1.0 - in_line))); + px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, fillR, y); + putpixels[global_canvas->format->BytesPerPixel] (global_canvas, fillR, y, blend(global_canvas, global_cur_colr, px_colr, (1.0 - in_line))); } - if (fillR > *x2) + if (fillR > global_extent_x2) { - *x2 = fillR; + global_extent_x2 = fillR; } fillR--; - /* Search top and bottom */ + /* Continue filling upwards from this scanline */ + just_queued = 0; for (i = narrowFillL; i <= narrowFillR; i++) { - px_colr = getpixels[last->format->BytesPerPixel] (last, i, y - 1); - closeness = colors_close(canvas, px_colr, old_colr); + px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, i, y - 1); + closeness = colors_close(global_canvas, px_colr, global_old_colr); if (y > 0 && ( closeness < COLOR_MATCH_NARROW || @@ -503,19 +451,50 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Surface * last, ) ) { - simulate_flood_fill_outside_check(screen, last, canvas, i, y - 1, cur_colr, old_colr, x1, y1, x2, y2, touched, y_outside + 1); + if (!just_queued && (global_touched == NULL || !global_touched[((y - 1) * global_canvas->w) + i])) + { + add_to_queue(i, y - 1, y_outside + 1); + just_queued = 1; + } + else + { + just_queued = 0; + } } + else + { + just_queued = 0; + } + } - px_colr = getpixels[last->format->BytesPerPixel] (last, i, y + 1); - closeness = colors_close(canvas, px_colr, old_colr); - if (y < canvas->h && + + /* Continue filling downwards from this scanline */ + + just_queued = 0; + for (i = narrowFillL; i <= narrowFillR; i++) + { + px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, i, y + 1); + closeness = colors_close(global_canvas, px_colr, global_old_colr); + if (y < global_canvas->h && ( closeness < COLOR_MATCH_NARROW || (closeness < COLOR_MATCH_WIDE && y_outside < WIDE_MATCH_THRESHOLD) ) ) { - simulate_flood_fill_outside_check(screen, last, canvas, i, y + 1, cur_colr, old_colr, x1, y1, x2, y2, touched, y_outside + 1); + if (!just_queued && (global_touched == NULL || !global_touched[((y + 1) * global_canvas->w) + i])) + { + add_to_queue(i, y + 1, y_outside + 1); + just_queued = 1; + } + else + { + just_queued = 0; + } + } + else + { + just_queued = 0; } } }