~smartboyhw/ubuntu/raring/calligra/2.6.0-0ubuntu1

« back to all changes in this revision

Viewing changes to libs/pigment/compositeops/KoCompositeOpBehind.h

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-10-23 21:09:16 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20121023210916-m82w6zxnxhaxz7va
Tags: 1:2.5.90-0ubuntu1
* New upstream alpha release (LP: #1070436)
  - Add libkactivities-dev and libopenimageio-dev to build-depends
  - Add kubuntu_build_calligraactive.diff to build calligraactive by default
  - Add package for calligraauthor and move files that are shared between
    calligrawords and calligraauthor to calligrawords-common
* Document the patches
* Remove numbers from patches so they follow the same naming scheme as
  the rest of our patches.
* calligra-data breaks replaces krita-data (<< 1:2.5.3) (LP: #1071686)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (c) 2012 José Luis Vergara <pentalis@gmail.com>
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
18
*/
 
19
 
 
20
#ifndef _KOCOMPOSITEOPBEHIND_H_
 
21
#define _KOCOMPOSITEOPBEHIND_H_
 
22
 
 
23
#include "KoCompositeOpBase.h"
 
24
 
 
25
/**
 
26
 *  Generic implementation of the Behind composite op, which blends the colors of a foreground layer as if it were in the background instead
 
27
 */
 
28
template<class CS_Traits>
 
29
class KoCompositeOpBehind : public KoCompositeOpBase<CS_Traits, KoCompositeOpBehind<CS_Traits> >
 
30
{
 
31
    typedef KoCompositeOpBase<CS_Traits, KoCompositeOpBehind<CS_Traits> > base_class;
 
32
    typedef typename CS_Traits::channels_type channels_type;
 
33
 
 
34
    static const qint8 channels_nb = CS_Traits::channels_nb;
 
35
    static const qint8 alpha_pos   = CS_Traits::alpha_pos;
 
36
 
 
37
public:
 
38
    KoCompositeOpBehind(const KoColorSpace * cs)
 
39
        : base_class(cs, COMPOSITE_BEHIND, i18n("Behind"), KoCompositeOp::categoryMix()) { }
 
40
 
 
41
public:
 
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;
 
48
                
 
49
        if (dstAlpha     == unitValue<channels_type>()) return dstAlpha;
 
50
        channels_type appliedAlpha       = mul(maskAlpha, srcAlpha, opacity);
 
51
        
 
52
        if (appliedAlpha == zeroValue<channels_type>()) return dstAlpha;
 
53
        channels_type newDstAlpha        = unionShapeOpacity(dstAlpha, appliedAlpha);
 
54
        
 
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*/
 
63
        }
 
64
        else {
 
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];
 
70
        }
 
71
 
 
72
        return newDstAlpha;
 
73
    }
 
74
};
 
75
 
 
76
#endif  // _KOCOMPOSITEOPBEHIND_H_
 
 
b'\\ No newline at end of file'