KoAlphaColorSpace.h 6.25 KB
Newer Older
1
/*
2
 *  Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
3
 *  Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
4 5
 *
 *  This program is free software; you can redistribute it and/or modify
6
 *  it under the terms of the GNU Lesser General Public License as published by
7 8 9 10 11 12
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU Lesser General Public License for more details.
14
 *
15
 *  You should have received a copy of the Lesser GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
 */
19 20
#ifndef KOALPHACOLORSPACE_H
#define KOALPHACOLORSPACE_H
21

22
#include <QColor>
23
#include <QBitArray>
24

25
#include <pigment_export.h>
26

27
#include "KoLcmsColorSpace.h"
28
#include "KoColorSpaceTraits.h"
29

30 31
#include "KoColorModelStandardIds.h"

32
typedef KoColorSpaceTrait<quint8, 1, 0> AlphaU8Traits;
33

34
/**
Boudewijn Rempt's avatar
Boudewijn Rempt committed
35
 * The alpha mask is a special color strategy that treats all pixels as
36
 * alpha value with a color common to the mask. The default color is white.
37
 */
Jarosław Staniek's avatar
Jarosław Staniek committed
38
class PIGMENTCMS_EXPORT KoAlphaColorSpace : public KoColorSpaceAbstract<AlphaU8Traits> {
39
public:
40
    KoAlphaColorSpace();
41
    virtual ~KoAlphaColorSpace();
42 43
    virtual KoID colorModelId() const { return AlphaColorModelID; }
    virtual KoID colorDepthId() const { return Integer8BitsColorDepthID; }
Cyrille Berger's avatar
Cyrille Berger committed
44
    virtual KoColorSpace* clone() const;
45

46
public:
Cyrille Berger's avatar
Cyrille Berger committed
47
    virtual bool willDegrade(ColorSpaceIndependence independence) const
48
        {
49
            Q_UNUSED(independence);
50
            return false;
51
        }
52

53
    virtual bool profileIsCompatible(const KoColorProfile* /*profile*/) const {
54 55 56
        return false;
    }

57 58
    virtual void fromQColor(const QColor& color, quint8 *dst, const KoColorProfile * profile = 0) const;
    virtual void fromQColor(const QColor& color, quint8 opacity, quint8 *dst, const KoColorProfile * profile = 0) const;
Boudewijn Rempt's avatar
Boudewijn Rempt committed
59

60 61
    virtual void toQColor(const quint8 *src, QColor *c, const KoColorProfile * profile = 0) const;
    virtual void toQColor(const quint8 *src, QColor *c, quint8 *opacity, const KoColorProfile * profile = 0) const;
62

63
    virtual quint8 difference(const quint8 *src1, const quint8 *src2) const;
Laurent Montel's avatar
Laurent Montel committed
64
    virtual void mixColors(const quint8 **colors, const quint8 *weights, quint32 nColors, quint8 *dst) const;
65

66
    virtual quint32 colorChannelCount() const { return 0; }
67

Laurent Montel's avatar
Laurent Montel committed
68 69
    virtual QString channelValueText(const quint8 *pixel, quint32 channelIndex) const;
    virtual QString normalisedChannelValueText(const quint8 *pixel, quint32 channelIndex) const;
70

71
    virtual void convolveColors(quint8** colors, qint32* kernelValues, quint8 *dst, qint32 factor, qint32 offset, qint32 nColors, const QBitArray & channelFlags) const;
72

73

Cyrille Berger's avatar
Cyrille Berger committed
74 75 76 77
    virtual quint32 colorSpaceType() const { return 0; }
    virtual icColorSpaceSignature colorSpaceSignature() const { return icSigGrayData; }

    virtual bool hasHighDynamicRange() const { return false; }
78
    virtual const KoColorProfile* profile() const { return 0; }
79
    virtual KoColorProfile* profile() { return 0; }
80
    virtual QImage convertToQImage(const quint8 *data, qint32 width, qint32 height,
81
                                   const KoColorProfile *  dstProfile, KoColorConversionTransformation::Intent renderingIntent) const;
82 83

    virtual void toLabA16(const quint8* src, quint8* dst, quint32 nPixels) const
Cyrille Berger's avatar
Cyrille Berger committed
84 85
    {
        quint16* lab = reinterpret_cast<quint16*>(dst);
86
        while(nPixels--)
Cyrille Berger's avatar
Cyrille Berger committed
87 88 89 90 91 92
        {
            lab[3] = src[0];
            src++;
            lab+=4;
        }
    }
93
    virtual void fromLabA16(const quint8* src, quint8* dst, quint32 nPixels) const
Cyrille Berger's avatar
Cyrille Berger committed
94 95
    {
        const quint16* lab = reinterpret_cast<const quint16*>(src);
96
        while(nPixels--)
Cyrille Berger's avatar
Cyrille Berger committed
97 98 99 100 101 102
        {
            dst[0] = lab[3];
            dst++;
            lab+=4;
        }
    }
103

104
    virtual void toRgbA16(const quint8* src, quint8* dst, quint32 nPixels) const
Cyrille Berger's avatar
Cyrille Berger committed
105 106
    {
        quint16* rgb = reinterpret_cast<quint16*>(dst);
107
        while(nPixels--)
Cyrille Berger's avatar
Cyrille Berger committed
108 109 110 111 112 113
        {
            rgb[3] = src[0];
            src++;
            rgb+=4;
        }
    }
114
    virtual void fromRgbA16(const quint8* src, quint8* dst, quint32 nPixels) const
Cyrille Berger's avatar
Cyrille Berger committed
115 116
    {
        const quint16* rgb = reinterpret_cast<const quint16*>(src);
117
        while(nPixels--)
Cyrille Berger's avatar
Cyrille Berger committed
118 119 120 121 122 123
        {
            dst[0] = rgb[3];
            dst++;
            rgb+=4;
        }
    }
124
    virtual KoColorTransformation* createBrightnessContrastAdjustment(const quint16* transferValues) const
Cyrille Berger's avatar
Cyrille Berger committed
125
    {
126
        Q_UNUSED(transferValues);
127
        kDebug() <<"Undefined operation in the alpha colorspace";
Cyrille Berger's avatar
Cyrille Berger committed
128 129
        return 0;
    }
130
    virtual KoColorTransformation* createDesaturateAdjustment() const
Cyrille Berger's avatar
Cyrille Berger committed
131
    {
132
        kDebug() <<"Undefined operation in the alpha colorspace";
Cyrille Berger's avatar
Cyrille Berger committed
133 134
        return 0;
    }
135
    virtual KoColorTransformation* createPerChannelAdjustment(const quint16* const*) const
Cyrille Berger's avatar
Cyrille Berger committed
136
    {
137
        kDebug() <<"Undefined operation in the alpha colorspace";
Cyrille Berger's avatar
Cyrille Berger committed
138 139
        return 0;
    }
140
    virtual KoColorTransformation *createDarkenAdjustement(qint32 , bool , double ) const
Cyrille Berger's avatar
Cyrille Berger committed
141
    {
142
        kDebug() <<"Undefined operation in the alpha colorspace";
143
        return 0;
Cyrille Berger's avatar
Cyrille Berger committed
144 145 146
    }
    virtual void invertColor(quint8*, qint32) const
    {
147
        kDebug() <<"Undefined operation in the alpha colorspace";
Cyrille Berger's avatar
Cyrille Berger committed
148
    }
149 150 151 152 153 154 155 156
    virtual void colorToXML( const quint8* , QDomDocument& , QDomElement& ) const
    {
        kDebug() <<"Undefined operation in the alpha colorspace";
    }
    virtual void colorFromXML( quint8* , const QDomElement& )
    {
        kDebug() <<"Undefined operation in the alpha colorspace";
    }
Cyrille Berger's avatar
Cyrille Berger committed
157 158

public:
159

160 161 162 163 164 165
    /**
     * Convert a byte array of srcLen pixels *src to the specified color space
     * and put the converted bytes into the prepared byte array *dst.
     *
     * Returns false if the conversion failed, true if it succeeded
     */
Laurent Montel's avatar
Laurent Montel committed
166
    virtual bool convertPixelsTo(const quint8 *src,
Cyrille Berger's avatar
Cyrille Berger committed
167
                     quint8 *dst, const KoColorSpace * dstColorSpace,
Laurent Montel's avatar
Laurent Montel committed
168
                     quint32 numPixels,
169
                     KoColorConversionTransformation::Intent  renderingIntent = KoColorConversionTransformation::IntentPerceptual ) const;
Laurent Montel's avatar
Laurent Montel committed
170

171 172
};

173
#endif // KIS_COLORSPACE_ALPHA_H_