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

« back to all changes in this revision

Viewing changes to libs/pigment/KoColorConversionCache.cpp

  • 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:
26
26
#include <KoColorSpace.h>
27
27
 
28
28
struct KoColorConversionCacheKey {
29
 
    KoColorConversionCacheKey(const KoColorSpace* _src, const KoColorSpace* _dst, KoColorConversionTransformation::Intent _renderingIntent) : src(_src), dst(_dst), renderingIntent(_renderingIntent)
30
 
    {
 
29
    KoColorConversionCacheKey(const KoColorSpace* _src, const KoColorSpace* _dst, KoColorConversionTransformation::Intent _renderingIntent) : src(_src), dst(_dst), renderingIntent(_renderingIntent) {
31
30
    }
32
31
    const KoColorSpace* src;
33
32
    const KoColorSpace* dst;
34
33
    KoColorConversionTransformation::Intent renderingIntent;
35
 
    bool operator==(const KoColorConversionCacheKey& rhs) const
36
 
    {
 
34
    bool operator==(const KoColorConversionCacheKey& rhs) const {
37
35
        return (*src == *(rhs.src)) && (*dst == *(rhs.dst)) && (renderingIntent == rhs.renderingIntent);
38
36
    }
39
37
};
44
42
}
45
43
 
46
44
struct KoColorConversionCache::CachedTransformation {
47
 
    CachedTransformation(KoColorConversionTransformation* _transfo) : transfo(_transfo), use(0)
48
 
    {}
49
 
    ~CachedTransformation()
50
 
    {
 
45
    CachedTransformation(KoColorConversionTransformation* _transfo) : transfo(_transfo), use(0) {}
 
46
    ~CachedTransformation() {
51
47
        delete transfo;
52
48
    }
53
49
    bool available() {
69
65
 
70
66
KoColorConversionCache::~KoColorConversionCache()
71
67
{
72
 
    foreach(CachedTransformation* transfo, d->cache)
73
 
    {
 
68
    foreach(CachedTransformation* transfo, d->cache) {
74
69
        delete transfo;
75
70
    }
76
71
    delete d;
80
75
{
81
76
    QMutexLocker lock(&d->cacheMutex);
82
77
    KoColorConversionCacheKey key(src, dst, _renderingIntent);
83
 
    QList< CachedTransformation* > cachedTransfos = d->cache.values( key );
84
 
    if(cachedTransfos.size() != 0)
85
 
    {
86
 
        foreach( CachedTransformation* ct, cachedTransfos)
87
 
        {
88
 
            if(ct->available())
89
 
            {
 
78
    QList< CachedTransformation* > cachedTransfos = d->cache.values(key);
 
79
    if (cachedTransfos.size() != 0) {
 
80
        foreach(CachedTransformation* ct, cachedTransfos) {
 
81
            if (ct->available()) {
90
82
                ct->transfo->setSrcColorSpace(src);
91
83
                ct->transfo->setDstColorSpace(dst);
92
84
                return KoCachedColorConversionTransformation(this, ct);
93
85
            }
94
86
        }
95
87
    }
96
 
    KoColorConversionTransformation* transfo = src->createColorConverter( dst, _renderingIntent);
 
88
    KoColorConversionTransformation* transfo = src->createColorConverter(dst, _renderingIntent);
97
89
    CachedTransformation* ct = new CachedTransformation(transfo);
98
90
    d->cache.insert(key, ct);
99
91
    return KoCachedColorConversionTransformation(this, ct);
103
95
{
104
96
    QMutexLocker lock(&d->cacheMutex);
105
97
    QMultiHash< KoColorConversionCacheKey, CachedTransformation*>::iterator endIt = d->cache.end();
106
 
    for( QMultiHash< KoColorConversionCacheKey, CachedTransformation*>::iterator it = d->cache.begin(); it != endIt; )
107
 
    {
108
 
        if(it.key().src == cs || it.key().dst == cs)
109
 
        {
 
98
    for (QMultiHash< KoColorConversionCacheKey, CachedTransformation*>::iterator it = d->cache.begin(); it != endIt;) {
 
99
        if (it.key().src == cs || it.key().dst == cs) {
110
100
            Q_ASSERT(it.value()->available()); // That's terribely evil, if that assert fails, that means that someone is using a color transformation with a color space which is currently being deleted
111
101
            delete it.value();
112
 
            it = d->cache.erase( it);
 
102
            it = d->cache.erase(it);
113
103
        } else {
114
104
            ++it;
115
105
        }
118
108
 
119
109
//--------- KoCachedColorConversionTransformation ----------//
120
110
 
121
 
struct KoCachedColorConversionTransformation::Private
122
 
{
 
111
struct KoCachedColorConversionTransformation::Private {
123
112
    KoColorConversionCache* cache;
124
113
    KoColorConversionCache::CachedTransformation* transfo;
125
114
};