Commit ad030d5f authored by Cyrille Berger's avatar Cyrille Berger

first step of use of the ColorConversionSystem, when there is a direct color...

first step of use of the ColorConversionSystem, when there is a direct color transformation between two color spaces

svn path=/trunk/koffice/; revision=722010
parent 3a27ed0c
......@@ -32,14 +32,14 @@ struct KoColorConversionSystem::Node {
Node() : isInitialized(false), colorSpaceFactory(0) {}
void init( const KoColorSpaceFactory* _colorSpaceFactory)
{
Q_ASSERT(!isInitialized);
Q_ASSERT(not isInitialized);
isInitialized = true;
isIcc = _colorSpaceFactory->isIcc();
isHdr = _colorSpaceFactory->isHdr();
colorSpaceFactory = _colorSpaceFactory;
referenceDepth = _colorSpaceFactory->referenceDepth();
isGray = ( _colorSpaceFactory->colorModelId() == GrayAColorModelID
|| _colorSpaceFactory->colorModelId() == GrayColorModelID );
or _colorSpaceFactory->colorModelId() == GrayColorModelID );
}
QString id() const {
return colorSpaceFactory->id();
......@@ -72,7 +72,7 @@ struct KoColorConversionSystem::Vertex {
void setFactoryFromDst(KoColorConversionTransformationFactory* factory)
{
factoryFromDst = factory;
if(!factoryFromSrc) initParameter(factoryFromDst);
if( not factoryFromSrc) initParameter(factoryFromDst);
}
void initParameter(KoColorConversionTransformationFactory* transfo)
{
......@@ -120,8 +120,8 @@ struct KoColorConversionSystem::Path {
}
void appendVertex(Vertex* v) {
vertexes.append(v);
if(!v->conserveColorInformation) respectColorCorrectness = false;
if(!v->conserveDynamicRange) keepDynamicRange = false;
if(not v->conserveColorInformation) respectColorCorrectness = false;
if(not v->conserveDynamicRange) keepDynamicRange = false;
bitDepthDecrease += v->depthDecrease;
}
int length() {
......@@ -131,7 +131,7 @@ struct KoColorConversionSystem::Path {
{
foreach(Vertex* v, vertexes)
{
if(v->srcNode == n || v->dstNode == n)
if(v->srcNode == n or v->dstNode == n)
{
return true;
}
......@@ -188,7 +188,7 @@ void KoColorConversionSystem::insertColorSpace(const KoColorSpaceFactory* csf)
QList<Node*> nodes = d->graph.values();
foreach(Node* node, nodes)
{
if(node->isIcc && node->isInitialized && node != csNode)
if(node->isIcc and node->isInitialized and node != csNode)
{
// Create the vertex from 1 to 2
Q_ASSERT(vertexBetween(node, csNode) == 0); // The two color spaces should not be connected yet
......@@ -214,11 +214,11 @@ void KoColorConversionSystem::insertColorSpace(const KoColorSpaceFactory* csf)
Q_ASSERT(srcNode);
Node* dstNode = nodeFor(cctf->dstColorModelId(), cctf->dstColorDepthId());
Q_ASSERT(dstNode);
Q_ASSERT(srcNode == csNode || dstNode == csNode);
Q_ASSERT(srcNode == csNode or dstNode == csNode);
// Check if the two nodes are allready connected
Vertex* v = vertexBetween(srcNode, dstNode);
// If the vertex doesn't allready exist, then create it
if(!v)
if(not v)
{
v = createVertex(srcNode, dstNode);
}
......@@ -251,7 +251,7 @@ KoColorConversionSystem::Node* KoColorConversionSystem::nodeFor(QString _colorMo
KoColorConversionSystem::Node* KoColorConversionSystem::nodeFor(const KoColorConversionSystem::NodeKey& key)
{
if(!d->graph.contains(key))
if(not d->graph.contains(key))
{
Node* n = new Node;
n->modelId = key.modelId;
......@@ -265,6 +265,14 @@ KoColorConversionSystem::Node* KoColorConversionSystem::nodeFor(const KoColorCon
KoColorConversionTransformation* KoColorConversionSystem::createColorConverter(const KoColorSpace * srcColorSpace, const KoColorSpace * dstColorSpace, KoColorConversionTransformation::Intent renderingIntent ) const
{
Path* path = findBestPath( nodeFor( srcColorSpace->colorModelId().id(), srcColorSpace->colorDepthId().id() ), nodeFor( dstColorSpace->colorModelId().id(), dstColorSpace->colorDepthId().id() ) );
Q_ASSERT(path);
if(path->length() == 1)
{ // Direct connection
return path->vertexes.first()->factory()->createColorTransformation( srcColorSpace, dstColorSpace, renderingIntent );
} else {
Q_ASSERT(false);
}
return 0;
}
......@@ -329,11 +337,11 @@ QString KoColorConversionSystem::bestPathToDot(QString srcModelId, QString srcDe
}
#define CHECK_ONE_AND_NOT_THE_OTHER(name) \
if(path1-> name && !path2-> name) \
if(path1-> name and not path2-> name) \
{ \
return true; \
} \
if(!path1-> name && path2-> name) \
if(not path1-> name and path2-> name) \
{ \
return false; \
}
......@@ -344,9 +352,9 @@ struct PathQualityChecker {
/// @return true if the path maximize all the criterions (except lenght)
inline bool isGoodPath(KoColorConversionSystem::Path* path)
{
return ( path->respectColorCorrectness || ignoreColorCorrectness ) &&
( path->bitDepthDecrease <= maxBitDecrease) &&
( path->keepDynamicRange || ignoreHdr );
return ( path->respectColorCorrectness or ignoreColorCorrectness ) and
( path->bitDepthDecrease <= maxBitDecrease) and
( path->keepDynamicRange or ignoreHdr );
}
/**
* Compare two pathes.
......@@ -356,11 +364,11 @@ struct PathQualityChecker {
// There is no point in comparing two pathes which doesn't start from the same node or doesn't end at the same node
Q_ASSERT(path1->startNode() == path2->startNode());
Q_ASSERT(path1->endNode() == path2->endNode());
if(!ignoreHdr)
if(not ignoreHdr)
{
CHECK_ONE_AND_NOT_THE_OTHER(keepDynamicRange)
}
if(!ignoreColorCorrectness)
if(not ignoreColorCorrectness)
{
CHECK_ONE_AND_NOT_THE_OTHER(respectColorCorrectness)
}
......@@ -384,7 +392,7 @@ void KoColorConversionSystem::deletePathes( QList<KoColorConversionSystem::Path*
template<bool ignoreHdr, bool ignoreColorCorrectness>
inline KoColorConversionSystem::Path* KoColorConversionSystem::findBestPathImpl( const KoColorConversionSystem::Node* srcNode, const KoColorConversionSystem::Node* dstNode) const
{
PathQualityChecker<ignoreHdr, ignoreColorCorrectness> pQC( qMax(0, dstNode->referenceDepth - srcNode->referenceDepth ) );
PathQualityChecker<ignoreHdr, ignoreColorCorrectness> pQC( qMax(0, srcNode->referenceDepth - dstNode->referenceDepth ) );
QHash<Node*, Path*> node2path; // current best path to reach a given node
QList<Path*> currentPathes; // list of all pathes
// Generate the initial list of pathes
......@@ -399,7 +407,7 @@ inline KoColorConversionSystem::Path* KoColorConversionSystem::findBestPathImpl(
deletePathes(currentPathes); // clean up
return p;
}
Q_ASSERT(!node2path.contains( endNode )); // That would be a total fuck up if there are two vertexes between two nodes
Q_ASSERT(not node2path.contains( endNode )); // That would be a total fuck up if there are two vertexes between two nodes
node2path[ endNode ] = new Path( *p );
currentPathes.append( p );
}
......@@ -412,7 +420,7 @@ inline KoColorConversionSystem::Path* KoColorConversionSystem::findBestPathImpl(
Node* endNode = p->endNode();
foreach( Vertex* v, endNode->outputVertexes)
{
if(!p->contains( v->dstNode ) )
if( not p->contains( v->dstNode ) )
{
Path* newP = new Path(*p);
newP->appendVertex( v );
......@@ -423,7 +431,7 @@ inline KoColorConversionSystem::Path* KoColorConversionSystem::findBestPathImpl(
{ // Victory
deletePathes(currentPathes); // clean up
return newP;
} else if(!lessWorsePath )
} else if( not lessWorsePath )
{
lessWorsePath = newP;
} else if( pQC.lessWorseThan( newP, lessWorsePath) ) {
......@@ -467,7 +475,7 @@ inline KoColorConversionSystem::Path* KoColorConversionSystem::findBestPathImpl(
template<bool ignoreHdr>
inline KoColorConversionSystem::Path* KoColorConversionSystem::findBestPathImpl( const KoColorConversionSystem::Node* srcNode, const KoColorConversionSystem::Node* dstNode) const
{
if(srcNode->isGray || dstNode->isGray)
if(srcNode->isGray or dstNode->isGray)
{
return findBestPathImpl<ignoreHdr, true>(srcNode, dstNode);
} else {
......@@ -477,7 +485,8 @@ inline KoColorConversionSystem::Path* KoColorConversionSystem::findBestPathImpl(
KoColorConversionSystem::Path* KoColorConversionSystem::findBestPath( const KoColorConversionSystem::Node* srcNode, const KoColorConversionSystem::Node* dstNode) const
{
if(srcNode->isHdr && dstNode->isHdr)
kDebug(/*31000*/) << "Find best path between " << srcNode->id() << " and " << dstNode->id();
if(srcNode->isHdr and dstNode->isHdr)
{
return findBestPathImpl<false>(srcNode, dstNode);
} else {
......
......@@ -29,13 +29,17 @@ class KoColorSpaceFactory;
#include <pigment_export.h>
class PIGMENT_EXPORT KoColorConversionSystem {
public:
struct Node;
struct Vertex;
struct NodeKey;
struct Path;
friend uint qHash(const KoColorConversionSystem::NodeKey &key);
public:
KoColorConversionSystem();
~KoColorConversionSystem();
void insertColorSpace(const KoColorSpaceFactory*);
KoColorConversionTransformation* createColorConverter(const KoColorSpace * srcColorSpace, const KoColorSpace * dstColorSpace, KoColorConversionTransformation::Intent renderingIntent = KoColorConversionTransformation::IntentPerceptual) const;
public:
/**
* This function return a text that can be compiled using dot to display
* the graph of color conversion connection.
......@@ -48,11 +52,8 @@ class PIGMENT_EXPORT KoColorConversionSystem {
*/
QString bestPathToDot(QString srcModelId, QString srcDepthId, QString dstModelId, QString dstDepthId) const;
private:
struct Node;
struct Vertex;
struct NodeKey;
QString vertexToDot(Vertex* v, QString options) const;
private:
Node* nodeFor(const NodeKey& key);
const Node* nodeFor(const NodeKey& key) const;
/**
......@@ -77,7 +78,7 @@ class PIGMENT_EXPORT KoColorConversionSystem {
inline Path* findBestPathImpl(const Node* srcNode, const Node* dstNode) const;
template<bool ignoreHdr>
inline Path* findBestPathImpl(const Node* srcNode, const Node* dstNode) const;
friend uint qHash(const KoColorConversionSystem::NodeKey &key);
private:
struct Private;
Private* const d;
};
......
......@@ -43,14 +43,14 @@ KoColorConversionTransformationFactory::~KoColorConversionTransformationFactory(
delete d;
}
bool KoColorConversionTransformationFactory::canBeSource(KoColorSpace* srcCS)
bool KoColorConversionTransformationFactory::canBeSource(const KoColorSpace* srcCS)
{
return ((srcCS->colorModelId().id() == d->srcModelId) && (srcCS->colorDepthId().id() == d->srcDepthId));
return ((srcCS->colorModelId().id() == d->srcModelId) and (srcCS->colorDepthId().id() == d->srcDepthId));
}
bool KoColorConversionTransformationFactory::canBeDestination(KoColorSpace* dstCS)
bool KoColorConversionTransformationFactory::canBeDestination(const KoColorSpace* dstCS)
{
return ((dstCS->colorModelId().id() == d->dstModelId) && (dstCS->colorDepthId().id() == d->dstDepthId));
return ((dstCS->colorModelId().id() == d->dstModelId) and (dstCS->colorDepthId().id() == d->dstDepthId));
}
QString KoColorConversionTransformationFactory::srcColorModelId() const
......
......@@ -52,7 +52,7 @@ class PIGMENT_EXPORT KoColorConversionTransformationFactory {
* @param srcColorSpace source color space
* @param dstColorSpace destination color space
*/
virtual KoColorConversionTransformation* createColorTransformation(KoColorSpace* srcColorSpace, KoColorSpace* dstColorSpace, KoColorConversionTransformation::Intent renderingIntent = KoColorConversionTransformation::IntentPerceptual) =0;
virtual KoColorConversionTransformation* createColorTransformation(const KoColorSpace* srcColorSpace, const KoColorSpace* dstColorSpace, KoColorConversionTransformation::Intent renderingIntent = KoColorConversionTransformation::IntentPerceptual) =0;
/**
* @return true if this factory creates a color conversion transformation which
* conserve color information (typical color transformation that lose that information
......@@ -94,12 +94,12 @@ class PIGMENT_EXPORT KoColorConversionTransformationFactory {
* @param srcCS source color space
* @return true if the color space given as argument can be used as a source colorspace
*/
bool canBeSource(KoColorSpace* srcCS);
bool canBeSource(const KoColorSpace* srcCS);
/**
* @param dstCS destination color space
* @return true if the color space given as argument can be used as a destination colorspace
*/
bool canBeDestination(KoColorSpace* dstCS);
bool canBeDestination(const KoColorSpace* dstCS);
private:
struct Private;
Private* const d;
......
......@@ -26,6 +26,8 @@
#include "KoCompositeOp.h"
#include "KoColorTransformation.h"
#include "KoColorConversionSystem.h"
#include "KoColorSpaceRegistry.h"
struct KoColorSpace::Private {
QString id;
......@@ -154,7 +156,8 @@ void KoColorSpace::addCompositeOp(const KoCompositeOp * op)
KoColorConversionTransformation* KoColorSpace::createColorConverter(const KoColorSpace * dstColorSpace, KoColorConversionTransformation::Intent renderingIntent) const
{
return new KoColorConversionTransformation(this, dstColorSpace, renderingIntent);
return d->parent->colorConversionSystem()->createColorConverter( this, dstColorSpace, renderingIntent);
// return new KoColorConversionTransformation(this, dstColorSpace, renderingIntent);
}
bool KoColorSpace::convertPixelsTo(const quint8 * src,
......
......@@ -25,15 +25,12 @@
#include "KoColorConversionTransformationFactory.h"
#include "KoColorModelStandardIds.h"
#include <kdebug.h>
#include <kconfiggroup.h>
// -- KoLcmsColorConversionTransformationFactory --
class KoLcmsColorConversionTransformationFactory : public KoColorConversionTransformationFactory {
public:
KoLcmsColorConversionTransformationFactory(QString _srcModelId, QString _srcDepthId, QString _dstModelId, QString _dstDepthId);
virtual KoColorConversionTransformation* createColorTransformation(KoColorSpace* srcColorSpace, KoColorSpace* dstColorSpace, KoColorConversionTransformation::Intent renderingIntent = KoColorConversionTransformation::IntentPerceptual);
virtual KoColorConversionTransformation* createColorTransformation(const KoColorSpace* srcColorSpace, const KoColorSpace* dstColorSpace, KoColorConversionTransformation::Intent renderingIntent = KoColorConversionTransformation::IntentPerceptual);
virtual bool conserveColorInformation() const;
virtual bool conserveDynamicRange() const;
virtual int depthDecrease() const;
......@@ -51,15 +48,15 @@ KoLcmsColorConversionTransformationFactory::KoLcmsColorConversionTransformationF
Q_ASSERT(m_srcColorSpaceType);
m_dstColorSpaceType = computeColorSpaceType( _dstModelId, _dstDepthId);
Q_ASSERT(m_dstColorSpaceType);
m_conserveColorInformation = !(_dstModelId == GrayAColorModelID.id() || _dstModelId == GrayColorModelID.id()); // color information is lost when converting to Grayscale
m_conserveColorInformation = not (_dstModelId == GrayAColorModelID.id() or _dstModelId == GrayColorModelID.id()); // color information is lost when converting to Grayscale
m_depthDecrease = 0;
if( _srcDepthId == Integer16BitsColorDepthID.id() || _dstDepthId == Integer8BitsColorDepthID.id())
if( _srcDepthId == Integer16BitsColorDepthID.id() and _dstDepthId == Integer8BitsColorDepthID.id())
{
m_depthDecrease = 8;
}
}
KoColorConversionTransformation* KoLcmsColorConversionTransformationFactory::createColorTransformation(KoColorSpace* srcColorSpace, KoColorSpace* dstColorSpace, KoColorConversionTransformation::Intent renderingIntent )
KoColorConversionTransformation* KoLcmsColorConversionTransformationFactory::createColorTransformation(const KoColorSpace* srcColorSpace, const KoColorSpace* dstColorSpace, KoColorConversionTransformation::Intent renderingIntent )
{
return new KoLcmsColorConversionTransformation(srcColorSpace, m_srcColorSpaceType, dynamic_cast<KoLcmsColorProfile*>(srcColorSpace->profile()), dstColorSpace, m_dstColorSpaceType, dynamic_cast<KoLcmsColorProfile*>(dstColorSpace->profile()), renderingIntent);
}
......@@ -116,7 +113,7 @@ quint32 KoLcmsColorConversionTransformationFactory::computeColorSpaceType(QStrin
{
modelType = (COLORSPACE_SH(PT_YCbCr)|EXTRA_SH(1)|CHANNELS_SH(3));
} else {
kDebug() << "Unknow color model";
kDebug(31000) << "Unknow color model";
return 0;
}
return depthType|modelType;
......
......@@ -392,17 +392,17 @@ class KoLcmsColorSpace : public KoColorSpaceAbstract<_CSTraits>, public KoLcmsIn
}
}
virtual KoColorConversionTransformation* createColorConverter(const KoColorSpace * dstColorSpace, KoColorConversionTransformation::Intent renderingIntent = KoColorConversionTransformation::IntentPerceptual) const
{
KoLcmsColorProfile* dstprofile = toLcmsProfile(dstColorSpace->profile());
const KoLcmsInfo* dstInfo = dynamic_cast<const KoLcmsInfo*>(dstColorSpace);
if(d->profile && dstprofile && dstInfo)
{
return new KoLcmsColorConversionTransformation(this, colorSpaceType(), d->profile, dstColorSpace, dstInfo->colorSpaceType(), dstprofile, renderingIntent);
} else {
return KoColorSpaceAbstract<_CSTraits>::createColorConverter(dstColorSpace, renderingIntent);
}
}
// virtual KoColorConversionTransformation* createColorConverter(const KoColorSpace * dstColorSpace, KoColorConversionTransformation::Intent renderingIntent = KoColorConversionTransformation::IntentPerceptual) const
// {
// KoLcmsColorProfile* dstprofile = toLcmsProfile(dstColorSpace->profile());
// const KoLcmsInfo* dstInfo = dynamic_cast<const KoLcmsInfo*>(dstColorSpace);
// if(d->profile and dstprofile and dstInfo)
// {
// return new KoLcmsColorConversionTransformation(this, colorSpaceType(), d->profile, dstColorSpace, dstInfo->colorSpaceType(), dstprofile, renderingIntent);
// } else {
// return KoColorSpaceAbstract<_CSTraits>::createColorConverter(dstColorSpace, renderingIntent);
// }
// }
virtual bool convertPixelsTo(const quint8 * src,
quint8 * dst,
......@@ -428,7 +428,7 @@ class KoLcmsColorSpace : public KoColorSpaceAbstract<_CSTraits>, public KoLcmsIn
}
}
if (!tf) {
if (not tf) {
if (!d->transforms.contains(dstColorSpace)) {
// XXX: Should we clear the transform cache if it gets too big?
......
......@@ -50,12 +50,12 @@ template<typename _src_CSTraits_, typename _dst_CSTraits_>
class KoScaleColorConversionTransformationFactory : public KoColorConversionTransformationFactory {
public:
KoScaleColorConversionTransformationFactory(QString colorModelId, QString _srcDepthId, QString _dstDepthId) : KoColorConversionTransformationFactory(colorModelId, _srcDepthId, colorModelId, _dstDepthId),
hdr( ( (srcColorDepthId() == Float16BitsColorDepthID.id()) &&
(dstColorDepthId() == Float32BitsColorDepthID.id()) ) ||
( (srcColorDepthId() == Float32BitsColorDepthID.id()) &&
hdr( ( (srcColorDepthId() == Float16BitsColorDepthID.id()) and
(dstColorDepthId() == Float32BitsColorDepthID.id()) ) or
( (srcColorDepthId() == Float32BitsColorDepthID.id()) and
(dstColorDepthId() == Float16BitsColorDepthID.id()) ) )
{}
virtual KoColorConversionTransformation* createColorTransformation(KoColorSpace* srcColorSpace, KoColorSpace* dstColorSpace, KoColorConversionTransformation::Intent renderingIntent = KoColorConversionTransformation::IntentPerceptual)
virtual KoColorConversionTransformation* createColorTransformation(const KoColorSpace* srcColorSpace, const KoColorSpace* dstColorSpace, KoColorConversionTransformation::Intent renderingIntent = KoColorConversionTransformation::IntentPerceptual)
{
Q_UNUSED(renderingIntent);
Q_ASSERT(canBeSource(srcColorSpace));
......
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