Better performance from "Rush" (by using SDL_gfx rotozoom)

Applying patch from Pere.  ALSO, bumping Tux Paint Magic Tool API version.
This commit is contained in:
Bill Kendrick 2022-10-03 22:50:40 -07:00
parent f32023666e
commit 632459087e
5 changed files with 50 additions and 6 deletions

View file

@ -4,7 +4,7 @@
# Various contributors (see AUTHORS.txt)
# http://www.tuxpaint.org/
# June 14, 2002 - July 3, 2022
# June 14, 2002 - October 3, 2022
# The version number, for release:
@ -16,7 +16,7 @@ ifdef SOURCE_DATE_EPOCH
else
VER_DATE=$(shell date "+%Y-%m-%d")
endif
MAGIC_API_VERSION:=0x00000005
MAGIC_API_VERSION:=0x00000006
# Need to know the OS

View file

@ -14,6 +14,11 @@ http://www.tuxpaint.org/
Use the "stamprotation=no" option to disable.
Pere Pujal i Carabantes <perepujal@gmail.com>
* Improvements to Magic Tools:
----------------------------
* Better performance from "Rush" (by using SDL_gfx rotozoom)
Pere Pujal i Carabantes <perepujal@gmail.com>
* Other Improvements:
-------------------
* A keyboard shortcut is now available for quickly accessing

View file

@ -46,7 +46,6 @@
#include <limits.h>
#include <time.h>
#ifndef gettext_noop
#define gettext_noop(String) String
#endif
@ -496,6 +495,7 @@ void perspective_release(magic_api * api, int which,
Uint32 r, g, b;
float pct;
SDL_Surface *scaled_surf;
SDL_Surface * aux1;
if (new_h == canvas->h || new_h == 0)
{
@ -503,8 +503,10 @@ void perspective_release(magic_api * api, int which,
return; /* Do nothing */
}
if (new_h > canvas->h * 1.5)
new_h = canvas->h * 1.5;
/* FIXME should be a percentage that takes in account what is carried later when blitting scaled surfaces over. */
/* Same should apply for new_h < canvas->h */
if (new_h > canvas->h * 1.08)
new_h = canvas->h * 1.08;
if (new_h < canvas->h)
{
@ -519,6 +521,28 @@ void perspective_release(magic_api * api, int which,
SDL_BlitSurface(last, NULL, canvas, NULL);
aux1 = api->scale(last, last->w, last->h, 0);
for (h = 0; h < h2 - h1; h++)
{
hh = h2 - h;
w = canvas->w * hh / canvas->h;
scaled_surf = api->rotate_scale(aux1, 0, w);
dx1 = (canvas->w - scaled_surf->w) / 2;
dy1 = (canvas->h - scaled_surf->h) / 2;
SDL_Rect rrr;
rrr.x = dx1;
rrr.y =dy1;
rrr.w = dx1 + scaled_surf->w;
rrr.h = dy1 + scaled_surf->h;
SDL_SetSurfaceBlendMode( scaled_surf, SDL_BLENDMODE_BLEND);
SDL_SetSurfaceAlphaMod(scaled_surf,24);
SDL_BlitSurface(scaled_surf, NULL, aux1, &rrr);
SDL_FreeSurface(scaled_surf);
}
SDL_BlitSurface(aux1, NULL, canvas, NULL);
SDL_FreeSurface(aux1);
/*
for (h = 0; h < (h2 - h1); h++)
{
if ((h / 2) % 10 == 0)
@ -566,7 +590,7 @@ void perspective_release(magic_api * api, int which,
}
}
}
}
}*/
update_rect->x = 0;
update_rect->y = 0;

View file

@ -148,6 +148,11 @@ typedef struct magic_api_t {
'w' and 'h' elements to confirm the actual size) */
SDL_Surface * (*scale)(SDL_Surface *, int, int, int);
/* Returns a new surface containing the rotated/scaled contents of
an input surface, rotated to r degrees, scaled to the w dimension and keeping its aspect ratio. */
SDL_Surface * (*rotate_scale)(SDL_Surface *, int, int);
/* Returns whether a particular position of the canvas has been labeled
as 'touched,' since the mouse was first clicked; this function ALSO
assigns the position as touched, until the next time the mouse is

View file

@ -2289,6 +2289,7 @@ static Uint8 magic_linear_to_sRGB(float lin);
static float magic_sRGB_to_linear(Uint8 srgb);
static int magic_button_down(void);
static SDL_Surface *magic_scale(SDL_Surface * surf, int w, int h, int aspect);
static SDL_Surface *magic_rotate_scale(SDL_Surface * surf, int r, int w);
static void reset_touched(void);
static Uint8 magic_touched(int x, int y);
@ -21836,6 +21837,7 @@ static void load_magic_plugins(void)
magic_api_struct->canvas_w = canvas->w;
magic_api_struct->canvas_h = canvas->h;
magic_api_struct->scale = magic_scale;
magic_api_struct->rotate_scale = magic_rotate_scale;
magic_api_struct->touched = magic_touched;
@ -22509,6 +22511,14 @@ static SDL_Surface *magic_scale(SDL_Surface * surf, int w, int h, int aspect)
return (thumbnail2(surf, w, h, aspect, 1));
}
/**
* FIXME
*/
static SDL_Surface *magic_rotate_scale(SDL_Surface * surf, int r, int w)
{
return (rotozoomSurface(surf, r, (float)w / surf->w, SMOOTHING_ON));
}
/**
* FIXME
*/