diff --git a/imageringlist.cpp b/imageringlist.cpp index 5dc6402..7f36724 100644 --- a/imageringlist.cpp +++ b/imageringlist.cpp @@ -1,56 +1,16 @@ #include "imageringlist.h" #include #include -#include -#include +#include "loadrunable.h" using namespace std; const int DEFAULT_WIDTH = 3; -class LoadRunable : public QRunnable -{ - QString m_file; - QObject *m_receiver; -public: - LoadRunable(const QString &file, QObject *receiver) : - m_file(file), - m_receiver(receiver) - { - } - void run() - { - if(m_file.endsWith(".CR2", Qt::CaseInsensitive)) - { - LibRaw raw; - raw.open_file(m_file.toLocal8Bit().data()); - raw.imgdata.params.half_size = true; - raw.imgdata.params.use_camera_wb = true; - raw.imgdata.params.user_flip = 0; - raw.unpack(); - raw.dcraw_process(); - libraw_processed_image_t *rawImg = raw.dcraw_make_mem_image(); - QImage img(rawImg->width, rawImg->height, QImage::Format_RGB888); - qDebug() << rawImg->width << img.width()*3 << img.scanLine(1)-img.scanLine(0); - uint scanLine = rawImg->width*rawImg->colors; - for(uint i=0; iheight; i++) - { - memcpy(img.scanLine(i), rawImg->data+(i*scanLine), scanLine); - } - raw.dcraw_clear_mem(rawImg); - QMetaObject::invokeMethod(m_receiver, "imageLoaded", Qt::QueuedConnection, Q_ARG(QImage, img)); - } - else - { - QImage img(m_file); - QMetaObject::invokeMethod(m_receiver, "imageLoaded", Qt::QueuedConnection, Q_ARG(QImage, img)); - } - } -}; - Image::Image(const QString name) : m_loading(false), m_released(true), + m_current(false), m_name(name) { } @@ -71,6 +31,7 @@ void Image::release() { m_pixmap = QPixmap(); m_released = true; + m_loading = false; } QString Image::name() const @@ -83,6 +44,11 @@ QPixmap Image::pixmap() const return m_pixmap; } +bool Image::isCurrent() const +{ + return !m_released; +} + void Image::imageLoaded(QImage img) { m_loading = false; diff --git a/imageringlist.h b/imageringlist.h index 96f93c9..fffed21 100644 --- a/imageringlist.h +++ b/imageringlist.h @@ -12,6 +12,7 @@ class Image : public QObject Q_OBJECT bool m_loading; bool m_released; + bool m_current; QPixmap m_pixmap; QString m_name; public: @@ -20,6 +21,7 @@ public: void release(); QString name() const; QPixmap pixmap() const; + bool isCurrent() const; signals: void pixmapLoaded(Image *ptr); protected slots: diff --git a/imageselector.pro b/imageselector.pro index 39ade6a..7e8070f 100644 --- a/imageselector.pro +++ b/imageselector.pro @@ -19,9 +19,11 @@ SOURCES += main.cpp\ mainwindow.cpp \ imagescrollarea.cpp \ imageringlist.cpp \ - database.cpp + database.cpp \ + loadrunable.cpp HEADERS += mainwindow.h \ imagescrollarea.h \ imageringlist.h \ - database.h + database.h \ + loadrunable.h diff --git a/loadrunable.cpp b/loadrunable.cpp new file mode 100644 index 0000000..f976ee3 --- /dev/null +++ b/loadrunable.cpp @@ -0,0 +1,43 @@ +#include "loadrunable.h" +#include "imageringlist.h" +#include + +LoadRunable::LoadRunable(const QString &file, Image *receiver) : + m_file(file), + m_receiver(receiver) +{ +} + +void LoadRunable::run() +{ + if(!m_receiver->isCurrent()) + { + return; + } + + if(m_file.endsWith(".CR2", Qt::CaseInsensitive)) + { + LibRaw raw; + raw.open_file(m_file.toLocal8Bit().data()); + raw.imgdata.params.half_size = true; + raw.imgdata.params.use_camera_wb = true; + raw.imgdata.params.user_flip = 0; + raw.unpack(); + raw.dcraw_process(); + libraw_processed_image_t *rawImg = raw.dcraw_make_mem_image(); + QImage img(rawImg->width, rawImg->height, QImage::Format_RGB888); + + uint scanLine = rawImg->width*rawImg->colors; + for(uint i=0; iheight; i++) + { + memcpy(img.scanLine(i), rawImg->data+(i*scanLine), scanLine); + } + raw.dcraw_clear_mem(rawImg); + QMetaObject::invokeMethod(m_receiver, "imageLoaded", Qt::QueuedConnection, Q_ARG(QImage, img)); + } + else + { + QImage img(m_file); + QMetaObject::invokeMethod(m_receiver, "imageLoaded", Qt::QueuedConnection, Q_ARG(QImage, img)); + } +} diff --git a/loadrunable.h b/loadrunable.h new file mode 100644 index 0000000..315cbcb --- /dev/null +++ b/loadrunable.h @@ -0,0 +1,18 @@ +#ifndef LOADRUNABLE_H +#define LOADRUNABLE_H + +#include +#include + +class Image; + +class LoadRunable : public QRunnable +{ + QString m_file; + Image *m_receiver; +public: + LoadRunable(const QString &file, Image *receiver); + void run(); +}; + +#endif // LOADRUNABLE_H