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

Handle converting qimages to canvas display space, make svgtextoutlinehelper work in hdr.

Wolthera van Hövell tot Westerflier9db170e93391
diff --git a/libs/flake/text/KoSvgTextShapeOutlineHelper.cpp b/libs/flake/text/KoSvgTextShapeOutlineHelper.cpp
index 4513ef1cb4..7364832c67 100644
--- a/libs/flake/text/KoSvgTextShapeOutlineHelper.cpp
+++ b/libs/flake/text/KoSvgTextShapeOutlineHelper.cpp
@@ -15,6 +15,7 @@
#include <KoSelection.h>
#include <QApplication>
#include <QPalette>
+#include <KoColorDisplayRendererInterface.h>
const int BUTTON_ICON_SIZE = 16;
const int BUTTON_PADDING = 4;
@@ -34,9 +35,6 @@ struct KoSvgTextShapeOutlineHelper::Private {
bool drawOutline = false;
bool textWrappingAreasHovered = false;
- KisHandlePalette handlePalette;
- QPalette systemPalette;
-
KoSvgTextShape *getTextModeShape() {
return dynamic_cast<KoSvgTextShape*>(canvas->currentShapeManagerOwnerShape());
}
@@ -68,6 +66,10 @@ struct KoSvgTextShapeOutlineHelper::Private {
bool drawButton(KoSvgTextShape *text) {
return text && !text->internalShapeManager()->shapes().isEmpty();
}
+
+ KoColorDisplayRendererInterface *renderInterface() {
+ return canvas->displayRendererInterface();
+ }
};
KoSvgTextShapeOutlineHelper::KoSvgTextShapeOutlineHelper(KoCanvasBase *canvas)
@@ -122,9 +124,10 @@ QList<QLineF> getTextAreaOrderArrows(QList<QPainterPath> areas) {
void KoSvgTextShapeOutlineHelper::paintTextShape(QPainter *painter, const KoViewConverter &converter,
KoSvgTextShape *text, bool contourModeActive) {
painter->save();
+ KisHandlePalette handlePalette = d->renderInterface()->handlePaletteForDisplayColorSpace();
KisHandlePainterHelper helper =
KoShape::createHandlePainterHelperView(painter, text, converter, d->handleRadius, d->decorationThickness);
- helper.setHandleStyle(KisHandleStyle::secondarySelection(d->handlePalette));
+ helper.setHandleStyle(KisHandleStyle::secondarySelection());
if (contourModeActive) {
if (d->drawOutline) {
@@ -148,7 +151,7 @@ void KoSvgTextShapeOutlineHelper::paintTextShape(QPainter *painter, const KoView
}
if (d->drawTextWrappingArea) {
if (d->textWrappingAreasHovered) {
- helper.setHandleStyle(KisHandleStyle::partiallyHighlightedPrimaryHandles(d->handlePalette));
+ helper.setHandleStyle(KisHandleStyle::partiallyHighlightedPrimaryHandles(handlePalette));
}
QList<QPainterPath> areas = text->textWrappingAreas();
Q_FOREACH(QLineF arrow, getTextAreaOrderArrows(areas)) {
@@ -161,17 +164,18 @@ void KoSvgTextShapeOutlineHelper::paintTextShape(QPainter *painter, const KoView
painter->restore();
painter->save();
+ QPalette systemPalette = d->renderInterface()->systemPaletteForDisplayColorSpace();
QIcon icon = contourModeActive? KisIconUtils::loadIcon(ICON_EXIT): KisIconUtils::loadIcon(ICON_ENTER);
- QPixmap pm = icon.pixmap(BUTTON_ICON_SIZE, BUTTON_ICON_SIZE);
- painter->setBrush(contourModeActive? d->systemPalette.highlight(): d->systemPalette.button());
+ QImage pm = d->renderInterface()->convertImageToDisplayColorSpace(icon.pixmap(BUTTON_ICON_SIZE, BUTTON_ICON_SIZE).toImage());
+ painter->setBrush(contourModeActive? systemPalette.highlight(): systemPalette.button());
QPen pen;
- pen.setColor(contourModeActive? d->systemPalette.highlightedText().color(): d->systemPalette.buttonText().color());
+ pen.setColor(contourModeActive? systemPalette.highlightedText().color(): systemPalette.buttonText().color());
pen.setCosmetic(true);
pen.setWidthF(d->decorationThickness);
painter->setPen(pen);
const QRectF buttonRect = d->getButtonRect(converter.documentToView().mapRect(text->boundingRect()));
painter->drawRoundedRect(buttonRect, BUTTON_CORNER_ROUND, BUTTON_CORNER_ROUND);
- painter->drawPixmap(buttonRect.topLeft()+QPointF(BUTTON_PADDING, BUTTON_PADDING), pm);
+ painter->drawImage(buttonRect.topLeft()+QPointF(BUTTON_PADDING, BUTTON_PADDING), pm);
painter->restore();
}
@@ -246,16 +250,6 @@ void KoSvgTextShapeOutlineHelper::setDecorationThickness(int thickness)
d->decorationThickness = thickness;
}
-void KoSvgTextShapeOutlineHelper::setHandlePalette(KisHandlePalette handlePalette)
-{
- d->handlePalette = handlePalette;
-}
-
-void KoSvgTextShapeOutlineHelper::setSystemPalette(QPalette pal)
-{
- d->systemPalette = pal;
-}
-
KoSvgTextShape *KoSvgTextShapeOutlineHelper::contourModeButtonHovered(const QPointF &point)
{
KoSvgTextShape *text = d->getTextModeShape();
diff --git a/libs/flake/text/KoSvgTextShapeOutlineHelper.h b/libs/flake/text/KoSvgTextShapeOutlineHelper.h
index 7b923ff505..dac76c6b68 100644
--- a/libs/flake/text/KoSvgTextShapeOutlineHelper.h
+++ b/libs/flake/text/KoSvgTextShapeOutlineHelper.h
@@ -63,9 +63,6 @@ public:
void setHandleRadius(int radius);
void setDecorationThickness(int thickness);
- void setHandlePalette(KisHandlePalette handlePalette);
- void setSystemPalette(QPalette pal);
-
KoSvgTextShape *contourModeButtonHovered(const QPointF &point);
/**
diff --git a/libs/pigment/KoColorDisplayRendererInterface.cpp b/libs/pigment/KoColorDisplayRendererInterface.cpp
index 5c70fd8ab2..2e000b774a 100644
--- a/libs/pigment/KoColorDisplayRendererInterface.cpp
+++ b/libs/pigment/KoColorDisplayRendererInterface.cpp
@@ -89,6 +89,11 @@ QColor KoDumbColorDisplayRenderer::convertColorToDisplayColorSpace(KoColor c) co
return c.toQColor();
}
+QImage KoDumbColorDisplayRenderer::convertImageToDisplayColorSpace(const QImage source) const
+{
+ return source;
+}
+
KisHandlePalette KoDumbColorDisplayRenderer::handlePaletteForDisplayColorSpace() const
{
return KisHandlePalette();
diff --git a/libs/pigment/KoColorDisplayRendererInterface.h b/libs/pigment/KoColorDisplayRendererInterface.h
index 3bcb90899c..2e9820e5f2 100644
--- a/libs/pigment/KoColorDisplayRendererInterface.h
+++ b/libs/pigment/KoColorDisplayRendererInterface.h
@@ -93,6 +93,13 @@ public:
*/
virtual QColor convertColorToDisplayColorSpace(const KoColor color) const = 0;
+ /**
+ * @brief convertImageToDisplayColorSpace
+ * @param source -- image to convert.
+ * @return image converted to be used as a canvas decoration.
+ */
+ virtual QImage convertImageToDisplayColorSpace(const QImage source) const = 0;
+
/**
* @brief handlePaletteForDisplayColorSpace
* @return get a version of KisHandlePalette suited for canvas decorations
@@ -132,6 +139,7 @@ public:
const KoColorSpace* getPaintingColorSpace() const override;
QColor convertColorToDisplayColorSpace(KoColor c) const override;
+ QImage convertImageToDisplayColorSpace(const QImage source) const override;
KisHandlePalette handlePaletteForDisplayColorSpace() const override;
QPalette systemPaletteForDisplayColorSpace() const override;
diff --git a/libs/ui/canvas/kis_display_color_converter.cpp b/libs/ui/canvas/kis_display_color_converter.cpp
index 1bc3732916..eec5143b4b 100644
--- a/libs/ui/canvas/kis_display_color_converter.cpp
+++ b/libs/ui/canvas/kis_display_color_converter.cpp
@@ -227,6 +227,15 @@ struct KisDisplayColorConverter::Private
return m_displayColorConverter->convertColorToDisplayColorSpace(c);
}
+ QImage convertImageToDisplayColorSpace(const QImage source) const override {
+ // Limited to 8bit sRGB for now...
+ KisPaintDeviceSP srcDevice = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8());
+ srcDevice->convertFromQImage(source, KoColorSpaceRegistry::instance()->p709SRGBProfile(), 0, 0);
+ QImage destination = m_displayColorConverter->convertImageToDisplayColorSpace(srcDevice);
+ destination.setDevicePixelRatio(source.devicePixelRatio());
+ return destination;
+ }
+
KisHandlePalette handlePaletteForDisplayColorSpace() const override {
return m_displayColorConverter->handlePaletteForDisplayColorSpace();
}
@@ -710,6 +719,13 @@ QColor KisDisplayColorConverter::convertColorToDisplayColorSpace(const KoColor c
return QColor::fromRgbF(sorted[0], sorted[1], sorted[2], sorted[3]);
}
+QImage KisDisplayColorConverter::convertImageToDisplayColorSpace(KisPaintDeviceSP srcDevice) const
+{
+ KisPaintDeviceSP conversionDevice = new KisPaintDevice(*srcDevice.data());
+ 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);
+}
+
KisHandlePalette KisDisplayColorConverter::handlePaletteForDisplayColorSpace() const
{
return m_d->handlePalette;
diff --git a/libs/ui/canvas/kis_display_color_converter.h b/libs/ui/canvas/kis_display_color_converter.h
index eedd456a6f..7d2279e042 100644
--- a/libs/ui/canvas/kis_display_color_converter.h
+++ b/libs/ui/canvas/kis_display_color_converter.h
@@ -80,10 +80,21 @@ public:
*/
QColor convertColorToDisplayColorSpace(const KoColor color) const;
+ QImage convertImageToDisplayColorSpace(KisPaintDeviceSP srcDevice) const;
+
+ /**
+ * @brief handlePaletteForDisplayColorSpace
+ * @return KisHandlePalette suitable to draw canvas decorations with.
+ */
KisHandlePalette handlePaletteForDisplayColorSpace() const;
+ /**
+ * @brief systemPaletteForDisplayColorSpace
+ * @return QPalette suitable to draw canvas decorations with.
+ */
QPalette systemPaletteForDisplayColorSpace() const;
+
/**
* Converts the exactBounds() (!) of the \p srcDevice into QImage
* properly rendered into display RGB space. Please note that the
diff --git a/plugins/tools/svgtexttool/SvgTextTool.cpp b/plugins/tools/svgtexttool/SvgTextTool.cpp
index 44df2b6e8f..e8f74eca93 100644
--- a/plugins/tools/svgtexttool/SvgTextTool.cpp
+++ b/plugins/tools/svgtexttool/SvgTextTool.cpp
@@ -737,8 +737,6 @@ void SvgTextTool::paint(QPainter &gc, const KoViewConverter &converter)
m_textOutlineHelper->setDecorationThickness(decorationThickness());
m_textOutlineHelper->setHandleRadius(handleRadius());
- m_textOutlineHelper->setHandlePalette(handlePalette);
- m_textOutlineHelper->setSystemPalette(systemPalette);
m_textOutlineHelper->paint(&gc, converter);
m_textOnPathHelper.setDecorationThickness(decorationThickness());
m_textOnPathHelper.setHandleRadius(handleRadius());