1 /* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2009-06-03
7 * Description : A PGF IO file for DImg framework
8 *
9 * Copyright (C) 2009-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
10 *
11 * This program is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU General
13 * Public License as published by the Free Software Foundation;
14 * either version 2, or (at your option)
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * ============================================================ */
23
24 #include "digikam_config.h"
25 #include "dimgpgfloader.h" // krazy:exclude=includes
26
27 // C Ansi includes
28
29 extern "C"
30 {
31 #ifndef Q_CC_MSVC
32 # include <unistd.h>
33 #endif
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <fcntl.h>
37 }
38
39 // C++ includes
40
41 #include <iostream>
42 #include <cmath>
43 #include <cstdio>
44
45 // Qt includes
46
47 #include <QFile>
48 #include <QVariant>
49 #include <QByteArray>
50 #include <QTextStream>
51 #include <QDataStream>
52 #include <qplatformdefs.h>
53
54 // Windows includes
55
56 #ifdef Q_OS_WIN32
57 # include <windows.h>
58 #endif
59
60 // Libpgf includes
61
62 // Pragma directives to reduce warnings from Libpgf header files.
63 #if defined(Q_CC_GNU)
64 # pragma GCC diagnostic push
65 # pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
66 #endif
67
68 #if defined(Q_CC_CLANG)
69 # pragma clang diagnostic push
70 # pragma clang diagnostic ignored "-Wkeyword-macro"
71 #endif
72
73 #include "PGFimage.h"
74
75 // Restore warnings
76 #if defined(Q_CC_CLANG)
77 # pragma clang diagnostic pop
78 #endif
79
80 #if defined(Q_CC_GNU)
81 # pragma GCC diagnostic pop
82 #endif
83
84 // Local includes
85
86 #include "digikam_debug.h"
87 #include "dimg.h"
88 #include "dimgloaderobserver.h"
89 #include "pgfutils.h"
90 #include "metaengine.h"
91
92 namespace Digikam
93 {
94
DImgPGFLoader(DImg * const image)95 DImgPGFLoader::DImgPGFLoader(DImg* const image)
96 : DImgLoader (image),
97 m_sixteenBit(false),
98 m_hasAlpha (false),
99 m_observer (nullptr)
100 {
101 }
102
~DImgPGFLoader()103 DImgPGFLoader::~DImgPGFLoader()
104 {
105 }
106
hasAlpha() const107 bool DImgPGFLoader::hasAlpha() const
108 {
109 return m_hasAlpha;
110 }
111
sixteenBit() const112 bool DImgPGFLoader::sixteenBit() const
113 {
114 return m_sixteenBit;
115 }
116
progressCallback(double percent,bool escapeAllowed)117 bool DImgPGFLoader::progressCallback(double percent, bool escapeAllowed)
118 {
119 if (m_observer)
120 {
121 m_observer->progressInfo((float)percent);
122
123 if (escapeAllowed)
124 {
125 return (!m_observer->continueQuery());
126 }
127 }
128
129 return false;
130 }
131
isReadOnly() const132 bool DImgPGFLoader::isReadOnly() const
133 {
134 return false;
135 }
136
CallbackForLibPGF(double percent,bool escapeAllowed,void * data)137 bool DImgPGFLoader::CallbackForLibPGF(double percent, bool escapeAllowed, void* data)
138 {
139 if (data)
140 {
141 DImgPGFLoader* const d = static_cast<DImgPGFLoader*>(data);
142
143 return (d->progressCallback(percent, escapeAllowed));
144 }
145
146 return false;
147 }
148
149 } // namespace Digikam
150