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

Fix compression of CLL calculation action

Dmitry Kazakova46d36546f87
diff --git a/libs/image/commands_new/KisChangeImageHdrContentLightLevelCommand.cpp b/libs/image/commands_new/KisChangeImageHdrContentLightLevelCommand.cpp
index 555deb94cf..f918a6b181 100644
--- a/libs/image/commands_new/KisChangeImageHdrContentLightLevelCommand.cpp
+++ b/libs/image/commands_new/KisChangeImageHdrContentLightLevelCommand.cpp
@@ -43,6 +43,13 @@ int KisChangeImageHdrContentLightLevelCommand::id() const
return KisCommandUtils::ChangeImageHdrContentLightLevelId;
}
+bool KisChangeImageHdrContentLightLevelCommand::canMergeWith(const KUndo2Command *otherCommand) const
+{
+ const KisChangeImageHdrContentLightLevelCommand *other = dynamic_cast<const KisChangeImageHdrContentLightLevelCommand *>(otherCommand);
+ if (!other || other->m_image != m_image) return false;
+ return true;
+}
+
bool KisChangeImageHdrContentLightLevelCommand::mergeWith(const KUndo2Command *otherCommand)
{
const KisChangeImageHdrContentLightLevelCommand *other = dynamic_cast<const KisChangeImageHdrContentLightLevelCommand *>(otherCommand);
diff --git a/libs/image/commands_new/KisChangeImageHdrContentLightLevelCommand.h b/libs/image/commands_new/KisChangeImageHdrContentLightLevelCommand.h
index 5773bc7244..f59c5162c7 100644
--- a/libs/image/commands_new/KisChangeImageHdrContentLightLevelCommand.h
+++ b/libs/image/commands_new/KisChangeImageHdrContentLightLevelCommand.h
@@ -7,12 +7,13 @@
#define KISCHANGEIMAGEHDRMETADATACOMMAND_H
#include <kundo2command.h>
+#include <commands_new/KisAsynchronouslyMergeableCommandInterface.h>
#include <kis_types.h>
#include <kis_hdr_metadata.h>
#include "kritaimage_export.h"
#include <optional>
-class KRITAIMAGE_EXPORT KisChangeImageHdrContentLightLevelCommand : public KUndo2Command
+class KRITAIMAGE_EXPORT KisChangeImageHdrContentLightLevelCommand : public KUndo2Command, public KisAsynchronouslyMergeableCommandInterface
{
public:
KisChangeImageHdrContentLightLevelCommand(KisImageWSP image,
@@ -23,6 +24,7 @@ public:
void undo() override;
int id() const override;
+ bool canMergeWith(const KUndo2Command *other) const override;
bool mergeWith(const KUndo2Command *other) override;
private:
KisImageWSP m_image;
diff --git a/libs/image/kis_processing_applicator.cpp b/libs/image/kis_processing_applicator.cpp
index 32f3734c04..3bef54aa82 100644
--- a/libs/image/kis_processing_applicator.cpp
+++ b/libs/image/kis_processing_applicator.cpp
@@ -285,7 +285,7 @@ KisProcessingApplicator::KisProcessingApplicator(KisImageWSP image,
m_sharedAllFramesToken(new bool(false))
{
StrategyWithStatusPromise *strategy =
- new StrategyWithStatusPromise(name, m_image.data());
+ new StrategyWithStatusPromise(name, !flags.testFlag(READ_ONLY_ACTION) ? m_image.data() : nullptr);
m_successfullyCompletedFuture = strategy->m_successfullyCompleted.get_future();
@@ -308,7 +308,7 @@ KisProcessingApplicator::KisProcessingApplicator(KisImageWSP image,
applyCommand(new DisableUIUpdatesCommand(m_image, false), KisStrokeJobData::BARRIER);
}
- if (!m_nodes.isEmpty()) {
+ if (!m_nodes.isEmpty() && !m_flags.testFlag(READ_ONLY_ACTION)) {
applyCommand(new UpdateCommand(m_image, m_nodes, m_flags,
UpdateCommand::INITIALIZING,
m_sharedAllFramesToken));
@@ -448,7 +448,7 @@ void KisProcessingApplicator::explicitlyEmitFinalSignals()
{
KIS_ASSERT_RECOVER_RETURN(!m_finalSignalsEmitted);
- if (!m_nodes.isEmpty()) {
+ if (!m_nodes.isEmpty() && !m_flags.testFlag(READ_ONLY_ACTION)) {
applyCommand(new UpdateCommand(m_image, m_nodes, m_flags,
UpdateCommand::FINALIZING,
m_sharedAllFramesToken));
@@ -485,7 +485,9 @@ void KisProcessingApplicator::runSingleCommandStroke(KisImageSP image, KUndo2Com
KisProcessingApplicator applicator(image, 0,
KisProcessingApplicator::NONE,
KisImageSignalVector(),
- cmd->text());
+ cmd->text(),
+ nullptr,
+ cmd->id());
applicator.applyCommand(cmd, sequentiality, exclusivity);
applicator.end();
}
diff --git a/libs/image/kis_processing_applicator.h b/libs/image/kis_processing_applicator.h
index 2977270f2f..58fd454033 100644
--- a/libs/image/kis_processing_applicator.h
+++ b/libs/image/kis_processing_applicator.h
@@ -27,8 +27,11 @@ public:
NO_UI_UPDATES = 0x2,
SUPPORTS_WRAPAROUND_MODE = 0x4,
NO_IMAGE_UPDATES = 0x8,
- RECURSIVE_FRAME_TIMES = 0x10 ///< When there's a non-recursive applicator on all frames,
+ RECURSIVE_FRAME_TIMES = 0x10, ///< When there's a non-recursive applicator on all frames,
///< you might want to have the frame times be recursive, useful for group layers.
+ READ_ONLY_ACTION = 0x20, ///< Do not save undo commands into the global undo stack after the
+ ///< action has been completed. Also, do not emit any updates and do not
+ ///< invalidate any frames.
};
Q_DECLARE_FLAGS(ProcessingFlags, ProcessingFlag)
diff --git a/libs/ui/dialogs/kis_dlg_image_properties.cc b/libs/ui/dialogs/kis_dlg_image_properties.cc
index 2256aa9a6f..7665779914 100644
--- a/libs/ui/dialogs/kis_dlg_image_properties.cc
+++ b/libs/ui/dialogs/kis_dlg_image_properties.cc
@@ -35,6 +35,8 @@
#include <commands_new/KisChangeImageHdrDiffuseWhiteCommand.h>
#include <KisContentLightLevelProcessingVistor.h>
+#include <kis_signal_compressor_with_param.h>
+
#include "KisProofingConfigModel.h"
struct KisDlgImageProperties::Private {
@@ -325,8 +327,8 @@ void KisDlgImageProperties::setHDRLightLevelsOnImage()
optClli = std::make_optional(clli);
}
if (d->image->relativeContentLightLevelInformation() != optClli) {
- KUndo2Command *cmd = new KisChangeImageHdrContentLightLevelCommand(d->image, optClli);
- d->image->undoAdapter()->addCommand(cmd);
+ KisProcessingApplicator::runSingleCommandStroke(d->image,
+ new KisChangeImageHdrContentLightLevelCommand(d->image, optClli));
}
}
@@ -410,22 +412,35 @@ void KisDlgImageProperties::changeColorVolumePreset()
void KisDlgImageProperties::slotCalculateLightLevels()
{
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, d->image->bounds());
+ new KisContentLightLevelProcessingVistor(type, d->image->bounds());
+
+ KisProcessingApplicator::ProcessingFlags flags =
+ KisProcessingApplicator::RECURSIVE_FRAME_TIMES | KisProcessingApplicator::READ_ONLY_ACTION;
+ KisProcessingApplicator applicator(d->image, d->image->rootLayer(), flags);
- applicator.applyVisitorAllFrames(visitor, KisStrokeJobData::SEQUENTIAL);
+ applicator.applyVisitorAllFrames(visitor);
- auto cmd = new KisCommandUtils::LambdaCommand(
- [visitor, image = d->image] () {
+ // a poor-man implementation of a QFuture (which is Qt6-only),
+ // the proxy object will notify us manually when the visitor
+ // has completed its execution
+ QSharedPointer<FunctionToSignalProxy> completionSignalProxy(new FunctionToSignalProxy);
+ connect(completionSignalProxy.get(), &FunctionToSignalProxy::timeout, this,
+ [visitor, image = d->image]() {
auto info = visitor->contentLightLevelInformation();
- return new KisChangeImageHdrContentLightLevelCommand(image, info);
+ if (info != image->relativeContentLightLevelInformation()) {
+ KisProcessingApplicator::runSingleCommandStroke(image,
+ new KisChangeImageHdrContentLightLevelCommand(image, info));
+ }
});
- applicator.applyCommand(cmd, KisStrokeJobData::SEQUENTIAL);
+
+ // add the command **after** the signal has been set up; this
+ // is not a QFuture, so it cannot store the actual "finished"
+ // state
+ applicator.applyCommand(new KisCommandUtils::LambdaCommand([completionSignalProxy]() {
+ completionSignalProxy->start();
+ return nullptr;
+ }));
applicator.end();
}