SDL2_gfx
1.0.1
GraphicsprimitivesandsurfacefunctionsforSDL2
|
Go to the source code of this file.
Data Structures | |
struct | tColorRGBA |
A 32 bit RGBA pixel. More... | |
struct | tColorY |
A 8bit Y/palette pixel. More... | |
Defines | |
#define | MAX(a, b) (((a) > (b)) ? (a) : (b)) |
Returns maximum of two numbers a and b. | |
#define | GUARD_ROWS (2) |
Number of guard rows added to destination surfaces. | |
#define | VALUE_LIMIT 0.001 |
Lower limit of absolute zoom factor or rotation degrees. | |
Typedefs | |
typedef struct tColorRGBA | tColorRGBA |
A 32 bit RGBA pixel. | |
typedef struct tColorY | tColorY |
A 8bit Y/palette pixel. | |
Functions | |
Uint32 | _colorkey (SDL_Surface *src) |
Returns colorkey info for a surface. | |
int | _shrinkSurfaceRGBA (SDL_Surface *src, SDL_Surface *dst, int factorx, int factory) |
Internal 32 bit integer-factor averaging Shrinker. | |
int | _shrinkSurfaceY (SDL_Surface *src, SDL_Surface *dst, int factorx, int factory) |
Internal 8 bit integer-factor averaging shrinker. | |
int | _zoomSurfaceRGBA (SDL_Surface *src, SDL_Surface *dst, int flipx, int flipy, int smooth) |
Internal 32 bit Zoomer with optional anti-aliasing by bilinear interpolation. | |
int | _zoomSurfaceY (SDL_Surface *src, SDL_Surface *dst, int flipx, int flipy) |
Internal 8 bit Zoomer without smoothing. | |
void | _transformSurfaceRGBA (SDL_Surface *src, SDL_Surface *dst, int cx, int cy, int isin, int icos, int flipx, int flipy, int smooth) |
Internal 32 bit rotozoomer with optional anti-aliasing. | |
void | transformSurfaceY (SDL_Surface *src, SDL_Surface *dst, int cx, int cy, int isin, int icos, int flipx, int flipy) |
Rotates and zooms 8 bit palette/Y 'src' surface to 'dst' surface without smoothing. | |
SDL_Surface * | rotateSurface90Degrees (SDL_Surface *src, int numClockwiseTurns) |
Rotates a 8/16/24/32 bit surface in increments of 90 degrees. | |
void | _rotozoomSurfaceSizeTrig (int width, int height, double angle, double zoomx, double zoomy, int *dstwidth, int *dstheight, double *canglezoom, double *sanglezoom) |
Internal target surface sizing function for rotozooms with trig result return. | |
void | rotozoomSurfaceSizeXY (int width, int height, double angle, double zoomx, double zoomy, int *dstwidth, int *dstheight) |
Returns the size of the resulting target surface for a rotozoomSurfaceXY() call. | |
void | rotozoomSurfaceSize (int width, int height, double angle, double zoom, int *dstwidth, int *dstheight) |
Returns the size of the resulting target surface for a rotozoomSurface() call. | |
SDL_Surface * | rotozoomSurface (SDL_Surface *src, double angle, double zoom, int smooth) |
Rotates and zooms a surface and optional anti-aliasing. | |
SDL_Surface * | rotozoomSurfaceXY (SDL_Surface *src, double angle, double zoomx, double zoomy, int smooth) |
Rotates and zooms a surface with different horizontal and vertival scaling factors and optional anti-aliasing. | |
void | zoomSurfaceSize (int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight) |
Calculates the size of the target surface for a zoomSurface() call. | |
SDL_Surface * | zoomSurface (SDL_Surface *src, double zoomx, double zoomy, int smooth) |
Zoom a surface by independent horizontal and vertical factors with optional smoothing. | |
SDL_Surface * | shrinkSurface (SDL_Surface *src, int factorx, int factory) |
Shrink a surface by an integer ratio using averaging. |
#define GUARD_ROWS (2) |
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 just the right src image dimensions and scale/rotation and can lead to a situation where the program can segfault.
Definition at line 73 of file SDL2_rotozoom.c.
#define MAX | ( | a, | |
b | |||
) | (((a) > (b)) ? (a) : (b)) |
Returns maximum of two numbers a and b.
Definition at line 61 of file SDL2_rotozoom.c.
#define VALUE_LIMIT 0.001 |
Lower limit of absolute zoom factor or rotation degrees.
Definition at line 78 of file SDL2_rotozoom.c.
typedef struct tColorRGBA tColorRGBA |
A 32 bit RGBA pixel.
Uint32 _colorkey | ( | SDL_Surface * | src | ) |
Returns colorkey info for a surface.
Definition at line 83 of file SDL2_rotozoom.c.
void _rotozoomSurfaceSizeTrig | ( | int | width, |
int | height, | ||
double | angle, | ||
double | zoomx, | ||
double | zoomy, | ||
int * | dstwidth, | ||
int * | dstheight, | ||
double * | canglezoom, | ||
double * | sanglezoom | ||
) |
Internal target surface sizing function for rotozooms with trig result return.
width | The source surface width. |
height | The source surface height. |
angle | The angle to rotate in degrees. |
zoomx | The horizontal scaling factor. |
zoomy | The vertical scaling factor. |
dstwidth | The calculated width of the destination surface. |
dstheight | The calculated height of the destination surface. |
canglezoom | The sine of the angle adjusted by the zoom factor. |
sanglezoom | The cosine of the angle adjusted by the zoom factor. |
Definition at line 954 of file SDL2_rotozoom.c.
int _shrinkSurfaceRGBA | ( | SDL_Surface * | src, |
SDL_Surface * | dst, | ||
int | factorx, | ||
int | factory | ||
) |
Internal 32 bit integer-factor averaging Shrinker.
Shrinks 32 bit RGBA/ABGR 'src' surface to 'dst' surface. Averages color and alpha values values of src pixels to calculate dst pixels. Assumes src and dst surfaces are of 32 bit depth. Assumes dst surface was allocated with the correct dimensions.
src | The surface to shrink (input). |
dst | The shrunken surface (output). |
factorx | The horizontal shrinking ratio. |
factory | The vertical shrinking ratio. |
Definition at line 106 of file SDL2_rotozoom.c.
int _shrinkSurfaceY | ( | SDL_Surface * | src, |
SDL_Surface * | dst, | ||
int | factorx, | ||
int | factory | ||
) |
Internal 8 bit integer-factor averaging shrinker.
Shrinks 8bit Y 'src' surface to 'dst' surface. Averages color (brightness) values values of src pixels to calculate dst pixels. Assumes src and dst surfaces are of 8 bit depth. Assumes dst surface was allocated with the correct dimensions.
src | The surface to shrink (input). |
dst | The shrunken surface (output). |
factorx | The horizontal shrinking ratio. |
factory | The vertical shrinking ratio. |
Definition at line 194 of file SDL2_rotozoom.c.
void _transformSurfaceRGBA | ( | SDL_Surface * | src, |
SDL_Surface * | dst, | ||
int | cx, | ||
int | cy, | ||
int | isin, | ||
int | icos, | ||
int | flipx, | ||
int | flipy, | ||
int | smooth | ||
) |
Internal 32 bit rotozoomer with optional anti-aliasing.
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. Assumes dst surface was allocated with the correct dimensions.
src | Source surface. |
dst | Destination surface. |
cx | Horizontal center coordinate. |
cy | Vertical center coordinate. |
isin | Integer version of sine of angle. |
icos | Integer version of cosine of angle. |
flipx | Flag indicating horizontal mirroring should be applied. |
flipy | Flag indicating vertical mirroring should be applied. |
smooth | Flag indicating anti-aliasing should be used. |
Definition at line 629 of file SDL2_rotozoom.c.
int _zoomSurfaceRGBA | ( | SDL_Surface * | src, |
SDL_Surface * | dst, | ||
int | flipx, | ||
int | flipy, | ||
int | smooth | ||
) |
Internal 32 bit Zoomer with optional anti-aliasing by bilinear interpolation.
Zooms 32 bit RGBA/ABGR 'src' surface to 'dst' surface. Assumes src and dst surfaces are of 32 bit depth. Assumes dst surface was allocated with the correct dimensions.
src | The surface to zoom (input). |
dst | The zoomed surface (output). |
flipx | Flag indicating if the image should be horizontally flipped. |
flipy | Flag indicating if the image should be vertically flipped. |
smooth | Antialiasing flag; set to SMOOTHING_ON to enable. |
Definition at line 277 of file SDL2_rotozoom.c.
int _zoomSurfaceY | ( | SDL_Surface * | src, |
SDL_Surface * | dst, | ||
int | flipx, | ||
int | flipy | ||
) |
Internal 8 bit Zoomer without smoothing.
Zooms 8bit palette/Y 'src' surface to 'dst' surface. Assumes src and dst surfaces are of 8 bit depth. Assumes dst surface was allocated with the correct dimensions.
src | The surface to zoom (input). |
dst | The zoomed surface (output). |
flipx | Flag indicating if the image should be horizontally flipped. |
flipy | Flag indicating if the image should be vertically flipped. |
Definition at line 510 of file SDL2_rotozoom.c.
SDL_Surface* rotateSurface90Degrees | ( | SDL_Surface * | src, |
int | numClockwiseTurns | ||
) |
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 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)
src | Source surface to rotate. |
numClockwiseTurns | Number of clockwise 90 degree turns to apply to the source. |
Definition at line 803 of file SDL2_rotozoom.c.
SDL_Surface* rotozoomSurface | ( | SDL_Surface * | src, |
double | angle, | ||
double | zoom, | ||
int | smooth | ||
) |
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 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.
src | The surface to rotozoom. |
angle | The angle to rotate in degrees. |
zoom | The scaling factor. |
smooth | Antialiasing flag; set to SMOOTHING_ON to enable. |
Definition at line 1035 of file SDL2_rotozoom.c.
void rotozoomSurfaceSize | ( | int | width, |
int | height, | ||
double | angle, | ||
double | zoom, | ||
int * | dstwidth, | ||
int * | dstheight | ||
) |
Returns the size of the resulting target surface for a rotozoomSurface() call.
width | The source surface width. |
height | The source surface height. |
angle | The angle to rotate in degrees. |
zoom | The scaling factor. |
dstwidth | The calculated width of the rotozoomed destination surface. |
dstheight | The calculated height of the rotozoomed destination surface. |
Definition at line 1013 of file SDL2_rotozoom.c.
void rotozoomSurfaceSizeXY | ( | int | width, |
int | height, | ||
double | angle, | ||
double | zoomx, | ||
double | zoomy, | ||
int * | dstwidth, | ||
int * | dstheight | ||
) |
Returns the size of the resulting target surface for a rotozoomSurfaceXY() call.
width | The source surface width. |
height | The source surface height. |
angle | The angle to rotate in degrees. |
zoomx | The horizontal scaling factor. |
zoomy | The vertical scaling factor. |
dstwidth | The calculated width of the rotozoomed destination surface. |
dstheight | The calculated height of the rotozoomed destination surface. |
Definition at line 996 of file SDL2_rotozoom.c.
SDL_Surface* rotozoomSurfaceXY | ( | SDL_Surface * | src, |
double | angle, | ||
double | zoomx, | ||
double | zoomy, | ||
int | smooth | ||
) |
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 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.
src | The surface to rotozoom. |
angle | The angle to rotate in degrees. |
zoomx | The horizontal scaling factor. |
zoomy | The vertical scaling factor. |
smooth | Antialiasing flag; set to SMOOTHING_ON to enable. |
Definition at line 1056 of file SDL2_rotozoom.c.
SDL_Surface* shrinkSurface | ( | SDL_Surface * | src, |
int | factorx, | ||
int | factory | ||
) |
Shrink a surface by an integer ratio using averaging.
Shrinks a 32bit or 8bit 'src' surface to a newly created 'dst' surface. 'factorx' and 'factory' are the shrinking ratios (i.e. 2=1/2 the size, 3=1/3 the size, etc.) The destination surface is antialiased by averaging the source box RGBA or Y information. If the surface is not 8bit or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly. The input surface is not modified. The output surface is newly allocated.
src | The surface to shrink. |
factorx | The horizontal shrinking ratio. |
factory | The vertical shrinking ratio. |
Definition at line 1512 of file SDL2_rotozoom.c.
void transformSurfaceY | ( | SDL_Surface * | src, |
SDL_Surface * | dst, | ||
int | cx, | ||
int | cy, | ||
int | isin, | ||
int | icos, | ||
int | flipx, | ||
int | flipy | ||
) |
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 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.
src | Source surface. |
dst | Destination surface. |
cx | Horizontal center coordinate. |
cy | Vertical center coordinate. |
isin | Integer version of sine of angle. |
icos | Integer version of cosine of angle. |
flipx | Flag indicating horizontal mirroring should be applied. |
flipy | Flag indicating vertical mirroring should be applied. |
Definition at line 746 of file SDL2_rotozoom.c.
SDL_Surface* zoomSurface | ( | SDL_Surface * | src, |
double | zoomx, | ||
double | zoomy, | ||
int | smooth | ||
) |
Zoom a surface by independent horizontal and vertical factors with optional smoothing.
Zooms a 32bit or 8bit 'src' surface to newly created 'dst' surface. 'zoomx' and 'zoomy' are scaling factors for width and height. If 'smooth' is on 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. If zoom factors are negative, the image is flipped on the axes.
src | The surface to zoom. |
zoomx | The horizontal zoom factor. |
zoomy | The vertical zoom factor. |
smooth | Antialiasing flag; set to SMOOTHING_ON to enable. |
Definition at line 1361 of file SDL2_rotozoom.c.
void zoomSurfaceSize | ( | int | width, |
int | height, | ||
double | zoomx, | ||
double | zoomy, | ||
int * | dstwidth, | ||
int * | dstheight | ||
) |
Calculates the size of the target surface for a zoomSurface() call.
The minimum size of the target surface is 1. The input factors can be positive or negative.
width | The width of the source surface to zoom. |
height | The height of the source surface to zoom. |
zoomx | The horizontal zoom factor. |
zoomy | The vertical zoom factor. |
dstwidth | Pointer to an integer to store the calculated width of the zoomed target surface. |
dstheight | Pointer to an integer to store the calculated height of the zoomed target surface. |
Definition at line 1311 of file SDL2_rotozoom.c.