SDL 3.0
SDL_surface.h File Reference
+ Include dependency graph for SDL_surface.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SDL_Surface
 

Macros

#define SDL_SURFACE_PREALLOCATED   0x00000001u
 
#define SDL_SURFACE_LOCK_NEEDED   0x00000002u
 
#define SDL_SURFACE_LOCKED   0x00000004u
 
#define SDL_SURFACE_SIMD_ALIGNED   0x00000008u
 
#define SDL_MUSTLOCK(S)   ((((S)->flags & SDL_SURFACE_LOCK_NEEDED)) == SDL_SURFACE_LOCK_NEEDED)
 
#define SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT   "SDL.surface.SDR_white_point"
 
#define SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT   "SDL.surface.HDR_headroom"
 
#define SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING   "SDL.surface.tonemap"
 

Typedefs

typedef Uint32 SDL_SurfaceFlags
 

Enumerations

enum  SDL_ScaleMode {
  SDL_SCALEMODE_NEAREST ,
  SDL_SCALEMODE_LINEAR
}
 
enum  SDL_FlipMode {
  SDL_FLIP_NONE ,
  SDL_FLIP_HORIZONTAL ,
  SDL_FLIP_VERTICAL
}
 

Functions

SDL_SurfaceSDL_CreateSurface (int width, int height, SDL_PixelFormat format)
 
SDL_SurfaceSDL_CreateSurfaceFrom (int width, int height, SDL_PixelFormat format, void *pixels, int pitch)
 
void SDL_DestroySurface (SDL_Surface *surface)
 
SDL_PropertiesID SDL_GetSurfaceProperties (SDL_Surface *surface)
 
bool SDL_SetSurfaceColorspace (SDL_Surface *surface, SDL_Colorspace colorspace)
 
SDL_Colorspace SDL_GetSurfaceColorspace (SDL_Surface *surface)
 
SDL_PaletteSDL_CreateSurfacePalette (SDL_Surface *surface)
 
bool SDL_SetSurfacePalette (SDL_Surface *surface, SDL_Palette *palette)
 
SDL_PaletteSDL_GetSurfacePalette (SDL_Surface *surface)
 
bool SDL_AddSurfaceAlternateImage (SDL_Surface *surface, SDL_Surface *image)
 
bool SDL_SurfaceHasAlternateImages (SDL_Surface *surface)
 
SDL_Surface ** SDL_GetSurfaceImages (SDL_Surface *surface, int *count)
 
void SDL_RemoveSurfaceAlternateImages (SDL_Surface *surface)
 
bool SDL_LockSurface (SDL_Surface *surface)
 
void SDL_UnlockSurface (SDL_Surface *surface)
 
SDL_SurfaceSDL_LoadBMP_IO (SDL_IOStream *src, bool closeio)
 
SDL_SurfaceSDL_LoadBMP (const char *file)
 
bool SDL_SaveBMP_IO (SDL_Surface *surface, SDL_IOStream *dst, bool closeio)
 
bool SDL_SaveBMP (SDL_Surface *surface, const char *file)
 
bool SDL_SetSurfaceRLE (SDL_Surface *surface, bool enabled)
 
bool SDL_SurfaceHasRLE (SDL_Surface *surface)
 
bool SDL_SetSurfaceColorKey (SDL_Surface *surface, bool enabled, Uint32 key)
 
bool SDL_SurfaceHasColorKey (SDL_Surface *surface)
 
bool SDL_GetSurfaceColorKey (SDL_Surface *surface, Uint32 *key)
 
bool SDL_SetSurfaceColorMod (SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b)
 
bool SDL_GetSurfaceColorMod (SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b)
 
bool SDL_SetSurfaceAlphaMod (SDL_Surface *surface, Uint8 alpha)
 
bool SDL_GetSurfaceAlphaMod (SDL_Surface *surface, Uint8 *alpha)
 
bool SDL_SetSurfaceBlendMode (SDL_Surface *surface, SDL_BlendMode blendMode)
 
bool SDL_GetSurfaceBlendMode (SDL_Surface *surface, SDL_BlendMode *blendMode)
 
bool SDL_SetSurfaceClipRect (SDL_Surface *surface, const SDL_Rect *rect)
 
bool SDL_GetSurfaceClipRect (SDL_Surface *surface, SDL_Rect *rect)
 
bool SDL_FlipSurface (SDL_Surface *surface, SDL_FlipMode flip)
 
SDL_SurfaceSDL_DuplicateSurface (SDL_Surface *surface)
 
SDL_SurfaceSDL_ScaleSurface (SDL_Surface *surface, int width, int height, SDL_ScaleMode scaleMode)
 
SDL_SurfaceSDL_ConvertSurface (SDL_Surface *surface, SDL_PixelFormat format)
 
SDL_SurfaceSDL_ConvertSurfaceAndColorspace (SDL_Surface *surface, SDL_PixelFormat format, SDL_Palette *palette, SDL_Colorspace colorspace, SDL_PropertiesID props)
 
bool SDL_ConvertPixels (int width, int height, SDL_PixelFormat src_format, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch)
 
bool SDL_ConvertPixelsAndColorspace (int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch)
 
bool SDL_PremultiplyAlpha (int width, int height, SDL_PixelFormat src_format, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch, bool linear)
 
bool SDL_PremultiplySurfaceAlpha (SDL_Surface *surface, bool linear)
 
bool SDL_ClearSurface (SDL_Surface *surface, float r, float g, float b, float a)
 
bool SDL_FillSurfaceRect (SDL_Surface *dst, const SDL_Rect *rect, Uint32 color)
 
bool SDL_FillSurfaceRects (SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color)
 
bool SDL_BlitSurface (SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect)
 
bool SDL_BlitSurfaceUnchecked (SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect)
 
bool SDL_BlitSurfaceScaled (SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode)
 
bool SDL_BlitSurfaceUncheckedScaled (SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode)
 
bool SDL_BlitSurfaceTiled (SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect)
 
bool SDL_BlitSurfaceTiledWithScale (SDL_Surface *src, const SDL_Rect *srcrect, float scale, SDL_ScaleMode scaleMode, SDL_Surface *dst, const SDL_Rect *dstrect)
 
bool SDL_BlitSurface9Grid (SDL_Surface *src, const SDL_Rect *srcrect, int left_width, int right_width, int top_height, int bottom_height, float scale, SDL_ScaleMode scaleMode, SDL_Surface *dst, const SDL_Rect *dstrect)
 
Uint32 SDL_MapSurfaceRGB (SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b)
 
Uint32 SDL_MapSurfaceRGBA (SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
 
bool SDL_ReadSurfacePixel (SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
 
bool SDL_ReadSurfacePixelFloat (SDL_Surface *surface, int x, int y, float *r, float *g, float *b, float *a)
 
bool SDL_WriteSurfacePixel (SDL_Surface *surface, int x, int y, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
 
bool SDL_WriteSurfacePixelFloat (SDL_Surface *surface, int x, int y, float r, float g, float b, float a)
 

Macro Definition Documentation

◆ SDL_MUSTLOCK

#define SDL_MUSTLOCK (   S)    ((((S)->flags & SDL_SURFACE_LOCK_NEEDED)) == SDL_SURFACE_LOCK_NEEDED)

Evaluates to true if the surface needs to be locked before access.

Since
This macro is available since SDL 3.0.0.

Definition at line 76 of file SDL_surface.h.

◆ SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT

#define SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT   "SDL.surface.HDR_headroom"

Definition at line 230 of file SDL_surface.h.

◆ SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT

#define SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT   "SDL.surface.SDR_white_point"

Definition at line 229 of file SDL_surface.h.

◆ SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING

#define SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING   "SDL.surface.tonemap"

Definition at line 231 of file SDL_surface.h.

◆ SDL_SURFACE_LOCK_NEEDED

#define SDL_SURFACE_LOCK_NEEDED   0x00000002u

Surface needs to be locked to access pixels

Definition at line 67 of file SDL_surface.h.

◆ SDL_SURFACE_LOCKED

#define SDL_SURFACE_LOCKED   0x00000004u

Surface is currently locked

Definition at line 68 of file SDL_surface.h.

◆ SDL_SURFACE_PREALLOCATED

#define SDL_SURFACE_PREALLOCATED   0x00000001u

Surface uses preallocated pixel memory

Definition at line 66 of file SDL_surface.h.

◆ SDL_SURFACE_SIMD_ALIGNED

#define SDL_SURFACE_SIMD_ALIGNED   0x00000008u

Surface uses pixel memory allocated with SDL_aligned_alloc()

Definition at line 69 of file SDL_surface.h.

Typedef Documentation

◆ SDL_SurfaceFlags

CategorySurface

SDL surfaces are buffers of pixels in system RAM. These are useful for passing around and manipulating images that are not stored in GPU memory.

SDL_Surface makes serious efforts to manage images in various formats, and provides a reasonable toolbox for transforming the data, including copying between surfaces, filling rectangles in the image data, etc.

There is also a simple .bmp loader, SDL_LoadBMP(). SDL itself does not provide loaders for various other file formats, but there are several excellent external libraries that do, including it's own satellite library, SDL_image:

https://github.com/libsdl-org/SDL_image The flags on an SDL_Surface.

These are generally considered read-only.

Since
This datatype is available since SDL 3.0.0.

Definition at line 64 of file SDL_surface.h.

Enumeration Type Documentation

◆ SDL_FlipMode

The flip mode.

Since
This enum is available since SDL 3.0.0.
Enumerator
SDL_FLIP_NONE 

Do not flip

SDL_FLIP_HORIZONTAL 

flip horizontally

SDL_FLIP_VERTICAL 

flip vertically

Definition at line 94 of file SDL_surface.h.

95{
96 SDL_FLIP_NONE, /**< Do not flip */
97 SDL_FLIP_HORIZONTAL, /**< flip horizontally */
98 SDL_FLIP_VERTICAL /**< flip vertically */
SDL_FlipMode
Definition SDL_surface.h:95
@ SDL_FLIP_VERTICAL
Definition SDL_surface.h:98
@ SDL_FLIP_NONE
Definition SDL_surface.h:96
@ SDL_FLIP_HORIZONTAL
Definition SDL_surface.h:97

◆ SDL_ScaleMode

The scaling mode.

Since
This enum is available since SDL 3.0.0.
Enumerator
SDL_SCALEMODE_NEAREST 

nearest pixel sampling

SDL_SCALEMODE_LINEAR 

linear filtering

Definition at line 83 of file SDL_surface.h.

84{
85 SDL_SCALEMODE_NEAREST, /**< nearest pixel sampling */
86 SDL_SCALEMODE_LINEAR /**< linear filtering */
SDL_ScaleMode
Definition SDL_surface.h:84
@ SDL_SCALEMODE_LINEAR
Definition SDL_surface.h:86
@ SDL_SCALEMODE_NEAREST
Definition SDL_surface.h:85

Function Documentation

◆ SDL_AddSurfaceAlternateImage()

bool SDL_AddSurfaceAlternateImage ( SDL_Surface surface,
SDL_Surface image 
)
extern

Add an alternate version of a surface.

This function adds an alternate version of this surface, usually used for content with high DPI representations like cursors or icons. The size, format, and content do not need to match the original surface, and these alternate versions will not be updated when the original surface changes.

This function adds a reference to the alternate version, so you should call SDL_DestroySurface() on the image after this call.

Parameters
surfacethe SDL_Surface structure to update.
imagea pointer to an alternate SDL_Surface to associate with this surface.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_RemoveSurfaceAlternateImages
SDL_GetSurfaceImages
SDL_SurfaceHasAlternateImages

◆ SDL_BlitSurface()

bool SDL_BlitSurface ( SDL_Surface src,
const SDL_Rect srcrect,
SDL_Surface dst,
const SDL_Rect dstrect 
)
extern

Performs a fast blit from the source surface to the destination surface.

This assumes that the source and destination rectangles are the same size. If either srcrect or dstrect are NULL, the entire surface (src or dst) is copied. The final blit rectangles are saved in srcrect and dstrect after all clipping is performed.

The blit function should not be called on a locked surface.

The blit semantics for surfaces with and without blending and colorkey are defined as follows:

RGBA->RGB:
Source surface blend mode set to SDL_BLENDMODE_BLEND:
alpha-blend (using the source alpha-channel and per-surface alpha)
SDL_SRCCOLORKEY ignored.
Source surface blend mode set to SDL_BLENDMODE_NONE:
copy RGB.
if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
RGB values of the source color key, ignoring alpha in the
comparison.
RGB->RGBA:
Source surface blend mode set to SDL_BLENDMODE_BLEND:
alpha-blend (using the source per-surface alpha)
Source surface blend mode set to SDL_BLENDMODE_NONE:
copy RGB, set destination alpha to source per-surface alpha value.
both:
if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
source color key.
RGBA->RGBA:
Source surface blend mode set to SDL_BLENDMODE_BLEND:
alpha-blend (using the source alpha-channel and per-surface alpha)
SDL_SRCCOLORKEY ignored.
Source surface blend mode set to SDL_BLENDMODE_NONE:
copy all of RGBA to the destination.
if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
RGB values of the source color key, ignoring alpha in the
comparison.
RGB->RGB:
Source surface blend mode set to SDL_BLENDMODE_BLEND:
alpha-blend (using the source per-surface alpha)
Source surface blend mode set to SDL_BLENDMODE_NONE:
copy RGB.
both:
if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
source color key.
#define SDL_BLENDMODE_BLEND
#define SDL_BLENDMODE_NONE
Parameters
srcthe SDL_Surface structure to be copied from.
srcrectthe SDL_Rect structure representing the rectangle to be copied, or NULL to copy the entire surface.
dstthe SDL_Surface structure that is the blit target.
dstrectthe SDL_Rect structure representing the x and y position in the destination surface, or NULL for (0,0). The width and height are ignored, and are copied from srcrect. If you want a specific width and height, you should use SDL_BlitSurfaceScaled().
Returns
true on success or false on failure; call SDL_GetError() for more information.

\threadsafety The same destination surface should not be used from two threads at once. It is safe to use the same source surface from multiple threads.

Since
This function is available since SDL 3.0.0.
See also
SDL_BlitSurfaceScaled

◆ SDL_BlitSurface9Grid()

bool SDL_BlitSurface9Grid ( SDL_Surface src,
const SDL_Rect srcrect,
int  left_width,
int  right_width,
int  top_height,
int  bottom_height,
float  scale,
SDL_ScaleMode  scaleMode,
SDL_Surface dst,
const SDL_Rect dstrect 
)
extern

Perform a scaled blit using the 9-grid algorithm to a destination surface, which may be of a different format.

The pixels in the source surface are split into a 3x3 grid, using the different corner sizes for each corner, and the sides and center making up the remaining pixels. The corners are then scaled using scale and fit into the corners of the destination rectangle. The sides and center are then stretched into place to cover the remaining destination rectangle.

Parameters
srcthe SDL_Surface structure to be copied from.
srcrectthe SDL_Rect structure representing the rectangle to be used for the 9-grid, or NULL to use the entire surface.
left_widththe width, in pixels, of the left corners in srcrect.
right_widththe width, in pixels, of the right corners in srcrect.
top_heightthe height, in pixels, of the top corners in srcrect.
bottom_heightthe height, in pixels, of the bottom corners in srcrect.
scalethe scale used to transform the corner of srcrect into the corner of dstrect, or 0.0f for an unscaled blit.
scaleModescale algorithm to be used.
dstthe SDL_Surface structure that is the blit target.
dstrectthe SDL_Rect structure representing the target rectangle in the destination surface, or NULL to fill the entire surface.
Returns
true on success or false on failure; call SDL_GetError() for more information.

\threadsafety The same destination surface should not be used from two threads at once. It is safe to use the same source surface from multiple threads.

Since
This function is available since SDL 3.0.0.
See also
SDL_BlitSurface

◆ SDL_BlitSurfaceScaled()

bool SDL_BlitSurfaceScaled ( SDL_Surface src,
const SDL_Rect srcrect,
SDL_Surface dst,
const SDL_Rect dstrect,
SDL_ScaleMode  scaleMode 
)
extern

Perform a scaled blit to a destination surface, which may be of a different format.

Parameters
srcthe SDL_Surface structure to be copied from.
srcrectthe SDL_Rect structure representing the rectangle to be copied, or NULL to copy the entire surface.
dstthe SDL_Surface structure that is the blit target.
dstrectthe SDL_Rect structure representing the target rectangle in the destination surface, or NULL to fill the entire destination surface.
scaleModethe SDL_ScaleMode to be used.
Returns
true on success or false on failure; call SDL_GetError() for more information.

\threadsafety The same destination surface should not be used from two threads at once. It is safe to use the same source surface from multiple threads.

Since
This function is available since SDL 3.0.0.
See also
SDL_BlitSurface

◆ SDL_BlitSurfaceTiled()

bool SDL_BlitSurfaceTiled ( SDL_Surface src,
const SDL_Rect srcrect,
SDL_Surface dst,
const SDL_Rect dstrect 
)
extern

Perform a tiled blit to a destination surface, which may be of a different format.

The pixels in srcrect will be repeated as many times as needed to completely fill dstrect.

Parameters
srcthe SDL_Surface structure to be copied from.
srcrectthe SDL_Rect structure representing the rectangle to be copied, or NULL to copy the entire surface.
dstthe SDL_Surface structure that is the blit target.
dstrectthe SDL_Rect structure representing the target rectangle in the destination surface, or NULL to fill the entire surface.
Returns
true on success or false on failure; call SDL_GetError() for more information.

\threadsafety The same destination surface should not be used from two threads at once. It is safe to use the same source surface from multiple threads.

Since
This function is available since SDL 3.0.0.
See also
SDL_BlitSurface

◆ SDL_BlitSurfaceTiledWithScale()

bool SDL_BlitSurfaceTiledWithScale ( SDL_Surface src,
const SDL_Rect srcrect,
float  scale,
SDL_ScaleMode  scaleMode,
SDL_Surface dst,
const SDL_Rect dstrect 
)
extern

Perform a scaled and tiled blit to a destination surface, which may be of a different format.

The pixels in srcrect will be scaled and repeated as many times as needed to completely fill dstrect.

Parameters
srcthe SDL_Surface structure to be copied from.
srcrectthe SDL_Rect structure representing the rectangle to be copied, or NULL to copy the entire surface.
scalethe scale used to transform srcrect into the destination rectangle, e.g. a 32x32 texture with a scale of 2 would fill 64x64 tiles.
scaleModescale algorithm to be used.
dstthe SDL_Surface structure that is the blit target.
dstrectthe SDL_Rect structure representing the target rectangle in the destination surface, or NULL to fill the entire surface.
Returns
true on success or false on failure; call SDL_GetError() for more information.

\threadsafety The same destination surface should not be used from two threads at once. It is safe to use the same source surface from multiple threads.

Since
This function is available since SDL 3.0.0.
See also
SDL_BlitSurface

◆ SDL_BlitSurfaceUnchecked()

bool SDL_BlitSurfaceUnchecked ( SDL_Surface src,
const SDL_Rect srcrect,
SDL_Surface dst,
const SDL_Rect dstrect 
)
extern

Perform low-level surface blitting only.

This is a semi-private blit function and it performs low-level surface blitting, assuming the input rectangles have already been clipped.

Parameters
srcthe SDL_Surface structure to be copied from.
srcrectthe SDL_Rect structure representing the rectangle to be copied, may not be NULL.
dstthe SDL_Surface structure that is the blit target.
dstrectthe SDL_Rect structure representing the target rectangle in the destination surface, may not be NULL.
Returns
true on success or false on failure; call SDL_GetError() for more information.

\threadsafety The same destination surface should not be used from two threads at once. It is safe to use the same source surface from multiple threads.

Since
This function is available since SDL 3.0.0.
See also
SDL_BlitSurface

◆ SDL_BlitSurfaceUncheckedScaled()

bool SDL_BlitSurfaceUncheckedScaled ( SDL_Surface src,
const SDL_Rect srcrect,
SDL_Surface dst,
const SDL_Rect dstrect,
SDL_ScaleMode  scaleMode 
)
extern

Perform low-level surface scaled blitting only.

This is a semi-private function and it performs low-level surface blitting, assuming the input rectangles have already been clipped.

Parameters
srcthe SDL_Surface structure to be copied from.
srcrectthe SDL_Rect structure representing the rectangle to be copied, may not be NULL.
dstthe SDL_Surface structure that is the blit target.
dstrectthe SDL_Rect structure representing the target rectangle in the destination surface, may not be NULL.
scaleModethe SDL_ScaleMode to be used.
Returns
true on success or false on failure; call SDL_GetError() for more information.

\threadsafety The same destination surface should not be used from two threads at once. It is safe to use the same source surface from multiple threads.

Since
This function is available since SDL 3.0.0.
See also
SDL_BlitSurfaceScaled

◆ SDL_ClearSurface()

bool SDL_ClearSurface ( SDL_Surface surface,
float  r,
float  g,
float  b,
float  a 
)
extern

Clear a surface with a specific color, with floating point precision.

This function handles all surface formats, and ignores any clip rectangle.

If the surface is YUV, the color is assumed to be in the sRGB colorspace, otherwise the color is assumed to be in the colorspace of the suface.

Parameters
surfacethe SDL_Surface to clear.
rthe red component of the pixel, normally in the range 0-1.
gthe green component of the pixel, normally in the range 0-1.
bthe blue component of the pixel, normally in the range 0-1.
athe alpha component of the pixel, normally in the range 0-1.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.

◆ SDL_ConvertPixels()

bool SDL_ConvertPixels ( int  width,
int  height,
SDL_PixelFormat  src_format,
const void *  src,
int  src_pitch,
SDL_PixelFormat  dst_format,
void *  dst,
int  dst_pitch 
)
extern

Copy a block of pixels of one format to another format.

Parameters
widththe width of the block to copy, in pixels.
heightthe height of the block to copy, in pixels.
src_formatan SDL_PixelFormat value of the src pixels format.
srca pointer to the source pixels.
src_pitchthe pitch of the source pixels, in bytes.
dst_formatan SDL_PixelFormat value of the dst pixels format.
dsta pointer to be filled in with new pixel data.
dst_pitchthe pitch of the destination pixels, in bytes.
Returns
false on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_ConvertPixelsAndColorspace

◆ SDL_ConvertPixelsAndColorspace()

bool SDL_ConvertPixelsAndColorspace ( int  width,
int  height,
SDL_PixelFormat  src_format,
SDL_Colorspace  src_colorspace,
SDL_PropertiesID  src_properties,
const void *  src,
int  src_pitch,
SDL_PixelFormat  dst_format,
SDL_Colorspace  dst_colorspace,
SDL_PropertiesID  dst_properties,
void *  dst,
int  dst_pitch 
)
extern

Copy a block of pixels of one format and colorspace to another format and colorspace.

Parameters
widththe width of the block to copy, in pixels.
heightthe height of the block to copy, in pixels.
src_formatan SDL_PixelFormat value of the src pixels format.
src_colorspacean SDL_ColorSpace value describing the colorspace of the src pixels.
src_propertiesan SDL_PropertiesID with additional source color properties, or 0.
srca pointer to the source pixels.
src_pitchthe pitch of the source pixels, in bytes.
dst_formatan SDL_PixelFormat value of the dst pixels format.
dst_colorspacean SDL_ColorSpace value describing the colorspace of the dst pixels.
dst_propertiesan SDL_PropertiesID with additional destination color properties, or 0.
dsta pointer to be filled in with new pixel data.
dst_pitchthe pitch of the destination pixels, in bytes.
Returns
false on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_ConvertPixels

◆ SDL_ConvertSurface()

SDL_Surface * SDL_ConvertSurface ( SDL_Surface surface,
SDL_PixelFormat  format 
)
extern

Copy an existing surface to a new surface of the specified format.

This function is used to optimize images for faster repeat blitting. This is accomplished by converting the original and storing the result as a new surface. The new, optimized surface can then be used as the source for future blits, making them faster.

If you are converting to an indexed surface and want to map colors to a palette, you can use SDL_ConvertSurfaceAndColorspace() instead.

If the original surface has alternate images, the new surface will have a reference to them as well.

Parameters
surfacethe existing SDL_Surface structure to convert.
formatthe new pixel format.
Returns
the new SDL_Surface structure that is created or NULL on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_ConvertSurfaceAndColorspace
SDL_DestroySurface

◆ SDL_ConvertSurfaceAndColorspace()

SDL_Surface * SDL_ConvertSurfaceAndColorspace ( SDL_Surface surface,
SDL_PixelFormat  format,
SDL_Palette palette,
SDL_Colorspace  colorspace,
SDL_PropertiesID  props 
)
extern

Copy an existing surface to a new surface of the specified format and colorspace.

This function converts an existing surface to a new format and colorspace and returns the new surface. This will perform any pixel format and colorspace conversion needed.

If the original surface has alternate images, the new surface will have a reference to them as well.

Parameters
surfacethe existing SDL_Surface structure to convert.
formatthe new pixel format.
palettean optional palette to use for indexed formats, may be NULL.
colorspacethe new colorspace.
propsan SDL_PropertiesID with additional color properties, or 0.
Returns
the new SDL_Surface structure that is created or NULL on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_ConvertSurface
SDL_ConvertSurface
SDL_DestroySurface

◆ SDL_CreateSurface()

SDL_Surface * SDL_CreateSurface ( int  width,
int  height,
SDL_PixelFormat  format 
)
extern

Allocate a new surface with a specific pixel format.

The pixels of the new surface are initialized to zero.

Parameters
widththe width of the surface.
heightthe height of the surface.
formatthe SDL_PixelFormat for the new surface's pixel format.
Returns
the new SDL_Surface structure that is created or NULL on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_CreateSurfaceFrom
SDL_DestroySurface

◆ SDL_CreateSurfaceFrom()

SDL_Surface * SDL_CreateSurfaceFrom ( int  width,
int  height,
SDL_PixelFormat  format,
void *  pixels,
int  pitch 
)
extern

Allocate a new surface with a specific pixel format and existing pixel data.

No copy is made of the pixel data. Pixel data is not managed automatically; you must free the surface before you free the pixel data.

Pitch is the offset in bytes from one row of pixels to the next, e.g. width*4 for SDL_PIXELFORMAT_RGBA8888.

You may pass NULL for pixels and 0 for pitch to create a surface that you will fill in with valid values later.

Parameters
widththe width of the surface.
heightthe height of the surface.
formatthe SDL_PixelFormat for the new surface's pixel format.
pixelsa pointer to existing pixel data.
pitchthe number of bytes between each row, including padding.
Returns
the new SDL_Surface structure that is created or NULL on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_CreateSurface
SDL_DestroySurface

◆ SDL_CreateSurfacePalette()

SDL_Palette * SDL_CreateSurfacePalette ( SDL_Surface surface)
extern

Create a palette and associate it with a surface.

This function creates a palette compatible with the provided surface. The palette is then returned for you to modify, and the surface will automatically use the new palette in future operations. You do not need to destroy the returned palette, it will be freed when the reference count reaches 0, usually when the surface is destroyed.

Bitmap surfaces (with format SDL_PIXELFORMAT_INDEX1LSB or SDL_PIXELFORMAT_INDEX1MSB) will have the palette initialized with 0 as white and 1 as black. Other surfaces will get a palette initialized with white in every entry.

If this function is called for a surface that already has a palette, a new palette will be created to replace it.

Parameters
surfacethe SDL_Surface structure to update.
Returns
a new SDL_Palette structure on success or NULL on failure (e.g. if the surface didn't have an index format); call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_SetPaletteColors

◆ SDL_DestroySurface()

void SDL_DestroySurface ( SDL_Surface surface)
extern

Free a surface.

It is safe to pass NULL to this function.

Parameters
surfacethe SDL_Surface to free.
Since
This function is available since SDL 3.0.0.
See also
SDL_CreateStackSurface
SDL_CreateSurface
SDL_CreateSurfaceFrom

◆ SDL_DuplicateSurface()

SDL_Surface * SDL_DuplicateSurface ( SDL_Surface surface)
extern

Creates a new surface identical to the existing surface.

If the original surface has alternate images, the new surface will have a reference to them as well.

The returned surface should be freed with SDL_DestroySurface().

Parameters
surfacethe surface to duplicate.
Returns
a copy of the surface or NULL on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_DestroySurface

◆ SDL_FillSurfaceRect()

bool SDL_FillSurfaceRect ( SDL_Surface dst,
const SDL_Rect rect,
Uint32  color 
)
extern

Perform a fast fill of a rectangle with a specific color.

color should be a pixel of the format used by the surface, and can be generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an alpha component then the destination is simply filled with that alpha information, no blending takes place.

If there is a clip rectangle set on the destination (set via SDL_SetSurfaceClipRect()), then this function will fill based on the intersection of the clip rectangle and rect.

Parameters
dstthe SDL_Surface structure that is the drawing target.
rectthe SDL_Rect structure representing the rectangle to fill, or NULL to fill the entire surface.
colorthe color to fill with.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_FillSurfaceRects

◆ SDL_FillSurfaceRects()

bool SDL_FillSurfaceRects ( SDL_Surface dst,
const SDL_Rect rects,
int  count,
Uint32  color 
)
extern

Perform a fast fill of a set of rectangles with a specific color.

color should be a pixel of the format used by the surface, and can be generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an alpha component then the destination is simply filled with that alpha information, no blending takes place.

If there is a clip rectangle set on the destination (set via SDL_SetSurfaceClipRect()), then this function will fill based on the intersection of the clip rectangle and rect.

Parameters
dstthe SDL_Surface structure that is the drawing target.
rectsan array of SDL_Rects representing the rectangles to fill.
countthe number of rectangles in the array.
colorthe color to fill with.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_FillSurfaceRect

◆ SDL_FlipSurface()

bool SDL_FlipSurface ( SDL_Surface surface,
SDL_FlipMode  flip 
)
extern

Flip a surface vertically or horizontally.

Parameters
surfacethe surface to flip.
flipthe direction to flip.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.

◆ SDL_GetSurfaceAlphaMod()

bool SDL_GetSurfaceAlphaMod ( SDL_Surface surface,
Uint8 alpha 
)
extern

Get the additional alpha value used in blit operations.

Parameters
surfacethe SDL_Surface structure to query.
alphaa pointer filled in with the current alpha value.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_GetSurfaceColorMod
SDL_SetSurfaceAlphaMod

◆ SDL_GetSurfaceBlendMode()

bool SDL_GetSurfaceBlendMode ( SDL_Surface surface,
SDL_BlendMode blendMode 
)
extern

Get the blend mode used for blit operations.

Parameters
surfacethe SDL_Surface structure to query.
blendModea pointer filled in with the current SDL_BlendMode.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_SetSurfaceBlendMode

◆ SDL_GetSurfaceClipRect()

bool SDL_GetSurfaceClipRect ( SDL_Surface surface,
SDL_Rect rect 
)
extern

Get the clipping rectangle for a surface.

When surface is the destination of a blit, only the area within the clip rectangle is drawn into.

Parameters
surfacethe SDL_Surface structure representing the surface to be clipped.
rectan SDL_Rect structure filled in with the clipping rectangle for the surface.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_SetSurfaceClipRect

◆ SDL_GetSurfaceColorKey()

bool SDL_GetSurfaceColorKey ( SDL_Surface surface,
Uint32 key 
)
extern

Get the color key (transparent pixel) for a surface.

The color key is a pixel of the format used by the surface, as generated by SDL_MapRGB().

If the surface doesn't have color key enabled this function returns false.

Parameters
surfacethe SDL_Surface structure to query.
keya pointer filled in with the transparent pixel.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_SetSurfaceColorKey
SDL_SurfaceHasColorKey

◆ SDL_GetSurfaceColorMod()

bool SDL_GetSurfaceColorMod ( SDL_Surface surface,
Uint8 r,
Uint8 g,
Uint8 b 
)
extern

Get the additional color value multiplied into blit operations.

Parameters
surfacethe SDL_Surface structure to query.
ra pointer filled in with the current red color value.
ga pointer filled in with the current green color value.
ba pointer filled in with the current blue color value.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_GetSurfaceAlphaMod
SDL_SetSurfaceColorMod

◆ SDL_GetSurfaceColorspace()

SDL_Colorspace SDL_GetSurfaceColorspace ( SDL_Surface surface)
extern

Get the colorspace used by a surface.

The colorspace defaults to SDL_COLORSPACE_SRGB_LINEAR for floating point formats, SDL_COLORSPACE_HDR10 for 10-bit formats, SDL_COLORSPACE_SRGB for other RGB surfaces and SDL_COLORSPACE_BT709_FULL for YUV textures.

Parameters
surfacethe SDL_Surface structure to query.
Returns
the colorspace used by the surface, or SDL_COLORSPACE_UNKNOWN if the surface is NULL.
Since
This function is available since SDL 3.0.0.
See also
SDL_SetSurfaceColorspace

◆ SDL_GetSurfaceImages()

SDL_Surface ** SDL_GetSurfaceImages ( SDL_Surface surface,
int *  count 
)
extern

Get an array including all versions of a surface.

This returns all versions of a surface, with the surface being queried as the first element in the returned array.

Freeing the array of surfaces does not affect the surfaces in the array. They are still referenced by the surface being queried and will be cleaned up normally.

Parameters
surfacethe SDL_Surface structure to query.
counta pointer filled in with the number of surface pointers returned, may be NULL.
Returns
a NULL terminated array of SDL_Surface pointers or NULL on failure; call SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed.
Since
This function is available since SDL 3.0.0.
See also
SDL_AddSurfaceAlternateImage
SDL_RemoveSurfaceAlternateImages
SDL_SurfaceHasAlternateImages

◆ SDL_GetSurfacePalette()

SDL_Palette * SDL_GetSurfacePalette ( SDL_Surface surface)
extern

Get the palette used by a surface.

Parameters
surfacethe SDL_Surface structure to query.
Returns
a pointer to the palette used by the surface, or NULL if there is no palette used.
Since
This function is available since SDL 3.0.0.
See also
SDL_SetSurfacePalette

◆ SDL_GetSurfaceProperties()

SDL_PropertiesID SDL_GetSurfaceProperties ( SDL_Surface surface)
extern

Get the properties associated with a surface.

The following properties are understood by SDL:

  • SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT: for HDR10 and floating point surfaces, this defines the value of 100% diffuse white, with higher values being displayed in the High Dynamic Range headroom. This defaults to 203 for HDR10 surfaces and 1.0 for floating point surfaces.
  • SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT: for HDR10 and floating point surfaces, this defines the maximum dynamic range used by the content, in terms of the SDR white point. This defaults to 0.0, which disables tone mapping.
  • SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING: the tone mapping operator used when compressing from a surface with high dynamic range to another with lower dynamic range. Currently this supports "chrome", which uses the same tone mapping that Chrome uses for HDR content, the form "*=N", where N is a floating point scale factor applied in linear space, and "none", which disables tone mapping. This defaults to "chrome".
Parameters
surfacethe SDL_Surface structure to query.
Returns
a valid property ID on success or 0 on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.

◆ SDL_LoadBMP()

SDL_Surface * SDL_LoadBMP ( const char *  file)
extern

Load a BMP image from a file.

The new surface should be freed with SDL_DestroySurface(). Not doing so will result in a memory leak.

Parameters
filethe BMP file to load.
Returns
a pointer to a new SDL_Surface structure or NULL on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_DestroySurface
SDL_LoadBMP_IO
SDL_SaveBMP

◆ SDL_LoadBMP_IO()

SDL_Surface * SDL_LoadBMP_IO ( SDL_IOStream src,
bool  closeio 
)
extern

Load a BMP image from a seekable SDL data stream.

The new surface should be freed with SDL_DestroySurface(). Not doing so will result in a memory leak.

Parameters
srcthe data stream for the surface.
closeioif true, calls SDL_CloseIO() on src before returning, even in the case of an error.
Returns
a pointer to a new SDL_Surface structure or NULL on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_DestroySurface
SDL_LoadBMP
SDL_SaveBMP_IO

◆ SDL_LockSurface()

bool SDL_LockSurface ( SDL_Surface surface)
extern

Set up a surface for directly accessing the pixels.

Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write to and read from surface->pixels, using the pixel format stored in surface->format. Once you are done accessing the surface, you should use SDL_UnlockSurface() to release it.

Not all surfaces require locking. If SDL_MUSTLOCK(surface) evaluates to 0, then you can read and write to the surface at any time, and the pixel format of the surface will not change.

Parameters
surfacethe SDL_Surface structure to be locked.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_MUSTLOCK
SDL_UnlockSurface

◆ SDL_MapSurfaceRGB()

Uint32 SDL_MapSurfaceRGB ( SDL_Surface surface,
Uint8  r,
Uint8  g,
Uint8  b 
)
extern

Map an RGB triple to an opaque pixel value for a surface.

This function maps the RGB color value to the specified pixel format and returns the pixel value best approximating the given RGB color value for the given pixel format.

If the surface has a palette, the index of the closest matching color in the palette will be returned.

If the surface pixel format has an alpha component it will be returned as all 1 bits (fully opaque).

If the pixel format bpp (color depth) is less than 32-bpp then the unused upper bits of the return value can safely be ignored (e.g., with a 16-bpp format the return value can be assigned to a Uint16, and similarly a Uint8 for an 8-bpp format).

Parameters
surfacethe surface to use for the pixel format and palette.
rthe red component of the pixel in the range 0-255.
gthe green component of the pixel in the range 0-255.
bthe blue component of the pixel in the range 0-255.
Returns
a pixel value.
Since
This function is available since SDL 3.0.0.
See also
SDL_MapSurfaceRGBA

◆ SDL_MapSurfaceRGBA()

Uint32 SDL_MapSurfaceRGBA ( SDL_Surface surface,
Uint8  r,
Uint8  g,
Uint8  b,
Uint8  a 
)
extern

Map an RGBA quadruple to a pixel value for a surface.

This function maps the RGBA color value to the specified pixel format and returns the pixel value best approximating the given RGBA color value for the given pixel format.

If the surface pixel format has no alpha component the alpha value will be ignored (as it will be in formats with a palette).

If the surface has a palette, the index of the closest matching color in the palette will be returned.

If the pixel format bpp (color depth) is less than 32-bpp then the unused upper bits of the return value can safely be ignored (e.g., with a 16-bpp format the return value can be assigned to a Uint16, and similarly a Uint8 for an 8-bpp format).

Parameters
surfacethe surface to use for the pixel format and palette.
rthe red component of the pixel in the range 0-255.
gthe green component of the pixel in the range 0-255.
bthe blue component of the pixel in the range 0-255.
athe alpha component of the pixel in the range 0-255.
Returns
a pixel value.
Since
This function is available since SDL 3.0.0.
See also
SDL_MapSurfaceRGB

◆ SDL_PremultiplyAlpha()

bool SDL_PremultiplyAlpha ( int  width,
int  height,
SDL_PixelFormat  src_format,
const void *  src,
int  src_pitch,
SDL_PixelFormat  dst_format,
void *  dst,
int  dst_pitch,
bool  linear 
)
extern

Premultiply the alpha on a block of pixels.

This is safe to use with src == dst, but not for other overlapping areas.

Parameters
widththe width of the block to convert, in pixels.
heightthe height of the block to convert, in pixels.
src_formatan SDL_PixelFormat value of the src pixels format.
srca pointer to the source pixels.
src_pitchthe pitch of the source pixels, in bytes.
dst_formatan SDL_PixelFormat value of the dst pixels format.
dsta pointer to be filled in with premultiplied pixel data.
dst_pitchthe pitch of the destination pixels, in bytes.
lineartrue to convert from sRGB to linear space for the alpha multiplication, false to do multiplication in sRGB space.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.

◆ SDL_PremultiplySurfaceAlpha()

bool SDL_PremultiplySurfaceAlpha ( SDL_Surface surface,
bool  linear 
)
extern

Premultiply the alpha in a surface.

This is safe to use with src == dst, but not for other overlapping areas.

Parameters
surfacethe surface to modify.
lineartrue to convert from sRGB to linear space for the alpha multiplication, false to do multiplication in sRGB space.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.

◆ SDL_ReadSurfacePixel()

bool SDL_ReadSurfacePixel ( SDL_Surface surface,
int  x,
int  y,
Uint8 r,
Uint8 g,
Uint8 b,
Uint8 a 
)
extern

Retrieves a single pixel from a surface.

This function prioritizes correctness over speed: it is suitable for unit tests, but is not intended for use in a game engine.

Like SDL_GetRGBA, this uses the entire 0..255 range when converting color components from pixel formats with less than 8 bits per RGB component.

Parameters
surfacethe surface to read.
xthe horizontal coordinate, 0 <= x < width.
ythe vertical coordinate, 0 <= y < height.
ra pointer filled in with the red channel, 0-255, or NULL to ignore this channel.
ga pointer filled in with the green channel, 0-255, or NULL to ignore this channel.
ba pointer filled in with the blue channel, 0-255, or NULL to ignore this channel.
aa pointer filled in with the alpha channel, 0-255, or NULL to ignore this channel.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.

◆ SDL_ReadSurfacePixelFloat()

bool SDL_ReadSurfacePixelFloat ( SDL_Surface surface,
int  x,
int  y,
float *  r,
float *  g,
float *  b,
float *  a 
)
extern

Retrieves a single pixel from a surface.

This function prioritizes correctness over speed: it is suitable for unit tests, but is not intended for use in a game engine.

Parameters
surfacethe surface to read.
xthe horizontal coordinate, 0 <= x < width.
ythe vertical coordinate, 0 <= y < height.
ra pointer filled in with the red channel, normally in the range 0-1, or NULL to ignore this channel.
ga pointer filled in with the green channel, normally in the range 0-1, or NULL to ignore this channel.
ba pointer filled in with the blue channel, normally in the range 0-1, or NULL to ignore this channel.
aa pointer filled in with the alpha channel, normally in the range 0-1, or NULL to ignore this channel.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.

◆ SDL_RemoveSurfaceAlternateImages()

void SDL_RemoveSurfaceAlternateImages ( SDL_Surface surface)
extern

Remove all alternate versions of a surface.

This function removes a reference from all the alternative versions, destroying them if this is the last reference to them.

Parameters
surfacethe SDL_Surface structure to update.
Since
This function is available since SDL 3.0.0.
See also
SDL_AddSurfaceAlternateImage
SDL_GetSurfaceImages
SDL_SurfaceHasAlternateImages

◆ SDL_SaveBMP()

bool SDL_SaveBMP ( SDL_Surface surface,
const char *  file 
)
extern

Save a surface to a file.

Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the BMP directly. Other RGB formats with 8-bit or higher get converted to a 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit surface before they are saved. YUV and paletted 1-bit and 4-bit formats are not supported.

Parameters
surfacethe SDL_Surface structure containing the image to be saved.
filea file to save to.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_LoadBMP
SDL_SaveBMP_IO

◆ SDL_SaveBMP_IO()

bool SDL_SaveBMP_IO ( SDL_Surface surface,
SDL_IOStream dst,
bool  closeio 
)
extern

Save a surface to a seekable SDL data stream in BMP format.

Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the BMP directly. Other RGB formats with 8-bit or higher get converted to a 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit surface before they are saved. YUV and paletted 1-bit and 4-bit formats are not supported.

Parameters
surfacethe SDL_Surface structure containing the image to be saved.
dsta data stream to save to.
closeioif true, calls SDL_CloseIO() on dst before returning, even in the case of an error.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_LoadBMP_IO
SDL_SaveBMP

◆ SDL_ScaleSurface()

SDL_Surface * SDL_ScaleSurface ( SDL_Surface surface,
int  width,
int  height,
SDL_ScaleMode  scaleMode 
)
extern

Creates a new surface identical to the existing surface, scaled to the desired size.

The returned surface should be freed with SDL_DestroySurface().

Parameters
surfacethe surface to duplicate and scale.
widththe width of the new surface.
heightthe height of the new surface.
scaleModethe SDL_ScaleMode to be used.
Returns
a copy of the surface or NULL on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_DestroySurface

◆ SDL_SetSurfaceAlphaMod()

bool SDL_SetSurfaceAlphaMod ( SDL_Surface surface,
Uint8  alpha 
)
extern

Set an additional alpha value used in blit operations.

When this surface is blitted, during the blit operation the source alpha value is modulated by this alpha value according to the following formula:

srcA = srcA * (alpha / 255)

Parameters
surfacethe SDL_Surface structure to update.
alphathe alpha value multiplied into blit operations.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_GetSurfaceAlphaMod
SDL_SetSurfaceColorMod

◆ SDL_SetSurfaceBlendMode()

bool SDL_SetSurfaceBlendMode ( SDL_Surface surface,
SDL_BlendMode  blendMode 
)
extern

Set the blend mode used for blit operations.

To copy a surface to another surface (or texture) without blending with the existing data, the blendmode of the SOURCE surface should be set to SDL_BLENDMODE_NONE.

Parameters
surfacethe SDL_Surface structure to update.
blendModethe SDL_BlendMode to use for blit blending.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_GetSurfaceBlendMode

◆ SDL_SetSurfaceClipRect()

bool SDL_SetSurfaceClipRect ( SDL_Surface surface,
const SDL_Rect rect 
)
extern

Set the clipping rectangle for a surface.

When surface is the destination of a blit, only the area within the clip rectangle is drawn into.

Note that blits are automatically clipped to the edges of the source and destination surfaces.

Parameters
surfacethe SDL_Surface structure to be clipped.
rectthe SDL_Rect structure representing the clipping rectangle, or NULL to disable clipping.
Returns
true if the rectangle intersects the surface, otherwise false and blits will be completely clipped.
Since
This function is available since SDL 3.0.0.
See also
SDL_GetSurfaceClipRect

◆ SDL_SetSurfaceColorKey()

bool SDL_SetSurfaceColorKey ( SDL_Surface surface,
bool  enabled,
Uint32  key 
)
extern

Set the color key (transparent pixel) in a surface.

The color key defines a pixel value that will be treated as transparent in a blit. For example, one can use this to specify that cyan pixels should be considered transparent, and therefore not rendered.

It is a pixel of the format used by the surface, as generated by SDL_MapRGB().

Parameters
surfacethe SDL_Surface structure to update.
enabledtrue to enable color key, false to disable color key.
keythe transparent pixel.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_GetSurfaceColorKey
SDL_SetSurfaceRLE
SDL_SurfaceHasColorKey

◆ SDL_SetSurfaceColorMod()

bool SDL_SetSurfaceColorMod ( SDL_Surface surface,
Uint8  r,
Uint8  g,
Uint8  b 
)
extern

Set an additional color value multiplied into blit operations.

When this surface is blitted, during the blit operation each source color channel is modulated by the appropriate color value according to the following formula:

srcC = srcC * (color / 255)

Parameters
surfacethe SDL_Surface structure to update.
rthe red color value multiplied into blit operations.
gthe green color value multiplied into blit operations.
bthe blue color value multiplied into blit operations.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_GetSurfaceColorMod
SDL_SetSurfaceAlphaMod

◆ SDL_SetSurfaceColorspace()

bool SDL_SetSurfaceColorspace ( SDL_Surface surface,
SDL_Colorspace  colorspace 
)
extern

Set the colorspace used by a surface.

Setting the colorspace doesn't change the pixels, only how they are interpreted in color operations.

Parameters
surfacethe SDL_Surface structure to update.
colorspacean SDL_ColorSpace value describing the surface colorspace.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_GetSurfaceColorspace

◆ SDL_SetSurfacePalette()

bool SDL_SetSurfacePalette ( SDL_Surface surface,
SDL_Palette palette 
)
extern

Set the palette used by a surface.

A single palette can be shared with many surfaces.

Parameters
surfacethe SDL_Surface structure to update.
palettethe SDL_Palette structure to use.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_CreatePalette
SDL_GetSurfacePalette

◆ SDL_SetSurfaceRLE()

bool SDL_SetSurfaceRLE ( SDL_Surface surface,
bool  enabled 
)
extern

Set the RLE acceleration hint for a surface.

If RLE is enabled, color key and alpha blending blits are much faster, but the surface must be locked before directly accessing the pixels.

Parameters
surfacethe SDL_Surface structure to optimize.
enabledtrue to enable RLE acceleration, false to disable it.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_BlitSurface
SDL_LockSurface
SDL_UnlockSurface

◆ SDL_SurfaceHasAlternateImages()

bool SDL_SurfaceHasAlternateImages ( SDL_Surface surface)
extern

Return whether a surface has alternate versions available.

Parameters
surfacethe SDL_Surface structure to query.
Returns
true if alternate versions are available or true otherwise.
Since
This function is available since SDL 3.0.0.
See also
SDL_AddSurfaceAlternateImage
SDL_RemoveSurfaceAlternateImages
SDL_GetSurfaceImages

◆ SDL_SurfaceHasColorKey()

bool SDL_SurfaceHasColorKey ( SDL_Surface surface)
extern

Returns whether the surface has a color key.

It is safe to pass a NULL surface here; it will return false.

Parameters
surfacethe SDL_Surface structure to query.
Returns
true if the surface has a color key, false otherwise.
Since
This function is available since SDL 3.0.0.
See also
SDL_SetSurfaceColorKey
SDL_GetSurfaceColorKey

◆ SDL_SurfaceHasRLE()

bool SDL_SurfaceHasRLE ( SDL_Surface surface)
extern

Returns whether the surface is RLE enabled.

It is safe to pass a NULL surface here; it will return false.

Parameters
surfacethe SDL_Surface structure to query.
Returns
true if the surface is RLE enabled, false otherwise.
Since
This function is available since SDL 3.0.0.
See also
SDL_SetSurfaceRLE

◆ SDL_UnlockSurface()

void SDL_UnlockSurface ( SDL_Surface surface)
extern

Release a surface after directly accessing the pixels.

Parameters
surfacethe SDL_Surface structure to be unlocked.
Since
This function is available since SDL 3.0.0.
See also
SDL_LockSurface

◆ SDL_WriteSurfacePixel()

bool SDL_WriteSurfacePixel ( SDL_Surface surface,
int  x,
int  y,
Uint8  r,
Uint8  g,
Uint8  b,
Uint8  a 
)
extern

Writes a single pixel to a surface.

This function prioritizes correctness over speed: it is suitable for unit tests, but is not intended for use in a game engine.

Like SDL_MapRGBA, this uses the entire 0..255 range when converting color components from pixel formats with less than 8 bits per RGB component.

Parameters
surfacethe surface to write.
xthe horizontal coordinate, 0 <= x < width.
ythe vertical coordinate, 0 <= y < height.
rthe red channel value, 0-255.
gthe green channel value, 0-255.
bthe blue channel value, 0-255.
athe alpha channel value, 0-255.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.

◆ SDL_WriteSurfacePixelFloat()

bool SDL_WriteSurfacePixelFloat ( SDL_Surface surface,
int  x,
int  y,
float  r,
float  g,
float  b,
float  a 
)
extern

Writes a single pixel to a surface.

This function prioritizes correctness over speed: it is suitable for unit tests, but is not intended for use in a game engine.

Parameters
surfacethe surface to write.
xthe horizontal coordinate, 0 <= x < width.
ythe vertical coordinate, 0 <= y < height.
rthe red channel value, normally in the range 0-1.
gthe green channel value, normally in the range 0-1.
bthe blue channel value, normally in the range 0-1.
athe alpha channel value, normally in the range 0-1.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.