Krita Source Code Documentation
Loading...
Searching...
No Matches
KoClipMaskApplicatorBase.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
7
8void KoClipMaskApplicatorBase::fallbackLuminanceMask(quint8 *pixels, quint8 *maskPixels, const int nPixels) const{
9 const quint32 colorChannelsMask = 0x00FFFFFF;
10 const float redLum = 0.2125f;
11 const float greenLum = 0.7154f;
12 const float blueLum = 0.0721f;
13 const float normCoeff = 1.0f / 255.0f;
14
15 const QRgb *mP = reinterpret_cast<const QRgb*>(maskPixels);
16 QRgb *sP = reinterpret_cast<QRgb*>(pixels);
17
18 for (int i = 0; i < nPixels; i++) {
19 const QRgb mask = *mP;
20 const QRgb shape = *sP;
21
22 const float maskValue = qAlpha(mask) * (redLum * qRed(mask) + greenLum * qGreen(mask) + blueLum * qBlue(mask)) * normCoeff;
23
24 const quint8 alpha = OptiRound<xsimd::generic, quint8>::roundScalar(maskValue * float(qAlpha(shape) * normCoeff));
25
26 *sP = (alpha << 24) | (shape & colorChannelsMask);
27
28 sP++;
29 mP++;
30 }
31}
unsigned int QRgb
virtual void fallbackLuminanceMask(quint8 *pixels, quint8 *maskPixels, const int nPixels) const
fallbackLuminanceMask This is the fallback algorithm for leftover pixels that for whatever reason can...
static ALWAYS_INLINE result_type roundScalar(const float value)