summaryrefslogtreecommitdiffstats
path: root/helper.cpp
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2015-07-18 08:52:46 +0200
committerArno <arno@disconnect.de>2015-07-18 08:52:46 +0200
commitb3ccbde0d3e540453b80709002cae0630172f1dc (patch)
treeb810c54996fde7f6f57b0ed8f31532c5ac8e82cc /helper.cpp
parenta53cf905aed8cc14c9120ad03b6f03fe1373fc2d (diff)
downloadSheMov-b3ccbde0d3e540453b80709002cae0630172f1dc.tar.gz
SheMov-b3ccbde0d3e540453b80709002cae0630172f1dc.tar.bz2
SheMov-b3ccbde0d3e540453b80709002cae0630172f1dc.zip
Automatically convert invalid jpg pics
Well, seems that's Qt's ImageReader got pickier regarding jpeg-files. If the resulting QPixmap is null and void, try to convert them to png. This introduces a new dependency to ImageMagic++. I don't like it, but it works, kinda... I saw random crashes while testing...
Diffstat (limited to 'helper.cpp')
-rw-r--r--helper.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/helper.cpp b/helper.cpp
index 3a1e780..ed1d31a 100644
--- a/helper.cpp
+++ b/helper.cpp
@@ -26,6 +26,9 @@
#include <QJsonObject>
#include <QPainter>
#include <QDir>
+#include <QRegularExpression>
+#include <QSqlDatabase>
+#include <QSqlQuery>
#include <stdio.h>
@@ -313,6 +316,54 @@ namespace Helper {
return QVariant();
}
+ PicData convertToPng(PicData data){
+ if(data.at(2) != "image/jpeg"){
+ return PicData();
+ }
+ PicData retval;
+ QString newFn = data.at(0).toString();
+ newFn.replace(QRegularExpression("(jpg|jpeg)$", QRegularExpression::CaseInsensitiveOption), "png");
+ Magick::Image img;
+ img.read(data.at(3).toByteArray().data());
+ QTemporaryFile outFile("shemovconvertXXXXXX.png");
+ if(outFile.open()){
+ try {
+ img.write(outFile.fileName().toStdString());
+ }
+ catch(Magick::Exception &e) {
+ return retval;
+ }
+ outFile.rename(newFn);
+ QString newMd5 = md5Sum(outFile.fileName());
+ QString dest = moveToArchive(outFile.fileName(), newMd5, true);
+ QFileInfo destFi(dest);
+ if(!destFi.exists()){
+ return PicData();
+ }
+ QString mt = mimeType(dest);
+ retval = data;
+ retval[0] = newFn; //Filename
+ retval[1] = destFi.size(); //Size
+ retval[2] = mt; //Mime-Type
+ retval[3] = dest; //Full path
+ retval[6] = newMd5; //md5sum
+ QSqlDatabase db = QSqlDatabase::database("treedb");
+ int id = data.at(4).toInt();
+ QSqlQuery q(db);
+ q.prepare("UPDATE pics SET tfilename = :fn, cmd5sum = :md5, isize = :size, tformat = :format WHERE ipicsid = :id");
+ q.bindValue(":fn", newFn);
+ q.bindValue(":md5", newMd5);
+ q.bindValue(":size", destFi.size());
+ q.bindValue(":format", mt);
+ q.bindValue(":id", id);
+
+ if(q.exec()){
+ return retval;
+ }
+ }
+ return PicData();
+ }
+
Duration::Duration() : mHours(0), mMinutes(0), mSeconds(0) {}
Duration::Duration(qint64 seconds){