File indexing completed on 2024-05-19 04:27:22
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #ifndef __KO_COLOR_DISPLAY_RENDERER_INTERFACE_H 0008 #define __KO_COLOR_DISPLAY_RENDERER_INTERFACE_H 0009 0010 #include <QObject> 0011 #include <QColor> 0012 #include <QSharedPointer> 0013 0014 #include "KoColor.h" 0015 0016 class KoChannelInfo; 0017 class KoColorSpace; 0018 0019 /** 0020 * A special interface class provided by pigment to let widgets render 0021 * a KoColor on screen using custom profiling provided by the user. 0022 * 0023 * If you want to provide your own rendering of the KoColor on screen, 0024 * reimplement this class and provide its instance to a supporting 0025 * widget. 0026 */ 0027 class KRITAPIGMENT_EXPORT KoColorDisplayRendererInterface : public QObject 0028 { 0029 Q_OBJECT 0030 0031 public: 0032 KoColorDisplayRendererInterface(); 0033 ~KoColorDisplayRendererInterface() override; 0034 0035 /** 0036 * @brief Convert a consecutive block of pixel data to an ARGB32 QImage 0037 * @param srcColorSpace the colorspace the pixel data is in 0038 * @param data a pointer to a byte array with color data; must cover the requested image size 0039 * @param size defines the dimensions of the resulting image 0040 * @param proofPaintColors optionally adjust the color data to painting gamut first 0041 * @return a QImage that can be displayed 0042 */ 0043 virtual QImage toQImage(const KoColorSpace *srcColorSpace, const quint8 *data, QSize size, bool proofPaintColors = false) const = 0; 0044 0045 /** 0046 * Convert the color \p c to a custom QColor that will be 0047 * displayed by the widget on screen. Please note, that the 0048 * reverse conversion may simply not exist. 0049 * @param proofPaintColors optionally adjust the color data to painting gamut first 0050 */ 0051 virtual QColor toQColor(const KoColor &c, bool proofToPaintColors = false) const = 0; 0052 0053 /** 0054 * This tries to approximate a rendered QColor into the KoColor 0055 * of the painting color space. Please note, that in most of the 0056 * cases the exact reverse transformation does not exist, so the 0057 * resulting color will be only a rough approximation. Never try 0058 * to do a round trip like that: 0059 * 0060 * // r will never be equal to c! 0061 * r = approximateFromRenderedQColor(toQColor(c)); 0062 */ 0063 virtual KoColor approximateFromRenderedQColor(const QColor &c) const = 0; 0064 0065 virtual KoColor fromHsv(int h, int s, int v, int a = 255) const = 0; 0066 virtual void getHsv(const KoColor &srcColor, int *h, int *s, int *v, int *a = 0) const = 0; 0067 0068 0069 /** 0070 * \return the minimum value of a floating point channel that can 0071 * be seen on screen 0072 */ 0073 virtual qreal minVisibleFloatValue(const KoChannelInfo *chaninfo) const = 0; 0074 0075 /** 0076 * \return the maximum value of a floating point channel that can 0077 * be seen on screen. In normal situation it is 1.0. When 0078 * the user changes exposure the value varies. 0079 */ 0080 virtual qreal maxVisibleFloatValue(const KoChannelInfo *chaninfo) const = 0; 0081 0082 /** 0083 * @brief getColorSpace 0084 * @return the painting color space, this is useful for determining the transform. 0085 */ 0086 virtual const KoColorSpace* getPaintingColorSpace() const = 0; 0087 0088 Q_SIGNALS: 0089 void displayConfigurationChanged(); 0090 0091 private: 0092 Q_DISABLE_COPY(KoColorDisplayRendererInterface) 0093 }; 0094 0095 /** 0096 * The default conversion class that just calls KoColor::toQColor() 0097 * conversion implementation which effectively renders the color into 0098 * sRGB color space. 0099 */ 0100 class KRITAPIGMENT_EXPORT KoDumbColorDisplayRenderer : public KoColorDisplayRendererInterface 0101 { 0102 public: 0103 QImage toQImage(const KoColorSpace *srcColorSpace, const quint8 *data, QSize size, bool proofPaintColors = false) const override; 0104 QColor toQColor(const KoColor &c, bool proofToPaintColors = false) const override; 0105 KoColor approximateFromRenderedQColor(const QColor &c) const override; 0106 KoColor fromHsv(int h, int s, int v, int a = 255) const override; 0107 void getHsv(const KoColor &srcColor, int *h, int *s, int *v, int *a = 0) const override; 0108 0109 qreal minVisibleFloatValue(const KoChannelInfo *chaninfo) const override; 0110 qreal maxVisibleFloatValue(const KoChannelInfo *chaninfo) const override; 0111 0112 const KoColorSpace* getPaintingColorSpace() const override; 0113 0114 static KoColorDisplayRendererInterface* instance(); 0115 }; 0116 0117 #endif /* __KO_COLOR_DISPLAY_RENDERER_INTERFACE_H */