如何客制化refine CCM
时间:10-02
整理:3721RD
点击:
[DESCRIPTION]
1:MT6582/MT6592 Chip 请参考如下修改。
FAQ 提供demo code以实现:
(1),定义指定的CCM参数以固定当前环境的CCM值不变
(2),CCM 会根据当前环境达到的real ISO动态调整饱和度
[SOLUTION]
demo code 如下:
FAQ 提供demo code以实现:
(1),定义指定的CCM参数以固定当前环境的CCM值不变
(2),CCM 会根据当前环境达到的real ISO动态调整饱和度
(3),需要注意的是,如果是 MT6735M/MT6735P 的话 ,下面demo code 里面如下部分要做客制化。
需要将chip_sumValue 修改成256 。反之 维持512 即可。
1:MT6582/MT6592 Chip 请参考如下修改。
FAQ 提供demo code以实现:
(1),定义指定的CCM参数以固定当前环境的CCM值不变
(2),CCM 会根据当前环境达到的real ISO动态调整饱和度
[SOLUTION]
demo code 如下:
- code path:
- mediatek\custom\【customer_project】\hal\CAMERA\camera\isp_tuning_custom.cpp
- #define CONV_2COMP_11(x) ( (x)<1024?(x):((int)(x)-2048) )
- #define ICONV_2COMP_11(x) ( (x)<0?((x)+2048):(x) )
- MVOID
- IspTuningCustom::
- refine_CCM(RAWIspCamInfo const& rCamInfo, IspNvrAMRegMgr const&
- rIspRegMgr, ISP_NVRAM_CCM_T& rCCM)
- {
- #if 1
- MY_LOG("%s()\n", __FUNCTION__);
- /****customize CCM value for fix CCM****/
- /************************************
- //0x072101FF, 0x000007E0, 0x016307C6, 0x000007D7, 0x075E000F, 0x00000193
- rCCM.conv0a.val = 0x072101FF;
- rCCM.conv0b.val = 0x000007E0;
- rCCM.conv1a.val = 0x016307C6;
- rCCM.conv1b.val = 0x000007D7;
- rCCM.conv2a.val = 0x075E000F;
- rCCM.conv2b.val = 0x00000193;
- ************************************/
- MY_LOG("Before rCCM.conv0a = 0x%8x", rCCM.conv0a);
- MY_LOG("Before rCCM.conv0b = 0x%8x", rCCM.conv0b);
- MY_LOG("Before rCCM.conv1a = 0x%8x", rCCM.conv1a);
- MY_LOG("Before rCCM.conv1b = 0x%8x", rCCM.conv1b);
- MY_LOG("Before rCCM.conv2a = 0x%8x", rCCM.conv2a);
- MY_LOG("Before rCCM.conv2b = 0x%8x", rCCM.conv2b);
- //get current CCM
- MINT32 CCM_00 = CONV_2COMP_11(rCCM.conv0a.bits.G2G_CNV_00);
- MINT32 CCM_01 = CONV_2COMP_11(rCCM.conv0a.bits.G2G_CNV_01);
- MINT32 CCM_02 = CONV_2COMP_11(rCCM.conv0b.bits.G2G_CNV_02);
- MINT32 CCM_10 = CONV_2COMP_11(rCCM.conv1a.bits.G2G_CNV_10);
- MINT32 CCM_11 = CONV_2COMP_11(rCCM.conv1a.bits.G2G_CNV_11);
- MINT32 CCM_12 = CONV_2COMP_11(rCCM.conv1b.bits.G2G_CNV_12);
- MINT32 CCM_20 = CONV_2COMP_11(rCCM.conv2a.bits.G2G_CNV_20);
- MINT32 CCM_21 = CONV_2COMP_11(rCCM.conv2a.bits.G2G_CNV_21);
- MINT32 CCM_22 = CONV_2COMP_11(rCCM.conv2b.bits.G2G_CNV_22);
- // tuning parameter
- const MINT32 iso_l = 400;//250;
- const MINT32 iso_h = 600;
- const int gain_l = 128;
- const int gain_h = (int)(0.75*128);
- /*
- --------------+---------------------------------------------------+-------
- ------------------------
- ISO < iso_l iso_l < ISO < iso_h ISO > iso_h
- gain = gain_l gain = linear interpolation(gain_l, gain_h) gain = gain_h
- */
- //update CCM when different real ISO
- MINT32 current_iso = rCamInfo.u4ISOValue;
- int current_gain = 128;
- if(current_iso<iso_l)
- current_gain = gain_l;
- else if(current_iso>iso_h)
- current_gain = gain_h;
- else
- current_gain = gain_l + (gain_h-gain_l)*(current_iso-iso_l)/(iso_h-iso_l);
- CCM_01 = (CCM_01)*current_gain/128;
- CCM_02 = (CCM_02)*current_gain/128;
- CCM_00 = 256 - (CCM_01+CCM_02);
- CCM_10 = (CCM_10)*current_gain/128;
- CCM_12 = (CCM_12)*current_gain/128;
- CCM_11 = 256 - (CCM_10+CCM_12);
- CCM_20 = (CCM_20)*current_gain/128;
- CCM_21 = (CCM_21)*current_gain/128;
- CCM_22 = 256 - (CCM_20+CCM_21);
- //set new CCM
- rCCM.conv0a.bits.G2G_CNV_00 = ICONV_2COMP_11(CCM_00);
- rCCM.conv0a.bits.G2G_CNV_01 = ICONV_2COMP_11(CCM_01);
- rCCM.conv0b.bits.G2G_CNV_02 = ICONV_2COMP_11(CCM_02);
- rCCM.conv1a.bits.G2G_CNV_10 = ICONV_2COMP_11(CCM_10);
- rCCM.conv1a.bits.G2G_CNV_11 = ICONV_2COMP_11(CCM_11);
- rCCM.conv1b.bits.G2G_CNV_12 = ICONV_2COMP_11(CCM_12);
- rCCM.conv2a.bits.G2G_CNV_20 = ICONV_2COMP_11(CCM_20);
- rCCM.conv2a.bits.G2G_CNV_21 = ICONV_2COMP_11(CCM_21);
- rCCM.conv2b.bits.G2G_CNV_22 = ICONV_2COMP_11(CCM_22);
- MY_LOG("After rCCM.conv0a = 0x%8x", rCCM.conv0a);
- MY_LOG("After rCCM.conv0b = 0x%8x", rCCM.conv0b);
- MY_LOG("After rCCM.conv1a = 0x%8x", rCCM.conv1a);
- MY_LOG("After rCCM.conv1b = 0x%8x", rCCM.conv1b);
- MY_LOG("After rCCM.conv2a = 0x%8x", rCCM.conv2a);
- MY_LOG("After rCCM.conv2b = 0x%8x", rCCM.conv2b);
- #endif
- }
FAQ 提供demo code以实现:
(1),定义指定的CCM参数以固定当前环境的CCM值不变
(2),CCM 会根据当前环境达到的real ISO动态调整饱和度
(3),需要注意的是,如果是 MT6735M/MT6735P 的话 ,下面demo code 里面如下部分要做客制化。
需要将chip_sumValue 修改成256 。反之 维持512 即可。
- const MINT32 chip_sumValue = 512; // for MT6752/32/35/53
- //const MINT32 chip_sumValue = 256; // for MT6735M/MT6735P
- [SOLUTION]
- code path:
- alps\vendor\mediatek\proprietary\custom\[$platform,$project]\hal\camera3a\isp_tuning_custom.cpp
- MVOID
- IspTuningCustom::
- refine_CCM(RAWIspCamInfo const& rCamInfo, IspNvramRegMgr & rIspRegMgr,
- ISP_NVRAM_CCM_T& rCCM)
- {
- #if 0
- MY_LOG("%s()\n", __FUNCTION__);
- // TODO: Add your code below...
- MY_LOG("rCCM.cnv_1 = 0x%8x", rCCM.cnv_1);
- MY_LOG("rCCM.cnv_2 = 0x%8x", rCCM.cnv_2);
- MY_LOG("rCCM.cnv_3 = 0x%8x", rCCM.cnv_3);
- MY_LOG("rCCM.cnv_4 = 0x%8x", rCCM.cnv_4);
- MY_LOG("rCCM.cnv_5 = 0x%8x", rCCM.cnv_5);
- MY_LOG("rCCM.cnv_6 = 0x%8x", rCCM.cnv_6);
- #endif
- if(rCamInfo.eIspProfile == EIspProfile_IHDR_Preview ||
- rCamInfo.eIspProfile == EIspProfile_IHDR_Video)
- {
- char debugFlag[PROPERTY_VALUE_MAX] = {'\0'};
- property_get("debug.vhdr.tuning", debugFlag, "0");
- MINT32 digit_00 = Complement2((rCCM.cnv_1.val & 0x1FFF),13);
- MINT32 digit_01 = Complement2(((rCCM.cnv_1.val & 0x1FFF0000) >> 16),13);
- MINT32 digit_02 = Complement2((rCCM.cnv_2.val & 0x1FFF),13);
- MINT32 digit_10 = Complement2((rCCM.cnv_3.val & 0x1FFF),13);
- MINT32 digit_11 = Complement2(((rCCM.cnv_3.val & 0x1FFF0000) >> 16),13);
- MINT32 digit_12 = Complement2((rCCM.cnv_4.val & 0x1FFF),13);
- MINT32 digit_20 = Complement2((rCCM.cnv_5.val & 0x1FFF),13);
- MINT32 digit_21 = Complement2(((rCCM.cnv_5.val & 0x1FFF0000) >> 16),13);
- MINT32 digit_22 = Complement2((rCCM.cnv_6.val & 0x1FFF),13);
- if(debugFlag[0] == '1')
- {
- MY_LOG("ori:00(%d),01(%d),02(%d)",digit_00,digit_01,digit_02);
- MY_LOG("ori:10(%d),11(%d),12(%d)",digit_10,digit_11,digit_12);
- MY_LOG("ori:20(%d),21(%d),22(%d)",digit_20,digit_21,digit_22);
- }
- MFLOAT temp_01 = 0.7 * (MFLOAT)digit_01;
- MFLOAT temp_02 = 0.7 * (MFLOAT)digit_02;
- MFLOAT temp_10 = 0.7 * (MFLOAT)digit_10;
- MFLOAT temp_12 = 0.7 * (MFLOAT)digit_12;
- MFLOAT temp_20 = 0.7 * (MFLOAT)digit_20;
- MFLOAT temp_21 = 0.7 * (MFLOAT)digit_21;
- MINT32 final_00 = ((MFLOAT)digit_00-512.0) * 0.7 + 0.5 + 512.0;
- MINT32 final_01 = (temp_01 > 0) ? temp_01 + 0.5 : temp_01 - 0.5;
- MINT32 final_02 = (temp_02 > 0) ? temp_02 + 0.5 : temp_02 - 0.5;
- MINT32 final_10 = (temp_10 > 0) ? temp_10 + 0.5 : temp_10 - 0.5;
- MINT32 final_11 = ((MFLOAT)digit_11-512.0) * 0.7 + 0.5 + 512.0;
- MINT32 final_12 = (temp_12 > 0) ? temp_12 + 0.5 : temp_12 - 0.5;
- MINT32 final_20 = (temp_20 > 0) ? temp_20 + 0.5 : temp_20 - 0.5;
- MINT32 final_21 = (temp_21 > 0) ? temp_21 + 0.5 : temp_21 - 0.5;
- MINT32 final_22 = ((MFLOAT)digit_22-512.0) * 0.7 + 0.5 + 512.0;
- //> check sum = 512 at each raw
- const MINT32 sumValue = 512;
- final_00 += sumValue - (final_00 + final_01 + final_02);
- final_11 += sumValue - (final_10 + final_11 + final_12);
- final_22 += sumValue - (final_20 + final_21 + final_22);
- if(debugFlag[0] == '1')
- {
- MY_LOG("final:00(%d),01(%d),02(%d)",final_00,final_01,final_02);
- MY_LOG("final:10(%d),11(%d),12(%d)",final_10,final_11,final_12);
- MY_LOG("final:20(%d),21(%d),22(%d)",final_20,final_21,final_22);
- }
- rCCM.cnv_1.val = 0 | (final_00 & 0x1FFF) | ((final_01 & 0x1FFF) << 16);
- rCCM.cnv_2.val = 0 | (final_02 & 0x1FFF);
- rCCM.cnv_3.val = 0 | (final_10 & 0x1FFF) | ((final_11 & 0x1FFF) << 16);
- rCCM.cnv_4.val = 0 | (final_12 & 0x1FFF);
- rCCM.cnv_5.val = 0 | (final_20 & 0x1FFF) | ((final_21 & 0x1FFF) << 16);
- rCCM.cnv_6.val = 0 | (final_22 & 0x1FFF);
- if(debugFlag[0] == '1')
- {
- MY_LOG("final:rCCM.cnv_1 = 0x%08x", rCCM.cnv_1.val);
- MY_LOG("final:rCCM.cnv_2 = 0x%08x", rCCM.cnv_2.val);
- MY_LOG("final:rCCM.cnv_3 = 0x%08x", rCCM.cnv_3.val);
- MY_LOG("final:rCCM.cnv_4 = 0x%08x", rCCM.cnv_4.val);
- MY_LOG("final:rCCM.cnv_5 = 0x%08x", rCCM.cnv_5.val);
- MY_LOG("final:rCCM.cnv_6 = 0x%08x", rCCM.cnv_6.val);
- } }
- else if(rCamInfo.eIspProfile ==EIspProfile_Preview || rCamInfo.eIspProfile
- == EIspProfile_Capture|| rCamInfo.eIspProfile == EIspProfile_Capture_SWNR)
- //
- {
- char debugFlag[PROPERTY_VALUE_MAX] = {'1'};
- property_get("debug.vhdr.tuning", debugFlag, "0");
- MINT32 iso_l ;//= 400;
- MINT32 iso_h;// = 600;
- const MINT32 chip_sumValue = 512; // for MT6752/32/35/53
- //const MINT32 chip_sumValue = 256; // for MT6735M/MT6735P
- const MFLOAT gain_l = 1;
- MFLOAT gain_h ;
- MFLOAT current_gain = 1;
- MY_LOG("shenan1,rCamInfo.rFlashInfo.isFlash = 0x%08x",
- rCamInfo.rFlashInfo.isFlash);
- iso_l = 800;
- iso_h = 1200;
- gain_h = 0.5;//0.2
- /*
- --------------+---------------------------------------------------+-------
- ------------------------
- ISO < iso_l iso_l < ISO < iso_h ISO > iso_h
- gain = gain_l gain = linear interpolation(gain_l, gain_h) gain = gain_h
- */
- //update CCM when different real ISO
- //MINT32 current_iso = rCamInfo.u4ISOValue;
- MINT32 current_iso =
- (rCamInfo.rAEInfo.u4AfeGain/10000.0)*(rCamInfo.rAEInfo.u4IspGain);
- //int current_gain = 128;
- MY_LOG("rCamInfo.rAEInfo.u4AfeGain = 0x%08x", rCamInfo.rAEInfo.u4AfeGain);
- MY_LOG("rCamInfo.rAEInfo.u4IspGain = 0x%08x", rCamInfo.rAEInfo.u4IspGain);
- MY_LOG("current_iso = 0x%08x", current_iso);
- if(current_iso < iso_l)
- {
- current_gain = gain_l;
- MY_LOG("1");
- }
- else {
- if(current_iso > iso_h)
- {
- current_gain = gain_h;
- MY_LOG("2");
- }
- else
- {
- current_gain = gain_l+(MFLOAT)((gain_h-gain_l)*(current_iso-iso_l)/(iso_hiso_l));
- MY_LOG("3");
- }
- }
- MY_LOG("current_gain = %f", current_gain);
- MINT32 digit_00 = Complement2((rCCM.cnv_1.val & 0x1FFF),13);
- MINT32 digit_01 = Complement2(((rCCM.cnv_1.val & 0x1FFF0000) >> 16),13);
- MINT32 digit_02 = Complement2((rCCM.cnv_2.val & 0x1FFF),13);
- MINT32 digit_10 = Complement2((rCCM.cnv_3.val & 0x1FFF),13);
- MINT32 digit_11 = Complement2(((rCCM.cnv_3.val & 0x1FFF0000) >> 16),13);
- MINT32 digit_12 = Complement2((rCCM.cnv_4.val & 0x1FFF),13);
- MINT32 digit_20 = Complement2((rCCM.cnv_5.val & 0x1FFF),13);
- MINT32 digit_21 = Complement2(((rCCM.cnv_5.val & 0x1FFF0000) >> 16),13);
- MINT32 digit_22 = Complement2((rCCM.cnv_6.val & 0x1FFF),13);
- //if(debugFlag[0] == '1')
- {
- MY_LOG("ori:00(%d),01(%d),02(%d)",digit_00,digit_01,digit_02);
- MY_LOG("ori:10(%d),11(%d),12(%d)",digit_10,digit_11,digit_12);
- MY_LOG("ori:20(%d),21(%d),22(%d)",digit_20,digit_21,digit_22);
- }
- MFLOAT temp_01 = current_gain * (MFLOAT)digit_01;
- MFLOAT temp_02 = current_gain * (MFLOAT)digit_02;
- MFLOAT temp_10 = current_gain * (MFLOAT)digit_10;
- MFLOAT temp_12 = current_gain * (MFLOAT)digit_12;
- MFLOAT temp_20 = current_gain * (MFLOAT)digit_20;
- MFLOAT temp_21 = current_gain * (MFLOAT)digit_21;
- MINT32 final_00 = ((MFLOAT)digit_00-chip_sumValue) * current_gain + 0.5 +
- chip_sumValue;
- MINT32 final_01 = (temp_01 > 0) ? temp_01 + 0.5 : temp_01 - 0.5;
- MINT32 final_02 = (temp_02 > 0) ? temp_02 + 0.5 : temp_02 - 0.5;
- MINT32 final_10 = (temp_10 > 0) ? temp_10 + 0.5 : temp_10 - 0.5;
- MINT32 final_11 = ((MFLOAT)digit_11-chip_sumValue) * current_gain + 0.5 +
- chip_sumValue;
- MINT32 final_12 = (temp_12 > 0) ? temp_12 + 0.5 : temp_12 - 0.5;
- MINT32 final_20 = (temp_20 > 0) ? temp_20 + 0.5 : temp_20 - 0.5;
- MINT32 final_21 = (temp_21 > 0) ? temp_21 + 0.5 : temp_21 - 0.5;
- MINT32 final_22 = ((MFLOAT)digit_22-chip_sumValue) * current_gain + 0.5 +
- chip_sumValue;
- final_00 += chip_sumValue - (final_00 + final_01 + final_02);
- final_11 += chip_sumValue - (final_10 + final_11 + final_12);
- final_22 += chip_sumValue - (final_20 + final_21 + final_22);
- //if(debugFlag[0] == '1')
- {
- MY_LOG("final:00(%d),01(%d),02(%d)",final_00,final_01,final_02);
- MY_LOG("final:10(%d),11(%d),12(%d)",final_10,final_11,final_12);
- MY_LOG("final:20(%d),21(%d),22(%d)",final_20,final_21,final_22);
- }
- rCCM.cnv_1.val = 0 | (final_00 & 0x1FFF) | ((final_01 & 0x1FFF) << 16);
- rCCM.cnv_2.val = 0 | (final_02 & 0x1FFF);
- rCCM.cnv_3.val = 0 | (final_10 & 0x1FFF) | ((final_11 & 0x1FFF) << 16);
- rCCM.cnv_4.val = 0 | (final_12 & 0x1FFF);
- rCCM.cnv_5.val = 0 | (final_20 & 0x1FFF) | ((final_21 & 0x1FFF) << 16);
- rCCM.cnv_6.val = 0 | (final_22 & 0x1FFF);
- //if(debugFlag[0] == '1')
- {
- MY_LOG("final:rCCM.cnv_1.val = 0x%08x", rCCM.cnv_1.val);
- MY_LOG("final:rCCM.cnv_2.val = 0x%08x", rCCM.cnv_2.val);
- MY_LOG("final:rCCM.cnv_3.val = 0x%08x", rCCM.cnv_3.val);
- MY_LOG("final:rCCM.cnv_4.val = 0x%08x", rCCM.cnv_4.val);
- MY_LOG("final:rCCM.cnv_5.val = 0x%08x", rCCM.cnv_5.val);
- MY_LOG("final:rCCM.cnv_6.val = 0x%08x", rCCM.cnv_6.val);
- }
- }
- }