ImageConvert.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /**
  2. * @file ImageConvert.h
  3. * @brief 图像格式转换.
  4. * @author qi_zhiyu
  5. * @par Copyright (c):
  6. * ZheJiang Dahua Technology Stock Co.Ltd.
  7. * All Rights Reserved
  8. * @version 1.0.0.1
  9. */
  10. #ifndef __IMAGE_CONVERT_H_
  11. #define __IMAGE_CONVERT_H_
  12. #ifdef __cplusplus
  13. extern "C"{
  14. #endif // end #ifdef __cplusplus
  15. #ifdef WIN64
  16. #undef WIN32
  17. #endif
  18. /** 编译选项 */
  19. #ifdef WIN32 // win64位下,会报和def重复定义的警告 In Win 64bit, it will report warning for duplicate definition
  20. # ifdef _USRDLL // 动态库导出 Export DLL
  21. # ifdef IMAGECONVERT_EXPORTS
  22. # define IMGCNV_API __declspec(dllexport)
  23. # else
  24. # define IMGCNV_API __declspec(dllimport)
  25. # endif
  26. # else
  27. # define IMGCNV_API
  28. # endif // end of ifdef _USRDLL
  29. #else
  30. # define IMGCNV_API
  31. #endif //end #ifdef WIN32
  32. #if (defined (WIN32) || defined(WIN64))
  33. # define CALLMETHOD __stdcall
  34. #else
  35. # define CALLMETHOD
  36. #endif // end #if (defined (WIN32) || defined(WIN64))
  37. typedef void* IMGCNV_HANDLE; ///< 转码API使用的句柄 Handle for using conversion API
  38. /**
  39. * @enum IMGCNV_EErr
  40. * @brief 接口返回值 Return value
  41. * @attention 无 No
  42. */
  43. typedef enum tagIMGCNV_EErr
  44. {
  45. IMGCNV_SUCCESS,
  46. IMGCNV_ILLEGAL_PARAM, ///< 非法参数 Illegal parameter
  47. IMGCNV_ERR_ORDER, ///< 调用接口顺序错误 Sequence error for calling interfaces
  48. IMGCNV_NO_MEMORY, ///< 内存不足 No memory
  49. IMGCNV_NOT_SUPPORT, ///< 不支持 Not support
  50. }IMGCNV_EErr;
  51. typedef struct tagIMGCNV_SOpenParam
  52. {
  53. int width; ///< 图像宽 Image width
  54. int height; ///< 图像高 Image Height
  55. int paddingX; ///< 图像宽填充 Padding X
  56. int paddingY; ///< 图像高填充 Padding Y
  57. int dataSize; ///< 图像大小 Image size
  58. unsigned int pixelForamt; ///< 源图像的图像格式 Image format of source image
  59. }IMGCNV_SOpenParam;
  60. typedef enum tagIMGCNV_EBayerDemosaic
  61. {
  62. IMGCNV_DEMOSAIC_NEAREST_NEIGHBOR, ///< 最近邻 Nearest neighbor
  63. IMGCNV_DEMOSAIC_BILINEAR, ///< 双线性 Bilinear
  64. IMGCNV_DEMOSAIC_EDGE_SENSING, ///< 边缘检测 Edge sensing
  65. IMGCNV_DEMOSAIC_NOT_SUPPORT = 255, ///< 不支持 Not support
  66. }IMGCNV_EBayerDemosaic;
  67. /**
  68. * ~chinese
  69. * @brief 转换为BGR24的转换函数
  70. * @param[in] pSrcData :源数据
  71. * @param[in] pOpenParam :IMGCNV_SOpenParam结构体,格式转换所需要的参数
  72. * @param[out]pDstData :转换后的数据
  73. * @param[out]pDstDataSize :转换后数据的长度
  74. * @Return: IMGCNV_ERR_E : 图像格式转换接口返回值
  75. * - IMGCNV_SUCCESS 表示执行成功
  76. * - 其他值见IMGCNV_ERR_E枚举
  77. * 特别说明
  78. * 像素格式为YUV411Packed的时,图像宽须能被4整除
  79. * 像素格式为YUV422Packed的时,图像宽须能被2整除
  80. * 像素格式为YUYVPacked的时,图像宽须能被2整除
  81. * 转换后的图像:数据存储是从最上面第一行开始的,这个是相机数据的默认存储方向
  82. * ~english
  83. * @brief convert to BGR24
  84. * @param[in] pSrcData :source data
  85. * @param[in] pOpenParam :conversion required paraneters
  86. * @param[out]pDstData :converted data
  87. * @param[out]pDstDataSize :length of converted data
  88. * @Return: IMGCNV_ERR_E :return value
  89. * - IMGCNV_SUCCESS return ok
  90. * - Other values refers to enumeration of IMGCNV_ERR_E
  91. * Special note
  92. * pixelFormat:YUV411Packed,the image width is divisible by 4
  93. * pixelFormat:YUV422Packed,the image width is divisible by 2
  94. * pixelFormat:YUYVPacked,the image width is divisible by 2
  95. * converted image:The first row of the image is located at the start of the image buffer.This is the default for image taken by a camera.
  96. */
  97. IMGCNV_API IMGCNV_EErr CALLMETHOD IMGCNV_ConvertToBGR24(unsigned char* pSrcData, IMGCNV_SOpenParam* pOpenParam, unsigned char* pDstData, int* pDstDataSize);
  98. /**
  99. * ~chinese
  100. * @brief 转换为RGB24的转换函数
  101. * @param[in] pSrcData :源数据
  102. * @param[in] pOpenParam :IMGCNV_SOpenParam结构体,格式转换所需要的参数
  103. * @param[out]pDstData :转换后的数据
  104. * @param[out]pDstDataSize :转换后数据的长度
  105. * @Return: IMGCNV_ERR_E : 图像格式转换接口返回值
  106. * - IMGCNV_SUCCESS 表示执行成功
  107. * - 其他值见IMGCNV_ERR_E枚举
  108. * 特别说明
  109. * 像素格式为YUV411Packed的时,图像宽须能被4整除
  110. * 像素格式为YUV422Packed的时,图像宽须能被2整除
  111. * 像素格式为YUYVPacked的时,图像宽须能被2整除
  112. * 转换后的图像:数据存储是从最上面第一行开始的,这个是相机数据的默认存储方向
  113. * ~english
  114. * @brief convert to RGB24
  115. * @param[in] pSrcData :source data
  116. * @param[in] pOpenParam :conversion required paraneters
  117. * @param[out]pDstData :converted data
  118. * @param[out]pDstDataSize :length of converted data
  119. * @Return: IMGCNV_ERR_E :return value
  120. * - IMGCNV_SUCCESS return ok
  121. * - Other values refers to enumeration of IMGCNV_ERR_E
  122. * Special note
  123. * pixelFormat:YUV411Packed,the image width is divisible by 4
  124. * pixelFormat:YUV422Packed,the image width is divisible by 2
  125. * pixelFormat:YUYVPacked,the image width is divisible by 2
  126. * converted image:The first row of the image is located at the start of the image buffer.This is the default for image taken by a camera.
  127. */
  128. IMGCNV_API IMGCNV_EErr CALLMETHOD IMGCNV_ConvertToRGB24(unsigned char* pSrcData, IMGCNV_SOpenParam* pOpenParam, unsigned char* pDstData, int* pDstDataSize);
  129. /**
  130. * ~chinese
  131. * @brief 转换为Mono8的转换函数
  132. * @param[in] pSrcData :源数据
  133. * @param[in] pOpenParam :IMGCNV_SOpenParam结构体,格式转换所需要的参数
  134. * @param[out]pDstData :转换后的数据
  135. * @param[out]pDstDataSize :转换后数据的长度
  136. * @Return: IMGCNV_ERR_E : 图像格式转换接口返回值
  137. * - IMGCNV_SUCCESS 表示执行成功
  138. * - 其他值见IMGCNV_ERR_E枚举
  139. * 特别说明
  140. * 像素格式为YUV411Packed的时,图像宽须能被4整除
  141. * 像素格式为YUV422Packed的时,图像宽须能被2整除
  142. * 像素格式为YUYVPacked的时,图像宽须能被2整除
  143. * 转换后的图像:数据存储是从最上面第一行开始的,这个是相机数据的默认存储方向
  144. * ~english
  145. * @brief convert to Mono8
  146. * @param[in] pSrcData :source data
  147. * @param[in] pOpenParam :conversion required paraneters
  148. * @param[out]pDstData :converted data
  149. * @param[out]pDstDataSize :length of converted data
  150. * @Return: IMGCNV_ERR_E :return value
  151. * - IMGCNV_SUCCESS return ok
  152. * - Other values refers to enumeration of IMGCNV_ERR_E
  153. * Special note
  154. * pixelFormat:YUV411Packed,the image width is divisible by 4
  155. * pixelFormat:YUV422Packed,the image width is divisible by 2
  156. * pixelFormat:YUYVPacked,the image width is divisible by 2
  157. * converted image:The first row of the image is located at the start of the image buffer.This is the default for image taken by a camera.
  158. */
  159. IMGCNV_API IMGCNV_EErr CALLMETHOD IMGCNV_ConvertToMono8(unsigned char* pSrcData, IMGCNV_SOpenParam* pOpenParam, unsigned char* pDstData, int* pDstDataSize);
  160. /**
  161. * ~chinese
  162. * @brief 转换为BGR24的转换函数
  163. * @param[in] pSrcData :源数据
  164. * @param[in] pOpenParam :IMGCNV_SOpenParam结构体,格式转换所需要的参数
  165. * @param[out]pDstData :转换后的数据
  166. * @param[out]pDstDataSize :转换后数据的长度
  167. * @param[in]eBayerDemosaic :选择转换Bayer格式所用的算法
  168. * @Return: IMGCNV_ERR_E : 图像格式转换接口返回值
  169. * - IMGCNV_SUCCESS 表示执行成功
  170. * - 其他值见IMGCNV_ERR_E枚举
  171. * 特别说明
  172. * 像素格式为YUV411Packed的时,图像宽须能被4整除
  173. * 像素格式为YUV422Packed的时,图像宽须能被2整除
  174. * 像素格式为YUYVPacked的时,图像宽须能被2整除
  175. * 转换后的图像:数据存储是从最上面第一行开始的,这个是相机数据的默认存储方向
  176. * ~english
  177. * @brief convert to BGR24
  178. * @param[in] pSrcData :source data
  179. * @param[in] pOpenParam :conversion required paraneters
  180. * @param[out]pDstData :converted data
  181. * @param[out]pDstDataSize :length of converted data
  182. * @param[in]eBayerDemosaic :alorithm used for Bayer demosaic
  183. * @Return: IMGCNV_ERR_E :return value
  184. * - IMGCNV_SUCCESS return ok
  185. * - Other values refers to enumeration of IMGCNV_ERR_E
  186. * Special note
  187. * pixelFormat:YUV411Packed,the image width is divisible by 4
  188. * pixelFormat:YUV422Packed,the image width is divisible by 2
  189. * pixelFormat:YUYVPacked,the image width is divisible by 2
  190. * converted image:The first row of the image is located at the start of the image buffer.This is the default for image taken by a camera.
  191. */
  192. IMGCNV_API IMGCNV_EErr CALLMETHOD IMGCNV_ConvertToBGR24_Ex(unsigned char* pSrcData, IMGCNV_SOpenParam* pOpenParam, unsigned char* pDstData, int* pDstDataSize, IMGCNV_EBayerDemosaic eBayerDemosaic);
  193. /**
  194. * ~chinese
  195. * @brief 转换为RGB24的转换函数
  196. * @param[in] pSrcData :源数据
  197. * @param[in] pOpenParam :IMGCNV_SOpenParam结构体,格式转换所需要的参数
  198. * @param[out]pDstData :转换后的数据
  199. * @param[out]pDstDataSize :转换后数据的长度
  200. * @param[in]eBayerDemosaic :选择转换Bayer格式所用的算法
  201. * @Return: IMGCNV_ERR_E : 图像格式转换接口返回值
  202. * - IMGCNV_SUCCESS 表示执行成功
  203. * - 其他值见IMGCNV_ERR_E枚举
  204. * 特别说明
  205. * 像素格式为YUV411Packed的时,图像宽须能被4整除
  206. * 像素格式为YUV422Packed的时,图像宽须能被2整除
  207. * 像素格式为YUYVPacked的时,图像宽须能被2整除
  208. * 转换后的图像:数据存储是从最上面第一行开始的,这个是相机数据的默认存储方向
  209. * ~english
  210. * @brief convert to RGB24
  211. * @param[in] pSrcData :source data
  212. * @param[in] pOpenParam :conversion required paraneters
  213. * @param[out]pDstData :converted data
  214. * @param[out]pDstDataSize :length of converted data
  215. * @param[in]eBayerDemosaic :alorithm used for Bayer demosaic
  216. * @Return: IMGCNV_ERR_E :return value
  217. * - IMGCNV_SUCCESS return ok
  218. * - Other values refers to enumeration of IMGCNV_ERR_E
  219. * Special note
  220. * pixelFormat:YUV411Packed,the image width is divisible by 4
  221. * pixelFormat:YUV422Packed,the image width is divisible by 2
  222. * pixelFormat:YUYVPacked,the image width is divisible by 2
  223. * converted image:The first row of the image is located at the start of the image buffer.This is the default for image taken by a camera.
  224. */
  225. IMGCNV_API IMGCNV_EErr CALLMETHOD IMGCNV_ConvertToRGB24_Ex(unsigned char* pSrcData, IMGCNV_SOpenParam* pOpenParam, unsigned char* pDstData, int* pDstDataSize, IMGCNV_EBayerDemosaic eBayerDemosaic);
  226. /**
  227. * ~chinese
  228. * @brief 转换为Mono8的转换函数
  229. * @param[in] pSrcData :源数据
  230. * @param[in] pOpenParam :IMGCNV_SOpenParam结构体,格式转换所需要的参数
  231. * @param[out]pDstData :转换后的数据
  232. * @param[out]pDstDataSize :转换后数据的长度
  233. * @param[in]eBayerDemosaic :选择转换Bayer格式所用的算法
  234. * @Return: IMGCNV_ERR_E : 图像格式转换接口返回值
  235. * - IMGCNV_SUCCESS 表示执行成功
  236. * - 其他值见IMGCNV_ERR_E枚举
  237. * 特别说明
  238. * 像素格式为YUV411Packed的时,图像宽须能被4整除
  239. * 像素格式为YUV422Packed的时,图像宽须能被2整除
  240. * 像素格式为YUYVPacked的时,图像宽须能被2整除
  241. * 转换后的图像:数据存储是从最上面第一行开始的,这个是相机数据的默认存储方向
  242. * ~english
  243. * @brief convert to Mono8
  244. * @param[in] pSrcData :source data
  245. * @param[in] pOpenParam :conversion required paraneters
  246. * @param[out]pDstData :converted data
  247. * @param[out]pDstDataSize :length of converted data
  248. * @param[in]eBayerDemosaic :alorithm used for Bayer demosaic
  249. * @Return: IMGCNV_ERR_E :return value
  250. * - IMGCNV_SUCCESS return ok
  251. * - Other values refers to enumeration of IMGCNV_ERR_E
  252. * Special note
  253. * pixelFormat:YUV411Packed,the image width is divisible by 4
  254. * pixelFormat:YUV422Packed,the image width is divisible by 2
  255. * pixelFormat:YUYVPacked,the image width is divisible by 2
  256. * converted image:The first row of the image is located at the start of the image buffer.This is the default for image taken by a camera.
  257. */
  258. IMGCNV_API IMGCNV_EErr CALLMETHOD IMGCNV_ConvertToMono8_Ex(unsigned char* pSrcData, IMGCNV_SOpenParam* pOpenParam, unsigned char* pDstData, int* pDstDataSize, IMGCNV_EBayerDemosaic eBayerDemosaic);
  259. #ifdef __cplusplus
  260. }
  261. #endif // end #ifdef __cplusplus
  262. #endif // end of #ifndef __IMAGE_CONVERT_H_