File indexing completed on 2024-12-22 04:11:38

0001 /*
0002  *  SPDX-FileCopyrightText: 2016 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
0003  *  SPDX-FileCopyrightText: 2012 José Luis Vergara <pentalis@gmail.com>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.1-or-later
0006 */
0007 
0008 #ifndef _KOCOMPOSITEOPDESTINATIONIN_H_
0009 #define _KOCOMPOSITEOPDESTINATIONIN_H_
0010 
0011 #include "KoCompositeOpBase.h"
0012 
0013 /**
0014  *  Generic implementation of the Destination-in composite op, based off the behind composite op.
0015  *  This is necessary for Open Raster support.
0016  *  https://www.w3.org/TR/compositing-1/
0017  */
0018 template<class CS_Traits>
0019 class KoCompositeOpDestinationIn : public KoCompositeOpBase<CS_Traits, KoCompositeOpDestinationIn<CS_Traits> >
0020 {
0021     typedef KoCompositeOpBase<CS_Traits, KoCompositeOpDestinationIn<CS_Traits> > base_class;
0022     typedef typename CS_Traits::channels_type channels_type;
0023 
0024     static const qint8 channels_nb = CS_Traits::channels_nb;
0025     static const qint8 alpha_pos   = CS_Traits::alpha_pos;
0026 
0027 public:
0028     KoCompositeOpDestinationIn(const KoColorSpace * cs)
0029         : base_class(cs, COMPOSITE_DESTINATION_IN, KoCompositeOp::categoryMix()) { }
0030 
0031 public:
0032     template<bool alphaLocked, bool allChannelFlags>
0033     inline static channels_type composeColorChannels(const channels_type* src, channels_type srcAlpha,
0034                                                      channels_type*       dst, channels_type dstAlpha,
0035                                                      channels_type  maskAlpha, channels_type  opacity,
0036                                                      const QBitArray& channelFlags                    )  {
0037         using namespace Arithmetic;
0038         Q_UNUSED(src);
0039         Q_UNUSED(dst);
0040         Q_UNUSED(channelFlags);
0041 
0042         channels_type appliedAlpha       = mul(maskAlpha, srcAlpha, opacity);
0043 
0044         channels_type newDstAlpha        = mul(dstAlpha, appliedAlpha);
0045 
0046         return newDstAlpha;
0047     }
0048 };
0049 
0050 #endif  // _KOCOMPOSITEOPDESTINATIONIN_H_