12 #include "../include/tscope5/bitmaps.h"
13 #include "../include/tscope5/display.h"
14 #include "../include/tscope5/graphics.h"
15 #include "../include/tscope5/bitmaps_internal.h"
16 #include "../include/tscope5/system_internal.h"
17 #include "../include/tscope5/graphics_internal.h"
42 ts5_check_bitmaps(
"ts5_alloc_bitmap");
43 ts5_log(TS5_LOGLEVEL_2,
"ts5_alloc_bitmap(%f,%f)\n", w, h);
45 if (_ts5_status.graphics_status.coordinate_scale==TS5_RELATIVE_COORDINATES) {
46 w *= _ts5_status.graphics_status.target_width;
47 h *= _ts5_status.graphics_status.target_height;
51 map = al_create_bitmap(w, h);
54 ts5_fatal(
"ts5_alloc_bitmap: could not make bitmap\n");
76 ts5_check_bitmaps(
"ts5_read_bitmap");
77 ts5_log(TS5_LOGLEVEL_2,
"ts5_read_bitmap(%s)\n", file);
80 map = al_load_bitmap(file);
83 ts5_fatal(
"ts5_read_bitmap: could not read bitmap\n");
86 al_convert_bitmap(map);
106 ts5_check_bitmaps(
"ts5_write_bitmap");
107 ts5_log(TS5_LOGLEVEL_2,
"ts5_write_bitmap(%s,%p)\n", file, map);
109 if (!al_save_bitmap(file, map)) {
110 ts5_fatal(
"ts5_write_bitmap: could not write bitmap\n");
125 ts5_check_bitmaps(
"ts5_free_bitmap");
126 ts5_log(TS5_LOGLEVEL_2,
"ts5_free_bitmap(%p)\n", map);
128 al_destroy_bitmap(map);
158 ts5_check_bitmaps(
"ts5_get_bitmap_size");
159 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_bitmap_size(%p,%p,%p)\n", map, w, h);
162 ts5_fatal(
"ts5_get_bitmap_size: bitmap pointer is null\n");
167 ww = al_get_bitmap_width(map);
168 hh = al_get_bitmap_height(map);
170 if (_ts5_status.graphics_status.coordinate_scale==TS5_RELATIVE_COORDINATES) {
171 ww /= _ts5_status.graphics_status.target_width;
172 hh /= _ts5_status.graphics_status.target_height;
194 ts5_check_bitmaps(
"ts5_get_bitmap_width");
195 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_bitmap_width(%p)\n", map);
213 ts5_check_bitmaps(
"ts5_get_bitmap_height");
214 ts5_log(TS5_LOGLEVEL_5,
"ts5_get_bitmap_width(%d)\n", map);
248 ts5_check_bitmaps2(
"ts5_draw_bitmap", map);
249 ts5_log(TS5_LOGLEVEL_5,
"ts5_draw_bitmap(%p,%f,%f)\n", map, dx, dy);
251 if (_ts5_status.graphics_status.coordinate_scale == TS5_RELATIVE_COORDINATES) {
256 if (_ts5_status.graphics_status.coordinate_system == TS5_CARTESIAN_COORDINATES) {
261 al_draw_bitmap(map, dx, dy, 0);
275 ts5_check_bitmaps2(
"ts5_draw_flipped_bitmap", map);
276 ts5_log(TS5_LOGLEVEL_5,
"ts5_draw_flipped_bitmap(%p,%f,%f,%d)\n", map, dx, dy, flip);
278 if (flip != TS5_FLIP_HORIZONTAL && flip != TS5_FLIP_VERTICAL && flip != TS5_FLIP_BOTH) {
279 ts5_fatal(
"ts5_draw_flipped_bitmap: flip should be",
280 " TS5_FLIP_HORIZONTAL, TS5_FLIP_VERTICAL or TS5_FLIP_BOTH\n");
283 if (_ts5_status.graphics_status.coordinate_scale == TS5_RELATIVE_COORDINATES) {
288 if (_ts5_status.graphics_status.coordinate_system == TS5_CARTESIAN_COORDINATES) {
293 al_draw_bitmap(map, dx, dy, flip);
307 ts5_check_bitmaps2(
"ts5_draw_tinted_bitmap", map);
308 ts5_log(TS5_LOGLEVEL_5,
"ts5_draw_tinted_bitmap(%p,(%f,%f,%f,%f),%f,%f)\n",
309 map, tint.r, tint.g, tint.b, tint.a, dx, dy);
311 if (_ts5_status.graphics_status.coordinate_scale == TS5_RELATIVE_COORDINATES) {
316 if (_ts5_status.graphics_status.coordinate_system == TS5_CARTESIAN_COORDINATES) {
321 al_draw_tinted_bitmap(map, tint, dx, dy, 0);
337 double dx,
double dy)
339 ts5_check_bitmaps2(
"ts5_draw_bitmap_region", map);
340 ts5_log(TS5_LOGLEVEL_5,
"ts5_draw_bitmap_region(%p,%f,%f,%f,%f,%f,%f)\n",
341 map, sx1, sy1, sx2, sy2, dx, dy);
343 if (_ts5_status.graphics_status.coordinate_scale == TS5_RELATIVE_COORDINATES) {
354 double width = abs(sx2 - sx1);
355 double height = abs(sy2 - sy1);
356 double x = sx1 < sx2 ? sx1 : sx2;
357 double y = sy1 < sy2 ? sy1 : sy2;
359 if (_ts5_status.graphics_status.coordinate_system == TS5_CARTESIAN_COORDINATES) {
362 x = x + al_get_bitmap_width(map) / 2.0;
363 y = y + al_get_bitmap_height(map) / 2.0;
366 al_draw_bitmap_region(map, x, y, width, height, dx, dy, 0);
384 ts5_check_bitmaps2(
"ts5_draw_rotated_bitmap", map);
385 ts5_log(TS5_LOGLEVEL_5,
"ts5_draw_rotated_bitmap(%p,%f,%f,%f,%f,%f)\n", map, cx, cy, angle, dx, dy);
387 if (_ts5_status.graphics_status.coordinate_scale == TS5_RELATIVE_COORDINATES) {
396 if (_ts5_status.graphics_status.coordinate_system == TS5_CARTESIAN_COORDINATES) {
399 cx = al_get_bitmap_width(map) / 2.0 + cx;
400 cy = al_get_bitmap_height(map) / 2.0 - cy;
403 angle = angle * TS5_PI / 180.0;
405 al_draw_rotated_bitmap(map, cx, cy, dx, dy, angle, 0);
420 ts5_check_bitmaps2(
"ts5_draw_scaled_bitmap", map);
421 ts5_log(TS5_LOGLEVEL_5,
"ts5_draw_scaled_bitmap(%p,%f,%f,%f,%f)\n", map, xratio, yratio, dx, dy);
423 double h = al_get_bitmap_height(map);
424 double w = al_get_bitmap_width(map);
426 if (_ts5_status.graphics_status.coordinate_scale == TS5_RELATIVE_COORDINATES) {
431 if (_ts5_status.graphics_status.coordinate_system == TS5_CARTESIAN_COORDINATES) {
436 al_draw_scaled_bitmap(map, 0.0, 0.0, w, h, dx, dy, w * xratio, h * yratio, 0);