From f7e9fa28705be3e0f87abd710d1cdcf2468da2b3 Mon Sep 17 00:00:00 2001 From: Bill Kendrick Date: Mon, 8 Mar 2021 01:36:07 -0800 Subject: [PATCH] Fill antialiasing edges; Not perfect, but improved Probably can still improve the ratio of {old pixel's difference to initial color to be replaced} to {new color being flood-filled}... --- docs/CHANGES.txt | 4 ++-- src/fill.c | 26 ++++++++++++++++++++------ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index d882258b8..e2de64f52 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -8,7 +8,7 @@ http://www.tuxpaint.org/ $Id$ -2021.March.7 (0.9.26) +2021.March.8 (0.9.26) * New Features ------------ * Larger UI buttons @@ -64,7 +64,7 @@ $Id$ * Other Improvements ------------------ - * [WIP] Fill tools do a better job at filling around + * Fill tools do a better job at filling around antialiased edges, and apply some blending. * Reduce CPU usage by increasing delay in main loop diff --git a/src/fill.c b/src/fill.c index 91a48fc8f..43be2ce2d 100644 --- a/src/fill.c +++ b/src/fill.c @@ -191,7 +191,7 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Surface * last, } px_colr = getpixels[last->format->BytesPerPixel] (last, fillL, y); - putpixels[canvas->format->BytesPerPixel] (canvas, fillL, y, blend(canvas, cur_colr, px_colr, (3.0 - in_line) / 3.0)); + putpixels[canvas->format->BytesPerPixel] (canvas, fillL, y, blend(canvas, cur_colr, px_colr, (1.0 - in_line))); fillL--; px_colr = getpixels[last->format->BytesPerPixel] (last, fillL, y); @@ -206,9 +206,15 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Surface * last, } } - if (touched != NULL && fillL >= 0) + if (fillL >= 0) { - touched[(y * canvas->w) + fillL] = (255 - ((Uint8) (in_line * 85))); + if (touched != NULL) + { + touched[(y * canvas->w) + fillL] = (255 - ((Uint8) (in_line * 85))); + } + + 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))); } @@ -236,8 +242,10 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Surface * last, if (touched != NULL) { touched[(y * canvas->w) + fillR] = (255 - ((Uint8) (in_line * 85))); } + px_colr = getpixels[last->format->BytesPerPixel] (last, fillR, y); - putpixels[canvas->format->BytesPerPixel] (canvas, fillR, y, blend(canvas, cur_colr, px_colr, (3.0 - in_line) / 3.0)); +printf("%f\n", in_line); + putpixels[canvas->format->BytesPerPixel] (canvas, fillR, y, blend(canvas, cur_colr, px_colr, (1.0 - in_line))); fillR++; px_colr = getpixels[last->format->BytesPerPixel] (last, fillR, y); @@ -252,9 +260,15 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Surface * last, } } - if (touched != NULL && fillR < canvas->w) + if (fillR < canvas->w) { - touched[(y * canvas->w) + fillR] = (255 - ((Uint8) (in_line * 85))); + if (touched != NULL) + { + touched[(y * canvas->w) + fillR] = (255 - ((Uint8) (in_line * 85))); + } + + 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))); } if (fillR > *x2)