stflib_isp_defs.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /**
  2. ******************************************************************************
  3. * @file stflib_isp_defs.h
  4. * @author StarFive Isp Team
  5. * @version V1.0
  6. * @date 05/26/2020
  7. * @brief
  8. ******************************************************************************
  9. * @copy
  10. *
  11. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  12. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  13. * TIME. AS A RESULT, STARFIVE SHALL NOT BE HELD LIABLE FOR ANY
  14. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  15. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  16. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  17. *
  18. * Copyright (C) 2019 - 2022 StarFive Technology Co., Ltd.
  19. ******************************************************************************/
  20. #ifndef __STFLIB_ISP_DEFS__
  21. #define __STFLIB_ISP_DEFS__
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. #ifdef WIN32
  26. #define NOMINMAX
  27. #endif
  28. #include <stddef.h>
  29. #include <stdbool.h>
  30. #include <math.h>
  31. #ifdef USE_MATH_NEON
  32. #include <mneon.h>
  33. #endif
  34. #include <limits.h>
  35. #include "stf_include.h"
  36. #include "stf_common/pixel_format.h"
  37. /** creates a lot of comparison errors if using std::min */
  38. #define ISPC_MIN(a, b) (((a) < (b)) ? (a) : (b))
  39. /** creates a lot of comparison errors if using std::max */
  40. #define ISPC_MAX(a, b) (((a) > (b)) ? (a) : (b))
  41. /** @brief clip a value between 2 bounds */
  42. #if 0
  43. #define CLIP(value_type, bound_type, value, bound1, bound2) \
  44. ( \
  45. value_type value_clip(value_type value, bound_type bound1, bound_type bound2) { \
  46. if (bound2 < bound1) { \
  47. const bound_type tmp = bound1; \
  48. bound1 = bound2; \
  49. bound2 = tmp; \
  50. } \
  51. return ISPC_MIN(ISPC_MAX(bound1, value), bound2); \
  52. } \
  53. )
  54. #elif 0
  55. #define CLIP(value, bound1, bound2) \
  56. ({ \
  57. (bound2 < bound1) ? \
  58. (ISPC_MIN(ISPC_MAX(bound2, value), bound1)) : \
  59. (ISPC_MIN(ISPC_MAX(bound1, value), bound2)); \
  60. })
  61. #elif 1
  62. #define CLIP(value, bound1, bound2) \
  63. ({ \
  64. typeof(value) __value = value; \
  65. typeof(value) __bound1 = bound1; \
  66. typeof(value) __bound2 = bound2; \
  67. if (__bound2 > __bound1) { \
  68. typeof(value) temp = __bound1; \
  69. __bound1 = __bound2; \
  70. __bound2 = temp; \
  71. } \
  72. ISPC_MIN(ISPC_MAX(bound1, value), bound2); \
  73. })
  74. #endif
  75. // Some versions of VisualStudio don't have log2()
  76. #ifdef USE_MATH_NEON
  77. inline double LOG2(double val) { return ((double)log10f_neon((float)(val))) / ((double)log10f_neon(2.0f)); }
  78. #else
  79. inline double LOG2(double val) { return log10(val) / log10(2.0); }
  80. #endif
  81. /**
  82. * @brief context status definitions
  83. */
  84. typedef enum __EN_CTX_STATUS {
  85. ISPC_Ctx_UNINIT = 0, /**< @brief Context not initialited */
  86. ISPC_Ctx_INIT, /**< @brief Context initialited */
  87. ISPC_Ctx_SETUP, /**< @brief Pipeline has been setup */
  88. ISPC_Ctx_READY, /**< @brief Pipeline is ready for capture */
  89. ISPC_Ctx_ERROR /**< @brief Pipeline is in error state */
  90. } EN_CTX_STATUS, *PEN_CTX_STATUS;
  91. typedef enum _EN_SCALER_RECT_TYPE {
  92. SCALER_RECT_CLIP = 0,
  93. SCALER_RECT_CROP,
  94. SCALER_RECT_SIZE
  95. } EN_SCALER_RECT_TYPE, *PEN_SCALER_RECT_TYPE;
  96. /**
  97. * @brief Global setup parameters that may be used in several places of the
  98. * pipeline.
  99. */
  100. typedef struct _ST_GLOBAL_SETUP
  101. {
  102. STF_U32 CFA_WIDTH;
  103. STF_U32 CFA_HEIGHT;
  104. /**
  105. * @name Sensor information
  106. * @{
  107. */
  108. /** @brief Input image width */
  109. STF_U32 u32Sensor_Width;
  110. /** @brief Input image height */
  111. STF_U32 u32Sensor_Height;
  112. /** @brief Input image bitdepth */
  113. STF_U32 u32Sensor_BitDepth;
  114. /** @brief IIF setup, imager ID */
  115. STF_U32 u32Sensor_Imager;
  116. /** @brief sensor gain - may change regularly */
  117. STF_DOUBLE dSensor_Gain;
  118. STF_U32 u32Sensor_WellDepth;
  119. /** @brief [enum] Layout of the CFA cells. One of:RGGB,GRBG,GBRG,BGGR. */
  120. eMOSAIC enSensor_BayerFormat;
  121. STF_DOUBLE dSensor_ReadNoise;
  122. /**
  123. * @}
  124. * @name Image size information
  125. * @note Managed by IIF module
  126. * @{
  127. */
  128. /* should it be removed because managed by IIF? or should IIF become
  129. * part of global? */
  130. /**
  131. * @brief Image width after decimation and cropping
  132. *
  133. * @note Derived from result of ModuleIIF::setup()
  134. */
  135. STF_U32 u32ImageWidth;
  136. /**
  137. * @brief Image height after decimation and cropping
  138. *
  139. * @note Derived from result of ModuleIIF::setup()
  140. */
  141. STF_U32 u32ImageHeight;
  142. /**
  143. * @}
  144. * @name Pipeline output width and height
  145. * @note Output size after the scaler
  146. * @{
  147. */
  148. //=== Godspeed === Add new memory/buffer type support here.
  149. /** @brief UO output format. */
  150. ePxlFormat enUoPixelFormat;
  151. /** @brief UO output width. */
  152. STF_U16 u16UoWidth;
  153. /** @brief UO output height. */
  154. STF_U16 u16UoHeight;
  155. /** @brief Ss0 output format. */
  156. ePxlFormat enSs0PixelFormat;
  157. /** @brief SS0 output width. */
  158. STF_U16 u16Ss0Width;
  159. /** @brief SS0 output height. */
  160. STF_U16 u16Ss0Height;
  161. /** @brief Ss1 output format. */
  162. ePxlFormat enSs1PixelFormat;
  163. /** @brief SS1 output width. */
  164. STF_U16 u16Ss1Width;
  165. /** @brief SS1 output height. */
  166. STF_U16 u16Ss1Height;
  167. /** @brief DUMP output format. */
  168. ePxlFormat enDumpPixelFormat;
  169. /** @brief DUMP output width. */
  170. STF_U16 u16DumpWidth;
  171. /** @brief DUMP output height. */
  172. STF_U16 u16DumpHeight;
  173. /** @brief TIL_1_RD input format. */
  174. ePxlFormat enTiling_1_RdPixelFormat;
  175. /** @brief TIL_1_RD input width. */
  176. STF_U16 u16Tiling_1_RdWidth;
  177. /** @brief TIL_1_RD input height. */
  178. STF_U16 u16Tiling_1_RdHeight;
  179. /** @brief TIL_1_WR output format. */
  180. ePxlFormat enTiling_1_WrPixelFormat;
  181. /** @brief TIL_1_WR output width. */
  182. STF_U16 u16Tiling_1_WrWidth;
  183. /** @brief TIL_1_WR output height. */
  184. STF_U16 u16Tiling_1_WrHeight;
  185. /**
  186. * @}
  187. * @name Other global parameters
  188. * @{
  189. */
  190. /**
  191. * @}
  192. */
  193. } ST_GLOBAL_SETUP, *PST_GLOBAL_SETUP;
  194. #ifdef __cplusplus
  195. }
  196. #endif
  197. #endif //__STFLIB_ISP_DEFS__