update
[kdegraphics.git] / strigi-analyzer / raw / kcamerarawplugin.cpp
bloba9994c7e47fe6a4fd02d3265b498fd45d7f63d40
1 /* This file is part of the KDE project
2 * Copyright (C) Steffen Hansen <hansen@kde.org>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License as published by the Free Software Foundation version 2.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; see the file COPYING. If not, write to
15 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
20 #include "kcamerarawplugin.h"
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
26 #include <klocale.h>
27 #include <kgenericfactory.h>
28 #include <kdebug.h>
29 #include <ktemporaryfile.h>
30 #include <kimageio.h>
31 #include <qfile.h>
32 #include <qimage.h>
33 #include <qwmatrix.h>
34 #include <cstdio>
37 typedef KGenericFactory<KCameraRawPlugin> RawFactory;
39 K_EXPORT_COMPONENT_FACTORY(kfile_raw, RawFactory("kfile_raw"))
41 #ifndef KDE_EXPORT
42 # define KDE_EXPORT
43 #endif
45 /* Main entry point into raw parser */
46 extern "C" {
47 int extract_thumbnail( FILE*, FILE*, int* );
48 extern char make[];
49 extern char model[];
52 bool KCameraRawPlugin::createPreview(const QString &path, QImage &img)
54 /* Open file and extract thumbnail */
55 FILE* input = fopen( QFile::encodeName(path), "rb" );
56 if( !input ) return false;
57 KTemporaryFile output;
58 output.open();
59 FILE* output_fs = fopen(output.fileName().toAscii(), "r+");
60 int orientation = 0;
61 if( extract_thumbnail( input, output_fs, &orientation ) ) {
62 fclose(input);
63 fclose(output_fs);
64 return false;
66 fclose(input);
67 fclose(output_fs);
68 if( !img.load( output.fileName() ) ) return false;
70 if(orientation) {
71 QMatrix M;
72 QMatrix flip= QMatrix(-1,0,0,1,0,0);
73 switch(orientation+1) { // notice intentional fallthroughs
74 case 2: M = flip; break;
75 case 4: M = flip;
76 case 3: M.rotate(180); break;
77 case 5: M = flip;
78 case 6: M.rotate(90); break;
79 case 7: M = flip;
80 case 8: M.rotate(270); break;
81 default: break; // should never happen
83 img = img.transformed(M);
85 return true;
88 KCameraRawPlugin::KCameraRawPlugin(QObject *parent, const QStringList &args )
89 : KFilePlugin(parent, args)
91 kDebug(7034) << "KCameraRawPlugin c'tor";
94 // define all possible meta info items
96 KFileMimeTypeInfo *info = addMimeTypeInfo("image/x-dcraw");
97 KFileMimeTypeInfo::GroupInfo *group = addGroupInfo( info, "Info",
98 i18n("Image Info") );
99 KFileMimeTypeInfo::ItemInfo* item;
101 item = addItemInfo( group, "Manufacturer", i18n("Camera Manufacturer"),
102 QVariant::String );
103 item = addItemInfo( group, "Model", i18n("Camera Model"),
104 QVariant::String );
105 item = addItemInfo( group, "Thumbnail", i18n("Thumbnail"),
106 QVariant::Image );
107 setHint( item, KFileMimeTypeInfo::Thumbnail );
110 bool KCameraRawPlugin::readInfo( KFileMetaInfo& info, uint what )
112 kDebug(7034) << "KCameraRawPlugin::readInfo()";
114 const QString path( info.path() );
115 if ( path.isEmpty() ) // remote file
116 return false;
118 KFileMetaInfoGroup group = appendGroup( info, "Info" );
119 if ( what & KFileMetaInfo::Thumbnail ){
120 QImage img;
121 if( createPreview( path,img ) ) {
122 appendItem( group, "Thumbnail", img );
123 kDebug(7034) << "thumbnail " << path << " created";
125 } else {
126 // HACK: We have to extract thumbnail to get any info...
127 QImage img;
128 createPreview( path,img );
130 kDebug(7034) << "make=" << make;
131 kDebug(7034) << "model=" << model;
132 if( make[0] ) {
133 appendItem( group, "Manufacturer", &make[0] );
135 if( model[0] ) {
136 appendItem( group, "Model", &model[0] );
139 return true;
142 #include "kcamerarawplugin.moc"