mirror of https://github.com/mosra/magnum.git
6 changed files with 185 additions and 0 deletions
@ -0,0 +1,56 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "AbstractImageConverter.h" |
||||
|
||||
#include <Utility/Assert.h> |
||||
|
||||
namespace Magnum { namespace Trade { |
||||
|
||||
AbstractImageConverter::AbstractImageConverter() = default; |
||||
|
||||
AbstractImageConverter::AbstractImageConverter(Corrade::PluginManager::AbstractPluginManager* manager, std::string plugin): AbstractPlugin(manager, std::move(plugin)) {} |
||||
|
||||
Image2D* AbstractImageConverter::convertToImage(const Image2D* const) const { |
||||
CORRADE_ASSERT(features() & Feature::ConvertToImage, |
||||
"Trade::AbstractImageConverter::convertToImage(): feature advertised but not implemented", nullptr); |
||||
|
||||
CORRADE_ASSERT(false, "Trade::AbstractImageConverter::convertToImage(): feature not implemented", nullptr); |
||||
} |
||||
|
||||
std::pair<const unsigned char*, std::size_t> AbstractImageConverter::convertToData(const Image2D* const) const { |
||||
CORRADE_ASSERT(features() & Feature::ConvertToData, |
||||
"Trade::AbstractImageConverter::convertToData(): feature advertised but not implemented", std::make_pair(nullptr, 0)); |
||||
|
||||
CORRADE_ASSERT(false, "Trade::AbstractImageConverter::convertToData(): feature not implemented", std::make_pair(nullptr, 0)); |
||||
} |
||||
|
||||
bool AbstractImageConverter::convertToFile(const Image2D* const, const std::string&) const { |
||||
CORRADE_ASSERT(features() & Feature::ConvertToFile, |
||||
"Trade::AbstractImageConverter::convertToFile(): feature advertised but not implemented", false); |
||||
|
||||
CORRADE_ASSERT(false, "Trade::AbstractImageConverter::convertToFile(): feature not implemented", false); |
||||
} |
||||
|
||||
}} |
||||
@ -0,0 +1,119 @@
|
||||
#ifndef Magnum_Trade_AbstractImageConverter_h |
||||
#define Magnum_Trade_AbstractImageConverter_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
/** @file
|
||||
* @brief Class Magnum::Trade::AbstractImageConverter |
||||
*/ |
||||
|
||||
#include <PluginManager/AbstractPlugin.h> |
||||
|
||||
#include "Magnum.h" |
||||
#include "Text/Text.h" |
||||
#include "magnumVisibility.h" |
||||
|
||||
namespace Magnum { namespace Trade { |
||||
|
||||
/**
|
||||
@brief Base for image converter plugins |
||||
|
||||
Provides functionality for converting images between various internal formats |
||||
or compressing them. |
||||
|
||||
@section AbstractImageConverter-subclassing Subclassing |
||||
|
||||
Plugin implements function features() and one or more of convertToImage(), |
||||
convertToData() or convertToFile() functions based on what features are |
||||
supported. |
||||
*/ |
||||
class MAGNUM_EXPORT AbstractImageConverter: public Corrade::PluginManager::AbstractPlugin { |
||||
PLUGIN_INTERFACE("cz.mosra.magnum.Trade.AbstractImageConverter/0.1") |
||||
|
||||
public: |
||||
/**
|
||||
* @brief Features supported by this converter |
||||
* |
||||
* @see Features, features() |
||||
*/ |
||||
enum class Feature: UnsignedByte { |
||||
/** Converting to image with different format with convertToImage() */ |
||||
ConvertToImage = 1 << 0, |
||||
|
||||
/** Converting to data with convertToData() */ |
||||
ConvertToData = 1 << 1, |
||||
|
||||
/** Converting to file with convertToFile() */ |
||||
ConvertToFile = 1 << 2 |
||||
}; |
||||
|
||||
/**
|
||||
* @brief Features supported by this converter |
||||
* |
||||
* @see features() |
||||
*/ |
||||
typedef Corrade::Containers::EnumSet<Feature, UnsignedByte> Features; |
||||
|
||||
/** @brief Default constructor */ |
||||
explicit AbstractImageConverter(); |
||||
|
||||
/** @brief Plugin manager constructor */ |
||||
explicit AbstractImageConverter(Corrade::PluginManager::AbstractPluginManager* manager, std::string plugin); |
||||
|
||||
/** @brief Features supported by this converter */ |
||||
virtual Features features() const = 0; |
||||
|
||||
/**
|
||||
* @brief Convert image to different format |
||||
* |
||||
* Available only if @ref Feature "Feature::ConvertToImage" is supported. |
||||
* Returns converted image on success, `nullptr` otherwise. |
||||
* @see features(), convertToData(), convertToFile() |
||||
*/ |
||||
virtual Image2D* convertToImage(const Image2D* const image) const; |
||||
|
||||
/**
|
||||
* @brief Convert image to raw data |
||||
* |
||||
* Available only if @ref Feature "Feature::ConvertToData" is supported. |
||||
* Returns data pointer and size on success, `nullptr` otherwise. |
||||
* @see features(), convertToImage(), convertToFile() |
||||
*/ |
||||
virtual std::pair<const unsigned char*, std::size_t> convertToData(const Image2D* const image) const; |
||||
|
||||
/**
|
||||
* @brief Convert image and save it to file |
||||
* |
||||
* Available only if @ref Feature "Feature::ConvertToFile" is supported. |
||||
* Returns `true` on success, `false` otherwise. |
||||
* @see features(), convertToImage(), convertToData() |
||||
*/ |
||||
virtual bool convertToFile(const Image2D* const image, const std::string& filename) const; |
||||
}; |
||||
|
||||
CORRADE_ENUMSET_OPERATORS(AbstractImageConverter::Features) |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
Loading…
Reference in new issue