Krita Source Code Documentation
Loading...
Searching...
No Matches
KoRgbU8ColorSpace.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2004 Boudewijn Rempt <boud@valdyas.org>
3 * SPDX-FileCopyrightText: 2006 Cyrille Berger <cberger@cberger.net>
4 * SPDX-FileCopyrightText: 2021 L. E. Segovia <amy@amyspark.me>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-or-later
7 */
8#include "KoRgbU8ColorSpace.h"
9
10#include <limits.h>
11#include <stdlib.h>
12
13
14#include <klocalizedstring.h>
15
16#include "KoChannelInfo.h"
17#include "KoID.h"
18#include "KoIntegerMaths.h"
21
22#include "KoColorConversions.h"
24
26
27 KoSimpleColorSpace<KoBgrU8Traits>(colorSpaceId(),
28 i18n("RGB (8-bit integer/channel, unmanaged)"),
31{
32
33 addChannel(new KoChannelInfo(i18n("Blue"), 0, 2, KoChannelInfo::COLOR, KoChannelInfo::UINT8, 1, QColor(0, 0, 255)));
34 addChannel(new KoChannelInfo(i18n("Green"), 1, 1, KoChannelInfo::COLOR, KoChannelInfo::UINT8, 1, QColor(0, 255, 0)));
35 addChannel(new KoChannelInfo(i18n("Red"), 2, 0, KoChannelInfo::COLOR, KoChannelInfo::UINT8, 1, QColor(255, 0, 0)));
37
38 // ADD, ALPHA_DARKEN, BURN, DIVIDE, DODGE, ERASE, MULTIPLY, OVER, OVERLAY, SCREEN, SUBTRACT
39 addStandardCompositeOps<KoBgrU8Traits>(this);
40 addStandardDitherOps<KoBgrU8Traits>(this);
41}
42
46
47
49{
50 return QStringLiteral("RGBA");
51}
52
53
58
59
60void KoRgbU8ColorSpace::fromQColor(const QColor& c, quint8 *dst) const
61{
62 QVector<float> channelValues;
63 channelValues << c.blueF() << c.greenF() << c.redF() << c.alphaF();
64 fromNormalisedChannelsValue(dst, channelValues);
65}
66
67void KoRgbU8ColorSpace::toQColor(const quint8 * src, QColor *c) const
68{
69 QVector<float> channelValues(4);
70 normalisedChannelsValue(src, channelValues);
71 c->setRgbF(channelValues[2], channelValues[1], channelValues[0], channelValues[3]);
72}
73
74void KoRgbU8ColorSpace::toHSY(const QVector<double> &channelValues, qreal *hue, qreal *sat, qreal *luma) const
75{
76
77 RGBToHSY(channelValues[0],channelValues[1],channelValues[2], hue, sat, luma);
78}
79
80QVector <double> KoRgbU8ColorSpace::fromHSY(qreal *hue, qreal *sat, qreal *luma) const
81{
82 QVector <double> channelValues(4);
83 HSYToRGB(*hue, *sat, *luma, &channelValues[0],&channelValues[1],&channelValues[2]);
84 channelValues[3]=1.0;
85 return channelValues;
86}
87
88void KoRgbU8ColorSpace::toYUV(const QVector<double> &channelValues, qreal *y, qreal *u, qreal *v) const
89{
90 RGBToYUV(channelValues[0],channelValues[1],channelValues[2], y, u, v);
91}
92
93QVector <double> KoRgbU8ColorSpace::fromYUV(qreal *y, qreal *u, qreal *v) const
94{
95 QVector <double> channelValues(4);
96 YUVToRGB(*y, *u, *v, &channelValues[0],&channelValues[1],&channelValues[2]);
97 channelValues[3]=1.0;
98 return channelValues;
99}
100
101void KoRgbU8ColorSpace::fillGrayBrushWithColorAndLightnessOverlay(quint8 *dst, const QRgb *brush, quint8 *brushColor, qint32 nPixels) const
102{
103 fillGrayBrushWithColorPreserveLightnessRGB<KoBgrU8Traits>(dst, brush, brushColor, 1.0, nPixels);
104}
105
106void KoRgbU8ColorSpace::fillGrayBrushWithColorAndLightnessWithStrength(quint8* dst, const QRgb* brush, quint8* brushColor, qreal strength, qint32 nPixels) const
107{
108 fillGrayBrushWithColorPreserveLightnessRGB<KoBgrU8Traits>(dst, brush, brushColor, strength, nPixels);
109}
110
111void KoRgbU8ColorSpace::modulateLightnessByGrayBrush(quint8 *dst, const QRgb *brush, qreal strength, qint32 nPixels) const
112{
113 modulateLightnessByGrayBrushRGB<KoBgrU8Traits>(dst, brush, strength, nPixels);
114}
qreal v
qreal u
void HSYToRGB(const qreal h, const qreal s, const qreal y, qreal *red, qreal *green, qreal *blue, qreal R, qreal G, qreal B)
void RGBToYUV(const qreal r, const qreal g, const qreal b, qreal *y, qreal *u, qreal *v, qreal R, qreal G, qreal B)
void RGBToHSY(const qreal r, const qreal g, const qreal b, qreal *h, qreal *s, qreal *y, qreal R, qreal G, qreal B)
void YUVToRGB(const qreal y, const qreal u, const qreal v, qreal *r, qreal *g, qreal *b, qreal R, qreal G, qreal B)
const KoID Integer8BitsColorDepthID("U8", ki18n("8-bit integer/channel"))
const KoID RGBAColorModelID("RGBA", ki18n("RGB/Alpha"))
@ ALPHA
The channel represents the opacity of a pixel.
@ COLOR
The channel represents a color.
@ UINT8
use this for an unsigned integer 8bits channel
void fromNormalisedChannelsValue(quint8 *pixel, const QVector< float > &values) const override
void normalisedChannelsValue(const quint8 *pixel, QVector< float > &channels) const override
virtual void addChannel(KoChannelInfo *ci)
void fillGrayBrushWithColorAndLightnessWithStrength(quint8 *dst, const QRgb *brush, quint8 *brushColor, qreal strength, qint32 nPixels) const override
virtual KoColorSpace * clone() const
void toHSY(const QVector< double > &channelValues, qreal *hue, qreal *sat, qreal *luma) const override
void fromQColor(const QColor &color, quint8 *dst) const override
QVector< double > fromYUV(qreal *y, qreal *u, qreal *v) const override
void modulateLightnessByGrayBrush(quint8 *dst, const QRgb *brush, qreal strength, qint32 nPixels) const override
void toYUV(const QVector< double > &channelValues, qreal *y, qreal *u, qreal *v) const override
static QString colorSpaceId()
QVector< double > fromHSY(qreal *hue, qreal *sat, qreal *luma) const override
void fillGrayBrushWithColorAndLightnessOverlay(quint8 *dst, const QRgb *brush, quint8 *brushColor, qint32 nPixels) const override
void toQColor(const quint8 *src, QColor *c) const override
unsigned int QRgb