File indexing completed on 2024-05-12 15:59:33

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 KoColorSpace::convertToQImage converts a whole row of colors in one go
0037      * @param srcColorSpace the colorspace the pixel data is in
0038      * @param data a pointer to a byte array with colors
0039      * @param width of the resulting image
0040      * @param height of the resulting image
0041      * @return a QImage that can be displayed
0042      */
0043     virtual QImage convertToQImage(const KoColorSpace *srcColorSpace, const quint8 *data, qint32 width, qint32 height) 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      */
0050     virtual QColor toQColor(const KoColor &c) const = 0;
0051 
0052     /**
0053      * This tries to approximate a rendered QColor into the KoColor
0054      * of the painting color space. Please note, that in most of the
0055      * cases the exact reverse transformation does not exist, so the
0056      * resulting color will be only a rough approximation. Never try
0057      * to do a round trip like that:
0058      *
0059      * // r will never be equal to c!
0060      * r = approximateFromRenderedQColor(toQColor(c));
0061      */
0062     virtual KoColor approximateFromRenderedQColor(const QColor &c) const = 0;
0063 
0064     virtual KoColor fromHsv(int h, int s, int v, int a = 255) const = 0;
0065     virtual void getHsv(const KoColor &srcColor, int *h, int *s, int *v, int *a = 0) const = 0;
0066 
0067 
0068     /**
0069      * \return the minimum value of a floating point channel that can
0070      *         be seen on screen
0071      */
0072     virtual qreal minVisibleFloatValue(const KoChannelInfo *chaninfo) const = 0;
0073 
0074     /**
0075      * \return the maximum value of a floating point channel that can
0076      *         be seen on screen. In normal situation it is 1.0. When
0077      *         the user changes exposure the value varies.
0078      */
0079     virtual qreal maxVisibleFloatValue(const KoChannelInfo *chaninfo) const = 0;
0080 
0081     /**
0082      * @brief getColorSpace
0083      * @return the painting color space, this is useful for determining the transform.
0084      */
0085     virtual const KoColorSpace* getPaintingColorSpace() const = 0;
0086 
0087 Q_SIGNALS:
0088     void displayConfigurationChanged();
0089 
0090 private:
0091     Q_DISABLE_COPY(KoColorDisplayRendererInterface)
0092 };
0093 
0094 /**
0095  * The default conversion class that just calls KoColor::toQColor()
0096  * conversion implementation which effectively renders the color into
0097  * sRGB color space.
0098  */
0099 class KRITAPIGMENT_EXPORT KoDumbColorDisplayRenderer : public KoColorDisplayRendererInterface
0100 {
0101 public:
0102     QImage convertToQImage(const KoColorSpace *srcColorSpace, const quint8 *data, qint32 width, qint32 height) const override;
0103     QColor toQColor(const KoColor &c) const override;
0104     KoColor approximateFromRenderedQColor(const QColor &c) const override;
0105     KoColor fromHsv(int h, int s, int v, int a = 255) const override;
0106     void getHsv(const KoColor &srcColor, int *h, int *s, int *v, int *a = 0) const override;
0107 
0108     qreal minVisibleFloatValue(const KoChannelInfo *chaninfo) const override;
0109     qreal maxVisibleFloatValue(const KoChannelInfo *chaninfo) const override;
0110 
0111     const KoColorSpace* getPaintingColorSpace() const override;
0112 
0113     static KoColorDisplayRendererInterface* instance();
0114 };
0115 
0116 #endif /* __KO_COLOR_DISPLAY_RENDERER_INTERFACE_H */