Commit d325b29f authored by Cyrille Berger's avatar Cyrille Berger

Make KoColor::setPixel takes a const pointer (and also reallocate memory

only if necesserary)
Make KisPaintDevice::pixel be const and use const iterator, this avoid
the memento manager to start creating a new history point, and therefor
fix the KisTransaction test

svn path=/trunk/koffice/; revision=1112881
parent 49fadfcb
......@@ -881,9 +881,9 @@ void KisPaintDevice::applySelectionMask(KisSelectionSP mask)
}
}
bool KisPaintDevice::pixel(qint32 x, qint32 y, QColor *c)
bool KisPaintDevice::pixel(qint32 x, qint32 y, QColor *c) const
{
KisHLineConstIteratorPixel iter = createHLineIterator(x, y, 1);
KisHLineConstIteratorPixel iter = createHLineConstIterator(x, y, 1);
const quint8 *pix = iter.rawData();
......@@ -895,11 +895,11 @@ bool KisPaintDevice::pixel(qint32 x, qint32 y, QColor *c)
}
bool KisPaintDevice::pixel(qint32 x, qint32 y, KoColor * kc)
bool KisPaintDevice::pixel(qint32 x, qint32 y, KoColor * kc) const
{
KisHLineIteratorPixel iter = createHLineIterator(x, y, 1);
KisHLineConstIteratorPixel iter = createHLineConstIterator(x, y, 1);
quint8 *pix = iter.rawData();
const quint8 *pix = iter.rawData();
if (!pix) return false;
......
......@@ -346,7 +346,7 @@ public:
*
* @return true if the operation was successful.
*/
bool pixel(qint32 x, qint32 y, QColor *c);
bool pixel(qint32 x, qint32 y, QColor *c) const;
/**
* Fill kc with the values found at x and y. This method differs
......@@ -357,7 +357,7 @@ public:
*
* @return true if the operation was successful.
*/
bool pixel(qint32 x, qint32 y, KoColor * kc);
bool pixel(qint32 x, qint32 y, KoColor * kc) const;
/**
* Set the specified pixel to the specified color. Note that this
......
......@@ -158,12 +158,15 @@ void KoColor::convertTo(const KoColorSpace * cs)
}
void KoColor::setColor(quint8 * data, const KoColorSpace * colorSpace)
void KoColor::setColor(const quint8 * data, const KoColorSpace * colorSpace)
{
Q_ASSERT(data);
Q_ASSERT(colorSpace);
delete [] d->data;
d->data = new quint8[colorSpace->pixelSize()];
if(d->colorSpace->pixelSize() != colorSpace->pixelSize())
{
delete [] d->data;
d->data = new quint8[colorSpace->pixelSize()];
}
memcpy(d->data, data, colorSpace->pixelSize());
d->colorSpace = KoColorSpaceRegistry::instance()->permanentColorspace(colorSpace);
}
......
......@@ -78,7 +78,9 @@ public:
void convertTo(const KoColorSpace * cs);
/// Replace the existing color data, and colorspace with the specified data.
void setColor(quint8 * data, const KoColorSpace * colorSpace = 0);
/// The data pointer remains of the responsability of the caller, and this function
/// might change the internal pointer and reallocate memory if necesserary.
void setColor(const quint8 * data, const 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.
......
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