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++
Implement commands for setting HDR metadata.
Wolthera van Hövell tot Westerflier0cc1804508e8
diff --git a/libs/command/kis_command_ids.h b/libs/command/kis_command_ids.hindex b1ae06d390..5d6725f008 100644--- a/libs/command/kis_command_ids.h+++ b/libs/command/kis_command_ids.h@@ -44,7 +44,10 @@ enum CommandId {KoShapeMergeTextPropertiesCommandId,ImageAnimSettingCommandId,SvgTextChangeTransformsOnRangeCommandId,- SvgTextPathInfoChangeCommandId+ SvgTextPathInfoChangeCommandId,+ ChangeImageHdrContentLightLevelId,+ ChangeImageHdrColorVolumeId,+ ChangeImageHdrDiffuseWhiteId};}diff --git a/libs/image/CMakeLists.txt b/libs/image/CMakeLists.txtindex 70fa682c8b..a9361ee5f5 100644--- a/libs/image/CMakeLists.txt+++ b/libs/image/CMakeLists.txt@@ -122,6 +122,9 @@ set(kritaimage_LIB_SRCScommands_new/KisLazyCreateTransformMaskKeyframesCommand.cppcommands_new/KisChangeCloneLayersCommand.cppcommands_new/KisLayerCollapseCommand.cpp+ commands_new/KisChangeImageHdrContentLightLevelCommand.cpp+ commands_new/KisChangeImageHdrColorVolumeCommand.cpp+ commands_new/KisChangeImageHdrDiffuseWhiteCommand.cppprocessing/kis_do_nothing_processing_visitor.cppprocessing/kis_simple_processing_visitor.cppprocessing/kis_convert_color_space_processing_visitor.cppdiff --git a/libs/image/commands_new/KisChangeImageHdrColorVolumeCommand.cpp b/libs/image/commands_new/KisChangeImageHdrColorVolumeCommand.cppnew file mode 100644index 0000000000..fdcc2f79ae--- /dev/null+++ b/libs/image/commands_new/KisChangeImageHdrColorVolumeCommand.cpp@@ -0,0 +1,52 @@+/*+ * SPDX-FileCopyrightText: 2026 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#include "KisChangeImageHdrColorVolumeCommand.h"+#include "kis_command_ids.h"+#include <kis_image.h>++KisChangeImageHdrColorVolumeCommand::KisChangeImageHdrColorVolumeCommand(KisImageWSP image,+ std::optional<KisColorVolumeInformation> cvi,+ KUndo2Command *parent)+ : KUndo2Command(kundo2_i18n("Set HDR Color Volume Information"), parent)+ , m_image(image)+ , m_cvi(cvi)+{+ KisImageSP img = m_image.toStrongRef();+ if (img) {+ m_cvi = img->colorVolumeInformation();+ }+}++void KisChangeImageHdrColorVolumeCommand::redo()+{+ KisImageSP img = m_image.toStrongRef();+ if (!img) return;++ img->setColorVolumeInformation(m_cvi);++}++void KisChangeImageHdrColorVolumeCommand::undo()+{+ KisImageSP img = m_image.toStrongRef();+ if (!img) return;++ img->setColorVolumeInformation(m_oldCvi);+}++int KisChangeImageHdrColorVolumeCommand::id() const+{+ return KisCommandUtils::ChangeImageHdrColorVolumeId;+}++bool KisChangeImageHdrColorVolumeCommand::mergeWith(const KUndo2Command *otherCommand)+{+ const KisChangeImageHdrColorVolumeCommand *other = dynamic_cast<const KisChangeImageHdrColorVolumeCommand *>(otherCommand);+ if (!other || other->m_image != m_image) return false;++ m_cvi = other->m_cvi;+ return true;+}diff --git a/libs/image/commands_new/KisChangeImageHdrColorVolumeCommand.h b/libs/image/commands_new/KisChangeImageHdrColorVolumeCommand.hnew file mode 100644index 0000000000..c0c4080919--- /dev/null+++ b/libs/image/commands_new/KisChangeImageHdrColorVolumeCommand.h@@ -0,0 +1,32 @@+/*+ * SPDX-FileCopyrightText: 2026 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#ifndef KISCHANGEIMAGEHDRCOLORVOLUMECOMMAND_H+#define KISCHANGEIMAGEHDRCOLORVOLUMECOMMAND_H++#include <kundo2command.h>+#include <kis_types.h>+#include <kis_hdr_metadata.h>+#include "kritaimage_export.h"++class KRITAIMAGE_EXPORT KisChangeImageHdrColorVolumeCommand : public KUndo2Command+{+public:+ KisChangeImageHdrColorVolumeCommand(KisImageWSP image,+ std::optional<KisColorVolumeInformation> cvi,+ KUndo2Command *parent = nullptr);++ void redo() override;+ void undo() override;++ int id() const override;+ bool mergeWith(const KUndo2Command *other) override;+private:+ KisImageWSP m_image;+ std::optional<KisColorVolumeInformation> m_cvi;+ std::optional<KisColorVolumeInformation> m_oldCvi;+};++#endif // KISCHANGEIMAGEHDRMETADATACOMMAND_Hdiff --git a/libs/image/commands_new/KisChangeImageHdrContentLightLevelCommand.cpp b/libs/image/commands_new/KisChangeImageHdrContentLightLevelCommand.cppnew file mode 100644index 0000000000..555deb94cf--- /dev/null+++ b/libs/image/commands_new/KisChangeImageHdrContentLightLevelCommand.cpp@@ -0,0 +1,53 @@+/*+ * SPDX-FileCopyrightText: 2026 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#include "KisChangeImageHdrContentLightLevelCommand.h"+#include "kis_command_ids.h"+#include <kis_image.h>++KisChangeImageHdrContentLightLevelCommand::KisChangeImageHdrContentLightLevelCommand(KisImageWSP image,+ std::optional<KisRelativeContentLightLevelInformation> clli,+ KUndo2Command *parent)+ : KUndo2Command(kundo2_i18n("Set HDR Content Light Level"), parent)+ , m_image(image)+ , m_clli(clli)+{+ KisImageSP img = m_image.toStrongRef();+ if (img) {+ m_oldClli = img->relativeContentLightLevelInformation();+ }+}++void KisChangeImageHdrContentLightLevelCommand::redo()+{+ KisImageSP img = m_image.toStrongRef();+ if (!img) return;++ if (img->relativeContentLightLevelInformation() != m_clli) {+ img->setRelativeContentLightLevelInformation(m_clli);+ }+}++void KisChangeImageHdrContentLightLevelCommand::undo()+{+ KisImageSP img = m_image.toStrongRef();+ if (!img) return;++ img->setRelativeContentLightLevelInformation(m_oldClli);+}++int KisChangeImageHdrContentLightLevelCommand::id() const+{+ return KisCommandUtils::ChangeImageHdrContentLightLevelId;+}++bool KisChangeImageHdrContentLightLevelCommand::mergeWith(const KUndo2Command *otherCommand)+{+ const KisChangeImageHdrContentLightLevelCommand *other = dynamic_cast<const KisChangeImageHdrContentLightLevelCommand *>(otherCommand);+ if (!other || other->m_image != m_image) return false;++ m_clli = other->m_clli;+ return true;+}diff --git a/libs/image/commands_new/KisChangeImageHdrContentLightLevelCommand.h b/libs/image/commands_new/KisChangeImageHdrContentLightLevelCommand.hnew file mode 100644index 0000000000..75b6246a9a--- /dev/null+++ b/libs/image/commands_new/KisChangeImageHdrContentLightLevelCommand.h@@ -0,0 +1,32 @@+/*+ * SPDX-FileCopyrightText: 2026 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#ifndef KISCHANGEIMAGEHDRMETADATACOMMAND_H+#define KISCHANGEIMAGEHDRMETADATACOMMAND_H++#include <kundo2command.h>+#include <kis_types.h>+#include <kis_hdr_metadata.h>+#include "kritaimage_export.h"++class KRITAIMAGE_EXPORT KisChangeImageHdrContentLightLevelCommand : public KUndo2Command+{+public:+ KisChangeImageHdrContentLightLevelCommand(KisImageWSP image,+ std::optional<KisRelativeContentLightLevelInformation> clli,+ KUndo2Command *parent = nullptr);++ void redo() override;+ void undo() override;++ int id() const override;+ bool mergeWith(const KUndo2Command *other) override;+private:+ KisImageWSP m_image;+ std::optional<KisRelativeContentLightLevelInformation> m_clli;+ std::optional<KisRelativeContentLightLevelInformation> m_oldClli;+};++#endif // KISCHANGEIMAGEHDRMETADATACOMMAND_Hdiff --git a/libs/image/commands_new/KisChangeImageHdrDiffuseWhiteCommand.cpp b/libs/image/commands_new/KisChangeImageHdrDiffuseWhiteCommand.cppnew file mode 100644index 0000000000..c0e17ac6ee--- /dev/null+++ b/libs/image/commands_new/KisChangeImageHdrDiffuseWhiteCommand.cpp@@ -0,0 +1,51 @@+/*+ * SPDX-FileCopyrightText: 2026 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#include "KisChangeImageHdrDiffuseWhiteCommand.h"+#include "kis_command_ids.h"+#include <kis_image.h>++KisChangeImageHdrDiffuseWhiteCommand::KisChangeImageHdrDiffuseWhiteCommand(KisImageWSP image,+ std::optional<double> diffuseWhite,+ KUndo2Command *parent)+ : KUndo2Command(kundo2_i18n("Set HDR Diffuse White Light Level"), parent)+ , m_image(image)+ , m_diffuseWhite(diffuseWhite)+{+ KisImageSP img = m_image.toStrongRef();+ if (img) {+ m_diffuseWhite = img->diffuseWhiteLightLevel();+ }+}++void KisChangeImageHdrDiffuseWhiteCommand::redo()+{+ KisImageSP img = m_image.toStrongRef();+ if (!img) return;++ img->setDiffuseWhiteLightLevel(m_diffuseWhite);+}++void KisChangeImageHdrDiffuseWhiteCommand::undo()+{+ KisImageSP img = m_image.toStrongRef();+ if (!img) return;++ img->setDiffuseWhiteLightLevel(m_oldDiffuseWhite);+}++int KisChangeImageHdrDiffuseWhiteCommand::id() const+{+ return KisCommandUtils::ChangeImageHdrDiffuseWhiteId;+}++bool KisChangeImageHdrDiffuseWhiteCommand::mergeWith(const KUndo2Command *otherCommand)+{+ const KisChangeImageHdrDiffuseWhiteCommand *other = dynamic_cast<const KisChangeImageHdrDiffuseWhiteCommand *>(otherCommand);+ if (!other || other->m_image != m_image) return false;++ m_diffuseWhite = other->m_diffuseWhite;+ return true;+}diff --git a/libs/image/commands_new/KisChangeImageHdrDiffuseWhiteCommand.h b/libs/image/commands_new/KisChangeImageHdrDiffuseWhiteCommand.hnew file mode 100644index 0000000000..ac7cb87673--- /dev/null+++ b/libs/image/commands_new/KisChangeImageHdrDiffuseWhiteCommand.h@@ -0,0 +1,31 @@+/*+ * SPDX-FileCopyrightText: 2026 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#ifndef KISCHANGEIMAGEHDRDIFFUSEWHITECOMMAND_H+#define KISCHANGEIMAGEHDRDIFFUSEWHITECOMMAND_H++#include <kundo2command.h>+#include <kis_types.h>+#include "kritaimage_export.h"++class KRITAIMAGE_EXPORT KisChangeImageHdrDiffuseWhiteCommand : public KUndo2Command+{+public:+ KisChangeImageHdrDiffuseWhiteCommand(KisImageWSP image,+ std::optional<double> diffuseWhite,+ KUndo2Command *parent = nullptr);++ void redo() override;+ void undo() override;++ int id() const override;+ bool mergeWith(const KUndo2Command *other) override;+private:+ KisImageWSP m_image;+ std::optional<double> m_diffuseWhite;+ std::optional<double> m_oldDiffuseWhite;+};++#endif // KISCHANGEIMAGEHDRDIFFUSEWHITECOMMAND_Hdiff --git a/libs/image/kis_image.cc b/libs/image/kis_image.ccindex a37d10ff03..63ecbdf696 100644--- a/libs/image/kis_image.cc+++ b/libs/image/kis_image.cc@@ -20,7 +20,6 @@#include <klocalizedstring.h>-#include "KisContentLightLevelProcessingVistor.h"#include "KoColorSpaceRegistry.h"#include "KoColor.h"#include "KoColorProfile.h"@@ -2103,26 +2102,6 @@ void KisImage::setRelativeContentLightLevelInformation(const std::optional<KisRe}}-void KisImage::calculateContentLightLevelInformation(int type)-{-- KisImageSignalVector emitSignals;- KUndo2MagicString actionName;- KisProcessingApplicator::ProcessingFlags signalFlags = KisProcessingApplicator::NO_UI_UPDATES | KisProcessingApplicator::RECURSIVE_FRAME_TIMES;- KisProcessingApplicator applicator(this, m_d->rootLayer,- signalFlags,- emitSignals, actionName);-- KisSharedPtr<KisContentLightLevelProcessingVistor> visitor =- new KisContentLightLevelProcessingVistor(KisRelativeContentLightLevelInformation::CalculationType(type));- applicator.applyVisitorAllFrames(visitor, KisStrokeJobData::SEQUENTIAL);- applicator.end();-- waitForDone();- m_d->relativeContentLightLevelInformation = std::make_optional(visitor->contentLightLevelInformation());- emit sigContentLightLevelInformationChanged();-}-std::optional<KisColorVolumeInformation> KisImage::colorVolumeInformation() const{return m_d->colorVolumeInformation;diff --git a/libs/image/kis_image.h b/libs/image/kis_image.hindex 59f8ad8623..165d7e4476 100644--- a/libs/image/kis_image.h+++ b/libs/image/kis_image.h@@ -838,10 +838,6 @@ public:public Q_SLOTS:void stopIsolatedMode();- /// Calculates the content light level inside a stroke.- /// @param type, see KisContentLightLevelInformation::CalculationType- void calculateContentLightLevelInformation(int type = 0);-public:KisNodeSP isolationRootNode() const;diff --git a/libs/image/processing/KisContentLightLevelProcessingVistor.h b/libs/image/processing/KisContentLightLevelProcessingVistor.hindex 7633bc8ccc..d95310efe1 100644--- a/libs/image/processing/KisContentLightLevelProcessingVistor.h+++ b/libs/image/processing/KisContentLightLevelProcessingVistor.h@@ -10,13 +10,14 @@#include <kis_do_nothing_processing_visitor.h>#include <QScopedPointer>#include <kis_hdr_metadata.h>+#include "kritaimage_export.h"/*** @brief The KisContentLightLevelProcessingVistor class* This processing visitor checks the projection of the root level node,* and calculates the Content Light Level Information for it.*/-class KisContentLightLevelProcessingVistor : public KisDoNothingProcessingVisitor+class KRITAIMAGE_EXPORT KisContentLightLevelProcessingVistor : public KisDoNothingProcessingVisitor{public:diff --git a/libs/ui/animation/KisDlgAnimationRenderer.cpp b/libs/ui/animation/KisDlgAnimationRenderer.cppindex b0fa11eb39..245f862964 100644--- a/libs/ui/animation/KisDlgAnimationRenderer.cpp+++ b/libs/ui/animation/KisDlgAnimationRenderer.cpp@@ -559,8 +559,8 @@ bool KisDlgAnimationRenderer::supportsAudio(const QString &videoType)KisHDRMetadataOptions KisDlgAnimationRenderer::optionsFromImage(){KisHDRMetadataOptions hdrOptions;- if (m_image->contentLightLevelInformation()) {- hdrOptions.clli = *m_image->contentLightLevelInformation();+ if (m_image->relativeContentLightLevelInformation()) {+ hdrOptions.clli = *m_image->relativeContentLightLevelInformation();}if (m_image->colorVolumeInformation()) {hdrOptions.cvi = *m_image->colorVolumeInformation();diff --git a/libs/ui/dialogs/kis_dlg_image_properties.cc b/libs/ui/dialogs/kis_dlg_image_properties.ccindex 338fcf591e..e67ff4e9bd 100644--- a/libs/ui/dialogs/kis_dlg_image_properties.cc+++ b/libs/ui/dialogs/kis_dlg_image_properties.cc@@ -24,6 +24,17 @@#include <kis_display_color_converter.h>#include <KisWidgetConnectionUtils.h>+#include <kis_processing_applicator.h>+#include <kis_image_signal_router.h>+#include <kis_undo_adapter.h>+#include <kis_types.h>+#include <kis_group_layer.h>++#include <commands_new/KisChangeImageHdrContentLightLevelCommand.h>+#include <commands_new/KisChangeImageHdrColorVolumeCommand.h>+#include <commands_new/KisChangeImageHdrDiffuseWhiteCommand.h>+#include <KisContentLightLevelProcessingVistor.h>+#include "KisProofingConfigModel.h"struct KisDlgImageProperties::Private {@@ -248,12 +259,13 @@ void KisDlgImageProperties::updateHDRLightLevels()m_page->gbxDiffuseWhite->setChecked(false);m_page->spnDiffuseWhite->setValue(80);}- if (d->image->contentLightLevelInformation()) {+ if (d->image->relativeContentLightLevelInformation()) {m_page->gbxContentLightLevel->setChecked(true);double diffuseWhite = d->image->diffuseWhiteLightLevel()? *d->image->diffuseWhiteLightLevel(): 80.0;- KisRelativeContentLightLevelInformation clli = *d->image->contentLightLevelInformation();+ KisRelativeContentLightLevelInformation clli = *d->image->relativeContentLightLevelInformation();m_page->spnMaxCll->setValue(clli.maxContentLightLevel*diffuseWhite);m_page->spnMaxFall->setValue(clli.maxFrameAverageLightLevel*diffuseWhite);+ m_page->cmbLumiCalcType->setCurrentIndex(clli.type);} else {m_page->gbxContentLightLevel->setChecked(false);}@@ -286,28 +298,38 @@ void KisDlgImageProperties::updateHDRColorVolume()void KisDlgImageProperties::setHDRLightLevelsOnImage(){+ KUndo2Command *cmd;if (m_page->gbxContentLightLevel->isChecked()) {double diffuseWhite = d->image->diffuseWhiteLightLevel()? *d->image->diffuseWhiteLightLevel(): 80.0;KisRelativeContentLightLevelInformation clli;clli.maxContentLightLevel = m_page->spnMaxCll->value() / diffuseWhite;clli.maxFrameAverageLightLevel = m_page->spnMaxFall->value() / diffuseWhite;- d->image->setRelativeContentLightLevelInformation(std::make_optional(clli));+ clli.type = KisRelativeContentLightLevelInformation::CalculationType(m_page->cmbLumiCalcType->currentData().toInt());+ cmd = new KisChangeImageHdrContentLightLevelCommand(d->image, std::make_optional(clli));} else {- d->image->setRelativeContentLightLevelInformation(std::nullopt);+ cmd = new KisChangeImageHdrContentLightLevelCommand(d->image, std::nullopt);+ }+ if (cmd) {+ d->image->undoAdapter()->addCommand(cmd);}}void KisDlgImageProperties::setHDRDiffuseLevelOnImage(){+ KUndo2Command *cmd;if (m_page->gbxDiffuseWhite->isChecked()) {- d->image->setDiffuseWhiteLightLevel(std::make_optional(m_page->spnDiffuseWhite->value()));+ cmd = new KisChangeImageHdrDiffuseWhiteCommand(d->image, std::make_optional(m_page->spnDiffuseWhite->value()));} else {- d->image->setDiffuseWhiteLightLevel(std::nullopt);+ cmd = new KisChangeImageHdrDiffuseWhiteCommand(d->image, std::nullopt);+ }+ if (cmd) {+ d->image->undoAdapter()->addCommand(cmd);}}void KisDlgImageProperties::setHDRColorVolumeOnImage(){+ KUndo2Command *cmd;if (m_page->gbxColorVolume->isChecked()) {KisColorVolumeInformation cvi;@@ -320,9 +342,12 @@ void KisDlgImageProperties::setHDRColorVolumeOnImage()cvi.maxLuminance = m_page->spnMaxLuminance->value();cvi.minLuminance = m_page->spnMinLuminance->value();- d->image->setColorVolumeInformation(std::make_optional(cvi));+ cmd = new KisChangeImageHdrColorVolumeCommand(d->image, std::make_optional(cvi));} else {- d->image->setColorVolumeInformation(std::nullopt);+ cmd = new KisChangeImageHdrColorVolumeCommand(d->image, std::nullopt);+ }+ if (cmd) {+ d->image->undoAdapter()->addCommand(cmd);}}@@ -366,10 +391,24 @@ void KisDlgImageProperties::changeColorVolumePreset()}}+void KisDlgImageProperties::slotCalculateLightLevels(){- int type = m_page->cmbLumiCalcType->currentData().toInt();- d->image->calculateContentLightLevelInformation(type);+ KisRelativeContentLightLevelInformation::CalculationType type = KisRelativeContentLightLevelInformation::CalculationType(m_page->cmbLumiCalcType->currentData().toInt());++ KisProcessingApplicator::ProcessingFlags signalFlags = KisProcessingApplicator::NO_UI_UPDATES | KisProcessingApplicator::RECURSIVE_FRAME_TIMES;+ KisProcessingApplicator applicator(d->image, d->image->rootLayer(),+ signalFlags);++ KisSharedPtr<KisContentLightLevelProcessingVistor> visitor =+ new KisContentLightLevelProcessingVistor(type);+ applicator.applyVisitorAllFrames(visitor, KisStrokeJobData::SEQUENTIAL);+ applicator.end();++ d->image->waitForDone();++ KUndo2Command *cmd = new KisChangeImageHdrContentLightLevelCommand(d->image, std::make_optional(visitor->contentLightLevelInformation()));+ d->image->undoAdapter()->addCommand(cmd);}void KisDlgImageProperties::slotColorSpaceChanged(const KoColorSpace *cs)