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; }
94 SDL_SURFACE_PREALLOCATED;
97 SDL_SURFACE_LOCK_NEEDED;
119#if SDL_VERSION_ATLEAST(3, 2, 10)
126 SDL_SCALEMODE_NEAREST;
129 SDL_SCALEMODE_LINEAR;
131#if SDL_VERSION_ATLEAST(3, 4, 0)
154#if SDL_VERSION_ATLEAST(3, 4, 0)
158 SDL_FLIP_HORIZONTAL_AND_VERTICAL;
196 constexpr Surface(std::nullptr_t =
nullptr) noexcept
209 : m_resource(resource)
215 : m_resource(other.m_resource)
217 if (m_resource) ++m_resource->refcount;
373 ++resource->refcount;
421#if SDL_VERSION_ATLEAST(3, 4, 0)
487 std::swap(m_resource, other.m_resource);
501 m_resource =
nullptr;
509 constexpr explicit operator bool() const noexcept {
return !!m_resource; }
834#if SDL_VERSION_ATLEAST(3, 4, 0)
890 void SetRLE(
bool enabled);
1173#if SDL_VERSION_ATLEAST(3, 4, 0)
1620#if SDL_VERSION_ATLEAST(3, 4, 0)
2008 std::swap(*
this, other);
2070 : m_lock(other.m_lock)
2093 std::swap(m_lock, other.m_lock);
2098 constexpr operator bool()
const {
return bool(m_lock); }
2306 : m_resource(
CheckError(SDL_CreateSurface(size.x, size.y, format)))
2315 CheckError(SDL_CreateSurfaceFrom(size.x, size.y, format, pixels, pitch)))
2350 return Surface(size, format, pixels, pitch);
2410 return {
CheckError(SDL_GetSurfaceProperties(surface))};
2418namespace prop::Surface {
2420constexpr auto SDR_WHITE_POINT_FLOAT = SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT;
2422constexpr auto HDR_HEADROOM_FLOAT = SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT;
2424constexpr auto TONEMAP_OPERATOR_STRING =
2425 SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING;
2427#if SDL_VERSION_ATLEAST(3, 2, 6)
2429constexpr auto HOTSPOT_X_NUMBER = SDL_PROP_SURFACE_HOTSPOT_X_NUMBER;
2431constexpr auto HOTSPOT_Y_NUMBER = SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER;
2435#if SDL_VERSION_ATLEAST(3, 4, 0)
2437constexpr auto ROTATION_FLOAT = SDL_PROP_SURFACE_ROTATION_FLOAT;
2462 CheckError(SDL_SetSurfaceColorspace(surface, colorspace));
2490 return SDL_GetSurfaceColorspace(surface);
2557 CheckError(SDL_SetSurfacePalette(surface, palette));
2615 CheckError(SDL_AddSurfaceAlternateImage(surface, image));
2639 return SDL_SurfaceHasAlternateImages(surface);
2673 auto data = SDL_GetSurfaceImages(surface, &count);
2701 SDL_RemoveSurfaceAlternateImages(surface);
2742 : m_lock(std::move(resource))
2770 if (!m_lock)
return;
2775#ifndef SDL3PP_ENABLE_IMAGE
2776#if SDL_VERSION_ATLEAST(3, 4, 0)
2799 return Surface{SDL_LoadSurface_IO(src, closeio)};
2821 return Surface{SDL_LoadSurface(file)};
2848 return Surface(SDL_LoadBMP_IO(src, closeio));
2906 bool closeio =
false)
2908 CheckError(SDL_SaveBMP_IO(surface, dst, closeio));
2947#if SDL_VERSION_ATLEAST(3, 4, 0)
2975 return Surface(SDL_LoadPNG_IO(src, closeio));
3031 bool closeio =
false)
3033 CheckError(SDL_SavePNG_IO(surface, dst, closeio));
3089 CheckError(SDL_SetSurfaceRLE(surface, enabled));
3113 return SDL_SurfaceHasRLE(surface);
3142 CheckError(SDL_SetSurfaceColorKey(surface, key.has_value(), key.value_or(0)));
3184 return SDL_SurfaceHasColorKey(surface);
3213 if (
Uint32 key; SDL_GetSurfaceColorKey(surface, &key))
return key;
3214 return std::nullopt;
3247 CheckError(SDL_SetSurfaceColorMod(surface, r, g, b));
3277 CheckError(SDL_GetSurfaceColorMod(surface, r, g, b));
3307 CheckError(SDL_SetSurfaceAlphaMod(surface, alpha));
3332 CheckError(SDL_GetSurfaceAlphaMod(surface, &alpha));
3402 CheckError(SDL_SetSurfaceBlendMode(surface, blendMode));
3426 CheckError(SDL_GetSurfaceBlendMode(surface, &blendmode));
3460 return SDL_SetSurfaceClipRect(surface, rect);
3501 CheckError(SDL_GetSurfaceClipRect(surface, &r));
3529#if SDL_VERSION_ATLEAST(3, 4, 0)
3560 return Surface{SDL_RotateSurface(surface, angle)};
3591 return Surface(SDL_DuplicateSurface(surface));
3622 return Surface(SDL_ScaleSurface(surface, size.x, size.y, scaleMode));
3659 return Surface(SDL_ConvertSurface(surface, format));
3701 return Surface{SDL_ConvertSurfaceAndColorspace(
3702 surface, format, palette, colorspace, props)};
3711 m_resource, format, palette, colorspace, props);
3743 size.x, size.y, src_format, src, src_pitch, dst_format, dst, dst_pitch));
3787 CheckError(SDL_ConvertPixelsAndColorspace(size.x,
3860 CheckError(SDL_PremultiplySurfaceAlpha(surface, linear));
3887 CheckError(SDL_ClearSurface(surface, c.r, c.g, c.b, c.a));
3924 CheckError(SDL_FillSurfaceRect(dst, rect, color));
4061 CheckError(SDL_BlitSurface(src, srcrect, dst, dstrect));
4075 Blit(src, srcrect,
Rect{dstpos, {}});
4150 BlitSurface(src, srcrect, dst, SDL_Rect{dstpos.x, dstpos.y});
4179 CheckError(SDL_BlitSurfaceUnchecked(src, &srcrect, dst, &dstrect));
4216 CheckError(SDL_BlitSurfaceScaled(src, srcrect, dst, dstrect, scaleMode));
4256 SDL_BlitSurfaceUncheckedScaled(src, &srcrect, dst, &dstrect, scaleMode));
4267#if SDL_VERSION_ATLEAST(3, 4, 0)
4295 CheckError(SDL_StretchSurface(src, srcrect, dst, dstrect, scaleMode));
4335 CheckError(SDL_BlitSurfaceTiled(src, srcrect, dst, dstrect));
4379 src, srcrect, scale, scaleMode, dst, dstrect));
4389 src, srcrect, scale, scaleMode, m_resource, dstrect);
4503 return SDL_MapSurfaceRGB(surface, r, g, b);
4542 return SDL_MapSurfaceRGBA(surface, c.r, c.g, c.b, c.a);
4583 CheckError(SDL_ReadSurfacePixel(surface, p.x, p.y, r, g, b, a));
4716 CheckError(SDL_ReadSurfacePixelFloat(surface, p.x, p.y, r, g, b, a));
4831 CheckError(SDL_WriteSurfacePixel(surface, p.x, p.y, c.r, c.g, c.b, c.a));
4883 CheckError(SDL_WriteSurfacePixelFloat(surface, p.x, p.y, c.r, c.g, c.b, c.a));
4945 return Point(surface->w, surface->h);
4962 return surface->pitch;
4979 return surface->format;
4996 return surface->pixels;
Colorspace definitions.
Definition: SDL3pp_pixels.h:1628
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:2482
static constexpr Palette Borrow(PaletteRaw resource)
Safely borrows the from PaletteRaw.
Definition: SDL3pp_pixels.h:2547
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:2034
constexpr PixelFormat GetFormat() const
Get the pixel format.
Definition: SDL3pp_surface.h:2258
FColor ReadPixelFloat(const PointRaw &p) const
Retrieves a single pixel from a surface.
Definition: SDL3pp_surface.h:2200
~SurfaceLock()
Release a surface after directly accessing the pixels.
Definition: SDL3pp_surface.h:2086
constexpr int GetHeight() const
Get the height in pixels.
Definition: SDL3pp_surface.h:2249
constexpr int GetWidth() const
Get the width in pixels.
Definition: SDL3pp_surface.h:2246
SurfaceRef get()
Get the reference to locked resource.
Definition: SDL3pp_surface.h:2277
constexpr void * GetPixels() const
Get the pixels.
Definition: SDL3pp_surface.h:2261
void release()
Releases the lock without unlocking.
Definition: SDL3pp_surface.h:2280
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:2125
constexpr SurfaceLock(SurfaceLock &&other) noexcept
Move constructor.
Definition: SDL3pp_surface.h:2069
void WritePixelFloat(const PointRaw &p, const FColorRaw &c)
Writes a single pixel to a surface.
Definition: SDL3pp_surface.h:2240
SurfaceLock & operator=(SurfaceLock &&other) noexcept
Assignment operator.
Definition: SDL3pp_surface.h:2091
void WritePixel(const PointRaw &p, ColorRaw c)
Writes a single pixel to a surface.
Definition: SDL3pp_surface.h:2223
constexpr Point GetSize() const
Get the size in pixels.
Definition: SDL3pp_surface.h:2252
Color ReadPixel(const PointRaw &p) const
Retrieves a single pixel from a surface.
Definition: SDL3pp_surface.h:2152
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:2176
constexpr int GetPitch() const
Get pitch in bytes.
Definition: SDL3pp_surface.h:2255
A collection of pixels used in software blitting.
Definition: SDL3pp_surface.h:191
constexpr const SurfaceRaw operator->() const noexcept
member access to underlying SurfaceRaw.
Definition: SDL3pp_surface.h:473
static constexpr Surface Borrow(SurfaceRaw resource)
Safely borrows the from SurfaceRaw.
Definition: SDL3pp_surface.h:370
constexpr SurfaceRaw release() noexcept
Retrieves underlying SurfaceRaw and clear this.
Definition: SDL3pp_surface.h:498
constexpr Surface & operator=(Surface &&other) noexcept
Assignment operator.
Definition: SDL3pp_surface.h:485
constexpr Surface(const Surface &other)
Copy constructor.
Definition: SDL3pp_surface.h:214
constexpr SurfaceRaw operator->() noexcept
member access to underlying SurfaceRaw.
Definition: SDL3pp_surface.h:476
constexpr Surface(Surface &&other) noexcept
Move constructor.
Definition: SDL3pp_surface.h:221
constexpr Surface(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition: SDL3pp_surface.h:196
constexpr Surface(const SurfaceRaw resource) noexcept
Constructs from SurfaceRef.
Definition: SDL3pp_surface.h:208
~Surface()
Destructor.
Definition: SDL3pp_surface.h:482
constexpr auto operator<=>(const Surface &other) const noexcept=default
Comparison.
constexpr Surface & operator=(const Surface &other) noexcept=default
Assignment operator.
constexpr SurfaceRaw get() const noexcept
Retrieves underlying SurfaceRaw.
Definition: SDL3pp_surface.h:495
constexpr bool MustLock() const
Evaluates to true if the surface needs to be locked before access.
Definition: SDL3pp_surface.h:530
#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:90
SDL_Color ColorRaw
Alias to raw representation for Color.
Definition: SDL3pp_pixels.h:84
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 LoadPNG(IOStreamRef src)
Load a PNG image directly.
Definition: SDL3pp_image.h:1761
void SaveBMP(SurfaceRef surface, StringParam file)
Save an Surface into a BMP image file.
Definition: SDL3pp_image.h:2270
void SavePNG(SurfaceRef surface, StringParam file)
Save an Surface into a PNG image file.
Definition: SDL3pp_image.h:2484
Surface LoadSurface(StringParam file)
Load an image from a filesystem path into a software surface.
Definition: SDL3pp_image.h:167
Surface LoadBMP(IOStreamRef src)
Load a BMP image directly.
Definition: SDL3pp_image.h:1489
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:280
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition: SDL3pp_stdinc.h:228
SurfaceLock(SurfaceRef resource)
Set up a surface for directly accessing the pixels.
Definition: SDL3pp_surface.h:2741
Rect GetClipRect() const
Get the clipping rectangle for a surface.
Definition: SDL3pp_surface.h:3505
Palette GetPalette() const
Get the palette used by a surface.
Definition: SDL3pp_surface.h:2583
std::optional< Uint32 > GetColorKey() const
Get the color key (transparent pixel) for a surface.
Definition: SDL3pp_surface.h:3217
static Surface LoadBMP(IOStreamRef src, bool closeio=false)
Load a BMP image from a seekable SDL data stream.
Definition: SDL3pp_surface.h:2871
void BlitTiled(SurfaceRef 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:4338
Palette CreateSurfacePalette(SurfaceRef surface)
Create a palette and associate it with a surface.
Definition: SDL3pp_surface.h:2525
constexpr FlipMode FLIP_VERTICAL
flip vertically
Definition: SDL3pp_surface.h:152
constexpr PixelFormat GetFormat() const
Get the pixel format.
Definition: SDL3pp_surface.h:4988
void Destroy()
Free a surface.
Definition: SDL3pp_surface.h:2369
void SetSurfaceColorKey(SurfaceRef surface, std::optional< Uint32 > key)
Set the color key (transparent pixel) in a surface.
Definition: SDL3pp_surface.h:3140
void AddAlternateImage(SurfaceRef image)
Add an alternate version of a surface.
Definition: SDL3pp_surface.h:2618
void WriteSurfacePixel(SurfaceRef surface, const PointRaw &p, ColorRaw c)
Writes a single pixel to a surface.
Definition: SDL3pp_surface.h:4829
void BlitSurfaceAt(SurfaceRef src, OptionalRef< const RectRaw > srcrect, SurfaceRef dst, const PointRaw &dstpos)
Performs a fast blit from the source surface to the destination surface with clipping.
Definition: SDL3pp_surface.h:4145
void BlitTiledWithScale(SurfaceRef 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:4382
void AddSurfaceAlternateImage(SurfaceRef surface, SurfaceRef image)
Add an alternate version of a surface.
Definition: SDL3pp_surface.h:2613
void GetSurfaceColorMod(SurfaceConstRef surface, Uint8 *r, Uint8 *g, Uint8 *b)
Get the additional color value multiplied into blit operations.
Definition: SDL3pp_surface.h:3272
void SetSurfaceMod(SurfaceRef surface, Color color)
Set an additional color and alpha value multiplied into blit operations.
Definition: SDL3pp_surface.h:3356
constexpr SurfaceFlags SURFACE_SIMD_ALIGNED
Surface uses pixel memory allocated with aligned_alloc()
Definition: SDL3pp_surface.h:103
BlendMode GetBlendMode() const
Get the blend mode used for blit operations.
Definition: SDL3pp_surface.h:3430
Uint32 MapSurfaceRGB(SurfaceConstRef surface, Uint8 r, Uint8 g, Uint8 b)
Map an RGB triple to an opaque pixel value for a surface.
Definition: SDL3pp_surface.h:4501
constexpr SurfaceFlags SURFACE_LOCK_NEEDED
Surface needs to be locked to access pixels.
Definition: SDL3pp_surface.h:96
void SetSurfaceAlphaMod(SurfaceRef surface, Uint8 alpha)
Set an additional alpha value used in blit operations.
Definition: SDL3pp_surface.h:3305
BlendMode GetSurfaceBlendMode(SurfaceConstRef surface)
Get the blend mode used for blit operations.
Definition: SDL3pp_surface.h:3423
void RemoveSurfaceAlternateImages(SurfaceRef surface)
Remove all alternate versions of a surface.
Definition: SDL3pp_surface.h:2699
void DestroySurface(SurfaceRaw surface)
Free a surface.
Definition: SDL3pp_surface.h:2367
void ClearSurface(SurfaceRef surface, const FColorRaw &c)
Clear a surface with a specific color, with floating point precision.
Definition: SDL3pp_surface.h:3885
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:3981
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:4506
bool HasRLE() const
Returns whether the surface is RLE enabled.
Definition: SDL3pp_surface.h:3116
void LockSurface(SurfaceRef surface)
Set up a surface for directly accessing the pixels.
Definition: SDL3pp_surface.h:2734
constexpr int GetHeight() const
Get the height in pixels.
Definition: SDL3pp_surface.h:4937
constexpr FlipMode FLIP_NONE
Do not flip.
Definition: SDL3pp_surface.h:148
void BlitSurface(SurfaceRef src, OptionalRef< const RectRaw > srcrect, SurfaceRef dst, OptionalRef< const RectRaw > dstrect)
Performs a fast blit from the source surface to the destination surface with clipping.
Definition: SDL3pp_surface.h:4056
void BlitSurface9Grid(SurfaceRef src, OptionalRef< const RectRaw > srcrect, int left_width, int right_width, int top_height, int bottom_height, SurfaceRef 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:4425
OwnArray< SurfaceRaw > GetSurfaceImages(SurfaceConstRef surface)
Get an array including all versions of a surface.
Definition: SDL3pp_surface.h:2670
constexpr bool MustLock(SurfaceConstRef S)
Evaluates to true if the surface needs to be locked before access.
Definition: SDL3pp_surface.h:110
constexpr int GetSurfaceWidth(SurfaceConstRef surface)
Get the width in pixels.
Definition: SDL3pp_surface.h:4915
Surface RotateSurface(SurfaceRef surface, float angle)
Return a copy of a surface rotated clockwise a number of degrees.
Definition: SDL3pp_surface.h:3558
void FillSurfaceRect(SurfaceRef dst, OptionalRef< const RectRaw > rect, Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition: SDL3pp_surface.h:3920
void PremultiplySurfaceAlpha(SurfaceRef surface, bool linear)
Premultiply the alpha in a surface.
Definition: SDL3pp_surface.h:3858
constexpr SurfaceFlags SURFACE_PREALLOCATED
Surface uses preallocated pixel memory.
Definition: SDL3pp_surface.h:93
bool HasColorKey() const
Returns whether the surface has a color key.
Definition: SDL3pp_surface.h:3187
constexpr ScaleMode SCALEMODE_LINEAR
linear filtering
Definition: SDL3pp_surface.h:128
void SetColorKey(std::optional< Uint32 > key)
Set the color key (transparent pixel) in a surface.
Definition: SDL3pp_surface.h:3145
void PremultiplyAlpha(bool linear)
Premultiply the alpha in a surface.
Definition: SDL3pp_surface.h:3863
void BlitSurfaceUnchecked(SurfaceRef src, const RectRaw &srcrect, SurfaceRef dst, const RectRaw &dstrect)
Perform low-level surface blitting only.
Definition: SDL3pp_surface.h:4174
Palette CreatePalette()
Create a palette and associate it with a surface.
Definition: SDL3pp_surface.h:2530
void reset()
Release a surface after directly accessing the pixels.
Definition: SDL3pp_surface.h:2768
void WriteSurfacePixelFloat(SurfaceRef surface, const PointRaw &p, const FColorRaw &c)
Writes a single pixel to a surface.
Definition: SDL3pp_surface.h:4879
bool SetSurfaceClipRect(SurfaceRef surface, OptionalRef< const RectRaw > rect)
Set the clipping rectangle for a surface.
Definition: SDL3pp_surface.h:3457
Colorspace GetColorspace() const
Get the colorspace used by a surface.
Definition: SDL3pp_surface.h:2493
constexpr PixelFormat GetSurfaceFormat(SurfaceConstRef surface)
Get the pixel format.
Definition: SDL3pp_surface.h:4977
void SetSurfacePalette(SurfaceRef surface, PaletteRef palette)
Set the palette used by a surface.
Definition: SDL3pp_surface.h:2555
constexpr ScaleMode SCALEMODE_NEAREST
nearest pixel sampling
Definition: SDL3pp_surface.h:125
void Flip(FlipMode flip)
Flip a surface vertically or horizontally.
Definition: SDL3pp_surface.h:3527
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:2345
void Blit(SurfaceRef 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:4064
PropertiesRef GetSurfaceProperties(SurfaceConstRef surface)
Get the properties associated with a surface.
Definition: SDL3pp_surface.h:2408
void BlitSurfaceTiledWithScale(SurfaceRef src, OptionalRef< const RectRaw > srcrect, float scale, ScaleMode scaleMode, SurfaceRef 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:4371
void ConvertPixelsAndColorspace(const PointRaw &size, PixelFormat src_format, Colorspace src_colorspace, PropertiesRef src_properties, const void *src, int src_pitch, PixelFormat dst_format, Colorspace dst_colorspace, PropertiesRef 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:3775
Colorspace GetSurfaceColorspace(SurfaceConstRef surface)
Get the colorspace used by a surface.
Definition: SDL3pp_surface.h:2488
void BlitSurfaceScaled(SurfaceRef src, OptionalRef< const RectRaw > srcrect, SurfaceRef 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:4210
void ResetClipRect()
Disable the clipping rectangle for a surface.
Definition: SDL3pp_surface.h:3478
void BlitSurfaceTiled(SurfaceRef src, OptionalRef< const RectRaw > srcrect, SurfaceRef dst, OptionalRef< const RectRaw > dstrect)
Perform a tiled blit to a destination surface, which may be of a different format.
Definition: SDL3pp_surface.h:4330
Surface ConvertSurface(SurfaceConstRef surface, PixelFormat format)
Copy an existing surface to a new surface of the specified format.
Definition: SDL3pp_surface.h:3657
PropertiesRef GetProperties() const
Get the properties associated with a surface.
Definition: SDL3pp_surface.h:2413
Surface DuplicateSurface(SurfaceConstRef surface)
Creates a new surface identical to the existing surface.
Definition: SDL3pp_surface.h:3589
constexpr ScaleMode SCALEMODE_PIXELART
nearest pixel sampling with improved scaling for pixel art, available since SDL 3....
Definition: SDL3pp_surface.h:137
Palette GetSurfacePalette(SurfaceConstRef surface)
Get the palette used by a surface.
Definition: SDL3pp_surface.h:2578
Surface ScaleSurface(SurfaceConstRef surface, const PointRaw &size, ScaleMode scaleMode)
Creates a new surface identical to the existing surface, scaled to the desired size.
Definition: SDL3pp_surface.h:3618
constexpr SurfaceFlags SURFACE_LOCKED
Surface is currently locked.
Definition: SDL3pp_surface.h:99
bool HasAlternateImages() const
Return whether a surface has alternate versions available.
Definition: SDL3pp_surface.h:2642
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:4971
void BlitUncheckedScaled(SurfaceRef src, const RectRaw &srcrect, const RectRaw &dstrect, ScaleMode scaleMode)
Perform low-level surface scaled blitting only.
Definition: SDL3pp_surface.h:4259
Uint8 GetSurfaceAlphaMod(SurfaceConstRef surface)
Get the additional alpha value used in blit operations.
Definition: SDL3pp_surface.h:3329
bool SurfaceHasColorKey(SurfaceConstRef surface)
Returns whether the surface has a color key.
Definition: SDL3pp_surface.h:3182
void Stretch(SurfaceRef src, OptionalRef< RectRaw > srcrect, OptionalRef< RectRaw > dstrect, ScaleMode scaleMode)
Perform a stretched pixel copy from one surface to another.
Definition: SDL3pp_surface.h:4298
void RemoveAlternateImages()
Remove all alternate versions of a surface.
Definition: SDL3pp_surface.h:2704
Surface Convert(PixelFormat format) const
Copy an existing surface to a new surface of the specified format.
Definition: SDL3pp_surface.h:3662
constexpr Point GetSize() const
Get the size in pixels.
Definition: SDL3pp_surface.h:4954
void SavePNG(IOStreamRef dst, bool closeio=false) const
Save a surface to a seekable SDL data stream in PNG format.
Definition: SDL3pp_surface.h:3056
void SetSurfaceBlendMode(SurfaceRef surface, BlendMode blendMode)
Set the blend mode used for blit operations.
Definition: SDL3pp_surface.h:3400
void SaveBMP(IOStreamRef dst, bool closeio=false) const
Save a surface to a seekable SDL data stream in BMP format.
Definition: SDL3pp_surface.h:2937
Uint8 GetAlphaMod() const
Get the additional alpha value used in blit operations.
Definition: SDL3pp_surface.h:3336
Surface Duplicate() const
Creates a new surface identical to the existing surface.
Definition: SDL3pp_surface.h:3594
void Clear(const FColorRaw &c)
Clear a surface with a specific color, with floating point precision.
Definition: SDL3pp_surface.h:3890
void UnlockSurface(SurfaceRef surface)
Release a surface after directly accessing the pixels.
Definition: SDL3pp_surface.h:2760
void SetMod(Color color)
Set an additional color and alpha value multiplied into blit operations.
Definition: SDL3pp_surface.h:3362
SDL_FlipMode FlipMode
The flip mode.
Definition: SDL3pp_surface.h:146
static Surface LoadPNG(IOStreamRef src, bool closeio=false)
Load a PNG image from a seekable SDL data stream.
Definition: SDL3pp_surface.h:3002
bool SurfaceHasAlternateImages(SurfaceConstRef surface)
Return whether a surface has alternate versions available.
Definition: SDL3pp_surface.h:2637
bool SurfaceHasRLE(SurfaceConstRef surface)
Returns whether the surface is RLE enabled.
Definition: SDL3pp_surface.h:3111
void GetColorMod(Uint8 *r, Uint8 *g, Uint8 *b) const
Get the additional color value multiplied into blit operations.
Definition: SDL3pp_surface.h:3280
void StretchSurface(SurfaceRef src, OptionalRef< RectRaw > srcrect, SurfaceRef dst, OptionalRef< RectRaw > dstrect, ScaleMode scaleMode)
Perform a stretched pixel copy from one surface to another.
Definition: SDL3pp_surface.h:4289
SurfaceLock Lock()
Set up a surface for directly accessing the pixels.
Definition: SDL3pp_surface.h:2739
constexpr ScaleMode SCALEMODE_INVALID
INVALID.
Definition: SDL3pp_surface.h:121
constexpr int GetWidth() const
Get the width in pixels.
Definition: SDL3pp_surface.h:4923
void SetColorMod(Uint8 r, Uint8 g, Uint8 b)
Set an additional color value multiplied into blit operations.
Definition: SDL3pp_surface.h:3250
void ClearSurfaceColorKey(SurfaceRef surface)
Unset the color key (transparent pixel) in a surface.
Definition: SDL3pp_surface.h:3160
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:3823
void SetBlendMode(BlendMode blendMode)
Set the blend mode used for blit operations.
Definition: SDL3pp_surface.h:3405
OwnArray< SurfaceRaw > GetImages() const
Get an array including all versions of a surface.
Definition: SDL3pp_surface.h:2677
Surface Rotate(float angle)
Return a copy of a surface rotated clockwise a number of degrees.
Definition: SDL3pp_surface.h:3563
Surface CreateSurface(const PointRaw &size, PixelFormat format)
Allocate a new surface with a specific pixel format.
Definition: SDL3pp_surface.h:2300
void SetSurfaceColorMod(SurfaceRef surface, Uint8 r, Uint8 g, Uint8 b)
Set an additional color value multiplied into blit operations.
Definition: SDL3pp_surface.h:3245
void FillSurfaceRects(SurfaceRef dst, SpanRef< const RectRaw > rects, Uint32 color)
Perform a fast fill of a set of rectangles with a specific color.
Definition: SDL3pp_surface.h:3974
void SetPalette(PaletteRef palette)
Set the palette used by a surface.
Definition: SDL3pp_surface.h:2560
void BlitSurfaceUncheckedScaled(SurfaceRef src, const RectRaw &srcrect, SurfaceRef dst, const RectRaw &dstrect, ScaleMode scaleMode)
Perform low-level surface scaled blitting only.
Definition: SDL3pp_surface.h:4249
constexpr FlipMode FLIP_HORIZONTAL
flip horizontally
Definition: SDL3pp_surface.h:150
void SetSurfaceRLE(SurfaceRef surface, bool enabled)
Set the RLE acceleration hint for a surface.
Definition: SDL3pp_surface.h:3087
Surface ConvertSurfaceAndColorspace(SurfaceConstRef surface, PixelFormat format, PaletteRef palette, Colorspace colorspace, PropertiesRef props)
Copy an existing surface to a new surface of the specified format and colorspace.
Definition: SDL3pp_surface.h:3695
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:4672
constexpr void * GetSurfacePixels(SurfaceConstRef surface)
Get the pixels.
Definition: SDL3pp_surface.h:4994
void Fill(Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition: SDL3pp_surface.h:3948
constexpr int GetSurfaceHeight(SurfaceConstRef surface)
Get the height in pixels.
Definition: SDL3pp_surface.h:4929
Uint32 MapRGBA(ColorRaw c) const
Map an RGBA quadruple to a pixel value for a surface.
Definition: SDL3pp_surface.h:4545
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:3625
void Blit9Grid(SurfaceRef 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:4448
void SetColorspace(Colorspace colorspace)
Set the colorspace used by a surface.
Definition: SDL3pp_surface.h:2465
void ClearColorKey()
Unset the color key (transparent pixel) in a surface.
Definition: SDL3pp_surface.h:3165
Uint32 SurfaceFlags
The flags on an Surface.
Definition: SDL3pp_surface.h:91
void WritePixel(const PointRaw &p, ColorRaw c)
Writes a single pixel to a surface.
Definition: SDL3pp_surface.h:4858
void ReadSurfacePixelFloat(SurfaceConstRef surface, const PointRaw &p, float *r, float *g, float *b, float *a)
Retrieves a single pixel from a surface.
Definition: SDL3pp_surface.h:4709
void ReadSurfacePixel(SurfaceConstRef surface, const PointRaw &p, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
Retrieves a single pixel from a surface.
Definition: SDL3pp_surface.h:4576
void BlitUnchecked(SurfaceRef src, const RectRaw &srcrect, const RectRaw &dstrect)
Perform low-level surface blitting only.
Definition: SDL3pp_surface.h:4182
Color GetSurfaceMod(SurfaceConstRef surface)
Get the additional color and alpha value multiplied into blit operations.
Definition: SDL3pp_surface.h:3372
void BlitScaled(SurfaceRef 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:4219
void FillRect(OptionalRef< const RectRaw > rect, Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition: SDL3pp_surface.h:3927
constexpr int GetSurfacePitch(SurfaceConstRef surface)
Get pitch in bytes.
Definition: SDL3pp_surface.h:4960
void Unlock(SurfaceLock &&lock)
Release a surface after directly accessing the pixels.
Definition: SDL3pp_surface.h:2762
constexpr Point GetSurfaceSize(SurfaceConstRef surface)
Get the size in pixels.
Definition: SDL3pp_surface.h:4943
void ResetSurfaceClipRect(SurfaceRef surface)
Disable the clipping rectangle for a surface.
Definition: SDL3pp_surface.h:3473
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:4796
std::optional< Uint32 > GetSurfaceColorKey(SurfaceConstRef surface)
Get the color key (transparent pixel) for a surface.
Definition: SDL3pp_surface.h:3211
void SetAlphaMod(Uint8 alpha)
Set an additional alpha value used in blit operations.
Definition: SDL3pp_surface.h:3310
constexpr void * GetPixels() const
Get the pixels.
Definition: SDL3pp_surface.h:5005
void BlitAt(SurfaceRef 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:4071
SDL_ScaleMode ScaleMode
The scaling mode.
Definition: SDL3pp_surface.h:117
void SetSurfaceColorspace(SurfaceRef surface, Colorspace colorspace)
Set the colorspace used by a surface.
Definition: SDL3pp_surface.h:2460
void SetRLE(bool enabled)
Set the RLE acceleration hint for a surface.
Definition: SDL3pp_surface.h:3092
Uint32 MapSurfaceRGBA(SurfaceConstRef surface, ColorRaw c)
Map an RGBA quadruple to a pixel value for a surface.
Definition: SDL3pp_surface.h:4540
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:3734
Color GetMod() const
Get the additional color and alpha value multiplied into blit operations.
Definition: SDL3pp_surface.h:3380
void FlipSurface(SurfaceRef surface, FlipMode flip)
Flip a surface vertically or horizontally.
Definition: SDL3pp_surface.h:3522
constexpr FlipMode FLIP_HORIZONTAL_AND_VERTICAL
flip horizontally and vertically (not a diagonal flip)
Definition: SDL3pp_surface.h:157
bool SetClipRect(OptionalRef< const RectRaw > rect)
Set the clipping rectangle for a surface.
Definition: SDL3pp_surface.h:3463
Rect GetSurfaceClipRect(SurfaceConstRef surface)
Get the clipping rectangle for a surface.
Definition: SDL3pp_surface.h:3498
void FillSurface(SurfaceRef dst, Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition: SDL3pp_surface.h:3943
void WritePixelFloat(const PointRaw &p, const FColorRaw &c)
Writes a single pixel to a surface.
Definition: SDL3pp_surface.h:4909
Main include header for the SDL3pp library.
A structure that represents a color as RGBA components.
Definition: SDL3pp_pixels.h:2166
The bits of this structure can be directly reinterpreted as a float-packed color which uses the PIXEL...
Definition: SDL3pp_pixels.h:2339
Reference for IOStream.
Definition: SDL3pp_iostream.h:1631
Reference for Palette.
Definition: SDL3pp_pixels.h:2648
The structure that defines a point (using integers).
Definition: SDL3pp_rect.h:83
Reference for Properties.
Definition: SDL3pp_properties.h:690
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:53
constexpr auto operator<=>(const SurfaceConstRef &other) const =default
Comparison.
constexpr SurfaceConstRef(const SurfaceRaw value)
Constructs from const SurfaceRaw.
Definition: SDL3pp_surface.h:57
constexpr auto operator->()
member access to underlying SurfaceRaw.
Definition: SDL3pp_surface.h:78
constexpr SurfaceConstRef(std::nullptr_t=nullptr)
Constructs null/invalid.
Definition: SDL3pp_surface.h:63
const SurfaceRaw value
parameter's const SurfaceRaw
Definition: SDL3pp_surface.h:54
Reference for Surface.
Definition: SDL3pp_surface.h:1963
~SurfaceRef()
Destructor.
Definition: SDL3pp_surface.h:2003
constexpr SurfaceRef(const Surface &resource) noexcept
Constructs from Surface.
Definition: SDL3pp_surface.h:1985
constexpr SurfaceRef & operator=(SurfaceRef other) noexcept
Assignment operator.
Definition: SDL3pp_surface.h:2006
SurfaceRef(SurfaceRaw resource) noexcept
Constructs from raw Surface.
Definition: SDL3pp_surface.h:1973
constexpr SurfaceRef(const SurfaceRef &other) noexcept
Copy constructor.
Definition: SDL3pp_surface.h:1991
constexpr SurfaceRef(SurfaceRef &&other) noexcept
Move constructor.
Definition: SDL3pp_surface.h:1997