SDL_image
repository·main·Indexed 21 days ago
https://github.com/libsdl-org/sdl_imageA library used to load various image formats as SDL surfaces, extending SDL's native BMP loading capabilities. SDL_image 3.0 provides a unified interface for formats including PNG, AVIF, and WebP, and features automatic initialization and integration guides for CMake, Android Studio, Emscripten, Visual Studio, and Xcode.
What's inside SDL_image
- SDL_image is a library designed to load various image formats directly into SDL surfaces. It provides a unified interface for handling multiple image types, ranging from standard formats like BMP and PNG to more specialized formats like AVIF and WebP (depending on which optional libraries are linked during build/installation).
Add support for additional image formats
mainSDL_image can load additional image format support dynamically. To do this, include the relevant format frameworks in theoptionalfolder within your application. SDL_image will automatically detect and load them as needed during runtime.Understand the SDL versioning policy
mainSDL uses an "odd/even" versioning policy to distinguish between stable production releases and development prereleases.
Stable Releases
A version is considered stable and suitable for production if both the minor version (second part) and the patch version (third part) are divisible by 2 (e.g.,
3.2.6,3.4.0).- Patch/Micro versions (third part): Indicate bugfix releases. These are backwards-compatible (e.g., code built against
3.2.0works with3.2.8), but not necessarily forwards-compatible. - Minor versions (second part): Increase for significant changes or new functionality. Newer minor versions are backwards-compatible with older ones in the same major series (e.g., code built against
3.2.xworks with3.4.x), but not forwards-compatible.
Prereleases
A version is a development prerelease if the minor version or patch version is not divisible by 2 (e.g.,
3.2.9,3.3.x). These are not suitable for stable software distributions.- Compatibility: Prereleases are backwards-compatible with older stable branches (e.g.,
3.2.xcode works with3.3.x), but they are not guaranteed to be backwards-compatible with each other (APIs may change between3.3.0and3.3.1). - Usage Warning: Only use prereleases if you can promptly upgrade to the subsequent stable release (e.g., upgrading from
3.3.xto3.4.0).
- Patch/Micro versions (third part): Indicate bugfix releases. These are backwards-compatible (e.g., code built against
Enable AVIF, TIFF, and WebP support in SDL_image
mainSupport for AVIF, TIFF, and WebP is dynamically loaded at runtime. To use these formats, you must include the corresponding DLLs and license files with your application. If these formats are not required, you can omit these files.Use SDL_image in an Xcode project
mainTo integrate SDL_image into an Xcode project, drag the
SDL3_image.xcframeworkfile directly into your project navigator. This package supports macOS, iOS, and tvOS.Drag SDL3_image.xcframework into your Xcode project.Access SDL_image documentation and community support
mainFor technical details and community interaction, use the following resources:
- API Reference & Documentation: https://wiki.libsdl.org/SDL3_image
- Discord: Join the official server for real-time discussion: https://discord.com/invite/BwpFGBWsv8
- Discourse Forums: Participate in development discussions: https://discourse.libsdl.org/
- Announcement List: Subscribe to the low-traffic mailing list for official updates: https://www.libsdl.org/mailing-list.php
Set up SDL_image with Visual Studio using subprojects
mainThe recommended way to use SDL_image in Visual Studio is to include both SDL and SDL_image as subprojects within your solution.
Follow these steps to configure a new C++ Empty Project:
- Project Creation: Create a new Visual Studio project using the C++ Empty Project template and add your source file (e.g.,
hello.c) to the Source Files. - Add SDL Subproject: Right-click the solution, select Add > Existing Project, and navigate to the
SDL VisualC/SDLdirectory to addSDL.vcxproj. - Add SDL_image Subproject: Right-click the solution, select Add > Existing Project, and navigate to the
SDL_image VisualCdirectory to addSDL_image.vcxproj. - Configure SDL_image Dependencies: Select your
SDL_imageproject, go to Project > Add Reference, and selectSDL3. - Configure SDL_image Include Paths: Select your
SDL_imageproject, go to Project > Properties, set the configuration/platform filters to All Configurations and All Platforms, navigate to VC++ Directories, and update the Include Directories to point to your SDL include directories. - Configure Main Project Dependencies: Select your main project, go to Project > Add Reference, and select both
SDL3andSDL3_image. - Configure Main Project Include Paths: Select your main project, go to Project > Properties, set filters to All Configurations and All Platforms, navigate to VC++ Directories, and add both the SDL and SDL_image include directories to Include Directories.
- Build and Run.
- Project Creation: Create a new Visual Studio project using the C++ Empty Project template and add your source file (e.g.,
Enable support for AVIF, JPEG-XL, TIFF, and WebP
mainBy default, SDL_image does not include support for AVIF, JPEG-XL, TIFF, or WebP to keep the library size small. To enable these formats:
- Run the
external/download.shscript to fetch the necessary decoding libraries. - Enable the corresponding
SDLIMAGE_*CMake options (e.g.,SDLIMAGE_AVIF,SDLIMAGE_JPEGXL, etc.) in your build configuration.
You can also use the
SDLIMAGE_VENDOREDoption to switch between using system-installed libraries or the vendored libraries downloaded via the script.- Run the
Use SDL_image in a CMake project
mainTo use SDL_image in a CMake-based project, you must copy both the
SDL3_image.xcframeworkand thesharedirectory to your local frameworks directory:~/Library/Frameworks.cp -R SDL3_image.xcframework share ~/Library/Frameworks/Access SDL_image API reference and documentation
mainThe complete API reference and additional technical documentation for SDL_image can be found on the official SDL Wiki.
https://wiki.libsdl.org/SDL3_imageEnable AVIF, JPEG-XL, and WebP support in Xcode
mainBy default, support for AVIF, JPEG-XL, and WebP is not included in the Xcode project due to the size of the decoding libraries. To enable these formats:
- Run the script
external/download.shto fetch the necessary dependencies. - Edit the configuration at the top of the Xcode project to enable the desired formats.
- Ensure you include the appropriate framework in your application to use these features.
./external/download.sh- Run the script
Build and use SDL_image with CMake
mainSDL_image can be integrated into your project using CMake. The general workflow is to use CMake to build the library and then link the resulting headers and library files to your own project.
To build the included example programs alongside the library, enable the
SDLIMAGE_SAMPLESoption during the CMake configuration step.cmake -DSDLIMAGE_SAMPLES=ON ..