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"
27 #include <kgenericfactory.h>
29 #include <ktemporaryfile.h>
37 typedef KGenericFactory
<KCameraRawPlugin
> RawFactory
;
39 K_EXPORT_COMPONENT_FACTORY(kfile_raw
, RawFactory("kfile_raw"))
45 /* Main entry point into raw parser */
47 int extract_thumbnail( FILE*, FILE*, int* );
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
;
59 FILE* output_fs
= fopen(output
.fileName().toAscii(), "r+");
61 if( extract_thumbnail( input
, output_fs
, &orientation
) ) {
68 if( !img
.load( output
.fileName() ) ) return false;
72 QMatrix flip
= QMatrix(-1,0,0,1,0,0);
73 switch(orientation
+1) { // notice intentional fallthroughs
74 case 2: M
= flip
; break;
76 case 3: M
.rotate(180); break;
78 case 6: M
.rotate(90); break;
80 case 8: M
.rotate(270); break;
81 default: break; // should never happen
83 img
= img
.transformed(M
);
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",
99 KFileMimeTypeInfo::ItemInfo
* item
;
101 item
= addItemInfo( group
, "Manufacturer", i18n("Camera Manufacturer"),
103 item
= addItemInfo( group
, "Model", i18n("Camera Model"),
105 item
= addItemInfo( group
, "Thumbnail", i18n("Thumbnail"),
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
118 KFileMetaInfoGroup group
= appendGroup( info
, "Info" );
119 if ( what
& KFileMetaInfo::Thumbnail
){
121 if( createPreview( path
,img
) ) {
122 appendItem( group
, "Thumbnail", img
);
123 kDebug(7034) << "thumbnail " << path
<< " created";
126 // HACK: We have to extract thumbnail to get any info...
128 createPreview( path
,img
);
130 kDebug(7034) << "make=" << make
;
131 kDebug(7034) << "model=" << model
;
133 appendItem( group
, "Manufacturer", &make
[0] );
136 appendItem( group
, "Model", &model
[0] );
142 #include "kcamerarawplugin.moc"