BufferImageStim

Attributes

Details

class psychopy.visual.BufferImageStim(*args, **kwargs)[source]

Take a “screen-shot”, save as an ImageStim (RBGA object). This is a lazy-imported class, therefore import using full path from psychopy.visual.bufferimage import BufferImageStim when inheriting from it.

The screen-shot is a single collage image composed of static elements that you can treat as being a single stimulus. The screen-shot can be of the visible screen (front buffer) or hidden (back buffer).

BufferImageStim aims to provide fast rendering, while still allowing dynamic orientation, position, and opacity. It’s fast to draw but slower to init (same as an ImageStim).

You specify the part of the screen to capture (in norm units), and optionally the stimuli themselves (as a list of items to be drawn). You get a screenshot of those pixels. If your OpenGL does not support arbitrary sizes, the image will be larger, using square powers of two if needed, with the excess image being invisible (using alpha). The aim is to preserve the buffer contents as rendered.

Checks for OpenGL 2.1+, or uses square-power-of-2 images.

Example:

# define lots of stimuli, make a list:
mySimpleImageStim = ...
myTextStim = ...
stimList = [mySimpleImageStim, myTextStim]

# draw stim list items & capture (slow; see EXP log for times):
screenshot = visual.BufferImageStim(myWin, stim=stimList)

# render to screen (very fast, except for the first draw):
while <conditions>:
    screenshot.draw()  # fast; can vary .ori, .pos, .opacity
    other_stuff.draw() # dynamic
    myWin.flip()

See coder Demos > stimuli > bufferImageStim.py for a demo, with timing stats.

Author:
  • 2010 Jeremy Gray, with on-going fixes

Parameters:
buffer :

the screen buffer to capture from, default is ‘back’ (hidden). ‘front’ is the buffer in view after win.flip()

rect :

a list of edges [left, top, right, bottom] defining a screen rectangle which is the area to capture from the screen, given in norm units. default is fullscreen: [-1, 1, 1, -1]

stim :

a list of item(s) to be drawn to the back buffer (in order). The back buffer is first cleared (without the win being flip()ed), then stim items are drawn, and finally the buffer (or part of it) is captured. Each item needs to have its own .draw() method, and have the same window as win.

interpolate :

whether to use interpolation (default = True, generally good, especially if you change the orientation)

sqPower2 :
  • False (default) = use rect for size if OpenGL = 2.1+

  • True = use square, power-of-two image sizes

flipHoriz :

horizontally flip (mirror) the captured image, default = False

flipVert :

vertically flip (mirror) the captured image; default = False


Back to top