Commit a1fca132 authored by Cyrille Berger's avatar Cyrille Berger

* move the color conversion caching for convertPixelsTo to KoColorSpace

* fix the Color Conversion System when the path is longer than 2

svn path=/trunk/koffice/; revision=722175
parent 2754676b
......@@ -333,13 +333,16 @@ KoColorConversionTransformation* KoColorConversionSystem::createColorConverter(c
KoColorSpace* intermCS = defaultColorSpaceForNode( path->vertexes.first()->dstNode );
mccTransfo->appendTransfo( path->vertexes.first()->factory()->createColorTransformation(srcColorSpace, intermCS, renderingIntent) );
kDebug(31000) << path->vertexes.first()->srcNode->id() << " to " << path->vertexes.first()->dstNode->id();
for(int i = 1; i < path->length() - 1; i++)
{
Vertex* v = path->vertexes[i];
kDebug(31000) << v->srcNode->id() << " to " << v->dstNode->id();
KoColorSpace* intermCS2 = defaultColorSpaceForNode( v->dstNode );
mccTransfo->appendTransfo( v->factory()->createColorTransformation(intermCS, intermCS2, renderingIntent) );
intermCS2 = intermCS;
intermCS = intermCS2;
}
kDebug(31000) << path->vertexes.last()->srcNode->id() << " to " << path->vertexes.last()->dstNode->id();
mccTransfo->appendTransfo( path->vertexes.last()->factory()->createColorTransformation(intermCS, dstColorSpace, renderingIntent) );
}
......
......@@ -39,6 +39,13 @@ struct KoColorSpace::Private {
KoConvolutionOp* convolutionOp;
QThreadStorage< QVector<quint8>* > conversionCache;
mutable const KoColorSpace *lastUsedDstColorSpace;
mutable KoColorConversionTransformation* lastUsedTransform;
// cmsHTRANSFORM is a void *, so this should work.
typedef QMap<const KoColorSpace *, KoColorConversionTransformation*> TransformMap;
mutable TransformMap transforms; // Cache for existing transforms
};
KoColorSpace::KoColorSpace()
......@@ -54,6 +61,8 @@ KoColorSpace::KoColorSpace(const QString &id, const QString &name, KoColorSpaceR
d->parent = parent;
d->mixColorsOp = mixColorsOp;
d->convolutionOp = convolutionOp;
d->lastUsedDstColorSpace = 0;
d->lastUsedTransform = 0;
}
KoColorSpace::~KoColorSpace()
......@@ -157,27 +166,52 @@ void KoColorSpace::addCompositeOp(const KoCompositeOp * op)
KoColorConversionTransformation* KoColorSpace::createColorConverter(const KoColorSpace * dstColorSpace, KoColorConversionTransformation::Intent renderingIntent) const
{
return d->parent->colorConversionSystem()->createColorConverter( this, dstColorSpace, renderingIntent);
// return new KoColorConversionTransformation(this, dstColorSpace, renderingIntent);
}
bool KoColorSpace::convertPixelsTo(const quint8 * src,
quint8 * dst,
const KoColorSpace * dstColorSpace,
quint32 numPixels,
KoColorConversionTransformation::Intent renderingIntent) const
quint8 * dst,
const KoColorSpace * dstColorSpace,
quint32 numPixels,
KoColorConversionTransformation::Intent renderingIntent) const
{
Q_UNUSED(renderingIntent);
if (dstColorSpace->id() == this->id()
&& dstColorSpace->profile() == profile())
{
if (src!= dst)
memcpy (dst, src, numPixels * this->pixelSize());
if (*this == *dstColorSpace) {
memmove(dst, src, numPixels*pixelSize());
} else {
KoColorConversionTransformation* transfo =new KoColorConversionTransformation(this, dstColorSpace, renderingIntent);
transfo->transform(src, dst, numPixels);
return true;
}
KoColorConversionTransformation* tf = 0;
if (d->lastUsedTransform != 0 && d->lastUsedDstColorSpace != 0) {
if (dstColorSpace->id() == d->lastUsedDstColorSpace->id() &&
dstColorSpace->profile() == d->lastUsedDstColorSpace->profile()) {
tf = d->lastUsedTransform;
}
}
if (not tf) {
if (!d->transforms.contains(dstColorSpace)) {
// XXX: Should we clear the transform cache if it gets too big?
tf = this->createColorConverter(dstColorSpace, renderingIntent);
d->transforms[dstColorSpace] = tf;
}
else {
tf = d->transforms[dstColorSpace];
}
d->lastUsedTransform = tf;
d->lastUsedDstColorSpace = dstColorSpace;
}
tf->transform(src, dst, numPixels);
return true;
}
void KoColorSpace::bitBlt(quint8 *dst,
qint32 dststride,
KoColorSpace * srcSpace,
......
......@@ -189,12 +189,6 @@ class KoLcmsColorSpace : public KoColorSpaceAbstract<_CSTraits>, public KoLcmsIn
cmsHTRANSFORM defaultFromLab;
KoLcmsColorProfile * profile;
mutable const KoColorSpace *lastUsedDstColorSpace;
mutable KoColorConversionTransformation* lastUsedTransform;
// cmsHTRANSFORM is a void *, so this should work.
typedef QMap<const KoColorSpace *, KoColorConversionTransformation*> TransformMap;
mutable TransformMap transforms; // Cache for existing transforms
};
protected:
KoLcmsColorSpace(const QString &id, const QString &name, KoColorSpaceRegistry * parent, DWORD cmType,
......@@ -204,8 +198,6 @@ class KoLcmsColorSpace : public KoColorSpaceAbstract<_CSTraits>, public KoLcmsIn
{
d->profile = toLcmsProfile(p);
d->qcolordata = 0;
d->lastUsedDstColorSpace = 0;
d->lastUsedTransform = 0;
d->lastRGBProfile = 0;
d->lastToRGB = 0;
d->lastFromRGB = 0;
......@@ -338,7 +330,7 @@ class KoLcmsColorSpace : public KoColorSpaceAbstract<_CSTraits>, public KoLcmsIn
dstCS = KoColorSpaceRegistry::instance()->colorSpace("RGBA", dstProfile);
if (data)
convertPixelsTo(const_cast<quint8 *>(data), img.bits(), dstCS, width * height, renderingIntent);
this->convertPixelsTo(const_cast<quint8 *>(data), img.bits(), dstCS, width * height, renderingIntent);
return img;
}
......@@ -392,61 +384,6 @@ 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 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,
const KoColorSpace * dstColorSpace,
quint32 numPixels,
KoColorConversionTransformation::Intent renderingIntent) const
{
if (dstColorSpace->id() == this->id()
&& dstColorSpace->profile() == profile())
{
if (src!= dst)
memcpy (dst, src, numPixels * this->pixelSize());
return true;
}
KoColorConversionTransformation* tf = 0;
if (d->lastUsedTransform != 0 && d->lastUsedDstColorSpace != 0) {
if (dstColorSpace->id() == d->lastUsedDstColorSpace->id() &&
dstColorSpace->profile() == d->lastUsedDstColorSpace->profile()) {
tf = d->lastUsedTransform;
}
}
if (not tf) {
if (!d->transforms.contains(dstColorSpace)) {
// XXX: Should we clear the transform cache if it gets too big?
tf = this->createColorConverter(dstColorSpace, renderingIntent);
d->transforms[dstColorSpace] = tf;
}
else {
tf = d->transforms[dstColorSpace];
}
d->lastUsedTransform = tf;
d->lastUsedDstColorSpace = dstColorSpace;
}
tf->transform(src, dst, numPixels);
return true;
}
virtual KoColorTransformation *createBrightnessContrastAdjustment(const quint16 *transferValues) const
{
if (!d->profile) return 0;
......
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