static __inline HI_U32 digital_gain_from_exposure_calculate( cmos_gains_ptr_t p_gains, HI_U32 exposure, HI_U32 exposure_max, HI_U32 exposure_shift) { int _i; HI_U32 _dgain = p_gains->dgain_offset; HI_U32 _ares = p_gains->dgain_offset; HI_U32 _lres = 0; int shft = 0; while (exposure > (1<<20)) { exposure >>= 1; exposure_max >>= 1; ++shft; } if(exposure > exposure_max) { //when setting manual exposure line, exposure_max>>shift should not be 0. exposure_max = DIV_0_TO_1(exposure_max); _dgain = (exposure * _dgain) / exposure_max; exposure = exposure_max; } else { // exposure >= exposure_shift exposure = (exposure < exposure_shift) ? exposure_shift : exposure; _dgain = (_dgain * exposure) / (exposure / exposure_shift) / exposure_shift; } _dgain = _dgain < p_gains->dgain_offset ? p_gains->dgain_offset : _dgain; _dgain = _dgain > (HI_U32)p_gains->dgain_offset * p_gains->max_dgain_target ? (HI_U32)p_gains->dgain_offset * p_gains->max_dgain_target : _dgain; for(_i=0; _i<(64*4*4); _i++) { if(_ares >= _dgain) break; _ares = (_ares * p_gains->max_dgain_step) / p_gains->dgain_offset; } _lres = _i; //exposure = exposure * (gain_offset / 64) / (_ares / 64); _dgain = _lres * 16; p_gains->dgain_fine = _dgain & 0x03FF; p_gains->dgain = _dgain >> 10; return exposure << shft; }
HI_S32 ISP_DbgRunEnd(ISP_DBG_CTRL_S *pstDbg, HI_U32 u32FrmCnt) { ISP_DBG_STATUS_S *pstDbgStatus = HI_NULL; if ((!pstDbg->bDebugEn) || (HI_NULL == pstDbg->pstDbgStatus)) { return HI_SUCCESS; } pstDbgStatus = pstDbg->pstDbgStatus + (u32FrmCnt % DIV_0_TO_1(pstDbg->u32Depth)); /* ------------- record status ------------------ */ pstDbgStatus->u32FrmNumEnd = u32FrmCnt; return HI_SUCCESS; }
static __inline HI_U32 analog_gain_from_exposure_calculate( cmos_gains_ptr_t p_gains, HI_U32 exposure, HI_U32 exposure_max, HI_U32 exposure_shift) { HI_U32 _again = 1<<p_gains->again_shift; //HI_U32 _ares = 1<<p_gains->again_shift; //HI_U32 _lres = 0; int shft = 0; while (exposure > (1<<24)) { exposure >>= 1; exposure_max >>= 1; ++shft; } if(exposure > exposure_max) { //when setting manual exposure line, exposure_max>>shift should not be 0. exposure_max = DIV_0_TO_1(exposure_max); _again = (exposure * _again) / exposure_max; // exposure = exposure_max; if (_again >= 1<< 3) { _again = 1<<3; } else if (_again >= 1<< 2) { _again = 1<<2; } else if (_again >= 1<< 1) { _again = 1<<1; } else if (_again >= 1) { _again = 1; } _again = _again < (1<<p_gains->again_shift) ? (1<<p_gains->again_shift) : _again; _again = _again > (HI_U32)(1<<p_gains->again_shift) * p_gains->max_again_target ? (HI_U32)(1<<p_gains->again_shift) * p_gains->max_again_target : _again; exposure = (exposure / _again); } else { //_again = (_again * exposure) / (exposure / exposure_shift) / exposure_shift; } p_gains->again = _again; p_gains->again_db = cmos_gains_lin_to_db_convert(p_gains->again, p_gains->again_shift); return (exposure << shft); }
HI_S32 ISP_DbgRunBgn(ISP_DBG_CTRL_S *pstDbg, HI_U32 u32FrmCnt) { //ISP_DBG_ATTR_S *pstDbgAttr = HI_NULL; ISP_DBG_STATUS_S *pstDbgStatus = HI_NULL; if (!pstDbg->bDebugEn) { if (HI_NULL != pstDbg->pstDbgAttr) { HI_MPI_SYS_Munmap(pstDbg->pstDbgAttr, pstDbg->u32Size); pstDbg->pstDbgAttr = HI_NULL; pstDbg->pstDbgStatus = HI_NULL; } return HI_SUCCESS; } if ((pstDbg->bDebugEn) && (HI_NULL == pstDbg->pstDbgAttr)) { pstDbg->pstDbgAttr = (ISP_DBG_ATTR_S *)HI_MPI_SYS_Mmap( pstDbg->u32PhyAddr, pstDbg->u32Size); if (HI_NULL == pstDbg->pstDbgAttr) { printf("isp map debug buf failed!\n"); return HI_FAILURE; } pstDbg->pstDbgStatus = (ISP_DBG_STATUS_S *)(pstDbg->pstDbgAttr + 1); //pstDbgAttr = pstDbg->pstDbgAttr; /* ------------- record attr ------------------ */ } pstDbgStatus = pstDbg->pstDbgStatus + (u32FrmCnt % DIV_0_TO_1(pstDbg->u32Depth)); pstDbgStatus->u32FrmNumBgn = u32FrmCnt; return HI_SUCCESS; }
static __inline HI_U32 digital_gain_from_exposure_calculate( cmos_gains_ptr_t p_gains, HI_U32 exposure, HI_U32 exposure_max, HI_U32 exposure_shift ) { HI_U32 _dgain = 1<<p_gains->dgain_shift; int shft = 0; while (exposure > (1<<24)) { exposure >>= 1; exposure_max >>= 1; ++shft; } if(exposure > exposure_max) { //when setting manual exposure line, exposure_max>>shift should not be 0. exposure_max = DIV_0_TO_1(exposure_max); _dgain = (exposure * _dgain) / exposure_max; exposure = exposure_max; } else { //TODO: after anti-flick, dgain may need to decrease. //_dgain = (_dgain * exposure) / (exposure / exposure_shift) / exposure_shift; } _dgain = _dgain < (1<<p_gains->dgain_shift) ? (1<<p_gains->dgain_shift) : _dgain; _dgain = _dgain > p_gains->max_dgain_target ? p_gains->max_dgain_target : _dgain; p_gains->dgain = _dgain; p_gains->dgain_db = cmos_gains_lin_to_db_convert(p_gains->dgain, p_gains->dgain_shift); return exposure << shft; }