Krita Source Code Documentation
Loading...
Searching...
No Matches
LcmsRGBP2020PQColorSpaceTransformation.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2019 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#ifndef LCMSRGBP2020PQCOLORSPACETRANSFORMATION_H
8#define LCMSRGBP2020PQCOLORSPACETRANSFORMATION_H
9
10#include "KoAlwaysInline.h"
12#include "KoColorSpaceMaths.h"
16
19#ifdef HAVE_OPENEXR
21#endif
23
24
25namespace
26{
27
28template <class T>
29struct DstTraitsForSource {
30 typedef KoRgbF32Traits result;
31};
32
36#ifdef HAVE_OPENEXR
37template <>
38struct DstTraitsForSource<KoBgrU16Traits> {
39 typedef KoRgbF16Traits result;
40};
41
42template <>
43struct DstTraitsForSource<KoBgrU8Traits> {
44 typedef KoRgbF16Traits result;
45};
46#endif
47
48template <typename src_channel_type,
49 typename dst_channel_type>
50struct RemoveSmpte2048Policy {
51 static ALWAYS_INLINE dst_channel_type process(src_channel_type value) {
52 return
56 value)));
57 }
58};
59
60template <typename src_channel_type,
61 typename dst_channel_type>
62struct ApplySmpte2048Policy {
63 static ALWAYS_INLINE dst_channel_type process(src_channel_type value) {
64 return
68 value)));
69 }
70};
71
72template <typename src_channel_type,
73 typename dst_channel_type>
74struct NoopPolicy {
75 static ALWAYS_INLINE dst_channel_type process(src_channel_type value) {
77 }
78};
79
80}
81
82template<typename SrcCSTraits,
83 typename DstCSTraits,
84 template<typename, typename> class Policy>
86{
88 const KoColorSpace* dstCs,
90 ConversionFlags conversionFlags)
92 dstCs,
95 {
96 }
97
98 void transform(const quint8 *src, quint8 *dst, qint32 nPixels) const override {
99 KIS_ASSERT(src != dst);
100
101 const typename SrcCSTraits::Pixel *srcPixel = reinterpret_cast<const typename SrcCSTraits::Pixel*>(src);
102 typename DstCSTraits::Pixel *dstPixel = reinterpret_cast<typename DstCSTraits::Pixel*>(dst);
103
104 typedef typename SrcCSTraits::channels_type src_channel_type;
105 typedef typename DstCSTraits::channels_type dst_channel_type;
106 typedef Policy<src_channel_type, dst_channel_type> ConcretePolicy;
107
108 for (int i = 0; i < nPixels; i++) {
109 dstPixel->red = ConcretePolicy::process(srcPixel->red);
110 dstPixel->green = ConcretePolicy::process(srcPixel->green);
111 dstPixel->blue = ConcretePolicy::process(srcPixel->blue);
112 dstPixel->alpha =
114 srcPixel->alpha);
115
116 srcPixel++;
117 dstPixel++;
118 }
119 }
120
121};
122
123template<class ParentColorSpace, class DstColorSpaceTraits = typename DstTraitsForSource<typename ParentColorSpace::ColorSpaceTraits>::result>
125{
126public:
129 colorDepthIdForChannelType<typename ParentColorSpace::ColorSpaceTraits::channels_type>().id(),
130 "High Dynamic Range UHDTV Wide Color Gamut Display (Rec. 2020) - SMPTE ST 2084 PQ EOTF",
131 RGBAColorModelID.id(),
132 colorDepthIdForChannelType<typename DstColorSpaceTraits::channels_type>().id(),
133 "Rec2020-elle-V4-g10.icc")
134 {
135 }
136
138 const KoColorSpace* dstColorSpace,
140 KoColorConversionTransformation::ConversionFlags conversionFlags) const override
141 {
142 return new ApplyRgbShaper<
143 typename ParentColorSpace::ColorSpaceTraits,
144 DstColorSpaceTraits,
145 RemoveSmpte2048Policy>(srcColorSpace,
146 dstColorSpace,
147 renderingIntent,
148 conversionFlags);
149 }
150};
151
152template<class ParentColorSpace, class DstColorSpaceTraits = typename DstTraitsForSource<typename ParentColorSpace::ColorSpaceTraits>::result>
154{
155public:
158 colorDepthIdForChannelType<typename DstColorSpaceTraits::channels_type>().id(),
159 "Rec2020-elle-V4-g10.icc",
160 RGBAColorModelID.id(),
161 colorDepthIdForChannelType<typename ParentColorSpace::ColorSpaceTraits::channels_type>().id(),
162 "High Dynamic Range UHDTV Wide Color Gamut Display (Rec. 2020) - SMPTE ST 2084 PQ EOTF")
163 {
164 }
165
167 const KoColorSpace* dstColorSpace,
169 KoColorConversionTransformation::ConversionFlags conversionFlags) const override
170 {
171 return new ApplyRgbShaper<
172 DstColorSpaceTraits,
173 typename ParentColorSpace::ColorSpaceTraits,
174 ApplySmpte2048Policy>(srcColorSpace,
175 dstColorSpace,
176 renderingIntent,
177 conversionFlags);
178 }
179};
180
181template<class ParentColorSpace, class DstColorSpaceTraits>
183{
184public:
187 colorDepthIdForChannelType<typename ParentColorSpace::ColorSpaceTraits::channels_type>().id(),
188 "High Dynamic Range UHDTV Wide Color Gamut Display (Rec. 2020) - SMPTE ST 2084 PQ EOTF",
189 RGBAColorModelID.id(),
190 colorDepthIdForChannelType<typename DstColorSpaceTraits::channels_type>().id(),
191 "High Dynamic Range UHDTV Wide Color Gamut Display (Rec. 2020) - SMPTE ST 2084 PQ EOTF")
192 {
194 }
195
197 const KoColorSpace* dstColorSpace,
199 KoColorConversionTransformation::ConversionFlags conversionFlags) const override
200 {
201 return new ApplyRgbShaper<
202 typename ParentColorSpace::ColorSpaceTraits,
203 DstColorSpaceTraits,
204 NoopPolicy>(srcColorSpace,
205 dstColorSpace,
206 renderingIntent,
207 conversionFlags);
208 }
209};
210
211#endif // LCMSRGBP2020PQCOLORSPACETRANSFORMATION_H
float value(const T *src, size_t ch)
#define ALWAYS_INLINE
KoID colorDepthIdForChannelType()
const KoID RGBAColorModelID("RGBA", ki18n("RGB/Alpha"))
ALWAYS_INLINE float applySmpte2048Curve(float x) noexcept
ALWAYS_INLINE float removeSmpte2048Curve(float x) noexcept
static _Tdst scaleToA(_T a)
KoColorConversionTransformation * createColorTransformation(const KoColorSpace *srcColorSpace, const KoColorSpace *dstColorSpace, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags) const override
KoColorConversionTransformation * createColorTransformation(const KoColorSpace *srcColorSpace, const KoColorSpace *dstColorSpace, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags) const override
KoColorConversionTransformation * createColorTransformation(const KoColorSpace *srcColorSpace, const KoColorSpace *dstColorSpace, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags) const override
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130
#define KIS_ASSERT(cond)
Definition kis_assert.h:33
void transform(const quint8 *src, quint8 *dst, qint32 nPixels) const override
ApplyRgbShaper(const KoColorSpace *srcCs, const KoColorSpace *dstCs, Intent renderingIntent, ConversionFlags conversionFlags)