Tscope5
bitmaps.c File Reference

Definitions of bitmap functions. More...

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.

TS5_BITMAP * ts5_alloc_bitmap (double w, double h)
 Create a bitmap. More...
 
TS5_BITMAP * ts5_read_bitmap (const char *file)
 Open a bitmap from a file. More...
 
void ts5_write_bitmap (const char *file, TS5_BITMAP *map)
 Write a bitmap. More...
 
void ts5_free_bitmap (TS5_BITMAP *map)
 Free the memory used by a bitmap. More...
 
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)
 Get the size of a bitmap in pixels. More...
 
double ts5_get_bitmap_width (TS5_BITMAP *map)
 Get the width of a bitmap in pixels. More...
 
double ts5_get_bitmap_height (TS5_BITMAP *map)
 Get the height of a bitmap in pixels. More...
 
Drawing on bitmaps

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

TS5_BITMAP * ts5_set_drawing_target (TS5_BITMAP *target)
 Set the active drawing target. More...
 
TS5_BITMAP * ts5_get_drawing_target ()
 Get the active drawing target. More...
 
void ts5_get_target_size (double *w, double *h)
 Get the total size of the drawing target in pixels. More...
 
double ts5_get_target_width ()
 Get the total width of the drawing target in pixels. More...
 
double ts5_get_target_height ()
 Get the total height of the drawing target in pixels. More...
 
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)
 Draw a bitmap. More...
 
void ts5_draw_flipped_bitmap (TS5_BITMAP *map, double dx, double dy, const int flip)
 Draw a flipped bitmap. More...
 
void ts5_draw_tinted_bitmap (TS5_BITMAP *map, TS5_COLOR tint, double dx, double dy)
 Draw a tinted bitmap. More...
 
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. More...
 
void ts5_draw_rotated_bitmap (TS5_BITMAP *map, double cx, double cy, double angle, double dx, double dy)
 Draw a rotated bitmap. More...
 
void ts5_draw_scaled_bitmap (TS5_BITMAP *map, double xratio, double yratio, double dx, double dy)
 Draw a scaled bitmap. More...
 

Detailed Description

Definitions of bitmap functions.

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:
bitmaps05.c, display02.c, graphics01.c, graphics02.c, graphics03.c, and graphics04.c.

Definition at line 49 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:
bitmaps01.c, bitmaps02.c, bitmaps03.c, and bitmaps04.c.

Definition at line 87 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 134 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:
bitmaps01.c, bitmaps02.c, bitmaps03.c, bitmaps04.c, bitmaps05.c, display02.c, graphics01.c, graphics02.c, graphics03.c, and graphics04.c.

Definition at line 172 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:
bitmaps01.c, bitmaps02.c, bitmaps03.c, bitmaps04.c, graphics01.c, graphics02.c, graphics03.c, and graphics04.c.

Definition at line 205 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 233 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 252 of file bitmaps.c.

TS5_BITMAP* ts5_set_drawing_target ( TS5_BITMAP *  target)

Set the active drawing target.

Parameters
targetPointer to the bitmap that will be used for drawing operations.
Returns
A pointer to the previous active drawing target.
Examples:
bitmaps05.c, display02.c, graphics01.c, graphics02.c, graphics03.c, and graphics04.c.

Definition at line 285 of file bitmaps.c.

TS5_BITMAP* ts5_get_drawing_target ( )

Get the active drawing target.

Returns
A pointer to the active drawing target.

Definition at line 313 of file bitmaps.c.

void ts5_get_target_size ( double *  w,
double *  h 
)

Get the total size of the drawing target in pixels.

Parameters
wVariable that will store the width.
hVariable that will store the height.

The drawing target can be either a display or a memory bitmap.

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

Definition at line 332 of file bitmaps.c.

double ts5_get_target_width ( )

Get the total width of the drawing target in pixels.

Returns
the width of the drawing target.

The drawing target can be either a display or a memory bitmap.

Definition at line 354 of file bitmaps.c.

double ts5_get_target_height ( )

Get the total height of the drawing target in pixels.

Returns
the height of the drawing target.

The drawing target can be either a display or a memory bitmap.

Definition at line 373 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:
bitmaps01.c, bitmaps02.c, bitmaps03.c, bitmaps04.c, bitmaps05.c, display02.c, graphics01.c, graphics02.c, graphics03.c, graphics04.c, and video01.c.

Definition at line 412 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:
bitmaps01.c, bitmaps02.c, bitmaps03.c, and bitmaps04.c.

Definition at line 449 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:
bitmaps01.c, bitmaps02.c, bitmaps03.c, and bitmaps04.c.

Definition at line 495 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:
bitmaps01.c, bitmaps02.c, bitmaps03.c, and bitmaps04.c.

Definition at line 536 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 counter clockwise, negative is 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:
bitmaps01.c, bitmaps02.c, bitmaps03.c, and bitmaps04.c.

Definition at line 593 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:
bitmaps01.c, bitmaps02.c, bitmaps03.c, and bitmaps04.c.

Definition at line 638 of file bitmaps.c.