Pixel access

Cyrille Berger cyb at lepi.org
Mon Sep 27 19:08:31 CEST 2004


> scaling gives good results, but the scaling code is really slow. The
> problem is, that the code accesses pixels using readpixel(x,y,x,y,pixel).
> This is probably the slowest way to access pixels. I think basically it
> would be the best idea to read a whole line from an image at a time. This
> could be done by calling readpixel (0,y,width(),y,line). But is this the
> most efficient way or is it better to use iterators. If yes, how can I use
> the iterators to read a whole line?

There are two functions to create an iterator : iteratorPixelBegin and 
iteratorPixelSelectionBegin, the first one if you don't care about selection, 
the second one if you care. I do think that in your case you need to use the 
first one.

KisIteratorLinePixel lineIt = device->iteratorPixelBegin( command, 0, width(), 
y);
KisIteratorPixel pixelIt = *linetIt;
KisIteratorPixel endIt = linetIt.end();
while( pixelIt <= endIt )
{
 // your computing
 ++pixelIt;
}

If y goes from 0 to height(), you might be willing to do this :

KisIteratorLinePixel lineIt = device->iteratorPixelBegin( command, 0, width(), 
0);
KisIteratorLinePixel endLineIt = device->iteratorPixelEnd( command, 0, 
width(), height);
while( lineIt <) endLineIt )
{
 KisIteratorPixel pixelIt = *linetIt;
 KisIteratorPixel endIt = linetIt.end();
 while( pixelIt <= endIt )
 {
   // your computing
   ++pixelIt;
 }
 ++lineIt;
}


-- 
--- Cyrille Berger ---


More information about the kimageshop mailing list