~ubuntu-branches/ubuntu/oneiric/koffice/oneiric-updates

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (c) 2007 Cyrille Berger <cberger@cberger.net>
 
3
 *  Copyright (c) 2010 Boudewijn Rempt <boud@valdyas.org>
 
4
 *
 
5
 * This library is free hardware; 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 Hardware Foundation; either
 
8
 * version 2 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 Hardware Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
 * Boston, MA 02110-1301, USA.
 
19
*/
 
20
 
 
21
#ifndef KOCOMPOSITEOPHARDLIGHT_H_
 
22
#define KOCOMPOSITEOPHARDLIGHT_H_
 
23
 
 
24
#include "KoCompositeOpAlphaBase.h"
 
25
 
 
26
/**
 
27
 * A template version of the hard light composite operation to use in colorspaces.
 
28
 */
 
29
template<class _CSTraits>
 
30
class KoCompositeOpHardlight : public KoCompositeOpAlphaBase<_CSTraits, KoCompositeOpHardlight<_CSTraits>, true >
 
31
{
 
32
    typedef typename _CSTraits::channels_type channels_type;
 
33
public:
 
34
 
 
35
    KoCompositeOpHardlight(const KoColorSpace * cs)
 
36
        : KoCompositeOpAlphaBase<_CSTraits, KoCompositeOpHardlight<_CSTraits>, true >(cs, COMPOSITE_HARD_LIGHT, i18n("Hard light"), KoCompositeOp::categoryLight()) {
 
37
    }
 
38
 
 
39
public:
 
40
    inline static channels_type selectAlpha(channels_type srcAlpha, channels_type dstAlpha) {
 
41
        return qMin(srcAlpha, dstAlpha);
 
42
    }
 
43
 
 
44
    inline static void composeColorChannels(channels_type srcBlend,
 
45
                                            const channels_type* src,
 
46
                                            channels_type* dst,
 
47
                                            bool allChannelFlags,
 
48
                                            const QBitArray & channelFlags) {
 
49
        for (uint i = 0; i < _CSTraits::channels_nb; i++) {
 
50
            if ((int)i != _CSTraits::alpha_pos  && (allChannelFlags || channelFlags.testBit(i))) {
 
51
 
 
52
                channels_type srcChannel = src[i];
 
53
                channels_type dstChannel = dst[i];
 
54
 
 
55
                if (srcChannel <= NATIVE_MAX_VALUE / 2) {
 
56
                    // Multiply
 
57
                    srcChannel = srcChannel * 2;
 
58
                    srcChannel = KoColorSpaceMaths<channels_type>::multiply(srcChannel, dstChannel);
 
59
                    dst[i] = KoColorSpaceMaths<channels_type>::blend(srcChannel, dstChannel, srcBlend);
 
60
                }
 
61
                else {
 
62
                    // Screen
 
63
                    srcChannel = 2 * srcChannel - NATIVE_MAX_VALUE;
 
64
                    srcChannel = NATIVE_MAX_VALUE - KoColorSpaceMaths<channels_type>::multiply(NATIVE_MAX_VALUE - dstChannel, NATIVE_MAX_VALUE - srcChannel);
 
65
                    dst[i] = KoColorSpaceMaths<channels_type>::blend(srcChannel, dstChannel, srcBlend);
 
66
                }
 
67
            }
 
68
        }
 
69
    }
 
70
 
 
71
};
 
72
 
 
73
#endif