20 #include "../include/tscope5/bitmaps.h"
21 #include "../include/tscope5/display.h"
22 #include "../include/tscope5/graphics.h"
23 #include "../include/tscope5/bitmaps_internal.h"
24 #include "../include/tscope5/system_internal.h"
25 #include "../include/tscope5/graphics_internal.h"
26 #include "../include/tscope5/display_internal.h"
52 ts5_log(TS5_LOGLEVEL_2,
"ts5_alloc_bitmap(%f,%f)\n", w, h);
54 if (_ts5_status.graphics.coordinate_scale
55 == TS5_RELATIVE_COORDINATES) {
56 w *= _ts5_status.graphics.target_width;
57 h *= _ts5_status.graphics.target_height;
60 w *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
61 h *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
64 map = al_create_bitmap(w, h);
67 ts5_fatal(
"ts5_alloc_bitmap: could not make bitmap\n");
90 ts5_log(TS5_LOGLEVEL_2,
"ts5_read_bitmap(%s)\n", file);
92 TS5_BITMAP *map1, *map2;
93 map1 = al_load_bitmap(file);
96 ts5_fatal(
"ts5_read_bitmap: could not read bitmap\n");
99 al_convert_bitmap(map1);
101 double w1 = al_get_bitmap_width(map1);
102 double h1 = al_get_bitmap_height(map1);
104 double w2 = w1 * _ts5_status.display[_ts5_status.active_display].sampling_factor;
105 double h2 = h1 * _ts5_status.display[_ts5_status.active_display].sampling_factor;
107 map2 = al_create_bitmap(w2, h2);
111 al_draw_scaled_bitmap(map1, 0.0, 0.0, w1, h1,
112 0.0, 0.0, w2, h2, 0);
115 al_destroy_bitmap(map1);
137 ts5_log(TS5_LOGLEVEL_2,
"ts5_write_bitmap(%s,%p)\n", file, map);
145 w *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
146 h *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
148 TS5_BITMAP *map2 = al_create_bitmap(w2, h2);
152 al_draw_scaled_bitmap(map, 0.0, 0.0, w, h,
153 0.0, 0.0, w2, h2, 0);
157 if (!al_save_bitmap(file, map2)) {
158 ts5_fatal(
"ts5_write_bitmap: could not write bitmap\n");
160 al_destroy_bitmap(map2);
175 ts5_log(TS5_LOGLEVEL_2,
"ts5_free_bitmap(%p)\n", map);
177 al_destroy_bitmap(map);
208 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_bitmap_size(%p,%p,%p)\n", map, w, h);
211 ts5_fatal(
"ts5_get_bitmap_size: bitmap pointer is null\n");
215 *w = al_get_bitmap_width(map) /
216 _ts5_status.display[_ts5_status.active_display].sampling_factor;
220 *h = al_get_bitmap_height(map) /
221 _ts5_status.display[_ts5_status.active_display].sampling_factor;
236 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_bitmap_width(%p)\n", map);
255 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_bitmap_width(%d)\n", map);
288 ts5_log(TS5_LOGLEVEL_4,
"ts5_set_drawing_target(%p)\n", target);
290 if (target == NULL) {
291 ts5_fatal(
"ts5_set_drawing_target: target is a NULL pointer\n");
294 TS5_BITMAP *retval = _ts5_data.target;
295 _ts5_data.target = target;
296 al_set_target_bitmap(_ts5_data.target);
298 _ts5_status.graphics.target_width =
301 _ts5_status.graphics.target_height =
316 ts5_log(TS5_LOGLEVEL_4,
"ts5_get_drawing_target()\n");
318 return _ts5_data.target;
335 ts5_log(TS5_LOGLEVEL_4,
"ts5_get_target_size(%p,%p)\n", w, h);
338 *w = _ts5_status.graphics.target_width;
342 *h = _ts5_status.graphics.target_height;
357 ts5_log(TS5_LOGLEVEL_4,
"ts5_get_target_width()\n");
376 ts5_log(TS5_LOGLEVEL_4,
"ts5_get_target_height()\n");
415 ts5_log(TS5_LOGLEVEL_5,
"ts5_draw_bitmap(%p,%f,%f)\n", map, dx, dy);
417 if (_ts5_status.graphics.coordinate_scale
418 == TS5_RELATIVE_COORDINATES) {
423 if (_ts5_status.graphics.coordinate_system
424 == TS5_CARTESIAN_COORDINATES) {
433 dx *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
434 dy *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
436 al_draw_bitmap(map, dx, dy, 0);
453 ts5_log(TS5_LOGLEVEL_5,
"ts5_draw_flipped_bitmap(%p,%f,%f,%d)\n",
456 if (flip != TS5_FLIP_HORIZONTAL && flip != TS5_FLIP_VERTICAL
457 && flip != TS5_FLIP_BOTH) {
458 ts5_fatal(
"%s: %s %s\n",
"ts5_draw_flipped_bitmap",
459 "flip should be TS5_FLIP_HORIZONTAL,",
460 "TS5_FLIP_VERTICAL or TS5_FLIP_BOTH");
463 if (_ts5_status.graphics.coordinate_scale
464 == TS5_RELATIVE_COORDINATES) {
469 if (_ts5_status.graphics.coordinate_system
470 == TS5_CARTESIAN_COORDINATES) {
479 dx *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
480 dy *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
482 al_draw_bitmap(map, dx, dy, flip);
496 double dx,
double dy)
499 ts5_log(TS5_LOGLEVEL_5,
"ts5_draw_tinted_bitmap(%p,(%f,%f,%f,%f),%f,%f)\n",
500 map, tint.r, tint.g, tint.b, tint.a, dx, dy);
502 if (_ts5_status.graphics.coordinate_scale
503 == TS5_RELATIVE_COORDINATES) {
508 if (_ts5_status.graphics.coordinate_system
509 == TS5_CARTESIAN_COORDINATES) {
518 dx *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
519 dy *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
521 al_draw_tinted_bitmap(map, tint, dx, dy, 0);
537 double sx2,
double sy2,
double dx,
double dy)
540 ts5_log(TS5_LOGLEVEL_5,
"ts5_draw_bitmap_region(%p,%f,%f,%f,%f,%f,%f)\n",
541 map, sx1, sy1, sx2, sy2, dx, dy);
543 if (_ts5_status.graphics.coordinate_scale
544 == TS5_RELATIVE_COORDINATES) {
555 double width = fabs(sx2 - sx1);
556 double height = fabs(sy2 - sy1);
557 double x = sx1 < sx2 ? sx1 : sx2;
558 double y = sy1 < sy2 ? sy1 : sy2;
560 if (_ts5_status.graphics.coordinate_system
561 == TS5_CARTESIAN_COORDINATES) {
568 x *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
569 y *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
570 width *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
571 height *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
572 dx *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
573 dy *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
576 al_draw_bitmap_region(map, x, y, width, height, dx, dy, 0);
594 double angle,
double dx,
double dy)
597 ts5_log(TS5_LOGLEVEL_5,
"ts5_draw_rotated_bitmap(%p,%f,%f,%f,%f,%f)\n",
598 map, cx, cy, angle, dx, dy);
600 if (_ts5_status.graphics.coordinate_scale
601 == TS5_RELATIVE_COORDINATES) {
610 if (_ts5_status.graphics.coordinate_system
611 == TS5_CARTESIAN_COORDINATES) {
618 angle = - angle * TS5_PI / 180.0;
620 cx *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
621 cy *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
622 dx *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
623 dy *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
625 al_draw_rotated_bitmap(map, cx, cy, dx, dy, angle, 0);
639 double dx,
double dy)
642 ts5_log(TS5_LOGLEVEL_5,
"ts5_draw_scaled_bitmap(%p,%f,%f,%f,%f)\n",
643 map, xratio, yratio, dx, dy);
648 if (_ts5_status.graphics.coordinate_scale
649 == TS5_RELATIVE_COORDINATES) {
654 if (_ts5_status.graphics.coordinate_system
655 == TS5_CARTESIAN_COORDINATES) {
660 w *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
661 h *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
662 dx *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
663 dy *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
665 al_draw_scaled_bitmap(map, 0.0, 0.0, w, h, dx, dy,
666 w * xratio, h * yratio, 0);
TS5_BITMAP * ts5_read_bitmap(const char *file)
Open a bitmap from a file.
void ts5_draw_bitmap(TS5_BITMAP *map, double dx, double dy)
Draw a bitmap.
void ts5_check_display(char *calling_function)
Do some checks at the start of each display function.
void ts5_draw_flipped_bitmap(TS5_BITMAP *map, double dx, double dy, const int flip)
Draw a flipped bitmap.
void ts5_free_bitmap(TS5_BITMAP *map)
Free the memory used by a bitmap.
void ts5_get_target_size(double *w, double *h)
Get the total size of the drawing target in pixels.
double ts5_get_bitmap_width(TS5_BITMAP *map)
Get the width of a bitmap in pixels.
void ts5_check_graphics(char *calling_function)
Do some checks at the start of each graphics function.
TS5_BITMAP * ts5_alloc_bitmap(double w, double h)
Create a bitmap.
void ts5_draw_tinted_bitmap(TS5_BITMAP *map, TS5_COLOR tint, double dx, double dy)
Draw a tinted bitmap.
double ts5_get_bitmap_height(TS5_BITMAP *map)
Get the height of a bitmap in pixels.
TS5_BITMAP * ts5_set_drawing_target(TS5_BITMAP *target)
Set the active drawing target.
void ts5_draw_rotated_bitmap(TS5_BITMAP *map, double cx, double cy, double angle, double dx, double dy)
Draw a rotated bitmap.
double ts5_relative_to_absolute_coordinate_x(const double x)
Convert a relative horizontal coordinate into an absolute horizontal coordinate.
void ts5_check_bitmaps(char *calling_function)
Do some checks at the start of each bitmap function.
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.
void ts5_draw_scaled_bitmap(TS5_BITMAP *map, double xratio, double yratio, double dx, double dy)
Draw a scaled bitmap.
void ts5_log(const unsigned int level, const char *format,...)
Send info to a logging window.
double ts5_cartesian_to_display_coordinate_x(const double x)
Convert a horizontal Cartesian coordinate into a horizontal display coordinate.
void ts5_clear_display()
Clear the current drawing target.
double ts5_cartesian_to_display_coordinate_y(const double y)
Convert a vertical Cartesian coordinate into a vertical display coordinate.
void ts5_check_bitmaps2(char *calling_function, TS5_BITMAP *map)
Do some checks at the start of each bitmap function.
TS5_BITMAP * ts5_get_drawing_target()
Get the active drawing target.
void ts5_fatal(const char *format,...)
Exit safely with an error message.
double ts5_relative_to_absolute_coordinate_y(const double y)
Convert a relative vertical coordinate into an absolute vertical coordinate.
void ts5_write_bitmap(const char *file, TS5_BITMAP *map)
Write a bitmap.
double ts5_get_target_width()
Get the total width of the drawing target in pixels.
double ts5_get_target_height()
Get the total height of the drawing target in pixels.
void ts5_get_bitmap_size(TS5_BITMAP *map, double *w, double *h)
Get the size of a bitmap in pixels.