Commit 7b98e442 authored by Cyrille Berger's avatar Cyrille Berger

- remove lcmsism from KoColorSpace

- might fix a bug in YCbCr's convertion to and from rgb (at least fix one of the function which was obviously wrong, can't remember if the problem was visible or not)
- disable convertion from read-only colorspaces in png/jpeg/tiff (for now)

svn path=/trunk/koffice/; revision=663371
parent 07fde752
......@@ -33,19 +33,14 @@ class KRITA_GRAY_U16_EXPORT KisGrayU16ColorSpace : public KoLcmsColorSpace<GrayU
virtual bool willDegrade(ColorSpaceIndependence ) const { return false; }
};
class KisGrayU16ColorSpaceFactory : public KoColorSpaceFactory
class KisGrayU16ColorSpaceFactory : public KoLcmsColorSpaceFactory
{
public:
KisGrayU16ColorSpaceFactory() : KoLcmsColorSpaceFactory(TYPE_GRAY_16, icSigGrayData)
{}
virtual QString id() const { return "GRAY16"; }
virtual QString name() const { return i18n("Grayscale (16-bit integer/channel)"); }
/**
* lcms colorspace type definition.
*/
virtual quint32 colorSpaceType() { return TYPE_GRAY_16; };
virtual icColorSpaceSignature colorSpaceSignature() { return icSigGrayData; };
virtual KoColorSpace *createColorSpace(KoColorSpaceRegistry * parent, KoColorProfile *p) { return new KisGrayU16ColorSpace(parent, p); };
virtual QString defaultProfile() { return "gray built-in - (lcms internal)"; };
......
......@@ -33,19 +33,14 @@ class KRITA_GRAY_U8_EXPORT KisGrayColorSpace : public KoLcmsColorSpace<GrayU8Tra
virtual bool willDegrade(ColorSpaceIndependence ) const { return false; }
};
class KisGrayColorSpaceFactory : public KoColorSpaceFactory
class KisGrayColorSpaceFactory : public KoLcmsColorSpaceFactory
{
public:
KisGrayColorSpaceFactory() : KoLcmsColorSpaceFactory(TYPE_GRAY_8, icSigGrayData)
{}
virtual QString id() const { return "GRAY"; }
virtual QString name() const { return i18n("Grayscale (8-bit integer/channel)"); }
/**
* lcms colorspace type definition.
*/
virtual quint32 colorSpaceType() { return TYPE_GRAY_8; };
virtual icColorSpaceSignature colorSpaceSignature() { return icSigGrayData; };
virtual KoColorSpace *createColorSpace(KoColorSpaceRegistry * parent, KoColorProfile *p) { return new KisGrayColorSpace(parent, p); };
virtual QString defaultProfile() { return "gray built-in - (lcms internal)"; };
......
......@@ -141,13 +141,6 @@ public:
*/
virtual KoID id() const { return KoID("LMSAF32", i18n("LMS Cone Space (32-bit float/channel)")); };
/**
* lcms colorspace type definition.
*/
virtual quint32 colorSpaceType() { return 0; }; // FIXME: lcms do not support LMS cone space
virtual icColorSpaceSignature colorSpaceSignature() { return icMaxEnumData; };
virtual KoColorSpace *createColorSpace(KoColorSpaceRegistry * parent, KoColorProfile *p) { return new KisLmsF32ColorSpace(parent, p); };
virtual QString defaultProfile() { return "sRGB built-in - (lcms internal)"; };
......
......@@ -33,7 +33,7 @@
#include "compositeops/KoCompositeOpErase.h"
KisRgbF16HDRColorSpace::KisRgbF16HDRColorSpace(KoColorSpaceRegistry * parent, KoColorProfile */*p*/)
: KisRgbFloatHDRColorSpace<RgbF16Traits>("RGBAF16HALF", i18n("RGB (16-bit float/channel) for High Dynamic Range imaging"), parent, RGBAF16HALF_LCMS_TYPE)
: KisRgbFloatHDRColorSpace<RgbF16Traits>("RGBAF16HALF", i18n("RGB (16-bit float/channel) for High Dynamic Range imaging"), parent)
{
addChannel(new KoChannelInfo(i18n("Red"), 2 * sizeof(half), KoChannelInfo::COLOR, KoChannelInfo::FLOAT16, sizeof(half), QColor(255,0,0)));
addChannel(new KoChannelInfo(i18n("Green"), 1 * sizeof(half), KoChannelInfo::COLOR, KoChannelInfo::FLOAT16, sizeof(half), QColor(0,255,0)));
......
......@@ -38,11 +38,11 @@ class KRITA_RGBF16_EXPORT KisRgbF16HDRColorSpace : public KisRgbFloatHDRColorSpa
else
return false;
}
bool profileIsCompatible(KoColorProfile*) const {
return false;
}
};
// FIXME: lcms doesn't support 16-bit float
#define RGBAF16HALF_LCMS_TYPE TYPE_BGRA_16
class KRITA_RGBF16_EXPORT KisRgbF16HDRColorSpaceFactory : public KoColorSpaceFactory
{
public:
......@@ -53,12 +53,10 @@ public:
virtual QString id() const { return "RGBAF16HALF"; }
virtual QString name() const { return i18n("RGB (16-bit float/channel) for High Dynamic Range imaging"); }
/**
* lcms colorspace type definition.
*/
virtual quint32 colorSpaceType() { return RGBAF16HALF_LCMS_TYPE; };
virtual icColorSpaceSignature colorSpaceSignature() { return icSigRgbData; };
virtual bool profileIsCompatible(KoColorProfile* profile) const
{
return false;
}
virtual KoColorSpace *createColorSpace(KoColorSpaceRegistry * parent, KoColorProfile * p) { return new KisRgbF16HDRColorSpace(parent, p); };
......
......@@ -35,7 +35,7 @@
#include "compositeops/KoCompositeOpErase.h"
KisRgbF32HDRColorSpace::KisRgbF32HDRColorSpace(KoColorSpaceRegistry * parent, KoColorProfile */*p*/)
: KisRgbFloatHDRColorSpace<RgbF32Traits>("RGBAF32", i18n("RGB (32-bit float/channel) for High Dynamic Range imaging"), parent, RGBAF32FLOAT_LCMS_TYPE)
: KisRgbFloatHDRColorSpace<RgbF32Traits>("RGBAF32", i18n("RGB (32-bit float/channel) for High Dynamic Range imaging"), parent)
{
addChannel(new KoChannelInfo(i18n("Red"), 2 * sizeof(float), KoChannelInfo::COLOR, KoChannelInfo::FLOAT32, sizeof(float), QColor(255,0,0)));
addChannel(new KoChannelInfo(i18n("Green"), 1 * sizeof(float), KoChannelInfo::COLOR, KoChannelInfo::FLOAT32, sizeof(float), QColor(0,255,0)));
......
......@@ -36,10 +36,11 @@ class KRITA_RGBF32_EXPORT KisRgbF32HDRColorSpace : public KisRgbFloatHDRColorSpa
else
return false;
}
bool profileIsCompatible(KoColorProfile*) const {
return false;
}
};
// FIXME: lcms doesn't support 32-bit float
#define RGBAF32FLOAT_LCMS_TYPE TYPE_BGRA_16
class KRITA_RGBF32_EXPORT KisRgbF32HDRColorSpaceFactory : public KoColorSpaceFactory
{
......@@ -50,13 +51,11 @@ public:
*/
virtual QString id() const { return "RGBAF32"; }
virtual QString name() const { return i18n("RGB (32-bit float/channel) for High Dynamic Range imaging"); }
/**
* lcms colorspace type definition.
*/
virtual quint32 colorSpaceType() { return RGBAF32FLOAT_LCMS_TYPE; };
virtual icColorSpaceSignature colorSpaceSignature() { return icSigRgbData; };
virtual bool profileIsCompatible(KoColorProfile* profile) const
{
return false;
}
virtual KoColorSpace *createColorSpace(KoColorSpaceRegistry * parent, KoColorProfile * p) { return new KisRgbF32HDRColorSpace(parent, p); };
......
......@@ -33,8 +33,8 @@ template <class _CSTraits>
class KisRgbFloatHDRColorSpace : public KoIncompleteColorSpace<_CSTraits, KoRGB16Fallback>
{
public:
KisRgbFloatHDRColorSpace(const QString &id, const QString &name, KoColorSpaceRegistry * parent, qint32 type)
: KoIncompleteColorSpace<_CSTraits, KoRGB16Fallback>(id, name, parent, type, icSigRgbData)
KisRgbFloatHDRColorSpace(const QString &id, const QString &name, KoColorSpaceRegistry * parent)
: KoIncompleteColorSpace<_CSTraits, KoRGB16Fallback>(id, name, parent)
{
}
......
......@@ -36,19 +36,15 @@ class PIGMENT_XYZ_U16_EXPORT KisXyzU16ColorSpace : public KoLcmsColorSpace<XyzU1
#define TYPE_XYZA_16 (COLORSPACE_SH(PT_XYZ)|CHANNELS_SH(3)|BYTES_SH(2)|EXTRA_SH(1))
class KisXyzU16ColorSpaceFactory : public KoColorSpaceFactory
class KisXyzU16ColorSpaceFactory : public KoLcmsColorSpaceFactory
{
public:
KisXyzU16ColorSpaceFactory() : KoLcmsColorSpaceFactory(TYPE_XYZA_16, icSigXYZData)
{
}
virtual QString id() const { return "XYZA16"; }
virtual QString name() const { return i18n("XYZ (16-bit integer/channel)"); }
/**
* lcms colorspace type definition.
*/
virtual quint32 colorSpaceType() { return TYPE_XYZA_16; };
virtual icColorSpaceSignature colorSpaceSignature() { return icSigXYZData; };
virtual KoColorSpace *createColorSpace(KoColorSpaceRegistry * parent, KoColorProfile *p) { return new KisXyzU16ColorSpace(parent, p); };
virtual QString defaultProfile() { return "XYZ built-in - (lcms internal)"; };
......
......@@ -34,12 +34,16 @@ template <class _CSTraits>
class KisYCbCrBaseColorSpace : public KoIncompleteColorSpace<_CSTraits, KoRGB16Fallback>
{
public:
KisYCbCrBaseColorSpace(const QString &id, const QString &name, KoColorSpaceRegistry * parent, qint32 type)
: KoIncompleteColorSpace<_CSTraits, KoRGB16Fallback>(id, name, parent, type, icSigRgbData)
KisYCbCrBaseColorSpace(const QString &id, const QString &name, KoColorSpaceRegistry * parent)
: KoIncompleteColorSpace<_CSTraits, KoRGB16Fallback>(id, name, parent)
{
}
virtual bool profileIsCompatible(KoColorProfile* /*profile*/) const
{
return false;
}
virtual void fromQColor(const QColor& c, quint8 *dstU8, KoColorProfile * /*profile*/) const
{
typename _CSTraits::Pixel *dst = reinterpret_cast< typename _CSTraits::Pixel *>(dstU8);
......@@ -82,26 +86,38 @@ class KisYCbCrBaseColorSpace : public KoIncompleteColorSpace<_CSTraits, KoRGB16F
*opacity = NATIVE_TO_UINT8(src->alpha);
}
virtual void fromRgbA16(const quint8 * srcU8, quint8 * dstU8, const quint32 nPixels) const
virtual void fromRgbA16(const quint8 * srcU8, quint8 * dstU8, quint32 nPixels) const
{
typename _CSTraits::Pixel* dst = reinterpret_cast<typename _CSTraits::Pixel*>(dstU8);
const quint16* src = reinterpret_cast<const quint16*>(srcU8);
typename _CSTraits::channels_type red = UINT16_TO_NATIVE(src[KoRgbU16Traits::red_pos]);
typename _CSTraits::channels_type green = UINT16_TO_NATIVE(src[KoRgbU16Traits::green_pos]);
typename _CSTraits::channels_type blue = UINT16_TO_NATIVE(src[KoRgbU16Traits::blue_pos]);
dst->Y = _CSTraits::computeY( red, green, blue);
dst->Cb = _CSTraits::computeCb( red, green, blue);
dst->Cr = _CSTraits::computeCr( red, green, blue);
dst->alpha = UINT16_TO_NATIVE(src[KoRgbU16Traits::alpha_pos]);
while(nPixels > 0)
{
typename _CSTraits::channels_type red = UINT16_TO_NATIVE(src[KoRgbU16Traits::red_pos]);
typename _CSTraits::channels_type green = UINT16_TO_NATIVE(src[KoRgbU16Traits::green_pos]);
typename _CSTraits::channels_type blue = UINT16_TO_NATIVE(src[KoRgbU16Traits::blue_pos]);
dst->Y = _CSTraits::computeY( red, green, blue);
dst->Cb = _CSTraits::computeCb( red, green, blue);
dst->Cr = _CSTraits::computeCr( red, green, blue);
dst->alpha = UINT16_TO_NATIVE(src[KoRgbU16Traits::alpha_pos]);
src ++;
dst += 4;
nPixels--;
}
}
virtual void toRgbA16(const quint8 * srcU8, quint8 * dstU8, const quint32 nPixels) const
virtual void toRgbA16(const quint8 * srcU8, quint8 * dstU8, quint32 nPixels) const
{
const typename _CSTraits::Pixel* src = reinterpret_cast< const typename _CSTraits::Pixel*>(srcU8);
quint16* dst = reinterpret_cast<quint16*>(dstU8);
dst[ KoRgbU16Traits::red_pos ] = NATIVE_TO_UINT16(_CSTraits::computeRed( src->Y, src->Cb, src->Cr));
dst[ KoRgbU16Traits::green_pos ] = NATIVE_TO_UINT16(_CSTraits::computeGreen( src->Y, src->Cb, src->Cr));
dst[ KoRgbU16Traits::blue_pos ] = NATIVE_TO_UINT16(_CSTraits::computeBlue( src->Y, src->Cb, src->Cr));
dst[KoRgbU16Traits::alpha_pos] = NATIVE_TO_UINT16(src->alpha);
while(nPixels > 0)
{
dst[ KoRgbU16Traits::red_pos ] = NATIVE_TO_UINT16(_CSTraits::computeRed( src->Y, src->Cb, src->Cr));
dst[ KoRgbU16Traits::green_pos ] = NATIVE_TO_UINT16(_CSTraits::computeGreen( src->Y, src->Cb, src->Cr));
dst[ KoRgbU16Traits::blue_pos ] = NATIVE_TO_UINT16(_CSTraits::computeBlue( src->Y, src->Cb, src->Cr));
dst[KoRgbU16Traits::alpha_pos] = NATIVE_TO_UINT16(src->alpha);
src ++;
dst += 4;
nPixels--;
}
}
private:
};
......
......@@ -31,7 +31,7 @@
#include "compositeops/KoCompositeOpErase.h"
KisYCbCrU16ColorSpace::KisYCbCrU16ColorSpace(KoColorSpaceRegistry * parent, KoColorProfile */*p*/)
: KisYCbCrBaseColorSpace<YCbCrU16Traits>("YCbCrAU16", i18n("YCbCr (16-bit integer/channel)"), parent, TYPE_YCbCr_16)
: KisYCbCrBaseColorSpace<YCbCrU16Traits>("YCbCrAU16", i18n("YCbCr (16-bit integer/channel)"), parent)
{
addChannel(new KoChannelInfo(i18n("Y"), YCbCrU16Traits::y_pos * sizeof(quint16), KoChannelInfo::COLOR, KoChannelInfo::UINT16, sizeof(quint16), QColor(255,0,0)));
addChannel(new KoChannelInfo(i18n("Cb"), YCbCrU16Traits::cb_pos * sizeof(quint16), KoChannelInfo::COLOR, KoChannelInfo::UINT16, sizeof(quint16), QColor(0,255,0)));
......
......@@ -44,6 +44,10 @@ public:
virtual QString id() const { return "YCbCrAU16"; }
virtual QString name() const { return i18n("YCBCR (16-bit integer/channel)"); }
virtual bool profileIsCompatible(KoColorProfile* /*profile*/) const
{
return false;
}
/**
* lcms colorspace type definition.
*/
......
......@@ -31,7 +31,7 @@
#include "compositeops/KoCompositeOpErase.h"
KisYCbCrU8ColorSpace::KisYCbCrU8ColorSpace(KoColorSpaceRegistry * parent, KoColorProfile */*p*/)
: KisYCbCrBaseColorSpace<YCbCrU8Traits>("YCbCrAU8", i18n("YCbCr (8-bit integer/channel)"), parent, TYPE_YCbCr_8)
: KisYCbCrBaseColorSpace<YCbCrU8Traits>("YCbCrAU8", i18n("YCbCr (8-bit integer/channel)"), parent)
{
addChannel(new KoChannelInfo(i18n("Y"), YCbCrU8Traits::y_pos * sizeof(quint8), KoChannelInfo::COLOR, KoChannelInfo::UINT8, sizeof(quint8), QColor(255,0,0)));
addChannel(new KoChannelInfo(i18n("Cb"), YCbCrU8Traits::cb_pos * sizeof(quint8), KoChannelInfo::COLOR, KoChannelInfo::UINT8, sizeof(quint8), QColor(0,255,0)));
......
......@@ -30,7 +30,7 @@ class KisYCbCrU8ColorSpace : public KisYCbCrBaseColorSpace<YCbCrU8Traits>
{
public:
KisYCbCrU8ColorSpace(KoColorSpaceRegistry * parent, KoColorProfile *p);
virtual bool willDegrade(ColorSpaceIndependence independence) const {
virtual bool willDegrade(ColorSpaceIndependence /*independence*/) const {
return false;
}
};
......@@ -41,6 +41,10 @@ public:
virtual QString id() const { return "YCbCrAU8"; }
virtual QString name() const { return i18n("YCBCR (8-bit integer/channel)"); }
virtual bool profileIsCompatible(KoColorProfile* /*profile*/) const
{
return false;
}
/**
* lcms colorspace type definition.
*/
......
......@@ -307,15 +307,17 @@ KisImageBuilder_Result KisPNGConverter::buildImage(QIODevice* iod)
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
return KisImageBuilder_RESULT_UNSUPPORTED_COLORSPACE;
}
//TODO: two fixes : one tell the user about the problem and ask for a solution, and two once the kocolorspace include KoColorTransformation, use that instead of hacking a lcms transformation
// Create the cmsTransform if needed
cmsHTRANSFORM transform = 0;
#if 0
if(profile && !profile->isSuitableForOutput())
{
transform = cmsCreateTransform(profile->profile(), cs->colorSpaceType(),
cs->profile()->profile() , cs->colorSpaceType(),
INTENT_PERCEPTUAL, 0);
}
#endif
// Read comments/texts...
png_text* text_ptr;
......
......@@ -37,8 +37,6 @@ struct KoColorSpace::Private {
KoConvolutionOp* convolutionOp;
QThreadStorage< QVector<quint8>* > conversionCache;
DWORD cmType; // The colorspace type as defined by littlecms
icColorSpaceSignature colorSpaceSignature; // The colorspace signature as defined in icm/icc files
};
KoColorSpace::KoColorSpace()
......@@ -46,7 +44,7 @@ KoColorSpace::KoColorSpace()
{
}
KoColorSpace::KoColorSpace(const QString &id, const QString &name, KoColorSpaceRegistry * parent, KoMixColorsOp* mixColorsOp, KoConvolutionOp* convolutionOp, DWORD cmType, icColorSpaceSignature colorSpaceSignature )
KoColorSpace::KoColorSpace(const QString &id, const QString &name, KoColorSpaceRegistry * parent, KoMixColorsOp* mixColorsOp, KoConvolutionOp* convolutionOp )
: d (new Private())
{
d->id = id;
......@@ -54,8 +52,6 @@ KoColorSpace::KoColorSpace(const QString &id, const QString &name, KoColorSpaceR
d->parent = parent;
d->mixColorsOp = mixColorsOp;
d->convolutionOp = convolutionOp;
d->cmType = cmType;
d->colorSpaceSignature = colorSpaceSignature;
}
KoColorSpace::~KoColorSpace()
......@@ -69,9 +65,6 @@ QString KoColorSpace::id() const {return d->id;}
QString KoColorSpace::name() const {return d->name;}
quint32 KoColorSpace::colorSpaceType() const { return d->cmType; }
icColorSpaceSignature KoColorSpace::colorSpaceSignature() const { return d->colorSpaceSignature; }
QList<KoChannelInfo *> KoColorSpace::channels() const
{
return d->channels;
......
......@@ -133,7 +133,7 @@ protected:
public:
/// Should be called by real color spaces
KoColorSpace(const QString &id, const QString &name, KoColorSpaceRegistry * parent, KoMixColorsOp* mixColorsOp, KoConvolutionOp* convolutionOp, DWORD cmType, icColorSpaceSignature colorSpaceSignature );
KoColorSpace(const QString &id, const QString &name, KoColorSpaceRegistry * parent, KoMixColorsOp* mixColorsOp, KoConvolutionOp* convolutionOp );
virtual ~KoColorSpace();
virtual bool operator==(const KoColorSpace& rhs) const {
......@@ -237,12 +237,7 @@ public:
*/
virtual QString name() const;
/**
* lcms colorspace type definition.
*/
virtual quint32 colorSpaceType() const;
virtual icColorSpaceSignature colorSpaceSignature() const;
virtual bool profileIsCompatible(KoColorProfile* profile) const =0;
/**
* If false, images in this colorspace will degrade considerably by
......@@ -368,7 +363,7 @@ public:
* @param dst the destination data
* @param nPixels the number of source pixels
*/
virtual void toLabA16(const quint8 * src, quint8 * dst, const quint32 nPixels) const = 0;
virtual void toLabA16(const quint8 * src, quint8 * dst, quint32 nPixels) const = 0;
/**
* Convert the specified data from Lab. to this colorspace. All colorspaces are
......@@ -378,7 +373,7 @@ public:
* @param dst the destination data
* @param nPixels the number of pixels in the array
*/
virtual void fromLabA16(const quint8 * src, quint8 * dst, const quint32 nPixels) const = 0;
virtual void fromLabA16(const quint8 * src, quint8 * dst, quint32 nPixels) const = 0;
/**
* Convert the specified data to Rgb 16 bits. All colorspaces are guaranteed to support this
......@@ -387,7 +382,7 @@ public:
* @param dst the destination data
* @param nPixels the number of source pixels
*/
virtual void toRgbA16(const quint8 * src, quint8 * dst, const quint32 nPixels) const =0;
virtual void toRgbA16(const quint8 * src, quint8 * dst, quint32 nPixels) const =0;
/**
* Convert the specified data from Rgb 16 bits. to this colorspace. All colorspaces are
......@@ -397,7 +392,7 @@ public:
* @param dst the destination data
* @param nPixels the number of pixels in the array
*/
virtual void fromRgbA16(const quint8 * src, quint8 * dst, const quint32 nPixels) const =0;
virtual void fromRgbA16(const quint8 * src, quint8 * dst, quint32 nPixels) const =0;
/**
* Convert a byte array of srcLen pixels *src to the specified color space
......@@ -635,13 +630,7 @@ public:
*/
virtual QString name() const = 0;
/**
* lcms colorspace type definition.
*/
virtual quint32 colorSpaceType() = 0;
virtual icColorSpaceSignature colorSpaceSignature() = 0;
virtual bool profileIsCompatible(KoColorProfile* profile) const =0;
virtual KoColorSpace *createColorSpace(KoColorSpaceRegistry * parent, KoColorProfile *) = 0;
/**
......
......@@ -236,9 +236,8 @@ namespace {
template<class _CSTraits>
class KoColorSpaceAbstract : public KoColorSpace {
public:
KoColorSpaceAbstract(const QString &id, const QString &name, KoColorSpaceRegistry * parent, DWORD cmType,
icColorSpaceSignature colorSpaceSignature ) :
KoColorSpace(id, name, parent, new KoMixColorsOpImpl< _CSTraits>(), new KoConvolutionOpImpl< _CSTraits>(), cmType, colorSpaceSignature)
KoColorSpaceAbstract(const QString &id, const QString &name, KoColorSpaceRegistry * parent ) :
KoColorSpace(id, name, parent, new KoMixColorsOpImpl< _CSTraits>(), new KoConvolutionOpImpl< _CSTraits>())
{
this->addCompositeOp( new CompositeCopy( this ) );
}
......
......@@ -175,7 +175,9 @@ QList<KoColorProfile *> KoColorSpaceRegistry::profilesFor(KoColorSpaceFactory *
QMap<QString, KoColorProfile * >::Iterator it;
for (it = d->profileMap.begin(); it != d->profileMap.end(); ++it) {
KoColorProfile * profile = it.value();
if (profile->colorSpaceSignature() == csf->colorSpaceSignature()) {
if(csf->profileIsCompatible(profile))
{
// if (profile->colorSpaceSignature() == csf->colorSpaceSignature()) {
profiles.push_back(profile);
}
}
......
......@@ -33,8 +33,7 @@
template<class _CSTraits, class _fallback_>
class KoIncompleteColorSpace : public KoColorSpaceAbstract<_CSTraits> {
protected:
KoIncompleteColorSpace(const QString &id, const QString &name, KoColorSpaceRegistry * parent, quint32 type,
icColorSpaceSignature colorSpaceSignature) : KoColorSpaceAbstract<_CSTraits>(id, name, parent, type, colorSpaceSignature), m_fallBackColorSpace(_fallback_::createColorSpace())
KoIncompleteColorSpace(const QString &id, const QString &name, KoColorSpaceRegistry * parent) : KoColorSpaceAbstract<_CSTraits>(id, name, parent), m_fallBackColorSpace(_fallback_::createColorSpace())
{
m_qcolordata = new quint16[4];
m_convertionCache.resize( m_fallBackColorSpace->pixelSize() );
......@@ -104,20 +103,20 @@ class KoIncompleteColorSpace : public KoColorSpaceAbstract<_CSTraits> {
}
return img;
}
virtual void toLabA16(const quint8 * src, quint8 * dst, const quint32 nPixels) const
virtual void toLabA16(const quint8 * src, quint8 * dst, quint32 nPixels) const
{
_fallback_::toLabA16( this, m_fallBackColorSpace, src, dst, m_convertionCache, nPixels);
}
virtual void fromLabA16(const quint8 * src, quint8 * dst, const quint32 nPixels) const
virtual void fromLabA16(const quint8 * src, quint8 * dst, quint32 nPixels) const
{
_fallback_::fromLabA16(this, m_fallBackColorSpace, src, dst, m_convertionCache, nPixels);
}
virtual void fromRgbA16(const quint8 * src, quint8 * dst, const quint32 nPixels) const
virtual void fromRgbA16(const quint8 * src, quint8 * dst, quint32 nPixels) const
{
_fallback_::fromRgbA16(this, m_fallBackColorSpace, src, dst, m_convertionCache, nPixels);
}
virtual void toRgbA16(const quint8 * src, quint8 * dst, const quint32 nPixels) const
virtual void toRgbA16(const quint8 * src, quint8 * dst, quint32 nPixels) const
{
_fallback_::toRgbA16(this, m_fallBackColorSpace, src, dst, m_convertionCache, nPixels);
}
......
......@@ -96,38 +96,65 @@ struct KoLcmsDarkenTransformation : public KoColorTransformation
double m_compensation;
};
class KoLcmsInfo {
struct Private {
DWORD cmType; // The colorspace type as defined by littlecms
icColorSpaceSignature colorSpaceSignature; // The colorspace signature as defined in icm/icc files
};
public:
KoLcmsInfo(DWORD cmType, icColorSpaceSignature colorSpaceSignature) : d(new Private)
{
d->cmType = cmType;
d->colorSpaceSignature = colorSpaceSignature;
}
virtual ~KoLcmsInfo()
{
delete d;
}
virtual quint32 colorSpaceType() const
{
return d->cmType;
}
virtual icColorSpaceSignature colorSpaceSignature() const
{
return d->colorSpaceSignature;
}
private:
Private* const d;
};
/**
* This is the base class for all colorspaces that are based on the lcms library, for instance
* RGB 8bits and 16bits, CMYK 8bits and 16bits, LAB...
*/
template<class _CSTraits>
class KoLcmsColorSpace : public KoColorSpaceAbstract<_CSTraits> {
class KoLcmsColorSpace : public KoColorSpaceAbstract<_CSTraits>, public KoLcmsInfo {
struct Private {
mutable quint8 * qcolordata; // A small buffer for conversion from and to qcolor.
cmsHTRANSFORM defaultToRGB; // Default transform to 8 bit sRGB
cmsHTRANSFORM defaultFromRGB; // Default transform from 8 bit sRGB
cmsHTRANSFORM defaultToRGB16; // Default transform to 16 bit sRGB
cmsHTRANSFORM defaultFromRGB16; // Default transform from 16 bit sRGB
mutable cmsHPROFILE lastRGBProfile; // Last used profile to transform to/from RGB
mutable cmsHTRANSFORM lastToRGB; // Last used transform to transform to RGB
mutable cmsHTRANSFORM lastFromRGB; // Last used transform to transform from RGB
cmsHTRANSFORM defaultToLab;
cmsHTRANSFORM defaultFromLab;
KoColorProfile * profile;
mutable const KoColorSpace *lastUsedDstColorSpace;
mutable cmsHTRANSFORM lastUsedTransform;
// cmsHTRANSFORM is a void *, so this should work.
typedef QMap<const KoColorSpace *, cmsHTRANSFORM> TransformMap;
mutable TransformMap transforms; // Cache for existing transforms
mutable quint8 * qcolordata; // A small buffer for conversion from and to qcolor.
cmsHTRANSFORM defaultToRGB; // Default transform to 8 bit sRGB
cmsHTRANSFORM defaultFromRGB; // Default transform from 8 bit sRGB
cmsHTRANSFORM defaultToRGB16; // Default transform to 16 bit sRGB
cmsHTRANSFORM defaultFromRGB16; // Default transform from 16 bit sRGB
mutable cmsHPROFILE lastRGBProfile; // Last used profile to transform to/from RGB
mutable cmsHTRANSFORM lastToRGB; // Last used transform to transform to RGB
mutable cmsHTRANSFORM lastFromRGB; // Last used transform to transform from RGB
cmsHTRANSFORM defaultToLab;
cmsHTRANSFORM defaultFromLab;
KoColorProfile * profile;
mutable const KoColorSpace *lastUsedDstColorSpace;
mutable cmsHTRANSFORM lastUsedTransform;
// cmsHTRANSFORM is a void *, so this should work.
typedef QMap<const KoColorSpace *, cmsHTRANSFORM> TransformMap;
mutable TransformMap transforms; // Cache for existing transforms
};
protected:
KoLcmsColorSpace(const QString &id, const QString &name, KoColorSpaceRegistry * parent, DWORD cmType,
icColorSpaceSignature colorSpaceSignature,
KoColorProfile *p) : KoColorSpaceAbstract<_CSTraits>(id, name, parent, cmType, colorSpaceSignature), d( new Private())
KoColorProfile *p) : KoColorSpaceAbstract<_CSTraits>(id, name, parent), KoLcmsInfo( cmType, colorSpaceSignature), d( new Private())
{
d->profile = p;
......@@ -189,6 +216,11 @@ class KoLcmsColorSpace : public KoColorSpaceAbstract<_CSTraits> {
virtual bool hasHighDynamicRange() const { return false; }
virtual KoColorProfile * profile() const { return d->profile; }
virtual bool profileIsCompatible(KoColorProfile* profile) const
{
return profile->colorSpaceSignature() == colorSpaceSignature();
}
virtual void fromQColor(const QColor& color, quint8 *dst, KoColorProfile * profile=0) const
{
d->qcolordata[2] = color.red();
......@@ -263,7 +295,7 @@ class KoLcmsColorSpace : public KoColorSpaceAbstract<_CSTraits> {
return img;
}
virtual void toLabA16(const quint8 * src, quint8 * dst, const quint32 nPixels) const
virtual void toLabA16(const quint8 * src, quint8 * dst, quint32 nPixels) const
{
if ( d->defaultToLab == 0 ) return;
......@@ -276,7 +308,7 @@ class KoLcmsColorSpace : public KoColorSpaceAbstract<_CSTraits> {