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
38// Forward decl
39struct Surface;
40
42using SurfaceRaw = SDL_Surface*;
43
46{
48
51 : value(value)
52 {
53 }
54
56 constexpr SurfaceParam(std::nullptr_t _ = nullptr)
57 : value(nullptr)
58 {
59 }
60
62 constexpr explicit operator bool() const { return !!value; }
63
65 constexpr auto operator<=>(const SurfaceParam& other) const = default;
66
68 constexpr operator SurfaceRaw() const { return value; }
69
71 constexpr auto operator->() { return value; }
72};
73
76{
78
81 : value(value)
82 {
83 }
84
88 {
89 }
90
92 constexpr SurfaceConstParam(std::nullptr_t _ = nullptr)
93 : value(nullptr)
94 {
95 }
96
98 constexpr explicit operator bool() const { return !!value; }
99
101 constexpr auto operator<=>(const SurfaceConstParam& other) const = default;
102
104 constexpr operator const SurfaceRaw() const { return value; }
105
107 constexpr auto operator->() { return value; }
108};
109
118
120 SDL_SURFACE_PREALLOCATED;
121
123 SDL_SURFACE_LOCK_NEEDED;
124
126 SDL_SURFACE_LOCKED;
127
129constexpr SurfaceFlags SURFACE_SIMD_ALIGNED = SDL_SURFACE_SIMD_ALIGNED;
130
136constexpr bool MustLock(SurfaceConstParam S) { return SDL_MUSTLOCK((S.value)); }
137
143using ScaleMode = SDL_ScaleMode;
144
145#if SDL_VERSION_ATLEAST(3, 2, 10)
146
147constexpr ScaleMode SCALEMODE_INVALID = SDL_SCALEMODE_INVALID;
148
149#endif // SDL_VERSION_ATLEAST(3, 2, 10)
150
152 SDL_SCALEMODE_NEAREST;
153
155 SDL_SCALEMODE_LINEAR;
156
162using FlipMode = SDL_FlipMode;
163
164constexpr FlipMode FLIP_NONE = SDL_FLIP_NONE;
165
166constexpr FlipMode FLIP_HORIZONTAL = SDL_FLIP_HORIZONTAL;
167
168constexpr FlipMode FLIP_VERTICAL = SDL_FLIP_VERTICAL;
169
201{
202 SurfaceRaw m_resource = nullptr;
203
204public:
206 constexpr Surface(std::nullptr_t = nullptr) noexcept
207 : m_resource(0)
208 {
209 }
210
218 constexpr explicit Surface(const SurfaceRaw resource) noexcept
219 : m_resource(resource)
220 {
221 }
222
224 constexpr Surface(const Surface& other) { ++m_resource->refcount; }
225
227 constexpr Surface(Surface&& other) noexcept
228 : Surface(other.release())
229 {
230 }
231
248 Surface(const PointRaw& size, PixelFormat format)
249 : m_resource(CheckError(SDL_CreateSurface(size.x, size.y, format)))
250 {
251 }
252
279 Surface(const PointRaw& size, PixelFormat format, void* pixels, int pitch)
280 : m_resource(CheckError(
281 SDL_CreateSurfaceFrom(size.x, size.y, format, pixels, pitch)))
282 {
283 }
284
322 Surface(StringParam file);
323
372 Surface(IOStreamParam src, bool closeio = false);
373
381 static constexpr Surface Borrow(SurfaceParam resource)
382 {
383 if (resource) {
384 ++resource.value->refcount;
385 return Surface(resource.value);
386 }
387 return {};
388 }
389
410 static Surface LoadBMP(IOStreamParam src, bool closeio = false);
411
430 static Surface LoadBMP(StringParam file);
431
433 constexpr const SurfaceRaw operator->() const noexcept { return m_resource; }
434
436 constexpr SurfaceRaw operator->() noexcept { return m_resource; }
437
439 ~Surface() { SDL_DestroySurface(m_resource); }
440
442 constexpr Surface& operator=(Surface&& other) noexcept
443 {
444 std::swap(m_resource, other.m_resource);
445 return *this;
446 }
447
449 constexpr Surface& operator=(const Surface& other) noexcept = default;
450
452 constexpr SurfaceRaw get() const noexcept { return m_resource; }
453
455 constexpr SurfaceRaw release() noexcept
456 {
457 auto r = m_resource;
458 m_resource = nullptr;
459 return r;
460 }
461
463 constexpr auto operator<=>(const Surface& other) const noexcept = default;
464
466 constexpr explicit operator bool() const noexcept { return !!m_resource; }
467
469 constexpr operator SurfaceParam() const noexcept { return {m_resource}; }
470
483 void Destroy();
484
490 constexpr bool MustLock() const { return SDL::MustLock(m_resource); }
491
524
540 void SetColorspace(Colorspace colorspace);
541
559
587
603 void SetPalette(PaletteParam palette);
604
617 Palette GetPalette() const;
618
642
656 bool HasAlternateImages() const;
657
676
692
716 void Lock();
717
729 void Unlock();
730
752 void SaveBMP(IOStreamParam dst, bool closeio = false) const;
753
773 void SaveBMP(StringParam file) const;
774
792 void SetRLE(bool enabled);
793
807 bool HasRLE() const;
808
829 void SetColorKey(std::optional<Uint32> key);
830
840 void ClearColorKey();
841
854 bool HasColorKey() const;
855
874 std::optional<Uint32> GetColorKey() const;
875
897 void SetColorMod(Uint8 r, Uint8 g, Uint8 b);
898
914 void GetColorMod(Uint8* r, Uint8* g, Uint8* b) const;
915
934 void SetAlphaMod(Uint8 alpha);
935
948 Uint8 GetAlphaMod() const;
949
964 void SetMod(Color color);
965
973 Color GetMod() const;
974
991 void SetBlendMode(BlendMode blendMode);
992
1005 BlendMode GetBlendMode() const;
1006
1029
1035 void ResetClipRect();
1036
1053 Rect GetClipRect() const;
1054
1065 void Flip(FlipMode flip);
1066
1082 Surface Duplicate() const;
1083
1099 Surface Scale(const PointRaw& size, ScaleMode scaleMode) const;
1100
1126 Surface Convert(PixelFormat format) const;
1127
1155 PaletteParam palette,
1156 Colorspace colorspace,
1157 PropertiesParam props) const;
1158
1172 void PremultiplyAlpha(bool linear);
1173
1189 void Clear(const FColorRaw& c);
1190
1214 void FillRect(OptionalRef<const RectRaw> rect, Uint32 color);
1215
1226 void Fill(Uint32 color);
1227
1250 void FillRects(SpanRef<const RectRaw> rects, Uint32 color);
1251
1321 void Blit(SurfaceParam src,
1324
1395 void BlitAt(SurfaceParam src,
1397 const PointRaw& dstpos);
1398
1419 void BlitUnchecked(SurfaceParam src,
1420 const RectRaw& srcrect,
1421 const RectRaw& dstrect);
1422
1443 void BlitScaled(SurfaceParam src,
1446 ScaleMode scaleMode);
1447
1470 const RectRaw& srcrect,
1471 const RectRaw& dstrect,
1472 ScaleMode scaleMode);
1473
1474#if SDL_VERSION_ATLEAST(3, 4, 0)
1475
1495 void Stretch(SurfaceParam src,
1496 OptionalRef<RectRaw> srcrect,
1497 OptionalRef<RectRaw> dstrect,
1498 ScaleMode scaleMode);
1499
1500#endif // SDL_VERSION_ATLEAST(3, 4, 0)
1501
1523 void BlitTiled(SurfaceParam src,
1526
1554 float scale,
1555 SDL_ScaleMode scaleMode,
1557
1590 void Blit9Grid(SurfaceParam src,
1592 int left_width,
1593 int right_width,
1594 int top_height,
1595 int bottom_height,
1597 float scale = 1,
1598 SDL_ScaleMode scaleMode = SCALEMODE_NEAREST);
1599
1629 Uint32 MapRGB(Uint8 r, Uint8 g, Uint8 b) const;
1630
1658 Uint32 MapRGBA(ColorRaw c) const;
1659
1684 void ReadPixel(const PointRaw& p,
1685 Uint8* r,
1686 Uint8* g,
1687 Uint8* b,
1688 Uint8* a) const;
1689
1704 Color ReadPixel(const PointRaw& p) const;
1705
1727 void ReadPixelFloat(const PointRaw& p,
1728 float* r,
1729 float* g,
1730 float* b,
1731 float* a) const;
1732
1747 FColor ReadPixelFloat(const PointRaw& p) const;
1748
1766 void WritePixel(const PointRaw& p, ColorRaw c);
1767
1782 void WritePixelFloat(const PointRaw& p, const FColorRaw& c);
1783
1787 constexpr int GetWidth() const;
1788
1792 constexpr int GetHeight() const;
1793
1797 constexpr Point GetSize() const;
1798
1802 constexpr int GetPitch() const;
1803
1807 constexpr PixelFormat GetFormat() const;
1808
1812 constexpr void* GetPixels() const;
1813};
1814
1832inline Surface CreateSurface(const PointRaw& size, PixelFormat format)
1833{
1834 return Surface(size, format);
1835}
1836
1864 PixelFormat format,
1865 void* pixels,
1866 int pitch)
1867{
1868 return Surface(size, format, pixels, pitch);
1869}
1870
1885inline void DestroySurface(SurfaceRaw surface) { SDL_DestroySurface(surface); }
1886
1888
1921{
1922 return {CheckError(SDL_GetSurfaceProperties(surface))};
1923}
1924
1926{
1927 return SDL::GetSurfaceProperties(m_resource);
1928}
1929
1930namespace prop::Surface {
1931
1932constexpr auto SDR_WHITE_POINT_FLOAT = SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT;
1933
1934constexpr auto HDR_HEADROOM_FLOAT = SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT;
1935
1936constexpr auto TONEMAP_OPERATOR_STRING =
1937 SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING;
1938
1939#if SDL_VERSION_ATLEAST(3, 2, 6)
1940
1941constexpr auto HOTSPOT_X_NUMBER = SDL_PROP_SURFACE_HOTSPOT_X_NUMBER;
1942
1943constexpr auto HOTSPOT_Y_NUMBER = SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER;
1944
1945#endif // SDL_VERSION_ATLEAST(3, 2, 6)
1946
1947} // namespace prop::Surface
1948
1965inline void SetSurfaceColorspace(SurfaceParam surface, Colorspace colorspace)
1966{
1967 CheckError(SDL_SetSurfaceColorspace(surface, colorspace));
1968}
1969
1970inline void Surface::SetColorspace(Colorspace colorspace)
1971{
1972 SDL::SetSurfaceColorspace(m_resource, colorspace);
1973}
1974
1993{
1994 return SDL_GetSurfaceColorspace(surface);
1995}
1996
1998{
1999 return SDL::GetSurfaceColorspace(m_resource);
2000}
2001
2029{
2030 return Palette::Borrow(CheckError(SDL_CreateSurfacePalette(surface)));
2031}
2032
2034{
2035 return SDL::CreateSurfacePalette(m_resource);
2036}
2037
2054inline void SetSurfacePalette(SurfaceParam surface, PaletteParam palette)
2055{
2056 CheckError(SDL_SetSurfacePalette(surface, palette));
2057}
2058
2060{
2061 SDL::SetSurfacePalette(m_resource, palette);
2062}
2063
2078{
2079 return Palette::Borrow(SDL_GetSurfacePalette(surface));
2080}
2081
2083{
2084 return SDL::GetSurfacePalette(m_resource);
2085}
2086
2112{
2113 CheckError(SDL_AddSurfaceAlternateImage(surface, image));
2114}
2115
2117{
2118 SDL::AddSurfaceAlternateImage(m_resource, image);
2119}
2120
2136{
2137 return SDL_SurfaceHasAlternateImages(surface);
2138}
2139
2141{
2142 return SDL::SurfaceHasAlternateImages(m_resource);
2143}
2144
2168{
2169 int count = 0;
2170 auto data = SDL_GetSurfaceImages(surface, &count);
2171 return OwnArray<SurfaceRaw>(CheckError(data), count);
2172}
2173
2175{
2176 return SDL::GetSurfaceImages(m_resource);
2177}
2178
2196{
2197 SDL_RemoveSurfaceAlternateImages(surface);
2198}
2199
2201{
2203}
2204
2229inline void LockSurface(SurfaceParam surface)
2230{
2231 CheckError(SDL_LockSurface(surface));
2232}
2233
2234inline void Surface::Lock() { SDL::LockSurface(m_resource); }
2235
2249inline void UnlockSurface(SurfaceParam surface) { SDL_UnlockSurface(surface); }
2250
2251inline void Surface::Unlock() { SDL::UnlockSurface(m_resource); }
2252
2273inline Surface LoadBMP(IOStreamParam src, bool closeio = false)
2274{
2275 return Surface(SDL_LoadBMP_IO(src, closeio));
2276}
2277
2296inline Surface LoadBMP(StringParam file) { return Surface(SDL_LoadBMP(file)); }
2297
2298inline Surface Surface::LoadBMP(IOStreamParam src, bool closeio)
2299{
2300 return SDL::LoadBMP(src, closeio);
2301}
2302
2304{
2305 return SDL::LoadBMP(std::move(file));
2306}
2307
2330inline void SaveBMP(SurfaceConstParam surface,
2331 IOStreamParam dst,
2332 bool closeio = false)
2333{
2334 CheckError(SDL_SaveBMP_IO(surface, dst, closeio));
2335}
2336
2357inline void SaveBMP(SurfaceConstParam surface, StringParam file)
2358{
2359 CheckError(SDL_SaveBMP(surface, file));
2360}
2361
2362inline void Surface::SaveBMP(IOStreamParam dst, bool closeio) const
2363{
2364 SDL::SaveBMP(m_resource, dst, closeio);
2365}
2366
2367inline void Surface::SaveBMP(StringParam file) const
2368{
2369 SDL::SaveBMP(m_resource, std::move(file));
2370}
2371
2390inline void SetSurfaceRLE(SurfaceParam surface, bool enabled)
2391{
2392 CheckError(SDL_SetSurfaceRLE(surface, enabled));
2393}
2394
2395inline void Surface::SetRLE(bool enabled)
2396{
2397 SDL::SetSurfaceRLE(m_resource, enabled);
2398}
2399
2415{
2416 return SDL_SurfaceHasRLE(surface);
2417}
2418
2419inline bool Surface::HasRLE() const { return SDL::SurfaceHasRLE(m_resource); }
2420
2442inline void SetSurfaceColorKey(SurfaceParam surface, std::optional<Uint32> key)
2443{
2444 CheckError(SDL_SetSurfaceColorKey(surface, key.has_value(), key.value_or(0)));
2445}
2446
2447inline void Surface::SetColorKey(std::optional<Uint32> key)
2448{
2449 SDL::SetSurfaceColorKey(m_resource, key);
2450}
2451
2463{
2464 SetSurfaceColorKey(surface, std::nullopt);
2465}
2466
2468
2485{
2486 return SDL_SurfaceHasColorKey(surface);
2487}
2488
2489inline bool Surface::HasColorKey() const
2490{
2491 return SDL::SurfaceHasColorKey(m_resource);
2492}
2493
2513inline std::optional<Uint32> GetSurfaceColorKey(SurfaceConstParam surface)
2514{
2515 if (Uint32 key; SDL_GetSurfaceColorKey(surface, &key)) return key;
2516 return std::nullopt;
2517}
2518
2519inline std::optional<Uint32> Surface::GetColorKey() const
2520{
2521 return SDL::GetSurfaceColorKey(m_resource);
2522}
2523
2546inline void SetSurfaceColorMod(SurfaceParam surface, Uint8 r, Uint8 g, Uint8 b)
2547{
2548 CheckError(SDL_SetSurfaceColorMod(surface, r, g, b));
2549}
2550
2552{
2553 SDL::SetSurfaceColorMod(m_resource, r, g, b);
2554}
2555
2573 Uint8* r,
2574 Uint8* g,
2575 Uint8* b)
2576{
2577 CheckError(SDL_GetSurfaceColorMod(surface, r, g, b));
2578}
2579
2580inline void Surface::GetColorMod(Uint8* r, Uint8* g, Uint8* b) const
2581{
2582 SDL::GetSurfaceColorMod(m_resource, r, g, b);
2583}
2584
2604inline void SetSurfaceAlphaMod(SurfaceParam surface, Uint8 alpha)
2605{
2606 CheckError(SDL_SetSurfaceAlphaMod(surface, alpha));
2607}
2608
2609inline void Surface::SetAlphaMod(Uint8 alpha)
2610{
2611 SDL::SetSurfaceAlphaMod(m_resource, alpha);
2612}
2613
2629{
2630 Uint8 alpha;
2631 CheckError(SDL_GetSurfaceAlphaMod(surface, &alpha));
2632 return alpha;
2633}
2634
2636{
2637 return SDL::GetSurfaceAlphaMod(m_resource);
2638}
2639
2655inline void SetSurfaceMod(SurfaceParam surface, Color color)
2656{
2657 SetSurfaceColorMod(surface, color.r, color.g, color.b);
2658 SetSurfaceAlphaMod(surface, color.a);
2659}
2660
2661inline void Surface::SetMod(Color color) { SetSurfaceMod(m_resource, color); }
2662
2672{
2673 Color c;
2674 GetSurfaceColorMod(surface, &c.r, &c.g, &c.b);
2675 c.a = GetSurfaceAlphaMod(surface);
2676 return c;
2677}
2678
2679inline Color Surface::GetMod() const { return SDL::GetSurfaceMod(m_resource); }
2680
2698inline void SetSurfaceBlendMode(SurfaceParam surface, BlendMode blendMode)
2699{
2700 CheckError(SDL_SetSurfaceBlendMode(surface, blendMode));
2701}
2702
2703inline void Surface::SetBlendMode(BlendMode blendMode)
2704{
2705 SDL::SetSurfaceBlendMode(m_resource, blendMode);
2706}
2707
2722{
2723 BlendMode blendmode;
2724 CheckError(SDL_GetSurfaceBlendMode(surface, &blendmode));
2725 return blendmode;
2726}
2727
2729{
2730 return SDL::GetSurfaceBlendMode(m_resource);
2731}
2732
2756{
2757 return SDL_SetSurfaceClipRect(surface, rect);
2758}
2759
2761{
2762 return SDL::SetSurfaceClipRect(m_resource, rect);
2763}
2764
2771{
2772 SetSurfaceClipRect(surface, std::nullopt);
2773}
2774
2776
2795{
2796 Rect r;
2797 CheckError(SDL_GetSurfaceClipRect(surface, &r));
2798 return r;
2799}
2800
2802{
2803 return SDL::GetSurfaceClipRect(m_resource);
2804}
2805
2817inline void FlipSurface(SurfaceParam surface, FlipMode flip)
2818{
2819 CheckError(SDL_FlipSurface(surface, flip));
2820}
2821
2822inline void Surface::Flip(FlipMode flip) { SDL::FlipSurface(m_resource, flip); }
2823
2843{
2844 return Surface(SDL_DuplicateSurface(surface));
2845}
2846
2848{
2849 return SDL::DuplicateSurface(m_resource);
2850}
2851
2871 const PointRaw& size,
2872 ScaleMode scaleMode)
2873{
2874 return Surface(SDL_ScaleSurface(surface, size.x, size.y, scaleMode));
2875}
2876
2877inline Surface Surface::Scale(const PointRaw& size, ScaleMode scaleMode) const
2878{
2879 return SDL::ScaleSurface(m_resource, size, scaleMode);
2880}
2881
2909{
2910 return Surface(SDL_ConvertSurface(surface, format));
2911}
2912
2914{
2915 return SDL::ConvertSurface(m_resource, format);
2916}
2917
2946 PixelFormat format,
2947 PaletteParam palette,
2948 Colorspace colorspace,
2949 PropertiesParam props)
2950{
2951 return Surface{SDL_ConvertSurfaceAndColorspace(
2952 surface, format, palette, colorspace, props)};
2953}
2954
2956 PaletteParam palette,
2957 Colorspace colorspace,
2958 PropertiesParam props) const
2959{
2961 m_resource, format, palette, colorspace, props);
2962}
2963
2984inline void ConvertPixels(const PointRaw& size,
2985 PixelFormat src_format,
2986 const void* src,
2987 int src_pitch,
2988 PixelFormat dst_format,
2989 void* dst,
2990 int dst_pitch)
2991{
2992 CheckError(SDL_ConvertPixels(
2993 size.x, size.y, src_format, src, src_pitch, dst_format, dst, dst_pitch));
2994}
2995
3025inline void ConvertPixelsAndColorspace(const PointRaw& size,
3026 PixelFormat src_format,
3027 Colorspace src_colorspace,
3028 PropertiesParam src_properties,
3029 const void* src,
3030 int src_pitch,
3031 PixelFormat dst_format,
3032 Colorspace dst_colorspace,
3033 PropertiesParam dst_properties,
3034 void* dst,
3035 int dst_pitch)
3036{
3037 CheckError(SDL_ConvertPixelsAndColorspace(size.x,
3038 size.y,
3039 src_format,
3040 src_colorspace,
3041 src_properties,
3042 src,
3043 src_pitch,
3044 dst_format,
3045 dst_colorspace,
3046 dst_properties,
3047 dst,
3048 dst_pitch));
3049}
3050
3073inline void PremultiplyAlpha(const PointRaw& size,
3074 PixelFormat src_format,
3075 const void* src,
3076 int src_pitch,
3077 PixelFormat dst_format,
3078 void* dst,
3079 int dst_pitch,
3080 bool linear)
3081{
3082 CheckError(SDL_PremultiplyAlpha(size.x,
3083 size.y,
3084 src_format,
3085 src,
3086 src_pitch,
3087 dst_format,
3088 dst,
3089 dst_pitch,
3090 linear));
3091}
3092
3107inline void PremultiplySurfaceAlpha(SurfaceParam surface, bool linear)
3108{
3109 CheckError(SDL_PremultiplySurfaceAlpha(surface, linear));
3110}
3111
3112inline void Surface::PremultiplyAlpha(bool linear)
3113{
3114 SDL::PremultiplySurfaceAlpha(m_resource, linear);
3115}
3116
3133inline void ClearSurface(SurfaceParam surface, const FColorRaw& c)
3134{
3135 CheckError(SDL_ClearSurface(surface, c.r, c.g, c.b, c.a));
3136}
3137
3138inline void Surface::Clear(const FColorRaw& c)
3139{
3140 SDL::ClearSurface(m_resource, c);
3141}
3142
3169 Uint32 color)
3170{
3171 CheckError(SDL_FillSurfaceRect(dst, rect, color));
3172}
3173
3175{
3176 SDL::FillSurfaceRect(m_resource, rect, color);
3177}
3178
3190inline void FillSurface(SurfaceParam dst, Uint32 color)
3191{
3192 FillSurfaceRect(dst, std::nullopt, color);
3193}
3194
3195inline void Surface::Fill(Uint32 color) { SDL::FillSurface(m_resource, color); }
3196
3222 Uint32 color)
3223{
3224 CheckError(SDL_FillSurfaceRects(dst, rects.data(), rects.size(), color));
3225}
3226
3228{
3229 SDL::FillSurfaceRects(m_resource, rects, color);
3230}
3231
3304 SurfaceParam dst,
3306{
3307 CheckError(SDL_BlitSurface(src, srcrect, dst, dstrect));
3308}
3309
3313{
3314 SDL::BlitSurface(src, srcrect, m_resource, dstrect);
3315}
3316
3319 const PointRaw& dstpos)
3320{
3321 Blit(src, srcrect, Rect{dstpos, {}});
3322}
3323
3393 SurfaceParam dst,
3394 const PointRaw& dstpos)
3395{
3396 BlitSurface(src, srcrect, dst, SDL_Rect{dstpos.x, dstpos.y});
3397}
3398
3421 const RectRaw& srcrect,
3422 SurfaceParam dst,
3423 const RectRaw& dstrect)
3424{
3425 CheckError(SDL_BlitSurfaceUnchecked(src, &srcrect, dst, &dstrect));
3426}
3427
3429 const RectRaw& srcrect,
3430 const RectRaw& dstrect)
3431{
3432 SDL::BlitSurfaceUnchecked(src, srcrect, m_resource, dstrect);
3433}
3434
3458 SurfaceParam dst,
3460 ScaleMode scaleMode)
3461{
3462 CheckError(SDL_BlitSurfaceScaled(src, srcrect, dst, dstrect, scaleMode));
3463}
3464
3468 ScaleMode scaleMode)
3469{
3470 SDL::BlitSurfaceScaled(src, srcrect, m_resource, dstrect, scaleMode);
3471}
3472
3496 const RectRaw& srcrect,
3497 SurfaceParam dst,
3498 const RectRaw& dstrect,
3499 ScaleMode scaleMode)
3500{
3501 CheckError(
3502 SDL_BlitSurfaceUncheckedScaled(src, &srcrect, dst, &dstrect, scaleMode));
3503}
3504
3506 const RectRaw& srcrect,
3507 const RectRaw& dstrect,
3508 ScaleMode scaleMode)
3509{
3510 SDL::BlitSurfaceUncheckedScaled(src, srcrect, m_resource, dstrect, scaleMode);
3511}
3512
3513#if SDL_VERSION_ATLEAST(3, 4, 0)
3514
3536 OptionalRef<RectRaw> srcrect,
3537 SurfaceParam dst,
3538 OptionalRef<RectRaw> dstrect,
3539 ScaleMode scaleMode)
3540{
3541 CheckError(SDL_StretchSurface(src, srcrect, dst, dstrect, scaleMode));
3542}
3543
3545 OptionalRef<RectRaw> srcrect,
3546 OptionalRef<RectRaw> dstrect,
3547 ScaleMode scaleMode)
3548{
3549 SDL::StretchSurface(src, srcrect, m_resource, dstrect, scaleMode);
3550}
3551
3552#endif // SDL_VERSION_ATLEAST(3, 4, 0)
3553
3578 SurfaceParam dst,
3580{
3581 CheckError(SDL_BlitSurfaceTiled(src, srcrect, dst, dstrect));
3582}
3583
3587{
3588 SDL::BlitSurfaceTiled(src, srcrect, m_resource, dstrect);
3589}
3590
3619 float scale,
3620 SDL_ScaleMode scaleMode,
3621 SurfaceParam dst,
3623{
3624 CheckError(SDL_BlitSurfaceTiledWithScale(
3625 src, srcrect, scale, scaleMode, dst, dstrect));
3626}
3627
3630 float scale,
3631 SDL_ScaleMode scaleMode,
3633{
3635 src, srcrect, scale, scaleMode, m_resource, dstrect);
3636}
3637
3673 int left_width,
3674 int right_width,
3675 int top_height,
3676 int bottom_height,
3677 SurfaceParam dst,
3679 float scale = 1,
3680 SDL_ScaleMode scaleMode = SCALEMODE_NEAREST)
3681{
3682 CheckError(SDL_BlitSurface9Grid(src,
3683 srcrect,
3684 left_width,
3685 right_width,
3686 top_height,
3687 bottom_height,
3688 scale,
3689 scaleMode,
3690 dst,
3691 dstrect));
3692}
3693
3696 int left_width,
3697 int right_width,
3698 int top_height,
3699 int bottom_height,
3701 float scale,
3702 SDL_ScaleMode scaleMode)
3703{
3705 srcrect,
3706 left_width,
3707 right_width,
3708 top_height,
3709 bottom_height,
3710 m_resource,
3711 dstrect,
3712 scale,
3713 scaleMode);
3714}
3715
3747 Uint8 r,
3748 Uint8 g,
3749 Uint8 b)
3750{
3751 return SDL_MapSurfaceRGB(surface, r, g, b);
3752}
3753
3755{
3756 return SDL::MapSurfaceRGB(m_resource, r, g, b);
3757}
3758
3788{
3789 return SDL_MapSurfaceRGBA(surface, c.r, c.g, c.b, c.a);
3790}
3791
3793{
3794 return SDL::MapSurfaceRGBA(m_resource, c);
3795}
3796
3823 const PointRaw& p,
3824 Uint8* r,
3825 Uint8* g,
3826 Uint8* b,
3827 Uint8* a)
3828{
3829 CheckError(SDL_ReadSurfacePixel(surface, p.x, p.y, r, g, b, a));
3830}
3831
3851{
3852 Color c;
3853 ReadSurfacePixel(surface, p, &c.r, &c.g, &c.b, &c.a);
3854 return c;
3855}
3856
3857inline void Surface::ReadPixel(const PointRaw& p,
3858 Uint8* r,
3859 Uint8* g,
3860 Uint8* b,
3861 Uint8* a) const
3862{
3863 SDL::ReadSurfacePixel(m_resource, p, r, g, b, a);
3864}
3865
3866inline Color Surface::ReadPixel(const PointRaw& p) const
3867{
3868 return SDL::ReadSurfacePixel(m_resource, p);
3869}
3870
3894 const PointRaw& p,
3895 float* r,
3896 float* g,
3897 float* b,
3898 float* a)
3899{
3900 CheckError(SDL_ReadSurfacePixelFloat(surface, p.x, p.y, r, g, b, a));
3901}
3902
3919 const PointRaw& p)
3920{
3921 FColor c;
3922 ReadSurfacePixelFloat(surface, p, &c.r, &c.g, &c.b, &c.a);
3923 return c;
3924}
3925
3927 float* r,
3928 float* g,
3929 float* b,
3930 float* a) const
3931{
3932 SDL::ReadSurfacePixelFloat(m_resource, p, r, g, b, a);
3933}
3934
3936{
3937 return SDL::ReadSurfacePixelFloat(m_resource, p);
3938}
3939
3959 const PointRaw& p,
3960 ColorRaw c)
3961{
3962 CheckError(SDL_WriteSurfacePixel(surface, p.x, p.y, c.r, c.g, c.b, c.a));
3963}
3964
3965inline void Surface::WritePixel(const PointRaw& p, ColorRaw c)
3966{
3967 SDL::WriteSurfacePixel(m_resource, p, c);
3968}
3969
3986 const PointRaw& p,
3987 const FColorRaw& c)
3988{
3989 CheckError(SDL_WriteSurfacePixelFloat(surface, p.x, p.y, c.r, c.g, c.b, c.a));
3990}
3991
3992inline void Surface::WritePixelFloat(const PointRaw& p, const FColorRaw& c)
3993{
3994 SDL::WriteSurfacePixelFloat(m_resource, p, c);
3995}
3996
4000constexpr int GetSurfaceWidth(SurfaceConstParam surface) { return surface->w; }
4001
4002constexpr int Surface::GetWidth() const
4003{
4004 return SDL::GetSurfaceWidth(m_resource);
4005}
4006
4010constexpr int GetSurfaceHeight(SurfaceConstParam surface) { return surface->h; }
4011
4012constexpr int Surface::GetHeight() const
4013{
4014 return SDL::GetSurfaceHeight(m_resource);
4015}
4016
4021{
4022 return Point(surface->w, surface->h);
4023}
4024
4025constexpr Point Surface::GetSize() const
4026{
4027 return SDL::GetSurfaceSize(m_resource);
4028}
4029
4034{
4035 return surface->pitch;
4036}
4037
4038constexpr int Surface::GetPitch() const
4039{
4040 return SDL::GetSurfacePitch(m_resource);
4041}
4042
4047{
4048 return surface->format;
4049}
4050
4052{
4053 return SDL::GetSurfaceFormat(m_resource);
4054}
4055
4059constexpr void* GetSurfacePixels(SurfaceConstParam surface)
4060{
4061 return surface->pixels;
4062}
4063
4064constexpr void* Surface::GetPixels() const
4065{
4066 return SDL::GetSurfacePixels(m_resource);
4067}
4068
4070
4071} // namespace SDL
4072
4073#endif /* SDL3PP_SURFACE_H_ */
Colorspace definitions.
Definition: SDL3pp_pixels.h:1654
Optional-like shim for references.
Definition: SDL3pp_optionalRef.h:20
Base class for SDL memory allocated array wrap.
Definition: SDL3pp_ownPtr.h:44
A set of indexed colors representing a palette.
Definition: SDL3pp_pixels.h:2476
static constexpr Palette Borrow(PaletteParam resource)
Safely borrows the from PaletteParam.
Definition: SDL3pp_pixels.h:2536
Pixel format.
Definition: SDL3pp_pixels.h:411
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
A collection of pixels used in software blitting.
Definition: SDL3pp_surface.h:201
constexpr const SurfaceRaw operator->() const noexcept
member access to underlying SurfaceRaw.
Definition: SDL3pp_surface.h:433
Surface(const PointRaw &size, PixelFormat format)
Allocate a new surface with a specific pixel format.
Definition: SDL3pp_surface.h:248
constexpr SurfaceRaw release() noexcept
Retrieves underlying SurfaceRaw and clear this.
Definition: SDL3pp_surface.h:455
constexpr Surface & operator=(Surface &&other) noexcept
Assignment operator.
Definition: SDL3pp_surface.h:442
constexpr Surface(const Surface &other)
Copy constructor.
Definition: SDL3pp_surface.h:224
constexpr SurfaceRaw operator->() noexcept
member access to underlying SurfaceRaw.
Definition: SDL3pp_surface.h:436
constexpr Surface(Surface &&other) noexcept
Move constructor.
Definition: SDL3pp_surface.h:227
constexpr Surface(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition: SDL3pp_surface.h:206
constexpr Surface(const SurfaceRaw resource) noexcept
Constructs from SurfaceParam.
Definition: SDL3pp_surface.h:218
~Surface()
Destructor.
Definition: SDL3pp_surface.h:439
constexpr auto operator<=>(const Surface &other) const noexcept=default
Comparison.
constexpr Surface & operator=(const Surface &other) noexcept=default
Assignment operator.
Surface(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:279
static constexpr Surface Borrow(SurfaceParam resource)
Safely borrows the from SurfaceParam.
Definition: SDL3pp_surface.h:381
constexpr SurfaceRaw get() const noexcept
Retrieves underlying SurfaceRaw.
Definition: SDL3pp_surface.h:452
constexpr bool MustLock() const
Evaluates to true if the surface needs to be locked before access.
Definition: SDL3pp_surface.h:490
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:197
SDL_FColor FColorRaw
Alias to raw representation for FColor.
Definition: SDL3pp_pixels.h:89
SDL_Color ColorRaw
Alias to raw representation for Color.
Definition: SDL3pp_pixels.h:83
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 LoadBMP(IOStreamParam src)
Load a BMP image directly.
Definition: SDL3pp_image.h:1354
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:341
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition: SDL3pp_stdinc.h:289
void ResetSurfaceClipRect(SurfaceParam surface)
Disable the clipping rectangle for a surface.
Definition: SDL3pp_surface.h:2770
constexpr int GetSurfaceHeight(SurfaceConstParam surface)
Get the height in pixels.
Definition: SDL3pp_surface.h:4010
void BlitSurfaceUnchecked(SurfaceParam src, const RectRaw &srcrect, SurfaceParam dst, const RectRaw &dstrect)
Perform low-level surface blitting only.
Definition: SDL3pp_surface.h:3420
Uint32 MapSurfaceRGBA(SurfaceConstParam surface, ColorRaw c)
Map an RGBA quadruple to a pixel value for a surface.
Definition: SDL3pp_surface.h:3787
Rect GetSurfaceClipRect(SurfaceConstParam surface)
Get the clipping rectangle for a surface.
Definition: SDL3pp_surface.h:2794
Surface ScaleSurface(SurfaceConstParam surface, const PointRaw &size, ScaleMode scaleMode)
Creates a new surface identical to the existing surface, scaled to the desired size.
Definition: SDL3pp_surface.h:2870
Rect GetClipRect() const
Get the clipping rectangle for a surface.
Definition: SDL3pp_surface.h:2801
void ClearSurface(SurfaceParam surface, const FColorRaw &c)
Clear a surface with a specific color, with floating point precision.
Definition: SDL3pp_surface.h:3133
Uint8 GetSurfaceAlphaMod(SurfaceConstParam surface)
Get the additional alpha value used in blit operations.
Definition: SDL3pp_surface.h:2628
Palette CreateSurfacePalette(SurfaceParam surface)
Create a palette and associate it with a surface.
Definition: SDL3pp_surface.h:2028
Palette GetPalette() const
Get the palette used by a surface.
Definition: SDL3pp_surface.h:2082
std::optional< Uint32 > GetColorKey() const
Get the color key (transparent pixel) for a surface.
Definition: SDL3pp_surface.h:2519
void SetSurfaceMod(SurfaceParam surface, Color color)
Set an additional color and alpha value multiplied into blit operations.
Definition: SDL3pp_surface.h:2655
constexpr FlipMode FLIP_VERTICAL
flip vertically
Definition: SDL3pp_surface.h:168
bool SetSurfaceClipRect(SurfaceParam surface, OptionalRef< const RectRaw > rect)
Set the clipping rectangle for a surface.
Definition: SDL3pp_surface.h:2754
constexpr PixelFormat GetFormat() const
Get the pixel format.
Definition: SDL3pp_surface.h:4051
void Destroy()
Free a surface.
Definition: SDL3pp_surface.h:1887
void BlitSurfaceScaled(SurfaceParam src, OptionalRef< const RectRaw > srcrect, SurfaceParam 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:3456
bool SurfaceHasAlternateImages(SurfaceConstParam surface)
Return whether a surface has alternate versions available.
Definition: SDL3pp_surface.h:2135
void FillSurfaceRects(SurfaceParam dst, SpanRef< const RectRaw > rects, Uint32 color)
Perform a fast fill of a set of rectangles with a specific color.
Definition: SDL3pp_surface.h:3220
constexpr SurfaceFlags SURFACE_SIMD_ALIGNED
Surface uses pixel memory allocated with aligned_alloc()
Definition: SDL3pp_surface.h:129
BlendMode GetBlendMode() const
Get the blend mode used for blit operations.
Definition: SDL3pp_surface.h:2728
constexpr SurfaceFlags SURFACE_LOCK_NEEDED
Surface needs to be locked to access pixels.
Definition: SDL3pp_surface.h:122
constexpr void * GetSurfacePixels(SurfaceConstParam surface)
Get the pixels.
Definition: SDL3pp_surface.h:4059
void SetSurfacePalette(SurfaceParam surface, PaletteParam palette)
Set the palette used by a surface.
Definition: SDL3pp_surface.h:2054
void Unlock()
Release a surface after directly accessing the pixels.
Definition: SDL3pp_surface.h:2251
bool SurfaceHasRLE(SurfaceConstParam surface)
Returns whether the surface is RLE enabled.
Definition: SDL3pp_surface.h:2414
void DestroySurface(SurfaceRaw surface)
Free a surface.
Definition: SDL3pp_surface.h:1885
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:3227
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:3754
void BlitSurfaceUncheckedScaled(SurfaceParam src, const RectRaw &srcrect, SurfaceParam dst, const RectRaw &dstrect, ScaleMode scaleMode)
Perform low-level surface scaled blitting only.
Definition: SDL3pp_surface.h:3495
bool HasRLE() const
Returns whether the surface is RLE enabled.
Definition: SDL3pp_surface.h:2419
void BlitSurface9Grid(SurfaceParam src, OptionalRef< const RectRaw > srcrect, int left_width, int right_width, int top_height, int bottom_height, SurfaceParam dst, OptionalRef< const RectRaw > dstrect, float scale=1, SDL_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:3671
constexpr int GetHeight() const
Get the height in pixels.
Definition: SDL3pp_surface.h:4012
constexpr FlipMode FLIP_NONE
Do not flip.
Definition: SDL3pp_surface.h:164
void WriteSurfacePixel(SurfaceParam surface, const PointRaw &p, ColorRaw c)
Writes a single pixel to a surface.
Definition: SDL3pp_surface.h:3958
bool SurfaceHasColorKey(SurfaceConstParam surface)
Returns whether the surface has a color key.
Definition: SDL3pp_surface.h:2484
BlendMode GetSurfaceBlendMode(SurfaceConstParam surface)
Get the blend mode used for blit operations.
Definition: SDL3pp_surface.h:2721
constexpr SurfaceFlags SURFACE_PREALLOCATED
Surface uses preallocated pixel memory.
Definition: SDL3pp_surface.h:119
void BlitSurfaceAt(SurfaceParam src, OptionalRef< const RectRaw > srcrect, SurfaceParam dst, const PointRaw &dstpos)
Performs a fast blit from the source surface to the destination surface with clipping.
Definition: SDL3pp_surface.h:3391
constexpr PixelFormat GetSurfaceFormat(SurfaceConstParam surface)
Get the pixel format.
Definition: SDL3pp_surface.h:4046
bool HasColorKey() const
Returns whether the surface has a color key.
Definition: SDL3pp_surface.h:2489
void BlitUncheckedScaled(SurfaceParam src, const RectRaw &srcrect, const RectRaw &dstrect, ScaleMode scaleMode)
Perform low-level surface scaled blitting only.
Definition: SDL3pp_surface.h:3505
constexpr ScaleMode SCALEMODE_LINEAR
linear filtering
Definition: SDL3pp_surface.h:154
void SetColorKey(std::optional< Uint32 > key)
Set the color key (transparent pixel) in a surface.
Definition: SDL3pp_surface.h:2447
void PremultiplyAlpha(bool linear)
Premultiply the alpha in a surface.
Definition: SDL3pp_surface.h:3112
void SaveBMP(IOStreamParam dst, bool closeio=false) const
Save a surface to a seekable SDL data stream in BMP format.
Definition: SDL3pp_surface.h:2362
Colorspace GetSurfaceColorspace(SurfaceConstParam surface)
Get the colorspace used by a surface.
Definition: SDL3pp_surface.h:1992
Surface DuplicateSurface(SurfaceConstParam surface)
Creates a new surface identical to the existing surface.
Definition: SDL3pp_surface.h:2842
std::optional< Uint32 > GetSurfaceColorKey(SurfaceConstParam surface)
Get the color key (transparent pixel) for a surface.
Definition: SDL3pp_surface.h:2513
Palette CreatePalette()
Create a palette and associate it with a surface.
Definition: SDL3pp_surface.h:2033
void Blit(SurfaceParam 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:3310
void SetSurfaceColorspace(SurfaceParam surface, Colorspace colorspace)
Set the colorspace used by a surface.
Definition: SDL3pp_surface.h:1965
Colorspace GetColorspace() const
Get the colorspace used by a surface.
Definition: SDL3pp_surface.h:1997
void ReadSurfacePixel(SurfaceConstParam surface, const PointRaw &p, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
Retrieves a single pixel from a surface.
Definition: SDL3pp_surface.h:3822
constexpr ScaleMode SCALEMODE_NEAREST
nearest pixel sampling
Definition: SDL3pp_surface.h:151
void Flip(FlipMode flip)
Flip a surface vertically or horizontally.
Definition: SDL3pp_surface.h:2822
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:1863
void FlipSurface(SurfaceParam surface, FlipMode flip)
Flip a surface vertically or horizontally.
Definition: SDL3pp_surface.h:2817
void ResetClipRect()
Disable the clipping rectangle for a surface.
Definition: SDL3pp_surface.h:2775
PropertiesRef GetProperties() const
Get the properties associated with a surface.
Definition: SDL3pp_surface.h:1925
void BlitTiledWithScale(SurfaceParam src, OptionalRef< const RectRaw > srcrect, float scale, SDL_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:3628
constexpr SurfaceFlags SURFACE_LOCKED
Surface is currently locked.
Definition: SDL3pp_surface.h:125
Surface ConvertSurface(SurfaceConstParam surface, PixelFormat format)
Copy an existing surface to a new surface of the specified format.
Definition: SDL3pp_surface.h:2908
constexpr Point GetSurfaceSize(SurfaceConstParam surface)
Get the size in pixels.
Definition: SDL3pp_surface.h:4020
constexpr int GetSurfaceWidth(SurfaceConstParam surface)
Get the width in pixels.
Definition: SDL3pp_surface.h:4000
bool HasAlternateImages() const
Return whether a surface has alternate versions available.
Definition: SDL3pp_surface.h:2140
void FillSurface(SurfaceParam dst, Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition: SDL3pp_surface.h:3190
SDL_Surface * SurfaceRaw
Alias to raw representation for Surface.
Definition: SDL3pp_surface.h:42
constexpr int GetPitch() const
Get pitch in bytes.
Definition: SDL3pp_surface.h:4038
void BlitSurfaceTiledWithScale(SurfaceParam src, OptionalRef< const RectRaw > srcrect, float scale, SDL_ScaleMode scaleMode, SurfaceParam 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:3617
void SetSurfaceColorMod(SurfaceParam surface, Uint8 r, Uint8 g, Uint8 b)
Set an additional color value multiplied into blit operations.
Definition: SDL3pp_surface.h:2546
Surface ConvertSurfaceAndColorspace(SurfaceConstParam surface, PixelFormat format, PaletteParam palette, Colorspace colorspace, PropertiesParam props)
Copy an existing surface to a new surface of the specified format and colorspace.
Definition: SDL3pp_surface.h:2945
void RemoveAlternateImages()
Remove all alternate versions of a surface.
Definition: SDL3pp_surface.h:2200
Surface Convert(PixelFormat format) const
Copy an existing surface to a new surface of the specified format.
Definition: SDL3pp_surface.h:2913
void Stretch(SurfaceParam src, OptionalRef< RectRaw > srcrect, OptionalRef< RectRaw > dstrect, ScaleMode scaleMode)
Perform a stretched pixel copy from one surface to another.
Definition: SDL3pp_surface.h:3544
constexpr Point GetSize() const
Get the size in pixels.
Definition: SDL3pp_surface.h:4025
void SetSurfaceAlphaMod(SurfaceParam surface, Uint8 alpha)
Set an additional alpha value used in blit operations.
Definition: SDL3pp_surface.h:2604
Uint8 GetAlphaMod() const
Get the additional alpha value used in blit operations.
Definition: SDL3pp_surface.h:2635
constexpr bool MustLock(SurfaceConstParam S)
Evaluates to true if the surface needs to be locked before access.
Definition: SDL3pp_surface.h:136
Surface Duplicate() const
Creates a new surface identical to the existing surface.
Definition: SDL3pp_surface.h:2847
static Surface LoadBMP(IOStreamParam src, bool closeio=false)
Load a BMP image from a seekable SDL data stream.
Definition: SDL3pp_surface.h:2298
void Clear(const FColorRaw &c)
Clear a surface with a specific color, with floating point precision.
Definition: SDL3pp_surface.h:3138
void BlitSurfaceTiled(SurfaceParam src, OptionalRef< const RectRaw > srcrect, SurfaceParam dst, OptionalRef< const RectRaw > dstrect)
Perform a tiled blit to a destination surface, which may be of a different format.
Definition: SDL3pp_surface.h:3576
void SetSurfaceColorKey(SurfaceParam surface, std::optional< Uint32 > key)
Set the color key (transparent pixel) in a surface.
Definition: SDL3pp_surface.h:2442
void SetSurfaceRLE(SurfaceParam surface, bool enabled)
Set the RLE acceleration hint for a surface.
Definition: SDL3pp_surface.h:2390
void SetMod(Color color)
Set an additional color and alpha value multiplied into blit operations.
Definition: SDL3pp_surface.h:2661
SDL_FlipMode FlipMode
The flip mode.
Definition: SDL3pp_surface.h:162
Uint32 MapSurfaceRGB(SurfaceConstParam surface, Uint8 r, Uint8 g, Uint8 b)
Map an RGB triple to an opaque pixel value for a surface.
Definition: SDL3pp_surface.h:3746
void GetColorMod(Uint8 *r, Uint8 *g, Uint8 *b) const
Get the additional color value multiplied into blit operations.
Definition: SDL3pp_surface.h:2580
constexpr ScaleMode SCALEMODE_INVALID
INVALID.
Definition: SDL3pp_surface.h:147
constexpr int GetWidth() const
Get the width in pixels.
Definition: SDL3pp_surface.h:4002
void UnlockSurface(SurfaceParam surface)
Release a surface after directly accessing the pixels.
Definition: SDL3pp_surface.h:2249
void PremultiplySurfaceAlpha(SurfaceParam surface, bool linear)
Premultiply the alpha in a surface.
Definition: SDL3pp_surface.h:3107
void SetColorMod(Uint8 r, Uint8 g, Uint8 b)
Set an additional color value multiplied into blit operations.
Definition: SDL3pp_surface.h:2551
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:3073
void BlitAt(SurfaceParam 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:3317
void SetBlendMode(BlendMode blendMode)
Set the blend mode used for blit operations.
Definition: SDL3pp_surface.h:2703
OwnArray< SurfaceRaw > GetImages() const
Get an array including all versions of a surface.
Definition: SDL3pp_surface.h:2174
Surface CreateSurface(const PointRaw &size, PixelFormat format)
Allocate a new surface with a specific pixel format.
Definition: SDL3pp_surface.h:1832
OwnArray< SurfaceRaw > GetSurfaceImages(SurfaceConstParam surface)
Get an array including all versions of a surface.
Definition: SDL3pp_surface.h:2167
constexpr int GetSurfacePitch(SurfaceConstParam surface)
Get pitch in bytes.
Definition: SDL3pp_surface.h:4033
constexpr FlipMode FLIP_HORIZONTAL
flip horizontally
Definition: SDL3pp_surface.h:166
void BlitScaled(SurfaceParam 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:3465
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:3857
void ReadSurfacePixelFloat(SurfaceConstParam surface, const PointRaw &p, float *r, float *g, float *b, float *a)
Retrieves a single pixel from a surface.
Definition: SDL3pp_surface.h:3893
Palette GetSurfacePalette(SurfaceConstParam surface)
Get the palette used by a surface.
Definition: SDL3pp_surface.h:2077
void StretchSurface(SurfaceParam src, OptionalRef< RectRaw > srcrect, SurfaceParam dst, OptionalRef< RectRaw > dstrect, ScaleMode scaleMode)
Perform a stretched pixel copy from one surface to another.
Definition: SDL3pp_surface.h:3535
void FillSurfaceRect(SurfaceParam dst, OptionalRef< const RectRaw > rect, Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition: SDL3pp_surface.h:3167
Color GetSurfaceMod(SurfaceConstParam surface)
Get the additional color and alpha value multiplied into blit operations.
Definition: SDL3pp_surface.h:2671
void Fill(Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition: SDL3pp_surface.h:3195
Uint32 MapRGBA(ColorRaw c) const
Map an RGBA quadruple to a pixel value for a surface.
Definition: SDL3pp_surface.h:3792
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:2877
void ConvertPixelsAndColorspace(const PointRaw &size, PixelFormat src_format, Colorspace src_colorspace, PropertiesParam src_properties, const void *src, int src_pitch, PixelFormat dst_format, Colorspace dst_colorspace, PropertiesParam 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:3025
void SetColorspace(Colorspace colorspace)
Set the colorspace used by a surface.
Definition: SDL3pp_surface.h:1970
void BlitTiled(SurfaceParam 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:3584
void SaveBMP(SurfaceConstParam surface, IOStreamParam dst, bool closeio=false)
Save a surface to a seekable SDL data stream in BMP format.
Definition: SDL3pp_surface.h:2330
void ClearColorKey()
Unset the color key (transparent pixel) in a surface.
Definition: SDL3pp_surface.h:2467
void AddSurfaceAlternateImage(SurfaceParam surface, SurfaceParam image)
Add an alternate version of a surface.
Definition: SDL3pp_surface.h:2111
Uint32 SurfaceFlags
The flags on an Surface.
Definition: SDL3pp_surface.h:117
void WritePixel(const PointRaw &p, ColorRaw c)
Writes a single pixel to a surface.
Definition: SDL3pp_surface.h:3965
PropertiesRef GetSurfaceProperties(SurfaceConstParam surface)
Get the properties associated with a surface.
Definition: SDL3pp_surface.h:1920
void BlitSurface(SurfaceParam src, OptionalRef< const RectRaw > srcrect, SurfaceParam dst, OptionalRef< const RectRaw > dstrect)
Performs a fast blit from the source surface to the destination surface with clipping.
Definition: SDL3pp_surface.h:3302
void FillRect(OptionalRef< const RectRaw > rect, Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition: SDL3pp_surface.h:3174
void Lock()
Set up a surface for directly accessing the pixels.
Definition: SDL3pp_surface.h:2234
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:3926
void GetSurfaceColorMod(SurfaceConstParam surface, Uint8 *r, Uint8 *g, Uint8 *b)
Get the additional color value multiplied into blit operations.
Definition: SDL3pp_surface.h:2572
void SetAlphaMod(Uint8 alpha)
Set an additional alpha value used in blit operations.
Definition: SDL3pp_surface.h:2609
constexpr void * GetPixels() const
Get the pixels.
Definition: SDL3pp_surface.h:4064
SDL_ScaleMode ScaleMode
The scaling mode.
Definition: SDL3pp_surface.h:143
void SetRLE(bool enabled)
Set the RLE acceleration hint for a surface.
Definition: SDL3pp_surface.h:2395
void BlitUnchecked(SurfaceParam src, const RectRaw &srcrect, const RectRaw &dstrect)
Perform low-level surface blitting only.
Definition: SDL3pp_surface.h:3428
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:2984
void ClearSurfaceColorKey(SurfaceParam surface)
Unset the color key (transparent pixel) in a surface.
Definition: SDL3pp_surface.h:2462
void WriteSurfacePixelFloat(SurfaceParam surface, const PointRaw &p, const FColorRaw &c)
Writes a single pixel to a surface.
Definition: SDL3pp_surface.h:3985
void SetPalette(PaletteParam palette)
Set the palette used by a surface.
Definition: SDL3pp_surface.h:2059
Color GetMod() const
Get the additional color and alpha value multiplied into blit operations.
Definition: SDL3pp_surface.h:2679
void LockSurface(SurfaceParam surface)
Set up a surface for directly accessing the pixels.
Definition: SDL3pp_surface.h:2229
void SetSurfaceBlendMode(SurfaceParam surface, BlendMode blendMode)
Set the blend mode used for blit operations.
Definition: SDL3pp_surface.h:2698
bool SetClipRect(OptionalRef< const RectRaw > rect)
Set the clipping rectangle for a surface.
Definition: SDL3pp_surface.h:2760
void AddAlternateImage(SurfaceParam image)
Add an alternate version of a surface.
Definition: SDL3pp_surface.h:2116
void WritePixelFloat(const PointRaw &p, const FColorRaw &c)
Writes a single pixel to a surface.
Definition: SDL3pp_surface.h:3992
void RemoveSurfaceAlternateImages(SurfaceParam surface)
Remove all alternate versions of a surface.
Definition: SDL3pp_surface.h:2195
void Blit9Grid(SurfaceParam src, OptionalRef< const RectRaw > srcrect, int left_width, int right_width, int top_height, int bottom_height, OptionalRef< const RectRaw > dstrect, float scale=1, SDL_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:3694
Main include header for the SDL3pp library.
A structure that represents a color as RGBA components.
Definition: SDL3pp_pixels.h:2189
The bits of this structure can be directly reinterpreted as a float-packed color which uses the PIXEL...
Definition: SDL3pp_pixels.h:2362
Safely wrap IOStream for non owning parameters.
Definition: SDL3pp_iostream.h:34
Safely wrap Palette for non owning parameters.
Definition: SDL3pp_pixels.h:102
The structure that defines a point (using integers).
Definition: SDL3pp_rect.h:83
Safely wrap Properties for non owning parameters.
Definition: SDL3pp_properties.h:52
Semi-safe reference for Properties.
Definition: SDL3pp_properties.h:708
A rectangle, with the origin at the upper left (using integers).
Definition: SDL3pp_rect.h:845
Safely wrap Surface for non owning const parameters.
Definition: SDL3pp_surface.h:76
constexpr SurfaceConstParam(const SurfaceRaw value)
Constructs from SurfaceRaw.
Definition: SDL3pp_surface.h:80
constexpr SurfaceConstParam(SurfaceParam value)
Constructs from SurfaceParam.
Definition: SDL3pp_surface.h:86
const SurfaceRaw value
parameter's const SurfaceRaw
Definition: SDL3pp_surface.h:77
constexpr auto operator<=>(const SurfaceConstParam &other) const =default
Comparison.
constexpr auto operator->()
member access to underlying SurfaceRaw.
Definition: SDL3pp_surface.h:107
constexpr SurfaceConstParam(std::nullptr_t _=nullptr)
Constructs null/invalid.
Definition: SDL3pp_surface.h:92
Safely wrap Surface for non owning parameters.
Definition: SDL3pp_surface.h:46
SurfaceRaw value
parameter's SurfaceRaw
Definition: SDL3pp_surface.h:47
constexpr auto operator->()
member access to underlying SurfaceRaw.
Definition: SDL3pp_surface.h:71
constexpr SurfaceParam(std::nullptr_t _=nullptr)
Constructs null/invalid.
Definition: SDL3pp_surface.h:56
constexpr SurfaceParam(SurfaceRaw value)
Constructs from SurfaceRaw.
Definition: SDL3pp_surface.h:50
constexpr auto operator<=>(const SurfaceParam &other) const =default
Comparison.