Commit 58a6088e authored by Cyrille Berger's avatar Cyrille Berger

make color serializable/unserializable following create's specification

svn path=/trunk/koffice/; revision=743791
parent 2f3cc747
......@@ -16,6 +16,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QDomElement>
#include <kdebug.h>
#include <klocale.h>
......@@ -43,3 +45,20 @@ KoColorSpace* KisGrayU16ColorSpace::clone() const
{
return new KisGrayU16ColorSpace(profile()->clone());
}
void KisGrayU16ColorSpace::colorToXML( const quint8* pixel, QDomDocument& doc, QDomElement& colorElt) const
{
const GrayU16Traits::channels_type* p = reinterpret_cast<const GrayU16Traits::channels_type*>( pixel );
QDomElement labElt = doc.createElement( "Gray" );
labElt.setAttribute("g", KoColorSpaceMaths< GrayU16Traits::channels_type, double>::scaleToA( p[0]) );
labElt.setAttribute("space", profile()->name() );
colorElt.appendChild( labElt );
}
void KisGrayU16ColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt)
{
GrayU16Traits::channels_type* p = reinterpret_cast<GrayU16Traits::channels_type*>( pixel );
p[0] = KoColorSpaceMaths< double, GrayU16Traits::channels_type >::scaleToA(elt.attribute("g").toDouble());
}
......@@ -35,6 +35,8 @@ class KRITA_GRAY_U16_EXPORT KisGrayU16ColorSpace : public KoLcmsColorSpace<GrayU
virtual KoID colorModelId() const { return GrayColorModelID; }
virtual KoID colorDepthId() const { return Integer16BitsColorDepthID; }
virtual KoColorSpace* clone() const;
virtual void colorToXML( const quint8* pixel, QDomDocument& doc, QDomElement& colorElt) const;
virtual void colorFromXML( quint8* pixel, const QDomElement& elt);
};
class KisGrayU16ColorSpaceFactory : public KoLcmsColorSpaceFactory
......
......@@ -16,6 +16,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QDomElement>
#include <kdebug.h>
#include <klocale.h>
......@@ -41,3 +43,20 @@ KoColorSpace* KisGrayColorSpace::clone() const
{
return new KisGrayColorSpace(profile()->clone());
}
void KisGrayColorSpace::colorToXML( const quint8* pixel, QDomDocument& doc, QDomElement& colorElt) const
{
const GrayU8Traits::channels_type* p = reinterpret_cast<const GrayU8Traits::channels_type*>( pixel );
QDomElement labElt = doc.createElement( "Gray" );
labElt.setAttribute("g", KoColorSpaceMaths< GrayU8Traits::channels_type, double>::scaleToA( p[0]) );
labElt.setAttribute("space", profile()->name() );
colorElt.appendChild( labElt );
}
void KisGrayColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt)
{
GrayU8Traits::channels_type* p = reinterpret_cast<GrayU8Traits::channels_type*>( pixel );
p[0] = KoColorSpaceMaths< double, GrayU8Traits::channels_type >::scaleToA(elt.attribute("g").toDouble());
}
......@@ -35,6 +35,8 @@ class KRITA_GRAY_U8_EXPORT KisGrayColorSpace : public KoLcmsColorSpace<GrayU8Tra
virtual KoID colorModelId() const { return GrayColorModelID; }
virtual KoID colorDepthId() const { return Integer8BitsColorDepthID; }
virtual KoColorSpace* clone() const;
virtual void colorToXML( const quint8* pixel, QDomDocument& doc, QDomElement& colorElt) const;
virtual void colorFromXML( quint8* pixel, const QDomElement& elt);
};
class KisGrayColorSpaceFactory : public KoLcmsColorSpaceFactory
......
......@@ -19,6 +19,8 @@
#ifndef KIS_RGB_FLOAT_HDR_COLORSPACE_H_
#define KIS_RGB_FLOAT_HDR_COLORSPACE_H_
#include <QDomElement>
#include <klocale.h>
#include <math.h>
......@@ -230,6 +232,27 @@ class KisRgbFloatHDRColorSpace : public KoIncompleteColorSpace<_CSTraits>
src += this->pixelSize();
}
}
void colorToXML( const quint8* pixel, QDomDocument& doc, QDomElement& colorElt) const
{
const typename _CSTraits::Pixel* p = reinterpret_cast<const typename _CSTraits::Pixel*>( pixel );
QDomElement labElt = doc.createElement( "RGB" );
labElt.setAttribute("r", KoColorSpaceMaths< typename _CSTraits::channels_type, double>::scaleToA( p->red) );
labElt.setAttribute("g", KoColorSpaceMaths< typename _CSTraits::channels_type, double>::scaleToA( p->green) );
labElt.setAttribute("b", KoColorSpaceMaths< typename _CSTraits::channels_type, double>::scaleToA( p->blue) );
labElt.setAttribute("space", profile()->name() );
colorElt.appendChild( labElt );
}
void colorFromXML( quint8* pixel, const QDomElement& elt)
{
typename _CSTraits::Pixel* p = reinterpret_cast<typename _CSTraits::Pixel*>( pixel );
p->red = KoColorSpaceMaths< double, typename _CSTraits::channels_type >::scaleToA(elt.attribute("r").toDouble());
p->green = KoColorSpaceMaths< double, typename _CSTraits::channels_type >::scaleToA(elt.attribute("g").toDouble());
p->blue = KoColorSpaceMaths< double, typename _CSTraits::channels_type >::scaleToA(elt.attribute("b").toDouble());
}
private:
struct Pixel {
typename _CSTraits::channels_type blue;
......
......@@ -20,6 +20,8 @@
#ifndef _KIS_XYZ_HDR_COLORSPACE_H_
#define _KIS_XYZ_HDR_COLORSPACE_H_
#include <QDomElement>
#include <math.h>
#include "KoIncompleteColorSpace.h"
......@@ -75,6 +77,24 @@ class KisXyzFloatHDRColorSpace : public KoIncompleteColorSpace<_CSTraits>
addCompositeOp( new KoCompositeOpErase<_CSTraits>( this ) );
}
virtual void colorToXML( const quint8* pixel, QDomDocument& doc, QDomElement& colorElt) const
{
const typename _CSTraits::Pixel* p = reinterpret_cast<const typename _CSTraits::Pixel*>( pixel );
QDomElement labElt = doc.createElement( "XYZ" );
labElt.setAttribute("x", KoColorSpaceMaths< typename _CSTraits::channels_type, double>::scaleToA( p->X) );
labElt.setAttribute("y", KoColorSpaceMaths< typename _CSTraits::channels_type, double>::scaleToA( p->Y) );
labElt.setAttribute("z", KoColorSpaceMaths< typename _CSTraits::channels_type, double>::scaleToA( p->Z) );
labElt.setAttribute("space", "xyz" );
colorElt.appendChild( labElt );
}
virtual void colorFromXML( quint8* pixel, const QDomElement& elt)
{
typename _CSTraits::Pixel* p = reinterpret_cast<typename _CSTraits::Pixel*>( pixel );
p->X = KoColorSpaceMaths< double, typename _CSTraits::channels_type >::scaleToA(elt.attribute("x").toDouble());
p->Y = KoColorSpaceMaths< double, typename _CSTraits::channels_type >::scaleToA(elt.attribute("y").toDouble());
p->Z = KoColorSpaceMaths< double, typename _CSTraits::channels_type >::scaleToA(elt.attribute("z").toDouble());
}
public:
virtual bool profileIsCompatible(const KoColorProfile* profile) const
{
......
......@@ -19,6 +19,8 @@
#include "kis_xyz_u16_colorspace.h"
#include <QDomElement>
#include <kdebug.h>
#include <klocale.h>
......@@ -57,3 +59,22 @@ KoColorSpace* KisXyzU16ColorSpace::clone() const
return new KisXyzU16ColorSpace( profile()->clone());
}
void KisXyzU16ColorSpace::colorToXML( const quint8* pixel, QDomDocument& doc, QDomElement& colorElt) const
{
const XyzU16Traits::Pixel* p = reinterpret_cast<const XyzU16Traits::Pixel*>( pixel );
QDomElement labElt = doc.createElement( "XYZ" );
labElt.setAttribute("x", KoColorSpaceMaths< XyzU16Traits::channels_type, double>::scaleToA( p->X) );
labElt.setAttribute("y", KoColorSpaceMaths< XyzU16Traits::channels_type, double>::scaleToA( p->Y) );
labElt.setAttribute("z", KoColorSpaceMaths< XyzU16Traits::channels_type, double>::scaleToA( p->Z) );
labElt.setAttribute("space", profile()->name() );
colorElt.appendChild( labElt );
}
void KisXyzU16ColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt)
{
XyzU16Traits::Pixel* p = reinterpret_cast<XyzU16Traits::Pixel*>( pixel );
p->X = KoColorSpaceMaths< double, XyzU16Traits::channels_type >::scaleToA(elt.attribute("x").toDouble());
p->Y = KoColorSpaceMaths< double, XyzU16Traits::channels_type >::scaleToA(elt.attribute("y").toDouble());
p->Z = KoColorSpaceMaths< double, XyzU16Traits::channels_type >::scaleToA(elt.attribute("z").toDouble());
}
......@@ -36,6 +36,8 @@ class PIGMENT_XYZ_U16_EXPORT KisXyzU16ColorSpace : public KoLcmsColorSpace<XyzU1
virtual KoID colorModelId() const { return XYZAColorModelID; }
virtual KoID colorDepthId() const { return Integer16BitsColorDepthID; }
virtual KoColorSpace* clone() const;
virtual void colorToXML( const quint8* pixel, QDomDocument& doc, QDomElement& colorElt) const;
virtual void colorFromXML( quint8* pixel, const QDomElement& elt);
};
#define TYPE_XYZA_16 (COLORSPACE_SH(PT_XYZ)|CHANNELS_SH(3)|BYTES_SH(2)|EXTRA_SH(1))
......
......@@ -17,6 +17,8 @@
#ifndef _KIS_YCBCR_BASE_COLORSPACE_H_
#define _KIS_YCBCR_BASE_COLORSPACE_H_
#include <QDomElement>
#include "klocale.h"
#include <KoIncompleteColorSpace.h>
#include <KoColorSpaceTraits.h>
......@@ -83,6 +85,25 @@ class KisYCbCrBaseColorSpace : public KoIncompleteColorSpace<_CSTraits>
NATIVE_TO_UINT8(_CSTraits::computeBlue( src->Y, src->Cb, src->Cr) ) );
*opacity = NATIVE_TO_UINT8(src->alpha);
}
virtual void colorToXML( const quint8* pixel, QDomDocument& doc, QDomElement& colorElt) const
{
const typename _CSTraits::Pixel* p = reinterpret_cast<const typename _CSTraits::Pixel*>( pixel );
QDomElement labElt = doc.createElement( "YCbCr" );
labElt.setAttribute("Y", KoColorSpaceMaths< typename _CSTraits::channels_type, double>::scaleToA( p->Y) );
labElt.setAttribute("Cb", KoColorSpaceMaths< typename _CSTraits::channels_type, double>::scaleToA( p->Cb) );
labElt.setAttribute("Cr", KoColorSpaceMaths< typename _CSTraits::channels_type, double>::scaleToA( p->Cr) );
labElt.setAttribute("space", "ycbcr" );
colorElt.appendChild( labElt );
}
virtual void colorFromXML( quint8* pixel, const QDomElement& elt)
{
typename _CSTraits::Pixel* p = reinterpret_cast<typename _CSTraits::Pixel*>( pixel );
p->Y = KoColorSpaceMaths< double, typename _CSTraits::channels_type >::scaleToA(elt.attribute("Y").toDouble());
p->Cb = KoColorSpaceMaths< double, typename _CSTraits::channels_type >::scaleToA(elt.attribute("Cb").toDouble());
p->Cr = KoColorSpaceMaths< double, typename _CSTraits::channels_type >::scaleToA(elt.attribute("Cr").toDouble());
}
private:
};
......
......@@ -238,6 +238,8 @@ class KisGenericColorSpace : public KoColorSpace {
qint32 /*cols*/,
const KoCompositeOp& /*op*/) { }
virtual void colorToXML( const quint8* , QDomDocument& , QDomElement& ) const{}
virtual void colorFromXML( quint8* , const QDomElement& ){}
};
#endif // KIS_COLORSPACE_H_
......@@ -96,6 +96,8 @@ private: // This is a singleton
KisPainterlyOverlayColorSpace operator=(const KisPainterlyOverlayColorSpace&);
public:
void colorToXML( const quint8* , QDomDocument& , QDomElement& ) const{}
void colorFromXML( quint8* , const QDomElement& ){}
bool willDegrade(ColorSpaceIndependence independence) const
{
......
......@@ -44,6 +44,7 @@ public:
UINT32, ///< use this for an unsigned integer 21bits channel
FLOAT16, ///< use this for a float 16bits channel
FLOAT32, ///< use this for a float 32bits channel
FLOAT64, ///< use this for a float 64bits channel
INT8, ///< use this for an integer 8bits channel
INT16, ///< use this for an integer 16bits channel
OTHER ///< Use this if the channel is neither an integer or a float
......
......@@ -19,12 +19,16 @@
*/
#include <QColor>
#include <QDomDocument>
#include "kdebug.h"
#include "KoColor.h"
#include "KoColorProfile.h"
#include "KoColorSpace.h"
#include "KoColorSpaceRegistry.h"
class KoColor::Private {
public:
Private() : data(0), colorSpace(0) {}
......@@ -253,3 +257,12 @@ const KoColorSpace * KoColor::colorSpace() const {
return d->colorSpace;
}
void KoColor::toXML(QDomDocument& doc, QDomElement& colorElt) const
{
d->colorSpace->colorToXML( d->data, doc, colorElt);
}
KoColor KoColor::fromXML(const QDomElement& elt, QString bitDepthId, QHash<QString, QString> aliases)
{
return KoColor();
}
......@@ -24,6 +24,9 @@
#include <QMetaType>
#include <pigment_export.h>
class QDomDocument;
class QDomElement;
class KoColorProfile;
class KoColorSpace;
......@@ -114,6 +117,35 @@ public:
*/
const quint8 * data() const;
/**
* Serialize this color following Create's swatch color specification available
* at http://create.freedesktop.org/wiki/index.php/Swatches_-_colour_file_format
*
* This function doesn't create the <color /> element but rather the <CMYK />,
* <sRGB />, <RGB /> ... elements. It is assumed that colorElt is the <color />
* element.
*
* @param colorElt root element for the serialization, it is assumed that this
* element is <color />
* @param doc is the document containing colorElt
*/
void toXML(QDomDocument& doc, QDomElement& colorElt) const;
/**
* Unserialize a color following Create's swatch color specification available
* at http://create.freedesktop.org/wiki/index.php/Swatches_-_colour_file_format
*
* @param elt the element to unserialize (<CMYK />, <sRGB />, <RGB />)
* @param bitDepthId the bit depth is unspecified by the spec, this allow to select
* a preferred bit depth for creating the KoColor object (if that
* bit depth isn't available, this function will randomly select
* an other bit depth)
* @param profileAliases alias between the profile name specified by the "space"
* attribute and the profile name used inside pigment
* @return the unserialize color, or an empty color object if the function failed
* to unserialize the color
*/
static KoColor fromXML(const QDomElement& elt, QString bitDepthId, QHash<QString, QString> aliases);
#ifndef NODEBUG
/// use kDebug calls to print internal info
void dump() const;
......
......@@ -35,6 +35,8 @@
#include <KoID.h>
#include <pigment_export.h>
class QDomDocument;
class QDomElement;
class KoCompositeOp;
class KoColorProfile;
class KoColorTransformation;
......@@ -625,6 +627,30 @@ public:
const QString& op) const;
/**
* Serialize this color following Create's swatch color specification available
* at http://create.freedesktop.org/wiki/index.php/Swatches_-_colour_file_format
*
* This function doesn't create the <color /> element but rather the <CMYK />,
* <sRGB />, <RGB /> ... elements. It is assumed that colorElt is the <color />
* element.
*
* @param pixel buffer to serialized
* @param colorElt root element for the serialization, it is assumed that this
* element is <color />
* @param doc is the document containing colorElt
*/
virtual void colorToXML( const quint8* pixel, QDomDocument& doc, QDomElement& colorElt) const = 0;
/**
* Unserialize a color following Create's swatch color specification available
* at http://create.freedesktop.org/wiki/index.php/Swatches_-_colour_file_format
*
* @param pixel buffer where the color will be unserialized
* @param elt the element to unserialize (<CMYK />, <sRGB />, <RGB />)
* @return the unserialize color, or an empty color object if the function failed
* to unserialize the color
*/
virtual void colorFromXML( quint8* pixel, const QDomElement& elt) = 0;
/**
* The backgroundfilters will be run periodically on the newly
......
......@@ -39,6 +39,14 @@ const float KoColorSpaceMathsTraits<float>::min = -FLT_MAX;
const float KoColorSpaceMathsTraits<float>::epsilon = FLT_EPSILON;
const KoChannelInfo::enumChannelValueType KoColorSpaceMathsTraits<float>::channelValueType = KoChannelInfo::FLOAT32;
const double KoColorSpaceMathsTraits<double>::zeroValue = 0.0;
const double KoColorSpaceMathsTraits<double>::unitValue = 1.0;
const double KoColorSpaceMathsTraits<double>::max = FLT_MAX;
const double KoColorSpaceMathsTraits<double>::min = -FLT_MAX;
const double KoColorSpaceMathsTraits<double>::epsilon = FLT_EPSILON;
const KoChannelInfo::enumChannelValueType KoColorSpaceMathsTraits<double>::channelValueType = KoChannelInfo::FLOAT64;
const KoChannelInfo::enumChannelValueType KoColorSpaceMathsTraits<quint8>::channelValueType = KoChannelInfo::UINT8;
const KoChannelInfo::enumChannelValueType KoColorSpaceMathsTraits<quint16>::channelValueType = KoChannelInfo::UINT16;
const KoChannelInfo::enumChannelValueType KoColorSpaceMathsTraits<qint16>::channelValueType = KoChannelInfo::INT16;
......
/*
* Copyright (c) 2006 Cyrille Berger <cberger@cberger.bet
* Copyright (c) 2006-2007 Cyrille Berger <cberger@cberger.bet
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -130,6 +130,19 @@ class PIGMENTCMS_EXPORT KoColorSpaceMathsTraits<float> {
static const KoChannelInfo::enumChannelValueType channelValueType;
};
template<>
class PIGMENTCMS_EXPORT KoColorSpaceMathsTraits<double> {
public:
typedef double compositetype;
static const double zeroValue;
static const double unitValue;
static const double max;
static const double min;
static const double epsilon;
static const qint8 bits = 64;
static const KoChannelInfo::enumChannelValueType channelValueType;
};
/**
* This class defines some elementary operations used by various color
* space. It's intended to be generic, but some specialization exists
......@@ -179,20 +192,46 @@ class KoColorSpaceMaths {
};
//------------------------------ double specialization ------------------------------//
template<>
inline quint8 KoColorSpaceMaths<float,quint8>::scaleToA(float a)
inline quint8 KoColorSpaceMaths<double,quint8>::scaleToA(double a)
{
float v = a * 255;
double v = a * 255;
return (quint8)(CLAMP(v, 0, 255));
}
template<>
inline float KoColorSpaceMaths<quint8,float>::scaleToA(quint8 a)
inline double KoColorSpaceMaths<quint8,double>::scaleToA(quint8 a)
{
return a * ( 1.0 / 255.0 );
}
template<>
inline quint16 KoColorSpaceMaths<double, quint16>::scaleToA(double a)
{
double v = a * 0xFFFF;
return (quint16)(CLAMP(v, 0, 0xFFFF));
}
template<>
inline double KoColorSpaceMaths<quint16, double>::scaleToA(quint16 a)
{
return a * ( 1.0 / 0xFFFF );
}
//------------------------------ half specialization ------------------------------//
template<>
inline float KoColorSpaceMaths<double, float>::scaleToA(double a)
{
return (float)a;
}
template<>
inline double KoColorSpaceMaths<float, double>::scaleToA(float a)
{
return a;
}
template<>
inline quint16 KoColorSpaceMaths<float,quint16>::scaleToA(float a)
{
......@@ -206,6 +245,19 @@ inline float KoColorSpaceMaths<quint16,float>::scaleToA(quint16 a)
return a * ( 1.0 / 0xFFFF );
}
template<>
inline quint8 KoColorSpaceMaths<float,quint8>::scaleToA(float a)
{
float v = a * 255;
return (quint8)(CLAMP(v, 0, 255));
}
template<>
inline float KoColorSpaceMaths<quint8,float>::scaleToA(quint8 a)
{
return a * ( 1.0 / 255.0 );
}
template<>
inline float KoColorSpaceMaths<float>::blend(float a, float b, float alpha)
{
......@@ -216,6 +268,18 @@ inline float KoColorSpaceMaths<float>::blend(float a, float b, float alpha)
#ifdef HAVE_OPENEXR
template<>
inline half KoColorSpaceMaths<double, half>::scaleToA(double a)
{
return (half)a;
}
template<>
inline double KoColorSpaceMaths<half, double>::scaleToA(half a)
{
return a;
}
template<>
inline float KoColorSpaceMaths<half,float>::scaleToA(half a)
{
......
......@@ -108,7 +108,7 @@ struct KoColorSpaceTrait {
*/
template<typename _channels_type_>
struct KoLabTraits : public KoColorSpaceTrait<quint16, 4,3> {
typedef _channels_type_ channels_type; // /me wonders why gcc refuses to build without that line ?, which is pretty annoying as it's less clean
typedef _channels_type_ channels_type;
static const qint32 L_pos = 0;
static const qint32 a_pos = 1;
static const qint32 b_pos = 2;
......@@ -170,7 +170,7 @@ struct KoLabU16Traits : public KoLabTraits<quint16> {
*/
template<typename _channels_type_>
struct KoRgbTraits : public KoColorSpaceTrait<_channels_type_, 4,3> {
typedef _channels_type_ channels_type; // /me wonders why gcc refuses to build without that line ?, which is pretty annoying as it's less clean
typedef _channels_type_ channels_type;
typedef KoColorSpaceTrait<_channels_type_, 4,3> parent;
static const qint32 red_pos = 2;
static const qint32 green_pos = 1;
......@@ -227,15 +227,15 @@ struct KoRgbTraits : public KoColorSpaceTrait<_channels_type_, 4,3> {
struct KoRgbU16Traits : public KoRgbTraits<quint16> {
};
/** Base class for rgb traits, it provides some convenient functions to
/** Base class for XYZ traits, it provides some convenient functions to
* access XYZ channels through an explicit API.
*/
template<typename _channels_type_>
struct KoXyzTraits : public KoColorSpaceTrait<_channels_type_, 4,3> {
typedef _channels_type_ channels_type; // /me wonders why gcc refuses to build without that line ?, which is pretty annoying as it's less clean
static const qint32 x_pos = 2;
typedef _channels_type_ channels_type;
static const qint32 x_pos = 0;
static const qint32 y_pos = 1;
static const qint32 z_pos = 0;
static const qint32 z_pos = 2;
/**
* An RGB pixel
......@@ -248,5 +248,30 @@ struct KoXyzTraits : public KoColorSpaceTrait<_channels_type_, 4,3> {
};
};
/** Base class for CMYK traits, it provides some convenient functions to
* access CMYK channels through an explicit API.
*/
template<typename _channels_type_>
struct KoCmykTraits : public KoColorSpaceTrait<_channels_type_, 5,4> {
typedef _channels_type_ channels_type;
static const qint32 c_pos = 2;
static const qint32 m_pos = 1;
static const qint32 y_pos = 0;
static const qint32 k_pos = 0;
/**
* An RGB pixel
*/
struct Pixel {
channels_type cyan;
channels_type magenta;
channels_type yellow;
channels_type black;
channels_type alpha;
};
};
#endif
......@@ -146,6 +146,14 @@ public:
{
kDebug() <<"Undefined operation in the alpha colorspace";
}
virtual void colorToXML( const quint8* , QDomDocument& , QDomElement& ) const
{
kDebug() <<"Undefined operation in the alpha colorspace";
}
virtual void colorFromXML( quint8* , const QDomElement& )
{
kDebug() <<"Undefined operation in the alpha colorspace";
}
public:
......
......@@ -19,6 +19,8 @@
#include "KoLabColorSpace.h"
#include <QDomElement>
#include <kdebug.h>
#include <klocale.h>
......@@ -84,3 +86,21 @@ QString KoLabColorSpace::colorSpaceId()
return QString("LABA");
}
void KoLabColorSpace::colorToXML( const quint8* pixel, QDomDocument& doc, QDomElement& colorElt) const
{
const KoLabU16Traits::Pixel* p = reinterpret_cast<const KoLabU16Traits::Pixel*>( pixel );
QDomElement labElt = doc.createElement( "Lab" );
labElt.setAttribute("L", KoColorSpaceMaths< KoLabU16Traits::channels_type, double>::scaleToA( p->L) );
labElt.setAttribute("a", KoColorSpaceMaths< KoLabU16Traits::channels_type, double>::scaleToA( p->a) );
labElt.setAttribute("b", KoColorSpaceMaths< KoLabU16Traits::channels_type, double>::scaleToA( p->b) );
labElt.setAttribute("space", profile()->name() );
colorElt.appendChild( labElt );
}
void KoLabColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt)
{
KoLabU16Traits::Pixel* p = reinterpret_cast<KoLabU16Traits::Pixel*>( pixel );
p->L = KoColorSpaceMaths< double, KoLabU16Traits::channels_type >::scaleToA(elt.attribute("L").toDouble());
p->a = KoColorSpaceMaths< double, KoLabU16Traits::channels_type >::scaleToA(elt.attribute("a").toDouble());
p->b = KoColorSpaceMaths< double, KoLabU16Traits::channels_type >::scaleToA(elt.attribute("b").toDouble());
}
......@@ -40,6 +40,8 @@ class KoLabColorSpace : public KoLcmsColorSpace<KoLabU16Traits>
virtual KoID colorModelId() const { return LABAColorModelID; }
virtual KoID colorDepthId() const { return Integer16BitsColorDepthID; }
virtual KoColorSpace* clone() const;
virtual void colorToXML( const quint8* pixel, QDomDocument& doc, QDomElement& colorElt) const;
virtual void colorFromXML( quint8* pixel, const QDomElement& elt);
private:
static const quint32 CHANNEL_L = 0;
......
......@@ -19,6 +19,8 @@
#include "KoRgbU16ColorSpace.h"
#include <QDomElement>
#include <kdebug.h>
#include <klocale.h>
......@@ -54,3 +56,22 @@ KoColorSpace* KoRgbU16ColorSpace::clone() const
return new KoRgbU16ColorSpace( profile()->clone());
}
void KoRgbU16ColorSpace::colorToXML( const quint8* pixel, QDomDocument& doc, QDomElement& colorElt) const
{
const KoRgbU16Traits::Pixel* p = reinterpret_cast<const KoRgbU16Traits::Pixel*>( pixel );
QDomElement labElt = doc.createElement( "RGB" );
labElt.setAttribute("r", KoColorSpaceMaths< KoRgbU16Traits::channels_type, double>::scaleToA( p->red) );
labElt.setAttribute("g", KoColorSpaceMaths< KoRgbU16Traits::channels_type, double>::scaleToA( p->green) );
labElt.setAttribute("b", KoColorSpaceMaths< KoRgbU16Traits::channels_type, double>::scaleToA( p->blue) );
labElt.setAttribute("space", profile()->name() );
colorElt.appendChild( labElt );
}
void KoRgbU16ColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt)