File indexing completed on 2024-12-01 07:35:09

0001 /*
0002     SPDX-FileCopyrightText: 2010 Simon Andreas Eugster <simon.eu@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QImage>
0010 #include <QObject>
0011 
0012 /** @class ColorTools
0013     @brief \@todo Describe class ColorTools
0014     @todo Describe class ColorTools
0015  */
0016 class ColorTools : public QObject
0017 {
0018     Q_OBJECT
0019 
0020 public:
0021     explicit ColorTools(QObject *parent = nullptr);
0022 
0023     // enum ColorsRGB { COL_R, COL_G, COL_B, COL_Luma, COL_A, COL_RGB };
0024     enum class ColorsRGB { R, G, B, Luma, A, RGB };
0025 
0026     enum ComponentsHSV { COM_H, COM_S, COM_V };
0027 
0028     /**
0029      * @brief Draws a UV plane with given Y value.
0030      * scaling defines how far to zoom in (or out). Lower value = zoom in.
0031      * The modified version always scales the RGB values so that at least one of them attains 255.
0032      * If not the full rect should be filled, set circleOnly to true.
0033      * See also: https://en.wikipedia.org/wiki/YUV and https://de.wikipedia.org/wiki/Vektorskop
0034      */
0035     QImage yuvColorWheel(const QSize &size, int Y, float scaling, bool modifiedVersion, bool circleOnly);
0036     /**
0037      * @brief Draws a UV plane with given UV angle (ratio u:v stays constant)
0038      * scaling defines how far to zoom in (or out). Lower value = zoom in.
0039      * angle defines the angle in a default U/V plane. A vertical plane, on which Y goes from 0 to 1,
0040      * is then laid through the UV plane, with the defined angle.
0041      * @see yuvColorWheel()
0042      */
0043     QImage yuvVerticalPlane(const QSize &size, int angle, float scaling);
0044     /**
0045      * @brief Draws a RGB plane with two values on one axis and one on the other.
0046      * This is e.g. useful as background for a curves dialog. On the line from bottom left to top right
0047      * are neutral colors. The colors on the y axis show what the neutral color will look like when modifying the curve.
0048      * color defines the color to modify on the y axis. The other two components will be increased
0049      * in equal terms (linear as well) on the x axis.
0050      * scaling \in ]0,1] defines the maximum variance of the selected component; Choosing a value lower than 1
0051      * simulates the case that the curves can adjust only +- scaling*255. This mainly delivers a more constant look
0052      * when also using the Luma component for the curves display but might not represent the actual color change!
0053      */
0054     static QImage rgbCurvePlane(const QSize &size, const ColorTools::ColorsRGB &color, float scaling = 1, const QRgb &background = QRgb());
0055 
0056     /**
0057        Same as the plane except that we vary only the vertical dimension
0058     */
0059     static QImage rgbCurveLine(const QSize &size, const ColorTools::ColorsRGB &color, const QRgb &background);
0060     /**
0061      * @brief Draws a YPbPr plane with Pb on the x axis and Pr on the y axis.
0062      * Y is the Y value to use.
0063      * scaling defines how far to zoom in (or out). Lower value = zoom in.
0064      * See also: https://de.wikipedia.org/wiki/YPbPr-Farbmodell and https://www.poynton.com/ColorFAQ.html
0065      */
0066     QImage yPbPrColorWheel(const QSize &size, int Y, float scaling, bool circleOnly);
0067     /**
0068      * @brief Draws a HSV plane with Hue on the x axis and hue difference on the y axis.
0069      * This is for the Bézier Curves widget which allows one to change the hue (y) of a certain hue.
0070      * MIN/MAX give the minimum/maximum hue difference, e.g. -128,+128.
0071      * For the value ranges see:
0072      * https://doc.qt.io/qt-5/qcolor.html#the-hsv-color-model
0073      */
0074     static QImage hsvHueShiftPlane(const QSize &size, int S, int V, int MIN, int MAX);
0075 
0076     /**
0077       Basic HSV plane with two components varying on the x and y axis.
0078       If both components are the same, then the y axis will be considered.
0079       MIN/MAX give the minimum/maximum saturation, usually 0..255.
0080       Missing colour components will be taken from baseColor.
0081       For shear == true, the image will be sheared such that the x axis goes through (0,0) and (1,1). offsetY can additionally
0082       shift the whole x axis vertically.
0083       */
0084     static QImage hsvCurvePlane(const QSize &size, const QColor &baseColor, const ComponentsHSV &xVariant, const ComponentsHSV &yVariant, bool shear = false,
0085                                 const float offsetY = 0);
0086 
0087 Q_SIGNALS:
0088     void signalYuvWheelCalculationFinished();
0089 };