Merge branch 'master' into sdl2.0

This commit is contained in:
Pere Pujal i Carabantes 2022-05-14 19:41:24 +02:00
commit 956292e122
818 changed files with 12739 additions and 11233 deletions

View file

@ -7,9 +7,13 @@
Tux Paint - A simple drawing program for children.
Credits: Andrew Corcoran <akanewbie@gmail.com>
Original Zoom & Perspective
By Pere Pujal Carabantes
Copyright (c) 2002-2022 by Bill Kendrick and others; see AUTHORS.txt
Panels, Tile mode of Zoom, and Rush
by Bill Kendrick
Copyright (c) 2014-2022
bill@newbreedsoftware.com
http://www.tuxpaint.org/
@ -28,7 +32,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: January 30, 2022
Last updated: May 7, 2022
$Id$
*/
@ -119,6 +123,7 @@ enum
TOOL_PANELS,
TOOL_TILEZOOM,
TOOL_ZOOM,
TOOL_RUSH,
perspective_NUM_TOOLS
};
@ -141,6 +146,7 @@ const char *perspective_snd_filenames[perspective_NUM_TOOLS + 1] = {
"zoom_down.ogg", /* TODO: Could use a different sound */
"zoom_up.ogg",
"zoom_down.ogg",
"zoom_down.ogg", /* TODO: Could use a different sound */
};
const char *perspective_icon_filenames[perspective_NUM_TOOLS] = {
@ -148,6 +154,7 @@ const char *perspective_icon_filenames[perspective_NUM_TOOLS] = {
"panels.png",
"tilezoom.png",
"zoom.png",
"rush.png",
};
const char *perspective_names[perspective_NUM_TOOLS] = {
@ -155,6 +162,7 @@ const char *perspective_names[perspective_NUM_TOOLS] = {
gettext_noop("Panels"),
gettext_noop("Tile Zoom"),
gettext_noop("Zoom"),
gettext_noop("Rush"),
};
const char *perspective_descs[perspective_NUM_TOOLS] = {
@ -165,6 +173,8 @@ const char *perspective_descs[perspective_NUM_TOOLS] = {
gettext_noop("Click and drag up to zoom in or drag down to zoom out the picture."),
gettext_noop("Click and drag up to zoom in or drag down to zoom out the picture."),
gettext_noop("Click and drag up to rush in or drag down to rush out the picture."),
};
Uint32 perspective_api_version(void)
@ -288,11 +298,12 @@ void perspective_drag(magic_api * api, int which, SDL_Surface * canvas,
}
break;
case TOOL_ZOOM:
case TOOL_RUSH:
case TOOL_TILEZOOM:
{
int x_distance, y_distance;
if (which == TOOL_ZOOM)
if (which == TOOL_ZOOM || which == TOOL_RUSH)
{
update_rect->x = update_rect->y = 0;
update_rect->w = canvas->w;
@ -370,6 +381,7 @@ void perspective_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
}
break;
case TOOL_RUSH:
case TOOL_ZOOM:
case TOOL_TILEZOOM:
{
@ -435,85 +447,163 @@ void perspective_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
void perspective_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
switch (which)
if (which == TOOL_PANELS)
return;
update_rect->x = update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = canvas->h;
if (which == TOOL_ZOOM || which == TOOL_PERSPECTIVE)
SDL_FillRect(canvas, update_rect, SDL_MapRGB(canvas->format, perspective_r, perspective_g, perspective_b));
if (which == TOOL_PERSPECTIVE)
{
case TOOL_PERSPECTIVE:
{
perspective_preview(api, which, canvas, last, x, y, update_rect, 0.5);
}
break;
perspective_preview(api, which, canvas, last, x, y, update_rect, 0.5);
}
else if (which == TOOL_RUSH)
{
int h1, h2, w, h, hh, x, y, dx1, dy1;
Uint8 r1, g1, b1, r2, g2, b2;
Uint32 r, g, b;
float pct;
SDL_Surface *scaled_surf;
case TOOL_ZOOM:
case TOOL_TILEZOOM:
{
SDL_Surface *aux_surf;
SDL_Surface *scaled_surf;
if (new_h == canvas->h || new_h == 0)
{
SDL_BlitSurface(last, NULL, canvas, NULL);
return; /* Do nothing */
}
update_rect->x = update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = canvas->h;
if (new_h > canvas->h * 1.5)
new_h = canvas->h * 1.5;
if (which == TOOL_ZOOM)
SDL_FillRect(canvas, update_rect, SDL_MapRGB(canvas->format, perspective_r, perspective_g, perspective_b));
if (new_h < canvas->h)
{
h1 = new_h;
h2 = canvas->h;
}
else
{
h1 = canvas->h;
h2 = new_h;
}
SDL_BlitSurface(last, NULL, canvas, NULL);
for (h = 0; h < (h2 - h1); h++)
{
if ((h / 2) % 10 == 0)
api->update_progress_bar();
// if (new_h < canvas->h)
hh = h2 - h;
// else
// hh = new_h + h;
w = canvas->w * hh / canvas->h;
scaled_surf = api->scale(last, w, hh, 0);
dx1 = (canvas->w - scaled_surf->w) / 2;
dy1 = (canvas->h - scaled_surf->h) / 2;
for (y = 0; y < scaled_surf->h; y++)
{
if (dy1 + y >= 0 && dy1 + y < canvas->h)
{
for (x = 0; x < scaled_surf->w; x++)
{
if (dx1 + x >= 0 && dx1 + x < canvas->w)
{
SDL_GetRGB(api->getpixel(scaled_surf, x, y), scaled_surf->format, &r1, &g1, &b1);
SDL_GetRGB(api->getpixel(canvas, dx1 + x, dy1 + y), canvas->format, &r2, &g2, &b2);
pct = (float) ((float) h / ((float) h2 - (float) h1));
// if (new_h > canvas->h)
// pct = 1.0 - pct;
r = api->linear_to_sRGB((api->sRGB_to_linear(r1) * (1.0 - pct)) + (api->sRGB_to_linear(r2) * (pct)));
g = api->linear_to_sRGB((api->sRGB_to_linear(g1) * (1.0 - pct)) + (api->sRGB_to_linear(g2) * (pct)));
b = api->linear_to_sRGB((api->sRGB_to_linear(b1) * (1.0 - pct)) + (api->sRGB_to_linear(b2) * (pct)));
api->putpixel(canvas, dx1 + x, dy1 + y, SDL_MapRGB(canvas->format, r, g, b));
}
}
}
}
}
update_rect->x = 0;
update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = canvas->h;
}
else /* ZOOM & TILEZOOM */
{
SDL_Surface *aux_surf;
SDL_Surface *scaled_surf;
update_rect->x = update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = canvas->h;
if (which == TOOL_ZOOM)
SDL_FillRect(canvas, update_rect, SDL_MapRGB(canvas->format, perspective_r, perspective_g, perspective_b));
if (new_h < canvas->h)
{
int xx, yy, x_span, y_span;
if (new_h < canvas->h)
{
int xx, yy, x_span, y_span;
scaled_surf = api->scale(canvas_back, new_w, new_h, 0);
scaled_surf = api->scale(canvas_back, new_w, new_h, 0);
if (which == TOOL_TILEZOOM && (new_w < canvas->w || new_h < canvas->h))
{
x_span = ceil(canvas->w / new_w);
y_span = ceil(canvas->h / new_h);
}
else
x_span = y_span = 0;
if (which == TOOL_TILEZOOM && (new_w < canvas->w || new_h < canvas->h))
{
x_span = ceil(canvas->w / new_w);
y_span = ceil(canvas->h / new_h);
}
else
x_span = y_span = 0;
for (yy = -y_span; yy <= y_span; yy++)
{
for (xx = -x_span; xx <= x_span; xx++)
{
update_rect->x = ((canvas->w - new_w) / 2) + (new_w * xx);
update_rect->y = ((canvas->h - new_h) / 2) + (new_h * yy);
update_rect->w = new_w;
update_rect->h = new_h;
SDL_BlitSurface(scaled_surf, NULL, canvas, update_rect);
}
}
}
else
{
int aux_h, aux_w;
for (yy = -y_span; yy <= y_span; yy++)
{
for (xx = -x_span; xx <= x_span; xx++)
{
update_rect->x = ((canvas->w - new_w) / 2) + (new_w * xx);
update_rect->y = ((canvas->h - new_h) / 2) + (new_h * yy);
update_rect->w = new_w;
update_rect->h = new_h;
SDL_BlitSurface(scaled_surf, NULL, canvas, update_rect);
}
}
}
else
{
int aux_h, aux_w;
aux_h = canvas->h * canvas->h / new_h;
aux_w = canvas->w * aux_h / canvas->h;
aux_h = canvas->h * canvas->h / new_h;
aux_w = canvas->w * aux_h / canvas->h;
update_rect->x = canvas->w / 2 - aux_w / 2;
update_rect->y = canvas->h / 2 - aux_h / 2;
update_rect->w = aux_w;
update_rect->h = aux_h;
update_rect->x = canvas->w / 2 - aux_w / 2;
update_rect->y = canvas->h / 2 - aux_h / 2;
update_rect->w = aux_w;
update_rect->h = aux_h;
aux_surf = SDL_CreateRGBSurface(SDL_SWSURFACE,
aux_w,
aux_h,
canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, 0);
aux_surf = SDL_CreateRGBSurface(SDL_SWSURFACE,
aux_w,
aux_h,
canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, 0);
SDL_BlitSurface(canvas_back, update_rect, aux_surf, NULL);
scaled_surf = api->scale(aux_surf, canvas->w, canvas->h, 0);
SDL_BlitSurface(scaled_surf, NULL, canvas, NULL);
SDL_FreeSurface(aux_surf);
}
SDL_FreeSurface(scaled_surf);
SDL_BlitSurface(canvas_back, update_rect, aux_surf, NULL);
scaled_surf = api->scale(aux_surf, canvas->w, canvas->h, 0);
SDL_BlitSurface(scaled_surf, NULL, canvas, NULL);
SDL_FreeSurface(aux_surf);
}
SDL_FreeSurface(scaled_surf);
update_rect->x = update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = canvas->h;
update_rect->x = update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = canvas->h;
}
break;
}
}
@ -533,7 +623,7 @@ void perspective_preview(magic_api * api, int which,
if (which == TOOL_ZOOM)
SDL_FillRect(canvas, update_rect, SDL_MapRGB(canvas->format, perspective_r, perspective_g, perspective_b));
else if (which == TOOL_TILEZOOM)
else if (which == TOOL_TILEZOOM || which == TOOL_RUSH)
SDL_FillRect(canvas, update_rect, SDL_MapRGB(canvas->format, 128, 128, 128));
ox_distance = otop_right_x - otop_left_x;
@ -626,7 +716,7 @@ void perspective_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, U
// Use colors:
int perspective_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which)
{
if (which == TOOL_PANELS || which == TOOL_TILEZOOM)
if (which == TOOL_PANELS || which == TOOL_TILEZOOM || which == TOOL_RUSH)
return 0;
return 1;
}