SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL3pp_surface.h
1#ifndef SDL3PP_SURFACE_H_
2#define SDL3PP_SURFACE_H_
3
4#include <SDL3/SDL_surface.h>
5#include "SDL3pp_blendmode.h"
6#include "SDL3pp_error.h"
7#include "SDL3pp_iostream.h"
8#include "SDL3pp_optionalRef.h"
9#include "SDL3pp_pixels.h"
10#include "SDL3pp_properties.h"
11#include "SDL3pp_rect.h"
12#include "SDL3pp_spanRef.h"
13#include "SDL3pp_strings.h"
14#include "SDL3pp_version.h"
15
16namespace SDL {
17
39
40// Forward decl
41struct SurfaceBase;
42
43// Forward decl
44struct Surface;
45
47using SurfaceRaw = SDL_Surface*;
48
50using SurfaceRawConst = const SDL_Surface*;
51
58
61
62// Forward decl
63struct SurfaceLock;
64
73
75 SDL_SURFACE_PREALLOCATED;
76
78 SDL_SURFACE_LOCK_NEEDED;
79
81 SDL_SURFACE_LOCKED;
82
84constexpr SurfaceFlags SURFACE_SIMD_ALIGNED = SDL_SURFACE_SIMD_ALIGNED;
85
91constexpr bool MustLock(SurfaceConstRef S)
92{
93 return SDL_MUSTLOCK((static_cast<SurfaceRawConst>(S)));
94}
95
101using ScaleMode = SDL_ScaleMode;
102
103#if SDL_VERSION_ATLEAST(3, 2, 10)
104
105constexpr ScaleMode SCALEMODE_INVALID = SDL_SCALEMODE_INVALID;
106
107#endif // SDL_VERSION_ATLEAST(3, 2, 10)
108
110 SDL_SCALEMODE_NEAREST;
111
113 SDL_SCALEMODE_LINEAR;
114
115#if SDL_VERSION_ATLEAST(3, 4, 0)
116
121constexpr ScaleMode SCALEMODE_PIXELART = SDL_SCALEMODE_PIXELART;
122
123#endif // SDL_VERSION_ATLEAST(3, 4, 0)
124
130using FlipMode = SDL_FlipMode;
131
132constexpr FlipMode FLIP_NONE = SDL_FLIP_NONE;
133
134constexpr FlipMode FLIP_HORIZONTAL = SDL_FLIP_HORIZONTAL;
135
136constexpr FlipMode FLIP_VERTICAL = SDL_FLIP_VERTICAL;
137
138#if SDL_VERSION_ATLEAST(3, 4, 0)
139
142 SDL_FLIP_HORIZONTAL_AND_VERTICAL;
143
144#endif // SDL_VERSION_ATLEAST(3, 4, 0)
145
151struct SurfaceBase : ResourceBaseT<SurfaceRaw, SurfaceRawConst>
152{
154
156 constexpr operator SurfaceConstRef() const noexcept { return get(); }
157
170 void Destroy();
171
177 constexpr bool MustLock() const { return SDL::MustLock(get()); }
178
216
233 void SetColorspace(Colorspace colorspace);
234
253
282
302 void SetPalette(PaletteRef palette);
303
316 Palette GetPalette() const;
317
341 void AddAlternateImage(SurfaceRef image);
342
356 bool HasAlternateImages() const;
357
377
394
420
432 void Unlock(SurfaceLock&& lock);
433
456 void SaveBMP_IO(IOStreamRef dst, bool closeio = false) const;
457
478 void SaveBMP(StringParam file) const;
479
499 void SavePNG_IO(IOStreamRef dst, bool closeio = false) const;
500
518 void SavePNG(StringParam file) const;
519
538 void SetRLE(bool enabled);
539
553 bool HasRLE() const;
554
576 void SetColorKey(std::optional<Uint32> key);
577
587 void ClearColorKey();
588
601 bool HasColorKey() const;
602
621 std::optional<Uint32> GetColorKey() const;
622
645 void SetColorMod(Uint8 r, Uint8 g, Uint8 b);
646
663 void GetColorMod(Uint8* r, Uint8* g, Uint8* b) const;
664
684 void SetAlphaMod(Uint8 alpha);
685
698 Uint8 GetAlphaMod() const;
699
714 void SetMod(Color color);
715
723 Color GetMod() const;
724
742 void SetBlendMode(BlendMode blendMode);
743
756 BlendMode GetBlendMode() const;
757
781
787 void ResetClipRect();
788
806 Rect GetClipRect() const;
807
819 void Flip(FlipMode flip);
820
821#if SDL_VERSION_ATLEAST(3, 4, 0)
822
849 Surface Rotate(float angle);
850
851#endif // SDL_VERSION_ATLEAST(3, 4, 0)
852
869 Surface Duplicate() const;
870
887 Surface Scale(const PointRaw& size, ScaleMode scaleMode) const;
888
915 Surface Convert(PixelFormat format) const;
916
945 PaletteRef palette,
946 Colorspace colorspace,
947 PropertiesRef props) const;
948
963 void PremultiplyAlpha(bool linear);
964
981 void Clear(const FColorRaw& c);
982
1007 void FillRect(OptionalRef<const RectRaw> rect, Uint32 color);
1008
1019 void Fill(Uint32 color);
1020
1044 void FillRects(SpanRef<const RectRaw> rects, Uint32 color);
1045
1115 void Blit(SurfaceRef src,
1118
1189 void BlitAt(SurfaceRef src,
1191 const PointRaw& dstpos);
1192
1213 void BlitUnchecked(SurfaceRef src,
1214 const RectRaw& srcrect,
1215 const RectRaw& dstrect);
1216
1237 void BlitScaled(SurfaceRef src,
1240 ScaleMode scaleMode);
1241
1264 const RectRaw& srcrect,
1265 const RectRaw& dstrect,
1266 ScaleMode scaleMode);
1267
1268#if SDL_VERSION_ATLEAST(3, 4, 0)
1269
1289 void Stretch(SurfaceRef src,
1290 OptionalRef<RectRaw> srcrect,
1291 OptionalRef<RectRaw> dstrect,
1292 ScaleMode scaleMode);
1293
1294#endif // SDL_VERSION_ATLEAST(3, 4, 0)
1295
1317 void BlitTiled(SurfaceRef src,
1320
1348 float scale,
1349 ScaleMode scaleMode,
1351
1384 void Blit9Grid(SurfaceRef src,
1386 int left_width,
1387 int right_width,
1388 int top_height,
1389 int bottom_height,
1391 float scale = 1,
1392 ScaleMode scaleMode = SCALEMODE_NEAREST);
1393
1424 Uint32 MapRGB(Uint8 r, Uint8 g, Uint8 b) const;
1425
1454 Uint32 MapRGBA(ColorRaw c) const;
1455
1481 void ReadPixel(const PointRaw& p,
1482 Uint8* r,
1483 Uint8* g,
1484 Uint8* b,
1485 Uint8* a) const;
1486
1502 Color ReadPixel(const PointRaw& p) const;
1503
1526 void ReadPixelFloat(const PointRaw& p,
1527 float* r,
1528 float* g,
1529 float* b,
1530 float* a) const;
1531
1547 FColor ReadPixelFloat(const PointRaw& p) const;
1548
1567 void WritePixel(const PointRaw& p, ColorRaw c);
1568
1584 void WritePixelFloat(const PointRaw& p, const FColorRaw& c);
1585
1587 constexpr int GetWidth() const;
1588
1590 constexpr int GetHeight() const;
1591
1593 constexpr Point GetSize() const;
1594
1596 constexpr int GetPitch() const;
1597
1599 constexpr PixelFormat GetFormat() const;
1600
1602 constexpr void* GetPixels() const;
1603
1618 void Save(StringParam filename) const;
1619
1641 void SaveTyped_IO(IOStreamRef dst,
1642 StringParam type,
1643 bool closeio = false) const;
1644};
1645
1677{
1678 using SurfaceBase::SurfaceBase;
1679
1687 constexpr explicit Surface(SurfaceRaw resource) noexcept
1688 : SurfaceBase(resource)
1689 {
1690 }
1691
1693 constexpr Surface(const Surface& other)
1694 : Surface(borrow(other.get()))
1695 {
1696 }
1697
1699 constexpr Surface(Surface&& other) noexcept
1700 : Surface(other.release())
1701 {
1702 }
1703
1720 Surface(const PointRaw& size, PixelFormat format);
1721
1748 Surface(const PointRaw& size, PixelFormat format, void* pixels, int pitch);
1749
1786 Surface(StringParam file);
1787
1835 Surface(IOStreamRef src, bool closeio = false);
1836
1844 static Surface borrow(SurfaceRaw resource)
1845 {
1846 if (resource) {
1847 ++resource->refcount;
1848 return Surface(resource);
1849 }
1850 return {};
1851 }
1852
1854 ~Surface() { SDL_DestroySurface(get()); }
1855
1857 constexpr Surface& operator=(Surface&& other) noexcept
1858 {
1859 swap(*this, other);
1860 return *this;
1861 }
1862
1865 {
1866 if (get() != other.get()) {
1867 Surface tmp(other);
1868 swap(*this, tmp);
1869 }
1870 return *this;
1871 }
1872};
1873
1892{
1893 Surface m_lock;
1894
1895public:
1922
1924 SurfaceLock(const SurfaceLock& other) = delete;
1925
1927 SurfaceLock(SurfaceLock&& other) noexcept
1928 : m_lock(std::move(other.m_lock))
1929 {
1930 }
1931
1944
1945 SurfaceLock& operator=(const SurfaceLock& other) = delete;
1946
1949 {
1950 std::swap(m_lock, other.m_lock);
1951 return *this;
1952 }
1953
1955 constexpr operator bool() const { return bool(m_lock); }
1956
1982 void ReadPixel(const PointRaw& p,
1983 Uint8* r,
1984 Uint8* g,
1985 Uint8* b,
1986 Uint8* a) const
1987 {
1988 m_lock.ReadPixel(p, r, g, b, a);
1989 }
1990
2009 Color ReadPixel(const PointRaw& p) const { return m_lock.ReadPixel(p); }
2010
2034 float* r,
2035 float* g,
2036 float* b,
2037 float* a) const
2038 {
2039 m_lock.ReadPixelFloat(p, r, g, b, a);
2040 }
2041
2058 {
2059 return m_lock.ReadPixelFloat(p);
2060 }
2061
2080 void WritePixel(const PointRaw& p, ColorRaw c) { m_lock.WritePixel(p, c); }
2081
2097 void WritePixelFloat(const PointRaw& p, const FColorRaw& c)
2098 {
2099 m_lock.WritePixelFloat(p, c);
2100 }
2101
2103 constexpr int GetWidth() const { return m_lock.GetWidth(); }
2104
2106 constexpr int GetHeight() const { return m_lock.GetHeight(); }
2107
2109 constexpr Point GetSize() const { return m_lock.GetSize(); }
2110
2112 constexpr int GetPitch() const { return m_lock.GetPitch(); }
2113
2115 constexpr PixelFormat GetFormat() const { return m_lock.GetFormat(); }
2116
2118 constexpr void* GetPixels() const { return m_lock.GetPixels(); }
2119
2131 void reset();
2132
2134 SurfaceRef resource() const { return m_lock; }
2135
2137 void release() { m_lock.release(); }
2138};
2139
2157inline Surface CreateSurface(const PointRaw& size, PixelFormat format)
2158{
2159 return Surface(size, format);
2160}
2161
2162inline Surface::Surface(const PointRaw& size, PixelFormat format)
2163 : Surface(CheckError(SDL_CreateSurface(size.x, size.y, format)))
2164{
2165}
2166
2167inline Surface::Surface(const PointRaw& size,
2168 PixelFormat format,
2169 void* pixels,
2170 int pitch)
2171 : Surface(
2172 CheckError(SDL_CreateSurfaceFrom(size.x, size.y, format, pixels, pitch)))
2173{
2174}
2175
2203 PixelFormat format,
2204 void* pixels,
2205 int pitch)
2206{
2207 return Surface(size, format, pixels, pitch);
2208}
2209
2224inline void DestroySurface(SurfaceRaw surface) { SDL_DestroySurface(surface); }
2225
2227
2266{
2267 return CheckError(SDL_GetSurfaceProperties(surface));
2268}
2269
2274
2287namespace prop::Surface {
2288
2290 SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT;
2291
2292constexpr auto HDR_HEADROOM_FLOAT =
2293 SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT;
2294
2296 SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING;
2297
2298#if SDL_VERSION_ATLEAST(3, 2, 6)
2299
2300constexpr auto HOTSPOT_X_NUMBER =
2301 SDL_PROP_SURFACE_HOTSPOT_X_NUMBER;
2302
2303constexpr auto HOTSPOT_Y_NUMBER =
2304 SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER;
2305
2306#endif // SDL_VERSION_ATLEAST(3, 2, 6)
2307
2308#if SDL_VERSION_ATLEAST(3, 4, 0)
2309
2310constexpr auto ROTATION_FLOAT =
2311 SDL_PROP_SURFACE_ROTATION_FLOAT;
2312
2313#endif // SDL_VERSION_ATLEAST(3, 4, 0)
2314
2315} // namespace prop::Surface
2316
2334inline void SetSurfaceColorspace(SurfaceRef surface, Colorspace colorspace)
2335{
2336 CheckError(SDL_SetSurfaceColorspace(surface, colorspace));
2337}
2338
2340{
2341 SDL::SetSurfaceColorspace(get(), colorspace);
2342}
2343
2363{
2364 return SDL_GetSurfaceColorspace(surface);
2365}
2366
2368{
2370}
2371
2400{
2401 return Palette::borrow(CheckError(SDL_CreateSurfacePalette(surface)));
2402}
2403
2408
2429inline void SetSurfacePalette(SurfaceRef surface, PaletteRef palette)
2430{
2431 CheckError(SDL_SetSurfacePalette(surface, palette));
2432}
2433
2435{
2436 SDL::SetSurfacePalette(get(), palette);
2437}
2438
2453{
2454 return Palette::borrow(SDL_GetSurfacePalette(surface));
2455}
2456
2458{
2459 return SDL::GetSurfacePalette(get());
2460}
2461
2488{
2489 CheckError(SDL_AddSurfaceAlternateImage(surface, image));
2490}
2491
2496
2512{
2513 return SDL_SurfaceHasAlternateImages(surface);
2514}
2515
2517{
2519}
2520
2545{
2546 int count = 0;
2547 auto data = SDL_GetSurfaceImages(surface, &count);
2548 return OwnArray<SurfaceRaw>(CheckError(data), count);
2549}
2550
2555
2574{
2575 SDL_RemoveSurfaceAlternateImages(surface);
2576}
2577
2582
2608inline void LockSurface(SurfaceRef surface)
2609{
2610 CheckError(SDL_LockSurface(surface));
2611}
2612
2613inline SurfaceLock SurfaceBase::Lock() { return {SurfaceRef(*this)}; }
2614
2616 : m_lock(resource)
2617{
2618 LockSurface(m_lock);
2619}
2620
2634inline void UnlockSurface(SurfaceRef surface) { SDL_UnlockSurface(surface); }
2635
2637{
2638 SDL_assert_paranoid(lock.resource() == *this);
2639 std::move(lock).reset();
2640}
2641
2643{
2644 if (!m_lock) return;
2645 UnlockSurface(m_lock);
2646 m_lock = {};
2647}
2648
2649#if !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC) && \
2650 SDL_VERSION_ATLEAST(3, 4, 0)
2651
2668inline Surface LoadSurface_IO(IOStreamRef src, bool closeio = false)
2669{
2670 return Surface{SDL_LoadSurface_IO(src, closeio)};
2671}
2672
2687inline Surface LoadSurface(StringParam file)
2688{
2689 return Surface{SDL_LoadSurface(file)};
2690}
2691
2692#endif // !defined(SDL3PP_ENABLE_IMAGE) && SDL_VERSION_ATLEAST(3, 4, 0)
2693
2714inline Surface LoadBMP_IO(IOStreamRef src, bool closeio = false)
2715{
2716 return Surface(SDL_LoadBMP_IO(src, closeio));
2717}
2718
2737inline Surface LoadBMP(StringParam file) { return Surface(SDL_LoadBMP(file)); }
2738
2762inline void SaveBMP_IO(SurfaceConstRef surface,
2763 IOStreamRef dst,
2764 bool closeio = false)
2765{
2766 CheckError(SDL_SaveBMP_IO(surface, dst, closeio));
2767}
2768
2769inline void SurfaceBase::SaveBMP_IO(IOStreamRef dst, bool closeio) const
2770{
2771 SDL::SaveBMP_IO(get(), dst, closeio);
2772}
2773
2795inline void SaveBMP(SurfaceConstRef surface, StringParam file)
2796{
2797 CheckError(SDL_SaveBMP(surface, file));
2798}
2799
2800inline void SurfaceBase::SaveBMP(StringParam file) const
2801{
2802 SDL::SaveBMP(get(), std::move(file));
2803}
2804
2805#if SDL_VERSION_ATLEAST(3, 4, 0)
2806
2828inline Surface LoadTrustedPNG_IO(IOStreamRef src, bool closeio = false)
2829{
2830 return Surface(SDL_LoadPNG_IO(src, closeio));
2831}
2832
2856{
2857 return Surface(SDL_LoadPNG(file));
2858}
2859
2860#if !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2861
2863inline Surface LoadPNG_IO(IOStreamRef src, bool closeio = false)
2864{
2865 return LoadTrustedPNG_IO(src, closeio);
2866}
2867
2869inline Surface LoadPNG(StringParam file)
2870{
2871 return LoadTrustedPNG(std::move(file));
2872}
2873
2874#endif // !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2875
2894 IOStreamRef dst,
2895 bool closeio = false)
2896{
2897 CheckError(SDL_SavePNG_IO(surface, dst, closeio));
2898}
2899
2900#if !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2901inline void Surface::SavePNG_IO(IOStreamRef dst, bool closeio) const
2902{
2903 SDL::SaveTrustedPNG_IO(get(), dst, closeio);
2904}
2905#endif // !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2906
2923{
2924 CheckError(SDL_SavePNG(surface, file));
2925}
2926
2927#if !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2928inline void Surface::SavePNG(StringParam file) const
2929{
2930 SDL::SaveTrustedPNG(get(), std::move(file));
2931}
2932#endif // !defined(SDL3PP_ENABLE_IMAGE) && !defined(SDL3PP_DOC)
2933
2934#endif // SDL_VERSION_ATLEAST(3, 4, 0)
2935
2955inline void SetSurfaceRLE(SurfaceRef surface, bool enabled)
2956{
2957 CheckError(SDL_SetSurfaceRLE(surface, enabled));
2958}
2959
2960inline void SurfaceBase::SetRLE(bool enabled)
2961{
2962 SDL::SetSurfaceRLE(get(), enabled);
2963}
2964
2979inline bool SurfaceHasRLE(SurfaceConstRef surface)
2980{
2981 return SDL_SurfaceHasRLE(surface);
2982}
2983
2984inline bool SurfaceBase::HasRLE() const { return SDL::SurfaceHasRLE(get()); }
2985
3008inline void SetSurfaceColorKey(SurfaceRef surface, std::optional<Uint32> key)
3009{
3010 CheckError(SDL_SetSurfaceColorKey(surface, key.has_value(), key.value_or(0)));
3011}
3012
3013inline void SurfaceBase::SetColorKey(std::optional<Uint32> key)
3014{
3016}
3017
3029{
3030 SetSurfaceColorKey(surface, std::nullopt);
3031}
3032
3034
3051{
3052 return SDL_SurfaceHasColorKey(surface);
3053}
3054
3055inline bool SurfaceBase::HasColorKey() const
3056{
3057 return SDL::SurfaceHasColorKey(get());
3058}
3059
3079inline std::optional<Uint32> GetSurfaceColorKey(SurfaceConstRef surface)
3080{
3081 if (Uint32 key; SDL_GetSurfaceColorKey(surface, &key)) return key;
3082 return std::nullopt;
3083}
3084
3085inline std::optional<Uint32> SurfaceBase::GetColorKey() const
3086{
3087 return SDL::GetSurfaceColorKey(get());
3088}
3089
3113inline void SetSurfaceColorMod(SurfaceRef surface, Uint8 r, Uint8 g, Uint8 b)
3114{
3115 CheckError(SDL_SetSurfaceColorMod(surface, r, g, b));
3116}
3117
3119{
3120 SDL::SetSurfaceColorMod(get(), r, g, b);
3121}
3122
3141 Uint8* r,
3142 Uint8* g,
3143 Uint8* b)
3144{
3145 CheckError(SDL_GetSurfaceColorMod(surface, r, g, b));
3146}
3147
3148inline void SurfaceBase::GetColorMod(Uint8* r, Uint8* g, Uint8* b) const
3149{
3150 SDL::GetSurfaceColorMod(get(), r, g, b);
3151}
3152
3173inline void SetSurfaceAlphaMod(SurfaceRef surface, Uint8 alpha)
3174{
3175 CheckError(SDL_SetSurfaceAlphaMod(surface, alpha));
3176}
3177
3179{
3180 SDL::SetSurfaceAlphaMod(get(), alpha);
3181}
3182
3198{
3199 Uint8 alpha;
3200 CheckError(SDL_GetSurfaceAlphaMod(surface, &alpha));
3201 return alpha;
3202}
3203
3205{
3206 return SDL::GetSurfaceAlphaMod(get());
3207}
3208
3224inline void SetSurfaceMod(SurfaceRef surface, Color color)
3225{
3226 SetSurfaceColorMod(surface, color.r, color.g, color.b);
3227 SetSurfaceAlphaMod(surface, color.a);
3228}
3229
3230inline void SurfaceBase::SetMod(Color color) { SetSurfaceMod(get(), color); }
3231
3241{
3242 Color c;
3243 GetSurfaceColorMod(surface, &c.r, &c.g, &c.b);
3244 c.a = GetSurfaceAlphaMod(surface);
3245 return c;
3246}
3247
3248inline Color SurfaceBase::GetMod() const { return GetSurfaceMod(get()); }
3249
3268inline void SetSurfaceBlendMode(SurfaceRef surface, BlendMode blendMode)
3269{
3270 CheckError(SDL_SetSurfaceBlendMode(surface, blendMode));
3271}
3272
3274{
3275 SDL::SetSurfaceBlendMode(get(), blendMode);
3276}
3277
3292{
3293 BlendMode blendmode;
3294 CheckError(SDL_GetSurfaceBlendMode(surface, &blendmode));
3295 return blendmode;
3296}
3297
3299{
3300 return SDL::GetSurfaceBlendMode(get());
3301}
3302
3326inline bool SetSurfaceClipRect(SurfaceRef surface,
3328{
3329 return SDL_SetSurfaceClipRect(surface, rect);
3330}
3331
3333{
3334 return SDL::SetSurfaceClipRect(get(), rect);
3335}
3336
3343{
3344 SetSurfaceClipRect(surface, std::nullopt);
3345}
3346
3348
3368{
3369 Rect r;
3370 CheckError(SDL_GetSurfaceClipRect(surface, &r));
3371 return r;
3372}
3373
3375{
3376 return SDL::GetSurfaceClipRect(get());
3377}
3378
3391inline void FlipSurface(SurfaceRef surface, FlipMode flip)
3392{
3393 CheckError(SDL_FlipSurface(surface, flip));
3394}
3395
3396inline void SurfaceBase::Flip(FlipMode flip) { SDL::FlipSurface(get(), flip); }
3397
3398#if SDL_VERSION_ATLEAST(3, 4, 0)
3399
3427inline Surface RotateSurface(SurfaceRef surface, float angle)
3428{
3429 return Surface{SDL_RotateSurface(surface, angle)};
3430}
3431
3432inline Surface SurfaceBase::Rotate(float angle)
3433{
3434 return SDL::RotateSurface(get(), angle);
3435}
3436
3437#endif // SDL_VERSION_ATLEAST(3, 4, 0)
3438
3459{
3460 return Surface(SDL_DuplicateSurface(surface));
3461}
3462
3464{
3465 return SDL::DuplicateSurface(get());
3466}
3467
3488 const PointRaw& size,
3489 ScaleMode scaleMode)
3490{
3491 return Surface(SDL_ScaleSurface(surface, size.x, size.y, scaleMode));
3492}
3493
3495 ScaleMode scaleMode) const
3496{
3497 return SDL::ScaleSurface(get(), size, scaleMode);
3498}
3499
3528{
3529 return Surface(SDL_ConvertSurface(surface, format));
3530}
3531
3533{
3534 return SDL::ConvertSurface(get(), format);
3535}
3536
3566 PixelFormat format,
3567 PaletteRef palette,
3568 Colorspace colorspace,
3569 PropertiesRef props)
3570{
3571 return Surface{SDL_ConvertSurfaceAndColorspace(
3572 surface, format, palette, colorspace, props)};
3573}
3574
3576 PaletteRef palette,
3577 Colorspace colorspace,
3578 PropertiesRef props) const
3579{
3581 get(), format, palette, colorspace, props);
3582}
3583
3604inline void ConvertPixels(const PointRaw& size,
3605 PixelFormat src_format,
3606 const void* src,
3607 int src_pitch,
3608 PixelFormat dst_format,
3609 void* dst,
3610 int dst_pitch)
3611{
3612 CheckError(SDL_ConvertPixels(
3613 size.x, size.y, src_format, src, src_pitch, dst_format, dst, dst_pitch));
3614}
3615
3645inline void ConvertPixelsAndColorspace(const PointRaw& size,
3646 PixelFormat src_format,
3647 Colorspace src_colorspace,
3648 PropertiesRef src_properties,
3649 const void* src,
3650 int src_pitch,
3651 PixelFormat dst_format,
3652 Colorspace dst_colorspace,
3653 PropertiesRef dst_properties,
3654 void* dst,
3655 int dst_pitch)
3656{
3657 CheckError(SDL_ConvertPixelsAndColorspace(size.x,
3658 size.y,
3659 src_format,
3660 src_colorspace,
3661 src_properties,
3662 src,
3663 src_pitch,
3664 dst_format,
3665 dst_colorspace,
3666 dst_properties,
3667 dst,
3668 dst_pitch));
3669}
3670
3693inline void PremultiplyAlpha(const PointRaw& size,
3694 PixelFormat src_format,
3695 const void* src,
3696 int src_pitch,
3697 PixelFormat dst_format,
3698 void* dst,
3699 int dst_pitch,
3700 bool linear)
3701{
3702 CheckError(SDL_PremultiplyAlpha(size.x,
3703 size.y,
3704 src_format,
3705 src,
3706 src_pitch,
3707 dst_format,
3708 dst,
3709 dst_pitch,
3710 linear));
3711}
3712
3728inline void PremultiplySurfaceAlpha(SurfaceRef surface, bool linear)
3729{
3730 CheckError(SDL_PremultiplySurfaceAlpha(surface, linear));
3731}
3732
3733inline void SurfaceBase::PremultiplyAlpha(bool linear)
3734{
3736}
3737
3755inline void ClearSurface(SurfaceRef surface, const FColorRaw& c)
3756{
3757 CheckError(SDL_ClearSurface(surface, c.r, c.g, c.b, c.a));
3758}
3759
3760inline void SurfaceBase::Clear(const FColorRaw& c) { ClearSurface(get(), c); }
3761
3789 Uint32 color)
3790{
3791 CheckError(SDL_FillSurfaceRect(dst, rect, color));
3792}
3793
3795{
3796 SDL::FillSurfaceRect(get(), rect, color);
3797}
3798
3810inline void FillSurface(SurfaceRef dst, Uint32 color)
3811{
3812 FillSurfaceRect(dst, std::nullopt, color);
3813}
3814
3815inline void SurfaceBase::Fill(Uint32 color) { FillSurface(get(), color); }
3816
3843 Uint32 color)
3844{
3845 CheckError(
3846 SDL_FillSurfaceRects(dst, rects.data(), narrowS32(rects.size()), color));
3847}
3848
3850{
3851 SDL::FillSurfaceRects(get(), rects, color);
3852}
3853
3924inline void BlitSurface(SurfaceRef src,
3926 SurfaceRef dst,
3928{
3929 CheckError(SDL_BlitSurface(src, srcrect, dst, dstrect));
3930}
3931
3935{
3936 SDL::BlitSurface(src, srcrect, get(), dstrect);
3937}
3938
3941 const PointRaw& dstpos)
3942{
3943 Blit(src, srcrect, Rect{dstpos, {}});
3944}
3945
4015 SurfaceRef dst,
4016 const PointRaw& dstpos)
4017{
4018 BlitSurface(src, srcrect, dst, SDL_Rect{dstpos.x, dstpos.y, 0, 0});
4019}
4020
4043 const RectRaw& srcrect,
4044 SurfaceRef dst,
4045 const RectRaw& dstrect)
4046{
4047 CheckError(SDL_BlitSurfaceUnchecked(src, &srcrect, dst, &dstrect));
4048}
4049
4051 const RectRaw& srcrect,
4052 const RectRaw& dstrect)
4053{
4054 SDL::BlitSurfaceUnchecked(src, srcrect, get(), dstrect);
4055}
4056
4080 SurfaceRef dst,
4082 ScaleMode scaleMode)
4083{
4084 CheckError(SDL_BlitSurfaceScaled(src, srcrect, dst, dstrect, scaleMode));
4085}
4086
4090 ScaleMode scaleMode)
4091{
4092 SDL::BlitSurfaceScaled(src, srcrect, get(), dstrect, scaleMode);
4093}
4094
4118 const RectRaw& srcrect,
4119 SurfaceRef dst,
4120 const RectRaw& dstrect,
4121 ScaleMode scaleMode)
4122{
4123 CheckError(
4124 SDL_BlitSurfaceUncheckedScaled(src, &srcrect, dst, &dstrect, scaleMode));
4125}
4126
4128 const RectRaw& srcrect,
4129 const RectRaw& dstrect,
4130 ScaleMode scaleMode)
4131{
4132 SDL::BlitSurfaceUncheckedScaled(src, srcrect, get(), dstrect, scaleMode);
4133}
4134
4135#if SDL_VERSION_ATLEAST(3, 4, 0)
4136
4158 OptionalRef<RectRaw> srcrect,
4159 SurfaceRef dst,
4160 OptionalRef<RectRaw> dstrect,
4161 ScaleMode scaleMode)
4162{
4163 CheckError(SDL_StretchSurface(src, srcrect, dst, dstrect, scaleMode));
4164}
4165
4167 OptionalRef<RectRaw> srcrect,
4168 OptionalRef<RectRaw> dstrect,
4169 ScaleMode scaleMode)
4170{
4171 SDL::StretchSurface(src, srcrect, get(), dstrect, scaleMode);
4172}
4173
4174#endif // SDL_VERSION_ATLEAST(3, 4, 0)
4175
4200 SurfaceRef dst,
4202{
4203 CheckError(SDL_BlitSurfaceTiled(src, srcrect, dst, dstrect));
4204}
4205
4209{
4210 SDL::BlitSurfaceTiled(src, srcrect, get(), dstrect);
4211}
4212
4241 float scale,
4242 ScaleMode scaleMode,
4243 SurfaceRef dst,
4245{
4246 CheckError(SDL_BlitSurfaceTiledWithScale(
4247 src, srcrect, scale, scaleMode, dst, dstrect));
4248}
4249
4252 float scale,
4253 ScaleMode scaleMode,
4255{
4257 src, srcrect, scale, scaleMode, get(), dstrect);
4258}
4259
4295 int left_width,
4296 int right_width,
4297 int top_height,
4298 int bottom_height,
4299 SurfaceRef dst,
4301 float scale = 1,
4302 ScaleMode scaleMode = SCALEMODE_NEAREST)
4303{
4304 CheckError(SDL_BlitSurface9Grid(src,
4305 srcrect,
4306 left_width,
4307 right_width,
4308 top_height,
4309 bottom_height,
4310 scale,
4311 scaleMode,
4312 dst,
4313 dstrect));
4314}
4315
4318 int left_width,
4319 int right_width,
4320 int top_height,
4321 int bottom_height,
4323 float scale,
4324 ScaleMode scaleMode)
4325{
4327 srcrect,
4328 left_width,
4329 right_width,
4330 top_height,
4331 bottom_height,
4332 get(),
4333 dstrect,
4334 scale,
4335 scaleMode);
4336}
4337
4370{
4371 return SDL_MapSurfaceRGB(surface, r, g, b);
4372}
4373
4375{
4376 return SDL::MapSurfaceRGB(get(), r, g, b);
4377}
4378
4409{
4410 return SDL_MapSurfaceRGBA(surface, c.r, c.g, c.b, c.a);
4411}
4412
4414{
4415 return SDL::MapSurfaceRGBA(get(), c);
4416}
4417
4445 const PointRaw& p,
4446 Uint8* r,
4447 Uint8* g,
4448 Uint8* b,
4449 Uint8* a)
4450{
4451 CheckError(SDL_ReadSurfacePixel(surface, p.x, p.y, r, g, b, a));
4452}
4453
4474{
4475 Color c;
4476 ReadSurfacePixel(surface, p, &c.r, &c.g, &c.b, &c.a);
4477 return c;
4478}
4479
4506inline void ReadSurfacePixel(const SurfaceLock& lock,
4507 const PointRaw& p,
4508 Uint8* r,
4509 Uint8* g,
4510 Uint8* b,
4511 Uint8* a)
4512{
4513 lock.ReadPixel(p, r, g, b, a);
4514}
4515
4535inline Color ReadSurfacePixel(const SurfaceLock& lock, const PointRaw& p)
4536{
4537 return lock.ReadPixel(p);
4538}
4539
4541 Uint8* r,
4542 Uint8* g,
4543 Uint8* b,
4544 Uint8* a) const
4545{
4546 SDL::ReadSurfacePixel(get(), p, r, g, b, a);
4547}
4548
4550{
4551 return SDL::ReadSurfacePixel(get(), p);
4552}
4553
4578 const PointRaw& p,
4579 float* r,
4580 float* g,
4581 float* b,
4582 float* a)
4583{
4584 CheckError(SDL_ReadSurfacePixelFloat(surface, p.x, p.y, r, g, b, a));
4585}
4586
4604{
4605 FColor c;
4606 ReadSurfacePixelFloat(surface, p, &c.r, &c.g, &c.b, &c.a);
4607 return c;
4608}
4609
4633inline void ReadSurfacePixelFloat(const SurfaceLock& lock,
4634 const PointRaw& p,
4635 float* r,
4636 float* g,
4637 float* b,
4638 float* a)
4639{
4640 lock.ReadPixelFloat(p, r, g, b, a);
4641}
4642
4660{
4661 return lock.ReadPixelFloat(p);
4662}
4663
4665 float* r,
4666 float* g,
4667 float* b,
4668 float* a) const
4669{
4670 SDL::ReadSurfacePixelFloat(get(), p, r, g, b, a);
4671}
4672
4674{
4675 return SDL::ReadSurfacePixelFloat(get(), p);
4676}
4677
4697inline void WriteSurfacePixel(SurfaceRef surface, const PointRaw& p, ColorRaw c)
4698{
4699 CheckError(SDL_WriteSurfacePixel(surface, p.x, p.y, c.r, c.g, c.b, c.a));
4700}
4701
4721inline void WriteSurfacePixel(SurfaceLock& lock, const PointRaw& p, ColorRaw c)
4722{
4723 lock.WritePixel(p, c);
4724}
4725
4727{
4728 SDL::WriteSurfacePixel(get(), p, c);
4729}
4730
4748 const PointRaw& p,
4749 const FColorRaw& c)
4750{
4751 CheckError(SDL_WriteSurfacePixelFloat(surface, p.x, p.y, c.r, c.g, c.b, c.a));
4752}
4753
4771 const PointRaw& p,
4772 const FColorRaw& c)
4773{
4774 lock.WritePixelFloat(p, c);
4775}
4776
4777inline void SurfaceBase::WritePixelFloat(const PointRaw& p, const FColorRaw& c)
4778{
4780}
4781
4783constexpr int GetSurfaceWidth(SurfaceConstRef surface) { return surface->w; }
4784
4786constexpr int GetSurfaceWidth(const SurfaceLock& lock)
4787{
4788 return lock.GetWidth();
4789}
4790
4791constexpr int SurfaceBase::GetWidth() const { return GetSurfaceWidth(get()); }
4792
4794constexpr int GetSurfaceHeight(SurfaceConstRef surface) { return surface->h; }
4795
4797constexpr int GetSurfaceHeight(const SurfaceLock& lock)
4798{
4799 return lock.GetHeight();
4800}
4801
4802constexpr int SurfaceBase::GetHeight() const { return GetSurfaceHeight(get()); }
4803
4806{
4807 return Point(surface->w, surface->h);
4808}
4809
4811constexpr Point GetSurfaceSize(const SurfaceLock& lock)
4812{
4813 return lock.GetSize();
4814}
4815
4816constexpr Point SurfaceBase::GetSize() const { return GetSurfaceSize(get()); }
4817
4819constexpr int GetSurfacePitch(SurfaceConstRef surface)
4820{
4821 return surface->pitch;
4822}
4823
4825constexpr int GetSurfacePitch(const SurfaceLock& lock)
4826{
4827 return lock.GetPitch();
4828}
4829
4830constexpr int SurfaceBase::GetPitch() const { return GetSurfacePitch(get()); }
4831
4834{
4835 return surface->format;
4836}
4837
4840{
4841 return lock.GetFormat();
4842}
4843
4845{
4846 return SDL::GetSurfaceFormat(get());
4847}
4848
4850constexpr void* GetSurfacePixels(SurfaceConstRef surface)
4851{
4852 return surface->pixels;
4853}
4854
4856constexpr void* GetSurfacePixels(const SurfaceLock& lock)
4857{
4858 return lock.GetPixels();
4859}
4860
4861constexpr void* SurfaceBase::GetPixels() const
4862{
4863 return SDL::GetSurfacePixels(get());
4864}
4865
4867
4868} // namespace SDL
4869
4870#endif /* SDL3PP_SURFACE_H_ */
Colorspace definitions.
Definition SDL3pp_pixels.h:1583
Optional-like shim for references.
Definition SDL3pp_optionalRef.h:20
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:44
Pixel format.
Definition SDL3pp_pixels.h:361
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:57
friend constexpr void swap(ResourceBaseT &lhs, ResourceBaseT &rhs) noexcept
Definition SDL3pp_resource.h:65
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:54
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
Const reference wrapper for a given resource,.
Definition SDL3pp_resource.h:115
span-like for empty-derived structs
Definition SDL3pp_spanRef.h:24
constexpr T * data() const
Retrieves contained data.
Definition SDL3pp_spanRef.h:75
constexpr size_t size() const
Retrieves contained size.
Definition SDL3pp_spanRef.h:69
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
Set up a surface for directly accessing the pixels.
Definition SDL3pp_surface.h:1892
SurfaceRef resource() const
Get the reference to locked resource.
Definition SDL3pp_surface.h:2134
constexpr PixelFormat GetFormat() const
Get the pixel format.
Definition SDL3pp_surface.h:2115
SurfaceLock(SurfaceLock &&other) noexcept
Move constructor.
Definition SDL3pp_surface.h:1927
FColor ReadPixelFloat(const PointRaw &p) const
Retrieves a single pixel from a surface.
Definition SDL3pp_surface.h:2057
~SurfaceLock()
Release a surface after directly accessing the pixels.
Definition SDL3pp_surface.h:1943
constexpr int GetHeight() const
Get the height in pixels.
Definition SDL3pp_surface.h:2106
constexpr int GetWidth() const
Get the width in pixels.
Definition SDL3pp_surface.h:2103
constexpr void * GetPixels() const
Get the pixels.
Definition SDL3pp_surface.h:2118
void release()
Releases the lock without unlocking.
Definition SDL3pp_surface.h:2137
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:1982
void WritePixelFloat(const PointRaw &p, const FColorRaw &c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:2097
SurfaceLock & operator=(SurfaceLock &&other) noexcept
Assignment operator.
Definition SDL3pp_surface.h:1948
void WritePixel(const PointRaw &p, ColorRaw c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:2080
constexpr Point GetSize() const
Get the size in pixels.
Definition SDL3pp_surface.h:2109
Color ReadPixel(const PointRaw &p) const
Retrieves a single pixel from a surface.
Definition SDL3pp_surface.h:2009
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:2033
constexpr int GetPitch() const
Get pitch in bytes.
Definition SDL3pp_surface.h:2112
#define SDL_assert_paranoid(condition)
An assertion test that is performed only when built with paranoid settings.
Definition SDL3pp_assert.h:383
Uint32 BlendMode
A set of blend modes used in drawing operations.
Definition SDL3pp_blendmode.h:35
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:199
ResourceRefT< IOStreamBase > IOStreamRef
Reference for IOStream.
Definition SDL3pp_iostream.h:37
SDL_Color ColorRaw
Alias to raw representation for Color.
Definition SDL3pp_pixels.h:83
SDL_FColor FColorRaw
Alias to raw representation for FColor.
Definition SDL3pp_pixels.h:89
ResourceRefT< PaletteBase > PaletteRef
Reference for Palette.
Definition SDL3pp_pixels.h:111
ResourceRefT< PropertiesBase > PropertiesRef
Reference for Properties.
Definition SDL3pp_properties.h:53
SDL_Rect RectRaw
Alias to raw representation for Rect.
Definition SDL3pp_rect.h:34
SDL_Point PointRaw
Alias to raw representation for Point.
Definition SDL3pp_rect.h:22
Surface LoadPNG_IO(IOStreamRef src)
Load a PNG image directly.
Definition SDL3pp_image.h:1742
Surface LoadPNG(StringParam file)
Load a PNG image from a file.
Definition SDL3pp_image.h:1820
void SavePNG(StringParam file) const
Save a surface to a file in PNG format.
Definition SDL3pp_image.h:2549
void Save(StringParam filename) const
Save an Surface into an image file.
Definition SDL3pp_image.h:2249
Surface LoadSurface_IO(IOStreamRef src, bool closeio=false)
Load an image from an SDL data source into a software surface.
Definition SDL3pp_image.h:221
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:2293
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:2579
Surface LoadSurface(StringParam file)
Load an image from a filesystem path into a software surface.
Definition SDL3pp_image.h:164
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition SDL3pp_stdinc.h:296
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition SDL3pp_stdinc.h:244
SurfaceLock(SurfaceRef resource)
Set up a surface for directly accessing the pixels.
Definition SDL3pp_surface.h:2615
constexpr int GetHeight() const
Get the height in pixels.
Definition SDL3pp_surface.h:4802
void BlitUnchecked(SurfaceRef src, const RectRaw &srcrect, const RectRaw &dstrect)
Perform low-level surface blitting only.
Definition SDL3pp_surface.h:4050
void SetPalette(PaletteRef palette)
Set the palette used by a surface.
Definition SDL3pp_surface.h:2434
Surface Convert(PixelFormat format) const
Copy an existing surface to a new surface of the specified format.
Definition SDL3pp_surface.h:3532
void SaveBMP(StringParam file) const
Save a surface to a file in BMP format.
Definition SDL3pp_surface.h:2800
Palette CreateSurfacePalette(SurfaceRef surface)
Create a palette and associate it with a surface.
Definition SDL3pp_surface.h:2399
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:4206
void SaveTrustedPNG(SurfaceConstRef surface, StringParam file)
Save a surface to a file in PNG format.
Definition SDL3pp_surface.h:2922
constexpr FlipMode FLIP_VERTICAL
flip vertically
Definition SDL3pp_surface.h:136
SurfaceLock Lock()
Set up a surface for directly accessing the pixels.
Definition SDL3pp_surface.h:2613
void ClearColorKey()
Unset the color key (transparent pixel) in a surface.
Definition SDL3pp_surface.h:3033
Surface LoadBMP_IO(IOStreamRef src, bool closeio=false)
Load a BMP image from a seekable SDL data stream.
Definition SDL3pp_surface.h:2714
void SetSurfaceColorKey(SurfaceRef surface, std::optional< Uint32 > key)
Set the color key (transparent pixel) in a surface.
Definition SDL3pp_surface.h:3008
void WriteSurfacePixel(SurfaceRef surface, const PointRaw &p, ColorRaw c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:4697
constexpr int GetWidth() const
Get the width in pixels.
Definition SDL3pp_surface.h:4791
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:4013
void Destroy()
Free this surface.
Definition SDL3pp_surface.h:2226
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:3939
void Unlock(SurfaceLock &&lock)
Release a surface after directly accessing the pixels.
Definition SDL3pp_surface.h:2636
void AddSurfaceAlternateImage(SurfaceRef surface, SurfaceRef image)
Add an alternate version of a surface.
Definition SDL3pp_surface.h:2487
SDL_FlipMode FlipMode
The flip mode.
Definition SDL3pp_surface.h:130
void GetSurfaceColorMod(SurfaceConstRef surface, Uint8 *r, Uint8 *g, Uint8 *b)
Get the additional color value multiplied into blit operations.
Definition SDL3pp_surface.h:3140
OwnArray< SurfaceRaw > GetImages() const
Get an array including all versions of a surface.
Definition SDL3pp_surface.h:2551
Colorspace GetColorspace() const
Get the colorspace used by a surface.
Definition SDL3pp_surface.h:2367
void SetSurfaceMod(SurfaceRef surface, Color color)
Set an additional color and alpha value multiplied into blit operations.
Definition SDL3pp_surface.h:3224
Uint8 GetAlphaMod() const
Get the additional alpha value used in blit operations.
Definition SDL3pp_surface.h:3204
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:4540
constexpr SurfaceFlags SURFACE_SIMD_ALIGNED
Surface uses pixel memory allocated with aligned_alloc().
Definition SDL3pp_surface.h:84
Uint32 MapSurfaceRGB(SurfaceConstRef surface, Uint8 r, Uint8 g, Uint8 b)
Map an RGB triple to an opaque pixel value for a surface.
Definition SDL3pp_surface.h:4369
constexpr PixelFormat GetFormat() const
Get the pixel format.
Definition SDL3pp_surface.h:4844
constexpr SurfaceFlags SURFACE_LOCK_NEEDED
Surface needs to be locked to access pixels.
Definition SDL3pp_surface.h:77
void BlitScaled(SurfaceRef src, OptionalRef< const RectRaw > srcrect, OptionalRef< const RectRaw > dstrect, ScaleMode scaleMode)
Perform a scaled blit to a destination surface, which may be of a different format.
Definition SDL3pp_surface.h:4087
void SetSurfaceAlphaMod(SurfaceRef surface, Uint8 alpha)
Set an additional alpha value used in blit operations.
Definition SDL3pp_surface.h:3173
void AddAlternateImage(SurfaceRef image)
Add an alternate version of a surface.
Definition SDL3pp_surface.h:2492
BlendMode GetSurfaceBlendMode(SurfaceConstRef surface)
Get the blend mode used for blit operations.
Definition SDL3pp_surface.h:3291
void RemoveSurfaceAlternateImages(SurfaceRef surface)
Remove all alternate versions of a surface.
Definition SDL3pp_surface.h:2573
constexpr Point GetSize() const
Get the size in pixels.
Definition SDL3pp_surface.h:4816
void DestroySurface(SurfaceRaw surface)
Free a surface.
Definition SDL3pp_surface.h:2224
void ClearSurface(SurfaceRef surface, const FColorRaw &c)
Clear a surface with a specific color, with floating point precision.
Definition SDL3pp_surface.h:3755
std::optional< Uint32 > GetColorKey() const
Get the color key (transparent pixel) for a surface.
Definition SDL3pp_surface.h:3085
void LockSurface(SurfaceRef surface)
Set up a surface for directly accessing the pixels.
Definition SDL3pp_surface.h:2608
SDL_ScaleMode ScaleMode
The scaling mode.
Definition SDL3pp_surface.h:101
constexpr FlipMode FLIP_NONE
Do not flip.
Definition SDL3pp_surface.h:132
void BlitSurface(SurfaceRef src, OptionalRef< const RectRaw > srcrect, SurfaceRef dst, OptionalRef< const RectRaw > dstrect)
Performs a fast blit from the source surface to the destination surface with clipping.
Definition SDL3pp_surface.h:3924
void RemoveAlternateImages()
Remove all alternate versions of a surface.
Definition SDL3pp_surface.h:2578
Color GetMod() const
Get the additional color and alpha value multiplied into blit operations.
Definition SDL3pp_surface.h:3248
void Clear(const FColorRaw &c)
Clear a surface with a specific color, with floating point precision.
Definition SDL3pp_surface.h:3760
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:4293
bool SetClipRect(OptionalRef< const RectRaw > rect)
Set the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3332
OwnArray< SurfaceRaw > GetSurfaceImages(SurfaceConstRef surface)
Get an array including all versions of a surface.
Definition SDL3pp_surface.h:2544
constexpr bool MustLock(SurfaceConstRef S)
Evaluates to true if the surface needs to be locked before access.
Definition SDL3pp_surface.h:91
constexpr int GetSurfaceWidth(SurfaceConstRef surface)
Get the width in pixels.
Definition SDL3pp_surface.h:4783
Surface RotateSurface(SurfaceRef surface, float angle)
Return a copy of a surface rotated clockwise a number of degrees.
Definition SDL3pp_surface.h:3427
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:3787
void PremultiplySurfaceAlpha(SurfaceRef surface, bool linear)
Premultiply the alpha in a surface.
Definition SDL3pp_surface.h:3728
constexpr SurfaceFlags SURFACE_PREALLOCATED
Surface uses preallocated pixel memory.
Definition SDL3pp_surface.h:74
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:2893
Surface Duplicate() const
Creates a new surface identical to the existing surface.
Definition SDL3pp_surface.h:3463
constexpr ScaleMode SCALEMODE_LINEAR
linear filtering
Definition SDL3pp_surface.h:112
void ReadPixelFloat(const PointRaw &p, float *r, float *g, float *b, float *a) const
Retrieves a single pixel from a surface.
Definition SDL3pp_surface.h:4664
void BlitSurfaceUnchecked(SurfaceRef src, const RectRaw &srcrect, SurfaceRef dst, const RectRaw &dstrect)
Perform low-level surface blitting only.
Definition SDL3pp_surface.h:4042
void SaveBMP(SurfaceConstRef surface, StringParam file)
Save a surface to a file in BMP format.
Definition SDL3pp_surface.h:2795
void Fill(Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition SDL3pp_surface.h:3815
SDL_Surface * SurfaceRaw
Alias to raw representation for Surface.
Definition SDL3pp_surface.h:47
void reset()
Release a surface after directly accessing the pixels.
Definition SDL3pp_surface.h:2642
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:3932
void WriteSurfacePixelFloat(SurfaceRef surface, const PointRaw &p, const FColorRaw &c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:4747
bool SetSurfaceClipRect(SurfaceRef surface, OptionalRef< const RectRaw > rect)
Set the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3326
constexpr PixelFormat GetSurfaceFormat(SurfaceConstRef surface)
Get the pixel format.
Definition SDL3pp_surface.h:4833
void SetSurfacePalette(SurfaceRef surface, PaletteRef palette)
Set the palette used by a surface.
Definition SDL3pp_surface.h:2429
constexpr ScaleMode SCALEMODE_NEAREST
nearest pixel sampling
Definition SDL3pp_surface.h:109
Surface CreateSurfaceFrom(const PointRaw &size, PixelFormat format, void *pixels, int pitch)
Allocate a new surface with a specific pixel format and existing pixel data.
Definition SDL3pp_surface.h:2202
void SetRLE(bool enabled)
Set the RLE acceleration hint for a surface.
Definition SDL3pp_surface.h:2960
PropertiesRef GetSurfaceProperties(SurfaceConstRef surface)
Get the properties associated with a surface.
Definition SDL3pp_surface.h:2265
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:4239
bool HasColorKey() const
Returns whether the surface has a color key.
Definition SDL3pp_surface.h:3055
void FillRect(OptionalRef< const RectRaw > rect, Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition SDL3pp_surface.h:3794
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:3645
Colorspace GetSurfaceColorspace(SurfaceConstRef surface)
Get the colorspace used by a surface.
Definition SDL3pp_surface.h:2362
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:4078
Surface LoadBMP(StringParam file)
Load a BMP image from a file.
Definition SDL3pp_surface.h:2737
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:4198
Surface ConvertSurface(SurfaceConstRef surface, PixelFormat format)
Copy an existing surface to a new surface of the specified format.
Definition SDL3pp_surface.h:3527
PropertiesRef GetProperties() const
Get the properties associated with a surface.
Definition SDL3pp_surface.h:2270
Surface DuplicateSurface(SurfaceConstRef surface)
Creates a new surface identical to the existing surface.
Definition SDL3pp_surface.h:3458
constexpr ScaleMode SCALEMODE_PIXELART
nearest pixel sampling with improved scaling for pixel art, available since SDL 3....
Definition SDL3pp_surface.h:121
bool HasRLE() const
Returns whether the surface is RLE enabled.
Definition SDL3pp_surface.h:2984
Palette GetSurfacePalette(SurfaceConstRef surface)
Get the palette used by a surface.
Definition SDL3pp_surface.h:2452
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:3487
void GetColorMod(Uint8 *r, Uint8 *g, Uint8 *b) const
Get the additional color value multiplied into blit operations.
Definition SDL3pp_surface.h:3148
constexpr SurfaceFlags SURFACE_LOCKED
Surface is currently locked.
Definition SDL3pp_surface.h:80
void SetMod(Color color)
Set an additional color and alpha value multiplied into blit operations.
Definition SDL3pp_surface.h:3230
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:4374
Surface Rotate(float angle)
Return a copy of a surface rotated clockwise a number of degrees.
Definition SDL3pp_surface.h:3432
constexpr void * GetPixels() const
Get the pixels.
Definition SDL3pp_surface.h:4861
const SDL_Surface * SurfaceRawConst
Alias to const raw representation for Surface.
Definition SDL3pp_surface.h:50
void BlitTiledWithScale(SurfaceRef src, OptionalRef< const RectRaw > srcrect, float scale, ScaleMode scaleMode, OptionalRef< const RectRaw > dstrect)
Perform a scaled and tiled blit to a destination surface, which may be of a different format.
Definition SDL3pp_surface.h:4250
Uint8 GetSurfaceAlphaMod(SurfaceConstRef surface)
Get the additional alpha value used in blit operations.
Definition SDL3pp_surface.h:3197
bool SurfaceHasColorKey(SurfaceConstRef surface)
Returns whether the surface has a color key.
Definition SDL3pp_surface.h:3050
Rect GetClipRect() const
Get the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3374
void SetSurfaceBlendMode(SurfaceRef surface, BlendMode blendMode)
Set the blend mode used for blit operations.
Definition SDL3pp_surface.h:3268
Surface LoadTrustedPNG_IO(IOStreamRef src, bool closeio=false)
Load a PNG image from a seekable SDL data stream.
Definition SDL3pp_surface.h:2828
Palette CreatePalette()
Create a palette and associate it with a surface.
Definition SDL3pp_surface.h:2404
void SetBlendMode(BlendMode blendMode)
Set the blend mode used for blit operations.
Definition SDL3pp_surface.h:3273
void UnlockSurface(SurfaceRef surface)
Release a surface after directly accessing the pixels.
Definition SDL3pp_surface.h:2634
void PremultiplyAlpha(bool linear)
Premultiply the alpha in a surface.
Definition SDL3pp_surface.h:3733
void SetColorKey(std::optional< Uint32 > key)
Set the color key (transparent pixel) in a surface.
Definition SDL3pp_surface.h:3013
void BlitUncheckedScaled(SurfaceRef src, const RectRaw &srcrect, const RectRaw &dstrect, ScaleMode scaleMode)
Perform low-level surface scaled blitting only.
Definition SDL3pp_surface.h:4127
ResourceRefT< SurfaceBase > SurfaceRef
Reference for Surface.
Definition SDL3pp_surface.h:57
bool SurfaceHasAlternateImages(SurfaceConstRef surface)
Return whether a surface has alternate versions available.
Definition SDL3pp_surface.h:2511
bool SurfaceHasRLE(SurfaceConstRef surface)
Returns whether the surface is RLE enabled.
Definition SDL3pp_surface.h:2979
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:4157
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:2769
constexpr ScaleMode SCALEMODE_INVALID
INVALID.
Definition SDL3pp_surface.h:105
constexpr int GetPitch() const
Get pitch in bytes.
Definition SDL3pp_surface.h:4830
void ClearSurfaceColorKey(SurfaceRef surface)
Unset the color key (transparent pixel) in a surface.
Definition SDL3pp_surface.h:3028
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:3693
bool HasAlternateImages() const
Return whether a surface has alternate versions available.
Definition SDL3pp_surface.h:2516
Surface CreateSurface(const PointRaw &size, PixelFormat format)
Allocate a new surface with a specific pixel format.
Definition SDL3pp_surface.h:2157
void SetSurfaceColorMod(SurfaceRef surface, Uint8 r, Uint8 g, Uint8 b)
Set an additional color value multiplied into blit operations.
Definition SDL3pp_surface.h:3113
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:3841
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:4117
Uint32 MapRGBA(ColorRaw c) const
Map an RGBA quadruple to a pixel value for a surface.
Definition SDL3pp_surface.h:4413
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:4316
constexpr FlipMode FLIP_HORIZONTAL
flip horizontally
Definition SDL3pp_surface.h:134
Surface Scale(const PointRaw &size, ScaleMode scaleMode) const
Creates a new surface identical to the existing surface, scaled to the desired size.
Definition SDL3pp_surface.h:3494
void SetSurfaceRLE(SurfaceRef surface, bool enabled)
Set the RLE acceleration hint for a surface.
Definition SDL3pp_surface.h:2955
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:3565
BlendMode GetBlendMode() const
Get the blend mode used for blit operations.
Definition SDL3pp_surface.h:3298
void WritePixel(const PointRaw &p, ColorRaw c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:4726
constexpr void * GetSurfacePixels(SurfaceConstRef surface)
Get the pixels.
Definition SDL3pp_surface.h:4850
void SetColorspace(Colorspace colorspace)
Set the colorspace used by a surface.
Definition SDL3pp_surface.h:2339
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:2762
Uint32 SurfaceFlags
The flags on an Surface.
Definition SDL3pp_surface.h:72
ResourceConstRef< SurfaceRaw, SurfaceRawConst > SurfaceConstRef
Safely wrap Surface for non owning const parameters.
Definition SDL3pp_surface.h:60
void Stretch(SurfaceRef src, OptionalRef< RectRaw > srcrect, OptionalRef< RectRaw > dstrect, ScaleMode scaleMode)
Perform a stretched pixel copy from one surface to another.
Definition SDL3pp_surface.h:4166
constexpr int GetSurfaceHeight(SurfaceConstRef surface)
Get the height in pixels.
Definition SDL3pp_surface.h:4794
void SetAlphaMod(Uint8 alpha)
Set an additional alpha value used in blit operations.
Definition SDL3pp_surface.h:3178
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:3849
void SetColorMod(Uint8 r, Uint8 g, Uint8 b)
Set an additional color value multiplied into blit operations.
Definition SDL3pp_surface.h:3118
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:4577
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:4444
Color GetSurfaceMod(SurfaceConstRef surface)
Get the additional color and alpha value multiplied into blit operations.
Definition SDL3pp_surface.h:3240
Surface LoadTrustedPNG(StringParam file)
Load a PNG image from a file.
Definition SDL3pp_surface.h:2855
constexpr int GetSurfacePitch(SurfaceConstRef surface)
Get pitch in bytes.
Definition SDL3pp_surface.h:4819
constexpr Point GetSurfaceSize(SurfaceConstRef surface)
Get the size in pixels.
Definition SDL3pp_surface.h:4805
void ResetSurfaceClipRect(SurfaceRef surface)
Disable the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3342
std::optional< Uint32 > GetSurfaceColorKey(SurfaceConstRef surface)
Get the color key (transparent pixel) for a surface.
Definition SDL3pp_surface.h:3079
Palette GetPalette() const
Get the palette used by a surface.
Definition SDL3pp_surface.h:2457
void WritePixelFloat(const PointRaw &p, const FColorRaw &c)
Writes a single pixel to a surface.
Definition SDL3pp_surface.h:4777
void SetSurfaceColorspace(SurfaceRef surface, Colorspace colorspace)
Set the colorspace used by a surface.
Definition SDL3pp_surface.h:2334
void Flip(FlipMode flip)
Flip a surface vertically or horizontally.
Definition SDL3pp_surface.h:3396
Uint32 MapSurfaceRGBA(SurfaceConstRef surface, ColorRaw c)
Map an RGBA quadruple to a pixel value for a surface.
Definition SDL3pp_surface.h:4408
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:3604
void FlipSurface(SurfaceRef surface, FlipMode flip)
Flip a surface vertically or horizontally.
Definition SDL3pp_surface.h:3391
constexpr FlipMode FLIP_HORIZONTAL_AND_VERTICAL
flip horizontally and vertically (not a diagonal flip)
Definition SDL3pp_surface.h:141
Rect GetSurfaceClipRect(SurfaceConstRef surface)
Get the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3367
void FillSurface(SurfaceRef dst, Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition SDL3pp_surface.h:3810
void ResetClipRect()
Disable the clipping rectangle for a surface.
Definition SDL3pp_surface.h:3347
Properties for Surface.
Definition SDL3pp_surface.h:2287
constexpr auto HOTSPOT_Y_NUMBER
Number for hotspot y.
Definition SDL3pp_surface.h:2303
constexpr auto TONEMAP_OPERATOR_STRING
String for tonemap operator.
Definition SDL3pp_surface.h:2295
constexpr auto SDR_WHITE_POINT_FLOAT
Float for sdr white point.
Definition SDL3pp_surface.h:2289
constexpr auto HDR_HEADROOM_FLOAT
Float for hdr headroom.
Definition SDL3pp_surface.h:2292
constexpr auto HOTSPOT_X_NUMBER
Number for hotspot x.
Definition SDL3pp_surface.h:2300
constexpr auto ROTATION_FLOAT
Float for rotation.
Definition SDL3pp_surface.h:2310
Main include header for the SDL3pp library.
Sint32 narrowS32(T value)
Narrows to Sint32.
Definition SDL3pp_stdinc.h:6263
A structure that represents a color as RGBA components.
Definition SDL3pp_pixels.h:2121
The bits of this structure can be directly reinterpreted as a float-packed color which uses the PIXEL...
Definition SDL3pp_pixels.h:2294
A set of indexed colors representing a palette.
Definition SDL3pp_pixels.h:2498
static Palette borrow(PaletteRaw resource)
Safely borrows the from PaletteRaw.
Definition SDL3pp_pixels.h:2551
The structure that defines a point (using integers).
Definition SDL3pp_rect.h:97
A rectangle, with the origin at the upper left (using integers).
Definition SDL3pp_rect.h:706
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:93
Base class to Surface.
Definition SDL3pp_surface.h:152
constexpr bool MustLock() const
Evaluates to true if the surface needs to be locked before access.
Definition SDL3pp_surface.h:177
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
A collection of pixels used in software blitting.
Definition SDL3pp_surface.h:1677
Surface & operator=(const Surface &other)
Assignment operator.
Definition SDL3pp_surface.h:1864
static Surface borrow(SurfaceRaw resource)
Safely borrows the from SurfaceRaw.
Definition SDL3pp_surface.h:1844
constexpr Surface & operator=(Surface &&other) noexcept
Assignment operator.
Definition SDL3pp_surface.h:1857
constexpr Surface(SurfaceRaw resource) noexcept
Constructs from raw Surface.
Definition SDL3pp_surface.h:1687
constexpr Surface(const Surface &other)
Copy constructor.
Definition SDL3pp_surface.h:1693
constexpr Surface(Surface &&other) noexcept
Move constructor.
Definition SDL3pp_surface.h:1699
~Surface()
Destructor.
Definition SDL3pp_surface.h:1854