Commit 1651da28 authored by Cyrille Berger's avatar Cyrille Berger

extend KoColor with some convenient functions

svn path=/trunk/koffice/; revision=607712
parent 34f74502
...@@ -31,6 +31,13 @@ KoColor::KoColor() ...@@ -31,6 +31,13 @@ KoColor::KoColor()
memset(m_data, 0, m_colorSpace->pixelSize()); memset(m_data, 0, m_colorSpace->pixelSize());
m_colorSpace->setAlpha(m_data, OPACITY_OPAQUE, 1); m_colorSpace->setAlpha(m_data, OPACITY_OPAQUE, 1);
} }
KoColor::KoColor(KoColorSpace * colorSpace)
{
m_colorSpace = colorSpace;
m_data = new quint8[m_colorSpace->pixelSize()];
memset(m_data, 0, m_colorSpace->pixelSize());
}
KoColor::~KoColor() KoColor::~KoColor()
{ {
...@@ -139,19 +146,14 @@ void KoColor::setColor(quint8 * data, KoColorSpace * colorSpace) ...@@ -139,19 +146,14 @@ void KoColor::setColor(quint8 * data, KoColorSpace * colorSpace)
void KoColor::toQColor(QColor *c) const void KoColor::toQColor(QColor *c) const
{ {
if (m_colorSpace && m_data) { if (m_colorSpace && m_data) {
// XXX (bsar): There must be a better way, but I'm getting hopelessly confused about constness by now m_colorSpace->toQColor(m_data, c);
KoColorSpace * cs(const_cast<KoColorSpace*>(m_colorSpace));
cs->toQColor(m_data, c);
} }
} }
void KoColor::toQColor(QColor *c, quint8 *opacity) const void KoColor::toQColor(QColor *c, quint8 *opacity) const
{ {
if (m_colorSpace && m_data) { if (m_colorSpace && m_data) {
// XXX (bsar): There must be a better way, but I'm getting hopelessly confused about constness by now m_colorSpace->toQColor(m_data, c, opacity);
KoColorSpace * cs(const_cast<KoColorSpace*>(m_colorSpace));
cs->toQColor(m_data, c, opacity);
} }
} }
...@@ -162,6 +164,22 @@ QColor KoColor::toQColor() const ...@@ -162,6 +164,22 @@ QColor KoColor::toQColor() const
return c; return c;
} }
void KoColor::fromQColor(const QColor& c) const
{
if (m_colorSpace && m_data) {
m_colorSpace->fromQColor(c, m_data);
}
}
void KoColor::fromQColor(const QColor& c, quint8 opacity) const
{
if (m_colorSpace && m_data) {
m_colorSpace->fromQColor(c, opacity, m_data);
}
}
void KoColor::dump() const void KoColor::dump() const
{ {
...@@ -190,3 +208,13 @@ void KoColor::dump() const ...@@ -190,3 +208,13 @@ void KoColor::dump() const
} }
} }
void KoColor::fromKoColor(const KoColor& src)
{
if(src.colorSpace()->id() == colorSpace()->id())
{
memcpy(m_data, src.m_data, colorSpace()->pixelSize());
} else {
src.colorSpace()->convertPixelsTo(src.m_data, m_data, colorSpace(), 1);
}
}
...@@ -40,6 +40,8 @@ public: ...@@ -40,6 +40,8 @@ public:
virtual ~KoColor(); virtual ~KoColor();
/// Create a null KoColor. It will be valid, but all channels will be set to 0
KoColor(KoColorSpace * colorSpace);
/// Create a KoColor from a QColor. The QColor is immediately converted to native. The QColor /// Create a KoColor from a QColor. The QColor is immediately converted to native. The QColor
/// is assumed to have the current monitor profile. /// is assumed to have the current monitor profile.
KoColor(const QColor & color, KoColorSpace * colorSpace); KoColor(const QColor & color, KoColorSpace * colorSpace);
...@@ -73,11 +75,20 @@ public: ...@@ -73,11 +75,20 @@ public:
/// Replace the existing color data, and colorspace with the specified data. /// Replace the existing color data, and colorspace with the specified data.
void setColor(quint8 * data, KoColorSpace * colorSpace = 0); void setColor(quint8 * data, KoColorSpace * colorSpace = 0);
/// Convert the color from src and replace the value of the current color with the converted data.
/// Don't convert the color if src and this have the same colorspace.
void fromKoColor(const KoColor& src);
/// To save the user the trouble of doing color->colorSpace()->toQColor(color->data(), &c, &a /// To save the user the trouble of doing color->colorSpace()->toQColor(color->data(), &c, &a
void toQColor(QColor *c) const; void toQColor(QColor *c) const;
void toQColor(QColor *c, quint8 *opacity) const; void toQColor(QColor *c, quint8 *opacity) const;
/// Convenient function for converting from a QColor
void fromQColor(const QColor& c) const;
/// Convenient function for converting from a QColor and setting the opacity
void fromQColor(const QColor& c, quint8 opacity) const;
QColor toQColor() const; QColor toQColor() const;
void dump() const; void dump() const;
......
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