indent halftone.c
This commit is contained in:
parent
fb1e2a092d
commit
3bfbc3e741
1 changed files with 167 additions and 149 deletions
|
|
@ -16,7 +16,8 @@
|
|||
#include "SDL_image.h"
|
||||
#include "SDL_mixer.h"
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOOL_HALFTONE,
|
||||
NUM_TOOLS
|
||||
};
|
||||
|
|
@ -45,11 +46,8 @@ static SDL_Surface * canvas_backup, * square;
|
|||
/* Function Prototypes: */
|
||||
|
||||
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);
|
||||
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);
|
||||
int halftone_init(magic_api * api);
|
||||
int halftone_get_tool_count(magic_api * api);
|
||||
|
|
@ -60,11 +58,9 @@ int halftone_requires_colors(magic_api * api, int which);
|
|||
int halftone_modes(magic_api * api, int which);
|
||||
void halftone_shutdown(magic_api * api);
|
||||
void halftone_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||
void halftone_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
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_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
void halftone_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
|
|
@ -85,12 +81,11 @@ int halftone_init(magic_api * api)
|
|||
|
||||
for (i = 0; i < NUM_TOOLS; i++)
|
||||
{
|
||||
snprintf(fname, sizeof(fname),
|
||||
"%s/sounds/magic/%s",
|
||||
api->data_directory, snd_filenames[i]);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, snd_filenames[i]);
|
||||
|
||||
snd_effect[i] = Mix_LoadWAV(fname);
|
||||
if (snd_effect[i] == NULL) {
|
||||
if (snd_effect[i] == NULL)
|
||||
{
|
||||
SDL_FreeSurface(canvas_backup);
|
||||
SDL_FreeSurface(square);
|
||||
return (0);
|
||||
|
|
@ -110,8 +105,7 @@ SDL_Surface * halftone_get_icon(magic_api * api, int which)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/%s",
|
||||
api->data_directory, icon_filenames[which]);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/%s", api->data_directory, icon_filenames[which]);
|
||||
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
|
@ -160,33 +154,42 @@ void halftone_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
|||
}
|
||||
|
||||
void halftone_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
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)
|
||||
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, 4, halftone_line_callback);
|
||||
api->line((void *)api, which, canvas, snapshot, ox, oy, x, y, 4, halftone_line_callback);
|
||||
|
||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
||||
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;
|
||||
|
||||
api->playsound(snd_effect[which],
|
||||
(x * 255) / canvas->w, // pan
|
||||
api->playsound(snd_effect[which], (x * 255) / canvas->w, // pan
|
||||
255); // distance
|
||||
}
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
CHAN_CYAN,
|
||||
CHAN_MAGENTA,
|
||||
CHAN_YELLOW,
|
||||
|
|
@ -210,9 +213,7 @@ int chan_angles[NUM_CHANS] = {
|
|||
|
||||
void halftone_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)
|
||||
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -222,8 +223,7 @@ void halftone_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUS
|
|||
}
|
||||
|
||||
void halftone_line_callback(void *ptr, int which 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)
|
||||
{
|
||||
Uint8 r, g, b, or, og, ob;
|
||||
Uint32 total_r, total_g, total_b;
|
||||
|
|
@ -240,15 +240,23 @@ void halftone_line_callback(void * ptr, int which ATTRIBUTE_UNUSED,
|
|||
x = ((x / 8) - 1) * 8;
|
||||
y = ((y / 8) - 1) * 8;
|
||||
|
||||
if (api->touched(x, y)) { return; }
|
||||
if (api->touched(x, y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (xx = 0; xx < 16; xx = xx + 4) {
|
||||
for (yy = 0; yy < 16; yy = yy + 4) {
|
||||
for (xx = 0; xx < 16; xx = xx + 4)
|
||||
{
|
||||
for (yy = 0; yy < 16; yy = yy + 4)
|
||||
{
|
||||
/* Get avg color around the mouse */
|
||||
total_r = total_g = total_b = 0;
|
||||
for (xxx = 0; xxx < 4; xxx++) {
|
||||
for (yyy = 0; yyy < 4; yyy++) {
|
||||
SDL_GetRGB(api->getpixel(canvas_backup, x + xx + xxx, y + yy + yyy), canvas_backup->format, &r, &g, &b);
|
||||
for (xxx = 0; xxx < 4; xxx++)
|
||||
{
|
||||
for (yyy = 0; yyy < 4; yyy++)
|
||||
{
|
||||
SDL_GetRGB(api->getpixel(canvas_backup, x + xx + xxx, y + yy + yyy), canvas_backup->format, &r, &g,
|
||||
&b);
|
||||
total_r += r;
|
||||
total_g += g;
|
||||
total_b += b;
|
||||
|
|
@ -262,13 +270,16 @@ void halftone_line_callback(void * ptr, int which ATTRIBUTE_UNUSED,
|
|||
halftone_rgb2cmyk(total_r, total_g, total_b, cmyk);
|
||||
|
||||
/* Draw C, M, Y and K blobs into our 'square' surface */
|
||||
for (channel = 0; channel < NUM_CHANS; channel++) {
|
||||
for (channel = 0; channel < NUM_CHANS; channel++)
|
||||
{
|
||||
r = chan_colors[channel][0];
|
||||
g = chan_colors[channel][1];
|
||||
b = chan_colors[channel][2];
|
||||
|
||||
for (xxx = 0; xxx < 8; xxx++) {
|
||||
for (yyy = 0; yyy < 8; yyy++) {
|
||||
for (xxx = 0; xxx < 8; xxx++)
|
||||
{
|
||||
for (yyy = 0; yyy < 8; yyy++)
|
||||
{
|
||||
/* A circle blob, radius based upon channel (C, M, Y or K) strength for this color */
|
||||
|
||||
/* FIXME: Base it upon this channel's angle! -bjk 2011.07.17 */
|
||||
|
|
@ -278,13 +289,17 @@ void halftone_line_callback(void * ptr, int which ATTRIBUTE_UNUSED,
|
|||
sqx = (xx + ox) % 16;
|
||||
sqy = (yy + oy) % 16;
|
||||
|
||||
if (api->in_circle(xxx - 4, yyy - 4, cmyk[channel] * 6.0)) {
|
||||
if (api->in_circle(xxx - 4, yyy - 4, cmyk[channel] * 6.0))
|
||||
{
|
||||
SDL_GetRGB(api->getpixel(square, sqx, sqy), square->format, &or, &og, &ob);
|
||||
|
||||
if (or == 255 && og == 255 && ob == 255) {
|
||||
if (or == 255 && og == 255 && ob == 255)
|
||||
{
|
||||
/* If it's just white, put full color down */
|
||||
pixel = SDL_MapRGB(square->format, r, g, b);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Otherwise, blend a little */
|
||||
pixel = SDL_MapRGB(square->format, (r + or) / 2, (g + og) / 2, (b + ob) / 2);
|
||||
}
|
||||
|
|
@ -303,14 +318,17 @@ void halftone_line_callback(void * ptr, int which ATTRIBUTE_UNUSED,
|
|||
SDL_BlitSurface(square, NULL, canvas, &dest);
|
||||
}
|
||||
|
||||
void halftone_switchin(magic_api * api, int which ATTRIBUTE_UNUSED,
|
||||
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
|
||||
void halftone_switchin(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
|
||||
{
|
||||
if (canvas_backup == NULL)
|
||||
canvas_backup = SDL_CreateRGBSurface(SDL_ANYFORMAT, api->canvas_w, api->canvas_h, canvas->format->BitsPerPixel, canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
|
||||
canvas_backup =
|
||||
SDL_CreateRGBSurface(SDL_ANYFORMAT, api->canvas_w, api->canvas_h, canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
|
||||
|
||||
if (square == NULL)
|
||||
square = SDL_CreateRGBSurface(SDL_ANYFORMAT, 16, 16, canvas->format->BitsPerPixel, canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
|
||||
square =
|
||||
SDL_CreateRGBSurface(SDL_ANYFORMAT, 16, 16, canvas->format->BitsPerPixel, canvas->format->Rmask,
|
||||
canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
|
||||
|
||||
/* FIXME: What to do if they come back NULL!? :( */
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue