Do not load images that were already released

This commit is contained in:
2019-08-21 16:32:14 +02:00
parent 50dcd4b902
commit f0e4923a68
5 changed files with 75 additions and 44 deletions
+8 -42
View File
@@ -1,56 +1,16 @@
#include "imageringlist.h"
#include <QThreadPool>
#include <QDir>
#include <libraw/libraw.h>
#include <QDebug>
#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; 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) :
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;