Fundementals of Palette Animation and how it works on the Bits++


Three different animation techniques

Some stimuli like, for example, drifting gratings, need to be animated in real time. That is, the image needs to be different from one frame to the next. There is more than one way to achieve this.

Brute force

The simplest is to create a loop in which the required appearance of the stimulus is calculated and the contents of the video memory are changed on each iteration. The trouble with this approach is that if all or most of the image changes each frame, as it does for a drifting grating, then a large number of calculations might need to be done and a very large number of pixels need to be changed every frame. This is time consuming and, particularly in an interpretted language like MatLab, it can't always be achieved quickly enough to work in real time.

Page cycling

The slowness of the large number of calculations can be dealt with by pre-calculating every page of your stimulus in advance, saving each one and then playing them back in real time like a movie. This can be a useful technique but it potentially requires a large amount of memory in which to store all these pre-calculated frames.

Palette animation

For certain types of animation there is another way around the problems called "palette animation". To understand how this works you need to know the difference between palette based images and true-colour images.

What is a palette?

In a true-colour image, each pixel of the image is stored in video memory as RGB values, so any pixel can have any colour - any combination of red, green and blue. In a palette based image the value stored in video memory is an index into a palette of RGB values. So each pixel can only have the colour of one of the entries in the palette. If the palette has 256 entries then you can only have 256 different colours, but these colours can be changed by changing the palette. When you change the colour of one palette entry all pixels containing that palette index will change colour. So by making one small change you can potentially change lots of pixels.

This is the basis of palette animation. The video memory contains a whole load of palette entries and these remain static. But the colours in the palette to which they point change each frame. This can be done quickly enough to work in real time.

When can palette animation be used?

This technique is fast but it can only be used for particular types of animation. Remember, the values stored in video memory do not change; only the colour values to which they point. This means that the basic shape of the stimulus cannot be varied, only the colours and luminances of the shape. It lends itself well to situations in which the whole stimulus flows or oscillates across the screen, like drifting gratings. To animate a rectangular sinusoidal monochrome grating so that it drifts across the screen at constant speed you could do one of two things.

You could draw a linear greyscale ramp into video memory and use a sinusoidally varying palette. Then you simply increment the phase of this sinusoid each frame.

Or you could draw a rectangle on the screen whose luminance varies sinusoidally and load a greyscale ramp into the palette, then increment the starting value of the greyscale ramp each frame.

Changing palettes in the Bits++

In Bits++ mode the Bits++ contains a palette, also known as a Colour Look Up Table, or CLUT. There are two ways to change the values in the CLUT. One way is to send a new CLUT down the USB connection, but this is too slow to be used in palette animation, so the Bits++ provides another method and this is known as T-Lock.

Valid XHTML :: Valid CSS: :: Powered by WikkaWiki