New Magic tool: Color Sep. (aka 3D Glasses)
This commit is contained in:
parent
1277ad5cf6
commit
71ea0358c2
5 changed files with 232 additions and 2 deletions
|
|
@ -6,7 +6,7 @@ Copyright (c) 2002-2023
|
||||||
Various contributors (see below, and CHANGES.txt)
|
Various contributors (see below, and CHANGES.txt)
|
||||||
https://tuxpaint.org/
|
https://tuxpaint.org/
|
||||||
|
|
||||||
June 17, 2002 - February 7, 2023
|
June 17, 2002 - February 21, 2023
|
||||||
|
|
||||||
* Design and Coding:
|
* Design and Coding:
|
||||||
|
|
||||||
|
|
@ -137,6 +137,12 @@ June 17, 2002 - February 7, 2023
|
||||||
(https://freesound.org/people/kentnelson64/sounds/647221/)
|
(https://freesound.org/people/kentnelson64/sounds/647221/)
|
||||||
Creative Commons 0 license by "kentnelson64"
|
Creative Commons 0 license by "kentnelson64"
|
||||||
|
|
||||||
|
Color Sep. magic tool
|
||||||
|
by Bill Kendrick <bill@newbreedsoftware.com>
|
||||||
|
Color Sep. sound effect: "Sci-Fi Sensors"
|
||||||
|
(https://freesound.org/people/Zarkonnen/sounds/168885/)
|
||||||
|
Creative Commons 0 license by "Zarkonnen"
|
||||||
|
|
||||||
Mouse accessibility code and keyboard access
|
Mouse accessibility code and keyboard access
|
||||||
Ankit Choudary <ankit.goaldecided@gmail.com>, as part of GSOC 2010,
|
Ankit Choudary <ankit.goaldecided@gmail.com>, as part of GSOC 2010,
|
||||||
with integration and fixes by Pere Pujal i Carabantes <pere@fornol.no-ip.org>
|
with integration and fixes by Pere Pujal i Carabantes <pere@fornol.no-ip.org>
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ Various contributors (see below, and AUTHORS.txt)
|
||||||
https://tuxpaint.org/
|
https://tuxpaint.org/
|
||||||
|
|
||||||
|
|
||||||
2023.February.19 (0.9.29)
|
2023.February.21 (0.9.29)
|
||||||
* Improvements to "Stamp" tool:
|
* Improvements to "Stamp" tool:
|
||||||
-----------------------------
|
-----------------------------
|
||||||
* Stamps may now be rotated.
|
* Stamps may now be rotated.
|
||||||
|
|
@ -48,6 +48,12 @@ https://tuxpaint.org/
|
||||||
(Sound effected licensed as Creative Commons 0 (CC0 1.0)
|
(Sound effected licensed as Creative Commons 0 (CC0 1.0)
|
||||||
by https://freesound.org/people/kentnelson64/)
|
by https://freesound.org/people/kentnelson64/)
|
||||||
|
|
||||||
|
* "Color Sep." (color separation) - Separate the colors of the
|
||||||
|
image, e.g. Red vs Cyan, as in anaglyphic "3D glasses" images.
|
||||||
|
Bill Kendrick <bill@newbreedsoftware.com>
|
||||||
|
(Sound effected licensed as Creative Commons 0 (CC0 1.0)
|
||||||
|
by https://freesound.org/people/Zarkonnen/)
|
||||||
|
|
||||||
* [WIP] "Rivulet"; apply rivulets of water to the canvas
|
* [WIP] "Rivulet"; apply rivulets of water to the canvas
|
||||||
- needs better icon
|
- needs better icon
|
||||||
- needs sound effect
|
- needs sound effect
|
||||||
|
|
|
||||||
BIN
magic/icons/colorsep.png
Normal file
BIN
magic/icons/colorsep.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2 KiB |
BIN
magic/sounds/colorsep.ogg
Normal file
BIN
magic/sounds/colorsep.ogg
Normal file
Binary file not shown.
218
magic/src/colorsep.c
Normal file
218
magic/src/colorsep.c
Normal file
|
|
@ -0,0 +1,218 @@
|
||||||
|
/* colorsep.c
|
||||||
|
|
||||||
|
Color separation effect (a la red/cyan aka red/blue 3D glasses).
|
||||||
|
Bill Kendrick
|
||||||
|
|
||||||
|
Last updated: February 21, 2023
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <libintl.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "tp_magic_api.h"
|
||||||
|
#include "SDL_image.h"
|
||||||
|
#include "SDL_mixer.h"
|
||||||
|
|
||||||
|
enum {
|
||||||
|
COLORSEP_MODE_RED_CYAN,
|
||||||
|
COLORSEP_MODE_GREEN_PURPLE,
|
||||||
|
COLORSEP_MODE_BLUE_YELLOW
|
||||||
|
};
|
||||||
|
|
||||||
|
Mix_Chunk *snd_effect = NULL;
|
||||||
|
int colorsep_click_x, colorsep_click_y;
|
||||||
|
int colorsep_mode = COLORSEP_MODE_RED_CYAN;
|
||||||
|
|
||||||
|
Uint32 colorsep_api_version(void);
|
||||||
|
int colorsep_init(magic_api * api);
|
||||||
|
int colorsep_get_tool_count(magic_api * api);
|
||||||
|
SDL_Surface *colorsep_get_icon(magic_api * api, int which);
|
||||||
|
char *colorsep_get_name(magic_api * api, int which);
|
||||||
|
int colorsep_get_group(magic_api * api, int which);
|
||||||
|
char *colorsep_get_description(magic_api * api, int which, int mode);
|
||||||
|
int colorsep_requires_colors(magic_api * api, int which);
|
||||||
|
int colorsep_modes(magic_api * api, int which);
|
||||||
|
void colorsep_shutdown(magic_api * api);
|
||||||
|
void colorsep_click(magic_api * api, int which, int mode,
|
||||||
|
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
|
||||||
|
int y, SDL_Rect * update_rect);
|
||||||
|
void colorsep_set_color(magic_api * api, int which, SDL_Surface * canvas,
|
||||||
|
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
|
||||||
|
void colorsep_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||||
|
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||||
|
SDL_Rect * update_rect);
|
||||||
|
void colorsep_release(magic_api * api, int which, SDL_Surface * canvas,
|
||||||
|
SDL_Surface * snapshot, int x, int y,
|
||||||
|
SDL_Rect * update_rect);
|
||||||
|
void colorsep_switchin(magic_api * api, int which, int mode,
|
||||||
|
SDL_Surface * canvas);
|
||||||
|
void colorsep_switchout(magic_api * api, int which, int mode,
|
||||||
|
SDL_Surface * canvas);
|
||||||
|
|
||||||
|
|
||||||
|
Uint32 colorsep_api_version(void)
|
||||||
|
{
|
||||||
|
return (TP_MAGIC_API_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
int colorsep_init(magic_api * api)
|
||||||
|
{
|
||||||
|
char fname[1024];
|
||||||
|
|
||||||
|
snprintf(fname, sizeof(fname), "%ssounds/magic/colorsep.ogg",
|
||||||
|
api->data_directory);
|
||||||
|
snd_effect = Mix_LoadWAV(fname);
|
||||||
|
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int colorsep_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||||
|
{
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SDL_Surface *colorsep_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||||
|
{
|
||||||
|
char fname[1024];
|
||||||
|
|
||||||
|
snprintf(fname, sizeof(fname), "%simages/magic/colorsep.png",
|
||||||
|
api->data_directory);
|
||||||
|
|
||||||
|
return (IMG_Load(fname));
|
||||||
|
}
|
||||||
|
|
||||||
|
char *colorsep_get_name(magic_api * api ATTRIBUTE_UNUSED,
|
||||||
|
int which ATTRIBUTE_UNUSED)
|
||||||
|
{
|
||||||
|
return strdup(gettext("Color Sep."));
|
||||||
|
}
|
||||||
|
|
||||||
|
int colorsep_get_group(magic_api * api ATTRIBUTE_UNUSED,
|
||||||
|
int which ATTRIBUTE_UNUSED)
|
||||||
|
{
|
||||||
|
return MAGIC_TYPE_COLOR_FILTERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *colorsep_get_description(magic_api * api ATTRIBUTE_UNUSED,
|
||||||
|
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||||
|
{
|
||||||
|
return strdup(gettext("Click and drag to separate your picture's colors (based on your color choice: red from cyan, green from purple, or blue from yellow)."));
|
||||||
|
}
|
||||||
|
|
||||||
|
int colorsep_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
|
||||||
|
int which ATTRIBUTE_UNUSED)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int colorsep_modes(magic_api * api ATTRIBUTE_UNUSED,
|
||||||
|
int which ATTRIBUTE_UNUSED)
|
||||||
|
{
|
||||||
|
return MODE_PAINT;
|
||||||
|
}
|
||||||
|
|
||||||
|
void colorsep_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
||||||
|
{
|
||||||
|
if (snd_effect != NULL)
|
||||||
|
Mix_FreeChunk(snd_effect);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
colorsep_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
||||||
|
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
|
||||||
|
SDL_Rect * update_rect)
|
||||||
|
{
|
||||||
|
if (snd_effect != NULL)
|
||||||
|
api->stopsound();
|
||||||
|
|
||||||
|
/* (Start off as if they clicked off to the side a little, so that
|
||||||
|
* quick click+release will split the image bit by bit */
|
||||||
|
colorsep_click_x = x;
|
||||||
|
colorsep_click_y = y;
|
||||||
|
colorsep_drag(api, which, canvas, snapshot, x, y, x - 10, y, update_rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
colorsep_drag(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
|
||||||
|
SDL_Surface * snapshot, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED,
|
||||||
|
int x, int y, SDL_Rect * update_rect)
|
||||||
|
{
|
||||||
|
int xx, yy, offset_x, offset_y;
|
||||||
|
Uint8 r1, g1, b1, r2, g2, b2;
|
||||||
|
|
||||||
|
offset_x = colorsep_click_x - x;
|
||||||
|
offset_y = colorsep_click_y - y;
|
||||||
|
|
||||||
|
api->playsound(snd_effect, (((-offset_x * 255) / canvas->w) + 128), 255);
|
||||||
|
|
||||||
|
for (yy = 0; yy < canvas->h; yy++) {
|
||||||
|
for (xx = 0; xx < canvas->w; xx++) {
|
||||||
|
SDL_GetRGB(api->getpixel(snapshot, xx + offset_x / 2, yy + offset_y / 2), snapshot->format, &r1, &g1, &b1);
|
||||||
|
SDL_GetRGB(api->getpixel(snapshot, xx - offset_x / 2, yy - offset_y / 2), snapshot->format, &r2, &g2, &b2);
|
||||||
|
|
||||||
|
if (colorsep_mode == COLORSEP_MODE_RED_CYAN) {
|
||||||
|
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, r1, g2, b2));
|
||||||
|
} else if (colorsep_mode == COLORSEP_MODE_GREEN_PURPLE) {
|
||||||
|
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, r2, g1, b2));
|
||||||
|
} else if (colorsep_mode == COLORSEP_MODE_BLUE_YELLOW) {
|
||||||
|
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, r2, g2, b1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
update_rect->x = 0;
|
||||||
|
update_rect->y = 0;
|
||||||
|
update_rect->w = canvas->w;
|
||||||
|
update_rect->h = canvas->h;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void colorsep_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||||
|
SDL_Surface * canvas ATTRIBUTE_UNUSED,
|
||||||
|
SDL_Surface * snapshot ATTRIBUTE_UNUSED,
|
||||||
|
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
|
||||||
|
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void colorsep_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||||
|
SDL_Surface * canvas ATTRIBUTE_UNUSED,
|
||||||
|
SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||||
|
Uint8 r, Uint8 g, Uint8 b,
|
||||||
|
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||||
|
{
|
||||||
|
r >>= 4;
|
||||||
|
g >>= 4;
|
||||||
|
b >>= 4;
|
||||||
|
|
||||||
|
/* If the color chosen is very strong in some colors, separate it */
|
||||||
|
if ((r > g && r > b) || (b > r && g > r)) {
|
||||||
|
colorsep_mode = COLORSEP_MODE_RED_CYAN;
|
||||||
|
} else if ((g > r && g > b) || (r > g && b > g)) {
|
||||||
|
colorsep_mode = COLORSEP_MODE_GREEN_PURPLE;
|
||||||
|
} else if ((b > r && b > g) || (r > b && g > b)) {
|
||||||
|
colorsep_mode = COLORSEP_MODE_BLUE_YELLOW;
|
||||||
|
} else {
|
||||||
|
/* No winner? Default to the most comment, red/cyan */
|
||||||
|
colorsep_mode = COLORSEP_MODE_RED_CYAN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void colorsep_switchin(magic_api * api ATTRIBUTE_UNUSED,
|
||||||
|
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||||
|
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void colorsep_switchout(magic_api * api ATTRIBUTE_UNUSED,
|
||||||
|
int which ATTRIBUTE_UNUSED,
|
||||||
|
int mode ATTRIBUTE_UNUSED,
|
||||||
|
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||||
|
{
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue