ark_isp_exposure.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //****************************************************************************
  2. //
  3. // Copyright (C) 2015 ZhuoYongHong
  4. //
  5. // Author ZhuoYongHong
  6. //
  7. // File name: arkn141_isp_exposure.h
  8. // constant,macro & basic typedef definition of ISP exposure
  9. //
  10. // Revision history
  11. //
  12. // 2015.08.30 ZhuoYongHong Initial version
  13. //
  14. //****************************************************************************
  15. #ifndef _ARK_ISP_EXPOSURE_H_
  16. #define _ARK_ISP_EXPOSURE_H_
  17. #include "Gem_isp_ae.h"
  18. #ifdef __cplusplus
  19. #if __cplusplus
  20. extern "C"{
  21. #endif
  22. #endif
  23. #define HISTOGRAM_BANDS 5
  24. typedef struct tag_histogram_band
  25. {
  26. i32_t value;
  27. i32_t error;
  28. i32_t balance;
  29. i32_t target;
  30. i32_t cent;
  31. } histogram_band_t, *histogram_band_ptr_t;
  32. typedef struct tag_histogram
  33. {
  34. i32_t hist_balance;
  35. i32_t hist_dark;
  36. i32_t hist_dark_shift;
  37. i32_t hist_error; // < 0, 需要减小曝光量
  38. // > 0, 需要增加曝光量
  39. histogram_band_t bands[HISTOGRAM_BANDS];
  40. u8_t lum_hist[4]; // 暗场景判断
  41. i32_t hist_error_min;
  42. i32_t hist_error_max;
  43. i32_t hist_error_one;
  44. i32_t hist_error_last;
  45. i32_t hist_error_ratio;
  46. } histogram_t, *histogram_ptr_t;
  47. #define STEADY_CONTROL_AE_ERR_THREAD 5 // 稳态控制曝光错误阈值
  48. #define STEADY_CONTROL_AE_LUM_THREAD 2 // 稳态控制曝光亮度阈值
  49. // 稳态控制
  50. typedef struct tag_steady_control {
  51. u8_t enable; // 稳态控制开启标志
  52. u8_t count; // 非稳次数
  53. // 记录稳态状态下的曝光参数
  54. u32_t exposure;
  55. // 保存稳态状态下的曝光评测. 一旦曝光评测超出阈值范围, 稳态控制解除
  56. i32_t steady_error; // 稳态下锁定的错误值
  57. u8_t steady_lum; // 稳态下锁定的亮度值
  58. } steady_control_t;
  59. #define AE_MODE_DARK 0
  60. #define AE_MODE_BRIGHT 1
  61. typedef struct auto_exposure {
  62. u32_t increment; // 曝光修正因子
  63. u32_t increment_max;
  64. u32_t increment_min;
  65. u32_t increment_offset; // 曝光修正范围
  66. u16_t increment_step;
  67. u16_t increment_ratio;
  68. u32_t increment_damping; // 增量阻尼
  69. // 当sensor持续曝光翻转时, 此时AE会开启稳态控制.
  70. steady_control_t steady_control;
  71. histogram_t histogram;
  72. u32_t exposure_target;
  73. u32_t exposure_quant; // 系统定义的曝光修正参考量
  74. i8_t exposure_steps;
  75. u8_t exposure_factor;
  76. u8_t ae_compensation;
  77. u8_t ae_black_target;
  78. u8_t ae_bright_target;
  79. i8_t ae_ev;
  80. u8_t metering_hist_thresh_0_1;
  81. u8_t metering_hist_thresh_1_2;
  82. u8_t metering_hist_thresh_3_4;
  83. u8_t metering_hist_thresh_4_5;
  84. u8_t window_weight[3][3]; // 9宫格权重因子
  85. u8_t ae_mode;
  86. u32_t d_cycle;
  87. u32_t n_cycle;
  88. } auto_exposure_t, *auto_exposure_ptr_t;
  89. // 初始化一个自动曝光的实例
  90. void isp_auto_exposure_initialize (auto_exposure_ptr_t p_ae_block);
  91. void isp_auto_exposure_compensation (auto_exposure_ptr_t ae, histogram_band_t bands[5]);
  92. void isp_histogram_bands_read (histogram_band_t bands[5], isp_ae_ptr_t isp_ae);
  93. void isp_histogram_thresh_write (auto_exposure_ptr_t ae, u8_t histoBand[4]);
  94. void isp_histogram_bands_write (u8_t histoBand[4]);
  95. void isp_ae_window_weight_write (auto_exposure_ptr_t ae, u8_t win_weight[3][3]);
  96. u32_t isp_ae_lum_read (void);
  97. void isp_system_ae_black_target_write (auto_exposure_ptr_t ae, u8_t data);
  98. u8_t isp_system_ae_black_target_read (auto_exposure_ptr_t ae);
  99. void isp_system_ae_bright_target_write (auto_exposure_ptr_t ae, u8_t data);
  100. u8_t isp_system_ae_bright_target_read (auto_exposure_ptr_t ae);
  101. void isp_system_ae_compensation_write (auto_exposure_ptr_t ae, u8_t data);
  102. u8_t isp_system_ae_compensation_read (auto_exposure_ptr_t ae);
  103. #define ISP_SYSTEM_EV_DEFAULT (64)
  104. void isp_system_ae_ev_write (auto_exposure_ptr_t ae, i8_t data); // 曝光补偿
  105. i8_t isp_system_ae_ev_read (auto_exposure_ptr_t ae);
  106. #define ISP_SYSTEM_MIN_INTEGRATION_TIME_DEFAULT (0x0002)
  107. #define ISP_SYSTEM_MAX_INTEGRATION_TIME_DEFAULT (0xFFFF)
  108. #define AE_COMPENSATION_DEFAULT 46 // 降低亮度值
  109. #define AE_BRIGHT_TARGET_DEFAULT 24
  110. #ifdef __cplusplus
  111. #if __cplusplus
  112. }
  113. #endif
  114. #endif
  115. #endif // _ARKN141_ISP_EXPOSURE_H_