2
* Copyright (c) 2012 José Luis Vergara <pentalis@gmail.com>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public License
15
* along with this library; see the file COPYING.LIB. If not, write to
16
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301, USA.
20
#ifndef _KOCOMPOSITEOPBEHIND_H_
21
#define _KOCOMPOSITEOPBEHIND_H_
23
#include "KoCompositeOpBase.h"
26
* Generic implementation of the Behind composite op, which blends the colors of a foreground layer as if it were in the background instead
28
template<class CS_Traits>
29
class KoCompositeOpBehind : public KoCompositeOpBase<CS_Traits, KoCompositeOpBehind<CS_Traits> >
31
typedef KoCompositeOpBase<CS_Traits, KoCompositeOpBehind<CS_Traits> > base_class;
32
typedef typename CS_Traits::channels_type channels_type;
34
static const qint8 channels_nb = CS_Traits::channels_nb;
35
static const qint8 alpha_pos = CS_Traits::alpha_pos;
38
KoCompositeOpBehind(const KoColorSpace * cs)
39
: base_class(cs, COMPOSITE_BEHIND, i18n("Behind"), KoCompositeOp::categoryMix()) { }
42
template<bool alphaLocked, bool allChannelFlags>
43
inline static channels_type composeColorChannels(const channels_type* src, channels_type srcAlpha,
44
channels_type* dst, channels_type dstAlpha,
45
channels_type maskAlpha, channels_type opacity,
46
const QBitArray& channelFlags ) {
47
using namespace Arithmetic;
49
if (dstAlpha == unitValue<channels_type>()) return dstAlpha;
50
channels_type appliedAlpha = mul(maskAlpha, srcAlpha, opacity);
52
if (appliedAlpha == zeroValue<channels_type>()) return dstAlpha;
53
channels_type newDstAlpha = unionShapeOpacity(dstAlpha, appliedAlpha);
55
if (dstAlpha != zeroValue<channels_type>()) {
56
// blend the color channels as if we were painting on the layer below
57
for (qint8 channel = 0; channel < channels_nb; ++channel)
58
if(channel != alpha_pos && (allChannelFlags || channelFlags.testBit(channel)))
59
dst[channel] = /*each color blended in proportion to their calculated opacity*/
60
( (dst[channel] * dstAlpha) + (src[channel] * (appliedAlpha - mul(dstAlpha, appliedAlpha))) )
61
/*------------------------------------------------------------------------------------------------*/
62
/ newDstAlpha; /*...divided by total new opacity*/
65
// don't blend if the color of the destination is undefined (has zero opacity)
66
// copy the source channel instead
67
for (qint8 channel = 0; channel < channels_nb; ++channel)
68
if(channel != alpha_pos && (allChannelFlags || channelFlags.testBit(channel)))
69
dst[channel] = src[channel];
76
#endif // _KOCOMPOSITEOPBEHIND_H_
b'\\ No newline at end of file'