From 26efc33502354550436306a49106794148304b50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 2 Aug 2015 00:38:18 +0200 Subject: [PATCH] Compressed image support, part 13: plugin interface for compressors. --- src/Magnum/Trade/AbstractImageConverter.cpp | 12 +++++++++ src/Magnum/Trade/AbstractImageConverter.h | 29 +++++++++++++++++---- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/Magnum/Trade/AbstractImageConverter.cpp b/src/Magnum/Trade/AbstractImageConverter.cpp index 1a0899b8f..8af2c77d5 100644 --- a/src/Magnum/Trade/AbstractImageConverter.cpp +++ b/src/Magnum/Trade/AbstractImageConverter.cpp @@ -49,6 +49,18 @@ std::optional AbstractImageConverter::doExportToImage(const ImageView2D return std::nullopt; } +std::optional AbstractImageConverter::exportToCompressedImage(const ImageView2D& image) const { + CORRADE_ASSERT(features() & Feature::CompressImage, + "Trade::AbstractImageConverter::exportToCompressedImage(): feature not supported", {}); + + return doExportToCompressedImage(image); +} + +std::optional AbstractImageConverter::doExportToCompressedImage(const ImageView2D&) const { + CORRADE_ASSERT(false, "Trade::AbstractImageConverter::exportToCompressedImage(): feature advertised but not implemented", {}); + return std::nullopt; +} + Containers::Array AbstractImageConverter::exportToData(const ImageView2D& image) const { CORRADE_ASSERT(features() & Feature::ConvertData, "Trade::AbstractImageConverter::exportToData(): feature not supported", nullptr); diff --git a/src/Magnum/Trade/AbstractImageConverter.h b/src/Magnum/Trade/AbstractImageConverter.h index d5b42a06d..9779ef8da 100644 --- a/src/Magnum/Trade/AbstractImageConverter.h +++ b/src/Magnum/Trade/AbstractImageConverter.h @@ -47,14 +47,18 @@ classes in @ref Trade namespace for available image converter plugins. ## Subclassing Plugin implements function @ref doFeatures() and one or more of -@ref doExportToImage(), @ref doExportToData() or @ref doExportToFile() -functions based on what features are supported. +@ref doExportToImage(), @ref doExportToCompressedImage(), @ref doExportToData() +or @ref 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: -- Functions @ref doExportToImage() or @ref doExportToData() are called only - if @ref Feature::ConvertImage or @ref Feature::ConvertData is supported. +- Function @ref doExportToImage() is called only if @ref Feature::ConvertImage + is supported. +- Function @ref doExportToData() are called only if @ref Feature::ConvertData + is supported. +- Function @ref doExportToCompressedImage() is called only if + @ref Feature::CompressImage is supported. Plugin interface string is `"cz.mosra.magnum.Trade.AbstractImageConverter/0.2.1"`. */ @@ -71,8 +75,11 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractPlugin /** Conversion to image with different format with @ref exportToImage() */ ConvertImage = 1 << 0, + /** Conversion to compressed image with @ref exportToCompressedImage() */ + CompressImage = 1 << 1, + /** Exporting to raw data with @ref exportToData() */ - ConvertData = 1 << 1 + ConvertData = 1 << 2 }; /** @@ -100,6 +107,15 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractPlugin */ std::optional exportToImage(const ImageView2D& image) const; + /** + * @brief Convert image to compressed format + * + * Available only if @ref Feature::CompressImage is supported. Returns + * converted image on success, `std::nullopt` otherwise. + * @see @ref features(), @ref exportToData(), @ref exportToFile() + */ + std::optional exportToCompressedImage(const ImageView2D& image) const; + /** * @brief Export image to raw data * @@ -128,6 +144,9 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractPlugin /** @brief Implementation of @ref exportToImage() */ virtual std::optional doExportToImage(const ImageView2D& image) const; + /** @brief Implementation of @ref exportToCompressedImage() */ + virtual std::optional doExportToCompressedImage(const ImageView2D& image) const; + /** @brief Implementation of @ref exportToData() */ virtual Containers::Array doExportToData(const ImageView2D& image) const;