From 55d48519c9132c6d213f2e733bcd806e3b1f05fb Mon Sep 17 00:00:00 2001 From: Arno Date: Sun, 11 Oct 2015 08:16:28 +0200 Subject: Change image size calculation Use ImageMagick::Image::ping to determine the size of an image, but only if the file size is < 400kb to prevent the impression of a deadlock. --- delegates.cpp | 2 +- helper.cpp | 10 ++++------ smdirwatcher.cpp | 8 ++++++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/delegates.cpp b/delegates.cpp index 927726c..db4b6b1 100644 --- a/delegates.cpp +++ b/delegates.cpp @@ -81,7 +81,7 @@ QString SizeDelegate::displayText(const QVariant &value, const QLocale &locale) QString DurationDelegate::displayText(const QVariant &value, const QLocale &locale) const{ Q_UNUSED(locale); - if(value.toString().contains("x")){ + if(value.toString().contains("x") || value.toString() == "skipped"){ return value.toString(); } int secs = value.toFloat(); diff --git a/helper.cpp b/helper.cpp index ed1d31a..dd6bedf 100644 --- a/helper.cpp +++ b/helper.cpp @@ -308,12 +308,10 @@ namespace Helper { } QVariant picSize(const QString &path){ - QImage img(path); - if(!img.isNull()){ - QString retval = QString("%1x%2").arg(QString::number(img.width())).arg(QString::number(img.height())); - return retval; - } - return QVariant(); + Magick::Image img; + img.ping(qPrintable(path)); + QString retval = QString("%1x%2").arg(QString::number(img.columns())).arg(QString::number(img.rows())); + return retval; } PicData convertToPng(PicData data){ diff --git a/smdirwatcher.cpp b/smdirwatcher.cpp index 79bce7c..2bcaff3 100644 --- a/smdirwatcher.cpp +++ b/smdirwatcher.cpp @@ -75,8 +75,12 @@ QList SmDirWatcher::generalData(const QString &path){ QVariantMap m = Helper::ffmpegData(fi.absoluteFilePath()); data << m.value("duration") << m.value("bit_rate"); }else if(mime.startsWith("image")){ - QVariant picSize = Helper::picSize(fi.absoluteFilePath()); - data << picSize << QVariant(); + if(fi.size() > 1024*400){ //skip images bigger than 300 kb + data << "skipped" << QVariant(); + }else{ + QVariant picSize = Helper::picSize(fi.absoluteFilePath()); + data << picSize << QVariant(); + } }else{ data << QVariant() << QVariant(); } -- cgit v1.2.3-70-g09d2