Magnum::Trade::SpngImporter class new in Git master

PNG importer plugin using libspng.

Imports Portable Network Graphics (*.png) images using the libspng library.

This plugin provides the PngImporter plugin and can be considerably faster than PngImporter, especially when combined with zlib-ng.


This plugin depends on the Trade library and is built if MAGNUM_WITH_SPNGIMPORTER is enabled when building Magnum Plugins. To use as a dynamic plugin, load "SpngImporter" via Corrade::PluginManager::Manager.

Additionally, if you're using Magnum as a CMake subproject, bundle the magnum-plugins repository and do the following. Using libspng itself as a CMake subproject isn't tested at the moment, so you need to provide it as a system dependency and point CMAKE_PREFIX_PATH to its installation dir if necessary.

add_subdirectory(magnum-plugins EXCLUDE_FROM_ALL)

# So the dynamically loaded plugin gets built implicitly
add_dependencies(your-app MagnumPlugins::SpngImporter)

To use as a static plugin or as a dependency of another plugin with CMake, put FindMagnumPlugins.cmake and FindSpng.cmake into your modules/ directory, request the SpngImporter component of the MagnumPlugins package in CMake and link to the MagnumPlugins::SpngImporter target:

find_package(MagnumPlugins REQUIRED SpngImporter)

# ...
target_link_libraries(your-app PRIVATE MagnumPlugins::SpngImporter)

See Downloading and building plugins, Plugin usage with CMake, Loading and using plugins and File format support for more information.

Behavior and limitations

The supported format feature set is similar to PngImporter — supports grayscale, grayscale+alpha, RGB and RGBA images with 1, 2, 4, 8 and 16 bits per channel. Palleted images and images with transparency mask are automatically converted to G(A) / RGB(A).

Grayscale images are imported as PixelFormat::R8Unorm / PixelFormat::R16Unorm, RGB as PixelFormat::RGB8Unorm / PixelFormat::RGB16Unorm and RGBA as PixelFormat::RGBA8Unorm / PixelFormat::RGBA16Unorm. All imported images use default PixelStorage parameters. Palleted images and images with transparency mask are automatically converted to G(A) / RGB(A).

The only exception is grayscale + alpha, which is improted as PixelFormat::RGBA8Unorm in the 8-bit case, as libspng implements bit depth conversion only for single-, three- and four-channel color types. 16-bit grayscale + alpha is imported as PixelFormat::RG16Unorm as no conversion needs to be performed there.

Handling of incomplete and corrupted data

In order to support Y flipping and row alignment, the importer uses libspng's progressive decoding which doesn't report errors in case of truncated files or invalid data chunks. Import of such files will succeed, but the contents will be incomplete. See libpng documentation about error handling for more information.

Apple CgBI PNGs

CgBI is a proprietary Apple-specific extension to PNG (details here), unfortunately libspng doesn't plan to support it. To import such files use either StbImageImporter or PngImporter with a patched libpng.

Base classes

class AbstractImporter
Base for importer plugins.

Constructors, destructors, conversion operators

SpngImporter(PluginManager::AbstractManager& manager, const Containers::StringView& plugin) explicit
Plugin manager constructor.