I’m trying to use the gif encoder to save gifs of my app over a ~20 second period. While the saving is already multi-threaded in the library, I also need to resize the frames from a large (2160 x 1920) size, to something appropriate for a gif (540 x 480 or so). The problem is that the resize is intensive enough that it slows the framerate to a crawl. I’ve tried to use the multithreading example, but keep getting bad access exceptions. Does anyone have any experience (or a library) running resizing in a separate thread?
the problem is that resize also updates the texture, you can’t do opengl calls in a different thread, what you can do is just disable the texture in the image while you are resizing it:
img.setUseTexture(false)
and then once it’s resized in the main thread, in update for example, enable it again:
So I tried disabling the texture, and I know avoid having a bad access exception. That being said, I can’t seem to clone the image of the current frame (in the main thread) to the image to be resized (in the secondary thread). When I try to capture a frame I do the following:
currentFrame.grabScreen(0,0,ofGetWidth(),ofGetHeight());
// lock access to the resource
thread.lock();
// copy image
currentFrame.setUseTexture(false);
currentFrame.clone(thread.toResize);
currentFrame.setUseTexture(true);
thread.imageFresh = true;
thread.resizeComplete = false;
// done with the resource
thread.unlock();
Where toResize is an ofImage in the thread, and currentFrame is an ofImage in the main thread. Current frame is fine, and gets an image of the correct dimensions (2160 x 1920) but the clone never seems to take, and the thread simply has a height and width of zero.
Good call: I did this and it simplified things considerably, since I ended up just working with ofPixels objects as shared thread resources.
Just to wrap up the thread: I was also having a problem where my screen captures were all black. This is apparently the result of known bug since 2010(!) that requires setBackgroundAuto to be true.