From 8f31459990a2f99aedb2f33a3844d4986177a7b7 Mon Sep 17 00:00:00 2001 From: Bill Kendrick Date: Mon, 20 Sep 2021 22:28:29 -0700 Subject: [PATCH] "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). --- docs/CHANGES.txt | 3 ++ magic/src/tv.c | 75 +++++++++++++++++++++++++++++++++++++----------- 2 files changed, 61 insertions(+), 17 deletions(-) diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index 8f9e58b76..8be9bfcac 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -29,6 +29,9 @@ $Id$ color of the area of the picture being replaced, to give a "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. * Other Improvements: diff --git a/magic/src/tv.c b/magic/src/tv.c index 95e893d8b..a3f432ab8 100644 --- a/magic/src/tv.c +++ b/magic/src/tv.c @@ -5,8 +5,9 @@ Tux Paint - A simple drawing program for children. Credits: Adam 'foo-script' Rakowski + and Bill Kendrick - 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 http://www.tuxpaint.org/ @@ -29,6 +30,7 @@ #include "tp_magic_api.h" #include "SDL_image.h" #include "SDL_mixer.h" +#include int RADIUS = 16; @@ -124,25 +126,61 @@ void tv_shutdown(magic_api * api ATTRIBUTE_UNUSED) // 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, SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y) { int i, j; magic_api *api = (magic_api *) ptr_to_api; + y = (y - (y % 2)); + 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; - - api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, 128, 128, 165)); - //api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, 0, 0, 255)); + { + for (j = y - RADIUS; j < y + RADIUS; j += 2) + { + if (api->in_circle(i - x, j - y, RADIUS) && !api->touched(i, j)) + { + tv_do_tv(api, 0, canvas, snapshot, i, j); + } + } + } } 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) { - int i; - - for (i = 0; i < canvas->h; i += 2) - api->line(api, which, canvas, last, 0, i, canvas->w, i, 1, tv_do_tv); + for (y = 0; y < canvas->h; y += 2) + { + for (x = 0; x < canvas->w; x++) + { + tv_do_tv(api, which, canvas, last, x, y); + } + } update_rect->w = canvas->w; update_rect->h = canvas->h;