File indexing completed on 2025-01-05 03:58:16
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2008-15-09 0007 * Description : a command line tool to convert RAW file to PNG 0008 * 0009 * SPDX-FileCopyrightText: 2008-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 // Qt includes 0016 0017 #include <QString> 0018 #include <QFile> 0019 #include <QFileInfo> 0020 #include <QPointer> 0021 #include <QScopedPointer> 0022 0023 // Local includes 0024 0025 #include "digikam_debug.h" 0026 #include "drawdecoder.h" 0027 #include "drawdecodersettings.h" 0028 0029 using namespace Digikam; 0030 0031 int main(int argc, char** argv) 0032 { 0033 if (argc != 2) 0034 { 0035 qCDebug(DIGIKAM_TESTS_LOG) << "raw2png - RAW Camera Image to PNG Converter"; 0036 qCDebug(DIGIKAM_TESTS_LOG) << "Usage: <rawfile>"; 0037 return -1; 0038 } 0039 0040 QString filePath = QString::fromLatin1(argv[1]); 0041 QFileInfo input(filePath); 0042 QString previewFilePath(input.baseName() + QString::QString::fromLatin1(".preview.png")); 0043 QFileInfo previewOutput(previewFilePath); 0044 QString halfFilePath(input.baseName() + QString::fromLatin1(".half.png")); 0045 QFileInfo halfOutput(halfFilePath); 0046 QString fullFilePath(input.baseName() + QString::fromLatin1(".full.png")); 0047 QFileInfo fullOutput(fullFilePath); 0048 QImage image; 0049 QScopedPointer<DRawInfo> identify(new DRawInfo); 0050 0051 // ----------------------------------------------------------- 0052 0053 qCDebug(DIGIKAM_TESTS_LOG) << "raw2png: Identify RAW image from " << input.fileName(); 0054 0055 QPointer<DRawDecoder> rawProcessor(new DRawDecoder); 0056 0057 if (!rawProcessor->rawFileIdentify(*identify, filePath)) 0058 { 0059 qCDebug(DIGIKAM_TESTS_LOG) << "raw2png: Identifying RAW image failed. Aborted..."; 0060 return -1; 0061 } 0062 0063 int width = identify->imageSize.width(); 0064 int height = identify->imageSize.height(); 0065 0066 qCDebug(DIGIKAM_TESTS_LOG) << "raw2png: Raw image info:"; 0067 qCDebug(DIGIKAM_TESTS_LOG) << "--- Date: " << identify->dateTime.toString(Qt::ISODate); 0068 qCDebug(DIGIKAM_TESTS_LOG) << "--- Make: " << identify->make; 0069 qCDebug(DIGIKAM_TESTS_LOG) << "--- Model: " << identify->model; 0070 qCDebug(DIGIKAM_TESTS_LOG) << "--- Size: " << width << "x" << height; 0071 qCDebug(DIGIKAM_TESTS_LOG) << "--- Filter: " << identify->filterPattern; 0072 qCDebug(DIGIKAM_TESTS_LOG) << "--- Colors: " << identify->rawColors; 0073 0074 // ----------------------------------------------------------- 0075 0076 qCDebug(DIGIKAM_TESTS_LOG) << "raw2png: Loading RAW image preview"; 0077 0078 if (!rawProcessor->loadRawPreview(image, filePath)) 0079 { 0080 qCDebug(DIGIKAM_TESTS_LOG) << "raw2png: Loading RAW image preview failed. Aborted..."; 0081 return -1; 0082 } 0083 0084 qCDebug(DIGIKAM_TESTS_LOG) << "raw2png: Saving preview image to " 0085 << previewOutput.fileName() << " size (" 0086 << image.width() << "x" << image.height() 0087 << ")"; 0088 image.save(previewFilePath, "PNG"); 0089 0090 // ----------------------------------------------------------- 0091 0092 qCDebug(DIGIKAM_TESTS_LOG) << "raw2png: Loading half RAW image"; 0093 0094 image = QImage(); 0095 0096 if (!rawProcessor->loadHalfPreview(image, filePath)) 0097 { 0098 qCDebug(DIGIKAM_TESTS_LOG) << "raw2png: Loading half RAW image failed. Aborted..."; 0099 return -1; 0100 } 0101 0102 qCDebug(DIGIKAM_TESTS_LOG) << "raw2png: Saving half image to " 0103 << halfOutput.fileName() << " size (" 0104 << image.width() << "x" << image.height() 0105 << ")"; 0106 0107 image.save(halfFilePath, "PNG"); 0108 0109 // ----------------------------------------------------------- 0110 0111 qCDebug(DIGIKAM_TESTS_LOG) << "raw2png: Loading full RAW image"; 0112 0113 image = QImage(); 0114 DRawDecoderSettings settings; 0115 settings.halfSizeColorImage = false; 0116 settings.sixteenBitsImage = false; 0117 settings.RGBInterpolate4Colors = false; 0118 settings.RAWQuality = DRawDecoderSettings::BILINEAR; 0119 0120 if (!rawProcessor->loadFullImage(image, filePath, settings)) 0121 { 0122 qCDebug(DIGIKAM_TESTS_LOG) << "raw2png: Loading full RAW image failed. Aborted..."; 0123 return -1; 0124 } 0125 0126 qCDebug(DIGIKAM_TESTS_LOG) << "raw2png: Saving full RAW image to " 0127 << fullOutput.fileName() << " size (" 0128 << image.width() << "x" << image.height() 0129 << ")"; 0130 0131 image.save(fullFilePath, "PNG"); 0132 0133 return 0; 0134 }