[opengtl-commits] [279] add GTLImageIO to handle loading/saving of images |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opengtl-commits Archives
]
Revision: 279
Author: cyrille
Date: 2008-07-02 00:13:20 +0200 (Wed, 02 Jul 2008)
Log Message:
-----------
add GTLImageIO to handle loading/saving of images
Modified Paths:
--------------
trunk/OpenGTL/OpenGTL/CMakeLists.txt
Added Paths:
-----------
trunk/OpenGTL/OpenGTL/GTLImageIO/
trunk/OpenGTL/OpenGTL/GTLImageIO/CMakeLists.txt
trunk/OpenGTL/OpenGTL/GTLImageIO/ImageDC.cpp
trunk/OpenGTL/OpenGTL/GTLImageIO/ImageDC.h
trunk/OpenGTL/OpenGTL/GTLImageIO/ImageDCRegistry.cpp
trunk/OpenGTL/OpenGTL/GTLImageIO/ImageDCRegistry.h
trunk/OpenGTL/OpenGTL/GTLImageIO/Version.h
trunk/OpenGTL/OpenGTL/GTLImageIO.doxy
Modified: trunk/OpenGTL/OpenGTL/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenGTL/CMakeLists.txt 2008-06-30 21:03:21 UTC (rev 278)
+++ trunk/OpenGTL/OpenGTL/CMakeLists.txt 2008-07-01 22:13:20 UTC (rev 279)
@@ -2,3 +2,5 @@
add_subdirectory(GTLCore)
add_subdirectory(GTLTest)
+add_subdirectory(GTLImageIO)
+add_subdirectory(tools)
Added: trunk/OpenGTL/OpenGTL/GTLImageIO/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLImageIO/CMakeLists.txt (rev 0)
+++ trunk/OpenGTL/OpenGTL/GTLImageIO/CMakeLists.txt 2008-07-01 22:13:20 UTC (rev 279)
@@ -0,0 +1,29 @@
+# add_subdirectory(tests)
+
+include_directories( ${LLVM_INCLUDE_DIR} )
+
+## GTLImageIO library ##
+
+set(GTLImageIO_SRCS
+ ImageDC.cpp
+ ImageDCRegistry.cpp )
+
+if (NOT APPLE)
+ add_definitions( -D_GTLIMAGEIO_EXTENSIONS_INSTALL_DIR_=\\"${GTLIMAGEIO_EXTENSIONS_INSTALL_DIR}\\" )
+else (NOT APPLE)
+ add_definitions( -D_GTLIMAGEIO_EXTENSIONS_INSTALL_DIR_='\"${GTLIMAGEIO_EXTENSIONS_INSTALL_DIR}\"' )
+endif(NOT APPLE)
+
+add_library(GTLImageIO SHARED ${GTLImageIO_SRCS} )
+target_link_libraries(GTLImageIO GTLCore )
+
+# __STDC_LIMIT_MACROS is needed by LLVM's DataTypes.h
+add_definitions( "-D__STDC_LIMIT_MACROS" )
+add_definitions( -DCOUMPONENT_NAME=\"\\\"GTLImageIO\\\"\" )
+
+# Set the ABI version of the library
+set_target_properties(GTLImageIO PROPERTIES VERSION ${OPENGTL_LIB_VERSION} SOVERSION ${OPENGTL_LIB_SOVERSION} )
+
+# Install target
+install(TARGETS GTLImageIO DESTINATION ${LIB_INSTALL_DIR} )
+# install( FILES ImageDC.h DESTINATION ${INCLUDE_INSTALL_DIR}/GTLImageIO ) # NO REASON TO INSTALL HEADERS FOR NOW
Added: trunk/OpenGTL/OpenGTL/GTLImageIO/ImageDC.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLImageIO/ImageDC.cpp (rev 0)
+++ trunk/OpenGTL/OpenGTL/GTLImageIO/ImageDC.cpp 2008-07-01 22:13:20 UTC (rev 279)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "ImageDC.h"
+
+#include <llvm/System/Path.h>
+
+#include <GTLCore/String.h>
+
+using namespace GTLImageIO;
+
+struct ImageDC::Private {
+ std::list< GTLCore::String > readExtension;
+ std::list< GTLCore::String > writeExtension;
+};
+
+ImageDC::ImageDC() : d(new Private)
+{
+}
+
+ImageDC::~ImageDC()
+{
+ delete d;
+}
+
+bool ImageDC::canDecodeImage( const GTLCore::String& _fileName ) const
+{
+ GTLCore::String extension_ = extension( _fileName );
+ return std::find( d->readExtension.begin(),
+ d->readExtension.end(),
+ extension_ ) != d->readExtension.end();
+}
+
+bool ImageDC::canEncodeImage( const GTLCore::String& _fileName ) const
+{
+ GTLCore::String extension_ = extension( _fileName );
+ return std::find( d->writeExtension.begin(),
+ d->writeExtension.end(),
+ extension_ ) != d->writeExtension.end();
+}
+
+GTLCore::String ImageDC::extension( const GTLCore::String& _fileName ) const
+{
+ GTLCore::String ext = llvm::sys::Path( _fileName ).getSuffix();
+ return ext.toLower();
+}
+
+void ImageDC::addReadExtension( const GTLCore::String& _extension )
+{
+ d->readExtension.push_back( _extension );
+}
+
+void ImageDC::addWriteExtension( const GTLCore::String& _extension )
+{
+ d->writeExtension.push_back( _extension );
+}
+
+void ImageDC::addReadWriteExtension( const GTLCore::String& _extension )
+{
+ addReadExtension(_extension);
+ addWriteExtension(_extension);
+}
Property changes on: trunk/OpenGTL/OpenGTL/GTLImageIO/ImageDC.cpp
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/OpenGTL/OpenGTL/GTLImageIO/ImageDC.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLImageIO/ImageDC.h (rev 0)
+++ trunk/OpenGTL/OpenGTL/GTLImageIO/ImageDC.h 2008-07-01 22:13:20 UTC (rev 279)
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _GTLIMAGEIO_IMAGE_DC_H_
+#define _GTLIMAGEIO_IMAGE_DC_H_
+
+#include <GTLCore/String.h>
+
+namespace GTLCore {
+ class AbstractImage;
+ class Region;
+}
+
+/**
+ * Use this macro in your \ref ImageDC when an error occurs (it assumes that the variable
+ * for error reporting is called _errorMessage), it will return false.
+ */
+#define TELL_ERROR( msg ) \
+ if( _errorMessage ) *_errorMessage = msg; \
+ return false
+
+#define COND_TELL_ERROR( cond, msg ) \
+ if( not (cond ) ) \
+ { \
+ TELL_ERROR( msg ); \
+ }
+
+namespace GTLImageIO {
+ /**
+ * Base class of Image Decoder / Coder .
+ * @ingroup GTLImageIO
+ */
+ class ImageDC {
+ public:
+ ImageDC();
+ virtual ~ImageDC();
+ /**
+ * Read file to disk.
+ * @return a pointer to the image, and an error message if no data
+ */
+ virtual GTLCore::AbstractImage* decode( const GTLCore::String& _fileName, GTLCore::Region* _region = 0, GTLCore::String* _errorMessage = 0 ) const = 0;
+ /**
+ * This function will only check if the extension is in the list. If you want more
+ * checking, you can reimplement in an herited class.
+ *
+ * @return true if this \ref ImageDC can decode images.
+ */
+ virtual bool canDecodeImage( const GTLCore::String& _fileName ) const;
+ /**
+ * Save file to disk.
+ * @return false if an error has happen, and fill \param _errorMessage
+ */
+ virtual bool encode( const GTLCore::AbstractImage* _image, const GTLCore::Region& _region, const GTLCore::String& _fileName, GTLCore::String* _errorMessage = 0 ) const = 0;
+ /**
+ * This function will only check if the extension is in the list. If you want more
+ * checking, you can reimplement in an herited class.
+ *
+ * @return true if this \ref ImageDC can encode images.
+ */
+ virtual bool canEncodeImage( const GTLCore::String& _fileName ) const;
+ protected:
+ /**
+ * Add an extension that can be read by this \ref ImageDC .
+ */
+ void addReadExtension( const GTLCore::String& _extension );
+ /**
+ * Add an extension that can be written by this \ref ImageDC .
+ */
+ void addWriteExtension( const GTLCore::String& _extension );
+ /**
+ * Convenient function that call \ref addReadExtension and
+ * \ref addWriteExtension with the \param _extension given in parameter.
+ */
+ void addReadWriteExtension( const GTLCore::String& _extension );
+ private:
+ GTLCore::String extension( const GTLCore::String& _fileName ) const;
+ private:
+ struct Private;
+ Private *const d;
+ };
+}
+
+#endif
Property changes on: trunk/OpenGTL/OpenGTL/GTLImageIO/ImageDC.h
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/OpenGTL/OpenGTL/GTLImageIO/ImageDCRegistry.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLImageIO/ImageDCRegistry.cpp (rev 0)
+++ trunk/OpenGTL/OpenGTL/GTLImageIO/ImageDCRegistry.cpp 2008-07-01 22:13:20 UTC (rev 279)
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "ImageDCRegistry.h"
+
+#include <llvm/System/Path.h>
+#include <llvm/System/DynamicLibrary.h>
+
+#include <GTLCore/Debug.h>
+#include "ImageDC.h"
+
+using namespace GTLImageIO;
+
+struct ImageDCRegistry::Private {
+ std::list< ImageDC* > imageDCS;
+};
+
+ImageDCRegistry* global_instance = 0;
+
+ImageDCRegistry::ImageDCRegistry() : d(new Private)
+{
+}
+
+ImageDCRegistry::~ImageDCRegistry()
+{
+ delete d;
+}
+
+void ImageDCRegistry::initialise()
+{
+ llvm::sys::Path extensionPath(_GTLIMAGEIO_EXTENSIONS_INSTALL_DIR_);
+ std::set<llvm::sys::Path> paths;
+ GTLCore::String errMsg;
+ GTL_DEBUG("Loading extensions from " << _GTLIMAGEIO_EXTENSIONS_INSTALL_DIR_ );
+ if( extensionPath.getDirectoryContents( paths, &errMsg))
+ {
+ GTL_DEBUG("Can't find exensions: " << errMsg );
+ } else {
+ for( std::set<llvm::sys::Path>::iterator it = paths.begin();
+ it != paths.end(); ++it)
+ {
+ GTL_DEBUG("Loading: " << it->toString() );
+ if( llvm::sys::DynamicLibrary::LoadLibraryPermanently( it->toString().c_str(), &errMsg ) )
+ {
+ GTL_ERROR("Can't load " << it->toString() << " : " << errMsg );
+ }
+ }
+ }
+}
+
+ImageDCRegistry* ImageDCRegistry::instance()
+{
+ if( not global_instance )
+ {
+ global_instance = new ImageDCRegistry();
+ global_instance->initialise();
+ }
+ return global_instance;
+}
+
+void ImageDCRegistry::registerDC( ImageDC* _imageDC )
+{
+ d->imageDCS.push_back( _imageDC );
+}
+
+const ImageDC* ImageDCRegistry::decoder( const GTLCore::String& _fileName ) const
+{
+ for( std::list< ImageDC* >::iterator it = d->imageDCS.begin();
+ it != d->imageDCS.end(); ++it)
+ {
+ if( (*it)->canDecodeImage( _fileName ) )
+ {
+ return *it;
+ }
+ }
+ return 0;
+}
+
+const ImageDC* ImageDCRegistry::encoder( const GTLCore::String& _fileName ) const
+{
+ for( std::list< ImageDC* >::iterator it = d->imageDCS.begin();
+ it != d->imageDCS.end(); ++it)
+ {
+ if( (*it)->canEncodeImage( _fileName ) )
+ {
+ return *it;
+ }
+ }
+ return 0;
+}
Property changes on: trunk/OpenGTL/OpenGTL/GTLImageIO/ImageDCRegistry.cpp
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/OpenGTL/OpenGTL/GTLImageIO/ImageDCRegistry.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLImageIO/ImageDCRegistry.h (rev 0)
+++ trunk/OpenGTL/OpenGTL/GTLImageIO/ImageDCRegistry.h 2008-07-01 22:13:20 UTC (rev 279)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _GTLIMAGEIO_IMAGE_DC_REGISTRY_H_
+#define _GTLIMAGEIO_IMAGE_DC_REGISTRY_H_
+
+#include <GTLCore/String.h>
+
+namespace GTLImageIO {
+ class ImageDC;
+ class ImageDCRegistry {
+ ImageDCRegistry();
+ virtual ~ImageDCRegistry();
+ void initialise();
+ public:
+ static ImageDCRegistry* instance();
+ void registerDC( ImageDC* _imageDC );
+ const ImageDC* decoder( const GTLCore::String& _fileName ) const;
+ const ImageDC* encoder( const GTLCore::String& _fileName ) const;
+ private:
+ struct Private;
+ Private* const d;
+ };
+}
+
+#endif
Property changes on: trunk/OpenGTL/OpenGTL/GTLImageIO/ImageDCRegistry.h
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/OpenGTL/OpenGTL/GTLImageIO/Version.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLImageIO/Version.h (rev 0)
+++ trunk/OpenGTL/OpenGTL/GTLImageIO/Version.h 2008-07-01 22:13:20 UTC (rev 279)
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _GTLIMAGEIO_VERSION_H_
+#define _GTLIMAGEIO_VERSION_H_
+
+namespace GTLImageIO {
+ const char* LibraryShortName = "OpenGTL ImageIO";
+ const char* LibraryName = "Open Graphics Transformation Languages Image Input/Output";
+ const char* LibraryCopyright = "Copyright (c) 2008 Cyrille Berger (cberger@xxxxxxxxxxx)";
+ const char* LibraryLicence = "GNU Lesser General Public License Version 2";
+ const char* LibraryVersionString = "0.9.5";
+ int LibraryVersionMajor = 0;
+ int LibraryVersionMinor = 9;
+ int LibraryVersionRevision = 5;
+}
+
+#endif
Property changes on: trunk/OpenGTL/OpenGTL/GTLImageIO/Version.h
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/OpenGTL/OpenGTL/GTLImageIO.doxy
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLImageIO.doxy (rev 0)
+++ trunk/OpenGTL/OpenGTL/GTLImageIO.doxy 2008-07-01 22:13:20 UTC (rev 279)
@@ -0,0 +1,6 @@
+/**
+ * @internal
+ * @addtogroup GTLImageIO GTLImage Input/Output Library
+ * @version 0.9.5
+ * @author Cyrille Berger
+ */