window.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*------------------------------------------------------------------------
  2. * Copyright 2007-2009 (c) Jeff Brown <spadix@users.sourceforge.net>
  3. *
  4. * This file is part of the ZBar Bar Code Reader.
  5. *
  6. * The ZBar Bar Code Reader is free software; you can redistribute it
  7. * and/or modify it under the terms of the GNU Lesser Public License as
  8. * published by the Free Software Foundation; either version 2.1 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * The ZBar Bar Code Reader is distributed in the hope that it will be
  12. * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  13. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser Public License
  17. * along with the ZBar Bar Code Reader; if not, write to the Free
  18. * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  19. * Boston, MA 02110-1301 USA
  20. *
  21. * http://sourceforge.net/projects/zbar
  22. *------------------------------------------------------------------------*/
  23. #ifndef _WINDOW_H_
  24. #define _WINDOW_H_
  25. #include <config.h>
  26. #ifdef HAVE_INTTYPES_H
  27. # include <inttypes.h>
  28. #endif
  29. ///#include <stdlib.h>
  30. #ifdef WIN32
  31. #include <stdint.h>
  32. #endif
  33. #include <zbar.h>
  34. #include "symbol.h"
  35. #include "error.h"
  36. #include "mutex.h"
  37. typedef struct window_state_s window_state_t;
  38. struct zbar_window_s {
  39. errinfo_t err; /* error reporting */
  40. zbar_image_t *image; /* last displayed image
  41. * NB image access must be locked!
  42. */
  43. unsigned overlay; /* user set overlay level */
  44. uint32_t format; /* output format */
  45. unsigned width, height; /* current output size */
  46. unsigned max_width, max_height;
  47. uint32_t src_format; /* current input format */
  48. unsigned src_width; /* last displayed image size */
  49. unsigned src_height;
  50. unsigned dst_width; /* conversion target */
  51. unsigned dst_height;
  52. unsigned scale_num; /* output scaling */
  53. unsigned scale_den;
  54. point_t scaled_offset; /* output position and size */
  55. point_t scaled_size;
  56. uint32_t *formats; /* supported formats (zero terminated) */
  57. zbar_mutex_t imglock; /* lock displayed image */
  58. void *display;
  59. unsigned long xwin;
  60. unsigned long time; /* last image display in milliseconds */
  61. unsigned long time_avg; /* average of inter-frame times */
  62. window_state_t *state; /* platform/interface specific state */
  63. /* interface dependent methods */
  64. int (*init)(zbar_window_t*, zbar_image_t*, int);
  65. int (*draw_image)(zbar_window_t*, zbar_image_t*);
  66. int (*cleanup)(zbar_window_t*);
  67. };
  68. /* window.draw has to be thread safe wrt/other apis
  69. * FIXME should be a semaphore
  70. */
  71. static inline int window_lock (zbar_window_t *w)
  72. {
  73. int rc = 0;
  74. if((rc = _zbar_mutex_lock(&w->imglock))) {
  75. err_capture(w, SEV_FATAL, ZBAR_ERR_LOCKING, __func__,
  76. "unable to acquire lock");
  77. w->err.errnum = rc;
  78. return(-1);
  79. }
  80. return(0);
  81. }
  82. static inline int window_unlock (zbar_window_t *w)
  83. {
  84. int rc = 0;
  85. if((rc = _zbar_mutex_unlock(&w->imglock))) {
  86. err_capture(w, SEV_FATAL, ZBAR_ERR_LOCKING, __func__,
  87. "unable to release lock");
  88. w->err.errnum = rc;
  89. return(-1);
  90. }
  91. return(0);
  92. }
  93. static inline int _zbar_window_add_format (zbar_window_t *w,
  94. uint32_t fmt)
  95. {
  96. int i;
  97. for(i = 0; w->formats && w->formats[i]; i++)
  98. if(w->formats[i] == fmt)
  99. return(i);
  100. w->formats = realloc(w->formats, (i + 2) * sizeof(uint32_t));
  101. w->formats[i] = fmt;
  102. w->formats[i + 1] = 0;
  103. return(i);
  104. }
  105. static inline point_t window_scale_pt (zbar_window_t *w,
  106. point_t p)
  107. {
  108. p.x = ((long)p.x * w->scale_num + w->scale_den - 1) / w->scale_den;
  109. p.y = ((long)p.y * w->scale_num + w->scale_den - 1) / w->scale_den;
  110. return(p);
  111. }
  112. /* PAL interface */
  113. extern int _zbar_window_attach(zbar_window_t*, void*, unsigned long);
  114. extern int _zbar_window_expose(zbar_window_t*, int, int, int, int);
  115. extern int _zbar_window_resize(zbar_window_t*);
  116. extern int _zbar_window_clear(zbar_window_t*);
  117. extern int _zbar_window_begin(zbar_window_t*);
  118. extern int _zbar_window_end(zbar_window_t*);
  119. extern int _zbar_window_draw_marker(zbar_window_t*, uint32_t, point_t);
  120. extern int _zbar_window_draw_polygon(zbar_window_t*, uint32_t, const point_t*, int);
  121. extern int _zbar_window_draw_text(zbar_window_t*, uint32_t,
  122. point_t, const char*);
  123. extern int _zbar_window_fill_rect(zbar_window_t*, uint32_t, point_t, point_t);
  124. extern int _zbar_window_draw_logo(zbar_window_t*);
  125. #endif