module lib.sdl2.surface

Code Map

module lib.sdl2.surface;


//! \name Surface flags
enum SDL_SWSURFACE;
enum SDL_PREALLOC;
enum SDL_RLEACCEL;
enum SDL_DONTFREE;

//! \brief The type of function used for surface blitting functions.
alias SDL_blit = fn (SDL_Surface*, SDL_Rect*, SDL_Surface*, SDL_Rect*) (i32);

//! \brief A collection of pixels used in software blitting.
struct SDL_Surface
{
public:
	flags: Uint32;
	format: SDL_PixelFormat*;
	w: i32;
	h: i32;
	pitch: i32;
	pixels: void*;
	userdata: void*;
	locked: i32;
	lock_data: void*;
	clip_rect: SDL_Rect;
	map: void*;
	refcount: i32;
}

//! Evaluates to true if the surface needs to be locked before access.
fn SDL_MUSTLOCK(s: SDL_Surface*) bool { }
//! Allocate and free an RGB surface.
fn SDL_CreateRGBSurface(flags: Uint32, width: i32, height: i32, depth: i32, Rmask: Uint32, Gmask: Uint32, Bmask: Uint32, Amask: Uint32) SDL_Surface*;
fn SDL_CreateRGBSurfaceWithFormat(flags: Uint32, width: i32, height: i32, depth: i32, format: Uint32) SDL_Surface*;
fn SDL_CreateRGBSurfaceFrom(pixels: void*, width: i32, height: i32, depth: i32, pitch: i32, Rmask: Uint32, Gmask: Uint32, Bmask: Uint32, Amask: Uint32) SDL_Surface*;
fn SDL_CreateRGBSurfaceWithFormatFrom(pixels: void*, width: i32, height: i32, depth: i32, pitch: i32, format: Uint32) SDL_Surface*;
fn SDL_FreeSurface(surface: SDL_Surface*);
//! \brief Set the palette used by a surface.
fn SDL_SetSurfacePalette(surface: SDL_Surface*, palette: SDL_Palette*) i32;
//! \brief Sets up a surface for directly accessing the pixels.
fn SDL_LockSurface(surface: SDL_Surface*) i32;
//! \sa SDL_LockSurface() *
fn SDL_UnlockSurface(surface: SDL_Surface*);
//! Load a surface from a seekable SDL data stream (memory or file).
fn SDL_LoadBMP_RW(src: SDL_RWops*, freesrc: i32) SDL_Surface*;
//! Load a surface from a file.
fn SDL_LoadBMP(s: const(char)*) SDL_Surface* { }
//! Save a surface to a seekable SDL data stream (memory or file).
fn SDL_SaveBMP_RW(surface: SDL_Surface*, dst: SDL_RWops*, freedst: i32) i32;
//! Save a surface to a file.
fn SDL_SaveBMP(surface: SDL_Surface*, s: const(char)*) i32 { }
//! \brief Sets the RLE acceleration hint for a surface.
fn SDL_SetSurfaceRLE(surface: SDL_Surface*, flag: i32) i32;
//! \brief Sets the color key (transparent pixel) in a blittable surface.
fn SDL_SetColorKey(surface: SDL_Surface*, flag: i32, key: Uint32) i32;
//! \brief Gets the color key (transparent pixel) in a blittable surface.
fn SDL_GetColorKey(surface: SDL_Surface*, key: Uint32*) i32;
//! \brief Set an additional color value used in blit operations.
fn SDL_SetSurfaceColorMod(surface: SDL_Surface*, r: Uint8, g: Uint8, b: Uint8) i32;
//! \brief Get the additional color value used in blit operations.
fn SDL_GetSurfaceColorMod(surface: SDL_Surface*, r: Uint8*, g: Uint8*, b: Uint8*) i32;
//! \brief Set an additional alpha value used in blit operations.
fn SDL_SetSurfaceAlphaMod(surface: SDL_Surface*, alpha: Uint8) i32;
//! \brief Get the additional alpha value used in blit operations.
fn SDL_GetSurfaceAlphaMod(surface: SDL_Surface*, alpha: Uint8*) i32;
//! \brief Set the blend mode used for blit operations.
fn SDL_SetSurfaceBlendMode(surface: SDL_Surface*, blendMode: SDL_BlendMode) i32;
//! \brief Get the blend mode used for blit operations.
fn SDL_GetSurfaceBlendMode(surface: SDL_Surface*, blendMode: SDL_BlendMode*) i32;
//! Sets the clipping rectangle for the destination surface in a blit.
fn SDL_SetClipRect(surface: SDL_Surface*, rect: const(const(SDL_Rect)*)) SDL_bool;
//! Gets the clipping rectangle for the destination surface in a blit.
fn SDL_GetClipRect(surface: SDL_Surface*, rect: SDL_Rect*);
//! Creates a new surface of the specified format, and then copies and
//! maps the given surface to it so the blit of the converted surface will
//! be as fast as possible. If this function fails, it returns NULL.
fn SDL_ConvertSurface(src: SDL_Surface*, fmt: SDL_PixelFormat*, flags: Uint32) SDL_Surface*;
fn SDL_ConvertSurfaceFormat(src: SDL_Surface*, pixel_format: Uint32, flags: Uint32) SDL_Surface*;
//! \brief Copy a block of pixels of one format to another format
fn SDL_ConvertPixels(width: i32, height: i32, src_format: Uint32, src: const(const(void)*), src_pitch: i32, dst_format: Uint32, dst: void*, dst_pitch: i32) i32;
//! Performs a fast fill of the given rectangle with \c color.
fn SDL_FillRect(dst: SDL_Surface*, rect: const(const(SDL_Rect)*), color: Uint32) i32;
fn SDL_FillRects(dst: SDL_Surface*, rects: const(const(SDL_Rect)*), count: i32, color: Uint32) i32;
//! Performs a fast blit from the source surface to the destination
//! surface.
fn SDL_BlitSurface(a: SDL_Surface*, b: const(const(SDL_Rect)*), c: SDL_Surface*, d: SDL_Rect*) i32 { }
//! This is the public blit function, SDL_BlitSurface(), and it performs
//! rectangle validation and clipping before passing it to SDL_LowerBlit()
fn SDL_UpperBlit(src: SDL_Surface*, srcrect: const(const(SDL_Rect)*), dst: SDL_Surface*, dstrect: SDL_Rect*) i32;
//! This is a semi-private blit function and it performs low-level surface
//! blitting only.
fn SDL_LowerBlit(src: SDL_Surface*, srcrect: SDL_Rect*, dst: SDL_Surface*, dstrect: SDL_Rect*) i32;
//! \brief Perform a fast, low quality, stretch blit between two surfaces
//! of the same pixel format.
fn SDL_SoftStretch(src: SDL_Surface*, srcrect: const(const(SDL_Rect)*), dst: SDL_Surface*, dstrect: const(const(SDL_Rect)*)) i32;
fn SDL_BlitScaled(a: SDL_Surface*, b: const(const(SDL_Rect)*), c: SDL_Surface*, d: SDL_Rect*) i32 { }
//! This is the public scaled blit function, SDL_BlitScaled(), and it
//! performs rectangle validation and clipping before passing it to
//! SDL_LowerBlitScaled()
fn SDL_UpperBlitScaled(src: SDL_Surface*, srcrect: const(const(SDL_Rect)*), dst: SDL_Surface*, dstrect: SDL_Rect*) i32;
//! This is a semi-private blit function and it performs low-level surface
//! scaled blitting only.
fn SDL_LowerBlitScaled(src: SDL_Surface*, srcrect: SDL_Rect*, dst: SDL_Surface*, dstrect: SDL_Rect*) i32;
enum SDL_SWSURFACE

\name Surface flags

These are the currently supported flags for the ::SDL_Surface.

\internal Used internally (read-only).

fn SDL_MUSTLOCK(s: SDL_Surface*) bool

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

struct SDL_Surface

\brief A collection of pixels used in software blitting.

\note This structure should be treated as read-only, except for \c pixels, which, if not NULL, contains the raw pixel data for the surface.

alias SDL_blit

\brief The type of function used for surface blitting functions.

fn SDL_CreateRGBSurface(flags: Uint32, width: i32, height: i32, depth: i32, Rmask: Uint32, Gmask: Uint32, Bmask: Uint32, Amask: Uint32) SDL_Surface*

Allocate and free an RGB surface.

If the depth is 4 or 8 bits, an empty palette is allocated for the surface. If the depth is greater than 8 bits, the pixel format is set using the flags '[RGB]mask'.

If the function runs out of memory, it will return NULL.

\param flags The \c flags are obsolete and should be set to 0. \param width The width in pixels of the surface to create. \param height The height in pixels of the surface to create. \param depth The depth in bits of the surface to create. \param Rmask The red mask of the surface to create. \param Gmask The green mask of the surface to create. \param Bmask The blue mask of the surface to create. \param Amask The alpha mask of the surface to create.

fn SDL_SetSurfacePalette(surface: SDL_Surface*, palette: SDL_Palette*) i32

\brief Set the palette used by a surface.

\return 0, or -1 if the surface format doesn't use a palette.

\note A single palette can be shared with many surfaces.

fn SDL_LockSurface(surface: SDL_Surface*) i32

\brief Sets up a surface for directly accessing the pixels.

Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write to and read from \c surface->pixels, using the pixel format stored in \c 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.

No operating system or library calls should be made between lock/unlock pairs, as critical system locks may be held during this time.

SDL_LockSurface() returns 0, or -1 if the surface couldn't be locked.

\sa SDL_UnlockSurface()

fn SDL_UnlockSurface(surface: SDL_Surface*)

\sa SDL_LockSurface() *

fn SDL_LoadBMP_RW(src: SDL_RWops*, freesrc: i32) SDL_Surface*

Load a surface from a seekable SDL data stream (memory or file).

If \c freesrc is non-zero, the stream will be closed after being read.

The new surface should be freed with SDL_FreeSurface().

\return the new surface, or NULL if there was an error.

fn SDL_LoadBMP(s: const(char)*) SDL_Surface*

Load a surface from a file.

Convenience macro.

fn SDL_SaveBMP_RW(surface: SDL_Surface*, dst: SDL_RWops*, freedst: i32) i32

Save a surface to a seekable SDL data stream (memory or file).

If \c freedst is non-zero, the stream will be closed after being written.

\return 0 if successful or -1 if there was an error.

fn SDL_SaveBMP(surface: SDL_Surface*, s: const(char)*) i32

Save a surface to a file.

Convenience macro.

fn SDL_SetSurfaceRLE(surface: SDL_Surface*, flag: i32) i32

\brief Sets the RLE acceleration hint for a surface.

\return 0 on success, or -1 if the surface is not valid

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

fn SDL_SetColorKey(surface: SDL_Surface*, flag: i32, key: Uint32) i32

\brief Sets the color key (transparent pixel) in a blittable surface.

\param surface The surface to update \param flag Non-zero to enable colorkey and 0 to disable colorkey \param key The transparent pixel in the native surface format

\return 0 on success, or -1 if the surface is not valid

You can pass SDL_RLEACCEL to enable RLE accelerated blits.

fn SDL_GetColorKey(surface: SDL_Surface*, key: Uint32*) i32

\brief Gets the color key (transparent pixel) in a blittable surface.

\param surface The surface to update \param key A pointer filled in with the transparent pixel in the native surface format

\return 0 on success, or -1 if the surface is not valid or colorkey is not enabled.

fn SDL_SetSurfaceColorMod(surface: SDL_Surface*, r: Uint8, g: Uint8, b: Uint8) i32

\brief Set an additional color value used in blit operations.

\param surface The surface to update. \param r The red color value multiplied into blit operations. \param g The green color value multiplied into blit operations. \param b The blue color value multiplied into blit operations.

\return 0 on success, or -1 if the surface is not valid.

\sa SDL_GetSurfaceColorMod()

fn SDL_GetSurfaceColorMod(surface: SDL_Surface*, r: Uint8*, g: Uint8*, b: Uint8*) i32

\brief Get the additional color value used in blit operations.

\param surface The surface to query. \param r A pointer filled in with the current red color value. \param g A pointer filled in with the current green color value. \param b A pointer filled in with the current blue color value.

\return 0 on success, or -1 if the surface is not valid.

\sa SDL_SetSurfaceColorMod()

fn SDL_SetSurfaceAlphaMod(surface: SDL_Surface*, alpha: Uint8) i32

\brief Set an additional alpha value used in blit operations.

\param surface The surface to update. \param alpha The alpha value multiplied into blit operations.

\return 0 on success, or -1 if the surface is not valid.

\sa SDL_GetSurfaceAlphaMod()

fn SDL_GetSurfaceAlphaMod(surface: SDL_Surface*, alpha: Uint8*) i32

\brief Get the additional alpha value used in blit operations.

\param surface The surface to query. \param alpha A pointer filled in with the current alpha value.

\return 0 on success, or -1 if the surface is not valid.

\sa SDL_SetSurfaceAlphaMod()

fn SDL_SetSurfaceBlendMode(surface: SDL_Surface*, blendMode: SDL_BlendMode) i32

\brief Set the blend mode used for blit operations.

\param surface The surface to update. \param blendMode ::SDL_BlendMode to use for blit blending.

\return 0 on success, or -1 if the parameters are not valid.

\sa SDL_GetSurfaceBlendMode()

fn SDL_GetSurfaceBlendMode(surface: SDL_Surface*, blendMode: SDL_BlendMode*) i32

\brief Get the blend mode used for blit operations.

\param surface The surface to query. \param blendMode A pointer filled in with the current blend mode.

\return 0 on success, or -1 if the surface is not valid.

\sa SDL_SetSurfaceBlendMode()

fn SDL_SetClipRect(surface: SDL_Surface*, rect: const(const(SDL_Rect)*)) SDL_bool

Sets the clipping rectangle for the destination surface in a blit.

If the clip rectangle is NULL, clipping will be disabled.

If the clip rectangle doesn't intersect the surface, the function will return SDL_FALSE and blits will be completely clipped. Otherwise the function returns SDL_TRUE and blits to the surface will be clipped to the intersection of the surface area and the clipping rectangle.

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

fn SDL_GetClipRect(surface: SDL_Surface*, rect: SDL_Rect*)

Gets the clipping rectangle for the destination surface in a blit.

\c rect must be a pointer to a valid rectangle which will be filled with the correct values.

fn SDL_ConvertSurface(src: SDL_Surface*, fmt: SDL_PixelFormat*, flags: Uint32) SDL_Surface*

Creates a new surface of the specified format, and then copies and maps the given surface to it so the blit of the converted surface will be as fast as possible. If this function fails, it returns NULL.

The \c flags parameter is passed to SDL_CreateRGBSurface() and has those semantics. You can also pass ::SDL_RLEACCEL in the flags parameter and SDL will try to RLE accelerate colorkey and alpha blits in the resulting surface.

fn SDL_ConvertPixels(width: i32, height: i32, src_format: Uint32, src: const(const(void)*), src_pitch: i32, dst_format: Uint32, dst: void*, dst_pitch: i32) i32

\brief Copy a block of pixels of one format to another format

\return 0 on success, or -1 if there was an error

fn SDL_FillRect(dst: SDL_Surface*, rect: const(const(SDL_Rect)*), color: Uint32) i32

Performs a fast fill of the given rectangle with \c color.

If \c rect is NULL, the whole surface will be filled with \c color.

The color should be a pixel of the format used by the surface, and can be generated by the SDL_MapRGB() function.

\return 0 on success, or -1 on error.

fn SDL_BlitSurface(a: SDL_Surface*, b: const(const(SDL_Rect)*), c: SDL_Surface*, d: SDL_Rect*) i32

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 \c srcrect or \c dstrect are NULL, the entire surface (\c src or \c dst) is copied. The final blit rectangles are saved in \c srcrect and \c dstrect after all clipping is performed.

\return If the blit is successful, it returns 0, otherwise it returns -1.

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

The blit semantics for surfaces with and without alpha and colorkey are defined as follows: \verbatim RGBA->RGB: SDL_SRCALPHA set: alpha-blend (using alpha-channel). SDL_SRCCOLORKEY ignored. SDL_SRCALPHA not set: copy RGB. if SDL_SRCCOLORKEY set, only copy the pixels matching the RGB values of the source color key, ignoring alpha in the comparison.

RGB->RGBA: SDL_SRCALPHA set: alpha-blend (using the source per-surface alpha value); set destination alpha to opaque. SDL_SRCALPHA not set: copy RGB, set destination alpha to source per-surface alpha value. both: if SDL_SRCCOLORKEY set, only copy the pixels matching the source color key.

RGBA->RGBA: SDL_SRCALPHA set: alpha-blend (using the source alpha channel) the RGB values; leave destination alpha untouched. [Note: is this correct?] SDL_SRCCOLORKEY ignored. SDL_SRCALPHA not set: copy all of RGBA to the destination. if SDL_SRCCOLORKEY set, only copy the pixels matching the RGB values of the source color key, ignoring alpha in the comparison.

RGB->RGB: SDL_SRCALPHA set: alpha-blend (using the source per-surface alpha value). SDL_SRCALPHA not set: copy RGB. both: if SDL_SRCCOLORKEY set, only copy the pixels matching the source color key. \endverbatim

You should call SDL_BlitSurface() unless you know exactly how SDL blitting works internally and how to use the other blit functions.

fn SDL_UpperBlit(src: SDL_Surface*, srcrect: const(const(SDL_Rect)*), dst: SDL_Surface*, dstrect: SDL_Rect*) i32

This is the public blit function, SDL_BlitSurface(), and it performs rectangle validation and clipping before passing it to SDL_LowerBlit()

fn SDL_LowerBlit(src: SDL_Surface*, srcrect: SDL_Rect*, dst: SDL_Surface*, dstrect: SDL_Rect*) i32

This is a semi-private blit function and it performs low-level surface blitting only.

fn SDL_SoftStretch(src: SDL_Surface*, srcrect: const(const(SDL_Rect)*), dst: SDL_Surface*, dstrect: const(const(SDL_Rect)*)) i32

\brief Perform a fast, low quality, stretch blit between two surfaces of the same pixel format.

\note This function uses a static buffer, and is not thread-safe.

fn SDL_UpperBlitScaled(src: SDL_Surface*, srcrect: const(const(SDL_Rect)*), dst: SDL_Surface*, dstrect: SDL_Rect*) i32

This is the public scaled blit function, SDL_BlitScaled(), and it performs rectangle validation and clipping before passing it to SDL_LowerBlitScaled()

fn SDL_LowerBlitScaled(src: SDL_Surface*, srcrect: SDL_Rect*, dst: SDL_Surface*, dstrect: SDL_Rect*) i32

This is a semi-private blit function and it performs low-level surface scaled blitting only.