class
PngImporterPNG 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 and libPNG libraries and is built if MAGNUM_WITH_PNGIMPORTER
is enabled when building Magnum Plugins. To use as a dynamic plugin, load "PngImporter"
via Corrade::
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::forceBitDepth
configuration option to import 8-bit-per-channel images as 16-bit and vice versa.
The importer recognizes ImporterFlag::
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:/
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. 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() explicit
- Default constructor.
-
PngImporter(PluginManager::
AbstractManager& manager, const Containers:: StringView& plugin) explicit - Plugin manager constructor.