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

« back to all changes in this revision

Viewing changes to libs/pigment/KoColorConversionSystem_p.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:
20
20
#include <QList>
21
21
 
22
22
struct KoColorConversionSystem::Node {
23
 
    
24
 
    Node() 
25
 
        : isIcc(false)
26
 
        , isHdr(false)
27
 
        , isInitialized(false)
28
 
        , referenceDepth(0)
29
 
        , isGray(false)
30
 
        , crossingCost(1)
31
 
        , colorSpaceFactory(0)
32
 
        , isEngine(false)
33
 
        , engine(0) {}
34
 
    
35
 
    void init( const KoColorSpaceFactory* _colorSpaceFactory)
36
 
    {
 
23
 
 
24
    Node()
 
25
            : isIcc(false)
 
26
            , isHdr(false)
 
27
            , isInitialized(false)
 
28
            , referenceDepth(0)
 
29
            , isGray(false)
 
30
            , crossingCost(1)
 
31
            , colorSpaceFactory(0)
 
32
            , isEngine(false)
 
33
            , engine(0) {}
 
34
 
 
35
    void init(const KoColorSpaceFactory* _colorSpaceFactory) {
37
36
        dbgPigment << "Initialise " << modelId << " " << depthId << " " << profileName;
38
 
        Q_ASSERT(not isInitialized);
 
37
 
 
38
        if (isInitialized) {
 
39
            dbgPigment << "Re-initializing node. Old factory" << colorSpaceFactory << "new factory" << _colorSpaceFactory;
 
40
        }
39
41
        isInitialized = true;
40
 
        
41
 
        if(_colorSpaceFactory)
42
 
        {
 
42
 
 
43
        if (_colorSpaceFactory) {
43
44
            isIcc = _colorSpaceFactory->colorSpaceEngine() == "icc";
44
45
            isHdr = _colorSpaceFactory->isHdr();
45
46
            colorSpaceFactory = _colorSpaceFactory;
46
47
            referenceDepth = _colorSpaceFactory->referenceDepth();
47
 
            isGray = ( _colorSpaceFactory->colorModelId() == GrayAColorModelID
48
 
                       or _colorSpaceFactory->colorModelId() == GrayColorModelID );
 
48
            isGray = (_colorSpaceFactory->colorModelId() == GrayAColorModelID
 
49
                      || _colorSpaceFactory->colorModelId() == GrayColorModelID);
49
50
        }
50
51
    }
51
 
    
52
 
    void init( const KoColorSpaceEngine* _engine)
53
 
    {
54
 
        Q_ASSERT(not isInitialized);
 
52
 
 
53
    void init(const KoColorSpaceEngine* _engine) {
 
54
        Q_ASSERT(!isInitialized);
55
55
        isEngine = true;
56
56
        isInitialized = true;
57
57
        engine = _engine;
58
58
    }
59
 
    
 
59
 
60
60
    QString id() const {
61
61
        return modelId + " " + depthId + " " + profileName;
62
62
    }
63
 
    
 
63
 
64
64
    QString modelId;
65
65
    QString depthId;
66
66
    QString profileName;
77
77
};
78
78
 
79
79
struct KoColorConversionSystem::Vertex {
80
 
    
81
 
    Vertex(Node* _srcNode, Node* _dstNode) 
82
 
        : srcNode(_srcNode)
83
 
        , dstNode(_dstNode)
84
 
        , factoryFromSrc(0)
85
 
        , factoryFromDst(0)
86
 
    {
 
80
 
 
81
    Vertex(Node* _srcNode, Node* _dstNode)
 
82
            : srcNode(_srcNode)
 
83
            , dstNode(_dstNode)
 
84
            , factoryFromSrc(0)
 
85
            , factoryFromDst(0) {
87
86
    }
88
 
    
89
 
    ~Vertex()
90
 
    {
 
87
 
 
88
    ~Vertex() {
91
89
        if (factoryFromSrc == factoryFromDst) {
92
90
            delete factoryFromSrc;
93
 
        }
94
 
        else {
 
91
        } else {
95
92
            delete factoryFromSrc;
96
93
            delete factoryFromDst;
97
94
        }
98
95
    }
99
 
    
100
 
    void setFactoryFromSrc(KoColorConversionTransformationFactory* factory)
101
 
    {
 
96
 
 
97
    void setFactoryFromSrc(KoColorConversionTransformationFactory* factory) {
102
98
        factoryFromSrc = factory;
103
99
        initParameter(factoryFromSrc);
104
100
    }
105
 
    
106
 
    void setFactoryFromDst(KoColorConversionTransformationFactory* factory)
107
 
    {
 
101
 
 
102
    void setFactoryFromDst(KoColorConversionTransformationFactory* factory) {
108
103
        factoryFromDst = factory;
109
104
        if (!factoryFromSrc) initParameter(factoryFromDst);
110
105
    }
111
 
    
112
 
    void initParameter(KoColorConversionTransformationFactory* transfo)
113
 
    {
 
106
 
 
107
    void initParameter(KoColorConversionTransformationFactory* transfo) {
114
108
        conserveColorInformation = transfo->conserveColorInformation();
115
109
        conserveDynamicRange = transfo->conserveDynamicRange();
116
110
    }
117
 
    
118
 
    KoColorConversionTransformationFactory* factory()
119
 
    {
 
111
 
 
112
    KoColorConversionTransformationFactory* factory() {
120
113
        if (factoryFromSrc) return factoryFromSrc;
121
114
        return factoryFromDst;
122
115
    }
126
119
 
127
120
    bool conserveColorInformation;
128
121
    bool conserveDynamicRange;
129
 
    
 
122
 
130
123
private:
131
124
 
132
125
    KoColorConversionTransformationFactory* factoryFromSrc; // Factory provided by the destination node
137
130
struct KoColorConversionSystem::NodeKey {
138
131
 
139
132
    NodeKey(QString _modelId, QString _depthId, QString _profileName)
140
 
        : modelId(_modelId)
141
 
        , depthId(_depthId)
142
 
        , profileName(_profileName)
143
 
    {}
 
133
            : modelId(_modelId)
 
134
            , depthId(_depthId)
 
135
            , profileName(_profileName) {}
144
136
 
145
 
    bool operator==(const KoColorConversionSystem::NodeKey& rhs) const
146
 
    {
147
 
        return modelId == rhs.modelId and depthId == rhs.depthId and profileName == rhs.profileName;
 
137
    bool operator==(const KoColorConversionSystem::NodeKey& rhs) const {
 
138
        return modelId == rhs.modelId && depthId == rhs.depthId && profileName == rhs.profileName;
148
139
    }
149
140
 
150
141
    QString modelId;
155
146
struct KoColorConversionSystem::Path {
156
147
 
157
148
    Path()
158
 
        : respectColorCorrectness(true)
159
 
        , referenceDepth(0)
160
 
        , keepDynamicRange(true)
161
 
        , isGood(false)
162
 
        , cost(0)
163
 
    {}
 
149
            : respectColorCorrectness(true)
 
150
            , referenceDepth(0)
 
151
            , keepDynamicRange(true)
 
152
            , isGood(false)
 
153
            , cost(0) {}
164
154
 
165
155
    Node* startNode() {
166
156
        return (vertexes.first())->srcNode;
179
169
    }
180
170
 
181
171
    void appendVertex(Vertex* v) {
182
 
        if(vertexes.empty())
183
 
        {
 
172
        if (vertexes.empty()) {
184
173
            referenceDepth = v->srcNode->referenceDepth;
185
174
        }
186
175
        vertexes.append(v);
187
 
        if(not v->conserveColorInformation) respectColorCorrectness = false;
188
 
        if(not v->conserveDynamicRange) keepDynamicRange = false;
189
 
        referenceDepth = qMin( referenceDepth, v->dstNode->referenceDepth);
 
176
        if (!v->conserveColorInformation) respectColorCorrectness = false;
 
177
        if (!v->conserveDynamicRange) keepDynamicRange = false;
 
178
        referenceDepth = qMin(referenceDepth, v->dstNode->referenceDepth);
190
179
        cost += v->dstNode->crossingCost;
191
180
    }
192
181
 
193
182
    // Compress path to hide the Engine node and correctly select the factory
194
183
    typedef QPair<Node*, const KoColorConversionTransformationAbstractFactory* > node2factory;
195
 
    QList< node2factory > compressedPath() const
196
 
    {
 
184
    QList< node2factory > compressedPath() const {
197
185
        QList< node2factory > nodes;
198
 
        nodes.push_back( node2factory( vertexes.first()->srcNode , vertexes.first()->factory() ) );
 
186
        nodes.push_back(node2factory(vertexes.first()->srcNode , vertexes.first()->factory()));
199
187
        const KoColorConversionTransformationAbstractFactory* previousFactory = 0;
200
 
        foreach( Vertex* vertex, vertexes)
201
 
        { // Unless the node is the icc node, add it to the path
 
188
        foreach(Vertex* vertex, vertexes) { // Unless the node is the icc node, add it to the path
202
189
            Node* n = vertex->dstNode;
203
 
            if( n->isEngine  )
204
 
            {
 
190
            if (n->isEngine) {
205
191
                previousFactory = n->engine;
206
192
            } else {
207
193
                nodes.push_back(
208
 
                        node2factory( n,
209
 
                                      previousFactory ? previousFactory : vertex->factory() ) );
 
194
                    node2factory(n,
 
195
                                 previousFactory ? previousFactory : vertex->factory()));
210
196
                previousFactory = 0;
211
197
            }
212
198
        }
213
199
        return nodes;
214
200
    }
215
201
 
216
 
    int length() const
217
 
    {
 
202
    int length() const {
218
203
        return vertexes.size();
219
204
    }
220
205
 
221
 
    bool contains(Node* n) const
222
 
    {
223
 
        foreach(Vertex* v, vertexes)
224
 
        {
225
 
            if(v->srcNode == n or v->dstNode == n)
226
 
            {
 
206
    bool contains(Node* n) const {
 
207
        foreach(Vertex* v, vertexes) {
 
208
            if (v->srcNode == n || v->dstNode == n) {
227
209
                return true;
228
210
            }
229
211
        }
241
223
class Node2PathHash : public QHash<KoColorConversionSystem::Node*, KoColorConversionSystem::Path*>
242
224
{
243
225
public:
244
 
    ~Node2PathHash() { qDeleteAll(*this); }
 
226
    ~Node2PathHash() {
 
227
        qDeleteAll(*this);
 
228
    }
245
229
};
246
230
 
247
231
uint qHash(const KoColorConversionSystem::NodeKey &key)
257
241
};
258
242
 
259
243
#define CHECK_ONE_AND_NOT_THE_OTHER(name) \
260
 
if(path1-> name and not path2-> name) \
261
 
{ \
262
 
  return true; \
263
 
} \
264
 
if(not path1-> name and path2-> name) \
265
 
{ \
266
 
  return false; \
267
 
}
 
244
    if(path1-> name && !path2-> name) \
 
245
    { \
 
246
        return true; \
 
247
    } \
 
248
    if(!path1-> name && path2-> name) \
 
249
    { \
 
250
        return false; \
 
251
    }
268
252
 
269
253
struct PathQualityChecker {
270
254
    PathQualityChecker(int _referenceDepth, bool _ignoreHdr, bool _ignoreColorCorrectness) : referenceDepth(_referenceDepth), ignoreHdr(_ignoreHdr), ignoreColorCorrectness(_ignoreColorCorrectness) {}
271
255
    /// @return true if the path maximize all the criterions (except length)
272
 
    inline bool isGoodPath(KoColorConversionSystem::Path* path)
273
 
    {
274
 
        return ( path->respectColorCorrectness or ignoreColorCorrectness ) and
275
 
                ( path->referenceDepth >= referenceDepth) and
276
 
                ( path->keepDynamicRange or ignoreHdr );
 
256
    inline bool isGoodPath(KoColorConversionSystem::Path* path) {
 
257
        return (path->respectColorCorrectness || ignoreColorCorrectness) &&
 
258
               (path->referenceDepth >= referenceDepth) &&
 
259
               (path->keepDynamicRange || ignoreHdr);
277
260
    }
278
261
    /**
279
 
     * Compare two pathes.
 
262
     * Compare two paths.
280
263
     */
281
 
    inline bool lessWorseThan(KoColorConversionSystem::Path* path1, KoColorConversionSystem::Path* path2)
282
 
    {
283
 
        // There is no point in comparing two pathes which doesn't start from the same node or doesn't end at the same node
284
 
        if(not ignoreHdr)
285
 
        {
 
264
    inline bool lessWorseThan(KoColorConversionSystem::Path* path1, KoColorConversionSystem::Path* path2) {
 
265
        // There is no point in comparing two paths which doesn't start from the same node or doesn't end at the same node
 
266
        if (!ignoreHdr) {
286
267
            CHECK_ONE_AND_NOT_THE_OTHER(keepDynamicRange)
287
 
                }
288
 
        if(not ignoreColorCorrectness)
289
 
        {
 
268
        }
 
269
        if (!ignoreColorCorrectness) {
290
270
            CHECK_ONE_AND_NOT_THE_OTHER(respectColorCorrectness)
291
 
                }
292
 
        if( path1->referenceDepth == path2->referenceDepth)
293
 
        {
 
271
        }
 
272
        if (path1->referenceDepth == path2->referenceDepth) {
294
273
            return path1->cost < path2->cost; // if they have the same cost, well anyway you have to choose one, and there is no point in keeping one and not the other
295
274
        }
296
275
        return path1->referenceDepth > path2->referenceDepth;