File indexing completed on 2024-05-19 04:24:48
0001 /* 0002 * SPDX-FileCopyrightText: 2023 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #include "KoClipMaskApplicatorBase.h" 0007 0008 void KoClipMaskApplicatorBase::fallbackLuminanceMask(quint8 *pixels, quint8 *maskPixels, const int nPixels) const{ 0009 const quint32 colorChannelsMask = 0x00FFFFFF; 0010 const float redLum = 0.2125f; 0011 const float greenLum = 0.7154f; 0012 const float blueLum = 0.0721f; 0013 const float normCoeff = 1.0f / 255.0f; 0014 0015 const QRgb *mP = reinterpret_cast<const QRgb*>(maskPixels); 0016 QRgb *sP = reinterpret_cast<QRgb*>(pixels); 0017 0018 for (int i = 0; i < nPixels; i++) { 0019 const QRgb mask = *mP; 0020 const QRgb shape = *sP; 0021 0022 const float maskValue = qAlpha(mask) * (redLum * qRed(mask) + greenLum * qGreen(mask) + blueLum * qBlue(mask)) * normCoeff; 0023 0024 const quint8 alpha = OptiRound<xsimd::generic, quint8>::roundScalar(maskValue * float(qAlpha(shape) * normCoeff)); 0025 0026 *sP = (alpha << 24) | (shape & colorChannelsMask); 0027 0028 sP++; 0029 mP++; 0030 } 0031 }