Freeciv-3.2
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Functions
SDL3_rotozoom.c File Reference
#include <stdlib.h>
#include <string.h>
#include "SDL3_rotozoom.h"

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...
 

Macros

#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

static int _shrinkSurfaceRGBA (SDL_Surface *src, SDL_Surface *dst, int factorx, int factory)
 Internal 32 bit integer-factor averaging Shrinker.
 
static 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.
 
static 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.
 
SDL_SurfacerotateSurface90Degrees (SDL_Surface *src, int numClockwiseTurns)
 Rotates a 8/16/24/32 bit surface in increments of 90 degrees.
 
static 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_SurfacerotozoomSurface (SDL_Surface *src, double angle, double zoom, int smooth)
 Rotates and zooms a surface and optional anti-aliasing.
 
SDL_SurfacerotozoomSurfaceXY (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_SurfacezoomSurface (SDL_Surface *src, double zoomx, double zoomy, int smooth)
 Zoom a surface by independent horizontal and vertical factors with optional smoothing.
 
SDL_SurfaceshrinkSurface (SDL_Surface *src, int factorx, int factory)
 Shrink a surface by an integer ratio using averaging.
 

Macro Definition Documentation

◆ GUARD_ROWS

#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 79 of file SDL3_rotozoom.c.

◆ MAX

#define MAX (   a,
 
)    (((a) > (b)) ? (a) : (b))

Returns maximum of two numbers a and b.

Definition at line 67 of file SDL3_rotozoom.c.

◆ VALUE_LIMIT

#define VALUE_LIMIT   0.001

Lower limit of absolute zoom factor or rotation degrees.

Definition at line 84 of file SDL3_rotozoom.c.

Typedef Documentation

◆ tColorRGBA

A 32 bit RGBA pixel.

◆ tColorY

A 8bit Y/palette pixel.

Function Documentation

◆ _rotozoomSurfaceSizeTrig()

static void _rotozoomSurfaceSizeTrig ( int  width,
int  height,
double  angle,
double  zoomx,
double  zoomy,
int dstwidth,
int dstheight,
double canglezoom,
double sanglezoom 
)
static

Internal target surface sizing function for rotozooms with trig result return.

Parameters
widthThe source surface width.
heightThe source surface height.
angleThe angle to rotate in degrees.
zoomxThe horizontal scaling factor.
zoomyThe vertical scaling factor.
dstwidthThe calculated width of the destination surface.
dstheightThe calculated height of the destination surface.
canglezoomThe sine of the angle adjusted by the zoom factor.
sanglezoomThe cosine of the angle adjusted by the zoom factor.

Definition at line 688 of file SDL3_rotozoom.c.

Referenced by rotozoomSurfaceSize(), rotozoomSurfaceSizeXY(), and rotozoomSurfaceXY().

◆ _shrinkSurfaceRGBA()

static int _shrinkSurfaceRGBA ( SDL_Surface src,
SDL_Surface dst,
int  factorx,
int  factory 
)
static

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.

Parameters
srcThe surface to shrink (input).
dstThe shrunken surface (output).
factorxThe horizontal shrinking ratio.
factoryThe vertical shrinking ratio.
Returns
0 for success or -1 for error.

Definition at line 102 of file SDL3_rotozoom.c.

Referenced by shrinkSurface().

◆ _transformSurfaceRGBA()

static void _transformSurfaceRGBA ( SDL_Surface src,
SDL_Surface dst,
int  cx,
int  cy,
int  isin,
int  icos,
int  flipx,
int  flipy,
int  smooth 
)
static

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.

Parameters
srcSource surface.
dstDestination surface.
cxHorizontal center coordinate.
cyVertical center coordinate.
isinInteger version of sine of angle.
icosInteger version of cosine of angle.
flipxFlag indicating horizontal mirroring should be applied.
flipyFlag indicating vertical mirroring should be applied.
smoothFlag indicating anti-aliasing should be used.

Definition at line 427 of file SDL3_rotozoom.c.

Referenced by rotozoomSurfaceXY().

◆ _zoomSurfaceRGBA()

static int _zoomSurfaceRGBA ( SDL_Surface src,
SDL_Surface dst,
int  flipx,
int  flipy,
int  smooth 
)
static

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.

Parameters
srcThe surface to zoom (input).
dstThe zoomed surface (output).
flipxFlag indicating if the image should be horizontally flipped.
flipyFlag indicating if the image should be vertically flipped.
smoothAntialiasing flag; set to SMOOTHING_ON to enable.
Returns
0 for success or -1 for error.

Definition at line 190 of file SDL3_rotozoom.c.

Referenced by rotozoomSurfaceXY(), and zoomSurface().

◆ rotateSurface90Degrees()

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)

Parameters
srcSource surface to rotate.
numClockwiseTurnsNumber of clockwise 90 degree turns to apply to the source.
Returns
The new, rotated surface; or NULL for surfaces with incorrect input format.

Definition at line 539 of file SDL3_rotozoom.c.

◆ rotozoomSurface()

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.

Parameters
srcThe surface to rotozoom.
angleThe angle to rotate in degrees.
zoomThe scaling factor.
smoothAntialiasing flag; set to SMOOTHING_ON to enable.
Returns
The new rotozoomed surface.

Definition at line 769 of file SDL3_rotozoom.c.

◆ rotozoomSurfaceSize()

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.

Parameters
widthThe source surface width.
heightThe source surface height.
angleThe angle to rotate in degrees.
zoomThe scaling factor.
dstwidthThe calculated width of the rotozoomed destination surface.
dstheightThe calculated height of the rotozoomed destination surface.

Definition at line 747 of file SDL3_rotozoom.c.

◆ rotozoomSurfaceSizeXY()

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.

Parameters
widthThe source surface width.
heightThe source surface height.
angleThe angle to rotate in degrees.
zoomxThe horizontal scaling factor.
zoomyThe vertical scaling factor.
dstwidthThe calculated width of the rotozoomed destination surface.
dstheightThe calculated height of the rotozoomed destination surface.

Definition at line 730 of file SDL3_rotozoom.c.

◆ rotozoomSurfaceXY()

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.

Parameters
srcThe surface to rotozoom.
angleThe angle to rotate in degrees.
zoomxThe horizontal scaling factor.
zoomyThe vertical scaling factor.
smoothAntialiasing flag; set to SMOOTHING_ON to enable.
Returns
The new rotozoomed surface.

Definition at line 790 of file SDL3_rotozoom.c.

Referenced by rotozoomSurface().

◆ shrinkSurface()

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.

Parameters
srcThe surface to shrink.
factorxThe horizontal shrinking ratio.
factoryThe vertical shrinking ratio.
Returns
The new, shrunken surface.

Definition at line 1175 of file SDL3_rotozoom.c.

◆ zoomSurface()

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.

Parameters
srcThe surface to zoom.
zoomxThe horizontal zoom factor.
zoomyThe vertical zoom factor.
smoothAntialiasing flag; set to SMOOTHING_ON to enable.
Returns
The new, zoomed surface.

Definition at line 1047 of file SDL3_rotozoom.c.

Referenced by change_nation_label(), create_select_tech_icon(), economy_report_dialog_popup(), get_scaled_city_map(), popup_players_dialog(), popup_races_dialog(), popup_worklist_editor(), real_science_report_dialog_update(), redraw_city_dialog(), redraw_happiness_city_dialog(), redraw_unit_info_label(), resize_surface(), resize_surface_box(), and update_intel_dialog().

◆ zoomSurfaceSize()

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.

Parameters
widthThe width of the source surface to zoom.
heightThe height of the source surface to zoom.
zoomxThe horizontal zoom factor.
zoomyThe vertical zoom factor.
dstwidthPointer to an integer to store the calculated width of the zoomed target surface.
dstheightPointer to an integer to store the calculated height of the zoomed target surface.

Definition at line 997 of file SDL3_rotozoom.c.

Referenced by rotozoomSurfaceXY(), and zoomSurface().