From db6b8d2089017690b6e4046c4f3ac115bdc86ede Mon Sep 17 00:00:00 2001 From: William Kendrick Date: Sat, 16 Jul 2011 05:44:49 +0000 Subject: [PATCH] Starting a Halftone magic tool. (SF Bug #3148011) --- magic/icons/halftone.png | Bin 0 -> 1285 bytes magic/src/halftone.c | 233 +++++++++++++++++++++++++++++++++++++++ magic/src/smudge.c | 5 +- 3 files changed, 236 insertions(+), 2 deletions(-) create mode 100644 magic/icons/halftone.png create mode 100644 magic/src/halftone.c diff --git a/magic/icons/halftone.png b/magic/icons/halftone.png new file mode 100644 index 0000000000000000000000000000000000000000..6696f892b195061899d4f04ce39322959a24aa2d GIT binary patch literal 1285 zcmV+g1^W7lP)Px(zez+vR9M61mw!lGR}{y;FNRN@s^V3blyBDR&{EUUJX3=E}$Qtc{h8?3VGN>Pk0PgD%0nnD>&sPNq%Yv0VQ zKL)P(V+Ytm3F(G9*>7bMMdoC>ET9N#eV_da5(7kczE^d zRTvBg*zI-*f&i1rgt4(P-o1O5TY@YvFQ0B|YGP()CSzk`85_kC90eX6R@a);MjeR+tPU>_zS}Yd!_4RRn zex6>hm-F-U?CtHP$z)lTxelDK>KZZ>xK~b@89RsiE#ozb8|DZva;4`?RGmg z8Vze|YWV2UBSuC>GB`MxuU@^1d#4#28>2>}q0wk$d3ia<$H)KnlbV{!W5Ng6T`!Y4|8~U*l(`V?REnIj7FoM!^giqW@$+&UcOwyA1l8D z1k|A+^7})F4&mInbC4v7dc9tFH=dW5C(O;w@%r`a7#ti#S63HSR#x!l%^O5VN29j3 z7KMd{*tc(=;J091T^#|?>-7=<=H?dI`NNO=%$!Y~?qf!4qxeyThWigBaAsykj^b@Z z92ptew78d+mRcl9;`8UvH`OUuS62Z5tE;OR{`nWq&d$Q}#piitUzH3^PEGR8odI|k z7jgD%C1PT9aukb;ivWOKyLN4QuI$~rw;n+KR_Bj0B;>DjkB*Mw2F*M0RV2d8)~&0TCMh{9XXC~-@Z)%n|?L#vxtZYn$2eJXm8MJwG;$_9UUFpa$Hqa zMF6~Z?b^3RYHD?mUdmW@A`bnBQXme9UGuT`m{(dc8dM zZ|iGY=JWY-FI>35+}vCyB_%OFKAxf|vaGC(4lR0Ke^TFo0bZUhd->2%8VrBo`})YKF>n90dWrlzLKTXp2f z5x=|02elV3UieHVlMIuYnMp~K0+*eVk`fsvE-sF4w>xk!R;!f?g@ORMXU`rw9FD-j zI2;a!hlk5;p|Pn$2%00000NkvXXu0mjfOvz%W literal 0 HcmV?d00001 diff --git a/magic/src/halftone.c b/magic/src/halftone.c new file mode 100644 index 000000000..2d5541ba3 --- /dev/null +++ b/magic/src/halftone.c @@ -0,0 +1,233 @@ +/* halftone.c + + Last modified: 2011.07.15 +*/ + + +/* Inclusion of header files: */ +/* -------------------------- */ + +#include +#include +#include + +#include "tp_magic_api.h" +#include "SDL_image.h" +#include "SDL_mixer.h" + +enum { + TOOL_HALFTONE, + NUM_TOOLS +}; + + +const char * snd_filenames[NUM_TOOLS] = { + "halftone.wav", +}; + +const char * icon_filenames[NUM_TOOLS] = { + "halftone.png", +}; + +const char * names[NUM_TOOLS] = { + gettext_noop("Halftone"), +}; + +const char * descs[NUM_TOOLS] = { + gettext_noop("Click and drag to turn your drawing into a newspaper."), +}; + +Mix_Chunk * snd_effect[NUM_TOOLS]; + +void halftone_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 halftone_line_callback(void * ptr, int which, + SDL_Surface * canvas, SDL_Surface * snapshot, + int x, int y); + + +Uint32 halftone_api_version(void) +{ + return(TP_MAGIC_API_VERSION); +} + +int halftone_init(magic_api * api) +{ + int i; + char fname[1024]; + + for (i = 0; i < NUM_TOOLS; i++) + { + snprintf(fname, sizeof(fname), + "%s/sounds/magic/%s", + api->data_directory, snd_filenames[i]); + +/* FIXME snd_effect[i] = Mix_LoadWAV(fname); */ + } + + return(1); +} + +int halftone_get_tool_count(magic_api * api) +{ + return(NUM_TOOLS); +} + +SDL_Surface * halftone_get_icon(magic_api * api, int which) +{ + char fname[1024]; + + snprintf(fname, sizeof(fname), "%s/images/magic/%s.png", + api->data_directory, icon_filenames[which]); + + return(IMG_Load(fname)); +} + +char * halftone_get_name(magic_api * api, int which) +{ + const char * our_name_english; + const char * our_name_localized; + + our_name_english = names[which]; + our_name_localized = gettext(our_name_english); + + return(strdup(our_name_localized)); +} + +char * halftone_get_description(magic_api * api, int which, int mode) +{ + const char * our_desc_english; + const char * our_desc_localized; + + our_desc_english = descs[which]; + our_desc_localized = gettext(our_desc_english); + + return(strdup(our_desc_localized)); +} + +int halftone_requires_colors(magic_api * api, int which) +{ + return 0; +} + +int halftone_modes(magic_api * api, int which) +{ + return MODE_PAINT; +} + +void halftone_shutdown(magic_api * api) +{ + int i; + + for (i = 0; i < NUM_TOOLS; i++) + Mix_FreeChunk(snd_effect[i]); +} + +void halftone_click(magic_api * api, int which, int mode, + SDL_Surface * canvas, SDL_Surface * snapshot, + int x, int y, SDL_Rect * update_rect) +{ + halftone_drag(api, which, canvas, snapshot, x, y, x, y, update_rect); +} + +void halftone_drag(magic_api * api, int which, SDL_Surface * canvas, + SDL_Surface * snapshot, int ox, int oy, int x, int y, + SDL_Rect * update_rect) +{ + api->line((void *) api, which, canvas, snapshot, + ox, oy, x, y, 1, halftone_line_callback); + + if (ox > x) { int tmp = ox; ox = x; x = tmp; } + if (oy > y) { int tmp = oy; oy = y; y = tmp; } + + update_rect->x = ox - 16; + update_rect->y = oy - 16; + update_rect->w = (x + 16) - update_rect->x; + update_rect->h = (y + 16) - update_rect->h; + +/* FIXME + api->playsound(snd_effect[which], + (x * 255) / canvas->w, // pan + 255); // distance +*/ +} + +enum { + CHAN_CYAN, + CHAN_MAGENTA, + CHAN_YELLOW, + CHAN_BLACK, + NUM_CHANS +}; + +Uint8 chan_colors[NUM_CHANS][3] = { + { 0, 255, 255 }, + { 255, 0, 255 }, + { 255, 255, 0 }, + { 0, 0, 0 } +}; + +int chan_angles[NUM_CHANS] = { + 100, + 15, + 0, + 45 +}; + +void halftone_release(magic_api * api, int which, + SDL_Surface * canvas, SDL_Surface * snapshot, + int x, int y, SDL_Rect * update_rect) +{ +} + +void halftone_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b) +{ +} + +void halftone_line_callback(void * ptr, int which, + SDL_Surface * canvas, SDL_Surface * snapshot, + int x, int y) +{ + Uint8 r, g, b; + Uint32 total_r, total_g, total_b; + Uint32 pixel; + int xx, yy, xxx, yyy, channel; + magic_api * api = (magic_api *) ptr; + + for (xx = x - 16; xx < x + 16; xx = xx + 4) { + for (yy = y - 16; yy < y + 16; yy = yy + 4) { + total_r = total_g = total_b = 0; + for (xxx = xx; xxx < xx + 4; xxx++) { + for (yyy = xx; yyy < xx + 4; yyy++) { + SDL_GetRGB(api->getpixel(canvas, x, y), canvas->format, &r, &g, &b); + total_r += r; + total_g += g; + total_b += b; + } + } + total_r /= 16; + total_g /= 16; + total_b /= 16; + + for (channel = 0; channel < NUM_CHANS; channel++) { + + } + + pixel = SDL_MapRGB(canvas->format, total_r, total_g, total_b); + for (xxx = xx; xxx < xx + 4; xxx++) { + for (yyy = yy; yyy < yy + 4; yyy++) { + api->putpixel(canvas, xxx, yyy, pixel); + } + } + } + } +} + +void halftone_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas) +{ +} + +void halftone_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas) +{ +} diff --git a/magic/src/smudge.c b/magic/src/smudge.c index 2f7268f61..6db328dba 100644 --- a/magic/src/smudge.c +++ b/magic/src/smudge.c @@ -7,7 +7,7 @@ Smudge by Albert Cahalan Wet Paint addition by Bill Kendrick - Copyright (c) 2002-2009 + Copyright (c) 2002-2011 http://www.tuxpaint.org/ This program is free software; you can redistribute it and/or modify @@ -115,7 +115,8 @@ static void do_smudge(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * { SDL_GetRGB(api->getpixel(last, x + xx, y + yy), last->format, &r, &g, &b); - strength = (abs(xx * yy) / 8) + 6; + //strength = (abs(xx * yy) / 8) + 6; + strength = (abs(xx * yy) / 8) + 1; api->putpixel(canvas, x + xx, y +yy, SDL_MapRGB(canvas->format, (smudge_r + r * strength) / (strength + 1), (smudge_g + g * strength) / (strength + 1),