[opengtl-commits] [577] replace openraw by libraw

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 577
Author:   cyrille
Date:     2009-03-02 11:18:33 +0100 (Mon, 02 Mar 2009)

Log Message:
-----------
replace openraw by libraw

Modified Paths:
--------------
    trunk/OpenGTL/Extensions/CMakeLists.txt
    trunk/OpenGTL/Extensions/RawDC/CMakeLists.txt
    trunk/OpenGTL/Extensions/RawDC/RawDC.cpp

Added Paths:
-----------
    trunk/OpenGTL/Extensions/RawDC/libraw/


Modified: trunk/OpenGTL/Extensions/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/Extensions/CMakeLists.txt	2009-03-01 10:15:00 UTC (rev 576)
+++ trunk/OpenGTL/Extensions/CMakeLists.txt	2009-03-02 10:18:33 UTC (rev 577)
@@ -1,10 +1,7 @@
 find_package(PNG )
-find_package(OpenRaw )
 
 if( PNG_FOUND )
   add_subdirectory( PngDC )
 endif( PNG_FOUND )
 
-if( OPENRAW_FOUND )
-  add_subdirectory( RawDC )
-endif( OPENRAW_FOUND )
+add_subdirectory( RawDC )

Modified: trunk/OpenGTL/Extensions/RawDC/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/Extensions/RawDC/CMakeLists.txt	2009-03-01 10:15:00 UTC (rev 576)
+++ trunk/OpenGTL/Extensions/RawDC/CMakeLists.txt	2009-03-02 10:18:33 UTC (rev 577)
@@ -1,15 +1,21 @@
-include_directories( ${OPENRAW_INCLUDE_DIR} )
+include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/libraw )
 
+SET(libraw_LIB_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/libraw/internal/dcraw_common.cpp
+                    ${CMAKE_CURRENT_SOURCE_DIR}/libraw/internal/dcraw_fileio.cpp
+                    ${CMAKE_CURRENT_SOURCE_DIR}/libraw/internal/foveon.cpp
+                    ${CMAKE_CURRENT_SOURCE_DIR}/libraw/src/libraw_cxx.cpp
+                    ${CMAKE_CURRENT_SOURCE_DIR}/libraw/src/libraw_c_api.cpp
+   )
+
 set( RAW_DC_SRCS
      RawDC.cpp )
 
-add_library( RawDC SHARED ${RAW_DC_SRCS} )
+add_library( RawDC SHARED ${RAW_DC_SRCS} ${libraw_LIB_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} )

Modified: trunk/OpenGTL/Extensions/RawDC/RawDC.cpp
===================================================================
--- trunk/OpenGTL/Extensions/RawDC/RawDC.cpp	2009-03-01 10:15:00 UTC (rev 576)
+++ trunk/OpenGTL/Extensions/RawDC/RawDC.cpp	2009-03-02 10:18:33 UTC (rev 577)
@@ -19,46 +19,19 @@
 
 #include "RawDC.h"
 
-#include <libopenraw/libopenraw.h>
+#include "libraw/libraw.h"
 
 #include <GTLCore/Macros_p.h>
 #include <GTLImageIO/ImageDCRegistry.h>
 #include <GTLCore/Image.h>
-#include <GTLCore/Buffer.h>
+#include <GTLCore/Array.h>
 #include <GTLCore/Type.h>
+#include <GTLCore/Utils_p.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 );
@@ -75,23 +48,52 @@
 
 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 )
+  LibRaw raw;
+ 
+  int ret = raw.open_file(_fileName.c_str());
+  if (ret != LIBRAW_SUCCESS)
   {
-    or_rawfile_release( file );
-    return 0;
+      return false;
   }
+ 
+  #define OUT raw.imgdata.params
+
+  OUT.document_mode=0;
+  OUT.output_bps=16;
+  OUT.user_flip=1;
+  OUT.no_auto_bright = 1;
+  OUT.filtering_mode=(LibRaw_filtering)(LIBRAW_FILTERING_NONE);
+  OUT.use_camera_wb = 0;
+
+  ret = raw.unpack();
+  if (ret != LIBRAW_SUCCESS)
+  {
+      return false;
+  }
   
-  or_rawfile_release( file );
-  uint32_t width, height;
-  or_rawdata_dimensions(rawData, &width, &height );
+
+  int count = raw.imgdata.sizes.iwidth * raw.imgdata.sizes.iheight;
+  GTLCore::Array* array = new GTLCore::Array((int)(count * sizeof(unsigned short)));
+  
+  int max = 0;
+  
+  unsigned short *output = array->data<unsigned short>();
+  double coef = 0xFFFF / raw.imgdata.color.maximum;
+
+  for (uint row=0 ; row < raw.imgdata.sizes.iheight ; row++)
+  {
+      for (uint col=0 ; col < raw.imgdata.sizes.iwidth ; col++)
+      {
+          *output = coef * raw.imgdata.image[raw.imgdata.sizes.iwidth*row + col] [raw.FC(row, col)];
+          ++output;
+      }
+  }
   if(_region)
   {
-    _region->setWidth( width );
-    _region->setHeight( height );
+    _region->setWidth(raw.imgdata.sizes.iwidth);
+    _region->setHeight(raw.imgdata.sizes.iheight);
   }
-  return new GTLCore::BufferImage( width, height, new OpenRawBuffer( rawData), GTLCore::PixelDescription( GTLCore::Type::UnsignedInteger16, 1 ) ) ;
+  return new GTLCore::BufferImage( raw.imgdata.sizes.iwidth, raw.imgdata.sizes.iheight, array, 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


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/