Feature #818 ยป 0028-SDL3_gfx-Clear-trailing-spaces.patch
dependencies/SDL3_gfx/SDL3_rotozoom.c | ||
---|---|---|
Uint8 y;
|
||
} tColorY;
|
||
/*!
|
||
/*!
|
||
\brief Returns maximum of two numbers a and b.
|
||
*/
|
||
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
||
/*!
|
||
/*!
|
||
\brief Number of guard rows added to destination surfaces.
|
||
This is a simple but effective workaround for observed issues.
|
||
These rows allocate extra memory and are then hidden from the surface.
|
||
Rows are added to the end of destination surfaces when they are allocated.
|
||
This catches any potential overflows which seem to happen with
|
||
Rows are added to the end of destination surfaces when they are allocated.
|
||
This catches any potential overflows which seem to happen with
|
||
just the right src image dimensions and scale/rotation and can lead
|
||
to a situation where the program can segfault.
|
||
*/
|
||
... | ... | |
#define VALUE_LIMIT 0.001
|
||
/*!
|
||
/*!
|
||
\brief Internal 32 bit integer-factor averaging Shrinker.
|
||
Shrinks 32 bit RGBA/ABGR 'src' surface to 'dst' surface.
|
||
... | ... | |
aa += sp->a;
|
||
sp++;
|
||
}
|
||
}
|
||
/* src dx loop */
|
||
sp = (tColorRGBA *)((Uint8*)sp + (src->pitch - 4*factorx)); // next y
|
||
}
|
||
... | ... | |
dp->a = aa/n_average;
|
||
/*
|
||
* Advance destination pointer
|
||
* Advance destination pointer
|
||
*/
|
||
dp++;
|
||
}
|
||
}
|
||
/* dst x loop */
|
||
/* next box-y */
|
||
sp = (tColorRGBA *)((Uint8*)osp + src->pitch*factory);
|
||
/*
|
||
* Advance destination pointers
|
||
* Advance destination pointers
|
||
*/
|
||
dp = (tColorRGBA *) ((Uint8 *) dp + dgap);
|
||
}
|
||
}
|
||
/* dst y loop */
|
||
return (0);
|
||
}
|
||
/*!
|
||
/*!
|
||
\brief Internal 32 bit Zoomer with optional anti-aliasing by bilinear interpolation.
|
||
Zooms 32 bit RGBA/ABGR 'src' surface to 'dst' surface.
|
||
... | ... | |
int spixelgap, spixelw, spixelh, dgap, t1, t2;
|
||
/*
|
||
* Allocate memory for row/column increments
|
||
* Allocate memory for row/column increments
|
||
*/
|
||
if ((sax = (int *) malloc((dst->w + 1) * sizeof(Uint32))) == NULL) {
|
||
return (-1);
|
||
... | ... | |
}
|
||
/*
|
||
* Precalculate row increments
|
||
* Precalculate row increments
|
||
*/
|
||
spixelw = (src->w - 1);
|
||
spixelh = (src->h - 1);
|
||
... | ... | |
csx += sx;
|
||
/* Guard from overflows */
|
||
if (csx > ssx) {
|
||
csx = ssx;
|
||
if (csx > ssx) {
|
||
csx = ssx;
|
||
}
|
||
}
|
||
... | ... | |
if (flipy) sp += (spixelgap * spixelh);
|
||
/*
|
||
* Switch between interpolating and non-interpolating code
|
||
* Switch between interpolating and non-interpolating code
|
||
*/
|
||
if (smooth) {
|
||
/*
|
||
* Interpolating Zoom
|
||
* Interpolating Zoom
|
||
*/
|
||
csay = say;
|
||
for (y = 0; y < dst->h; y++) {
|
||
... | ... | |
csax = sax;
|
||
for (x = 0; x < dst->w; x++) {
|
||
/*
|
||
* Setup color source pointers
|
||
* Setup color source pointers
|
||
*/
|
||
ex = (*csax & 0xffff);
|
||
ey = (*csay & 0xffff);
|
||
... | ... | |
}
|
||
/*
|
||
* Draw and interpolate colors
|
||
* Draw and interpolate colors
|
||
*/
|
||
t1 = ((((c01->r - c00->r) * ex) >> 16) + c00->r) & 0xff;
|
||
t2 = ((((c11->r - c10->r) * ex) >> 16) + c10->r) & 0xff;
|
||
... | ... | |
csay++;
|
||
sstep = (*csay >> 16) - (*salast >> 16);
|
||
sstep *= spixelgap;
|
||
if (flipy) {
|
||
if (flipy) {
|
||
sp = csp - sstep;
|
||
} else {
|
||
sp = csp + sstep;
|
||
... | ... | |
}
|
||
} else {
|
||
/*
|
||
* Non-Interpolating Zoom
|
||
* Non-Interpolating Zoom
|
||
*/
|
||
csay = say;
|
||
for (y = 0; y < dst->h; y++) {
|
||
... | ... | |
csax = sax;
|
||
for (x = 0; x < dst->w; x++) {
|
||
/*
|
||
* Draw
|
||
* Draw
|
||
*/
|
||
*dp = *sp;
|
||
... | ... | |
}
|
||
/*
|
||
* Remove temp arrays
|
||
* Remove temp arrays
|
||
*/
|
||
free(sax);
|
||
free(say);
|
||
... | ... | |
return (0);
|
||
}
|
||
/*!
|
||
/*!
|
||
\brief Internal 32 bit rotozoomer with optional anti-aliasing.
|
||
Rotates and zooms 32 bit RGBA/ABGR 'src' surface to 'dst' surface based on the control
|
||
Rotates and zooms 32 bit RGBA/ABGR 'src' surface to 'dst' surface based on the control
|
||
parameters by scanning the destination surface and applying optionally anti-aliasing
|
||
by bilinear interpolation.
|
||
Assumes src and dst surfaces are of 32 bit depth.
|
||
... | ... | |
int gap;
|
||
/*
|
||
* Variable setup
|
||
* Variable setup
|
||
*/
|
||
xd = ((src->w - dst->w) << 15);
|
||
yd = ((src->h - dst->h) << 15);
|
||
... | ... | |
gap = dst->pitch - dst->w * 4;
|
||
/*
|
||
* Switch between interpolating and non-interpolating code
|
||
* Switch between interpolating and non-interpolating code
|
||
*/
|
||
if (smooth) {
|
||
for (y = 0; y < dst->h; y++) {
|
||
... | ... | |
cswap = c01; c01=c11; c11=cswap;
|
||
}
|
||
/*
|
||
* Interpolate colors
|
||
* Interpolate colors
|
||
*/
|
||
ex = (sdx & 0xffff);
|
||
ey = (sdy & 0xffff);
|
||
... | ... | |
/*!
|
||
\brief Rotates a 8/16/24/32 bit surface in increments of 90 degrees.
|
||
Specialized 90 degree rotator which rotates a 'src' surface in 90 degree
|
||
Specialized 90 degree rotator which rotates a 'src' surface in 90 degree
|
||
increments clockwise returning a new surface. Faster than rotozoomer since
|
||
no scanning or interpolation takes place. Input surface must be 8/16/24/32 bit.
|
||
(code contributed by J. Schiller, improved by C. Allport and A. Schiffler)
|
||
... | ... | |
\returns The new, rotated surface; or NULL for surfaces with incorrect input format.
|
||
*/
|
||
SDL_Surface* rotateSurface90Degrees(SDL_Surface* src, int numClockwiseTurns)
|
||
SDL_Surface* rotateSurface90Degrees(SDL_Surface* src, int numClockwiseTurns)
|
||
{
|
||
int row, col, newWidth, newHeight;
|
||
int bpp, bpr;
|
||
... | ... | |
int normalizedClockwiseTurns;
|
||
/* Has to be a valid surface pointer and be a Nbit surface where n is divisible by 8 */
|
||
if (!src ||
|
||
if (!src ||
|
||
!src->format) {
|
||
SDL_SetError("NULL source surface or source surface format");
|
||
return NULL;
|
||
return NULL;
|
||
}
|
||
if ((src->format->bits_per_pixel % 8) != 0) {
|
||
SDL_SetError("Invalid source surface bit depth");
|
||
return NULL;
|
||
return NULL;
|
||
}
|
||
/* normalize numClockwiseTurns */
|
||
... | ... | |
dst = SDL_CreateSurface( newWidth, newHeight, SDL_PIXELFORMAT_RGBA8888);
|
||
if(!dst) {
|
||
SDL_SetError("Could not create destination surface");
|
||
SDL_SetError("Could not create destination surface");
|
||
return NULL;
|
||
}
|
||
... | ... | |
memcpy (dstBuf, srcBuf, bpp);
|
||
srcBuf += bpp;
|
||
dstBuf += dst->pitch;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
... | ... | |
memcpy (dstBuf, srcBuf, bpp);
|
||
srcBuf += bpp;
|
||
dstBuf -= bpp;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
... | ... | |
memcpy (dstBuf, srcBuf, bpp);
|
||
srcBuf += bpp;
|
||
dstBuf -= dst->pitch;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
/* end switch */
|
||
if (SDL_MUSTLOCK(src)) {
|
||
... | ... | |
/*!
|
||
\brief Internal target surface sizing function for rotozooms with trig result return.
|
||
\brief Internal target surface sizing function for rotozooms with trig result return.
|
||
\param width The source surface width.
|
||
\param height The source surface height.
|
||
... | ... | |
*/
|
||
static void _rotozoomSurfaceSizeTrig(int width, int height, double angle, double zoomx, double zoomy,
|
||
int *dstwidth, int *dstheight,
|
||
int *dstwidth, int *dstheight,
|
||
double *canglezoom, double *sanglezoom)
|
||
{
|
||
double x, y, cx, cy, sx, sy;
|
||
... | ... | |
int dstwidthhalf, dstheighthalf;
|
||
/*
|
||
* Determine destination width and height by rotating a centered source box
|
||
* Determine destination width and height by rotating a centered source box
|
||
*/
|
||
radangle = angle * (M_PI / 180.0);
|
||
*sanglezoom = sin(radangle);
|
||
... | ... | |
*dstheight = 2 * dstheighthalf;
|
||
}
|
||
/*!
|
||
\brief Returns the size of the resulting target surface for a rotozoomSurfaceXY() call.
|
||
/*!
|
||
\brief Returns the size of the resulting target surface for a rotozoomSurfaceXY() call.
|
||
\param width The source surface width.
|
||
\param height The source surface height.
|
||
... | ... | |
_rotozoomSurfaceSizeTrig(width, height, angle, zoomx, zoomy, dstwidth, dstheight, &dummy_sanglezoom, &dummy_canglezoom);
|
||
}
|
||
/*!
|
||
\brief Returns the size of the resulting target surface for a rotozoomSurface() call.
|
||
/*!
|
||
\brief Returns the size of the resulting target surface for a rotozoomSurface() call.
|
||
\param width The source surface width.
|
||
\param height The source surface height.
|
||
... | ... | |
}
|
||
/*!
|
||
\brief Rotates and zooms a surface and optional anti-aliasing.
|
||
\brief Rotates and zooms a surface and optional anti-aliasing.
|
||
Rotates and zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface.
|
||
'angle' is the rotation in degrees and 'zoom' a scaling factor. If 'smooth' is set
|
||
... | ... | |
}
|
||
/*!
|
||
\brief Rotates and zooms a surface with different horizontal and vertival scaling factors and optional anti-aliasing.
|
||
\brief Rotates and zooms a surface with different horizontal and vertival scaling factors and optional anti-aliasing.
|
||
Rotates and zooms a 32bit or 8bit 'src' surface to newly created 'dst' surface.
|
||
'angle' is the rotation in degrees, 'zoomx and 'zoomy' scaling factors. If 'smooth' is set
|
||
... | ... | |
int flipx,flipy;
|
||
/*
|
||
* Sanity check
|
||
* Sanity check
|
||
*/
|
||
if (src == NULL) {
|
||
return (NULL);
|
||
}
|
||
/*
|
||
* Determine if source surface is 32bit or 8bit
|
||
* Determine if source surface is 32bit or 8bit
|
||
*/
|
||
if ((src->format->bits_per_pixel == 32)
|
||
|| (src->format->bits_per_pixel == 8)) {
|
||
/*
|
||
* Use source surface 'as is'
|
||
* Use source surface 'as is'
|
||
*/
|
||
rz_src = src;
|
||
src_converted = 0;
|
||
} else {
|
||
/*
|
||
* New source surface is 32bit with a defined RGBA ordering
|
||
* New source surface is 32bit with a defined RGBA ordering
|
||
*/
|
||
rz_src =
|
||
SDL_CreateSurface(src->w, src->h, SDL_PIXELFORMAT_RGBA8888);
|
||
... | ... | |
}
|
||
/*
|
||
* Sanity check zoom factor
|
||
* Sanity check zoom factor
|
||
*/
|
||
flipx = (zoomx<0.0);
|
||
if (flipx) zoomx=-zoomx;
|
||
... | ... | |
zoominv = 65536.0 / (zoomx * zoomx);
|
||
/*
|
||
* Check if we have a rotozoom or just a zoom
|
||
* Check if we have a rotozoom or just a zoom
|
||
*/
|
||
if (fabs(angle) > VALUE_LIMIT) {
|
||
/*
|
||
* Angle!=0: full rotozoom
|
||
* Angle!=0: full rotozoom
|
||
*/
|
||
/*
|
||
* -----------------------
|
||
* -----------------------
|
||
*/
|
||
/* Determine target size */
|
||
_rotozoomSurfaceSizeTrig(rz_src->w, rz_src->h, angle, zoomx, zoomy, &dstwidth, &dstheight, &canglezoom, &sanglezoom);
|
||
/*
|
||
* Calculate target factors from sin/cos and zoom
|
||
* Calculate target factors from sin/cos and zoom
|
||
*/
|
||
sanglezoominv = sanglezoom;
|
||
canglezoominv = canglezoom;
|
||
... | ... | |
dstheighthalf = dstheight / 2;
|
||
/*
|
||
* Alloc space to completely contain the rotated surface
|
||
* Alloc space to completely contain the rotated surface
|
||
*/
|
||
rz_dst = NULL;
|
||
... | ... | |
rz_dst->h = dstheight;
|
||
/*
|
||
* Lock source surface
|
||
* Lock source surface
|
||
*/
|
||
if (SDL_MUSTLOCK(rz_src)) {
|
||
SDL_LockSurface(rz_src);
|
||
}
|
||
/*
|
||
* Check which kind of surface we have
|
||
* Check which kind of surface we have
|
||
*/
|
||
/*
|
||
... | ... | |
smooth);
|
||
/*
|
||
* Unlock source surface
|
||
* Unlock source surface
|
||
*/
|
||
if (SDL_MUSTLOCK(rz_src)) {
|
||
SDL_UnlockSurface(rz_src);
|
||
... | ... | |
} else {
|
||
/*
|
||
* Angle=0: Just a zoom
|
||
* Angle=0: Just a zoom
|
||
*/
|
||
/*
|
||
* --------------------
|
||
* --------------------
|
||
*/
|
||
/*
|
||
... | ... | |
zoomSurfaceSize(rz_src->w, rz_src->h, zoomx, zoomy, &dstwidth, &dstheight);
|
||
/*
|
||
* Alloc space to completely contain the zoomed surface
|
||
* Alloc space to completely contain the zoomed surface
|
||
*/
|
||
rz_dst = NULL;
|
||
... | ... | |
rz_dst->h = dstheight;
|
||
/*
|
||
* Lock source surface
|
||
* Lock source surface
|
||
*/
|
||
if (SDL_MUSTLOCK(rz_src)) {
|
||
SDL_LockSurface(rz_src);
|
||
}
|
||
/*
|
||
* Check which kind of surface we have
|
||
* Check which kind of surface we have
|
||
*/
|
||
/*
|
||
... | ... | |
_zoomSurfaceRGBA(rz_src, rz_dst, flipx, flipy, smooth);
|
||
/*
|
||
* Unlock source surface
|
||
* Unlock source surface
|
||
*/
|
||
if (SDL_MUSTLOCK(rz_src)) {
|
||
SDL_UnlockSurface(rz_src);
|
||
... | ... | |
}
|
||
/*
|
||
* Cleanup temp surface
|
||
* Cleanup temp surface
|
||
*/
|
||
if (src_converted) {
|
||
SDL_DestroySurface(rz_src);
|
||
}
|
||
/*
|
||
* Return destination surface
|
||
* Return destination surface
|
||
*/
|
||
return (rz_dst);
|
||
}
|
||
... | ... | |
void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight)
|
||
{
|
||
/*
|
||
* Make zoom factors positive
|
||
* Make zoom factors positive
|
||
*/
|
||
int flipx, flipy;
|
||
flipx = (zoomx<0.0);
|
||
... | ... | |
if (flipy) zoomy = -zoomy;
|
||
/*
|
||
* Sanity check zoom factors
|
||
* Sanity check zoom factors
|
||
*/
|
||
if (zoomx < VALUE_LIMIT) {
|
||
zoomx = VALUE_LIMIT;
|
||
... | ... | |
}
|
||
/*
|
||
* Calculate target size
|
||
* Calculate target size
|
||
*/
|
||
*dstwidth = (int) floor(((double) width * zoomx) + 0.5);
|
||
*dstheight = (int) floor(((double) height * zoomy) + 0.5);
|
||
... | ... | |
}
|
||
}
|
||
/*!
|
||
/*!
|
||
\brief Zoom a surface by independent horizontal and vertical factors with optional smoothing.
|
||
Zooms a 32bit or 8bit 'src' surface to newly created 'dst' surface.
|
||
... | ... | |
int flipx, flipy;
|
||
/*
|
||
* Sanity check
|
||
* Sanity check
|
||
*/
|
||
if (src == NULL)
|
||
return (NULL);
|
||
/*
|
||
* Determine if source surface is 32bit or 8bit
|
||
* Determine if source surface is 32bit or 8bit
|
||
*/
|
||
if ((src->format->bits_per_pixel == 32)
|
||
|| (src->format->bits_per_pixel == 8)) {
|
||
/*
|
||
* Use source surface 'as is'
|
||
* Use source surface 'as is'
|
||
*/
|
||
rz_src = src;
|
||
src_converted = 0;
|
||
} else {
|
||
/*
|
||
* New source surface is 32bit with a defined RGBA ordering
|
||
* New source surface is 32bit with a defined RGBA ordering
|
||
*/
|
||
rz_src =
|
||
SDL_CreateSurface(src->w, src->h,
|
||
... | ... | |
zoomSurfaceSize(rz_src->w, rz_src->h, zoomx, zoomy, &dstwidth, &dstheight);
|
||
/*
|
||
* Alloc space to completely contain the zoomed surface
|
||
* Alloc space to completely contain the zoomed surface
|
||
*/
|
||
rz_dst = NULL;
|
||
... | ... | |
/* Check target */
|
||
if (rz_dst == NULL) {
|
||
/*
|
||
* Cleanup temp surface
|
||
* Cleanup temp surface
|
||
*/
|
||
if (src_converted) {
|
||
SDL_DestroySurface(rz_src);
|
||
... | ... | |
rz_dst->h = dstheight;
|
||
/*
|
||
* Lock source surface
|
||
* Lock source surface
|
||
*/
|
||
if (SDL_MUSTLOCK(rz_src)) {
|
||
SDL_LockSurface(rz_src);
|
||
}
|
||
/*
|
||
* Check which kind of surface we have
|
||
* Check which kind of surface we have
|
||
*/
|
||
/*
|
||
... | ... | |
_zoomSurfaceRGBA(rz_src, rz_dst, flipx, flipy, smooth);
|
||
/*
|
||
* Unlock source surface
|
||
* Unlock source surface
|
||
*/
|
||
if (SDL_MUSTLOCK(rz_src)) {
|
||
SDL_UnlockSurface(rz_src);
|
||
}
|
||
/*
|
||
* Cleanup temp surface
|
||
* Cleanup temp surface
|
||
*/
|
||
if (src_converted) {
|
||
SDL_DestroySurface(rz_src);
|
||
}
|
||
/*
|
||
* Return destination surface
|
||
* Return destination surface
|
||
*/
|
||
return (rz_dst);
|
||
}
|
||
/*!
|
||
/*!
|
||
\brief Shrink a surface by an integer ratio using averaging.
|
||
Shrinks a 32bit or 8bit 'src' surface to a newly created 'dst' surface.
|
||
... | ... | |
\return The new, shrunken surface.
|
||
*/
|
||
/*@null@*/
|
||
/*@null@*/
|
||
SDL_Surface *shrinkSurface(SDL_Surface *src, int factorx, int factory)
|
||
{
|
||
int result;
|
||
... | ... | |
int haveError = 0;
|
||
/*
|
||
* Sanity check
|
||
* Sanity check
|
||
*/
|
||
if (src == NULL) {
|
||
return (NULL);
|
||
}
|
||
/*
|
||
* Determine if source surface is 32bit or 8bit
|
||
* Determine if source surface is 32bit or 8bit
|
||
*/
|
||
if ((src->format->bits_per_pixel == 32)
|
||
|| (src->format->bits_per_pixel == 8)) {
|
||
/*
|
||
* Use source surface 'as is'
|
||
* Use source surface 'as is'
|
||
*/
|
||
rz_src = src;
|
||
src_converted = 0;
|
||
... | ... | |
}
|
||
/*
|
||
* Lock the surface
|
||
* Lock the surface
|
||
*/
|
||
if (SDL_MUSTLOCK(rz_src)) {
|
||
if (SDL_LockSurface(rz_src) < 0) {
|
||
... | ... | |
rz_dst->h = dstheight;
|
||
/*
|
||
* Check which kind of surface we have
|
||
* Check which kind of surface we have
|
||
*/
|
||
/*
|
||
... | ... | |
exitShrinkSurface:
|
||
if (rz_src!=NULL) {
|
||
/*
|
||
* Unlock source surface
|
||
* Unlock source surface
|
||
*/
|
||
if (SDL_MUSTLOCK(rz_src)) {
|
||
SDL_UnlockSurface(rz_src);
|
||
}
|
||
/*
|
||
* Cleanup temp surface
|
||
* Cleanup temp surface
|
||
*/
|
||
if (src_converted==1) {
|
||
SDL_DestroySurface(rz_src);
|
||
... | ... | |
SDL_DestroySurface(rz_dst);
|
||
}
|
||
rz_dst=NULL;
|
||
}
|
||
}
|
||
/*
|
||
* Return destination surface
|
||
* Return destination surface
|
||
*/
|
||
return (rz_dst);
|
||
}
|
dependencies/SDL3_gfx/SDL3_rotozoom.h | ||
---|---|---|
/*
|
||
/*
|
||
SDL2_rotozoom.c: rotozoomer, zoomer and shrinker for 32bit or 8bit surfaces
|
||
... | ... | |
# define SDL2_ROTOZOOM_SCOPE extern
|
||
#endif
|
||
/*
|
||
/*
|
||
Rotozoom functions
|
||
... | ... | |
int *dstheight);
|
||
SDL2_ROTOZOOM_SCOPE void rotozoomSurfaceSizeXY
|
||
(int width, int height, double angle, double zoomx, double zoomy,
|
||
(int width, int height, double angle, double zoomx, double zoomy,
|
||
int *dstwidth, int *dstheight);
|
||
/*
|
||
/*
|
||
Zooming functions
|
||
... | ... | |
SDL2_ROTOZOOM_SCOPE void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight);
|
||
/*
|
||
/*
|
||
Shrinking functions
|
||
*/
|
||
*/
|
||
SDL2_ROTOZOOM_SCOPE SDL_Surface *shrinkSurface(SDL_Surface * src, int factorx, int factory);
|
||
/*
|
||
/*
|
||
Specialized rotation functions
|
||