Do not load images that were already released
This commit is contained in:
+8
-42
@@ -1,56 +1,16 @@
|
|||||||
#include "imageringlist.h"
|
#include "imageringlist.h"
|
||||||
#include <QThreadPool>
|
#include <QThreadPool>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <libraw/libraw.h>
|
#include "loadrunable.h"
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
const int DEFAULT_WIDTH = 3;
|
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; i<rawImg->height; 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) :
|
Image::Image(const QString name) :
|
||||||
m_loading(false),
|
m_loading(false),
|
||||||
m_released(true),
|
m_released(true),
|
||||||
|
m_current(false),
|
||||||
m_name(name)
|
m_name(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -71,6 +31,7 @@ void Image::release()
|
|||||||
{
|
{
|
||||||
m_pixmap = QPixmap();
|
m_pixmap = QPixmap();
|
||||||
m_released = true;
|
m_released = true;
|
||||||
|
m_loading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Image::name() const
|
QString Image::name() const
|
||||||
@@ -83,6 +44,11 @@ QPixmap Image::pixmap() const
|
|||||||
return m_pixmap;
|
return m_pixmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Image::isCurrent() const
|
||||||
|
{
|
||||||
|
return !m_released;
|
||||||
|
}
|
||||||
|
|
||||||
void Image::imageLoaded(QImage img)
|
void Image::imageLoaded(QImage img)
|
||||||
{
|
{
|
||||||
m_loading = false;
|
m_loading = false;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ class Image : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
bool m_loading;
|
bool m_loading;
|
||||||
bool m_released;
|
bool m_released;
|
||||||
|
bool m_current;
|
||||||
QPixmap m_pixmap;
|
QPixmap m_pixmap;
|
||||||
QString m_name;
|
QString m_name;
|
||||||
public:
|
public:
|
||||||
@@ -20,6 +21,7 @@ public:
|
|||||||
void release();
|
void release();
|
||||||
QString name() const;
|
QString name() const;
|
||||||
QPixmap pixmap() const;
|
QPixmap pixmap() const;
|
||||||
|
bool isCurrent() const;
|
||||||
signals:
|
signals:
|
||||||
void pixmapLoaded(Image *ptr);
|
void pixmapLoaded(Image *ptr);
|
||||||
protected slots:
|
protected slots:
|
||||||
|
|||||||
+4
-2
@@ -19,9 +19,11 @@ SOURCES += main.cpp\
|
|||||||
mainwindow.cpp \
|
mainwindow.cpp \
|
||||||
imagescrollarea.cpp \
|
imagescrollarea.cpp \
|
||||||
imageringlist.cpp \
|
imageringlist.cpp \
|
||||||
database.cpp
|
database.cpp \
|
||||||
|
loadrunable.cpp
|
||||||
|
|
||||||
HEADERS += mainwindow.h \
|
HEADERS += mainwindow.h \
|
||||||
imagescrollarea.h \
|
imagescrollarea.h \
|
||||||
imageringlist.h \
|
imageringlist.h \
|
||||||
database.h
|
database.h \
|
||||||
|
loadrunable.h
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
#include "loadrunable.h"
|
||||||
|
#include "imageringlist.h"
|
||||||
|
#include <libraw/libraw.h>
|
||||||
|
|
||||||
|
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; i<rawImg->height; 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef LOADRUNABLE_H
|
||||||
|
#define LOADRUNABLE_H
|
||||||
|
|
||||||
|
#include <QRunnable>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
class Image;
|
||||||
|
|
||||||
|
class LoadRunable : public QRunnable
|
||||||
|
{
|
||||||
|
QString m_file;
|
||||||
|
Image *m_receiver;
|
||||||
|
public:
|
||||||
|
LoadRunable(const QString &file, Image *receiver);
|
||||||
|
void run();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LOADRUNABLE_H
|
||||||
Reference in New Issue
Block a user