File indexing completed on 2025-01-19 03:51:01
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2019-09-22 0007 * Description : PGF 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 "dimgpgfplugin.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 "dimgpgfloader.h" 0031 #include "dimgpgfexportsettings.h" 0032 0033 namespace DigikamPGFDImgPlugin 0034 { 0035 0036 DImgPGFPlugin::DImgPGFPlugin(QObject* const parent) 0037 : DPluginDImg(parent) 0038 { 0039 } 0040 0041 DImgPGFPlugin::~DImgPGFPlugin() 0042 { 0043 } 0044 0045 QString DImgPGFPlugin::name() const 0046 { 0047 return i18nc("@title", "PGF loader"); 0048 } 0049 0050 QString DImgPGFPlugin::iid() const 0051 { 0052 return QLatin1String(DPLUGIN_IID); 0053 } 0054 0055 QIcon DImgPGFPlugin::icon() const 0056 { 0057 return QIcon::fromTheme(QLatin1String("image-x-generic")); 0058 } 0059 0060 QString DImgPGFPlugin::description() const 0061 { 0062 return i18nc("@info", "An image loader based on Libpgf codec"); 0063 } 0064 0065 QString DImgPGFPlugin::handbookSection() const 0066 { 0067 return QLatin1String("supported_materials"); 0068 } 0069 0070 QString DImgPGFPlugin::handbookChapter() const 0071 { 0072 return QLatin1String("image_formats"); 0073 } 0074 0075 QString DImgPGFPlugin::handbookReference() const 0076 { 0077 return QLatin1String("image-pgf"); 0078 } 0079 0080 QString DImgPGFPlugin::details() const 0081 { 0082 return xi18nc("@info", "<para>This plugin allows users to load and save image using Libpgf codec.</para>" 0083 "<para>The Progressive Graphics File (PGF) is an efficient image file format, " 0084 "that is based on a fast, discrete wavelet transform with progressive coding " 0085 "features. PGF can be used for lossless and lossy compression. It's most suitable " 0086 "for natural images. PGF can be used as a very efficient and fast replacement of JPEG-2000.</para>" 0087 "<para>See <a href='https://en.wikipedia.org/wiki/Progressive_Graphics_File'>" 0088 "Progressive Graphics File documentation</a> for details.</para>" 0089 ); 0090 } 0091 0092 QList<DPluginAuthor> DImgPGFPlugin::authors() const 0093 { 0094 return QList<DPluginAuthor>() 0095 << DPluginAuthor(QString::fromUtf8("Gilles Caulier"), 0096 QString::fromUtf8("caulier dot gilles at gmail dot com"), 0097 QString::fromUtf8("(C) 2009-2022")) 0098 ; 0099 } 0100 0101 void DImgPGFPlugin::setup(QObject* const /*parent*/) 0102 { 0103 // Nothing to do 0104 } 0105 0106 QMap<QString, QStringList> DImgPGFPlugin::extraAboutData() const 0107 { 0108 QMap<QString, QStringList> map; 0109 map.insert(QLatin1String("PGF"), 0110 QStringList() << i18nc("@title", "Progressive Graphics File") 0111 << i18nc("@info: can read file format", "yes") 0112 << i18nc("@info: can write file format", "yes") 0113 ); 0114 0115 return map; 0116 } 0117 0118 QString DImgPGFPlugin::loaderName() const 0119 { 0120 return QLatin1String("PGF"); 0121 } 0122 0123 QString DImgPGFPlugin::typeMimes() const 0124 { 0125 return QLatin1String("PGF"); 0126 } 0127 0128 int DImgPGFPlugin::canRead(const QFileInfo& fileInfo, bool magic) const 0129 { 0130 QString filePath = fileInfo.filePath(); 0131 QString format = fileInfo.suffix().toUpper(); 0132 0133 // First simply check file extension 0134 0135 if (!magic) 0136 { 0137 return (!format.isEmpty() && typeMimes().contains(format)) ? 10 : 0; 0138 } 0139 0140 // In second, we trying to parse file header. 0141 0142 QFile file(filePath); 0143 0144 if (!file.open(QIODevice::ReadOnly)) 0145 { 0146 qCDebug(DIGIKAM_DIMG_LOG) << "Failed to open file " << filePath; 0147 0148 return 0; 0149 } 0150 0151 const qint64 headerLen = 9; 0152 0153 QByteArray header(headerLen, '\0'); 0154 0155 if (file.read((char*)header.data(), headerLen) != headerLen) 0156 { 0157 qCDebug(DIGIKAM_DIMG_LOG) << "Failed to read header of file " << filePath; 0158 0159 return 0; 0160 } 0161 0162 uchar pgfID[3] = { 0x50, 0x47, 0x46 }; 0163 0164 if (memcmp(header.data(), &pgfID, 3) == 0) 0165 { 0166 return 10; 0167 } 0168 0169 return 0; 0170 } 0171 0172 int DImgPGFPlugin::canWrite(const QString& format) const 0173 { 0174 return typeMimes().contains(format.toUpper()) ? 10 : 0; 0175 } 0176 0177 DImgLoader* DImgPGFPlugin::loader(DImg* const image, const DRawDecoding&) const 0178 { 0179 return new DImgPGFLoader(image); 0180 } 0181 0182 DImgLoaderSettings* DImgPGFPlugin::exportWidget(const QString& format) const 0183 { 0184 if (canWrite(format)) 0185 { 0186 return (new DImgPGFExportSettings()); 0187 } 0188 0189 return nullptr; 0190 } 0191 0192 } // namespace DigikamPGFDImgPlugin 0193 0194 #include "moc_dimgpgfplugin.cpp"