[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/graphics/darkroom/src
From: Cyrille Berger <cyb () lepi ! org>
Date: 2008-07-23 7:46:55
Message-ID: 1216799215.587394.7036.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 836862 by berger:
multithreading of the export
M +1 -1 CMakeLists.txt
A JobExport.cpp darkroomview.cpp#836834 [License: BSD]
A JobExport.h darkroomview.h#836834 [License: BSD]
M +1 -2 ListRawFileModel.cpp
M +4 -0 RawImageInfo.cpp
M +2 -0 RawImageInfo.h
M +7 -2 darkroom.cpp
M +11 -168 darkroomview.cpp
M +3 -3 darkroomview.h
--- trunk/playground/graphics/darkroom/src/CMakeLists.txt #836861:836862
@@ -5,7 +5,7 @@
ListRawFileModel.cpp
RawImageInfo.cpp
JobPreview.cpp
-# JobExport.cpp
+ JobExport.cpp
)
--- trunk/playground/graphics/darkroom/src/ListRawFileModel.cpp #836861:836862
@@ -44,7 +44,6 @@
{
d->infos = _infos;
d->dataMapper = new QSignalMapper( this );
- int count = 0;
for(int i = 0; i < _infos.size(); ++i)
{
connect(_infos[i], SIGNAL(previewChanged()), d->dataMapper, SLOT(map()));
@@ -79,7 +78,7 @@
}
case 100:
{
- return d->infos[ index.row() ]->fileInfo().absoluteFilePath();
+ return qVariantFromValue(d->infos[ index.row() ]);
}
}
return QVariant();
--- trunk/playground/graphics/darkroom/src/RawImageInfo.cpp #836861:836862
@@ -26,6 +26,7 @@
#include "RawImageInfo.h"
#include <QFileInfo>
+#include <QMutex>
#include <QPixmap>
#include <KIcon>
#include "JobPreview.h"
@@ -34,6 +35,7 @@
struct RawImageInfo::Private {
QFileInfo fileInfo;
QPixmap pixmap;
+ QMutex lock;
};
RawImageInfo::RawImageInfo(const QFileInfo& fileInfo ) : d(new Private)
@@ -56,10 +58,12 @@
const QPixmap& RawImageInfo::preview()
{
+ QMutexLocker locker(&d->lock);
return d->pixmap;
}
void RawImageInfo::setPreview(const QPixmap& pixmap)
{
+ QMutexLocker locker(&d->lock);
d->pixmap = pixmap;
emit( previewChanged( ) );
}
--- trunk/playground/graphics/darkroom/src/RawImageInfo.h #836861:836862
@@ -27,6 +27,7 @@
#define _RAW_IMAGE_INFO_H_
#include <QObject>
+#include <QVariant>
class QFileInfo;
class QPixmap;
@@ -46,4 +47,5 @@
Private* const d;
};
+Q_DECLARE_METATYPE ( RawImageInfo* );
#endif
--- trunk/playground/graphics/darkroom/src/darkroom.cpp #836861:836862
@@ -31,6 +31,7 @@
#include <QPainter>
#include <QPrinter>
+#include <KDebug>
#include <kconfigdialog.h>
#include <kstatusbar.h>
@@ -44,6 +45,8 @@
#include <libkdcraw/dcrawsettingswidget.h>
+#include <RawImageInfo.h>
+
Darkroom::Darkroom()
: KXmlGuiWindow(),
m_view(new DarkroomView(this))
@@ -120,8 +123,10 @@
void Darkroom::rawFileActivated ( const QModelIndex & index )
{
- QString fpo = m_fileListView->model()->data( index, 100).toString();
- m_view->openFile( fpo );
+ QVariant variant = m_fileListView->model()->data( index, 100);
+ RawImageInfo* fpo = variant.value<RawImageInfo*>();
+ kDebug() << variant << " " << fpo << " " << variant.value<RawImageInfo*>();
+ m_view->setRawImageInfo( fpo );
}
--- trunk/playground/graphics/darkroom/src/darkroomview.cpp #836861:836862
@@ -39,15 +39,17 @@
#include <libkdcraw/rawfiles.h>
#include <libkdcraw/dcrawsettingswidget.h>
-#include <libkexiv2/kexiv2.h>
-
#include <RawImageInfo.h>
#include "ListRawFileModel.h"
+#include <threadweaver/ThreadWeaver.h>
+
+#include <JobExport.h>
+
using namespace KDcrawIface;
-DarkroomView::DarkroomView(QWidget *) : m_dcraw(new KDcraw ), m_rawSettings(0), \
m_is16BitsDepth(true), m_fileListView(0) +DarkroomView::DarkroomView(QWidget *) : \
m_dcraw(new KDcraw ), m_rawSettings(0), m_is16BitsDepth(true), m_fileListView(0), \
m_currentRawFile(0) {
ui_darkroomview_base.setupUi(this);
setAutoFillBackground(true);
@@ -67,8 +69,7 @@
QString file = KFileDialog::getOpenFileName( KUrl(), raw_file_extentions );
if( not file.isEmpty() and not file.isNull() )
{
- m_currentRawFileName = file;
- m_currentDirectory = "";
+ m_currentRawFile = new RawImageInfo( QFileInfo( file ) );
m_fileListView->setEnabled( false );
updatePreview();
}
@@ -79,7 +80,6 @@
QString directoryName = KFileDialog::getExistingDirectory();
if( not directoryName.isEmpty() and not directoryName.isNull())
{
- m_currentDirectory = directoryName;
m_fileListView->setEnabled( true );
m_index = 0;
QDir directory( directoryName );
@@ -93,96 +93,9 @@
}
}
-#define TELL_ERROR( msg ) \
- KMessageBox::error( this, msg, i18n("An error has occured while saving.")); \
- return;
-
-#define COND_TELL_ERROR( cond, msg ) \
- if( not (cond ) ) \
- { \
- TELL_ERROR( msg ); \
- }
-
-long formatStringList(char *string, const size_t length, const char *format, va_list \
operands)
-{
- int n = vsnprintf(string, length, format, operands);
-
- if (n < 0)
- string[length-1] = '\0';
-
- return((long) n);
-}
-
-long formatString(char *string, const size_t length, const char *format,...)
-{
- long n;
-
- va_list operands;
-
- va_start(operands,format);
- n = (long) formatStringList(string, length, format, operands);
- va_end(operands);
- return(n);
-}
-
-void writeRawProfile(png_struct *ping, png_info *ping_info, QString profile_type, \
QByteArray profile_data)
-{
-
- png_textp text;
-
- png_uint_32 allocated_length, description_length;
-
- const uchar hex[16] = \
{'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
-
- kDebug() << "Writing Raw profile: type=" << profile_type << ", length=" << \
profile_data.length() << endl;
-
- text = (png_textp) png_malloc(ping, (png_uint_32) \
sizeof(png_text));
- description_length = profile_type.length();
- allocated_length = (png_uint_32) (profile_data.length()*2 + \
(profile_data.length() >> 5) + 20 + description_length);
-
- text[0].text = (png_charp) png_malloc(ping, allocated_length);
-
- QString key = "Raw profile type " + profile_type.toLatin1();
- QByteArray keyData = key.toLatin1();
- text[0].key = keyData.data();
-
- uchar* sp = (uchar*)profile_data.data();
- png_charp dp = text[0].text;
- *dp++='\n';
-
- memcpy(dp, (const char *) profile_type.toLatin1().data(), \
profile_type.length());
-
- dp += description_length;
- *dp++='\n';
-
- formatString(dp, allocated_length-strlen(text[0].text), "%8lu ", \
profile_data.length());
-
- dp += 8;
-
- for(long i=0; i < (long) profile_data.length(); i++)
- {
- if (i%36 == 0)
- *dp++='\n';
-
- *(dp++)=(char) hex[((*sp >> 4) & 0x0f)];
- *(dp++)=(char) hex[((*sp++ ) & 0x0f)];
- }
-
- *dp++='\n';
- *dp='\0';
- text[0].text_length = (png_size_t) (dp-text[0].text);
- text[0].compression = -1;
-
- if (text[0].text_length <= allocated_length)
- png_set_text(ping, ping_info,text, 1);
-
- png_free(ping, text[0].text);
- png_free(ping, text);
-}
-
void DarkroomView::fileSaveAs()
{
- QFileInfo fi(m_currentRawFileName);
+ QFileInfo fi = m_currentRawFile->fileInfo();
QString file = KFileDialog::getSaveFileName( KUrl(fi.baseName() + ".png"), "*.png" \
); if( not file.isEmpty() and not file.isNull() )
@@ -194,88 +107,18 @@
return;
}
}
- QByteArray imageData;
- RawDecodingSettings settings = rawDecodingSettings();
- int width, height, rgbmax;
- if( m_dcraw->decodeRAWImage( m_currentRawFileName, settings, imageData, width, \
height, rgbmax) )
- {
- // Now, do the PNG save dance
- FILE *fp = fopen(file.toLatin1(), "wb");
- COND_TELL_ERROR( fp, "Can't open file: " + file);
-
- png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
- COND_TELL_ERROR( png_ptr, "Can't initialize libpng." );
-
- // Create info structure
- png_infop info_ptr = png_create_info_struct(png_ptr);
- if(not info_ptr)
- {
- png_destroy_write_struct(&png_ptr, 0);
- fclose(fp);
- TELL_ERROR( "Can't initialize libpng." );
- }
-
- // Set error handler
- if (setjmp(png_jmpbuf(png_ptr)))
- {
- png_destroy_write_struct(&png_ptr, &info_ptr);
- fclose(fp);
- TELL_ERROR( "Can't initialize libpng." );
- }
-
- int bit_depth = settings.sixteenBitsImage ? 16 : 8;
- int color_type = PNG_COLOR_TYPE_RGB;
-
- png_set_IHDR( png_ptr, info_ptr, width, height, bit_depth, color_type, \
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, \
PNG_FILTER_TYPE_DEFAULT);
-
- png_init_io(png_ptr, fp );
-
- // Save metadata
-
- KExiv2Iface::KExiv2 exiv2;
- if(exiv2.load( m_currentRawFileName ))
- {
- // Save exif
- if(exiv2.hasExif()) {
- QByteArray exifArray = exiv2.getExif(true);
- writeRawProfile(png_ptr, info_ptr, "exif", exifArray);
- }
- // Save IPTC
- if(exiv2.hasIptc()) {
- QByteArray exifArray = exiv2.getIptc(true);
- writeRawProfile(png_ptr, info_ptr, "iptc", exifArray);
- }
- // Save XMP
- if(exiv2.hasXmp()) {
- QByteArray exifArray = exiv2.getXmp();
- writeRawProfile(png_ptr, info_ptr, "xmp", exifArray);
- }
- }
-
- png_write_info(png_ptr, info_ptr);
-
- // Save data
- int lineWidth = ( settings.sixteenBitsImage ? sizeof( quint16 ) : sizeof( \
quint8 ) ) * 3 * width;
-
- for( int y = 0; y < height; ++y)
- {
- png_write_row(png_ptr, (png_byte*)(imageData.data() + y * lineWidth ));
- }
-
- png_write_end(png_ptr, info_ptr);
- png_destroy_write_struct(&png_ptr, &info_ptr);
- fclose(fp);
-
- }
+ ThreadWeaver::Weaver::instance()->enqueue( new JobExport( m_currentRawFile, \
file, rawDecodingSettings() ) ); }
}
void DarkroomView::updatePreview()
{
+ kDebug() << "updatePreview " << m_currentRawFile;
+ if( not m_currentRawFile) return;
QByteArray imageData;
RawDecodingSettings settings = rawDecodingSettings();
int width, height, rgbmax;
- m_dcraw->decodeHalfRAWImage( m_currentRawFileName, settings, imageData, width, \
height, rgbmax); + m_dcraw->decodeHalfRAWImage( \
m_currentRawFile->fileInfo().absoluteFilePath(), settings, imageData, width, height, \
rgbmax); QImage image( width, height, QImage::Format_RGB32);
for( int y = 0; y < height; ++y)
{
--- trunk/playground/graphics/darkroom/src/darkroomview.h #836861:836862
@@ -33,6 +33,7 @@
class QListView;
class QPainter;
class KUrl;
+class RawImageInfo;
namespace KDcrawIface {
class KDcraw;
@@ -67,7 +68,7 @@
* Destructor
*/
virtual ~DarkroomView();
- void openFile( const QString& name ) { m_currentRawFileName = name; \
updatePreview(); } + void setRawImageInfo( RawImageInfo* v) { m_currentRawFile = \
v; updatePreview(); } public slots:
void fileOpen();
void fileSaveAs();
@@ -94,8 +95,7 @@
KDcrawIface::RawDecodingSettings rawDecodingSettings();
private:
void updateBatchProcessBox();
- QString m_currentRawFileName;
- QString m_currentDirectory;
+ RawImageInfo* m_currentRawFile;
QListView* m_fileListView;
int m_index;
KDcrawIface::KDcraw* m_dcraw;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic