[opengtl-commits] [344] add support for RAW images with libopenraw |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opengtl-commits Archives
]
Revision: 344
Author: cyrille
Date: 2008-09-01 22:53:29 +0200 (Mon, 01 Sep 2008)
Log Message:
-----------
add support for RAW images with libopenraw
Modified Paths:
--------------
trunk/OpenGTL/Extensions/CMakeLists.txt
trunk/OpenGTL/Extensions/PngDC/CMakeLists.txt
Added Paths:
-----------
trunk/OpenGTL/Extensions/RawDC/
trunk/OpenGTL/Extensions/RawDC/CMakeLists.txt
trunk/OpenGTL/Extensions/RawDC/RawDC.cpp
trunk/OpenGTL/Extensions/RawDC/RawDC.h
Modified: trunk/OpenGTL/Extensions/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/Extensions/CMakeLists.txt 2008-09-01 06:46:22 UTC (rev 343)
+++ trunk/OpenGTL/Extensions/CMakeLists.txt 2008-09-01 20:53:29 UTC (rev 344)
@@ -1,5 +1,10 @@
find_package(PNG )
+find_package(OpenRaw )
if( PNG_FOUND )
add_subdirectory( PngDC )
endif( PNG_FOUND )
+
+if( OPENRAW_FOUND )
+ add_subdirectory( RawDC )
+endif( OPENRAW_FOUND )
Modified: trunk/OpenGTL/Extensions/PngDC/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/Extensions/PngDC/CMakeLists.txt 2008-09-01 06:46:22 UTC (rev 343)
+++ trunk/OpenGTL/Extensions/PngDC/CMakeLists.txt 2008-09-01 20:53:29 UTC (rev 344)
@@ -1,7 +1,3 @@
-# add_subdirectory(tests)
-
-## GTLImageIO library ##
-
include_directories(${PNG_INCLUDE_DIR})
set(PNG_DC_SRCS
Added: trunk/OpenGTL/Extensions/RawDC/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/Extensions/RawDC/CMakeLists.txt (rev 0)
+++ trunk/OpenGTL/Extensions/RawDC/CMakeLists.txt 2008-09-01 20:53:29 UTC (rev 344)
@@ -0,0 +1,16 @@
+include_directories( ${OPENRAW_INCLUDE_DIR} )
+
+set( RAW_DC_SRCS
+ RawDC.cpp )
+
+add_library( RawDC SHARED ${RAW_DC_SRCS} )
+target_link_libraries( RawDC GTLImageIO ${OPENRAW_LIBRARIES} )
+
+# __STDC_LIMIT_MACROS is needed by LLVM's DataTypes.h
+add_definitions( "-D__STDC_LIMIT_MACROS" )
+add_definitions( -DCOUMPONENT_NAME=\"\\\"RawDC\\\"\" )
+add_definitions( ${PNG_DEFINITIONS} )
+
+# Install target
+install( TARGETS RawDC DESTINATION ${GTLIMAGEIO_EXTENSIONS_INSTALL_DIR} )
+# install( FILES ImageDC.h DESTINATION ${INCLUDE_INSTALL_DIR}/GTLImageIO ) # NO REASON TO INSTALL HEADERS FOR NOW
Added: trunk/OpenGTL/Extensions/RawDC/RawDC.cpp
===================================================================
--- trunk/OpenGTL/Extensions/RawDC/RawDC.cpp (rev 0)
+++ trunk/OpenGTL/Extensions/RawDC/RawDC.cpp 2008-09-01 20:53:29 UTC (rev 344)
@@ -0,0 +1,100 @@
+/*
+ * 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 "RawDC.h"
+
+#include <libopenraw/libopenraw.h>
+
+#include <GTLCore/Macros_p.h>
+#include <GTLImageIO/ImageDCRegistry.h>
+#include <GTLCore/Image.h>
+#include <GTLCore/Buffer.h>
+#include <GTLCore/Type.h>
+#include <GTLCore/Region.h>
+#include <GTLCore/Debug.h>
+#include <GTLCore/PixelDescription.h>
+
+class OpenRawBuffer : public GTLCore::Buffer {
+ public:
+ OpenRawBuffer(ORRawDataRef rawData) : m_rawData( rawData )
+ {
+ }
+ virtual ~OpenRawBuffer()
+ {
+ or_rawdata_release( m_rawData );
+ }
+ virtual char * rawData()
+ {
+ return reinterpret_cast<char*>( or_rawdata_data( m_rawData ) );
+ }
+ virtual const char * rawData() const
+ {
+ return reinterpret_cast<const char*>( or_rawdata_data( m_rawData ) );
+ }
+
+ virtual int size() const
+ {
+ return or_rawdata_data_size( m_rawData );
+ }
+
+
+ private:
+ ORRawDataRef m_rawData;
+};
+
+
+STATIC_INITIALISATION( RawDC )
+{
+ GTLImageIO::ImageDCRegistry::instance()->registerDC( new RawDC );
+}
+
+RawDC::RawDC()
+{
+ addReadWriteExtension("nef");
+}
+
+RawDC::~RawDC()
+{
+}
+
+GTLCore::AbstractImage* RawDC::decode( const GTLCore::String& _fileName, GTLCore::Region* _region, GTLCore::String* _errorMessage ) const
+{
+ ORRawFileRef file = or_rawfile_new( _fileName.c_str(), OR_RAWFILE_TYPE_UNKNOWN );
+ ORRawDataRef rawData = or_rawdata_new();
+ if( or_rawfile_get_rawdata( file, rawData, OR_OPTIONS_NONE) != OR_ERROR_NONE )
+ {
+ or_rawfile_release( file );
+ return 0;
+ }
+
+ or_rawfile_release( file );
+ uint32_t width, height;
+ or_rawdata_dimensions(rawData, &width, &height );
+ return new GTLCore::BufferImage( width, height, new OpenRawBuffer( rawData), GTLCore::PixelDescription( GTLCore::Type::UnsignedInteger16, 1 ) ) ;
+}
+
+bool RawDC::encode( const GTLCore::AbstractImage* _image, const GTLCore::Region& _region, const GTLCore::String& _fileName, GTLCore::String* _errorMessage ) const
+{
+ return false;
+}
+
+bool RawDC::canEncodeImage( const GTLCore::String& _fileName ) const
+{
+ return false;
+}
Added: trunk/OpenGTL/Extensions/RawDC/RawDC.h
===================================================================
--- trunk/OpenGTL/Extensions/RawDC/RawDC.h (rev 0)
+++ trunk/OpenGTL/Extensions/RawDC/RawDC.h 2008-09-01 20:53:29 UTC (rev 344)
@@ -0,0 +1,29 @@
+/*
+ * 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 <GTLImageIO/ImageDC.h>
+
+class RawDC : public GTLImageIO::ImageDC {
+ public:
+ RawDC();
+ virtual ~RawDC();
+ virtual GTLCore::AbstractImage* decode( const GTLCore::String& _fileName, GTLCore::Region* = 0, GTLCore::String* _errorMessage = 0 ) const;
+ virtual bool encode( const GTLCore::AbstractImage* _image, const GTLCore::Region& _region, const GTLCore::String& _fileName, GTLCore::String* _errorMessage = 0 ) const;
+ virtual bool canEncodeImage( const GTLCore::String& _fileName ) const;
+};