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() = default;
207
215 constexpr explicit Surface(const SurfaceRaw resource)
216 : m_resource(resource)
217 {
218 }
219
221 constexpr Surface(const Surface& other) { ++m_resource->refcount; }
222
224 constexpr Surface(Surface&& other)
225 : Surface(other.release())
226 {
227 }
228
245 Surface(const PointRaw& size, PixelFormat format)
246 : m_resource(CheckError(SDL_CreateSurface(size.x, size.y, format)))
247 {
248 }
249
276 Surface(const PointRaw& size, PixelFormat format, void* pixels, int pitch)
277 : m_resource(CheckError(
278 SDL_CreateSurfaceFrom(size.x, size.y, format, pixels, pitch)))
279 {
280 }
281
320 Surface(StringParam file);
321
371 Surface(IOStreamParam src, bool closeio = false);
372
380 static constexpr Surface Borrow(SurfaceParam resource)
381 {
382 if (resource) {
383 ++resource.value->refcount;
384 return Surface(resource.value);
385 }
386 return {};
387 }
388
409 static Surface LoadBMP(IOStreamParam src, bool closeio = false);
410
429 static Surface LoadBMP(StringParam file);
430
432 constexpr const SurfaceRaw operator->() const { return m_resource; }
433
435 constexpr SurfaceRaw operator->() { return m_resource; }
436
438 ~Surface() { SDL_DestroySurface(m_resource); }
439
442 {
443 std::swap(m_resource, other.m_resource);
444 return *this;
445 }
446
448 constexpr SurfaceRaw get() const { return m_resource; }
449
451 constexpr SurfaceRaw release()
452 {
453 auto r = m_resource;
454 m_resource = nullptr;
455 return r;
456 }
457
459 constexpr auto operator<=>(const Surface& other) const = default;
460
462 constexpr bool operator==(std::nullptr_t _) const { return !m_resource; }
463
465 constexpr explicit operator bool() const { return !!m_resource; }
466
468 constexpr operator SurfaceParam() const { return {m_resource}; }
469
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
693
717 void Lock();
718
731 void Unlock();
732
754 void SaveBMP(IOStreamParam dst, bool closeio = false) const;
755
775 void SaveBMP(StringParam file) const;
776
794 void SetRLE(bool enabled);
795
809 bool HasRLE() const;
810
832 void SetColorKey(std::optional<Uint32> key);
833
843 void ClearColorKey();
844
857 bool HasColorKey() const;
858
877 std::optional<Uint32> GetColorKey() const;
878
900 void SetColorMod(Uint8 r, Uint8 g, Uint8 b);
901
917 void GetColorMod(Uint8* r, Uint8* g, Uint8* b) const;
918
937 void SetAlphaMod(Uint8 alpha);
938
951 Uint8 GetAlphaMod() const;
952
967 void SetMod(Color color);
968
976 Color GetMod() const;
977
994 void SetBlendMode(BlendMode blendMode);
995
1008 BlendMode GetBlendMode() const;
1009
1032
1038 void ResetClipRect();
1039
1056 Rect GetClipRect() const;
1057
1068 void Flip(FlipMode flip);
1069
1085 Surface Duplicate() const;
1086
1102 Surface Scale(const PointRaw& size, ScaleMode scaleMode) const;
1103
1129 Surface Convert(PixelFormat format) const;
1130
1158 PaletteParam palette,
1159 Colorspace colorspace,
1160 PropertiesParam props) const;
1161
1175 void PremultiplyAlpha(bool linear);
1176
1192 void Clear(const FColorRaw& c);
1193
1217 void FillRect(OptionalRef<const RectRaw> rect, Uint32 color);
1218
1229 void Fill(Uint32 color);
1230
1253 void FillRects(SpanRef<const RectRaw> rects, Uint32 color);
1254
1324 void Blit(SurfaceParam src,
1327
1398 void BlitAt(SurfaceParam src,
1400 const PointRaw& dstpos);
1401
1422 void BlitUnchecked(SurfaceParam src,
1423 const RectRaw& srcrect,
1424 const RectRaw& dstrect);
1425
1446 void BlitScaled(SurfaceParam src,
1449 ScaleMode scaleMode);
1450
1473 const RectRaw& srcrect,
1474 const RectRaw& dstrect,
1475 ScaleMode scaleMode);
1476
1477#if SDL_VERSION_ATLEAST(3, 4, 0)
1478
1498 void Stretch(SurfaceParam src,
1499 OptionalRef<RectRaw> srcrect,
1500 OptionalRef<RectRaw> dstrect,
1501 ScaleMode scaleMode);
1502
1503#endif // SDL_VERSION_ATLEAST(3, 4, 0)
1504
1527 void BlitTiled(SurfaceParam src,
1530
1559 float scale,
1560 SDL_ScaleMode scaleMode,
1562
1596 void Blit9Grid(SurfaceParam src,
1598 int left_width,
1599 int right_width,
1600 int top_height,
1601 int bottom_height,
1603 float scale = 1,
1604 SDL_ScaleMode scaleMode = SCALEMODE_NEAREST);
1605
1635 Uint32 MapRGB(Uint8 r, Uint8 g, Uint8 b) const;
1636
1664 Uint32 MapRGBA(ColorRaw c) const;
1665
1690 void ReadPixel(const PointRaw& p,
1691 Uint8* r,
1692 Uint8* g,
1693 Uint8* b,
1694 Uint8* a) const;
1695
1710 Color ReadPixel(const PointRaw& p) const;
1711
1733 void ReadPixelFloat(const PointRaw& p,
1734 float* r,
1735 float* g,
1736 float* b,
1737 float* a) const;
1738
1753 FColor ReadPixelFloat(const PointRaw& p) const;
1754
1772 void WritePixel(const PointRaw& p, ColorRaw c);
1773
1788 void WritePixelFloat(const PointRaw& p, const FColorRaw& c);
1789
1793 constexpr int GetWidth() const;
1794
1798 constexpr int GetHeight() const;
1799
1803 constexpr Point GetSize() const;
1804
1808 constexpr int GetPitch() const;
1809
1813 constexpr PixelFormat GetFormat() const;
1814
1818 constexpr void* GetPixels() const;
1819};
1820
1838inline Surface CreateSurface(const PointRaw& size, PixelFormat format)
1839{
1840 return Surface(size, format);
1841}
1842
1871 PixelFormat format,
1872 void* pixels,
1873 int pitch)
1874{
1875 return Surface(size, format, pixels, pitch);
1876}
1877
1892inline void DestroySurface(SurfaceRaw surface) { SDL_DestroySurface(surface); }
1893
1895
1929{
1930 return {CheckError(SDL_GetSurfaceProperties(surface))};
1931}
1932
1934{
1935 return SDL::GetSurfaceProperties(m_resource);
1936}
1937
1938namespace prop::Surface {
1939
1940constexpr auto SDR_WHITE_POINT_FLOAT = SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT;
1941
1942constexpr auto HDR_HEADROOM_FLOAT = SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT;
1943
1944constexpr auto TONEMAP_OPERATOR_STRING =
1945 SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING;
1946
1947#if SDL_VERSION_ATLEAST(3, 2, 6)
1948
1949constexpr auto HOTSPOT_X_NUMBER = SDL_PROP_SURFACE_HOTSPOT_X_NUMBER;
1950
1951constexpr auto HOTSPOT_Y_NUMBER = SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER;
1952
1953#endif // SDL_VERSION_ATLEAST(3, 2, 6)
1954
1955} // namespace prop::Surface
1956
1974inline void SetSurfaceColorspace(SurfaceParam surface, Colorspace colorspace)
1975{
1976 CheckError(SDL_SetSurfaceColorspace(surface, colorspace));
1977}
1978
1979inline void Surface::SetColorspace(Colorspace colorspace)
1980{
1981 SDL::SetSurfaceColorspace(m_resource, colorspace);
1982}
1983
2002{
2003 return SDL_GetSurfaceColorspace(surface);
2004}
2005
2007{
2008 return SDL::GetSurfaceColorspace(m_resource);
2009}
2010
2039{
2040 return Palette::Borrow(CheckError(SDL_CreateSurfacePalette(surface)));
2041}
2042
2044{
2045 return SDL::CreateSurfacePalette(m_resource);
2046}
2047
2064inline void SetSurfacePalette(SurfaceParam surface, PaletteParam palette)
2065{
2066 CheckError(SDL_SetSurfacePalette(surface, palette));
2067}
2068
2070{
2071 SDL::SetSurfacePalette(m_resource, palette);
2072}
2073
2088{
2089 return Palette::Borrow(SDL_GetSurfacePalette(surface));
2090}
2091
2093{
2094 return SDL::GetSurfacePalette(m_resource);
2095}
2096
2122{
2123 CheckError(SDL_AddSurfaceAlternateImage(surface, image));
2124}
2125
2127{
2128 SDL::AddSurfaceAlternateImage(m_resource, image);
2129}
2130
2146{
2147 return SDL_SurfaceHasAlternateImages(surface);
2148}
2149
2151{
2152 return SDL::SurfaceHasAlternateImages(m_resource);
2153}
2154
2178{
2179 int count = 0;
2180 auto data = SDL_GetSurfaceImages(surface, &count);
2181 return OwnArray<SurfaceRaw>(CheckError(data), count);
2182}
2183
2185{
2186 return SDL::GetSurfaceImages(m_resource);
2187}
2188
2206{
2207 SDL_RemoveSurfaceAlternateImages(surface);
2208}
2209
2211{
2213}
2214
2239inline void LockSurface(SurfaceParam surface)
2240{
2241 CheckError(SDL_LockSurface(surface));
2242}
2243
2244inline void Surface::Lock() { SDL::LockSurface(m_resource); }
2245
2259inline void UnlockSurface(SurfaceParam surface) { SDL_UnlockSurface(surface); }
2260
2261inline void Surface::Unlock() { SDL::UnlockSurface(m_resource); }
2262
2283inline Surface LoadBMP(IOStreamParam src, bool closeio = false)
2284{
2285 return Surface(SDL_LoadBMP_IO(src, closeio));
2286}
2287
2306inline Surface LoadBMP(StringParam file) { return Surface(SDL_LoadBMP(file)); }
2307
2308inline Surface Surface::LoadBMP(IOStreamParam src, bool closeio)
2309{
2310 return SDL::LoadBMP(src, closeio);
2311}
2312
2314{
2315 return SDL::LoadBMP(std::move(file));
2316}
2317
2340inline void SaveBMP(SurfaceConstParam surface,
2341 IOStreamParam dst,
2342 bool closeio = false)
2343{
2344 CheckError(SDL_SaveBMP_IO(surface, dst, closeio));
2345}
2346
2367inline void SaveBMP(SurfaceConstParam surface, StringParam file)
2368{
2369 CheckError(SDL_SaveBMP(surface, file));
2370}
2371
2372inline void Surface::SaveBMP(IOStreamParam dst, bool closeio) const
2373{
2374 SDL::SaveBMP(m_resource, dst, closeio);
2375}
2376
2377inline void Surface::SaveBMP(StringParam file) const
2378{
2379 SDL::SaveBMP(m_resource, std::move(file));
2380}
2381
2400inline void SetSurfaceRLE(SurfaceParam surface, bool enabled)
2401{
2402 CheckError(SDL_SetSurfaceRLE(surface, enabled));
2403}
2404
2405inline void Surface::SetRLE(bool enabled)
2406{
2407 SDL::SetSurfaceRLE(m_resource, enabled);
2408}
2409
2425{
2426 return SDL_SurfaceHasRLE(surface);
2427}
2428
2429inline bool Surface::HasRLE() const { return SDL::SurfaceHasRLE(m_resource); }
2430
2453inline void SetSurfaceColorKey(SurfaceParam surface, std::optional<Uint32> key)
2454{
2455 CheckError(SDL_SetSurfaceColorKey(surface, key.has_value(), key.value_or(0)));
2456}
2457
2458inline void Surface::SetColorKey(std::optional<Uint32> key)
2459{
2460 SDL::SetSurfaceColorKey(m_resource, key);
2461}
2462
2474{
2475 SetSurfaceColorKey(surface, std::nullopt);
2476}
2477
2479
2496{
2497 return SDL_SurfaceHasColorKey(surface);
2498}
2499
2500inline bool Surface::HasColorKey() const
2501{
2502 return SDL::SurfaceHasColorKey(m_resource);
2503}
2504
2524inline std::optional<Uint32> GetSurfaceColorKey(SurfaceConstParam surface)
2525{
2526 if (Uint32 key; SDL_GetSurfaceColorKey(surface, &key)) return key;
2527 return std::nullopt;
2528}
2529
2530inline std::optional<Uint32> Surface::GetColorKey() const
2531{
2532 return SDL::GetSurfaceColorKey(m_resource);
2533}
2534
2557inline void SetSurfaceColorMod(SurfaceParam surface, Uint8 r, Uint8 g, Uint8 b)
2558{
2559 CheckError(SDL_SetSurfaceColorMod(surface, r, g, b));
2560}
2561
2563{
2564 SDL::SetSurfaceColorMod(m_resource, r, g, b);
2565}
2566
2584 Uint8* r,
2585 Uint8* g,
2586 Uint8* b)
2587{
2588 CheckError(SDL_GetSurfaceColorMod(surface, r, g, b));
2589}
2590
2591inline void Surface::GetColorMod(Uint8* r, Uint8* g, Uint8* b) const
2592{
2593 SDL::GetSurfaceColorMod(m_resource, r, g, b);
2594}
2595
2615inline void SetSurfaceAlphaMod(SurfaceParam surface, Uint8 alpha)
2616{
2617 CheckError(SDL_SetSurfaceAlphaMod(surface, alpha));
2618}
2619
2620inline void Surface::SetAlphaMod(Uint8 alpha)
2621{
2622 SDL::SetSurfaceAlphaMod(m_resource, alpha);
2623}
2624
2640{
2641 Uint8 alpha;
2642 CheckError(SDL_GetSurfaceAlphaMod(surface, &alpha));
2643 return alpha;
2644}
2645
2647{
2648 return SDL::GetSurfaceAlphaMod(m_resource);
2649}
2650
2666inline void SetSurfaceMod(SurfaceParam surface, Color color)
2667{
2668 SetSurfaceColorMod(surface, color.r, color.g, color.b);
2669 SetSurfaceAlphaMod(surface, color.a);
2670}
2671
2672inline void Surface::SetMod(Color color) { SetSurfaceMod(m_resource, color); }
2673
2683{
2684 Color c;
2685 GetSurfaceColorMod(surface, &c.r, &c.g, &c.b);
2686 c.a = GetSurfaceAlphaMod(surface);
2687 return c;
2688}
2689
2690inline Color Surface::GetMod() const { return SDL::GetSurfaceMod(m_resource); }
2691
2709inline void SetSurfaceBlendMode(SurfaceParam surface, BlendMode blendMode)
2710{
2711 CheckError(SDL_SetSurfaceBlendMode(surface, blendMode));
2712}
2713
2714inline void Surface::SetBlendMode(BlendMode blendMode)
2715{
2716 SDL::SetSurfaceBlendMode(m_resource, blendMode);
2717}
2718
2733{
2734 BlendMode blendmode;
2735 CheckError(SDL_GetSurfaceBlendMode(surface, &blendmode));
2736 return blendmode;
2737}
2738
2740{
2741 return SDL::GetSurfaceBlendMode(m_resource);
2742}
2743
2767{
2768 return SDL_SetSurfaceClipRect(surface, rect);
2769}
2770
2772{
2773 return SDL::SetSurfaceClipRect(m_resource, rect);
2774}
2775
2782{
2783 SetSurfaceClipRect(surface, std::nullopt);
2784}
2785
2787
2807{
2808 Rect r;
2809 CheckError(SDL_GetSurfaceClipRect(surface, &r));
2810 return r;
2811}
2812
2814{
2815 return SDL::GetSurfaceClipRect(m_resource);
2816}
2817
2829inline void FlipSurface(SurfaceParam surface, FlipMode flip)
2830{
2831 CheckError(SDL_FlipSurface(surface, flip));
2832}
2833
2834inline void Surface::Flip(FlipMode flip) { SDL::FlipSurface(m_resource, flip); }
2835
2855{
2856 return Surface(SDL_DuplicateSurface(surface));
2857}
2858
2860{
2861 return SDL::DuplicateSurface(m_resource);
2862}
2863
2883 const PointRaw& size,
2884 ScaleMode scaleMode)
2885{
2886 return Surface(SDL_ScaleSurface(surface, size.x, size.y, scaleMode));
2887}
2888
2889inline Surface Surface::Scale(const PointRaw& size, ScaleMode scaleMode) const
2890{
2891 return SDL::ScaleSurface(m_resource, size, scaleMode);
2892}
2893
2921{
2922 return Surface(SDL_ConvertSurface(surface, format));
2923}
2924
2926{
2927 return SDL::ConvertSurface(m_resource, format);
2928}
2929
2958 PixelFormat format,
2959 PaletteParam palette,
2960 Colorspace colorspace,
2961 PropertiesParam props)
2962{
2963 return Surface{SDL_ConvertSurfaceAndColorspace(
2964 surface, format, palette, colorspace, props)};
2965}
2966
2968 PaletteParam palette,
2969 Colorspace colorspace,
2970 PropertiesParam props) const
2971{
2973 m_resource, format, palette, colorspace, props);
2974}
2975
2996inline void ConvertPixels(const PointRaw& size,
2997 PixelFormat src_format,
2998 const void* src,
2999 int src_pitch,
3000 PixelFormat dst_format,
3001 void* dst,
3002 int dst_pitch)
3003{
3004 CheckError(SDL_ConvertPixels(
3005 size.x, size.y, src_format, src, src_pitch, dst_format, dst, dst_pitch));
3006}
3007
3037inline void ConvertPixelsAndColorspace(const PointRaw& size,
3038 PixelFormat src_format,
3039 Colorspace src_colorspace,
3040 PropertiesParam src_properties,
3041 const void* src,
3042 int src_pitch,
3043 PixelFormat dst_format,
3044 Colorspace dst_colorspace,
3045 PropertiesParam dst_properties,
3046 void* dst,
3047 int dst_pitch)
3048{
3049 CheckError(SDL_ConvertPixelsAndColorspace(size.x,
3050 size.y,
3051 src_format,
3052 src_colorspace,
3053 src_properties,
3054 src,
3055 src_pitch,
3056 dst_format,
3057 dst_colorspace,
3058 dst_properties,
3059 dst,
3060 dst_pitch));
3061}
3062
3085inline void PremultiplyAlpha(const PointRaw& size,
3086 PixelFormat src_format,
3087 const void* src,
3088 int src_pitch,
3089 PixelFormat dst_format,
3090 void* dst,
3091 int dst_pitch,
3092 bool linear)
3093{
3094 CheckError(SDL_PremultiplyAlpha(size.x,
3095 size.y,
3096 src_format,
3097 src,
3098 src_pitch,
3099 dst_format,
3100 dst,
3101 dst_pitch,
3102 linear));
3103}
3104
3119inline void PremultiplySurfaceAlpha(SurfaceParam surface, bool linear)
3120{
3121 CheckError(SDL_PremultiplySurfaceAlpha(surface, linear));
3122}
3123
3124inline void Surface::PremultiplyAlpha(bool linear)
3125{
3126 SDL::PremultiplySurfaceAlpha(m_resource, linear);
3127}
3128
3145inline void ClearSurface(SurfaceParam surface, const FColorRaw& c)
3146{
3147 CheckError(SDL_ClearSurface(surface, c.r, c.g, c.b, c.a));
3148}
3149
3150inline void Surface::Clear(const FColorRaw& c)
3151{
3152 SDL::ClearSurface(m_resource, c);
3153}
3154
3181 Uint32 color)
3182{
3183 CheckError(SDL_FillSurfaceRect(dst, rect, color));
3184}
3185
3187{
3188 SDL::FillSurfaceRect(m_resource, rect, color);
3189}
3190
3202inline void FillSurface(SurfaceParam dst, Uint32 color)
3203{
3204 FillSurfaceRect(dst, std::nullopt, color);
3205}
3206
3207inline void Surface::Fill(Uint32 color) { SDL::FillSurface(m_resource, color); }
3208
3234 Uint32 color)
3235{
3236 CheckError(SDL_FillSurfaceRects(dst, rects.data(), rects.size(), color));
3237}
3238
3240{
3241 SDL::FillSurfaceRects(m_resource, rects, color);
3242}
3243
3316 SurfaceParam dst,
3318{
3319 CheckError(SDL_BlitSurface(src, srcrect, dst, dstrect));
3320}
3321
3325{
3326 SDL::BlitSurface(src, srcrect, m_resource, dstrect);
3327}
3328
3331 const PointRaw& dstpos)
3332{
3333 Blit(src, srcrect, Rect{dstpos, {}});
3334}
3335
3405 SurfaceParam dst,
3406 const PointRaw& dstpos)
3407{
3408 BlitSurface(src, srcrect, dst, SDL_Rect{dstpos.x, dstpos.y});
3409}
3410
3433 const RectRaw& srcrect,
3434 SurfaceParam dst,
3435 const RectRaw& dstrect)
3436{
3437 CheckError(SDL_BlitSurfaceUnchecked(src, &srcrect, dst, &dstrect));
3438}
3439
3441 const RectRaw& srcrect,
3442 const RectRaw& dstrect)
3443{
3444 SDL::BlitSurfaceUnchecked(src, srcrect, m_resource, dstrect);
3445}
3446
3470 SurfaceParam dst,
3472 ScaleMode scaleMode)
3473{
3474 CheckError(SDL_BlitSurfaceScaled(src, srcrect, dst, dstrect, scaleMode));
3475}
3476
3480 ScaleMode scaleMode)
3481{
3482 SDL::BlitSurfaceScaled(src, srcrect, m_resource, dstrect, scaleMode);
3483}
3484
3508 const RectRaw& srcrect,
3509 SurfaceParam dst,
3510 const RectRaw& dstrect,
3511 ScaleMode scaleMode)
3512{
3513 CheckError(
3514 SDL_BlitSurfaceUncheckedScaled(src, &srcrect, dst, &dstrect, scaleMode));
3515}
3516
3518 const RectRaw& srcrect,
3519 const RectRaw& dstrect,
3520 ScaleMode scaleMode)
3521{
3522 SDL::BlitSurfaceUncheckedScaled(src, srcrect, m_resource, dstrect, scaleMode);
3523}
3524
3525#if SDL_VERSION_ATLEAST(3, 4, 0)
3526
3548 OptionalRef<RectRaw> srcrect,
3549 SurfaceParam dst,
3550 OptionalRef<RectRaw> dstrect,
3551 ScaleMode scaleMode)
3552{
3553 CheckError(SDL_StretchSurface(src, srcrect, dst, dstrect, scaleMode));
3554}
3555
3557 OptionalRef<RectRaw> srcrect,
3558 OptionalRef<RectRaw> dstrect,
3559 ScaleMode scaleMode)
3560{
3561 SDL::StretchSurface(src, srcrect, m_resource, dstrect, scaleMode);
3562}
3563
3564#endif // SDL_VERSION_ATLEAST(3, 4, 0)
3565
3591 SurfaceParam dst,
3593{
3594 CheckError(SDL_BlitSurfaceTiled(src, srcrect, dst, dstrect));
3595}
3596
3600{
3601 SDL::BlitSurfaceTiled(src, srcrect, m_resource, dstrect);
3602}
3603
3633 float scale,
3634 SDL_ScaleMode scaleMode,
3635 SurfaceParam dst,
3637{
3638 CheckError(SDL_BlitSurfaceTiledWithScale(
3639 src, srcrect, scale, scaleMode, dst, dstrect));
3640}
3641
3644 float scale,
3645 SDL_ScaleMode scaleMode,
3647{
3649 src, srcrect, scale, scaleMode, m_resource, dstrect);
3650}
3651
3688 int left_width,
3689 int right_width,
3690 int top_height,
3691 int bottom_height,
3692 SurfaceParam dst,
3694 float scale = 1,
3695 SDL_ScaleMode scaleMode = SCALEMODE_NEAREST)
3696{
3697 CheckError(SDL_BlitSurface9Grid(src,
3698 srcrect,
3699 left_width,
3700 right_width,
3701 top_height,
3702 bottom_height,
3703 scale,
3704 scaleMode,
3705 dst,
3706 dstrect));
3707}
3708
3711 int left_width,
3712 int right_width,
3713 int top_height,
3714 int bottom_height,
3716 float scale,
3717 SDL_ScaleMode scaleMode)
3718{
3720 srcrect,
3721 left_width,
3722 right_width,
3723 top_height,
3724 bottom_height,
3725 m_resource,
3726 dstrect,
3727 scale,
3728 scaleMode);
3729}
3730
3762 Uint8 r,
3763 Uint8 g,
3764 Uint8 b)
3765{
3766 return SDL_MapSurfaceRGB(surface, r, g, b);
3767}
3768
3770{
3771 return SDL::MapSurfaceRGB(m_resource, r, g, b);
3772}
3773
3803{
3804 return SDL_MapSurfaceRGBA(surface, c.r, c.g, c.b, c.a);
3805}
3806
3808{
3809 return SDL::MapSurfaceRGBA(m_resource, c);
3810}
3811
3838 const PointRaw& p,
3839 Uint8* r,
3840 Uint8* g,
3841 Uint8* b,
3842 Uint8* a)
3843{
3844 CheckError(SDL_ReadSurfacePixel(surface, p.x, p.y, r, g, b, a));
3845}
3846
3866{
3867 Color c;
3868 ReadSurfacePixel(surface, p, &c.r, &c.g, &c.b, &c.a);
3869 return c;
3870}
3871
3872inline void Surface::ReadPixel(const PointRaw& p,
3873 Uint8* r,
3874 Uint8* g,
3875 Uint8* b,
3876 Uint8* a) const
3877{
3878 SDL::ReadSurfacePixel(m_resource, p, r, g, b, a);
3879}
3880
3881inline Color Surface::ReadPixel(const PointRaw& p) const
3882{
3883 return SDL::ReadSurfacePixel(m_resource, p);
3884}
3885
3909 const PointRaw& p,
3910 float* r,
3911 float* g,
3912 float* b,
3913 float* a)
3914{
3915 CheckError(SDL_ReadSurfacePixelFloat(surface, p.x, p.y, r, g, b, a));
3916}
3917
3934 const PointRaw& p)
3935{
3936 FColor c;
3937 ReadSurfacePixelFloat(surface, p, &c.r, &c.g, &c.b, &c.a);
3938 return c;
3939}
3940
3942 float* r,
3943 float* g,
3944 float* b,
3945 float* a) const
3946{
3947 SDL::ReadSurfacePixelFloat(m_resource, p, r, g, b, a);
3948}
3949
3951{
3952 return SDL::ReadSurfacePixelFloat(m_resource, p);
3953}
3954
3974 const PointRaw& p,
3975 ColorRaw c)
3976{
3977 CheckError(SDL_WriteSurfacePixel(surface, p.x, p.y, c.r, c.g, c.b, c.a));
3978}
3979
3980inline void Surface::WritePixel(const PointRaw& p, ColorRaw c)
3981{
3982 SDL::WriteSurfacePixel(m_resource, p, c);
3983}
3984
4001 const PointRaw& p,
4002 const FColorRaw& c)
4003{
4004 CheckError(SDL_WriteSurfacePixelFloat(surface, p.x, p.y, c.r, c.g, c.b, c.a));
4005}
4006
4007inline void Surface::WritePixelFloat(const PointRaw& p, const FColorRaw& c)
4008{
4009 SDL::WriteSurfacePixelFloat(m_resource, p, c);
4010}
4011
4015constexpr int GetSurfaceWidth(SurfaceConstParam surface) { return surface->w; }
4016
4017constexpr int Surface::GetWidth() const
4018{
4019 return SDL::GetSurfaceWidth(m_resource);
4020}
4021
4025constexpr int GetSurfaceHeight(SurfaceConstParam surface) { return surface->h; }
4026
4027constexpr int Surface::GetHeight() const
4028{
4029 return SDL::GetSurfaceHeight(m_resource);
4030}
4031
4036{
4037 return Point(surface->w, surface->h);
4038}
4039
4040constexpr Point Surface::GetSize() const
4041{
4042 return SDL::GetSurfaceSize(m_resource);
4043}
4044
4049{
4050 return surface->pitch;
4051}
4052
4053constexpr int Surface::GetPitch() const
4054{
4055 return SDL::GetSurfacePitch(m_resource);
4056}
4057
4062{
4063 return surface->format;
4064}
4065
4067{
4068 return SDL::GetSurfaceFormat(m_resource);
4069}
4070
4074constexpr void* GetSurfacePixels(SurfaceConstParam surface)
4075{
4076 return surface->pixels;
4077}
4078
4079constexpr void* Surface::GetPixels() const
4080{
4081 return SDL::GetSurfacePixels(m_resource);
4082}
4083
4085
4086} // namespace SDL
4087
4088#endif /* SDL3PP_SURFACE_H_ */
Colorspace definitions.
Definition: SDL3pp_pixels.h:1660
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:2484
static constexpr Palette Borrow(PaletteParam resource)
Safely borrows the from PaletteParam.
Definition: SDL3pp_pixels.h:2541
Pixel format.
Definition: SDL3pp_pixels.h:414
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
Surface(const PointRaw &size, PixelFormat format)
Allocate a new surface with a specific pixel format.
Definition: SDL3pp_surface.h:245
Surface & operator=(Surface other)
Assignment operator.
Definition: SDL3pp_surface.h:441
constexpr const SurfaceRaw operator->() const
member access to underlying SurfaceRaw.
Definition: SDL3pp_surface.h:432
constexpr Surface(const Surface &other)
Copy constructor.
Definition: SDL3pp_surface.h:221
constexpr Surface()=default
Default ctor.
~Surface()
Destructor.
Definition: SDL3pp_surface.h:438
constexpr Surface(const SurfaceRaw resource)
Constructs from SurfaceParam.
Definition: SDL3pp_surface.h:215
constexpr bool operator==(std::nullptr_t _) const
Comparison.
Definition: SDL3pp_surface.h:462
constexpr Surface(Surface &&other)
Move constructor.
Definition: SDL3pp_surface.h:224
constexpr SurfaceRaw get() const
Retrieves underlying SurfaceRaw.
Definition: SDL3pp_surface.h:448
constexpr SurfaceRaw release()
Retrieves underlying SurfaceRaw and clear this.
Definition: SDL3pp_surface.h:451
constexpr auto operator<=>(const Surface &other) const =default
Comparison.
constexpr SurfaceRaw operator->()
member access to underlying SurfaceRaw.
Definition: SDL3pp_surface.h:435
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:276
static constexpr Surface Borrow(SurfaceParam resource)
Safely borrows the from SurfaceParam.
Definition: SDL3pp_surface.h:380
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:198
SDL_FColor FColorRaw
Alias to raw representation for FColor.
Definition: SDL3pp_pixels.h:90
SDL_Color ColorRaw
Alias to raw representation for Color.
Definition: SDL3pp_pixels.h:84
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:1389
Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:328
Uint8 Uint8
An unsigned 8-bit integer type.
Definition: SDL3pp_stdinc.h:260
void ResetSurfaceClipRect(SurfaceParam surface)
Disable the clipping rectangle for a surface.
Definition: SDL3pp_surface.h:2781
constexpr int GetSurfaceHeight(SurfaceConstParam surface)
Get the height in pixels.
Definition: SDL3pp_surface.h:4025
void BlitSurfaceUnchecked(SurfaceParam src, const RectRaw &srcrect, SurfaceParam dst, const RectRaw &dstrect)
Perform low-level surface blitting only.
Definition: SDL3pp_surface.h:3432
Uint32 MapSurfaceRGBA(SurfaceConstParam surface, ColorRaw c)
Map an RGBA quadruple to a pixel value for a surface.
Definition: SDL3pp_surface.h:3802
Rect GetSurfaceClipRect(SurfaceConstParam surface)
Get the clipping rectangle for a surface.
Definition: SDL3pp_surface.h:2806
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:2882
Rect GetClipRect() const
Get the clipping rectangle for a surface.
Definition: SDL3pp_surface.h:2813
void ClearSurface(SurfaceParam surface, const FColorRaw &c)
Clear a surface with a specific color, with floating point precision.
Definition: SDL3pp_surface.h:3145
Uint8 GetSurfaceAlphaMod(SurfaceConstParam surface)
Get the additional alpha value used in blit operations.
Definition: SDL3pp_surface.h:2639
Palette CreateSurfacePalette(SurfaceParam surface)
Create a palette and associate it with a surface.
Definition: SDL3pp_surface.h:2038
Palette GetPalette() const
Get the palette used by a surface.
Definition: SDL3pp_surface.h:2092
std::optional< Uint32 > GetColorKey() const
Get the color key (transparent pixel) for a surface.
Definition: SDL3pp_surface.h:2530
void SetSurfaceMod(SurfaceParam surface, Color color)
Set an additional color and alpha value multiplied into blit operations.
Definition: SDL3pp_surface.h:2666
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:2765
constexpr PixelFormat GetFormat() const
Get the pixel format.
Definition: SDL3pp_surface.h:4066
void Destroy()
Free a surface.
Definition: SDL3pp_surface.h:1894
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:3468
bool SurfaceHasAlternateImages(SurfaceConstParam surface)
Return whether a surface has alternate versions available.
Definition: SDL3pp_surface.h:2145
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:3232
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:2739
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:4074
void SetSurfacePalette(SurfaceParam surface, PaletteParam palette)
Set the palette used by a surface.
Definition: SDL3pp_surface.h:2064
void Unlock()
Release a surface after directly accessing the pixels.
Definition: SDL3pp_surface.h:2261
bool SurfaceHasRLE(SurfaceConstParam surface)
Returns whether the surface is RLE enabled.
Definition: SDL3pp_surface.h:2424
void DestroySurface(SurfaceRaw surface)
Free a surface.
Definition: SDL3pp_surface.h:1892
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:3239
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:3769
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:3507
bool HasRLE() const
Returns whether the surface is RLE enabled.
Definition: SDL3pp_surface.h:2429
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:3686
constexpr int GetHeight() const
Get the height in pixels.
Definition: SDL3pp_surface.h:4027
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:3973
bool SurfaceHasColorKey(SurfaceConstParam surface)
Returns whether the surface has a color key.
Definition: SDL3pp_surface.h:2495
BlendMode GetSurfaceBlendMode(SurfaceConstParam surface)
Get the blend mode used for blit operations.
Definition: SDL3pp_surface.h:2732
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:3403
constexpr PixelFormat GetSurfaceFormat(SurfaceConstParam surface)
Get the pixel format.
Definition: SDL3pp_surface.h:4061
bool HasColorKey() const
Returns whether the surface has a color key.
Definition: SDL3pp_surface.h:2500
void BlitUncheckedScaled(SurfaceParam src, const RectRaw &srcrect, const RectRaw &dstrect, ScaleMode scaleMode)
Perform low-level surface scaled blitting only.
Definition: SDL3pp_surface.h:3517
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:2458
void PremultiplyAlpha(bool linear)
Premultiply the alpha in a surface.
Definition: SDL3pp_surface.h:3124
void SaveBMP(IOStreamParam dst, bool closeio=false) const
Save a surface to a seekable SDL data stream in BMP format.
Definition: SDL3pp_surface.h:2372
Colorspace GetSurfaceColorspace(SurfaceConstParam surface)
Get the colorspace used by a surface.
Definition: SDL3pp_surface.h:2001
Surface DuplicateSurface(SurfaceConstParam surface)
Creates a new surface identical to the existing surface.
Definition: SDL3pp_surface.h:2854
std::optional< Uint32 > GetSurfaceColorKey(SurfaceConstParam surface)
Get the color key (transparent pixel) for a surface.
Definition: SDL3pp_surface.h:2524
Palette CreatePalette()
Create a palette and associate it with a surface.
Definition: SDL3pp_surface.h:2043
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:3322
void SetSurfaceColorspace(SurfaceParam surface, Colorspace colorspace)
Set the colorspace used by a surface.
Definition: SDL3pp_surface.h:1974
Colorspace GetColorspace() const
Get the colorspace used by a surface.
Definition: SDL3pp_surface.h:2006
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:3837
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:2834
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:1870
void FlipSurface(SurfaceParam surface, FlipMode flip)
Flip a surface vertically or horizontally.
Definition: SDL3pp_surface.h:2829
void ResetClipRect()
Disable the clipping rectangle for a surface.
Definition: SDL3pp_surface.h:2786
PropertiesRef GetProperties() const
Get the properties associated with a surface.
Definition: SDL3pp_surface.h:1933
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:3642
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:2920
constexpr Point GetSurfaceSize(SurfaceConstParam surface)
Get the size in pixels.
Definition: SDL3pp_surface.h:4035
constexpr int GetSurfaceWidth(SurfaceConstParam surface)
Get the width in pixels.
Definition: SDL3pp_surface.h:4015
bool HasAlternateImages() const
Return whether a surface has alternate versions available.
Definition: SDL3pp_surface.h:2150
void FillSurface(SurfaceParam dst, Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition: SDL3pp_surface.h:3202
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:4053
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:3631
void SetSurfaceColorMod(SurfaceParam surface, Uint8 r, Uint8 g, Uint8 b)
Set an additional color value multiplied into blit operations.
Definition: SDL3pp_surface.h:2557
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:2957
void RemoveAlternateImages()
Remove all alternate versions of a surface.
Definition: SDL3pp_surface.h:2210
Surface Convert(PixelFormat format) const
Copy an existing surface to a new surface of the specified format.
Definition: SDL3pp_surface.h:2925
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:3556
constexpr Point GetSize() const
Get the size in pixels.
Definition: SDL3pp_surface.h:4040
void SetSurfaceAlphaMod(SurfaceParam surface, Uint8 alpha)
Set an additional alpha value used in blit operations.
Definition: SDL3pp_surface.h:2615
Uint8 GetAlphaMod() const
Get the additional alpha value used in blit operations.
Definition: SDL3pp_surface.h:2646
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:2859
static Surface LoadBMP(IOStreamParam src, bool closeio=false)
Load a BMP image from a seekable SDL data stream.
Definition: SDL3pp_surface.h:2308
void Clear(const FColorRaw &c)
Clear a surface with a specific color, with floating point precision.
Definition: SDL3pp_surface.h:3150
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:3589
void SetSurfaceColorKey(SurfaceParam surface, std::optional< Uint32 > key)
Set the color key (transparent pixel) in a surface.
Definition: SDL3pp_surface.h:2453
void SetSurfaceRLE(SurfaceParam surface, bool enabled)
Set the RLE acceleration hint for a surface.
Definition: SDL3pp_surface.h:2400
void SetMod(Color color)
Set an additional color and alpha value multiplied into blit operations.
Definition: SDL3pp_surface.h:2672
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:3761
void GetColorMod(Uint8 *r, Uint8 *g, Uint8 *b) const
Get the additional color value multiplied into blit operations.
Definition: SDL3pp_surface.h:2591
constexpr ScaleMode SCALEMODE_INVALID
INVALID.
Definition: SDL3pp_surface.h:147
constexpr int GetWidth() const
Get the width in pixels.
Definition: SDL3pp_surface.h:4017
void UnlockSurface(SurfaceParam surface)
Release a surface after directly accessing the pixels.
Definition: SDL3pp_surface.h:2259
void PremultiplySurfaceAlpha(SurfaceParam surface, bool linear)
Premultiply the alpha in a surface.
Definition: SDL3pp_surface.h:3119
void SetColorMod(Uint8 r, Uint8 g, Uint8 b)
Set an additional color value multiplied into blit operations.
Definition: SDL3pp_surface.h:2562
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:3085
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:3329
void SetBlendMode(BlendMode blendMode)
Set the blend mode used for blit operations.
Definition: SDL3pp_surface.h:2714
OwnArray< SurfaceRaw > GetImages() const
Get an array including all versions of a surface.
Definition: SDL3pp_surface.h:2184
Surface CreateSurface(const PointRaw &size, PixelFormat format)
Allocate a new surface with a specific pixel format.
Definition: SDL3pp_surface.h:1838
OwnArray< SurfaceRaw > GetSurfaceImages(SurfaceConstParam surface)
Get an array including all versions of a surface.
Definition: SDL3pp_surface.h:2177
constexpr int GetSurfacePitch(SurfaceConstParam surface)
Get pitch in bytes.
Definition: SDL3pp_surface.h:4048
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:3477
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:3872
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:3908
Palette GetSurfacePalette(SurfaceConstParam surface)
Get the palette used by a surface.
Definition: SDL3pp_surface.h:2087
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:3547
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:3179
Color GetSurfaceMod(SurfaceConstParam surface)
Get the additional color and alpha value multiplied into blit operations.
Definition: SDL3pp_surface.h:2682
void Fill(Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition: SDL3pp_surface.h:3207
Uint32 MapRGBA(ColorRaw c) const
Map an RGBA quadruple to a pixel value for a surface.
Definition: SDL3pp_surface.h:3807
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:2889
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:3037
void SetColorspace(Colorspace colorspace)
Set the colorspace used by a surface.
Definition: SDL3pp_surface.h:1979
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:3597
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:2340
void ClearColorKey()
Unset the color key (transparent pixel) in a surface.
Definition: SDL3pp_surface.h:2478
void AddSurfaceAlternateImage(SurfaceParam surface, SurfaceParam image)
Add an alternate version of a surface.
Definition: SDL3pp_surface.h:2121
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:3980
PropertiesRef GetSurfaceProperties(SurfaceConstParam surface)
Get the properties associated with a surface.
Definition: SDL3pp_surface.h:1928
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:3314
void FillRect(OptionalRef< const RectRaw > rect, Uint32 color)
Perform a fast fill of a rectangle with a specific color.
Definition: SDL3pp_surface.h:3186
void Lock()
Set up a surface for directly accessing the pixels.
Definition: SDL3pp_surface.h:2244
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:3941
void GetSurfaceColorMod(SurfaceConstParam surface, Uint8 *r, Uint8 *g, Uint8 *b)
Get the additional color value multiplied into blit operations.
Definition: SDL3pp_surface.h:2583
void SetAlphaMod(Uint8 alpha)
Set an additional alpha value used in blit operations.
Definition: SDL3pp_surface.h:2620
constexpr void * GetPixels() const
Get the pixels.
Definition: SDL3pp_surface.h:4079
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:2405
void BlitUnchecked(SurfaceParam src, const RectRaw &srcrect, const RectRaw &dstrect)
Perform low-level surface blitting only.
Definition: SDL3pp_surface.h:3440
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:2996
void ClearSurfaceColorKey(SurfaceParam surface)
Unset the color key (transparent pixel) in a surface.
Definition: SDL3pp_surface.h:2473
void WriteSurfacePixelFloat(SurfaceParam surface, const PointRaw &p, const FColorRaw &c)
Writes a single pixel to a surface.
Definition: SDL3pp_surface.h:4000
void SetPalette(PaletteParam palette)
Set the palette used by a surface.
Definition: SDL3pp_surface.h:2069
Color GetMod() const
Get the additional color and alpha value multiplied into blit operations.
Definition: SDL3pp_surface.h:2690
void LockSurface(SurfaceParam surface)
Set up a surface for directly accessing the pixels.
Definition: SDL3pp_surface.h:2239
void SetSurfaceBlendMode(SurfaceParam surface, BlendMode blendMode)
Set the blend mode used for blit operations.
Definition: SDL3pp_surface.h:2709
bool SetClipRect(OptionalRef< const RectRaw > rect)
Set the clipping rectangle for a surface.
Definition: SDL3pp_surface.h:2771
void AddAlternateImage(SurfaceParam image)
Add an alternate version of a surface.
Definition: SDL3pp_surface.h:2126
void WritePixelFloat(const PointRaw &p, const FColorRaw &c)
Writes a single pixel to a surface.
Definition: SDL3pp_surface.h:4007
void RemoveSurfaceAlternateImages(SurfaceParam surface)
Remove all alternate versions of a surface.
Definition: SDL3pp_surface.h:2205
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:3709
Main include header for the SDL3pp library.
A structure that represents a color as RGBA components.
Definition: SDL3pp_pixels.h:2197
The bits of this structure can be directly reinterpreted as a float-packed color which uses the PIXEL...
Definition: SDL3pp_pixels.h:2370
Safely wrap IOStream for non owning parameters.
Definition: SDL3pp_iostream.h:34
Safely wrap Palette for non owning parameters.
Definition: SDL3pp_pixels.h:103
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:701
A rectangle, with the origin at the upper left (using integers).
Definition: SDL3pp_rect.h:839
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.