CIOFrameGrabDefines.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. /*****************************************************************************
  2. * CIOFrameGrabDefines.h
  3. *****************************************************************************
  4. *
  5. * Project: HALCON/libhalcon
  6. * Description: Basic defines and type definitions of the
  7. * Image acquisition integration interface
  8. * (pure header, no CIOFrameGrabDefines.c file)
  9. * Attention: The types, defines, and constants defined in this file are
  10. * used by the hlib extension programming interface (hlibxpi).
  11. * Therefore, they must not be changed without considering the
  12. * effect on released IA interfaces.
  13. * So, for substantial changes the major version of the hlibxpi
  14. * must be increased and a strategy for handling old interfaces
  15. * is needed. I.e. appropriate wrapper have to be provided or
  16. * the collaboration must be rejected in a defined manner.
  17. *
  18. * (c) 1996-2020 by MVTec Software GmbH
  19. * www.mvtec.com
  20. *
  21. *****************************************************************************
  22. *
  23. *
  24. *****************************************************************************
  25. *
  26. * See also: "Image Acquisition Integration Programmer's Manual"
  27. *
  28. *****************************************************************************
  29. */
  30. #ifndef CIOFRAMEGRAB_DEFINES_H
  31. #define CIOFRAMEGRAB_DEFINES_H
  32. #ifndef HC_NO_FRAMEGRABBER
  33. /* FG_INTERFACE_VERSION identifies the HALCON integration interface version.
  34. * Since HALCON 13.0 this version number is basically fixed to 1300.
  35. * With HALCON 17.12 we introduced the new hlibxpi programming interface which
  36. * is mainly for managing interoperabilty of different versions of hlib and
  37. * extensions like the IA interfaces */
  38. # define FG_INTERFACE_VERSION 1300
  39. # define FG_NUM_RESERVED 20
  40. # ifndef HC_NO_FRAMEGRABBER
  41. # define FG_MAX_INST \
  42. 256 /* max. number of handles (instances) per class */
  43. # else
  44. # define FG_MAX_INST 1
  45. # endif
  46. # ifndef FG_PREFIX
  47. # if !defined(H_PARALLEL)
  48. # define FG_PREFIX "seqhAcq"
  49. # else
  50. # define FG_PREFIX "hAcq"
  51. # endif
  52. # endif
  53. # ifndef XL_SUFFIX
  54. # if defined(HC_LARGE_IMAGES)
  55. # define XL_SUFFIX "xl"
  56. # else
  57. # define XL_SUFFIX ""
  58. # endif
  59. # endif
  60. # define FG_QUERY_PORT 0 /* Query: Available port values */
  61. # define FG_QUERY_CAMERA_TYPE 1 /* Query: Available camera types */
  62. # define FG_QUERY_GENERAL 2 /* Query: General information */
  63. # define FG_QUERY_DEFAULTS 3 /* Query: Default values */
  64. # define FG_QUERY_PARAMETERS 4 /* Query: Additional parameters */
  65. # define FG_QUERY_INFO_BOARDS 5 /* Query: Actual installed boards */
  66. # define FG_QUERY_REVISION 6 /* Query: Interface revision */
  67. # define FG_QUERY_INFO_PARAMETERS 7 /* Query: Info to avail. parameters */
  68. # define FG_QUERY_FIELD 8 /* Query: Available field values */
  69. /* Query: Available bits per channel */
  70. # define FG_QUERY_BITS_PER_CHANNEL 9
  71. # define FG_QUERY_COLOR_SPACE 10 /* Query: Available color spaces */
  72. # define FG_QUERY_EXT_TRIGGER 11 /* Query: Available ext. trigger */
  73. # define FG_QUERY_DEVICE 12 /* Query: Available device values */
  74. # define FG_QUERY_PARAMETERS_RO 13 /* Query: Add. read-only parameters */
  75. # define FG_QUERY_PARAMETERS_WO 14 /* Query: Add. write-only parameters*/
  76. # define FG_QUERY_IMAGE_HEIGHT 15 /* Query: Available image_height */
  77. # define FG_QUERY_IMAGE_WIDTH 16 /* Query: Available image_widht */
  78. # define FG_QUERY_START_ROW 17 /* Query: Available start_row values*/
  79. # define FG_QUERY_START_COLUMN 18 /* Query: Available start_column */
  80. /* Query: horizontal_resolution */
  81. # define FG_QUERY_HORIZONTAL_RESOLUTION 19
  82. # define FG_QUERY_VERTICAL_RESOLUTION 20 /* Query: vertical resolution */
  83. # define FG_QUERY_LINE_IN 21 /* Query: Available line_in values */
  84. /* Query: Not for display in generic GUI */
  85. # define FG_QUERY_PARAMETERS_HIDDEN 22
  86. # define FG_QUERY_GENERIC 23 /* Query: Available generic values */
  87. # define FG_FIRST_FIELD 0 /* grab first field */
  88. # define FG_SECOND_FIELD 1 /* grab second field */
  89. # define FG_NEXT_FIELD 3 /* grab next field */
  90. # define FG_FULL_FRAME 2 /* grab frame / interlaced */
  91. # define FG_PROGRESSIVE_FRAME 4 /* grab frame / progressive */
  92. # define FG_FIELD_DEFAULT 5 /* default */
  93. /* corresponding text encoding: */
  94. # define FG_FIRST_FIELD_TXT "first"
  95. # define FG_SECOND_FIELD_TXT "second"
  96. # define FG_NEXT_FIELD_TXT "next"
  97. # define FG_FULL_FRAME_TXT "interlaced"
  98. # define FG_PROGRESSIVE_FRAME_TXT "progressive"
  99. # define FG_FIELD_DEFAULT_TXT "default"
  100. # define FG_PARAM_HORIZONTAL_RESOLUTION "horizontal_resolution"
  101. # define FG_PARAM_VERTICAL_RESOLUTION "vertical_resolution"
  102. # define FG_PARAM_IMAGE_WIDTH "image_width"
  103. # define FG_PARAM_IMAGE_HEIGHT "image_height"
  104. # define FG_PARAM_START_ROW "start_row"
  105. # define FG_PARAM_START_COL "start_column"
  106. # define FG_PARAM_FIELD "field"
  107. # define FG_PARAM_BITS_PER_CHANNEL "bits_per_channel"
  108. # define FG_PARAM_COLOR_SPACE "color_space"
  109. # define FG_PARAM_GAIN "gain" /* only for compatibility */
  110. # define FG_PARAM_GENERIC "generic"
  111. # define FG_PARAM_EXT_TRIGGER "external_trigger"
  112. # define FG_PARAM_CAMERA_TYPE "camera_type"
  113. # define FG_PARAM_DEVICE "device"
  114. # define FG_PARAM_PORT "port"
  115. # define FG_PARAM_LINE_IN "line_in"
  116. # define FG_MAX_CHANNELS 1000 /* max number of channels that can be grabbed */
  117. # define FG_MAX_LUT_LENGTH 65536 /* max. length of a Lut */
  118. # define FG_INIT_NAME "FGInit"
  119. # define FG_FLAGS_NAME "FGFlags"
  120. # define FG_MAX_PARAM 2048
  121. /* defines for encoding which method is used for allocating Hrlregions */
  122. # define FG_RLALLOC_PERMANENT 1
  123. # define FG_RLALLOC_TMP 2
  124. # define FG_RLALLOC_LOCAL 4
  125. /* This Macro checks the syntax of Generic. *
  126. * Call it within the loop over the tuple of Generic parameters. *
  127. * i index of parameter *
  128. * pos char *, that points to the "=" *
  129. * ret_act_t return action in case of wrong type (H_ERR_FGPART) *
  130. * ret_act_v return action in case of wrong value (H_ERR_FGPARV) */
  131. # define CHECK_GENERIC(i, pos, ret_act_t, ret_act_v) \
  132. { \
  133. if (fginst->generic[(i)].type == STRING_PAR) \
  134. { \
  135. if (!strlen(fginst->generic[i].par.s)) \
  136. continue; \
  137. if (((pos) = strstr(fginst->generic[(i)].par.s, "=")) != NULL) \
  138. { \
  139. if (strstr((pos) + 1, "=")) \
  140. { \
  141. sprintf(errMsg, \
  142. "Error: More than one '=' found in '%s'. " \
  143. "Please make sure to use a syntax like this " \
  144. "for multiple parameters: " \
  145. "['par1=arg1', 'par2=arg2', ...]", \
  146. fginst->generic[i].par.s); \
  147. MY_PRINT_ERROR_MESSAGE(errMsg); \
  148. ret_act_v; \
  149. } \
  150. } \
  151. else \
  152. { \
  153. sprintf(errMsg, \
  154. "Error: No '=' found in '%s'. " \
  155. "Please make sure to use a syntax like this: " \
  156. "'parameter=argument'", \
  157. fginst->generic[i].par.s); \
  158. MY_PRINT_ERROR_MESSAGE(errMsg); \
  159. ret_act_v; \
  160. } \
  161. } \
  162. else \
  163. { \
  164. if (fginst->num_generic == 1 && \
  165. ((fginst->generic[(i)].type == LONG_PAR && \
  166. fginst->generic[(i)].par.l == -1) || \
  167. (fginst->generic[(i)].type == FLOAT_PAR && \
  168. fginst->generic[(i)].par.f == -1.0))) \
  169. break; \
  170. else \
  171. { \
  172. MY_PRINT_ERROR_MESSAGE("Generic parameter accepts " \
  173. "only string values!"); \
  174. ret_act_t; \
  175. } \
  176. } \
  177. }
  178. # ifdef _WIN32
  179. # include <windows.h>
  180. # endif
  181. /* define HALCON acquisition callback */
  182. # ifndef _WIN32
  183. # define __stdcall
  184. # endif
  185. typedef Herror(__stdcall* HAcqCallback)(void* AcqHandle, void* Context,
  186. void* UserContext);
  187. # if defined(__cplusplus)
  188. extern "C" {
  189. # endif
  190. # ifndef HCVERSION_H
  191. # ifndef _WIN32
  192. /* time */
  193. # if !defined(HE_TI_C6X)
  194. # if defined(__vxworks)
  195. # include <sys/times.h>
  196. # else
  197. # include <sys/time.h>
  198. # endif /* __vxworks */
  199. # else
  200. struct timezone
  201. {
  202. int tz_minuteswest; /* minutes W of Greenwich */
  203. int tz_dsttime; /* type of dst correction */
  204. };
  205. # if !defined(_B_TIME_H_)
  206. struct timeval
  207. {
  208. int tv_sec; /* seconds */
  209. int tv_usec; /* and microseconds */
  210. };
  211. # endif
  212. # endif /* ! HE_TI_C6X */
  213. # endif /* _WIN32 */
  214. # endif /* ifndef HCVERSION_H */
  215. /*****************************************************************************
  216. *
  217. * struct FGInstance
  218. *
  219. *****************************************************************************/
  220. typedef struct _FGInstance
  221. {
  222. struct _FGClass* fgclass; /* a pointer to the corresponding class */
  223. /* ----------------------- regular parameters --------------------------- */
  224. HIMGDIM horizontal_resolution, /* desired resolution delivered */
  225. vertical_resolution; /* by the board */
  226. HIMGDIM image_width, image_height; /* desired image size */
  227. HIMGDIM start_row, start_col; /* upper left corner */
  228. HINT field; /* even- or odd-field, full image mode */
  229. HINT bits_per_channel; /* color depth per pixel & channel */
  230. char color_space[MAX_STRING]; /* "gray", "rgb", "yuv", ... */
  231. float gain; /* for backwards compatibility only! */
  232. HBOOL external_trigger; /* trigger mode */
  233. char camera_type[MAX_STRING]; /* used camera type (fg-specific!) */
  234. char device[MAX_STRING]; /* device name */
  235. HINT port; /* port to use */
  236. HINT line_in; /* multiplexer input line */
  237. Hcpar* generic; /* generic parameter */
  238. HINT num_generic;
  239. /* ---------------------- miscellaneous parameters ---------------------- */
  240. INT4_8 mode; /* current operating mode */
  241. HIMGDIM width_max, height_max; /* maximum image size */
  242. HINT num_channels; /* number of image channels */
  243. HBOOL async_grab; /* TRUE <=> async grabbing engaged */
  244. Himage* image; /* image objects to grab into (aux.) */
  245. void* gen_pointer; /* generic pointer (auxiliary) */
  246. /* -------------------- external memory allocation ---------------------- */
  247. HBOOL halcon_malloc; /* TRUE <-> standard memory allocation */
  248. /* by HNewImage */
  249. HImageFreeProc clear_proc; /* pointer to specific clear function */
  250. /* (if halcon_malloc==FALSE) */
  251. } FGInstance;
  252. /*****************************************************************************
  253. *
  254. * struct FGClass
  255. *
  256. *****************************************************************************/
  257. typedef struct _FGClass
  258. {
  259. /* -------------------------- internal -------------------------------- */
  260. char name[MAX_STRING]; /* frame grabber name (interface module) */
  261. void* lib_handle; /* handle of interface library */
  262. HINT interface_version; /* current HALCON frame grabber */
  263. /* interface version */
  264. INT4 flags; /* interface flags */
  265. /* ------------------- properties / management ------------------------ */
  266. HBOOL available; /* supported for the current platform */
  267. HINT instances_num; /* current number instances (INTERNAL!) */
  268. HINT instances_max; /* maximum number of instances */
  269. FGInstance* instance[FG_MAX_INST]; /* list of instances (INTERNAL!) */
  270. /* ----------------- interface-specific functions --------------------- */
  271. FGInstance** (*OpenRequest)(Hproc_handle proc_id, FGInstance* fginst);
  272. Herror (*Open)(Hproc_handle proc_id, FGInstance* fginst);
  273. Herror (*Close)(Hproc_handle proc_id, FGInstance* fginst);
  274. Herror (*Grab)(Hproc_handle proc_id, FGInstance* fginst, Himage* image,
  275. HINT* num_image);
  276. Herror (*GrabStartAsync)(Hproc_handle proc_id, FGInstance* fginst,
  277. double maxDelay);
  278. Herror (*GrabAsync)(Hproc_handle proc_id, FGInstance* fginst,
  279. double maxDelay, Himage* image, HINT* num_image);
  280. Herror (*GrabData)(Hproc_handle proc_id, FGInstance* fginst, Himage** image,
  281. HINT** num_channel, HINT* num_image, Hrlregion*** region,
  282. HINT* num_region, Hcont*** cont, HINT* num_cont,
  283. Hcpar** data, HINT* num_data);
  284. Herror (*GrabDataAsync)(Hproc_handle proc_id, FGInstance* fginst,
  285. double maxDelay, Himage** image, HINT** num_channel,
  286. HINT* num_image, Hrlregion*** region,
  287. HINT* num_region, Hcont*** cont, HINT* num_cont,
  288. Hcpar** data, HINT* num_data);
  289. Herror (*Info)(Hproc_handle proc_id, HINT queryType, char** info,
  290. Hcpar** values, HINT* numValues);
  291. Herror (*SetParam)(Hproc_handle proc_id, FGInstance* fginst, char* param,
  292. Hcpar* value, HINT num);
  293. Herror (*GetParam)(Hproc_handle proc_id, FGInstance* fginst, char* param,
  294. Hcpar* value, HINT* num);
  295. Herror (*SetLut)(Hproc_handle proc_id, FGInstance* fginst, INT4_8* red,
  296. INT4_8* green, INT4_8* blue, HINT num);
  297. Herror (*GetLut)(Hproc_handle proc_id, FGInstance* fginst, INT4_8* red,
  298. INT4_8* green, INT4_8* blue, HINT* num);
  299. Herror (*SetCallback)(Hproc_handle proc_id, FGInstance* fginst,
  300. char* callback_type, HAcqCallback callback_function,
  301. void* user_context);
  302. Herror (*GetCallback)(Hproc_handle proc_id, FGInstance* fginst,
  303. char* callback_type, HAcqCallback* callback_function,
  304. void** user_context);
  305. /* -------------------------- default values -------------------------- */
  306. HIMGDIM horizontal_resolution, /* desired resolution delivered */
  307. vertical_resolution; /* by the board */
  308. HIMGDIM image_width, image_height; /* desired image size */
  309. HIMGDIM start_row, start_col; /* upper left corner */
  310. HINT field; /* even- or odd-field, full image mode */
  311. HINT bits_per_channel; /* color depth per pixel & channel */
  312. char color_space[MAX_STRING]; /* "gray", "rgb", "yuv", ... */
  313. float gain; /* for backwards compatibility only! */
  314. HBOOL external_trigger; /* trigger mode */
  315. char camera_type[MAX_STRING]; /* used camera type (fg-specific!) */
  316. char device[MAX_STRING]; /* device name */
  317. HINT port; /* port to use */
  318. HINT line_in; /* multiplexer input line */
  319. Hcpar* generic; /* generic parameter */
  320. HINT num_generic;
  321. /* ------------------------- miscellaneous ---------------------------- */
  322. void* reserved[FG_NUM_RESERVED];
  323. } FGClass;
  324. /*
  325. * Special framegrabber flags. To set the flags, the interface should export
  326. * the symbol FG_FLAGS_NAME, which must be an INT4. Note that if the interface
  327. * is openend using the HAddFgClass function, the flags cannot be set.
  328. *
  329. * The following flags are defined:
  330. *
  331. * FG_FLAG_THREAD_OPEN: if set, the interface is opened and closed from the
  332. * same thread.
  333. * FG_FLAG_THREAD_ALL: if set, all interface functions are called from the
  334. * same thread.
  335. */
  336. # define FG_FLAG_THREAD_OPEN (1 << 0)
  337. # define FG_FLAG_THREAD_ALL (FG_FLAG_THREAD_OPEN | (1 << 1))
  338. typedef Herror (*FG_INIT_FUNC)(Hproc_handle, FGClass*);
  339. # if defined(__cplusplus)
  340. }
  341. # endif
  342. #endif /* ifndef HC_NO_FRAMEGRABBER */
  343. #endif /* ifndef #ifndef CIOFRAMEGRAB_DEFINES_H */