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

0001 /*
0002  * SPDX-FileCopyrightText: 2011 Silvio Heinrich <plassy@web.de>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 #ifndef _KOCOMPOSITEOP_COPY_CHANNEL_H_
0008 #define _KOCOMPOSITEOP_COPY_CHANNEL_H_
0009 
0010 #include "KoCompositeOpBase.h"
0011 
0012 /**
0013  * KoCompositeOpCopyChannel class
0014  * 
0015  * This class creates a CompositeOp that will just copy/blend
0016  * a source channel to a destination channel
0017  * 
0018  * @param channel_pos the channel to copy/blend
0019  */
0020 template<class Traits, qint32 channel_pos>
0021 class KoCompositeOpCopyChannel: public KoCompositeOpBase< Traits, KoCompositeOpCopyChannel<Traits,channel_pos> >
0022 {
0023     typedef KoCompositeOpBase< Traits, KoCompositeOpCopyChannel<Traits,channel_pos> > base_class;
0024     typedef typename Traits::channels_type                                            channels_type;
0025     typedef typename KoColorSpaceMathsTraits<channels_type>::compositetype            composite_type;
0026     
0027     static const qint32 alpha_pos = Traits::alpha_pos;
0028     
0029 public:
0030     KoCompositeOpCopyChannel(const KoColorSpace* cs, const QString& id, const QString& category)
0031         : base_class(cs, id, category) { }
0032 
0033 public:
0034     template<bool alphaLocked, bool allChannelFlags>
0035     inline static channels_type composeColorChannels(const channels_type* src, channels_type srcAlpha,
0036                                                      channels_type*       dst, channels_type dstAlpha, channels_type maskAlpha,
0037                                                      channels_type opacity, const QBitArray& channelFlags) {
0038         using namespace Arithmetic;
0039         opacity = mul(opacity, maskAlpha);
0040         
0041         if(allChannelFlags || channelFlags.testBit(channel_pos)) {
0042             if(channel_pos == alpha_pos)
0043                 return lerp(dstAlpha, srcAlpha, opacity);
0044             
0045             srcAlpha = mul(srcAlpha, opacity);
0046             dst[channel_pos] = lerp(dst[channel_pos], src[channel_pos], srcAlpha);
0047         }
0048         
0049         return dstAlpha;
0050     }
0051 };
0052 
0053 #endif // _KOCOMPOSITEOP_COPY_CHANNEL_H_