SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL3pp_surface.h
1#ifndef SDL3PP_SURFACE_H_
2#define SDL3PP_SURFACE_H_
3
4#include <SDL3/SDL_surface.h>
5#include <SDL3/SDL_version.h>
6#include "SDL3pp_blendmode.h"
7#include "SDL3pp_iostream.h"
8#include "SDL3pp_pixels.h"
9#include "SDL3pp_properties.h"
10#include "SDL3pp_rect.h"
11#include "SDL3pp_stdinc.h"
12
13namespace SDL {
14
35// Forward decl
36struct SurfaceRef;
37
38// Forward decl
39struct Surface;
40
50
60
61// Forward decl
62struct SurfaceLock;
63
71using SurfaceFlags = Uint32;
72
74 SDL_SURFACE_PREALLOCATED;
75
77 SDL_SURFACE_LOCK_NEEDED;
78
80 SDL_SURFACE_LOCKED;
81
85constexpr SurfaceFlags SURFACE_SIMD_ALIGNED = SDL_SURFACE_SIMD_ALIGNED;
86
92using ScaleMode = SDL_ScaleMode;
93
94#if SDL_VERSION_ATLEAST(3, 2, 10)
95
96constexpr ScaleMode SCALEMODE_INVALID = SDL_SCALEMODE_INVALID;
97
98#endif // SDL_VERSION_ATLEAST(3, 2, 10)
99
101 SDL_SCALEMODE_NEAREST;
102
104 SDL_SCALEMODE_LINEAR;
105
111using FlipMode = SDL_FlipMode;
112
113constexpr FlipMode FLIP_NONE = SDL_FLIP_NONE;
114
115constexpr FlipMode FLIP_HORIZONTAL = SDL_FLIP_HORIZONTAL;
116
117constexpr FlipMode FLIP_VERTICAL = SDL_FLIP_VERTICAL;
118
152struct SurfaceRef : Resource<SDL_Surface*>
153{
154 using Resource::Resource;
155
188 {
189 return CheckError(SDL_GetSurfaceProperties(get()));
190 }
191
207 void SetColorspace(Colorspace colorspace)
208 {
209 CheckError(SDL_SetSurfaceColorspace(get(), colorspace));
210 }
211
228 Colorspace GetColorspace() const { return SDL_GetSurfaceColorspace(get()); }
229
257 {
258 return CheckError(SDL_CreateSurfacePalette(get()));
259 }
260
276 void SetPalette(PaletteRef palette)
277 {
278 CheckError(SDL_SetSurfacePalette(get(), palette.get()));
279 }
280
293 PaletteRef GetPalette() const { return SDL_GetSurfacePalette(get()); }
294
318 {
319 CheckError(SDL_AddSurfaceAlternateImage(get(), image.get()));
320 }
321
336 {
337 return SDL_SurfaceHasAlternateImages(get());
338 }
339
358 {
359 int count = 0;
360 auto data =
361 reinterpret_cast<SurfaceRef*>(SDL_GetSurfaceImages(get(), &count));
362 return OwnArray<SurfaceRef>{data, size_t(count)};
363 }
364
380 void RemoveAlternateImages() { SDL_RemoveSurfaceAlternateImages(get()); }
381
387 constexpr bool MustLock() const { return SDL_MUSTLOCK(get()); }
388
412 SurfaceLock Lock() &;
413
431 void SetRLE(bool enabled) { CheckError(SDL_SetSurfaceRLE(get(), enabled)); }
432
444 bool HasRLE() const { return SDL_SurfaceHasRLE(get()); }
445
466
488 void SetColorKey(std::optional<Uint32> key)
489 {
490 CheckError(SDL_SetSurfaceColorKey(get(), key.has_value(), key.value_or(0)));
491 }
492
502 void ClearColorKey() { CheckError(SDL_SetSurfaceColorKey(get(), false, 0)); }
503
516 bool HasColorKey() const { return SDL_SurfaceHasColorKey(get()); }
517
536 {
537 Color color;
538 GetColorKey(&color);
539 return color;
540 }
541
560 void GetColorKey(Color* key) const
561 {
562 Uint32 color;
563 GetColorKey(&color);
564 *key = GetFormat().Get(color, GetPalette());
565 }
566
585 void GetColorKey(Uint32* key) const
586 {
587 CheckError(SDL_GetSurfaceColorKey(get(), key));
588 }
589
611 void SetColorMod(Uint8 r, Uint8 g, Uint8 b)
612 {
613 CheckError(SDL_SetSurfaceColorMod(get(), r, g, b));
614 }
615
631 void GetColorMod(Uint8* r, Uint8* g, Uint8* b) const
632 {
633 CheckError(SDL_GetSurfaceColorMod(get(), r, g, b));
634 }
635
654 void SetAlphaMod(Uint8 alpha)
655 {
656 CheckError(SDL_SetSurfaceAlphaMod(get(), alpha));
657 }
658
671 Uint8 GetAlphaMod() const
672 {
673 Uint8 alpha;
674 CheckError(SDL_GetSurfaceAlphaMod(get(), &alpha));
675 return alpha;
676 }
677
692 void SetMod(Color color)
693 {
694 SetColorMod(color.r, color.g, color.b);
695 SetAlphaMod(color.a);
696 }
697
705 Color GetMod() const
706 {
707 Color c;
708 GetColorMod(&c.r, &c.g, &c.b);
709 c.a = GetAlphaMod();
710 return c;
711 }
712
729 void SetBlendMode(BlendMode blendMode)
730 {
731 CheckError(SDL_SetSurfaceBlendMode(get(), blendMode));
732 }
733
741 {
742 if (BlendMode blendMode; SDL_GetSurfaceBlendMode(get(), &blendMode)) {
743 return blendMode;
744 }
745 return BLENDMODE_INVALID;
746 }
747
770 {
771 return SDL_SetSurfaceClipRect(get(), rect);
772 }
773
779 void ResetClipRect() { SDL_SetSurfaceClipRect(get(), nullptr); }
780
798 {
799 Rect r;
800 CheckError(SDL_GetSurfaceClipRect(get(), &r));
801 return r;
802 }
803
814 void Flip(FlipMode flip) { CheckError(SDL_FlipSurface(get(), flip)); }
815
831 Surface Duplicate() const;
832
849 Surface Scale(int width, int height, ScaleMode scaleMode) const;
850
876 Surface Convert(PixelFormat format) const;
877
905 PaletteRef palette,
906 Colorspace colorspace,
907 PropertiesRef props) const;
908
922 void PremultiplyAlpha(bool linear)
923 {
924 CheckError(SDL_PremultiplySurfaceAlpha(get(), linear));
925 }
926
942 void Clear(SDL_FColor color)
943 {
944 CheckError(SDL_ClearSurface(get(), color.r, color.g, color.b, color.a));
945 }
946
957 void Fill(SDL_Color color) { return FillRect({}, color); }
958
974 void Fill(Uint32 color) { return FillRect({}, color); }
975
993 void FillRect(OptionalRef<const SDL_Rect> rect, SDL_Color color)
994 {
995 FillRect(rect, MapColor(color));
996 }
997
1020 void FillRect(OptionalRef<const SDL_Rect> rect, Uint32 color)
1021 {
1022 CheckError(SDL_FillSurfaceRect(get(), rect, color));
1023 }
1024
1042 void FillRects(SpanRef<const SDL_Rect> rects, SDL_Color color)
1043 {
1044 FillRects(rects, MapColor(color));
1045 }
1046
1069 void FillRects(SpanRef<const SDL_Rect> rects, Uint32 color)
1070 {
1071 SDL_assert_paranoid(rects.size() < SDL_MAX_UINT32);
1072 CheckError(SDL_FillSurfaceRects(get(), rects.data(), rects.size(), color));
1073 }
1074
1146 const SDL_Point& dstpos)
1147 {
1148 Blit(src, srcrect, Rect{dstpos, {}});
1149 }
1150
1223 {
1224 CheckError(SDL_BlitSurface(src.get(), srcrect, get(), dstrect));
1225 }
1226
1248 const SDL_Rect& srcrect,
1249 const SDL_Rect& dstrect)
1250 {
1251 CheckError(SDL_BlitSurfaceUnchecked(src.get(), &srcrect, get(), &dstrect));
1252 }
1253
1277 ScaleMode scaleMode)
1278 {
1279 CheckError(
1280 SDL_BlitSurfaceScaled(src.get(), srcrect, get(), dstrect, scaleMode));
1281 }
1282
1305 const SDL_Rect& srcrect,
1306 const SDL_Rect& dstrect,
1307 ScaleMode scaleMode)
1308 {
1309 CheckError(
1310 SDL_BlitSurfaceScaled(src.get(), &srcrect, get(), &dstrect, scaleMode));
1311 }
1312
1313#if SDL_VERSION_ATLEAST(3, 2, 4)
1314
1334 OptionalRef<SDL_Rect> srcrect,
1335 OptionalRef<SDL_Rect> dstrect,
1336 ScaleMode scaleMode)
1337 {
1338 CheckError(
1339 SDL_StretchSurface(src.get(), srcrect, get(), dstrect, scaleMode));
1340 }
1341
1342#endif // SDL_VERSION_ATLEAST(3, 2, 4)
1343
1369 {
1370 CheckError(SDL_BlitSurfaceTiled(src.get(), srcrect, get(), dstrect));
1371 }
1372
1401 float scale,
1402 SDL_ScaleMode scaleMode,
1404 {
1405 CheckError(SDL_BlitSurfaceTiledWithScale(
1406 src.get(), srcrect, scale, scaleMode, get(), dstrect));
1407 }
1408
1441 int left_width,
1442 int right_width,
1443 int top_height,
1444 int bottom_height,
1446 {
1448 srcrect,
1449 left_width,
1450 right_width,
1451 top_height,
1452 bottom_height,
1453 0.0,
1454 SDL_SCALEMODE_NEAREST,
1455 dstrect);
1456 }
1457
1493 int left_width,
1494 int right_width,
1495 int top_height,
1496 int bottom_height,
1497 float scale,
1498 SDL_ScaleMode scaleMode,
1500 {
1501 CheckError(SDL_BlitSurface9Grid(src.get(),
1502 srcrect,
1503 left_width,
1504 right_width,
1505 top_height,
1506 bottom_height,
1507 scale,
1508 scaleMode,
1509 get(),
1510 dstrect));
1511 }
1512
1534 Uint32 MapColor(SDL_Color color) const
1535 {
1536 return MapColor(color.r, color.g, color.b, color.a);
1537 }
1538
1568 Uint32 MapColor(Uint8 r, Uint8 g, Uint8 b) const
1569 {
1570 return SDL_MapSurfaceRGB(get(), r, g, b);
1571 }
1572
1603 Uint32 MapColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a) const
1604 {
1605 return SDL_MapSurfaceRGBA(get(), r, g, b, a);
1606 }
1607
1621 Color ReadPixel(const SDL_Point& p) const
1622 {
1623 Color c;
1624 ReadPixel(p, &c);
1625 return c;
1626 }
1627
1642 void ReadPixel(const SDL_Point& p, SDL_Color* c) const
1643 {
1644 ReadPixel(p, &c->r, &c->g, &c->b, &c->a);
1645 }
1646
1660 void ReadPixel(const SDL_Point& p, SDL_FColor* c) const
1661 {
1662 return ReadPixel(p, &c->r, &c->g, &c->b, &c->a);
1663 }
1664
1689 void ReadPixel(const SDL_Point& p,
1690 Uint8* r,
1691 Uint8* g,
1692 Uint8* b,
1693 Uint8* a) const
1694 {
1695 CheckError(SDL_ReadSurfacePixel(get(), p.x, p.y, r, g, b, a));
1696 }
1697
1719 void ReadPixel(const SDL_Point& p,
1720 float* r,
1721 float* g,
1722 float* b,
1723 float* a) const
1724 {
1725 CheckError(SDL_ReadSurfacePixelFloat(get(), p.x, p.y, r, g, b, a));
1726 }
1727
1745 void WritePixel(const SDL_Point& p, SDL_Color c)
1746 {
1747 CheckError(SDL_WriteSurfacePixel(get(), p.x, p.y, c.r, c.g, c.b, c.a));
1748 }
1749
1764 void WritePixel(const SDL_Point& p, SDL_FColor c)
1765 {
1766 CheckError(SDL_WriteSurfacePixelFloat(get(), p.x, p.y, c.r, c.g, c.b, c.a));
1767 }
1768
1772 constexpr int GetWidth() const { return get()->w; }
1773
1777 constexpr int GetHeight() const { return get()->h; }
1778
1782 constexpr Point GetSize() const { return Point(GetWidth(), GetHeight()); }
1783
1787 constexpr int GetPitch() const { return get()->pitch; }
1788
1792 constexpr PixelFormat GetFormat() const { return get()->format; }
1793
1797 constexpr void* GetPixels() const { return get()->pixels; }
1798
1813 static void reset(SDL_Surface* resource) { SDL_DestroySurface(resource); }
1814};
1815
1823struct Surface : ResourceUnique<SurfaceRef>
1824{
1826
1840 static Surface Load(StringParam file);
1841
1855 static Surface Load(IOStreamRef src);
1856
1876 {
1877 return Surface(SDL_LoadBMP_IO(src, false));
1878 }
1879
1899 {
1900 return Surface(SDL_LoadBMP(file));
1901 }
1902
1920 static Surface Create(const SDL_Point& size, PixelFormat format)
1921 {
1922 return Surface(CheckError(SDL_CreateSurface(size.x, size.y, format)));
1923 }
1924
1952 static Surface CreateFrom(const SDL_Point& size,
1953 PixelFormat format,
1954 void* pixels,
1955 int pitch)
1956 {
1957 return Surface(
1958 CheckError(SDL_CreateSurfaceFrom(size.x, size.y, format, pixels, pitch)));
1959 }
1960
1974 void Destroy() { reset(); }
1979};
1980
1982{
1983 return SurfaceShared(std::move(*this));
1984}
1985
1995struct SurfaceUnsafe : ResourceUnsafe<SurfaceRef>
1996{
1998
2002 constexpr explicit SurfaceUnsafe(Surface&& other)
2003 : SurfaceUnsafe(other.release())
2004 {
2005 }
2006};
2007
2013struct SurfaceLock : LockBase<SurfaceRef>
2014{
2018 constexpr SurfaceLock() = default;
2019
2023 constexpr SurfaceLock(SurfaceLock&& other)
2024 : LockBase(other.release())
2025 {
2026 }
2027
2053 : LockBase<SurfaceRef>(std::move(surface))
2054 {
2055 if (!SDL_LockSurface(get())) release();
2056 }
2057
2064
2076 void Unlock() { SDL_UnlockSurface(release()); }
2077
2081 void reset() { Unlock(); }
2082};
2083
2084namespace prop::Surface {
2085
2086constexpr auto SDR_WHITE_POINT_FLOAT = SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT;
2087
2088constexpr auto HDR_HEADROOM_FLOAT = SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT;
2089
2090constexpr auto TONEMAP_OPERATOR_STRING =
2091 SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING;
2092
2093#if SDL_VERSION_ATLEAST(3, 2, 6)
2094
2095constexpr auto HOTSPOT_X_NUMBER = SDL_PROP_SURFACE_HOTSPOT_X_NUMBER;
2096
2097constexpr auto HOTSPOT_Y_NUMBER = SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER;
2098
2099#endif // SDL_VERSION_ATLEAST(3, 2, 6)
2100
2101} // namespace prop::Surface
2102
2103inline SurfaceLock SurfaceRef::Lock() & { return SurfaceLock{get()}; }
2104
2125inline void SaveBMP(SurfaceRef surface, IOStreamRef dst)
2126{
2127 CheckError(SDL_SaveBMP_IO(surface.get(), dst.get(), false));
2128}
2129
2150inline void SaveBMP(SurfaceRef surface, StringParam file)
2151{
2152 CheckError(SDL_SaveBMP(surface.get(), file));
2153}
2154
2156{
2157 return Surface{SDL_DuplicateSurface(get())};
2158}
2159
2161 int height,
2162 ScaleMode scaleMode) const
2163{
2164 return Surface{SDL_ScaleSurface(get(), width, height, scaleMode)};
2165}
2166
2168{
2169 return Surface{SDL_ConvertSurface(get(), format)};
2170}
2171
2173 PaletteRef palette,
2174 Colorspace colorspace,
2175 PropertiesRef props) const
2176{
2177 return Surface{SDL_ConvertSurfaceAndColorspace(
2178 get(), format, palette.get(), colorspace, props.get())};
2179}
2180
2202inline void ConvertPixels(int width,
2203 int height,
2204 PixelFormat src_format,
2205 const void* src,
2206 int src_pitch,
2207 PixelFormat dst_format,
2208 void* dst,
2209 int dst_pitch)
2210{
2211 CheckError(SDL_ConvertPixels(
2212 width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch));
2213}
2214
2245inline void ConvertPixelsAndColorspace(int width,
2246 int height,
2247 PixelFormat src_format,
2248 Colorspace src_colorspace,
2249 PropertiesRef src_properties,
2250 const void* src,
2251 int src_pitch,
2252 PixelFormat dst_format,
2253 Colorspace dst_colorspace,
2254 PropertiesRef dst_properties,
2255 void* dst,
2256 int dst_pitch)
2257{
2258 CheckError(SDL_ConvertPixelsAndColorspace(width,
2259 height,
2260 src_format,
2261 src_colorspace,
2262 src_properties.get(),
2263 src,
2264 src_pitch,
2265 dst_format,
2266 dst_colorspace,
2267 dst_properties.get(),
2268 dst,
2269 dst_pitch));
2270}
2271
2295inline void PremultiplyAlpha(int width,
2296 int height,
2297 PixelFormat src_format,
2298 const void* src,
2299 int src_pitch,
2300 PixelFormat dst_format,
2301 void* dst,
2302 int dst_pitch,
2303 bool linear)
2304{
2305 CheckError(SDL_PremultiplyAlpha(width,
2306 height,
2307 src_format,
2308 src,
2309 src_pitch,
2310 dst_format,
2311 dst,
2312 dst_pitch,
2313 linear));
2314}
2315
2317
2318} // namespace SDL
2319
2320#endif /* SDL3PP_SURFACE_H_ */
Colorspace definitions.
Definition SDL3pp_pixels.h:1318
Base class for locks.
Definition SDL3pp_resource.h:408
Optional-like shim for references.
Definition SDL3pp_optionalRef.h:20
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:43
Pixel format.
Definition SDL3pp_pixels.h:391
Color Get(Uint32 pixel, PaletteRef palette) const
Get RGBA values from a pixel in the specified format.
Definition SDL3pp_pixels.h:2282
RESOURCE release()
Returns reference and reset this.
Definition SDL3pp_resource.h:178
reference & get()
Get reference.
Definition SDL3pp_resource.h:120
Implement shared ownership for a resource.
Definition SDL3pp_resource.h:283
Implement unique ownership for a resource.
Definition SDL3pp_resource.h:226
constexpr ResourceUnique(std::nullptr_t=nullptr)
Default constructor.
Definition SDL3pp_resource.h:231
void reset()
Resets the value, destroying the resource if not nullptr.
Definition SDL3pp_resource.h:265
A dumb pointer to resource.
Definition SDL3pp_resource.h:197
constexpr ResourceUnsafe()=default
Default constructor.
Implement weak ownership for a resource.
Definition SDL3pp_resource.h:328
A SDL managed resource.
Definition SDL3pp_resource.h:29
constexpr Resource(T resource={})
Constructs from the underlying resource.
Definition SDL3pp_resource.h:37
constexpr SDL_Surface * get() const
Return contained resource;.
Definition SDL3pp_resource.h:76
span-like for empty-derived structs
Definition SDL3pp_spanRef.h:24
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
#define SDL_assert_paranoid(condition)
An assertion test that is performed only when built with paranoid settings.
Definition SDL3pp_assert.h:364
Uint32 BlendMode
A set of blend modes used in drawing operations.
Definition SDL3pp_blendmode.h:35
constexpr BlendMode BLENDMODE_INVALID
INVALID.
Definition SDL3pp_blendmode.h:73
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:206
constexpr FlipMode FLIP_VERTICAL
flip vertically
Definition SDL3pp_surface.h:117
constexpr SurfaceFlags SURFACE_SIMD_ALIGNED
Surface uses pixel memory allocated with aligned_alloc()
Definition SDL3pp_surface.h:85
constexpr SurfaceFlags SURFACE_LOCK_NEEDED
Surface needs to be locked to access pixels.
Definition SDL3pp_surface.h:76
void ConvertPixels(int width, int height, 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:2202
void SaveBMP(SurfaceRef surface, IOStreamRef dst)
Save a surface to a seekable SDL data stream in BMP format.
Definition SDL3pp_surface.h:2125
Surface Convert(PixelFormat format) const
Copy an existing surface to a new surface of the specified format.
Definition SDL3pp_surface.h:2167
SurfaceLock Lock() &
Set up a surface for directly accessing the pixels.
Definition SDL3pp_surface.h:2103
constexpr FlipMode FLIP_NONE
Do not flip.
Definition SDL3pp_surface.h:113
constexpr SurfaceFlags SURFACE_PREALLOCATED
Surface uses preallocated pixel memory.
Definition SDL3pp_surface.h:73
ResourceShared< Surface > SurfaceShared
Handle to a shared surface.
Definition SDL3pp_surface.h:49
void ConvertPixelsAndColorspace(int width, int height, 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:2245
constexpr ScaleMode SCALEMODE_LINEAR
linear filtering
Definition SDL3pp_surface.h:103
Surface Duplicate() const
Creates a new surface identical to the existing surface.
Definition SDL3pp_surface.h:2155
constexpr ScaleMode SCALEMODE_NEAREST
nearest pixel sampling
Definition SDL3pp_surface.h:100
constexpr SurfaceFlags SURFACE_LOCKED
Surface is currently locked.
Definition SDL3pp_surface.h:79
SurfaceShared share()
Move this surface into a SurfaceShared.
Definition SDL3pp_surface.h:1981
SDL_FlipMode FlipMode
The flip mode.
Definition SDL3pp_surface.h:111
constexpr ScaleMode SCALEMODE_INVALID
INVALID.
Definition SDL3pp_surface.h:96
constexpr FlipMode FLIP_HORIZONTAL
flip horizontally
Definition SDL3pp_surface.h:115
Uint32 SurfaceFlags
The flags on an Surface.
Definition SDL3pp_surface.h:71
SDL_ScaleMode ScaleMode
The scaling mode.
Definition SDL3pp_surface.h:92
void PremultiplyAlpha(int width, int height, 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:2295
Surface Scale(int width, int height, ScaleMode scaleMode) const
Creates a new surface identical to the existing surface, scaled to the desired size.
Definition SDL3pp_surface.h:2160
the main namespace where all SDL3pp public functions and types live
Definition SDL3pp_assert.h:7
A structure that represents a color as RGBA components.
Definition SDL3pp_pixels.h:1638
The read/write operation structure.
Definition SDL3pp_iostream.h:123
A set of indexed colors representing a palette.
Definition SDL3pp_pixels.h:1971
The structure that defines a point (using integers).
Definition SDL3pp_rect.h:46
SDL properties ID.
Definition SDL3pp_properties.h:209
A rectangle, with the origin at the upper left (using integers).
Definition SDL3pp_rect.h:833
Locks a Surface.
Definition SDL3pp_surface.h:2014
~SurfaceLock()
Destructor.
Definition SDL3pp_surface.h:2063
SurfaceLock(SurfaceRef surface)
Set up a surface for directly accessing the pixels.
Definition SDL3pp_surface.h:2052
void reset()
Same as Unlock(), just for uniformity.
Definition SDL3pp_surface.h:2081
constexpr SurfaceLock(SurfaceLock &&other)
Move constructor.
Definition SDL3pp_surface.h:2023
constexpr SurfaceLock()=default
Creates an empty lock.
void Unlock()
Release a surface after directly accessing the pixels.
Definition SDL3pp_surface.h:2076
A collection of pixels used in software blitting.
Definition SDL3pp_surface.h:153
void WritePixel(const SDL_Point &p, SDL_Color c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:1745
constexpr Point GetSize() const
Get the size in pixels.
Definition SDL3pp_surface.h:1782
void ReadPixel(const SDL_Point &p, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a) const
Retrieves a single pixel from a surface.
Definition SDL3pp_surface.h:1689
bool HasColorKey() const
Returns whether the surface has a color key.
Definition SDL3pp_surface.h:516
void ReadPixel(const SDL_Point &p, SDL_Color *c) const
This function prioritizes correctness over speed: it is suitable for unit tests, but is not intended ...
Definition SDL3pp_surface.h:1642
void SetColorKey(Color key)
Set the color key (transparent pixel) in a surface.
Definition SDL3pp_surface.h:465
void FillRect(OptionalRef< const SDL_Rect > rect, Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition SDL3pp_surface.h:1020
static void reset(SDL_Surface *resource)
Free a surface.
Definition SDL3pp_surface.h:1813
void Flip(FlipMode flip)
Flip a surface vertically or horizontally.
Definition SDL3pp_surface.h:814
void Blit9GridWithScale(SurfaceRef src, OptionalRef< const SDL_Rect > srcrect, int left_width, int right_width, int top_height, int bottom_height, float scale, SDL_ScaleMode scaleMode, OptionalRef< const SDL_Rect > dstrect)
Perform a scaled blit using the 9-grid algorithm to a destination surface, which may be of a differen...
Definition SDL3pp_surface.h:1491
void WritePixel(const SDL_Point &p, SDL_FColor c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:1764
void RemoveAlternateImages()
Remove all alternate versions of a surface.
Definition SDL3pp_surface.h:380
void BlitScaled(SurfaceRef src, OptionalRef< const SDL_Rect > srcrect, OptionalRef< const SDL_Rect > dstrect, ScaleMode scaleMode)
Perform a scaled blit to a destination surface, which may be of a different format.
Definition SDL3pp_surface.h:1274
void ReadPixel(const SDL_Point &p, float *r, float *g, float *b, float *a) const
Retrieves a single pixel from a surface.
Definition SDL3pp_surface.h:1719
constexpr void * GetPixels() const
Get the pixels.
Definition SDL3pp_surface.h:1797
void Blit(SurfaceRef src, OptionalRef< const SDL_Rect > srcrect, OptionalRef< const SDL_Rect > dstrect)
Performs a fast blit from the source surface to the destination surface with clipping.
Definition SDL3pp_surface.h:1220
Uint32 MapColor(Uint8 r, Uint8 g, Uint8 b) const
Map an RGB triple to an opaque pixel value for a surface.
Definition SDL3pp_surface.h:1568
void Blit(SurfaceRef src, OptionalRef< const SDL_Rect > srcrect, const SDL_Point &dstpos)
Performs a fast blit from the source surface to the destination surface with clipping.
Definition SDL3pp_surface.h:1144
void GetColorMod(Uint8 *r, Uint8 *g, Uint8 *b) const
Get the additional color value multiplied into blit operations.
Definition SDL3pp_surface.h:631
constexpr bool MustLock() const
Evaluates to true if the surface needs to be locked before access.
Definition SDL3pp_surface.h:387
BlendMode GetBlendMode() const
Get the blend mode used for blit operations.
Definition SDL3pp_surface.h:740
PaletteRef CreatePalette()
Create a palette and associate it with a surface.
Definition SDL3pp_surface.h:256
void SetRLE(bool enabled)
Set the RLE acceleration hint for a surface.
Definition SDL3pp_surface.h:431
void FillRects(SpanRef< const SDL_Rect > rects, SDL_Color color)
Perform a fast fill of a set of rectangles with a specific color.
Definition SDL3pp_surface.h:1042
Color ReadPixel(const SDL_Point &p) const
This function prioritizes correctness over speed: it is suitable for unit tests, but is not intended ...
Definition SDL3pp_surface.h:1621
void BlitUncheckedScaled(SurfaceRef src, const SDL_Rect &srcrect, const SDL_Rect &dstrect, ScaleMode scaleMode)
Perform low-level surface scaled blitting only.
Definition SDL3pp_surface.h:1304
void Blit9Grid(SurfaceRef src, OptionalRef< const SDL_Rect > srcrect, int left_width, int right_width, int top_height, int bottom_height, OptionalRef< const SDL_Rect > dstrect)
Perform a scaled blit using the 9-grid algorithm to a destination surface, which may be of a differen...
Definition SDL3pp_surface.h:1439
constexpr PixelFormat GetFormat() const
Get the pixel format.
Definition SDL3pp_surface.h:1792
void BlitTiled(SurfaceRef src, OptionalRef< const SDL_Rect > srcrect, OptionalRef< const SDL_Rect > dstrect)
Perform a tiled blit to a destination surface, which may be of a different format.
Definition SDL3pp_surface.h:1366
Colorspace GetColorspace() const
Get the colorspace used by a surface.
Definition SDL3pp_surface.h:228
bool SetClipRect(OptionalRef< const SDL_Rect > rect)
Set the clipping rectangle for a surface.
Definition SDL3pp_surface.h:769
PropertiesRef GetProperties() const
Get the properties associated with a surface.
Definition SDL3pp_surface.h:187
bool HasAlternateImages() const
Return whether a surface has alternate versions available.
Definition SDL3pp_surface.h:335
Uint32 MapColor(SDL_Color color) const
Map an RGBA quadruple to a pixel value for a surface.
Definition SDL3pp_surface.h:1534
constexpr int GetHeight() const
Get the height in pixels.
Definition SDL3pp_surface.h:1777
Color GetColorKey() const
Get the color key (transparent pixel) for a surface.
Definition SDL3pp_surface.h:535
void SetColorMod(Uint8 r, Uint8 g, Uint8 b)
Set an additional color value multiplied into blit operations.
Definition SDL3pp_surface.h:611
void FillRect(OptionalRef< const SDL_Rect > rect, SDL_Color color)
Perform a fast fill of a rectangle with a specific color.
Definition SDL3pp_surface.h:993
void SetAlphaMod(Uint8 alpha)
Set an additional alpha value used in blit operations.
Definition SDL3pp_surface.h:654
PaletteRef GetPalette() const
Get the palette used by a surface.
Definition SDL3pp_surface.h:293
void PremultiplyAlpha(bool linear)
Premultiply the alpha in a surface.
Definition SDL3pp_surface.h:922
void ResetClipRect()
Disable the clipping rectangle for a surface.
Definition SDL3pp_surface.h:779
Uint8 GetAlphaMod() const
Get the additional alpha value used in blit operations.
Definition SDL3pp_surface.h:671
void SetMod(Color color)
Set an additional color and alpha value multiplied into blit operations.
Definition SDL3pp_surface.h:692
bool HasRLE() const
Returns whether the surface is RLE enabled.
Definition SDL3pp_surface.h:444
void ReadPixel(const SDL_Point &p, SDL_FColor *c) const
Retrieves a single pixel from a surface.
Definition SDL3pp_surface.h:1660
constexpr int GetPitch() const
Get pitch in bytes.
Definition SDL3pp_surface.h:1787
Color GetMod() const
Get the additional color and alpha value multiplied into blit operations.
Definition SDL3pp_surface.h:705
Rect GetClipRect() const
Get the clipping rectangle for a surface.
Definition SDL3pp_surface.h:797
void Stretch(SurfaceRef src, OptionalRef< SDL_Rect > srcrect, OptionalRef< SDL_Rect > dstrect, ScaleMode scaleMode)
Perform a stretched pixel copy from one surface to another.
Definition SDL3pp_surface.h:1333
void AddAlternateImage(SurfaceRef image)
Add an alternate version of a surface.
Definition SDL3pp_surface.h:317
void GetColorKey(Color *key) const
Get the color key (transparent pixel) for a surface.
Definition SDL3pp_surface.h:560
void Clear(SDL_FColor color)
Clear a surface with a specific color, with floating point precision.
Definition SDL3pp_surface.h:942
void SetPalette(PaletteRef palette)
Set the palette used by a surface.
Definition SDL3pp_surface.h:276
void Fill(SDL_Color color)
Perform a fast fill of a rectangle with a specific color.
Definition SDL3pp_surface.h:957
void BlitUnchecked(SurfaceRef src, const SDL_Rect &srcrect, const SDL_Rect &dstrect)
Perform low-level surface blitting only.
Definition SDL3pp_surface.h:1247
OwnArray< SurfaceRef > GetImages() const
Get an array including all versions of a surface.
Definition SDL3pp_surface.h:357
void BlitTiledWithScale(SurfaceRef src, OptionalRef< const SDL_Rect > srcrect, float scale, SDL_ScaleMode scaleMode, OptionalRef< const SDL_Rect > dstrect)
Perform a scaled and tiled blit to a destination surface, which may be of a different format.
Definition SDL3pp_surface.h:1399
void FillRects(SpanRef< const SDL_Rect > rects, Uint32 color)
Perform a fast fill of a set of rectangles with a specific color.
Definition SDL3pp_surface.h:1069
Uint32 MapColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a) const
Map an RGBA quadruple to a pixel value for a surface.
Definition SDL3pp_surface.h:1603
void Fill(Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition SDL3pp_surface.h:974
void SetBlendMode(BlendMode blendMode)
Set the blend mode used for blit operations.
Definition SDL3pp_surface.h:729
void SetColorspace(Colorspace colorspace)
Set the colorspace used by a surface.
Definition SDL3pp_surface.h:207
void GetColorKey(Uint32 *key) const
Get the color key (transparent pixel) for a surface.
Definition SDL3pp_surface.h:585
void SetColorKey(std::optional< Uint32 > key)
Set the color key (transparent pixel) in a surface.
Definition SDL3pp_surface.h:488
void ClearColorKey()
Unset the color key (transparent pixel) in a surface.
Definition SDL3pp_surface.h:502
constexpr int GetWidth() const
Get the width in pixels.
Definition SDL3pp_surface.h:1772
Unsafe Handle to surface.
Definition SDL3pp_surface.h:1996
constexpr SurfaceUnsafe(Surface &&other)
Constructs SurfaceUnsafe from Surface.
Definition SDL3pp_surface.h:2002
Handle to an owned surface.
Definition SDL3pp_surface.h:1824
static Surface LoadBMP(IOStreamRef src)
Load a BMP image from a seekable SDL data stream.
Definition SDL3pp_surface.h:1875
void Destroy()
Free a surface.
Definition SDL3pp_surface.h:1974
static Surface Create(const SDL_Point &size, PixelFormat format)
Allocate a new surface with a specific pixel format.
Definition SDL3pp_surface.h:1920
static Surface CreateFrom(const SDL_Point &size, PixelFormat format, void *pixels, int pitch)
Allocate a new surface with a specific pixel format and existing pixel data.
Definition SDL3pp_surface.h:1952
static Surface LoadBMP(StringParam file)
Load a BMP image from a file.
Definition SDL3pp_surface.h:1898
static Surface Load(StringParam file)
Load an image from a filesystem path into a software surface.
Definition SDL3pp_image.h:2217