You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
300 lines
12 KiB
300 lines
12 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
* Copyright (C) 2002 Nadeem Hasan <nhasan@kde.org>
|
||
|
*
|
||
|
* This program is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU General Public
|
||
|
* License as published by the Free Software Foundation version 2.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program; see the file COPYING. If not, write to
|
||
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*
|
||
|
*/
|
||
|
|
||
12 years ago
|
#include "tdefile_tiff.h"
|
||
15 years ago
|
|
||
|
#include <kgenericfactory.h>
|
||
|
#include <kdebug.h>
|
||
|
|
||
15 years ago
|
#include <tqstringlist.h>
|
||
|
#include <tqfile.h>
|
||
|
#include <tqdatetime.h>
|
||
|
#include <tqregexp.h>
|
||
15 years ago
|
|
||
|
#include <tiff.h>
|
||
|
#include <tiffio.h>
|
||
|
|
||
|
typedef KGenericFactory<KTiffPlugin> TiffFactory;
|
||
|
|
||
12 years ago
|
K_EXPORT_COMPONENT_FACTORY(tdefile_tiff, TiffFactory("tdefile_tiff"))
|
||
15 years ago
|
|
||
14 years ago
|
KTiffPlugin::KTiffPlugin(TQObject *parent, const char *name,
|
||
|
const TQStringList &args) : KFilePlugin(parent, name, args)
|
||
15 years ago
|
{
|
||
|
kdDebug(7034) << "TIFF file meta info plugin" << endl;
|
||
|
KFileMimeTypeInfo* info = addMimeTypeInfo( "image/tiff" );
|
||
|
|
||
|
KFileMimeTypeInfo::GroupInfo* group =
|
||
|
addGroupInfo(info, "General", i18n("General"));
|
||
|
|
||
|
KFileMimeTypeInfo::ItemInfo* item;
|
||
|
item = addItemInfo(group, "Description", i18n("Description"),
|
||
15 years ago
|
TQVariant::String);
|
||
15 years ago
|
setHint(item, KFileMimeTypeInfo::Description);
|
||
|
item = addItemInfo(group, "Copyright", i18n("Copyright"),
|
||
15 years ago
|
TQVariant::String);
|
||
15 years ago
|
item = addItemInfo(group, "ColorMode", i18n("Color Mode"),
|
||
15 years ago
|
TQVariant::String);
|
||
15 years ago
|
item = addItemInfo(group, "Dimensions", i18n("Dimensions"),
|
||
15 years ago
|
TQVariant::Size);
|
||
15 years ago
|
setHint(item, KFileMimeTypeInfo::Size);
|
||
|
setUnit(item, KFileMimeTypeInfo::Pixels);
|
||
|
item = addItemInfo(group, "Resolution", i18n("Resolution"),
|
||
15 years ago
|
TQVariant::Size);
|
||
15 years ago
|
setUnit(item, KFileMimeTypeInfo::DotsPerInch);
|
||
|
item = addItemInfo(group, "BitDepth", i18n("Bit Depth"),
|
||
15 years ago
|
TQVariant::Int);
|
||
15 years ago
|
setUnit(item, KFileMimeTypeInfo::BitsPerPixel);
|
||
|
item = addItemInfo(group, "Compression", i18n("Compression"),
|
||
15 years ago
|
TQVariant::String);
|
||
15 years ago
|
item = addItemInfo(group, "Software", i18n("Software"),
|
||
15 years ago
|
TQVariant::String);
|
||
15 years ago
|
item = addItemInfo(group, "DateTime", i18n("Date/Time"),
|
||
15 years ago
|
TQVariant::DateTime);
|
||
15 years ago
|
item = addItemInfo(group, "Artist", i18n("Artist"),
|
||
15 years ago
|
TQVariant::String);
|
||
15 years ago
|
setHint(item, KFileMimeTypeInfo::Author);
|
||
|
item = addItemInfo(group, "FaxPages", i18n("Fax Pages"),
|
||
15 years ago
|
TQVariant::Int);
|
||
15 years ago
|
|
||
|
group = addGroupInfo(info, "Scanner", i18n("Scanner"));
|
||
|
|
||
15 years ago
|
item = addItemInfo(group, "Make", i18n("Make"), TQVariant::String);
|
||
|
item = addItemInfo(group, "Model", i18n("Model"), TQVariant::String);
|
||
15 years ago
|
|
||
|
m_colorMode.setAutoDelete(true);
|
||
|
m_imageCompression.setAutoDelete(true);
|
||
|
|
||
|
m_colorMode.insert(PHOTOMETRIC_MINISWHITE,
|
||
15 years ago
|
new TQString(I18N_NOOP("Monochrome")));
|
||
15 years ago
|
m_colorMode.insert(PHOTOMETRIC_MINISBLACK,
|
||
15 years ago
|
new TQString(I18N_NOOP("Monochrome")));
|
||
15 years ago
|
m_colorMode.insert(PHOTOMETRIC_RGB,
|
||
15 years ago
|
new TQString(I18N_NOOP("RGB")));
|
||
15 years ago
|
m_colorMode.insert(PHOTOMETRIC_PALETTE,
|
||
15 years ago
|
new TQString(I18N_NOOP("Palette color")));
|
||
15 years ago
|
m_colorMode.insert(PHOTOMETRIC_MASK,
|
||
14 years ago
|
new TQString(I18N_NOOP("Transparency mask")));
|
||
15 years ago
|
m_colorMode.insert(PHOTOMETRIC_SEPARATED,
|
||
15 years ago
|
new TQString(I18N_NOOP("Color separations")));
|
||
15 years ago
|
m_colorMode.insert(PHOTOMETRIC_YCBCR,
|
||
15 years ago
|
new TQString(I18N_NOOP("YCbCr")));
|
||
15 years ago
|
m_colorMode.insert(PHOTOMETRIC_CIELAB,
|
||
15 years ago
|
new TQString(I18N_NOOP("CIE Lab")));
|
||
15 years ago
|
#ifdef PHOTOMETRIC_ITULAB
|
||
|
m_colorMode.insert(PHOTOMETRIC_ITULAB,
|
||
15 years ago
|
new TQString(I18N_NOOP("ITU Lab")));
|
||
15 years ago
|
#endif
|
||
|
m_colorMode.insert(PHOTOMETRIC_LOGL,
|
||
15 years ago
|
new TQString(I18N_NOOP("LOGL")));
|
||
15 years ago
|
m_colorMode.insert(PHOTOMETRIC_LOGLUV,
|
||
15 years ago
|
new TQString(I18N_NOOP("LOGLUV")));
|
||
15 years ago
|
|
||
|
m_imageCompression.insert(COMPRESSION_NONE,
|
||
15 years ago
|
new TQString(I18N_NOOP("None")));
|
||
15 years ago
|
m_imageCompression.insert(COMPRESSION_CCITTRLE,
|
||
15 years ago
|
new TQString(I18N_NOOP("RLE")));
|
||
15 years ago
|
m_imageCompression.insert(COMPRESSION_CCITTFAX3,
|
||
15 years ago
|
new TQString(I18N_NOOP("G3 Fax")));
|
||
15 years ago
|
m_imageCompression.insert(COMPRESSION_CCITTFAX4,
|
||
15 years ago
|
new TQString(I18N_NOOP("G4 Fax")));
|
||
15 years ago
|
m_imageCompression.insert(COMPRESSION_LZW,
|
||
15 years ago
|
new TQString(I18N_NOOP("LZW")));
|
||
15 years ago
|
m_imageCompression.insert(COMPRESSION_OJPEG,
|
||
15 years ago
|
new TQString(I18N_NOOP("JPEG")));
|
||
15 years ago
|
m_imageCompression.insert(COMPRESSION_JPEG,
|
||
15 years ago
|
new TQString(I18N_NOOP("JPEG DCT")));
|
||
15 years ago
|
#ifdef COMPRESSION_ADOBE_DEFLATE
|
||
|
m_imageCompression.insert(COMPRESSION_ADOBE_DEFLATE,
|
||
15 years ago
|
new TQString(I18N_NOOP("Adobe Deflate")));
|
||
15 years ago
|
#endif
|
||
|
m_imageCompression.insert(COMPRESSION_NEXT,
|
||
15 years ago
|
new TQString(I18N_NOOP("NeXT 2-bit RLE")));
|
||
15 years ago
|
m_imageCompression.insert(COMPRESSION_CCITTRLEW,
|
||
15 years ago
|
new TQString(I18N_NOOP("RLE Word")));
|
||
15 years ago
|
m_imageCompression.insert(COMPRESSION_PACKBITS,
|
||
15 years ago
|
new TQString(I18N_NOOP("Packbits")));
|
||
15 years ago
|
m_imageCompression.insert(COMPRESSION_THUNDERSCAN,
|
||
15 years ago
|
new TQString(I18N_NOOP("Thunderscan RLE")));
|
||
15 years ago
|
m_imageCompression.insert(COMPRESSION_IT8CTPAD,
|
||
15 years ago
|
new TQString(I18N_NOOP("IT8 CT w/padding")));
|
||
15 years ago
|
m_imageCompression.insert(COMPRESSION_IT8LW,
|
||
15 years ago
|
new TQString(I18N_NOOP("IT8 linework RLE")));
|
||
15 years ago
|
m_imageCompression.insert(COMPRESSION_IT8MP,
|
||
15 years ago
|
new TQString(I18N_NOOP("IT8 monochrome")));
|
||
15 years ago
|
m_imageCompression.insert(COMPRESSION_IT8BL,
|
||
15 years ago
|
new TQString(I18N_NOOP("IT8 binary lineart")));
|
||
15 years ago
|
m_imageCompression.insert(COMPRESSION_PIXARFILM,
|
||
15 years ago
|
new TQString(I18N_NOOP("Pixar 10-bit LZW")));
|
||
15 years ago
|
m_imageCompression.insert(COMPRESSION_PIXARLOG,
|
||
15 years ago
|
new TQString(I18N_NOOP("Pixar 11-bit ZIP")));
|
||
15 years ago
|
m_imageCompression.insert(COMPRESSION_DEFLATE,
|
||
15 years ago
|
new TQString(I18N_NOOP("Pixar deflate")));
|
||
15 years ago
|
m_imageCompression.insert(COMPRESSION_DCS,
|
||
15 years ago
|
new TQString(I18N_NOOP("Kodak DCS")));
|
||
15 years ago
|
m_imageCompression.insert(COMPRESSION_JBIG,
|
||
15 years ago
|
new TQString(I18N_NOOP("ISO JBIG")));
|
||
15 years ago
|
m_imageCompression.insert(COMPRESSION_SGILOG,
|
||
15 years ago
|
new TQString(I18N_NOOP("SGI log luminance RLE")));
|
||
15 years ago
|
m_imageCompression.insert(COMPRESSION_SGILOG24,
|
||
15 years ago
|
new TQString(I18N_NOOP("SGI log 24-bit packed")));
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
TQDateTime KTiffPlugin::tiffDate(const TQString& s) const
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDateTime dt;
|
||
|
TQRegExp rxDate("^([0-9]{4}):([0-9]{2}):([0-9]{2})\\s"
|
||
15 years ago
|
"([0-9]{2}):([0-9]{2}):([0-9]{2})$");
|
||
|
|
||
|
if (rxDate.search(s) != -1)
|
||
|
{
|
||
|
int year = rxDate.cap(1).toInt();
|
||
|
int month = rxDate.cap(2).toInt();
|
||
|
int day = rxDate.cap(3).toInt();
|
||
|
int hour = rxDate.cap(4).toInt();
|
||
|
int min = rxDate.cap(5).toInt();
|
||
|
int sec = rxDate.cap(6).toInt();
|
||
|
|
||
15 years ago
|
TQDate d = TQDate(year, month, day);
|
||
|
TQTime t = TQTime(hour, min, sec);
|
||
15 years ago
|
|
||
|
if (d.isValid() && t.isValid())
|
||
|
{
|
||
|
dt.setDate(d);
|
||
|
dt.setTime(t);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return dt;
|
||
|
}
|
||
|
|
||
|
bool KTiffPlugin::readInfo(KFileMetaInfo& info, uint)
|
||
|
{
|
||
15 years ago
|
TIFF *tiff = TIFFOpen(TQFile::encodeName(info.path()), "r");
|
||
15 years ago
|
if (!tiff)
|
||
|
return false;
|
||
|
|
||
|
uint32 imageLength=0, imageWidth=0;
|
||
|
uint16 bitsPerSample=0, imageCompression=0, colorMode=0, samplesPerPixel=0,
|
||
|
imageAlpha=0, imageResUnit=0, dummy=0, faxPages=0;
|
||
|
float imageXResolution=0, imageYResolution=0;
|
||
|
char *description=0, *copyright=0, *software=0, *datetime=0, *artist=0,
|
||
|
*scannerMake=0, *scannerModel=0;
|
||
|
|
||
|
TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &imageLength);
|
||
|
TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &imageWidth);
|
||
|
TIFFGetFieldDefaulted(tiff, TIFFTAG_BITSPERSAMPLE, &bitsPerSample);
|
||
|
TIFFGetFieldDefaulted(tiff, TIFFTAG_SAMPLESPERPIXEL, &samplesPerPixel);
|
||
|
TIFFGetField(tiff, TIFFTAG_PHOTOMETRIC, &colorMode);
|
||
|
TIFFGetFieldDefaulted(tiff, TIFFTAG_COMPRESSION, &imageCompression);
|
||
|
TIFFGetField(tiff, TIFFTAG_MATTEING, &imageAlpha);
|
||
|
TIFFGetField(tiff, TIFFTAG_XRESOLUTION, &imageXResolution);
|
||
|
TIFFGetField(tiff, TIFFTAG_YRESOLUTION, &imageYResolution);
|
||
|
TIFFGetFieldDefaulted(tiff, TIFFTAG_RESOLUTIONUNIT, &imageResUnit);
|
||
|
TIFFGetField(tiff, TIFFTAG_IMAGEDESCRIPTION, &description);
|
||
|
TIFFGetField(tiff, TIFFTAG_SOFTWARE, &software);
|
||
|
TIFFGetField(tiff, TIFFTAG_COPYRIGHT, ©right);
|
||
|
TIFFGetField(tiff, TIFFTAG_DATETIME, &datetime);
|
||
|
TIFFGetField(tiff, TIFFTAG_ARTIST, &artist);
|
||
|
TIFFGetField(tiff, TIFFTAG_PAGENUMBER, &dummy, &faxPages);
|
||
|
TIFFGetField(tiff, TIFFTAG_MAKE, &scannerMake);
|
||
|
TIFFGetField(tiff, TIFFTAG_MODEL, &scannerModel);
|
||
|
|
||
|
kdDebug(7034) << "Description: " << description << endl;
|
||
|
kdDebug(7034) << "Width: " << imageWidth << endl;
|
||
|
kdDebug(7034) << "Height: " << imageLength << endl;
|
||
|
kdDebug(7034) << "BitDepth: " << bitsPerSample << endl;
|
||
|
kdDebug(7034) << "ColorMode: " << colorMode << endl;
|
||
|
kdDebug(7034) << "Compression: " << imageCompression << endl;
|
||
|
kdDebug(7034) << "SamplesPerPixel: " << samplesPerPixel << endl;
|
||
|
kdDebug(7034) << "ImageAlpha: " << imageAlpha << endl;
|
||
|
kdDebug(7034) << "XResolution: " << imageXResolution << endl;
|
||
|
kdDebug(7034) << "YResolution: " << imageYResolution << endl;
|
||
|
kdDebug(7034) << "ResolutionUnit: " << imageResUnit << endl;
|
||
|
kdDebug(7034) << "FaxPages: " << faxPages << endl;
|
||
|
kdDebug(7034) << "DateTime: " << datetime << endl;
|
||
|
kdDebug(7034) << "Copyright: " << copyright << endl;
|
||
|
kdDebug(7034) << "Software: " << software << endl;
|
||
|
kdDebug(7034) << "Artist: " << artist << endl;
|
||
|
kdDebug(7034) << "Make: " << scannerMake << endl;
|
||
|
kdDebug(7034) << "Model: " << scannerModel << endl;
|
||
|
|
||
|
if (imageResUnit == RESUNIT_CENTIMETER)
|
||
|
{
|
||
|
imageXResolution *= 2.54;
|
||
|
imageYResolution *= 2.54;
|
||
|
}
|
||
|
else if (imageResUnit == RESUNIT_NONE)
|
||
|
{
|
||
|
imageXResolution = 0;
|
||
|
imageYResolution = 0;
|
||
|
}
|
||
|
|
||
|
int imageBpp = bitsPerSample*samplesPerPixel;
|
||
|
if (imageAlpha && colorMode==PHOTOMETRIC_RGB)
|
||
14 years ago
|
m_colorMode.replace(PHOTOMETRIC_RGB, new TQString(I18N_NOOP("RGBA")));
|
||
15 years ago
|
|
||
|
KFileMetaInfoGroup group = appendGroup(info, "General");
|
||
|
if (description)
|
||
15 years ago
|
appendItem(group, "Description", TQString(description));
|
||
|
appendItem(group, "Dimensions", TQSize(imageWidth, imageLength));
|
||
15 years ago
|
appendItem(group, "BitDepth", imageBpp);
|
||
|
if (imageXResolution>0 && imageYResolution>0)
|
||
15 years ago
|
appendItem(group, "Resolution", TQSize(
|
||
15 years ago
|
static_cast<int>(imageXResolution),
|
||
|
static_cast<int>(imageYResolution)));
|
||
|
if (m_colorMode[colorMode])
|
||
|
appendItem(group, "ColorMode", *m_colorMode[colorMode]);
|
||
|
if (m_imageCompression[imageCompression])
|
||
|
appendItem(group, "Compression", *m_imageCompression[imageCompression]);
|
||
|
if (datetime)
|
||
|
{
|
||
15 years ago
|
TQDateTime dt = tiffDate(TQString(datetime));
|
||
15 years ago
|
if (dt.isValid())
|
||
|
appendItem(group, "DateTime", dt);
|
||
|
}
|
||
|
if (copyright)
|
||
15 years ago
|
appendItem(group, "Copyright", TQString(copyright));
|
||
15 years ago
|
if (software)
|
||
15 years ago
|
appendItem(group, "Software", TQString(software));
|
||
15 years ago
|
if (artist)
|
||
15 years ago
|
appendItem(group, "Artist", TQString(artist));
|
||
15 years ago
|
|
||
|
if (faxPages>0 && (imageCompression==COMPRESSION_CCITTFAX3 ||
|
||
|
imageCompression==COMPRESSION_CCITTFAX4))
|
||
|
{
|
||
|
appendItem(group, "FaxPages", faxPages);
|
||
|
}
|
||
|
|
||
|
if (scannerMake || scannerModel)
|
||
|
{
|
||
|
group = appendGroup(info, "Scanner");
|
||
|
if (scannerMake)
|
||
15 years ago
|
appendItem(group, "Make", TQString(scannerMake));
|
||
15 years ago
|
if (scannerModel)
|
||
15 years ago
|
appendItem(group, "Model", TQString(scannerModel));
|
||
15 years ago
|
}
|
||
|
|
||
|
TIFFClose(tiff);
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
12 years ago
|
#include "tdefile_tiff.moc"
|