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"
75 SDL_SURFACE_PREALLOCATED;
78 SDL_SURFACE_LOCK_NEEDED;
103#if SDL_VERSION_ATLEAST(3, 2, 10)
110 SDL_SCALEMODE_NEAREST;
113 SDL_SCALEMODE_LINEAR;
115#if SDL_VERSION_ATLEAST(3, 4, 0)
138#if SDL_VERSION_ATLEAST(3, 4, 0)
142 SDL_FLIP_HORIZONTAL_AND_VERTICAL;
534 void SetRLE(
bool enabled);
817#if SDL_VERSION_ATLEAST(3, 4, 0)
1264#if SDL_VERSION_ATLEAST(3, 4, 0)
1667 using SurfaceBase::SurfaceBase;
1830 ++resource->refcount;
1849 if (
get() != other.
get()) {
1911 : m_lock(std::move(other.m_lock))
1933 std::swap(m_lock, other.m_lock);
1938 constexpr operator bool()
const {
return bool(m_lock); }
1971 m_lock.ReadPixel(p, r, g, b, a);
2022 m_lock.ReadPixelFloat(p, r, g, b, a);
2042 return m_lock.ReadPixelFloat(p);
2082 m_lock.WritePixelFloat(p, c);
2086 constexpr int GetWidth()
const {
return m_lock.GetWidth(); }
2089 constexpr int GetHeight()
const {
return m_lock.GetHeight(); }
2095 constexpr int GetPitch()
const {
return m_lock.GetPitch(); }
2101 constexpr void*
GetPixels()
const {
return m_lock.GetPixels(); }
2155 CheckError(SDL_CreateSurfaceFrom(size.x, size.y, format, pixels, pitch)))
2190 return Surface(size, format, pixels, pitch);
2250 return CheckError(SDL_GetSurfaceProperties(surface));
2273 SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT;
2276 SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT;
2279 SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING;
2281#if SDL_VERSION_ATLEAST(3, 2, 6)
2284 SDL_PROP_SURFACE_HOTSPOT_X_NUMBER;
2287 SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER;
2291#if SDL_VERSION_ATLEAST(3, 4, 0)
2294 SDL_PROP_SURFACE_ROTATION_FLOAT;
2319 CheckError(SDL_SetSurfaceColorspace(surface, colorspace));
2347 return SDL_GetSurfaceColorspace(surface);
2414 CheckError(SDL_SetSurfacePalette(surface, palette));
2472 CheckError(SDL_AddSurfaceAlternateImage(surface, image));
2496 return SDL_SurfaceHasAlternateImages(surface);
2530 auto data = SDL_GetSurfaceImages(surface, &count);
2558 SDL_RemoveSurfaceAlternateImages(surface);
2622 std::move(lock).reset();
2627 if (!m_lock)
return;
2632#if !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC) && \
2633 SDL_VERSION_ATLEAST(3, 4, 0)
2670 return Surface{SDL_LoadSurface(file)};
2780#if SDL_VERSION_ATLEAST(3, 4, 0)
2830 return Surface(SDL_LoadPNG(file));
2833#if !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2863#if !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2890#if !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2920 CheckError(SDL_SetSurfaceRLE(surface, enabled));
2944 return SDL_SurfaceHasRLE(surface);
2973 CheckError(SDL_SetSurfaceColorKey(surface, key.has_value(), key.value_or(0)));
3015 return SDL_SurfaceHasColorKey(surface);
3044 if (
Uint32 key; SDL_GetSurfaceColorKey(surface, &key))
return key;
3045 return std::nullopt;
3078 CheckError(SDL_SetSurfaceColorMod(surface, r, g, b));
3108 CheckError(SDL_GetSurfaceColorMod(surface, r, g, b));
3138 CheckError(SDL_SetSurfaceAlphaMod(surface, alpha));
3163 CheckError(SDL_GetSurfaceAlphaMod(surface, &alpha));
3233 CheckError(SDL_SetSurfaceBlendMode(surface, blendMode));
3257 CheckError(SDL_GetSurfaceBlendMode(surface, &blendmode));
3292 return SDL_SetSurfaceClipRect(surface, rect);
3333 CheckError(SDL_GetSurfaceClipRect(surface, &r));
3361#if SDL_VERSION_ATLEAST(3, 4, 0)
3392 return Surface{SDL_RotateSurface(surface, angle)};
3423 return Surface(SDL_DuplicateSurface(surface));
3454 return Surface(SDL_ScaleSurface(surface, size.x, size.y, scaleMode));
3492 return Surface(SDL_ConvertSurface(surface, format));
3534 return Surface{SDL_ConvertSurfaceAndColorspace(
3535 surface, format, palette, colorspace, props)};
3544 get(), format, palette, colorspace, props);
3576 size.x, size.y, src_format, src, src_pitch, dst_format, dst, dst_pitch));
3620 CheckError(SDL_ConvertPixelsAndColorspace(size.x,
3693 CheckError(SDL_PremultiplySurfaceAlpha(surface, linear));
3720 CheckError(SDL_ClearSurface(surface, c.r, c.g, c.b, c.a));
3754 CheckError(SDL_FillSurfaceRect(dst, rect, color));
3892 CheckError(SDL_BlitSurface(src, srcrect, dst, dstrect));
3906 Blit(src, srcrect,
Rect{dstpos, {}});
3981 BlitSurface(src, srcrect, dst, SDL_Rect{dstpos.x, dstpos.y, 0, 0});
4010 CheckError(SDL_BlitSurfaceUnchecked(src, &srcrect, dst, &dstrect));
4047 CheckError(SDL_BlitSurfaceScaled(src, srcrect, dst, dstrect, scaleMode));
4087 SDL_BlitSurfaceUncheckedScaled(src, &srcrect, dst, &dstrect, scaleMode));
4098#if SDL_VERSION_ATLEAST(3, 4, 0)
4126 CheckError(SDL_StretchSurface(src, srcrect, dst, dstrect, scaleMode));
4166 CheckError(SDL_BlitSurfaceTiled(src, srcrect, dst, dstrect));
4210 src, srcrect, scale, scaleMode, dst, dstrect));
4220 src, srcrect, scale, scaleMode,
get(), dstrect);
4334 return SDL_MapSurfaceRGB(surface, r, g, b);
4373 return SDL_MapSurfaceRGBA(surface, c.r, c.g, c.b, c.a);
4414 CheckError(SDL_ReadSurfacePixel(surface, p.x, p.y, r, g, b, a));
4547 CheckError(SDL_ReadSurfacePixelFloat(surface, p.x, p.y, r, g, b, a));
4662 CheckError(SDL_WriteSurfacePixel(surface, p.x, p.y, c.r, c.g, c.b, c.a));
4714 CheckError(SDL_WriteSurfacePixelFloat(surface, p.x, p.y, c.r, c.g, c.b, c.a));
4770 return Point(surface->w, surface->h);
4784 return surface->pitch;
4798 return surface->format;
4815 return surface->pixels;
Colorspace definitions.
Definition SDL3pp_pixels.h:1583
Optional-like shim for references.
Definition SDL3pp_optionalRef.h:20
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:44
constexpr OwnArray(std::nullptr_t=nullptr)
Constructor.
Definition SDL3pp_ownPtr.h:50
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:57
friend constexpr void swap(ResourceBaseT &lhs, ResourceBaseT &rhs) noexcept
Definition SDL3pp_resource.h:65
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:54
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
Const reference wrapper for a given resource,.
Definition SDL3pp_resource.h:115
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:58
Set up a surface for directly accessing the pixels.
Definition SDL3pp_surface.h:1875
SurfaceRef resource() const
Get the reference to locked resource.
Definition SDL3pp_surface.h:2117
constexpr PixelFormat GetFormat() const
Get the pixel format.
Definition SDL3pp_surface.h:2098
SurfaceLock(SurfaceLock &&other) noexcept
Move constructor.
Definition SDL3pp_surface.h:1910
FColor ReadPixelFloat(const PointRaw &p) const
Retrieves a single pixel from a surface.
Definition SDL3pp_surface.h:2040
~SurfaceLock()
Release a surface after directly accessing the pixels.
Definition SDL3pp_surface.h:1926
constexpr int GetHeight() const
Get the height in pixels.
Definition SDL3pp_surface.h:2089
constexpr int GetWidth() const
Get the width in pixels.
Definition SDL3pp_surface.h:2086
constexpr void * GetPixels() const
Get the pixels.
Definition SDL3pp_surface.h:2101
void release()
Releases the lock without unlocking.
Definition SDL3pp_surface.h:2120
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:1965
void WritePixelFloat(const PointRaw &p, const FColorRaw &c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:2080
SurfaceLock & operator=(SurfaceLock &&other) noexcept
Assignment operator.
Definition SDL3pp_surface.h:1931
void WritePixel(const PointRaw &p, ColorRaw c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:2063
constexpr Point GetSize() const
Get the size in pixels.
Definition SDL3pp_surface.h:2092
Color ReadPixel(const PointRaw &p) const
Retrieves a single pixel from a surface.
Definition SDL3pp_surface.h:1992
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:2016
constexpr int GetPitch() const
Get pitch in bytes.
Definition SDL3pp_surface.h:2095
#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:199
ResourceRefT< IOStreamBase > IOStreamRef
Reference for IOStream.
Definition SDL3pp_iostream.h:37
SDL_Color ColorRaw
Alias to raw representation for Color.
Definition SDL3pp_pixels.h:83
Uint32 MapRGBA(const PixelFormatDetails &format, Uint8 r, Uint8 g, Uint8 b, Uint8 a, PaletteConstRef palette={})
Map an RGBA quadruple to a pixel value for a given pixel format.
Definition SDL3pp_pixels.h:2860
SDL_FColor FColorRaw
Alias to raw representation for FColor.
Definition SDL3pp_pixels.h:89
Uint32 MapRGB(const PixelFormatDetails &format, PaletteConstRef palette, Uint8 r, Uint8 g, Uint8 b)
Map an RGB triple to an opaque pixel value for a given pixel format.
Definition SDL3pp_pixels.h:2814
ResourceRefT< PaletteBase > PaletteRef
Reference for Palette.
Definition SDL3pp_pixels.h:111
Palette CreatePalette(int ncolors)
Create a palette structure with the specified number of color entries.
Definition SDL3pp_pixels.h:2723
ResourceRefT< PropertiesBase > PropertiesRef
Reference for Properties.
Definition SDL3pp_properties.h:56
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(StringParam file)
Load a PNG image from a file.
Definition SDL3pp_image.h:1739
void SavePNG(StringParam file) const
Save a surface to a file in PNG format.
Definition SDL3pp_image.h:2423
void Save(SurfaceConstRef surface, StringParam file)
Save an Surface into an image file.
Definition SDL3pp_image.h:2163
Surface LoadSurface_IO(IOStreamParam src)
Load an image from an SDL data source into a software surface.
Definition SDL3pp_image.h:215
void SavePNG(SurfaceRef surface, StringParam file)
Save an Surface into a PNG image file.
Definition SDL3pp_image.h:2418
void SaveTyped_IO(SurfaceConstRef surface, IOStreamParam dst, StringParam type)
Save an Surface into formatted image data, via an IOStream.
Definition SDL3pp_image.h:2199
void SavePNG_IO(IOStreamParam dst) const
Save a surface to a seekable SDL data stream in PNG format.
Definition SDL3pp_image.h:2446
Surface LoadSurface(StringParam file)
Load an image from a filesystem path into a software surface.
Definition SDL3pp_image.h:164
void SavePNG_IO(SurfaceRef surface, IOStreamParam dst)
Save an Surface into PNG image data, via an IOStream.
Definition SDL3pp_image.h:2441
Surface LoadPNG_IO(IOStreamParam src)
Load a PNG image directly.
Definition SDL3pp_image.h:1701
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition SDL3pp_stdinc.h:296
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition SDL3pp_stdinc.h:244
SurfaceLock(SurfaceRef resource)
Set up a surface for directly accessing the pixels.
Definition SDL3pp_surface.h:2598
constexpr int GetHeight() const
Get the height in pixels.
Definition SDL3pp_surface.h:4765
void BlitUnchecked(SurfaceRef src, const RectRaw &srcrect, const RectRaw &dstrect)
Perform low-level surface blitting only.
Definition SDL3pp_surface.h:4013
void SetPalette(PaletteRef palette)
Set the palette used by a surface.
Definition SDL3pp_surface.h:2417
Surface Convert(PixelFormat format) const
Copy an existing surface to a new surface of the specified format.
Definition SDL3pp_surface.h:3495
void SaveBMP(StringParam file) const
Save a surface to a file in BMP format.
Definition SDL3pp_surface.h:2775
Palette CreateSurfacePalette(SurfaceRef surface)
Create a palette and associate it with a surface.
Definition SDL3pp_surface.h:2382
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:4169
void SaveTrustedPNG(SurfaceConstRef surface, StringParam file)
Save a surface to a file in PNG format.
Definition SDL3pp_surface.h:2885
constexpr FlipMode FLIP_VERTICAL
flip vertically
Definition SDL3pp_surface.h:136
SurfaceLock Lock()
Set up a surface for directly accessing the pixels.
Definition SDL3pp_surface.h:2596
void ClearColorKey()
Unset the color key (transparent pixel) in a surface.
Definition SDL3pp_surface.h:2996
void SetSurfaceColorKey(SurfaceRef surface, std::optional< Uint32 > key)
Set the color key (transparent pixel) in a surface.
Definition SDL3pp_surface.h:2971
void WriteSurfacePixel(SurfaceRef surface, const PointRaw &p, ColorRaw c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:4660
constexpr int GetWidth() const
Get the width in pixels.
Definition SDL3pp_surface.h:4754
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:3976
void Destroy()
Free this surface.
Definition SDL3pp_surface.h:2209
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:3902
void Unlock(SurfaceLock &&lock)
Release a surface after directly accessing the pixels.
Definition SDL3pp_surface.h:2619
void AddSurfaceAlternateImage(SurfaceRef surface, SurfaceRef image)
Add an alternate version of a surface.
Definition SDL3pp_surface.h:2470
SDL_FlipMode FlipMode
The flip mode.
Definition SDL3pp_surface.h:130
void GetSurfaceColorMod(SurfaceConstRef surface, Uint8 *r, Uint8 *g, Uint8 *b)
Get the additional color value multiplied into blit operations.
Definition SDL3pp_surface.h:3103
OwnArray< SurfaceRaw > GetImages() const
Get an array including all versions of a surface.
Definition SDL3pp_surface.h:2534
Colorspace GetColorspace() const
Get the colorspace used by a surface.
Definition SDL3pp_surface.h:2350
void SetSurfaceMod(SurfaceRef surface, Color color)
Set an additional color and alpha value multiplied into blit operations.
Definition SDL3pp_surface.h:3187
Uint8 GetAlphaMod() const
Get the additional alpha value used in blit operations.
Definition SDL3pp_surface.h:3167
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:4503
constexpr SurfaceFlags SURFACE_SIMD_ALIGNED
Surface uses pixel memory allocated with aligned_alloc().
Definition SDL3pp_surface.h:84
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:4332
constexpr PixelFormat GetFormat() const
Get the pixel format.
Definition SDL3pp_surface.h:4807
constexpr SurfaceFlags SURFACE_LOCK_NEEDED
Surface needs to be locked to access pixels.
Definition SDL3pp_surface.h:77
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:4050
void SetSurfaceAlphaMod(SurfaceRef surface, Uint8 alpha)
Set an additional alpha value used in blit operations.
Definition SDL3pp_surface.h:3136
void AddAlternateImage(SurfaceRef image)
Add an alternate version of a surface.
Definition SDL3pp_surface.h:2475
BlendMode GetSurfaceBlendMode(SurfaceConstRef surface)
Get the blend mode used for blit operations.
Definition SDL3pp_surface.h:3254
void RemoveSurfaceAlternateImages(SurfaceRef surface)
Remove all alternate versions of a surface.
Definition SDL3pp_surface.h:2556
constexpr Point GetSize() const
Get the size in pixels.
Definition SDL3pp_surface.h:4779
void DestroySurface(SurfaceRaw surface)
Free a surface.
Definition SDL3pp_surface.h:2207
void ClearSurface(SurfaceRef surface, const FColorRaw &c)
Clear a surface with a specific color, with floating point precision.
Definition SDL3pp_surface.h:3718
std::optional< Uint32 > GetColorKey() const
Get the color key (transparent pixel) for a surface.
Definition SDL3pp_surface.h:3048
void LockSurface(SurfaceRef surface)
Set up a surface for directly accessing the pixels.
Definition SDL3pp_surface.h:2591
SDL_ScaleMode ScaleMode
The scaling mode.
Definition SDL3pp_surface.h:101
constexpr FlipMode FLIP_NONE
Do not flip.
Definition SDL3pp_surface.h:132
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:3887
void RemoveAlternateImages()
Remove all alternate versions of a surface.
Definition SDL3pp_surface.h:2561
Color GetMod() const
Get the additional color and alpha value multiplied into blit operations.
Definition SDL3pp_surface.h:3211
void Clear(const FColorRaw &c)
Clear a surface with a specific color, with floating point precision.
Definition SDL3pp_surface.h:3723
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:4256
bool SetClipRect(OptionalRef< const RectRaw > rect)
Set the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3295
OwnArray< SurfaceRaw > GetSurfaceImages(SurfaceConstRef surface)
Get an array including all versions of a surface.
Definition SDL3pp_surface.h:2527
constexpr bool MustLock(SurfaceConstRef S)
Evaluates to true if the surface needs to be locked before access.
Definition SDL3pp_surface.h:91
constexpr int GetSurfaceWidth(SurfaceConstRef surface)
Get the width in pixels.
Definition SDL3pp_surface.h:4746
Surface RotateSurface(SurfaceRef surface, float angle)
Return a copy of a surface rotated clockwise a number of degrees.
Definition SDL3pp_surface.h:3390
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:3750
void PremultiplySurfaceAlpha(SurfaceRef surface, bool linear)
Premultiply the alpha in a surface.
Definition SDL3pp_surface.h:3691
constexpr SurfaceFlags SURFACE_PREALLOCATED
Surface uses preallocated pixel memory.
Definition SDL3pp_surface.h:74
Surface Duplicate() const
Creates a new surface identical to the existing surface.
Definition SDL3pp_surface.h:3426
constexpr ScaleMode SCALEMODE_LINEAR
linear filtering
Definition SDL3pp_surface.h:112
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:4627
void BlitSurfaceUnchecked(SurfaceRef src, const RectRaw &srcrect, SurfaceRef dst, const RectRaw &dstrect)
Perform low-level surface blitting only.
Definition SDL3pp_surface.h:4005
void SaveBMP(SurfaceConstRef surface, StringParam file)
Save a surface to a file in BMP format.
Definition SDL3pp_surface.h:2770
void Fill(Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition SDL3pp_surface.h:3778
SDL_Surface * SurfaceRaw
Alias to raw representation for Surface.
Definition SDL3pp_surface.h:47
void reset()
Release a surface after directly accessing the pixels.
Definition SDL3pp_surface.h:2625
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:3895
void WriteSurfacePixelFloat(SurfaceRef surface, const PointRaw &p, const FColorRaw &c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:4710
bool SetSurfaceClipRect(SurfaceRef surface, OptionalRef< const RectRaw > rect)
Set the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3289
constexpr PixelFormat GetSurfaceFormat(SurfaceConstRef surface)
Get the pixel format.
Definition SDL3pp_surface.h:4796
void SetSurfacePalette(SurfaceRef surface, PaletteRef palette)
Set the palette used by a surface.
Definition SDL3pp_surface.h:2412
constexpr ScaleMode SCALEMODE_NEAREST
nearest pixel sampling
Definition SDL3pp_surface.h:109
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:2185
void SetRLE(bool enabled)
Set the RLE acceleration hint for a surface.
Definition SDL3pp_surface.h:2923
PropertiesRef GetSurfaceProperties(SurfaceConstRef surface)
Get the properties associated with a surface.
Definition SDL3pp_surface.h:2248
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:4202
bool HasColorKey() const
Returns whether the surface has a color key.
Definition SDL3pp_surface.h:3018
void FillRect(OptionalRef< const RectRaw > rect, Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition SDL3pp_surface.h:3757
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:3608
Colorspace GetSurfaceColorspace(SurfaceConstRef surface)
Get the colorspace used by a surface.
Definition SDL3pp_surface.h:2345
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:4041
Surface LoadBMP(StringParam file)
Load a BMP image from a file.
Definition SDL3pp_surface.h:2716
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:4161
Surface ConvertSurface(SurfaceConstRef surface, PixelFormat format)
Copy an existing surface to a new surface of the specified format.
Definition SDL3pp_surface.h:3490
PropertiesRef GetProperties() const
Get the properties associated with a surface.
Definition SDL3pp_surface.h:2253
Surface DuplicateSurface(SurfaceConstRef surface)
Creates a new surface identical to the existing surface.
Definition SDL3pp_surface.h:3421
constexpr ScaleMode SCALEMODE_PIXELART
nearest pixel sampling with improved scaling for pixel art, available since SDL 3....
Definition SDL3pp_surface.h:121
bool HasRLE() const
Returns whether the surface is RLE enabled.
Definition SDL3pp_surface.h:2947
Palette GetSurfacePalette(SurfaceConstRef surface)
Get the palette used by a surface.
Definition SDL3pp_surface.h:2435
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:3450
void GetColorMod(Uint8 *r, Uint8 *g, Uint8 *b) const
Get the additional color value multiplied into blit operations.
Definition SDL3pp_surface.h:3111
void SaveTrustedPNG_IO(SurfaceConstRef surface, IOStreamParam dst)
Save a surface to a seekable SDL data stream in PNG format.
Definition SDL3pp_surface.h:2858
constexpr SurfaceFlags SURFACE_LOCKED
Surface is currently locked.
Definition SDL3pp_surface.h:80
void SetMod(Color color)
Set an additional color and alpha value multiplied into blit operations.
Definition SDL3pp_surface.h:3193
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:4337
Surface Rotate(float angle)
Return a copy of a surface rotated clockwise a number of degrees.
Definition SDL3pp_surface.h:3395
constexpr void * GetPixels() const
Get the pixels.
Definition SDL3pp_surface.h:4824
const SDL_Surface * SurfaceRawConst
Alias to const raw representation for Surface.
Definition SDL3pp_surface.h:50
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:4213
Uint8 GetSurfaceAlphaMod(SurfaceConstRef surface)
Get the additional alpha value used in blit operations.
Definition SDL3pp_surface.h:3160
bool SurfaceHasColorKey(SurfaceConstRef surface)
Returns whether the surface has a color key.
Definition SDL3pp_surface.h:3013
void SaveBMP_IO(SurfaceConstRef surface, IOStreamParam dst)
Save a surface to a seekable SDL data stream in BMP format.
Definition SDL3pp_surface.h:2739
Surface LoadBMP_IO(IOStreamParam src)
Load a BMP image from a seekable SDL data stream.
Definition SDL3pp_surface.h:2693
Rect GetClipRect() const
Get the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3337
void SetSurfaceBlendMode(SurfaceRef surface, BlendMode blendMode)
Set the blend mode used for blit operations.
Definition SDL3pp_surface.h:3231
Palette CreatePalette()
Create a palette and associate it with a surface.
Definition SDL3pp_surface.h:2387
void SetBlendMode(BlendMode blendMode)
Set the blend mode used for blit operations.
Definition SDL3pp_surface.h:3236
void UnlockSurface(SurfaceRef surface)
Release a surface after directly accessing the pixels.
Definition SDL3pp_surface.h:2617
Surface LoadTrustedPNG_IO(IOStreamParam src)
Load a PNG image from a seekable SDL data stream.
Definition SDL3pp_surface.h:2801
void PremultiplyAlpha(bool linear)
Premultiply the alpha in a surface.
Definition SDL3pp_surface.h:3696
void SetColorKey(std::optional< Uint32 > key)
Set the color key (transparent pixel) in a surface.
Definition SDL3pp_surface.h:2976
void BlitUncheckedScaled(SurfaceRef src, const RectRaw &srcrect, const RectRaw &dstrect, ScaleMode scaleMode)
Perform low-level surface scaled blitting only.
Definition SDL3pp_surface.h:4090
ResourceRefT< SurfaceBase > SurfaceRef
Reference for Surface.
Definition SDL3pp_surface.h:57
bool SurfaceHasAlternateImages(SurfaceConstRef surface)
Return whether a surface has alternate versions available.
Definition SDL3pp_surface.h:2494
bool SurfaceHasRLE(SurfaceConstRef surface)
Returns whether the surface is RLE enabled.
Definition SDL3pp_surface.h:2942
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:4120
constexpr ScaleMode SCALEMODE_INVALID
INVALID.
Definition SDL3pp_surface.h:105
constexpr int GetPitch() const
Get pitch in bytes.
Definition SDL3pp_surface.h:4793
void ClearSurfaceColorKey(SurfaceRef surface)
Unset the color key (transparent pixel) in a surface.
Definition SDL3pp_surface.h:2991
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:3656
bool HasAlternateImages() const
Return whether a surface has alternate versions available.
Definition SDL3pp_surface.h:2499
Surface CreateSurface(const PointRaw &size, PixelFormat format)
Allocate a new surface with a specific pixel format.
Definition SDL3pp_surface.h:2140
void SetSurfaceColorMod(SurfaceRef surface, Uint8 r, Uint8 g, Uint8 b)
Set an additional color value multiplied into blit operations.
Definition SDL3pp_surface.h:3076
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:3804
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:4080
Uint32 MapRGBA(ColorRaw c) const
Map an RGBA quadruple to a pixel value for a surface.
Definition SDL3pp_surface.h:4376
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:4279
constexpr FlipMode FLIP_HORIZONTAL
flip horizontally
Definition SDL3pp_surface.h:134
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:3457
void SetSurfaceRLE(SurfaceRef surface, bool enabled)
Set the RLE acceleration hint for a surface.
Definition SDL3pp_surface.h:2918
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:3528
BlendMode GetBlendMode() const
Get the blend mode used for blit operations.
Definition SDL3pp_surface.h:3261
void WritePixel(const PointRaw &p, ColorRaw c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:4689
constexpr void * GetSurfacePixels(SurfaceConstRef surface)
Get the pixels.
Definition SDL3pp_surface.h:4813
void SetColorspace(Colorspace colorspace)
Set the colorspace used by a surface.
Definition SDL3pp_surface.h:2322
Uint32 SurfaceFlags
The flags on an Surface.
Definition SDL3pp_surface.h:72
ResourceConstRef< SurfaceRaw, SurfaceRawConst > SurfaceConstRef
Safely wrap Surface for non owning const parameters.
Definition SDL3pp_surface.h:60
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:4129
constexpr int GetSurfaceHeight(SurfaceConstRef surface)
Get the height in pixels.
Definition SDL3pp_surface.h:4757
void SetAlphaMod(Uint8 alpha)
Set an additional alpha value used in blit operations.
Definition SDL3pp_surface.h:3141
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:3812
void SetColorMod(Uint8 r, Uint8 g, Uint8 b)
Set an additional color value multiplied into blit operations.
Definition SDL3pp_surface.h:3081
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:4540
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:4407
Color GetSurfaceMod(SurfaceConstRef surface)
Get the additional color and alpha value multiplied into blit operations.
Definition SDL3pp_surface.h:3203
Surface LoadTrustedPNG(StringParam file)
Load a PNG image from a file.
Definition SDL3pp_surface.h:2828
constexpr int GetSurfacePitch(SurfaceConstRef surface)
Get pitch in bytes.
Definition SDL3pp_surface.h:4782
constexpr Point GetSurfaceSize(SurfaceConstRef surface)
Get the size in pixels.
Definition SDL3pp_surface.h:4768
void ResetSurfaceClipRect(SurfaceRef surface)
Disable the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3305
std::optional< Uint32 > GetSurfaceColorKey(SurfaceConstRef surface)
Get the color key (transparent pixel) for a surface.
Definition SDL3pp_surface.h:3042
void SaveBMP_IO(IOStreamParam dst) const
Save a surface to a seekable SDL data stream in BMP format.
Definition SDL3pp_surface.h:2744
Palette GetPalette() const
Get the palette used by a surface.
Definition SDL3pp_surface.h:2440
void WritePixelFloat(const PointRaw &p, const FColorRaw &c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:4740
void SetSurfaceColorspace(SurfaceRef surface, Colorspace colorspace)
Set the colorspace used by a surface.
Definition SDL3pp_surface.h:2317
void Flip(FlipMode flip)
Flip a surface vertically or horizontally.
Definition SDL3pp_surface.h:3359
Uint32 MapSurfaceRGBA(SurfaceConstRef surface, ColorRaw c)
Map an RGBA quadruple to a pixel value for a surface.
Definition SDL3pp_surface.h:4371
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:3567
void FlipSurface(SurfaceRef surface, FlipMode flip)
Flip a surface vertically or horizontally.
Definition SDL3pp_surface.h:3354
constexpr FlipMode FLIP_HORIZONTAL_AND_VERTICAL
flip horizontally and vertically (not a diagonal flip)
Definition SDL3pp_surface.h:141
Rect GetSurfaceClipRect(SurfaceConstRef surface)
Get the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3330
void FillSurface(SurfaceRef dst, Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition SDL3pp_surface.h:3773
void ResetClipRect()
Disable the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3310
Properties for Surface.
Definition SDL3pp_surface.h:2270
constexpr auto HOTSPOT_Y_NUMBER
Number for hotspot y.
Definition SDL3pp_surface.h:2286
constexpr auto TONEMAP_OPERATOR_STRING
String for tonemap operator.
Definition SDL3pp_surface.h:2278
constexpr auto SDR_WHITE_POINT_FLOAT
Float for sdr white point.
Definition SDL3pp_surface.h:2272
constexpr auto HDR_HEADROOM_FLOAT
Float for hdr headroom.
Definition SDL3pp_surface.h:2275
constexpr auto HOTSPOT_X_NUMBER
Number for hotspot x.
Definition SDL3pp_surface.h:2283
constexpr auto ROTATION_FLOAT
Float for rotation.
Definition SDL3pp_surface.h:2293
Main include header for the SDL3pp library.
Sint32 narrowS32(T value)
Narrows to Sint32.
Definition SDL3pp_stdinc.h:6262
A structure that represents a color as RGBA components.
Definition SDL3pp_pixels.h:2121
The bits of this structure can be directly reinterpreted as a float-packed color which uses the PIXEL...
Definition SDL3pp_pixels.h:2294
Wrapper to be used as parameter to LoadFile_IO() and SaveFile_IO() and similar.
Definition SDL3pp_iostream.h:2243
IOStreamRef stream
The IOStream to read from or write to.
Definition SDL3pp_iostream.h:2244
bool closeio
Whether to close the IOStream after the operation.
Definition SDL3pp_iostream.h:2245
A set of indexed colors representing a palette.
Definition SDL3pp_pixels.h:2498
static Palette borrow(PaletteRaw resource)
Safely borrows the from PaletteRaw.
Definition SDL3pp_pixels.h:2551
The structure that defines a point (using integers).
Definition SDL3pp_rect.h:97
constexpr Point(const PointRaw &p={}) noexcept
Wraps Point.
Definition SDL3pp_rect.h:103
A rectangle, with the origin at the upper left (using integers).
Definition SDL3pp_rect.h:706
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:93
Base class to Surface.
Definition SDL3pp_surface.h:152
constexpr bool MustLock() const
Evaluates to true if the surface needs to be locked before access.
Definition SDL3pp_surface.h:177
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
A collection of pixels used in software blitting.
Definition SDL3pp_surface.h:1666
Surface & operator=(const Surface &other)
Assignment operator.
Definition SDL3pp_surface.h:1847
static Surface borrow(SurfaceRaw resource)
Safely borrows the from SurfaceRaw.
Definition SDL3pp_surface.h:1827
constexpr Surface & operator=(Surface &&other) noexcept
Assignment operator.
Definition SDL3pp_surface.h:1840
constexpr Surface(SurfaceRaw resource) noexcept
Constructs from raw Surface.
Definition SDL3pp_surface.h:1676
constexpr Surface(const Surface &other)
Copy constructor.
Definition SDL3pp_surface.h:1682
constexpr Surface(Surface &&other) noexcept
Move constructor.
Definition SDL3pp_surface.h:1688
~Surface()
Destructor.
Definition SDL3pp_surface.h:1837