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_DISABLE_IMAGE) && !defined(SDL3PP_ENABLE_IMAGE) && \
11 __has_include(<SDL3_image/SDL_image.h>)
12#define SDL3PP_ENABLE_IMAGE
15#if defined(SDL3PP_ENABLE_IMAGE) || defined(SDL3PP_DOC)
17#include <SDL3_image/SDL_image.h>
58 constexpr explicit operator bool()
const {
return !!
value; }
94 constexpr explicit operator bool()
const {
return !!
value; }
113#define SDL_IMAGE_MAJOR_VERSION
115#define SDL_IMAGE_MINOR_VERSION
117#define SDL_IMAGE_MICRO_VERSION
124#define SDL_IMAGE_VERSION \
126 SDL_IMAGE_MAJOR_VERSION, SDL_IMAGE_MINOR_VERSION, SDL_IMAGE_MICRO_VERSION)
129#define SDL_IMAGE_VERSION_ATLEAST(X, Y, Z) \
130 ((SDL_IMAGE_MAJOR_VERSION >= X) && \
131 (SDL_IMAGE_MAJOR_VERSION > X || SDL_IMAGE_MINOR_VERSION >= Y) && \
132 (SDL_IMAGE_MAJOR_VERSION > X || SDL_IMAGE_MINOR_VERSION > Y || \
133 SDL_IMAGE_MICRO_VERSION >= Z))
146inline int Version() {
return IMG_Version(); }
206 bool closeio =
false)
208 return Surface(IMG_LoadTyped_IO(src, closeio, type));
296 return Surface(IMG_Load_IO(src, closeio));
300 : m_resource(IMG_Load(file))
305 : m_resource(IMG_Load_IO(src, closeio))
339 return Texture(IMG_LoadTexture(renderer, file));
384 bool closeio =
false)
386 return Texture(IMG_LoadTexture_IO(renderer, src, closeio));
390 : m_resource(IMG_LoadTexture(renderer, file))
395 : m_resource(IMG_LoadTexture_IO(renderer, src, closeio))
449 bool closeio =
false)
451 return Texture(IMG_LoadTextureTyped_IO(renderer, src, closeio, type));
1245 return Surface(IMG_LoadAVIF_IO(src));
1282 return Surface{IMG_LoadICO_IO(src)};
1319 return Surface{IMG_LoadCUR_IO(src)};
1356 return Surface{IMG_LoadBMP_IO(src)};
1393 return Surface{IMG_LoadGIF_IO(src)};
1430 return Surface{IMG_LoadJPG_IO(src)};
1467 return Surface{IMG_LoadJXL_IO(src)};
1504 return Surface{IMG_LoadLBM_IO(src)};
1541 return Surface{IMG_LoadPCX_IO(src)};
1578 return Surface{IMG_LoadPNG_IO(src)};
1615 return Surface{IMG_LoadPNM_IO(src)};
1652 return Surface{IMG_LoadSVG_IO(src)};
1689 return Surface{IMG_LoadQOI_IO(src)};
1726 return Surface{IMG_LoadTGA_IO(src)};
1763 return Surface{IMG_LoadTIF_IO(src)};
1800 return Surface{IMG_LoadXCF_IO(src)};
1837 return Surface{IMG_LoadXPM_IO(src)};
1908 return Surface{IMG_LoadWEBP_IO(src)};
1928 return Surface(IMG_LoadSizedSVG_IO(src, size.x, size.y));
1947 return Surface{IMG_ReadXPMFromArray(xpm)};
1965 return Surface{IMG_ReadXPMFromArrayToRGB888(xpm)};
1983 CheckError(IMG_SaveAVIF(surface, file, quality));
2007 bool closeio =
false)
2009 CheckError(IMG_SaveAVIF_IO(surface, dst, closeio, quality));
2048 bool closeio =
false)
2050 CheckError(IMG_SavePNG_IO(surface, dst, closeio));
2068 CheckError(IMG_SaveJPG(surface, file, quality));
2092 bool closeio =
false)
2094 CheckError(IMG_SaveJPG_IO(surface, dst, closeio, quality));
2120 : m_resource(resource)
2151 : m_resource(IMG_LoadAnimation(file))
2175 : m_resource(IMG_LoadAnimation_IO(src, closeio))
2191 std::swap(m_resource, other.m_resource);
2201 auto r = m_resource;
2202 m_resource =
nullptr;
2210 constexpr bool operator==(std::nullptr_t _)
const {
return !m_resource; }
2213 constexpr explicit operator bool()
const {
return !!m_resource; }
2301 return {anim->w, anim->h};
2341 return anim->delays[index];
2420 bool closeio =
false)
2422 return Animation(IMG_LoadAnimationTyped_IO(src, closeio, type));
2460 return Animation(IMG_LoadGIFAnimation_IO(src));
2482 return Animation{IMG_LoadWEBPAnimation_IO(src)};
Animated image support.
Definition: SDL3pp_image.h:2105
constexpr AnimationRaw get() const
Retrieves underlying AnimationRaw.
Definition: SDL3pp_image.h:2196
constexpr Animation(Animation &&other)
Move constructor.
Definition: SDL3pp_image.h:2128
constexpr Animation(const AnimationRaw resource)
Constructs from AnimationParam.
Definition: SDL3pp_image.h:2119
~Animation()
Destructor.
Definition: SDL3pp_image.h:2186
constexpr AnimationRaw operator->()
member access to underlying AnimationRaw.
Definition: SDL3pp_image.h:2183
constexpr bool operator==(std::nullptr_t _) const
Comparison.
Definition: SDL3pp_image.h:2210
Animation(IOStreamParam src, bool closeio=false)
Load an animation from an IOStream.
Definition: SDL3pp_image.h:2174
constexpr Animation()=default
Default ctor.
constexpr const AnimationRaw operator->() const
member access to underlying AnimationRaw.
Definition: SDL3pp_image.h:2180
constexpr auto operator<=>(const Animation &other) const =default
Comparison.
constexpr AnimationRaw release()
Retrieves underlying AnimationRaw and clear this.
Definition: SDL3pp_image.h:2199
constexpr Animation(const Animation &other)=delete
Copy constructor.
Animation & operator=(Animation other)
Assignment operator.
Definition: SDL3pp_image.h:2189
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:201
constexpr Surface()=default
Default ctor.
static constexpr Surface Borrow(SurfaceParam resource)
Safely borrows the from SurfaceParam.
Definition: SDL3pp_surface.h:378
An efficient driver-specific representation of pixel data.
Definition: SDL3pp_render.h:2136
constexpr Texture()=default
Default ctor.
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:1963
bool isTIF(IOStreamParam src)
Detect TIFF image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:1041
int GetWidth() const
Get the width in pixels.
Definition: SDL3pp_image.h:2285
Surface ReadXPMFromArray(char **xpm)
Load an XPM image from a memory array.
Definition: SDL3pp_image.h:1945
Surface LoadCUR(IOStreamParam src)
Load a CUR image directly.
Definition: SDL3pp_image.h:1317
void FreeAnimation(AnimationRaw anim)
Dispose of an Animation and free its resources.
Definition: SDL3pp_image.h:2437
Surface LoadSVG(IOStreamParam src)
Load a SVG image directly.
Definition: SDL3pp_image.h:1650
int GetHeight() const
Get the height in pixels.
Definition: SDL3pp_image.h:2293
bool isXCF(IOStreamParam src)
Detect XCF image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:1083
Surface LoadPCX(IOStreamParam src)
Load a PCX image directly.
Definition: SDL3pp_image.h:1539
Surface LoadLBM(IOStreamParam src)
Load a LBM image directly.
Definition: SDL3pp_image.h:1502
bool isQOI(IOStreamParam src)
Detect QOI image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:999
bool isJPG(IOStreamParam src)
Detect JPG image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:705
Surface LoadXV(IOStreamParam src)
Load a XV image directly.
Definition: SDL3pp_image.h:1872
bool isXPM(IOStreamParam src)
Detect XPM image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:1125
bool isGIF(IOStreamParam src)
Detect GIF image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:663
int GetDelay(int index) const
Return the frame delay under given index.
Definition: SDL3pp_image.h:2344
Surface LoadBMP(IOStreamParam src)
Load a BMP image directly.
Definition: SDL3pp_image.h:1354
Animation LoadWEBPAnimation(IOStreamParam src)
Load a WEBP animation directly.
Definition: SDL3pp_image.h:2480
void SaveJPG(SurfaceParam surface, StringParam file, int quality)
Save an Surface into a JPEG image file.
Definition: SDL3pp_image.h:2066
Surface LoadWEBP(IOStreamParam src)
Load a WEBP image directly.
Definition: SDL3pp_image.h:1906
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:204
Surface LoadTIF(IOStreamParam src)
Load a TIFF image directly.
Definition: SDL3pp_image.h:1761
Surface LoadJPG(IOStreamParam src)
Load a JPG image directly.
Definition: SDL3pp_image.h:1428
Surface LoadPNM(IOStreamParam src)
Load a PNM image directly.
Definition: SDL3pp_image.h:1613
bool isPCX(IOStreamParam src)
Detect PCX image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:831
Animation LoadAnimation(StringParam file)
Load an animation from a file.
Definition: SDL3pp_image.h:2362
bool isICO(IOStreamParam src)
Detect ICO image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:537
Animation LoadAnimationTyped(IOStreamParam src, StringParam type, bool closeio=false)
Load an animation from an SDL datasource.
Definition: SDL3pp_image.h:2418
int GetAnimationDelay(AnimationConstParam anim, int index)
Return the frame delay under given index.
Definition: SDL3pp_image.h:2339
Surface LoadTGA(IOStreamParam src)
Load a TGA image directly.
Definition: SDL3pp_image.h:1724
void Free()
Dispose of an Animation and free its resources.
Definition: SDL3pp_image.h:2439
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:446
bool isJXL(IOStreamParam src)
Detect JXL image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:747
bool isWEBP(IOStreamParam src)
Detect WEBP image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:1209
bool isPNM(IOStreamParam src)
Detect PNM image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:915
bool isSVG(IOStreamParam src)
Detect SVG image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:957
Point GetAnimationSize(AnimationConstParam anim)
Get the size in pixels.
Definition: SDL3pp_image.h:2299
Surface LoadGIF(IOStreamParam src)
Load a GIF image directly.
Definition: SDL3pp_image.h:1391
Surface LoadJXL(IOStreamParam src)
Load a JXL image directly.
Definition: SDL3pp_image.h:1465
bool isAVIF(IOStreamParam src)
Detect AVIF image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:495
void SaveAVIF(SurfaceParam surface, StringParam file, int quality)
Save an Surface into a AVIF image file.
Definition: SDL3pp_image.h:1981
bool isLBM(IOStreamParam src)
Detect LBM image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:789
Surface GetFrame(int index) const
Return the frame image under given index.
Definition: SDL3pp_image.h:2328
Surface LoadICO(IOStreamParam src)
Load a ICO image directly.
Definition: SDL3pp_image.h:1280
bool isPNG(IOStreamParam src)
Detect PNG image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:873
Surface LoadAVIF(IOStreamParam src)
Load a AVIF image directly.
Definition: SDL3pp_image.h:1243
Surface LoadXPM(IOStreamParam src)
Load a XPM image directly.
Definition: SDL3pp_image.h:1835
Surface LoadPNG(IOStreamParam src)
Load a PNG image directly.
Definition: SDL3pp_image.h:1576
Surface LoadSizedSVG(IOStreamParam src, const PointRaw &size)
Load an SVG image, scaled to a specific size.
Definition: SDL3pp_image.h:1926
Animation LoadGIFAnimation(IOStreamParam src)
Load a GIF animation directly.
Definition: SDL3pp_image.h:2458
int GetCount() const
Return the number of frames.
Definition: SDL3pp_image.h:2312
bool isXV(IOStreamParam src)
Detect XV image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:1167
Surface GetAnimationFrame(AnimationConstParam anim, int index)
Return the frame image under given index.
Definition: SDL3pp_image.h:2323
Surface LoadQOI(IOStreamParam src)
Load a QOI image directly.
Definition: SDL3pp_image.h:1687
Texture LoadTexture(RendererParam renderer, StringParam file)
Load an image from a filesystem path into a GPU texture.
Definition: SDL3pp_image.h:337
int GetAnimationCount(AnimationConstParam anim)
Return the number of frames.
Definition: SDL3pp_image.h:2310
int GetAnimationWidth(AnimationConstParam anim)
Get the width in pixels.
Definition: SDL3pp_image.h:2283
Surface LoadXCF(IOStreamParam src)
Load a XCF image directly.
Definition: SDL3pp_image.h:1798
IMG_Animation * AnimationRaw
Alias to raw representation for Animation.
Definition: SDL3pp_image.h:35
int GetAnimationHeight(AnimationConstParam anim)
Get the height in pixels.
Definition: SDL3pp_image.h:2291
Surface LoadSurface(StringParam file)
Load an image from a filesystem path into a software surface.
Definition: SDL3pp_image.h:246
void SavePNG(SurfaceParam surface, StringParam file)
Save an Surface into a PNG image file.
Definition: SDL3pp_image.h:2025
bool isBMP(IOStreamParam src)
Detect BMP image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:621
bool isCUR(IOStreamParam src)
Detect CUR image data on a readable/seekable IOStream.
Definition: SDL3pp_image.h:579
Point GetSize() const
Get the size in pixels.
Definition: SDL3pp_image.h:2304
Main include header for the SDL3pp library.
Safely wrap Animation for non owning const parameters.
Definition: SDL3pp_image.h:72
constexpr AnimationConstParam(std::nullptr_t _=nullptr)
Constructs null/invalid.
Definition: SDL3pp_image.h:88
constexpr auto operator->()
member access to underlying AnimationRaw.
Definition: SDL3pp_image.h:103
const AnimationRaw value
parameter's const AnimationRaw
Definition: SDL3pp_image.h:73
constexpr auto operator<=>(const AnimationConstParam &other) const =default
Comparison.
constexpr AnimationConstParam(const AnimationRaw value)
Constructs from const AnimationRaw.
Definition: SDL3pp_image.h:76
constexpr AnimationConstParam(AnimationParam value)
Constructs from AnimationParam.
Definition: SDL3pp_image.h:82
Safely wrap Animation for non owning parameters.
Definition: SDL3pp_image.h:42
AnimationRaw value
parameter's AnimationRaw
Definition: SDL3pp_image.h:43
constexpr AnimationParam(std::nullptr_t _=nullptr)
Constructs null/invalid.
Definition: SDL3pp_image.h:52
constexpr AnimationParam(AnimationRaw value)
Constructs from AnimationRaw.
Definition: SDL3pp_image.h:46
constexpr auto operator<=>(const AnimationParam &other) const =default
Comparison.
constexpr auto operator->()
member access to underlying AnimationRaw.
Definition: SDL3pp_image.h:67
Semi-safe reference for Animation.
Definition: SDL3pp_image.h:2259
~AnimationRef()
Destructor.
Definition: SDL3pp_image.h:2279
AnimationRef(AnimationParam resource)
Constructs from AnimationParam.
Definition: SDL3pp_image.h:2267
AnimationRef(const AnimationRef &other)
Copy constructor.
Definition: SDL3pp_image.h:2273
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:53
Safely wrap Surface for non owning parameters.
Definition: SDL3pp_surface.h:46