Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_png_export.cc
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2005 Cyrille Berger <cberger@cberger.net>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#include "kis_png_export.h"
8
9#include <QCheckBox>
10#include <QSlider>
11#include <QApplication>
12
13#include <kpluginfactory.h>
14
15#include <KoColorSpace.h>
18#include <KoColorProfile.h>
21
23
25#include <kis_paint_device.h>
26#include <KisDocument.h>
27#include <kis_image.h>
28#include <kis_paint_layer.h>
29#include <kis_group_layer.h>
30#include <kis_config.h>
31#include <kis_meta_data_store.h>
34#include "kis_png_converter.h"
35#include <kis_iterator_ng.h>
36
37K_PLUGIN_FACTORY_WITH_JSON(KisPNGExportFactory, "krita_png_export.json", registerPlugin<KisPNGExport>();)
38
39KisPNGExport::KisPNGExport(QObject *parent, const QVariantList &) : KisImportExportFilter(parent)
40{
41}
42
46
48{
49 KisImageSP image = document->savingImage();
50
51 KisPNGOptions options;
52
53 options.alpha = configuration->getBool("alpha", true);
54 options.interlace = configuration->getBool("interlaced", false);
55 options.compression = configuration->getInt("compression", 3);
56 options.tryToSaveAsIndexed = configuration->getBool("indexed", false);
58 c.fromQColor(Qt::white);
59 options.transparencyFillColor = configuration->getColor("transparencyFillcolor", c).toQColor();
60 options.saveSRGBProfile = configuration->getBool("saveSRGBProfile", false);
61 options.forceSRGB = configuration->getBool("forceSRGB", true);
62 options.storeAuthor = configuration->getBool("storeAuthor", false);
63 options.storeMetaData = configuration->getBool("storeMetaData", false);
64 options.saveAsHDR = configuration->getBool("saveAsHDR", false);
65 options.downsample = configuration->getBool("downsample", false);
66
67 vKisAnnotationSP_it beginIt = image->beginAnnotations();
68 vKisAnnotationSP_it endIt = image->endAnnotations();
69
71 eIV.visit(image->rootLayer().data());
72 KisMetaData::Store *eI = 0;
73 if (eIV.metaDataCount() == 1) {
74 eI = eIV.exifInfo();
75 }
76 if (eI) {
78 eI = copy;
79 }
80
81 KisPNGConverter pngConverter(document);
82
83 KisImportExportErrorCode res = pngConverter.buildFile(io, image->bounds(), image->xRes(), image->yRes(), image->projection(), beginIt, endIt, options, eI);
84 delete eI;
85 dbgFile << " Result =" << res;
86 return res;
87}
88
89KisPropertiesConfigurationSP KisPNGExport::defaultConfiguration(const QByteArray &, const QByteArray &) const
90{
92 cfg->setProperty("alpha", true);
93 cfg->setProperty("indexed", false);
94 cfg->setProperty("compression", 3);
95 cfg->setProperty("interlaced", false);
96
97 KoColor fill_color(KoColorSpaceRegistry::instance()->rgb8());
98 fill_color = KoColor();
99 fill_color.fromQColor(Qt::white);
100 QVariant v;
101 v.setValue(fill_color);
102
103 cfg->setProperty("transparencyFillcolor", v);
104 cfg->setProperty("saveSRGBProfile", false);
105 cfg->setProperty("forceSRGB", true);
106 cfg->setProperty("saveAsHDR", false);
107 cfg->setProperty("storeMetaData", false);
108 cfg->setProperty("storeAuthor", false);
109 cfg->setProperty("downsample", false);
110 return cfg;
111}
112
113KisConfigWidget *KisPNGExport::createConfigurationWidget(QWidget *parent, const QByteArray &, const QByteArray &) const
114{
115 return new KisWdgOptionsPNG(parent);
116}
117
119{
121 QList<QPair<KoID, KoID> > supportedColorModels;
122 supportedColorModels << QPair<KoID, KoID>()
123 << QPair<KoID, KoID>(RGBAColorModelID, Integer8BitsColorDepthID)
124 << QPair<KoID, KoID>(RGBAColorModelID, Integer16BitsColorDepthID)
125 << QPair<KoID, KoID>(GrayAColorModelID, Integer8BitsColorDepthID)
126 << QPair<KoID, KoID>(GrayAColorModelID, Integer16BitsColorDepthID);
127 addSupportedColorModels(supportedColorModels, "PNG");
128}
129
131 : KisConfigWidget(parent)
132{
133 setupUi(this);
134
135 connect(chkSaveAsHDR, SIGNAL(toggled(bool)), this, SLOT(slotUseHDRChanged(bool)));
136}
137
139{
140 // the export manager should have prepared some info for us!
144
145 const bool isThereAlpha = cfg->getBool(KisImportExportFilter::ImageContainsTransparencyTag);
146
147 alpha->setChecked(cfg->getBool("alpha", isThereAlpha));
148
149 bnTransparencyFillColor->setEnabled(!alpha->isChecked());
150
152 tryToSaveAsIndexed->setVisible(true);
153 if (alpha->isChecked()) {
154 tryToSaveAsIndexed->setChecked(false);
155 }
156 else {
157 tryToSaveAsIndexed->setChecked(cfg->getBool("indexed", false));
158 }
159 }
160 else {
161 tryToSaveAsIndexed->setVisible(false);
162 }
163 interlacing->setChecked(cfg->getBool("interlaced", false));
164 compressionLevel->setValue(cfg->getInt("compression", 3));
165 compressionLevel->setRange(1, 9, 0);
166
167 tryToSaveAsIndexed->setVisible(!isThereAlpha);
168
169 //const bool sRGB = cfg->getBool(KisImportExportFilter::sRGBTag, false);
170
171 //chkSRGB->setEnabled(sRGB);
172 chkSRGB->setChecked(cfg->getBool("saveSRGBProfile", true));
173
174 //chkForceSRGB->setEnabled(!sRGB);
175 chkForceSRGB->setChecked(cfg->getBool("forceSRGB", false));
176
177 chkSaveAsHDR->setChecked(cfg->getBool("saveAsHDR", false));
178 slotUseHDRChanged(chkSaveAsHDR->isChecked());
179
180 chkAuthor->setChecked(cfg->getBool("storeAuthor", false));
181 chkMetaData->setChecked(cfg->getBool("storeMetaData", false));
182
183 KoColor background(KoColorSpaceRegistry::instance()->rgb8());
184 background.fromQColor(Qt::white);
185 bnTransparencyFillColor->setDefaultColor(background);
186 bnTransparencyFillColor->setColor(cfg->getColor("transparencyFillcolor", background));
187
188 chkDownsample->setChecked(cfg->getBool("downsample", false));
189}
190
192{
193
195
196 bool alpha = this->alpha->isChecked();
197 bool interlace = interlacing->isChecked();
198 int compression = (int)compressionLevel->value();
199 bool saveAsHDR = chkSaveAsHDR->isChecked();
200 bool tryToSaveAsIndexed = !saveAsHDR && this->tryToSaveAsIndexed->isChecked();
201 bool saveSRGB = !saveAsHDR && chkSRGB->isChecked();
202 bool forceSRGB = !saveAsHDR && chkForceSRGB->isChecked();
203 bool storeAuthor = chkAuthor->isChecked();
204 bool storeMetaData = chkMetaData->isChecked();
205 bool downsample = chkDownsample->isChecked();
206
207
208 QVariant transparencyFillcolor;
209 transparencyFillcolor.setValue(bnTransparencyFillColor->color());
210
211 cfg->setProperty("alpha", alpha);
212 cfg->setProperty("indexed", tryToSaveAsIndexed);
213 cfg->setProperty("compression", compression);
214 cfg->setProperty("interlaced", interlace);
215 cfg->setProperty("transparencyFillcolor", transparencyFillcolor);
216 cfg->setProperty("saveAsHDR", saveAsHDR);
217 cfg->setProperty("saveSRGBProfile", saveSRGB);
218 cfg->setProperty("forceSRGB", forceSRGB);
219 cfg->setProperty("storeAuthor", storeAuthor);
220 cfg->setProperty("storeMetaData", storeMetaData);
221 cfg->setProperty("downsample", downsample);
222 return cfg;
223}
224
226{
227 bnTransparencyFillColor->setEnabled(!checked);
228}
229
231{
232 tryToSaveAsIndexed->setDisabled(value);
233 chkForceSRGB->setDisabled(value);
234 chkSRGB->setDisabled(value);
235}
236
237#include "kis_png_export.moc"
238
float value(const T *src, size_t ch)
qreal v
VertexDescriptor get(PredecessorMap const &m, VertexDescriptor v)
const KoID GrayAColorModelID("GRAYA", ki18n("Grayscale/Alpha"))
const KoID Integer8BitsColorDepthID("U8", ki18n("8-bit integer/channel"))
const KoID Integer16BitsColorDepthID("U16", ki18n("16-bit integer/channel"))
const KoID RGBAColorModelID("RGBA", ki18n("RGB/Alpha"))
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
The KisExifInfoVisitor class looks for a layer with metadata.
KisMetaData::Store * exifInfo()
bool visit(KisNode *) override
static KisExportCheckRegistry * instance()
vKisAnnotationSP_it endAnnotations()
KisGroupLayerSP rootLayer() const
KisPaintDeviceSP projection() const
double xRes() const
double yRes() const
QRect bounds() const override
vKisAnnotationSP_it beginAnnotations()
The base class for import and export filters.
static const QString ColorModelIDTag
void addSupportedColorModels(QList< QPair< KoID, KoID > > supportedColorModels, const QString &name, KisExportCheckBase::Level level=KisExportCheckBase::PARTIALLY)
static const QString ImageContainsTransparencyTag
static const QString sRGBTag
void addCapability(KisExportCheckBase *capability)
KisImportExportErrorCode buildFile(const QString &filename, const QRect &imageRect, const qreal xRes, const qreal yRes, KisPaintDeviceSP device, vKisAnnotationSP_it annotationsStart, vKisAnnotationSP_it annotationsEnd, KisPNGOptions options, KisMetaData::Store *metaData)
KisPropertiesConfigurationSP defaultConfiguration(const QByteArray &from="", const QByteArray &to="") const override
defaultConfiguration defines the default settings for the given import export filter
KisConfigWidget * createConfigurationWidget(QWidget *parent, const QByteArray &from="", const QByteArray &to="") const override
createConfigurationWidget creates a widget that can be used to define the settings for a given import...
KisImportExportErrorCode convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration=0) override
~KisPNGExport() override
void initializeCapabilities() override
KisPNGExport(QObject *parent, const QVariantList &)
KisWdgOptionsPNG(QWidget *parent)
void slotUseHDRChanged(bool value)
void on_alpha_toggled(bool checked)
KisPropertiesConfigurationSP configuration() const override
void setConfiguration(const KisPropertiesConfigurationSP config) override
void fromQColor(const QColor &c)
Convenient function for converting from a QColor.
Definition KoColor.cpp:213
QString id() const
Definition KoID.cpp:63
K_PLUGIN_FACTORY_WITH_JSON(KritaASCCDLFactory, "kritaasccdl.json", registerPlugin< KritaASCCDL >();) KritaASCCDL
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130
#define dbgFile
Definition kis_debug.h:53
vKisAnnotationSP::iterator vKisAnnotationSP_it
Definition kis_types.h:181
QColor transparencyFillColor
static KoColorSpaceRegistry * instance()