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

« back to all changes in this revision

Viewing changes to krita/plugins/colorspaces/ctlcs/KoCtlChannel.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) 2009 Cyrille Berger <cberger@cberger.net>
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 _KO_CTL_CHANNEL_H_
21
 
#define _KO_CTL_CHANNEL_H_
22
 
 
23
 
#include <QtGlobal>
24
 
#include <QString>
25
 
#include <KoColorSpaceMaths.h>
26
 
#include <KoColorSpaceConstants.h>
27
 
 
28
 
class KoCtlChannel
29
 
{
30
 
public:
31
 
    virtual ~KoCtlChannel();
32
 
    virtual QString channelValueText(const quint8 *pixel) const = 0;
33
 
    virtual QString normalisedChannelValueText(const quint8 *pixel) const = 0;
34
 
    virtual quint8 scaleToU8(const quint8 * srcPixel) const = 0;
35
 
    virtual void scaleFromU8(quint8 * dstPixel, quint8 value) const = 0;
36
 
    virtual quint16 scaleToU16(const quint8 * srcPixel) const = 0;
37
 
    virtual float scaleToF32(const quint8 * srcPixel) const = 0;
38
 
    virtual void scaleFromF32(quint8 * dstPixel, float value) const = 0;
39
 
    virtual void singleChannelPixel(quint8 *dstPixel, const quint8 *srcPixel) const = 0;
40
 
    virtual void multiplyU8(quint8 * pixels, quint8 alpha, qint32 nPixels) const = 0;
41
 
    virtual void applyU8Mask(quint8 * pixels, const quint8 * alpha, qint32 nPixels) const = 0;
42
 
    virtual void applyInverseU8Mask(quint8 * pixels, const quint8 * alpha, qint32 nPixels) const = 0;
43
 
};
44
 
 
45
 
#include<iostream>
46
 
#include<cstdlib>
47
 
 
48
 
template<typename _ChannelType_>
49
 
class KoCtlChannelImpl : public KoCtlChannel
50
 
{
51
 
public:
52
 
    KoCtlChannelImpl(quint32 _pos, quint32 _pixelSize) : m_pos(_pos), m_pixelSize(_pixelSize) { }
53
 
    virtual ~KoCtlChannelImpl() {}
54
 
    virtual QString channelValueText(const quint8* pixel) const {
55
 
        return QString::number(*channel(pixel));
56
 
    }
57
 
    virtual QString normalisedChannelValueText(const quint8* pixel) const {
58
 
        return QString::number(scaleToF32(pixel));
59
 
    }
60
 
    virtual quint8 scaleToU8(const quint8* srcPixel) const {
61
 
        return KoColorSpaceMaths<_ChannelType_, quint8>::scaleToA(*channel(srcPixel));
62
 
    }
63
 
    virtual void scaleFromU8(quint8 * dstPixel, quint8 value) const {
64
 
        *channel(dstPixel) = KoColorSpaceMaths<quint8, _ChannelType_ >::scaleToA(value);
65
 
    }
66
 
    virtual quint16 scaleToU16(const quint8* srcPixel) const {
67
 
        return KoColorSpaceMaths<_ChannelType_, quint16>::scaleToA(*channel(srcPixel));
68
 
    }
69
 
    virtual float scaleToF32(const quint8* srcPixel) const {
70
 
        return KoColorSpaceMaths<_ChannelType_, float>::scaleToA(*channel(srcPixel));
71
 
    }
72
 
    virtual void singleChannelPixel(quint8* dstPixel, const quint8 *srcPixel) const {
73
 
        *channel(dstPixel) = *channel(srcPixel);
74
 
    }
75
 
    virtual void scaleFromF32(quint8* dstPixel, float value) const {
76
 
        *channel(dstPixel) = KoColorSpaceMaths<float, _ChannelType_ >::scaleToA(value);
77
 
    }
78
 
    virtual void multiplyU8(quint8 * pixels, quint8 alpha, qint32 nPixels) const {
79
 
        _ChannelType_ valpha =  KoColorSpaceMaths<quint8, _ChannelType_>::scaleToA(alpha);
80
 
 
81
 
        for (; nPixels > 0; --nPixels, pixels += m_pixelSize) {
82
 
            _ChannelType_* alphapixel = channel(pixels);
83
 
            *alphapixel = KoColorSpaceMaths<_ChannelType_>::multiply(*alphapixel, valpha);
84
 
        }
85
 
    }
86
 
 
87
 
    virtual void applyU8Mask(quint8 * pixels, const quint8 * alpha, qint32 nPixels) const {
88
 
        for (; nPixels > 0; --nPixels, pixels += m_pixelSize, ++alpha) {
89
 
            _ChannelType_ valpha =  KoColorSpaceMaths<quint8, _ChannelType_>::scaleToA(*alpha);
90
 
            _ChannelType_* alphapixel = channel(pixels);
91
 
            *alphapixel = KoColorSpaceMaths<_ChannelType_>::multiply(*alphapixel, valpha);
92
 
        }
93
 
    }
94
 
 
95
 
    virtual void applyInverseU8Mask(quint8 * pixels, const quint8 * alpha, qint32 nPixels) const {
96
 
        for (; nPixels > 0; --nPixels, pixels += m_pixelSize, ++alpha) {
97
 
            _ChannelType_ valpha =  KoColorSpaceMaths<quint8, _ChannelType_>::scaleToA(OPACITY_OPAQUE_U8 - *alpha);
98
 
            _ChannelType_* alphapixel = channel(pixels);
99
 
            *alphapixel = KoColorSpaceMaths<_ChannelType_>::multiply(*alphapixel, valpha);
100
 
        }
101
 
    }
102
 
private:
103
 
    inline const _ChannelType_* channel(const quint8* pixel) const {
104
 
        return reinterpret_cast<const _ChannelType_*>(pixel + m_pos);
105
 
    }
106
 
    inline _ChannelType_* channel(quint8* pixel) const {
107
 
        return reinterpret_cast<_ChannelType_*>(pixel + m_pos);
108
 
    }
109
 
private:
110
 
    quint32 m_pos;
111
 
    quint32 m_pixelSize;
112
 
};
113
 
 
114
 
 
115
 
 
116
 
#endif