4#include "SDL3pp_error.h"
5#include "SDL3pp_render.h"
6#include "SDL3pp_surface.h"
7#include "SDL3pp_version.h"
8#include "SDL3pp_video.h"
10#if defined(SDL3PP_ENABLE_IMAGE) || defined(SDL3PP_DOC)
12#include <SDL3_image/SDL_image.h>
53 constexpr explicit operator bool()
const {
return !!
value; }
89 constexpr explicit operator bool()
const {
return !!
value; }
108#define SDL_IMAGE_MAJOR_VERSION
110#define SDL_IMAGE_MINOR_VERSION
112#define SDL_IMAGE_MICRO_VERSION
119#define SDL_IMAGE_VERSION \
121 SDL_IMAGE_MAJOR_VERSION, SDL_IMAGE_MINOR_VERSION, SDL_IMAGE_MICRO_VERSION)
124#define SDL_IMAGE_VERSION_ATLEAST(X, Y, Z) \
125 ((SDL_IMAGE_MAJOR_VERSION >= X) && \
126 (SDL_IMAGE_MAJOR_VERSION > X || SDL_IMAGE_MINOR_VERSION >= Y) && \
127 (SDL_IMAGE_MAJOR_VERSION > X || SDL_IMAGE_MINOR_VERSION > Y || \
128 SDL_IMAGE_MICRO_VERSION >= Z))
141inline int Version() {
return IMG_Version(); }
201 bool closeio =
false)
203 return Surface(IMG_LoadTyped_IO(src, closeio, type));
291 return Surface(IMG_Load_IO(src, closeio));
295 : m_resource(IMG_Load(file))
300 : m_resource(IMG_Load_IO(src, closeio))
334 return Texture(IMG_LoadTexture(renderer, file));
379 bool closeio =
false)
381 return Texture(IMG_LoadTexture_IO(renderer, src, closeio));
385 : m_resource(IMG_LoadTexture(renderer, file))
390 : m_resource(IMG_LoadTexture_IO(renderer, src, closeio))
444 bool closeio =
false)
446 return Texture(IMG_LoadTextureTyped_IO(renderer, src, closeio, type));
1240 return Surface(IMG_LoadAVIF_IO(src));
1277 return Surface{IMG_LoadICO_IO(src)};
1314 return Surface{IMG_LoadCUR_IO(src)};
1351 return Surface{IMG_LoadBMP_IO(src)};
1388 return Surface{IMG_LoadGIF_IO(src)};
1425 return Surface{IMG_LoadJPG_IO(src)};
1462 return Surface{IMG_LoadJXL_IO(src)};
1499 return Surface{IMG_LoadLBM_IO(src)};
1536 return Surface{IMG_LoadPCX_IO(src)};
1573 return Surface{IMG_LoadPNG_IO(src)};
1610 return Surface{IMG_LoadPNM_IO(src)};
1647 return Surface{IMG_LoadSVG_IO(src)};
1684 return Surface{IMG_LoadQOI_IO(src)};
1721 return Surface{IMG_LoadTGA_IO(src)};
1758 return Surface{IMG_LoadTIF_IO(src)};
1795 return Surface{IMG_LoadXCF_IO(src)};
1832 return Surface{IMG_LoadXPM_IO(src)};
1903 return Surface{IMG_LoadWEBP_IO(src)};
1923 return Surface(IMG_LoadSizedSVG_IO(src, size.x, size.y));
1942 return Surface{IMG_ReadXPMFromArray(xpm)};
1960 return Surface{IMG_ReadXPMFromArrayToRGB888(xpm)};
1978 CheckError(IMG_SaveAVIF(surface, file, quality));
2002 bool closeio =
false)
2004 CheckError(IMG_SaveAVIF_IO(surface, dst, closeio, quality));
2043 bool closeio =
false)
2045 CheckError(IMG_SavePNG_IO(surface, dst, closeio));
2063 CheckError(IMG_SaveJPG(surface, file, quality));
2087 bool closeio =
false)
2089 CheckError(IMG_SaveJPG_IO(surface, dst, closeio, quality));
2118 : m_resource(resource)
2151 : m_resource(IMG_LoadAnimation(file))
2175 : m_resource(IMG_LoadAnimation_IO(src, closeio))
2194 std::swap(m_resource, other.m_resource);
2209 auto r = m_resource;
2210 m_resource =
nullptr;
2218 constexpr explicit operator bool() const noexcept {
return !!m_resource; }
2317 return {anim->w, anim->h};
2357 return anim->delays[index];
2436 bool closeio =
false)
2438 return Animation(IMG_LoadAnimationTyped_IO(src, closeio, type));
2476 return Animation(IMG_LoadGIFAnimation_IO(src));
2498 return Animation{IMG_LoadWEBPAnimation_IO(src)};
2510 : Surface(
LoadBMP(std::move(file)))
2514inline Surface::Surface(IOStreamParam src,
bool closeio)
2515 : Surface(
LoadBMP(std::move(src), closeio))
2519inline Texture::Texture(RendererParam renderer, StringParam file)
2520 : Texture(std::move(renderer), Surface(std::move(file)))
2524inline Texture::Texture(RendererParam renderer, IOStreamParam src,
bool closeio)
2525 : Texture(std::move(renderer), Surface(std::move(src), closeio))
Animated image support.
Definition: SDL3pp_image.h:2100
constexpr Animation(Animation &&other) noexcept
Move constructor.
Definition: SDL3pp_image.h:2128
constexpr AnimationRaw release() noexcept
Retrieves underlying AnimationRaw and clear this.
Definition: SDL3pp_image.h:2207
constexpr auto operator<=>(const Animation &other) const noexcept=default
Comparison.
~Animation()
Destructor.
Definition: SDL3pp_image.h:2189
constexpr Animation(const Animation &other) noexcept=default
Copy constructor.
constexpr Animation & operator=(const Animation &other) noexcept=default
Assignment operator.
Animation(IOStreamParam src, bool closeio=false)
Load an animation from an IOStream.
Definition: SDL3pp_image.h:2174
constexpr AnimationRaw get() const noexcept
Retrieves underlying AnimationRaw.
Definition: SDL3pp_image.h:2204
constexpr AnimationRaw operator->() noexcept
member access to underlying AnimationRaw.
Definition: SDL3pp_image.h:2186
constexpr Animation(const AnimationRaw resource) noexcept
Constructs from AnimationParam.
Definition: SDL3pp_image.h:2117
constexpr const AnimationRaw operator->() const noexcept
member access to underlying AnimationRaw.
Definition: SDL3pp_image.h:2180
constexpr Animation & operator=(Animation &&other) noexcept
Assignment operator.
Definition: SDL3pp_image.h:2192
constexpr Animation(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition: SDL3pp_image.h:2105
Animation(StringParam file)
Load an animation from a file.
Definition: SDL3pp_image.h:2150
Helpers to use C++ strings parameters.
Definition: SDL3pp_strings.h:43
A collection of pixels used in software blitting.
Definition: SDL3pp_surface.h:227
constexpr Surface(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition: SDL3pp_surface.h:232
static constexpr Surface Borrow(SurfaceParam resource)
Safely borrows the from SurfaceParam.
Definition: SDL3pp_surface.h:411
An efficient driver-specific representation of pixel data.
Definition: SDL3pp_render.h:2466
constexpr Texture(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition: SDL3pp_render.h:2471
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:197
SDL_Point PointRaw
Alias to raw representation for Point.
Definition: SDL3pp_rect.h:22
Surface ReadXPMFromArrayToRGB888(char **xpm)
Load an XPM image from a memory array.
Definition: SDL3pp_image.h:1958
bool isTIF(IOStreamParam src)
Detect TIFF image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:1036
int GetWidth() const
Get the width in pixels.
Definition: SDL3pp_image.h:2301
Surface ReadXPMFromArray(char **xpm)
Load an XPM image from a memory array.
Definition: SDL3pp_image.h:1940
Surface LoadCUR(IOStreamParam src)
Load a CUR image directly.
Definition: SDL3pp_image.h:1312
void FreeAnimation(AnimationRaw anim)
Dispose of an Animation and free its resources.
Definition: SDL3pp_image.h:2453
Surface LoadSVG(IOStreamParam src)
Load a SVG image directly.
Definition: SDL3pp_image.h:1645
int GetHeight() const
Get the height in pixels.
Definition: SDL3pp_image.h:2309
bool isXCF(IOStreamParam src)
Detect XCF image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:1078
Surface LoadPCX(IOStreamParam src)
Load a PCX image directly.
Definition: SDL3pp_image.h:1534
Surface LoadLBM(IOStreamParam src)
Load a LBM image directly.
Definition: SDL3pp_image.h:1497
bool isQOI(IOStreamParam src)
Detect QOI image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:994
bool isJPG(IOStreamParam src)
Detect JPG image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:700
Surface LoadXV(IOStreamParam src)
Load a XV image directly.
Definition: SDL3pp_image.h:1867
bool isXPM(IOStreamParam src)
Detect XPM image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:1120
bool isGIF(IOStreamParam src)
Detect GIF image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:658
int GetDelay(int index) const
Return the frame delay under given index.
Definition: SDL3pp_image.h:2360
Surface LoadBMP(IOStreamParam src)
Load a BMP image directly.
Definition: SDL3pp_image.h:1349
Animation LoadWEBPAnimation(IOStreamParam src)
Load a WEBP animation directly.
Definition: SDL3pp_image.h:2496
void SaveJPG(SurfaceParam surface, StringParam file, int quality)
Save an Surface into a JPEG image file.
Definition: SDL3pp_image.h:2061
Surface LoadWEBP(IOStreamParam src)
Load a WEBP image directly.
Definition: SDL3pp_image.h:1901
Surface LoadSurfaceTyped(IOStreamParam src, StringParam type, bool closeio=false)
Load an image from an SDL data source into a software surface.
Definition: SDL3pp_image.h:199
Surface LoadTIF(IOStreamParam src)
Load a TIFF image directly.
Definition: SDL3pp_image.h:1756
Surface LoadJPG(IOStreamParam src)
Load a JPG image directly.
Definition: SDL3pp_image.h:1423
Surface LoadPNM(IOStreamParam src)
Load a PNM image directly.
Definition: SDL3pp_image.h:1608
bool isPCX(IOStreamParam src)
Detect PCX image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:826
Animation LoadAnimation(StringParam file)
Load an animation from a file.
Definition: SDL3pp_image.h:2378
bool isICO(IOStreamParam src)
Detect ICO image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:532
Animation LoadAnimationTyped(IOStreamParam src, StringParam type, bool closeio=false)
Load an animation from an SDL datasource.
Definition: SDL3pp_image.h:2434
int GetAnimationDelay(AnimationConstParam anim, int index)
Return the frame delay under given index.
Definition: SDL3pp_image.h:2355
Surface LoadTGA(IOStreamParam src)
Load a TGA image directly.
Definition: SDL3pp_image.h:1719
void Free()
Dispose of an Animation and free its resources.
Definition: SDL3pp_image.h:2455
Texture LoadTextureTyped(RendererParam renderer, IOStreamParam src, StringParam type, bool closeio=false)
Load an image from an SDL data source into a GPU texture.
Definition: SDL3pp_image.h:441
bool isJXL(IOStreamParam src)
Detect JXL image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:742
bool isWEBP(IOStreamParam src)
Detect WEBP image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:1204
bool isPNM(IOStreamParam src)
Detect PNM image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:910
bool isSVG(IOStreamParam src)
Detect SVG image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:952
Point GetAnimationSize(AnimationConstParam anim)
Get the size in pixels.
Definition: SDL3pp_image.h:2315
Surface LoadGIF(IOStreamParam src)
Load a GIF image directly.
Definition: SDL3pp_image.h:1386
Surface LoadJXL(IOStreamParam src)
Load a JXL image directly.
Definition: SDL3pp_image.h:1460
bool isAVIF(IOStreamParam src)
Detect AVIF image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:490
void SaveAVIF(SurfaceParam surface, StringParam file, int quality)
Save an Surface into a AVIF image file.
Definition: SDL3pp_image.h:1976
bool isLBM(IOStreamParam src)
Detect LBM image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:784
Surface GetFrame(int index) const
Return the frame image under given index.
Definition: SDL3pp_image.h:2344
Surface LoadICO(IOStreamParam src)
Load a ICO image directly.
Definition: SDL3pp_image.h:1275
bool isPNG(IOStreamParam src)
Detect PNG image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:868
Surface LoadAVIF(IOStreamParam src)
Load a AVIF image directly.
Definition: SDL3pp_image.h:1238
Surface LoadXPM(IOStreamParam src)
Load a XPM image directly.
Definition: SDL3pp_image.h:1830
Surface LoadPNG(IOStreamParam src)
Load a PNG image directly.
Definition: SDL3pp_image.h:1571
Surface LoadSizedSVG(IOStreamParam src, const PointRaw &size)
Load an SVG image, scaled to a specific size.
Definition: SDL3pp_image.h:1921
Animation LoadGIFAnimation(IOStreamParam src)
Load a GIF animation directly.
Definition: SDL3pp_image.h:2474
int GetCount() const
Return the number of frames.
Definition: SDL3pp_image.h:2328
bool isXV(IOStreamParam src)
Detect XV image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:1162
Surface GetAnimationFrame(AnimationConstParam anim, int index)
Return the frame image under given index.
Definition: SDL3pp_image.h:2339
Surface LoadQOI(IOStreamParam src)
Load a QOI image directly.
Definition: SDL3pp_image.h:1682
Texture LoadTexture(RendererParam renderer, StringParam file)
Load an image from a filesystem path into a GPU texture.
Definition: SDL3pp_image.h:332
int GetAnimationCount(AnimationConstParam anim)
Return the number of frames.
Definition: SDL3pp_image.h:2326
int GetAnimationWidth(AnimationConstParam anim)
Get the width in pixels.
Definition: SDL3pp_image.h:2299
Surface LoadXCF(IOStreamParam src)
Load a XCF image directly.
Definition: SDL3pp_image.h:1793
IMG_Animation * AnimationRaw
Alias to raw representation for Animation.
Definition: SDL3pp_image.h:30
int GetAnimationHeight(AnimationConstParam anim)
Get the height in pixels.
Definition: SDL3pp_image.h:2307
Surface LoadSurface(StringParam file)
Load an image from a filesystem path into a software surface.
Definition: SDL3pp_image.h:241
void SavePNG(SurfaceParam surface, StringParam file)
Save an Surface into a PNG image file.
Definition: SDL3pp_image.h:2020
bool isBMP(IOStreamParam src)
Detect BMP image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:616
bool isCUR(IOStreamParam src)
Detect CUR image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:574
Point GetSize() const
Get the size in pixels.
Definition: SDL3pp_image.h:2320
Main include header for the SDL3pp library.
Safely wrap Animation for non owning const parameters.
Definition: SDL3pp_image.h:67
constexpr auto operator->()
member access to underlying AnimationRaw.
Definition: SDL3pp_image.h:98
const AnimationRaw value
parameter's const AnimationRaw
Definition: SDL3pp_image.h:68
constexpr auto operator<=>(const AnimationConstParam &other) const =default
Comparison.
constexpr AnimationConstParam(const AnimationRaw value)
Constructs from const AnimationRaw.
Definition: SDL3pp_image.h:71
constexpr AnimationConstParam(AnimationParam value)
Constructs from AnimationParam.
Definition: SDL3pp_image.h:77
constexpr AnimationConstParam(std::nullptr_t=nullptr)
Constructs null/invalid.
Definition: SDL3pp_image.h:83
Safely wrap Animation for non owning parameters.
Definition: SDL3pp_image.h:37
AnimationRaw value
parameter's AnimationRaw
Definition: SDL3pp_image.h:38
constexpr AnimationParam(AnimationRaw value)
Constructs from AnimationRaw.
Definition: SDL3pp_image.h:41
constexpr auto operator<=>(const AnimationParam &other) const =default
Comparison.
constexpr auto operator->()
member access to underlying AnimationRaw.
Definition: SDL3pp_image.h:62
constexpr AnimationParam(std::nullptr_t=nullptr)
Constructs null/invalid.
Definition: SDL3pp_image.h:47
Semi-safe reference for Animation.
Definition: SDL3pp_image.h:2264
AnimationRef(AnimationParam resource) noexcept
Constructs from AnimationParam.
Definition: SDL3pp_image.h:2274
~AnimationRef()
Destructor.
Definition: SDL3pp_image.h:2295
AnimationRef(AnimationRaw resource) noexcept
Constructs from AnimationParam.
Definition: SDL3pp_image.h:2286
constexpr AnimationRef(const AnimationRef &other) noexcept=default
Copy constructor.
Safely wrap IOStream for non owning parameters.
Definition: SDL3pp_iostream.h:34
The structure that defines a point (using integers).
Definition: SDL3pp_rect.h:83
Safely wrap Renderer for non owning parameters.
Definition: SDL3pp_render.h:54
Safely wrap Surface for non owning parameters.
Definition: SDL3pp_surface.h:53