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
34// Forward decl
35struct SurfaceLock;
36
37// Forward decl
38struct SurfaceBase;
39
40// Forward decl
41struct SurfaceRef;
42
43// Forward decl
44struct Surface;
45
53using SurfaceFlags = Uint32;
54
56 SDL_SURFACE_PREALLOCATED;
57
59 SDL_SURFACE_LOCK_NEEDED;
60
62 SDL_SURFACE_LOCKED;
63
67constexpr SurfaceFlags SURFACE_SIMD_ALIGNED = SDL_SURFACE_SIMD_ALIGNED;
68
74using ScaleMode = SDL_ScaleMode;
75
76#if SDL_VERSION_ATLEAST(3, 2, 10)
77
81constexpr ScaleMode SCALEMODE_INVALID = SDL_SCALEMODE_INVALID;
82
83#endif // SDL_VERSION_ATLEAST(3, 2, 10)
84
86 SDL_SCALEMODE_NEAREST;
87
89 SDL_SCALEMODE_LINEAR;
90
96using FlipMode = SDL_FlipMode;
97
98constexpr FlipMode FLIP_NONE = SDL_FLIP_NONE;
99
100constexpr FlipMode FLIP_HORIZONTAL = SDL_FLIP_HORIZONTAL;
101
102constexpr FlipMode FLIP_VERTICAL = SDL_FLIP_VERTICAL;
103
137struct SurfaceBase : Resource<SDL_Surface*>
138{
139 using Resource::Resource;
140
155
170
185 SurfaceBase(const SDL_Point& size, PixelFormat format)
186 : Resource(CheckError(SDL_CreateSurface(size.x, size.y, format)))
187 {
188 }
189
214 SurfaceBase(const SDL_Point& size,
215 PixelFormat format,
216 void* pixels,
217 int pitch)
219 SDL_CreateSurfaceFrom(size.x, size.y, format, pixels, pitch)))
220 {
221 }
222
249 {
250 return PropertiesRef{SDL_GetSurfaceProperties(get())};
251 }
252
268 void SetColorspace(Colorspace colorspace)
269 {
270 CheckError(SDL_SetSurfaceColorspace(get(), colorspace));
271 }
272
283 Colorspace GetColorspace() const { return SDL_GetSurfaceColorspace(get()); }
284
310 PaletteRef CreatePalette() { return SDL_CreateSurfacePalette(get()); }
311
327 void SetPalette(PaletteBase& palette)
328 {
329 CheckError(SDL_SetSurfacePalette(get(), palette.get()));
330 }
331
338 PaletteRef GetPalette() const { return SDL_GetSurfacePalette(get()); }
339
364 {
365 CheckError(SDL_AddSurfaceAlternateImage(get(), image.get()));
366 }
367
380 {
381 return SDL_SurfaceHasAlternateImages(get());
382 }
383
403 {
404 int count = 0;
405 auto data =
406 reinterpret_cast<SurfaceRef*>(SDL_GetSurfaceImages(get(), &count));
407 return OwnArray<SurfaceRef>{data, size_t(count)};
408 }
409
422 void RemoveAlternateImages() { SDL_RemoveSurfaceAlternateImages(get()); }
423
429 constexpr bool MustLock() const { return SDL_MUSTLOCK(get()); }
430
454 SurfaceLock Lock() &;
455
473 void SetRLE(bool enabled) { CheckError(SDL_SetSurfaceRLE(get(), enabled)); }
474
480 bool HasRLE() const { return SDL_SurfaceHasRLE(get()); }
481
502
524 void SetColorKey(std::optional<Uint32> key)
525 {
526 CheckError(SDL_SetSurfaceColorKey(get(), key.has_value(), key.value_or(0)));
527 }
528
538 void ClearColorKey() { CheckError(SDL_SetSurfaceColorKey(get(), false, 0)); }
539
545 bool HasColorKey() const { return SDL_SurfaceHasColorKey(get()); }
546
565 {
566 Color color;
567 GetColorKey(&color);
568 return color;
569 }
570
589 void GetColorKey(Color* key) const
590 {
591 Uint32 color;
592 GetColorKey(&color);
593 *key = GetFormat().Get(color, GetPalette());
594 }
595
614 void GetColorKey(Uint32* key) const
615 {
616 CheckError(SDL_GetSurfaceColorKey(get(), key));
617 }
618
640 void SetColorMod(Uint8 r, Uint8 g, Uint8 b)
641 {
642 CheckError(SDL_SetSurfaceColorMod(get(), r, g, b));
643 }
644
660 void GetColorMod(Uint8* r, Uint8* g, Uint8* b) const
661 {
662 CheckError(SDL_GetSurfaceColorMod(get(), r, g, b));
663 }
664
683 void SetAlphaMod(Uint8 alpha)
684 {
685 CheckError(SDL_SetSurfaceAlphaMod(get(), alpha));
686 }
687
700 Uint8 GetAlphaMod() const
701 {
702 Uint8 alpha;
703 CheckError(SDL_GetSurfaceAlphaMod(get(), &alpha));
704 return alpha;
705 }
706
721 void SetMod(Color color)
722 {
723 SetColorMod(color.r, color.g, color.b);
724 SetAlphaMod(color.a);
725 }
726
734 Color GetMod() const
735 {
736 Color c;
737 GetColorMod(&c.r, &c.g, &c.b);
738 c.a = GetAlphaMod();
739 return c;
740 }
741
758 void SetBlendMode(BlendMode blendMode)
759 {
760 CheckError(SDL_SetSurfaceBlendMode(get(), blendMode));
761 }
762
770 {
771 if (BlendMode blendMode; SDL_GetSurfaceBlendMode(get(), &blendMode)) {
772 return blendMode;
773 }
774 return BLENDMODE_INVALID;
775 }
776
796 {
797 return SDL_SetSurfaceClipRect(get(), rect);
798 }
799
805 void ResetClipRect() { SDL_SetSurfaceClipRect(get(), nullptr); }
806
818 {
819 if (Rect r; SDL_GetSurfaceClipRect(get(), &r)) return r;
820 return {};
821 }
822
833 void Flip(FlipMode flip) { CheckError(SDL_FlipSurface(get(), flip)); }
834
850 Surface Duplicate() const;
851
868 Surface Scale(int width, int height, ScaleMode scaleMode) const;
869
895 Surface Convert(PixelFormat format) const;
896
924 PaletteBase& palette,
925 Colorspace colorspace,
926 PropertiesBase& props) const;
927
941 void PremultiplyAlpha(bool linear)
942 {
943 CheckError(SDL_PremultiplySurfaceAlpha(get(), linear));
944 }
945
946 // TODO SDL_ConvertSurfaceAndColorspace
947
963 void Clear(SDL_FColor color)
964 {
965 CheckError(SDL_ClearSurface(get(), color.r, color.g, color.b, color.a));
966 }
967
978 void Fill(SDL_Color color) { return Fill(MapColor(color)); }
979
995 void Fill(Uint32 color)
996 {
997 CheckError(SDL_FillSurfaceRect(get(), nullptr, color));
998 }
999
1017 void FillRect(const SDL_Rect& rect, SDL_Color color)
1018 {
1019 FillRect(rect, MapColor(color));
1020 }
1021
1044 void FillRect(const SDL_Rect& rect, Uint32 color)
1045 {
1046 CheckError(SDL_FillSurfaceRect(get(), &rect, color));
1047 }
1048
1066 void FillRects(SpanRef<const SDL_Rect> rects, SDL_Color color)
1067 {
1068 FillRects(rects, MapColor(color));
1069 }
1070
1093 void FillRects(SpanRef<const SDL_Rect> rects, Uint32 color)
1094 {
1095 SDL_assert_paranoid(rects.size() < SDL_MAX_UINT32);
1096 CheckError(SDL_FillSurfaceRects(get(), rects.data(), rects.size(), color));
1097 }
1098
1168 void Blit(const SurfaceBase& src,
1170 const SDL_Point& dstpos)
1171 {
1172 Blit(src, srcrect, Rect{dstpos, {}});
1173 }
1174
1247 void Blit(const SurfaceBase& src,
1250 {
1251 CheckError(SDL_BlitSurface(src.get(), srcrect, get(), dstrect));
1252 }
1253
1275 const SDL_Rect& srcrect,
1276 const SDL_Rect& dstrect)
1277 {
1278 CheckError(SDL_BlitSurfaceUnchecked(src.get(), &srcrect, get(), &dstrect));
1279 }
1280
1301 void BlitScaled(const SurfaceBase& src,
1304 ScaleMode scaleMode)
1305 {
1306 CheckError(
1307 SDL_BlitSurfaceScaled(src.get(), srcrect, get(), dstrect, scaleMode));
1308 }
1309
1332 const SDL_Rect& srcrect,
1333 const SDL_Rect& dstrect,
1334 ScaleMode scaleMode)
1335 {
1336 CheckError(
1337 SDL_BlitSurfaceScaled(src.get(), &srcrect, get(), &dstrect, scaleMode));
1338 }
1339
1340#if SDL_VERSION_ATLEAST(3, 2, 4)
1341
1360 void Stretch(const SurfaceBase& src,
1361 const SDL_Rect& srcrect,
1362 const SDL_Rect& dstrect,
1363 ScaleMode scaleMode)
1364 {
1365 CheckError(
1366 SDL_StretchSurface(src.get(), &srcrect, get(), &dstrect, scaleMode));
1367 }
1368
1369#endif // SDL_VERSION_ATLEAST(3, 2, 4)
1370
1393 void BlitTiled(const SurfaceBase& src,
1396 {
1397 CheckError(SDL_BlitSurfaceTiled(src.get(), srcrect, get(), dstrect));
1398 }
1399
1428 float scale,
1429 SDL_ScaleMode scaleMode,
1431 {
1432 CheckError(SDL_BlitSurfaceTiledWithScale(
1433 src.get(), srcrect, scale, scaleMode, get(), dstrect));
1434 }
1435
1466 void Blit9Grid(const SurfaceBase& src,
1468 int left_width,
1469 int right_width,
1470 int top_height,
1471 int bottom_height,
1473 {
1475 srcrect,
1476 left_width,
1477 right_width,
1478 top_height,
1479 bottom_height,
1480 0.0,
1481 SDL_SCALEMODE_NEAREST,
1482 dstrect);
1483 }
1484
1520 int left_width,
1521 int right_width,
1522 int top_height,
1523 int bottom_height,
1524 float scale,
1525 SDL_ScaleMode scaleMode,
1527 {
1528 CheckError(SDL_BlitSurface9Grid(src.get(),
1529 srcrect,
1530 left_width,
1531 right_width,
1532 top_height,
1533 bottom_height,
1534 scale,
1535 scaleMode,
1536 get(),
1537 dstrect));
1538 }
1539
1561 Uint32 MapColor(SDL_Color color) const
1562 {
1563 return MapColor(color.r, color.g, color.b, color.a);
1564 }
1565
1589 Uint32 MapColor(Uint8 r, Uint8 g, Uint8 b) const
1590 {
1591 return SDL_MapSurfaceRGB(get(), r, g, b);
1592 }
1593
1618 Uint32 MapColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a) const
1619 {
1620 return SDL_MapSurfaceRGBA(get(), r, g, b, a);
1621 }
1622
1636 Color ReadPixel(const SDL_Point& p) const
1637 {
1638 Color c;
1639 ReadPixel(p, &c);
1640 return c;
1641 }
1642
1657 void ReadPixel(const SDL_Point& p, SDL_Color* c) const
1658 {
1659 ReadPixel(p, &c->r, &c->g, &c->b, &c->a);
1660 }
1661
1675 void ReadPixel(const SDL_Point& p, SDL_FColor* c) const
1676 {
1677 return ReadPixel(p, &c->r, &c->g, &c->b, &c->a);
1678 }
1679
1704 void ReadPixel(const SDL_Point& p,
1705 Uint8* r,
1706 Uint8* g,
1707 Uint8* b,
1708 Uint8* a) const
1709 {
1710 CheckError(SDL_ReadSurfacePixel(get(), p.x, p.y, r, g, b, a));
1711 }
1712
1734 void ReadPixel(const SDL_Point& p,
1735 float* r,
1736 float* g,
1737 float* b,
1738 float* a) const
1739 {
1740 CheckError(SDL_ReadSurfacePixelFloat(get(), p.x, p.y, r, g, b, a));
1741 }
1742
1760 void WritePixel(const SDL_Point& p, SDL_Color c)
1761 {
1762 CheckError(SDL_WriteSurfacePixel(get(), p.x, p.y, c.r, c.g, c.b, c.a));
1763 }
1764
1779 void WritePixel(const SDL_Point& p, SDL_FColor c)
1780 {
1781 CheckError(SDL_WriteSurfacePixelFloat(get(), p.x, p.y, c.r, c.g, c.b, c.a));
1782 }
1783
1787 int GetWidth() const { return get()->w; }
1788
1792 int GetHeight() const { return get()->h; }
1793
1797 Point GetSize() const { return Point(GetWidth(), GetHeight()); }
1798
1802 PixelFormat GetFormat() const { return get()->format; }
1803};
1804
1814{
1816
1820 constexpr SurfaceRef(const SurfaceRef& other)
1821 : SurfaceBase(other.get())
1822 {
1823 }
1824
1828 constexpr SurfaceRef(SurfaceRef&& other)
1829 : SurfaceBase(other.release())
1830 {
1831 }
1832
1836 constexpr ~SurfaceRef() = default;
1837
1842 {
1843 release(other.release());
1844 return *this;
1845 }
1846
1858 void reset(SDL_Surface* newResource = {})
1859 {
1860 SDL_DestroySurface(release(newResource));
1861 }
1862};
1863
1873{
1875
1879 constexpr explicit Surface(SDL_Surface* resource = {})
1880 : SurfaceRef(resource)
1881 {
1882 }
1883
1884 constexpr Surface(const Surface& other) = delete;
1885
1889 constexpr Surface(Surface&& other) = default;
1890
1895
1900 {
1901 reset(other.release());
1902 return *this;
1903 }
1904};
1905
1912{
1913 SurfaceRef surface;
1914
1918 explicit SurfaceLock(SurfaceRef surface)
1919 : surface(std::move(surface))
1920 {
1921 if (!SDL_LockSurface(this->surface.get())) this->surface.reset();
1922 }
1923
1924public:
1925 // default ctor
1926 SurfaceLock()
1927 : surface(nullptr)
1928 {
1929 }
1930
1932 SurfaceLock(const SurfaceLock& other) = delete;
1933
1936 : surface(other.surface.release())
1937 {
1938 }
1939
1945
1948 {
1949 std::swap(surface, other.surface);
1950 return *this;
1951 }
1952
1956 constexpr operator bool() const { return bool(surface); }
1957
1965 void Unlock() { return SDL_UnlockSurface(surface.release()); }
1966
1970 void* GetPixels() const { return surface->pixels; }
1971
1975 int GetPitch() const { return surface->pitch; }
1976
1980 PixelFormat GetFormat() const { return surface->format; }
1981
1982 friend class SurfaceBase;
1983};
1984
1985namespace prop::Surface {
1986
1987constexpr auto SDR_WHITE_POINT_FLOAT = SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT;
1988
1989constexpr auto HDR_HEADROOM_FLOAT = SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT;
1990
1991constexpr auto TONEMAP_OPERATOR_STRING =
1992 SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING;
1993
1994constexpr auto HOTSPOT_X_NUMBER = SDL_PROP_SURFACE_HOTSPOT_X_NUMBER;
1995
1996constexpr auto HOTSPOT_Y_NUMBER = SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER;
1997
1998} // namespace prop::Surface
1999
2014{
2015 return Surface{SDL_LoadBMP_IO(src.get(), false)};
2016}
2017
2031inline Surface LoadBMP(StringParam file) { return Surface{SDL_LoadBMP(file)}; }
2032
2052inline void SaveBMP(SurfaceBase& surface, IOStreamBase& dst)
2053{
2054 CheckError(SDL_SaveBMP_IO(surface.get(), dst.get(), false));
2055}
2056
2076inline void SaveBMP(SurfaceBase& surface, StringParam file)
2077{
2078 CheckError(SDL_SaveBMP(surface.get(), file));
2079}
2080
2082{
2083 return Surface{SDL_DuplicateSurface(get())};
2084}
2085
2087 int height,
2088 ScaleMode scaleMode) const
2089{
2090 return Surface{SDL_ScaleSurface(get(), width, height, scaleMode)};
2091}
2092
2094{
2095 return Surface{SDL_ConvertSurface(get(), format)};
2096}
2097
2099 PaletteBase& palette,
2100 Colorspace colorspace,
2101 PropertiesBase& props) const
2102{
2103 return Surface{SDL_ConvertSurfaceAndColorspace(
2104 get(), format, palette.get(), colorspace, props.get())};
2105}
2106
2128inline void ConvertPixels(int width,
2129 int height,
2130 PixelFormat src_format,
2131 const void* src,
2132 int src_pitch,
2133 PixelFormat dst_format,
2134 void* dst,
2135 int dst_pitch)
2136{
2137 CheckError(SDL_ConvertPixels(
2138 width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch));
2139}
2140
2171inline void ConvertPixelsAndColorspace(int width,
2172 int height,
2173 PixelFormat src_format,
2174 Colorspace src_colorspace,
2175 PropertiesBase& src_properties,
2176 const void* src,
2177 int src_pitch,
2178 PixelFormat dst_format,
2179 Colorspace dst_colorspace,
2180 PropertiesBase& dst_properties,
2181 void* dst,
2182 int dst_pitch)
2183{
2184 CheckError(SDL_ConvertPixelsAndColorspace(width,
2185 height,
2186 src_format,
2187 src_colorspace,
2188 src_properties.get(),
2189 src,
2190 src_pitch,
2191 dst_format,
2192 dst_colorspace,
2193 dst_properties.get(),
2194 dst,
2195 dst_pitch));
2196}
2197
2221inline void PremultiplyAlpha(int width,
2222 int height,
2223 PixelFormat src_format,
2224 const void* src,
2225 int src_pitch,
2226 PixelFormat dst_format,
2227 void* dst,
2228 int dst_pitch,
2229 bool linear)
2230{
2231 CheckError(SDL_PremultiplyAlpha(width,
2232 height,
2233 src_format,
2234 src,
2235 src_pitch,
2236 dst_format,
2237 dst,
2238 dst_pitch,
2239 linear));
2240}
2241
2243
2244#pragma region impl
2245
2246inline SurfaceLock SurfaceBase::Lock() & { return SurfaceLock{get()}; }
2247
2248#pragma endregion impl
2249
2250} // namespace SDL
2251
2252#endif /* SDL3PP_SURFACE_H_ */
Colorspace definitions.
Definition SDL3pp_pixels.h:1301
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:374
Color Get(Uint32 pixel, PaletteRef palette) const
Get RGBA values from a pixel in the specified format.
Definition SDL3pp_pixels.h:2316
A SDL managed resource.
Definition SDL3pp_resource.h:17
constexpr SDL_Surface * release(SDL_Surface * newResource={})
Return contained resource and empties or replace value.
Definition SDL3pp_resource.h:60
constexpr Resource(T resource={})
Constructs the underlying resource.
Definition SDL3pp_resource.h:22
constexpr SDL_Surface * get() const
Return contained resource;.
Definition SDL3pp_resource.h:57
span-like for empty-derived structs
Definition SDL3pp_spanRef.h:24
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
Locks a Surface for access to its pixels.
Definition SDL3pp_surface.h:1912
void * GetPixels() const
Get the pixels.
Definition SDL3pp_surface.h:1970
~SurfaceLock()
destructor
Definition SDL3pp_surface.h:1944
int GetPitch() const
Get pitch (the number of bytes between the start of one row the next)
Definition SDL3pp_surface.h:1975
SurfaceLock & operator=(SurfaceLock other)
Assignment operator.
Definition SDL3pp_surface.h:1947
SurfaceLock(const SurfaceLock &other)=delete
Copy ctor.
void Unlock()
Release the locked surface after directly accessing the pixels.
Definition SDL3pp_surface.h:1965
PixelFormat GetFormat() const
Get the pixel format.
Definition SDL3pp_surface.h:1980
SurfaceLock(SurfaceLock &&other)
Move ctor.
Definition SDL3pp_surface.h:1935
#define SDL_assert_paranoid(condition)
An assertion test that is performed only when built with paranoid settings.
Definition SDL3pp_assert.h:374
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:75
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:206
Surface Convert(PixelFormat format) const
Copy an existing surface to a new surface of the specified format.
Definition SDL3pp_surface.h:2093
constexpr FlipMode FLIP_VERTICAL
flip vertically
Definition SDL3pp_surface.h:102
constexpr SurfaceFlags SURFACE_SIMD_ALIGNED
Surface uses pixel memory allocated with aligned_alloc()
Definition SDL3pp_surface.h:67
constexpr SurfaceFlags SURFACE_LOCK_NEEDED
Surface needs to be locked to access pixels.
Definition SDL3pp_surface.h:58
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:2128
constexpr FlipMode FLIP_NONE
Do not flip.
Definition SDL3pp_surface.h:98
constexpr SurfaceFlags SURFACE_PREALLOCATED
Surface uses preallocated pixel memory.
Definition SDL3pp_surface.h:55
Surface Duplicate() const
Creates a new surface identical to the existing surface.
Definition SDL3pp_surface.h:2081
constexpr ScaleMode SCALEMODE_LINEAR
linear filtering
Definition SDL3pp_surface.h:88
constexpr ScaleMode SCALEMODE_NEAREST
nearest pixel sampling
Definition SDL3pp_surface.h:85
constexpr SurfaceFlags SURFACE_LOCKED
Surface is currently locked.
Definition SDL3pp_surface.h:61
SDL_FlipMode FlipMode
The flip mode.
Definition SDL3pp_surface.h:96
constexpr ScaleMode SCALEMODE_INVALID
Definition SDL3pp_surface.h:81
void SaveBMP(SurfaceBase &surface, IOStreamBase &dst)
Save a surface to a seekable SDL data stream in BMP format.
Definition SDL3pp_surface.h:2052
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:2086
constexpr FlipMode FLIP_HORIZONTAL
flip horizontally
Definition SDL3pp_surface.h:100
void ConvertPixelsAndColorspace(int width, int height, PixelFormat src_format, Colorspace src_colorspace, PropertiesBase &src_properties, const void *src, int src_pitch, PixelFormat dst_format, Colorspace dst_colorspace, PropertiesBase &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:2171
Uint32 SurfaceFlags
The flags on an SurfaceBase.
Definition SDL3pp_surface.h:53
SDL_ScaleMode ScaleMode
The scaling mode.
Definition SDL3pp_surface.h:74
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:2221
Surface LoadBMP(IOStreamBase &src)
Load a BMP image from a seekable SDL data stream.
Definition SDL3pp_surface.h:2013
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:1621
The read/write operation structure.
Definition SDL3pp_iostream.h:107
A set of indexed colors representing a palette.
Definition SDL3pp_pixels.h:1954
Handle to a non owned palette.
Definition SDL3pp_pixels.h:2030
The structure that defines a point (using integers)
Definition SDL3pp_rect.h:41
Wrap properties id.
Definition SDL3pp_properties.h:203
Handle to a non owned properties.
Definition SDL3pp_properties.h:693
A rectangle, with the origin at the upper left (using integers).
Definition SDL3pp_rect.h:817
A collection of pixels used in software blitting.
Definition SDL3pp_surface.h:138
Point GetSize() const
Get the size in pixels.
Definition SDL3pp_surface.h:1797
void ClearColorKey()
Unset the color key (transparent pixel) in a surface.
Definition SDL3pp_surface.h:538
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:1618
void SetColorKey(Color key)
Set the color key (transparent pixel) in a surface.
Definition SDL3pp_surface.h:501
SurfaceBase(StringParam file)
Load an image from a filesystem path into a software surface.
Definition SDL3pp_image.h:2189
Colorspace GetColorspace() const
Get the colorspace used by a surface.
Definition SDL3pp_surface.h:283
void BlitScaled(const SurfaceBase &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:1301
Uint8 GetAlphaMod() const
Get the additional alpha value used in blit operations.
Definition SDL3pp_surface.h:700
int GetHeight() const
Get the height in pixels.
Definition SDL3pp_surface.h:1792
void RemoveAlternateImages()
Remove all alternate versions of a surface.
Definition SDL3pp_surface.h:422
Color GetMod() const
Get the additional color and alpha value multiplied into blit operations.
Definition SDL3pp_surface.h:734
void Blit(const SurfaceBase &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:1168
PaletteRef GetPalette() const
Get the palette used by a surface.
Definition SDL3pp_surface.h:338
void Clear(SDL_FColor color)
Clear a surface with a specific color, with floating point precision.
Definition SDL3pp_surface.h:963
void Fill(SDL_Color color)
Perform a fast fill of a rectangle with a specific color.
Definition SDL3pp_surface.h:978
void Fill(Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition SDL3pp_surface.h:995
void Blit9Grid(const SurfaceBase &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:1466
void SetRLE(bool enabled)
Set the RLE acceleration hint for a surface.
Definition SDL3pp_surface.h:473
bool HasColorKey() const
Returns whether the surface has a color key.
Definition SDL3pp_surface.h:545
PixelFormat GetFormat() const
Get the pixel format.
Definition SDL3pp_surface.h:1802
PropertiesRef GetProperties() const
Get the properties associated with a surface.
Definition SDL3pp_surface.h:248
bool HasRLE() const
Returns whether the surface is RLE enabled.
Definition SDL3pp_surface.h:480
void AddAlternateImage(SurfaceBase &image)
Add an alternate version of a surface.
Definition SDL3pp_surface.h:363
void GetColorMod(Uint8 *r, Uint8 *g, Uint8 *b) const
Get the additional color value multiplied into blit operations.
Definition SDL3pp_surface.h:660
void SetMod(Color color)
Set an additional color and alpha value multiplied into blit operations.
Definition SDL3pp_surface.h:721
Uint32 MapColor(SDL_Color color) const
Map an RGBA quadruple to a pixel value for a surface.
Definition SDL3pp_surface.h:1561
void ReadPixel(const SDL_Point &p, SDL_FColor *c) const
Retrieves a single pixel from a surface.
Definition SDL3pp_surface.h:1675
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:1093
void BlitTiledWithScale(const SurfaceBase &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:1426
OwnArray< SurfaceRef > GetImages() const
Get an array including all versions of a surface.
Definition SDL3pp_surface.h:402
void FillRect(const SDL_Rect &rect, Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition SDL3pp_surface.h:1044
void BlitUncheckedScaled(const SurfaceBase &src, const SDL_Rect &srcrect, const SDL_Rect &dstrect, ScaleMode scaleMode)
Perform low-level surface scaled blitting only.
Definition SDL3pp_surface.h:1331
Rect GetClipRect() const
Get the clipping rectangle for a surface.
Definition SDL3pp_surface.h:817
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:1734
void FillRect(const SDL_Rect &rect, SDL_Color color)
Perform a fast fill of a rectangle with a specific color.
Definition SDL3pp_surface.h:1017
void SetBlendMode(BlendMode blendMode)
Set the blend mode used for blit operations.
Definition SDL3pp_surface.h:758
SurfaceBase(const SDL_Point &size, PixelFormat format)
Allocate a new surface with a specific pixel format.
Definition SDL3pp_surface.h:185
void PremultiplyAlpha(bool linear)
Premultiply the alpha in a surface.
Definition SDL3pp_surface.h:941
void SetColorKey(std::optional< Uint32 > key)
Set the color key (transparent pixel) in a surface.
Definition SDL3pp_surface.h:524
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:1636
void BlitTiled(const SurfaceBase &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:1393
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:1066
void WritePixel(const SDL_Point &p, SDL_FColor c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:1779
bool HasAlternateImages() const
Return whether a surface has alternate versions available.
Definition SDL3pp_surface.h:379
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:1704
Color GetColorKey() const
Get the color key (transparent pixel) for a surface.
Definition SDL3pp_surface.h:564
void SetPalette(PaletteBase &palette)
Set the palette used by a surface.
Definition SDL3pp_surface.h:327
bool SetClipRect(OptionalRef< const SDL_Rect > rect)
Set the clipping rectangle for a surface.
Definition SDL3pp_surface.h:795
void GetColorKey(Color *key) const
Get the color key (transparent pixel) for a surface.
Definition SDL3pp_surface.h:589
void GetColorKey(Uint32 *key) const
Get the color key (transparent pixel) for a surface.
Definition SDL3pp_surface.h:614
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:1589
BlendMode GetBlendMode() const
Get the blend mode used for blit operations.
Definition SDL3pp_surface.h:769
constexpr bool MustLock() const
Evaluates to true if the surface needs to be locked before access.
Definition SDL3pp_surface.h:429
void SetColorspace(Colorspace colorspace)
Set the colorspace used by a surface.
Definition SDL3pp_surface.h:268
void SetAlphaMod(Uint8 alpha)
Set an additional alpha value used in blit operations.
Definition SDL3pp_surface.h:683
void BlitUnchecked(const SurfaceBase &src, const SDL_Rect &srcrect, const SDL_Rect &dstrect)
Perform low-level surface blitting only.
Definition SDL3pp_surface.h:1274
SurfaceBase(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:214
void SetColorMod(Uint8 r, Uint8 g, Uint8 b)
Set an additional color value multiplied into blit operations.
Definition SDL3pp_surface.h:640
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:1657
void Blit(const SurfaceBase &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:1247
void Blit9GridWithScale(const SurfaceBase &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:1518
int GetWidth() const
Get the width in pixels.
Definition SDL3pp_surface.h:1787
void Flip(FlipMode flip)
Flip a surface vertically or horizontally.
Definition SDL3pp_surface.h:833
void Stretch(const SurfaceBase &src, const SDL_Rect &srcrect, const SDL_Rect &dstrect, ScaleMode scaleMode)
Perform a stretched pixel copy from one surface to another.
Definition SDL3pp_surface.h:1360
PaletteRef CreatePalette()
Create a palette and associate it with a surface.
Definition SDL3pp_surface.h:310
SurfaceLock Lock() &
Set up a surface for directly accessing the pixels.
Definition SDL3pp_surface.h:2246
void WritePixel(const SDL_Point &p, SDL_Color c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:1760
void ResetClipRect()
Disable the clipping rectangle for a surface.
Definition SDL3pp_surface.h:805
Handle to a non owned surface.
Definition SDL3pp_surface.h:1814
constexpr SurfaceRef(SurfaceRef &&other)
Move constructor.
Definition SDL3pp_surface.h:1828
constexpr ~SurfaceRef()=default
Default constructor.
void reset(SDL_Surface *newResource={})
Free a surface.
Definition SDL3pp_surface.h:1858
constexpr SurfaceRef(const SurfaceRef &other)
Copy constructor.
Definition SDL3pp_surface.h:1820
SurfaceRef & operator=(SurfaceRef other)
Assignment operator.
Definition SDL3pp_surface.h:1841
Handle to an owned surface.
Definition SDL3pp_surface.h:1873
Surface & operator=(Surface other)
Assignment operator.
Definition SDL3pp_surface.h:1899
~Surface()
Frees up resource when object goes out of scope.
Definition SDL3pp_surface.h:1894
constexpr Surface(Surface &&other)=default
Move constructor.
constexpr Surface(SDL_Surface *resource={})
Constructs from the underlying resource.
Definition SDL3pp_surface.h:1879