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 "createpreviewtask.h" 0016 0017 // Qt includes 0018 0019 #include <QFile> 0020 0021 // KDE includes 0022 0023 #include <klocalizedstring.h> 0024 0025 // Local includes 0026 0027 #include "digikam_debug.h" 0028 0029 namespace DigikamGenericPanoramaPlugin 0030 { 0031 0032 CreatePreviewTask::CreatePreviewTask(const QString& workDirPath, 0033 QSharedPointer<const PTOType> inputPTO, 0034 QUrl& previewPtoUrl, 0035 const PanoramaItemUrlsMap& preProcessedUrlsMap) 0036 : PanoTask(PANO_CREATEMKPREVIEW, workDirPath), 0037 previewPtoUrl(previewPtoUrl), 0038 ptoData(inputPTO), 0039 preProcessedUrlsMap(preProcessedUrlsMap) 0040 { 0041 } 0042 0043 CreatePreviewTask::~CreatePreviewTask() 0044 { 0045 } 0046 0047 void CreatePreviewTask::run(ThreadWeaver::JobPointer, ThreadWeaver::Thread*) 0048 { 0049 PTOType data(*ptoData); 0050 0051 if (data.images.size() != preProcessedUrlsMap.size()) 0052 { 0053 errString = i18n("Project file parsing failed."); 0054 qCDebug(DIGIKAM_DPLUGIN_GENERIC_LOG) << "Missing parsing data!"; 0055 successFlag = false; 0056 return; 0057 } 0058 0059 m_meta.load(preProcessedUrlsMap.begin().value().preprocessedUrl.toLocalFile()); 0060 double wIn = (double)m_meta.getPixelSize().width(); 0061 0062 m_meta.load(preProcessedUrlsMap.begin().value().previewUrl.toLocalFile()); 0063 double wOut = (double)m_meta.getPixelSize().width(); 0064 0065 double scalingFactor = wOut / wIn; 0066 0067 data.project.fileFormat.fileType = PTOType::Project::FileFormat::JPEG; 0068 data.project.fileFormat.quality = 90; 0069 data.project.size.setHeight(data.project.size.height() * scalingFactor); 0070 data.project.size.setWidth(data.project.size.width() * scalingFactor); 0071 data.project.crop = QRect(); 0072 0073 for (auto& image : data.images) 0074 { 0075 QUrl imgUrl = QUrl::fromLocalFile(image.fileName); 0076 0077 PanoramaItemUrlsMap::const_iterator it; 0078 const PanoramaItemUrlsMap* const ppum = &preProcessedUrlsMap; 0079 0080 for (it = ppum->constBegin() ; 0081 it != ppum->constEnd() && (it.value().preprocessedUrl.toLocalFile() != imgUrl.toLocalFile()) ; 0082 ++it); 0083 0084 if (it == ppum->constEnd()) 0085 { 0086 errString = i18n("Unknown input file in the project file: <filename>%1</filename>", image.fileName); 0087 qCDebug(DIGIKAM_DPLUGIN_GENERIC_LOG) << "Unknown input File in the PTO: " << image.fileName; 0088 qCDebug(DIGIKAM_DPLUGIN_GENERIC_LOG) << "IMG: " << imgUrl.toLocalFile(); 0089 successFlag = false; 0090 0091 return; 0092 } 0093 0094 image.fileName = it.value().previewUrl.toLocalFile(); 0095 m_meta.load(image.fileName); 0096 image.size = m_meta.getPixelSize(); 0097 image.optimizationParameters.clear(); 0098 } 0099 0100 // Remove unnecessary stuff 0101 0102 data.controlPoints.clear(); 0103 0104 // Add two commented line for a JPEG output 0105 0106 data.lastComments.clear(); 0107 data.lastComments << QLatin1String("#hugin_outputImageType jpg"); 0108 data.lastComments << QLatin1String("#hugin_outputJPEGQuality 90"); 0109 0110 previewPtoUrl = tmpDir; 0111 previewPtoUrl.setPath(previewPtoUrl.path() + QLatin1String("preview.pto")); 0112 data.createFile(previewPtoUrl.toLocalFile()); 0113 0114 qCDebug(DIGIKAM_DPLUGIN_GENERIC_LOG) << "Preview PTO File created: " << previewPtoUrl.fileName(); 0115 0116 successFlag = true; 0117 } 0118 0119 } // namespace DigikamGenericPanoramaPlugin