Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Make the PNG forceConvertsRGB toggle disable in certain circumstances.

Wolthera van Hövell tot Westerflier9d6d713861de
diff --git a/libs/ui/kis_png_converter.cpp b/libs/ui/kis_png_converter.cpp
index 3e1f5060f4..3a7711e5c9 100644
--- a/libs/ui/kis_png_converter.cpp
+++ b/libs/ui/kis_png_converter.cpp
@@ -1244,7 +1244,8 @@ KisImportExportErrorCode KisPNGConverter::buildFile(QIODevice* iodevice, const Q
// set sRGB only if the profile is sRGB -- http://www.w3.org/TR/PNG/#11sRGB says sRGB and iCCP should not both be present
const bool sRGB = *device->colorSpace()->profile() == *KoColorSpaceRegistry::instance()->p709SRGBProfile();
- const bool colorProfilePQ = device->colorSpace()->profile()->getTransferCharacteristics() == TRC_ITU_R_BT_2100_0_PQ;
+ const bool colorProfilePQ = (device->colorSpace()->profile()->getTransferCharacteristics() == TRC_ITU_R_BT_2100_0_PQ
+ && device->colorSpace()->profile()->getColorPrimaries() == PRIMARIES_ITU_R_BT_2020_2_AND_2100_0);
/*
* This automatically writes the correct gamma and chroma chunks along with the sRGB chunk, but firefox's
* color management is bugged, so once you give it any incentive to start color managing an sRGB image it
diff --git a/plugins/impex/png/kis_png_export.cc b/plugins/impex/png/kis_png_export.cc
index a676848e9f..c5965cca61 100644
--- a/plugins/impex/png/kis_png_export.cc
+++ b/plugins/impex/png/kis_png_export.cc
@@ -150,6 +150,9 @@ KisWdgOptionsPNG::KisWdgOptionsPNG(QWidget *parent)
: KisConfigWidget(parent)
{
setupUi(this);
+
+ connect(cmbFloatingConversion, SIGNAL(activated(int)), this, SLOT(on_conversion_policy_changed()));
+ connect(chkCICP, SIGNAL(toggled(bool)), this, SLOT(on_conversion_policy_changed()));
}
void KisWdgOptionsPNG::setConfiguration(const KisPropertiesConfigurationSP cfg)
@@ -168,29 +171,29 @@ void KisWdgOptionsPNG::setConfiguration(const KisPropertiesConfigurationSP cfg)
QStringList conversionOptionName = {"Rec2100PQ", "Rec2100HLG"};
int cicpPrimaries = cfg->getInt(KisImportExportFilter::CICPPrimariesTag,
static_cast<int>(PRIMARIES_UNSPECIFIED));
- if (cfg->getString(KisImportExportFilter::ColorModelIDTag) == "RGBA") {
- if (cicpPrimaries != PRIMARIES_UNSPECIFIED) {
- conversionOptionsList << i18nc("Color space option plus transfer function name", "Keep colorants, encode PQ");
- toolTipList << i18nc("@tooltip", "The image will be linearized first, and then encoded with a perceptual quantizer curve"
- " (also known as the SMPTE 2048 curve). Recommended for images where the absolute brightness is important.");
- conversionOptionName << "ApplyPQ";
-
- conversionOptionsList << i18nc("Color space option plus transfer function name", "Keep colorants, encode HLG");
- toolTipList << i18nc("@tooltip", "The image will be linearized first, and then encoded with a Hybrid Log Gamma curve."
- " Recommended for images intended for screens which cannot understand PQ");
- conversionOptionName << "ApplyHLG";
-
- conversionOptionsList << i18nc("Color space option plus transfer function name", "Keep colorants, encode SMPTE ST 428");
- toolTipList << i18nc("@tooltip", "The image will be linearized first, and then encoded with SMPTE ST 428."
- " Krita always opens images like these as linear floating point, this option is there to reverse that");
- conversionOptionName << "ApplySMPTE428";
- }
-
- conversionOptionsList << i18nc("Color space option", "No changes, clip");
- toolTipList << i18nc("@tooltip", "The image will be converted plainly to 12bit integer, and values that are out of bounds are clipped, the icc profile will be embedded.");
- conversionOptionName << "KeepSame";
+ if (cicpPrimaries != PRIMARIES_UNSPECIFIED) {
+ conversionOptionsList << i18nc("Color space option plus transfer function name", "Keep colorants, encode PQ");
+ toolTipList << i18nc("@tooltip", "The image will be linearized first, and then encoded with a perceptual quantizer curve"
+ " (also known as the SMPTE 2048 curve). Recommended for images where the absolute brightness is important.");
+ conversionOptionName << "ApplyPQ";
+
+ conversionOptionsList << i18nc("Color space option plus transfer function name", "Keep colorants, encode HLG");
+ toolTipList << i18nc("@tooltip", "The image will be linearized first, and then encoded with a Hybrid Log Gamma curve."
+ " Recommended for images intended for screens which cannot understand PQ");
+ conversionOptionName << "ApplyHLG";
+
+ conversionOptionsList << i18nc("Color space option plus transfer function name", "Keep colorants, encode SMPTE ST 428");
+ toolTipList << i18nc("@tooltip", "The image will be linearized first, and then encoded with SMPTE ST 428."
+ " Krita always opens images like these as linear floating point, this option is there to reverse that");
+ conversionOptionName << "ApplySMPTE428";
}
+ conversionOptionsList << i18nc("Color space option", "No changes, clip");
+ toolTipList << i18nc("@tooltip", "The image will be converted plainly to 16bit integer, and values that are out of bounds are clipped, the icc profile will be embedded.");
+ conversionOptionName << "KeepSame";
+
+
+ cmbFloatingConversion->clear();
cmbFloatingConversion->addItems(conversionOptionsList);
for (int i=0; i< toolTipList.size(); i++) {
cmbFloatingConversion->setItemData(i, toolTipList.at(i), Qt::ToolTipRole);
@@ -204,12 +207,13 @@ void KisWdgOptionsPNG::setConfiguration(const KisPropertiesConfigurationSP cfg)
}
const QString colorDepthId =
cfg->getString(KisImportExportFilter::ColorDepthIDTag);
- if (colorDepthId == Float16BitsColorDepthID.id()
+ if ((colorDepthId == Float16BitsColorDepthID.id()
|| colorDepthId == Float32BitsColorDepthID.id()
- || colorDepthId == Float64BitsColorDepthID.id()) {
- cmbFloatingConversion->setEnabled(true);
+ || colorDepthId == Float64BitsColorDepthID.id())
+ && cfg->getString(KisImportExportFilter::ColorModelIDTag) == "RGBA") {
+ m_floatingPoint = true;
} else {
- cmbFloatingConversion->setEnabled(false);
+ m_floatingPoint = false;
}
gbSaveColorInfo->setChecked(cfg->getBool("storeColorSpaceInfo", true));
@@ -252,6 +256,8 @@ void KisWdgOptionsPNG::setConfiguration(const KisPropertiesConfigurationSP cfg)
bnTransparencyFillColor->setColor(cfg->getColor("transparencyFillcolor", background));
chkDownsample->setChecked(cfg->getBool("downsample", false));
+
+ on_conversion_policy_changed();
}
KisPropertiesConfigurationSP KisWdgOptionsPNG::configuration() const
@@ -263,7 +269,7 @@ KisPropertiesConfigurationSP KisWdgOptionsPNG::configuration() const
bool interlace = interlacing->isChecked();
int compression = (int)compressionLevel->value();
bool tryToSaveAsIndexed = this->tryToSaveAsIndexed->isChecked();
- bool forceSRGB = chkForceSRGB->isChecked();
+ bool forceSRGB = chkForceSRGB->isEnabled()? chkForceSRGB->isChecked(): false;
bool storeAuthor = chkAuthor->isChecked();
bool storeMetaData = chkMetaData->isChecked();
bool downsample = chkDownsample->isChecked();
@@ -298,5 +304,16 @@ void KisWdgOptionsPNG::on_alpha_toggled(bool checked)
bnTransparencyFillColor->setEnabled(!checked);
}
+void KisWdgOptionsPNG::on_conversion_policy_changed()
+{
+ cmbFloatingConversion->setEnabled(m_floatingPoint && chkCICP->isChecked());
+ const QString conversionMode = cmbFloatingConversion->currentData(Qt::UserRole+1).toString();
+ if (cmbFloatingConversion->isEnabled()) {
+ chkForceSRGB->setEnabled(conversionMode == "KeepSame");
+ } else {
+ chkForceSRGB->setEnabled(true);
+ }
+}
+
#include "kis_png_export.moc"
diff --git a/plugins/impex/png/kis_png_export.h b/plugins/impex/png/kis_png_export.h
index 44640de6c8..905b63c188 100644
--- a/plugins/impex/png/kis_png_export.h
+++ b/plugins/impex/png/kis_png_export.h
@@ -24,6 +24,10 @@ public:
private Q_SLOTS:
void on_alpha_toggled(bool checked);
+ void on_conversion_policy_changed();
+
+private:
+ bool m_floatingPoint {false};
};
class KisPNGExport : public KisImportExportFilter