微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 手机设计讨论 > MTK手机平台交流 > 如何客制化refine CCM

如何客制化refine CCM

时间:10-02 整理:3721RD 点击:
[DESCRIPTION]
1:MT6582/MT6592 Chip 请参考如下修改。
FAQ 提供demo code以实现:
(1),定义指定的CCM参数以固定当前环境的CCM值不变
(2),CCM 会根据当前环境达到的real ISO动态调整饱和度
[SOLUTION]
demo code 如下:

  1. code path:
  2. mediatek\custom\【customer_project】\hal\CAMERA\camera\isp_tuning_custom.cpp
  3. #define CONV_2COMP_11(x) ( (x)<1024?(x):((int)(x)-2048) )
  4. #define ICONV_2COMP_11(x) ( (x)<0?((x)+2048):(x) )
  5. MVOID
  6. IspTuningCustom::
  7. refine_CCM(RAWIspCamInfo const& rCamInfo, IspNvrAMRegMgr const&
  8. rIspRegMgr, ISP_NVRAM_CCM_T& rCCM)
  9. {
  10. #if 1
  11. MY_LOG("%s()\n", __FUNCTION__);
  12. /****customize CCM value for fix CCM****/
  13. /************************************
  14. //0x072101FF, 0x000007E0, 0x016307C6, 0x000007D7, 0x075E000F, 0x00000193
  15. rCCM.conv0a.val = 0x072101FF;
  16. rCCM.conv0b.val = 0x000007E0;
  17. rCCM.conv1a.val = 0x016307C6;
  18. rCCM.conv1b.val = 0x000007D7;
  19. rCCM.conv2a.val = 0x075E000F;
  20. rCCM.conv2b.val = 0x00000193;
  21. ************************************/
  22. MY_LOG("Before rCCM.conv0a = 0x%8x", rCCM.conv0a);
  23. MY_LOG("Before rCCM.conv0b = 0x%8x", rCCM.conv0b);
  24. MY_LOG("Before rCCM.conv1a = 0x%8x", rCCM.conv1a);
  25. MY_LOG("Before rCCM.conv1b = 0x%8x", rCCM.conv1b);
  26. MY_LOG("Before rCCM.conv2a = 0x%8x", rCCM.conv2a);
  27. MY_LOG("Before rCCM.conv2b = 0x%8x", rCCM.conv2b);
  28. //get current CCM
  29. MINT32 CCM_00 = CONV_2COMP_11(rCCM.conv0a.bits.G2G_CNV_00);
  30. MINT32 CCM_01 = CONV_2COMP_11(rCCM.conv0a.bits.G2G_CNV_01);
  31. MINT32 CCM_02 = CONV_2COMP_11(rCCM.conv0b.bits.G2G_CNV_02);
  32. MINT32 CCM_10 = CONV_2COMP_11(rCCM.conv1a.bits.G2G_CNV_10);
  33. MINT32 CCM_11 = CONV_2COMP_11(rCCM.conv1a.bits.G2G_CNV_11);
  34. MINT32 CCM_12 = CONV_2COMP_11(rCCM.conv1b.bits.G2G_CNV_12);
  35. MINT32 CCM_20 = CONV_2COMP_11(rCCM.conv2a.bits.G2G_CNV_20);
  36. MINT32 CCM_21 = CONV_2COMP_11(rCCM.conv2a.bits.G2G_CNV_21);
  37. MINT32 CCM_22 = CONV_2COMP_11(rCCM.conv2b.bits.G2G_CNV_22);
  38. // tuning parameter
  39. const MINT32 iso_l = 400;//250;
  40. const MINT32 iso_h = 600;
  41. const int gain_l = 128;
  42. const int gain_h = (int)(0.75*128);
  43. /*
  44. --------------+---------------------------------------------------+-------
  45. ------------------------
  46. ISO < iso_l iso_l < ISO < iso_h ISO > iso_h
  47. gain = gain_l gain = linear interpolation(gain_l, gain_h) gain = gain_h
  48. */
  49. //update CCM when different real ISO
  50. MINT32 current_iso = rCamInfo.u4ISOValue;
  51. int current_gain = 128;
  52. if(current_iso<iso_l)
  53. current_gain = gain_l;
  54. else if(current_iso>iso_h)
  55. current_gain = gain_h;
  56. else
  57. current_gain = gain_l + (gain_h-gain_l)*(current_iso-iso_l)/(iso_h-iso_l);
  58. CCM_01 = (CCM_01)*current_gain/128;
  59. CCM_02 = (CCM_02)*current_gain/128;
  60. CCM_00 = 256 - (CCM_01+CCM_02);
  61. CCM_10 = (CCM_10)*current_gain/128;
  62. CCM_12 = (CCM_12)*current_gain/128;
  63. CCM_11 = 256 - (CCM_10+CCM_12);
  64. CCM_20 = (CCM_20)*current_gain/128;
  65. CCM_21 = (CCM_21)*current_gain/128;
  66. CCM_22 = 256 - (CCM_20+CCM_21);
  67. //set new CCM
  68. rCCM.conv0a.bits.G2G_CNV_00 = ICONV_2COMP_11(CCM_00);
  69. rCCM.conv0a.bits.G2G_CNV_01 = ICONV_2COMP_11(CCM_01);
  70. rCCM.conv0b.bits.G2G_CNV_02 = ICONV_2COMP_11(CCM_02);
  71. rCCM.conv1a.bits.G2G_CNV_10 = ICONV_2COMP_11(CCM_10);
  72. rCCM.conv1a.bits.G2G_CNV_11 = ICONV_2COMP_11(CCM_11);
  73. rCCM.conv1b.bits.G2G_CNV_12 = ICONV_2COMP_11(CCM_12);
  74. rCCM.conv2a.bits.G2G_CNV_20 = ICONV_2COMP_11(CCM_20);
  75. rCCM.conv2a.bits.G2G_CNV_21 = ICONV_2COMP_11(CCM_21);
  76. rCCM.conv2b.bits.G2G_CNV_22 = ICONV_2COMP_11(CCM_22);
  77. MY_LOG("After rCCM.conv0a = 0x%8x", rCCM.conv0a);
  78. MY_LOG("After rCCM.conv0b = 0x%8x", rCCM.conv0b);
  79. MY_LOG("After rCCM.conv1a = 0x%8x", rCCM.conv1a);
  80. MY_LOG("After rCCM.conv1b = 0x%8x", rCCM.conv1b);
  81. MY_LOG("After rCCM.conv2a = 0x%8x", rCCM.conv2a);
  82. MY_LOG("After rCCM.conv2b = 0x%8x", rCCM.conv2b);
  83. #endif
  84. }

复制代码

2:MT6752/MT6732/mt6735/MT6753/MT6735M/MT6735P 请参考如下修改。
FAQ 提供demo code以实现:
(1),定义指定的CCM参数以固定当前环境的CCM值不变
(2),CCM 会根据当前环境达到的real ISO动态调整饱和度
(3),需要注意的是,如果是 MT6735M/MT6735P 的话 ,下面demo code 里面如下部分要做客制化。
需要将chip_sumValue 修改成256 。反之 维持512 即可。

  1. const MINT32 chip_sumValue = 512; // for MT6752/32/35/53
  2. //const MINT32 chip_sumValue = 256; // for MT6735M/MT6735P
  3. [SOLUTION]

复制代码

demo code 如下:

  1. code path:
  2. alps\vendor\mediatek\proprietary\custom\[$platform,$project]\hal\camera3a\isp_tuning_custom.cpp
  3. MVOID
  4. IspTuningCustom::
  5. refine_CCM(RAWIspCamInfo const& rCamInfo, IspNvramRegMgr & rIspRegMgr,
  6. ISP_NVRAM_CCM_T& rCCM)
  7. {
  8. #if 0
  9. MY_LOG("%s()\n", __FUNCTION__);
  10. // TODO: Add your code below...
  11. MY_LOG("rCCM.cnv_1 = 0x%8x", rCCM.cnv_1);
  12. MY_LOG("rCCM.cnv_2 = 0x%8x", rCCM.cnv_2);
  13. MY_LOG("rCCM.cnv_3 = 0x%8x", rCCM.cnv_3);
  14. MY_LOG("rCCM.cnv_4 = 0x%8x", rCCM.cnv_4);
  15. MY_LOG("rCCM.cnv_5 = 0x%8x", rCCM.cnv_5);
  16. MY_LOG("rCCM.cnv_6 = 0x%8x", rCCM.cnv_6);
  17. #endif
  18. if(rCamInfo.eIspProfile == EIspProfile_IHDR_Preview ||
  19. rCamInfo.eIspProfile == EIspProfile_IHDR_Video)
  20. {
  21. char debugFlag[PROPERTY_VALUE_MAX] = {'\0'};
  22. property_get("debug.vhdr.tuning", debugFlag, "0");
  23. MINT32 digit_00 = Complement2((rCCM.cnv_1.val & 0x1FFF),13);
  24. MINT32 digit_01 = Complement2(((rCCM.cnv_1.val & 0x1FFF0000) >> 16),13);
  25. MINT32 digit_02 = Complement2((rCCM.cnv_2.val & 0x1FFF),13);
  26. MINT32 digit_10 = Complement2((rCCM.cnv_3.val & 0x1FFF),13);
  27. MINT32 digit_11 = Complement2(((rCCM.cnv_3.val & 0x1FFF0000) >> 16),13);
  28. MINT32 digit_12 = Complement2((rCCM.cnv_4.val & 0x1FFF),13);
  29. MINT32 digit_20 = Complement2((rCCM.cnv_5.val & 0x1FFF),13);
  30. MINT32 digit_21 = Complement2(((rCCM.cnv_5.val & 0x1FFF0000) >> 16),13);
  31. MINT32 digit_22 = Complement2((rCCM.cnv_6.val & 0x1FFF),13);
  32. if(debugFlag[0] == '1')
  33. {
  34. MY_LOG("ori:00(%d),01(%d),02(%d)",digit_00,digit_01,digit_02);
  35. MY_LOG("ori:10(%d),11(%d),12(%d)",digit_10,digit_11,digit_12);
  36. MY_LOG("ori:20(%d),21(%d),22(%d)",digit_20,digit_21,digit_22);
  37. }
  38. MFLOAT temp_01 = 0.7 * (MFLOAT)digit_01;
  39. MFLOAT temp_02 = 0.7 * (MFLOAT)digit_02;
  40. MFLOAT temp_10 = 0.7 * (MFLOAT)digit_10;
  41. MFLOAT temp_12 = 0.7 * (MFLOAT)digit_12;
  42. MFLOAT temp_20 = 0.7 * (MFLOAT)digit_20;
  43. MFLOAT temp_21 = 0.7 * (MFLOAT)digit_21;
  44. MINT32 final_00 = ((MFLOAT)digit_00-512.0) * 0.7 + 0.5 + 512.0;
  45. MINT32 final_01 = (temp_01 > 0) ? temp_01 + 0.5 : temp_01 - 0.5;
  46. MINT32 final_02 = (temp_02 > 0) ? temp_02 + 0.5 : temp_02 - 0.5;
  47. MINT32 final_10 = (temp_10 > 0) ? temp_10 + 0.5 : temp_10 - 0.5;
  48. MINT32 final_11 = ((MFLOAT)digit_11-512.0) * 0.7 + 0.5 + 512.0;
  49. MINT32 final_12 = (temp_12 > 0) ? temp_12 + 0.5 : temp_12 - 0.5;
  50. MINT32 final_20 = (temp_20 > 0) ? temp_20 + 0.5 : temp_20 - 0.5;
  51. MINT32 final_21 = (temp_21 > 0) ? temp_21 + 0.5 : temp_21 - 0.5;
  52. MINT32 final_22 = ((MFLOAT)digit_22-512.0) * 0.7 + 0.5 + 512.0;
  53. //> check sum = 512 at each raw
  54. const MINT32 sumValue = 512;
  55. final_00 += sumValue - (final_00 + final_01 + final_02);
  56. final_11 += sumValue - (final_10 + final_11 + final_12);
  57. final_22 += sumValue - (final_20 + final_21 + final_22);
  58. if(debugFlag[0] == '1')
  59. {
  60. MY_LOG("final:00(%d),01(%d),02(%d)",final_00,final_01,final_02);
  61. MY_LOG("final:10(%d),11(%d),12(%d)",final_10,final_11,final_12);
  62. MY_LOG("final:20(%d),21(%d),22(%d)",final_20,final_21,final_22);
  63. }
  64. rCCM.cnv_1.val = 0 | (final_00 & 0x1FFF) | ((final_01 & 0x1FFF) << 16);
  65. rCCM.cnv_2.val = 0 | (final_02 & 0x1FFF);
  66. rCCM.cnv_3.val = 0 | (final_10 & 0x1FFF) | ((final_11 & 0x1FFF) << 16);
  67. rCCM.cnv_4.val = 0 | (final_12 & 0x1FFF);
  68. rCCM.cnv_5.val = 0 | (final_20 & 0x1FFF) | ((final_21 & 0x1FFF) << 16);
  69. rCCM.cnv_6.val = 0 | (final_22 & 0x1FFF);
  70. if(debugFlag[0] == '1')
  71. {
  72. MY_LOG("final:rCCM.cnv_1 = 0x%08x", rCCM.cnv_1.val);
  73. MY_LOG("final:rCCM.cnv_2 = 0x%08x", rCCM.cnv_2.val);
  74. MY_LOG("final:rCCM.cnv_3 = 0x%08x", rCCM.cnv_3.val);
  75. MY_LOG("final:rCCM.cnv_4 = 0x%08x", rCCM.cnv_4.val);
  76. MY_LOG("final:rCCM.cnv_5 = 0x%08x", rCCM.cnv_5.val);
  77. MY_LOG("final:rCCM.cnv_6 = 0x%08x", rCCM.cnv_6.val);
  78. } }
  79. else if(rCamInfo.eIspProfile ==EIspProfile_Preview || rCamInfo.eIspProfile
  80. == EIspProfile_Capture|| rCamInfo.eIspProfile == EIspProfile_Capture_SWNR)
  81. //
  82. {
  83. char debugFlag[PROPERTY_VALUE_MAX] = {'1'};
  84. property_get("debug.vhdr.tuning", debugFlag, "0");
  85. MINT32 iso_l ;//= 400;
  86. MINT32 iso_h;// = 600;
  87. const MINT32 chip_sumValue = 512; // for MT6752/32/35/53
  88. //const MINT32 chip_sumValue = 256; // for MT6735M/MT6735P
  89. const MFLOAT gain_l = 1;
  90. MFLOAT gain_h ;
  91. MFLOAT current_gain = 1;
  92. MY_LOG("shenan1,rCamInfo.rFlashInfo.isFlash = 0x%08x",
  93. rCamInfo.rFlashInfo.isFlash);
  94. iso_l = 800;
  95. iso_h = 1200;
  96. gain_h = 0.5;//0.2
  97. /*
  98. --------------+---------------------------------------------------+-------
  99. ------------------------
  100. ISO < iso_l iso_l < ISO < iso_h ISO > iso_h
  101. gain = gain_l gain = linear interpolation(gain_l, gain_h) gain = gain_h
  102. */
  103. //update CCM when different real ISO
  104. //MINT32 current_iso = rCamInfo.u4ISOValue;
  105. MINT32 current_iso =
  106. (rCamInfo.rAEInfo.u4AfeGain/10000.0)*(rCamInfo.rAEInfo.u4IspGain);
  107. //int current_gain = 128;
  108. MY_LOG("rCamInfo.rAEInfo.u4AfeGain = 0x%08x", rCamInfo.rAEInfo.u4AfeGain);
  109. MY_LOG("rCamInfo.rAEInfo.u4IspGain = 0x%08x", rCamInfo.rAEInfo.u4IspGain);
  110. MY_LOG("current_iso = 0x%08x", current_iso);
  111. if(current_iso < iso_l)
  112. {
  113. current_gain = gain_l;
  114. MY_LOG("1");
  115. }
  116. else {
  117. if(current_iso > iso_h)
  118. {
  119. current_gain = gain_h;
  120. MY_LOG("2");
  121. }
  122. else
  123. {
  124. current_gain = gain_l+(MFLOAT)((gain_h-gain_l)*(current_iso-iso_l)/(iso_hiso_l));
  125. MY_LOG("3");
  126. }
  127. }
  128. MY_LOG("current_gain = %f", current_gain);
  129. MINT32 digit_00 = Complement2((rCCM.cnv_1.val & 0x1FFF),13);
  130. MINT32 digit_01 = Complement2(((rCCM.cnv_1.val & 0x1FFF0000) >> 16),13);
  131. MINT32 digit_02 = Complement2((rCCM.cnv_2.val & 0x1FFF),13);
  132. MINT32 digit_10 = Complement2((rCCM.cnv_3.val & 0x1FFF),13);
  133. MINT32 digit_11 = Complement2(((rCCM.cnv_3.val & 0x1FFF0000) >> 16),13);
  134. MINT32 digit_12 = Complement2((rCCM.cnv_4.val & 0x1FFF),13);
  135. MINT32 digit_20 = Complement2((rCCM.cnv_5.val & 0x1FFF),13);
  136. MINT32 digit_21 = Complement2(((rCCM.cnv_5.val & 0x1FFF0000) >> 16),13);
  137. MINT32 digit_22 = Complement2((rCCM.cnv_6.val & 0x1FFF),13);
  138. //if(debugFlag[0] == '1')
  139. {
  140. MY_LOG("ori:00(%d),01(%d),02(%d)",digit_00,digit_01,digit_02);
  141. MY_LOG("ori:10(%d),11(%d),12(%d)",digit_10,digit_11,digit_12);
  142. MY_LOG("ori:20(%d),21(%d),22(%d)",digit_20,digit_21,digit_22);
  143. }
  144. MFLOAT temp_01 = current_gain * (MFLOAT)digit_01;
  145. MFLOAT temp_02 = current_gain * (MFLOAT)digit_02;
  146. MFLOAT temp_10 = current_gain * (MFLOAT)digit_10;
  147. MFLOAT temp_12 = current_gain * (MFLOAT)digit_12;
  148. MFLOAT temp_20 = current_gain * (MFLOAT)digit_20;
  149. MFLOAT temp_21 = current_gain * (MFLOAT)digit_21;
  150. MINT32 final_00 = ((MFLOAT)digit_00-chip_sumValue) * current_gain + 0.5 +
  151. chip_sumValue;
  152. MINT32 final_01 = (temp_01 > 0) ? temp_01 + 0.5 : temp_01 - 0.5;
  153. MINT32 final_02 = (temp_02 > 0) ? temp_02 + 0.5 : temp_02 - 0.5;
  154. MINT32 final_10 = (temp_10 > 0) ? temp_10 + 0.5 : temp_10 - 0.5;
  155. MINT32 final_11 = ((MFLOAT)digit_11-chip_sumValue) * current_gain + 0.5 +
  156. chip_sumValue;
  157. MINT32 final_12 = (temp_12 > 0) ? temp_12 + 0.5 : temp_12 - 0.5;
  158. MINT32 final_20 = (temp_20 > 0) ? temp_20 + 0.5 : temp_20 - 0.5;
  159. MINT32 final_21 = (temp_21 > 0) ? temp_21 + 0.5 : temp_21 - 0.5;
  160. MINT32 final_22 = ((MFLOAT)digit_22-chip_sumValue) * current_gain + 0.5 +
  161. chip_sumValue;
  162. final_00 += chip_sumValue - (final_00 + final_01 + final_02);
  163. final_11 += chip_sumValue - (final_10 + final_11 + final_12);
  164. final_22 += chip_sumValue - (final_20 + final_21 + final_22);
  165. //if(debugFlag[0] == '1')
  166. {
  167. MY_LOG("final:00(%d),01(%d),02(%d)",final_00,final_01,final_02);
  168. MY_LOG("final:10(%d),11(%d),12(%d)",final_10,final_11,final_12);
  169. MY_LOG("final:20(%d),21(%d),22(%d)",final_20,final_21,final_22);
  170. }
  171. rCCM.cnv_1.val = 0 | (final_00 & 0x1FFF) | ((final_01 & 0x1FFF) << 16);
  172. rCCM.cnv_2.val = 0 | (final_02 & 0x1FFF);
  173. rCCM.cnv_3.val = 0 | (final_10 & 0x1FFF) | ((final_11 & 0x1FFF) << 16);
  174. rCCM.cnv_4.val = 0 | (final_12 & 0x1FFF);
  175. rCCM.cnv_5.val = 0 | (final_20 & 0x1FFF) | ((final_21 & 0x1FFF) << 16);
  176. rCCM.cnv_6.val = 0 | (final_22 & 0x1FFF);
  177. //if(debugFlag[0] == '1')
  178. {
  179. MY_LOG("final:rCCM.cnv_1.val = 0x%08x", rCCM.cnv_1.val);
  180. MY_LOG("final:rCCM.cnv_2.val = 0x%08x", rCCM.cnv_2.val);
  181. MY_LOG("final:rCCM.cnv_3.val = 0x%08x", rCCM.cnv_3.val);
  182. MY_LOG("final:rCCM.cnv_4.val = 0x%08x", rCCM.cnv_4.val);
  183. MY_LOG("final:rCCM.cnv_5.val = 0x%08x", rCCM.cnv_5.val);
  184. MY_LOG("final:rCCM.cnv_6.val = 0x%08x", rCCM.cnv_6.val);
  185. }
  186. }
  187. }

复制代码

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top