Const iterators

Boudewijn Rempt boud at valdyas.org
Mon Mar 28 18:37:36 CEST 2005


On Mon, 28 Mar 2005, Adrian Page wrote:

> Boudewijn Rempt wrote:
> > Is it maybe an idea to add const iterators for the paint devices some time
> > soon? I'm everlastingly either const_casting or removings consts because I
> > cannot read out a device const'ly...
>
> Yes, we should have const iterators, or at least a way to access the
> data in a read-only manner.

I'm glad you confirm my suspicion... Of course, we can already set the iterators
read-only, which percolates down to the tile manager -- but that's not enough.

> I have been looking at the iterators lately and have thought about
> making some changes like this. We could make rawData() return a const
> Q_UINT8 *, and maybe have a function to copy into the data:
>
> const Q_UINT8 *rawData()
> void setRawData(const Q_UINT8 *src, Q_INT32 numPixels = 1)
>
> An advantage of having a function to do the job of the memcpy is that we
> could track the exact extent of the data without having to do the pixel
> search that you do in exactExtent. Then everything that would benefit
> from an exact extent could just use it without having to think about it.

Wouldn't that slow down all write operations quite a bit --
adding a

if x < m_x; m_x = x;
if y < m_y; m_y = y;
if x > m_width; m_width = x;
if y > m_height; m_height = y;

for every pixel we write?

> The same idea would apply to the KisPixel access. Instead of a KisPixel
> pointing to the raw data, allowing you to modify it directly, KisPixel
> would hold its own data and you would do an it.setPixel(pixel) to write it.
>
> Another idea is to make iterators easier to use by being able to set and
> get QColors directly (until we replace QColor with KisColor). Either
> that or allow KisPixels to be settable to a QColor and return a QColor -
> no matter what colour space is in use.

This is a bit trickier -- ideally, you want to preserve data that cannot
be in a QColor, like wetness/opacity/thickness etc -- and if you convert to
QColor and then write, you would lose all the extra data.

> It would be nice to be able to do things like
>
> KisHLineIteratorPixel pixelIt = createHLineIteratorPixel(...);
>
> QColor color = pixelIt.color();
> ... do something interesting with the color...
> it.setColor(color);

It remains a perennial problem... I was already bashing my head against this wall
within a month of joining Krita, and a good solution is still quite far away.

Boudewijn


More information about the kimageshop mailing list