1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2012-10-23
7  * Description : a command line tool to test DImg image loader
8  *
9  * Copyright (C) 2012-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * ============================================================ */
22 
23 #include "loadsavethread_cli.h"
24 
25 // Qt includes
26 
27 #include <QFileInfo>
28 
29 // Local includes
30 
31 #include "digikam_debug.h"
32 #include "metaengine.h"
33 #include "dimg.h"
34 #include "drawdecoding.h"
35 
LoadSaveThreadTest(int & argc,char ** argv)36 LoadSaveThreadTest::LoadSaveThreadTest(int& argc, char** argv)
37     : QApplication(argc, argv)
38 {
39     qRegisterMetaType<LoadingDescription>("LoadingDescription");
40     qRegisterMetaType<DImg>("DImg");
41 
42     m_thread = new LoadSaveThread;
43 
44     connect( m_thread, SIGNAL(signalImageLoaded(LoadingDescription,DImg)),
45              this, SLOT(slotImageLoaded(LoadingDescription,DImg)) );
46 
47     connect( m_thread, SIGNAL(signalImageSaved(QString,bool)),
48              this, SLOT(slotImageSaved(QString,bool)) );
49 
50     connect( m_thread, SIGNAL(signalLoadingProgress(LoadingDescription,float)),
51              this, SLOT(slotLoadingProgress(LoadingDescription,float)) );
52 
53     connect( m_thread, SIGNAL(signalSavingProgress(QString,float)),
54              this, SLOT(slotSavingProgress(QString,float)) );
55 
56     DRawDecoderSettings settings;
57     settings.halfSizeColorImage    = false;
58     settings.sixteenBitsImage      = false;
59     settings.RGBInterpolate4Colors = false;
60     settings.RAWQuality            = DRawDecoderSettings::BILINEAR;
61 
62     LoadingDescription desc(QString::fromUtf8(argv[1]), DRawDecoding(settings));
63 
64     m_thread->load(desc);
65 }
66 
slotLoadingProgress(const LoadingDescription & desc,float p)67 void LoadSaveThreadTest::slotLoadingProgress(const LoadingDescription& desc, float p)
68 {
69     QFileInfo fi(desc.filePath);
70     qCDebug(DIGIKAM_TESTS_LOG) << "Loading " << fi.baseName() << " : " << p << " %";
71 }
72 
slotImageLoaded(const LoadingDescription & desc,const DImg & img)73 void LoadSaveThreadTest::slotImageLoaded(const LoadingDescription& desc, const DImg& img)
74 {
75     QFileInfo fi(desc.filePath);
76     qCDebug(DIGIKAM_TESTS_LOG) << "Image " << fi.baseName() << " loaded";
77 
78     QString outFilePath(fi.baseName() + QString::fromUtf8(".out.png"));
79     DImg image = img;
80     m_thread->save(image, outFilePath, QLatin1String("PNG"));
81 }
82 
slotSavingProgress(const QString & filePath,float p)83 void LoadSaveThreadTest::slotSavingProgress(const QString& filePath, float p)
84 {
85     QFileInfo fi(filePath);
86     qCDebug(DIGIKAM_TESTS_LOG) << "Saving " << fi.baseName() << " : " << p << " %";
87 }
88 
slotImageSaved(const QString & filePath,bool b)89 void LoadSaveThreadTest::slotImageSaved(const QString& filePath, bool b)
90 {
91     QFileInfo fi(filePath);
92     qCDebug(DIGIKAM_TESTS_LOG) << fi.baseName() << " saved : " << (b ? "ok" : "pb");
93 
94     exit();
95 }
96 
97 // ------------------------------------------------------------------------------------------
98 
main(int argc,char ** argv)99 int main(int argc, char** argv)
100 {
101     if (argc != 2)
102     {
103         qCDebug(DIGIKAM_TESTS_LOG) << "loadsavethreadtest - test DImg image loader with multithreading";
104         qCDebug(DIGIKAM_TESTS_LOG) << "Usage: <image>";
105         return -1;
106     }
107 
108     MetaEngine::initializeExiv2();
109 
110     LoadSaveThreadTest app(argc, argv);
111     int ret = app.exec();
112 
113     return ret;
114 }
115