Commit e1e5fe81 authored by Cyrille Berger's avatar Cyrille Berger

* add missing files from previous commit ( the one holding the color conversion transformations)

* add a self to self transformation for color space that don't define one (make TestColorConversionSystem successfull, for now)

svn path=/trunk/koffice/; revision=722533
parent 467c874f
/*
* Copyright (c) 2007 Cyrille Berger <cberger@cberger.net>
*
* This program 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; version 2 of the License.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _KIS_RGB_TO_YCBCR_COLOR_CONVERSION_TRANSFORMATION_H_
#define _KIS_RGB_TO_YCBCR_COLOR_CONVERSION_TRANSFORMATION_H_
#include <KoColorConversionTransformation.h>
#define SRC_TO_DST(v) (KoColorSpaceMaths<typename _src_CSTraits_::channels_type, typename _dst_CSTraits_::channels_type >::scaleToA(v))
template<typename _src_CSTraits_, typename _dst_CSTraits_>
class KisRgbToYCbCrColorConversionTransformation : public KoColorConversionTransformation {
public:
KisRgbToYCbCrColorConversionTransformation(const KoColorSpace* srcCs, const KoColorSpace* dstCs) : KoColorConversionTransformation(srcCs, dstCs)
{
}
virtual void transform(const quint8 *srcU8, quint8 *dstU8, qint32 nPixels) const
{
const typename _src_CSTraits_::Pixel* src = reinterpret_cast< const typename _src_CSTraits_::Pixel*>(srcU8);
typename _dst_CSTraits_::Pixel* dst = reinterpret_cast<typename _dst_CSTraits_::Pixel*>(dstU8);
while(nPixels > 0)
{
typename _dst_CSTraits_::channels_type red = SRC_TO_DST(src->red);
typename _dst_CSTraits_::channels_type green = SRC_TO_DST(src->green);
typename _dst_CSTraits_::channels_type blue = SRC_TO_DST(src->blue);
dst->Y = _dst_CSTraits_::computeY( red, green, blue);
dst->Cb = _dst_CSTraits_::computeCb( red, green, blue);
dst->Cr = _dst_CSTraits_::computeCr( red, green, blue);
dst->alpha = SRC_TO_DST(src->alpha);
src ++;
dst ++;
nPixels--;
}
}
};
template<typename _src_CSTraits_, typename _dst_CSTraits_>
class KisRgbToYCbCrColorConversionTransformationFactory : public KoColorConversionTransformationFactory {
public:
KisRgbToYCbCrColorConversionTransformationFactory(QString _srcColorModelId, QString _srcDepthId, QString _dstColorModelId, QString _dstDepthId) : KoColorConversionTransformationFactory(_srcColorModelId, _srcDepthId, _dstColorModelId, _dstDepthId)
{}
virtual KoColorConversionTransformation* createColorTransformation(const KoColorSpace* srcColorSpace, const KoColorSpace* dstColorSpace, KoColorConversionTransformation::Intent renderingIntent = KoColorConversionTransformation::IntentPerceptual)
{
Q_UNUSED(renderingIntent);
Q_ASSERT(canBeSource(srcColorSpace));
Q_ASSERT(canBeDestination(dstColorSpace));
return new KisRgbToYCbCrColorConversionTransformation<_src_CSTraits_, _dst_CSTraits_>(srcColorSpace, dstColorSpace);
}
virtual bool conserveColorInformation() const
{
return true;
}
virtual bool conserveDynamicRange() const
{
return false;
}
virtual int depthDecrease() const
{
return qMax(0, _src_CSTraits_::depth - _dst_CSTraits_::depth);
}
private:
bool hdr;
};
#endif
/*
* Copyright (c) 2007 Cyrille Berger <cberger@cberger.net>
*
* This program 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; version 2 of the License.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _KIS_YCBCR_TO_RGB_COLOR_CONVERSION_TRANSFORMATION_H_
#define _KIS_YCBCR_TO_RGB_COLOR_CONVERSION_TRANSFORMATION_H_
#include <KoColorConversionTransformation.h>
#define SRC_TO_DST(v) (KoColorSpaceMaths<typename _src_CSTraits_::channels_type, typename _dst_CSTraits_::channels_type >::scaleToA(v))
template<typename _src_CSTraits_, typename _dst_CSTraits_>
class KisYCbCrToRgbColorConversionTransformation : public KoColorConversionTransformation {
public:
KisYCbCrToRgbColorConversionTransformation(const KoColorSpace* srcCs, const KoColorSpace* dstCs) : KoColorConversionTransformation(srcCs, dstCs)
{
}
virtual void transform(const quint8 *srcU8, quint8 *dstU8, qint32 nPixels) const
{
const typename _src_CSTraits_::Pixel* src = reinterpret_cast< const typename _src_CSTraits_::Pixel*>(srcU8);
typename _dst_CSTraits_::Pixel* dst = reinterpret_cast<typename _dst_CSTraits_::Pixel*>(dstU8);
while(nPixels > 0)
{
dst->red = SRC_TO_DST(_src_CSTraits_::computeRed( src->Y, src->Cb, src->Cr));
dst->green = SRC_TO_DST(_src_CSTraits_::computeGreen( src->Y, src->Cb, src->Cr));
dst->blue = SRC_TO_DST(_src_CSTraits_::computeBlue( src->Y, src->Cb, src->Cr));
dst->alpha = SRC_TO_DST(src->alpha);
src ++;
dst ++;
nPixels--;
}
}
};
template<typename _src_CSTraits_, typename _dst_CSTraits_>
class KisYCbCrToRgbColorConversionTransformationFactory : public KoColorConversionTransformationFactory {
public:
KisYCbCrToRgbColorConversionTransformationFactory(QString _srcColorModelId, QString _srcDepthId, QString _dstColorModelId, QString _dstDepthId) : KoColorConversionTransformationFactory(_srcColorModelId, _srcDepthId, _dstColorModelId, _dstDepthId)
{}
virtual KoColorConversionTransformation* createColorTransformation(const KoColorSpace* srcColorSpace, const KoColorSpace* dstColorSpace, KoColorConversionTransformation::Intent renderingIntent = KoColorConversionTransformation::IntentPerceptual)
{
Q_UNUSED(renderingIntent);
Q_ASSERT(canBeSource(srcColorSpace));
Q_ASSERT(canBeDestination(dstColorSpace));
return new KisYCbCrToRgbColorConversionTransformation<_src_CSTraits_, _dst_CSTraits_>(srcColorSpace, dstColorSpace);
}
virtual bool conserveColorInformation() const
{
return true;
}
virtual bool conserveDynamicRange() const
{
return false;
}
virtual int depthDecrease() const
{
return qMax(0, _src_CSTraits_::depth - _dst_CSTraits_::depth);
}
private:
bool hdr;
};
#endif
......@@ -29,6 +29,7 @@
#include "KoColorSpace.h"
#include "KoColorSpaceRegistry.h"
#include "KoColorModelStandardIds.h"
#include "KoCopyColorConversionTransformation.h"
class KoMultipleColorConversionTransformation : public KoColorConversionTransformation {
public:
......@@ -285,6 +286,14 @@ void KoColorConversionSystem::insertColorSpace(const KoColorSpaceFactory* csf)
v->setFactoryFromSrc(cctf);
}
}
// Check if there is a path to convert self into self
Vertex* v = vertexBetween(csNode, csNode);
if( not v)
{
v = createVertex(csNode, csNode);
kDebug(31000) << "No self to self color conversion, add the copy one";
v->setFactoryFromSrc( new KoCopyColorConversionTransformationFactory(modelId, depthId));
}
}
KoColorSpace* KoColorConversionSystem::defaultColorSpaceForNode(const Node* node) const
......
......@@ -28,18 +28,7 @@
#include "KoColorTransformation.h"
#include "KoColorConversionSystem.h"
#include "KoColorSpaceRegistry.h"
class KoCopyConversionTransformation : public KoColorConversionTransformation {
public:
KoCopyConversionTransformation(const KoColorSpace* cs) : KoColorConversionTransformation(cs, cs)
{
}
virtual void transform(const quint8 *srcU8, quint8 *dstU8, qint32 nPixels) const
{
memcpy(dstU8, srcU8, nPixels * srcColorSpace()->pixelSize());
}
};
#include "KoCopyColorConversionTransformation.h"
struct KoColorSpace::Private {
QString id;
......@@ -241,7 +230,7 @@ KoColorConversionTransformation* KoColorSpace::createColorConverter(const KoColo
{
if( this == dstColorSpace)
{
return new KoCopyConversionTransformation(this);
return new KoCopyColorConversionTransformation(this);
} else {
return d->parent->colorConversionSystem()->createColorConverter( this, dstColorSpace, renderingIntent);
}
......
/*
* Copyright (c) 2007 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_COPY_COLOR_CONVERSION_TRANSFORMATION_H_
#define _KO_COPY_COLOR_CONVERSION_TRANSFORMATION_H_
#include "KoColorConversionTransformation.h"
#include "KoColorConversionTransformationFactory.h"
class KoCopyColorConversionTransformation : public KoColorConversionTransformation {
public:
KoCopyColorConversionTransformation(const KoColorSpace* cs) : KoColorConversionTransformation(cs, cs)
{
}
virtual void transform(const quint8 *srcU8, quint8 *dstU8, qint32 nPixels) const
{
memcpy(dstU8, srcU8, nPixels * srcColorSpace()->pixelSize());
}
};
class KoCopyColorConversionTransformationFactory : public KoColorConversionTransformationFactory {
public:
KoCopyColorConversionTransformationFactory(QString colorModelId, QString depthId) : KoColorConversionTransformationFactory(colorModelId, depthId, colorModelId, depthId)
{}
virtual KoColorConversionTransformation* createColorTransformation(const KoColorSpace* srcColorSpace, const KoColorSpace* dstColorSpace, KoColorConversionTransformation::Intent renderingIntent = KoColorConversionTransformation::IntentPerceptual)
{
Q_UNUSED(renderingIntent);
Q_ASSERT(canBeSource(srcColorSpace));
Q_ASSERT(canBeDestination(dstColorSpace));
Q_ASSERT(srcColorSpace == dstColorSpace);
return new KoCopyColorConversionTransformation(srcColorSpace);
}
virtual bool conserveColorInformation() const
{
return true;
}
virtual bool conserveDynamicRange() const
{
return true;
}
virtual int depthDecrease() const
{
return 0;
}
};
#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