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.

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 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

enum class Feature: UnsignedByte { ConvertImage = 1 << 0, ConvertCompressedImage = 1 << 1, ConvertFile = 1 << 2, ConvertCompressedFile = 1 << 3, ConvertData = ConvertFile|(1 << 4), ConvertCompressedData = ConvertCompressedFile|(1 << 4) }
Features supported by this converter.
using Features = Containers::EnumSet<Feature>
Features supported by this 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 -> Features
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.

Protected functions

auto doFeatures() const -> Features 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&)

Enum documentation

enum class Magnum::Trade::AbstractImageConverter::Feature: UnsignedByte

Features supported by this converter.

Enumerators
ConvertImage

Conversion to image with different format with exportToImage()

ConvertCompressedImage

Conversion to compressed image with exportToCompressedImage()

ConvertFile

Exporting to file with exportToFile(const ImageView2D&, const std::string&)

ConvertCompressedFile

Exporting to file with exportToFile(const CompressedImageView2D&, const std::string&)

ConvertData

Exporting to raw data with exportToData(const ImageView2D&). Implies Feature::ConvertFile.

ConvertCompressedData

Exporting compressed image to raw data with exportToData(const CompressedImageView2D&). Implies Feature::ConvertCompressedFile.

Typedef documentation

typedef Containers::EnumSet<Feature> Magnum::Trade::AbstractImageConverter::Features

Features supported by this 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 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 Feature::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 Feature::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 Feature::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 Feature::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 Feature::ConvertFile or Feature::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 Feature::ConvertCompressedFile or Feature::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 protected

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

If Feature::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 protected

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

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