1 /*
2  *  Copyright (c) 2016 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3  *  Copyright (c) 2012 José Luis Vergara <pentalis@gmail.com>
4  *
5  * This library is free software; 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 Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
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.
14  *
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 Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19 */
20 
21 #ifndef _KOCOMPOSITEOPDESTINATIONIN_H_
22 #define _KOCOMPOSITEOPDESTINATIONIN_H_
23 
24 #include "KoCompositeOpBase.h"
25 
26 /**
27  *  Generic implementation of the Destination-in composite op, based off the behind composite op.
28  *  This is necessary for Open Raster support.
29  *  https://www.w3.org/TR/compositing-1/
30  */
31 template<class CS_Traits>
32 class KoCompositeOpDestinationIn : public KoCompositeOpBase<CS_Traits, KoCompositeOpDestinationIn<CS_Traits> >
33 {
34     typedef KoCompositeOpBase<CS_Traits, KoCompositeOpDestinationIn<CS_Traits> > base_class;
35     typedef typename CS_Traits::channels_type channels_type;
36 
37     static const qint8 channels_nb = CS_Traits::channels_nb;
38     static const qint8 alpha_pos   = CS_Traits::alpha_pos;
39 
40 public:
KoCompositeOpDestinationIn(const KoColorSpace * cs)41     KoCompositeOpDestinationIn(const KoColorSpace * cs)
42         : base_class(cs, COMPOSITE_DESTINATION_IN, i18n("Destination In"), KoCompositeOp::categoryMix()) { }
43 
44 public:
45     template<bool alphaLocked, bool allChannelFlags>
composeColorChannels(const channels_type * src,channels_type srcAlpha,channels_type * dst,channels_type dstAlpha,channels_type maskAlpha,channels_type opacity,const QBitArray & channelFlags)46     inline static channels_type composeColorChannels(const channels_type* src, channels_type srcAlpha,
47                                                      channels_type*       dst, channels_type dstAlpha,
48                                                      channels_type  maskAlpha, channels_type  opacity,
49                                                      const QBitArray& channelFlags                    )  {
50         using namespace Arithmetic;
51         Q_UNUSED(src);
52         Q_UNUSED(dst);
53         Q_UNUSED(channelFlags);
54 
55         channels_type appliedAlpha       = mul(maskAlpha, srcAlpha, opacity);
56 
57         channels_type newDstAlpha        = mul(dstAlpha, appliedAlpha);
58 
59         return newDstAlpha;
60     }
61 };
62 
63 #endif  // _KOCOMPOSITEOPDESTINATIONIN_H_
64