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 Surface;
42
44using SurfaceRaw = SDL_Surface*;
45
47using SurfaceRawConst = const SDL_Surface*;
48
55
58
59// Forward decl
60struct SurfaceLock;
61
70
72 SDL_SURFACE_PREALLOCATED;
73
75 SDL_SURFACE_LOCK_NEEDED;
76
78 SDL_SURFACE_LOCKED;
79
81constexpr SurfaceFlags SURFACE_SIMD_ALIGNED = SDL_SURFACE_SIMD_ALIGNED;
82
88constexpr bool MustLock(SurfaceConstRef S)
89{
90 return SDL_MUSTLOCK((static_cast<SurfaceRawConst>(S)));
91}
92
98using ScaleMode = SDL_ScaleMode;
99
100#if SDL_VERSION_ATLEAST(3, 2, 10)
101
102constexpr ScaleMode SCALEMODE_INVALID = SDL_SCALEMODE_INVALID;
103
104#endif // SDL_VERSION_ATLEAST(3, 2, 10)
105
107 SDL_SCALEMODE_NEAREST;
108
110 SDL_SCALEMODE_LINEAR;
111
112#if SDL_VERSION_ATLEAST(3, 4, 0)
113
118constexpr ScaleMode SCALEMODE_PIXELART = SDL_SCALEMODE_PIXELART;
119
120#endif // SDL_VERSION_ATLEAST(3, 4, 0)
121
127using FlipMode = SDL_FlipMode;
128
129constexpr FlipMode FLIP_NONE = SDL_FLIP_NONE;
130
131constexpr FlipMode FLIP_HORIZONTAL = SDL_FLIP_HORIZONTAL;
132
133constexpr FlipMode FLIP_VERTICAL = SDL_FLIP_VERTICAL;
134
135#if SDL_VERSION_ATLEAST(3, 4, 0)
136
139 SDL_FLIP_HORIZONTAL_AND_VERTICAL;
140
141#endif // SDL_VERSION_ATLEAST(3, 4, 0)
142
171struct Surface : ResourceBase<SurfaceRaw, SurfaceRawConst>
172{
174
182 constexpr explicit Surface(SurfaceRaw resource) noexcept
183 : ResourceBase(resource)
184 {
185 }
186
188 constexpr Surface(const Surface& other)
189 : Surface(other.get())
190 {
191 if (auto res = get()) ++res->refcount;
192 }
193
195 constexpr Surface(Surface&& other) noexcept
196 : Surface(other.release())
197 {
198 }
199
216 Surface(const PointRaw& size, PixelFormat format);
217
244 Surface(const PointRaw& size, PixelFormat format, void* pixels, int pitch);
245
282 Surface(StringParam file);
283
331 Surface(IOStreamRef src, bool closeio = false);
332
340 static Surface Borrow(SurfaceRaw resource)
341 {
342 if (resource) {
343 ++resource->refcount;
344 return Surface(resource);
345 }
346 return {};
347 }
348
350 constexpr operator SurfaceConstRef() const noexcept { return get(); }
351
353 ~Surface() { SDL_DestroySurface(get()); }
354
356 constexpr Surface& operator=(Surface&& other) noexcept
357 {
358 swap(*this, other);
359 return *this;
360 }
361
363 Surface& operator=(const Surface& other)
364 {
365 if (get() != other.get()) {
366 Surface tmp(other);
367 swap(*this, tmp);
368 }
369 return *this;
370 }
371
384 void Destroy();
385
391 constexpr bool MustLock() const { return SDL::MustLock(get()); }
392
431
448 void SetColorspace(Colorspace colorspace);
449
468
497
517 void SetPalette(PaletteRef palette);
518
531 Palette GetPalette() const;
532
556 void AddAlternateImage(SurfaceRef image);
557
571 bool HasAlternateImages() const;
572
592
609
635
647 void Unlock(SurfaceLock&& lock);
648
671 void SaveBMP_IO(IOStreamRef dst, bool closeio = false) const;
672
693 void SaveBMP(StringParam file) const;
694
714 void SavePNG_IO(IOStreamRef dst, bool closeio = false) const;
715
733 void SavePNG(StringParam file) const;
734
753 void SetRLE(bool enabled);
754
768 bool HasRLE() const;
769
791 void SetColorKey(std::optional<Uint32> key);
792
802 void ClearColorKey();
803
816 bool HasColorKey() const;
817
836 std::optional<Uint32> GetColorKey() const;
837
860 void SetColorMod(Uint8 r, Uint8 g, Uint8 b);
861
878 void GetColorMod(Uint8* r, Uint8* g, Uint8* b) const;
879
899 void SetAlphaMod(Uint8 alpha);
900
913 Uint8 GetAlphaMod() const;
914
929 void SetMod(Color color);
930
938 Color GetMod() const;
939
957 void SetBlendMode(BlendMode blendMode);
958
971 BlendMode GetBlendMode() const;
972
996
1002 void ResetClipRect();
1003
1021 Rect GetClipRect() const;
1022
1034 void Flip(FlipMode flip);
1035
1036#if SDL_VERSION_ATLEAST(3, 4, 0)
1037
1064 Surface Rotate(float angle);
1065
1066#endif // SDL_VERSION_ATLEAST(3, 4, 0)
1067
1084 Surface Duplicate() const;
1085
1102 Surface Scale(const PointRaw& size, ScaleMode scaleMode) const;
1103
1130 Surface Convert(PixelFormat format) const;
1131
1160 PaletteRef palette,
1161 Colorspace colorspace,
1162 PropertiesRef props) const;
1163
1178 void PremultiplyAlpha(bool linear);
1179
1196 void Clear(const FColorRaw& c);
1197
1222 void FillRect(OptionalRef<const RectRaw> rect, Uint32 color);
1223
1234 void Fill(Uint32 color);
1235
1259 void FillRects(SpanRef<const RectRaw> rects, Uint32 color);
1260
1330 void Blit(SurfaceRef src,
1333
1404 void BlitAt(SurfaceRef src,
1406 const PointRaw& dstpos);
1407
1428 void BlitUnchecked(SurfaceRef src,
1429 const RectRaw& srcrect,
1430 const RectRaw& dstrect);
1431
1452 void BlitScaled(SurfaceRef src,
1455 ScaleMode scaleMode);
1456
1479 const RectRaw& srcrect,
1480 const RectRaw& dstrect,
1481 ScaleMode scaleMode);
1482
1483#if SDL_VERSION_ATLEAST(3, 4, 0)
1484
1504 void Stretch(SurfaceRef src,
1505 OptionalRef<RectRaw> srcrect,
1506 OptionalRef<RectRaw> dstrect,
1507 ScaleMode scaleMode);
1508
1509#endif // SDL_VERSION_ATLEAST(3, 4, 0)
1510
1532 void BlitTiled(SurfaceRef src,
1535
1563 float scale,
1564 ScaleMode scaleMode,
1566
1599 void Blit9Grid(SurfaceRef src,
1601 int left_width,
1602 int right_width,
1603 int top_height,
1604 int bottom_height,
1606 float scale = 1,
1607 ScaleMode scaleMode = SCALEMODE_NEAREST);
1608
1639 Uint32 MapRGB(Uint8 r, Uint8 g, Uint8 b) const;
1640
1669 Uint32 MapRGBA(ColorRaw c) const;
1670
1696 void ReadPixel(const PointRaw& p,
1697 Uint8* r,
1698 Uint8* g,
1699 Uint8* b,
1700 Uint8* a) const;
1701
1717 Color ReadPixel(const PointRaw& p) const;
1718
1741 void ReadPixelFloat(const PointRaw& p,
1742 float* r,
1743 float* g,
1744 float* b,
1745 float* a) const;
1746
1762 FColor ReadPixelFloat(const PointRaw& p) const;
1763
1782 void WritePixel(const PointRaw& p, ColorRaw c);
1783
1799 void WritePixelFloat(const PointRaw& p, const FColorRaw& c);
1800
1802 constexpr int GetWidth() const;
1803
1805 constexpr int GetHeight() const;
1806
1808 constexpr Point GetSize() const;
1809
1811 constexpr int GetPitch() const;
1812
1814 constexpr PixelFormat GetFormat() const;
1815
1817 constexpr void* GetPixels() const;
1818
1833 void Save(StringParam filename) const;
1834
1856 void SaveTyped_IO(IOStreamRef dst,
1857 StringParam type,
1858 bool closeio = false) const;
1859};
1860
1879{
1880 Surface m_lock;
1881
1882public:
1909
1911 SurfaceLock(const SurfaceLock& other) = delete;
1912
1914 SurfaceLock(SurfaceLock&& other) noexcept
1915 : m_lock(std::move(other.m_lock))
1916 {
1917 }
1918
1931
1932 SurfaceLock& operator=(const SurfaceLock& other) = delete;
1933
1936 {
1937 std::swap(m_lock, other.m_lock);
1938 return *this;
1939 }
1940
1942 constexpr operator bool() const { return bool(m_lock); }
1943
1969 void ReadPixel(const PointRaw& p,
1970 Uint8* r,
1971 Uint8* g,
1972 Uint8* b,
1973 Uint8* a) const
1974 {
1975 m_lock.ReadPixel(p, r, g, b, a);
1976 }
1977
1996 Color ReadPixel(const PointRaw& p) const { return m_lock.ReadPixel(p); }
1997
2021 float* r,
2022 float* g,
2023 float* b,
2024 float* a) const
2025 {
2026 m_lock.ReadPixelFloat(p, r, g, b, a);
2027 }
2028
2045 {
2046 return m_lock.ReadPixelFloat(p);
2047 }
2048
2067 void WritePixel(const PointRaw& p, ColorRaw c) { m_lock.WritePixel(p, c); }
2068
2084 void WritePixelFloat(const PointRaw& p, const FColorRaw& c)
2085 {
2086 m_lock.WritePixelFloat(p, c);
2087 }
2088
2090 constexpr int GetWidth() const { return m_lock.GetWidth(); }
2091
2093 constexpr int GetHeight() const { return m_lock.GetHeight(); }
2094
2096 constexpr Point GetSize() const { return m_lock.GetSize(); }
2097
2099 constexpr int GetPitch() const { return m_lock.GetPitch(); }
2100
2102 constexpr PixelFormat GetFormat() const { return m_lock.GetFormat(); }
2103
2105 constexpr void* GetPixels() const { return m_lock.GetPixels(); }
2106
2118 void reset();
2119
2121 SurfaceRef resource() const { return m_lock; }
2122
2124 void release() { m_lock.release(); }
2125};
2126
2144inline Surface CreateSurface(const PointRaw& size, PixelFormat format)
2145{
2146 return Surface(size, format);
2147}
2148
2149inline Surface::Surface(const PointRaw& size, PixelFormat format)
2150 : Surface(CheckError(SDL_CreateSurface(size.x, size.y, format)))
2151{
2152}
2153
2154inline Surface::Surface(const PointRaw& size,
2155 PixelFormat format,
2156 void* pixels,
2157 int pitch)
2158 : Surface(
2159 CheckError(SDL_CreateSurfaceFrom(size.x, size.y, format, pixels, pitch)))
2160{
2161}
2162
2190 PixelFormat format,
2191 void* pixels,
2192 int pitch)
2193{
2194 return Surface(size, format, pixels, pitch);
2195}
2196
2211inline void DestroySurface(SurfaceRaw surface) { SDL_DestroySurface(surface); }
2212
2214
2253{
2254 return {CheckError(SDL_GetSurfaceProperties(surface))};
2255}
2256
2258{
2260}
2261
2274namespace prop::Surface {
2275
2276constexpr auto SDR_WHITE_POINT_FLOAT = SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT;
2277
2278constexpr auto HDR_HEADROOM_FLOAT = SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT;
2279
2280constexpr auto TONEMAP_OPERATOR_STRING =
2281 SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING;
2282
2283#if SDL_VERSION_ATLEAST(3, 2, 6)
2284
2285constexpr auto HOTSPOT_X_NUMBER = SDL_PROP_SURFACE_HOTSPOT_X_NUMBER;
2286
2287constexpr auto HOTSPOT_Y_NUMBER = 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 = SDL_PROP_SURFACE_ROTATION_FLOAT;
2294
2295#endif // SDL_VERSION_ATLEAST(3, 4, 0)
2296
2297} // namespace prop::Surface
2298
2316inline void SetSurfaceColorspace(SurfaceRef surface, Colorspace colorspace)
2317{
2318 CheckError(SDL_SetSurfaceColorspace(surface, colorspace));
2319}
2320
2321inline void Surface::SetColorspace(Colorspace colorspace)
2322{
2323 SDL::SetSurfaceColorspace(get(), colorspace);
2324}
2325
2345{
2346 return SDL_GetSurfaceColorspace(surface);
2347}
2348
2350{
2352}
2353
2382{
2383 return Palette::Borrow(CheckError(SDL_CreateSurfacePalette(surface)));
2384}
2385
2390
2411inline void SetSurfacePalette(SurfaceRef surface, PaletteRef palette)
2412{
2413 CheckError(SDL_SetSurfacePalette(surface, palette));
2414}
2415
2417{
2418 SDL::SetSurfacePalette(get(), palette);
2419}
2420
2435{
2436 return Palette::Borrow(SDL_GetSurfacePalette(surface));
2437}
2438
2440{
2441 return SDL::GetSurfacePalette(get());
2442}
2443
2470{
2471 CheckError(SDL_AddSurfaceAlternateImage(surface, image));
2472}
2473
2475{
2477}
2478
2494{
2495 return SDL_SurfaceHasAlternateImages(surface);
2496}
2497
2499{
2501}
2502
2527{
2528 int count = 0;
2529 auto data = SDL_GetSurfaceImages(surface, &count);
2530 return OwnArray<SurfaceRaw>(CheckError(data), count);
2531}
2532
2534{
2535 return SDL::GetSurfaceImages(get());
2536}
2537
2556{
2557 SDL_RemoveSurfaceAlternateImages(surface);
2558}
2559
2564
2590inline void LockSurface(SurfaceRef surface)
2591{
2592 CheckError(SDL_LockSurface(surface));
2593}
2594
2595inline SurfaceLock Surface::Lock() { return {SurfaceRef(*this)}; }
2596
2598 : m_lock(resource)
2599{
2600 LockSurface(m_lock);
2601}
2602
2616inline void UnlockSurface(SurfaceRef surface) { SDL_UnlockSurface(surface); }
2617
2618inline void Surface::Unlock(SurfaceLock&& lock)
2619{
2620 SDL_assert_paranoid(lock.resource() == *this);
2621 std::move(lock).reset();
2622}
2623
2625{
2626 if (!m_lock) return;
2627 UnlockSurface(m_lock);
2628 m_lock = {};
2629}
2630
2631#if !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC) && \
2632 SDL_VERSION_ATLEAST(3, 4, 0)
2633
2650inline Surface LoadSurface_IO(IOStreamRef src, bool closeio = false)
2651{
2652 return Surface{SDL_LoadSurface_IO(src, closeio)};
2653}
2654
2669inline Surface LoadSurface(StringParam file)
2670{
2671 return Surface{SDL_LoadSurface(file)};
2672}
2673
2674#endif // !defined(SDL3PP_ENABLE_IMAGE) && SDL_VERSION_ATLEAST(3, 4, 0)
2675
2696inline Surface LoadBMP_IO(IOStreamRef src, bool closeio = false)
2697{
2698 return Surface(SDL_LoadBMP_IO(src, closeio));
2699}
2700
2719inline Surface LoadBMP(StringParam file) { return Surface(SDL_LoadBMP(file)); }
2720
2744inline void SaveBMP_IO(SurfaceConstRef surface,
2745 IOStreamRef dst,
2746 bool closeio = false)
2747{
2748 CheckError(SDL_SaveBMP_IO(surface, dst, closeio));
2749}
2750
2751inline void Surface::SaveBMP_IO(IOStreamRef dst, bool closeio) const
2752{
2753 SDL::SaveBMP_IO(get(), dst, closeio);
2754}
2755
2777inline void SaveBMP(SurfaceConstRef surface, StringParam file)
2778{
2779 CheckError(SDL_SaveBMP(surface, file));
2780}
2781
2782inline void Surface::SaveBMP(StringParam file) const
2783{
2784 SDL::SaveBMP(get(), std::move(file));
2785}
2786
2787#if SDL_VERSION_ATLEAST(3, 4, 0)
2788
2810inline Surface LoadTrustedPNG_IO(IOStreamRef src, bool closeio = false)
2811{
2812 return Surface(SDL_LoadPNG_IO(src, closeio));
2813}
2814
2838{
2839 return Surface(SDL_LoadPNG(file));
2840}
2841
2842#if !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2843
2845inline Surface LoadPNG_IO(IOStreamRef src, bool closeio = false)
2846{
2847 return LoadTrustedPNG_IO(src, closeio);
2848}
2849
2851inline Surface LoadPNG(StringParam file)
2852{
2853 return LoadTrustedPNG(std::move(file));
2854}
2855
2856#endif // !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2857
2876 IOStreamRef dst,
2877 bool closeio = false)
2878{
2879 CheckError(SDL_SavePNG_IO(surface, dst, closeio));
2880}
2881
2882#if !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2883inline void Surface::SavePNG_IO(IOStreamRef dst, bool closeio) const
2884{
2885 SDL::SaveTrustedPNG_IO(get(), dst, closeio);
2886}
2887#endif // !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2888
2905{
2906 CheckError(SDL_SavePNG(surface, file));
2907}
2908
2909#if !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2910inline void Surface::SavePNG(StringParam file) const
2911{
2912 SDL::SaveTrustedPNG(get(), std::move(file));
2913}
2914#endif // !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2915
2916#endif // SDL_VERSION_ATLEAST(3, 4, 0)
2917
2937inline void SetSurfaceRLE(SurfaceRef surface, bool enabled)
2938{
2939 CheckError(SDL_SetSurfaceRLE(surface, enabled));
2940}
2941
2942inline void Surface::SetRLE(bool enabled)
2943{
2944 SDL::SetSurfaceRLE(get(), enabled);
2945}
2946
2961inline bool SurfaceHasRLE(SurfaceConstRef surface)
2962{
2963 return SDL_SurfaceHasRLE(surface);
2964}
2965
2966inline bool Surface::HasRLE() const { return SDL::SurfaceHasRLE(get()); }
2967
2990inline void SetSurfaceColorKey(SurfaceRef surface, std::optional<Uint32> key)
2991{
2992 CheckError(SDL_SetSurfaceColorKey(surface, key.has_value(), key.value_or(0)));
2993}
2994
2995inline void Surface::SetColorKey(std::optional<Uint32> key)
2996{
2998}
2999
3011{
3012 SetSurfaceColorKey(surface, std::nullopt);
3013}
3014
3016
3033{
3034 return SDL_SurfaceHasColorKey(surface);
3035}
3036
3037inline bool Surface::HasColorKey() const
3038{
3039 return SDL::SurfaceHasColorKey(get());
3040}
3041
3061inline std::optional<Uint32> GetSurfaceColorKey(SurfaceConstRef surface)
3062{
3063 if (Uint32 key; SDL_GetSurfaceColorKey(surface, &key)) return key;
3064 return std::nullopt;
3065}
3066
3067inline std::optional<Uint32> Surface::GetColorKey() const
3068{
3069 return SDL::GetSurfaceColorKey(get());
3070}
3071
3095inline void SetSurfaceColorMod(SurfaceRef surface, Uint8 r, Uint8 g, Uint8 b)
3096{
3097 CheckError(SDL_SetSurfaceColorMod(surface, r, g, b));
3098}
3099
3101{
3102 SDL::SetSurfaceColorMod(get(), r, g, b);
3103}
3104
3123 Uint8* r,
3124 Uint8* g,
3125 Uint8* b)
3126{
3127 CheckError(SDL_GetSurfaceColorMod(surface, r, g, b));
3128}
3129
3130inline void Surface::GetColorMod(Uint8* r, Uint8* g, Uint8* b) const
3131{
3132 SDL::GetSurfaceColorMod(get(), r, g, b);
3133}
3134
3155inline void SetSurfaceAlphaMod(SurfaceRef surface, Uint8 alpha)
3156{
3157 CheckError(SDL_SetSurfaceAlphaMod(surface, alpha));
3158}
3159
3160inline void Surface::SetAlphaMod(Uint8 alpha)
3161{
3162 SDL::SetSurfaceAlphaMod(get(), alpha);
3163}
3164
3180{
3181 Uint8 alpha;
3182 CheckError(SDL_GetSurfaceAlphaMod(surface, &alpha));
3183 return alpha;
3184}
3185
3187{
3188 return SDL::GetSurfaceAlphaMod(get());
3189}
3190
3206inline void SetSurfaceMod(SurfaceRef surface, Color color)
3207{
3208 SetSurfaceColorMod(surface, color.r, color.g, color.b);
3209 SetSurfaceAlphaMod(surface, color.a);
3210}
3211
3212inline void Surface::SetMod(Color color) { SetSurfaceMod(get(), color); }
3213
3223{
3224 Color c;
3225 GetSurfaceColorMod(surface, &c.r, &c.g, &c.b);
3226 c.a = GetSurfaceAlphaMod(surface);
3227 return c;
3228}
3229
3230inline Color Surface::GetMod() const { return SDL::GetSurfaceMod(get()); }
3231
3250inline void SetSurfaceBlendMode(SurfaceRef surface, BlendMode blendMode)
3251{
3252 CheckError(SDL_SetSurfaceBlendMode(surface, blendMode));
3253}
3254
3255inline void Surface::SetBlendMode(BlendMode blendMode)
3256{
3257 SDL::SetSurfaceBlendMode(get(), blendMode);
3258}
3259
3274{
3275 BlendMode blendmode;
3276 CheckError(SDL_GetSurfaceBlendMode(surface, &blendmode));
3277 return blendmode;
3278}
3279
3281{
3282 return SDL::GetSurfaceBlendMode(get());
3283}
3284
3307inline bool SetSurfaceClipRect(SurfaceRef surface,
3309{
3310 return SDL_SetSurfaceClipRect(surface, rect);
3311}
3312
3314{
3315 return SDL::SetSurfaceClipRect(get(), rect);
3316}
3317
3324{
3325 SetSurfaceClipRect(surface, std::nullopt);
3326}
3327
3329
3349{
3350 Rect r;
3351 CheckError(SDL_GetSurfaceClipRect(surface, &r));
3352 return r;
3353}
3354
3356{
3357 return SDL::GetSurfaceClipRect(get());
3358}
3359
3372inline void FlipSurface(SurfaceRef surface, FlipMode flip)
3373{
3374 CheckError(SDL_FlipSurface(surface, flip));
3375}
3376
3377inline void Surface::Flip(FlipMode flip) { SDL::FlipSurface(get(), flip); }
3378
3379#if SDL_VERSION_ATLEAST(3, 4, 0)
3380
3408inline Surface RotateSurface(SurfaceRef surface, float angle)
3409{
3410 return Surface{SDL_RotateSurface(surface, angle)};
3411}
3412
3413inline Surface Surface::Rotate(float angle)
3414{
3415 return SDL::RotateSurface(get(), angle);
3416}
3417
3418#endif // SDL_VERSION_ATLEAST(3, 4, 0)
3419
3440{
3441 return Surface(SDL_DuplicateSurface(surface));
3442}
3443
3445{
3446 return SDL::DuplicateSurface(get());
3447}
3448
3469 const PointRaw& size,
3470 ScaleMode scaleMode)
3471{
3472 return Surface(SDL_ScaleSurface(surface, size.x, size.y, scaleMode));
3473}
3474
3475inline Surface Surface::Scale(const PointRaw& size, ScaleMode scaleMode) const
3476{
3477 return SDL::ScaleSurface(get(), size, scaleMode);
3478}
3479
3508{
3509 return Surface(SDL_ConvertSurface(surface, format));
3510}
3511
3513{
3514 return SDL::ConvertSurface(get(), format);
3515}
3516
3546 PixelFormat format,
3547 PaletteRef palette,
3548 Colorspace colorspace,
3549 PropertiesRef props)
3550{
3551 return Surface{SDL_ConvertSurfaceAndColorspace(
3552 surface, format, palette, colorspace, props)};
3553}
3554
3556 PaletteRef palette,
3557 Colorspace colorspace,
3558 PropertiesRef props) const
3559{
3561 get(), format, palette, colorspace, props);
3562}
3563
3584inline void ConvertPixels(const PointRaw& size,
3585 PixelFormat src_format,
3586 const void* src,
3587 int src_pitch,
3588 PixelFormat dst_format,
3589 void* dst,
3590 int dst_pitch)
3591{
3592 CheckError(SDL_ConvertPixels(
3593 size.x, size.y, src_format, src, src_pitch, dst_format, dst, dst_pitch));
3594}
3595
3625inline void ConvertPixelsAndColorspace(const PointRaw& size,
3626 PixelFormat src_format,
3627 Colorspace src_colorspace,
3628 PropertiesRef src_properties,
3629 const void* src,
3630 int src_pitch,
3631 PixelFormat dst_format,
3632 Colorspace dst_colorspace,
3633 PropertiesRef dst_properties,
3634 void* dst,
3635 int dst_pitch)
3636{
3637 CheckError(SDL_ConvertPixelsAndColorspace(size.x,
3638 size.y,
3639 src_format,
3640 src_colorspace,
3641 src_properties,
3642 src,
3643 src_pitch,
3644 dst_format,
3645 dst_colorspace,
3646 dst_properties,
3647 dst,
3648 dst_pitch));
3649}
3650
3673inline void PremultiplyAlpha(const PointRaw& size,
3674 PixelFormat src_format,
3675 const void* src,
3676 int src_pitch,
3677 PixelFormat dst_format,
3678 void* dst,
3679 int dst_pitch,
3680 bool linear)
3681{
3682 CheckError(SDL_PremultiplyAlpha(size.x,
3683 size.y,
3684 src_format,
3685 src,
3686 src_pitch,
3687 dst_format,
3688 dst,
3689 dst_pitch,
3690 linear));
3691}
3692
3708inline void PremultiplySurfaceAlpha(SurfaceRef surface, bool linear)
3709{
3710 CheckError(SDL_PremultiplySurfaceAlpha(surface, linear));
3711}
3712
3713inline void Surface::PremultiplyAlpha(bool linear)
3714{
3716}
3717
3735inline void ClearSurface(SurfaceRef surface, const FColorRaw& c)
3736{
3737 CheckError(SDL_ClearSurface(surface, c.r, c.g, c.b, c.a));
3738}
3739
3740inline void Surface::Clear(const FColorRaw& c) { SDL::ClearSurface(get(), c); }
3741
3769 Uint32 color)
3770{
3771 CheckError(SDL_FillSurfaceRect(dst, rect, color));
3772}
3773
3775{
3776 SDL::FillSurfaceRect(get(), rect, color);
3777}
3778
3790inline void FillSurface(SurfaceRef dst, Uint32 color)
3791{
3792 FillSurfaceRect(dst, std::nullopt, color);
3793}
3794
3795inline void Surface::Fill(Uint32 color) { SDL::FillSurface(get(), color); }
3796
3823 Uint32 color)
3824{
3825 CheckError(
3826 SDL_FillSurfaceRects(dst, rects.data(), narrowS32(rects.size()), color));
3827}
3828
3830{
3831 SDL::FillSurfaceRects(get(), rects, color);
3832}
3833
3904inline void BlitSurface(SurfaceRef src,
3906 SurfaceRef dst,
3908{
3909 CheckError(SDL_BlitSurface(src, srcrect, dst, dstrect));
3910}
3911
3915{
3916 SDL::BlitSurface(src, srcrect, get(), dstrect);
3917}
3918
3921 const PointRaw& dstpos)
3922{
3923 Blit(src, srcrect, Rect{dstpos, {}});
3924}
3925
3995 SurfaceRef dst,
3996 const PointRaw& dstpos)
3997{
3998 BlitSurface(src, srcrect, dst, SDL_Rect{dstpos.x, dstpos.y, 0, 0});
3999}
4000
4023 const RectRaw& srcrect,
4024 SurfaceRef dst,
4025 const RectRaw& dstrect)
4026{
4027 CheckError(SDL_BlitSurfaceUnchecked(src, &srcrect, dst, &dstrect));
4028}
4029
4031 const RectRaw& srcrect,
4032 const RectRaw& dstrect)
4033{
4034 SDL::BlitSurfaceUnchecked(src, srcrect, get(), dstrect);
4035}
4036
4060 SurfaceRef dst,
4062 ScaleMode scaleMode)
4063{
4064 CheckError(SDL_BlitSurfaceScaled(src, srcrect, dst, dstrect, scaleMode));
4065}
4066
4070 ScaleMode scaleMode)
4071{
4072 SDL::BlitSurfaceScaled(src, srcrect, get(), dstrect, scaleMode);
4073}
4074
4098 const RectRaw& srcrect,
4099 SurfaceRef dst,
4100 const RectRaw& dstrect,
4101 ScaleMode scaleMode)
4102{
4103 CheckError(
4104 SDL_BlitSurfaceUncheckedScaled(src, &srcrect, dst, &dstrect, scaleMode));
4105}
4106
4108 const RectRaw& srcrect,
4109 const RectRaw& dstrect,
4110 ScaleMode scaleMode)
4111{
4112 SDL::BlitSurfaceUncheckedScaled(src, srcrect, get(), dstrect, scaleMode);
4113}
4114
4115#if SDL_VERSION_ATLEAST(3, 4, 0)
4116
4138 OptionalRef<RectRaw> srcrect,
4139 SurfaceRef dst,
4140 OptionalRef<RectRaw> dstrect,
4141 ScaleMode scaleMode)
4142{
4143 CheckError(SDL_StretchSurface(src, srcrect, dst, dstrect, scaleMode));
4144}
4145
4147 OptionalRef<RectRaw> srcrect,
4148 OptionalRef<RectRaw> dstrect,
4149 ScaleMode scaleMode)
4150{
4151 SDL::StretchSurface(src, srcrect, get(), dstrect, scaleMode);
4152}
4153
4154#endif // SDL_VERSION_ATLEAST(3, 4, 0)
4155
4180 SurfaceRef dst,
4182{
4183 CheckError(SDL_BlitSurfaceTiled(src, srcrect, dst, dstrect));
4184}
4185
4189{
4190 SDL::BlitSurfaceTiled(src, srcrect, get(), dstrect);
4191}
4192
4221 float scale,
4222 ScaleMode scaleMode,
4223 SurfaceRef dst,
4225{
4226 CheckError(SDL_BlitSurfaceTiledWithScale(
4227 src, srcrect, scale, scaleMode, dst, dstrect));
4228}
4229
4232 float scale,
4233 ScaleMode scaleMode,
4235{
4237 src, srcrect, scale, scaleMode, get(), dstrect);
4238}
4239
4275 int left_width,
4276 int right_width,
4277 int top_height,
4278 int bottom_height,
4279 SurfaceRef dst,
4281 float scale = 1,
4282 ScaleMode scaleMode = SCALEMODE_NEAREST)
4283{
4284 CheckError(SDL_BlitSurface9Grid(src,
4285 srcrect,
4286 left_width,
4287 right_width,
4288 top_height,
4289 bottom_height,
4290 scale,
4291 scaleMode,
4292 dst,
4293 dstrect));
4294}
4295
4298 int left_width,
4299 int right_width,
4300 int top_height,
4301 int bottom_height,
4303 float scale,
4304 ScaleMode scaleMode)
4305{
4307 srcrect,
4308 left_width,
4309 right_width,
4310 top_height,
4311 bottom_height,
4312 get(),
4313 dstrect,
4314 scale,
4315 scaleMode);
4316}
4317
4350{
4351 return SDL_MapSurfaceRGB(surface, r, g, b);
4352}
4353
4355{
4356 return SDL::MapSurfaceRGB(get(), r, g, b);
4357}
4358
4389{
4390 return SDL_MapSurfaceRGBA(surface, c.r, c.g, c.b, c.a);
4391}
4392
4394{
4395 return SDL::MapSurfaceRGBA(get(), c);
4396}
4397
4425 const PointRaw& p,
4426 Uint8* r,
4427 Uint8* g,
4428 Uint8* b,
4429 Uint8* a)
4430{
4431 CheckError(SDL_ReadSurfacePixel(surface, p.x, p.y, r, g, b, a));
4432}
4433
4454{
4455 Color c;
4456 ReadSurfacePixel(surface, p, &c.r, &c.g, &c.b, &c.a);
4457 return c;
4458}
4459
4486inline void ReadSurfacePixel(const SurfaceLock& lock,
4487 const PointRaw& p,
4488 Uint8* r,
4489 Uint8* g,
4490 Uint8* b,
4491 Uint8* a)
4492{
4493 lock.ReadPixel(p, r, g, b, a);
4494}
4495
4515inline Color ReadSurfacePixel(const SurfaceLock& lock, const PointRaw& p)
4516{
4517 return lock.ReadPixel(p);
4518}
4519
4520inline void Surface::ReadPixel(const PointRaw& p,
4521 Uint8* r,
4522 Uint8* g,
4523 Uint8* b,
4524 Uint8* a) const
4525{
4526 SDL::ReadSurfacePixel(get(), p, r, g, b, a);
4527}
4528
4529inline Color Surface::ReadPixel(const PointRaw& p) const
4530{
4531 return SDL::ReadSurfacePixel(get(), p);
4532}
4533
4558 const PointRaw& p,
4559 float* r,
4560 float* g,
4561 float* b,
4562 float* a)
4563{
4564 CheckError(SDL_ReadSurfacePixelFloat(surface, p.x, p.y, r, g, b, a));
4565}
4566
4584{
4585 FColor c;
4586 ReadSurfacePixelFloat(surface, p, &c.r, &c.g, &c.b, &c.a);
4587 return c;
4588}
4589
4613inline void ReadSurfacePixelFloat(const SurfaceLock& lock,
4614 const PointRaw& p,
4615 float* r,
4616 float* g,
4617 float* b,
4618 float* a)
4619{
4620 lock.ReadPixelFloat(p, r, g, b, a);
4621}
4622
4640{
4641 return lock.ReadPixelFloat(p);
4642}
4643
4645 float* r,
4646 float* g,
4647 float* b,
4648 float* a) const
4649{
4650 SDL::ReadSurfacePixelFloat(get(), p, r, g, b, a);
4651}
4652
4654{
4655 return SDL::ReadSurfacePixelFloat(get(), p);
4656}
4657
4677inline void WriteSurfacePixel(SurfaceRef surface, const PointRaw& p, ColorRaw c)
4678{
4679 CheckError(SDL_WriteSurfacePixel(surface, p.x, p.y, c.r, c.g, c.b, c.a));
4680}
4681
4701inline void WriteSurfacePixel(SurfaceLock& lock, const PointRaw& p, ColorRaw c)
4702{
4703 lock.WritePixel(p, c);
4704}
4705
4706inline void Surface::WritePixel(const PointRaw& p, ColorRaw c)
4707{
4708 SDL::WriteSurfacePixel(get(), p, c);
4709}
4710
4728 const PointRaw& p,
4729 const FColorRaw& c)
4730{
4731 CheckError(SDL_WriteSurfacePixelFloat(surface, p.x, p.y, c.r, c.g, c.b, c.a));
4732}
4733
4751 const PointRaw& p,
4752 const FColorRaw& c)
4753{
4754 lock.WritePixelFloat(p, c);
4755}
4756
4757inline void Surface::WritePixelFloat(const PointRaw& p, const FColorRaw& c)
4758{
4760}
4761
4763constexpr int GetSurfaceWidth(SurfaceConstRef surface) { return surface->w; }
4764
4766constexpr int GetSurfaceWidth(const SurfaceLock& lock)
4767{
4768 return lock.GetWidth();
4769}
4770
4771constexpr int Surface::GetWidth() const { return SDL::GetSurfaceWidth(get()); }
4772
4774constexpr int GetSurfaceHeight(SurfaceConstRef surface) { return surface->h; }
4775
4777constexpr int GetSurfaceHeight(const SurfaceLock& lock)
4778{
4779 return lock.GetHeight();
4780}
4781
4782constexpr int Surface::GetHeight() const
4783{
4784 return SDL::GetSurfaceHeight(get());
4785}
4786
4789{
4790 return Point(surface->w, surface->h);
4791}
4792
4794constexpr Point GetSurfaceSize(const SurfaceLock& lock)
4795{
4796 return lock.GetSize();
4797}
4798
4799constexpr Point Surface::GetSize() const { return SDL::GetSurfaceSize(get()); }
4800
4802constexpr int GetSurfacePitch(SurfaceConstRef surface)
4803{
4804 return surface->pitch;
4805}
4806
4808constexpr int GetSurfacePitch(const SurfaceLock& lock)
4809{
4810 return lock.GetPitch();
4811}
4812
4813constexpr int Surface::GetPitch() const { return SDL::GetSurfacePitch(get()); }
4814
4817{
4818 return surface->format;
4819}
4820
4823{
4824 return lock.GetFormat();
4825}
4826
4828{
4829 return SDL::GetSurfaceFormat(get());
4830}
4831
4833constexpr void* GetSurfacePixels(SurfaceConstRef surface)
4834{
4835 return surface->pixels;
4836}
4837
4839constexpr void* GetSurfacePixels(const SurfaceLock& lock)
4840{
4841 return lock.GetPixels();
4842}
4843
4844constexpr void* Surface::GetPixels() const
4845{
4846 return SDL::GetSurfacePixels(get());
4847}
4848
4850
4851} // namespace SDL
4852
4853#endif /* SDL3PP_SURFACE_H_ */
Colorspace definitions.
Definition SDL3pp_pixels.h:1607
Optional-like shim for references.
Definition SDL3pp_optionalRef.h:20
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:44
Pixel format.
Definition SDL3pp_pixels.h:358
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:53
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:56
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
Const reference wrapper for a given resource,.
Definition SDL3pp_resource.h:111
span-like for empty-derived structs
Definition SDL3pp_spanRef.h:24
constexpr T * data() const
Retrieves contained data.
Definition SDL3pp_spanRef.h:75
constexpr size_t size() const
Retrieves contained size.
Definition SDL3pp_spanRef.h:69
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
Set up a surface for directly accessing the pixels.
Definition SDL3pp_surface.h:1879
SurfaceRef resource() const
Get the reference to locked resource.
Definition SDL3pp_surface.h:2121
constexpr PixelFormat GetFormat() const
Get the pixel format.
Definition SDL3pp_surface.h:2102
SurfaceLock(SurfaceLock &&other) noexcept
Move constructor.
Definition SDL3pp_surface.h:1914
FColor ReadPixelFloat(const PointRaw &p) const
Retrieves a single pixel from a surface.
Definition SDL3pp_surface.h:2044
~SurfaceLock()
Release a surface after directly accessing the pixels.
Definition SDL3pp_surface.h:1930
constexpr int GetHeight() const
Get the height in pixels.
Definition SDL3pp_surface.h:2093
constexpr int GetWidth() const
Get the width in pixels.
Definition SDL3pp_surface.h:2090
constexpr void * GetPixels() const
Get the pixels.
Definition SDL3pp_surface.h:2105
void release()
Releases the lock without unlocking.
Definition SDL3pp_surface.h:2124
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:1969
void WritePixelFloat(const PointRaw &p, const FColorRaw &c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:2084
SurfaceLock & operator=(SurfaceLock &&other) noexcept
Assignment operator.
Definition SDL3pp_surface.h:1935
void WritePixel(const PointRaw &p, ColorRaw c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:2067
constexpr Point GetSize() const
Get the size in pixels.
Definition SDL3pp_surface.h:2096
Color ReadPixel(const PointRaw &p) const
Retrieves a single pixel from a surface.
Definition SDL3pp_surface.h:1996
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:2020
constexpr int GetPitch() const
Get pitch in bytes.
Definition SDL3pp_surface.h:2099
#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
ResourceRef< IOStream > IOStreamRef
Reference for IOStream.
Definition SDL3pp_iostream.h:34
SDL_Color ColorRaw
Alias to raw representation for Color.
Definition SDL3pp_pixels.h:83
SDL_FColor FColorRaw
Alias to raw representation for FColor.
Definition SDL3pp_pixels.h:89
ResourceRef< Palette > PaletteRef
Reference for Palette.
Definition SDL3pp_pixels.h:108
ResourceRef< Properties > PropertiesRef
Reference for Properties.
Definition SDL3pp_properties.h:54
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
void Save(StringParam filename) const
Save an Surface into an image file.
Definition SDL3pp_image.h:2246
Surface LoadPNG_IO(IOStreamRef src)
Load a PNG image directly.
Definition SDL3pp_image.h:1736
Surface LoadPNG(StringParam file)
Load a PNG image from a file.
Definition SDL3pp_image.h:1814
void SaveTyped_IO(IOStreamRef dst, StringParam type, bool closeio=false) const
Save an Surface into formatted image data, via an IOStream.
Definition SDL3pp_image.h:2290
void SavePNG(StringParam file) const
Save a surface to a file in PNG format.
Definition SDL3pp_image.h:2546
Surface LoadSurface_IO(IOStreamRef src, bool closeio=false)
Load an image from an SDL data source into a software surface.
Definition SDL3pp_image.h:212
void SavePNG_IO(IOStreamRef dst, bool closeio=false) const
Save a surface to a seekable SDL data stream in PNG format.
Definition SDL3pp_image.h:2576
Surface LoadSurface(StringParam file)
Load an image from a filesystem path into a software surface.
Definition SDL3pp_image.h:155
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition SDL3pp_stdinc.h:290
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition SDL3pp_stdinc.h:238
SurfaceLock(SurfaceRef resource)
Set up a surface for directly accessing the pixels.
Definition SDL3pp_surface.h:2597
Rect GetClipRect() const
Get the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3355
Palette GetPalette() const
Get the palette used by a surface.
Definition SDL3pp_surface.h:2439
std::optional< Uint32 > GetColorKey() const
Get the color key (transparent pixel) for a surface.
Definition SDL3pp_surface.h:3067
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:4186
Palette CreateSurfacePalette(SurfaceRef surface)
Create a palette and associate it with a surface.
Definition SDL3pp_surface.h:2381
void SaveTrustedPNG(SurfaceConstRef surface, StringParam file)
Save a surface to a file in PNG format.
Definition SDL3pp_surface.h:2904
constexpr FlipMode FLIP_VERTICAL
flip vertically
Definition SDL3pp_surface.h:133
constexpr PixelFormat GetFormat() const
Get the pixel format.
Definition SDL3pp_surface.h:4827
Surface LoadBMP_IO(IOStreamRef src, bool closeio=false)
Load a BMP image from a seekable SDL data stream.
Definition SDL3pp_surface.h:2696
void Destroy()
Free this surface.
Definition SDL3pp_surface.h:2213
void SetSurfaceColorKey(SurfaceRef surface, std::optional< Uint32 > key)
Set the color key (transparent pixel) in a surface.
Definition SDL3pp_surface.h:2990
void AddAlternateImage(SurfaceRef image)
Add an alternate version of a surface.
Definition SDL3pp_surface.h:2474
void WriteSurfacePixel(SurfaceRef surface, const PointRaw &p, ColorRaw c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:4677
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:3993
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:4230
void AddSurfaceAlternateImage(SurfaceRef surface, SurfaceRef image)
Add an alternate version of a surface.
Definition SDL3pp_surface.h:2469
SDL_FlipMode FlipMode
The flip mode.
Definition SDL3pp_surface.h:127
void GetSurfaceColorMod(SurfaceConstRef surface, Uint8 *r, Uint8 *g, Uint8 *b)
Get the additional color value multiplied into blit operations.
Definition SDL3pp_surface.h:3122
void SetSurfaceMod(SurfaceRef surface, Color color)
Set an additional color and alpha value multiplied into blit operations.
Definition SDL3pp_surface.h:3206
constexpr SurfaceFlags SURFACE_SIMD_ALIGNED
Surface uses pixel memory allocated with aligned_alloc().
Definition SDL3pp_surface.h:81
BlendMode GetBlendMode() const
Get the blend mode used for blit operations.
Definition SDL3pp_surface.h:3280
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:4349
constexpr SurfaceFlags SURFACE_LOCK_NEEDED
Surface needs to be locked to access pixels.
Definition SDL3pp_surface.h:74
void SetSurfaceAlphaMod(SurfaceRef surface, Uint8 alpha)
Set an additional alpha value used in blit operations.
Definition SDL3pp_surface.h:3155
BlendMode GetSurfaceBlendMode(SurfaceConstRef surface)
Get the blend mode used for blit operations.
Definition SDL3pp_surface.h:3273
void RemoveSurfaceAlternateImages(SurfaceRef surface)
Remove all alternate versions of a surface.
Definition SDL3pp_surface.h:2555
void DestroySurface(SurfaceRaw surface)
Free a surface.
Definition SDL3pp_surface.h:2211
void ClearSurface(SurfaceRef surface, const FColorRaw &c)
Clear a surface with a specific color, with floating point precision.
Definition SDL3pp_surface.h:3735
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:3829
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:4354
bool HasRLE() const
Returns whether the surface is RLE enabled.
Definition SDL3pp_surface.h:2966
void LockSurface(SurfaceRef surface)
Set up a surface for directly accessing the pixels.
Definition SDL3pp_surface.h:2590
SDL_ScaleMode ScaleMode
The scaling mode.
Definition SDL3pp_surface.h:98
constexpr int GetHeight() const
Get the height in pixels.
Definition SDL3pp_surface.h:4782
constexpr FlipMode FLIP_NONE
Do not flip.
Definition SDL3pp_surface.h:129
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:3904
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:4273
OwnArray< SurfaceRaw > GetSurfaceImages(SurfaceConstRef surface)
Get an array including all versions of a surface.
Definition SDL3pp_surface.h:2526
constexpr bool MustLock(SurfaceConstRef S)
Evaluates to true if the surface needs to be locked before access.
Definition SDL3pp_surface.h:88
constexpr int GetSurfaceWidth(SurfaceConstRef surface)
Get the width in pixels.
Definition SDL3pp_surface.h:4763
Surface RotateSurface(SurfaceRef surface, float angle)
Return a copy of a surface rotated clockwise a number of degrees.
Definition SDL3pp_surface.h:3408
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:3767
void PremultiplySurfaceAlpha(SurfaceRef surface, bool linear)
Premultiply the alpha in a surface.
Definition SDL3pp_surface.h:3708
constexpr SurfaceFlags SURFACE_PREALLOCATED
Surface uses preallocated pixel memory.
Definition SDL3pp_surface.h:71
void SaveTrustedPNG_IO(SurfaceConstRef surface, IOStreamRef dst, bool closeio=false)
Save a surface to a seekable SDL data stream in PNG format.
Definition SDL3pp_surface.h:2875
bool HasColorKey() const
Returns whether the surface has a color key.
Definition SDL3pp_surface.h:3037
constexpr ScaleMode SCALEMODE_LINEAR
linear filtering
Definition SDL3pp_surface.h:109
void SetColorKey(std::optional< Uint32 > key)
Set the color key (transparent pixel) in a surface.
Definition SDL3pp_surface.h:2995
void PremultiplyAlpha(bool linear)
Premultiply the alpha in a surface.
Definition SDL3pp_surface.h:3713
void BlitSurfaceUnchecked(SurfaceRef src, const RectRaw &srcrect, SurfaceRef dst, const RectRaw &dstrect)
Perform low-level surface blitting only.
Definition SDL3pp_surface.h:4022
void SaveBMP(SurfaceConstRef surface, StringParam file)
Save a surface to a file in BMP format.
Definition SDL3pp_surface.h:2777
SDL_Surface * SurfaceRaw
Alias to raw representation for Surface.
Definition SDL3pp_surface.h:44
Palette CreatePalette()
Create a palette and associate it with a surface.
Definition SDL3pp_surface.h:2386
void reset()
Release a surface after directly accessing the pixels.
Definition SDL3pp_surface.h:2624
void SaveBMP_IO(IOStreamRef dst, bool closeio=false) const
Save a surface to a seekable SDL data stream in BMP format.
Definition SDL3pp_surface.h:2751
void WriteSurfacePixelFloat(SurfaceRef surface, const PointRaw &p, const FColorRaw &c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:4727
bool SetSurfaceClipRect(SurfaceRef surface, OptionalRef< const RectRaw > rect)
Set the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3307
Colorspace GetColorspace() const
Get the colorspace used by a surface.
Definition SDL3pp_surface.h:2349
constexpr PixelFormat GetSurfaceFormat(SurfaceConstRef surface)
Get the pixel format.
Definition SDL3pp_surface.h:4816
void SetSurfacePalette(SurfaceRef surface, PaletteRef palette)
Set the palette used by a surface.
Definition SDL3pp_surface.h:2411
constexpr ScaleMode SCALEMODE_NEAREST
nearest pixel sampling
Definition SDL3pp_surface.h:106
void Flip(FlipMode flip)
Flip a surface vertically or horizontally.
Definition SDL3pp_surface.h:3377
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:2189
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:3912
PropertiesRef GetSurfaceProperties(SurfaceConstRef surface)
Get the properties associated with a surface.
Definition SDL3pp_surface.h:2252
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:4219
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:3625
Colorspace GetSurfaceColorspace(SurfaceConstRef surface)
Get the colorspace used by a surface.
Definition SDL3pp_surface.h:2344
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:4058
Surface LoadBMP(StringParam file)
Load a BMP image from a file.
Definition SDL3pp_surface.h:2719
void ResetClipRect()
Disable the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3328
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:4178
Surface ConvertSurface(SurfaceConstRef surface, PixelFormat format)
Copy an existing surface to a new surface of the specified format.
Definition SDL3pp_surface.h:3507
PropertiesRef GetProperties() const
Get the properties associated with a surface.
Definition SDL3pp_surface.h:2257
Surface DuplicateSurface(SurfaceConstRef surface)
Creates a new surface identical to the existing surface.
Definition SDL3pp_surface.h:3439
constexpr ScaleMode SCALEMODE_PIXELART
nearest pixel sampling with improved scaling for pixel art, available since SDL 3....
Definition SDL3pp_surface.h:118
Palette GetSurfacePalette(SurfaceConstRef surface)
Get the palette used by a surface.
Definition SDL3pp_surface.h:2434
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:3468
constexpr SurfaceFlags SURFACE_LOCKED
Surface is currently locked.
Definition SDL3pp_surface.h:77
bool HasAlternateImages() const
Return whether a surface has alternate versions available.
Definition SDL3pp_surface.h:2498
const SDL_Surface * SurfaceRawConst
Alias to const raw representation for Surface.
Definition SDL3pp_surface.h:47
constexpr int GetPitch() const
Get pitch in bytes.
Definition SDL3pp_surface.h:4813
void BlitUncheckedScaled(SurfaceRef src, const RectRaw &srcrect, const RectRaw &dstrect, ScaleMode scaleMode)
Perform low-level surface scaled blitting only.
Definition SDL3pp_surface.h:4107
Uint8 GetSurfaceAlphaMod(SurfaceConstRef surface)
Get the additional alpha value used in blit operations.
Definition SDL3pp_surface.h:3179
bool SurfaceHasColorKey(SurfaceConstRef surface)
Returns whether the surface has a color key.
Definition SDL3pp_surface.h:3032
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:4146
void RemoveAlternateImages()
Remove all alternate versions of a surface.
Definition SDL3pp_surface.h:2560
Surface Convert(PixelFormat format) const
Copy an existing surface to a new surface of the specified format.
Definition SDL3pp_surface.h:3512
constexpr Point GetSize() const
Get the size in pixels.
Definition SDL3pp_surface.h:4799
void SetSurfaceBlendMode(SurfaceRef surface, BlendMode blendMode)
Set the blend mode used for blit operations.
Definition SDL3pp_surface.h:3250
Surface LoadTrustedPNG_IO(IOStreamRef src, bool closeio=false)
Load a PNG image from a seekable SDL data stream.
Definition SDL3pp_surface.h:2810
Uint8 GetAlphaMod() const
Get the additional alpha value used in blit operations.
Definition SDL3pp_surface.h:3186
Surface Duplicate() const
Creates a new surface identical to the existing surface.
Definition SDL3pp_surface.h:3444
void Clear(const FColorRaw &c)
Clear a surface with a specific color, with floating point precision.
Definition SDL3pp_surface.h:3740
void UnlockSurface(SurfaceRef surface)
Release a surface after directly accessing the pixels.
Definition SDL3pp_surface.h:2616
void SetMod(Color color)
Set an additional color and alpha value multiplied into blit operations.
Definition SDL3pp_surface.h:3212
bool SurfaceHasAlternateImages(SurfaceConstRef surface)
Return whether a surface has alternate versions available.
Definition SDL3pp_surface.h:2493
bool SurfaceHasRLE(SurfaceConstRef surface)
Returns whether the surface is RLE enabled.
Definition SDL3pp_surface.h:2961
void GetColorMod(Uint8 *r, Uint8 *g, Uint8 *b) const
Get the additional color value multiplied into blit operations.
Definition SDL3pp_surface.h:3130
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:4137
SurfaceLock Lock()
Set up a surface for directly accessing the pixels.
Definition SDL3pp_surface.h:2595
constexpr ScaleMode SCALEMODE_INVALID
INVALID.
Definition SDL3pp_surface.h:102
constexpr int GetWidth() const
Get the width in pixels.
Definition SDL3pp_surface.h:4771
void SetColorMod(Uint8 r, Uint8 g, Uint8 b)
Set an additional color value multiplied into blit operations.
Definition SDL3pp_surface.h:3100
void ClearSurfaceColorKey(SurfaceRef surface)
Unset the color key (transparent pixel) in a surface.
Definition SDL3pp_surface.h:3010
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:3673
void SetBlendMode(BlendMode blendMode)
Set the blend mode used for blit operations.
Definition SDL3pp_surface.h:3255
OwnArray< SurfaceRaw > GetImages() const
Get an array including all versions of a surface.
Definition SDL3pp_surface.h:2533
Surface Rotate(float angle)
Return a copy of a surface rotated clockwise a number of degrees.
Definition SDL3pp_surface.h:3413
Surface CreateSurface(const PointRaw &size, PixelFormat format)
Allocate a new surface with a specific pixel format.
Definition SDL3pp_surface.h:2144
void SetSurfaceColorMod(SurfaceRef surface, Uint8 r, Uint8 g, Uint8 b)
Set an additional color value multiplied into blit operations.
Definition SDL3pp_surface.h:3095
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:3821
void SetPalette(PaletteRef palette)
Set the palette used by a surface.
Definition SDL3pp_surface.h:2416
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:4097
constexpr FlipMode FLIP_HORIZONTAL
flip horizontally
Definition SDL3pp_surface.h:131
void SetSurfaceRLE(SurfaceRef surface, bool enabled)
Set the RLE acceleration hint for a surface.
Definition SDL3pp_surface.h:2937
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:3545
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:4520
constexpr void * GetSurfacePixels(SurfaceConstRef surface)
Get the pixels.
Definition SDL3pp_surface.h:4833
void SaveBMP_IO(SurfaceConstRef surface, IOStreamRef dst, bool closeio=false)
Save a surface to a seekable SDL data stream in BMP format.
Definition SDL3pp_surface.h:2744
Uint32 SurfaceFlags
The flags on an Surface.
Definition SDL3pp_surface.h:69
void Fill(Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition SDL3pp_surface.h:3795
ResourceConstRef< SurfaceRaw, SurfaceRawConst > SurfaceConstRef
Safely wrap Surface for non owning const parameters.
Definition SDL3pp_surface.h:57
constexpr int GetSurfaceHeight(SurfaceConstRef surface)
Get the height in pixels.
Definition SDL3pp_surface.h:4774
Uint32 MapRGBA(ColorRaw c) const
Map an RGBA quadruple to a pixel value for a surface.
Definition SDL3pp_surface.h:4393
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:3475
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:4296
void SetColorspace(Colorspace colorspace)
Set the colorspace used by a surface.
Definition SDL3pp_surface.h:2321
void ClearColorKey()
Unset the color key (transparent pixel) in a surface.
Definition SDL3pp_surface.h:3015
void WritePixel(const PointRaw &p, ColorRaw c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:4706
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:4557
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:4424
void BlitUnchecked(SurfaceRef src, const RectRaw &srcrect, const RectRaw &dstrect)
Perform low-level surface blitting only.
Definition SDL3pp_surface.h:4030
Color GetSurfaceMod(SurfaceConstRef surface)
Get the additional color and alpha value multiplied into blit operations.
Definition SDL3pp_surface.h:3222
Surface LoadTrustedPNG(StringParam file)
Load a PNG image from a file.
Definition SDL3pp_surface.h:2837
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:4067
void FillRect(OptionalRef< const RectRaw > rect, Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition SDL3pp_surface.h:3774
constexpr int GetSurfacePitch(SurfaceConstRef surface)
Get pitch in bytes.
Definition SDL3pp_surface.h:4802
void Unlock(SurfaceLock &&lock)
Release a surface after directly accessing the pixels.
Definition SDL3pp_surface.h:2618
constexpr Point GetSurfaceSize(SurfaceConstRef surface)
Get the size in pixels.
Definition SDL3pp_surface.h:4788
void SaveBMP(StringParam file) const
Save a surface to a file in BMP format.
Definition SDL3pp_surface.h:2782
void ResetSurfaceClipRect(SurfaceRef surface)
Disable the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3323
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:4644
std::optional< Uint32 > GetSurfaceColorKey(SurfaceConstRef surface)
Get the color key (transparent pixel) for a surface.
Definition SDL3pp_surface.h:3061
void SetAlphaMod(Uint8 alpha)
Set an additional alpha value used in blit operations.
Definition SDL3pp_surface.h:3160
constexpr void * GetPixels() const
Get the pixels.
Definition SDL3pp_surface.h:4844
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:3919
void SetSurfaceColorspace(SurfaceRef surface, Colorspace colorspace)
Set the colorspace used by a surface.
Definition SDL3pp_surface.h:2316
void SetRLE(bool enabled)
Set the RLE acceleration hint for a surface.
Definition SDL3pp_surface.h:2942
Uint32 MapSurfaceRGBA(SurfaceConstRef surface, ColorRaw c)
Map an RGBA quadruple to a pixel value for a surface.
Definition SDL3pp_surface.h:4388
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:3584
Color GetMod() const
Get the additional color and alpha value multiplied into blit operations.
Definition SDL3pp_surface.h:3230
void FlipSurface(SurfaceRef surface, FlipMode flip)
Flip a surface vertically or horizontally.
Definition SDL3pp_surface.h:3372
constexpr FlipMode FLIP_HORIZONTAL_AND_VERTICAL
flip horizontally and vertically (not a diagonal flip)
Definition SDL3pp_surface.h:138
bool SetClipRect(OptionalRef< const RectRaw > rect)
Set the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3313
Rect GetSurfaceClipRect(SurfaceConstRef surface)
Get the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3348
ResourceRef< Surface > SurfaceRef
Reference for Surface.
Definition SDL3pp_surface.h:54
void FillSurface(SurfaceRef dst, Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition SDL3pp_surface.h:3790
void WritePixelFloat(const PointRaw &p, const FColorRaw &c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:4757
Properties for Surface.
Definition SDL3pp_surface.h:2274
Main include header for the SDL3pp library.
Sint32 narrowS32(T value)
Narrows to Sint32.
Definition SDL3pp_stdinc.h:6257
A structure that represents a color as RGBA components.
Definition SDL3pp_pixels.h:2145
The bits of this structure can be directly reinterpreted as a float-packed color which uses the PIXEL...
Definition SDL3pp_pixels.h:2318
A set of indexed colors representing a palette.
Definition SDL3pp_pixels.h:2463
static Palette Borrow(PaletteRaw resource)
Safely borrows the from PaletteRaw.
Definition SDL3pp_pixels.h:2517
The structure that defines a point (using integers).
Definition SDL3pp_rect.h:97
A rectangle, with the origin at the upper left (using integers).
Definition SDL3pp_rect.h:859
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:156
A collection of pixels used in software blitting.
Definition SDL3pp_surface.h:172
Surface & operator=(const Surface &other)
Assignment operator.
Definition SDL3pp_surface.h:363
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
constexpr Surface & operator=(Surface &&other) noexcept
Assignment operator.
Definition SDL3pp_surface.h:356
constexpr Surface(SurfaceRaw resource) noexcept
Constructs from raw Surface.
Definition SDL3pp_surface.h:182
static Surface Borrow(SurfaceRaw resource)
Safely borrows the from SurfaceRaw.
Definition SDL3pp_surface.h:340
constexpr Surface(const Surface &other)
Copy constructor.
Definition SDL3pp_surface.h:188
constexpr Surface(Surface &&other) noexcept
Move constructor.
Definition SDL3pp_surface.h:195
~Surface()
Destructor.
Definition SDL3pp_surface.h:353
constexpr bool MustLock() const
Evaluates to true if the surface needs to be locked before access.
Definition SDL3pp_surface.h:391