r14217 by jghali - enable color profiles and transforms caching and sharing across documents

scribus-commit scribus-commit at lists.scribus.net
Fri Oct 23 00:35:37 CEST 2009


Revision: 14217
Author: jghali
Date: 2009-10-22T19:28:16.845559Z
Commit message: enable color profiles and transforms caching and sharing across documents

Changeset: 
M  /trunk/Scribus/scribus/colormngt/sccolorprofile.cpp
M  /trunk/Scribus/scribus/colormngt/sccolortransform.h
M  /trunk/Scribus/scribus/colormngt/sclcmscolormngtengineimpl.h
M  /trunk/Scribus/scribus/colormngt/sccolorprofilecache.cpp
M  /trunk/Scribus/scribus/colormngt/sccolorprofile.h
M  /trunk/Scribus/scribus/colormngt/sccolortransformpool.cpp
M  /trunk/Scribus/scribus/colormngt/sccolorprofilecache.h
M  /trunk/Scribus/scribus/colormngt/sccolormngtenginedata.h
M  /trunk/Scribus/scribus/colormngt/sccolortransformpool.h
M  /trunk/Scribus/scribus/colormngt/sccolortransform.cpp
M  /trunk/Scribus/scribus/colormngt/sclcmscolormngtengineimpl.cpp

Diffs:
Index: scribus/colormngt/sccolortransformpool.h
===================================================================
--- scribus/colormngt/sccolortransformpool.h	(revision 14216)
+++ scribus/colormngt/sccolortransformpool.h	(revision 14217)
@@ -8,17 +8,20 @@
 #ifndef SCCOLORTRANSFORMPOOL_H
 #define SCCOLORTRANSFORMPOOL_H
 
-#include <QSet>
+#include <QList>
+#include <QWeakPointer>
 #include "sccolormngtstructs.h"
 #include "sccolortransform.h"
 
 class ScColorTransformPool
 {
+	friend class ScColorMngtEngineData;
+
 public:
 	ScColorTransformPool (int engineID);
 
 	void clear(void);
-	void addTransform(const ScColorTransform& transform);
+	void addTransform(const ScColorTransform& transform, bool force = false);
 	void removeTransform(const ScColorTransform& transform);
 	void removeTransform(const ScColorTransformInfo& info);
 
@@ -26,7 +29,7 @@
 
 protected:
 	int m_engineID;
-	QSet<ScColorTransform> m_pool;
+	QList< QWeakPointer<ScColorTransformData> > m_pool;
 };
 
 #endif
Index: scribus/colormngt/sccolortransform.cpp
===================================================================
--- scribus/colormngt/sccolortransform.cpp	(revision 14216)
+++ scribus/colormngt/sccolortransform.cpp	(revision 14217)
@@ -9,12 +9,14 @@
 
 ScColorTransform::ScColorTransform() : m_data(NULL)
 {
-
 }
 
 ScColorTransform::ScColorTransform(ScColorTransformData* data) : m_data(data)
 {
+}
 
+ScColorTransform::ScColorTransform(const QSharedPointer<ScColorTransformData>& data) : m_data(data)
+{
 }
 
 bool ScColorTransform::apply(void* input, void* output, uint numElem)
Index: scribus/colormngt/sccolortransform.h
===================================================================
--- scribus/colormngt/sccolortransform.h	(revision 14216)
+++ scribus/colormngt/sccolortransform.h	(revision 14217)
@@ -9,14 +9,17 @@
 #define SCCOLORTRANSFORM_H
 
 #include <QSharedPointer>
+#include <QWeakPointer>
 #include "scribusapi.h"
 #include "sccolortransformdata.h"
 
 class SCRIBUS_API ScColorTransform
 {
+	friend class ScColorTransformPool;
 public:
 	ScColorTransform();
 	ScColorTransform(ScColorTransformData* data);
+	ScColorTransform(const QSharedPointer<ScColorTransformData>& data);
 	
 	ScColorMngtEngine& engine() { return m_data->engine(); }
 	const ScColorMngtEngine& engine() const { return m_data->engine(); }
@@ -36,6 +39,9 @@
 
 protected:
 	QSharedPointer<ScColorTransformData> m_data;
+
+	QWeakPointer<ScColorTransformData>   weakRef()   const { return m_data.toWeakRef(); }
+	QSharedPointer<ScColorTransformData> strongRef() const { return m_data; }
 };
 
 #endif
Index: scribus/colormngt/sccolorprofilecache.cpp
===================================================================
--- scribus/colormngt/sccolorprofilecache.cpp	(revision 14216)
+++ scribus/colormngt/sccolorprofilecache.cpp	(revision 14217)
@@ -12,7 +12,7 @@
 	if (!path.isEmpty())
 	{
 		if (!m_profileMap.contains(path))
-			m_profileMap.insert(path, profile);
+			m_profileMap.insert(path, profile.weakRef());
 	}
 }
 
@@ -33,9 +33,9 @@
 
 ScColorProfile ScColorProfileCache::profile(const QString& profilePath)
 {
-	ScColorProfile profile(NULL);
-	QMap<QString, ScColorProfile>::iterator iter = m_profileMap.find(profilePath);
+	ScColorProfile profile;
+	QMap<QString, QWeakPointer<ScColorProfileData> >::iterator iter = m_profileMap.find(profilePath);
 	if (iter != m_profileMap.end())
-		profile = iter.value();
+		profile = ScColorProfile(iter.value());
 	return profile;
 }
\ No newline at end of file
Index: scribus/colormngt/sccolorprofilecache.h
===================================================================
--- scribus/colormngt/sccolorprofilecache.h	(revision 14216)
+++ scribus/colormngt/sccolorprofilecache.h	(revision 14217)
@@ -10,13 +10,12 @@
 
 #include <QMap>
 #include <QString>
-
+#include <QWeakPointer>
 #include "sccolorprofile.h"
 
 class ScColorProfileCache 
 {
 public:
-
 	void addProfile(const ScColorProfile& profile);
 	void removeProfile(const QString& profilePath);
 	void removeProfile(const ScColorProfile& profile);
@@ -25,7 +24,7 @@
 	ScColorProfile profile(const QString& profilePath);
 
 protected:
-	QMap<QString, ScColorProfile> m_profileMap;
+	QMap<QString, QWeakPointer<ScColorProfileData> > m_profileMap;
 };
 
 #endif
Index: scribus/colormngt/sccolormngtenginedata.h
===================================================================
--- scribus/colormngt/sccolormngtenginedata.h	(revision 14216)
+++ scribus/colormngt/sccolormngtenginedata.h	(revision 14217)
@@ -24,13 +24,11 @@
 	int     m_engineID;
 	QString m_description;
 	ScColorMngtStrategy  m_strategy;
-	ScColorTransformPool m_transformPool;
 	
 public:
 
 	ScColorMngtEngineData(const QString& desc, int uniqueID) : m_engineID(uniqueID), 
-	                                                           m_description(desc),
-	                                                           m_transformPool(uniqueID)
+	                                                           m_description(desc)
 	{}
 	
 	// Getters
Index: scribus/colormngt/sclcmscolormngtengineimpl.cpp
===================================================================
--- scribus/colormngt/sclcmscolormngtengineimpl.cpp	(revision 14216)
+++ scribus/colormngt/sclcmscolormngtengineimpl.cpp	(revision 14217)
@@ -18,20 +18,22 @@
 #define cmsFLAGS_PRESERVEBLACK 0x8000
 #endif
 
-QSharedPointer<ScColorProfileCache> ScLcmsColorMngtEngineImpl::m_profileCache;
+QSharedPointer<ScColorProfileCache>  ScLcmsColorMngtEngineImpl::m_profileCache;
+QSharedPointer<ScColorTransformPool> ScLcmsColorMngtEngineImpl::m_transformPool;
 
 ScLcmsColorMngtEngineImpl::ScLcmsColorMngtEngineImpl()
                          : ScColorMngtEngineData("Littlecms v1", 0)
 {
 	if (!m_profileCache)
 		m_profileCache = QSharedPointer<ScColorProfileCache>(new ScColorProfileCache());
+	if (!m_transformPool)
+		m_transformPool = QSharedPointer<ScColorTransformPool>(new ScColorTransformPool(0));
 	cmsSetAlarmCodes(0, 255, 0);
 }
 
 void ScLcmsColorMngtEngineImpl::setStrategy(const ScColorMngtStrategy& strategy)
 {
 	m_strategy = strategy;
-	m_transformPool.clear();
 }
 
 QList<ScColorProfileInfo> ScLcmsColorMngtEngineImpl::getAvailableProfileInfo(const QString& directory, bool recursive)
@@ -118,7 +120,9 @@
 ScColorProfile ScLcmsColorMngtEngineImpl::openProfileFromFile(ScColorMngtEngine& engine, const QString& filePath)
 {
 	// Search profile in profile cache first
-	ScColorProfile profile;
+	ScColorProfile profile = m_profileCache->profile(filePath);
+	if (!profile.isNull())
+		return profile;
 	cmsHPROFILE lcmsProf = NULL;
 	cmsSetErrorHandler(&cmsErrorHandler);
 	try
@@ -138,6 +142,7 @@
 					profData->m_profileData = data;
 					profData->m_profilePath = filePath;
 					profile = ScColorProfile(dynamic_cast<ScColorProfileData*>(profData));
+					m_profileCache->addProfile(profile);
 				}
 				if (profile.isNull() && lcmsProf)
 				{
@@ -263,7 +268,9 @@
 	ScColorTransform transform(NULL);
 	if (inputProfile.isNull() || outputProfile.isNull())
 		return transform;
-	if ((engine.engineID() != m_engineID) || (inputProfile.engine() != engine) || (outputProfile.engine() != engine))
+	int inputProfEngineID  = inputProfile.engine().engineID();
+	int outputProfEngineID = outputProfile.engine().engineID();
+	if ((engine.engineID() != m_engineID) || (inputProfEngineID != m_engineID) || (outputProfEngineID != m_engineID))
 		return transform;
 	const ScLcmsColorProfileImpl* lcmsInputProf  = dynamic_cast<const ScLcmsColorProfileImpl*>(inputProfile.data());
 	const ScLcmsColorProfileImpl* lcmsOutputProf = dynamic_cast<const ScLcmsColorProfileImpl*>(outputProfile.data());
@@ -301,7 +308,7 @@
 		nullTransform = true;
 	}
 
-	transform = m_transformPool.findTransform(transInfo);
+	transform = m_transformPool->findTransform(transInfo);
 	if (transform.isNull())
 	{
 		DWORD lcmsFlags     = translateFlagsToLcmsFlags(transformFlags | strategyFlags);
@@ -322,6 +329,7 @@
 				ScLcmsColorTransformImpl* newTrans = new ScLcmsColorTransformImpl(engine, hTransform);
 				newTrans->setTransformInfo(transInfo);
 				transform = ScColorTransform(dynamic_cast<ScColorTransformData*>(newTrans));
+				m_transformPool->addTransform(transform, true);
 			}
 		}
 		catch (lcmsException& e)
@@ -345,12 +353,15 @@
 	ScColorTransform transform(NULL);
 	if (inputProfile.isNull() || outputProfile.isNull())
 		return transform;
-	if ((engine.engineID() != m_engineID) || (inputProfile.engine() != engine) || 
-		(outputProfile.engine() != engine)|| (proofProfile.engine() != engine) )
+	int inputProfEngineID  = inputProfile.engine().engineID();
+	int outputProfEngineID = outputProfile.engine().engineID();
+	int proofProfEngineID  = proofProfile.engine().engineID();
+	if ((engine.engineID()  != m_engineID) || (inputProfEngineID != m_engineID) || 
+		(outputProfEngineID != m_engineID) || (proofProfEngineID != m_engineID))
 		return transform;
 	const ScLcmsColorProfileImpl* lcmsInputProf    = dynamic_cast<const ScLcmsColorProfileImpl*>(inputProfile.data());
 	const ScLcmsColorProfileImpl* lcmsOutputProf   = dynamic_cast<const ScLcmsColorProfileImpl*>(outputProfile.data());
-	const ScLcmsColorProfileImpl* lcmsProofingProf = dynamic_cast<const ScLcmsColorProfileImpl*>(outputProfile.data());
+	const ScLcmsColorProfileImpl* lcmsProofingProf = dynamic_cast<const ScLcmsColorProfileImpl*>(proofProfile.data());
 	if (!lcmsInputProf || !lcmsOutputProf || !lcmsProofingProf)
 		return transform;
 
@@ -383,7 +394,7 @@
 			transInfo.proofingIntent = Intent_Relative_Colorimetric;
 			lcmsPrfIntent = translateIntentToLcmsIntent(Intent_Relative_Colorimetric);
 		}
-		transform = m_transformPool.findTransform(transInfo);
+		transform = m_transformPool->findTransform(transInfo);
 		if (transform.isNull())
 		{
 			cmsSetErrorHandler(&cmsErrorHandler);
@@ -399,6 +410,7 @@
 					ScLcmsColorTransformImpl* newTrans = new ScLcmsColorTransformImpl(engine, hTransform);
 					newTrans->setTransformInfo(transInfo);
 					transform = ScColorTransform(dynamic_cast<ScColorTransformData*>(newTrans));
+					m_transformPool->addTransform(transform, true);
 				}
 			}
 			catch (lcmsException& e)
@@ -429,7 +441,7 @@
 			transInfo.proofingIntent  = (eRenderIntent) 0;
 			transInfo.flags = 0;
 		}
-		transform = m_transformPool.findTransform(transInfo);
+		transform = m_transformPool->findTransform(transInfo);
 		if (transform.isNull())
 		{
 			cmsSetErrorHandler(&cmsErrorHandler);
@@ -444,6 +456,7 @@
 					ScLcmsColorTransformImpl* newTrans = new ScLcmsColorTransformImpl(engine, hTransform);
 					newTrans->setTransformInfo(transInfo);
 					transform = ScColorTransform(dynamic_cast<ScColorTransformData*>(newTrans));
+					m_transformPool->addTransform(transform, true);
 				}
 			}
 			catch (lcmsException& e)
Index: scribus/colormngt/sccolorprofile.cpp
===================================================================
--- scribus/colormngt/sccolorprofile.cpp	(revision 14216)
+++ scribus/colormngt/sccolorprofile.cpp	(revision 14217)
@@ -15,6 +15,10 @@
 {
 }
 
+ScColorProfile::ScColorProfile(const QSharedPointer<ScColorProfileData>& data) : m_data(data)
+{
+}
+
 icColorSpaceSignature ScColorProfile::colorSpace() const
 {
 	if (m_data)
Index: scribus/colormngt/sclcmscolormngtengineimpl.h
===================================================================
--- scribus/colormngt/sclcmscolormngtengineimpl.h	(revision 14216)
+++ scribus/colormngt/sclcmscolormngtengineimpl.h	(revision 14217)
@@ -48,8 +48,12 @@
 
 protected:
 
+	// Color profile cache
 	static QSharedPointer<ScColorProfileCache> m_profileCache;
 
+	// Color transform cache
+	static QSharedPointer<ScColorTransformPool> m_transformPool;
+
 	static DWORD translateFlagsToLcmsFlags(long flags);
 	static DWORD translateFormatToLcmsFormat(eColorFormat format);
 	static int translateIntentToLcmsIntent(eRenderIntent intent, eRenderIntent defaut = Intent_Relative_Colorimetric);
Index: scribus/colormngt/sccolorprofile.h
===================================================================
--- scribus/colormngt/sccolorprofile.h	(revision 14216)
+++ scribus/colormngt/sccolorprofile.h	(revision 14217)
@@ -9,14 +9,18 @@
 #define SCCOLORPROFILE_H
 
 #include <QSharedPointer>
+#include <QWeakPointer>
 #include "scribusapi.h"
 #include "sccolorprofiledata.h"
 
 class SCRIBUS_API ScColorProfile
 {
+	friend class ScColorProfileCache;
+
 public:
 	ScColorProfile();
 	ScColorProfile(ScColorProfileData*);
+	ScColorProfile(const QSharedPointer<ScColorProfileData>&);
 	
 	ScColorMngtEngine& engine() { return m_data->engine(); }
 	const ScColorMngtEngine& engine() const { return m_data->engine(); }
@@ -36,6 +40,9 @@
 	
 protected:
 	QSharedPointer<ScColorProfileData> m_data;
+
+	QWeakPointer<ScColorProfileData>   weakRef()   const { return m_data.toWeakRef(); }
+	QSharedPointer<ScColorProfileData> strongRef() const { return m_data; }
 };
 
 #endif
Index: scribus/colormngt/sccolortransformpool.cpp
===================================================================
--- scribus/colormngt/sccolortransformpool.cpp	(revision 14216)
+++ scribus/colormngt/sccolortransformpool.cpp	(revision 14217)
@@ -5,6 +5,7 @@
 for which a new license (GPL+exception) is in place.
 */
 
+#include <QSharedPointer>
 #include "sccolormngtengine.h"
 #include "sccolormngtstructs.h"
 #include "sccolortransformpool.h"
@@ -19,32 +20,33 @@
 	m_pool.clear();
 }
 
-void ScColorTransformPool::addTransform(const ScColorTransform& transform)
+void ScColorTransformPool::addTransform(const ScColorTransform& transform, bool force)
 {
 	// Check engine ID. If different, transform was created by another engine
 	//  and we MUST NOT add it to the transform pool
 	if (m_engineID != transform.engine().engineID())
 		return;
-	ScColorTransform trans = findTransform(transform.transformInfo());
+	ScColorTransform trans;
+	if (!force)
+		trans = findTransform(transform.transformInfo());
 	if (trans.isNull())
-	{
-		m_pool.insert(transform);
-	}
+		m_pool.append(transform.weakRef());
 }
 
 void ScColorTransformPool::removeTransform(const ScColorTransform& transform)
 {
 	if (m_engineID != transform.engine().engineID())
 		return;
-	m_pool.remove(transform);
+	m_pool.removeOne(transform.strongRef());
 }
 
 void ScColorTransformPool::removeTransform(const ScColorTransformInfo& info)
 {
-	QSet<ScColorTransform>::Iterator it = m_pool.begin();
+	QList< QWeakPointer<ScColorTransformData> >::Iterator it = m_pool.begin();
 	while (it != m_pool.end())
 	{
-		if (info == it->transformInfo())
+		QSharedPointer<ScColorTransformData> ref = it->toStrongRef();
+		if ((info == ref->transformInfo()) || ref.isNull())
 		{
 			it = m_pool.erase(it);
 			continue;
@@ -56,13 +58,17 @@
 ScColorTransform ScColorTransformPool::findTransform(const ScColorTransformInfo& info) const
 {
 	ScColorTransform transform(NULL);
-	QSet<ScColorTransform>::ConstIterator it = m_pool.begin();
+	QList< QWeakPointer<ScColorTransformData> >::ConstIterator it = m_pool.begin();
 	for ( ; it != m_pool.end(); ++it)
 	{
-		if (info == it->transformInfo())
+		QSharedPointer<ScColorTransformData> ref = it->toStrongRef();
+		if (!ref.isNull())
 		{
-			transform = *it;
-			break;
+			if (info == ref->transformInfo())
+			{
+				transform = ScColorTransform(ref);
+				break;
+			}
 		}
 	}
 	return transform;




More information about the scribus-commit mailing list