cleanups
This commit is contained in:
@@ -4,16 +4,17 @@
|
|||||||
|
|
||||||
LGPL (c) A. Schiffler
|
LGPL (c) A. Schiffler
|
||||||
|
|
||||||
|
This file is indented with a tab size of 8, unlike the rest of the SM
|
||||||
|
source which has a tab size of 4. I'm leaving it that way so I can
|
||||||
|
send patches upstream. (Since 8 is the de-facto standard tab size,
|
||||||
|
it'd be nice to fix the rest of the source to use it, but I don't want
|
||||||
|
to do a full-source commit ...) -glenn
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef WIN32
|
#include "SDL_rotozoom.h"
|
||||||
#include <windows.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "SDL_rotozoom.h"
|
|
||||||
|
|
||||||
typedef struct tColorRGBA {
|
typedef struct tColorRGBA {
|
||||||
Uint8 r;
|
Uint8 r;
|
||||||
@@ -39,7 +40,6 @@ typedef struct tColorY {
|
|||||||
int zoomSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int smooth)
|
int zoomSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int smooth)
|
||||||
{
|
{
|
||||||
int x, y, sx, sy, *sax, *say;
|
int x, y, sx, sy, *sax, *say;
|
||||||
tColorRGBA *c00, *c01, *c10, *c11;
|
|
||||||
|
|
||||||
/* Variable setup */
|
/* Variable setup */
|
||||||
// if (smooth) {
|
// if (smooth) {
|
||||||
@@ -53,9 +53,7 @@ int zoomSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int smooth)
|
|||||||
sy = (int) (65536.0 * (float) src->h / (float) dst->h);
|
sy = (int) (65536.0 * (float) src->h / (float) dst->h);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
/*
|
/* Allocate memory for row increments */
|
||||||
* Allocate memory for row increments
|
|
||||||
*/
|
|
||||||
if ((sax = (int *) malloc((dst->w + 1) * sizeof(Uint32))) == NULL)
|
if ((sax = (int *) malloc((dst->w + 1) * sizeof(Uint32))) == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
@@ -64,32 +62,29 @@ int zoomSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int smooth)
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* Precalculate row increments */
|
||||||
* Precalculate row increments
|
|
||||||
*/
|
|
||||||
int csx = 0;
|
int csx = 0;
|
||||||
int *csax = sax;
|
int *csax = sax;
|
||||||
for (x = 0; x <= dst->w; x++) {
|
for (x = 0; x <= dst->w; x++) {
|
||||||
|
csx &= 0xffff;
|
||||||
*csax = csx;
|
*csax = csx;
|
||||||
csax++;
|
csax++;
|
||||||
csx &= 0xffff;
|
|
||||||
csx += sx;
|
csx += sx;
|
||||||
}
|
}
|
||||||
int csy = 0;
|
int csy = 0;
|
||||||
int *csay = say;
|
int *csay = say;
|
||||||
for (y = 0; y <= dst->h; y++) {
|
for (y = 0; y <= dst->h; y++) {
|
||||||
|
csy &= 0xffff;
|
||||||
*csay = csy;
|
*csay = csy;
|
||||||
csay++;
|
csay++;
|
||||||
csy &= 0xffff;
|
|
||||||
csy += sy;
|
csy += sy;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Pointer setup
|
* Pointer setup
|
||||||
*/
|
*/
|
||||||
tColorRGBA *sp, *csp, *dp;
|
tColorRGBA *sp, *csp;
|
||||||
sp = csp = (tColorRGBA *) src->pixels;
|
sp = csp = (tColorRGBA *) src->pixels;
|
||||||
dp = (tColorRGBA *) dst->pixels;
|
|
||||||
int sgap = src->pitch - src->w * 4;
|
int sgap = src->pitch - src->w * 4;
|
||||||
int dgap = dst->pitch - dst->w * 4;
|
int dgap = dst->pitch - dst->w * 4;
|
||||||
|
|
||||||
@@ -100,23 +95,22 @@ int zoomSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int smooth)
|
|||||||
|
|
||||||
/* Scan destination */
|
/* Scan destination */
|
||||||
for (y = 0; y < dst->h; y++) {
|
for (y = 0; y < dst->h; y++) {
|
||||||
/*
|
/* Set up color source pointers */
|
||||||
* Setup color source pointers
|
tColorRGBA *c00 = csp;
|
||||||
*/
|
tColorRGBA *c01 = csp+1;
|
||||||
c00 = csp;
|
tColorRGBA *c10 = (tColorRGBA *) ((Uint8 *) csp + src->pitch);
|
||||||
c01 = csp;
|
tColorRGBA *c11 = c10+1;
|
||||||
c01++;
|
|
||||||
c10 = (tColorRGBA *) ((Uint8 *) csp + src->pitch);
|
|
||||||
c11 = c10;
|
|
||||||
c11++;
|
|
||||||
csax = sax;
|
csax = sax;
|
||||||
|
/* Set destination pointer. */
|
||||||
|
tColorRGBA *dp = (tColorRGBA *) ((Uint8 *) dst->pixels + dgap*y);
|
||||||
|
|
||||||
for (x = 0; x < dst->w; x++) {
|
for (x = 0; x < dst->w; x++) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Interpolate colors
|
* Interpolate colors
|
||||||
*/
|
*/
|
||||||
int ex = (*csax & 0xffff);
|
int ex = *csax;
|
||||||
int ey = (*csay & 0xffff);
|
int ey = *csay;
|
||||||
int t1, t2;
|
int t1, t2;
|
||||||
t1 = ((((c01->r - c00->r) * ex) >> 16) + c00->r) & 0xff;
|
t1 = ((((c01->r - c00->r) * ex) >> 16) + c00->r) & 0xff;
|
||||||
t2 = ((((c11->r - c10->r) * ex) >> 16) + c10->r) & 0xff;
|
t2 = ((((c11->r - c10->r) * ex) >> 16) + c10->r) & 0xff;
|
||||||
@@ -131,37 +125,27 @@ int zoomSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int smooth)
|
|||||||
t2 = ((((c11->a - c10->a) * ex) >> 16) + c10->a) & 0xff;
|
t2 = ((((c11->a - c10->a) * ex) >> 16) + c10->a) & 0xff;
|
||||||
dp->a = (Uint8)((((t2 - t1) * ey) >> 16) + t1);
|
dp->a = (Uint8)((((t2 - t1) * ey) >> 16) + t1);
|
||||||
|
|
||||||
/*
|
/* Advance source pointers. */
|
||||||
* Advance source pointers
|
|
||||||
*/
|
|
||||||
csax++;
|
csax++;
|
||||||
int sstep = (*csax >> 16);
|
int sstep = (*csax >> 16);
|
||||||
c00 += sstep;
|
c00 += sstep;
|
||||||
c01 += sstep;
|
c01 += sstep;
|
||||||
c10 += sstep;
|
c10 += sstep;
|
||||||
c11 += sstep;
|
c11 += sstep;
|
||||||
/*
|
/* Advance destination pointer. */
|
||||||
* Advance destination pointer
|
|
||||||
*/
|
|
||||||
dp++;
|
dp++;
|
||||||
}
|
}
|
||||||
/*
|
/* Advance source pointer. */
|
||||||
* Advance source pointer
|
|
||||||
*/
|
|
||||||
csay++;
|
csay++;
|
||||||
csp = (tColorRGBA *) ((Uint8 *) csp + (*csay >> 16) * src->pitch);
|
csp = (tColorRGBA *) ((Uint8 *) csp + (*csay >> 16) * src->pitch);
|
||||||
/*
|
|
||||||
* Advance destination pointers
|
|
||||||
*/
|
|
||||||
dp = (tColorRGBA *) ((Uint8 *) dp + dgap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* Non-Interpolating Zoom */
|
/* Non-Interpolating Zoom */
|
||||||
|
|
||||||
for (y = 0; y < dst->h; y++) {
|
for (y = 0; y < dst->h; y++) {
|
||||||
sp = csp;
|
sp = csp;
|
||||||
csax = sax;
|
csax = sax;
|
||||||
|
tColorRGBA *dp = (tColorRGBA *) ((Uint8 *) dst->pixels + dgap*y);
|
||||||
for (x = 0; x < dst->w; x++) {
|
for (x = 0; x < dst->w; x++) {
|
||||||
/* Draw */
|
/* Draw */
|
||||||
*dp = *sp;
|
*dp = *sp;
|
||||||
@@ -174,8 +158,6 @@ int zoomSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int smooth)
|
|||||||
/* Advance source pointer */
|
/* Advance source pointer */
|
||||||
csay++;
|
csay++;
|
||||||
csp = (tColorRGBA *) ((Uint8 *) csp + (*csay >> 16) * src->pitch);
|
csp = (tColorRGBA *) ((Uint8 *) csp + (*csay >> 16) * src->pitch);
|
||||||
/* Advance destination pointers */
|
|
||||||
dp = (tColorRGBA *) ((Uint8 *) dp + dgap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
SDL_rotozoom - rotozoomer
|
SDL_rotozoom - rotozoomer
|
||||||
@@ -7,57 +6,16 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SDL_rotozoom_h
|
#ifndef SDL_ROTOZOOM_H
|
||||||
#define SDL_rotozoom_h
|
#define SDL_ROTOZOOM_H 1
|
||||||
|
|
||||||
/* Set up for C function definitions, even when using C++ */
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//#include <math.h> /* VC6 seems to hate this why?? - ANDY */
|
|
||||||
#ifndef M_PI
|
|
||||||
#define M_PI 3.141592654
|
|
||||||
#endif
|
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
|
|
||||||
/* ---- Defines */
|
/* ---- Defines */
|
||||||
|
|
||||||
#define SMOOTHING_OFF 0
|
#define SMOOTHING_OFF 0
|
||||||
#define SMOOTHING_ON 1
|
#define SMOOTHING_ON 1
|
||||||
|
|
||||||
/* ---- Prototypes */
|
|
||||||
|
|
||||||
/* #ifdef WIN32
|
|
||||||
#ifdef BUILD_DLL
|
|
||||||
#define DLLINTERFACE __declspec(dllexport)
|
|
||||||
#else
|
|
||||||
#define DLLINTERFACE __declspec(dllimport)
|
|
||||||
#endif
|
|
||||||
#else */
|
|
||||||
#define DLLINTERFACE
|
|
||||||
/* #endif */
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
rotozoomSurface()
|
|
||||||
|
|
||||||
Rotates and zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface.
|
|
||||||
'angle' is the rotation in degrees. 'zoom' a scaling factor. If 'smooth' is 1
|
|
||||||
then the destination 32bit surface is anti-aliased. If the surface is not 8bit
|
|
||||||
or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
DLLINTERFACE SDL_Surface *rotozoomSurface(SDL_Surface * src, double angle, double zoom, int smooth);
|
|
||||||
|
|
||||||
|
|
||||||
/* Returns the size of the target surface for a rotozoomSurface() call */
|
|
||||||
|
|
||||||
DLLINTERFACE void rotozoomSurfaceSize(int width, int height, double angle, double zoom, int *dstwidth,
|
|
||||||
int *dstheight);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
zoomSurface()
|
zoomSurface()
|
||||||
@@ -69,16 +27,9 @@ extern "C" {
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
DLLINTERFACE SDL_Surface *zoomSurface(SDL_Surface * src, double zoomx, double zoomy, int smooth);
|
SDL_Surface *zoomSurface(SDL_Surface * src, double zoomx, double zoomy, int smooth);
|
||||||
|
|
||||||
/* Returns the size of the target surface for a zoomSurface() call */
|
/* Returns the size of the target surface for a zoomSurface() call */
|
||||||
|
void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight);
|
||||||
|
|
||||||
DLLINTERFACE void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight);
|
|
||||||
|
|
||||||
|
|
||||||
/* Ends C function definitions when using C++ */
|
|
||||||
#ifdef __cplusplus
|
|
||||||
};
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _SDL_rotozoom_h */
|
|
||||||
|
|||||||
Reference in New Issue
Block a user