Previous topic

Aperture

Next topic

Circle

This Page

Quick links

BufferImageStim

class psychopy.visual.BufferImageStim(win, buffer='back', rect=(-1, 1, 1, -1), sqPower2=False, stim=(), interpolate=True, vertMirror=False, name='', autoLog=True)

Take a “screen-shot” (full or partial), save to a PatchStim()-like RBGA object.

The class returns a screen-shot, i.e., a single collage image composed of static elements, ones that you want to treat as effectively 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. Its fast to draw but slow to init: ~75ms for a 1024 x 512 capture; init time is proportional to image size (as for PatchStim). There is no support for dynamic depth or color.

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.

Status: seems to work on Mac, but limitations:
  • Screen units are not properly sorted out, better to allow pix too
  • Rudimentary testing on pygame; none on Windows, Linux, FreeBSD

Example:

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

# draw stim list items & capture everything (slow):
screenshot = visual.BufferImageStim(myWin, stim=stimList)

# render to screen (fast):
while <conditions>:
    screenshot.draw()  # fast; can vary .ori, ._position, .opacity
    other_stuff.draw() # dynamic
    myWin.flip()

See coder Demos > stimuli > bufferImageStim.py for a demo.

Author :
  • 2010 Jeremy Gray
Parameters :
win :

A Window object (required)

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 buffer in order, then 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
vertMirror :

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

name : string

The name of the object to be using during logged messages about this stim

draw()

streamlined version of draw. limitations / bugs: not sure what happens with shaders & self._updateList()

setTex(tex, interpolate=True)