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++

Allow multiple luminance calculation types for hdr content light level.

Wolthera van Hövell tot Westerflier5abe986b3e8c
diff --git a/libs/image/kis_hdr_metadata.h b/libs/image/kis_hdr_metadata.h
index 7ca768369c..7f2b8e996c 100644
--- a/libs/image/kis_hdr_metadata.h
+++ b/libs/image/kis_hdr_metadata.h
@@ -30,6 +30,12 @@ struct KisContentLightLevelInformation: public boost::equality_comparable<KisCon
return qFuzzyCompare(maxContentLightLevel, other.maxContentLightLevel)
&& qFuzzyCompare(maxFrameAverageLightLevel, other.maxFrameAverageLightLevel);
};
+
+ enum CalculationType {
+ XYZLuminance, ///< Calculate luminance by converting to xyz.
+ Rec2020Component, ///< Calculate luminance by converting to rec2020
+ RGBComponent ///< Calculate luminance on the RGB components if possible.
+ };
};
/**
diff --git a/libs/image/kis_image.cc b/libs/image/kis_image.cc
index 5a51c9c575..f23419541d 100644
--- a/libs/image/kis_image.cc
+++ b/libs/image/kis_image.cc
@@ -2103,7 +2103,7 @@ void KisImage::setContentLightLevelInformation(const std::optional<KisContentLig
}
}
-void KisImage::calculateContentLightLevelInformation()
+void KisImage::calculateContentLightLevelInformation(int type)
{
KisImageSignalVector emitSignals;
@@ -2113,7 +2113,8 @@ void KisImage::calculateContentLightLevelInformation()
KisProcessingApplicator::RECURSIVE | signalFlags,
emitSignals, actionName);
- KisSharedPtr<KisContentLightLevelProcessingVistor> visitor = new KisContentLightLevelProcessingVistor();
+ KisSharedPtr<KisContentLightLevelProcessingVistor> visitor =
+ new KisContentLightLevelProcessingVistor(KisContentLightLevelInformation::CalculationType(type));
applicator.applyVisitorAllFrames(visitor, KisStrokeJobData::SEQUENTIAL);
applicator.end();
diff --git a/libs/image/kis_image.h b/libs/image/kis_image.h
index 3c24502acc..4b3979a8de 100644
--- a/libs/image/kis_image.h
+++ b/libs/image/kis_image.h
@@ -839,7 +839,8 @@ public Q_SLOTS:
void stopIsolatedMode();
/// Calculates the content light level inside a stroke.
- void calculateContentLightLevelInformation();
+ /// @param type, see KisContentLightLevelInformation::CalculationType
+ void calculateContentLightLevelInformation(int type = 0);
public:
diff --git a/libs/image/processing/KisContentLightLevelProcessingVistor.cpp b/libs/image/processing/KisContentLightLevelProcessingVistor.cpp
index ad540235f7..f9a98f5c6b 100644
--- a/libs/image/processing/KisContentLightLevelProcessingVistor.cpp
+++ b/libs/image/processing/KisContentLightLevelProcessingVistor.cpp
@@ -5,18 +5,22 @@
*/
#include "KisContentLightLevelProcessingVistor.h"
#include <kis_hdr_metadata.h>
+#include <KoColorProfile.h>
+#include <KoColorProfileQuery.h>
#include "kis_group_layer.h"
#include "kis_iterator_ng.h"
#include "kis_raster_keyframe_channel.h"
struct KisContentLightLevelProcessingVistor::Private {
+ KisContentLightLevelInformation::CalculationType type;
QList<KisContentLightLevelInformation> clli;
};
-KisContentLightLevelProcessingVistor::KisContentLightLevelProcessingVistor()
+KisContentLightLevelProcessingVistor::KisContentLightLevelProcessingVistor(KisContentLightLevelInformation::CalculationType type)
: KisDoNothingProcessingVisitor(), d(new Private)
{
+ d->type = type;
}
KisContentLightLevelProcessingVistor::~KisContentLightLevelProcessingVistor()
@@ -50,32 +54,67 @@ KisContentLightLevelInformation KisContentLightLevelProcessingVistor::contentLig
KisContentLightLevelInformation KisContentLightLevelProcessingVistor::calculateForDev(KisPaintDeviceSP dev)
{
- /**
- * @brief xyzCS
- * We need the luminance, so we could either do complex luminance calculations
- * for each and every color space... Or we could convert to linear XYZ and only
- * test the Y value.
- */
- const KoColorSpace *xyzCS = KoColorSpaceRegistry::instance()->colorSpace(XYZAColorModelID.id(), Float32BitsColorDepthID.id());
- dev->convertTo(xyzCS, KoColorConversionTransformation::IntentRelativeColorimetric);
-
- QRectF imageBounds = dev->extent();
- KisHLineConstIteratorSP it = dev->createHLineConstIteratorNG(imageBounds.x(), imageBounds.y(), imageBounds.width());
-
KisContentLightLevelInformation clli;
double average = 0.0;
int divider = 0;
-
+ const QRectF imageBounds = dev->extent();
qDebug() << "preparing frame" << imageBounds;
- for (int y = 0; y < imageBounds.height(); y++) {
- for (int x = 0; x < imageBounds.width(); x++) {
- const KoXyzF32Traits::Pixel* pixel = reinterpret_cast<const KoXyzF32Traits::Pixel*> (it->rawDataConst());
- clli.maxContentLightLevel = qMax(clli.maxContentLightLevel, double(pixel->y));
- average += pixel->y;
- divider ++;
- it->nextPixel();
+
+ bool canConvertLinear = dev->colorSpace()->colorModelId() == RGBAColorModelID && dev->colorSpace()->profile()->getColorPrimaries() != PRIMARIES_UNSPECIFIED;
+
+ if ((d->type == KisContentLightLevelInformation::RGBComponent && canConvertLinear)
+ || d->type == KisContentLightLevelInformation::Rec2020Component){
+ if (d->type == KisContentLightLevelInformation::Rec2020Component) {
+ const KoColorSpace *rec2020CS = KoColorSpaceRegistry::instance()->colorSpace(RGBAColorModelID.id(),
+ Float32BitsColorDepthID.id(),
+ KoColorSpaceRegistry::instance()->p2020G10Profile());
+ dev->convertTo(rec2020CS, KoColorConversionTransformation::IntentRelativeColorimetric);
+ } else {
+ const KoColorProfile *linP = KoColorSpaceRegistry::instance()->profileFor(KoColorProfileQuery(dev->colorSpace()->profile()->getColorPrimaries(), TRC_LINEAR), true);
+ const KoColorSpace *linear = KoColorSpaceRegistry::instance()->colorSpace(RGBAColorModelID.id(),
+ Float32BitsColorDepthID.id(),
+ linP);
+ dev->convertTo(linear, KoColorConversionTransformation::IntentRelativeColorimetric);
+ }
+ KisHLineConstIteratorSP it = dev->createHLineConstIteratorNG(imageBounds.x(), imageBounds.y(), imageBounds.width());
+
+ QVector<float> channels(dev->colorSpace()->channelCount());
+ for (int y = 0; y < imageBounds.height(); y++) {
+ for (int x = 0; x < imageBounds.width(); x++) {
+ const quint8* pixel = it->rawDataConst();
+ dev->colorSpace()->normalisedChannelsValue(pixel, channels);
+
+ const double rgbMax = qMax(channels[0], qMax(channels[1], channels[2]));
+
+ average += rgbMax;
+ divider ++;
+ clli.maxContentLightLevel = qMax(clli.maxContentLightLevel, rgbMax);
+ it->nextPixel();
+ }
+ it->nextRow();
+ }
+ } else {
+ /**
+ * @brief xyzCS
+ * We need the luminance, so we could either do complex luminance calculations
+ * for each and every color space... Or we could convert to linear XYZ and only
+ * test the Y value.
+ */
+ const KoColorSpace *xyzCS = KoColorSpaceRegistry::instance()->colorSpace(XYZAColorModelID.id(), Float32BitsColorDepthID.id());
+ dev->convertTo(xyzCS, KoColorConversionTransformation::IntentRelativeColorimetric);
+
+ KisHLineConstIteratorSP it = dev->createHLineConstIteratorNG(imageBounds.x(), imageBounds.y(), imageBounds.width());
+
+ for (int y = 0; y < imageBounds.height(); y++) {
+ for (int x = 0; x < imageBounds.width(); x++) {
+ const KoXyzF32Traits::Pixel* pixel = reinterpret_cast<const KoXyzF32Traits::Pixel*> (it->rawDataConst());
+ clli.maxContentLightLevel = qMax(clli.maxContentLightLevel, double(pixel->y));
+ average += pixel->y;
+ divider ++;
+ it->nextPixel();
+ }
+ it->nextRow();
}
- it->nextRow();
}
clli.maxFrameAverageLightLevel = average / divider;
diff --git a/libs/image/processing/KisContentLightLevelProcessingVistor.h b/libs/image/processing/KisContentLightLevelProcessingVistor.h
index efcc370b87..1186d8c1cd 100644
--- a/libs/image/processing/KisContentLightLevelProcessingVistor.h
+++ b/libs/image/processing/KisContentLightLevelProcessingVistor.h
@@ -9,8 +9,8 @@
#include "kis_types.h"
#include <kis_do_nothing_processing_visitor.h>
#include <QScopedPointer>
+#include <kis_hdr_metadata.h>
-struct KisContentLightLevelInformation;
/**
* @brief The KisContentLightLevelProcessingVistor class
* This processing visitor checks the projection of the root level node,
@@ -20,7 +20,7 @@ class KisContentLightLevelProcessingVistor : public KisDoNothingProcessingVisito
{
public:
- KisContentLightLevelProcessingVistor();
+ KisContentLightLevelProcessingVistor(KisContentLightLevelInformation::CalculationType type = KisContentLightLevelInformation::XYZLuminance);
~KisContentLightLevelProcessingVistor() override;
using KisDoNothingProcessingVisitor::visit;
diff --git a/libs/ui/dialogs/kis_dlg_image_properties.cc b/libs/ui/dialogs/kis_dlg_image_properties.cc
index c846ce76e5..0ef68eaa4b 100644
--- a/libs/ui/dialogs/kis_dlg_image_properties.cc
+++ b/libs/ui/dialogs/kis_dlg_image_properties.cc
@@ -114,17 +114,25 @@ KisDlgImageProperties::KisDlgImageProperties(KisImageWSP image, KisDisplayColorC
updateHDRLightLevels();
updateHDRColorVolume();
- connect(m_page->btnCalculateClli, &QPushButton::clicked, d->image, &KisImage::calculateContentLightLevelInformation);
+ connect(m_page->btnCalculateClli, &QPushButton::clicked, this, &KisDlgImageProperties::slotCalculateLightLevels);
connect(d->image, &KisImage::sigContentLightLevelInformationChanged, this, &KisDlgImageProperties::updateHDRLightLevels);
connect(d->image, &KisImage::sigDiffuseWhiteLightLevelChanged, this, &KisDlgImageProperties::updateHDRLightLevels);
connect(d->image, &KisImage::sigColorVolumeInformationChanged, this, &KisDlgImageProperties::updateHDRColorVolume);
- connect(m_page->gbxDiffuseWhite, &QGroupBox::clicked, this, &KisDlgImageProperties::setHDRLightLevelsOnImage);
- connect(m_page->spnDiffuseWhite, &QDoubleSpinBox::valueChanged, this, &KisDlgImageProperties::setHDRLightLevelsOnImage);
+ connect(m_page->gbxDiffuseWhite, &QGroupBox::clicked, this, &KisDlgImageProperties::setHDRDiffuseLevelOnImage);
+ connect(m_page->spnDiffuseWhite, &QDoubleSpinBox::valueChanged, this, &KisDlgImageProperties::setHDRDiffuseLevelOnImage);
+
+ connect(m_page->gbxContentLightLevel, &QGroupBox::clicked, this, &KisDlgImageProperties::setHDRLightLevelsOnImage);
+ connect(m_page->spnMaxCll, &QDoubleSpinBox::valueChanged, this, &KisDlgImageProperties::setHDRLightLevelsOnImage);
+ connect(m_page->spnMaxFall, &QDoubleSpinBox::valueChanged, this, &KisDlgImageProperties::setHDRLightLevelsOnImage);
m_page->cmbColorVolumePresets->addItem(i18n("Rec. 2100 PQ"), "p2100-pq");
m_page->cmbColorVolumePresets->addItem(i18n("DCI-P3 D65"), "dci-p3-d65");
+ m_page->cmbLumiCalcType->addItem(i18n("XYZ Luminance"), KisContentLightLevelInformation::XYZLuminance);
+ m_page->cmbLumiCalcType->addItem(i18n("Rec 2020 Per Component"), KisContentLightLevelInformation::Rec2020Component);
+ m_page->cmbLumiCalcType->addItem(i18n("RGB Per Component"), KisContentLightLevelInformation::RGBComponent);
+
connect(m_page->cmbColorVolumePresets, &QComboBox::activated, this, &KisDlgImageProperties::changeColorVolumePreset);
connect(m_page->gbxColorVolume, &QGroupBox::clicked, &d->colorVolumeCompressor, &KisSignalCompressor::start);
connect(m_page->spnWhiteX, &QDoubleSpinBox::valueChanged, &d->colorVolumeCompressor, &KisSignalCompressor::start);
@@ -237,13 +245,13 @@ void KisDlgImageProperties::updateHDRLightLevels()
m_page->spnDiffuseWhite->setValue(80);
}
if (d->image->contentLightLevelInformation()) {
+ m_page->gbxContentLightLevel->setChecked(true);
double diffuseWhite = d->image->diffuseWhiteLightLevel()? *d->image->diffuseWhiteLightLevel(): 80.0;
KisContentLightLevelInformation clli = *d->image->contentLightLevelInformation();
- m_page->lblMaxCll->setText(i18n("%1 cd/m²").arg(QString::number(diffuseWhite*clli.maxContentLightLevel)));
- m_page->lblMaxFall->setText(i18n("%1 cd/m²").arg(QString::number(diffuseWhite*clli.maxFrameAverageLightLevel)));
+ m_page->spnMaxCll->setValue(clli.maxContentLightLevel*diffuseWhite);
+ m_page->spnMaxFall->setValue(clli.maxFrameAverageLightLevel*diffuseWhite);
} else {
- m_page->lblMaxCll->setText(i18n("Unknown"));
- m_page->lblMaxFall->setText(i18n("Unknown"));
+ m_page->gbxContentLightLevel->setChecked(false);
}
}
@@ -273,6 +281,19 @@ void KisDlgImageProperties::updateHDRColorVolume()
}
void KisDlgImageProperties::setHDRLightLevelsOnImage()
+{
+ if (m_page->gbxContentLightLevel->isChecked()) {
+ double diffuseWhite = d->image->diffuseWhiteLightLevel()? *d->image->diffuseWhiteLightLevel(): 80.0;
+ KisContentLightLevelInformation clli;
+ clli.maxContentLightLevel = m_page->spnMaxCll->value() / diffuseWhite;
+ clli.maxFrameAverageLightLevel = m_page->spnMaxFall->value() / diffuseWhite;
+ d->image->setContentLightLevelInformation(std::make_optional(clli));
+ } else {
+ d->image->setContentLightLevelInformation(std::nullopt);
+ }
+}
+
+void KisDlgImageProperties::setHDRDiffuseLevelOnImage()
{
if (m_page->gbxDiffuseWhite->isChecked()) {
d->image->setDiffuseWhiteLightLevel(std::make_optional(m_page->spnDiffuseWhite->value()));
@@ -341,6 +362,12 @@ void KisDlgImageProperties::changeColorVolumePreset()
}
}
+void KisDlgImageProperties::slotCalculateLightLevels()
+{
+ int type = m_page->cmbLumiCalcType->currentData().toInt();
+ d->image->calculateContentLightLevelInformation(type);
+}
+
void KisDlgImageProperties::slotColorSpaceChanged(const KoColorSpace *cs)
{
if (*d->image->profile() != *cs->profile() &&
diff --git a/libs/ui/dialogs/kis_dlg_image_properties.h b/libs/ui/dialogs/kis_dlg_image_properties.h
index b081667c31..3834753f2e 100644
--- a/libs/ui/dialogs/kis_dlg_image_properties.h
+++ b/libs/ui/dialogs/kis_dlg_image_properties.h
@@ -48,10 +48,12 @@ private Q_SLOTS:
void updateHDRLightLevels();
void updateHDRColorVolume();
+ void setHDRDiffuseLevelOnImage();
void setHDRLightLevelsOnImage();
void setHDRColorVolumeOnImage();
void changeColorVolumePreset();
+ void slotCalculateLightLevels();
void slotColorSpaceChanged(const KoColorSpace*);
private:
diff --git a/libs/ui/forms/wdgimageproperties.ui b/libs/ui/forms/wdgimageproperties.ui
index 2ea4555fc1..52c1fcbacb 100644
--- a/libs/ui/forms/wdgimageproperties.ui
+++ b/libs/ui/forms/wdgimageproperties.ui
@@ -11,7 +11,7 @@
<x>0</x>
<y>0</y>
<width>449</width>
- <height>504</height>
+ <height>522</height>
</rect>
</property>
<property name="windowTitle">
@@ -333,7 +333,7 @@
<string>Content Light Level Information</string>
</property>
<property name="checkable">
- <bool>false</bool>
+ <bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
@@ -353,17 +353,13 @@
</property>
</widget>
</item>
- <item row="0" column="1">
- <widget class="QLabel" name="lblMaxCll">
- <property name="text">
- <string>Unknown</string>
- </property>
- </widget>
- </item>
- <item row="1" column="1">
- <widget class="QLabel" name="lblMaxFall">
- <property name="text">
- <string>Unknown</string>
+ <item row="2" column="0">
+ <widget class="QComboBox" name="cmbLumiCalcType">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
</property>
</widget>
</item>
@@ -374,6 +370,26 @@
</property>
</widget>
</item>
+ <item row="0" column="1">
+ <widget class="QDoubleSpinBox" name="spnMaxCll">
+ <property name="suffix">
+ <string>cd/m²</string>
+ </property>
+ <property name="maximum">
+ <double>10000.000000000000000</double>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QDoubleSpinBox" name="spnMaxFall">
+ <property name="suffix">
+ <string>cd/m²</string>
+ </property>
+ <property name="maximum">
+ <double>10000.000000000000000</double>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</item>