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
2276 SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT;
2277
2278constexpr auto HDR_HEADROOM_FLOAT =
2279 SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT;
2280
2282 SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING;
2283
2284#if SDL_VERSION_ATLEAST(3, 2, 6)
2285
2286constexpr auto HOTSPOT_X_NUMBER =
2287 SDL_PROP_SURFACE_HOTSPOT_X_NUMBER;
2288
2289constexpr auto HOTSPOT_Y_NUMBER =
2290 SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER;
2291
2292#endif // SDL_VERSION_ATLEAST(3, 2, 6)
2293
2294#if SDL_VERSION_ATLEAST(3, 4, 0)
2295
2296constexpr auto ROTATION_FLOAT =
2297 SDL_PROP_SURFACE_ROTATION_FLOAT;
2298
2299#endif // SDL_VERSION_ATLEAST(3, 4, 0)
2300
2301} // namespace prop::Surface
2302
2320inline void SetSurfaceColorspace(SurfaceRef surface, Colorspace colorspace)
2321{
2322 CheckError(SDL_SetSurfaceColorspace(surface, colorspace));
2323}
2324
2325inline void Surface::SetColorspace(Colorspace colorspace)
2326{
2327 SDL::SetSurfaceColorspace(get(), colorspace);
2328}
2329
2349{
2350 return SDL_GetSurfaceColorspace(surface);
2351}
2352
2354{
2356}
2357
2386{
2387 return Palette::Borrow(CheckError(SDL_CreateSurfacePalette(surface)));
2388}
2389
2394
2415inline void SetSurfacePalette(SurfaceRef surface, PaletteRef palette)
2416{
2417 CheckError(SDL_SetSurfacePalette(surface, palette));
2418}
2419
2421{
2422 SDL::SetSurfacePalette(get(), palette);
2423}
2424
2439{
2440 return Palette::Borrow(SDL_GetSurfacePalette(surface));
2441}
2442
2444{
2445 return SDL::GetSurfacePalette(get());
2446}
2447
2474{
2475 CheckError(SDL_AddSurfaceAlternateImage(surface, image));
2476}
2477
2479{
2481}
2482
2498{
2499 return SDL_SurfaceHasAlternateImages(surface);
2500}
2501
2503{
2505}
2506
2531{
2532 int count = 0;
2533 auto data = SDL_GetSurfaceImages(surface, &count);
2534 return OwnArray<SurfaceRaw>(CheckError(data), count);
2535}
2536
2538{
2539 return SDL::GetSurfaceImages(get());
2540}
2541
2560{
2561 SDL_RemoveSurfaceAlternateImages(surface);
2562}
2563
2568
2594inline void LockSurface(SurfaceRef surface)
2595{
2596 CheckError(SDL_LockSurface(surface));
2597}
2598
2599inline SurfaceLock Surface::Lock() { return {SurfaceRef(*this)}; }
2600
2602 : m_lock(resource)
2603{
2604 LockSurface(m_lock);
2605}
2606
2620inline void UnlockSurface(SurfaceRef surface) { SDL_UnlockSurface(surface); }
2621
2622inline void Surface::Unlock(SurfaceLock&& lock)
2623{
2624 SDL_assert_paranoid(lock.resource() == *this);
2625 std::move(lock).reset();
2626}
2627
2629{
2630 if (!m_lock) return;
2631 UnlockSurface(m_lock);
2632 m_lock = {};
2633}
2634
2635#if !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC) && \
2636 SDL_VERSION_ATLEAST(3, 4, 0)
2637
2654inline Surface LoadSurface_IO(IOStreamRef src, bool closeio = false)
2655{
2656 return Surface{SDL_LoadSurface_IO(src, closeio)};
2657}
2658
2673inline Surface LoadSurface(StringParam file)
2674{
2675 return Surface{SDL_LoadSurface(file)};
2676}
2677
2678#endif // !defined(SDL3PP_ENABLE_IMAGE) && SDL_VERSION_ATLEAST(3, 4, 0)
2679
2700inline Surface LoadBMP_IO(IOStreamRef src, bool closeio = false)
2701{
2702 return Surface(SDL_LoadBMP_IO(src, closeio));
2703}
2704
2723inline Surface LoadBMP(StringParam file) { return Surface(SDL_LoadBMP(file)); }
2724
2748inline void SaveBMP_IO(SurfaceConstRef surface,
2749 IOStreamRef dst,
2750 bool closeio = false)
2751{
2752 CheckError(SDL_SaveBMP_IO(surface, dst, closeio));
2753}
2754
2755inline void Surface::SaveBMP_IO(IOStreamRef dst, bool closeio) const
2756{
2757 SDL::SaveBMP_IO(get(), dst, closeio);
2758}
2759
2781inline void SaveBMP(SurfaceConstRef surface, StringParam file)
2782{
2783 CheckError(SDL_SaveBMP(surface, file));
2784}
2785
2786inline void Surface::SaveBMP(StringParam file) const
2787{
2788 SDL::SaveBMP(get(), std::move(file));
2789}
2790
2791#if SDL_VERSION_ATLEAST(3, 4, 0)
2792
2814inline Surface LoadTrustedPNG_IO(IOStreamRef src, bool closeio = false)
2815{
2816 return Surface(SDL_LoadPNG_IO(src, closeio));
2817}
2818
2842{
2843 return Surface(SDL_LoadPNG(file));
2844}
2845
2846#if !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2847
2849inline Surface LoadPNG_IO(IOStreamRef src, bool closeio = false)
2850{
2851 return LoadTrustedPNG_IO(src, closeio);
2852}
2853
2855inline Surface LoadPNG(StringParam file)
2856{
2857 return LoadTrustedPNG(std::move(file));
2858}
2859
2860#endif // !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2861
2880 IOStreamRef dst,
2881 bool closeio = false)
2882{
2883 CheckError(SDL_SavePNG_IO(surface, dst, closeio));
2884}
2885
2886#if !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2887inline void Surface::SavePNG_IO(IOStreamRef dst, bool closeio) const
2888{
2889 SDL::SaveTrustedPNG_IO(get(), dst, closeio);
2890}
2891#endif // !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2892
2909{
2910 CheckError(SDL_SavePNG(surface, file));
2911}
2912
2913#if !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2914inline void Surface::SavePNG(StringParam file) const
2915{
2916 SDL::SaveTrustedPNG(get(), std::move(file));
2917}
2918#endif // !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2919
2920#endif // SDL_VERSION_ATLEAST(3, 4, 0)
2921
2941inline void SetSurfaceRLE(SurfaceRef surface, bool enabled)
2942{
2943 CheckError(SDL_SetSurfaceRLE(surface, enabled));
2944}
2945
2946inline void Surface::SetRLE(bool enabled)
2947{
2948 SDL::SetSurfaceRLE(get(), enabled);
2949}
2950
2965inline bool SurfaceHasRLE(SurfaceConstRef surface)
2966{
2967 return SDL_SurfaceHasRLE(surface);
2968}
2969
2970inline bool Surface::HasRLE() const { return SDL::SurfaceHasRLE(get()); }
2971
2994inline void SetSurfaceColorKey(SurfaceRef surface, std::optional<Uint32> key)
2995{
2996 CheckError(SDL_SetSurfaceColorKey(surface, key.has_value(), key.value_or(0)));
2997}
2998
2999inline void Surface::SetColorKey(std::optional<Uint32> key)
3000{
3002}
3003
3015{
3016 SetSurfaceColorKey(surface, std::nullopt);
3017}
3018
3020
3037{
3038 return SDL_SurfaceHasColorKey(surface);
3039}
3040
3041inline bool Surface::HasColorKey() const
3042{
3043 return SDL::SurfaceHasColorKey(get());
3044}
3045
3065inline std::optional<Uint32> GetSurfaceColorKey(SurfaceConstRef surface)
3066{
3067 if (Uint32 key; SDL_GetSurfaceColorKey(surface, &key)) return key;
3068 return std::nullopt;
3069}
3070
3071inline std::optional<Uint32> Surface::GetColorKey() const
3072{
3073 return SDL::GetSurfaceColorKey(get());
3074}
3075
3099inline void SetSurfaceColorMod(SurfaceRef surface, Uint8 r, Uint8 g, Uint8 b)
3100{
3101 CheckError(SDL_SetSurfaceColorMod(surface, r, g, b));
3102}
3103
3105{
3106 SDL::SetSurfaceColorMod(get(), r, g, b);
3107}
3108
3127 Uint8* r,
3128 Uint8* g,
3129 Uint8* b)
3130{
3131 CheckError(SDL_GetSurfaceColorMod(surface, r, g, b));
3132}
3133
3134inline void Surface::GetColorMod(Uint8* r, Uint8* g, Uint8* b) const
3135{
3136 SDL::GetSurfaceColorMod(get(), r, g, b);
3137}
3138
3159inline void SetSurfaceAlphaMod(SurfaceRef surface, Uint8 alpha)
3160{
3161 CheckError(SDL_SetSurfaceAlphaMod(surface, alpha));
3162}
3163
3164inline void Surface::SetAlphaMod(Uint8 alpha)
3165{
3166 SDL::SetSurfaceAlphaMod(get(), alpha);
3167}
3168
3184{
3185 Uint8 alpha;
3186 CheckError(SDL_GetSurfaceAlphaMod(surface, &alpha));
3187 return alpha;
3188}
3189
3191{
3192 return SDL::GetSurfaceAlphaMod(get());
3193}
3194
3210inline void SetSurfaceMod(SurfaceRef surface, Color color)
3211{
3212 SetSurfaceColorMod(surface, color.r, color.g, color.b);
3213 SetSurfaceAlphaMod(surface, color.a);
3214}
3215
3216inline void Surface::SetMod(Color color) { SetSurfaceMod(get(), color); }
3217
3227{
3228 Color c;
3229 GetSurfaceColorMod(surface, &c.r, &c.g, &c.b);
3230 c.a = GetSurfaceAlphaMod(surface);
3231 return c;
3232}
3233
3234inline Color Surface::GetMod() const { return SDL::GetSurfaceMod(get()); }
3235
3254inline void SetSurfaceBlendMode(SurfaceRef surface, BlendMode blendMode)
3255{
3256 CheckError(SDL_SetSurfaceBlendMode(surface, blendMode));
3257}
3258
3259inline void Surface::SetBlendMode(BlendMode blendMode)
3260{
3261 SDL::SetSurfaceBlendMode(get(), blendMode);
3262}
3263
3278{
3279 BlendMode blendmode;
3280 CheckError(SDL_GetSurfaceBlendMode(surface, &blendmode));
3281 return blendmode;
3282}
3283
3285{
3286 return SDL::GetSurfaceBlendMode(get());
3287}
3288
3311inline bool SetSurfaceClipRect(SurfaceRef surface,
3313{
3314 return SDL_SetSurfaceClipRect(surface, rect);
3315}
3316
3318{
3319 return SDL::SetSurfaceClipRect(get(), rect);
3320}
3321
3328{
3329 SetSurfaceClipRect(surface, std::nullopt);
3330}
3331
3333
3353{
3354 Rect r;
3355 CheckError(SDL_GetSurfaceClipRect(surface, &r));
3356 return r;
3357}
3358
3360{
3361 return SDL::GetSurfaceClipRect(get());
3362}
3363
3376inline void FlipSurface(SurfaceRef surface, FlipMode flip)
3377{
3378 CheckError(SDL_FlipSurface(surface, flip));
3379}
3380
3381inline void Surface::Flip(FlipMode flip) { SDL::FlipSurface(get(), flip); }
3382
3383#if SDL_VERSION_ATLEAST(3, 4, 0)
3384
3412inline Surface RotateSurface(SurfaceRef surface, float angle)
3413{
3414 return Surface{SDL_RotateSurface(surface, angle)};
3415}
3416
3417inline Surface Surface::Rotate(float angle)
3418{
3419 return SDL::RotateSurface(get(), angle);
3420}
3421
3422#endif // SDL_VERSION_ATLEAST(3, 4, 0)
3423
3444{
3445 return Surface(SDL_DuplicateSurface(surface));
3446}
3447
3449{
3450 return SDL::DuplicateSurface(get());
3451}
3452
3473 const PointRaw& size,
3474 ScaleMode scaleMode)
3475{
3476 return Surface(SDL_ScaleSurface(surface, size.x, size.y, scaleMode));
3477}
3478
3479inline Surface Surface::Scale(const PointRaw& size, ScaleMode scaleMode) const
3480{
3481 return SDL::ScaleSurface(get(), size, scaleMode);
3482}
3483
3512{
3513 return Surface(SDL_ConvertSurface(surface, format));
3514}
3515
3517{
3518 return SDL::ConvertSurface(get(), format);
3519}
3520
3550 PixelFormat format,
3551 PaletteRef palette,
3552 Colorspace colorspace,
3553 PropertiesRef props)
3554{
3555 return Surface{SDL_ConvertSurfaceAndColorspace(
3556 surface, format, palette, colorspace, props)};
3557}
3558
3560 PaletteRef palette,
3561 Colorspace colorspace,
3562 PropertiesRef props) const
3563{
3565 get(), format, palette, colorspace, props);
3566}
3567
3588inline void ConvertPixels(const PointRaw& size,
3589 PixelFormat src_format,
3590 const void* src,
3591 int src_pitch,
3592 PixelFormat dst_format,
3593 void* dst,
3594 int dst_pitch)
3595{
3596 CheckError(SDL_ConvertPixels(
3597 size.x, size.y, src_format, src, src_pitch, dst_format, dst, dst_pitch));
3598}
3599
3629inline void ConvertPixelsAndColorspace(const PointRaw& size,
3630 PixelFormat src_format,
3631 Colorspace src_colorspace,
3632 PropertiesRef src_properties,
3633 const void* src,
3634 int src_pitch,
3635 PixelFormat dst_format,
3636 Colorspace dst_colorspace,
3637 PropertiesRef dst_properties,
3638 void* dst,
3639 int dst_pitch)
3640{
3641 CheckError(SDL_ConvertPixelsAndColorspace(size.x,
3642 size.y,
3643 src_format,
3644 src_colorspace,
3645 src_properties,
3646 src,
3647 src_pitch,
3648 dst_format,
3649 dst_colorspace,
3650 dst_properties,
3651 dst,
3652 dst_pitch));
3653}
3654
3677inline void PremultiplyAlpha(const PointRaw& size,
3678 PixelFormat src_format,
3679 const void* src,
3680 int src_pitch,
3681 PixelFormat dst_format,
3682 void* dst,
3683 int dst_pitch,
3684 bool linear)
3685{
3686 CheckError(SDL_PremultiplyAlpha(size.x,
3687 size.y,
3688 src_format,
3689 src,
3690 src_pitch,
3691 dst_format,
3692 dst,
3693 dst_pitch,
3694 linear));
3695}
3696
3712inline void PremultiplySurfaceAlpha(SurfaceRef surface, bool linear)
3713{
3714 CheckError(SDL_PremultiplySurfaceAlpha(surface, linear));
3715}
3716
3717inline void Surface::PremultiplyAlpha(bool linear)
3718{
3720}
3721
3739inline void ClearSurface(SurfaceRef surface, const FColorRaw& c)
3740{
3741 CheckError(SDL_ClearSurface(surface, c.r, c.g, c.b, c.a));
3742}
3743
3744inline void Surface::Clear(const FColorRaw& c) { SDL::ClearSurface(get(), c); }
3745
3773 Uint32 color)
3774{
3775 CheckError(SDL_FillSurfaceRect(dst, rect, color));
3776}
3777
3779{
3780 SDL::FillSurfaceRect(get(), rect, color);
3781}
3782
3794inline void FillSurface(SurfaceRef dst, Uint32 color)
3795{
3796 FillSurfaceRect(dst, std::nullopt, color);
3797}
3798
3799inline void Surface::Fill(Uint32 color) { SDL::FillSurface(get(), color); }
3800
3827 Uint32 color)
3828{
3829 CheckError(
3830 SDL_FillSurfaceRects(dst, rects.data(), narrowS32(rects.size()), color));
3831}
3832
3834{
3835 SDL::FillSurfaceRects(get(), rects, color);
3836}
3837
3908inline void BlitSurface(SurfaceRef src,
3910 SurfaceRef dst,
3912{
3913 CheckError(SDL_BlitSurface(src, srcrect, dst, dstrect));
3914}
3915
3919{
3920 SDL::BlitSurface(src, srcrect, get(), dstrect);
3921}
3922
3925 const PointRaw& dstpos)
3926{
3927 Blit(src, srcrect, Rect{dstpos, {}});
3928}
3929
3999 SurfaceRef dst,
4000 const PointRaw& dstpos)
4001{
4002 BlitSurface(src, srcrect, dst, SDL_Rect{dstpos.x, dstpos.y, 0, 0});
4003}
4004
4027 const RectRaw& srcrect,
4028 SurfaceRef dst,
4029 const RectRaw& dstrect)
4030{
4031 CheckError(SDL_BlitSurfaceUnchecked(src, &srcrect, dst, &dstrect));
4032}
4033
4035 const RectRaw& srcrect,
4036 const RectRaw& dstrect)
4037{
4038 SDL::BlitSurfaceUnchecked(src, srcrect, get(), dstrect);
4039}
4040
4064 SurfaceRef dst,
4066 ScaleMode scaleMode)
4067{
4068 CheckError(SDL_BlitSurfaceScaled(src, srcrect, dst, dstrect, scaleMode));
4069}
4070
4074 ScaleMode scaleMode)
4075{
4076 SDL::BlitSurfaceScaled(src, srcrect, get(), dstrect, scaleMode);
4077}
4078
4102 const RectRaw& srcrect,
4103 SurfaceRef dst,
4104 const RectRaw& dstrect,
4105 ScaleMode scaleMode)
4106{
4107 CheckError(
4108 SDL_BlitSurfaceUncheckedScaled(src, &srcrect, dst, &dstrect, scaleMode));
4109}
4110
4112 const RectRaw& srcrect,
4113 const RectRaw& dstrect,
4114 ScaleMode scaleMode)
4115{
4116 SDL::BlitSurfaceUncheckedScaled(src, srcrect, get(), dstrect, scaleMode);
4117}
4118
4119#if SDL_VERSION_ATLEAST(3, 4, 0)
4120
4142 OptionalRef<RectRaw> srcrect,
4143 SurfaceRef dst,
4144 OptionalRef<RectRaw> dstrect,
4145 ScaleMode scaleMode)
4146{
4147 CheckError(SDL_StretchSurface(src, srcrect, dst, dstrect, scaleMode));
4148}
4149
4151 OptionalRef<RectRaw> srcrect,
4152 OptionalRef<RectRaw> dstrect,
4153 ScaleMode scaleMode)
4154{
4155 SDL::StretchSurface(src, srcrect, get(), dstrect, scaleMode);
4156}
4157
4158#endif // SDL_VERSION_ATLEAST(3, 4, 0)
4159
4184 SurfaceRef dst,
4186{
4187 CheckError(SDL_BlitSurfaceTiled(src, srcrect, dst, dstrect));
4188}
4189
4193{
4194 SDL::BlitSurfaceTiled(src, srcrect, get(), dstrect);
4195}
4196
4225 float scale,
4226 ScaleMode scaleMode,
4227 SurfaceRef dst,
4229{
4230 CheckError(SDL_BlitSurfaceTiledWithScale(
4231 src, srcrect, scale, scaleMode, dst, dstrect));
4232}
4233
4236 float scale,
4237 ScaleMode scaleMode,
4239{
4241 src, srcrect, scale, scaleMode, get(), dstrect);
4242}
4243
4279 int left_width,
4280 int right_width,
4281 int top_height,
4282 int bottom_height,
4283 SurfaceRef dst,
4285 float scale = 1,
4286 ScaleMode scaleMode = SCALEMODE_NEAREST)
4287{
4288 CheckError(SDL_BlitSurface9Grid(src,
4289 srcrect,
4290 left_width,
4291 right_width,
4292 top_height,
4293 bottom_height,
4294 scale,
4295 scaleMode,
4296 dst,
4297 dstrect));
4298}
4299
4302 int left_width,
4303 int right_width,
4304 int top_height,
4305 int bottom_height,
4307 float scale,
4308 ScaleMode scaleMode)
4309{
4311 srcrect,
4312 left_width,
4313 right_width,
4314 top_height,
4315 bottom_height,
4316 get(),
4317 dstrect,
4318 scale,
4319 scaleMode);
4320}
4321
4354{
4355 return SDL_MapSurfaceRGB(surface, r, g, b);
4356}
4357
4359{
4360 return SDL::MapSurfaceRGB(get(), r, g, b);
4361}
4362
4393{
4394 return SDL_MapSurfaceRGBA(surface, c.r, c.g, c.b, c.a);
4395}
4396
4398{
4399 return SDL::MapSurfaceRGBA(get(), c);
4400}
4401
4429 const PointRaw& p,
4430 Uint8* r,
4431 Uint8* g,
4432 Uint8* b,
4433 Uint8* a)
4434{
4435 CheckError(SDL_ReadSurfacePixel(surface, p.x, p.y, r, g, b, a));
4436}
4437
4458{
4459 Color c;
4460 ReadSurfacePixel(surface, p, &c.r, &c.g, &c.b, &c.a);
4461 return c;
4462}
4463
4490inline void ReadSurfacePixel(const SurfaceLock& lock,
4491 const PointRaw& p,
4492 Uint8* r,
4493 Uint8* g,
4494 Uint8* b,
4495 Uint8* a)
4496{
4497 lock.ReadPixel(p, r, g, b, a);
4498}
4499
4519inline Color ReadSurfacePixel(const SurfaceLock& lock, const PointRaw& p)
4520{
4521 return lock.ReadPixel(p);
4522}
4523
4524inline void Surface::ReadPixel(const PointRaw& p,
4525 Uint8* r,
4526 Uint8* g,
4527 Uint8* b,
4528 Uint8* a) const
4529{
4530 SDL::ReadSurfacePixel(get(), p, r, g, b, a);
4531}
4532
4533inline Color Surface::ReadPixel(const PointRaw& p) const
4534{
4535 return SDL::ReadSurfacePixel(get(), p);
4536}
4537
4562 const PointRaw& p,
4563 float* r,
4564 float* g,
4565 float* b,
4566 float* a)
4567{
4568 CheckError(SDL_ReadSurfacePixelFloat(surface, p.x, p.y, r, g, b, a));
4569}
4570
4588{
4589 FColor c;
4590 ReadSurfacePixelFloat(surface, p, &c.r, &c.g, &c.b, &c.a);
4591 return c;
4592}
4593
4617inline void ReadSurfacePixelFloat(const SurfaceLock& lock,
4618 const PointRaw& p,
4619 float* r,
4620 float* g,
4621 float* b,
4622 float* a)
4623{
4624 lock.ReadPixelFloat(p, r, g, b, a);
4625}
4626
4644{
4645 return lock.ReadPixelFloat(p);
4646}
4647
4649 float* r,
4650 float* g,
4651 float* b,
4652 float* a) const
4653{
4654 SDL::ReadSurfacePixelFloat(get(), p, r, g, b, a);
4655}
4656
4658{
4659 return SDL::ReadSurfacePixelFloat(get(), p);
4660}
4661
4681inline void WriteSurfacePixel(SurfaceRef surface, const PointRaw& p, ColorRaw c)
4682{
4683 CheckError(SDL_WriteSurfacePixel(surface, p.x, p.y, c.r, c.g, c.b, c.a));
4684}
4685
4705inline void WriteSurfacePixel(SurfaceLock& lock, const PointRaw& p, ColorRaw c)
4706{
4707 lock.WritePixel(p, c);
4708}
4709
4710inline void Surface::WritePixel(const PointRaw& p, ColorRaw c)
4711{
4712 SDL::WriteSurfacePixel(get(), p, c);
4713}
4714
4732 const PointRaw& p,
4733 const FColorRaw& c)
4734{
4735 CheckError(SDL_WriteSurfacePixelFloat(surface, p.x, p.y, c.r, c.g, c.b, c.a));
4736}
4737
4755 const PointRaw& p,
4756 const FColorRaw& c)
4757{
4758 lock.WritePixelFloat(p, c);
4759}
4760
4761inline void Surface::WritePixelFloat(const PointRaw& p, const FColorRaw& c)
4762{
4764}
4765
4767constexpr int GetSurfaceWidth(SurfaceConstRef surface) { return surface->w; }
4768
4770constexpr int GetSurfaceWidth(const SurfaceLock& lock)
4771{
4772 return lock.GetWidth();
4773}
4774
4775constexpr int Surface::GetWidth() const { return SDL::GetSurfaceWidth(get()); }
4776
4778constexpr int GetSurfaceHeight(SurfaceConstRef surface) { return surface->h; }
4779
4781constexpr int GetSurfaceHeight(const SurfaceLock& lock)
4782{
4783 return lock.GetHeight();
4784}
4785
4786constexpr int Surface::GetHeight() const
4787{
4788 return SDL::GetSurfaceHeight(get());
4789}
4790
4793{
4794 return Point(surface->w, surface->h);
4795}
4796
4798constexpr Point GetSurfaceSize(const SurfaceLock& lock)
4799{
4800 return lock.GetSize();
4801}
4802
4803constexpr Point Surface::GetSize() const { return SDL::GetSurfaceSize(get()); }
4804
4806constexpr int GetSurfacePitch(SurfaceConstRef surface)
4807{
4808 return surface->pitch;
4809}
4810
4812constexpr int GetSurfacePitch(const SurfaceLock& lock)
4813{
4814 return lock.GetPitch();
4815}
4816
4817constexpr int Surface::GetPitch() const { return SDL::GetSurfacePitch(get()); }
4818
4821{
4822 return surface->format;
4823}
4824
4827{
4828 return lock.GetFormat();
4829}
4830
4832{
4833 return SDL::GetSurfaceFormat(get());
4834}
4835
4837constexpr void* GetSurfacePixels(SurfaceConstRef surface)
4838{
4839 return surface->pixels;
4840}
4841
4843constexpr void* GetSurfacePixels(const SurfaceLock& lock)
4844{
4845 return lock.GetPixels();
4846}
4847
4848constexpr void* Surface::GetPixels() const
4849{
4850 return SDL::GetSurfacePixels(get());
4851}
4852
4854
4855} // namespace SDL
4856
4857#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:2601
Rect GetClipRect() const
Get the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3359
Palette GetPalette() const
Get the palette used by a surface.
Definition SDL3pp_surface.h:2443
std::optional< Uint32 > GetColorKey() const
Get the color key (transparent pixel) for a surface.
Definition SDL3pp_surface.h:3071
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:4190
Palette CreateSurfacePalette(SurfaceRef surface)
Create a palette and associate it with a surface.
Definition SDL3pp_surface.h:2385
void SaveTrustedPNG(SurfaceConstRef surface, StringParam file)
Save a surface to a file in PNG format.
Definition SDL3pp_surface.h:2908
constexpr FlipMode FLIP_VERTICAL
flip vertically
Definition SDL3pp_surface.h:133
constexpr PixelFormat GetFormat() const
Get the pixel format.
Definition SDL3pp_surface.h:4831
Surface LoadBMP_IO(IOStreamRef src, bool closeio=false)
Load a BMP image from a seekable SDL data stream.
Definition SDL3pp_surface.h:2700
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:2994
void AddAlternateImage(SurfaceRef image)
Add an alternate version of a surface.
Definition SDL3pp_surface.h:2478
void WriteSurfacePixel(SurfaceRef surface, const PointRaw &p, ColorRaw c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:4681
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:3997
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:4234
void AddSurfaceAlternateImage(SurfaceRef surface, SurfaceRef image)
Add an alternate version of a surface.
Definition SDL3pp_surface.h:2473
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:3126
void SetSurfaceMod(SurfaceRef surface, Color color)
Set an additional color and alpha value multiplied into blit operations.
Definition SDL3pp_surface.h:3210
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:3284
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:4353
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:3159
BlendMode GetSurfaceBlendMode(SurfaceConstRef surface)
Get the blend mode used for blit operations.
Definition SDL3pp_surface.h:3277
void RemoveSurfaceAlternateImages(SurfaceRef surface)
Remove all alternate versions of a surface.
Definition SDL3pp_surface.h:2559
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:3739
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:3833
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:4358
bool HasRLE() const
Returns whether the surface is RLE enabled.
Definition SDL3pp_surface.h:2970
void LockSurface(SurfaceRef surface)
Set up a surface for directly accessing the pixels.
Definition SDL3pp_surface.h:2594
SDL_ScaleMode ScaleMode
The scaling mode.
Definition SDL3pp_surface.h:98
constexpr int GetHeight() const
Get the height in pixels.
Definition SDL3pp_surface.h:4786
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:3908
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:4277
OwnArray< SurfaceRaw > GetSurfaceImages(SurfaceConstRef surface)
Get an array including all versions of a surface.
Definition SDL3pp_surface.h:2530
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:4767
Surface RotateSurface(SurfaceRef surface, float angle)
Return a copy of a surface rotated clockwise a number of degrees.
Definition SDL3pp_surface.h:3412
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:3771
void PremultiplySurfaceAlpha(SurfaceRef surface, bool linear)
Premultiply the alpha in a surface.
Definition SDL3pp_surface.h:3712
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:2879
bool HasColorKey() const
Returns whether the surface has a color key.
Definition SDL3pp_surface.h:3041
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:2999
void PremultiplyAlpha(bool linear)
Premultiply the alpha in a surface.
Definition SDL3pp_surface.h:3717
void BlitSurfaceUnchecked(SurfaceRef src, const RectRaw &srcrect, SurfaceRef dst, const RectRaw &dstrect)
Perform low-level surface blitting only.
Definition SDL3pp_surface.h:4026
void SaveBMP(SurfaceConstRef surface, StringParam file)
Save a surface to a file in BMP format.
Definition SDL3pp_surface.h:2781
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:2390
void reset()
Release a surface after directly accessing the pixels.
Definition SDL3pp_surface.h:2628
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:2755
void WriteSurfacePixelFloat(SurfaceRef surface, const PointRaw &p, const FColorRaw &c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:4731
bool SetSurfaceClipRect(SurfaceRef surface, OptionalRef< const RectRaw > rect)
Set the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3311
Colorspace GetColorspace() const
Get the colorspace used by a surface.
Definition SDL3pp_surface.h:2353
constexpr PixelFormat GetSurfaceFormat(SurfaceConstRef surface)
Get the pixel format.
Definition SDL3pp_surface.h:4820
void SetSurfacePalette(SurfaceRef surface, PaletteRef palette)
Set the palette used by a surface.
Definition SDL3pp_surface.h:2415
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:3381
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:3916
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:4223
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:3629
Colorspace GetSurfaceColorspace(SurfaceConstRef surface)
Get the colorspace used by a surface.
Definition SDL3pp_surface.h:2348
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:4062
Surface LoadBMP(StringParam file)
Load a BMP image from a file.
Definition SDL3pp_surface.h:2723
void ResetClipRect()
Disable the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3332
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:4182
Surface ConvertSurface(SurfaceConstRef surface, PixelFormat format)
Copy an existing surface to a new surface of the specified format.
Definition SDL3pp_surface.h:3511
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:3443
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:2438
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:3472
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:2502
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:4817
void BlitUncheckedScaled(SurfaceRef src, const RectRaw &srcrect, const RectRaw &dstrect, ScaleMode scaleMode)
Perform low-level surface scaled blitting only.
Definition SDL3pp_surface.h:4111
Uint8 GetSurfaceAlphaMod(SurfaceConstRef surface)
Get the additional alpha value used in blit operations.
Definition SDL3pp_surface.h:3183
bool SurfaceHasColorKey(SurfaceConstRef surface)
Returns whether the surface has a color key.
Definition SDL3pp_surface.h:3036
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:4150
void RemoveAlternateImages()
Remove all alternate versions of a surface.
Definition SDL3pp_surface.h:2564
Surface Convert(PixelFormat format) const
Copy an existing surface to a new surface of the specified format.
Definition SDL3pp_surface.h:3516
constexpr Point GetSize() const
Get the size in pixels.
Definition SDL3pp_surface.h:4803
void SetSurfaceBlendMode(SurfaceRef surface, BlendMode blendMode)
Set the blend mode used for blit operations.
Definition SDL3pp_surface.h:3254
Surface LoadTrustedPNG_IO(IOStreamRef src, bool closeio=false)
Load a PNG image from a seekable SDL data stream.
Definition SDL3pp_surface.h:2814
Uint8 GetAlphaMod() const
Get the additional alpha value used in blit operations.
Definition SDL3pp_surface.h:3190
Surface Duplicate() const
Creates a new surface identical to the existing surface.
Definition SDL3pp_surface.h:3448
void Clear(const FColorRaw &c)
Clear a surface with a specific color, with floating point precision.
Definition SDL3pp_surface.h:3744
void UnlockSurface(SurfaceRef surface)
Release a surface after directly accessing the pixels.
Definition SDL3pp_surface.h:2620
void SetMod(Color color)
Set an additional color and alpha value multiplied into blit operations.
Definition SDL3pp_surface.h:3216
bool SurfaceHasAlternateImages(SurfaceConstRef surface)
Return whether a surface has alternate versions available.
Definition SDL3pp_surface.h:2497
bool SurfaceHasRLE(SurfaceConstRef surface)
Returns whether the surface is RLE enabled.
Definition SDL3pp_surface.h:2965
void GetColorMod(Uint8 *r, Uint8 *g, Uint8 *b) const
Get the additional color value multiplied into blit operations.
Definition SDL3pp_surface.h:3134
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:4141
SurfaceLock Lock()
Set up a surface for directly accessing the pixels.
Definition SDL3pp_surface.h:2599
constexpr ScaleMode SCALEMODE_INVALID
INVALID.
Definition SDL3pp_surface.h:102
constexpr int GetWidth() const
Get the width in pixels.
Definition SDL3pp_surface.h:4775
void SetColorMod(Uint8 r, Uint8 g, Uint8 b)
Set an additional color value multiplied into blit operations.
Definition SDL3pp_surface.h:3104
void ClearSurfaceColorKey(SurfaceRef surface)
Unset the color key (transparent pixel) in a surface.
Definition SDL3pp_surface.h:3014
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:3677
void SetBlendMode(BlendMode blendMode)
Set the blend mode used for blit operations.
Definition SDL3pp_surface.h:3259
OwnArray< SurfaceRaw > GetImages() const
Get an array including all versions of a surface.
Definition SDL3pp_surface.h:2537
Surface Rotate(float angle)
Return a copy of a surface rotated clockwise a number of degrees.
Definition SDL3pp_surface.h:3417
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:3099
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:3825
void SetPalette(PaletteRef palette)
Set the palette used by a surface.
Definition SDL3pp_surface.h:2420
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:4101
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:2941
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:3549
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:4524
constexpr void * GetSurfacePixels(SurfaceConstRef surface)
Get the pixels.
Definition SDL3pp_surface.h:4837
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:2748
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:3799
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:4778
Uint32 MapRGBA(ColorRaw c) const
Map an RGBA quadruple to a pixel value for a surface.
Definition SDL3pp_surface.h:4397
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:3479
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:4300
void SetColorspace(Colorspace colorspace)
Set the colorspace used by a surface.
Definition SDL3pp_surface.h:2325
void ClearColorKey()
Unset the color key (transparent pixel) in a surface.
Definition SDL3pp_surface.h:3019
void WritePixel(const PointRaw &p, ColorRaw c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:4710
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:4561
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:4428
void BlitUnchecked(SurfaceRef src, const RectRaw &srcrect, const RectRaw &dstrect)
Perform low-level surface blitting only.
Definition SDL3pp_surface.h:4034
Color GetSurfaceMod(SurfaceConstRef surface)
Get the additional color and alpha value multiplied into blit operations.
Definition SDL3pp_surface.h:3226
Surface LoadTrustedPNG(StringParam file)
Load a PNG image from a file.
Definition SDL3pp_surface.h:2841
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:4071
void FillRect(OptionalRef< const RectRaw > rect, Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition SDL3pp_surface.h:3778
constexpr int GetSurfacePitch(SurfaceConstRef surface)
Get pitch in bytes.
Definition SDL3pp_surface.h:4806
void Unlock(SurfaceLock &&lock)
Release a surface after directly accessing the pixels.
Definition SDL3pp_surface.h:2622
constexpr Point GetSurfaceSize(SurfaceConstRef surface)
Get the size in pixels.
Definition SDL3pp_surface.h:4792
void SaveBMP(StringParam file) const
Save a surface to a file in BMP format.
Definition SDL3pp_surface.h:2786
void ResetSurfaceClipRect(SurfaceRef surface)
Disable the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3327
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:4648
std::optional< Uint32 > GetSurfaceColorKey(SurfaceConstRef surface)
Get the color key (transparent pixel) for a surface.
Definition SDL3pp_surface.h:3065
void SetAlphaMod(Uint8 alpha)
Set an additional alpha value used in blit operations.
Definition SDL3pp_surface.h:3164
constexpr void * GetPixels() const
Get the pixels.
Definition SDL3pp_surface.h:4848
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:3923
void SetSurfaceColorspace(SurfaceRef surface, Colorspace colorspace)
Set the colorspace used by a surface.
Definition SDL3pp_surface.h:2320
void SetRLE(bool enabled)
Set the RLE acceleration hint for a surface.
Definition SDL3pp_surface.h:2946
Uint32 MapSurfaceRGBA(SurfaceConstRef surface, ColorRaw c)
Map an RGBA quadruple to a pixel value for a surface.
Definition SDL3pp_surface.h:4392
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:3588
Color GetMod() const
Get the additional color and alpha value multiplied into blit operations.
Definition SDL3pp_surface.h:3234
void FlipSurface(SurfaceRef surface, FlipMode flip)
Flip a surface vertically or horizontally.
Definition SDL3pp_surface.h:3376
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:3317
Rect GetSurfaceClipRect(SurfaceConstRef surface)
Get the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3352
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:3794
void WritePixelFloat(const PointRaw &p, const FColorRaw &c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:4761
Properties for Surface.
Definition SDL3pp_surface.h:2273
constexpr auto HOTSPOT_Y_NUMBER
Number for hotspot y.
Definition SDL3pp_surface.h:2289
constexpr auto TONEMAP_OPERATOR_STRING
String for tonemap operator.
Definition SDL3pp_surface.h:2281
constexpr auto SDR_WHITE_POINT_FLOAT
Float for sdr white point.
Definition SDL3pp_surface.h:2275
constexpr auto HDR_HEADROOM_FLOAT
Float for hdr headroom.
Definition SDL3pp_surface.h:2278
constexpr auto HOTSPOT_X_NUMBER
Number for hotspot x.
Definition SDL3pp_surface.h:2286
constexpr auto ROTATION_FLOAT
Float for rotation.
Definition SDL3pp_surface.h:2296
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