PDA

View Full Version : Is it better to read the whole row in bitmap than read it pixel by pixel?


doCHtor
03-26-2008, 08:33 PM
Hi,

is it better to read the whole row in bitmap than to read it pixel by pixel when I need to work with every pixel?
When I open a bitmap, and than read values from it, maxscript reads the values from memory or does it access harddrive each time I read a single pixel?

What I mean is that when I read the values of pixel, I convert it to greyscale, than if it's larger than 0 (black) I store it to array together with it's coords and value. Is there any advantage to read the whole row to array and than check each value from it and than output it to second array?

doC

RustyKnight
03-26-2008, 11:05 PM
Not been fully aware of the inner workings of max, I would suggest that it would be better to read the whole "line" in one single step and process it accordingly...but this is based on experience and assumptions (ie, that the bitmap has not yet been buffered into memory and/or the pixel information has not yet been decoded)...

You could do some speed trials and see what you get

Shane

Bobo
03-27-2008, 12:09 AM
Hi,

is it better to read the whole row in bitmap than to read it pixel by pixel when I need to work with every pixel?
When I open a bitmap, and than read values from it, maxscript reads the values from memory or does it access harddrive each time I read a single pixel?

What I mean is that when I read the values of pixel, I convert it to greyscale, than if it's larger than 0 (black) I store it to array together with it's coords and value. Is there any advantage to read the whole row to array and than check each value from it and than output it to second array?

doC

Yes and no.

It IS better to read a whole line of pixels and then process them instead of calling getPixels() for each pixel, but MAXScript does NOT access the image on disk on each call.

The MAXScript Bitmap Value wraps the bitmap class and when you create a bitmap by either loading one from disk or creating a new one via the bitmap() contructor or by calling render() or renderMap(), you get a bitmap value in memory.

The trouble is that getPixels() is *relatively* slow, so if you have a bitmap with 1000x1000 pixels, you have to call getPixels() 1 million times if you want each pixel, but only 1000 times if you want each row. Then a for loop can read and process the data from the returned row array of pixels which is much faster than reading pixel by pixel from the bitmap value.

The difference in speed is NOT necessarily orders of magnitude though, if you are reading and writing each pixel or reading and writing each line, you should get a difference factor of between 2 and 3 times.

doCHtor
03-27-2008, 08:35 AM
Thanks Bobo for clearing this up.

CGTalk Moderation
03-27-2008, 08:35 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.