2
* Copyright (c) 2007 Cyrille Berger <cberger@cberger.net>
3
* Copyright (c) 2010 Boudewijn Rempt <boud@valdyas.org>
5
* This library is free hardware; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Hardware Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public License
16
* along with this library; see the file COPYING.LIB. If not, write to
17
* the Free Hardware Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
* Boston, MA 02110-1301, USA.
21
#ifndef KOCOMPOSITEOPHARDLIGHT_H_
22
#define KOCOMPOSITEOPHARDLIGHT_H_
24
#include "KoCompositeOpAlphaBase.h"
27
* A template version of the hard light composite operation to use in colorspaces.
29
template<class _CSTraits>
30
class KoCompositeOpHardlight : public KoCompositeOpAlphaBase<_CSTraits, KoCompositeOpHardlight<_CSTraits>, true >
32
typedef typename _CSTraits::channels_type channels_type;
35
KoCompositeOpHardlight(const KoColorSpace * cs)
36
: KoCompositeOpAlphaBase<_CSTraits, KoCompositeOpHardlight<_CSTraits>, true >(cs, COMPOSITE_HARD_LIGHT, i18n("Hard light"), KoCompositeOp::categoryLight()) {
40
inline static channels_type selectAlpha(channels_type srcAlpha, channels_type dstAlpha) {
41
return qMin(srcAlpha, dstAlpha);
44
inline static void composeColorChannels(channels_type srcBlend,
45
const channels_type* src,
48
const QBitArray & channelFlags) {
49
for (uint i = 0; i < _CSTraits::channels_nb; i++) {
50
if ((int)i != _CSTraits::alpha_pos && (allChannelFlags || channelFlags.testBit(i))) {
52
channels_type srcChannel = src[i];
53
channels_type dstChannel = dst[i];
55
if (srcChannel <= NATIVE_MAX_VALUE / 2) {
57
srcChannel = srcChannel * 2;
58
srcChannel = KoColorSpaceMaths<channels_type>::multiply(srcChannel, dstChannel);
59
dst[i] = KoColorSpaceMaths<channels_type>::blend(srcChannel, dstChannel, srcBlend);
63
srcChannel = 2 * srcChannel - NATIVE_MAX_VALUE;
64
srcChannel = NATIVE_MAX_VALUE - KoColorSpaceMaths<channels_type>::multiply(NATIVE_MAX_VALUE - dstChannel, NATIVE_MAX_VALUE - srcChannel);
65
dst[i] = KoColorSpaceMaths<channels_type>::blend(srcChannel, dstChannel, srcBlend);