File indexing completed on 2025-01-19 03:57:41
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam 0004 * 0005 * Date : 2020-08-23 0006 * Description : Convert images format to PNG 0007 * 0008 * SPDX-FileCopyrightText: 2020 by Nghia Duong <minhnghiaduong997 at gmail dot com> 0009 * 0010 * SPDX-License-Identifier: GPL-2.0-or-later 0011 * 0012 * ============================================================ */ 0013 0014 // Qt includes 0015 0016 #include <QCoreApplication> 0017 #include <QCommandLineParser> 0018 #include <QDir> 0019 #include <QImage> 0020 #include <QElapsedTimer> 0021 0022 // Local includes 0023 0024 #include "digikam_debug.h" 0025 0026 QCommandLineParser* parseOptions(const QCoreApplication& app) 0027 { 0028 QCommandLineParser* const parser = new QCommandLineParser(); 0029 parser->addOption(QCommandLineOption(QLatin1String("source"), QLatin1String("source folder"), QLatin1String("path relative to original data folder"))); 0030 parser->addOption(QCommandLineOption(QLatin1String("destination"), QLatin1String("destination location"), QLatin1String("path relative to result data folder"))); 0031 parser->addHelpOption(); 0032 parser->process(app); 0033 0034 return parser; 0035 } 0036 0037 int main(int argc, char** argv) 0038 { 0039 QCoreApplication app(argc, argv); 0040 QCommandLineParser* const parser = parseOptions(app); 0041 0042 if (!parser->isSet(QLatin1String("source")) && 0043 !parser->isSet(QLatin1String("destination"))) 0044 { 0045 qCWarning(DIGIKAM_TESTS_LOG) << "Folders are not set !!!"; 0046 0047 return 1; 0048 } 0049 0050 QDir source(parser->value(QLatin1String("source"))); 0051 QDir destination(parser->value(QLatin1String("destination"))); 0052 0053 if (! source.exists()) 0054 { 0055 return 1; 0056 } 0057 0058 QFileInfoList subDirs = source.entryInfoList(QDir::NoDotAndDotDot | QDir::Dirs, QDir::Name); 0059 0060 QElapsedTimer timer; 0061 timer.start(); 0062 0063 for (int i = 0 ; i < subDirs.size() ; ++i) 0064 { 0065 QDir subDir(subDirs[i].absoluteFilePath()); 0066 0067 QString path = destination.absolutePath() + QLatin1String("/") + subDir.dirName(); 0068 0069 destination.mkpath(path); 0070 0071 QFileInfoList filesInfo = subDir.entryInfoList(QDir::Files | QDir::Readable); 0072 0073 for (int j = 0; j < filesInfo.size(); ++j) 0074 { 0075 QImage img(filesInfo[j].absoluteFilePath()); 0076 0077 img.save(path + 0078 QLatin1String("/") + 0079 subDir.dirName() + 0080 QLatin1String("_") + 0081 QString::number(j) + 0082 QLatin1String(".png"), 0083 "PNG"); 0084 } 0085 } 0086 0087 return 0; 0088 }