Smudge & Wet Paint: Support sizes

This commit is contained in:
Bill Kendrick 2023-04-23 16:37:52 -07:00
parent 17b23e19d0
commit 7ab630c914
2 changed files with 47 additions and 21 deletions

View file

@ -63,6 +63,7 @@ https://tuxpaint.org/
+ Rosette, Picasso + Rosette, Picasso
+ Saturate, Desaturate + Saturate, Desaturate
+ Sharpen, Edges, Silhouette + Sharpen, Edges, Silhouette
+ Smudge, Wet Paint
+ Tint, Color & White + Tint, Color & White
+ Toothpaste + Toothpaste
+ TV + TV

View file

@ -25,7 +25,9 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt) (See COPYING.txt)
Last updated: February 12, 2023 Last updated: April 23, 2023
FIXME: "Wet Paint" doesn't smudge enough -bjk 2023.04.23
*/ */
#include <stdio.h> #include <stdio.h>
@ -38,8 +40,9 @@
static Mix_Chunk *smudge_snd; static Mix_Chunk *smudge_snd;
static Uint8 smudge_r, smudge_g, smudge_b; static Uint8 smudge_r, smudge_g, smudge_b;
static int smudge_radius = 16;
int smudge_init(magic_api * api); int smudge_init(magic_api * api, Uint32 disabled_features);
Uint32 smudge_api_version(void); Uint32 smudge_api_version(void);
SDL_Surface *smudge_get_icon(magic_api * api, int which); SDL_Surface *smudge_get_icon(magic_api * api, int which);
char *smudge_get_name(magic_api * api, int which); char *smudge_get_name(magic_api * api, int which);
@ -64,9 +67,12 @@ void smudge_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas); SDL_Surface * canvas);
int smudge_modes(magic_api * api, int which); int smudge_modes(magic_api * api, int which);
int smudge_get_tool_count(magic_api * api); int smudge_get_tool_count(magic_api * api);
Uint8 smudge_accepted_sizes(magic_api * api, int which, int mode);
Uint8 smudge_default_size(magic_api * api, int which, int mode);
void smudge_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
// No setup required:
int smudge_init(magic_api * api) int smudge_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{ {
char fname[1024]; char fname[1024];
@ -141,8 +147,8 @@ static void do_smudge(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y) SDL_Surface * last, int x, int y)
{ {
magic_api *api = (magic_api *) ptr; magic_api *api = (magic_api *) ptr;
static double state[32][32][3]; static double state[256][256][3];
unsigned i = 32 * 32; unsigned i = (smudge_radius * 2) * (smudge_radius * 2);
double rate = api->button_down()? 0.5 : 0.0; double rate = api->button_down()? 0.5 : 0.0;
Uint8 r, g, b; Uint8 r, g, b;
int xx, yy, strength; int xx, yy, strength;
@ -150,14 +156,13 @@ static void do_smudge(void *ptr, int which, SDL_Surface * canvas,
if (which == 1) if (which == 1)
{ {
/* Wet paint */ /* Wet paint */
for (yy = -8; yy < 8; yy++) for (yy = -(smudge_radius / 2); yy < (smudge_radius / 2); yy++)
for (xx = -8; xx < 8; xx++) for (xx = -(smudge_radius / 2); xx < (smudge_radius / 2); xx++)
if (api->in_circle(xx, yy, 8)) if (api->in_circle(xx, yy, (smudge_radius / 2)))
{ {
SDL_GetRGB(api->getpixel(last, x + xx, y + yy), last->format, &r, SDL_GetRGB(api->getpixel(last, x + xx, y + yy), last->format, &r,
&g, &b); &g, &b);
//strength = (abs(xx * yy) / 8) + 6; strength = (abs(xx * yy) / (smudge_radius / 2)) + 1;
strength = (abs(xx * yy) / 8) + 1;
api->putpixel(canvas, x + xx, y + yy, SDL_MapRGB(canvas->format, api->putpixel(canvas, x + xx, y + yy, SDL_MapRGB(canvas->format,
(smudge_r + (smudge_r +
r * strength) / r * strength) /
@ -173,15 +178,18 @@ static void do_smudge(void *ptr, int which, SDL_Surface * canvas,
while (i--) while (i--)
{ {
int iy = i >> 5; int iy = i / (smudge_radius * 2);
int ix = i & 0x1f; int ix = i % (smudge_radius * 2);
int radius_check;
// is it not on the circle of radius sqrt(120) at location 16,16? radius_check = (smudge_radius * 75) / 10; /* For 16 radius, we'll use 120 */
if ((ix - 16) * (ix - 16) + (iy - 16) * (iy - 16) > 120)
// is it not on the circle of radius sqrt(radius_check) at location (smudge_radius,smudge_radius)?
if ((ix - smudge_radius) * (ix - smudge_radius) + (iy - smudge_radius) * (iy - smudge_radius) > radius_check)
continue; continue;
// it is on the circle, so grab it // it is on the circle, so grab it
SDL_GetRGB(api->getpixel(canvas, x + ix - 16, y + iy - 16), last->format, SDL_GetRGB(api->getpixel(canvas, x + ix - smudge_radius, y + iy - smudge_radius), last->format,
&r, &g, &b); &r, &g, &b);
state[ix][iy][0] = state[ix][iy][0] =
rate * state[ix][iy][0] + (1.0 - rate) * api->sRGB_to_linear(r); rate * state[ix][iy][0] + (1.0 - rate) * api->sRGB_to_linear(r);
@ -191,7 +199,7 @@ static void do_smudge(void *ptr, int which, SDL_Surface * canvas,
rate * state[ix][iy][2] + (1.0 - rate) * api->sRGB_to_linear(b); rate * state[ix][iy][2] + (1.0 - rate) * api->sRGB_to_linear(b);
// opacity 100% --> new data not blended w/ existing data // opacity 100% --> new data not blended w/ existing data
api->putpixel(canvas, x + ix - 16, y + iy - 16, api->putpixel(canvas, x + ix - smudge_radius, y + iy - smudge_radius,
SDL_MapRGB(canvas->format, SDL_MapRGB(canvas->format,
api->linear_to_sRGB(state[ix][iy][0]), api->linear_to_sRGB(state[ix][iy][0]),
api->linear_to_sRGB(state[ix][iy][1]), api->linear_to_sRGB(state[ix][iy][1]),
@ -223,10 +231,10 @@ void smudge_drag(magic_api * api, int which, SDL_Surface * canvas,
y = tmp; y = tmp;
} }
update_rect->x = ox - 16; update_rect->x = ox - smudge_radius;
update_rect->y = oy - 16; update_rect->y = oy - smudge_radius;
update_rect->w = (x + 16) - update_rect->x; update_rect->w = (x + smudge_radius) - update_rect->x;
update_rect->h = (y + 16) - update_rect->y; update_rect->h = (y + smudge_radius) - update_rect->y;
} }
// Affect the canvas on click: // Affect the canvas on click:
@ -289,3 +297,20 @@ int smudge_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{ {
return (MODE_PAINT); return (MODE_PAINT);
} }
Uint8 smudge_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return 8;
}
Uint8 smudge_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return 4;
}
void smudge_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
smudge_radius = size * 4;
}