File indexing completed on 2025-01-19 03:51:03
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2019-09-22 0007 * Description : TIFF DImg plugin. 0008 * 0009 * SPDX-FileCopyrightText: 2020-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "dimgtiffplugin.h" 0016 0017 // Qt includes 0018 0019 #include <QFile> 0020 0021 // KDE includes 0022 0023 #include <klocalizedstring.h> 0024 0025 // Local includes 0026 0027 #include "digikam_debug.h" 0028 #include "digikam_config.h" 0029 #include "digikam_globals.h" 0030 #include "dimgtiffloader.h" 0031 #include "dimgtiffexportsettings.h" 0032 0033 namespace DigikamTIFFDImgPlugin 0034 { 0035 0036 DImgTIFFPlugin::DImgTIFFPlugin(QObject* const parent) 0037 : DPluginDImg(parent) 0038 { 0039 } 0040 0041 DImgTIFFPlugin::~DImgTIFFPlugin() 0042 { 0043 } 0044 0045 QString DImgTIFFPlugin::name() const 0046 { 0047 return i18nc("@title", "TIFF loader"); 0048 } 0049 0050 QString DImgTIFFPlugin::iid() const 0051 { 0052 return QLatin1String(DPLUGIN_IID); 0053 } 0054 0055 QIcon DImgTIFFPlugin::icon() const 0056 { 0057 return QIcon::fromTheme(QLatin1String("image-tiff")); 0058 } 0059 0060 QString DImgTIFFPlugin::description() const 0061 { 0062 return i18nc("@info", "An image loader based on Libtiff codec"); 0063 } 0064 0065 QString DImgTIFFPlugin::details() const 0066 { 0067 return xi18nc("@info", "<para>This plugin allows users to load and save image using Libtiff codec.</para>" 0068 "<para>Tagged Image File Format, abbreviated TIFF or TIF, is a computer file format " 0069 "for storing raster graphics images, popular among graphic artists, the publishing " 0070 "industry, and photographers. TIFF is widely supported by scanning, faxing, " 0071 "word processing, optical character recognition, image manipulation, " 0072 "desktop publishing, and page-layout applications.</para>" 0073 "<para>See <a href='https://en.wikipedia.org/wiki/TIFF'>" 0074 "Tagged Image File Format documentation</a> for details.</para>" 0075 ); 0076 } 0077 0078 QString DImgTIFFPlugin::handbookSection() const 0079 { 0080 return QLatin1String("supported_materials"); 0081 } 0082 0083 QString DImgTIFFPlugin::handbookChapter() const 0084 { 0085 return QLatin1String("image_formats"); 0086 } 0087 0088 QString DImgTIFFPlugin::handbookReference() const 0089 { 0090 return QLatin1String("image-tiff"); 0091 } 0092 0093 QList<DPluginAuthor> DImgTIFFPlugin::authors() const 0094 { 0095 return QList<DPluginAuthor>() 0096 << DPluginAuthor(QString::fromUtf8("Renchi Raju"), 0097 QString::fromUtf8("renchi dot raju at gmail dot com"), 0098 QString::fromUtf8("(C) 2005")) 0099 << DPluginAuthor(QString::fromUtf8("Gilles Caulier"), 0100 QString::fromUtf8("caulier dot gilles at gmail dot com"), 0101 QString::fromUtf8("(C) 2006-2022")) 0102 ; 0103 } 0104 0105 void DImgTIFFPlugin::setup(QObject* const /*parent*/) 0106 { 0107 // Nothing to do 0108 } 0109 0110 QString DImgTIFFPlugin::loaderName() const 0111 { 0112 return QLatin1String("TIFF"); 0113 } 0114 0115 QString DImgTIFFPlugin::typeMimes() const 0116 { 0117 return QLatin1String("TIF TIFF"); 0118 } 0119 0120 QMap<QString, QStringList> DImgTIFFPlugin::extraAboutData() const 0121 { 0122 QMap<QString, QStringList> map; 0123 map.insert(QLatin1String("TIF"), QStringList() << i18nc("@title", "Tagged Image Format") 0124 << i18nc("@info: can read file format", "yes") 0125 << i18nc("@info: can write file format", "yes") 0126 ); 0127 map.insert(QLatin1String("TIFF"), QStringList() << i18nc("@title", "Tagged Image Format") 0128 << i18nc("@info: can read file format", "yes") 0129 << i18nc("@info: can write file format", "yes") 0130 ); 0131 0132 return map; 0133 } 0134 0135 int DImgTIFFPlugin::canRead(const QFileInfo& fileInfo, bool magic) const 0136 { 0137 QString filePath = fileInfo.filePath(); 0138 QString format = fileInfo.suffix().toUpper(); 0139 0140 // First simply check file extension 0141 0142 if (!magic) 0143 { 0144 return (!format.isEmpty() && typeMimes().contains(format)) ? 10 : 0; 0145 } 0146 0147 // In second, we trying to parse file header. 0148 0149 QFile file(filePath); 0150 0151 if (!file.open(QIODevice::ReadOnly)) 0152 { 0153 qCDebug(DIGIKAM_DIMG_LOG) << "Failed to open file " << filePath; 0154 0155 return 0; 0156 } 0157 0158 const qint64 headerLen = 9; 0159 0160 QByteArray header(headerLen, '\0'); 0161 0162 if (file.read((char*)header.data(), headerLen) != headerLen) 0163 { 0164 qCDebug(DIGIKAM_DIMG_LOG) << "Failed to read header of file " << filePath; 0165 0166 return 0; 0167 } 0168 0169 uchar tiffBigID[4] = { 0x4D, 0x4D, 0x00, 0x2A }; 0170 uchar tiffLilID[4] = { 0x49, 0x49, 0x2A, 0x00 }; 0171 0172 if (memcmp(header.data(), &tiffBigID, 4) == 0 || 0173 memcmp(header.data(), &tiffLilID, 4) == 0) 0174 { 0175 return 10; 0176 } 0177 0178 return 0; 0179 } 0180 0181 int DImgTIFFPlugin::canWrite(const QString& format) const 0182 { 0183 return typeMimes().contains(format.toUpper()) ? 10 : 0; 0184 } 0185 0186 DImgLoader* DImgTIFFPlugin::loader(DImg* const image, const DRawDecoding&) const 0187 { 0188 return new DImgTIFFLoader(image); 0189 } 0190 0191 DImgLoaderSettings* DImgTIFFPlugin::exportWidget(const QString& format) const 0192 { 0193 if (canWrite(format)) 0194 { 0195 return (new DImgTIFFExportSettings()); 0196 } 0197 0198 return nullptr; 0199 } 0200 0201 } // namespace DigikamTIFFDImgPlugin 0202 0203 #include "moc_dimgtiffplugin.cpp"