Tscope5
bitmaps.c File Reference

Go to the source code of this file.

Functions

Loading bitmaps

Bitmaps can either be read from a file, or empty bitmaps can be generated.

Text/primitives output that is normally drawn on the display can be redirected to a bitmap using ts5_set_drawing_target().

TS5_BITMAP * ts5_alloc_bitmap (double w, double h)
TS5_BITMAP * ts5_read_bitmap (const char *file)
void ts5_write_bitmap (const char *file, TS5_BITMAP *map)
void ts5_free_bitmap (TS5_BITMAP *map)
Query bitmap dimensions

The dimensions of a bitmap can be queried using the functions below:

void ts5_get_bitmap_size (TS5_BITMAP *map, double *w, double *h)
double ts5_get_bitmap_width (TS5_BITMAP *map)
double ts5_get_bitmap_height (TS5_BITMAP *map)
Drawing bitmaps on the display

The destination coordinates of the bitmap drawing functions below are interpreted dependent on the coordinate system used.

  • When using the Cartesian coordinate system, bitmaps are centered around the destination coordinates.
  • When using the Display coordinate system, the destination coordinates correspond to the upper left corner of the bitmap.
void ts5_draw_bitmap (TS5_BITMAP *map, double dx, double dy)
void ts5_draw_flipped_bitmap (TS5_BITMAP *map, double dx, double dy, const int flip)
void ts5_draw_tinted_bitmap (TS5_BITMAP *map, TS5_COLOR tint, double dx, double dy)
void ts5_draw_bitmap_region (TS5_BITMAP *map, double sx1, double sy1, double sx2, double sy2, double dx, double dy)
void ts5_draw_rotated_bitmap (TS5_BITMAP *map, double cx, double cy, double angle, double dx, double dy)
void ts5_draw_scaled_bitmap (TS5_BITMAP *map, double xratio, double yratio, double dx, double dy)

Detailed Description

Definition in file bitmaps.c.


Function Documentation

TS5_BITMAP* ts5_alloc_bitmap ( double  w,
double  h 
)

Create a bitmap.

Parameters:
wWidth of the bitmap.
hHeight of the bitmap.
Returns:
A pointer to the newly created bitmap.

The default background color of the newly created bitmap is the same as the display.

Examples:
bitmaps5.c, display3.c, graphics1.c, graphics2.c, graphics3.c, and graphics4.c.

Definition at line 40 of file bitmaps.c.

TS5_BITMAP* ts5_read_bitmap ( const char *  file)

Open a bitmap from a file.

Parameters:
filePath to the bitmap file.
Returns:
A pointer to the newly created bitmap.

Available bitmap types are: bmp, pcx, tga, jpeg and png.

Examples:
bitmaps1.c, bitmaps2.c, bitmaps3.c, and bitmaps4.c.

Definition at line 74 of file bitmaps.c.

void ts5_write_bitmap ( const char *  file,
TS5_BITMAP *  map 
)

Write a bitmap.

Parameters:
filePath to the bitmap file.
mapPointer to the bitmap that will be written.

The extension specifies the file type. Available bitmap types are: bmp, pcx, tga, jpeg and png.

Useful for saving screenshots of the experiment.

Useful for creating complex stimuli beforehand.

Definition at line 104 of file bitmaps.c.

void ts5_free_bitmap ( TS5_BITMAP *  map)

Free the memory used by a bitmap.

Parameters:
mappointer to the bitmap that will be freed.

This function should be called at the end of the program for each bitmap allocated or read by the user.

Examples:
bitmaps1.c, bitmaps2.c, bitmaps3.c, bitmaps4.c, bitmaps5.c, display3.c, graphics1.c, graphics2.c, graphics3.c, and graphics4.c.

Definition at line 123 of file bitmaps.c.

void ts5_get_bitmap_size ( TS5_BITMAP *  map,
double *  w,
double *  h 
)

Get the size of a bitmap in pixels.

Parameters:
mapThe bitmap that will be queried.
wVariable that will store the width.
hVariable that will store the height.

You can pass NULL for values you are not interested in.

ts5_alloc_bitmap(), ts5_read_bitmap(), primitives.c, textio.c

Examples:
bitmaps1.c, bitmaps2.c, bitmaps3.c, bitmaps4.c, graphics1.c, graphics2.c, graphics3.c, and graphics4.c.

Definition at line 156 of file bitmaps.c.

double ts5_get_bitmap_width ( TS5_BITMAP *  map)

Get the width of a bitmap in pixels.

Parameters:
mapThe bitmap that will be queried.
Returns:
The width of the bitmap.

Definition at line 192 of file bitmaps.c.

double ts5_get_bitmap_height ( TS5_BITMAP *  map)

Get the height of a bitmap in pixels.

Parameters:
mapThe bitmap that will be queried.
Returns:
The height of the bitmap.

Definition at line 211 of file bitmaps.c.

void ts5_draw_bitmap ( TS5_BITMAP *  map,
double  dx,
double  dy 
)

Draw a bitmap.

Parameters:
mapThe bitmap that will be drawn.
dxHorizontal position where it will be drawn.
dyVertical position where it will be drawn.
Examples:
bitmaps1.c, bitmaps2.c, bitmaps3.c, bitmaps4.c, bitmaps5.c, display3.c, graphics1.c, graphics2.c, graphics3.c, and graphics4.c.

Definition at line 246 of file bitmaps.c.

void ts5_draw_flipped_bitmap ( TS5_BITMAP *  map,
double  dx,
double  dy,
const int  flip 
)

Draw a flipped bitmap.

Parameters:
mapThe bitmap that will be drawn.
dxHorizontal position where it will be drawn.
dyVertical position where it will be drawn.
flipDirection of the flip. Can be TS5_FLIP_HORIZONTAL, TS5_FLIP_VERTICAL or TS5_FLIP_BOTH.
Examples:
bitmaps1.c, bitmaps2.c, bitmaps3.c, and bitmaps4.c.

Definition at line 273 of file bitmaps.c.

void ts5_draw_tinted_bitmap ( TS5_BITMAP *  map,
TS5_COLOR  tint,
double  dx,
double  dy 
)

Draw a tinted bitmap.

Parameters:
mapThe bitmap that will be drawn.
tintThe tint color. All colors in the bitmap are multiplied with the color specified in tint.
dxHorizontal position where it will be drawn.
dyVertical position where it will be drawn.
Examples:
bitmaps1.c, bitmaps2.c, bitmaps3.c, and bitmaps4.c.

Definition at line 305 of file bitmaps.c.

void ts5_draw_bitmap_region ( TS5_BITMAP *  map,
double  sx1,
double  sy1,
double  sx2,
double  sy2,
double  dx,
double  dy 
)

Draw a region of a bitmap.

Parameters:
mapThe bitmap that will be drawn.
sx1Horizontal coordinate of the first corner or the region.
sy1Vertical coordinate of the first corner or the region.
sx2Horizontal coordinate of the second corner or the region.
sy2Vertical coordinate of the second corner or the region.
dxHorizontal position where it will be drawn.
dyVertical position where it will be drawn.
Examples:
bitmaps1.c, bitmaps2.c, bitmaps3.c, and bitmaps4.c.

Definition at line 336 of file bitmaps.c.

void ts5_draw_rotated_bitmap ( TS5_BITMAP *  map,
double  cx,
double  cy,
double  angle,
double  dx,
double  dy 
)

Draw a rotated bitmap.

Parameters:
mapThe bitmap that will be drawn.
cxHorizontal coordinate of the center of rotation.
cyCertical coordinate of the center of rotation.
angleThe angle of rotation in degrees (positive is clockwise, negative is counter clockwise).
dxHorizontal position where it will be drawn.
dyVertical position where it will be drawn.

The center of rotation (cx,cy) will be drawn at (dx,dy).

Examples:
bitmaps1.c, bitmaps2.c, bitmaps3.c, and bitmaps4.c.

Definition at line 382 of file bitmaps.c.

void ts5_draw_scaled_bitmap ( TS5_BITMAP *  map,
double  xratio,
double  yratio,
double  dx,
double  dy 
)

Draw a scaled bitmap.

Parameters:
mapThe bitmap that will be drawn.
xratioThe scaling factor in the horizontal direction.
yratioThe scaling factor in the vertical direction.
dxHorizontal position where it will be drawn.
dyVertical position where it will be drawn.
Examples:
bitmaps1.c, bitmaps2.c, bitmaps3.c, and bitmaps4.c.

Definition at line 418 of file bitmaps.c.