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 transform tool work with HDR canvas.

Wolthera van Hövell tot Westerflierb5be85482554
diff --git a/libs/ui/canvas/kis_display_color_converter.cpp b/libs/ui/canvas/kis_display_color_converter.cpp
index 57eb7efc0a..15a6c988f9 100644
--- a/libs/ui/canvas/kis_display_color_converter.cpp
+++ b/libs/ui/canvas/kis_display_color_converter.cpp
@@ -725,11 +725,28 @@ QColor KisDisplayColorConverter::convertColorToDisplayColorSpace(const KoColor c
return QColor::fromRgbF(sorted[0], sorted[1], sorted[2], sorted[3]);
}
-QImage KisDisplayColorConverter::convertImageToDisplayColorSpace(KisPaintDeviceSP srcDevice) const
+QImage KisDisplayColorConverter::convertImageToDisplayColorSpace(KisPaintDeviceSP srcDevice, QRect source, bool applyOcio) const
{
KisPaintDeviceSP conversionDevice = new KisPaintDevice(*srcDevice.data());
+ const QRect s = source.isValid()? source: conversionDevice->exactBounds();
+
+ if (m_d->useOcio() && applyOcio) {
+ KIS_ASSERT_RECOVER(m_d->ocioInputColorSpace()->pixelSize() == 16) {
+ return QImage();
+ }
+
+ conversionDevice->convertTo(m_d->ocioInputColorSpace());
+ KisSequentialIterator it(conversionDevice, s);
+ int numConseqPixels = it.nConseqPixels();
+ while (it.nextPixels(numConseqPixels)) {
+ numConseqPixels = it.nConseqPixels();
+ m_d->displayFilter->filter(it.rawData(), numConseqPixels);
+ }
+ conversionDevice->setProfile(m_d->ocioOutputProfile(), 0);
+ }
+
conversionDevice->convertTo(m_d->openGLSurfaceColorSpace(Float32BitsColorDepthID), m_d->multiSurfaceDisplayConfig.intent, m_d->multiSurfaceDisplayConfig.conversionFlags);
- return conversionDevice->convertToQImage(m_d->openGLSurfaceProfile(), m_d->multiSurfaceDisplayConfig.intent, m_d->multiSurfaceDisplayConfig.conversionFlags);
+ return conversionDevice->convertToQImage(m_d->openGLSurfaceProfile(), s, m_d->multiSurfaceDisplayConfig.intent, m_d->multiSurfaceDisplayConfig.conversionFlags);
}
KisHandlePalette KisDisplayColorConverter::handlePaletteForDisplayColorSpace() const
diff --git a/libs/ui/canvas/kis_display_color_converter.h b/libs/ui/canvas/kis_display_color_converter.h
index a28603f55f..b3b9127fef 100644
--- a/libs/ui/canvas/kis_display_color_converter.h
+++ b/libs/ui/canvas/kis_display_color_converter.h
@@ -81,7 +81,15 @@ public:
*/
QColor convertColorToDisplayColorSpace(const KoColor color, bool applyOcio = false) const;
- QImage convertImageToDisplayColorSpace(KisPaintDeviceSP srcDevice) const;
+ /**
+ * @brief convertImageToDisplayColorSpace
+ * Same as convertColorToDisplayColorSpace, but then for a KisPaintDevice.
+ * @param srcDevice -- src device to process.
+ * @param source -- source rect.
+ * @param applyOcio -- whether to also apply OCIO. Only useful for previews and not UI elements.
+ * @return a QImage in the display color space.
+ */
+ QImage convertImageToDisplayColorSpace(KisPaintDeviceSP srcDevice, QRect source = QRect(), bool applyOcio = false) const;
/**
* @brief handlePaletteForDisplayColorSpace
diff --git a/libs/ui/tool/KisAsyncColorSamplerHelper.cpp b/libs/ui/tool/KisAsyncColorSamplerHelper.cpp
index b929b123fc..cd14f52afb 100644
--- a/libs/ui/tool/KisAsyncColorSamplerHelper.cpp
+++ b/libs/ui/tool/KisAsyncColorSamplerHelper.cpp
@@ -198,6 +198,7 @@ bool KisAsyncColorSamplerHelper::isActive() const
void KisAsyncColorSamplerHelper::activate(bool sampleCurrentLayer, bool pickFgColor)
{
+
KIS_SAFE_ASSERT_RECOVER_RETURN(!m_d->isActive);
m_d->isActive = true;
diff --git a/plugins/tools/tool_transform2/kis_free_transform_strategy.cpp b/plugins/tools/tool_transform2/kis_free_transform_strategy.cpp
index ac78dcaafc..5a666a4ab4 100644
--- a/plugins/tools/tool_transform2/kis_free_transform_strategy.cpp
+++ b/plugins/tools/tool_transform2/kis_free_transform_strategy.cpp
@@ -13,6 +13,7 @@
#include <KoResourcePaths.h>
+#include "KoColorDisplayRendererInterface.h"
#include "kis_coordinates_converter.h"
#include "tool_transform_args.h"
#include "transform_transaction_properties.h"
@@ -350,7 +351,7 @@ QCursor KisFreeTransformStrategy::getCurrentCursor() const
return cursor;
}
-void KisFreeTransformStrategy::paint(QPainter &gc)
+void KisFreeTransformStrategy::paint(QPainter &gc, const KoColorDisplayRendererInterface *displayRendererInterface)
{
gc.save();
@@ -416,7 +417,7 @@ void KisFreeTransformStrategy::paint(QPainter &gc)
pen[0].setCosmetic(true);
pen[1].setWidth(decorationThickness() * 2);
pen[1].setCosmetic(true);
- pen[1].setColor(Qt::lightGray);
+ pen[1].setColor(displayRendererInterface->convertColorToDisplayColorSpace(KoColor(Qt::lightGray, KoColorSpaceRegistry::instance()->rgb8())));
for (int i = 1; i >= 0; --i) {
gc.setPen(pen[i]);
diff --git a/plugins/tools/tool_transform2/kis_free_transform_strategy.h b/plugins/tools/tool_transform2/kis_free_transform_strategy.h
index a6edc77479..be7d32c568 100644
--- a/plugins/tools/tool_transform2/kis_free_transform_strategy.h
+++ b/plugins/tools/tool_transform2/kis_free_transform_strategy.h
@@ -32,7 +32,7 @@ public:
void setTransformFunction(const QPointF &mousePos, bool perspectiveModifierActive, bool shiftModifierActive, bool altModifierActive) override;
bool shiftModifierIsUsed() const override;
- void paint(QPainter &gc) override;
+ void paint(QPainter &gc, const KoColorDisplayRendererInterface *displayRendererInterface) override;
QCursor getCurrentCursor() const override;
void externalConfigChanged() override;
diff --git a/plugins/tools/tool_transform2/kis_liquify_transform_strategy.cpp b/plugins/tools/tool_transform2/kis_liquify_transform_strategy.cpp
index 3a90a6d344..d58f0b74f1 100644
--- a/plugins/tools/tool_transform2/kis_liquify_transform_strategy.cpp
+++ b/plugins/tools/tool_transform2/kis_liquify_transform_strategy.cpp
@@ -114,8 +114,9 @@ QCursor KisLiquifyTransformStrategy::getCurrentCursor() const
return Qt::BlankCursor;
}
-void KisLiquifyTransformStrategy::paint(QPainter &gc)
+void KisLiquifyTransformStrategy::paint(QPainter &gc, const KoColorDisplayRendererInterface *displayRendererInterface)
{
+ Q_UNUSED(displayRendererInterface)
// Draw preview image
if (m_d->recalculateOnNextRedraw) {
diff --git a/plugins/tools/tool_transform2/kis_liquify_transform_strategy.h b/plugins/tools/tool_transform2/kis_liquify_transform_strategy.h
index 8cc38b7e6f..c1804c6f98 100644
--- a/plugins/tools/tool_transform2/kis_liquify_transform_strategy.h
+++ b/plugins/tools/tool_transform2/kis_liquify_transform_strategy.h
@@ -30,7 +30,7 @@ public:
~KisLiquifyTransformStrategy() override;
void setTransformFunction(const QPointF &mousePos, bool perspectiveModifierActive, bool shiftModifierActive);
- void paint(QPainter &gc) override;
+ void paint(QPainter &gc, const KoColorDisplayRendererInterface *displayRendererInterface) override;
QCursor getCurrentCursor() const override;
QPainterPath getCursorOutline() const override;
diff --git a/plugins/tools/tool_transform2/kis_mesh_transform_strategy.cpp b/plugins/tools/tool_transform2/kis_mesh_transform_strategy.cpp
index 55e431d66d..0152d8af6c 100644
--- a/plugins/tools/tool_transform2/kis_mesh_transform_strategy.cpp
+++ b/plugins/tools/tool_transform2/kis_mesh_transform_strategy.cpp
@@ -5,6 +5,7 @@
*/
#include "kis_mesh_transform_strategy.h"
+#include "KoColorDisplayRendererInterface.h"
#include "tool_transform_args.h"
#include <QPointF>
@@ -260,7 +261,7 @@ void KisMeshTransformStrategy::verifyExpectedMeshSize()
}
}
-void KisMeshTransformStrategy::paint(QPainter &gc)
+void KisMeshTransformStrategy::paint(QPainter &gc, const KoColorDisplayRendererInterface *displayRendererInterface)
{
gc.save();
@@ -274,15 +275,16 @@ void KisMeshTransformStrategy::paint(QPainter &gc)
gc.setTransform(KisTransformUtils::imageToFlakeTransform(m_d->converter), true);
KisHandlePainterHelper handlePainter(&gc, 0.5 * KisTransformUtils::handleRadius, decorationThickness());
+ KisHandlePalette palette = displayRendererInterface->handlePaletteForDisplayColorSpace();
for (auto it = m_d->currentArgs.meshTransform()->beginSegments();
it != m_d->currentArgs.meshTransform()->endSegments();
++it) {
if (m_d->hoveredSegment && it.segmentIndex() == *m_d->hoveredSegment) {
- handlePainter.setHandleStyle(KisHandleStyle::highlightedPrimaryHandlesWithSolidOutline());
+ handlePainter.setHandleStyle(KisHandleStyle::highlightedPrimaryHandlesWithSolidOutline(palette));
} else {
- handlePainter.setHandleStyle(KisHandleStyle::primarySelection());
+ handlePainter.setHandleStyle(KisHandleStyle::primarySelection(palette));
}
QPainterPath path;
@@ -305,15 +307,15 @@ void KisMeshTransformStrategy::paint(QPainter &gc)
if (m_d->hoveredControl && *m_d->hoveredControl == it.controlIndex()) {
- handlePainter.setHandleStyle(KisHandleStyle::highlightedPrimaryHandles());
+ handlePainter.setHandleStyle(KisHandleStyle::highlightedPrimaryHandles(palette));
} else if (it.type() == KisBezierTransformMesh::ControlType::Node &&
m_d->selectedNodes.contains(it.nodeIndex())) {
- handlePainter.setHandleStyle(KisHandleStyle::selectedPrimaryHandles());
+ handlePainter.setHandleStyle(KisHandleStyle::selectedPrimaryHandles(palette));
} else {
- handlePainter.setHandleStyle(KisHandleStyle::primarySelection());
+ handlePainter.setHandleStyle(KisHandleStyle::primarySelection(palette));
}
if (it.type() == KisBezierTransformMesh::ControlType::Node) {
diff --git a/plugins/tools/tool_transform2/kis_mesh_transform_strategy.h b/plugins/tools/tool_transform2/kis_mesh_transform_strategy.h
index 375b430d23..767c3f32cf 100644
--- a/plugins/tools/tool_transform2/kis_mesh_transform_strategy.h
+++ b/plugins/tools/tool_transform2/kis_mesh_transform_strategy.h
@@ -35,7 +35,7 @@ public:
QPointF handleSnapPoint(const QPointF &imagePos) override;
bool shiftModifierIsUsed() const override;
- void paint(QPainter &gc) override;
+ void paint(QPainter &gc, const KoColorDisplayRendererInterface *displayRendererInterface) override;
QCursor getCurrentCursor() const override;
void externalConfigChanged() override;
diff --git a/plugins/tools/tool_transform2/kis_perspective_transform_strategy.cpp b/plugins/tools/tool_transform2/kis_perspective_transform_strategy.cpp
index c505892cbc..dd44924ba1 100644
--- a/plugins/tools/tool_transform2/kis_perspective_transform_strategy.cpp
+++ b/plugins/tools/tool_transform2/kis_perspective_transform_strategy.cpp
@@ -15,6 +15,7 @@
#include <Eigen/Dense>
+#include "KoColorDisplayRendererInterface.h"
#include "kis_coordinates_converter.h"
#include "tool_transform_args.h"
#include "transform_transaction_properties.h"
@@ -214,7 +215,7 @@ QCursor KisPerspectiveTransformStrategy::getCurrentCursor() const
return cursor;
}
-void KisPerspectiveTransformStrategy::paint(QPainter &gc)
+void KisPerspectiveTransformStrategy::paint(QPainter &gc, const KoColorDisplayRendererInterface *displayRendererInterface)
{
gc.save();
@@ -277,7 +278,7 @@ void KisPerspectiveTransformStrategy::paint(QPainter &gc)
pen[0].setCosmetic(true);
pen[1].setWidth(decorationThickness() * 2);
pen[1].setCosmetic(true);
- pen[1].setColor(Qt::lightGray);
+ pen[1].setColor(displayRendererInterface->convertColorToDisplayColorSpace(KoColor(Qt::lightGray, KoColorSpaceRegistry::instance()->rgb8())));
for (int i = 1; i >= 0; --i) {
gc.setPen(pen[i]);
diff --git a/plugins/tools/tool_transform2/kis_perspective_transform_strategy.h b/plugins/tools/tool_transform2/kis_perspective_transform_strategy.h
index a1d4e63ab0..a4febb870c 100644
--- a/plugins/tools/tool_transform2/kis_perspective_transform_strategy.h
+++ b/plugins/tools/tool_transform2/kis_perspective_transform_strategy.h
@@ -30,7 +30,7 @@ public:
~KisPerspectiveTransformStrategy() override;
void setTransformFunction(const QPointF &mousePos, bool perspectiveModifierActive, bool shiftModifierActive, bool altModifierActive) override;
- void paint(QPainter &gc) override;
+ void paint(QPainter &gc, const KoColorDisplayRendererInterface *displayRendererInterface) override;
QCursor getCurrentCursor() const override;
void externalConfigChanged() override;
diff --git a/plugins/tools/tool_transform2/kis_tool_transform.cc b/plugins/tools/tool_transform2/kis_tool_transform.cc
index 9c05de5687..8f3e3f30f5 100644
--- a/plugins/tools/tool_transform2/kis_tool_transform.cc
+++ b/plugins/tools/tool_transform2/kis_tool_transform.cc
@@ -57,6 +57,7 @@
#include <KoShapeTransformCommand.h>
#include <KoCanvasController.h>
+#include <kis_display_color_converter.h>
#include "kis_action_registry.h"
@@ -293,7 +294,7 @@ void KisToolTransform::paint(QPainter& gc, const KoViewConverter &converter)
currentStrategy()->externalConfigChanged();
}
currentStrategy()->setDecorationThickness(decorationThickness());
- currentStrategy()->paint(gc);
+ currentStrategy()->paint(gc, m_canvas->displayRendererInterface());
if (!m_cursorOutline.isEmpty()) {
@@ -777,18 +778,16 @@ void KisToolTransform::initThumbnailImage(KisPaintDeviceSP previewDevice)
QRect thumbRect = scaleTransform.mapRect(m_transaction.originalRect()).toAlignedRect();
- origImg = m_selectedPortionCache->
- createThumbnailUncached(thumbRect.width(),
- thumbRect.height(),
- srcRect, 1,
- KoColorConversionTransformation::internalRenderingIntent(),
- KoColorConversionTransformation::internalConversionFlags());
+ QSize size = thumbRect.size();
+ if (size.width() < 1) size.setWidth(1);
+ if (size.height() < 1) size.setHeight(1);
+ KisPaintDeviceSP dev = m_selectedPortionCache->createThumbnailDeviceOversampled(size.width(), size.height(), 1, srcRect);
+ origImg = m_canvas->displayColorConverter()->convertImageToDisplayColorSpace(dev, QRect(QPoint(0, 0), size), true);
+
thumbToImageTransform = scaleTransform.inverted();
} else {
- origImg = m_selectedPortionCache->convertToQImage(0, x, y, w, h,
- KoColorConversionTransformation::internalRenderingIntent(),
- KoColorConversionTransformation::internalConversionFlags());
+ origImg = m_canvas->displayColorConverter()->convertImageToDisplayColorSpace(m_selectedPortionCache, QRect(x, y, w, h), true);
thumbToImageTransform = QTransform();
}
}
@@ -1565,4 +1564,4 @@ void KisToolTransformFactory::activateSubtoolLiquify()
void KisToolTransformFactory::activateSubtoolMesh()
{
activateSubtool(KisToolTransform::MeshTransformMode);
-}
\ No newline at end of file
+}
diff --git a/plugins/tools/tool_transform2/kis_transform_strategy_base.h b/plugins/tools/tool_transform2/kis_transform_strategy_base.h
index 02b61f09d2..bd14f813f5 100644
--- a/plugins/tools/tool_transform2/kis_transform_strategy_base.h
+++ b/plugins/tools/tool_transform2/kis_transform_strategy_base.h
@@ -19,6 +19,7 @@ class QPainter;
class QCursor;
class KoPointerEvent;
class QPainterPath;
+class KoColorDisplayRendererInterface;
class KisTransformStrategyBase : public QObject
@@ -36,7 +37,7 @@ public:
virtual bool acceptsClicks() const;
- virtual void paint(QPainter &gc) = 0;
+ virtual void paint(QPainter &gc, const KoColorDisplayRendererInterface *displayRendererInterface) = 0;
virtual QCursor getCurrentCursor() const = 0;
virtual QPainterPath getCursorOutline() const;
diff --git a/plugins/tools/tool_transform2/kis_warp_transform_strategy.cpp b/plugins/tools/tool_transform2/kis_warp_transform_strategy.cpp
index b8a4ae9ba0..732ea31e75 100644
--- a/plugins/tools/tool_transform2/kis_warp_transform_strategy.cpp
+++ b/plugins/tools/tool_transform2/kis_warp_transform_strategy.cpp
@@ -12,6 +12,7 @@
#include <QPainter>
#include <QPainterPath>
+#include "KoColorDisplayRendererInterface.h"
#include "kis_coordinates_converter.h"
#include "tool_transform_args.h"
#include "transform_transaction_properties.h"
@@ -223,7 +224,7 @@ void KisWarpTransformStrategy::drawConnectionLines(QPainter &gc,
}
}
-void KisWarpTransformStrategy::paint(QPainter &gc)
+void KisWarpTransformStrategy::paint(QPainter &gc, const KoColorDisplayRendererInterface *displayRendererInterface)
{
// Draw preview image
@@ -247,12 +248,12 @@ void KisWarpTransformStrategy::paint(QPainter &gc)
m_d->currentArgs.transfPoints(),
m_d->currentArgs.isEditingTransformPoints());
}
+ KisHandlePalette palette = displayRendererInterface->handlePaletteForDisplayColorSpace();
-
- QPen mainPen(Qt::black);
+ QPen mainPen(palette.black);
mainPen.setCosmetic(true);
mainPen.setWidth(decorationThickness());
- QPen outlinePen(Qt::white);
+ QPen outlinePen(palette.white);
outlinePen.setCosmetic(true);
outlinePen.setWidth(decorationThickness());
@@ -335,7 +336,7 @@ void KisWarpTransformStrategy::paint(QPainter &gc)
KisHandlePainterHelper handlePainter(&gc, 0.0, decorationThickness());
- handlePainter.setHandleStyle(KisHandleStyle::primarySelection());
+ handlePainter.setHandleStyle(KisHandleStyle::primarySelection(palette));
// draw horizontal lines
for (int i = 0; i < numPoints; i++) {
diff --git a/plugins/tools/tool_transform2/kis_warp_transform_strategy.h b/plugins/tools/tool_transform2/kis_warp_transform_strategy.h
index af9f5020d8..6bdb650646 100644
--- a/plugins/tools/tool_transform2/kis_warp_transform_strategy.h
+++ b/plugins/tools/tool_transform2/kis_warp_transform_strategy.h
@@ -39,7 +39,7 @@ public:
void setTransformFunction(const QPointF &mousePos, bool perspectiveModifierActive, bool shiftModifierActive, bool altModifierActive) override;
void setTransformType(TransformType type);
- void paint(QPainter &gc) override;
+ void paint(QPainter &gc, const KoColorDisplayRendererInterface *displayRendererInterface) override;
QCursor getCurrentCursor() const override;
void externalConfigChanged() override;