Magnum::Trade::PngImporter class

PNG importer plugin.

Imports Portable Network Graphics (*.png) images using the libPNG library. You can use PngImageConverter to encode images into this format.

Usage

This plugin depends on the Trade library and libPNG version 1.5.4 and newer. It is built if MAGNUM_WITH_PNGIMPORTER is enabled when building Magnum Plugins. To use as a dynamic plugin, load "PngImporter" via Corrade::PluginManager::Manager.

Additionally, if you're using Magnum as a CMake subproject, bundle the magnum-plugins repository and do the following. Using libPNG 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.

set(MAGNUM_WITH_PNGIMPORTER ON CACHE BOOL "" FORCE)
add_subdirectory(magnum-plugins EXCLUDE_FROM_ALL)

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

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

find_package(MagnumPlugins REQUIRED PngImporter)

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

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

Behavior and limitations

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, grayscale + alpha as PixelFormat::RG8Unorm / PixelFormat::RG16Unorm, RGB as PixelFormat::RGB8Unorm / PixelFormat::RGB16Unorm and RGBA as PixelFormat::RGBA8Unorm / PixelFormat::RGBA16Unorm. All imported images use default PixelStorage parameters. It's possible to use the forceBitDepth configuration option to import 8-bit-per-channel images as 16-bit and vice versa.

The importer recognizes ImporterFlag::Verbose, printing additional info when the flag is enabled. ImporterFlag::Quiet is recognized as well and causes all import warnings, coming either from the plugin or libpng itself, to be suppressed.

Apple CgBI PNGs

CgBI is a proprietary Apple-specific extension to PNG (details here). Stock libPNG doesn't support these, you might want to use some fork that supports it, for example https://github.com/jongwook/libpng. Or use StbImageImporter, which has the support.

The test for this plugin contains a file that can be used for verifying CgBI support.

Plugin-specific configuration

For some formats, it's possible to tune various output options through configuration(). See below for all options and their default values:

[configuration]
# Override channel bit depth. Allowed values are 0, 8 and 16, with zero
# keeping the original bit depth.
forceBitDepth=0

# According to the PNG standard, the alpha is stored unpremultiplied in the
# file, and by default it's passed through unchanged. Set to `premultiplied`
# to scale the RGB channels by the alpha on import, applying sRGB decoding
# and encoding in the process unless the file explicitly says it contains a
# linear colorspace; and to `premultipliedLinear` to scale the RGB channels
# by the alpha without any sRGB decoding and encoding, no matter what the
# file says. To better preserve precision of the premultiplied output you may
# also want to set forceBitDepth to 16.
alphaMode=

See Editing plugin-specific configuration for more information and an example showing how to edit the configuration values.

Base classes

class AbstractImporter
Base for importer plugins.

Constructors, destructors, conversion operators

PngImporter() deprecated in Git master explicit
Default constructor.
PngImporter(PluginManager::AbstractManager& manager, const Containers::StringView& plugin) explicit
Plugin manager constructor.

Function documentation

Magnum::Trade::PngImporter::PngImporter() explicit

Default constructor.