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++
5.5 KB
Raw Blame
/*
 *  SPDX-FileCopyrightText: 2014 Dmitry Kazakov <[email protected]>
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#ifndef __KO_COLOR_DISPLAY_RENDERER_INTERFACE_H
#define __KO_COLOR_DISPLAY_RENDERER_INTERFACE_H

#include <QObject>
#include <QColor>

#include "KoColor.h"

class KoChannelInfo;
class KoColorSpace;
struct KisHandlePalette;
class QPalette;

/**
 * A special interface class provided by pigment to let widgets render
 * a KoColor on screen using custom profiling provided by the user.
 *
 * If you want to provide your own rendering of the KoColor on screen,
 * reimplement this class and provide its instance to a supporting
 * widget.
 */
class KRITAPIGMENT_EXPORT KoColorDisplayRendererInterface : public QObject
{
    Q_OBJECT

public:
    KoColorDisplayRendererInterface();
    ~KoColorDisplayRendererInterface() override;

    /**
     * @brief Convert a consecutive block of pixel data to an ARGB32 QImage
     * @param srcColorSpace the colorspace the pixel data is in
     * @param data a pointer to a byte array with color data; must cover the requested image size
     * @param size defines the dimensions of the resulting image
     * @param proofPaintColors optionally adjust the color data to painting gamut first
     * @return a QImage that can be displayed
     */
    virtual QImage toQImage(const KoColorSpace *srcColorSpace, const quint8 *data, QSize size, bool proofPaintColors = false) const = 0;

    /**
     * Convert the color \p c to a custom QColor that will be
     * displayed by the widget on screen. Please note, that the
     * reverse conversion may simply not exist.
     * @param proofPaintColors optionally adjust the color data to painting gamut first
     */
    virtual QColor toQColor(const KoColor &c, bool proofToPaintColors = false) const = 0;

    /**
     * This tries to approximate a rendered QColor into the KoColor
     * of the painting color space. Please note, that in most of the
     * cases the exact reverse transformation does not exist, so the
     * resulting color will be only a rough approximation. Never try
     * to do a round trip like that:
     *
     * // r will never be equal to c!
     * r = approximateFromRenderedQColor(toQColor(c));
     */
    virtual KoColor approximateFromRenderedQColor(const QColor &c) const = 0;

    virtual KoColor fromHsv(int h, int s, int v, int a = 255) const = 0;
    virtual void getHsv(const KoColor &srcColor, int *h, int *s, int *v, int *a = 0) const = 0;


    /**
     * \return the minimum value of a floating point channel that can
     *         be seen on screen
     */
    virtual qreal minVisibleFloatValue(const KoChannelInfo *chaninfo) const = 0;

    /**
     * \return the maximum value of a floating point channel that can
     *         be seen on screen. In normal situation it is 1.0. When
     *         the user changes exposure the value varies.
     */
    virtual qreal maxVisibleFloatValue(const KoChannelInfo *chaninfo) const = 0;

    /**
     * @brief getColorSpace
     * @return the painting color space, this is useful for determining the transform.
     */
    virtual const KoColorSpace* getPaintingColorSpace() const = 0;

    /**
     * @brief convertColorToDisplayColorSpace
     * @param color -- base color.
     * @return get a QColor version of the KoColor that is suited for canvas decorations.
     */
    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
     */
    virtual KisHandlePalette handlePaletteForDisplayColorSpace() const = 0;

    /**
     * @brief systemPaletteForDisplayColorSpace
     * @return  get a version of the system palette that is suited for canvas decorations.
     */
    virtual QPalette systemPaletteForDisplayColorSpace() const = 0;

Q_SIGNALS:
    void displayConfigurationChanged();

private:
    Q_DISABLE_COPY(KoColorDisplayRendererInterface)
};

/**
 * The default conversion class that just calls KoColor::toQColor()
 * conversion implementation which effectively renders the color into
 * sRGB color space.
 */
class KRITAPIGMENT_EXPORT KoDumbColorDisplayRenderer : public KoColorDisplayRendererInterface
{
public:
    QImage toQImage(const KoColorSpace *srcColorSpace, const quint8 *data, QSize size, bool proofPaintColors = false) const override;
    QColor toQColor(const KoColor &c, bool proofToPaintColors = false) const override;
    KoColor approximateFromRenderedQColor(const QColor &c) const override;
    KoColor fromHsv(int h, int s, int v, int a = 255) const override;
    void getHsv(const KoColor &srcColor, int *h, int *s, int *v, int *a = 0) const override;

    qreal minVisibleFloatValue(const KoChannelInfo *chaninfo) const override;
    qreal maxVisibleFloatValue(const KoChannelInfo *chaninfo) const override;

    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;

    static KoColorDisplayRendererInterface* instance();
};

#endif /* __KO_COLOR_DISPLAY_RENDERER_INTERFACE_H */