Author: post
Date: 2011-11-20 12:58:09 +0100 (Sun, 20 Nov 2011)
New Revision: 392

Added:
   RawSpeed/RawParser.cpp
   RawSpeed/RawParser.h
Modified:
   RawSpeed/ArwDecoder.cpp
   RawSpeed/Cr2Decoder.cpp
   RawSpeed/DngDecoder.cpp
   RawSpeed/NefDecoder.cpp
   RawSpeed/OrfDecoder.cpp
   RawSpeed/PefDecoder.cpp
   RawSpeed/RawSpeed.cpp
   RawSpeed/RawSpeed.vcproj
   RawSpeed/Rw2Decoder.cpp
   RawSpeed/SrwDecoder.cpp
   RawSpeed/TiffParser.cpp
Log:
Add abstraction layer, so other decoders than TIFF-based decoders can easily be 
supported. Use "RawParser" instead of "TiffParser" to get a decoder - this also 
eliminates the need for you to use "TiffParser::parseData()".

Modified: RawSpeed/ArwDecoder.cpp
===================================================================
--- RawSpeed/ArwDecoder.cpp     2011-11-20 10:57:59 UTC (rev 391)
+++ RawSpeed/ArwDecoder.cpp     2011-11-20 11:58:09 UTC (rev 392)
@@ -30,6 +30,9 @@
 }
 
 ArwDecoder::~ArwDecoder(void) {
+  if (mRootIFD)
+    delete mRootIFD;
+  mRootIFD = NULL;
 }
 
 RawImage ArwDecoder::decodeRaw() {

Modified: RawSpeed/Cr2Decoder.cpp
===================================================================
--- RawSpeed/Cr2Decoder.cpp     2011-11-20 10:57:59 UTC (rev 391)
+++ RawSpeed/Cr2Decoder.cpp     2011-11-20 11:58:09 UTC (rev 392)
@@ -32,6 +32,9 @@
 }
 
 Cr2Decoder::~Cr2Decoder(void) {
+  if (mRootIFD)
+    delete mRootIFD;
+  mRootIFD = NULL;
 }
 
 RawImage Cr2Decoder::decodeRaw() {

Modified: RawSpeed/DngDecoder.cpp
===================================================================
--- RawSpeed/DngDecoder.cpp     2011-11-20 10:57:59 UTC (rev 391)
+++ RawSpeed/DngDecoder.cpp     2011-11-20 11:58:09 UTC (rev 392)
@@ -42,6 +42,9 @@
 }
 
 DngDecoder::~DngDecoder(void) {
+  if (mRootIFD)
+    delete mRootIFD;
+  mRootIFD = NULL;
 }
 
 RawImage DngDecoder::decodeRaw() {

Modified: RawSpeed/NefDecoder.cpp
===================================================================
--- RawSpeed/NefDecoder.cpp     2011-11-20 10:57:59 UTC (rev 391)
+++ RawSpeed/NefDecoder.cpp     2011-11-20 11:58:09 UTC (rev 392)
@@ -32,6 +32,9 @@
 }
 
 NefDecoder::~NefDecoder(void) {
+  if (mRootIFD)
+    delete mRootIFD;
+  mRootIFD = NULL;
 }
 
 RawImage NefDecoder::decodeRaw() {

Modified: RawSpeed/OrfDecoder.cpp
===================================================================
--- RawSpeed/OrfDecoder.cpp     2011-11-20 10:57:59 UTC (rev 391)
+++ RawSpeed/OrfDecoder.cpp     2011-11-20 11:58:09 UTC (rev 392)
@@ -33,6 +33,9 @@
 }
 
 OrfDecoder::~OrfDecoder(void) {
+  if (mRootIFD)
+    delete mRootIFD;
+  mRootIFD = NULL;
 }
 
 RawImage OrfDecoder::decodeRaw() {
@@ -73,17 +76,19 @@
   TiffEntry *makernoteEntry = exif->getEntry(MAKERNOTE);
   const uchar8* makernote = makernoteEntry->getData();
   FileMap makermap((uchar8*)&makernote[8], makernoteEntry->count - 8);
-  TiffParserOlympus makertiff(&makermap);
-  makertiff.parseData();
+  try {
+    TiffParserOlympus makertiff(&makermap);
+    makertiff.parseData();
+    data = makertiff.RootIFD()->getIFDsWithTag((TiffTag)0x2010);
+    if (data.empty())
+      ThrowRDE("ORF Decoder: Unsupported compression");
+    TiffEntry *oly = data[0]->getEntry((TiffTag)0x2010);
+    if (oly->type == TIFF_UNDEFINED)
+      ThrowRDE("ORF Decoder: Unsupported compression");
+  } catch (TiffParserException) {
+    ThrowRDE("ORF Decoder: Unable to parse makernote");
+  }
 
-  data = makertiff.RootIFD()->getIFDsWithTag((TiffTag)0x2010);
-
-  if (data.empty())
-    ThrowRDE("ORF Decoder: Unsupported compression");
-  TiffEntry *oly = data[0]->getEntry((TiffTag)0x2010);
-  if (oly->type == TIFF_UNDEFINED)
-    ThrowRDE("ORF Decoder: Unsupported compression");
-
   // We add 3 bytes slack, since the bitpump might be a few bytes ahead.
   ByteStream s(mFile->getData(offsets->getInt()), counts->getInt() + 3);
 

Modified: RawSpeed/PefDecoder.cpp
===================================================================
--- RawSpeed/PefDecoder.cpp     2011-11-20 10:57:59 UTC (rev 391)
+++ RawSpeed/PefDecoder.cpp     2011-11-20 11:58:09 UTC (rev 392)
@@ -30,6 +30,9 @@
 }
 
 PefDecoder::~PefDecoder(void) {
+  if (mRootIFD)
+    delete mRootIFD;
+  mRootIFD = NULL;
 }
 
 RawImage PefDecoder::decodeRaw() {

Added: RawSpeed/RawParser.cpp
===================================================================
--- RawSpeed/RawParser.cpp                              (rev 0)
+++ RawSpeed/RawParser.cpp      2011-11-20 11:58:09 UTC (rev 392)
@@ -0,0 +1,48 @@
+#include "StdAfx.h"
+#include "RawParser.h"
+#include "TiffParserException.h"
+#include "TiffParser.h"
+
+/*
+    RawSpeed - RAW file decoder.
+
+    Copyright (C) 2009 Klaus Post
+
+    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; either
+    version 2 of the License, or (at your option) any later version.
+
+    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; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
USA
+
+    http://www.klauspost.com
+*/
+
+namespace RawSpeed {
+
+
+RawParser::RawParser(FileMap* inputData): mInput(inputData) {
+}
+
+
+RawParser::~RawParser(void) {
+}
+
+RawDecoder* RawParser::getDecoder() {
+  try {
+    TiffParser p(mInput);
+    p.parseData();
+    return p.getDecoder();
+  } catch (TiffParserException) {}
+  throw RawDecoderException("No decoder found. Sorry.");
+  return NULL;
+}
+
+} // namespace RawSpeed

Added: RawSpeed/RawParser.h
===================================================================
--- RawSpeed/RawParser.h                                (rev 0)
+++ RawSpeed/RawParser.h        2011-11-20 11:58:09 UTC (rev 392)
@@ -0,0 +1,43 @@
+/* 
+    RawSpeed - RAW file decoder.
+
+    Copyright (C) 2009 Klaus Post
+
+    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; either
+    version 2 of the License, or (at your option) any later version.
+
+    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; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
USA
+
+    http://www.klauspost.com
+*/
+
+#ifndef RAW_PARSER_H
+#define RAW_PARSER_H
+
+#include "FileMap.h"
+#include "RawDecoder.h"
+
+namespace RawSpeed {
+
+class RawParser 
+{
+public:
+  RawParser(FileMap* input);
+  virtual ~RawParser();
+  virtual RawDecoder* getDecoder();
+protected:
+  FileMap *mInput;
+};
+
+} // namespace RawSpeed
+
+#endif

Modified: RawSpeed/RawSpeed.cpp
===================================================================
--- RawSpeed/RawSpeed.cpp       2011-11-20 10:57:59 UTC (rev 391)
+++ RawSpeed/RawSpeed.cpp       2011-11-20 11:58:09 UTC (rev 392)
@@ -1,6 +1,6 @@
 #include "stdafx.h"
 #include "FileReader.h"
-#include "TiffParser.h"
+#include "RawParser.h"
 #include "RawDecoder.h"
 #include "CameraMetaData.h"
 #include "ColorFilterArray.h"
@@ -29,7 +29,7 @@
 
 using namespace RawSpeed;
 
-#define _USE_GFL_
+//#define _USE_GFL_
 #ifdef _USE_GFL_
 #include "libgfl.h"
 #pragma comment(lib, "libgfl.lib") 
@@ -51,77 +51,69 @@
       printf("Could not open image:%s\n", e.what());
       return;
     }
-    TiffParser t(m);
-    t.parseData();
+    RawParser t(m);
     d = t.getDecoder();
-    try {
-      d->checkSupport(meta);
-      startTime = GetTickCount();
+    d->checkSupport(meta);
+    startTime = GetTickCount();
 
-      d->decodeRaw();
-      d->decodeMetaData(meta);
-      RawImage r = d->mRaw;
-      r->scaleBlackWhite();
+    d->decodeRaw();
+    d->decodeMetaData(meta);
+    RawImage r = d->mRaw;
+    r->scaleBlackWhite();
 
-      uint32 time = GetTickCount()-startTime;
-      float mpps = (float)r->dim.x * (float)r->dim.y * (float)r->getCpp()  / 
(1000.0f * (float)time);
-      wprintf(L"Decoding %s took: %u ms, %4.2f Mpixel/s\n", f.Filename(), 
time, mpps);
+    uint32 time = GetTickCount()-startTime;
+    float mpps = (float)r->dim.x * (float)r->dim.y * (float)r->getCpp()  / 
(1000.0f * (float)time);
+    wprintf(L"Decoding %s took: %u ms, %4.2f Mpixel/s\n", f.Filename(), time, 
mpps);
 
-      for (uint32 i = 0; i < d->errors.size(); i++) {
-        printf("Error Encountered:%s", d->errors[i]);
-      }
-      if (r->isCFA) {
+    for (uint32 i = 0; i < d->errors.size(); i++) {
+      printf("Error Encountered:%s", d->errors[i]);
+    }
+    if (r->isCFA) {
 //        printf("DCRAW filter:%x\n",r->cfa.getDcrawFilter());
 //        printf(r->cfa.asString().c_str());
-      }
+    }
 /*
-      for (uint32 y=200;y<r->dim.y-400; y+=2) {
-        printf("black,");
-        for (uint32 x=20;x<=100; x+=2) {
-          (x==100) ? printf("%d\n",(int)*(UINT16*)r->getData(x,y)) : 
printf("%d,",(int)*(UINT16*)r->getData(x,y));
-        }
-        printf("color,");
-        for (uint32 x=1020;x<=1100; x+=2) {
-          (x==1100) ? printf("%d\n",(int)*(UINT16*)r->getData(x,y)) : 
printf("%d,",(int)*(UINT16*)r->getData(x,y));
-        }
+    for (uint32 y=200;y<r->dim.y-400; y+=2) {
+      printf("black,");
+      for (uint32 x=20;x<=100; x+=2) {
+        (x==100) ? printf("%d\n",(int)*(UINT16*)r->getData(x,y)) : 
printf("%d,",(int)*(UINT16*)r->getData(x,y));
       }
+      printf("color,");
+      for (uint32 x=1020;x<=1100; x+=2) {
+        (x==1100) ? printf("%d\n",(int)*(UINT16*)r->getData(x,y)) : 
printf("%d,",(int)*(UINT16*)r->getData(x,y));
+      }
+    }
 */
 #ifdef _USE_GFL_
-      GFL_BITMAP* b;
-      if (r->getCpp() == 1)
-        b = gflAllockBitmapEx(GFL_GREY,d->mRaw->dim.x, 
d->mRaw->dim.y,16,16,NULL);
-      else if (r->getCpp() == 3)
-        b = gflAllockBitmapEx(GFL_RGB,d->mRaw->dim.x, 
d->mRaw->dim.y,16,8,NULL);
-      else
-        ThrowRDE("Unable to save image.");
+    GFL_BITMAP* b;
+    if (r->getCpp() == 1)
+      b = gflAllockBitmapEx(GFL_GREY,d->mRaw->dim.x, 
d->mRaw->dim.y,16,16,NULL);
+    else if (r->getCpp() == 3)
+      b = gflAllockBitmapEx(GFL_RGB,d->mRaw->dim.x, d->mRaw->dim.y,16,8,NULL);
+    else
+      ThrowRDE("Unable to save image.");
 
-      BitBlt(b->Data,b->BytesPerLine, r->getData(),r->pitch, 
r->dim.x*r->getBpp(), r->dim.y );
+    BitBlt(b->Data,b->BytesPerLine, r->getData(),r->pitch, 
r->dim.x*r->getBpp(), r->dim.y );
 
-      GFL_SAVE_PARAMS s;
-      gflGetDefaultSaveParams(&s);
-      s.FormatIndex = gflGetFormatIndexByName("tiff");
+    GFL_SAVE_PARAMS s;
+    gflGetDefaultSaveParams(&s);
+    s.FormatIndex = gflGetFormatIndexByName("tiff");
 
-      char ascii[1024];
-      WideCharToMultiByte(CP_ACP, 0, f.Filename(), -1, ascii, 1024, NULL, 
NULL);
-      string savename(ascii);
-      size_t index = savename.rfind('.');
-      replace(r->mode.begin(), r->mode.end(), ':', '-');
-      savename = 
savename.substr(0,index).append("[").append(r->mode).append("].tiff");
+    char ascii[1024];
+    WideCharToMultiByte(CP_ACP, 0, f.Filename(), -1, ascii, 1024, NULL, NULL);
+    string savename(ascii);
+    size_t index = savename.rfind('.');
+    replace(r->mode.begin(), r->mode.end(), ':', '-');
+    savename = 
savename.substr(0,index).append("[").append(r->mode).append("].tiff");
 
-      gflSaveBitmap((char*)savename.c_str(),b,&s);
-      gflFreeBitmap(b);
+    gflSaveBitmap((char*)savename.c_str(),b,&s);
+    gflFreeBitmap(b);
 #endif
-    } catch (RawDecoderException e) {
-      wchar_t uni[1024];
-      MultiByteToWideChar(CP_ACP, 0, e.what(), -1, uni, 1024);
-      //    MessageBox(0,uni, L"RawDecoder Exception",0);
-      wprintf(L"Raw Decoder Exception:%s\n",uni);
-    }
-  } catch (TiffParserException e) {
+  } catch (RawDecoderException e) {
     wchar_t uni[1024];
     MultiByteToWideChar(CP_ACP, 0, e.what(), -1, uni, 1024);
-    //    MessageBox(0,uni, L"Tiff Parser error",0);
-    wprintf(L"Tiff Exception:%s\n",uni);
+    //    MessageBox(0,uni, L"RawDecoder Exception",0);
+    wprintf(L"Raw Decoder Exception:%s\n",uni);
   }
   if (d) delete d;
   if (m) delete m;
@@ -152,8 +144,7 @@
     try {    
       // Insert 1000 random errors in file
       m2->corrupt(1000);
-      TiffParser t(m2);
-      t.parseData();
+      RawParser t(m2);
       d = t.getDecoder();
 
       startTime = GetTickCount();
@@ -174,10 +165,6 @@
       wchar_t uni[1024];
       MultiByteToWideChar(CP_ACP, 0, e.what(), -1, uni, 1024);
       wprintf(L"Raw Decoder Exception:%s\n",uni);
-    } catch (TiffParserException e) {
-      wchar_t uni[1024];
-      MultiByteToWideChar(CP_ACP, 0, e.what(), -1, uni, 1024);
-      wprintf(L"Tiff Parser Exception:%s\n",uni);
     }
     delete m2;
     if (d)
@@ -190,8 +177,7 @@
     // Get truncated file
     FileMap *m2 = m->cloneRandomSize();
     try {    
-      TiffParser t(m2);
-      t.parseData();
+      RawParser t(m2);
       d = t.getDecoder();
 
       startTime = GetTickCount();
@@ -211,10 +197,6 @@
       wchar_t uni[1024];
       MultiByteToWideChar(CP_ACP, 0, e.what(), -1, uni, 1024);
       wprintf(L"Raw Decoder Exception:%s\n",uni);
-    } catch (TiffParserException e) {
-      wchar_t uni[1024];
-      MultiByteToWideChar(CP_ACP, 0, e.what(), -1, uni, 1024);
-      wprintf(L"Tiff Parser Exception:%s\n",uni);
     }
     delete m2;
     if (d)
@@ -238,7 +220,23 @@
 #endif
   try {
     CameraMetaData meta("..\\data\\cameras.xml");
-
+    
OpenFile(FileReader(L"..\\testimg\\panasonic_lumix_dmc_fz150_18.rw2"),&meta);
+    
OpenFile(FileReader(L"..\\testimg\\panasonic_lumix_dmc_fz150_17.rw2"),&meta);
+    
OpenFile(FileReader(L"..\\testimg\\panasonic_lumix_dmc_fz150_16.rw2"),&meta);
+    
OpenFile(FileReader(L"..\\testimg\\panasonic_lumix_dmc_fz150_15.rw2"),&meta);
+    
OpenFile(FileReader(L"..\\testimg\\panasonic_lumix_dmc_fz150_14.rw2"),&meta);
+    
OpenFile(FileReader(L"..\\testimg\\panasonic_lumix_dmc_fz150_13.rw2"),&meta);
+    
OpenFile(FileReader(L"..\\testimg\\panasonic_lumix_dmc_fz150_10.rw2"),&meta);
+    
OpenFile(FileReader(L"..\\testimg\\panasonic_lumix_dmc_fz150_07.rw2"),&meta);
+    
OpenFile(FileReader(L"..\\testimg\\panasonic_lumix_dmc_fz150_01.rw2"),&meta);
+    
OpenFile(FileReader(L"..\\testimg\\Canon_PowerShot_S100-PS100hSLI0200.CR2"),&meta);
+    
OpenFile(FileReader(L"..\\testimg\\Canon_PowerShot_S100-PS100LL64003.CR2"),&meta);
+    
OpenFile(FileReader(L"..\\testimg\\Canon_PowerShot_S100-PS100LL32003.CR2"),&meta);
+    
OpenFile(FileReader(L"..\\testimg\\Canon_PowerShot_S100-PS100LL16003.CR2"),&meta);
+    
OpenFile(FileReader(L"..\\testimg\\Canon_PowerShot_S100-PS100LL08003.CR2"),&meta);
+    
OpenFile(FileReader(L"..\\testimg\\Canon_PowerShot_S100-PS100LL04003.CR2"),&meta);
+    
OpenFile(FileReader(L"..\\testimg\\Canon_PowerShot_S100-PS100LL00806.CR2"),&meta);
+    
OpenFile(FileReader(L"..\\testimg\\Canon_PowerShot_S100-PS100hVFATB.CR2"),&meta);
     OpenFile(FileReader(L"..\\testimg\\samsung_ex1_07.srw"),&meta);
     
OpenFile(FileReader(L"..\\testimg\\Olympus_E-PM1-EPM1hVFAI00200.ORF"),&meta);
     OpenFile(FileReader(L"..\\testimg\\Pentax_Kx_IGP2252.PEF"),&meta);
@@ -444,7 +442,6 @@
       OpenFile(FileReader(L"..\\testimg\\Sony Alpha 
SLT-A77-AA77hSLI16000NR1.ARW"),&meta);
       OpenFile(FileReader(L"..\\testimg\\Sony Alpha 
SLT-A77-AA77hVFAI00200.ARW"),&meta);
       OpenFile(FileReader(L"..\\testimg\\Sony Alpha 
SLT-A77-AA77hVFAWS_DISTORT_OFF.ARW"),&meta);
-/*
     OpenFile(FileReader(L"..\\testimg\\Phase One H25 Capture One PRO 3.7.10 
IIQ Raw Large-001.tif"),&meta);
       OpenFile(FileReader(L"..\\testimg\\Phase One H25 Capture One PRO 3.7.10 
IIQ Raw Small-001.tif"),&meta);
       OpenFile(FileReader(L"..\\testimg\\Phase One H25 Capture One PRO 3.7.10 
Raw Compatible with 3.0-001.Cap"),&meta);
@@ -467,7 +464,6 @@
       
OpenFile(FileReader(L"..\\testimg\\Olympus_PEN_E-P3-EP3hSLI01600NR0.ORF"),&meta);
       
OpenFile(FileReader(L"..\\testimg\\Olympus_PEN_E-P3-EP3hVFAI00200.ORF"),&meta);
       
OpenFile(FileReader(L"..\\testimg\\Olympus_PEN_E-P3-EP3hVFAWB.ORF"),&meta);
-      return 0;
     OpenFile(FileReader(L"..\\testimg\\dng\\_DSC5230.dng"),&meta);
     OpenFile(FileReader(L"..\\testimg\\Nikon_D5100-dsc_0081.NEF"),&meta);
       OpenFile(FileReader(L"..\\testimg\\Nikon_D5100-dsc_0064.NEF"),&meta);
@@ -487,7 +483,7 @@
   OpenFile(FileReader(L"..\\testimg\\Nikon_E5400.nef"),&meta);
     OpenFile(FileReader(L"..\\testimg\\350d-color_problem.cr2"),&meta);
     OpenFile(FileReader(L"..\\testimg\\samsung_nx100_02.srw"),&meta);
-    OpenFile(FileReader(L"..\\testimg\\samsung_ex1_10.srw"),&meta);*/
+    OpenFile(FileReader(L"..\\testimg\\samsung_ex1_10.srw"),&meta);
     OpenFile(FileReader(L"..\\testimg\\olympus_xz1_26.orf"),&meta);
     OpenFile(FileReader(L"..\\testimg\\olympus_xz1_06.orf"),&meta);
     OpenFile(FileReader(L"..\\testimg\\olympus_xz1_05.orf"),&meta);

Modified: RawSpeed/RawSpeed.vcproj
===================================================================
--- RawSpeed/RawSpeed.vcproj    2011-11-20 10:57:59 UTC (rev 391)
+++ RawSpeed/RawSpeed.vcproj    2011-11-20 11:58:09 UTC (rev 392)
@@ -353,6 +353,10 @@
                                        >
                                </File>
                                <File
+                                       RelativePath=".\RawParser.cpp"
+                                       >
+                               </File>
+                               <File
                                        RelativePath=".\Rw2Decoder.cpp"
                                        >
                                </File>
@@ -535,6 +539,10 @@
                                        >
                                </File>
                                <File
+                                       RelativePath=".\RawParser.h"
+                                       >
+                               </File>
+                               <File
                                        RelativePath=".\Rw2Decoder.h"
                                        >
                                </File>

Modified: RawSpeed/Rw2Decoder.cpp
===================================================================
--- RawSpeed/Rw2Decoder.cpp     2011-11-20 10:57:59 UTC (rev 391)
+++ RawSpeed/Rw2Decoder.cpp     2011-11-20 11:58:09 UTC (rev 392)
@@ -32,6 +32,9 @@
   if (input_start)
     delete input_start;
   input_start = 0;
+  if (mRootIFD)
+    delete mRootIFD;
+  mRootIFD = NULL;
 }
 
 RawImage Rw2Decoder::decodeRaw() {

Modified: RawSpeed/SrwDecoder.cpp
===================================================================
--- RawSpeed/SrwDecoder.cpp     2011-11-20 10:57:59 UTC (rev 391)
+++ RawSpeed/SrwDecoder.cpp     2011-11-20 11:58:09 UTC (rev 392)
@@ -33,6 +33,9 @@
 }
 
 SrwDecoder::~SrwDecoder(void) {
+  if (mRootIFD)
+    delete mRootIFD;
+  mRootIFD = NULL;
 }
 
 RawImage SrwDecoder::decodeRaw() {

Modified: RawSpeed/TiffParser.cpp
===================================================================
--- RawSpeed/TiffParser.cpp     2011-11-20 10:57:59 UTC (rev 391)
+++ RawSpeed/TiffParser.cpp     2011-11-20 11:58:09 UTC (rev 392)
@@ -64,6 +64,9 @@
       throw TiffParserException("Not a TIFF file (magic 42)");
   }
 
+  if (mRootIFD)
+    delete mRootIFD;
+
   if (tiff_endian == host_endian)
     mRootIFD = new TiffIFD();
   else
@@ -89,15 +92,22 @@
 }
 
 RawDecoder* TiffParser::getDecoder() {
+  if (!mRootIFD)
+    parseData();
+
   vector<TiffIFD*> potentials;
   potentials = mRootIFD->getIFDsWithTag(DNGVERSION);
 
+  /* Copy, so we can pass it on and not have it destroyed with ourselves */
+  TiffIFD* root = mRootIFD;
+
   if (!potentials.empty()) {  // We have a dng image entry
     TiffIFD *t = potentials[0];
     const unsigned char* c = t->getEntry(DNGVERSION)->getData();
     if (c[0] > 1)
       throw TiffParserException("DNG version too new.");
-    return new DngDecoder(mRootIFD, mInput);
+    mRootIFD = NULL;
+    return new DngDecoder(root, mInput);
   }
 
   potentials = mRootIFD->getIFDsWithTag(MAKE);
@@ -107,31 +117,40 @@
       string make = (*i)->getEntry(MAKE)->getString();
       TrimSpaces(make);
       if (!make.compare("Canon")) {
-        return new Cr2Decoder(mRootIFD, mInput);
+        mRootIFD = NULL;
+        return new Cr2Decoder(root, mInput);
       }
       if (!make.compare("NIKON CORPORATION")) {
-        return new NefDecoder(mRootIFD, mInput);
+        mRootIFD = NULL;
+        return new NefDecoder(root, mInput);
       }
       if (!make.compare("NIKON")) {
-        return new NefDecoder(mRootIFD, mInput);
+        mRootIFD = NULL;
+        return new NefDecoder(root, mInput);
       }
       if (!make.compare("OLYMPUS IMAGING CORP.")) {
-        return new OrfDecoder(mRootIFD, mInput);
+        mRootIFD = NULL;
+        return new OrfDecoder(root, mInput);
       }
       if (!make.compare("SONY")) {
-        return new ArwDecoder(mRootIFD, mInput);
+        mRootIFD = NULL;
+        return new ArwDecoder(root, mInput);
       }
       if (!make.compare("PENTAX Corporation ")) {
-        return new PefDecoder(mRootIFD, mInput);
+        mRootIFD = NULL;
+        return new PefDecoder(root, mInput);
       }
       if (!make.compare("PENTAX")) {
-        return new PefDecoder(mRootIFD, mInput);
+        mRootIFD = NULL;
+        return new PefDecoder(root, mInput);
       }
       if (!make.compare("Panasonic")) {
-        return new Rw2Decoder(mRootIFD, mInput);
+        mRootIFD = NULL;
+        return new Rw2Decoder(root, mInput);
       }
       if (!make.compare("SAMSUNG")) {
-        return new SrwDecoder(mRootIFD, mInput);
+        mRootIFD = NULL;
+        return new SrwDecoder(root, mInput);
       }
     }
   }


_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit

Reply via email to