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

« back to all changes in this revision

Viewing changes to libs/pigment/colorspaces/KoSimpleColorSpace.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (c) 2004-2009 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
 *  the Free Software Foundation; either version 2 of the License, or
 
8
 *  (at your option) any later version.
 
9
 *
 
10
 *  This program 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
 
13
 *  GNU 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 program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
18
 */
 
19
#ifndef KOSIMPLECOLORSPACE_H
 
20
#define KOSIMPLECOLORSPACE_H
 
21
 
 
22
#include <QColor>
 
23
#include <QBitArray>
 
24
 
 
25
#include "DebugPigment.h"
 
26
 
 
27
#include "KoColorSpaceAbstract.h"
 
28
#include "KoColorSpaceTraits.h"
 
29
#include "KoSimpleColorSpaceFactory.h"
 
30
#include "KoColorModelStandardIds.h"
 
31
#include "colorprofiles/KoDummyColorProfile.h"
 
32
 
 
33
template<class _CSTraits>
 
34
class KoSimpleColorSpace : public KoColorSpaceAbstract<_CSTraits>
 
35
{
 
36
 
 
37
public:
 
38
 
 
39
    KoSimpleColorSpace(const QString& id,
 
40
                       const QString& name,
 
41
                       const KoID& colorModelId,
 
42
                       const KoID& colorDepthId)
 
43
            : KoColorSpaceAbstract<_CSTraits>(id, name)
 
44
            , m_name(name)
 
45
            , m_colorModelId(colorModelId)
 
46
            , m_colorDepthId(colorDepthId)
 
47
            , m_profile(new KoDummyColorProfile) {
 
48
    }
 
49
 
 
50
    virtual ~KoSimpleColorSpace() {
 
51
        delete m_profile;
 
52
    }
 
53
 
 
54
    virtual KoID colorModelId() const {
 
55
        return m_colorModelId;
 
56
    }
 
57
 
 
58
    virtual KoID colorDepthId() const {
 
59
        return m_colorDepthId;
 
60
    }
 
61
 
 
62
    virtual bool willDegrade(ColorSpaceIndependence independence) const {
 
63
        Q_UNUSED(independence);
 
64
        return false;
 
65
    }
 
66
 
 
67
    virtual bool profileIsCompatible(const KoColorProfile* /*profile*/) const {
 
68
        return true;
 
69
    }
 
70
 
 
71
    virtual quint8 difference(const quint8 *src1, const quint8 *src2) const {
 
72
        Q_UNUSED(src1);
 
73
        Q_UNUSED(src2);
 
74
        warnPigment << i18n("Undefined operation in the %1 space").arg(m_name);
 
75
        return 0;
 
76
    }
 
77
 
 
78
    virtual quint32 colorSpaceType() const {
 
79
        return 0;
 
80
    }
 
81
 
 
82
    virtual bool hasHighDynamicRange() const {
 
83
        return false;
 
84
    }
 
85
 
 
86
    virtual const KoColorProfile* profile() const {
 
87
        return m_profile;
 
88
    }
 
89
 
 
90
    virtual KoColorProfile* profile() {
 
91
        return m_profile;
 
92
    }
 
93
 
 
94
    virtual KoColorTransformation* createBrightnessContrastAdjustment(const quint16*) const {
 
95
        warnPigment << i18n("Undefined operation in the %1 space").arg(m_name);
 
96
        return 0;
 
97
    }
 
98
 
 
99
    virtual KoColorTransformation* createDesaturateAdjustment() const {
 
100
        warnPigment << i18n("Undefined operation in the %1 color space").arg(m_name);
 
101
        return 0;
 
102
    }
 
103
 
 
104
    virtual KoColorTransformation* createPerChannelAdjustment(const quint16* const*) const {
 
105
        warnPigment << i18n("Undefined operation in the %1 color space").arg(m_name);
 
106
        return 0;
 
107
    }
 
108
 
 
109
    virtual KoColorTransformation *createDarkenAdjustment(qint32 , bool , qreal) const {
 
110
        warnPigment << i18n("Undefined operation in the %1 color space").arg(m_name);
 
111
        return 0;
 
112
    }
 
113
 
 
114
    virtual void invertColor(quint8*, qint32) const {
 
115
        warnPigment << i18n("Undefined operation in the %1 color space").arg(m_name);
 
116
    }
 
117
 
 
118
    virtual void colorToXML(const quint8* , QDomDocument& , QDomElement&) const {
 
119
        warnPigment << i18n("Undefined operation in the %1 color space").arg(m_name);
 
120
    }
 
121
 
 
122
    virtual void colorFromXML(quint8* , const QDomElement&) const {
 
123
        warnPigment << i18n("Undefined operation in the %1 color space").arg(m_name);
 
124
    }
 
125
 
 
126
    virtual void toLabA16(const quint8* src, quint8* dst, quint32 nPixels) const {
 
127
        if (colorDepthId() == Integer16BitsColorDepthID && colorModelId() == LABAColorModelID) {
 
128
            memcpy(dst, src, nPixels * 2);
 
129
        } else {
 
130
            const KoColorSpace* dstCs = KoColorSpaceRegistry::instance()->lab16();
 
131
            convertPixelsTo(src, dst, dstCs, nPixels);
 
132
        }
 
133
    }
 
134
 
 
135
    virtual void fromLabA16(const quint8* src, quint8* dst, quint32 nPixels) const {
 
136
        if (colorDepthId() == Integer16BitsColorDepthID && colorModelId() == LABAColorModelID) {
 
137
            memcpy(dst, src, nPixels * 2);
 
138
        } else {
 
139
            const KoColorSpace* srcCs = KoColorSpaceRegistry::instance()->lab16();
 
140
            srcCs->convertPixelsTo(src, dst, this, nPixels);
 
141
        }
 
142
    }
 
143
 
 
144
    virtual void toRgbA16(const quint8* src, quint8* dst, quint32 nPixels) const {
 
145
        if (colorDepthId() == Integer16BitsColorDepthID && colorModelId() == RGBAColorModelID) {
 
146
            memcpy(dst, src, nPixels * 2);
 
147
        } else {
 
148
            const KoColorSpace* dstCs = KoColorSpaceRegistry::instance()->rgb16();
 
149
            convertPixelsTo(src, dst, dstCs, nPixels);
 
150
        }
 
151
    }
 
152
 
 
153
    virtual void fromRgbA16(const quint8* src, quint8* dst, quint32 nPixels) const {
 
154
        if (colorDepthId() == Integer16BitsColorDepthID && colorModelId() == RGBAColorModelID) {
 
155
            memcpy(dst, src, nPixels * 2);
 
156
        } else {
 
157
            const KoColorSpace* srcCs = KoColorSpaceRegistry::instance()->rgb16();
 
158
            srcCs->convertPixelsTo(src, dst, this, nPixels);
 
159
        }
 
160
    }
 
161
 
 
162
    virtual bool convertPixelsTo(const quint8 *src,
 
163
                                 quint8 *dst, const KoColorSpace * dstColorSpace,
 
164
                                 quint32 numPixels,
 
165
                                 KoColorConversionTransformation::Intent  renderingIntent = KoColorConversionTransformation::IntentPerceptual) const {
 
166
        Q_UNUSED(renderingIntent);
 
167
 
 
168
        QColor c;
 
169
        quint32 srcPixelsize = this->pixelSize();
 
170
        quint32 dstPixelsize = dstColorSpace->pixelSize();
 
171
 
 
172
        while (numPixels > 0) {
 
173
 
 
174
            this->toQColor(src, &c);
 
175
            dstColorSpace->fromQColor(c, dst);
 
176
 
 
177
            src += srcPixelsize;
 
178
            dst += dstPixelsize;
 
179
 
 
180
            --numPixels;
 
181
        }
 
182
        return true;
 
183
    }
 
184
 
 
185
 
 
186
    virtual QString colorSpaceEngine() const {
 
187
        return "simple";
 
188
    }
 
189
 
 
190
private:
 
191
    QString m_name;
 
192
    KoID m_colorModelId;
 
193
    KoID m_colorDepthId;
 
194
    KoColorProfile* m_profile;
 
195
 
 
196
};
 
197
 
 
198
 
 
199
#endif // KOSIMPLECOLORSPACE_H