Commit 5200997a authored by Cyrille Berger's avatar Cyrille Berger

implement unserialization in KoColor

svn path=/trunk/koffice/; revision=743933
parent 67579ff3
......@@ -56,7 +56,7 @@ void KisGrayU16ColorSpace::colorToXML( const quint8* pixel, QDomDocument& doc, Q
colorElt.appendChild( labElt );
}
void KisGrayU16ColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt)
void KisGrayU16ColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt) const
{
GrayU16Traits::channels_type* p = reinterpret_cast<GrayU16Traits::channels_type*>( pixel );
p[0] = KoColorSpaceMaths< double, GrayU16Traits::channels_type >::scaleToA(elt.attribute("g").toDouble());
......
......@@ -36,7 +36,7 @@ class KRITA_GRAY_U16_EXPORT KisGrayU16ColorSpace : public KoLcmsColorSpace<GrayU
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);
virtual void colorFromXML( quint8* pixel, const QDomElement& elt) const;
};
class KisGrayU16ColorSpaceFactory : public KoLcmsColorSpaceFactory
......
......@@ -54,7 +54,7 @@ void KisGrayColorSpace::colorToXML( const quint8* pixel, QDomDocument& doc, QDom
colorElt.appendChild( labElt );
}
void KisGrayColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt)
void KisGrayColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt) const
{
GrayU8Traits::channels_type* p = reinterpret_cast<GrayU8Traits::channels_type*>( pixel );
p[0] = KoColorSpaceMaths< double, GrayU8Traits::channels_type >::scaleToA(elt.attribute("g").toDouble());
......
......@@ -36,7 +36,7 @@ class KRITA_GRAY_U8_EXPORT KisGrayColorSpace : public KoLcmsColorSpace<GrayU8Tra
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);
virtual void colorFromXML( quint8* pixel, const QDomElement& elt) const;
};
class KisGrayColorSpaceFactory : public KoLcmsColorSpaceFactory
......
......@@ -244,7 +244,7 @@ class KisRgbFloatHDRColorSpace : public KoIncompleteColorSpace<_CSTraits>
colorElt.appendChild( labElt );
}
void colorFromXML( quint8* pixel, const QDomElement& elt)
void colorFromXML( quint8* pixel, const QDomElement& elt) const
{
typename _CSTraits::Pixel* p = reinterpret_cast<typename _CSTraits::Pixel*>( pixel );
p->red = KoColorSpaceMaths< double, typename _CSTraits::channels_type >::scaleToA(elt.attribute("r").toDouble());
......
......@@ -88,7 +88,7 @@ class KisXyzFloatHDRColorSpace : public KoIncompleteColorSpace<_CSTraits>
colorElt.appendChild( labElt );
}
virtual void colorFromXML( quint8* pixel, const QDomElement& elt)
virtual void colorFromXML( quint8* pixel, const QDomElement& elt) const
{
typename _CSTraits::Pixel* p = reinterpret_cast<typename _CSTraits::Pixel*>( pixel );
p->X = KoColorSpaceMaths< double, typename _CSTraits::channels_type >::scaleToA(elt.attribute("x").toDouble());
......
......@@ -70,7 +70,7 @@ void KisXyzU16ColorSpace::colorToXML( const quint8* pixel, QDomDocument& doc, QD
colorElt.appendChild( labElt );
}
void KisXyzU16ColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt)
void KisXyzU16ColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt) const
{
XyzU16Traits::Pixel* p = reinterpret_cast<XyzU16Traits::Pixel*>( pixel );
p->X = KoColorSpaceMaths< double, XyzU16Traits::channels_type >::scaleToA(elt.attribute("x").toDouble());
......
......@@ -37,7 +37,7 @@ class PIGMENT_XYZ_U16_EXPORT KisXyzU16ColorSpace : public KoLcmsColorSpace<XyzU1
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);
virtual void colorFromXML( quint8* pixel, const QDomElement& elt) const;
};
#define TYPE_XYZA_16 (COLORSPACE_SH(PT_XYZ)|CHANNELS_SH(3)|BYTES_SH(2)|EXTRA_SH(1))
......
......@@ -96,7 +96,7 @@ class KisYCbCrBaseColorSpace : public KoIncompleteColorSpace<_CSTraits>
colorElt.appendChild( labElt );
}
virtual void colorFromXML( quint8* pixel, const QDomElement& elt)
virtual void colorFromXML( quint8* pixel, const QDomElement& elt) const
{
typename _CSTraits::Pixel* p = reinterpret_cast<typename _CSTraits::Pixel*>( pixel );
p->Y = KoColorSpaceMaths< double, typename _CSTraits::channels_type >::scaleToA(elt.attribute("Y").toDouble());
......
......@@ -239,7 +239,7 @@ class KisGenericColorSpace : public KoColorSpace {
const KoCompositeOp& /*op*/) { }
virtual void colorToXML( const quint8* , QDomDocument& , QDomElement& ) const{}
virtual void colorFromXML( quint8* , const QDomElement& ){}
virtual void colorFromXML( quint8* , const QDomElement& ) const{}
};
#endif // KIS_COLORSPACE_H_
......@@ -97,7 +97,7 @@ private: // This is a singleton
public:
void colorToXML( const quint8* , QDomDocument& , QDomElement& ) const{}
void colorFromXML( quint8* , const QDomElement& ){}
void colorFromXML( quint8* , const QDomElement& ) const{}
bool willDegrade(ColorSpaceIndependence independence) const
{
......
......@@ -23,6 +23,7 @@
#include "kdebug.h"
#include "KoColor.h"
#include "KoColorModelStandardIds.h"
#include "KoColorProfile.h"
#include "KoColorSpace.h"
#include "KoColorSpaceRegistry.h"
......@@ -264,5 +265,48 @@ void KoColor::toXML(QDomDocument& doc, QDomElement& colorElt) const
KoColor KoColor::fromXML(const QDomElement& elt, QString bitDepthId, QHash<QString, QString> aliases)
{
return KoColor();
QString modelId;
if(elt.tagName() == "CMYK")
{
modelId = CMYKAColorModelID.id();
} else if( elt.tagName() == "RGB") {
modelId = RGBAColorModelID.id();
} else if( elt.tagName() == "sRGB") {
modelId = RGBAColorModelID.id();
} else if( elt.tagName() == "Lab") {
modelId = LABAColorModelID.id();
} else if( elt.tagName() == "XYZ") {
modelId = XYZAColorModelID.id();
} else if( elt.tagName() == "Gray") {
modelId = GrayAColorModelID.id();
} else if( elt.tagName() == "YCbCr") {
modelId = YCbCrAColorModelID.id();
}
QString profileName;
if( elt.tagName() != "sRGB")
{
profileName = elt.attribute("space","");
if( aliases.contains(profileName))
{
profileName = aliases.value(profileName);
}
}
QString csId = KoColorSpaceRegistry::instance()->colorSpaceId(modelId, bitDepthId);
if(csId == "")
{
QList<KoID> list = KoColorSpaceRegistry::instance()->colorDepthList(modelId, KoColorSpaceRegistry::AllColorSpaces );
if(not list.empty())
{
csId = KoColorSpaceRegistry::instance()->colorSpaceId(modelId, list[0].id());
}
}
const KoColorSpace* cs = KoColorSpaceRegistry::instance()->colorSpace(csId, profileName);
if(cs)
{
KoColor c(cs);
cs->colorFromXML( c.data(), elt);
return c;
} else {
return KoColor();
}
}
......@@ -650,7 +650,7 @@ public:
* @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;
virtual void colorFromXML( quint8* pixel, const QDomElement& elt) const = 0;
/**
* The backgroundfilters will be run periodically on the newly
......
......@@ -353,15 +353,20 @@ QList<KoID> KoColorSpaceRegistry::colorModelsList(ColorSpaceListVisibility optio
}
return ids;
}
QList<KoID> KoColorSpaceRegistry::colorDepthList(const KoID& colorModelId, ColorSpaceListVisibility option ) const
{
return colorDepthList(colorModelId.id(), option);
}
QList<KoID> KoColorSpaceRegistry::colorDepthList(QString colorModelId, ColorSpaceListVisibility option ) const
{
QList<KoID> ids;
QList<KoColorSpaceFactory*> factories = values();
foreach(KoColorSpaceFactory* factory, factories)
{
if(not ids.contains(factory->colorDepthId())
and factory->colorModelId() == colorModelId
if(not ids.contains(KoID(factory->colorDepthId()))
and factory->colorModelId().id() == colorModelId
and ( option == AllColorSpaces or factory->userVisible() ))
{
ids << factory->colorDepthId();
......
......@@ -236,6 +236,10 @@ public:
* @return the list of available color models for the given colorModelId
*/
QList<KoID> colorDepthList(const KoID& colorModelId, ColorSpaceListVisibility option ) const;
/**
* @return the list of available color models for the given colorModelId
*/
QList<KoID> colorDepthList(QString colorModelId, ColorSpaceListVisibility option ) const;
/**
* @return the color conversion system use by the registry and the color
......
......@@ -150,7 +150,7 @@ public:
{
kDebug() <<"Undefined operation in the alpha colorspace";
}
virtual void colorFromXML( quint8* , const QDomElement& )
virtual void colorFromXML( quint8* , const QDomElement& ) const
{
kDebug() <<"Undefined operation in the alpha colorspace";
}
......
......@@ -97,7 +97,7 @@ void KoLabColorSpace::colorToXML( const quint8* pixel, QDomDocument& doc, QDomEl
colorElt.appendChild( labElt );
}
void KoLabColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt)
void KoLabColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt) const
{
KoLabU16Traits::Pixel* p = reinterpret_cast<KoLabU16Traits::Pixel*>( pixel );
p->L = KoColorSpaceMaths< double, KoLabU16Traits::channels_type >::scaleToA(elt.attribute("L").toDouble());
......
......@@ -41,7 +41,7 @@ class KoLabColorSpace : public KoLcmsColorSpace<KoLabU16Traits>
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);
virtual void colorFromXML( quint8* pixel, const QDomElement& elt) const;
private:
static const quint32 CHANNEL_L = 0;
......
......@@ -67,7 +67,7 @@ void KoRgbU16ColorSpace::colorToXML( const quint8* pixel, QDomDocument& doc, QDo
colorElt.appendChild( labElt );
}
void KoRgbU16ColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt)
void KoRgbU16ColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt) const
{
KoRgbU16Traits::Pixel* p = reinterpret_cast<KoRgbU16Traits::Pixel*>( pixel );
p->red = KoColorSpaceMaths< double, KoRgbU16Traits::channels_type >::scaleToA(elt.attribute("r").toDouble());
......
......@@ -33,7 +33,7 @@ class KoRgbU16ColorSpace : public KoLcmsColorSpace<KoRgbU16Traits>
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);
virtual void colorFromXML( quint8* pixel, const QDomElement& elt) const;
/**
* The ID that identifies this colorspace. Pass this as the colorSpaceId parameter
......
......@@ -113,7 +113,7 @@ void KoRgbU8ColorSpace::colorToXML( const quint8* pixel, QDomDocument& doc, QDom
colorElt.appendChild( labElt );
}
void KoRgbU8ColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt)
void KoRgbU8ColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt) const
{
RgbU8Traits::Pixel* p = reinterpret_cast<RgbU8Traits::Pixel*>( pixel );
p->red = KoColorSpaceMaths< double, RgbU8Traits::channels_type >::scaleToA(elt.attribute("r").toDouble());
......
......@@ -39,7 +39,7 @@ public:
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);
virtual void colorFromXML( quint8* pixel, const QDomElement& elt) const;
/**
* The ID that identifies this colorspace. Pass this as the colorSpaceId parameter
......
......@@ -71,7 +71,7 @@ void KisCmykU16ColorSpace::colorToXML( const quint8* pixel, QDomDocument& doc, Q
colorElt.appendChild( labElt );
}
void KisCmykU16ColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt)
void KisCmykU16ColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt) const
{
CmykU16Traits::Pixel* p = reinterpret_cast<CmykU16Traits::Pixel*>( pixel );
p->cyan = KoColorSpaceMaths< double, CmykU16Traits::channels_type >::scaleToA(elt.attribute("c").toDouble());
......
......@@ -37,7 +37,7 @@ class KisCmykU16ColorSpace : public KoLcmsColorSpace<CmykU16Traits>
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);
virtual void colorFromXML( quint8* pixel, const QDomElement& elt) const;
};
class KisCmykU16ColorSpaceFactory : public KoLcmsColorSpaceFactory
......
......@@ -72,7 +72,7 @@ void KisCmykU8ColorSpace::colorToXML( const quint8* pixel, QDomDocument& doc, QD
colorElt.appendChild( labElt );
}
void KisCmykU8ColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt)
void KisCmykU8ColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt) const
{
CmykU8Traits::Pixel* p = reinterpret_cast<CmykU8Traits::Pixel*>( pixel );
p->cyan = KoColorSpaceMaths< double, CmykU8Traits::channels_type >::scaleToA(elt.attribute("c").toDouble());
......
......@@ -35,7 +35,7 @@ class KisCmykU8ColorSpace : public KoLcmsColorSpace<CmykU8Traits>
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);
virtual void colorFromXML( quint8* pixel, const QDomElement& elt) const;
};
class KisCmykU8ColorSpaceFactory : public KoLcmsColorSpaceFactory
......
......@@ -61,7 +61,7 @@ void KisGrayAU16ColorSpace::colorToXML( const quint8* pixel, QDomDocument& doc,
colorElt.appendChild( labElt );
}
void KisGrayAU16ColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt)
void KisGrayAU16ColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt) const
{
GrayAU16Traits::channels_type* p = reinterpret_cast<GrayAU16Traits::channels_type*>( pixel );
p[0] = KoColorSpaceMaths< double, GrayAU16Traits::channels_type >::scaleToA(elt.attribute("g").toDouble());
......
......@@ -36,7 +36,7 @@ class PIGMENT_GRAY_U16_EXPORT KisGrayAU16ColorSpace : public KoLcmsColorSpace<Gr
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);
virtual void colorFromXML( quint8* pixel, const QDomElement& elt) const;
};
class KisGrayAU16ColorSpaceFactory : public KoLcmsColorSpaceFactory
......
......@@ -61,7 +61,7 @@ void KisGrayAU8ColorSpace::colorToXML( const quint8* pixel, QDomDocument& doc, Q
colorElt.appendChild( labElt );
}
void KisGrayAU8ColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt)
void KisGrayAU8ColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt) const
{
GrayAU8Traits::channels_type* p = reinterpret_cast<GrayAU8Traits::channels_type*>( pixel );
p[0] = KoColorSpaceMaths< double, GrayAU8Traits::channels_type >::scaleToA(elt.attribute("g").toDouble());
......
......@@ -36,7 +36,7 @@ class PIGMENT_GRAY_U8_EXPORT KisGrayAU8ColorSpace : public KoLcmsColorSpace<Gray
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);
virtual void colorFromXML( quint8* pixel, const QDomElement& elt) const;
};
class KisGrayAU8ColorSpaceFactory : public KoLcmsColorSpaceFactory
......
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