File indexing completed on 2025-01-05 03:53:10

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2012-03-15
0007  * Description : a tool to create panorama by fusion of several images.
0008  *
0009  * SPDX-FileCopyrightText: 2012-2016 by Benjamin Girault <benjamin dot girault at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "optimisationtask.h"
0016 
0017 // Qt includes
0018 
0019 #include <QFile>
0020 
0021 namespace DigikamGenericPanoramaPlugin
0022 {
0023 
0024 OptimisationTask::OptimisationTask(const QString& workDirPath, const QUrl& input,
0025                                    QUrl& autoOptimiserPtoUrl, bool levelHorizon, bool gPano,
0026                                    const QString& autooptimiserPath)
0027     : CommandTask(PANO_OPTIMIZE, workDirPath, autooptimiserPath),
0028       autoOptimiserPtoUrl(autoOptimiserPtoUrl),
0029       ptoUrl(input),
0030       levelHorizon(levelHorizon),
0031       buildGPano(gPano)
0032 {
0033 }
0034 
0035 OptimisationTask::~OptimisationTask()
0036 {
0037 }
0038 
0039 void OptimisationTask::run(ThreadWeaver::JobPointer, ThreadWeaver::Thread*)
0040 {
0041     autoOptimiserPtoUrl = tmpDir;
0042     autoOptimiserPtoUrl.setPath(autoOptimiserPtoUrl.path() + QLatin1String("auto_op_pano.pto"));
0043 
0044     QStringList args;
0045     args << QLatin1String("-am");
0046 
0047     if (levelHorizon)
0048     {
0049        args << QLatin1String("-l");
0050     }
0051 
0052     // NOTE: This parameter changes the projection type
0053     // See also Bug 346053 and Bug 416492
0054 
0055     Q_UNUSED(buildGPano);
0056 /*
0057     if (buildGPano)
0058     {
0059         args << QLatin1String("-s");
0060     }
0061 */
0062     args << QLatin1String("-o");
0063     args << autoOptimiserPtoUrl.toLocalFile();
0064     args << ptoUrl.toLocalFile();
0065 
0066     runProcess(args);
0067 
0068     // AutoOptimiser does not return an error code when something went wrong...
0069 
0070     QFile ptoOutput(autoOptimiserPtoUrl.toLocalFile());
0071 
0072     if (!ptoOutput.exists())
0073     {
0074         successFlag = false;
0075         errString = getProcessError();
0076     }
0077 
0078     printDebug(QLatin1String("autooptimiser"));
0079 }
0080 
0081 } // namespace DigikamGenericPanoramaPlugin