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