Commit ee940f1a authored by Cyrille Berger's avatar Cyrille Berger

optimize color spaces comparison, compare a number instead of a string

svn path=/trunk/koffice/; revision=872805
parent bac7aa58
......@@ -56,6 +56,7 @@ set(pigmentcms_SRCS
KoIccColorSpaceEngine.cpp
KoLcmsColorSpace.cpp
KoMultipleColorConversionTransformation.cpp
KoUniqueNumberForIdServer.cpp
colorprofiles/KoIccColorProfile.cpp
colorprofiles/KoHdrColorProfile.cpp
colorprofiles/KoLcmsColorProfileContainer.cpp
......
......@@ -35,9 +35,11 @@
#include "KoColorProfile.h"
#include "KoCopyColorConversionTransformation.h"
#include "KoFallBackColorTransformation.h"
#include "KoUniqueNumberForIdServer.h"
struct KoColorSpace::Private {
QString id;
quint32 idNumber;
QString name;
QHash<QString, KoCompositeOp *> compositeOps;
QList<KoChannelInfo *> channels;
......@@ -62,6 +64,7 @@ KoColorSpace::KoColorSpace(const QString &id, const QString &name, KoMixColorsOp
: d (new Private())
{
d->id = id;
d->idNumber = KoUniqueNumberForIdServer::instance()->numberForId( d->id );
d->name = name;
d->mixColorsOp = mixColorsOp;
d->convolutionOp = convolutionOp;
......@@ -90,7 +93,7 @@ KoColorSpace::~KoColorSpace()
bool KoColorSpace::operator==(const KoColorSpace& rhs) const {
const KoColorProfile* p1 = rhs.profile();
const KoColorProfile* p2 = profile();
return id() == rhs.id() && ((p1 == p2) || (*p1 == *p2 ));
return d->idNumber == rhs.d->idNumber && ((p1 == p2) || (*p1 == *p2 ));
}
QString KoColorSpace::id() const {return d->id;}
......
......@@ -93,7 +93,7 @@ void KoCtlColorConversionTransformation::transform(const quint8 *src8, quint8 *d
dbgPigment << "Unsuitable type";
}
}
d->program->apply(src, dst);
// d->program->apply(src, dst);
}
struct KoCtlColorConversionTransformationFactory::Private {
......
/*
* Copyright (c) 2008 Cyrille Berger <cberger@cberger.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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 GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "KoUniqueNumberForIdServer.h"
#include <QHash>
struct KoUniqueNumberForIdServer::Private
{
Private() : currentNumber(0) { }
QHash<QString, quint32 > id2Number;
quint32 currentNumber;
static KoUniqueNumberForIdServer* s_instance;
};
KoUniqueNumberForIdServer* KoUniqueNumberForIdServer::Private::s_instance = 0;
KoUniqueNumberForIdServer::KoUniqueNumberForIdServer() : d(new Private)
{
}
KoUniqueNumberForIdServer::~KoUniqueNumberForIdServer()
{
delete d;
}
KoUniqueNumberForIdServer* KoUniqueNumberForIdServer::instance()
{
if( not KoUniqueNumberForIdServer::Private::s_instance )
{
KoUniqueNumberForIdServer::Private::s_instance = new KoUniqueNumberForIdServer;
}
return KoUniqueNumberForIdServer::Private::s_instance;
}
quint32 KoUniqueNumberForIdServer::numberForId( const QString& _id )
{
QHash<QString, quint32>::iterator it = d->id2Number.find( _id );
if( it != d->id2Number.end() )
{
return it.value();
}
quint32 number = ++d->currentNumber;
d->id2Number[ _id ] = number;
return number;
}
/*
* Copyright (c) 2008 Cyrille Berger <cberger@cberger.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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 GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef _KO_UNIQUE_NUMBER_FOR_ID_SERVER_H_
#define _KO_UNIQUE_NUMBER_FOR_ID_SERVER_H_
#include <QtGlobal>
class QString;
/**
* This class is used to provide an unique number for a given \ref QString .
* This is usefull for fast comparison of Ids, but the number *should* remains private
* especially considering that it changes from one running instance to an other.
*/
class KoUniqueNumberForIdServer {
private:
KoUniqueNumberForIdServer();
~KoUniqueNumberForIdServer();
public:
static KoUniqueNumberForIdServer* instance();
/**
* @return an unique number for the given \p _id , for two different call to this function
* with the same \p id the function will allways return the same value.
*
* @code
* KoUniqueNumberForIdServer::instance()->numberForId( "rgb" ) == KoUniqueNumberForIdServer::instance()->numberForId( "rgb" );
* KoUniqueNumberForIdServer::instance()->numberForId( "rgb" ) != KoUniqueNumberForIdServer::instance()->numberForId( "cmyk" );
* @endcode
*/
quint32 numberForId( const QString& );
private:
struct Private;
Private* const d;
};
#endif
......@@ -34,6 +34,7 @@
#include <KoColorModelStandardIds.h>
#include <KoColorSpaceRegistry.h>
#include <KoCtlColorConversionTransformation.h>
#include <KoUniqueNumberForIdServer.h>
#include <GTLCore/PixelDescription.h>
#include <GTLCore/String.h>
......@@ -56,7 +57,9 @@ struct KoCtlColorProfile::Private {
OpenCTL::Module* module;
QList<ConversionInfo> conversionInfos;
QString colorModelID;
quint32 colorModelIDNumber;
QString colorDepthID;
quint32 colorDepthIDNumber;
qreal exposure;
qreal middleGreyScaleFactor;
};
......@@ -183,7 +186,7 @@ bool KoCtlColorProfile::operator==(const KoColorProfile& p) const
const KoCtlColorProfile* ctlp = dynamic_cast<const KoCtlColorProfile*>(&p);
if(ctlp)
{
return ctlp->name() == name() and ctlp->colorModel() == colorModel() and ctlp->colorDepth() == colorDepth();
return ctlp->name() == name() and ctlp->d->colorModelIDNumber == d->colorModelIDNumber and ctlp->d->colorDepthIDNumber == d->colorDepthIDNumber;
} else {
return false;
}
......@@ -299,7 +302,9 @@ bool KoCtlColorProfile::load()
{
setName(e.attribute("name"));
d->colorDepthID = generateDepthID(e.attribute("depth"), e.attribute("type"));
d->colorDepthIDNumber = KoUniqueNumberForIdServer::instance()->numberForId( d->colorDepthID );
d->colorModelID = e.attribute("colorModel");
d->colorModelIDNumber = KoUniqueNumberForIdServer::instance()->numberForId( d->colorModelID );
kDebug(DBG_PIGMENT) << "colorModel = " << e.attribute("colorModel");;
} else if(e.tagName() == "program")
{
......
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