libkipi from trunk (KDE 4.3) : add support of kipi host settings "file timestamp...
[kdegraphics.git] / libs / libkdcraw / test / raw2png.cpp
blob114cdc550dfab37d8c0173b93abb206f4b93b0a7
1 /* ============================================================
3 * This file is a part of kipi-plugins project
4 * http://www.kipi-plugins.org
6 * Date : 2008-15-09
7 * Description : a command line tool to convert RAW file to PNG
9 * Copyright (C) 2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
11 * This program is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU General
13 * Public License as published by the Free Software Foundation;
14 * either version 2, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * ============================================================ */
23 // Qt includes.
25 #include <qstring.h>
26 #include <qfile.h>
27 #include <qfileinfo.h>
29 // KDE includes.
31 #include "kdeversion.h"
33 #if KDE_IS_VERSION(4,0,0)
34 #include "qdebug.h"
35 #define PRINT_DEBUG qDebug()
36 #define ENDL
37 #else
38 #include "kdebug.h"
39 #define PRINT_DEBUG kdDebug()
40 #define ENDL << endl
41 #endif
43 // Local includes.
45 #include "kdcraw.h"
47 using namespace KDcrawIface;
49 int main (int argc, char **argv)
51 if(argc != 2)
53 PRINT_DEBUG << "raw2png - RAW Camera Image to PNG Converter" ENDL;
54 PRINT_DEBUG << "Usage: <rawfile>" ENDL;
55 return -1;
58 QString filePath(argv[1]);
59 QFileInfo input(filePath);
60 QString previewFilePath(input.baseName() + QString(".preview.png"));
61 QFileInfo previewOutput(previewFilePath);
62 QString halfFilePath(input.baseName() + QString(".half.png"));
63 QFileInfo halfOutput(halfFilePath);
64 QImage image;
65 DcrawInfoContainer identify;
67 // -----------------------------------------------------------
69 PRINT_DEBUG << "raw2png: Identify RAW image from " << input.fileName() ENDL;
71 KDcraw rawProcessor;
72 if (!rawProcessor.rawFileIdentify(identify, filePath))
74 PRINT_DEBUG << "raw2png: Idendify RAW image failed. Aborted..." ENDL;
75 return -1;
78 int width = identify.imageSize.width();
79 int height = identify.imageSize.height();
81 PRINT_DEBUG << "raw2png: Raw image info:" ENDL;
82 PRINT_DEBUG << "--- Date: " << identify.dateTime.toString(Qt::ISODate) ENDL;
83 PRINT_DEBUG << "--- Make: " << identify.make ENDL;
84 PRINT_DEBUG << "--- Model: " << identify.model ENDL;
85 PRINT_DEBUG << "--- Size: " << width << "x" << height ENDL;
86 PRINT_DEBUG << "--- Filter: " << identify.filterPattern ENDL;
87 PRINT_DEBUG << "--- Colors: " << identify.rawColors ENDL;
89 // -----------------------------------------------------------
91 PRINT_DEBUG << "raw2png: Loading RAW image preview" ENDL;
93 if (!rawProcessor.loadDcrawPreview(image, filePath))
95 PRINT_DEBUG << "raw2png: Loading RAW image preview failed. Aborted..." ENDL;
96 return -1;
99 PRINT_DEBUG << "raw2png: Saving preview image to "
100 << previewOutput.fileName() << " size ("
101 << image.width() << "x" << image.height()
102 << ")" ENDL;
103 image.save(previewFilePath, "PNG");
105 // -----------------------------------------------------------
107 PRINT_DEBUG << "raw2png: Loading half RAW image" ENDL;
109 image = QImage();
110 if (!rawProcessor.loadHalfPreview(image, filePath))
112 PRINT_DEBUG << "raw2png: Loading half RAW image failed. Aborted..." ENDL;
113 return -1;
116 PRINT_DEBUG << "raw2png: Saving half image to "
117 << halfOutput.fileName() << " size ("
118 << image.width() << "x" << image.height()
119 << ")" ENDL;
120 image.save(halfFilePath, "PNG");
122 return 0;