Project

General

Profile

Feature #1738 ยป 0034-SDL2_rotozoom-Clear-trailing-spaces.patch

Marko Lindqvist, 11/15/2025 03:02 PM

View differences:

dependencies/SDL2_gfx/SDL2_rotozoom.c
/*
/*
SDL2_rotozoom.c: rotozoomer, zoomer and shrinker for 32bit or 8bit surfaces
......
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.
*/
......
*/
static Uint32 _colorkey(SDL_Surface *src)
{
Uint32 key = 0;
Uint32 key = 0;
SDL_GetColorKey(src, &key);
return key;
}
/*!
/*!
\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 8 bit integer-factor averaging shrinker.
Shrinks 8bit Y 'src' surface to 'dst' surface.
......
dp = (Uint8 *) dst->pixels;
dgap = dst->pitch - dst->w;
for (y = 0; y < dst->h; y++) {
for (y = 0; y < dst->h; y++) {
osp=sp;
for (x = 0; x < dst->w; x++) {
......
for (dy=0; dy < factory; dy++) {
for (dx=0; dx < factorx; dx++) {
a += (*sp);
/* next x */
/* next x */
sp++;
}
/* end src dx loop */
}
/* end src dx loop */
/* next y */
sp = (Uint8 *)((Uint8*)sp + (src->pitch - factorx));
}
sp = (Uint8 *)((Uint8*)sp + (src->pitch - factorx));
}
/* end src dy loop */
/* next box-x */
......
*dp = a/n_average;
/*
* Advance destination pointer
* Advance destination pointer
*/
dp++;
}
}
/* end dst x loop */
/* next box-y */
sp = (Uint8 *)((Uint8*)osp + src->pitch*factory);
/*
* Advance destination pointers
* Advance destination pointers
*/
dp = (Uint8 *)((Uint8 *)dp + dgap);
}
}
/* end 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 8 bit Zoomer without smoothing.
......
int dgap;
/*
* Allocate memory for row increments
* Allocate memory for row increments
*/
if ((sax = (Uint32 *) malloc((dst->w + 1) * sizeof(Uint32))) == NULL) {
return (-1);
......
}
/*
* Pointer setup
* Pointer setup
*/
sp = csp = (Uint8 *) src->pixels;
dp = (Uint8 *) dst->pixels;
......
if (flipy) csp = ( (Uint8*)csp + src->pitch*(src->h-1) );
/*
* Precalculate row increments
* Precalculate row increments
*/
csx = 0;
csax = sax;
......
}
/*
* Draw
* Draw
*/
csay = say;
for (y = 0; y < dst->h; y++) {
......
sp = csp;
for (x = 0; x < dst->w; x++) {
/*
* Draw
* Draw
*/
*dp = *sp;
/*
* Advance source pointers
* Advance source pointers
*/
sp += (*csax);
csax++;
/*
* Advance destination pointer
* Advance destination pointer
*/
dp++;
}
/*
* Advance source pointer (for row)
* Advance source pointer (for row)
*/
csp += ((*csay) * src->pitch);
csay++;
/*
* Advance destination pointers
* Advance destination pointers
*/
dp += dgap;
}
/*
* 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 and zooms 8 bit palette/Y 'src' surface to 'dst' surface without smoothing.
Rotates and zooms 8 bit RGBA/ABGR 'src' surface to 'dst' surface based on the control
Rotates and zooms 8 bit RGBA/ABGR 'src' surface to 'dst' surface based on the control
parameters by scanning the destination surface.
Assumes src and dst surfaces are of 8 bit depth.
Assumes dst surface was allocated with the correct dimensions.
......
int gap;
/*
* Variable setup
* Variable setup
*/
xd = ((src->w - dst->w) << 15);
yd = ((src->h - dst->h) << 15);
......
pc = (tColorY*) dst->pixels;
gap = dst->pitch - dst->w;
/*
* Clear surface to colorkey
* Clear surface to colorkey
*/
memset(pc, (int)(_colorkey(src) & 0xff), dst->pitch * dst->h);
/*
* Iterate through destination surface
* Iterate through destination surface
*/
for (y = 0; y < dst->h; y++) {
dy = cy - y;
......
/*!
\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->BitsPerPixel % 8) != 0) {
SDL_SetError("Invalid source surface bit depth");
return NULL;
return NULL;
}
/* normalize numClockwiseTurns */
......
dst = SDL_CreateRGBSurface( src->flags, newWidth, newHeight, src->format->BitsPerPixel,
src->format->Rmask,
src->format->Gmask,
src->format->Bmask,
src->format->Gmask,
src->format->Bmask,
src->format->Amask);
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
*/
is32bit = (src->format->BitsPerPixel == 32);
if ((is32bit) || (src->format->BitsPerPixel == 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_CreateRGBSurface(SDL_SWSURFACE, src->w, src->h, 32,
SDL_CreateRGBSurface(SDL_SWSURFACE, src->w, src->h, 32,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000
#else
......
}
/*
* 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;
if (is32bit) {
/*
* Target surface is 32bit with source RGBA/ABGR ordering
* Target surface is 32bit with source RGBA/ABGR ordering
*/
rz_dst =
SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight + GUARD_ROWS, 32,
......
rz_src->format->Bmask, rz_src->format->Amask);
} else {
/*
* Target surface is 8bit
* Target surface is 8bit
*/
rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight + GUARD_ROWS, 8, 0, 0, 0, 0);
}
......
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
*/
if (is32bit) {
/*
* Call the 32bit transformation routine to do the rotation (using alpha)
* Call the 32bit transformation routine to do the rotation (using alpha)
*/
_transformSurfaceRGBA(rz_src, rz_dst, dstwidthhalf, dstheighthalf,
(int) (sanglezoominv), (int) (canglezoominv),
(int) (sanglezoominv), (int) (canglezoominv),
flipx, flipy,
smooth);
} else {
/*
* Copy palette and colorkey info
* Copy palette and colorkey info
*/
for (i = 0; i < rz_src->format->palette->ncolors; i++) {
rz_dst->format->palette->colors[i] = rz_src->format->palette->colors[i];
}
rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors;
/*
* Call the 8bit transformation routine to do the rotation
* Call the 8bit transformation routine to do the rotation
*/
transformSurfaceY(rz_src, rz_dst, dstwidthhalf, dstheighthalf,
(int) (sanglezoominv), (int) (canglezoominv),
flipx, flipy);
}
/*
* 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;
if (is32bit) {
/*
* Target surface is 32bit with source RGBA/ABGR ordering
* Target surface is 32bit with source RGBA/ABGR ordering
*/
rz_dst =
SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight + GUARD_ROWS, 32,
......
rz_src->format->Bmask, rz_src->format->Amask);
} else {
/*
* Target surface is 8bit
* Target surface is 8bit
*/
rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight + GUARD_ROWS, 8, 0, 0, 0, 0);
}
......
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
*/
if (is32bit) {
/*
* Call the 32bit transformation routine to do the zooming (using alpha)
* Call the 32bit transformation routine to do the zooming (using alpha)
*/
_zoomSurfaceRGBA(rz_src, rz_dst, flipx, flipy, smooth);
} else {
/*
* Copy palette and colorkey info
* Copy palette and colorkey info
*/
for (i = 0; i < rz_src->format->palette->ncolors; i++) {
rz_dst->format->palette->colors[i] = rz_src->format->palette->colors[i];
......
rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors;
/*
* Call the 8bit transformation routine to do the zooming
* Call the 8bit transformation routine to do the zooming
*/
_zoomSurfaceY(rz_src, rz_dst, flipx, flipy);
}
/*
* 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_FreeSurface(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
*/
is32bit = (src->format->BitsPerPixel == 32);
if ((is32bit) || (src->format->BitsPerPixel == 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_CreateRGBSurface(SDL_SWSURFACE, src->w, src->h, 32,
SDL_CreateRGBSurface(SDL_SWSURFACE, src->w, src->h, 32,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000
#else
......
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;
if (is32bit) {
/*
* Target surface is 32bit with source RGBA/ABGR ordering
* Target surface is 32bit with source RGBA/ABGR ordering
*/
rz_dst =
SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight + GUARD_ROWS, 32,
......
rz_src->format->Bmask, rz_src->format->Amask);
} else {
/*
* Target surface is 8bit
* Target surface is 8bit
*/
rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight + GUARD_ROWS, 8, 0, 0, 0, 0);
}
......
/* Check target */
if (rz_dst == NULL) {
/*
* Cleanup temp surface
* Cleanup temp surface
*/
if (src_converted) {
SDL_FreeSurface(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
*/
if (is32bit) {
/*
* Call the 32bit transformation routine to do the zooming (using alpha)
* Call the 32bit transformation routine to do the zooming (using alpha)
*/
_zoomSurfaceRGBA(rz_src, rz_dst, flipx, flipy, smooth);
} else {
/*
* Copy palette and colorkey info
* Copy palette and colorkey info
*/
for (i = 0; i < rz_src->format->palette->ncolors; i++) {
rz_dst->format->palette->colors[i] = rz_src->format->palette->colors[i];
}
rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors;
/*
* Call the 8bit transformation routine to do the zooming
* Call the 8bit transformation routine to do the zooming
*/
_zoomSurfaceY(rz_src, rz_dst, flipx, flipy);
}
/*
* 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_FreeSurface(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
*/
is32bit = (src->format->BitsPerPixel == 32);
if ((is32bit) || (src->format->BitsPerPixel == 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_CreateRGBSurface(SDL_SWSURFACE, src->w, src->h, 32,
rz_src = SDL_CreateRGBSurface(SDL_SWSURFACE, src->w, src->h, 32,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000
#else
......
}
/*
* Lock the surface
* Lock the surface
*/
if (SDL_MUSTLOCK(rz_src)) {
if (SDL_LockSurface(rz_src) < 0) {
......
*/
if (is32bit==1) {
/*
* Target surface is 32bit with source RGBA/ABGR ordering
* Target surface is 32bit with source RGBA/ABGR ordering
*/
rz_dst =
SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight + GUARD_ROWS, 32,
......
rz_src->format->Bmask, rz_src->format->Amask);
} else {
/*
* Target surface is 8bit
* Target surface is 8bit
*/
rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight + GUARD_ROWS, 8, 0, 0, 0, 0);
}
......
rz_dst->h = dstheight;
/*
* Check which kind of surface we have
* Check which kind of surface we have
*/
if (is32bit==1) {
/*
* Call the 32bit transformation routine to do the shrinking (using alpha)
* Call the 32bit transformation routine to do the shrinking (using alpha)
*/
result = _shrinkSurfaceRGBA(rz_src, rz_dst, factorx, factory);
if ((result!=0) || (rz_dst==NULL)) {
......
}
} else {
/*
* Copy palette and colorkey info
* Copy palette and colorkey info
*/
for (i = 0; i < rz_src->format->palette->ncolors; i++) {
rz_dst->format->palette->colors[i] = rz_src->format->palette->colors[i];
}
rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors;
/*
* Call the 8bit transformation routine to do the shrinking
* Call the 8bit transformation routine to do the shrinking
*/
result = _shrinkSurfaceY(rz_src, rz_dst, factorx, factory);
if (result!=0) {
......
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_FreeSurface(rz_src);
......
SDL_FreeSurface(rz_dst);
}
rz_dst=NULL;
}
}
/*
* Return destination surface
* Return destination surface
*/
return (rz_dst);
}
dependencies/SDL2_gfx/SDL2_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
    (1-1/1)