Magnum::Trade::AnyImageConverter class

Any image converter plugin.

Detects file type based on file extension, loads corresponding plugin and then tries to convert the file with it. Supported formats:

  • Basis Universal (*.basis), converted with BasisImageConverter or any other plugin that provides it. Only uncompressed 2D/3D and multi-level 2D/3D images.
  • Windows Bitmap (*.bmp), converted with any plugin that provides BmpImageConverter. Only uncompressed 2D images.
  • OpenEXR (*.exr), converted with OpenExrImageConverter or any other plugin that provides it. Only uncompressed 2D/3D and multi-level 2D/3D images.
  • Radiance HDR (*.hdr), converted with any plugin that provides HdrImageConverter. Only uncompressed 2D images.
  • JPEG (*.jpg, *.jpe, *.jpeg), converted with JpegImageConverter or any other plugin that provides it. Only uncompressed 2D images.
  • KTX2 (*.ktx2), converted with KtxImageConverter or any other plugin that provides it. Uncompressed, compressed, 1D/2D/3D and multi-level 1D/2D/3D images.
  • Portable Network Graphics (*.png), converted with PngImageConverter or any other plugin that provides it. Only uncompressed 2D images.
  • Truevision TGA (*.tga, *.vda, *.icb, *.vst), converted with TgaImageConverter or any other plugin that provides it. Only uncompressed 2D images.
  • OpenVDB (*.vdb), converted with any plugin that provides OpenVdbImageConverter. Only uncompressed 3D images.
  • WebP (*.webp), converted with WebPImageConverter or any other plugin that provides it. Only uncompressed 2D images.

As the converter plugin is picked based on file extension, only saving to files is supported.

Usage

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

Additionally, if you're using Magnum as a CMake subproject, do the following:

set(MAGNUM_WITH_ANYIMAGECONVERTER ON CACHE BOOL "" FORCE)
add_subdirectory(magnum EXCLUDE_FROM_ALL)

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

To use as a static plugin or as a dependency of another plugin with CMake, you need to request the AnyImageConverter component of the Magnum package and link to the Magnum::AnyImageConverter target:

find_package(Magnum REQUIRED AnyImageConverter)

# ...
target_link_libraries(your-app PRIVATE Magnum::AnyImageConverter)

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

Interface proxying and option propagation

On a call to convertToFile(), a target file format is detected from the extension and a corresponding plugin is loaded. After that, flags set via setFlags() and options set through configuration() are propagated to the concrete implementation, with a warning emitted in case given option is not present in the default configuration of the target plugin.

The extension() and mimeType() functions can't be implemented as they depend on the plugin chosen inside convertToFile(). Both return an empty string.

The output of the convertToFile() function called on the concrete implementation is then proxied back.

Besides delegating the flags, the AnyImageConverter itself recognizes ImageConverterFlag::Verbose, printing info about the concrete plugin being used when the flag is enabled. ImageConverterFlag::Quiet is recognized as well and causes all warnings to be suppressed.

Base classes

class AbstractImageConverter
Base for image converter plugins.

Constructors, destructors, conversion operators

AnyImageConverter(PluginManager::Manager<AbstractImageConverter>& manager) explicit
Constructor with access to plugin manager.
AnyImageConverter(PluginManager::AbstractManager& manager, const Containers::StringView& plugin) explicit
Plugin manager constructor.