Krita Source Code Documentation
Loading...
Searching...
No Matches
KoMixColorsOpImpl< _CSTrait >::MixDataResult Class Reference

Public Member Functions

template<class AbstractSource , class WeightsWrapper >
void accumulateColors (AbstractSource source, WeightsWrapper weightsWrapper, int nColors)
 
void computeMixedColor (quint8 *dst)
 
qint64 currentWeightsSum () const
 
 MixDataResult ()
 

Private Types

using channels_type = typename _CSTrait::channels_type
 
using MathsTraits = KoColorSpaceMathsTraits<channels_type>
 
using mix_type = typename KoColorSpaceMathsTraits<channels_type>::mixtype
 

Private Attributes

qint64 normalizeFactor = 0
 
mix_type totalAlpha = 0
 
mix_type totals [_CSTrait::channels_nb]
 

Detailed Description

template<class _CSTrait>
class KoMixColorsOpImpl< _CSTrait >::MixDataResult

Definition at line 188 of file KoMixColorsOpImpl.h.

Member Typedef Documentation

◆ channels_type

template<class _CSTrait >
using KoMixColorsOpImpl< _CSTrait >::MixDataResult::channels_type = typename _CSTrait::channels_type
private

Definition at line 189 of file KoMixColorsOpImpl.h.

◆ MathsTraits

template<class _CSTrait >
using KoMixColorsOpImpl< _CSTrait >::MixDataResult::MathsTraits = KoColorSpaceMathsTraits<channels_type>
private

Definition at line 191 of file KoMixColorsOpImpl.h.

◆ mix_type

template<class _CSTrait >
using KoMixColorsOpImpl< _CSTrait >::MixDataResult::mix_type = typename KoColorSpaceMathsTraits<channels_type>::mixtype
private

Definition at line 190 of file KoMixColorsOpImpl.h.

Constructor & Destructor Documentation

◆ MixDataResult()

template<class _CSTrait >
KoMixColorsOpImpl< _CSTrait >::MixDataResult::MixDataResult ( )
inline

Definition at line 202 of file KoMixColorsOpImpl.h.

202 {
203 memset(totals, 0, sizeof(totals));
204 }
mix_type totals[_CSTrait::channels_nb]

References KoMixColorsOpImpl< _CSTrait >::MixDataResult::totals.

Member Function Documentation

◆ accumulateColors()

template<class _CSTrait >
template<class AbstractSource , class WeightsWrapper >
void KoMixColorsOpImpl< _CSTrait >::MixDataResult::accumulateColors ( AbstractSource source,
WeightsWrapper weightsWrapper,
int nColors )
inline

Definition at line 260 of file KoMixColorsOpImpl.h.

260 {
261 // Compute the total for each channel by summing each colors multiplied by the weightlabcache
262
263#ifdef SANITY_CHECKS
264 m_numPixels += nColors;
265#endif
266
267 while (nColors--) {
268 const channels_type* color = _CSTrait::nativeArray(source.getPixel());
269 mix_type alphaTimesWeight;
270
271 if (_CSTrait::alpha_pos != -1) {
272 alphaTimesWeight = color[_CSTrait::alpha_pos];
273 } else {
274 alphaTimesWeight = MathsTraits::unitValue;
275 }
276
277 weightsWrapper.premultiplyAlphaWithWeight(alphaTimesWeight);
278
279 for (int i = 0; i < (int)_CSTrait::channels_nb; i++) {
280 if (i != _CSTrait::alpha_pos) {
281 totals[i] += color[i] * alphaTimesWeight;
282 }
283 }
284
285 totalAlpha += alphaTimesWeight;
286 source.nextPixel();
287 weightsWrapper.nextPixel();
288 }
289
290 normalizeFactor += weightsWrapper.normalizeFactor();
291 }
KisMagneticGraph::vertex_descriptor source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
typename _CSTrait::channels_type channels_type
typename KoColorSpaceMathsTraits< channels_type >::mixtype mix_type

References KoMixColorsOpImpl< _CSTrait >::WeightsWrapper::nextPixel(), KoMixColorsOpImpl< _CSTrait >::WeightsWrapper::normalizeFactor(), KoMixColorsOpImpl< _CSTrait >::MixDataResult::normalizeFactor, KoMixColorsOpImpl< _CSTrait >::WeightsWrapper::premultiplyAlphaWithWeight(), source(), KoMixColorsOpImpl< _CSTrait >::MixDataResult::totalAlpha, and KoMixColorsOpImpl< _CSTrait >::MixDataResult::totals.

◆ computeMixedColor()

template<class _CSTrait >
void KoMixColorsOpImpl< _CSTrait >::MixDataResult::computeMixedColor ( quint8 * dst)
inline

FIXME: The following code relies on the unit value for floating point spaces being 1.0 We should be using the division functions in KoColorSpaceMaths for this, but right now it is not clear how to call these functions.

Definition at line 206 of file KoMixColorsOpImpl.h.

206 {
207#ifdef SANITY_CHECKS
208
209 const mix_type maxSaneNumPixels =
210 std::numeric_limits<mix_type>::max() / pow2(mix_type(MathsTraits::unitValue));
211
212 if (m_numPixels > maxSaneNumPixels) {
213 qWarning() << "SANITY CHECK FAILED: KoMixColorOp got too many pixels to mix, the containing type may overflow";
214 qWarning() << " " << ppVar(m_numPixels);
215 qWarning() << " " << ppVar(maxSaneNumPixels);
216 }
217#endif
218
219 channels_type* dstColor = _CSTrait::nativeArray(dst);
220
226 if (totalAlpha > 0) {
227
228 for (int i = 0; i < (int)_CSTrait::channels_nb; i++) {
229 if (i != _CSTrait::alpha_pos) {
230
232
233 if (v > MathsTraits::max) {
234 v = MathsTraits::max;
235 }
236 if (v < MathsTraits::min) {
237 v = MathsTraits::min;
238 }
239 dstColor[ i ] = v;
240 }
241 }
242
243 if (_CSTrait::alpha_pos != -1) {
245
246 if (v > MathsTraits::max) {
247 v = MathsTraits::max;
248 }
249 if (v < MathsTraits::min) {
250 v = MathsTraits::min;
251 }
252 dstColor[ _CSTrait::alpha_pos ] = v;
253 }
254 } else {
255 memset(dst, 0, sizeof(channels_type) * _CSTrait::channels_nb);
256 }
257 }
qreal v
static T safeDivideWithRound(T dividend, std::enable_if_t<!std::numeric_limits< T >::is_integer, T > divisor)
#define ppVar(var)
Definition kis_debug.h:155
T pow2(const T &x)
Definition kis_global.h:166

References KoMixColorsOpImpl< _CSTrait >::MixDataResult::normalizeFactor, pow2(), ppVar, safeDivideWithRound(), KoMixColorsOpImpl< _CSTrait >::MixDataResult::totalAlpha, KoMixColorsOpImpl< _CSTrait >::MixDataResult::totals, and v.

◆ currentWeightsSum()

template<class _CSTrait >
qint64 KoMixColorsOpImpl< _CSTrait >::MixDataResult::currentWeightsSum ( ) const
inline

Definition at line 293 of file KoMixColorsOpImpl.h.

294 {
295 return normalizeFactor;
296 }

References KoMixColorsOpImpl< _CSTrait >::MixDataResult::normalizeFactor.

Member Data Documentation

◆ normalizeFactor

template<class _CSTrait >
qint64 KoMixColorsOpImpl< _CSTrait >::MixDataResult::normalizeFactor = 0
private

Definition at line 195 of file KoMixColorsOpImpl.h.

◆ totalAlpha

template<class _CSTrait >
mix_type KoMixColorsOpImpl< _CSTrait >::MixDataResult::totalAlpha = 0
private

Definition at line 194 of file KoMixColorsOpImpl.h.

◆ totals

template<class _CSTrait >
mix_type KoMixColorsOpImpl< _CSTrait >::MixDataResult::totals[_CSTrait::channels_nb]
private

Definition at line 193 of file KoMixColorsOpImpl.h.


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