[Digikam-devel] extragear/graphics/digikam [POSSIBLY UNSAFE]

Gilles Caulier caulier.gilles at free.fr
Mon Jun 5 21:21:37 BST 2006


SVN commit 548534 by cgilles:

digikam from trunk: use new dcraw thumbnail extraction method to render album items content and camera items content about all RAW files. This way will be always the more performant instead to use dcraw::parse method from digiKam core. Note that DCR raw files from Kodak camera works fine in this case.

IMPORTANT : you need to use last dcraw 8.21, else thumbs render can take a while !!!

BUG: 128283
CCMAIL: digikam-devel at kde.org

 M  +40 -21    kioslave/digikamthumbnail.cpp   [POSSIBLY UNSAFE: popen]
 M  +41 -13    utilities/cameragui/umscamera.cpp   [POSSIBLY UNSAFE: popen]


--- trunk/extragear/graphics/digikam/kioslave/digikamthumbnail.cpp #548533:548534
@@ -64,7 +64,6 @@
 
 // Local includes
 
-#include "dcraw_parse.h"
 #include "dimg.h"
 #include "dmetadata.h"
 #include "digikamthumbnail.h"
@@ -651,48 +650,68 @@
 
 bool kio_digikamthumbnailProtocol::loadDCRAW(QImage& image, const QString& path)
 {
-    // first try with Dave Coffin's "parse" utility
+    // Try to extract embedded thumbnail using dcraw with options:
+    // -c : write to stdout
+    // -e : Extract the camera-generated thumbnail, not the raw image (JPEG or a PPM file).
+    // Note : this code require at least dcraw version 8.21
 
-    kdDebug() << k_funcinfo << "Parsing file: " << path << endl;
+    QCString command  = "dcraw -c -e ";
+    command += QFile::encodeName( KProcess::quote( path ) );
+    kdDebug() << "Running dcraw command " << command << endl;
 
-    KTempFile thumbFile(QString::null, "rawthumb");
-    thumbFile.setAutoDelete(true);
-    Digikam::DcrawParse rawFileParser;
+    FILE* f = popen( command.data(), "r" );
 
-    if (thumbFile.status() == 0)
+    if ( !f )
+        return false;
+
+    QByteArray imgData;
+    const int  MAX_IPC_SIZE = (1024*32);
+    char       buffer[MAX_IPC_SIZE];
+    QFile      file;
+    Q_LONG     len;
+
+    file.open( IO_ReadOnly,  f );
+
+    while ((len = file.readBlock(buffer, MAX_IPC_SIZE)) != 0)
     {
-        if (rawFileParser.getThumbnail(QFile::encodeName(path),
-                                       QFile::encodeName(thumbFile.name())) == 0)
+        if ( len == -1 )
         {
-            image.load(thumbFile.name());
-            if (!image.isNull())
-                return true;
+            file.close();
+            return false;
         }
+        else
+        {
+            int oldSize = imgData.size();
+            imgData.resize( imgData.size() + len );
+            memcpy(imgData.data()+oldSize, buffer, len);
+        }
     }
 
-    QCString command;
+    file.close();
+    pclose( f );
 
-    // run dcraw with options:
+    if ( !imgData.isEmpty() )
+    {
+        if (image.loadFromData( imgData ))
+            return true;
+    }
+    
+    // In second, try to use simple RAW extraction method
     // -c : write to stdout
     // -h : Half-size color image (3x faster than -q)
     // -2 : 8bit ppm output
     // -a : Use automatic white balance
     // -w : Use camera white balance, if possible
+
     command  = "dcraw -c -h -2 -w -a ";
     command += QFile::encodeName( KProcess::quote( path ) );
     kdDebug() << "Running dcraw command " << command << endl;
 
-    FILE* f = popen( command.data(), "r" );
+    f = popen( command.data(), "r" );
 
     if ( !f )
         return false;
 
-    QByteArray imgData;
-    const int  MAX_IPC_SIZE = (1024*32);
-    char       buffer[MAX_IPC_SIZE];
-    QFile      file;
-    Q_LONG     len;
-
     file.open( IO_ReadOnly,  f );
 
     while ((len = file.readBlock(buffer, MAX_IPC_SIZE)) != 0)
--- trunk/extragear/graphics/digikam/utilities/cameragui/umscamera.cpp #548533:548534
@@ -41,7 +41,7 @@
 
 // KDE includes.
 
-#include <ktempfile.h>
+#include <kprocess.h>
 #include <kdebug.h>
 #include <kfilemetainfo.h>
 
@@ -49,7 +49,6 @@
 
 #include "dimg.h"
 #include "dmetadata.h"
-#include "dcraw_parse.h"
 #include "umscamera.h"
 
 namespace Digikam
@@ -192,23 +191,52 @@
         }
     }
 
-    // In 4th we trying to get thumbnail from RAW files using dcraw parse utility.
+    // In 4th, try to extract embedded thumbnail using dcraw with options:
+    // -c : write to stdout
+    // -e : Extract the camera-generated thumbnail, not the raw image (JPEG or a PPM file).
+    // Note : this code require at least dcraw version 8.21
 
-    KTempFile thumbFile(QString::null, "camerarawthumb");
-    thumbFile.setAutoDelete(true);
-    DcrawParse rawFileParser;
-  
-    if (thumbFile.status() == 0)
+    QCString command  = "dcraw -c -e ";
+    command += QFile::encodeName( KProcess::quote( folder + "/" + itemName ) );
+    kdDebug() << "Running dcraw command " << command << endl;
+
+    FILE* f = popen( command.data(), "r" );
+
+    if ( !f )
+        return false;
+
+    QByteArray imgData;
+    const int  MAX_IPC_SIZE = (1024*32);
+    char       buffer[MAX_IPC_SIZE];
+    QFile      file;
+    Q_LONG     len;
+
+    file.open( IO_ReadOnly,  f );
+
+    while ((len = file.readBlock(buffer, MAX_IPC_SIZE)) != 0)
     {
-        if (rawFileParser.getThumbnail(QFile::encodeName(folder + "/" + itemName),
-                                       QFile::encodeName(thumbFile.name())) == 0)
+        if ( len == -1 )
         {
-            thumbnail.load(thumbFile.name());
-            if (!thumbnail.isNull())
-                return true;
+            file.close();
+            return false;
         }
+        else
+        {
+            int oldSize = imgData.size();
+            imgData.resize( imgData.size() + len );
+            memcpy(imgData.data()+oldSize, buffer, len);
+        }
     }
 
+    file.close();
+    pclose( f );
+
+    if ( !imgData.isEmpty() )
+    {
+        if (thumbnail.loadFromData( imgData ))
+            return true;
+    }
+
     // Finaly, we trying to get thumbnail using DImg API.
 
     DImg dimgThumb(QFile::encodeName(folder + "/" + itemName));



More information about the Digikam-devel mailing list