tbItf.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. #ifndef __TB_ITF_H__
  2. #define __TB_ITF_H__
  3. #if defined(__cplusplus) || defined(c_plusplus)
  4. #define TBEXTERN_C extern "C"
  5. #else
  6. #define TBEXTERN_C extern
  7. #endif
  8. #ifdef ANDROID
  9. #define _HYMOBILE
  10. #endif
  11. #ifdef __IPHONE_NA
  12. #ifndef __MAC_NA
  13. #define _HYMOBILE
  14. #endif
  15. #endif
  16. #ifndef _HYMOBILE
  17. #if !(TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
  18. #define _PC
  19. #endif
  20. #endif
  21. /*
  22. #ifdef _PC
  23. #include "cv.h"
  24. #include "highgui.h"
  25. #endif
  26. */
  27. //SQY:
  28. #define GEN3ON true
  29. #define MAXQRDIMENSION 177
  30. // 二维码最大的字节容量
  31. #define MAX_QR_DATA_SIZE 8192
  32. #define TB_STR_SIZE 2048
  33. #define AUTOFOCUS 0
  34. #define DEFOCUS 1
  35. #define HY_RGBA 0
  36. #define HY_YUV 1
  37. #define EAN13 0x1
  38. #define EAN8 0x2
  39. #define UPCA 0x4
  40. #define UPCE 0x8
  41. #define CODE39 0x10
  42. #define CODE128 0x20
  43. #define ITF 0x40
  44. #define EAN14 0X80
  45. #define CODE93 0X100
  46. #define FASTMAIL ( CODE39 | CODE128 )
  47. #if ENABLE_CODE93
  48. # define ONED ( EAN13 | EAN8 | UPCA | UPCE | CODE39 | CODE128 | ITF | EAN14 | CODE93)
  49. #else
  50. # define ONED ( EAN13 | EAN8 | UPCA | UPCE | CODE39 | CODE128 | ITF | EAN14)
  51. #endif
  52. #define QRCODE 0x200
  53. #define DATAMATRIX 0x400
  54. #define PDF417 0x800
  55. #define GEN3 0x8000
  56. #define APCODE 0x10000
  57. #define NARROW_CODE 0x20000
  58. #define HM_CODE 0x40000
  59. //AP Code 有8个子类型, 0是ARcode, 1 预留给小程序,2-7预留
  60. #define APCODE_SUBTYPE_ARCODE (0x00)
  61. #define APCODE_SUBTYPE_XCODE (0x01)
  62. #define APCODE_SUBTYPE_RESVERED_02 (0x02)
  63. #define APCODE_SUBTYPE_RESVERED_03 (0x03)
  64. #define APCODE_SUBTYPE_RESVERED_04 (0x04)
  65. #define APCODE_SUBTYPE_RESVERED_05 (0x05)
  66. #define APCODE_SUBTYPE_RESVERED_06 (0x06)
  67. #define APCODE_SUBTYPE_RESVERED_07 (0x07)
  68. #define KEY_WHOLE_REAL_TIME_COST "wholeRealTimeCost"
  69. #define KEY_LAST_HAS_CODE_DURATION "lastHasCodeDuration"
  70. #define KEY_LAST_HAS_CODE_DURATION2 "lastHasCodeDuration2"
  71. #define KEY_DURATION_OF_SCAN_NOTHING "scanNothingDuration"
  72. #define STRATEGY_NORMAL (0)
  73. #define STRATEGY_REVERSE (1)
  74. #define STRATEGY_TOLARENCE (2)
  75. #define STRATEGY_MULTIAP (4)
  76. #define STRATEGY_SAMPLE_AREAS (8)
  77. #define STRATEGY_SAMPLE_CAREFUL (16)
  78. #define STRATEGY_BACKUP_PATTERN_INFO (32)
  79. #define STRATEGY_NEW_MAX_WIDTH_HEIGHT_DIFFER_RATE (64)
  80. #define STRATEGY_TEMPLATE_MATCHING_REFIND (128)
  81. #define STRATEGY_NEW_TEMPLATE_MATCHING_FOUND (256)
  82. #define STRATEGY_TEMPLATE_MATCHING_FOUND (512)
  83. #define STRATEGY_AIDETECTED_GUESS (1024)
  84. #define STRATEGY_311113 (2048)
  85. #define STRATEGY_MAX (4096)
  86. #define HY_MINIMUM_FEATURE 36
  87. //#define ALLCODE ( ONED | QRCODE | DATAMATRIX)
  88. #define ALLCODE ( ONED | QRCODE | DATAMATRIX | GEN3)
  89. //reserved for HYSDK
  90. #define HYSDK_NET_LOGO 0x01000000
  91. #define HYSDK_RESERVED1 0x02000000
  92. #define HYSDK_RESERVED2 0x04000000
  93. #define HYSDK_RESERVED3 0x08000000
  94. #define HYSDK_RESERVED4 0x10000000
  95. #define HYSDK_RESERVED5 0x20000000
  96. #define HYSDK_RESERVED6 0x40000000
  97. #define HYSDK_RESERVED7 0x80000000
  98. //switcher
  99. #define MA_SDK_QR_OFF
  100. #define MA_SDK_BARCODE_OFF
  101. #define NEW_QR_ENGINE_ON
  102. typedef signed int TBInt;
  103. typedef signed char TBChar;
  104. typedef unsigned char TBUChar;
  105. #define AUTO_SIZE 480
  106. #define TBAR_DEBUG 0
  107. #define TBAR_SVAEIMAGE 0
  108. #ifndef MAX
  109. #define MAX(a, b) ((a)>(b)?(a):(b))
  110. #endif
  111. #ifndef MIN
  112. #define MIN(a, b) ((a)<(b)?(a):(b))
  113. #endif
  114. #ifndef FLT_EPSILON
  115. #define FLT_EPSILON 1.192092896e-07F
  116. #endif
  117. #ifndef TRUE
  118. #define TRUE 1
  119. #endif
  120. #ifndef FALSE
  121. #define FALSE 0
  122. #endif
  123. #ifdef APCODE_DEV_MACHINE
  124. #ifndef nullptr
  125. #define nullptr NULL
  126. #endif
  127. #include <string>
  128. namespace std{
  129. static string to_string(float &x){
  130. return to_string((long double)x);
  131. }
  132. static string to_string(int &x){
  133. return to_string((long long int)x);
  134. }
  135. static string to_string(size_t x){
  136. return to_string((long long int)x);
  137. }
  138. }
  139. #endif
  140. #define TDEBUG 0
  141. //获取线程时间函数指针
  142. TBEXTERN_C int (*getThreadTime)(int __clock_id, struct timespec *__tp);
  143. typedef struct {
  144. TBInt x;
  145. TBInt y;
  146. TBInt width;
  147. TBInt height;
  148. } TBarRect;
  149. // The format of TBarImage MUST be BGRA(8888)
  150. typedef struct {
  151. float cameraZoomFactor;
  152. TBInt width;
  153. TBInt height;
  154. TBInt bytesPerRow;
  155. TBarRect cropRect;
  156. TBInt format;
  157. TBInt resample;
  158. TBUChar *data;
  159. TBUChar *bitMatrix;
  160. // char addr[1024];
  161. #ifdef ANDROID
  162. char* str4GLocalAddr;
  163. #endif
  164. } TBarImage;
  165. #ifdef SCANNER_DEBUG
  166. typedef struct {
  167. size_t len;
  168. int points[200][2];
  169. } Points;
  170. #endif
  171. #define TYPE_UNKNOWN -1
  172. #define TYPE_PRODUCT_CODE 0
  173. #define TYPE_QR_CODE 1
  174. #define TYPE_EXPRESS_CODE 2
  175. typedef struct {
  176. TBInt type; //0:unknown 1:barcode 2:qrcode //这是假的,别上当
  177. TBInt subType; //depend on 'type'.
  178. TBChar str[MAX_QR_DATA_SIZE];//null-terminated string for decoding info
  179. TBChar typeName[TB_STR_SIZE]; // null-terminated stringfor typename of dsl
  180. int rawDataLength; // if QRCode its strSize in fact
  181. #ifdef __ANDROID__
  182. TBInt avgGray; //average gray
  183. #endif
  184. float codeProportion;
  185. int version;
  186. char ecLevel;
  187. int bitErrors;
  188. int strategy; //使用的扫码策略,算法功能回传
  189. float errPercent;
  190. int qrSize;
  191. int isMirrored;
  192. #ifdef SCANNER_DEBUG
  193. Points tried, possible, guess;
  194. #endif
  195. TBarRect rect; //hot area
  196. #ifndef ALIPAY_DEPRECATED
  197. TBInt x[4], y[4];
  198. TBInt dir;
  199. TBChar bitstream[MAXQRDIMENSION * MAXQRDIMENSION];
  200. //SQY in the old version . sometimes ,we use subtype to send the dimension of the bitstream , now we separate them ,
  201. // we use TBInt dimension
  202. TBInt dimension;
  203. //SQY since we merge GEN2 into this SDK ,so we create hiddenData to save the gen2Result.
  204. TBChar hiddenData[TB_STR_SIZE];
  205. #endif
  206. int byteErrors;
  207. } TBarRet;
  208. #define POSITIVE_PROBABILITY 60 // 扫条码先正向后逆向的概率
  209. #define MAX_PROBABLE_NUM 4
  210. #define MAX_CHARACTER_NUM 100
  211. #define MAX_ROW_LEN 2048
  212. #define MAX_MEMORY_SIZE (MAX_ROW_LEN*MAX_ROW_LEN)
  213. #ifdef ANDROID
  214. #define BARCODE_STEP_NUM_OF_TRYHARD_2 300
  215. #define BARCODE_STEP_NUM_OF_TRYHARD_1 60
  216. #else
  217. #define BARCODE_STEP_NUM_OF_TRYHARD_2 300
  218. #define BARCODE_STEP_NUM_OF_TRYHARD_1 60
  219. #endif
  220. #define BARCODE_THRESHOLD_LEN 7
  221. typedef struct BarcodeResult {
  222. char string[MAX_CHARACTER_NUM];
  223. int count; // 用于条形码算法策略统计
  224. int type;
  225. int subType;
  226. TBarRect rect;
  227. #ifndef ALIPAY_DEPRECATED
  228. TBInt dir;
  229. #endif
  230. } BARCODERESULT;
  231. typedef struct {
  232. TBInt keyValue;
  233. const char *name;
  234. } APCODE_TYPE;
  235. // all method are Locked and wait, except Decode Method ,Decode will just return
  236. // Init
  237. // for some defaultParams and recoder triger
  238. TBEXTERN_C TBInt CameraDecodeInit(void);
  239. TBEXTERN_C TBInt CameraDecodeUnInit(void);
  240. TBEXTERN_C TBInt DownGradeSdkMemoryAllocate();
  241. TBEXTERN_C void enableFastBitmapDecode();
  242. TBEXTERN_C void TBarImgRGB2Gray(const TBarImage *image1, TBarImage *image2);
  243. // image: image info provided by camera
  244. // ret: decoded data return form decoder. ret may be NULL.
  245. // return: 1: success
  246. TBEXTERN_C TBInt TBDecode(const TBarImage *image, TBarRet *ret, TBInt inCount, TBInt *outCount, int ScanMode);
  247. TBEXTERN_C TBInt TBDecode_Test(const TBarImage *image, TBarRet *ret, TBInt inCount, TBInt *outCount, int ScanMode);
  248. TBEXTERN_C TBInt TBDecode_CodeFinder(const TBarImage *image, TBarRet *result, TBInt inCount,
  249. TBInt *outCount, int ScanMode, bool useQRModel);
  250. TBEXTERN_C TBInt TBDecodeBigImage(const TBarImage *image, TBarRet *ret, TBInt inCount, TBInt *outCount, int scanMode);
  251. TBEXTERN_C TBInt TBDecodeBigImageMult(const TBarImage *image, TBarRet *ret, TBInt inCount, TBInt *outCount, int scanMode);
  252. // image: provid bitMatrix
  253. TBEXTERN_C int RegistDSLReader(const char *const dsl, bool isAlbum);
  254. TBEXTERN_C TBInt UnRegistDSLReader(bool isAlbum);
  255. TBEXTERN_C double getTime(void);
  256. //TBEXTERN_C bool (*isInBlackList)(const char *codeContent);
  257. //TBEXTERN_C TBInt configDecode(const int argn, const char **argv);
  258. #endif // __TB_ITF_H__