Magnum::Trade::AbstractImageConverter class

Base for image converter plugins.

Provides functionality for converting images between various internal formats or compressing them. See Loading and using plugins for more information and *ImageConverter classes in Trade namespace for available image converter plugins.

Data dependency

The instances returned from various functions by design have no dependency on the importer instance and neither on the dynamic plugin module. In other words, you don't need to keep the importer instance (or the plugin manager instance) around in order to have the *Data instances valid. Moreover, all Corrade::Containers::Array instances returned through Image, CompressedImage and others are only allowed to have default deleters — this is to avoid potential dangling function pointer calls when destructing such instances after the plugin module has been unloaded.

Subclassing

The plugin needs to implement thedoFeatures() function and one or more of doExportToImage(), doExportToCompressedImage(), doExportToData() or doExportToFile() functions based on what features are supported.

You don't need to do most of the redundant sanity checks, these things are checked by the implementation:

Derived classes

class AnyImageConverter
Any image converter plugin.
class BasisImageConverter new in 2019.10
Basis Universal image converter plugin.
class JpegImageConverter
JPEG image converter plugin.
class MiniExrImageConverter
OpenEXR image converter plugin using miniexr.
class PngImageConverter
PNG image converter plugin.
class StbImageConverter
Image converter plugin using stb_image_write.
class TgaImageConverter
TGA image converter plugin.

Public types

using Feature = ImageConverterFeature deprecated in Git master
Features supported by an image converter.
using Features = ImageConverterFeatures deprecated in Git master
Features supported by an image converter.

Public static functions

static auto pluginInterface() -> std::string
Plugin interface.
static auto pluginSearchPaths() -> std::vector<std::string>
Plugin search paths.

Constructors, destructors, conversion operators

AbstractImageConverter() explicit
Default constructor.
AbstractImageConverter(PluginManager::Manager<AbstractImageConverter>& manager) explicit
Constructor with access to plugin manager.
AbstractImageConverter(PluginManager::AbstractManager& manager, const std::string& plugin) explicit
Plugin manager constructor.

Public functions

auto features() const -> ImageConverterFeatures
Features supported by this converter.
auto exportToImage(const ImageView2D& image) -> Containers::Optional<Image2D>
Convert image to different format.
auto exportToCompressedImage(const ImageView2D& image) -> Containers::Optional<CompressedImage2D>
Convert image to compressed format.
auto exportToData(const ImageView2D& image) -> Containers::Array<char>
Export image to raw data.
auto exportToData(const CompressedImageView2D& image) -> Containers::Array<char>
Export compressed image to raw data.
auto exportToData(const ImageData2D& image) -> Containers::Array<char>
Export image to raw data.
auto exportToFile(const ImageView2D& image, const std::string& filename) -> bool
Export image to file.
auto exportToFile(const CompressedImageView2D& image, const std::string& filename) -> bool
Export compressed image to file.
auto exportToFile(const ImageData2D& image, const std::string& filename) -> bool
Export image to file.

Private functions

auto doFeatures() const -> ImageConverterFeatures pure virtual
Implementation of features()
auto doExportToImage(const ImageView2D& image) -> Containers::Optional<Image2D> virtual
Implementation of exportToImage()
auto doExportToCompressedImage(const ImageView2D& image) -> Containers::Optional<CompressedImage2D> virtual
Implementation of exportToCompressedImage()
auto doExportToData(const ImageView2D& image) -> Containers::Array<char> virtual
Implementation of exportToData(const ImageView2D&)
auto doExportToData(const CompressedImageView2D& image) -> Containers::Array<char> virtual
Implementation of exportToData(const CompressedImageView2D&)
auto doExportToFile(const ImageView2D& image, const std::string& filename) -> bool virtual
Implementation of exportToFile(const ImageView2D&, const std::string&)
auto doExportToFile(const CompressedImageView2D& image, const std::string& filename) -> bool virtual
Implementation of exportToFile(const CompressedImageView2D&, const std::string&)

Typedef documentation

typedef ImageConverterFeature Magnum::Trade::AbstractImageConverter::Feature

Features supported by an image converter.

typedef ImageConverterFeatures Magnum::Trade::AbstractImageConverter::Features

Features supported by an image converter.

Function documentation

static std::string Magnum::Trade::AbstractImageConverter::pluginInterface()

Plugin interface.

"cz.mosra.magnum.Trade.AbstractImageConverter/0.2.1"

static std::vector<std::string> Magnum::Trade::AbstractImageConverter::pluginSearchPaths()

Plugin search paths.

First looks in magnum/imageconverters/ or magnum-d/imageconverters/ next to the dynamic Trade library (unless it's a static build), then in the same location next to the executable and as a fallback in magnum/imageconverters/ or magnum-d/imageconverters/ in the runtime install location (lib[64]/ on Unix-like systems, bin/ on Windows). The system-wide plugin search directory is configurable using the MAGNUM_PLUGINS_DIR CMake variables, see Downloading and building for more information.

Not defined on platforms without dynamic plugin support.

Containers::Optional<Image2D> Magnum::Trade::AbstractImageConverter::exportToImage(const ImageView2D& image)

Convert image to different format.

Available only if ImageConverterFeature::ConvertImage is supported. Returns converted image on success, Containers::NullOpt otherwise.

Containers::Optional<CompressedImage2D> Magnum::Trade::AbstractImageConverter::exportToCompressedImage(const ImageView2D& image)

Convert image to compressed format.

Available only if ImageConverterFeature::ConvertCompressedImage is supported. Returns converted image on success, Containers::NullOpt otherwise.

Containers::Array<char> Magnum::Trade::AbstractImageConverter::exportToData(const ImageView2D& image)

Export image to raw data.

Available only if ImageConverterFeature::ConvertData is supported. Returns data on success, zero-sized array otherwise.

Containers::Array<char> Magnum::Trade::AbstractImageConverter::exportToData(const CompressedImageView2D& image)

Export compressed image to raw data.

Available only if ImageConverterFeature::ConvertCompressedData is supported. Returns data on success, zero-sized array otherwise.

Containers::Array<char> Magnum::Trade::AbstractImageConverter::exportToData(const ImageData2D& image)

Export image to raw data.

Based on whether the image is compressed or not, calls either exportToData(const ImageView2D&) or exportToData(const CompressedImageView2D&). See documentation of those two functions for details.

bool Magnum::Trade::AbstractImageConverter::exportToFile(const ImageView2D& image, const std::string& filename)

Export image to file.

Available only if ImageConverterFeature::ConvertFile or ImageConverterFeature::ConvertData is supported. Returns true on success, false otherwise.

bool Magnum::Trade::AbstractImageConverter::exportToFile(const CompressedImageView2D& image, const std::string& filename)

Export compressed image to file.

Available only if ImageConverterFeature::ConvertCompressedFile or ImageConverterFeature::ConvertCompressedData is supported. Returns true on success, false otherwise.

bool Magnum::Trade::AbstractImageConverter::exportToFile(const ImageData2D& image, const std::string& filename)

Export image to file.

Based on whether the image is compressed or not, calls either exportToFile(const ImageView2D&, const std::string&) or exportToFile(const CompressedImageView2D&, const std::string&). See documentation of those two functions for details.

bool Magnum::Trade::AbstractImageConverter::doExportToFile(const ImageView2D& image, const std::string& filename) virtual private

Implementation of exportToFile(const ImageView2D&, const std::string&)

If ImageConverterFeature::ConvertData is supported, default implementation calls doExportToData(const ImageView2D&) and saves the result to given file.

bool Magnum::Trade::AbstractImageConverter::doExportToFile(const CompressedImageView2D& image, const std::string& filename) virtual private

Implementation of exportToFile(const CompressedImageView2D&, const std::string&)

If ImageConverterFeature::ConvertCompressedData is supported, default implementation calls doExportToData(const CompressedImageView2D&) and saves the result to given file.