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"
50 ts5_log(TS5_LOGLEVEL_2,
"ts5_alloc_bitmap(%f,%f)\n", w, h);
52 if (_ts5_status.graphics.coordinate_scale
53 == TS5_RELATIVE_COORDINATES) {
54 w *= _ts5_status.graphics.target_width;
55 h *= _ts5_status.graphics.target_height;
59 map = al_create_bitmap(w, h);
62 ts5_fatal(
"ts5_alloc_bitmap: could not make bitmap\n");
85 ts5_log(TS5_LOGLEVEL_2,
"ts5_read_bitmap(%s)\n", file);
88 map = al_load_bitmap(file);
91 ts5_fatal(
"ts5_read_bitmap: could not read bitmap\n");
94 al_convert_bitmap(map);
116 ts5_log(TS5_LOGLEVEL_2,
"ts5_write_bitmap(%s,%p)\n", file, map);
118 if (!al_save_bitmap(file, map)) {
119 ts5_fatal(
"ts5_write_bitmap: could not write bitmap\n");
135 ts5_log(TS5_LOGLEVEL_2,
"ts5_free_bitmap(%p)\n", map);
137 al_destroy_bitmap(map);
168 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_bitmap_size(%p,%p,%p)\n", map, w, h);
171 ts5_fatal(
"ts5_get_bitmap_size: bitmap pointer is null\n");
175 *w = al_get_bitmap_width(map);
179 *h = al_get_bitmap_height(map);
194 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_bitmap_width(%p)\n", map);
213 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_bitmap_width(%d)\n", map);
246 ts5_log(TS5_LOGLEVEL_4,
"ts5_set_drawing_target(%p)\n", target);
248 if (target == NULL) {
249 ts5_fatal(
"ts5_set_drawing_target: target is a NULL pointer\n");
252 TS5_BITMAP *retval = _ts5_data.target;
253 _ts5_data.target = target;
254 al_set_target_bitmap(_ts5_data.target);
256 _ts5_status.graphics.target_width =
257 al_get_bitmap_width(_ts5_data.target);
259 _ts5_status.graphics.target_height =
260 al_get_bitmap_height(_ts5_data.target);
274 ts5_log(TS5_LOGLEVEL_4,
"ts5_get_drawing_target()\n");
276 return _ts5_data.target;
293 ts5_log(TS5_LOGLEVEL_4,
"ts5_get_target_size(%p,%p)\n", w, h);
296 *w = _ts5_status.graphics.target_width;
300 *h = _ts5_status.graphics.target_height;
315 ts5_log(TS5_LOGLEVEL_4,
"ts5_get_target_width()\n");
334 ts5_log(TS5_LOGLEVEL_4,
"ts5_get_target_height()\n");
373 ts5_log(TS5_LOGLEVEL_5,
"ts5_draw_bitmap(%p,%f,%f)\n", map, dx, dy);
375 if (_ts5_status.graphics.coordinate_scale
376 == TS5_RELATIVE_COORDINATES) {
381 if (_ts5_status.graphics.coordinate_system
382 == TS5_CARTESIAN_COORDINATES) {
385 - al_get_bitmap_width(map) / 2.0;
388 - al_get_bitmap_height(map) / 2.0;
391 al_draw_bitmap(map, dx, dy, 0);
408 ts5_log(TS5_LOGLEVEL_5,
"ts5_draw_flipped_bitmap(%p,%f,%f,%d)\n",
411 if (flip != TS5_FLIP_HORIZONTAL && flip != TS5_FLIP_VERTICAL
412 && flip != TS5_FLIP_BOTH) {
413 ts5_fatal(
"%s: %s %s\n",
"ts5_draw_flipped_bitmap",
414 "flip should be TS5_FLIP_HORIZONTAL,",
415 "TS5_FLIP_VERTICAL or TS5_FLIP_BOTH");
418 if (_ts5_status.graphics.coordinate_scale
419 == TS5_RELATIVE_COORDINATES) {
424 if (_ts5_status.graphics.coordinate_system
425 == TS5_CARTESIAN_COORDINATES) {
428 - al_get_bitmap_width(map) / 2.0;
431 - al_get_bitmap_height(map) / 2.0;
434 al_draw_bitmap(map, dx, dy, flip);
448 double dx,
double dy)
451 ts5_log(TS5_LOGLEVEL_5,
"ts5_draw_tinted_bitmap(%p,(%f,%f,%f,%f),%f,%f)\n",
452 map, tint.r, tint.g, tint.b, tint.a, dx, dy);
454 if (_ts5_status.graphics.coordinate_scale
455 == TS5_RELATIVE_COORDINATES) {
460 if (_ts5_status.graphics.coordinate_system
461 == TS5_CARTESIAN_COORDINATES) {
464 - al_get_bitmap_width(map) / 2.0;
467 - al_get_bitmap_height(map) / 2.0;
470 al_draw_tinted_bitmap(map, tint, dx, dy, 0);
486 double sx2,
double sy2,
double dx,
double dy)
489 ts5_log(TS5_LOGLEVEL_5,
"ts5_draw_bitmap_region(%p,%f,%f,%f,%f,%f,%f)\n",
490 map, sx1, sy1, sx2, sy2, dx, dy);
492 if (_ts5_status.graphics.coordinate_scale
493 == TS5_RELATIVE_COORDINATES) {
504 double width = abs(sx2 - sx1);
505 double height = abs(sy2 - sy1);
506 double x = sx1 < sx2 ? sx1 : sx2;
507 double y = sy1 < sy2 ? sy1 : sy2;
509 if (_ts5_status.graphics.coordinate_system
510 == TS5_CARTESIAN_COORDINATES) {
513 x = x + al_get_bitmap_width(map) / 2.0;
514 y = y + al_get_bitmap_height(map) / 2.0;
517 al_draw_bitmap_region(map, x, y, width, height, dx, dy, 0);
535 double angle,
double dx,
double dy)
538 ts5_log(TS5_LOGLEVEL_5,
"ts5_draw_rotated_bitmap(%p,%f,%f,%f,%f,%f)\n",
539 map, cx, cy, angle, dx, dy);
541 if (_ts5_status.graphics.coordinate_scale
542 == TS5_RELATIVE_COORDINATES) {
551 if (_ts5_status.graphics.coordinate_system
552 == TS5_CARTESIAN_COORDINATES) {
555 cx = al_get_bitmap_width(map) / 2.0 + cx;
556 cy = al_get_bitmap_height(map) / 2.0 - cy;
559 angle = - angle * TS5_PI / 180.0;
561 al_draw_rotated_bitmap(map, cx, cy, dx, dy, angle, 0);
575 double dx,
double dy)
578 ts5_log(TS5_LOGLEVEL_5,
"ts5_draw_scaled_bitmap(%p,%f,%f,%f,%f)\n",
579 map, xratio, yratio, dx, dy);
581 double h = al_get_bitmap_height(map);
582 double w = al_get_bitmap_width(map);
584 if (_ts5_status.graphics.coordinate_scale
585 == TS5_RELATIVE_COORDINATES) {
590 if (_ts5_status.graphics.coordinate_system
591 == TS5_CARTESIAN_COORDINATES) {
596 al_draw_scaled_bitmap(map, 0.0, 0.0, w, h, dx, dy,
597 w * xratio, h * yratio, 0);