Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_wdg_options_webp.cpp
Go to the documentation of this file.
1/*
2 * This file is part of Krita
3 *
4 * SPDX-FileCopyrightText: 2021 L. E. Segovia <amy@amyspark.me>
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9#include <webp/encode.h>
10
12
14
16
18 : KisConfigWidget(parent)
19{
20 setupUi(this);
21
22 // HACK ALERT!
23 // QScrollArea contents are opaque at multiple levels
24 // The contents themselves AND the viewport widget
25 {
26 scrollAreaWidgetContents->setAutoFillBackground(false);
27 scrollAreaWidgetContents->parentWidget()->setAutoFillBackground(false);
28 }
29
30#if WEBP_ENCODER_ABI_VERSION < 0x020f
31 qMin->setEnabled(false);
32 qMax->setEnabled(false);
33#endif
34
35 preset->addItem(i18nc("WebP presets", "Default"), WEBP_PRESET_DEFAULT);
36 preset->addItem(i18nc("WebP presets", "Portrait"), WEBP_PRESET_PICTURE);
37 preset->addItem(i18nc("WebP presets", "Outdoor photo"), WEBP_PRESET_PHOTO);
38 preset->addItem(i18nc("WebP presets", "Line drawing"), WEBP_PRESET_DRAWING);
39 preset->addItem(i18nc("WebP presets", "Icon"), WEBP_PRESET_ICON);
40 preset->addItem(i18nc("WebP presets", "Text"), WEBP_PRESET_TEXT);
41
42 filterType->addItem(i18nc("WebP filters", "Simple"), 0);
43 filterType->addItem(i18nc("WebP filters", "Strong"), 1);
44
45 alphaCompression->addItem(i18nc("WebP alpha plane compression", "None"), 0);
46 alphaCompression->addItem(i18nc("WebP alpha plane compression", "Lossless"),
47 1);
48
49 preprocessing->addItem(i18nc("WebP preprocessing filters", "None"), 0);
50 preprocessing->addItem(
51 i18nc("WebP preprocessing filters", "Segment-smooth"),
52 1);
53 preprocessing->addItem(
54 i18nc("WebP preprocessing filters", "Pseudo-random dithering"),
55 2);
56
57 targetPSNR->setDisplayUnit(false);
58 targetPSNR->setSuffix(" dB");
59
60 metaDataFilters->setModel(&m_filterRegistryModel);
61
62 connect(preset,
63 SIGNAL(currentIndexChanged(int)),
64 this,
65 SLOT(changePreset(void)));
66 connect(lossless, SIGNAL(toggled(bool)), this, SLOT(changePreset(void)));
67}
68
70{
71 haveAnimation->setChecked(cfg->getBool("haveAnimation", true));
72
73 preset->setCurrentIndex(cfg->getInt("preset", 0));
74 lossless->setChecked(cfg->getBool("lossless", true));
75 quality->setValue(cfg->getDouble("quality", 75.0));
76 KisSpinBoxI18nHelper::setText(quality, i18nc("{n} is the number value, % is the percent sign", "{n}%"));
77 tradeoff->setValue(cfg->getInt("method", 4));
78 dithering->setChecked(cfg->getBool("dithering", true));
79 chkForceSRGB->setChecked(cfg->getBool("force_srgb", false));
80 chkSaveProfile->setChecked(cfg->getBool("save_profile", true));
81
82 targetSize->setValue(cfg->getInt("target_size", 0));
83 targetPSNR->setValue(cfg->getDouble("target_PSNR", 0.0));
84 segments->setValue(cfg->getInt("segments", 4));
85 snsStrength->setValue(cfg->getInt("sns_strength", 50));
86 KisSpinBoxI18nHelper::setText(snsStrength, i18nc("{n} is the number value, % is the percent sign", "{n}%"));
87 filterStrength->setValue(cfg->getInt("filter_strength", 60));
88 KisSpinBoxI18nHelper::setText(filterStrength, i18nc("{n} is the number value, % is the percent sign", "{n}%"));
89 filterSharpness->setValue(cfg->getInt("filter_sharpness", 0));
90 filterType->setCurrentIndex(cfg->getInt("filter_type", 1));
91 autofilter->setChecked(cfg->getBool("autofilter", false));
92 alphaCompression->setCurrentIndex(cfg->getInt("alpha_compression", 1));
93 alphaFiltering->setValue(cfg->getInt("alpha_filtering", 1));
94 alphaQuality->setValue(cfg->getInt("alpha_quality", 100));
95 KisSpinBoxI18nHelper::setText(alphaQuality, i18nc("{n} is the number value, % is the percent sign", "{n}%"));
96 pass->setValue(cfg->getInt("pass", 1));
97 showCompressed->setChecked(cfg->getBool("show_compressed", false));
98 preprocessing->setCurrentIndex(cfg->getInt("preprocessing", 0));
99 partitions->setValue(cfg->getInt("partitions", 0));
100 partitionLimit->setValue(cfg->getInt("partition_limit", 0));
101 KisSpinBoxI18nHelper::setText(partitionLimit, i18nc("{n} is the number value, % is the percent sign", "{n}%"));
102 emulateJPEGSize->setChecked(cfg->getBool("emulate_jpeg_size", false));
103 threadLevel->setChecked(cfg->getBool("thread_level", false));
104 lowMemory->setChecked(cfg->getBool("low_memory", false));
105 nearLossless->setValue(cfg->getInt("near_lossless", 100));
106 KisSpinBoxI18nHelper::setText(nearLossless, i18nc("{n} is the number value, % is the percent sign", "{n}%"));
107 exact->setChecked(cfg->getBool("exact", false));
108 useSharpYUV->setChecked(cfg->getBool("use_sharp_yuv", false));
109#if WEBP_ENCODER_ABI_VERSION >= 0x020f
110 qMin->setValue(cfg->getInt("qmin", 0));
111 KisSpinBoxI18nHelper::setText(qMin, i18nc("{n} is the number value, % is the percent sign", "{n}%"));
112 qMax->setValue(cfg->getInt("qmax", 100));
113 KisSpinBoxI18nHelper::setText(qMax, i18nc("{n} is the number value, % is the percent sign", "{n}%"));
114#endif
115
116 exif->setChecked(cfg->getBool("exif", true));
117 xmp->setChecked(cfg->getBool("xmp", true));
118 chkMetadata->setChecked(cfg->getBool("storeMetaData", true));
120 cfg->getString("filters").split(','));
121}
122
124{
125 WebPConfig preset;
126
127 if (!WebPConfigPreset(
128 &preset,
129 static_cast<WebPPreset>(this->preset->currentData().value<int>()),
130 static_cast<float>(this->quality->value()))) {
131 return;
132 }
133
134 if (this->lossless->isChecked()
135 && !WebPConfigLosslessPreset(&preset, this->tradeoff->value())) {
136 return;
137 }
138
139 quality->setValue(static_cast<double>(preset.quality));
140 tradeoff->setValue(preset.method);
141
142 targetSize->setValue(preset.target_size);
143 targetPSNR->setValue(static_cast<double>(preset.target_PSNR));
144 segments->setValue(preset.segments);
145 snsStrength->setValue(preset.sns_strength);
146 filterStrength->setValue(preset.filter_strength);
147 filterSharpness->setValue(preset.filter_sharpness);
148 filterType->setCurrentIndex(preset.filter_type);
149 autofilter->setChecked(preset.autofilter == 1);
150 alphaCompression->setCurrentIndex(
151 alphaCompression->findData(preset.alpha_compression));
152 alphaFiltering->setValue(preset.alpha_filtering);
153 alphaQuality->setValue(preset.alpha_quality);
154 pass->setValue(preset.pass);
155 showCompressed->setChecked(preset.show_compressed == 1);
156 preprocessing->setCurrentIndex(
157 preprocessing->findData(preset.preprocessing));
158 partitions->setValue(preset.partitions);
159 partitionLimit->setValue(preset.partition_limit);
160 emulateJPEGSize->setChecked(preset.emulate_jpeg_size == 1);
161 threadLevel->setChecked(preset.thread_level > 0);
162 lowMemory->setChecked(preset.low_memory == 1);
163 nearLossless->setValue(preset.near_lossless);
164 exact->setChecked(preset.exact == 1);
165 useSharpYUV->setChecked(preset.use_sharp_yuv);
166#if WEBP_ENCODER_ABI_VERSION >= 0x020f
167 qMin->setValue(preset.qmin);
168 qMax->setValue(preset.qmax);
169#endif
170}
171
173{
175
176 cfg->setProperty("haveAnimation", haveAnimation->isChecked());
177
178 cfg->setProperty("preset", preset->currentIndex());
179 cfg->setProperty("lossless", lossless->isChecked());
180 cfg->setProperty("quality", quality->value());
181 cfg->setProperty("method", tradeoff->value());
182 cfg->setProperty("dithering", dithering->isChecked());
183 cfg->setProperty("force_srgb", chkForceSRGB->isChecked());
184 cfg->setProperty("save_profile", chkSaveProfile->isChecked());
185
186 cfg->setProperty("target_size", targetSize->value());
187 cfg->setProperty("target_PSNR", targetPSNR->value());
188 cfg->setProperty("segments", segments->value());
189 cfg->setProperty("sns_strength", snsStrength->value());
190 cfg->setProperty("filter_strength", filterStrength->value());
191 cfg->setProperty("filter_sharpness", filterSharpness->value());
192 cfg->setProperty("filter_type", filterType->currentData().value<int>());
193 cfg->setProperty("autofilter", autofilter->isChecked());
194 cfg->setProperty("alpha_compression",
195 alphaCompression->currentData().value<int>());
196 cfg->setProperty("alpha_filtering", alphaFiltering->value());
197 cfg->setProperty("alpha_quality", alphaQuality->value());
198 cfg->setProperty("pass", pass->value());
199 cfg->setProperty("show_compressed", showCompressed->isChecked());
200 cfg->setProperty("preprocessing",
201 preprocessing->currentData().value<int>());
202 cfg->setProperty("partitions", partitions->value());
203 cfg->setProperty("partition_limit", partitionLimit->value());
204 cfg->setProperty("emulate_jpeg_size", emulateJPEGSize->isChecked());
205 cfg->setProperty("thread_level", threadLevel->isChecked());
206 cfg->setProperty("low_memory", lowMemory->isChecked());
207 cfg->setProperty("near_lossless", nearLossless->value());
208 cfg->setProperty("exact", exact->isChecked());
209 cfg->setProperty("use_sharp_yuv", useSharpYUV->isChecked());
210#if WEBP_ENCODER_ABI_VERSION >= 0x020f
211 cfg->setProperty("qmin", qMin->value());
212 cfg->setProperty("qmax", qMax->value());
213#endif
214
215 cfg->setProperty("exif", exif->isChecked());
216 cfg->setProperty("xmp", xmp->isChecked());
217 cfg->setProperty("storeMetaData", chkMetadata->isChecked());
218
219 QString enabledFilters;
220 for (const KisMetaData::Filter *filter :
222 enabledFilters += filter->id() + ',';
223 }
224 cfg->setProperty("filters", enabledFilters);
225
226 return cfg;
227}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
virtual void setEnabledFilters(const QStringList &enabledFilters)
enable the filters in the given list; others will be disabled.
KisPropertiesConfigurationSP configuration() const override
KisMetaData::FilterRegistryModel m_filterRegistryModel
KisWdgOptionsWebP(QWidget *parent)
void setConfiguration(const KisPropertiesConfigurationSP cfg) override
void setText(QSpinBox *spinBox, const QStringView textTemplate)