1 /*
2 A command line tool to convert RAW file to PNG
3
4 SPDX-FileCopyrightText: 2008-2015 Gilles Caulier <caulier dot gilles at gmail dot com>
5
6 SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9 // Qt includes
10
11 #include <QString>
12 #include <QFile>
13 #include <QFileInfo>
14 #include <QDebug>
15
16 // Local includes
17
18 #include <KDCRAW/KDcraw>
19 #include <KDCRAW/RawDecodingSettings>
20
21 using namespace KDcrawIface;
22
main(int argc,char ** argv)23 int main(int argc, char** argv)
24 {
25 if(argc != 2)
26 {
27 qDebug() << "raw2png - RAW Camera Image to PNG Converter";
28 qDebug() << "Usage: <rawfile>";
29 return -1;
30 }
31
32 QString filePath = QString::fromLatin1(argv[1]);
33 QFileInfo input(filePath);
34 QString previewFilePath(input.baseName() + QString::QString::fromLatin1(".preview.png"));
35 QFileInfo previewOutput(previewFilePath);
36 QString halfFilePath(input.baseName() + QString::fromLatin1(".half.png"));
37 QFileInfo halfOutput(halfFilePath);
38 QString fullFilePath(input.baseName() + QString::fromLatin1(".full.png"));
39 QFileInfo fullOutput(fullFilePath);
40 QImage image;
41 DcrawInfoContainer identify;
42
43 // -----------------------------------------------------------
44
45 qDebug() << "raw2png: Identify RAW image from " << input.fileName();
46
47 KDcraw rawProcessor;
48 if (!rawProcessor.rawFileIdentify(identify, filePath))
49 {
50 qDebug() << "raw2png: Idendify RAW image failed. Aborted...";
51 return -1;
52 }
53
54 int width = identify.imageSize.width();
55 int height = identify.imageSize.height();
56
57 qDebug() << "raw2png: Raw image info:";
58 qDebug() << "--- Date: " << identify.dateTime.toString(Qt::ISODate);
59 qDebug() << "--- Make: " << identify.make;
60 qDebug() << "--- Model: " << identify.model;
61 qDebug() << "--- Size: " << width << "x" << height;
62 qDebug() << "--- Filter: " << identify.filterPattern;
63 qDebug() << "--- Colors: " << identify.rawColors;
64
65 // -----------------------------------------------------------
66
67 qDebug() << "raw2png: Loading RAW image preview";
68
69 if (!rawProcessor.loadRawPreview(image, filePath))
70 {
71 qDebug() << "raw2png: Loading RAW image preview failed. Aborted...";
72 return -1;
73 }
74
75 qDebug() << "raw2png: Saving preview image to "
76 << previewOutput.fileName() << " size ("
77 << image.width() << "x" << image.height()
78 << ")";
79 image.save(previewFilePath, "PNG");
80
81 // -----------------------------------------------------------
82
83 qDebug() << "raw2png: Loading half RAW image";
84
85 image = QImage();
86 if (!rawProcessor.loadHalfPreview(image, filePath))
87 {
88 qDebug() << "raw2png: Loading half RAW image failed. Aborted...";
89 return -1;
90 }
91
92 qDebug() << "raw2png: Saving half image to "
93 << halfOutput.fileName() << " size ("
94 << image.width() << "x" << image.height()
95 << ")";
96 image.save(halfFilePath, "PNG");
97
98 // -----------------------------------------------------------
99
100 qDebug() << "raw2png: Loading full RAW image";
101
102 image = QImage();
103 RawDecodingSettings settings;
104 settings.halfSizeColorImage = false;
105 settings.sixteenBitsImage = false;
106 settings.RGBInterpolate4Colors = false;
107 settings.RAWQuality = RawDecodingSettings::BILINEAR;
108
109 if (!rawProcessor.loadFullImage(image, filePath, settings))
110 {
111 qDebug() << "raw2png: Loading full RAW image failed. Aborted...";
112 return -1;
113 }
114
115 qDebug() << "raw2png: Saving full RAW image to "
116 << fullOutput.fileName() << " size ("
117 << image.width() << "x" << image.height()
118 << ")";
119 image.save(fullFilePath, "PNG");
120
121 return 0;
122 }
123