Browse Source

Compressed image support, part 13: plugin interface for compressors.

pull/107/head
Vladimír Vondruš 11 years ago
parent
commit
26efc33502
  1. 12
      src/Magnum/Trade/AbstractImageConverter.cpp
  2. 29
      src/Magnum/Trade/AbstractImageConverter.h

12
src/Magnum/Trade/AbstractImageConverter.cpp

@ -49,6 +49,18 @@ std::optional<Image2D> AbstractImageConverter::doExportToImage(const ImageView2D
return std::nullopt; return std::nullopt;
} }
std::optional<CompressedImage2D> AbstractImageConverter::exportToCompressedImage(const ImageView2D& image) const {
CORRADE_ASSERT(features() & Feature::CompressImage,
"Trade::AbstractImageConverter::exportToCompressedImage(): feature not supported", {});
return doExportToCompressedImage(image);
}
std::optional<CompressedImage2D> AbstractImageConverter::doExportToCompressedImage(const ImageView2D&) const {
CORRADE_ASSERT(false, "Trade::AbstractImageConverter::exportToCompressedImage(): feature advertised but not implemented", {});
return std::nullopt;
}
Containers::Array<char> AbstractImageConverter::exportToData(const ImageView2D& image) const { Containers::Array<char> AbstractImageConverter::exportToData(const ImageView2D& image) const {
CORRADE_ASSERT(features() & Feature::ConvertData, CORRADE_ASSERT(features() & Feature::ConvertData,
"Trade::AbstractImageConverter::exportToData(): feature not supported", nullptr); "Trade::AbstractImageConverter::exportToData(): feature not supported", nullptr);

29
src/Magnum/Trade/AbstractImageConverter.h

@ -47,14 +47,18 @@ classes in @ref Trade namespace for available image converter plugins.
## Subclassing ## Subclassing
Plugin implements function @ref doFeatures() and one or more of Plugin implements function @ref doFeatures() and one or more of
@ref doExportToImage(), @ref doExportToData() or @ref doExportToFile() @ref doExportToImage(), @ref doExportToCompressedImage(), @ref doExportToData()
functions based on what features are supported. 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 You don't need to do most of the redundant sanity checks, these things are
checked by the implementation: checked by the implementation:
- Functions @ref doExportToImage() or @ref doExportToData() are called only - Function @ref doExportToImage() is called only if @ref Feature::ConvertImage
if @ref Feature::ConvertImage or @ref Feature::ConvertData is supported. 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"`. 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() */ /** Conversion to image with different format with @ref exportToImage() */
ConvertImage = 1 << 0, ConvertImage = 1 << 0,
/** Conversion to compressed image with @ref exportToCompressedImage() */
CompressImage = 1 << 1,
/** Exporting to raw data with @ref exportToData() */ /** 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<Image2D> exportToImage(const ImageView2D& image) const; std::optional<Image2D> 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<CompressedImage2D> exportToCompressedImage(const ImageView2D& image) const;
/** /**
* @brief Export image to raw data * @brief Export image to raw data
* *
@ -128,6 +144,9 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractPlugin
/** @brief Implementation of @ref exportToImage() */ /** @brief Implementation of @ref exportToImage() */
virtual std::optional<Image2D> doExportToImage(const ImageView2D& image) const; virtual std::optional<Image2D> doExportToImage(const ImageView2D& image) const;
/** @brief Implementation of @ref exportToCompressedImage() */
virtual std::optional<CompressedImage2D> doExportToCompressedImage(const ImageView2D& image) const;
/** @brief Implementation of @ref exportToData() */ /** @brief Implementation of @ref exportToData() */
virtual Containers::Array<char> doExportToData(const ImageView2D& image) const; virtual Containers::Array<char> doExportToData(const ImageView2D& image) const;

Loading…
Cancel
Save