"TV" Magic Tool enhancement

"TV" now breaks pixels into red/green/blue components,
rather than merely adding a 'scanline' effect.

Reworked how it handles interaction (click/drag vs fullscreen).
This commit is contained in:
Bill Kendrick 2021-09-20 22:28:29 -07:00
parent f1e297260a
commit 8f31459990
2 changed files with 61 additions and 17 deletions

View file

@ -29,6 +29,9 @@ $Id$
color of the area of the picture being replaced, to give a color of the area of the picture being replaced, to give a
"newsprint" effect. "newsprint" effect.
* "TV" now breaks pixels into red/green/blue components,
rather than merely adding a 'scanline' effect.
* "Halftone" and "Emboss" can now affect the entire image at once. * "Halftone" and "Emboss" can now affect the entire image at once.
* Other Improvements: * Other Improvements:

View file

@ -5,8 +5,9 @@
Tux Paint - A simple drawing program for children. Tux Paint - A simple drawing program for children.
Credits: Adam 'foo-script' Rakowski <foo-script@o2.pl> Credits: Adam 'foo-script' Rakowski <foo-script@o2.pl>
and Bill Kendrick <bill@newbreedsoftware.com>
Copyright (c) 2002-2008 by Bill Kendrick and others; see AUTHORS.txt Copyright (c) 2002-2021 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com bill@newbreedsoftware.com
http://www.tuxpaint.org/ http://www.tuxpaint.org/
@ -29,6 +30,7 @@
#include "tp_magic_api.h" #include "tp_magic_api.h"
#include "SDL_image.h" #include "SDL_image.h"
#include "SDL_mixer.h" #include "SDL_mixer.h"
#include <math.h>
int RADIUS = 16; int RADIUS = 16;
@ -124,25 +126,61 @@ void tv_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Interactivity functions // Interactivity functions
void tv_do_tv(void *ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr_to_api;
Uint8 r, g, b, i;
for (i = 0; i < 2; i++)
{
/* Convert the line below to their red/green/blue elements */
SDL_GetRGB(api->getpixel(snapshot, x, y + i), snapshot->format, &r, &g, &b);
if (x % 3 == 0)
{
/* Red */
g = 0;
b = 0;
}
else if (x % 3 == 1)
{
/* Green */
r = 0;
b = 0;
}
else
{
/* Blue */
r = 0;
g = 0;
}
r = r / (i + 1);
g = g / (i + 1);
b = b / (i + 1);
api->putpixel(canvas, x, y + i, SDL_MapRGB(canvas->format, r, g, b));
}
}
void tv_paint_tv(void *ptr_to_api, int which_tool ATTRIBUTE_UNUSED, void tv_paint_tv(void *ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y) SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{ {
int i, j; int i, j;
magic_api *api = (magic_api *) ptr_to_api; magic_api *api = (magic_api *) ptr_to_api;
y = (y - (y % 2));
for (i = x - RADIUS; i < x + RADIUS; i++) for (i = x - RADIUS; i < x + RADIUS; i++)
for (j = y - RADIUS; j < y + RADIUS; j++)
if ((j + 1) % 2 && api->in_circle(i - x, j - y, RADIUS) && !api->touched(i, j))
api->putpixel(canvas, i, j, SDL_MapRGB(canvas->format, 128, 128, 165));
}
void tv_do_tv(void *ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{ {
magic_api *api = (magic_api *) ptr_to_api; for (j = y - RADIUS; j < y + RADIUS; j += 2)
{
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, 128, 128, 165)); if (api->in_circle(i - x, j - y, RADIUS) && !api->touched(i, j))
//api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, 0, 0, 255)); {
tv_do_tv(api, 0, canvas, snapshot, i, j);
}
}
}
} }
void tv_drag(magic_api * api, int which, SDL_Surface * canvas, void tv_drag(magic_api * api, int which, SDL_Surface * canvas,
@ -162,10 +200,13 @@ void tv_click(magic_api * api, int which, int mode,
{ {
if (mode == MODE_FULLSCREEN) if (mode == MODE_FULLSCREEN)
{ {
int i; for (y = 0; y < canvas->h; y += 2)
{
for (i = 0; i < canvas->h; i += 2) for (x = 0; x < canvas->w; x++)
api->line(api, which, canvas, last, 0, i, canvas->w, i, 1, tv_do_tv); {
tv_do_tv(api, which, canvas, last, x, y);
}
}
update_rect->w = canvas->w; update_rect->w = canvas->w;
update_rect->h = canvas->h; update_rect->h = canvas->h;