Tscope5
bitmaps.c
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // __ ______
4 // / /_______________ ____ ___ / ____/
5 // / __/ ___/ ___/ __ \/ __ \/ _ \ /___ )
6 // / /_(__ ) /__/ /_/ / /_/ / __/ ____/ /
7 // \__/____/\___/\____/ .___/\___/ /_____/
8 // /_/
9 //
10 /// \file bitmaps.c
11 /// Definitions of bitmap functions.
12 /// \example bitmaps01.c
13 /// \example bitmaps02.c
14 /// \example bitmaps03.c
15 /// \example bitmaps04.c
16 /// \example bitmaps05.c
17 ////////////////////////////////////////////////////////////////////////////////
18 
19 
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"
27 
28 #include <math.h>
29 
30 
31 ////////////////////////////////////////////////////////////////////////////////
32 /// @name Loading bitmaps
33 /// Bitmaps can either be read from a file, or empty bitmaps can be generated.
34 //@{
35 ////////////////////////////////////////////////////////////////////////////////
36 
37 
38 ////////////////////////////////////////////////////////////////////////////////
39 /// Create a bitmap.
40 ///
41 /// \param w Width of the bitmap.
42 /// \param h Height of the bitmap.
43 ///
44 /// \return A pointer to the newly created bitmap.
45 ///
46 /// The default background color of the newly created bitmap
47 /// is the same as the display.
48 ////////////////////////////////////////////////////////////////////////////////
49 TS5_BITMAP *ts5_alloc_bitmap(double w, double h)
50 {
51  ts5_check_bitmaps("ts5_alloc_bitmap");
52  ts5_log(TS5_LOGLEVEL_2, "ts5_alloc_bitmap(%f,%f)\n", w, h);
53 
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;
58  }
59 
60  w *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
61  h *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
62 
63  TS5_BITMAP *map;
64  map = al_create_bitmap(w, h);
65 
66  if (map == NULL) {
67  ts5_fatal("ts5_alloc_bitmap: could not make bitmap\n");
68  }
69 
70  TS5_BITMAP *oldval = ts5_set_drawing_target(map);
72  ts5_set_drawing_target(oldval);
73 
74  return map;
75 }
76 
77 
78 ////////////////////////////////////////////////////////////////////////////////
79 /// Open a bitmap from a file.
80 ///
81 /// \param file Path to the bitmap file.
82 ///
83 /// \return A pointer to the newly created bitmap.
84 ///
85 /// Available bitmap types are: bmp, pcx, tga, jpeg and png.
86 ////////////////////////////////////////////////////////////////////////////////
87 TS5_BITMAP *ts5_read_bitmap(const char *file)
88 {
89  ts5_check_bitmaps("ts5_read_bitmap");
90  ts5_log(TS5_LOGLEVEL_2, "ts5_read_bitmap(%s)\n", file);
91 
92  TS5_BITMAP *map1, *map2;
93  map1 = al_load_bitmap(file);
94 
95  if (map1 == NULL) {
96  ts5_fatal("ts5_read_bitmap: could not read bitmap\n");
97  }
98 
99  al_convert_bitmap(map1);
100 
101  double w1 = al_get_bitmap_width(map1);
102  double h1 = al_get_bitmap_height(map1);
103 
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;
106 
107  map2 = al_create_bitmap(w2, h2);
108 
109  TS5_BITMAP *oldmap = ts5_set_drawing_target(map2);
110 
111  al_draw_scaled_bitmap(map1, 0.0, 0.0, w1, h1,
112  0.0, 0.0, w2, h2, 0);
113 
114  ts5_set_drawing_target(oldmap);
115  al_destroy_bitmap(map1);
116 
117  return map2;
118 }
119 
120 
121 ////////////////////////////////////////////////////////////////////////////////
122 /// Write a bitmap.
123 ///
124 /// \param file Path to the bitmap file.
125 /// \param map Pointer to the bitmap that will be written.
126 ///
127 /// The extension specifies the file type.
128 /// Available bitmap types are: bmp, pcx, tga, jpeg and png.
129 ///
130 /// Useful for saving screenshots of the experiment.
131 ///
132 /// Useful for creating complex stimuli beforehand.
133 ////////////////////////////////////////////////////////////////////////////////
134 void ts5_write_bitmap(const char *file, TS5_BITMAP *map)
135 {
136  ts5_check_bitmaps("ts5_write_bitmap");
137  ts5_log(TS5_LOGLEVEL_2, "ts5_write_bitmap(%s,%p)\n", file, map);
138 
139  double w, w2, h, h2;
140  ts5_get_bitmap_size(map, &w, &h);
141 
142  w2 = w;
143  h2 = h;
144 
145  w *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
146  h *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
147 
148  TS5_BITMAP *map2 = al_create_bitmap(w2, h2);
149 
150  TS5_BITMAP *oldmap = ts5_set_drawing_target(map2);
151 
152  al_draw_scaled_bitmap(map, 0.0, 0.0, w, h,
153  0.0, 0.0, w2, h2, 0);
154 
155  ts5_set_drawing_target(oldmap);
156 
157  if (!al_save_bitmap(file, map2)) {
158  ts5_fatal("ts5_write_bitmap: could not write bitmap\n");
159  }
160  al_destroy_bitmap(map2);
161 }
162 
163 
164 ////////////////////////////////////////////////////////////////////////////////
165 /// Free the memory used by a bitmap.
166 ///
167 /// \param map pointer to the bitmap that will be freed.
168 ///
169 /// This function should be called at the end of the program for
170 /// each bitmap allocated or read by the user.
171 ////////////////////////////////////////////////////////////////////////////////
172 void ts5_free_bitmap(TS5_BITMAP *map)
173 {
174  ts5_check_bitmaps("ts5_free_bitmap");
175  ts5_log(TS5_LOGLEVEL_2, "ts5_free_bitmap(%p)\n", map);
176 
177  al_destroy_bitmap(map);
178  map = NULL;
179 }
180 
181 
182 ////////////////////////////////////////////////////////////////////////////////
183 //@}
184 ////////////////////////////////////////////////////////////////////////////////
185 
186 
187 ////////////////////////////////////////////////////////////////////////////////
188 /// @name Query bitmap dimensions
189 /// The dimensions of a bitmap can be queried using the functions below:
190 //@{
191 ////////////////////////////////////////////////////////////////////////////////
192 
193 
194 ////////////////////////////////////////////////////////////////////////////////
195 /// Get the size of a bitmap in pixels.
196 ///
197 /// \param map The bitmap that will be queried.
198 /// \param w Variable that will store the width.
199 /// \param h Variable that will store the height.
200 ///
201 /// You can pass NULL for values you are not interested in.
202 ///
203 /// ts5_alloc_bitmap(), ts5_read_bitmap(), primitives.c, textio.c
204 ////////////////////////////////////////////////////////////////////////////////
205 void ts5_get_bitmap_size(TS5_BITMAP *map, double *w, double *h)
206 {
207  ts5_check_bitmaps("ts5_get_bitmap_size");
208  ts5_log(TS5_LOGLEVEL_5, "ts5_get_bitmap_size(%p,%p,%p)\n", map, w, h);
209 
210  if (!map) {
211  ts5_fatal("ts5_get_bitmap_size: bitmap pointer is null\n");
212  }
213 
214  if (w) {
215  *w = al_get_bitmap_width(map) /
216  _ts5_status.display[_ts5_status.active_display].sampling_factor;
217  }
218 
219  if (h) {
220  *h = al_get_bitmap_height(map) /
221  _ts5_status.display[_ts5_status.active_display].sampling_factor;
222  }
223 }
224 
225 
226 ////////////////////////////////////////////////////////////////////////////////
227 /// Get the width of a bitmap in pixels.
228 ///
229 /// \param map The bitmap that will be queried.
230 ///
231 /// \return The width of the bitmap.
232 ////////////////////////////////////////////////////////////////////////////////
233 double ts5_get_bitmap_width(TS5_BITMAP *map)
234 {
235  ts5_check_bitmaps("ts5_get_bitmap_width");
236  ts5_log(TS5_LOGLEVEL_5, "ts5_get_bitmap_width(%p)\n", map);
237 
238  double w;
239  ts5_get_bitmap_size(map, &w, NULL);
240 
241  return w;
242 }
243 
244 
245 ////////////////////////////////////////////////////////////////////////////////
246 /// Get the height of a bitmap in pixels.
247 ///
248 /// \param map The bitmap that will be queried.
249 ///
250 /// \return The height of the bitmap.
251 ////////////////////////////////////////////////////////////////////////////////
252 double ts5_get_bitmap_height(TS5_BITMAP *map)
253 {
254  ts5_check_bitmaps("ts5_get_bitmap_height");
255  ts5_log(TS5_LOGLEVEL_5, "ts5_get_bitmap_width(%d)\n", map);
256 
257  double h;
258  ts5_get_bitmap_size(map, NULL, &h);
259 
260  return h;
261 }
262 
263 
264 ////////////////////////////////////////////////////////////////////////////////
265 //@}
266 ////////////////////////////////////////////////////////////////////////////////
267 
268 
269 ////////////////////////////////////////////////////////////////////////////////
270 /// @name Drawing on bitmaps
271 /// Text/primitives output that is normally drawn on the display can
272 /// be redirected to a bitmap.
273 //@{
274 ////////////////////////////////////////////////////////////////////////////////
275 
276 
277 ////////////////////////////////////////////////////////////////////////////////
278 /// Set the active drawing target.
279 ///
280 /// \param target Pointer to the bitmap that will be used
281 /// for drawing operations.
282 ///
283 /// \return A pointer to the previous active drawing target.
284 ////////////////////////////////////////////////////////////////////////////////
285 TS5_BITMAP *ts5_set_drawing_target(TS5_BITMAP * target)
286 {
287  ts5_check_display("ts5_set_drawing_target");
288  ts5_log(TS5_LOGLEVEL_4, "ts5_set_drawing_target(%p)\n", target);
289 
290  if (target == NULL) {
291  ts5_fatal("ts5_set_drawing_target: target is a NULL pointer\n");
292  }
293 
294  TS5_BITMAP *retval = _ts5_data.target;
295  _ts5_data.target = target;
296  al_set_target_bitmap(_ts5_data.target);
297 
298  _ts5_status.graphics.target_width =
299  ts5_get_bitmap_width(_ts5_data.target);
300 
301  _ts5_status.graphics.target_height =
302  ts5_get_bitmap_height(_ts5_data.target);
303 
304  return retval;
305 }
306 
307 
308 ////////////////////////////////////////////////////////////////////////////////
309 /// Get the active drawing target.
310 ///
311 /// \return A pointer to the active drawing target.
312 ////////////////////////////////////////////////////////////////////////////////
314 {
315  ts5_check_display("ts5_get_drawing_target");
316  ts5_log(TS5_LOGLEVEL_4, "ts5_get_drawing_target()\n");
317 
318  return _ts5_data.target;
319 }
320 
321 
322 ////////////////////////////////////////////////////////////////////////////////
323 /// Get the total size of the drawing target in pixels.
324 ///
325 /// \param w Variable that will store the width.
326 /// \param h Variable that will store the height.
327 ///
328 /// The drawing target can be either a display or a memory bitmap.
329 ///
330 /// You can pass NULL for values you are not interested in.
331 ////////////////////////////////////////////////////////////////////////////////
332 void ts5_get_target_size(double *w, double *h)
333 {
334  ts5_check_graphics("ts5_get_target_size");
335  ts5_log(TS5_LOGLEVEL_4, "ts5_get_target_size(%p,%p)\n", w, h);
336 
337  if (w) {
338  *w = _ts5_status.graphics.target_width;
339  }
340 
341  if (h) {
342  *h = _ts5_status.graphics.target_height;
343  }
344 }
345 
346 
347 ////////////////////////////////////////////////////////////////////////////////
348 /// Get the total width of the drawing target in pixels.
349 ///
350 /// \return the width of the drawing target.
351 ///
352 /// The drawing target can be either a display or a memory bitmap.
353 ////////////////////////////////////////////////////////////////////////////////
355 {
356  ts5_check_graphics("ts5_get_target_width");
357  ts5_log(TS5_LOGLEVEL_4, "ts5_get_target_width()\n");
358 
359  double w;
360  ts5_get_target_size(&w, NULL);
361 
362  return w;
363 }
364 
365 
366 ////////////////////////////////////////////////////////////////////////////////
367 /// Get the total height of the drawing target in pixels.
368 ///
369 /// \return the height of the drawing target.
370 ///
371 /// The drawing target can be either a display or a memory bitmap.
372 ////////////////////////////////////////////////////////////////////////////////
374 {
375  ts5_check_graphics("ts5_get_target_height");
376  ts5_log(TS5_LOGLEVEL_4, "ts5_get_target_height()\n");
377 
378  double h;
379  ts5_get_target_size(NULL, &h);
380 
381  return h;
382 
383 }
384 
385 
386 ////////////////////////////////////////////////////////////////////////////////
387 //@}
388 ////////////////////////////////////////////////////////////////////////////////
389 
390 
391 ////////////////////////////////////////////////////////////////////////////////
392 /// @name Drawing bitmaps on the display
393 ///
394 /// The destination coordinates of the bitmap drawing functions below are
395 /// interpreted dependent on the coordinate system used.
396 /// - When using the Cartesian coordinate system,
397 /// bitmaps are centered around the destination coordinates.
398 /// - When using the Display coordinate system,
399 /// the destination coordinates correspond to the
400 /// upper left corner of the bitmap.
401 //@{
402 ////////////////////////////////////////////////////////////////////////////////
403 
404 
405 ////////////////////////////////////////////////////////////////////////////////
406 /// Draw a bitmap.
407 ///
408 /// \param map The bitmap that will be drawn.
409 /// \param dx Horizontal position where it will be drawn.
410 /// \param dy Vertical position where it will be drawn.
411 ////////////////////////////////////////////////////////////////////////////////
412 void ts5_draw_bitmap(TS5_BITMAP *map, double dx, double dy)
413 {
414  ts5_check_bitmaps2("ts5_draw_bitmap", map);
415  ts5_log(TS5_LOGLEVEL_5, "ts5_draw_bitmap(%p,%f,%f)\n", map, dx, dy);
416 
417  if (_ts5_status.graphics.coordinate_scale
418  == TS5_RELATIVE_COORDINATES) {
421  }
422 
423  if (_ts5_status.graphics.coordinate_system
424  == TS5_CARTESIAN_COORDINATES) {
425 
427  - ts5_get_bitmap_width(map) / 2.0;
428 
430  - ts5_get_bitmap_height(map) / 2.0;
431  }
432 
433  dx *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
434  dy *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
435 
436  al_draw_bitmap(map, dx, dy, 0);
437 }
438 
439 
440 ////////////////////////////////////////////////////////////////////////////////
441 /// Draw a flipped bitmap.
442 ///
443 /// \param map The bitmap that will be drawn.
444 /// \param dx Horizontal position where it will be drawn.
445 /// \param dy Vertical position where it will be drawn.
446 /// \param flip Direction of the flip.
447 /// Can be TS5_FLIP_HORIZONTAL, TS5_FLIP_VERTICAL or TS5_FLIP_BOTH.
448 ////////////////////////////////////////////////////////////////////////////////
449 void ts5_draw_flipped_bitmap(TS5_BITMAP *map, double dx, double dy,
450  const int flip)
451 {
452  ts5_check_bitmaps2("ts5_draw_flipped_bitmap", map);
453  ts5_log(TS5_LOGLEVEL_5, "ts5_draw_flipped_bitmap(%p,%f,%f,%d)\n",
454  map, dx, dy, flip);
455 
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");
461  }
462 
463  if (_ts5_status.graphics.coordinate_scale
464  == TS5_RELATIVE_COORDINATES) {
467  }
468 
469  if (_ts5_status.graphics.coordinate_system
470  == TS5_CARTESIAN_COORDINATES) {
471 
473  - ts5_get_bitmap_width(map) / 2.0;
474 
476  - ts5_get_bitmap_height(map) / 2.0;
477  }
478 
479  dx *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
480  dy *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
481 
482  al_draw_bitmap(map, dx, dy, flip);
483 }
484 
485 
486 ////////////////////////////////////////////////////////////////////////////////
487 /// Draw a tinted bitmap.
488 ///
489 /// \param map The bitmap that will be drawn.
490 /// \param tint The tint color.
491 /// All colors in the bitmap are multiplied with the color specified in tint.
492 /// \param dx Horizontal position where it will be drawn.
493 /// \param dy Vertical position where it will be drawn.
494 ////////////////////////////////////////////////////////////////////////////////
495 void ts5_draw_tinted_bitmap(TS5_BITMAP *map, TS5_COLOR tint,
496  double dx, double dy)
497 {
498  ts5_check_bitmaps2("ts5_draw_tinted_bitmap", map);
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);
501 
502  if (_ts5_status.graphics.coordinate_scale
503  == TS5_RELATIVE_COORDINATES) {
506  }
507 
508  if (_ts5_status.graphics.coordinate_system
509  == TS5_CARTESIAN_COORDINATES) {
510 
512  - ts5_get_bitmap_width(map) / 2.0;
513 
515  - ts5_get_bitmap_height(map) / 2.0;
516  }
517 
518  dx *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
519  dy *= _ts5_status.display[_ts5_status.active_display].sampling_factor;
520 
521  al_draw_tinted_bitmap(map, tint, dx, dy, 0);
522 }
523 
524 
525 ////////////////////////////////////////////////////////////////////////////////
526 /// Draw a region of a bitmap.
527 ///
528 /// \param map The bitmap that will be drawn.
529 /// \param sx1 Horizontal coordinate of the first corner or the region.
530 /// \param sy1 Vertical coordinate of the first corner or the region.
531 /// \param sx2 Horizontal coordinate of the second corner or the region.
532 /// \param sy2 Vertical coordinate of the second corner or the region.
533 /// \param dx Horizontal position where it will be drawn.
534 /// \param dy Vertical position where it will be drawn.
535 ////////////////////////////////////////////////////////////////////////////////
536 void ts5_draw_bitmap_region(TS5_BITMAP *map, double sx1, double sy1,
537  double sx2, double sy2, double dx, double dy)
538 {
539  ts5_check_bitmaps2("ts5_draw_bitmap_region", map);
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);
542 
543  if (_ts5_status.graphics.coordinate_scale
544  == TS5_RELATIVE_COORDINATES) {
547  TS5_BITMAP *oldval = ts5_set_drawing_target (map);
552  ts5_set_drawing_target(oldval);
553  }
554 
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;
559 
560  if (_ts5_status.graphics.coordinate_system
561  == TS5_CARTESIAN_COORDINATES) {
562  dx = ts5_cartesian_to_display_coordinate_x(dx - width / 2.0);
563  dy = ts5_cartesian_to_display_coordinate_y(height / 2.0 - dy);
564  x = x + ts5_get_bitmap_width(map) / 2.0;
565  y = y + ts5_get_bitmap_height(map) / 2.0;
566  }
567 
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;
574 
575 
576  al_draw_bitmap_region(map, x, y, width, height, dx, dy, 0);
577 }
578 
579 
580 ////////////////////////////////////////////////////////////////////////////////
581 /// Draw a rotated bitmap.
582 ///
583 /// \param map The bitmap that will be drawn.
584 /// \param cx Horizontal coordinate of the center of rotation.
585 /// \param cy Certical coordinate of the center of rotation.
586 /// \param angle The angle of rotation in degrees
587 /// (positive is counter clockwise, negative is clockwise).
588 /// \param dx Horizontal position where it will be drawn.
589 /// \param dy Vertical position where it will be drawn.
590 ///
591 /// The center of rotation (cx,cy) will be drawn at (dx,dy).
592 ////////////////////////////////////////////////////////////////////////////////
593 void ts5_draw_rotated_bitmap(TS5_BITMAP *map, double cx, double cy,
594  double angle, double dx, double dy)
595 {
596  ts5_check_bitmaps2("ts5_draw_rotated_bitmap", map);
597  ts5_log(TS5_LOGLEVEL_5, "ts5_draw_rotated_bitmap(%p,%f,%f,%f,%f,%f)\n",
598  map, cx, cy, angle, dx, dy);
599 
600  if (_ts5_status.graphics.coordinate_scale
601  == TS5_RELATIVE_COORDINATES) {
604  TS5_BITMAP *oldval = ts5_set_drawing_target (map);
607  ts5_set_drawing_target(oldval);
608  }
609 
610  if (_ts5_status.graphics.coordinate_system
611  == TS5_CARTESIAN_COORDINATES) {
614  cx = ts5_get_bitmap_width(map) / 2.0 + cx;
615  cy = ts5_get_bitmap_height(map) / 2.0 - cy;
616  }
617 
618  angle = - angle * TS5_PI / 180.0;
619 
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;
624 
625  al_draw_rotated_bitmap(map, cx, cy, dx, dy, angle, 0);
626 }
627 
628 
629 ////////////////////////////////////////////////////////////////////////////////
630 /// Draw a scaled bitmap.
631 ///
632 /// \param map The bitmap that will be drawn.
633 /// \param xratio The scaling factor in the horizontal direction.
634 /// \param yratio The scaling factor in the vertical direction.
635 /// \param dx Horizontal position where it will be drawn.
636 /// \param dy Vertical position where it will be drawn.
637 ////////////////////////////////////////////////////////////////////////////////
638 void ts5_draw_scaled_bitmap(TS5_BITMAP *map, double xratio, double yratio,
639  double dx, double dy)
640 {
641  ts5_check_bitmaps2("ts5_draw_scaled_bitmap", map);
642  ts5_log(TS5_LOGLEVEL_5, "ts5_draw_scaled_bitmap(%p,%f,%f,%f,%f)\n",
643  map, xratio, yratio, dx, dy);
644 
645  double w = ts5_get_bitmap_width(map);
646  double h = ts5_get_bitmap_height(map);
647 
648  if (_ts5_status.graphics.coordinate_scale
649  == TS5_RELATIVE_COORDINATES) {
652  }
653 
654  if (_ts5_status.graphics.coordinate_system
655  == TS5_CARTESIAN_COORDINATES) {
656  dx = ts5_cartesian_to_display_coordinate_x(dx) - w * xratio / 2.0;
657  dy = ts5_cartesian_to_display_coordinate_y(dy) - h * yratio / 2.0;
658  }
659 
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;
664 
665  al_draw_scaled_bitmap(map, 0.0, 0.0, w, h, dx, dy,
666  w * xratio, h * yratio, 0);
667 }
668 
TS5_BITMAP * ts5_read_bitmap(const char *file)
Open a bitmap from a file.
Definition: bitmaps.c:87
void ts5_draw_bitmap(TS5_BITMAP *map, double dx, double dy)
Draw a bitmap.
Definition: bitmaps.c:412
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.
Definition: bitmaps.c:449
void ts5_free_bitmap(TS5_BITMAP *map)
Free the memory used by a bitmap.
Definition: bitmaps.c:172
void ts5_get_target_size(double *w, double *h)
Get the total size of the drawing target in pixels.
Definition: bitmaps.c:332
double ts5_get_bitmap_width(TS5_BITMAP *map)
Get the width of a bitmap in pixels.
Definition: bitmaps.c:233
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.
Definition: bitmaps.c:49
void ts5_draw_tinted_bitmap(TS5_BITMAP *map, TS5_COLOR tint, double dx, double dy)
Draw a tinted bitmap.
Definition: bitmaps.c:495
double ts5_get_bitmap_height(TS5_BITMAP *map)
Get the height of a bitmap in pixels.
Definition: bitmaps.c:252
TS5_BITMAP * ts5_set_drawing_target(TS5_BITMAP *target)
Set the active drawing target.
Definition: bitmaps.c:285
void ts5_draw_rotated_bitmap(TS5_BITMAP *map, double cx, double cy, double angle, double dx, double dy)
Draw a rotated bitmap.
Definition: bitmaps.c:593
double ts5_relative_to_absolute_coordinate_x(const double x)
Convert a relative horizontal coordinate into an absolute horizontal coordinate.
Definition: graphics.c:208
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.
Definition: bitmaps.c:536
void ts5_draw_scaled_bitmap(TS5_BITMAP *map, double xratio, double yratio, double dx, double dy)
Draw a scaled bitmap.
Definition: bitmaps.c:638
void ts5_log(const unsigned int level, const char *format,...)
Send info to a logging window.
Definition: system.c:45
double ts5_cartesian_to_display_coordinate_x(const double x)
Convert a horizontal Cartesian coordinate into a horizontal display coordinate.
Definition: graphics.c:333
void ts5_clear_display()
Clear the current drawing target.
Definition: display.c:515
double ts5_cartesian_to_display_coordinate_y(const double y)
Convert a vertical Cartesian coordinate into a vertical display coordinate.
Definition: graphics.c:354
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.
Definition: bitmaps.c:313
void ts5_fatal(const char *format,...)
Exit safely with an error message.
Definition: system.c:533
double ts5_relative_to_absolute_coordinate_y(const double y)
Convert a relative vertical coordinate into an absolute vertical coordinate.
Definition: graphics.c:240
void ts5_write_bitmap(const char *file, TS5_BITMAP *map)
Write a bitmap.
Definition: bitmaps.c:134
double ts5_get_target_width()
Get the total width of the drawing target in pixels.
Definition: bitmaps.c:354
double ts5_get_target_height()
Get the total height of the drawing target in pixels.
Definition: bitmaps.c:373
void ts5_get_bitmap_size(TS5_BITMAP *map, double *w, double *h)
Get the size of a bitmap in pixels.
Definition: bitmaps.c:205