Krita Source Code Documentation
Loading...
Searching...
No Matches
KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType > Class Template Reference

#include <KisCmykDitherOpFactory.h>

+ Inheritance diagram for KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >:

Public Member Functions

void dither (const quint8 *src, quint8 *dst, int x, int y) const override
 
void dither (const quint8 *srcRowStart, int srcRowStride, quint8 *dstRowStart, int dstRowStride, int x, int y, int columns, int rows) const override
 
 KisCmykDitherOpImpl (const KoID &srcId, const KoID &dstId)
 
- Public Member Functions inherited from KisDitherOpImpl< srcCSTraits, dstCSTraits, dType >
KoID destinationDepthId () const override
 
void dither (const quint8 *src, quint8 *dst, int x, int y) const override
 
void dither (const quint8 *srcRowStart, int srcRowStride, quint8 *dstRowStart, int dstRowStride, int x, int y, int columns, int rows) const override
 
 KisDitherOpImpl (const KoID &srcId, const KoID &dstId)
 
KoID sourceDepthId () const override
 
DitherType type () const override
 
- Public Member Functions inherited from KisDitherOp
virtual ~KisDitherOp ()=default
 

Private Types

using dstChannelsType = typename dstCSTraits::channels_type
 
using srcChannelsType = typename srcCSTraits::channels_type
 

Private Member Functions

template<typename A , typename std::enable_if< std::numeric_limits< A >::is_integer, void >::type * = nullptr>
A denormalize (float value) const
 
template<typename A , typename std::enable_if<!std::numeric_limits< A >::is_integer, void >::type * = nullptr>
A denormalize (float value) const
 
template<DitherType t = dType, typename std::enable_if< t !=DITHER_NONE, void >::type * = nullptr>
void ditherImpl (const quint8 *src, quint8 *dst, int x, int y) const
 
template<DitherType t = dType, typename std::enable_if< t==DITHER_NONE &&std::is_same< srcCSTraits, dstCSTraits >::value, void >::type * = nullptr>
void ditherImpl (const quint8 *src, quint8 *dst, int, int) const
 
template<DitherType t = dType, typename std::enable_if< t==DITHER_NONE &&!std::is_same< srcCSTraits, dstCSTraits >::value, void >::type * = nullptr>
void ditherImpl (const quint8 *src, quint8 *dst, int, int) const
 
template<DitherType t = dType, typename std::enable_if< t !=DITHER_NONE, void >::type * = nullptr>
void ditherImpl (const quint8 *srcRowStart, int srcRowStride, quint8 *dstRowStart, int dstRowStride, int x, int y, int columns, int rows) const
 
template<DitherType t = dType, typename std::enable_if< t==DITHER_NONE &&std::is_same< srcCSTraits, dstCSTraits >::value, void >::type * = nullptr>
void ditherImpl (const quint8 *srcRowStart, int srcRowStride, quint8 *dstRowStart, int dstRowStride, int, int, int columns, int rows) const
 
template<DitherType t = dType, typename std::enable_if< t==DITHER_NONE &&!std::is_same< srcCSTraits, dstCSTraits >::value, void >::type * = nullptr>
void ditherImpl (const quint8 *srcRowStart, int srcRowStride, quint8 *dstRowStart, int dstRowStride, int, int, int columns, int rows) const
 
template<DitherType t = dType, typename std::enable_if< t==DITHER_BAYER, void >::type * = nullptr>
float factor (int x, int y) const
 
template<DitherType t = dType, typename std::enable_if< t==DITHER_BLUE_NOISE, void >::type * = nullptr>
float factor (int x, int y) const
 
template<typename A , typename U = srcCSTraits, typename std::enable_if< std::numeric_limits< A >::is_integer, void >::type * = nullptr>
float normalize (A value) const
 
template<typename A , typename std::enable_if<!std::numeric_limits< A >::is_integer, void >::type * = nullptr>
float normalize (A value) const
 
template<typename U = typename dstCSTraits::channels_type, typename std::enable_if<!std::numeric_limits< U >::is_integer, void >::type * = nullptr>
constexpr float scale () const
 
template<typename U = typename dstCSTraits::channels_type, typename std::enable_if< std::numeric_limits< U >::is_integer, void >::type * = nullptr>
constexpr float scale () const
 
template<typename A , typename B >
B scaleToA (A c) const
 

Detailed Description

template<typename srcCSTraits, typename dstCSTraits, DitherType dType>
class KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >

THIS CLASS OVERRIDES THE STANDARD FACTORY. Floating point CMYK uses different normalization for the color and alpha channels.

Definition at line 17 of file KisCmykDitherOpFactory.h.

Member Typedef Documentation

◆ dstChannelsType

template<typename srcCSTraits , typename dstCSTraits , DitherType dType>
using KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::dstChannelsType = typename dstCSTraits::channels_type
private

Definition at line 20 of file KisCmykDitherOpFactory.h.

◆ srcChannelsType

template<typename srcCSTraits , typename dstCSTraits , DitherType dType>
using KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::srcChannelsType = typename srcCSTraits::channels_type
private

Definition at line 19 of file KisCmykDitherOpFactory.h.

Constructor & Destructor Documentation

◆ KisCmykDitherOpImpl()

template<typename srcCSTraits , typename dstCSTraits , DitherType dType>
KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::KisCmykDitherOpImpl ( const KoID & srcId,
const KoID & dstId )
inline

Definition at line 23 of file KisCmykDitherOpFactory.h.

Member Function Documentation

◆ denormalize() [1/2]

template<typename srcCSTraits , typename dstCSTraits , DitherType dType>
template<typename A , typename std::enable_if< std::numeric_limits< A >::is_integer, void >::type * = nullptr>
A KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::denormalize ( float value) const
inlineprivate

Definition at line 183 of file KisCmykDitherOpFactory.h.

184 {
185 return static_cast<A>(value * static_cast<float>(KoColorSpaceMathsTraits<A>::unitValue));
186 };
float value(const T *src, size_t ch)

References A, and value().

◆ denormalize() [2/2]

template<typename srcCSTraits , typename dstCSTraits , DitherType dType>
template<typename A , typename std::enable_if<!std::numeric_limits< A >::is_integer, void >::type * = nullptr>
A KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::denormalize ( float value) const
inlineprivate

Definition at line 188 of file KisCmykDitherOpFactory.h.

189 {
190 return static_cast<A>(value * static_cast<float>(KoCmykColorSpaceMathsTraits<A>::unitValueCMYK));
191 };

References A, and value().

◆ dither() [1/2]

template<typename srcCSTraits , typename dstCSTraits , DitherType dType>
void KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::dither ( const quint8 * src,
quint8 * dst,
int x,
int y ) const
inlineoverridevirtual

Implements KisDitherOp.

Definition at line 28 of file KisCmykDitherOpFactory.h.

29 {
30 ditherImpl(src, dst, x, y);
31 }
void ditherImpl(const quint8 *src, quint8 *dst, int, int) const

References KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::ditherImpl().

◆ dither() [2/2]

template<typename srcCSTraits , typename dstCSTraits , DitherType dType>
void KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::dither ( const quint8 * srcRowStart,
int srcRowStride,
quint8 * dstRowStart,
int dstRowStride,
int x,
int y,
int columns,
int rows ) const
inlineoverridevirtual

Implements KisDitherOp.

Definition at line 33 of file KisCmykDitherOpFactory.h.

34 {
35 ditherImpl(srcRowStart, srcRowStride, dstRowStart, dstRowStride, x, y, columns, rows);
36 }

References KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::ditherImpl().

◆ ditherImpl() [1/6]

template<typename srcCSTraits , typename dstCSTraits , DitherType dType>
template<DitherType t = dType, typename std::enable_if< t !=DITHER_NONE, void >::type * = nullptr>
void KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::ditherImpl ( const quint8 * src,
quint8 * dst,
int x,
int y ) const
inlineprivate

Definition at line 60 of file KisCmykDitherOpFactory.h.

61 {
62 const srcChannelsType *nativeSrc = srcCSTraits::nativeArray(src);
63 dstChannelsType *nativeDst = dstCSTraits::nativeArray(dst);
64
65 float f = factor(x, y);
66 float s = scale();
67
68 // In (non-integer) CMYK, all channels except alpha are normalized
69 // to a different range, [0, 100].
70 for (uint channelIndex = 0; channelIndex < srcCSTraits::channels_nb; ++channelIndex) {
71 if (channelIndex == srcCSTraits::alpha_pos) {
72 // The standard normalization.
73 float c = KoColorSpaceMaths<srcChannelsType, float>::scaleToA(nativeSrc[channelIndex]);
75 nativeDst[channelIndex] = KoColorSpaceMaths<float, dstChannelsType>::scaleToA(c);
76 ;
77 } else {
78 // Normalize using unitCMYKValue.
79 float c = normalize<srcChannelsType>(nativeSrc[channelIndex]);
81 nativeDst[channelIndex] = denormalize<dstChannelsType>(c);
82 ;
83 }
84 }
85 }
unsigned int uint
float factor(int x, int y) const
constexpr float scale() const
typename dstCSTraits::channels_type dstChannelsType
typename srcCSTraits::channels_type srcChannelsType
static _Tdst scaleToA(_T a)
float apply_dither(float f, float d, float s)

References KisDitherMaths::apply_dither(), KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::factor(), KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::scale(), and KoColorSpaceMaths< _T, _Tdst >::scaleToA().

◆ ditherImpl() [2/6]

template<typename srcCSTraits , typename dstCSTraits , DitherType dType>
template<DitherType t = dType, typename std::enable_if< t==DITHER_NONE &&std::is_same< srcCSTraits, dstCSTraits >::value, void >::type * = nullptr>
void KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::ditherImpl ( const quint8 * src,
quint8 * dst,
int ,
int  ) const
inlineprivate

Definition at line 39 of file KisCmykDitherOpFactory.h.

40 {
41 memcpy(dst, src, srcCSTraits::pixelSize);
42 }

◆ ditherImpl() [3/6]

template<typename srcCSTraits , typename dstCSTraits , DitherType dType>
template<DitherType t = dType, typename std::enable_if< t==DITHER_NONE &&!std::is_same< srcCSTraits, dstCSTraits >::value, void >::type * = nullptr>
void KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::ditherImpl ( const quint8 * src,
quint8 * dst,
int ,
int  ) const
inlineprivate

Definition at line 44 of file KisCmykDitherOpFactory.h.

45 {
46 const srcChannelsType *nativeSrc = srcCSTraits::nativeArray(src);
47 dstChannelsType *nativeDst = dstCSTraits::nativeArray(dst);
48
49 for (uint channelIndex = 0; channelIndex < srcCSTraits::channels_nb; ++channelIndex) {
50 if (channelIndex == srcCSTraits::alpha_pos) {
51 // The standard normalization.
52 nativeDst[channelIndex] = KoColorSpaceMaths<srcChannelsType, dstChannelsType>::scaleToA(nativeSrc[channelIndex]);
53 } else {
54 // Normalize using unitCMYKValue.
55 nativeDst[channelIndex] = scaleToA<srcChannelsType, dstChannelsType>(nativeSrc[channelIndex]);
56 }
57 }
58 }

References KoColorSpaceMaths< _T, _Tdst >::scaleToA().

◆ ditherImpl() [4/6]

template<typename srcCSTraits , typename dstCSTraits , DitherType dType>
template<DitherType t = dType, typename std::enable_if< t !=DITHER_NONE, void >::type * = nullptr>
void KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::ditherImpl ( const quint8 * srcRowStart,
int srcRowStride,
quint8 * dstRowStart,
int dstRowStride,
int x,
int y,
int columns,
int rows ) const
inlineprivate

Definition at line 132 of file KisCmykDitherOpFactory.h.

133 {
134 const quint8 *nativeSrc = srcRowStart;
135 quint8 *nativeDst = dstRowStart;
136
137 float s = scale();
138
139 for (int a = 0; a < rows; ++a) {
140 const srcChannelsType *srcPtr = srcCSTraits::nativeArray(nativeSrc);
141 dstChannelsType *dstPtr = dstCSTraits::nativeArray(nativeDst);
142
143 for (int b = 0; b < columns; ++b) {
144 float f = factor(x + b, y + a);
145
146 for (uint channelIndex = 0; channelIndex < srcCSTraits::channels_nb; ++channelIndex) {
147 if (channelIndex == srcCSTraits::alpha_pos) {
148 // The standard normalization.
149 float c = KoColorSpaceMaths<srcChannelsType, float>::scaleToA(srcPtr[channelIndex]);
150 c = KisDitherMaths::apply_dither(c, f, s);
152 ;
153 } else {
154 // Normalize using unitCMYKValue.
155 float c = normalize<srcChannelsType>(srcPtr[channelIndex]);
156 c = KisDitherMaths::apply_dither(c, f, s);
157 dstPtr[channelIndex] = denormalize<dstChannelsType>(c);
158 ;
159 }
160 }
161
162 srcPtr += srcCSTraits::channels_nb;
163 dstPtr += dstCSTraits::channels_nb;
164 }
165
166 nativeSrc += srcRowStride;
167 nativeDst += dstRowStride;
168 }
169 }

References KisDitherMaths::apply_dither(), KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::factor(), KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::scale(), and KoColorSpaceMaths< _T, _Tdst >::scaleToA().

◆ ditherImpl() [5/6]

template<typename srcCSTraits , typename dstCSTraits , DitherType dType>
template<DitherType t = dType, typename std::enable_if< t==DITHER_NONE &&std::is_same< srcCSTraits, dstCSTraits >::value, void >::type * = nullptr>
void KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::ditherImpl ( const quint8 * srcRowStart,
int srcRowStride,
quint8 * dstRowStart,
int dstRowStride,
int ,
int ,
int columns,
int rows ) const
inlineprivate

Definition at line 88 of file KisCmykDitherOpFactory.h.

89 {
90 const quint8 *nativeSrc = srcRowStart;
91 quint8 *nativeDst = dstRowStart;
92
93 for (int y = 0; y < rows; ++y) {
94 memcpy(nativeDst, nativeSrc, srcCSTraits::pixelSize * columns);
95
96 nativeSrc += srcRowStride;
97 nativeDst += dstRowStride;
98 }
99 }

◆ ditherImpl() [6/6]

template<typename srcCSTraits , typename dstCSTraits , DitherType dType>
template<DitherType t = dType, typename std::enable_if< t==DITHER_NONE &&!std::is_same< srcCSTraits, dstCSTraits >::value, void >::type * = nullptr>
void KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::ditherImpl ( const quint8 * srcRowStart,
int srcRowStride,
quint8 * dstRowStart,
int dstRowStride,
int ,
int ,
int columns,
int rows ) const
inlineprivate

Definition at line 102 of file KisCmykDitherOpFactory.h.

103 {
104 const quint8 *nativeSrc = srcRowStart;
105 quint8 *nativeDst = dstRowStart;
106
107 for (int y = 0; y < rows; ++y) {
108 const srcChannelsType *srcPtr = srcCSTraits::nativeArray(nativeSrc);
109 dstChannelsType *dstPtr = dstCSTraits::nativeArray(nativeDst);
110
111 for (int x = 0; x < columns; ++x) {
112 for (uint channelIndex = 0; channelIndex < srcCSTraits::channels_nb; ++channelIndex) {
113 if (channelIndex == srcCSTraits::alpha_pos) {
114 // The standard normalization.
115 dstPtr[channelIndex] = KoColorSpaceMaths<srcChannelsType, dstChannelsType>::scaleToA(srcPtr[channelIndex]);
116 } else {
117 // Normalize using unitCMYKValue.
118 dstPtr[channelIndex] = scaleToA<srcChannelsType, dstChannelsType>(srcPtr[channelIndex]);
119 }
120 }
121
122 srcPtr += srcCSTraits::channels_nb;
123 dstPtr += dstCSTraits::channels_nb;
124 }
125
126 nativeSrc += srcRowStride;
127 nativeDst += dstRowStride;
128 }
129 }

References KoColorSpaceMaths< _T, _Tdst >::scaleToA().

◆ factor() [1/2]

template<typename srcCSTraits , typename dstCSTraits , DitherType dType>
template<DitherType t = dType, typename std::enable_if< t==DITHER_BAYER, void >::type * = nullptr>
float KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::factor ( int x,
int y ) const
inlineprivate

Definition at line 208 of file KisCmykDitherOpFactory.h.

209 {
211 }
float dither_factor_bayer_8(int x, int y)

References KisDitherMaths::dither_factor_bayer_8().

◆ factor() [2/2]

template<typename srcCSTraits , typename dstCSTraits , DitherType dType>
template<DitherType t = dType, typename std::enable_if< t==DITHER_BLUE_NOISE, void >::type * = nullptr>
float KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::factor ( int x,
int y ) const
inlineprivate

Definition at line 213 of file KisCmykDitherOpFactory.h.

214 {
216 }
float dither_factor_blue_noise_64(int x, int y)

References KisDitherMaths::dither_factor_blue_noise_64().

◆ normalize() [1/2]

template<typename srcCSTraits , typename dstCSTraits , DitherType dType>
template<typename A , typename U = srcCSTraits, typename std::enable_if< std::numeric_limits< A >::is_integer, void >::type * = nullptr>
float KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::normalize ( A value) const
inlineprivate

Definition at line 173 of file KisCmykDitherOpFactory.h.

174 {
175 return static_cast<float>(value) / KoColorSpaceMathsTraits<A>::unitValue;
176 };

References value().

◆ normalize() [2/2]

template<typename srcCSTraits , typename dstCSTraits , DitherType dType>
template<typename A , typename std::enable_if<!std::numeric_limits< A >::is_integer, void >::type * = nullptr>
float KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::normalize ( A value) const
inlineprivate

Definition at line 178 of file KisCmykDitherOpFactory.h.

179 {
180 return static_cast<float>(value) / KoCmykColorSpaceMathsTraits<A>::unitValueCMYK;
181 };

References value().

◆ scale() [1/2]

template<typename srcCSTraits , typename dstCSTraits , DitherType dType>
template<typename U = typename dstCSTraits::channels_type, typename std::enable_if<!std::numeric_limits< U >::is_integer, void >::type * = nullptr>
constexpr float KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::scale ( ) const
inlineconstexprprivate

Definition at line 198 of file KisCmykDitherOpFactory.h.

199 {
200 return 0.f; // no dithering for floating point
201 }

◆ scale() [2/2]

template<typename srcCSTraits , typename dstCSTraits , DitherType dType>
template<typename U = typename dstCSTraits::channels_type, typename std::enable_if< std::numeric_limits< U >::is_integer, void >::type * = nullptr>
constexpr float KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::scale ( ) const
inlineconstexprprivate

Definition at line 203 of file KisCmykDitherOpFactory.h.

204 {
205 return 1.f / static_cast<float>(1 << dstCSTraits::depth);
206 }

◆ scaleToA()

template<typename srcCSTraits , typename dstCSTraits , DitherType dType>
template<typename A , typename B >
B KisCmykDitherOpImpl< srcCSTraits, dstCSTraits, dType >::scaleToA ( A c) const
inlineprivate

Definition at line 193 of file KisCmykDitherOpFactory.h.

194 {
195 return denormalize<B>(normalize<A>(c));
196 }

The documentation for this class was generated from the following file: