1#ifndef SDL3PP_SURFACE_H_
2#define SDL3PP_SURFACE_H_
4#include <SDL3/SDL_surface.h>
5#include "SDL3pp_blendmode.h"
6#include "SDL3pp_error.h"
7#include "SDL3pp_iostream.h"
8#include "SDL3pp_optionalRef.h"
9#include "SDL3pp_pixels.h"
10#include "SDL3pp_properties.h"
11#include "SDL3pp_rect.h"
12#include "SDL3pp_spanRef.h"
13#include "SDL3pp_strings.h"
14#include "SDL3pp_version.h"
69 constexpr explicit operator bool()
const {
return !!
value; }
105 constexpr explicit operator bool()
const {
return !!
value; }
130 SDL_SURFACE_PREALLOCATED;
133 SDL_SURFACE_LOCK_NEEDED;
155#if SDL_VERSION_ATLEAST(3, 2, 10)
162 SDL_SCALEMODE_NEAREST;
165 SDL_SCALEMODE_LINEAR;
167#if SDL_VERSION_ATLEAST(3, 4, 0)
190#if SDL_VERSION_ATLEAST(3, 4, 0)
194 SDL_FLIP_HORIZONTAL_AND_VERTICAL;
232 constexpr Surface(std::nullptr_t =
nullptr) noexcept
245 : m_resource(resource)
251 : m_resource(other.m_resource)
253 ++m_resource->refcount;
279 : m_resource(
CheckError(SDL_CreateSurface(size.x, size.y, format)))
311 SDL_CreateSurfaceFrom(size.x, size.y, format, pixels, pitch)))
414 ++resource.
value->refcount;
462#if SDL_VERSION_ATLEAST(3, 4, 0)
525 std::swap(m_resource, other.m_resource);
539 m_resource =
nullptr;
547 constexpr explicit operator bool() const noexcept {
return !!m_resource; }
550 constexpr operator SurfaceParam() const noexcept {
return {m_resource}; }
875#if SDL_VERSION_ATLEAST(3, 4, 0)
931 void SetRLE(
bool enabled);
1214#if SDL_VERSION_ATLEAST(3, 4, 0)
1661#if SDL_VERSION_ATLEAST(3, 4, 0)
2017 :
Surface(std::move(resource))
2076 : m_lock(other.m_lock)
2099 std::swap(m_lock, other.m_lock);
2104 constexpr operator bool()
const {
return bool(m_lock); }
2342 return Surface(size, format, pixels, pitch);
2402 return {
CheckError(SDL_GetSurfaceProperties(surface))};
2410namespace prop::Surface {
2412constexpr auto SDR_WHITE_POINT_FLOAT = SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT;
2414constexpr auto HDR_HEADROOM_FLOAT = SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT;
2416constexpr auto TONEMAP_OPERATOR_STRING =
2417 SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING;
2419#if SDL_VERSION_ATLEAST(3, 2, 6)
2421constexpr auto HOTSPOT_X_NUMBER = SDL_PROP_SURFACE_HOTSPOT_X_NUMBER;
2423constexpr auto HOTSPOT_Y_NUMBER = SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER;
2427#if SDL_VERSION_ATLEAST(3, 4, 0)
2429constexpr auto ROTATION_FLOAT = SDL_PROP_SURFACE_ROTATION_FLOAT;
2454 CheckError(SDL_SetSurfaceColorspace(surface, colorspace));
2482 return SDL_GetSurfaceColorspace(surface);
2549 CheckError(SDL_SetSurfacePalette(surface, palette));
2607 CheckError(SDL_AddSurfaceAlternateImage(surface, image));
2631 return SDL_SurfaceHasAlternateImages(surface);
2665 auto data = SDL_GetSurfaceImages(surface, &count);
2693 SDL_RemoveSurfaceAlternateImages(surface);
2734 : m_lock(std::move(resource))
2762 if (!m_lock)
return;
2767#ifndef SDL3PP_ENABLE_IMAGE
2768#if SDL_VERSION_ATLEAST(3, 4, 0)
2791 return Surface{SDL_LoadSurface_IO(src, closeio)};
2813 return Surface{SDL_LoadSurface(file)};
2840 return Surface(SDL_LoadBMP_IO(src, closeio));
2898 bool closeio =
false)
2900 CheckError(SDL_SaveBMP_IO(surface, dst, closeio));
2939#if SDL_VERSION_ATLEAST(3, 4, 0)
2967 return Surface(SDL_LoadPNG_IO(src, closeio));
3023 bool closeio =
false)
3025 CheckError(SDL_SavePNG_IO(surface, dst, closeio));
3081 CheckError(SDL_SetSurfaceRLE(surface, enabled));
3105 return SDL_SurfaceHasRLE(surface);
3134 CheckError(SDL_SetSurfaceColorKey(surface, key.has_value(), key.value_or(0)));
3176 return SDL_SurfaceHasColorKey(surface);
3205 if (
Uint32 key; SDL_GetSurfaceColorKey(surface, &key))
return key;
3206 return std::nullopt;
3239 CheckError(SDL_SetSurfaceColorMod(surface, r, g, b));
3269 CheckError(SDL_GetSurfaceColorMod(surface, r, g, b));
3299 CheckError(SDL_SetSurfaceAlphaMod(surface, alpha));
3324 CheckError(SDL_GetSurfaceAlphaMod(surface, &alpha));
3394 CheckError(SDL_SetSurfaceBlendMode(surface, blendMode));
3418 CheckError(SDL_GetSurfaceBlendMode(surface, &blendmode));
3452 return SDL_SetSurfaceClipRect(surface, rect);
3493 CheckError(SDL_GetSurfaceClipRect(surface, &r));
3521#if SDL_VERSION_ATLEAST(3, 4, 0)
3552 return Surface{SDL_RotateSurface(surface, angle)};
3583 return Surface(SDL_DuplicateSurface(surface));
3614 return Surface(SDL_ScaleSurface(surface, size.x, size.y, scaleMode));
3651 return Surface(SDL_ConvertSurface(surface, format));
3693 return Surface{SDL_ConvertSurfaceAndColorspace(
3694 surface, format, palette, colorspace, props)};
3703 m_resource, format, palette, colorspace, props);
3735 size.x, size.y, src_format, src, src_pitch, dst_format, dst, dst_pitch));
3779 CheckError(SDL_ConvertPixelsAndColorspace(size.x,
3852 CheckError(SDL_PremultiplySurfaceAlpha(surface, linear));
3879 CheckError(SDL_ClearSurface(surface, c.r, c.g, c.b, c.a));
3916 CheckError(SDL_FillSurfaceRect(dst, rect, color));
4053 CheckError(SDL_BlitSurface(src, srcrect, dst, dstrect));
4067 Blit(src, srcrect,
Rect{dstpos, {}});
4142 BlitSurface(src, srcrect, dst, SDL_Rect{dstpos.x, dstpos.y});
4171 CheckError(SDL_BlitSurfaceUnchecked(src, &srcrect, dst, &dstrect));
4208 CheckError(SDL_BlitSurfaceScaled(src, srcrect, dst, dstrect, scaleMode));
4248 SDL_BlitSurfaceUncheckedScaled(src, &srcrect, dst, &dstrect, scaleMode));
4259#if SDL_VERSION_ATLEAST(3, 4, 0)
4287 CheckError(SDL_StretchSurface(src, srcrect, dst, dstrect, scaleMode));
4327 CheckError(SDL_BlitSurfaceTiled(src, srcrect, dst, dstrect));
4371 src, srcrect, scale, scaleMode, dst, dstrect));
4381 src, srcrect, scale, scaleMode, m_resource, dstrect);
4498 return SDL_MapSurfaceRGB(surface, r, g, b);
4537 return SDL_MapSurfaceRGBA(surface, c.r, c.g, c.b, c.a);
4578 CheckError(SDL_ReadSurfacePixel(surface, p.x, p.y, r, g, b, a));
4711 CheckError(SDL_ReadSurfacePixelFloat(surface, p.x, p.y, r, g, b, a));
4829 CheckError(SDL_WriteSurfacePixel(surface, p.x, p.y, c.r, c.g, c.b, c.a));
4881 CheckError(SDL_WriteSurfacePixelFloat(surface, p.x, p.y, c.r, c.g, c.b, c.a));
4943 return Point(surface->w, surface->h);
4960 return surface->pitch;
4977 return surface->format;
4994 return surface->pixels;
Colorspace definitions.
Definition: SDL3pp_pixels.h:1657
Optional-like shim for references.
Definition: SDL3pp_optionalRef.h:20
Base class for SDL memory allocated array wrap.
Definition: SDL3pp_ownPtr.h:44
A set of indexed colors representing a palette.
Definition: SDL3pp_pixels.h:2479
static constexpr Palette Borrow(PaletteParam resource)
Safely borrows the from PaletteParam.
Definition: SDL3pp_pixels.h:2543
span-like for empty-derived structs
Definition: SDL3pp_spanRef.h:24
constexpr T * data() const
Retrieves contained data.
Definition: SDL3pp_spanRef.h:75
constexpr size_t size() const
Retrieves contained size.
Definition: SDL3pp_spanRef.h:69
Helpers to use C++ strings parameters.
Definition: SDL3pp_strings.h:43
Set up a surface for directly accessing the pixels.
Definition: SDL3pp_surface.h:2040
constexpr PixelFormat GetFormat() const
Get the pixel format.
Definition: SDL3pp_surface.h:2264
FColor ReadPixelFloat(const PointRaw &p) const
Retrieves a single pixel from a surface.
Definition: SDL3pp_surface.h:2206
~SurfaceLock()
Release a surface after directly accessing the pixels.
Definition: SDL3pp_surface.h:2092
constexpr int GetHeight() const
Get the height in pixels.
Definition: SDL3pp_surface.h:2255
constexpr int GetWidth() const
Get the width in pixels.
Definition: SDL3pp_surface.h:2252
SurfaceRef get()
Get the reference to locked resource.
Definition: SDL3pp_surface.h:2283
constexpr void * GetPixels() const
Get the pixels.
Definition: SDL3pp_surface.h:2267
void release()
Releases the lock without unlocking.
Definition: SDL3pp_surface.h:2286
void ReadPixel(const PointRaw &p, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a) const
Retrieves a single pixel from a surface.
Definition: SDL3pp_surface.h:2131
constexpr SurfaceLock(SurfaceLock &&other) noexcept
Move constructor.
Definition: SDL3pp_surface.h:2075
void WritePixelFloat(const PointRaw &p, const FColorRaw &c)
Writes a single pixel to a surface.
Definition: SDL3pp_surface.h:2246
SurfaceLock & operator=(SurfaceLock &&other) noexcept
Assignment operator.
Definition: SDL3pp_surface.h:2097
void WritePixel(const PointRaw &p, ColorRaw c)
Writes a single pixel to a surface.
Definition: SDL3pp_surface.h:2229
constexpr Point GetSize() const
Get the size in pixels.
Definition: SDL3pp_surface.h:2258
Color ReadPixel(const PointRaw &p) const
Retrieves a single pixel from a surface.
Definition: SDL3pp_surface.h:2158
SurfaceLock(const SurfaceLock &other)=delete
Copy constructor.
void ReadPixelFloat(const PointRaw &p, float *r, float *g, float *b, float *a) const
Retrieves a single pixel from a surface.
Definition: SDL3pp_surface.h:2182
constexpr int GetPitch() const
Get pitch in bytes.
Definition: SDL3pp_surface.h:2261
A collection of pixels used in software blitting.
Definition: SDL3pp_surface.h:227
constexpr const SurfaceRaw operator->() const noexcept
member access to underlying SurfaceRaw.
Definition: SDL3pp_surface.h:514
Surface(const PointRaw &size, PixelFormat format)
Allocate a new surface with a specific pixel format.
Definition: SDL3pp_surface.h:278
constexpr SurfaceRaw release() noexcept
Retrieves underlying SurfaceRaw and clear this.
Definition: SDL3pp_surface.h:536
constexpr Surface & operator=(Surface &&other) noexcept
Assignment operator.
Definition: SDL3pp_surface.h:523
constexpr Surface(const Surface &other)
Copy constructor.
Definition: SDL3pp_surface.h:250
constexpr SurfaceRaw operator->() noexcept
member access to underlying SurfaceRaw.
Definition: SDL3pp_surface.h:517
constexpr Surface(Surface &&other) noexcept
Move constructor.
Definition: SDL3pp_surface.h:257
constexpr Surface(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition: SDL3pp_surface.h:232
constexpr Surface(const SurfaceRaw resource) noexcept
Constructs from SurfaceParam.
Definition: SDL3pp_surface.h:244
~Surface()
Destructor.
Definition: SDL3pp_surface.h:520
constexpr auto operator<=>(const Surface &other) const noexcept=default
Comparison.
constexpr Surface & operator=(const Surface &other) noexcept=default
Assignment operator.
Surface(const PointRaw &size, PixelFormat format, void *pixels, int pitch)
Allocate a new surface with a specific pixel format and existing pixel data.
Definition: SDL3pp_surface.h:309
static constexpr Surface Borrow(SurfaceParam resource)
Safely borrows the from SurfaceParam.
Definition: SDL3pp_surface.h:411
constexpr SurfaceRaw get() const noexcept
Retrieves underlying SurfaceRaw.
Definition: SDL3pp_surface.h:533
constexpr bool MustLock() const
Evaluates to true if the surface needs to be locked before access.
Definition: SDL3pp_surface.h:571
#define SDL_assert_paranoid(condition)
An assertion test that is performed only when built with paranoid settings.
Definition: SDL3pp_assert.h:383
Uint32 BlendMode
A set of blend modes used in drawing operations.
Definition: SDL3pp_blendmode.h:35
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:197
SDL_FColor FColorRaw
Alias to raw representation for FColor.
Definition: SDL3pp_pixels.h:89
SDL_Color ColorRaw
Alias to raw representation for Color.
Definition: SDL3pp_pixels.h:83
SDL_Rect RectRaw
Alias to raw representation for Rect.
Definition: SDL3pp_rect.h:34
SDL_Point PointRaw
Alias to raw representation for Point.
Definition: SDL3pp_rect.h:22
Surface LoadBMP(IOStreamParam src)
Load a BMP image directly.
Definition: SDL3pp_image.h:1349
Surface LoadPNG(IOStreamParam src)
Load a PNG image directly.
Definition: SDL3pp_image.h:1571
Surface LoadSurface(StringParam file)
Load an image from a filesystem path into a software surface.
Definition: SDL3pp_image.h:241
void SavePNG(SurfaceParam surface, StringParam file)
Save an Surface into a PNG image file.
Definition: SDL3pp_image.h:2020
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:341
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition: SDL3pp_stdinc.h:289
SurfaceLock(SurfaceRef resource)
Set up a surface for directly accessing the pixels.
Definition: SDL3pp_surface.h:2733
void ResetSurfaceClipRect(SurfaceParam surface)
Disable the clipping rectangle for a surface.
Definition: SDL3pp_surface.h:3465
constexpr int GetSurfaceHeight(SurfaceConstParam surface)
Get the height in pixels.
Definition: SDL3pp_surface.h:4927
void BlitSurfaceUnchecked(SurfaceParam src, const RectRaw &srcrect, SurfaceParam dst, const RectRaw &dstrect)
Perform low-level surface blitting only.
Definition: SDL3pp_surface.h:4166
Uint32 MapSurfaceRGBA(SurfaceConstParam surface, ColorRaw c)
Map an RGBA quadruple to a pixel value for a surface.
Definition: SDL3pp_surface.h:4535
Rect GetSurfaceClipRect(SurfaceConstParam surface)
Get the clipping rectangle for a surface.
Definition: SDL3pp_surface.h:3490
Surface ScaleSurface(SurfaceConstParam surface, const PointRaw &size, ScaleMode scaleMode)
Creates a new surface identical to the existing surface, scaled to the desired size.
Definition: SDL3pp_surface.h:3610
Rect GetClipRect() const
Get the clipping rectangle for a surface.
Definition: SDL3pp_surface.h:3497
void ClearSurface(SurfaceParam surface, const FColorRaw &c)
Clear a surface with a specific color, with floating point precision.
Definition: SDL3pp_surface.h:3877
Uint8 GetSurfaceAlphaMod(SurfaceConstParam surface)
Get the additional alpha value used in blit operations.
Definition: SDL3pp_surface.h:3321
Palette CreateSurfacePalette(SurfaceParam surface)
Create a palette and associate it with a surface.
Definition: SDL3pp_surface.h:2517
Palette GetPalette() const
Get the palette used by a surface.
Definition: SDL3pp_surface.h:2575
std::optional< Uint32 > GetColorKey() const
Get the color key (transparent pixel) for a surface.
Definition: SDL3pp_surface.h:3209
void SetSurfaceMod(SurfaceParam surface, Color color)
Set an additional color and alpha value multiplied into blit operations.
Definition: SDL3pp_surface.h:3348
constexpr FlipMode FLIP_VERTICAL
flip vertically
Definition: SDL3pp_surface.h:188
bool SetSurfaceClipRect(SurfaceParam surface, OptionalRef< const RectRaw > rect)
Set the clipping rectangle for a surface.
Definition: SDL3pp_surface.h:3449
constexpr PixelFormat GetFormat() const
Get the pixel format.
Definition: SDL3pp_surface.h:4986
void Destroy()
Free a surface.
Definition: SDL3pp_surface.h:2361
void BlitSurfaceScaled(SurfaceParam src, OptionalRef< const RectRaw > srcrect, SurfaceParam dst, OptionalRef< const RectRaw > dstrect, ScaleMode scaleMode)
Perform a scaled blit to a destination surface, which may be of a different format.
Definition: SDL3pp_surface.h:4202
void SavePNG(IOStreamParam dst, bool closeio=false) const
Save a surface to a seekable SDL data stream in PNG format.
Definition: SDL3pp_surface.h:3048
bool SurfaceHasAlternateImages(SurfaceConstParam surface)
Return whether a surface has alternate versions available.
Definition: SDL3pp_surface.h:2629
void FillSurfaceRects(SurfaceParam dst, SpanRef< const RectRaw > rects, Uint32 color)
Perform a fast fill of a set of rectangles with a specific color.
Definition: SDL3pp_surface.h:3966
constexpr SurfaceFlags SURFACE_SIMD_ALIGNED
Surface uses pixel memory allocated with aligned_alloc()
Definition: SDL3pp_surface.h:139
BlendMode GetBlendMode() const
Get the blend mode used for blit operations.
Definition: SDL3pp_surface.h:3422
constexpr SurfaceFlags SURFACE_LOCK_NEEDED
Surface needs to be locked to access pixels.
Definition: SDL3pp_surface.h:132
constexpr void * GetSurfacePixels(SurfaceConstParam surface)
Get the pixels.
Definition: SDL3pp_surface.h:4992
void SetSurfacePalette(SurfaceParam surface, PaletteParam palette)
Set the palette used by a surface.
Definition: SDL3pp_surface.h:2547
bool SurfaceHasRLE(SurfaceConstParam surface)
Returns whether the surface is RLE enabled.
Definition: SDL3pp_surface.h:3103
void DestroySurface(SurfaceRaw surface)
Free a surface.
Definition: SDL3pp_surface.h:2359
void FillRects(SpanRef< const RectRaw > rects, Uint32 color)
Perform a fast fill of a set of rectangles with a specific color.
Definition: SDL3pp_surface.h:3973
Uint32 MapRGB(Uint8 r, Uint8 g, Uint8 b) const
Map an RGB triple to an opaque pixel value for a surface.
Definition: SDL3pp_surface.h:4501
void BlitSurfaceUncheckedScaled(SurfaceParam src, const RectRaw &srcrect, SurfaceParam dst, const RectRaw &dstrect, ScaleMode scaleMode)
Perform low-level surface scaled blitting only.
Definition: SDL3pp_surface.h:4241
bool HasRLE() const
Returns whether the surface is RLE enabled.
Definition: SDL3pp_surface.h:3108
constexpr int GetHeight() const
Get the height in pixels.
Definition: SDL3pp_surface.h:4935
constexpr FlipMode FLIP_NONE
Do not flip.
Definition: SDL3pp_surface.h:184
void WriteSurfacePixel(SurfaceParam surface, const PointRaw &p, ColorRaw c)
Writes a single pixel to a surface.
Definition: SDL3pp_surface.h:4825
bool SurfaceHasColorKey(SurfaceConstParam surface)
Returns whether the surface has a color key.
Definition: SDL3pp_surface.h:3174
BlendMode GetSurfaceBlendMode(SurfaceConstParam surface)
Get the blend mode used for blit operations.
Definition: SDL3pp_surface.h:3415
void Blit9Grid(SurfaceParam src, OptionalRef< const RectRaw > srcrect, int left_width, int right_width, int top_height, int bottom_height, OptionalRef< const RectRaw > dstrect, float scale=1, ScaleMode scaleMode=SCALEMODE_NEAREST)
Perform a scaled blit using the 9-grid algorithm to a destination surface, which may be of a differen...
Definition: SDL3pp_surface.h:4440
void BlitTiledWithScale(SurfaceParam src, OptionalRef< const RectRaw > srcrect, float scale, ScaleMode scaleMode, OptionalRef< const RectRaw > dstrect)
Perform a scaled and tiled blit to a destination surface, which may be of a different format.
Definition: SDL3pp_surface.h:4374
constexpr SurfaceFlags SURFACE_PREALLOCATED
Surface uses preallocated pixel memory.
Definition: SDL3pp_surface.h:129
void BlitSurfaceAt(SurfaceParam src, OptionalRef< const RectRaw > srcrect, SurfaceParam dst, const PointRaw &dstpos)
Performs a fast blit from the source surface to the destination surface with clipping.
Definition: SDL3pp_surface.h:4137
constexpr PixelFormat GetSurfaceFormat(SurfaceConstParam surface)
Get the pixel format.
Definition: SDL3pp_surface.h:4975
bool HasColorKey() const
Returns whether the surface has a color key.
Definition: SDL3pp_surface.h:3179
void BlitUncheckedScaled(SurfaceParam src, const RectRaw &srcrect, const RectRaw &dstrect, ScaleMode scaleMode)
Perform low-level surface scaled blitting only.
Definition: SDL3pp_surface.h:4251
constexpr ScaleMode SCALEMODE_LINEAR
linear filtering
Definition: SDL3pp_surface.h:164
void SetColorKey(std::optional< Uint32 > key)
Set the color key (transparent pixel) in a surface.
Definition: SDL3pp_surface.h:3137
void PremultiplyAlpha(bool linear)
Premultiply the alpha in a surface.
Definition: SDL3pp_surface.h:3855
void SaveBMP(IOStreamParam dst, bool closeio=false) const
Save a surface to a seekable SDL data stream in BMP format.
Definition: SDL3pp_surface.h:2929
Colorspace GetSurfaceColorspace(SurfaceConstParam surface)
Get the colorspace used by a surface.
Definition: SDL3pp_surface.h:2480
Surface DuplicateSurface(SurfaceConstParam surface)
Creates a new surface identical to the existing surface.
Definition: SDL3pp_surface.h:3581
std::optional< Uint32 > GetSurfaceColorKey(SurfaceConstParam surface)
Get the color key (transparent pixel) for a surface.
Definition: SDL3pp_surface.h:3203
Palette CreatePalette()
Create a palette and associate it with a surface.
Definition: SDL3pp_surface.h:2522
void reset()
Release a surface after directly accessing the pixels.
Definition: SDL3pp_surface.h:2760
void Blit(SurfaceParam src, OptionalRef< const RectRaw > srcrect, OptionalRef< const RectRaw > dstrect)
Performs a fast blit from the source surface to the destination surface with clipping.
Definition: SDL3pp_surface.h:4056
void SetSurfaceColorspace(SurfaceParam surface, Colorspace colorspace)
Set the colorspace used by a surface.
Definition: SDL3pp_surface.h:2452
Colorspace GetColorspace() const
Get the colorspace used by a surface.
Definition: SDL3pp_surface.h:2485
void ReadSurfacePixel(SurfaceConstParam surface, const PointRaw &p, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
Retrieves a single pixel from a surface.
Definition: SDL3pp_surface.h:4571
constexpr ScaleMode SCALEMODE_NEAREST
nearest pixel sampling
Definition: SDL3pp_surface.h:161
void Flip(FlipMode flip)
Flip a surface vertically or horizontally.
Definition: SDL3pp_surface.h:3519
Surface CreateSurfaceFrom(const PointRaw &size, PixelFormat format, void *pixels, int pitch)
Allocate a new surface with a specific pixel format and existing pixel data.
Definition: SDL3pp_surface.h:2337
void FlipSurface(SurfaceParam surface, FlipMode flip)
Flip a surface vertically or horizontally.
Definition: SDL3pp_surface.h:3514
void ResetClipRect()
Disable the clipping rectangle for a surface.
Definition: SDL3pp_surface.h:3470
PropertiesRef GetProperties() const
Get the properties associated with a surface.
Definition: SDL3pp_surface.h:2405
constexpr ScaleMode SCALEMODE_PIXELART
nearest pixel sampling with improved scaling for pixel art, available since SDL 3....
Definition: SDL3pp_surface.h:173
constexpr SurfaceFlags SURFACE_LOCKED
Surface is currently locked.
Definition: SDL3pp_surface.h:135
Surface ConvertSurface(SurfaceConstParam surface, PixelFormat format)
Copy an existing surface to a new surface of the specified format.
Definition: SDL3pp_surface.h:3649
constexpr Point GetSurfaceSize(SurfaceConstParam surface)
Get the size in pixels.
Definition: SDL3pp_surface.h:4941
constexpr int GetSurfaceWidth(SurfaceConstParam surface)
Get the width in pixels.
Definition: SDL3pp_surface.h:4913
bool HasAlternateImages() const
Return whether a surface has alternate versions available.
Definition: SDL3pp_surface.h:2634
void FillSurface(SurfaceParam dst, Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition: SDL3pp_surface.h:3935
SDL_Surface * SurfaceRaw
Alias to raw representation for Surface.
Definition: SDL3pp_surface.h:46
constexpr int GetPitch() const
Get pitch in bytes.
Definition: SDL3pp_surface.h:4969
void SetSurfaceColorMod(SurfaceParam surface, Uint8 r, Uint8 g, Uint8 b)
Set an additional color value multiplied into blit operations.
Definition: SDL3pp_surface.h:3237
Surface ConvertSurfaceAndColorspace(SurfaceConstParam surface, PixelFormat format, PaletteParam palette, Colorspace colorspace, PropertiesParam props)
Copy an existing surface to a new surface of the specified format and colorspace.
Definition: SDL3pp_surface.h:3687
void BlitSurface9Grid(SurfaceParam src, OptionalRef< const RectRaw > srcrect, int left_width, int right_width, int top_height, int bottom_height, SurfaceParam dst, OptionalRef< const RectRaw > dstrect, float scale=1, ScaleMode scaleMode=SCALEMODE_NEAREST)
Perform a scaled blit using the 9-grid algorithm to a destination surface, which may be of a differen...
Definition: SDL3pp_surface.h:4417
void RemoveAlternateImages()
Remove all alternate versions of a surface.
Definition: SDL3pp_surface.h:2696
Surface Convert(PixelFormat format) const
Copy an existing surface to a new surface of the specified format.
Definition: SDL3pp_surface.h:3654
void Stretch(SurfaceParam src, OptionalRef< RectRaw > srcrect, OptionalRef< RectRaw > dstrect, ScaleMode scaleMode)
Perform a stretched pixel copy from one surface to another.
Definition: SDL3pp_surface.h:4290
constexpr Point GetSize() const
Get the size in pixels.
Definition: SDL3pp_surface.h:4952
void SetSurfaceAlphaMod(SurfaceParam surface, Uint8 alpha)
Set an additional alpha value used in blit operations.
Definition: SDL3pp_surface.h:3297
Uint8 GetAlphaMod() const
Get the additional alpha value used in blit operations.
Definition: SDL3pp_surface.h:3328
constexpr bool MustLock(SurfaceConstParam S)
Evaluates to true if the surface needs to be locked before access.
Definition: SDL3pp_surface.h:146
Surface Duplicate() const
Creates a new surface identical to the existing surface.
Definition: SDL3pp_surface.h:3586
static Surface LoadBMP(IOStreamParam src, bool closeio=false)
Load a BMP image from a seekable SDL data stream.
Definition: SDL3pp_surface.h:2863
void Clear(const FColorRaw &c)
Clear a surface with a specific color, with floating point precision.
Definition: SDL3pp_surface.h:3882
Surface RotateSurface(SurfaceParam surface, float angle)
Return a copy of a surface rotated clockwise a number of degrees.
Definition: SDL3pp_surface.h:3550
void BlitSurfaceTiled(SurfaceParam src, OptionalRef< const RectRaw > srcrect, SurfaceParam dst, OptionalRef< const RectRaw > dstrect)
Perform a tiled blit to a destination surface, which may be of a different format.
Definition: SDL3pp_surface.h:4322
void SetSurfaceColorKey(SurfaceParam surface, std::optional< Uint32 > key)
Set the color key (transparent pixel) in a surface.
Definition: SDL3pp_surface.h:3132
static Surface LoadPNG(IOStreamParam src, bool closeio=false)
Load a PNG image from a seekable SDL data stream.
Definition: SDL3pp_surface.h:2994
void SetSurfaceRLE(SurfaceParam surface, bool enabled)
Set the RLE acceleration hint for a surface.
Definition: SDL3pp_surface.h:3079
void SetMod(Color color)
Set an additional color and alpha value multiplied into blit operations.
Definition: SDL3pp_surface.h:3354
SDL_FlipMode FlipMode
The flip mode.
Definition: SDL3pp_surface.h:182
Uint32 MapSurfaceRGB(SurfaceConstParam surface, Uint8 r, Uint8 g, Uint8 b)
Map an RGB triple to an opaque pixel value for a surface.
Definition: SDL3pp_surface.h:4493
void GetColorMod(Uint8 *r, Uint8 *g, Uint8 *b) const
Get the additional color value multiplied into blit operations.
Definition: SDL3pp_surface.h:3272
SurfaceLock Lock()
Set up a surface for directly accessing the pixels.
Definition: SDL3pp_surface.h:2731
constexpr ScaleMode SCALEMODE_INVALID
INVALID.
Definition: SDL3pp_surface.h:157
constexpr int GetWidth() const
Get the width in pixels.
Definition: SDL3pp_surface.h:4921
void UnlockSurface(SurfaceParam surface)
Release a surface after directly accessing the pixels.
Definition: SDL3pp_surface.h:2752
void PremultiplySurfaceAlpha(SurfaceParam surface, bool linear)
Premultiply the alpha in a surface.
Definition: SDL3pp_surface.h:3850
void SetColorMod(Uint8 r, Uint8 g, Uint8 b)
Set an additional color value multiplied into blit operations.
Definition: SDL3pp_surface.h:3242
void PremultiplyAlpha(const PointRaw &size, PixelFormat src_format, const void *src, int src_pitch, PixelFormat dst_format, void *dst, int dst_pitch, bool linear)
Premultiply the alpha on a block of pixels.
Definition: SDL3pp_surface.h:3815
void BlitAt(SurfaceParam src, OptionalRef< const RectRaw > srcrect, const PointRaw &dstpos)
Performs a fast blit from the source surface to the destination surface with clipping.
Definition: SDL3pp_surface.h:4063
void BlitSurfaceTiledWithScale(SurfaceParam src, OptionalRef< const RectRaw > srcrect, float scale, ScaleMode scaleMode, SurfaceParam dst, OptionalRef< const RectRaw > dstrect)
Perform a scaled and tiled blit to a destination surface, which may be of a different format.
Definition: SDL3pp_surface.h:4363
void SetBlendMode(BlendMode blendMode)
Set the blend mode used for blit operations.
Definition: SDL3pp_surface.h:3397
OwnArray< SurfaceRaw > GetImages() const
Get an array including all versions of a surface.
Definition: SDL3pp_surface.h:2669
Surface Rotate(float angle)
Return a copy of a surface rotated clockwise a number of degrees.
Definition: SDL3pp_surface.h:3555
Surface CreateSurface(const PointRaw &size, PixelFormat format)
Allocate a new surface with a specific pixel format.
Definition: SDL3pp_surface.h:2306
OwnArray< SurfaceRaw > GetSurfaceImages(SurfaceConstParam surface)
Get an array including all versions of a surface.
Definition: SDL3pp_surface.h:2662
constexpr int GetSurfacePitch(SurfaceConstParam surface)
Get pitch in bytes.
Definition: SDL3pp_surface.h:4958
constexpr FlipMode FLIP_HORIZONTAL
flip horizontally
Definition: SDL3pp_surface.h:186
void BlitScaled(SurfaceParam src, OptionalRef< const RectRaw > srcrect, OptionalRef< const RectRaw > dstrect, ScaleMode scaleMode)
Perform a scaled blit to a destination surface, which may be of a different format.
Definition: SDL3pp_surface.h:4211
void ReadPixel(const PointRaw &p, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a) const
Retrieves a single pixel from a surface.
Definition: SDL3pp_surface.h:4667
void ReadSurfacePixelFloat(SurfaceConstParam surface, const PointRaw &p, float *r, float *g, float *b, float *a)
Retrieves a single pixel from a surface.
Definition: SDL3pp_surface.h:4704
Palette GetSurfacePalette(SurfaceConstParam surface)
Get the palette used by a surface.
Definition: SDL3pp_surface.h:2570
void StretchSurface(SurfaceParam src, OptionalRef< RectRaw > srcrect, SurfaceParam dst, OptionalRef< RectRaw > dstrect, ScaleMode scaleMode)
Perform a stretched pixel copy from one surface to another.
Definition: SDL3pp_surface.h:4281
void FillSurfaceRect(SurfaceParam dst, OptionalRef< const RectRaw > rect, Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition: SDL3pp_surface.h:3912
Color GetSurfaceMod(SurfaceConstParam surface)
Get the additional color and alpha value multiplied into blit operations.
Definition: SDL3pp_surface.h:3364
void Fill(Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition: SDL3pp_surface.h:3940
Uint32 MapRGBA(ColorRaw c) const
Map an RGBA quadruple to a pixel value for a surface.
Definition: SDL3pp_surface.h:4540
Surface Scale(const PointRaw &size, ScaleMode scaleMode) const
Creates a new surface identical to the existing surface, scaled to the desired size.
Definition: SDL3pp_surface.h:3617
void ConvertPixelsAndColorspace(const PointRaw &size, PixelFormat src_format, Colorspace src_colorspace, PropertiesParam src_properties, const void *src, int src_pitch, PixelFormat dst_format, Colorspace dst_colorspace, PropertiesParam dst_properties, void *dst, int dst_pitch)
Copy a block of pixels of one format and colorspace to another format and colorspace.
Definition: SDL3pp_surface.h:3767
void SetColorspace(Colorspace colorspace)
Set the colorspace used by a surface.
Definition: SDL3pp_surface.h:2457
void BlitTiled(SurfaceParam src, OptionalRef< const RectRaw > srcrect, OptionalRef< const RectRaw > dstrect)
Perform a tiled blit to a destination surface, which may be of a different format.
Definition: SDL3pp_surface.h:4330
void SaveBMP(SurfaceConstParam surface, IOStreamParam dst, bool closeio=false)
Save a surface to a seekable SDL data stream in BMP format.
Definition: SDL3pp_surface.h:2896
void ClearColorKey()
Unset the color key (transparent pixel) in a surface.
Definition: SDL3pp_surface.h:3157
void AddSurfaceAlternateImage(SurfaceParam surface, SurfaceParam image)
Add an alternate version of a surface.
Definition: SDL3pp_surface.h:2605
Uint32 SurfaceFlags
The flags on an Surface.
Definition: SDL3pp_surface.h:127
void WritePixel(const PointRaw &p, ColorRaw c)
Writes a single pixel to a surface.
Definition: SDL3pp_surface.h:4856
PropertiesRef GetSurfaceProperties(SurfaceConstParam surface)
Get the properties associated with a surface.
Definition: SDL3pp_surface.h:2400
void BlitSurface(SurfaceParam src, OptionalRef< const RectRaw > srcrect, SurfaceParam dst, OptionalRef< const RectRaw > dstrect)
Performs a fast blit from the source surface to the destination surface with clipping.
Definition: SDL3pp_surface.h:4048
void FillRect(OptionalRef< const RectRaw > rect, Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition: SDL3pp_surface.h:3919
void Unlock(SurfaceLock &&lock)
Release a surface after directly accessing the pixels.
Definition: SDL3pp_surface.h:2754
void ReadPixelFloat(const PointRaw &p, float *r, float *g, float *b, float *a) const
Retrieves a single pixel from a surface.
Definition: SDL3pp_surface.h:4792
void GetSurfaceColorMod(SurfaceConstParam surface, Uint8 *r, Uint8 *g, Uint8 *b)
Get the additional color value multiplied into blit operations.
Definition: SDL3pp_surface.h:3264
void SetAlphaMod(Uint8 alpha)
Set an additional alpha value used in blit operations.
Definition: SDL3pp_surface.h:3302
constexpr void * GetPixels() const
Get the pixels.
Definition: SDL3pp_surface.h:5003
SDL_ScaleMode ScaleMode
The scaling mode.
Definition: SDL3pp_surface.h:153
void SetRLE(bool enabled)
Set the RLE acceleration hint for a surface.
Definition: SDL3pp_surface.h:3084
void BlitUnchecked(SurfaceParam src, const RectRaw &srcrect, const RectRaw &dstrect)
Perform low-level surface blitting only.
Definition: SDL3pp_surface.h:4174
void ConvertPixels(const PointRaw &size, PixelFormat src_format, const void *src, int src_pitch, PixelFormat dst_format, void *dst, int dst_pitch)
Copy a block of pixels of one format to another format.
Definition: SDL3pp_surface.h:3726
void ClearSurfaceColorKey(SurfaceParam surface)
Unset the color key (transparent pixel) in a surface.
Definition: SDL3pp_surface.h:3152
void WriteSurfacePixelFloat(SurfaceParam surface, const PointRaw &p, const FColorRaw &c)
Writes a single pixel to a surface.
Definition: SDL3pp_surface.h:4877
void SetPalette(PaletteParam palette)
Set the palette used by a surface.
Definition: SDL3pp_surface.h:2552
Color GetMod() const
Get the additional color and alpha value multiplied into blit operations.
Definition: SDL3pp_surface.h:3372
void LockSurface(SurfaceParam surface)
Set up a surface for directly accessing the pixels.
Definition: SDL3pp_surface.h:2726
constexpr FlipMode FLIP_HORIZONTAL_AND_VERTICAL
flip horizontally and vertically (not a diagonal flip)
Definition: SDL3pp_surface.h:193
void SetSurfaceBlendMode(SurfaceParam surface, BlendMode blendMode)
Set the blend mode used for blit operations.
Definition: SDL3pp_surface.h:3392
bool SetClipRect(OptionalRef< const RectRaw > rect)
Set the clipping rectangle for a surface.
Definition: SDL3pp_surface.h:3455
void AddAlternateImage(SurfaceParam image)
Add an alternate version of a surface.
Definition: SDL3pp_surface.h:2610
void WritePixelFloat(const PointRaw &p, const FColorRaw &c)
Writes a single pixel to a surface.
Definition: SDL3pp_surface.h:4907
void RemoveSurfaceAlternateImages(SurfaceParam surface)
Remove all alternate versions of a surface.
Definition: SDL3pp_surface.h:2691
Main include header for the SDL3pp library.
A structure that represents a color as RGBA components.
Definition: SDL3pp_pixels.h:2192
The bits of this structure can be directly reinterpreted as a float-packed color which uses the PIXEL...
Definition: SDL3pp_pixels.h:2365
Safely wrap IOStream for non owning parameters.
Definition: SDL3pp_iostream.h:34
Safely wrap Palette for non owning parameters.
Definition: SDL3pp_pixels.h:105
The structure that defines a point (using integers).
Definition: SDL3pp_rect.h:83
Safely wrap Properties for non owning parameters.
Definition: SDL3pp_properties.h:53
Semi-safe reference for Properties.
Definition: SDL3pp_properties.h:716
A rectangle, with the origin at the upper left (using integers).
Definition: SDL3pp_rect.h:845
Safely wrap Surface for non owning const parameters.
Definition: SDL3pp_surface.h:83
constexpr SurfaceConstParam(const SurfaceRaw value)
Constructs from SurfaceRaw.
Definition: SDL3pp_surface.h:87
constexpr SurfaceConstParam(std::nullptr_t=nullptr)
Constructs null/invalid.
Definition: SDL3pp_surface.h:99
constexpr SurfaceConstParam(SurfaceParam value)
Constructs from SurfaceParam.
Definition: SDL3pp_surface.h:93
const SurfaceRaw value
parameter's const SurfaceRaw
Definition: SDL3pp_surface.h:84
constexpr auto operator<=>(const SurfaceConstParam &other) const =default
Comparison.
constexpr auto operator->()
member access to underlying SurfaceRaw.
Definition: SDL3pp_surface.h:114
Safely wrap Surface for non owning parameters.
Definition: SDL3pp_surface.h:53
SurfaceRaw value
parameter's SurfaceRaw
Definition: SDL3pp_surface.h:54
constexpr auto operator->()
member access to underlying SurfaceRaw.
Definition: SDL3pp_surface.h:78
constexpr SurfaceParam(SurfaceRaw value)
Constructs from SurfaceRaw.
Definition: SDL3pp_surface.h:57
constexpr SurfaceParam(std::nullptr_t=nullptr)
Constructs null/invalid.
Definition: SDL3pp_surface.h:63
constexpr auto operator<=>(const SurfaceParam &other) const =default
Comparison.
Safe reference for Surface.
Definition: SDL3pp_surface.h:2000
SurfaceRef(Surface resource) noexcept
Constructs from Surface.
Definition: SDL3pp_surface.h:2016
SurfaceRef(SurfaceRaw resource) noexcept
Constructs from SurfaceRaw.
Definition: SDL3pp_surface.h:2010