We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
speed up save? (Read 358 times)
speed up save?
Dec 5th, 2007, 7:40pm
 
hi all

i need to use save() in order to save a jpeg of the current screen, but it takes a little while to do this (say 0.2 secs) -- enough that it slows down the animation perceptibly when saving (which i'm only doing once per minute or so).

is there any way to speed up the saving so that the draw loop can continue while saving? i tried making a separate thread but of course then it doesn't capture the screen at exactly the right state.

thanks for any pointers.
Re: speed up save?
Reply #1 - Dec 5th, 2007, 9:20pm
 
Just a thought, but perhaps you could create a separate PImage object to quickly capture a given frame from the PGraphics to the PImage (using PGraphics.copy() I believe). This copy() operation would be called from within the draw loop, after which point you could use your separate thread to call the PImage.save() method to write the PImage data to disk. This way, the frame capturing is still in sync with the draw loop, but it shouldn't slow down your animation because you're still using the other thread to perform the relatively slow task of saving your images to disk.

Of course, if the saving operation is so slow that it begins to fall seriously behind the rate of frame captures, you'll run into some nasty concurrency problems. In that case, you would want to keep an array of PImage objects available to be written to, cycling through them as necessary. This process would be similar to the internal memory that digital cameras have, using a fast-write RAM buffer when the relatively slow flash memory becomes a bottleneck.

Hope this makes at least a little sense!

greg
Page Index Toggle Pages: 1