Ran through: astyle --unpad-paren --pad-oper --pad-header --add-brackets --style=allman --delete-empty-lines --break-blocks

This commit is contained in:
William Kendrick 2014-08-05 07:40:15 +00:00
parent 1a31c28d40
commit 5d164e8254
2 changed files with 398 additions and 345 deletions

View file

@ -244,8 +244,8 @@ DEFS:=-DVER_DATE=\"$(VER_DATE)\" -DVER_VERSION=\"$(VER_VERSION)\" \
$(NOSOUNDFLAG) $(NOSVGFLAG) $(OLDSVGFLAG) $(NOPANGOFLAG) \ $(NOSOUNDFLAG) $(NOSVGFLAG) $(OLDSVGFLAG) $(NOPANGOFLAG) \
$(MAEMOFLAG) $(MAEMOFLAG)
DEBUG_FLAGS:= #DEBUG_FLAGS:=
#DEBUG_FLAGS:=-g DEBUG_FLAGS:=-g
MOUSE_CFLAGS:=-Isrc/$(MOUSEDIR) -D$(CURSOR_SHAPES)_CURSOR_SHAPES MOUSE_CFLAGS:=-Isrc/$(MOUSEDIR) -D$(CURSOR_SHAPES)_CURSOR_SHAPES

View file

@ -60,7 +60,7 @@ static void mosaic_shaped_fill(void * ptr_to_api, int which, SDL_Surface * canva
Uint32 mosaic_shaped_api_version(void); Uint32 mosaic_shaped_api_version(void);
int mosaic_shaped_init(magic_api * api); int mosaic_shaped_init(magic_api * api);
int mosaic_shaped_get_tool_count(magic_api * api); int mosaic_shaped_get_tool_count(magic_api * api);
SDL_Surface * mosaic_shaped_get_icon(magic_api * api, int which); SDL_Surface * mosaic_shaped_get_icon(magic_api * api, int which);
char * mosaic_shaped_get_name(magic_api * api, int which); char * mosaic_shaped_get_name(magic_api * api, int which);
char * mosaic_shaped_get_description(magic_api * api, int which, int mode); char * mosaic_shaped_get_description(magic_api * api, int which, int mode);
@ -89,12 +89,12 @@ void mosaic_shaped_switchout(magic_api * api, int which, int mode, SDL_Surface *
int mosaic_shaped_modes(magic_api * api, int which); int mosaic_shaped_modes(magic_api * api, int which);
int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc,int x,int y, int fill_edge, int fill_tile, int size, Uint32 color); int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc, int x, int y, int fill_edge, int fill_tile, int size, Uint32 color);
static const int mosaic_shaped_AMOUNT= 300; static const int mosaic_shaped_AMOUNT = 300;
static const int mosaic_shaped_RADIUS = 16; static const int mosaic_shaped_RADIUS = 16;
static const double mosaic_shaped_SHARPEN = 1.0; static const double mosaic_shaped_SHARPEN = 1.0;
Uint8 * mosaic_shaped_counted; Uint8 * mosaic_shaped_counted;
@ -108,7 +108,8 @@ Uint32 pixel_average, black, white;
api->data_directory points to the local user directory instead of the system wide instalation. */ api->data_directory points to the local user directory instead of the system wide instalation. */
char api_data_directory_at_init[1024]; char api_data_directory_at_init[1024];
enum { enum
{
TOOL_SQUARE, TOOL_SQUARE,
TOOL_HEX, TOOL_HEX,
TOOL_IRREGULAR, TOOL_IRREGULAR,
@ -120,107 +121,129 @@ static SDL_Surface * canvas_shaped;
static SDL_Surface * canvas_back; static SDL_Surface * canvas_back;
static SDL_Surface * mosaic_shaped_pattern; static SDL_Surface * mosaic_shaped_pattern;
const char * mosaic_shaped_snd_filenames[mosaic_shaped_NUM_TOOLS] = { const char * mosaic_shaped_snd_filenames[mosaic_shaped_NUM_TOOLS] =
{
"mosaic_shaped_square.ogg", "mosaic_shaped_square.ogg",
"mosaic_shaped_hex.ogg", "mosaic_shaped_hex.ogg",
"mosaic_shaped_irregular.ogg", /* FIXME */ /*what's problem?*/ "mosaic_shaped_irregular.ogg", /* FIXME */ /*what's problem?*/
}; };
const char * mosaic_shaped_icon_filenames[mosaic_shaped_NUM_TOOLS] = { const char * mosaic_shaped_icon_filenames[mosaic_shaped_NUM_TOOLS] =
{
"mosaic_shaped_square.png", "mosaic_shaped_square.png",
"mosaic_shaped_hex.png", "mosaic_shaped_hex.png",
"mosaic_shaped_irregular.png", "mosaic_shaped_irregular.png",
}; };
const char * mosaic_shaped_pattern_filenames[mosaic_shaped_NUM_TOOLS] = { const char * mosaic_shaped_pattern_filenames[mosaic_shaped_NUM_TOOLS] =
{
"mosaic_shaped_square_pattern.png", "mosaic_shaped_square_pattern.png",
"mosaic_shaped_hex_pattern.png", "mosaic_shaped_hex_pattern.png",
"mosaic_shaped_irregular_pattern.png", "mosaic_shaped_irregular_pattern.png",
}; };
const char * mosaic_shaped_names[mosaic_shaped_NUM_TOOLS] = { const char * mosaic_shaped_names[mosaic_shaped_NUM_TOOLS] =
{
gettext_noop("Square Mosaic"), gettext_noop("Square Mosaic"),
gettext_noop("Hexagon Mosaic"), gettext_noop("Hexagon Mosaic"),
gettext_noop("Irregular Mosaic"), gettext_noop("Irregular Mosaic"),
}; };
const char * mosaic_shaped_descs[mosaic_shaped_NUM_TOOLS][2] = { const char * mosaic_shaped_descs[mosaic_shaped_NUM_TOOLS][2] =
{gettext_noop("Click and move the mouse to add a square mosaic to parts of your picture."), {
gettext_noop("Click to add a square mosaic to your entire picture."),}, {
gettext_noop("Click and move the mouse to add a square mosaic to parts of your picture."),
gettext_noop("Click to add a square mosaic to your entire picture."),
},
{gettext_noop("Click and move the mouse to add a hexagonal mosaic to parts of your picture."), {
gettext_noop("Click to add a hexagonal mosaic to your entire picture."),}, gettext_noop("Click and move the mouse to add a hexagonal mosaic to parts of your picture."),
gettext_noop("Click to add a hexagonal mosaic to your entire picture."),
},
{gettext_noop("Click and move the mouse to add an irregular mosaic to parts of your picture."), {
gettext_noop("Click to add an irregular mosaic to your entire picture."),}, gettext_noop("Click and move the mouse to add an irregular mosaic to parts of your picture."),
gettext_noop("Click to add an irregular mosaic to your entire picture."),
},
}; };
Uint32 mosaic_shaped_api_version(void) { return(TP_MAGIC_API_VERSION); } Uint32 mosaic_shaped_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
//Load sounds //Load sounds
int mosaic_shaped_init(magic_api * api){ int mosaic_shaped_init(magic_api * api)
{
int i; int i;
char fname[1024]; char fname[1024];
mosaic_shaped_pattern = NULL; mosaic_shaped_pattern = NULL;
for (i = 0; i < mosaic_shaped_NUM_TOOLS; i++){
for (i = 0; i < mosaic_shaped_NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, mosaic_shaped_snd_filenames[i]); snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, mosaic_shaped_snd_filenames[i]);
mosaic_shaped_snd_effect[i] = Mix_LoadWAV(fname); mosaic_shaped_snd_effect[i] = Mix_LoadWAV(fname);
} }
snprintf(api_data_directory_at_init, sizeof(api_data_directory_at_init), api->data_directory); snprintf(api_data_directory_at_init, sizeof(api_data_directory_at_init), api->data_directory);
return(1); return (1);
} }
int mosaic_shaped_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){ int mosaic_shaped_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
return(mosaic_shaped_NUM_TOOLS); {
return (mosaic_shaped_NUM_TOOLS);
} }
// Load our icons: // Load our icons:
SDL_Surface * mosaic_shaped_get_icon(magic_api * api, int which){ SDL_Surface * mosaic_shaped_get_icon(magic_api * api, int which)
{
char fname[1024]; char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, mosaic_shaped_icon_filenames[which]); snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, mosaic_shaped_icon_filenames[which]);
return(IMG_Load(fname)); return (IMG_Load(fname));
} }
// Return our names, localized: // Return our names, localized:
char * mosaic_shaped_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){ char * mosaic_shaped_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
return(strdup(gettext_noop(mosaic_shaped_names[which]))); {
return (strdup(gettext_noop(mosaic_shaped_names[which])));
} }
// Return our descriptions, localized: // Return our descriptions, localized:
char * mosaic_shaped_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode){ char * mosaic_shaped_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
return(strdup(gettext_noop(mosaic_shaped_descs[which][mode-1]))); {
return (strdup(gettext_noop(mosaic_shaped_descs[which][mode - 1])));
} }
//Calculates the grey scale value for a rgb pixel //Calculates the grey scale value for a rgb pixel
static int mosaic_shaped_grey(Uint8 r1,Uint8 g1,Uint8 b1){ static int mosaic_shaped_grey(Uint8 r1, Uint8 g1, Uint8 b1)
return 0.3*r1+.59*g1+0.11*b1; {
return 0.3 * r1 + .59 * g1 + 0.11 * b1;
} }
// Do the effect for the full image // Do the effect for the full image
static void do_mosaic_shaped_full(void * ptr, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED){ static void do_mosaic_shaped_full(void * ptr, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
int i, j, size; int i, j, size;
Uint32 mosaic_shaped_color; Uint32 mosaic_shaped_color;
magic_api * api = (magic_api *) ptr; magic_api * api = (magic_api *) ptr;
mosaic_shaped_color = SDL_MapRGBA(canvas->format, mosaic_shaped_r, mosaic_shaped_g, mosaic_shaped_b, 0); mosaic_shaped_color = SDL_MapRGBA(canvas->format, mosaic_shaped_r, mosaic_shaped_g, mosaic_shaped_b, 0);
for( i = 3; i < canvas->w - 3; i +=2) for (i = 3; i < canvas->w - 3; i += 2)
{ {
api->playsound(mosaic_shaped_snd_effect[which], 128, 255); api->playsound(mosaic_shaped_snd_effect[which], 128, 255);
api->update_progress_bar(); api->update_progress_bar();
for (j = 3; j < canvas->h - 3; j +=2) for (j = 3; j < canvas->h - 3; j += 2)
{ {
if(!mosaic_shaped_done[canvas->w * j + i]) if (!mosaic_shaped_done[canvas->w * j + i])
if (!mosaic_shaped_counted[canvas->w * j + i]) if (!mosaic_shaped_counted[canvas->w * j + i])
if(api->getpixel(canvas_shaped, i, j) != black ) if (api->getpixel(canvas_shaped, i, j) != black)
{ {
mosaic_shaped_average_r = 0; mosaic_shaped_average_r = 0;
mosaic_shaped_average_g = 0; mosaic_shaped_average_g = 0;
mosaic_shaped_average_b = 0; mosaic_shaped_average_b = 0;
mosaic_shaped_average_count = 0; mosaic_shaped_average_count = 0;
scan_fill(api, canvas, canvas_shaped, i, j, 1, 0, 1, mosaic_shaped_color); scan_fill(api, canvas, canvas_shaped, i, j, 1, 0, 1, mosaic_shaped_color);
if (mosaic_shaped_average_count > 0) if (mosaic_shaped_average_count > 0)
@ -243,13 +266,18 @@ static void mosaic_shaped_fill(void * ptr_to_api, int which ATTRIBUTE_UNUSED, SD
int size; int size;
magic_api * api = (magic_api *) ptr_to_api; magic_api * api = (magic_api *) ptr_to_api;
x = clamp(0, x, canvas->w - 1); x = clamp(0, x, canvas->w - 1);
y = clamp(0,y,canvas->h - 1); y = clamp(0, y, canvas->h - 1);
mosaic_shaped_color = SDL_MapRGBA(canvas->format, mosaic_shaped_r, mosaic_shaped_g, mosaic_shaped_b, 0); mosaic_shaped_color = SDL_MapRGBA(canvas->format, mosaic_shaped_r, mosaic_shaped_g, mosaic_shaped_b, 0);
mosaic_shaped_average_r = 0; mosaic_shaped_average_r = 0;
mosaic_shaped_average_g = 0; mosaic_shaped_average_g = 0;
mosaic_shaped_average_b = 0; mosaic_shaped_average_b = 0;
mosaic_shaped_average_count = 0; mosaic_shaped_average_count = 0;
if (api->getpixel(canvas_shaped, x, y) == black) return;
if (api->getpixel(canvas_shaped, x, y) == black)
{
return;
}
scan_fill(api, canvas, canvas_shaped, x, y, 1, 0, 1, mosaic_shaped_color); scan_fill(api, canvas, canvas_shaped, x, y, 1, 0, 1, mosaic_shaped_color);
if (mosaic_shaped_average_count > 0) if (mosaic_shaped_average_count > 0)
@ -264,10 +292,9 @@ static void mosaic_shaped_fill(void * ptr_to_api, int which ATTRIBUTE_UNUSED, SD
// Affect the canvas on drag: // Affect the canvas on drag:
void mosaic_shaped_drag(magic_api * api, int which, SDL_Surface * canvas, void mosaic_shaped_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect){ SDL_Rect * update_rect)
{
api->line(api, which, canvas, last, ox, oy, x, y, 1, mosaic_shaped_fill); api->line(api, which, canvas, last, ox, oy, x, y, 1, mosaic_shaped_fill);
update_rect->x = min(ox, x) - mosaic_shaped_pattern->w; update_rect->x = min(ox, x) - mosaic_shaped_pattern->w;
update_rect->y = min(oy, y) - mosaic_shaped_pattern->h; update_rect->y = min(oy, y) - mosaic_shaped_pattern->h;
update_rect->w = max(ox, x) + mosaic_shaped_pattern->w - update_rect->x; update_rect->w = max(ox, x) + mosaic_shaped_pattern->w - update_rect->x;
@ -278,23 +305,21 @@ void mosaic_shaped_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click: // Affect the canvas on click:
void mosaic_shaped_click(magic_api * api, int which, int mode, void mosaic_shaped_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect){ int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_FULLSCREEN) if (mode == MODE_FULLSCREEN)
{ {
update_rect->x = 0; update_rect->x = 0;
update_rect->y = 0; update_rect->y = 0;
update_rect->w = canvas->w; update_rect->w = canvas->w;
update_rect->h = canvas->h; update_rect->h = canvas->h;
do_mosaic_shaped_full(api, canvas, last, which, update_rect); do_mosaic_shaped_full(api, canvas, last, which, update_rect);
api->playsound(mosaic_shaped_snd_effect[which], 128, 255); api->playsound(mosaic_shaped_snd_effect[which], 128, 255);
} }
else else
{
mosaic_shaped_drag(api, which, canvas, last, x, y, x, y, update_rect); mosaic_shaped_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
} }
// Affect the canvas on release: // Affect the canvas on release:
@ -309,8 +334,11 @@ void mosaic_shaped_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{ {
//Clean up sounds //Clean up sounds
int i; int i;
for(i=0; i<mosaic_shaped_NUM_TOOLS; i++){
if(mosaic_shaped_snd_effect[i] != NULL){ for (i = 0; i < mosaic_shaped_NUM_TOOLS; i++)
{
if (mosaic_shaped_snd_effect[i] != NULL)
{
Mix_FreeChunk(mosaic_shaped_snd_effect[i]); Mix_FreeChunk(mosaic_shaped_snd_effect[i]);
} }
} }
@ -333,40 +361,45 @@ int mosaic_shaped_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which AT
//Sharpen a pixel //Sharpen a pixel
static void mosaic_shaped_sharpen_pixel(void * ptr, static void mosaic_shaped_sharpen_pixel(void * ptr,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last,
int x, int y){ int x, int y)
{
magic_api * api = (magic_api *) ptr; magic_api * api = (magic_api *) ptr;
Uint8 r1, g1, b1; Uint8 r1, g1, b1;
int grey; int grey;
int i,j; int i, j;
double sobel_1=0,sobel_2=0; double sobel_1 = 0, sobel_2 = 0;
double temp; double temp;
//Sobel weighting masks //Sobel weighting masks
const int sobel_weights_1[3][3] = { {1,2,1}, const int sobel_weights_1[3][3] = { {1, 2, 1},
{0,0,0}, {0, 0, 0},
{-1,-2,-1}}; { -1, -2, -1}
const int sobel_weights_2[3][3] = { {-1,0,1}, };
{-2,0,2}, const int sobel_weights_2[3][3] = { { -1, 0, 1},
{-1,0,1}}; { -2, 0, 2},
{ -1, 0, 1}
};
sobel_1 = 0;
sobel_2 = 0;
sobel_1=0; for (i = -1; i < 2; i++)
sobel_2=0; {
for (i=-1;i<2;i++){ for (j = -1; j < 2; j++)
for(j=-1; j<2; j++){ {
//No need to check if inside canvas, getpixel does it for us. //No need to check if inside canvas, getpixel does it for us.
SDL_GetRGB(api->getpixel(last, x+i, y+j), last->format, &r1, &g1, &b1); SDL_GetRGB(api->getpixel(last, x + i, y + j), last->format, &r1, &g1, &b1);
grey = mosaic_shaped_grey(r1,g1,b1); grey = mosaic_shaped_grey(r1, g1, b1);
sobel_1 += grey * sobel_weights_1[i+1][j+1]; sobel_1 += grey * sobel_weights_1[i + 1][j + 1];
sobel_2 += grey * sobel_weights_2[i+1][j+1]; sobel_2 += grey * sobel_weights_2[i + 1][j + 1];
} }
} }
temp = sqrt(sobel_1*sobel_1 + sobel_2*sobel_2); temp = sqrt(sobel_1 * sobel_1 + sobel_2 * sobel_2);
temp = (temp/1443)*255.0; temp = (temp / 1443) * 255.0;
if (temp > 25) if (temp > 25)
{
api->putpixel(canvas_shaped, x, y, SDL_MapRGBA(canvas_shaped->format, 0, 0, 0, 0)); api->putpixel(canvas_shaped, x, y, SDL_MapRGBA(canvas_shaped->format, 0, 0, 0, 0));
}
} }
@ -379,8 +412,8 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
SDL_Surface * surf_aux; SDL_Surface * surf_aux;
Uint32 amask; Uint32 amask;
char fname[1024]; char fname[1024];
mosaic_shaped_counted = (Uint8 *) malloc(sizeof(Uint8) * (canvas->w * canvas->h)); mosaic_shaped_counted = (Uint8 *) malloc(sizeof(Uint8) * (canvas->w * canvas->h));
if (mosaic_shaped_counted == NULL) if (mosaic_shaped_counted == NULL)
{ {
fprintf(stderr, "\nError: Can't build drawing touch mask!\n"); fprintf(stderr, "\nError: Can't build drawing touch mask!\n");
@ -388,6 +421,7 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
} }
mosaic_shaped_done = (Uint8 *) malloc(sizeof(Uint8) * (canvas->w * canvas->h)); mosaic_shaped_done = (Uint8 *) malloc(sizeof(Uint8) * (canvas->w * canvas->h));
if (mosaic_shaped_done == NULL) if (mosaic_shaped_done == NULL)
{ {
fprintf(stderr, "\nError: Can't build drawing touch mask!\n"); fprintf(stderr, "\nError: Can't build drawing touch mask!\n");
@ -397,7 +431,6 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
amask = ~(canvas->format->Rmask | amask = ~(canvas->format->Rmask |
canvas->format->Gmask | canvas->format->Gmask |
canvas->format->Bmask); canvas->format->Bmask);
canvas_shaped = SDL_CreateRGBSurface(SDL_SWSURFACE, canvas_shaped = SDL_CreateRGBSurface(SDL_SWSURFACE,
canvas->w, canvas->w,
canvas->h, canvas->h,
@ -405,7 +438,6 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
canvas->format->Rmask, canvas->format->Rmask,
canvas->format->Gmask, canvas->format->Gmask,
canvas->format->Bmask, amask); canvas->format->Bmask, amask);
surf_aux = SDL_CreateRGBSurface(SDL_SWSURFACE, surf_aux = SDL_CreateRGBSurface(SDL_SWSURFACE,
canvas->w + 10, canvas->w + 10,
canvas->h + 10, canvas->h + 10,
@ -414,29 +446,29 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
canvas->format->Gmask, canvas->format->Gmask,
canvas->format->Bmask, amask); canvas->format->Bmask, amask);
snprintf(fname, sizeof(fname), "%simages/magic/%s", api_data_directory_at_init, mosaic_shaped_pattern_filenames[which]); snprintf(fname, sizeof(fname), "%simages/magic/%s", api_data_directory_at_init, mosaic_shaped_pattern_filenames[which]);
mosaic_shaped_pattern = IMG_Load(fname);
mosaic_shaped_pattern = IMG_Load(fname);
rect.w = mosaic_shaped_pattern->w; rect.w = mosaic_shaped_pattern->w;
rect.h = mosaic_shaped_pattern->h; rect.h = mosaic_shaped_pattern->h;
for( i = 0; i < surf_aux->w; i += mosaic_shaped_pattern->w)
for( j = 0; j < surf_aux->h; j += mosaic_shaped_pattern->h) for (i = 0; i < surf_aux->w; i += mosaic_shaped_pattern->w)
for (j = 0; j < surf_aux->h; j += mosaic_shaped_pattern->h)
{ {
rect.x = i; rect.x = i;
rect.y = j; rect.y = j;
SDL_BlitSurface(mosaic_shaped_pattern, NULL, surf_aux, &rect); SDL_BlitSurface(mosaic_shaped_pattern, NULL, surf_aux, &rect);
} }
if(which == TOOL_IRREGULAR) if (which == TOOL_IRREGULAR)
{
deform(api, surf_aux); deform(api, surf_aux);
}
SDL_SetAlpha(surf_aux, 0 , SDL_ALPHA_OPAQUE); SDL_SetAlpha(surf_aux, 0 , SDL_ALPHA_OPAQUE);
SDL_BlitSurface(surf_aux, NULL, canvas_shaped, NULL); SDL_BlitSurface(surf_aux, NULL, canvas_shaped, NULL);
SDL_FreeSurface(surf_aux); SDL_FreeSurface(surf_aux);
black = SDL_MapRGBA(canvas->format, 0, 0, 0, 0); black = SDL_MapRGBA(canvas->format, 0, 0, 0, 0);
white = SDL_MapRGBA(canvas->format, 255, 255, 255, 0); white = SDL_MapRGBA(canvas->format, 255, 255, 255, 0);
/* Two black lines at the edges */ /* Two black lines at the edges */
for (i = 0; i < canvas->w; i++) for (i = 0; i < canvas->w; i++)
{ {
@ -454,7 +486,6 @@ mosaic_shaped_pattern = IMG_Load(fname);
api->putpixel(canvas_shaped, canvas->w - 2, j, black); api->putpixel(canvas_shaped, canvas->w - 2, j, black);
} }
/* A copy of canvas at switchin, will be used to draw from it as snapshot changes at each click */ /* A copy of canvas at switchin, will be used to draw from it as snapshot changes at each click */
canvas_back = SDL_CreateRGBSurface(SDL_SWSURFACE, canvas_back = SDL_CreateRGBSurface(SDL_SWSURFACE,
canvas->w, canvas->w,
@ -463,12 +494,13 @@ mosaic_shaped_pattern = IMG_Load(fname);
canvas->format->Rmask, canvas->format->Rmask,
canvas->format->Gmask, canvas->format->Gmask,
canvas->format->Bmask, amask); canvas->format->Bmask, amask);
SDL_BlitSurface(canvas, NULL, canvas_back, NULL); SDL_BlitSurface(canvas, NULL, canvas_back, NULL);
if(which != TOOL_SQUARE) /* The pattern for square is small enouth to not need an additional shape */ if (which != TOOL_SQUARE) /* The pattern for square is small enouth to not need an additional shape */
for (y = 0; y < canvas->h; y++){ for (y = 0; y < canvas->h; y++)
for (x=0; x < canvas->w; x++){ {
for (x = 0; x < canvas->w; x++)
{
mosaic_shaped_sharpen_pixel(api, canvas_shaped, canvas, x, y); mosaic_shaped_sharpen_pixel(api, canvas_shaped, canvas, x, y);
} }
} }
@ -482,12 +514,12 @@ void mosaic_shaped_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBU
SDL_FreeSurface(canvas_shaped); SDL_FreeSurface(canvas_shaped);
SDL_FreeSurface(canvas_back); SDL_FreeSurface(canvas_back);
SDL_FreeSurface(mosaic_shaped_pattern); SDL_FreeSurface(mosaic_shaped_pattern);
free (mosaic_shaped_counted); free(mosaic_shaped_counted);
} }
int mosaic_shaped_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) int mosaic_shaped_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{ {
return(MODE_PAINT|MODE_FULLSCREEN); return (MODE_PAINT | MODE_FULLSCREEN);
} }
void reset_counter(SDL_Surface * canvas, Uint8 * counter) void reset_counter(SDL_Surface * canvas, Uint8 * counter)
@ -496,27 +528,40 @@ void reset_counter(SDL_Surface * canvas, Uint8 * counter)
for (j = 0; j < canvas->h; j++) for (j = 0; j < canvas->h; j++)
for (i = 0; i < canvas->w; i++) for (i = 0; i < canvas->w; i++)
{
counter[j * canvas->w + i] = 0; counter[j * canvas->w + i] = 0;
}
} }
int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc,int x,int y, int fill_edge, int fill_tile, int size, Uint32 color) int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc, int x, int y, int fill_edge, int fill_tile, int size, Uint32 color)
{ {
int leftx, rightx; int leftx, rightx;
Uint8 r, g, b, a; Uint8 r, g, b, a;
int i; int i;
leftx = x - 1; leftx = x - 1;
rightx = x + 1; rightx = x + 1;
/*
printf("x=%d, y=%d, fill_edge=%d\n", x, y, fill_edge);
fflush(stdout);
*/
if (mosaic_shaped_counted[y * srfc->w + x] == 1) return (0); if (mosaic_shaped_counted[y * canvas->w + x] == 1)
{
return (0);
}
if (api->getpixel(srfc, x, y) == black) if (api->getpixel(srfc, x, y) == black)
{ {
if (fill_edge == 1) if (fill_edge == 1)
{
fill_square(api, canvas, x, y, size, color); fill_square(api, canvas, x, y, size, color);
return(0); /* No need to check more */
} }
return (0); /* No need to check more */
}
if (fill_tile == 1) if (fill_tile == 1)
{ {
Uint32 shadow; Uint32 shadow;
@ -525,20 +570,18 @@ int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc,int x,in
shadow = api->getpixel(srfc, x, y); shadow = api->getpixel(srfc, x, y);
SDL_GetRGBA(shadow, srfc->format, &shr, &shg, &shb, &sha); SDL_GetRGBA(shadow, srfc->format, &shr, &shg, &shb, &sha);
SDL_GetRGBA(pixel_average, srfc->format, &cnvsr, &cnvsg, &cnvsb, &cnvsa); SDL_GetRGBA(pixel_average, srfc->format, &cnvsr, &cnvsg, &cnvsb, &cnvsa);
shadow = SDL_MapRGBA(canvas->format, (shr * cnvsr) /255, (shg * cnvsg) /255, (shb * cnvsb) /255, 0);//(shr + cnvsr) /2, ; shadow = SDL_MapRGBA(canvas->format, (shr * cnvsr) / 255, (shg * cnvsg) / 255, (shb * cnvsb) / 255, 0); //(shr + cnvsr) /2, ;
api->putpixel(canvas, x, y, shadow); api->putpixel(canvas, x, y, shadow);
mosaic_shaped_counted[y * canvas->w + x] = 1; mosaic_shaped_counted[y * canvas->w + x] = 1;
mosaic_shaped_done[y * canvas->w + x] = 1; mosaic_shaped_done[y * canvas->w + x] = 1;
} }
else else
{ {
SDL_GetRGBA(api->getpixel(canvas_back, x, y), canvas_back->format, &r, &g, &b, &a); SDL_GetRGBA(api->getpixel(canvas_back, x, y), canvas_back->format, &r, &g, &b, &a);
mosaic_shaped_average_r += r; mosaic_shaped_average_r += r;
mosaic_shaped_average_g +=g; mosaic_shaped_average_g += g;
mosaic_shaped_average_b += b; mosaic_shaped_average_b += b;
mosaic_shaped_average_count +=1; mosaic_shaped_average_count += 1;
mosaic_shaped_counted[y * canvas->w + x] = 1; mosaic_shaped_counted[y * canvas->w + x] = 1;
} }
@ -557,9 +600,17 @@ int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc,int x,in
/* Top / bottom */ /* Top / bottom */
for (i = leftx; i <= rightx; i++) for (i = leftx; i <= rightx; i++)
{ {
if(y > 0) scan_fill(api, canvas, srfc, i, y - 1, fill_edge, fill_tile, size, color); if (y > 0)
if(y + 1 < canvas->w) scan_fill(api, canvas, srfc, i, y + 1, fill_edge, fill_tile, size, color); {
scan_fill(api, canvas, srfc, i, y - 1, fill_edge, fill_tile, size, color);
} }
if (y + 1 < canvas->w)
{
scan_fill(api, canvas, srfc, i, y + 1, fill_edge, fill_tile, size, color);
}
}
return (1); return (1);
} }
@ -567,8 +618,9 @@ int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc,int x,in
void fill_square(magic_api * api, SDL_Surface * canvas, int x, int y, int size, Uint32 color) void fill_square(magic_api * api, SDL_Surface * canvas, int x, int y, int size, Uint32 color)
{ {
int i, j; int i, j;
for (i = (x - size); i < (x + 1 + size); i++) for (i = (x - size); i < (x + 1 + size); i++)
for(j = (y - size); j < (y + 1 + size); j++) for (j = (y - size); j < (y + 1 + size); j++)
{ {
api->putpixel(canvas, i, j, color); api->putpixel(canvas, i, j, color);
} }
@ -577,15 +629,16 @@ void fill_square(magic_api * api, SDL_Surface * canvas, int x, int y, int size,
void deform(magic_api * api, SDL_Surface * srfc) void deform(magic_api * api, SDL_Surface * srfc)
{ {
int i, j; int i, j;
for (j = 0; j < srfc->h; j++) for (j = 0; j < srfc->h; j++)
for (i = 0; i < srfc->w; i++) for (i = 0; i < srfc->w; i++)
{ {
api->putpixel(srfc, i, j, api->getpixel(srfc, i + sin(j * M_PI / 90 ) * 10 + 10, j)); api->putpixel(srfc, i, j, api->getpixel(srfc, i + sin(j * M_PI / 90) * 10 + 10, j));
} }
for (i = 0; i < srfc->w; i++) for (i = 0; i < srfc->w; i++)
for (j = 0; j < srfc->h; j++) for (j = 0; j < srfc->h; j++)
{ {
api->putpixel(srfc, i, j, api->getpixel(srfc, i, j + sin(i * M_PI / 90 ) * 10 + 10)); api->putpixel(srfc, i, j, api->getpixel(srfc, i, j + sin(i * M_PI / 90) * 10 + 10));
} }
} }