Browse Source

Trade: pass ImageReference2D to image converter.

Also not through pointer, but throught const&, allows implicit
conversion from Image2D and Trade::ImageData2D, which is good.

Bumped plugin interface version a bit, as this is not so drastic change
in behavior.
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
1d6015e95b
  1. 12
      src/Trade/AbstractImageConverter.cpp
  2. 14
      src/Trade/AbstractImageConverter.h
  3. 12
      src/Trade/Test/AbstractImageConverterTest.cpp

12
src/Trade/AbstractImageConverter.cpp

@ -34,33 +34,33 @@ AbstractImageConverter::AbstractImageConverter() = default;
AbstractImageConverter::AbstractImageConverter(PluginManager::AbstractManager* manager, std::string plugin): AbstractPlugin(manager, std::move(plugin)) {}
Image2D* AbstractImageConverter::exportToImage(const Image2D* const image) const {
Image2D* AbstractImageConverter::exportToImage(const ImageReference2D& image) const {
CORRADE_ASSERT(features() & Feature::ConvertImage,
"Trade::AbstractImageConverter::exportToImage(): feature not supported", nullptr);
return doExportToImage(image);
}
Image2D* AbstractImageConverter::doExportToImage(const Image2D*) const {
Image2D* AbstractImageConverter::doExportToImage(const ImageReference2D&) const {
CORRADE_ASSERT(false, "Trade::AbstractImageConverter::exportToImage(): feature advertised but not implemented", nullptr);
}
Containers::Array<unsigned char> AbstractImageConverter::exportToData(const Image2D* const image) const {
Containers::Array<unsigned char> AbstractImageConverter::exportToData(const ImageReference2D& image) const {
CORRADE_ASSERT(features() & Feature::ConvertData,
"Trade::AbstractImageConverter::exportToData(): feature not supported", nullptr);
return doExportToData(image);
}
Containers::Array<unsigned char> AbstractImageConverter::doExportToData(const Image2D*) const {
Containers::Array<unsigned char> AbstractImageConverter::doExportToData(const ImageReference2D&) const {
CORRADE_ASSERT(false, "Trade::AbstractImageConverter::exportToData(): feature advertised but not implemented", nullptr);
}
bool AbstractImageConverter::exportToFile(const Image2D* const image, const std::string& filename) const {
bool AbstractImageConverter::exportToFile(const ImageReference2D& image, const std::string& filename) const {
return doExportToFile(image, filename);
}
bool AbstractImageConverter::doExportToFile(const Image2D* const image, const std::string& filename) const {
bool AbstractImageConverter::doExportToFile(const ImageReference2D& image, const std::string& filename) const {
CORRADE_ASSERT(features() & Feature::ConvertData, "Trade::AbstractImageConverter::exportToFile(): not implemented", false);
auto data = doExportToData(image);

14
src/Trade/AbstractImageConverter.h

@ -56,7 +56,7 @@ checked by the implementation:
is supported.
*/
class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractPlugin {
CORRADE_PLUGIN_INTERFACE("cz.mosra.magnum.Trade.AbstractImageConverter/0.2")
CORRADE_PLUGIN_INTERFACE("cz.mosra.magnum.Trade.AbstractImageConverter/0.2.1")
public:
/**
@ -95,7 +95,7 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractPlugin
* Returns converted image on success, `nullptr` otherwise.
* @see features(), exportToData(), exportToFile()
*/
Image2D* exportToImage(const Image2D* image) const;
Image2D* exportToImage(const ImageReference2D& image) const;
/**
* @brief Export image to raw data
@ -104,7 +104,7 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractPlugin
* Returns data on success, zero-sized array otherwise.
* @see features(), exportToImage(), exportToFile()
*/
Containers::Array<unsigned char> exportToData(const Image2D* image) const;
Containers::Array<unsigned char> exportToData(const ImageReference2D& image) const;
/**
* @brief Export image to file
@ -112,7 +112,7 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractPlugin
* Returns `true` on success, `false` otherwise.
* @see features(), exportToImage(), exportToData()
*/
bool exportToFile(const Image2D* image, const std::string& filename) const;
bool exportToFile(const ImageReference2D& image, const std::string& filename) const;
#ifndef DOXYGEN_GENERATING_OUTPUT
private:
@ -123,10 +123,10 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractPlugin
virtual Features doFeatures() const = 0;
/** @brief Implementation of exportToImage() */
virtual Image2D* doExportToImage(const Image2D* image) const;
virtual Image2D* doExportToImage(const ImageReference2D& image) const;
/** @brief Implementation of exportToData() */
virtual Containers::Array<unsigned char> doExportToData(const Image2D* image) const;
virtual Containers::Array<unsigned char> doExportToData(const ImageReference2D& image) const;
/**
* @brief Implementation of exportToFile()
@ -135,7 +135,7 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractPlugin
* implementation calls doExportToData() and saves the result to given
* file.
*/
virtual bool doExportToFile(const Image2D* image, const std::string& filename) const;
virtual bool doExportToFile(const ImageReference2D& image, const std::string& filename) const;
};
CORRADE_ENUMSET_OPERATORS(AbstractImageConverter::Features)

12
src/Trade/Test/AbstractImageConverterTest.cpp

@ -27,8 +27,8 @@
#include <TestSuite/Compare/FileToString.h>
#include <Utility/Directory.h>
#include "Image.h"
#include "ImageFormat.h"
#include "ImageReference.h"
#include "Trade/AbstractImageConverter.h"
#include "testConfigure.h"
@ -51,10 +51,10 @@ void AbstractImageConverterTest::exportToFile() {
private:
Features doFeatures() const override { return Feature::ConvertData; }
Containers::Array<unsigned char> doExportToData(const Image2D* image) const override {
Containers::Array<unsigned char> doExportToData(const ImageReference2D& image) const override {
Containers::Array<unsigned char> out(2);
out[0] = image->size().x();
out[1] = image->size().y();
out[0] = image.size().x();
out[1] = image.size().y();
return out;
};
};
@ -64,8 +64,8 @@ void AbstractImageConverterTest::exportToFile() {
/* doExportToFile() should call doExportToData() */
DataExporter exporter;
Image2D image(ImageFormat::RGBA, ImageType::UnsignedByte, {0xfe, 0xed}, nullptr);
CORRADE_VERIFY(exporter.exportToFile(&image, Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out")));
ImageReference2D image(ImageFormat::RGBA, ImageType::UnsignedByte, {0xfe, 0xed}, nullptr);
CORRADE_VERIFY(exporter.exportToFile(image, Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out")));
CORRADE_COMPARE_AS(Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out"),
"\xFE\xED", TestSuite::Compare::FileToString);
}

Loading…
Cancel
Save