Browse Source

Base for image converter plugins.

pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
bbb764eff5
  1. 7
      modules/FindMagnum.cmake
  2. 1
      src/CMakeLists.txt
  3. 56
      src/Trade/AbstractImageConverter.cpp
  4. 119
      src/Trade/AbstractImageConverter.h
  5. 1
      src/Trade/CMakeLists.txt
  6. 1
      src/Trade/Trade.h

7
modules/FindMagnum.cmake

@ -8,6 +8,7 @@
# MAGNUM_INCLUDE_DIRS - Root include dir and include dirs of
# dependencies
# MAGNUM_PLUGINS_FONT_DIR - Directory with font plugins
# MAGNUM_PLUGINS_IMAGECONVERTER_DIR - Directory with image converter plugins
# MAGNUM_PLUGINS_IMPORTER_DIR - Directory with importer plugins
# This command will try to find only the base library, not the optional
# components. The base library depends on Corrade, OpenGL and GLEW
@ -63,6 +64,8 @@
# MAGNUM_PLUGINS_INSTALL_DIR - Plugin installation directory
# MAGNUM_PLUGINS_FONT_INSTALL_DIR - Font plugin installation
# directory
# MAGNUM_PLUGINS_IMAGECONVERTER_INSTALL_DIR - Image converter plugin
# installation directory
# MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR - Importer plugin installation
# directory
# MAGNUM_CMAKE_MODULE_INSTALL_DIR - Installation dir for CMake
@ -323,6 +326,7 @@ endif()
set(MAGNUM_LIBRARY_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX})
set(MAGNUM_PLUGINS_INSTALL_DIR ${MAGNUM_LIBRARY_INSTALL_DIR}/magnum)
set(MAGNUM_PLUGINS_FONT_INSTALL_DIR ${MAGNUM_PLUGINS_INSTALL_DIR}/fonts)
set(MAGNUM_PLUGINS_IMAGECONVERTER_INSTALL_DIR ${MAGNUM_PLUGINS_INSTALL_DIR}/imageconverters)
set(MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR ${MAGNUM_PLUGINS_INSTALL_DIR}/importers)
set(MAGNUM_CMAKE_MODULE_INSTALL_DIR ${CMAKE_ROOT}/Modules)
set(MAGNUM_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include/Magnum)
@ -333,6 +337,7 @@ mark_as_advanced(FORCE
MAGNUM_LIBRARY_INSTALL_DIR
MAGNUM_PLUGINS_INSTALL_DIR
MAGNUM_PLUGINS_FONT_INSTALL_DIR
MAGNUM_PLUGINS_IMAGECONVERTER_INSTALL_DIR
MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR
MAGNUM_CMAKE_MODULE_INSTALL_DIR
MAGNUM_INCLUDE_INSTALL_DIR
@ -341,8 +346,10 @@ mark_as_advanced(FORCE
# Plugin directories
if(NOT WIN32)
set(MAGNUM_PLUGINS_FONT_DIR ${MAGNUM_PLUGINS_INSTALL_DIR}/fonts)
set(MAGNUM_PLUGINS_IMAGECONVERTER_DIR ${MAGNUM_PLUGINS_INSTALL_DIR}/imageconverters)
set(MAGNUM_PLUGINS_IMPORTER_DIR ${MAGNUM_PLUGINS_INSTALL_DIR}/importers)
else()
set(MAGNUM_PLUGINS_FONT_DIR fonts)
set(MAGNUM_PLUGINS_IMAGECONVERTER_DIR imageconverters)
set(MAGNUM_PLUGINS_IMPORTER_DIR importers)
endif()

1
src/CMakeLists.txt

@ -67,6 +67,7 @@ set(Magnum_SRCS
Implementation/BufferState.cpp
Implementation/State.cpp
Trade/AbstractImageConverter.cpp
Trade/AbstractImporter.cpp
Trade/AbstractMaterialData.cpp
Trade/MeshData2D.cpp

56
src/Trade/AbstractImageConverter.cpp

@ -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);
}
}}

119
src/Trade/AbstractImageConverter.h

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

1
src/Trade/CMakeLists.txt

@ -24,6 +24,7 @@
set(MagnumTrade_HEADERS
AbstractImporter.h
AbstractImageConverter.h
AbstractMaterialData.h
CameraData.h
ImageData.h

1
src/Trade/Trade.h

@ -34,6 +34,7 @@ namespace Magnum { namespace Trade {
/** @todoc Remove `ifndef` when Doxygen is sane again */
#ifndef DOXYGEN_GENERATING_OUTPUT
class AbstractImageConverter;
class AbstractImporter;
class AbstractMaterialData;
class CameraData;

Loading…
Cancel
Save