Notifications
Clear all

[Closed] faster bitmap processing?

Hi I have written (or rather copied from http://www.louismarcoux.com/MaxTips.htm , to be honest), a script that combines two renderings to create an anaglyph image to be viewed with red-cyan glasses. It is not really complicated or long:


      left = render camera:$camleft rendertype:#regioncrop region:#(imgdiff+1,1,fwidth,renderheight) fromframe:rendstart toframe:rendend --gamma:2.2
     right = render camera:$camright rendertype:#regioncrop region:#(1,1,fwidth-imgdiff,renderheight) fromframe:rendstart toframe:rendend --gamma:2.2
     newimage = bitmap dwidth renderheight --gamma:2.2-- create a new image of the correct size
      	
      	for j = 0 to (newimage.height)-1 do
      	(	
      		
      		for i = 0 to (newimage.width)-1 do
      		(
      			Colorleft = getpixels left [i,j] 1 -- get the red pixel color
      			ColorRight = getpixels right [i,j] 1  -- get the blue and green 
      			
      			ColorFinal = #([ Colorleft[1].red,Colorright[1].green,Colorright[1].blue] ) 
      		
      			setpixels newimage [i,j] Colorfinal
      		)
      	)
      	display newimage
      

my problem is. Though it is working perfectly i find it is rather slow. My question: Is there a way to speed the process up? Some other approach then going through all the pixels, maybe? I remember delphi had something like a scanline command which was really fast, does maxscript have this, too?

thx in advance

David

4 Replies

Is there any reason why you would do this directly in max? Why don’t use use a comp app for this instead?

Yes, there is a way, as discussed in the “How To Make It Faster?” >“Never get a single pixel when you can get a whole line” chapter of the MAXScript Reference.

In short, getPixels() is rather slow. You should not call it once per pixel, but once per horizontal scanline, then process the pixels in the returned arrays and write back the final array containing the whole scanline using setPixels(). So if your image is 640×480, instead of calling the getPixels() and setPixels() 307200 times each, you will be calling them only 480 times. Your code will not be 640 times faster, but still at least twice as fast.

@Bobo: Thanks man. You are always really helpful. At first i thought you’d be kidding: A “how to make it faster” page inside the maxscript-helpfile :curious: ?!? But the page existed and was just what i was looking for. I haven’t measured, but the speed gain is highly visible.

@theotheo: It’s very comfortable to get preview stills inside Max without the hassle of opening a second program and loading the bitmaps into the composition, every time i want to test something real quick. For the final movie i will of course use a compositing software.

1 Reply
(@bobo)
Joined: 1 year ago

Posts: 0

I am not kidding when it comes to the Reference.
I highly suggest reading the complete Frequently Asked Questions chapter as it contains some compressed knowledge including solutions from this forum.
The How To Make It Faster was added around Max 6 I think (that’s why the benchmark numbers were from an 800 MHz PC – that was my humble machine in those days).