Commit 024b2a2c authored by Boudewijn Rempt's avatar Boudewijn Rempt

make it possible to delete colorspaces from the registry

Introduce three states for KoColorSpace:
 * deletable (should use the registry to get the conversion cache to remove itself)
 * owned by the registry, shouldn't be deleted (during runtime)
 * owned by the registry, can be deleted, but shouldn't try to clear the cache (when the registry is being destructed).

svn path=/trunk/koffice/; revision=1039404
parent 01e2a5b5
......@@ -56,19 +56,23 @@ KoColorSpace::KoColorSpace(const QString &id, const QString &name, KoMixColorsOp
d->transfoFromRGBA16 = 0;
d->transfoToLABA16 = 0;
d->transfoFromLABA16 = 0;
d->deletability = NotOwnedByRegistry;
}
KoColorSpace::~KoColorSpace()
{
Q_ASSERT(!d->ownedByRegistry);
Q_ASSERT(d->deletability != OwnedByRegistryDoNotDelete);
qDeleteAll(d->compositeOps);
foreach(KoChannelInfo * channel, d->channels)
{
delete channel;
}
KoColorConversionCache* cache = KoColorSpaceRegistry::instance()->colorConversionCache();
if (cache) {
cache->colorSpaceIsDestroyed(this);
if (d->deletability == NotOwnedByRegistry) {
KoColorConversionCache* cache = KoColorSpaceRegistry::instance()->colorConversionCache();
if (cache) {
cache->colorSpaceIsDestroyed(this);
}
}
delete d->mixColorsOp;
delete d->convolutionOp;
......
......@@ -42,6 +42,12 @@ class KoColorTransformation;
class KoColorConversionTransformationFactory;
class QBitArray;
enum Deletability {
OwnedByRegistryDoNotDelete,
OwnedByRegistryRegistyDeletes,
NotOwnedByRegistry
};
enum ColorSpaceIndependence {
FULLY_INDEPENDENT,
TO_LAB16,
......
......@@ -137,7 +137,7 @@ void KoColorSpaceRegistry::init()
// Create the built-in colorspaces
d->alphaCs = new KoAlphaColorSpace();
d->alphaCs->d->ownedByRegistry = true;
d->alphaCs->d->deletability = OwnedByRegistryDoNotDelete;
KoPluginLoader::PluginsConfig config;
config.whiteList = "ColorSpacePlugins";
......@@ -160,7 +160,6 @@ KoColorSpaceRegistry::KoColorSpaceRegistry() : d(new Private())
KoColorSpaceRegistry::~KoColorSpaceRegistry()
{
d->alphaCs->d->ownedByRegistry = false;
delete d->colorConversionSystem;
foreach( KoColorProfile* profile, d->profileMap) {
......@@ -168,7 +167,7 @@ KoColorSpaceRegistry::~KoColorSpaceRegistry()
}
d->profileMap.clear();
foreach( const KoColorSpace * cs, d->csMap) {
cs->d->ownedByRegistry = false;
cs->d->deletability = OwnedByRegistryRegistyDeletes;
delete cs;
}
d->csMap.clear();
......@@ -176,6 +175,7 @@ KoColorSpaceRegistry::~KoColorSpaceRegistry()
delete d->colorConversionCache;
d->colorConversionCache = 0;
d->alphaCs->d->deletability = OwnedByRegistryRegistyDeletes;
delete d->alphaCs;
// Do not explicitly delete d->rgbU8sRGB and d->lab16sLAB, since they are contained in the d->csMap
delete d;
......@@ -319,7 +319,7 @@ const KoColorSpace * KoColorSpaceRegistry::colorSpace(const QString &csID, const
}
d->csMap[name] = cs;
cs->d->ownedByRegistry = true;
cs->d->deletability = OwnedByRegistryDoNotDelete;
dbgPigmentCSRegistry << "colorspace count: " << d->csMap.count() << ", adding name: " << name;
}
......@@ -361,7 +361,7 @@ const KoColorSpace * KoColorSpaceRegistry::colorSpace(const QString &csID, const
QString name = csID + "<comb>" + profile->name();
d->csMap[name] = cs;
cs->d->ownedByRegistry = true;
cs->d->deletability = OwnedByRegistryDoNotDelete;
dbgPigmentCSRegistry << "colorspace count: " << d->csMap.count() << ", adding name: " << name;
}
......@@ -508,7 +508,7 @@ KoColorConversionCache* KoColorSpaceRegistry::colorConversionCache() const
const KoColorSpace* KoColorSpaceRegistry::permanentColorspace( const KoColorSpace* _colorSpace )
{
if(_colorSpace->d->ownedByRegistry) return _colorSpace;
if(_colorSpace->d->deletability != NotOwnedByRegistry) return _colorSpace;
else if(*_colorSpace == *d->alphaCs) return d->alphaCs;
else {
const KoColorSpace* cs = colorSpace(_colorSpace->id(), _colorSpace->profile());
......
......@@ -23,8 +23,6 @@
#include "KoColorSpace.h"
struct KoColorSpace::Private {
Private() : ownedByRegistry(false)
{}
QString id;
quint32 idNumber;
......@@ -35,13 +33,12 @@ struct KoColorSpace::Private {
KoConvolutionOp* convolutionOp;
QThreadStorage< QVector<quint8>* > conversionCache;
mutable KoColorConversionTransformation* transfoToRGBA16;
mutable KoColorConversionTransformation* transfoFromRGBA16;
mutable KoColorConversionTransformation* transfoToLABA16;
mutable KoColorConversionTransformation* transfoFromLABA16;
bool ownedByRegistry;
Deletability deletability;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment