~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to plugins/colorengines/lcms2/compositeops/RgbCompositeOpBumpmap.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) 2006 Boudewijn Rempt <boud@valdyas.org>
 
3
 *
 
4
 *  This program is free software const; you can redistribute it and/or modify
 
5
 *  it under the terms of the GNU Lesser General Public License as published by
 
6
 *  the Free Software Foundation const; either version 2 of the License, or
 
7
 *  (at your option) any later version.
 
8
 *
 
9
 *  This program is distributed in the hope that it will be useful,
 
10
 *  but WITHOUT ANY WARRANTY const; without even the implied warranty of
 
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *  GNU 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 program const; if not, write to the Free Software
 
16
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
17
 */
 
18
 
 
19
#ifndef RGBCOMPOSITEOPBUMPMAP_H
 
20
#define RGBCOMPOSITEOPBUMPMAP_H
 
21
 
 
22
#include "KoColorSpaceMaths.h"
 
23
#include <KoCompositeOpAlphaBase.h>
 
24
 
 
25
template<class _CSTraits>
 
26
class RgbCompositeOpBumpmap : public KoCompositeOpAlphaBase<_CSTraits, RgbCompositeOpBumpmap<_CSTraits>, true >
 
27
{
 
28
    typedef typename _CSTraits::channels_type channels_type;
 
29
    typedef typename KoColorSpaceMathsTraits<typename _CSTraits::channels_type>::compositetype compositetype;
 
30
 
 
31
public:
 
32
 
 
33
    RgbCompositeOpBumpmap(KoColorSpace * cs)
 
34
            : KoCompositeOpAlphaBase<_CSTraits, RgbCompositeOpBumpmap<_CSTraits>, true >(cs, COMPOSITE_BUMPMAP, i18n("Bumpmap"),  KoCompositeOp::categoryMisc()) {
 
35
    }                       
 
36
                       
 
37
    inline static channels_type selectAlpha(channels_type srcAlpha, channels_type dstAlpha) {
 
38
        return qMin(srcAlpha, dstAlpha);
 
39
    }
 
40
 
 
41
    inline static void composeColorChannels(channels_type srcBlend,
 
42
                                            const channels_type* src,
 
43
                                            channels_type* dst,
 
44
                                            bool allChannelFlags,
 
45
                                            const QBitArray & channelFlags) {
 
46
        qreal intensity;
 
47
        
 
48
        // And I'm not sure whether this is correct, either.
 
49
        intensity = ((qreal)306.0 * src[_CSTraits::red_pos] +
 
50
                        (qreal)601.0 * src[_CSTraits::green_pos] +
 
51
                        (qreal)117.0 * src[_CSTraits::blue_pos]) / 1024.0;
 
52
                        
 
53
        for (uint i = 0; i < _CSTraits::channels_nb; i++) {
 
54
            if ((int)i != _CSTraits::alpha_pos  && (allChannelFlags || channelFlags.testBit(i))) {
 
55
                channels_type srcChannel = (channels_type)(((qreal)
 
56
                                            intensity * dst[i]) / NATIVE_OPACITY_OPAQUE + 0.5);
 
57
                channels_type dstChannel = dst[i];
 
58
 
 
59
                dst[i] = KoColorSpaceMaths<channels_type>::blend(srcChannel, dstChannel, srcBlend);
 
60
            }
 
61
        }
 
62
    }
 
63
 
 
64
};
 
65
 
 
66
#endif