optimizing the scaling code
Casper Boemann
cbr at boemann.dk
Tue Jun 28 10:34:00 CEST 2005
On Tuesday 28 June 2005 09:41, Michael Thaler wrote:
> Hello,
>
> I think the main speed problem in my current scaling code is that I read
> single pixels using
>
> QUANTUM *tmp = new QUANTUM[ pixelSize * sizeof(QUANTUM) ];
> m_dev -> readBytes(tmp, x, y, 1, 1);
>
> I am currently rewriting the code to read whole lines and I wonder what is
> the best way to do this. Casper's transform visitor does this:
>
> KisHLineIteratorPixel srcIt = src->createHLineIterator(left, y, w, true);
> int i = 0;
> while(!srcIt.isDone())
> {
> Q_UINT8 *data;
> data = srcIt.rawData();
> memcpy(&tmpLine[i*pixelSize], data, pixelSize);
> ++srcIt;
> i++;
> }
>
> which creates a temporary array with the pixel data of a line.
>
> Another method would be to just use
>
> QUANTUM *tmp = new QUANTUM[ width * pixelSize * sizeof(QUANTUM) ];
> m_dev -> readBytes(tmp, 0, y, width, 1);
>
> What is faster? Or is there any other method to read a line as fast as
> possible?
about the same.
the advantage of using an iterator could be if you need to do some per pixel
work while reading
btw I now see that I can optimize my code here, by using the number of
consequtive pixels to copy larger blocks. This is actually a reason to use
readBytes as that function is likely to be update with such fixes faster than
your own code.
--
best regards / venlig hilsen
Casper Boemann
More information about the kimageshop
mailing list