[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/base/nepomuk-kde/annotation/plugins/olena
From:       Sebastian Trueg <sebastian () trueg ! de>
Date:       2009-09-17 15:58:39
Message-ID: 1253203119.190679.15290.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1024924 by trueg:

tesseract is not thread-safe. Thus, we make sure it is only used once at all times

 M  +4 -3      olenaplugin.cpp  
 M  +27 -6     olenatextextractionjob.cpp  


--- trunk/playground/base/nepomuk-kde/annotation/plugins/olena/olenaplugin.cpp \
#1024923:1024924 @@ -80,9 +80,10 @@
         connect( job, SIGNAL( result( KJob* ) ), this, SLOT( slotMimetypeJobResult( \
KJob* ) ) );  m_currentMimeTypeJob = job;
     }
-
-    // nothing to be done
-    emitFinished();
+    else {
+        // nothing to be done
+        emitFinished();
+    }
 }
 
 
--- trunk/playground/base/nepomuk-kde/annotation/plugins/olena/olenatextextractionjob.cpp \
#1024923:1024924 @@ -21,6 +21,8 @@
 #include "olenatextextractionjob.h"
 
 #include <QtCore/QThread>
+#include <QtCore/QMutex>
+#include <QtCore/QMutexLocker>
 #include <QtCore/QFile>
 
 #include <KIO/NetAccess>
@@ -37,6 +39,30 @@
 #include "obj2txt.hh"
 
 
+namespace {
+    /**
+     * Helper class to work around the fact that Tesseract is not thread-safe.
+     */
+    class ScriboHandler
+    {
+    public:
+        QString extractText( const mln::labeled_image< \
mln::image2d<mln::value::label_16> >& obj ); +
+    private:
+        QMutex m_mutex;
+    };
+
+    QString ScriboHandler::extractText( const mln::labeled_image< \
mln::image2d<mln::value::label_16> >& obj ) +    {
+        QMutexLocker lock( &m_mutex );
+        // FIXME: do not default to "fra" here but use the current locale
+        return QString::fromUtf8( scribo::text::obj2txt(obj, "fra").c_str() );
+    }
+
+    K_GLOBAL_STATIC( ScriboHandler, s_scriboHandler )
+}
+
+
 class Nepomuk::OlenaTextExtractionJob::Private : public QThread
 {
 public:
@@ -97,13 +123,8 @@
 
     kDebug() << "3";
 
-    // objects -> text string
-    // FIXME: do not default to "fra" here but use the current locale
-    std::string txt = scribo::text::obj2txt(obj, "fra");
+    m_extractedText = s_scriboHandler->extractText(obj);
 
-    kDebug() << "4";
-
-    m_extractedText = QString::fromUtf8( txt.c_str() );
     kDebug() << m_extractedText;
 }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic