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
430
447 void SetColorspace(Colorspace colorspace);
448
467
496
516 void SetPalette(PaletteRef palette);
517
530 Palette GetPalette() const;
531
555 void AddAlternateImage(SurfaceRef image);
556
570 bool HasAlternateImages() const;
571
591
608
634
646 void Unlock(SurfaceLock&& lock);
647
670 void SaveBMP_IO(IOStreamRef dst, bool closeio = false) const;
671
692 void SaveBMP(StringParam file) const;
693
713 void SavePNG_IO(IOStreamRef dst, bool closeio = false) const;
714
732 void SavePNG(StringParam file) const;
733
752 void SetRLE(bool enabled);
753
767 bool HasRLE() const;
768
790 void SetColorKey(std::optional<Uint32> key);
791
801 void ClearColorKey();
802
815 bool HasColorKey() const;
816
835 std::optional<Uint32> GetColorKey() const;
836
859 void SetColorMod(Uint8 r, Uint8 g, Uint8 b);
860
877 void GetColorMod(Uint8* r, Uint8* g, Uint8* b) const;
878
898 void SetAlphaMod(Uint8 alpha);
899
912 Uint8 GetAlphaMod() const;
913
928 void SetMod(Color color);
929
937 Color GetMod() const;
938
956 void SetBlendMode(BlendMode blendMode);
957
970 BlendMode GetBlendMode() const;
971
995
1001 void ResetClipRect();
1002
1020 Rect GetClipRect() const;
1021
1033 void Flip(FlipMode flip);
1034
1035#if SDL_VERSION_ATLEAST(3, 4, 0)
1036
1063 Surface Rotate(float angle);
1064
1065#endif // SDL_VERSION_ATLEAST(3, 4, 0)
1066
1083 Surface Duplicate() const;
1084
1101 Surface Scale(const PointRaw& size, ScaleMode scaleMode) const;
1102
1129 Surface Convert(PixelFormat format) const;
1130
1159 PaletteRef palette,
1160 Colorspace colorspace,
1161 PropertiesRef props) const;
1162
1177 void PremultiplyAlpha(bool linear);
1178
1195 void Clear(const FColorRaw& c);
1196
1221 void FillRect(OptionalRef<const RectRaw> rect, Uint32 color);
1222
1233 void Fill(Uint32 color);
1234
1258 void FillRects(SpanRef<const RectRaw> rects, Uint32 color);
1259
1329 void Blit(SurfaceRef src,
1332
1403 void BlitAt(SurfaceRef src,
1405 const PointRaw& dstpos);
1406
1427 void BlitUnchecked(SurfaceRef src,
1428 const RectRaw& srcrect,
1429 const RectRaw& dstrect);
1430
1451 void BlitScaled(SurfaceRef src,
1454 ScaleMode scaleMode);
1455
1478 const RectRaw& srcrect,
1479 const RectRaw& dstrect,
1480 ScaleMode scaleMode);
1481
1482#if SDL_VERSION_ATLEAST(3, 4, 0)
1483
1503 void Stretch(SurfaceRef src,
1504 OptionalRef<RectRaw> srcrect,
1505 OptionalRef<RectRaw> dstrect,
1506 ScaleMode scaleMode);
1507
1508#endif // SDL_VERSION_ATLEAST(3, 4, 0)
1509
1531 void BlitTiled(SurfaceRef src,
1534
1562 float scale,
1563 ScaleMode scaleMode,
1565
1598 void Blit9Grid(SurfaceRef src,
1600 int left_width,
1601 int right_width,
1602 int top_height,
1603 int bottom_height,
1605 float scale = 1,
1606 ScaleMode scaleMode = SCALEMODE_NEAREST);
1607
1638 Uint32 MapRGB(Uint8 r, Uint8 g, Uint8 b) const;
1639
1668 Uint32 MapRGBA(ColorRaw c) const;
1669
1695 void ReadPixel(const PointRaw& p,
1696 Uint8* r,
1697 Uint8* g,
1698 Uint8* b,
1699 Uint8* a) const;
1700
1716 Color ReadPixel(const PointRaw& p) const;
1717
1740 void ReadPixelFloat(const PointRaw& p,
1741 float* r,
1742 float* g,
1743 float* b,
1744 float* a) const;
1745
1761 FColor ReadPixelFloat(const PointRaw& p) const;
1762
1781 void WritePixel(const PointRaw& p, ColorRaw c);
1782
1798 void WritePixelFloat(const PointRaw& p, const FColorRaw& c);
1799
1801 constexpr int GetWidth() const;
1802
1804 constexpr int GetHeight() const;
1805
1807 constexpr Point GetSize() const;
1808
1810 constexpr int GetPitch() const;
1811
1813 constexpr PixelFormat GetFormat() const;
1814
1816 constexpr void* GetPixels() const;
1817
1832 void Save(StringParam filename) const;
1833
1855 void SaveTyped_IO(IOStreamRef dst,
1856 StringParam type,
1857 bool closeio = false) const;
1858};
1859
1878{
1879 Surface m_lock;
1880
1881public:
1908
1910 SurfaceLock(const SurfaceLock& other) = delete;
1911
1913 SurfaceLock(SurfaceLock&& other) noexcept
1914 : m_lock(std::move(other.m_lock))
1915 {
1916 }
1917
1930
1931 SurfaceLock& operator=(const SurfaceLock& other) = delete;
1932
1935 {
1936 std::swap(m_lock, other.m_lock);
1937 return *this;
1938 }
1939
1941 constexpr operator bool() const { return bool(m_lock); }
1942
1968 void ReadPixel(const PointRaw& p,
1969 Uint8* r,
1970 Uint8* g,
1971 Uint8* b,
1972 Uint8* a) const
1973 {
1974 m_lock.ReadPixel(p, r, g, b, a);
1975 }
1976
1995 Color ReadPixel(const PointRaw& p) const { return m_lock.ReadPixel(p); }
1996
2020 float* r,
2021 float* g,
2022 float* b,
2023 float* a) const
2024 {
2025 m_lock.ReadPixelFloat(p, r, g, b, a);
2026 }
2027
2044 {
2045 return m_lock.ReadPixelFloat(p);
2046 }
2047
2066 void WritePixel(const PointRaw& p, ColorRaw c) { m_lock.WritePixel(p, c); }
2067
2083 void WritePixelFloat(const PointRaw& p, const FColorRaw& c)
2084 {
2085 m_lock.WritePixelFloat(p, c);
2086 }
2087
2089 constexpr int GetWidth() const { return m_lock.GetWidth(); }
2090
2092 constexpr int GetHeight() const { return m_lock.GetHeight(); }
2093
2095 constexpr Point GetSize() const { return m_lock.GetSize(); }
2096
2098 constexpr int GetPitch() const { return m_lock.GetPitch(); }
2099
2101 constexpr PixelFormat GetFormat() const { return m_lock.GetFormat(); }
2102
2104 constexpr void* GetPixels() const { return m_lock.GetPixels(); }
2105
2117 void reset();
2118
2120 SurfaceRef resource() const { return m_lock; }
2121
2123 void release() { m_lock.release(); }
2124};
2125
2143inline Surface CreateSurface(const PointRaw& size, PixelFormat format)
2144{
2145 return Surface(size, format);
2146}
2147
2148inline Surface::Surface(const PointRaw& size, PixelFormat format)
2149 : Surface(CheckError(SDL_CreateSurface(size.x, size.y, format)))
2150{
2151}
2152
2153inline Surface::Surface(const PointRaw& size,
2154 PixelFormat format,
2155 void* pixels,
2156 int pitch)
2157 : Surface(
2158 CheckError(SDL_CreateSurfaceFrom(size.x, size.y, format, pixels, pitch)))
2159{
2160}
2161
2189 PixelFormat format,
2190 void* pixels,
2191 int pitch)
2192{
2193 return Surface(size, format, pixels, pitch);
2194}
2195
2210inline void DestroySurface(SurfaceRaw surface) { SDL_DestroySurface(surface); }
2211
2213
2252{
2253 return {CheckError(SDL_GetSurfaceProperties(surface))};
2254}
2255
2257{
2259}
2260
2273namespace prop::Surface {
2274
2275constexpr auto SDR_WHITE_POINT_FLOAT = SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT;
2276
2277constexpr auto HDR_HEADROOM_FLOAT = SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT;
2278
2279constexpr auto TONEMAP_OPERATOR_STRING =
2280 SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING;
2281
2282#if SDL_VERSION_ATLEAST(3, 2, 6)
2283
2284constexpr auto HOTSPOT_X_NUMBER = SDL_PROP_SURFACE_HOTSPOT_X_NUMBER;
2285
2286constexpr auto HOTSPOT_Y_NUMBER = SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER;
2287
2288#endif // SDL_VERSION_ATLEAST(3, 2, 6)
2289
2290#if SDL_VERSION_ATLEAST(3, 4, 0)
2291
2292constexpr auto ROTATION_FLOAT = SDL_PROP_SURFACE_ROTATION_FLOAT;
2293
2294#endif // SDL_VERSION_ATLEAST(3, 4, 0)
2295
2296} // namespace prop::Surface
2297
2315inline void SetSurfaceColorspace(SurfaceRef surface, Colorspace colorspace)
2316{
2317 CheckError(SDL_SetSurfaceColorspace(surface, colorspace));
2318}
2319
2320inline void Surface::SetColorspace(Colorspace colorspace)
2321{
2322 SDL::SetSurfaceColorspace(get(), colorspace);
2323}
2324
2344{
2345 return SDL_GetSurfaceColorspace(surface);
2346}
2347
2349{
2351}
2352
2381{
2382 return Palette::Borrow(CheckError(SDL_CreateSurfacePalette(surface)));
2383}
2384
2389
2410inline void SetSurfacePalette(SurfaceRef surface, PaletteRef palette)
2411{
2412 CheckError(SDL_SetSurfacePalette(surface, palette));
2413}
2414
2416{
2417 SDL::SetSurfacePalette(get(), palette);
2418}
2419
2434{
2435 return Palette::Borrow(SDL_GetSurfacePalette(surface));
2436}
2437
2439{
2440 return SDL::GetSurfacePalette(get());
2441}
2442
2469{
2470 CheckError(SDL_AddSurfaceAlternateImage(surface, image));
2471}
2472
2474{
2476}
2477
2493{
2494 return SDL_SurfaceHasAlternateImages(surface);
2495}
2496
2498{
2500}
2501
2526{
2527 int count = 0;
2528 auto data = SDL_GetSurfaceImages(surface, &count);
2529 return OwnArray<SurfaceRaw>(CheckError(data), count);
2530}
2531
2533{
2534 return SDL::GetSurfaceImages(get());
2535}
2536
2555{
2556 SDL_RemoveSurfaceAlternateImages(surface);
2557}
2558
2563
2589inline void LockSurface(SurfaceRef surface)
2590{
2591 CheckError(SDL_LockSurface(surface));
2592}
2593
2594inline SurfaceLock Surface::Lock() { return {SurfaceRef(*this)}; }
2595
2597 : m_lock(resource)
2598{
2599 LockSurface(m_lock);
2600}
2601
2615inline void UnlockSurface(SurfaceRef surface) { SDL_UnlockSurface(surface); }
2616
2617inline void Surface::Unlock(SurfaceLock&& lock)
2618{
2619 SDL_assert_paranoid(lock.resource() == *this);
2620 std::move(lock).reset();
2621}
2622
2624{
2625 if (!m_lock) return;
2626 UnlockSurface(m_lock);
2627 m_lock = {};
2628}
2629
2630#if !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC) && \
2631 SDL_VERSION_ATLEAST(3, 4, 0)
2632
2649inline Surface LoadSurface_IO(IOStreamRef src, bool closeio = false)
2650{
2651 return Surface{SDL_LoadSurface_IO(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
2695inline Surface LoadBMP_IO(IOStreamRef src, bool closeio = false)
2696{
2697 return Surface(SDL_LoadBMP_IO(src, closeio));
2698}
2699
2718inline Surface LoadBMP(StringParam file) { return Surface(SDL_LoadBMP(file)); }
2719
2743inline void SaveBMP_IO(SurfaceConstRef surface,
2744 IOStreamRef dst,
2745 bool closeio = false)
2746{
2747 CheckError(SDL_SaveBMP_IO(surface, dst, closeio));
2748}
2749
2750inline void Surface::SaveBMP_IO(IOStreamRef dst, bool closeio) const
2751{
2752 SDL::SaveBMP_IO(get(), dst, closeio);
2753}
2754
2776inline void SaveBMP(SurfaceConstRef surface, StringParam file)
2777{
2778 CheckError(SDL_SaveBMP(surface, file));
2779}
2780
2781inline void Surface::SaveBMP(StringParam file) const
2782{
2783 SDL::SaveBMP(get(), std::move(file));
2784}
2785
2786#if SDL_VERSION_ATLEAST(3, 4, 0)
2787
2809inline Surface LoadTrustedPNG_IO(IOStreamRef src, bool closeio = false)
2810{
2811 return Surface(SDL_LoadPNG_IO(src, closeio));
2812}
2813
2837{
2838 return Surface(SDL_LoadPNG(file));
2839}
2840
2841#if !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2842
2844inline Surface LoadPNG_IO(IOStreamRef src, bool closeio = false)
2845{
2846 return LoadTrustedPNG_IO(src, closeio);
2847}
2848
2850inline Surface LoadPNG(StringParam file)
2851{
2852 return LoadTrustedPNG(std::move(file));
2853}
2854
2855#endif // !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2856
2875 IOStreamRef dst,
2876 bool closeio = false)
2877{
2878 CheckError(SDL_SavePNG_IO(surface, dst, closeio));
2879}
2880
2881#if !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2882inline void Surface::SavePNG_IO(IOStreamRef dst, bool closeio) const
2883{
2884 SDL::SaveTrustedPNG_IO(get(), dst, closeio);
2885}
2886#endif // !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2887
2904{
2905 CheckError(SDL_SavePNG(surface, file));
2906}
2907
2908#if !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2909inline void Surface::SavePNG(StringParam file) const
2910{
2911 SDL::SaveTrustedPNG(get(), std::move(file));
2912}
2913#endif // !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2914
2915#endif // SDL_VERSION_ATLEAST(3, 4, 0)
2916
2936inline void SetSurfaceRLE(SurfaceRef surface, bool enabled)
2937{
2938 CheckError(SDL_SetSurfaceRLE(surface, enabled));
2939}
2940
2941inline void Surface::SetRLE(bool enabled)
2942{
2943 SDL::SetSurfaceRLE(get(), enabled);
2944}
2945
2960inline bool SurfaceHasRLE(SurfaceConstRef surface)
2961{
2962 return SDL_SurfaceHasRLE(surface);
2963}
2964
2965inline bool Surface::HasRLE() const { return SDL::SurfaceHasRLE(get()); }
2966
2989inline void SetSurfaceColorKey(SurfaceRef surface, std::optional<Uint32> key)
2990{
2991 CheckError(SDL_SetSurfaceColorKey(surface, key.has_value(), key.value_or(0)));
2992}
2993
2994inline void Surface::SetColorKey(std::optional<Uint32> key)
2995{
2997}
2998
3010{
3011 SetSurfaceColorKey(surface, std::nullopt);
3012}
3013
3015
3032{
3033 return SDL_SurfaceHasColorKey(surface);
3034}
3035
3036inline bool Surface::HasColorKey() const
3037{
3038 return SDL::SurfaceHasColorKey(get());
3039}
3040
3060inline std::optional<Uint32> GetSurfaceColorKey(SurfaceConstRef surface)
3061{
3062 if (Uint32 key; SDL_GetSurfaceColorKey(surface, &key)) return key;
3063 return std::nullopt;
3064}
3065
3066inline std::optional<Uint32> Surface::GetColorKey() const
3067{
3068 return SDL::GetSurfaceColorKey(get());
3069}
3070
3094inline void SetSurfaceColorMod(SurfaceRef surface, Uint8 r, Uint8 g, Uint8 b)
3095{
3096 CheckError(SDL_SetSurfaceColorMod(surface, r, g, b));
3097}
3098
3100{
3101 SDL::SetSurfaceColorMod(get(), r, g, b);
3102}
3103
3122 Uint8* r,
3123 Uint8* g,
3124 Uint8* b)
3125{
3126 CheckError(SDL_GetSurfaceColorMod(surface, r, g, b));
3127}
3128
3129inline void Surface::GetColorMod(Uint8* r, Uint8* g, Uint8* b) const
3130{
3131 SDL::GetSurfaceColorMod(get(), r, g, b);
3132}
3133
3154inline void SetSurfaceAlphaMod(SurfaceRef surface, Uint8 alpha)
3155{
3156 CheckError(SDL_SetSurfaceAlphaMod(surface, alpha));
3157}
3158
3159inline void Surface::SetAlphaMod(Uint8 alpha)
3160{
3161 SDL::SetSurfaceAlphaMod(get(), alpha);
3162}
3163
3179{
3180 Uint8 alpha;
3181 CheckError(SDL_GetSurfaceAlphaMod(surface, &alpha));
3182 return alpha;
3183}
3184
3186{
3187 return SDL::GetSurfaceAlphaMod(get());
3188}
3189
3205inline void SetSurfaceMod(SurfaceRef surface, Color color)
3206{
3207 SetSurfaceColorMod(surface, color.r, color.g, color.b);
3208 SetSurfaceAlphaMod(surface, color.a);
3209}
3210
3211inline void Surface::SetMod(Color color) { SetSurfaceMod(get(), color); }
3212
3222{
3223 Color c;
3224 GetSurfaceColorMod(surface, &c.r, &c.g, &c.b);
3225 c.a = GetSurfaceAlphaMod(surface);
3226 return c;
3227}
3228
3229inline Color Surface::GetMod() const { return SDL::GetSurfaceMod(get()); }
3230
3249inline void SetSurfaceBlendMode(SurfaceRef surface, BlendMode blendMode)
3250{
3251 CheckError(SDL_SetSurfaceBlendMode(surface, blendMode));
3252}
3253
3254inline void Surface::SetBlendMode(BlendMode blendMode)
3255{
3256 SDL::SetSurfaceBlendMode(get(), blendMode);
3257}
3258
3273{
3274 BlendMode blendmode;
3275 CheckError(SDL_GetSurfaceBlendMode(surface, &blendmode));
3276 return blendmode;
3277}
3278
3280{
3281 return SDL::GetSurfaceBlendMode(get());
3282}
3283
3306inline bool SetSurfaceClipRect(SurfaceRef surface,
3308{
3309 return SDL_SetSurfaceClipRect(surface, rect);
3310}
3311
3313{
3314 return SDL::SetSurfaceClipRect(get(), rect);
3315}
3316
3323{
3324 SetSurfaceClipRect(surface, std::nullopt);
3325}
3326
3328
3348{
3349 Rect r;
3350 CheckError(SDL_GetSurfaceClipRect(surface, &r));
3351 return r;
3352}
3353
3355{
3356 return SDL::GetSurfaceClipRect(get());
3357}
3358
3371inline void FlipSurface(SurfaceRef surface, FlipMode flip)
3372{
3373 CheckError(SDL_FlipSurface(surface, flip));
3374}
3375
3376inline void Surface::Flip(FlipMode flip) { SDL::FlipSurface(get(), flip); }
3377
3378#if SDL_VERSION_ATLEAST(3, 4, 0)
3379
3407inline Surface RotateSurface(SurfaceRef surface, float angle)
3408{
3409 return Surface{SDL_RotateSurface(surface, angle)};
3410}
3411
3412inline Surface Surface::Rotate(float angle)
3413{
3414 return SDL::RotateSurface(get(), angle);
3415}
3416
3417#endif // SDL_VERSION_ATLEAST(3, 4, 0)
3418
3439{
3440 return Surface(SDL_DuplicateSurface(surface));
3441}
3442
3444{
3445 return SDL::DuplicateSurface(get());
3446}
3447
3468 const PointRaw& size,
3469 ScaleMode scaleMode)
3470{
3471 return Surface(SDL_ScaleSurface(surface, size.x, size.y, scaleMode));
3472}
3473
3474inline Surface Surface::Scale(const PointRaw& size, ScaleMode scaleMode) const
3475{
3476 return SDL::ScaleSurface(get(), size, scaleMode);
3477}
3478
3507{
3508 return Surface(SDL_ConvertSurface(surface, format));
3509}
3510
3512{
3513 return SDL::ConvertSurface(get(), format);
3514}
3515
3545 PixelFormat format,
3546 PaletteRef palette,
3547 Colorspace colorspace,
3548 PropertiesRef props)
3549{
3550 return Surface{SDL_ConvertSurfaceAndColorspace(
3551 surface, format, palette, colorspace, props)};
3552}
3553
3555 PaletteRef palette,
3556 Colorspace colorspace,
3557 PropertiesRef props) const
3558{
3560 get(), format, palette, colorspace, props);
3561}
3562
3583inline void ConvertPixels(const PointRaw& size,
3584 PixelFormat src_format,
3585 const void* src,
3586 int src_pitch,
3587 PixelFormat dst_format,
3588 void* dst,
3589 int dst_pitch)
3590{
3591 CheckError(SDL_ConvertPixels(
3592 size.x, size.y, src_format, src, src_pitch, dst_format, dst, dst_pitch));
3593}
3594
3624inline void ConvertPixelsAndColorspace(const PointRaw& size,
3625 PixelFormat src_format,
3626 Colorspace src_colorspace,
3627 PropertiesRef src_properties,
3628 const void* src,
3629 int src_pitch,
3630 PixelFormat dst_format,
3631 Colorspace dst_colorspace,
3632 PropertiesRef dst_properties,
3633 void* dst,
3634 int dst_pitch)
3635{
3636 CheckError(SDL_ConvertPixelsAndColorspace(size.x,
3637 size.y,
3638 src_format,
3639 src_colorspace,
3640 src_properties,
3641 src,
3642 src_pitch,
3643 dst_format,
3644 dst_colorspace,
3645 dst_properties,
3646 dst,
3647 dst_pitch));
3648}
3649
3672inline void PremultiplyAlpha(const PointRaw& size,
3673 PixelFormat src_format,
3674 const void* src,
3675 int src_pitch,
3676 PixelFormat dst_format,
3677 void* dst,
3678 int dst_pitch,
3679 bool linear)
3680{
3681 CheckError(SDL_PremultiplyAlpha(size.x,
3682 size.y,
3683 src_format,
3684 src,
3685 src_pitch,
3686 dst_format,
3687 dst,
3688 dst_pitch,
3689 linear));
3690}
3691
3707inline void PremultiplySurfaceAlpha(SurfaceRef surface, bool linear)
3708{
3709 CheckError(SDL_PremultiplySurfaceAlpha(surface, linear));
3710}
3711
3712inline void Surface::PremultiplyAlpha(bool linear)
3713{
3715}
3716
3734inline void ClearSurface(SurfaceRef surface, const FColorRaw& c)
3735{
3736 CheckError(SDL_ClearSurface(surface, c.r, c.g, c.b, c.a));
3737}
3738
3739inline void Surface::Clear(const FColorRaw& c) { SDL::ClearSurface(get(), c); }
3740
3768 Uint32 color)
3769{
3770 CheckError(SDL_FillSurfaceRect(dst, rect, color));
3771}
3772
3774{
3775 SDL::FillSurfaceRect(get(), rect, color);
3776}
3777
3789inline void FillSurface(SurfaceRef dst, Uint32 color)
3790{
3791 FillSurfaceRect(dst, std::nullopt, color);
3792}
3793
3794inline void Surface::Fill(Uint32 color) { SDL::FillSurface(get(), color); }
3795
3822 Uint32 color)
3823{
3824 CheckError(
3825 SDL_FillSurfaceRects(dst, rects.data(), narrowS32(rects.size()), color));
3826}
3827
3829{
3830 SDL::FillSurfaceRects(get(), rects, color);
3831}
3832
3903inline void BlitSurface(SurfaceRef src,
3905 SurfaceRef dst,
3907{
3908 CheckError(SDL_BlitSurface(src, srcrect, dst, dstrect));
3909}
3910
3914{
3915 SDL::BlitSurface(src, srcrect, get(), dstrect);
3916}
3917
3920 const PointRaw& dstpos)
3921{
3922 Blit(src, srcrect, Rect{dstpos, {}});
3923}
3924
3994 SurfaceRef dst,
3995 const PointRaw& dstpos)
3996{
3997 BlitSurface(src, srcrect, dst, SDL_Rect{dstpos.x, dstpos.y, 0, 0});
3998}
3999
4022 const RectRaw& srcrect,
4023 SurfaceRef dst,
4024 const RectRaw& dstrect)
4025{
4026 CheckError(SDL_BlitSurfaceUnchecked(src, &srcrect, dst, &dstrect));
4027}
4028
4030 const RectRaw& srcrect,
4031 const RectRaw& dstrect)
4032{
4033 SDL::BlitSurfaceUnchecked(src, srcrect, get(), dstrect);
4034}
4035
4059 SurfaceRef dst,
4061 ScaleMode scaleMode)
4062{
4063 CheckError(SDL_BlitSurfaceScaled(src, srcrect, dst, dstrect, scaleMode));
4064}
4065
4069 ScaleMode scaleMode)
4070{
4071 SDL::BlitSurfaceScaled(src, srcrect, get(), dstrect, scaleMode);
4072}
4073
4097 const RectRaw& srcrect,
4098 SurfaceRef dst,
4099 const RectRaw& dstrect,
4100 ScaleMode scaleMode)
4101{
4102 CheckError(
4103 SDL_BlitSurfaceUncheckedScaled(src, &srcrect, dst, &dstrect, scaleMode));
4104}
4105
4107 const RectRaw& srcrect,
4108 const RectRaw& dstrect,
4109 ScaleMode scaleMode)
4110{
4111 SDL::BlitSurfaceUncheckedScaled(src, srcrect, get(), dstrect, scaleMode);
4112}
4113
4114#if SDL_VERSION_ATLEAST(3, 4, 0)
4115
4137 OptionalRef<RectRaw> srcrect,
4138 SurfaceRef dst,
4139 OptionalRef<RectRaw> dstrect,
4140 ScaleMode scaleMode)
4141{
4142 CheckError(SDL_StretchSurface(src, srcrect, dst, dstrect, scaleMode));
4143}
4144
4146 OptionalRef<RectRaw> srcrect,
4147 OptionalRef<RectRaw> dstrect,
4148 ScaleMode scaleMode)
4149{
4150 SDL::StretchSurface(src, srcrect, get(), dstrect, scaleMode);
4151}
4152
4153#endif // SDL_VERSION_ATLEAST(3, 4, 0)
4154
4179 SurfaceRef dst,
4181{
4182 CheckError(SDL_BlitSurfaceTiled(src, srcrect, dst, dstrect));
4183}
4184
4188{
4189 SDL::BlitSurfaceTiled(src, srcrect, get(), dstrect);
4190}
4191
4220 float scale,
4221 ScaleMode scaleMode,
4222 SurfaceRef dst,
4224{
4225 CheckError(SDL_BlitSurfaceTiledWithScale(
4226 src, srcrect, scale, scaleMode, dst, dstrect));
4227}
4228
4231 float scale,
4232 ScaleMode scaleMode,
4234{
4236 src, srcrect, scale, scaleMode, get(), dstrect);
4237}
4238
4274 int left_width,
4275 int right_width,
4276 int top_height,
4277 int bottom_height,
4278 SurfaceRef dst,
4280 float scale = 1,
4281 ScaleMode scaleMode = SCALEMODE_NEAREST)
4282{
4283 CheckError(SDL_BlitSurface9Grid(src,
4284 srcrect,
4285 left_width,
4286 right_width,
4287 top_height,
4288 bottom_height,
4289 scale,
4290 scaleMode,
4291 dst,
4292 dstrect));
4293}
4294
4297 int left_width,
4298 int right_width,
4299 int top_height,
4300 int bottom_height,
4302 float scale,
4303 ScaleMode scaleMode)
4304{
4306 srcrect,
4307 left_width,
4308 right_width,
4309 top_height,
4310 bottom_height,
4311 get(),
4312 dstrect,
4313 scale,
4314 scaleMode);
4315}
4316
4349{
4350 return SDL_MapSurfaceRGB(surface, r, g, b);
4351}
4352
4354{
4355 return SDL::MapSurfaceRGB(get(), r, g, b);
4356}
4357
4388{
4389 return SDL_MapSurfaceRGBA(surface, c.r, c.g, c.b, c.a);
4390}
4391
4393{
4394 return SDL::MapSurfaceRGBA(get(), c);
4395}
4396
4424 const PointRaw& p,
4425 Uint8* r,
4426 Uint8* g,
4427 Uint8* b,
4428 Uint8* a)
4429{
4430 CheckError(SDL_ReadSurfacePixel(surface, p.x, p.y, r, g, b, a));
4431}
4432
4453{
4454 Color c;
4455 ReadSurfacePixel(surface, p, &c.r, &c.g, &c.b, &c.a);
4456 return c;
4457}
4458
4485inline void ReadSurfacePixel(const SurfaceLock& lock,
4486 const PointRaw& p,
4487 Uint8* r,
4488 Uint8* g,
4489 Uint8* b,
4490 Uint8* a)
4491{
4492 lock.ReadPixel(p, r, g, b, a);
4493}
4494
4514inline Color ReadSurfacePixel(const SurfaceLock& lock, const PointRaw& p)
4515{
4516 return lock.ReadPixel(p);
4517}
4518
4519inline void Surface::ReadPixel(const PointRaw& p,
4520 Uint8* r,
4521 Uint8* g,
4522 Uint8* b,
4523 Uint8* a) const
4524{
4525 SDL::ReadSurfacePixel(get(), p, r, g, b, a);
4526}
4527
4528inline Color Surface::ReadPixel(const PointRaw& p) const
4529{
4530 return SDL::ReadSurfacePixel(get(), p);
4531}
4532
4557 const PointRaw& p,
4558 float* r,
4559 float* g,
4560 float* b,
4561 float* a)
4562{
4563 CheckError(SDL_ReadSurfacePixelFloat(surface, p.x, p.y, r, g, b, a));
4564}
4565
4583{
4584 FColor c;
4585 ReadSurfacePixelFloat(surface, p, &c.r, &c.g, &c.b, &c.a);
4586 return c;
4587}
4588
4612inline void ReadSurfacePixelFloat(const SurfaceLock& lock,
4613 const PointRaw& p,
4614 float* r,
4615 float* g,
4616 float* b,
4617 float* a)
4618{
4619 lock.ReadPixelFloat(p, r, g, b, a);
4620}
4621
4639{
4640 return lock.ReadPixelFloat(p);
4641}
4642
4644 float* r,
4645 float* g,
4646 float* b,
4647 float* a) const
4648{
4649 SDL::ReadSurfacePixelFloat(get(), p, r, g, b, a);
4650}
4651
4653{
4654 return SDL::ReadSurfacePixelFloat(get(), p);
4655}
4656
4676inline void WriteSurfacePixel(SurfaceRef surface, const PointRaw& p, ColorRaw c)
4677{
4678 CheckError(SDL_WriteSurfacePixel(surface, p.x, p.y, c.r, c.g, c.b, c.a));
4679}
4680
4700inline void WriteSurfacePixel(SurfaceLock& lock, const PointRaw& p, ColorRaw c)
4701{
4702 lock.WritePixel(p, c);
4703}
4704
4705inline void Surface::WritePixel(const PointRaw& p, ColorRaw c)
4706{
4707 SDL::WriteSurfacePixel(get(), p, c);
4708}
4709
4727 const PointRaw& p,
4728 const FColorRaw& c)
4729{
4730 CheckError(SDL_WriteSurfacePixelFloat(surface, p.x, p.y, c.r, c.g, c.b, c.a));
4731}
4732
4750 const PointRaw& p,
4751 const FColorRaw& c)
4752{
4753 lock.WritePixelFloat(p, c);
4754}
4755
4756inline void Surface::WritePixelFloat(const PointRaw& p, const FColorRaw& c)
4757{
4759}
4760
4762constexpr int GetSurfaceWidth(SurfaceConstRef surface) { return surface->w; }
4763
4765constexpr int GetSurfaceWidth(const SurfaceLock& lock)
4766{
4767 return lock.GetWidth();
4768}
4769
4770constexpr int Surface::GetWidth() const { return SDL::GetSurfaceWidth(get()); }
4771
4773constexpr int GetSurfaceHeight(SurfaceConstRef surface) { return surface->h; }
4774
4776constexpr int GetSurfaceHeight(const SurfaceLock& lock)
4777{
4778 return lock.GetHeight();
4779}
4780
4781constexpr int Surface::GetHeight() const
4782{
4783 return SDL::GetSurfaceHeight(get());
4784}
4785
4788{
4789 return Point(surface->w, surface->h);
4790}
4791
4793constexpr Point GetSurfaceSize(const SurfaceLock& lock)
4794{
4795 return lock.GetSize();
4796}
4797
4798constexpr Point Surface::GetSize() const { return SDL::GetSurfaceSize(get()); }
4799
4801constexpr int GetSurfacePitch(SurfaceConstRef surface)
4802{
4803 return surface->pitch;
4804}
4805
4807constexpr int GetSurfacePitch(const SurfaceLock& lock)
4808{
4809 return lock.GetPitch();
4810}
4811
4812constexpr int Surface::GetPitch() const { return SDL::GetSurfacePitch(get()); }
4813
4816{
4817 return surface->format;
4818}
4819
4822{
4823 return lock.GetFormat();
4824}
4825
4827{
4828 return SDL::GetSurfaceFormat(get());
4829}
4830
4832constexpr void* GetSurfacePixels(SurfaceConstRef surface)
4833{
4834 return surface->pixels;
4835}
4836
4838constexpr void* GetSurfacePixels(const SurfaceLock& lock)
4839{
4840 return lock.GetPixels();
4841}
4842
4843constexpr void* Surface::GetPixels() const
4844{
4845 return SDL::GetSurfacePixels(get());
4846}
4847
4849
4850} // namespace SDL
4851
4852#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:1878
SurfaceRef resource() const
Get the reference to locked resource.
Definition SDL3pp_surface.h:2120
constexpr PixelFormat GetFormat() const
Get the pixel format.
Definition SDL3pp_surface.h:2101
SurfaceLock(SurfaceLock &&other) noexcept
Move constructor.
Definition SDL3pp_surface.h:1913
FColor ReadPixelFloat(const PointRaw &p) const
Retrieves a single pixel from a surface.
Definition SDL3pp_surface.h:2043
~SurfaceLock()
Release a surface after directly accessing the pixels.
Definition SDL3pp_surface.h:1929
constexpr int GetHeight() const
Get the height in pixels.
Definition SDL3pp_surface.h:2092
constexpr int GetWidth() const
Get the width in pixels.
Definition SDL3pp_surface.h:2089
constexpr void * GetPixels() const
Get the pixels.
Definition SDL3pp_surface.h:2104
void release()
Releases the lock without unlocking.
Definition SDL3pp_surface.h:2123
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:1968
void WritePixelFloat(const PointRaw &p, const FColorRaw &c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:2083
SurfaceLock & operator=(SurfaceLock &&other) noexcept
Assignment operator.
Definition SDL3pp_surface.h:1934
void WritePixel(const PointRaw &p, ColorRaw c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:2066
constexpr Point GetSize() const
Get the size in pixels.
Definition SDL3pp_surface.h:2095
Color ReadPixel(const PointRaw &p) const
Retrieves a single pixel from a surface.
Definition SDL3pp_surface.h:1995
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:2019
constexpr int GetPitch() const
Get pitch in bytes.
Definition SDL3pp_surface.h:2098
#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:2596
Rect GetClipRect() const
Get the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3354
Palette GetPalette() const
Get the palette used by a surface.
Definition SDL3pp_surface.h:2438
std::optional< Uint32 > GetColorKey() const
Get the color key (transparent pixel) for a surface.
Definition SDL3pp_surface.h:3066
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:4185
Palette CreateSurfacePalette(SurfaceRef surface)
Create a palette and associate it with a surface.
Definition SDL3pp_surface.h:2380
void SaveTrustedPNG(SurfaceConstRef surface, StringParam file)
Save a surface to a file in PNG format.
Definition SDL3pp_surface.h:2903
constexpr FlipMode FLIP_VERTICAL
flip vertically
Definition SDL3pp_surface.h:133
constexpr PixelFormat GetFormat() const
Get the pixel format.
Definition SDL3pp_surface.h:4826
Surface LoadBMP_IO(IOStreamRef src, bool closeio=false)
Load a BMP image from a seekable SDL data stream.
Definition SDL3pp_surface.h:2695
void Destroy()
Free this surface.
Definition SDL3pp_surface.h:2212
void SetSurfaceColorKey(SurfaceRef surface, std::optional< Uint32 > key)
Set the color key (transparent pixel) in a surface.
Definition SDL3pp_surface.h:2989
void AddAlternateImage(SurfaceRef image)
Add an alternate version of a surface.
Definition SDL3pp_surface.h:2473
void WriteSurfacePixel(SurfaceRef surface, const PointRaw &p, ColorRaw c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:4676
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:3992
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:4229
void AddSurfaceAlternateImage(SurfaceRef surface, SurfaceRef image)
Add an alternate version of a surface.
Definition SDL3pp_surface.h:2468
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:3121
void SetSurfaceMod(SurfaceRef surface, Color color)
Set an additional color and alpha value multiplied into blit operations.
Definition SDL3pp_surface.h:3205
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:3279
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:4348
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:3154
BlendMode GetSurfaceBlendMode(SurfaceConstRef surface)
Get the blend mode used for blit operations.
Definition SDL3pp_surface.h:3272
void RemoveSurfaceAlternateImages(SurfaceRef surface)
Remove all alternate versions of a surface.
Definition SDL3pp_surface.h:2554
void DestroySurface(SurfaceRaw surface)
Free a surface.
Definition SDL3pp_surface.h:2210
void ClearSurface(SurfaceRef surface, const FColorRaw &c)
Clear a surface with a specific color, with floating point precision.
Definition SDL3pp_surface.h:3734
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:3828
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:4353
bool HasRLE() const
Returns whether the surface is RLE enabled.
Definition SDL3pp_surface.h:2965
void LockSurface(SurfaceRef surface)
Set up a surface for directly accessing the pixels.
Definition SDL3pp_surface.h:2589
SDL_ScaleMode ScaleMode
The scaling mode.
Definition SDL3pp_surface.h:98
constexpr int GetHeight() const
Get the height in pixels.
Definition SDL3pp_surface.h:4781
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:3903
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:4272
OwnArray< SurfaceRaw > GetSurfaceImages(SurfaceConstRef surface)
Get an array including all versions of a surface.
Definition SDL3pp_surface.h:2525
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:4762
Surface RotateSurface(SurfaceRef surface, float angle)
Return a copy of a surface rotated clockwise a number of degrees.
Definition SDL3pp_surface.h:3407
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:3766
void PremultiplySurfaceAlpha(SurfaceRef surface, bool linear)
Premultiply the alpha in a surface.
Definition SDL3pp_surface.h:3707
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:2874
bool HasColorKey() const
Returns whether the surface has a color key.
Definition SDL3pp_surface.h:3036
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:2994
void PremultiplyAlpha(bool linear)
Premultiply the alpha in a surface.
Definition SDL3pp_surface.h:3712
void BlitSurfaceUnchecked(SurfaceRef src, const RectRaw &srcrect, SurfaceRef dst, const RectRaw &dstrect)
Perform low-level surface blitting only.
Definition SDL3pp_surface.h:4021
void SaveBMP(SurfaceConstRef surface, StringParam file)
Save a surface to a file in BMP format.
Definition SDL3pp_surface.h:2776
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:2385
void reset()
Release a surface after directly accessing the pixels.
Definition SDL3pp_surface.h:2623
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:2750
void WriteSurfacePixelFloat(SurfaceRef surface, const PointRaw &p, const FColorRaw &c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:4726
bool SetSurfaceClipRect(SurfaceRef surface, OptionalRef< const RectRaw > rect)
Set the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3306
Colorspace GetColorspace() const
Get the colorspace used by a surface.
Definition SDL3pp_surface.h:2348
constexpr PixelFormat GetSurfaceFormat(SurfaceConstRef surface)
Get the pixel format.
Definition SDL3pp_surface.h:4815
void SetSurfacePalette(SurfaceRef surface, PaletteRef palette)
Set the palette used by a surface.
Definition SDL3pp_surface.h:2410
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:3376
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:2188
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:3911
PropertiesRef GetSurfaceProperties(SurfaceConstRef surface)
Get the properties associated with a surface.
Definition SDL3pp_surface.h:2251
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:4218
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:3624
Colorspace GetSurfaceColorspace(SurfaceConstRef surface)
Get the colorspace used by a surface.
Definition SDL3pp_surface.h:2343
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:4057
Surface LoadBMP(StringParam file)
Load a BMP image from a file.
Definition SDL3pp_surface.h:2718
void ResetClipRect()
Disable the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3327
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:4177
Surface ConvertSurface(SurfaceConstRef surface, PixelFormat format)
Copy an existing surface to a new surface of the specified format.
Definition SDL3pp_surface.h:3506
PropertiesRef GetProperties() const
Get the properties associated with a surface.
Definition SDL3pp_surface.h:2256
Surface DuplicateSurface(SurfaceConstRef surface)
Creates a new surface identical to the existing surface.
Definition SDL3pp_surface.h:3438
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:2433
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:3467
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:2497
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:4812
void BlitUncheckedScaled(SurfaceRef src, const RectRaw &srcrect, const RectRaw &dstrect, ScaleMode scaleMode)
Perform low-level surface scaled blitting only.
Definition SDL3pp_surface.h:4106
Uint8 GetSurfaceAlphaMod(SurfaceConstRef surface)
Get the additional alpha value used in blit operations.
Definition SDL3pp_surface.h:3178
bool SurfaceHasColorKey(SurfaceConstRef surface)
Returns whether the surface has a color key.
Definition SDL3pp_surface.h:3031
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:4145
void RemoveAlternateImages()
Remove all alternate versions of a surface.
Definition SDL3pp_surface.h:2559
Surface Convert(PixelFormat format) const
Copy an existing surface to a new surface of the specified format.
Definition SDL3pp_surface.h:3511
constexpr Point GetSize() const
Get the size in pixels.
Definition SDL3pp_surface.h:4798
void SetSurfaceBlendMode(SurfaceRef surface, BlendMode blendMode)
Set the blend mode used for blit operations.
Definition SDL3pp_surface.h:3249
Surface LoadTrustedPNG_IO(IOStreamRef src, bool closeio=false)
Load a PNG image from a seekable SDL data stream.
Definition SDL3pp_surface.h:2809
Uint8 GetAlphaMod() const
Get the additional alpha value used in blit operations.
Definition SDL3pp_surface.h:3185
Surface Duplicate() const
Creates a new surface identical to the existing surface.
Definition SDL3pp_surface.h:3443
void Clear(const FColorRaw &c)
Clear a surface with a specific color, with floating point precision.
Definition SDL3pp_surface.h:3739
void UnlockSurface(SurfaceRef surface)
Release a surface after directly accessing the pixels.
Definition SDL3pp_surface.h:2615
void SetMod(Color color)
Set an additional color and alpha value multiplied into blit operations.
Definition SDL3pp_surface.h:3211
bool SurfaceHasAlternateImages(SurfaceConstRef surface)
Return whether a surface has alternate versions available.
Definition SDL3pp_surface.h:2492
bool SurfaceHasRLE(SurfaceConstRef surface)
Returns whether the surface is RLE enabled.
Definition SDL3pp_surface.h:2960
void GetColorMod(Uint8 *r, Uint8 *g, Uint8 *b) const
Get the additional color value multiplied into blit operations.
Definition SDL3pp_surface.h:3129
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:4136
SurfaceLock Lock()
Set up a surface for directly accessing the pixels.
Definition SDL3pp_surface.h:2594
constexpr ScaleMode SCALEMODE_INVALID
INVALID.
Definition SDL3pp_surface.h:102
constexpr int GetWidth() const
Get the width in pixels.
Definition SDL3pp_surface.h:4770
void SetColorMod(Uint8 r, Uint8 g, Uint8 b)
Set an additional color value multiplied into blit operations.
Definition SDL3pp_surface.h:3099
void ClearSurfaceColorKey(SurfaceRef surface)
Unset the color key (transparent pixel) in a surface.
Definition SDL3pp_surface.h:3009
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:3672
void SetBlendMode(BlendMode blendMode)
Set the blend mode used for blit operations.
Definition SDL3pp_surface.h:3254
OwnArray< SurfaceRaw > GetImages() const
Get an array including all versions of a surface.
Definition SDL3pp_surface.h:2532
Surface Rotate(float angle)
Return a copy of a surface rotated clockwise a number of degrees.
Definition SDL3pp_surface.h:3412
Surface CreateSurface(const PointRaw &size, PixelFormat format)
Allocate a new surface with a specific pixel format.
Definition SDL3pp_surface.h:2143
void SetSurfaceColorMod(SurfaceRef surface, Uint8 r, Uint8 g, Uint8 b)
Set an additional color value multiplied into blit operations.
Definition SDL3pp_surface.h:3094
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:3820
void SetPalette(PaletteRef palette)
Set the palette used by a surface.
Definition SDL3pp_surface.h:2415
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:4096
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:2936
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:3544
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:4519
constexpr void * GetSurfacePixels(SurfaceConstRef surface)
Get the pixels.
Definition SDL3pp_surface.h:4832
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:2743
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:3794
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:4773
Uint32 MapRGBA(ColorRaw c) const
Map an RGBA quadruple to a pixel value for a surface.
Definition SDL3pp_surface.h:4392
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:3474
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:4295
void SetColorspace(Colorspace colorspace)
Set the colorspace used by a surface.
Definition SDL3pp_surface.h:2320
void ClearColorKey()
Unset the color key (transparent pixel) in a surface.
Definition SDL3pp_surface.h:3014
void WritePixel(const PointRaw &p, ColorRaw c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:4705
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:4556
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:4423
void BlitUnchecked(SurfaceRef src, const RectRaw &srcrect, const RectRaw &dstrect)
Perform low-level surface blitting only.
Definition SDL3pp_surface.h:4029
Color GetSurfaceMod(SurfaceConstRef surface)
Get the additional color and alpha value multiplied into blit operations.
Definition SDL3pp_surface.h:3221
Surface LoadTrustedPNG(StringParam file)
Load a PNG image from a file.
Definition SDL3pp_surface.h:2836
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:4066
void FillRect(OptionalRef< const RectRaw > rect, Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition SDL3pp_surface.h:3773
constexpr int GetSurfacePitch(SurfaceConstRef surface)
Get pitch in bytes.
Definition SDL3pp_surface.h:4801
void Unlock(SurfaceLock &&lock)
Release a surface after directly accessing the pixels.
Definition SDL3pp_surface.h:2617
constexpr Point GetSurfaceSize(SurfaceConstRef surface)
Get the size in pixels.
Definition SDL3pp_surface.h:4787
void SaveBMP(StringParam file) const
Save a surface to a file in BMP format.
Definition SDL3pp_surface.h:2781
void ResetSurfaceClipRect(SurfaceRef surface)
Disable the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3322
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:4643
std::optional< Uint32 > GetSurfaceColorKey(SurfaceConstRef surface)
Get the color key (transparent pixel) for a surface.
Definition SDL3pp_surface.h:3060
void SetAlphaMod(Uint8 alpha)
Set an additional alpha value used in blit operations.
Definition SDL3pp_surface.h:3159
constexpr void * GetPixels() const
Get the pixels.
Definition SDL3pp_surface.h:4843
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:3918
void SetSurfaceColorspace(SurfaceRef surface, Colorspace colorspace)
Set the colorspace used by a surface.
Definition SDL3pp_surface.h:2315
void SetRLE(bool enabled)
Set the RLE acceleration hint for a surface.
Definition SDL3pp_surface.h:2941
Uint32 MapSurfaceRGBA(SurfaceConstRef surface, ColorRaw c)
Map an RGBA quadruple to a pixel value for a surface.
Definition SDL3pp_surface.h:4387
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:3583
Color GetMod() const
Get the additional color and alpha value multiplied into blit operations.
Definition SDL3pp_surface.h:3229
void FlipSurface(SurfaceRef surface, FlipMode flip)
Flip a surface vertically or horizontally.
Definition SDL3pp_surface.h:3371
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:3312
Rect GetSurfaceClipRect(SurfaceConstRef surface)
Get the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3347
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:3789
void WritePixelFloat(const PointRaw &p, const FColorRaw &c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:4756
Properties for Surface.
Definition SDL3pp_surface.h:2273
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