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 "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"
15
16namespace SDL {
17
39
40// Forward decl
41struct SurfaceBase;
42
43// Forward decl
44struct Surface;
45
47using SurfaceRaw = SDL_Surface*;
48
50using SurfaceRawConst = const SDL_Surface*;
51
58
61
62// Forward decl
63struct SurfaceLock;
64
73
75 SDL_SURFACE_PREALLOCATED;
76
78 SDL_SURFACE_LOCK_NEEDED;
79
81 SDL_SURFACE_LOCKED;
82
84constexpr SurfaceFlags SURFACE_SIMD_ALIGNED = SDL_SURFACE_SIMD_ALIGNED;
85
91constexpr bool MustLock(SurfaceConstRef S)
92{
93 return SDL_MUSTLOCK((static_cast<SurfaceRawConst>(S)));
94}
95
101using ScaleMode = SDL_ScaleMode;
102
103#if SDL_VERSION_ATLEAST(3, 2, 10)
104
105constexpr ScaleMode SCALEMODE_INVALID = SDL_SCALEMODE_INVALID;
106
107#endif // SDL_VERSION_ATLEAST(3, 2, 10)
108
110 SDL_SCALEMODE_NEAREST;
111
113 SDL_SCALEMODE_LINEAR;
114
115#if SDL_VERSION_ATLEAST(3, 4, 0)
116
121constexpr ScaleMode SCALEMODE_PIXELART = SDL_SCALEMODE_PIXELART;
122
123#endif // SDL_VERSION_ATLEAST(3, 4, 0)
124
130using FlipMode = SDL_FlipMode;
131
132constexpr FlipMode FLIP_NONE = SDL_FLIP_NONE;
133
134constexpr FlipMode FLIP_HORIZONTAL = SDL_FLIP_HORIZONTAL;
135
136constexpr FlipMode FLIP_VERTICAL = SDL_FLIP_VERTICAL;
137
138#if SDL_VERSION_ATLEAST(3, 4, 0)
139
142 SDL_FLIP_HORIZONTAL_AND_VERTICAL;
143
144#endif // SDL_VERSION_ATLEAST(3, 4, 0)
145
151struct SurfaceBase : ResourceBaseT<SurfaceRaw, SurfaceRawConst>
152{
154
156 constexpr operator SurfaceConstRef() const noexcept { return get(); }
157
170 void Destroy();
171
177 constexpr bool MustLock() const { return SDL::MustLock(get()); }
178
216
233 void SetColorspace(Colorspace colorspace);
234
253
282
302 void SetPalette(PaletteRef palette);
303
316 Palette GetPalette() const;
317
341 void AddAlternateImage(SurfaceRef image);
342
356 bool HasAlternateImages() const;
357
377
394
420
432 void Unlock(SurfaceLock&& lock);
433
454 void SaveBMP_IO(IOStreamParam dst) const;
455
476 void SaveBMP(StringParam file) const;
477
495 void SavePNG_IO(IOStreamParam dst) const;
496
514 void SavePNG(StringParam file) const;
515
534 void SetRLE(bool enabled);
535
549 bool HasRLE() const;
550
572 void SetColorKey(std::optional<Uint32> key);
573
583 void ClearColorKey();
584
597 bool HasColorKey() const;
598
617 std::optional<Uint32> GetColorKey() const;
618
641 void SetColorMod(Uint8 r, Uint8 g, Uint8 b);
642
659 void GetColorMod(Uint8* r, Uint8* g, Uint8* b) const;
660
680 void SetAlphaMod(Uint8 alpha);
681
694 Uint8 GetAlphaMod() const;
695
710 void SetMod(Color color);
711
719 Color GetMod() const;
720
738 void SetBlendMode(BlendMode blendMode);
739
752 BlendMode GetBlendMode() const;
753
777
783 void ResetClipRect();
784
802 Rect GetClipRect() const;
803
815 void Flip(FlipMode flip);
816
817#if SDL_VERSION_ATLEAST(3, 4, 0)
818
845 Surface Rotate(float angle);
846
847#endif // SDL_VERSION_ATLEAST(3, 4, 0)
848
865 Surface Duplicate() const;
866
883 Surface Scale(const PointRaw& size, ScaleMode scaleMode) const;
884
911 Surface Convert(PixelFormat format) const;
912
941 PaletteRef palette,
942 Colorspace colorspace,
943 PropertiesRef props) const;
944
959 void PremultiplyAlpha(bool linear);
960
977 void Clear(const FColorRaw& c);
978
1003 void FillRect(OptionalRef<const RectRaw> rect, Uint32 color);
1004
1015 void Fill(Uint32 color);
1016
1040 void FillRects(SpanRef<const RectRaw> rects, Uint32 color);
1041
1111 void Blit(SurfaceRef src,
1114
1185 void BlitAt(SurfaceRef src,
1187 const PointRaw& dstpos);
1188
1209 void BlitUnchecked(SurfaceRef src,
1210 const RectRaw& srcrect,
1211 const RectRaw& dstrect);
1212
1233 void BlitScaled(SurfaceRef src,
1236 ScaleMode scaleMode);
1237
1260 const RectRaw& srcrect,
1261 const RectRaw& dstrect,
1262 ScaleMode scaleMode);
1263
1264#if SDL_VERSION_ATLEAST(3, 4, 0)
1265
1285 void Stretch(SurfaceRef src,
1286 OptionalRef<RectRaw> srcrect,
1287 OptionalRef<RectRaw> dstrect,
1288 ScaleMode scaleMode);
1289
1290#endif // SDL_VERSION_ATLEAST(3, 4, 0)
1291
1313 void BlitTiled(SurfaceRef src,
1316
1344 float scale,
1345 ScaleMode scaleMode,
1347
1380 void Blit9Grid(SurfaceRef src,
1382 int left_width,
1383 int right_width,
1384 int top_height,
1385 int bottom_height,
1387 float scale = 1,
1388 ScaleMode scaleMode = SCALEMODE_NEAREST);
1389
1420 Uint32 MapRGB(Uint8 r, Uint8 g, Uint8 b) const;
1421
1450 Uint32 MapRGBA(ColorRaw c) const;
1451
1477 void ReadPixel(const PointRaw& p,
1478 Uint8* r,
1479 Uint8* g,
1480 Uint8* b,
1481 Uint8* a) const;
1482
1498 Color ReadPixel(const PointRaw& p) const;
1499
1522 void ReadPixelFloat(const PointRaw& p,
1523 float* r,
1524 float* g,
1525 float* b,
1526 float* a) const;
1527
1543 FColor ReadPixelFloat(const PointRaw& p) const;
1544
1563 void WritePixel(const PointRaw& p, ColorRaw c);
1564
1580 void WritePixelFloat(const PointRaw& p, const FColorRaw& c);
1581
1583 constexpr int GetWidth() const;
1584
1586 constexpr int GetHeight() const;
1587
1589 constexpr Point GetSize() const;
1590
1592 constexpr int GetPitch() const;
1593
1595 constexpr PixelFormat GetFormat() const;
1596
1598 constexpr void* GetPixels() const;
1599
1614 void Save(StringParam filename) const;
1615
1632 void SaveTyped_IO(IOStreamParam dst, StringParam type) const;
1633};
1634
1666{
1667 using SurfaceBase::SurfaceBase;
1668
1676 constexpr explicit Surface(SurfaceRaw resource) noexcept
1677 : SurfaceBase(resource)
1678 {
1679 }
1680
1682 constexpr Surface(const Surface& other)
1683 : Surface(borrow(other.get()))
1684 {
1685 }
1686
1688 constexpr Surface(Surface&& other) noexcept
1689 : Surface(other.release())
1690 {
1691 }
1692
1709 Surface(const PointRaw& size, PixelFormat format);
1710
1737 Surface(const PointRaw& size, PixelFormat format, void* pixels, int pitch);
1738
1775 Surface(StringParam file);
1776
1819
1827 static Surface borrow(SurfaceRaw resource)
1828 {
1829 if (resource) {
1830 ++resource->refcount;
1831 return Surface(resource);
1832 }
1833 return {};
1834 }
1835
1837 ~Surface() { SDL_DestroySurface(get()); }
1838
1840 constexpr Surface& operator=(Surface&& other) noexcept
1841 {
1842 swap(*this, other);
1843 return *this;
1844 }
1845
1848 {
1849 if (get() != other.get()) {
1850 Surface tmp(other);
1851 swap(*this, tmp);
1852 }
1853 return *this;
1854 }
1855};
1856
1875{
1876 Surface m_lock;
1877
1878public:
1905
1907 SurfaceLock(const SurfaceLock& other) = delete;
1908
1910 SurfaceLock(SurfaceLock&& other) noexcept
1911 : m_lock(std::move(other.m_lock))
1912 {
1913 }
1914
1927
1928 SurfaceLock& operator=(const SurfaceLock& other) = delete;
1929
1932 {
1933 std::swap(m_lock, other.m_lock);
1934 return *this;
1935 }
1936
1938 constexpr operator bool() const { return bool(m_lock); }
1939
1965 void ReadPixel(const PointRaw& p,
1966 Uint8* r,
1967 Uint8* g,
1968 Uint8* b,
1969 Uint8* a) const
1970 {
1971 m_lock.ReadPixel(p, r, g, b, a);
1972 }
1973
1992 Color ReadPixel(const PointRaw& p) const { return m_lock.ReadPixel(p); }
1993
2017 float* r,
2018 float* g,
2019 float* b,
2020 float* a) const
2021 {
2022 m_lock.ReadPixelFloat(p, r, g, b, a);
2023 }
2024
2041 {
2042 return m_lock.ReadPixelFloat(p);
2043 }
2044
2063 void WritePixel(const PointRaw& p, ColorRaw c) { m_lock.WritePixel(p, c); }
2064
2080 void WritePixelFloat(const PointRaw& p, const FColorRaw& c)
2081 {
2082 m_lock.WritePixelFloat(p, c);
2083 }
2084
2086 constexpr int GetWidth() const { return m_lock.GetWidth(); }
2087
2089 constexpr int GetHeight() const { return m_lock.GetHeight(); }
2090
2092 constexpr Point GetSize() const { return m_lock.GetSize(); }
2093
2095 constexpr int GetPitch() const { return m_lock.GetPitch(); }
2096
2098 constexpr PixelFormat GetFormat() const { return m_lock.GetFormat(); }
2099
2101 constexpr void* GetPixels() const { return m_lock.GetPixels(); }
2102
2114 void reset();
2115
2117 SurfaceRef resource() const { return m_lock; }
2118
2120 void release() { m_lock.release(); }
2121};
2122
2140inline Surface CreateSurface(const PointRaw& size, PixelFormat format)
2141{
2142 return Surface(size, format);
2143}
2144
2145inline Surface::Surface(const PointRaw& size, PixelFormat format)
2146 : Surface(CheckError(SDL_CreateSurface(size.x, size.y, format)))
2147{
2148}
2149
2150inline Surface::Surface(const PointRaw& size,
2151 PixelFormat format,
2152 void* pixels,
2153 int pitch)
2154 : Surface(
2155 CheckError(SDL_CreateSurfaceFrom(size.x, size.y, format, pixels, pitch)))
2156{
2157}
2158
2186 PixelFormat format,
2187 void* pixels,
2188 int pitch)
2189{
2190 return Surface(size, format, pixels, pitch);
2191}
2192
2207inline void DestroySurface(SurfaceRaw surface) { SDL_DestroySurface(surface); }
2208
2210
2249{
2250 return CheckError(SDL_GetSurfaceProperties(surface));
2251}
2252
2257
2270namespace prop::Surface {
2271
2273 SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT;
2274
2275constexpr auto HDR_HEADROOM_FLOAT =
2276 SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT;
2277
2279 SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING;
2280
2281#if SDL_VERSION_ATLEAST(3, 2, 6)
2282
2283constexpr auto HOTSPOT_X_NUMBER =
2284 SDL_PROP_SURFACE_HOTSPOT_X_NUMBER;
2285
2286constexpr auto HOTSPOT_Y_NUMBER =
2287 SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER;
2288
2289#endif // SDL_VERSION_ATLEAST(3, 2, 6)
2290
2291#if SDL_VERSION_ATLEAST(3, 4, 0)
2292
2293constexpr auto ROTATION_FLOAT =
2294 SDL_PROP_SURFACE_ROTATION_FLOAT;
2295
2296#endif // SDL_VERSION_ATLEAST(3, 4, 0)
2297
2298} // namespace prop::Surface
2299
2317inline void SetSurfaceColorspace(SurfaceRef surface, Colorspace colorspace)
2318{
2319 CheckError(SDL_SetSurfaceColorspace(surface, colorspace));
2320}
2321
2323{
2324 SDL::SetSurfaceColorspace(get(), colorspace);
2325}
2326
2346{
2347 return SDL_GetSurfaceColorspace(surface);
2348}
2349
2351{
2353}
2354
2383{
2384 return Palette::borrow(CheckError(SDL_CreateSurfacePalette(surface)));
2385}
2386
2391
2412inline void SetSurfacePalette(SurfaceRef surface, PaletteRef palette)
2413{
2414 CheckError(SDL_SetSurfacePalette(surface, palette));
2415}
2416
2418{
2419 SDL::SetSurfacePalette(get(), palette);
2420}
2421
2436{
2437 return Palette::borrow(SDL_GetSurfacePalette(surface));
2438}
2439
2441{
2442 return SDL::GetSurfacePalette(get());
2443}
2444
2471{
2472 CheckError(SDL_AddSurfaceAlternateImage(surface, image));
2473}
2474
2479
2495{
2496 return SDL_SurfaceHasAlternateImages(surface);
2497}
2498
2500{
2502}
2503
2528{
2529 int count = 0;
2530 auto data = SDL_GetSurfaceImages(surface, &count);
2531 return OwnArray<SurfaceRaw>(CheckError(data), count);
2532}
2533
2538
2557{
2558 SDL_RemoveSurfaceAlternateImages(surface);
2559}
2560
2565
2591inline void LockSurface(SurfaceRef surface)
2592{
2593 CheckError(SDL_LockSurface(surface));
2594}
2595
2596inline SurfaceLock SurfaceBase::Lock() { return {SurfaceRef(*this)}; }
2597
2599 : m_lock(resource)
2600{
2601 LockSurface(m_lock);
2602}
2603
2617inline void UnlockSurface(SurfaceRef surface) { SDL_UnlockSurface(surface); }
2618
2620{
2621 SDL_assert_paranoid(lock.resource() == *this);
2622 std::move(lock).reset();
2623}
2624
2626{
2627 if (!m_lock) return;
2628 UnlockSurface(m_lock);
2629 m_lock = {};
2630}
2631
2632#if !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC) && \
2633 SDL_VERSION_ATLEAST(3, 4, 0)
2634
2650{
2651 return Surface{SDL_LoadSurface_IO(src.stream, src.closeio)};
2652}
2653
2668inline Surface LoadSurface(StringParam file)
2669{
2670 return Surface{SDL_LoadSurface(file)};
2671}
2672
2673#endif // !defined(SDL3PP_ENABLE_IMAGE) && SDL_VERSION_ATLEAST(3, 4, 0)
2674
2694{
2695 return Surface{SDL_LoadBMP_IO(src.stream, src.closeio)};
2696}
2697
2716inline Surface LoadBMP(StringParam file) { return Surface(SDL_LoadBMP(file)); }
2717
2740{
2741 CheckError(SDL_SaveBMP_IO(surface, dst.stream, dst.closeio));
2742}
2743
2745{
2746 SDL::SaveBMP_IO(get(), dst);
2747}
2748
2770inline void SaveBMP(SurfaceConstRef surface, StringParam file)
2771{
2772 CheckError(SDL_SaveBMP(surface, file));
2773}
2774
2775inline void SurfaceBase::SaveBMP(StringParam file) const
2776{
2777 SDL::SaveBMP(get(), file);
2778}
2779
2780#if SDL_VERSION_ATLEAST(3, 4, 0)
2781
2802{
2803 return Surface(SDL_LoadPNG_IO(src.stream, src.closeio));
2804}
2805
2829{
2830 return Surface(SDL_LoadPNG(file));
2831}
2832
2833#if !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2834
2836inline Surface LoadPNG_IO(IOStreamRef src) { return LoadTrustedPNG_IO(src); }
2837
2839inline Surface LoadPNG(StringParam file) { return LoadTrustedPNG(file); }
2840
2841#endif // !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2842
2859{
2860 CheckError(SDL_SavePNG_IO(surface, dst.stream, dst.closeio));
2861}
2862
2863#if !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2864inline void SurfaceBase::SavePNG_IO(IOStreamParam dst) const
2865{
2867}
2868#endif // !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2869
2886{
2887 CheckError(SDL_SavePNG(surface, file));
2888}
2889
2890#if !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2891inline void SurfaceBase::SavePNG(StringParam file) const
2892{
2893 SDL::SaveTrustedPNG(get(), file);
2894}
2895#endif // !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2896
2897#endif // SDL_VERSION_ATLEAST(3, 4, 0)
2898
2918inline void SetSurfaceRLE(SurfaceRef surface, bool enabled)
2919{
2920 CheckError(SDL_SetSurfaceRLE(surface, enabled));
2921}
2922
2923inline void SurfaceBase::SetRLE(bool enabled)
2924{
2925 SDL::SetSurfaceRLE(get(), enabled);
2926}
2927
2942inline bool SurfaceHasRLE(SurfaceConstRef surface)
2943{
2944 return SDL_SurfaceHasRLE(surface);
2945}
2946
2947inline bool SurfaceBase::HasRLE() const { return SDL::SurfaceHasRLE(get()); }
2948
2971inline void SetSurfaceColorKey(SurfaceRef surface, std::optional<Uint32> key)
2972{
2973 CheckError(SDL_SetSurfaceColorKey(surface, key.has_value(), key.value_or(0)));
2974}
2975
2976inline void SurfaceBase::SetColorKey(std::optional<Uint32> key)
2977{
2979}
2980
2992{
2993 SetSurfaceColorKey(surface, std::nullopt);
2994}
2995
2997
3014{
3015 return SDL_SurfaceHasColorKey(surface);
3016}
3017
3018inline bool SurfaceBase::HasColorKey() const
3019{
3020 return SDL::SurfaceHasColorKey(get());
3021}
3022
3042inline std::optional<Uint32> GetSurfaceColorKey(SurfaceConstRef surface)
3043{
3044 if (Uint32 key; SDL_GetSurfaceColorKey(surface, &key)) return key;
3045 return std::nullopt;
3046}
3047
3048inline std::optional<Uint32> SurfaceBase::GetColorKey() const
3049{
3050 return SDL::GetSurfaceColorKey(get());
3051}
3052
3076inline void SetSurfaceColorMod(SurfaceRef surface, Uint8 r, Uint8 g, Uint8 b)
3077{
3078 CheckError(SDL_SetSurfaceColorMod(surface, r, g, b));
3079}
3080
3082{
3083 SDL::SetSurfaceColorMod(get(), r, g, b);
3084}
3085
3104 Uint8* r,
3105 Uint8* g,
3106 Uint8* b)
3107{
3108 CheckError(SDL_GetSurfaceColorMod(surface, r, g, b));
3109}
3110
3111inline void SurfaceBase::GetColorMod(Uint8* r, Uint8* g, Uint8* b) const
3112{
3113 SDL::GetSurfaceColorMod(get(), r, g, b);
3114}
3115
3136inline void SetSurfaceAlphaMod(SurfaceRef surface, Uint8 alpha)
3137{
3138 CheckError(SDL_SetSurfaceAlphaMod(surface, alpha));
3139}
3140
3142{
3143 SDL::SetSurfaceAlphaMod(get(), alpha);
3144}
3145
3161{
3162 Uint8 alpha;
3163 CheckError(SDL_GetSurfaceAlphaMod(surface, &alpha));
3164 return alpha;
3165}
3166
3168{
3169 return SDL::GetSurfaceAlphaMod(get());
3170}
3171
3187inline void SetSurfaceMod(SurfaceRef surface, Color color)
3188{
3189 SetSurfaceColorMod(surface, color.r, color.g, color.b);
3190 SetSurfaceAlphaMod(surface, color.a);
3191}
3192
3193inline void SurfaceBase::SetMod(Color color) { SetSurfaceMod(get(), color); }
3194
3204{
3205 Color c;
3206 GetSurfaceColorMod(surface, &c.r, &c.g, &c.b);
3207 c.a = GetSurfaceAlphaMod(surface);
3208 return c;
3209}
3210
3211inline Color SurfaceBase::GetMod() const { return GetSurfaceMod(get()); }
3212
3231inline void SetSurfaceBlendMode(SurfaceRef surface, BlendMode blendMode)
3232{
3233 CheckError(SDL_SetSurfaceBlendMode(surface, blendMode));
3234}
3235
3237{
3238 SDL::SetSurfaceBlendMode(get(), blendMode);
3239}
3240
3255{
3256 BlendMode blendmode;
3257 CheckError(SDL_GetSurfaceBlendMode(surface, &blendmode));
3258 return blendmode;
3259}
3260
3262{
3263 return SDL::GetSurfaceBlendMode(get());
3264}
3265
3289inline bool SetSurfaceClipRect(SurfaceRef surface,
3291{
3292 return SDL_SetSurfaceClipRect(surface, rect);
3293}
3294
3296{
3297 return SDL::SetSurfaceClipRect(get(), rect);
3298}
3299
3306{
3307 SetSurfaceClipRect(surface, std::nullopt);
3308}
3309
3311
3331{
3332 Rect r;
3333 CheckError(SDL_GetSurfaceClipRect(surface, &r));
3334 return r;
3335}
3336
3338{
3339 return SDL::GetSurfaceClipRect(get());
3340}
3341
3354inline void FlipSurface(SurfaceRef surface, FlipMode flip)
3355{
3356 CheckError(SDL_FlipSurface(surface, flip));
3357}
3358
3359inline void SurfaceBase::Flip(FlipMode flip) { SDL::FlipSurface(get(), flip); }
3360
3361#if SDL_VERSION_ATLEAST(3, 4, 0)
3362
3390inline Surface RotateSurface(SurfaceRef surface, float angle)
3391{
3392 return Surface{SDL_RotateSurface(surface, angle)};
3393}
3394
3395inline Surface SurfaceBase::Rotate(float angle)
3396{
3397 return SDL::RotateSurface(get(), angle);
3398}
3399
3400#endif // SDL_VERSION_ATLEAST(3, 4, 0)
3401
3422{
3423 return Surface(SDL_DuplicateSurface(surface));
3424}
3425
3427{
3428 return SDL::DuplicateSurface(get());
3429}
3430
3451 const PointRaw& size,
3452 ScaleMode scaleMode)
3453{
3454 return Surface(SDL_ScaleSurface(surface, size.x, size.y, scaleMode));
3455}
3456
3458 ScaleMode scaleMode) const
3459{
3460 return SDL::ScaleSurface(get(), size, scaleMode);
3461}
3462
3491{
3492 return Surface(SDL_ConvertSurface(surface, format));
3493}
3494
3496{
3497 return SDL::ConvertSurface(get(), format);
3498}
3499
3529 PixelFormat format,
3530 PaletteRef palette,
3531 Colorspace colorspace,
3532 PropertiesRef props)
3533{
3534 return Surface{SDL_ConvertSurfaceAndColorspace(
3535 surface, format, palette, colorspace, props)};
3536}
3537
3539 PaletteRef palette,
3540 Colorspace colorspace,
3541 PropertiesRef props) const
3542{
3544 get(), format, palette, colorspace, props);
3545}
3546
3567inline void ConvertPixels(const PointRaw& size,
3568 PixelFormat src_format,
3569 const void* src,
3570 int src_pitch,
3571 PixelFormat dst_format,
3572 void* dst,
3573 int dst_pitch)
3574{
3575 CheckError(SDL_ConvertPixels(
3576 size.x, size.y, src_format, src, src_pitch, dst_format, dst, dst_pitch));
3577}
3578
3608inline void ConvertPixelsAndColorspace(const PointRaw& size,
3609 PixelFormat src_format,
3610 Colorspace src_colorspace,
3611 PropertiesRef src_properties,
3612 const void* src,
3613 int src_pitch,
3614 PixelFormat dst_format,
3615 Colorspace dst_colorspace,
3616 PropertiesRef dst_properties,
3617 void* dst,
3618 int dst_pitch)
3619{
3620 CheckError(SDL_ConvertPixelsAndColorspace(size.x,
3621 size.y,
3622 src_format,
3623 src_colorspace,
3624 src_properties,
3625 src,
3626 src_pitch,
3627 dst_format,
3628 dst_colorspace,
3629 dst_properties,
3630 dst,
3631 dst_pitch));
3632}
3633
3656inline void PremultiplyAlpha(const PointRaw& size,
3657 PixelFormat src_format,
3658 const void* src,
3659 int src_pitch,
3660 PixelFormat dst_format,
3661 void* dst,
3662 int dst_pitch,
3663 bool linear)
3664{
3665 CheckError(SDL_PremultiplyAlpha(size.x,
3666 size.y,
3667 src_format,
3668 src,
3669 src_pitch,
3670 dst_format,
3671 dst,
3672 dst_pitch,
3673 linear));
3674}
3675
3691inline void PremultiplySurfaceAlpha(SurfaceRef surface, bool linear)
3692{
3693 CheckError(SDL_PremultiplySurfaceAlpha(surface, linear));
3694}
3695
3696inline void SurfaceBase::PremultiplyAlpha(bool linear)
3697{
3699}
3700
3718inline void ClearSurface(SurfaceRef surface, const FColorRaw& c)
3719{
3720 CheckError(SDL_ClearSurface(surface, c.r, c.g, c.b, c.a));
3721}
3722
3723inline void SurfaceBase::Clear(const FColorRaw& c) { ClearSurface(get(), c); }
3724
3752 Uint32 color)
3753{
3754 CheckError(SDL_FillSurfaceRect(dst, rect, color));
3755}
3756
3758{
3759 SDL::FillSurfaceRect(get(), rect, color);
3760}
3761
3773inline void FillSurface(SurfaceRef dst, Uint32 color)
3774{
3775 FillSurfaceRect(dst, std::nullopt, color);
3776}
3777
3778inline void SurfaceBase::Fill(Uint32 color) { FillSurface(get(), color); }
3779
3806 Uint32 color)
3807{
3808 CheckError(
3809 SDL_FillSurfaceRects(dst, rects.data(), narrowS32(rects.size()), color));
3810}
3811
3813{
3814 SDL::FillSurfaceRects(get(), rects, color);
3815}
3816
3887inline void BlitSurface(SurfaceRef src,
3889 SurfaceRef dst,
3891{
3892 CheckError(SDL_BlitSurface(src, srcrect, dst, dstrect));
3893}
3894
3898{
3899 SDL::BlitSurface(src, srcrect, get(), dstrect);
3900}
3901
3904 const PointRaw& dstpos)
3905{
3906 Blit(src, srcrect, Rect{dstpos, {}});
3907}
3908
3978 SurfaceRef dst,
3979 const PointRaw& dstpos)
3980{
3981 BlitSurface(src, srcrect, dst, SDL_Rect{dstpos.x, dstpos.y, 0, 0});
3982}
3983
4006 const RectRaw& srcrect,
4007 SurfaceRef dst,
4008 const RectRaw& dstrect)
4009{
4010 CheckError(SDL_BlitSurfaceUnchecked(src, &srcrect, dst, &dstrect));
4011}
4012
4014 const RectRaw& srcrect,
4015 const RectRaw& dstrect)
4016{
4017 SDL::BlitSurfaceUnchecked(src, srcrect, get(), dstrect);
4018}
4019
4043 SurfaceRef dst,
4045 ScaleMode scaleMode)
4046{
4047 CheckError(SDL_BlitSurfaceScaled(src, srcrect, dst, dstrect, scaleMode));
4048}
4049
4053 ScaleMode scaleMode)
4054{
4055 SDL::BlitSurfaceScaled(src, srcrect, get(), dstrect, scaleMode);
4056}
4057
4081 const RectRaw& srcrect,
4082 SurfaceRef dst,
4083 const RectRaw& dstrect,
4084 ScaleMode scaleMode)
4085{
4086 CheckError(
4087 SDL_BlitSurfaceUncheckedScaled(src, &srcrect, dst, &dstrect, scaleMode));
4088}
4089
4091 const RectRaw& srcrect,
4092 const RectRaw& dstrect,
4093 ScaleMode scaleMode)
4094{
4095 SDL::BlitSurfaceUncheckedScaled(src, srcrect, get(), dstrect, scaleMode);
4096}
4097
4098#if SDL_VERSION_ATLEAST(3, 4, 0)
4099
4121 OptionalRef<RectRaw> srcrect,
4122 SurfaceRef dst,
4123 OptionalRef<RectRaw> dstrect,
4124 ScaleMode scaleMode)
4125{
4126 CheckError(SDL_StretchSurface(src, srcrect, dst, dstrect, scaleMode));
4127}
4128
4130 OptionalRef<RectRaw> srcrect,
4131 OptionalRef<RectRaw> dstrect,
4132 ScaleMode scaleMode)
4133{
4134 SDL::StretchSurface(src, srcrect, get(), dstrect, scaleMode);
4135}
4136
4137#endif // SDL_VERSION_ATLEAST(3, 4, 0)
4138
4163 SurfaceRef dst,
4165{
4166 CheckError(SDL_BlitSurfaceTiled(src, srcrect, dst, dstrect));
4167}
4168
4172{
4173 SDL::BlitSurfaceTiled(src, srcrect, get(), dstrect);
4174}
4175
4204 float scale,
4205 ScaleMode scaleMode,
4206 SurfaceRef dst,
4208{
4209 CheckError(SDL_BlitSurfaceTiledWithScale(
4210 src, srcrect, scale, scaleMode, dst, dstrect));
4211}
4212
4215 float scale,
4216 ScaleMode scaleMode,
4218{
4220 src, srcrect, scale, scaleMode, get(), dstrect);
4221}
4222
4258 int left_width,
4259 int right_width,
4260 int top_height,
4261 int bottom_height,
4262 SurfaceRef dst,
4264 float scale = 1,
4265 ScaleMode scaleMode = SCALEMODE_NEAREST)
4266{
4267 CheckError(SDL_BlitSurface9Grid(src,
4268 srcrect,
4269 left_width,
4270 right_width,
4271 top_height,
4272 bottom_height,
4273 scale,
4274 scaleMode,
4275 dst,
4276 dstrect));
4277}
4278
4281 int left_width,
4282 int right_width,
4283 int top_height,
4284 int bottom_height,
4286 float scale,
4287 ScaleMode scaleMode)
4288{
4290 srcrect,
4291 left_width,
4292 right_width,
4293 top_height,
4294 bottom_height,
4295 get(),
4296 dstrect,
4297 scale,
4298 scaleMode);
4299}
4300
4333{
4334 return SDL_MapSurfaceRGB(surface, r, g, b);
4335}
4336
4338{
4339 return SDL::MapSurfaceRGB(get(), r, g, b);
4340}
4341
4372{
4373 return SDL_MapSurfaceRGBA(surface, c.r, c.g, c.b, c.a);
4374}
4375
4377{
4378 return SDL::MapSurfaceRGBA(get(), c);
4379}
4380
4408 const PointRaw& p,
4409 Uint8* r,
4410 Uint8* g,
4411 Uint8* b,
4412 Uint8* a)
4413{
4414 CheckError(SDL_ReadSurfacePixel(surface, p.x, p.y, r, g, b, a));
4415}
4416
4437{
4438 Color c;
4439 ReadSurfacePixel(surface, p, &c.r, &c.g, &c.b, &c.a);
4440 return c;
4441}
4442
4469inline void ReadSurfacePixel(const SurfaceLock& lock,
4470 const PointRaw& p,
4471 Uint8* r,
4472 Uint8* g,
4473 Uint8* b,
4474 Uint8* a)
4475{
4476 lock.ReadPixel(p, r, g, b, a);
4477}
4478
4498inline Color ReadSurfacePixel(const SurfaceLock& lock, const PointRaw& p)
4499{
4500 return lock.ReadPixel(p);
4501}
4502
4504 Uint8* r,
4505 Uint8* g,
4506 Uint8* b,
4507 Uint8* a) const
4508{
4509 SDL::ReadSurfacePixel(get(), p, r, g, b, a);
4510}
4511
4513{
4514 return SDL::ReadSurfacePixel(get(), p);
4515}
4516
4541 const PointRaw& p,
4542 float* r,
4543 float* g,
4544 float* b,
4545 float* a)
4546{
4547 CheckError(SDL_ReadSurfacePixelFloat(surface, p.x, p.y, r, g, b, a));
4548}
4549
4567{
4568 FColor c;
4569 ReadSurfacePixelFloat(surface, p, &c.r, &c.g, &c.b, &c.a);
4570 return c;
4571}
4572
4596inline void ReadSurfacePixelFloat(const SurfaceLock& lock,
4597 const PointRaw& p,
4598 float* r,
4599 float* g,
4600 float* b,
4601 float* a)
4602{
4603 lock.ReadPixelFloat(p, r, g, b, a);
4604}
4605
4623{
4624 return lock.ReadPixelFloat(p);
4625}
4626
4628 float* r,
4629 float* g,
4630 float* b,
4631 float* a) const
4632{
4633 SDL::ReadSurfacePixelFloat(get(), p, r, g, b, a);
4634}
4635
4637{
4638 return SDL::ReadSurfacePixelFloat(get(), p);
4639}
4640
4660inline void WriteSurfacePixel(SurfaceRef surface, const PointRaw& p, ColorRaw c)
4661{
4662 CheckError(SDL_WriteSurfacePixel(surface, p.x, p.y, c.r, c.g, c.b, c.a));
4663}
4664
4684inline void WriteSurfacePixel(SurfaceLock& lock, const PointRaw& p, ColorRaw c)
4685{
4686 lock.WritePixel(p, c);
4687}
4688
4690{
4691 SDL::WriteSurfacePixel(get(), p, c);
4692}
4693
4711 const PointRaw& p,
4712 const FColorRaw& c)
4713{
4714 CheckError(SDL_WriteSurfacePixelFloat(surface, p.x, p.y, c.r, c.g, c.b, c.a));
4715}
4716
4734 const PointRaw& p,
4735 const FColorRaw& c)
4736{
4737 lock.WritePixelFloat(p, c);
4738}
4739
4740inline void SurfaceBase::WritePixelFloat(const PointRaw& p, const FColorRaw& c)
4741{
4743}
4744
4746constexpr int GetSurfaceWidth(SurfaceConstRef surface) { return surface->w; }
4747
4749constexpr int GetSurfaceWidth(const SurfaceLock& lock)
4750{
4751 return lock.GetWidth();
4752}
4753
4754constexpr int SurfaceBase::GetWidth() const { return GetSurfaceWidth(get()); }
4755
4757constexpr int GetSurfaceHeight(SurfaceConstRef surface) { return surface->h; }
4758
4760constexpr int GetSurfaceHeight(const SurfaceLock& lock)
4761{
4762 return lock.GetHeight();
4763}
4764
4765constexpr int SurfaceBase::GetHeight() const { return GetSurfaceHeight(get()); }
4766
4769{
4770 return Point(surface->w, surface->h);
4771}
4772
4774constexpr Point GetSurfaceSize(const SurfaceLock& lock)
4775{
4776 return lock.GetSize();
4777}
4778
4779constexpr Point SurfaceBase::GetSize() const { return GetSurfaceSize(get()); }
4780
4782constexpr int GetSurfacePitch(SurfaceConstRef surface)
4783{
4784 return surface->pitch;
4785}
4786
4788constexpr int GetSurfacePitch(const SurfaceLock& lock)
4789{
4790 return lock.GetPitch();
4791}
4792
4793constexpr int SurfaceBase::GetPitch() const { return GetSurfacePitch(get()); }
4794
4797{
4798 return surface->format;
4799}
4800
4803{
4804 return lock.GetFormat();
4805}
4806
4808{
4809 return SDL::GetSurfaceFormat(get());
4810}
4811
4813constexpr void* GetSurfacePixels(SurfaceConstRef surface)
4814{
4815 return surface->pixels;
4816}
4817
4819constexpr void* GetSurfacePixels(const SurfaceLock& lock)
4820{
4821 return lock.GetPixels();
4822}
4823
4824constexpr void* SurfaceBase::GetPixels() const
4825{
4826 return SDL::GetSurfacePixels(get());
4827}
4828
4830
4831} // namespace SDL
4832
4833#endif /* SDL3PP_SURFACE_H_ */
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
Pixel format.
Definition SDL3pp_pixels.h:361
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