1 /* This file is part of the KDE project
2 * Copyright (C) 2002 Nadeem Hasan <nhasan@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 "kfile_tiff.h"
22 #include <kgenericfactory.h>
25 #include <qstringlist.h>
27 #include <qdatetime.h>
33 typedef KGenericFactory
<KTiffPlugin
> TiffFactory
;
35 K_EXPORT_COMPONENT_FACTORY(kfile_tiff
, TiffFactory("kfile_tiff"))
37 KTiffPlugin::KTiffPlugin(QObject
*parent
,
38 const QStringList
&args
) : KFilePlugin(parent
, args
)
40 kDebug(7034) << "TIFF file meta info plugin";
41 KFileMimeTypeInfo
* info
= addMimeTypeInfo( "image/tiff" );
43 KFileMimeTypeInfo::GroupInfo
* group
=
44 addGroupInfo(info
, "General", i18n("General"));
46 KFileMimeTypeInfo::ItemInfo
* item
;
47 item
= addItemInfo(group
, "Description", i18n("Description"),
49 setHint(item
, KFileMimeTypeInfo::Description
);
50 item
= addItemInfo(group
, "Copyright", i18n("Copyright"),
52 item
= addItemInfo(group
, "ColorMode", i18n("Color Mode"),
54 item
= addItemInfo(group
, "Dimensions", i18n("Dimensions"),
56 setHint(item
, KFileMimeTypeInfo::Size
);
57 setUnit(item
, KFileMimeTypeInfo::Pixels
);
58 item
= addItemInfo(group
, "Resolution", i18n("Resolution"),
60 setUnit(item
, KFileMimeTypeInfo::DotsPerInch
);
61 item
= addItemInfo(group
, "BitDepth", i18n("Bit Depth"),
63 setUnit(item
, KFileMimeTypeInfo::BitsPerPixel
);
64 item
= addItemInfo(group
, "Compression", i18n("Compression"),
66 item
= addItemInfo(group
, "Software", i18n("Software"),
68 item
= addItemInfo(group
, "DateTime", i18n("Date/Time"),
70 item
= addItemInfo(group
, "Artist", i18n("Artist"),
72 setHint(item
, KFileMimeTypeInfo::Author
);
73 item
= addItemInfo(group
, "FaxPages", i18n("Fax Pages"),
76 group
= addGroupInfo(info
, "Scanner", i18n("Scanner"));
78 item
= addItemInfo(group
, "Make", i18n("Make"), QVariant::String
);
79 item
= addItemInfo(group
, "Model", i18n("Model"), QVariant::String
);
81 m_colorMode
.setAutoDelete(true);
82 m_imageCompression
.setAutoDelete(true);
84 m_colorMode
.insert(PHOTOMETRIC_MINISWHITE
,
85 new QString(I18N_NOOP("Monochrome")));
86 m_colorMode
.insert(PHOTOMETRIC_MINISBLACK
,
87 new QString(I18N_NOOP("Monochrome")));
88 m_colorMode
.insert(PHOTOMETRIC_RGB
,
89 new QString(I18N_NOOP("RGB")));
90 m_colorMode
.insert(PHOTOMETRIC_PALETTE
,
91 new QString(I18N_NOOP("Palette color")));
92 m_colorMode
.insert(PHOTOMETRIC_MASK
,
93 new QString(I18N_NOOP("Transparency mask")));
94 m_colorMode
.insert(PHOTOMETRIC_SEPARATED
,
95 new QString(I18N_NOOP("Color separations")));
96 m_colorMode
.insert(PHOTOMETRIC_YCBCR
,
97 new QString(I18N_NOOP("YCbCr")));
98 m_colorMode
.insert(PHOTOMETRIC_CIELAB
,
99 new QString(I18N_NOOP("CIE Lab")));
100 #ifdef PHOTOMETRIC_ITULAB
101 m_colorMode
.insert(PHOTOMETRIC_ITULAB
,
102 new QString(I18N_NOOP("ITU Lab")));
104 m_colorMode
.insert(PHOTOMETRIC_LOGL
,
105 new QString(I18N_NOOP("LOGL")));
106 m_colorMode
.insert(PHOTOMETRIC_LOGLUV
,
107 new QString(I18N_NOOP("LOGLUV")));
109 m_imageCompression
.insert(COMPRESSION_NONE
,
110 new QString(I18N_NOOP("None")));
111 m_imageCompression
.insert(COMPRESSION_CCITTRLE
,
112 new QString(I18N_NOOP("RLE")));
113 m_imageCompression
.insert(COMPRESSION_CCITTFAX3
,
114 new QString(I18N_NOOP("G3 Fax")));
115 m_imageCompression
.insert(COMPRESSION_CCITTFAX4
,
116 new QString(I18N_NOOP("G4 Fax")));
117 m_imageCompression
.insert(COMPRESSION_LZW
,
118 new QString(I18N_NOOP("LZW")));
119 m_imageCompression
.insert(COMPRESSION_OJPEG
,
120 new QString(I18N_NOOP("JPEG")));
121 m_imageCompression
.insert(COMPRESSION_JPEG
,
122 new QString(I18N_NOOP("JPEG DCT")));
123 #ifdef COMPRESSION_ADOBE_DEFLATE
124 m_imageCompression
.insert(COMPRESSION_ADOBE_DEFLATE
,
125 new QString(I18N_NOOP("Adobe Deflate")));
127 m_imageCompression
.insert(COMPRESSION_NEXT
,
128 new QString(I18N_NOOP("NeXT 2-bit RLE")));
129 m_imageCompression
.insert(COMPRESSION_CCITTRLEW
,
130 new QString(I18N_NOOP("RLE Word")));
131 m_imageCompression
.insert(COMPRESSION_PACKBITS
,
132 new QString(I18N_NOOP("Packbits")));
133 m_imageCompression
.insert(COMPRESSION_THUNDERSCAN
,
134 new QString(I18N_NOOP("Thunderscan RLE")));
135 m_imageCompression
.insert(COMPRESSION_IT8CTPAD
,
136 new QString(I18N_NOOP("IT8 CT w/padding")));
137 m_imageCompression
.insert(COMPRESSION_IT8LW
,
138 new QString(I18N_NOOP("IT8 linework RLE")));
139 m_imageCompression
.insert(COMPRESSION_IT8MP
,
140 new QString(I18N_NOOP("IT8 monochrome")));
141 m_imageCompression
.insert(COMPRESSION_IT8BL
,
142 new QString(I18N_NOOP("IT8 binary lineart")));
143 m_imageCompression
.insert(COMPRESSION_PIXARFILM
,
144 new QString(I18N_NOOP("Pixar 10-bit LZW")));
145 m_imageCompression
.insert(COMPRESSION_PIXARLOG
,
146 new QString(I18N_NOOP("Pixar 11-bit ZIP")));
147 m_imageCompression
.insert(COMPRESSION_DEFLATE
,
148 new QString(I18N_NOOP("Pixar deflate")));
149 m_imageCompression
.insert(COMPRESSION_DCS
,
150 new QString(I18N_NOOP("Kodak DCS")));
151 m_imageCompression
.insert(COMPRESSION_JBIG
,
152 new QString(I18N_NOOP("ISO JBIG")));
153 m_imageCompression
.insert(COMPRESSION_SGILOG
,
154 new QString(I18N_NOOP("SGI log luminance RLE")));
155 m_imageCompression
.insert(COMPRESSION_SGILOG24
,
156 new QString(I18N_NOOP("SGI log 24-bit packed")));
159 QDateTime
KTiffPlugin::tiffDate(const QString
& s
) const
162 QRegExp
rxDate("^([0-9]{4}):([0-9]{2}):([0-9]{2})\\s"
163 "([0-9]{2}):([0-9]{2}):([0-9]{2})$");
165 if (rxDate
.indexIn(s
) != -1)
167 int year
= rxDate
.cap(1).toInt();
168 int month
= rxDate
.cap(2).toInt();
169 int day
= rxDate
.cap(3).toInt();
170 int hour
= rxDate
.cap(4).toInt();
171 int min
= rxDate
.cap(5).toInt();
172 int sec
= rxDate
.cap(6).toInt();
174 QDate d
= QDate(year
, month
, day
);
175 QTime t
= QTime(hour
, min
, sec
);
177 if (d
.isValid() && t
.isValid())
187 bool KTiffPlugin::readInfo(KFileMetaInfo
& info
, uint
)
189 TIFF
*tiff
= TIFFOpen(QFile::encodeName(info
.path()), "r");
193 uint32 imageLength
=0, imageWidth
=0;
194 uint16 bitsPerSample
=0, imageCompression
=0, colorMode
=0, samplesPerPixel
=0,
195 imageAlpha
=0, imageResUnit
=0, dummy
=0, faxPages
=0;
196 float imageXResolution
=0, imageYResolution
=0;
197 char *description
=0, *copyright
=0, *software
=0, *datetime
=0, *artist
=0,
198 *scannerMake
=0, *scannerModel
=0;
200 TIFFGetField(tiff
, TIFFTAG_IMAGELENGTH
, &imageLength
);
201 TIFFGetField(tiff
, TIFFTAG_IMAGEWIDTH
, &imageWidth
);
202 TIFFGetFieldDefaulted(tiff
, TIFFTAG_BITSPERSAMPLE
, &bitsPerSample
);
203 TIFFGetFieldDefaulted(tiff
, TIFFTAG_SAMPLESPERPIXEL
, &samplesPerPixel
);
204 TIFFGetField(tiff
, TIFFTAG_PHOTOMETRIC
, &colorMode
);
205 TIFFGetFieldDefaulted(tiff
, TIFFTAG_COMPRESSION
, &imageCompression
);
206 TIFFGetField(tiff
, TIFFTAG_MATTEING
, &imageAlpha
);
207 TIFFGetField(tiff
, TIFFTAG_XRESOLUTION
, &imageXResolution
);
208 TIFFGetField(tiff
, TIFFTAG_YRESOLUTION
, &imageYResolution
);
209 TIFFGetFieldDefaulted(tiff
, TIFFTAG_RESOLUTIONUNIT
, &imageResUnit
);
210 TIFFGetField(tiff
, TIFFTAG_IMAGEDESCRIPTION
, &description
);
211 TIFFGetField(tiff
, TIFFTAG_SOFTWARE
, &software
);
212 TIFFGetField(tiff
, TIFFTAG_COPYRIGHT
, ©right
);
213 TIFFGetField(tiff
, TIFFTAG_DATETIME
, &datetime
);
214 TIFFGetField(tiff
, TIFFTAG_ARTIST
, &artist
);
215 TIFFGetField(tiff
, TIFFTAG_PAGENUMBER
, &dummy
, &faxPages
);
216 TIFFGetField(tiff
, TIFFTAG_MAKE
, &scannerMake
);
217 TIFFGetField(tiff
, TIFFTAG_MODEL
, &scannerModel
);
219 kDebug(7034) << "Description: " << description
;
220 kDebug(7034) << "Width: " << imageWidth
;
221 kDebug(7034) << "Height: " << imageLength
;
222 kDebug(7034) << "BitDepth: " << bitsPerSample
;
223 kDebug(7034) << "ColorMode: " << colorMode
;
224 kDebug(7034) << "Compression: " << imageCompression
;
225 kDebug(7034) << "SamplesPerPixel: " << samplesPerPixel
;
226 kDebug(7034) << "ImageAlpha: " << imageAlpha
;
227 kDebug(7034) << "XResolution: " << imageXResolution
;
228 kDebug(7034) << "YResolution: " << imageYResolution
;
229 kDebug(7034) << "ResolutionUnit: " << imageResUnit
;
230 kDebug(7034) << "FaxPages: " << faxPages
;
231 kDebug(7034) << "DateTime: " << datetime
;
232 kDebug(7034) << "Copyright: " << copyright
;
233 kDebug(7034) << "Software: " << software
;
234 kDebug(7034) << "Artist: " << artist
;
235 kDebug(7034) << "Make: " << scannerMake
;
236 kDebug(7034) << "Model: " << scannerModel
;
238 if (imageResUnit
== RESUNIT_CENTIMETER
)
240 imageXResolution
*= 2.54;
241 imageYResolution
*= 2.54;
243 else if (imageResUnit
== RESUNIT_NONE
)
245 imageXResolution
= 0;
246 imageYResolution
= 0;
249 int imageBpp
= bitsPerSample
*samplesPerPixel
;
250 if (imageAlpha
&& colorMode
==PHOTOMETRIC_RGB
)
251 m_colorMode
.replace(PHOTOMETRIC_RGB
, new QString(I18N_NOOP("RGBA")));
253 KFileMetaInfoGroup group
= appendGroup(info
, "General");
255 appendItem(group
, "Description", QString(description
));
256 appendItem(group
, "Dimensions", QSize(imageWidth
, imageLength
));
257 appendItem(group
, "BitDepth", imageBpp
);
258 if (imageXResolution
>0 && imageYResolution
>0)
259 appendItem(group
, "Resolution", QSize(
260 static_cast<int>(imageXResolution
),
261 static_cast<int>(imageYResolution
)));
262 if (m_colorMode
[colorMode
])
263 appendItem(group
, "ColorMode", *m_colorMode
[colorMode
]);
264 if (m_imageCompression
[imageCompression
])
265 appendItem(group
, "Compression", *m_imageCompression
[imageCompression
]);
268 QDateTime dt
= tiffDate(QString(datetime
));
270 appendItem(group
, "DateTime", dt
);
273 appendItem(group
, "Copyright", QString(copyright
));
275 appendItem(group
, "Software", QString(software
));
277 appendItem(group
, "Artist", QString(artist
));
279 if (faxPages
>0 && (imageCompression
==COMPRESSION_CCITTFAX3
||
280 imageCompression
==COMPRESSION_CCITTFAX4
))
282 appendItem(group
, "FaxPages", faxPages
);
285 if (scannerMake
|| scannerModel
)
287 group
= appendGroup(info
, "Scanner");
289 appendItem(group
, "Make", QString(scannerMake
));
291 appendItem(group
, "Model", QString(scannerModel
));
299 #include "kfile_tiff.moc"