• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * x3a_ciq_bnr_ee_tuning_handler.cpp - x3a Common IQ Bayer NR EE tuning handler
3  *
4  *  Copyright (c) 2015 Intel Corporation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * Author: Wangfei <feix.w.wang@intel.com>
19  */
20 
21 #include "x3a_analyzer.h"
22 #include "x3a_ciq_tuning_handler.h"
23 #include "x3a_ciq_bnr_ee_tuning_handler.h"
24 
25 namespace XCam {
26 
27 typedef struct _X3aCiqBnrEeTuningStaticData {
28     double analog_gain;
29     double ee_gain;
30     double ee_threshold;
31 } X3aCiqBnrEeTuningStaticData;
32 
33 double table_2_0[XCAM_BNR_TABLE_SIZE] = {
34     3.978874, 3.966789, 3.930753, 3.871418, 3.789852, 3.687501, 3.566151, 3.427876, 3.274977, 3.109920,
35     2.935268, 2.753622, 2.567547, 2.379525, 2.191896, 2.006815, 1.826218, 1.651792, 1.484965, 1.326889,
36     1.178449, 1.040267, 0.912718, 0.795950, 0.689911, 0.594371, 0.508957, 0.433173, 0.366437, 0.308103,
37     0.257483, 0.213875, 0.176575, 0.144896, 0.118179, 0.095804, 0.077194, 0.061822, 0.049210, 0.038934,
38     0.030617, 0.023930, 0.018591, 0.014355, 0.011017, 0.008404, 0.006372, 0.004802, 0.003597, 0.002678,
39     0.001981, 0.001457, 0.001065, 0.000774, 0.000559, 0.000401, 0.000286, 0.000203, 0.000143, 0.000100,
40     0.000070, 0.000048, 0.000033, 0.000023
41 };
42 
43 double table_0_0_5[XCAM_BNR_TABLE_SIZE] = {
44     63.661991, 60.628166, 52.366924, 41.023067, 29.146584, 18.781729, 10.976704, 6.000000, 6.000000, 6.000000,
45     6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000,
46     6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000,
47     6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000,
48     6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000,
49     6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000, 6.000000,
50     6.000000, 6.000000, 6.000000, 6.000000
51 };
52 
53 const X3aCiqBnrEeTuningStaticData imx185_tuning[X3A_CIQ_EE_GAIN_STEPS] = {
54     {1.0, 2.5, 0.008},
55     {4.0, 1.8, 0.012},
56     {16.98, 1.1, 0.02},
57     {49.55, 0.8, 0.06},
58     {139.63, 0.07, 0.1},
59     {X3A_CIQ_GAIN_MAX, 0.03, 0.4},
60 };
61 
X3aCiqBnrEeTuningHandler()62 X3aCiqBnrEeTuningHandler::X3aCiqBnrEeTuningHandler ()
63     : X3aCiqTuningHandler ("X3aCiqBnrEeTuningHandler")
64 {
65 }
66 
~X3aCiqBnrEeTuningHandler()67 X3aCiqBnrEeTuningHandler::~X3aCiqBnrEeTuningHandler ()
68 {
69 }
70 
71 XCamReturn
analyze(X3aResultList & output)72 X3aCiqBnrEeTuningHandler::analyze (X3aResultList &output)
73 {
74     XCamReturn ret = XCAM_RETURN_NO_ERROR;
75 
76     const X3aCiqBnrEeTuningStaticData* tuning = imx185_tuning;
77     if (NULL != _tuning_data) {
78         tuning = (X3aCiqBnrEeTuningStaticData*)_tuning_data;;
79     }
80 
81     XCam3aResultBayerNoiseReduction bnr_config;
82     XCam3aResultEdgeEnhancement ee_config;
83     SmartPtr<X3aBayerNoiseReduction> bnr_result = new X3aBayerNoiseReduction (XCAM_3A_RESULT_BAYER_NOISE_REDUCTION);
84     SmartPtr<X3aEdgeEnhancementResult> ee_result = new X3aEdgeEnhancementResult (XCAM_3A_RESULT_EDGE_ENHANCEMENT);
85 
86     double analog_gain = get_current_analog_gain ();
87 
88     uint8_t i_curr = 0;
89     uint8_t i_prev = 0;
90     for (i_curr = 0; i_curr < X3A_CIQ_EE_GAIN_STEPS; i_curr++) {
91         if (analog_gain <= tuning[i_curr].analog_gain) {
92             break;
93         }
94         i_prev = i_curr;
95     }
96     if (i_curr >= X3A_CIQ_EE_GAIN_STEPS) {
97         i_curr = X3A_CIQ_EE_GAIN_STEPS - 1;
98     }
99 
100     xcam_mem_clear (bnr_config);
101     xcam_mem_clear (ee_config);
102 
103     ee_config.gain = linear_interpolate_p2 (tuning[i_prev].ee_gain, tuning[i_curr].ee_gain,
104                                             tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);
105 
106     ee_config.threshold = linear_interpolate_p2 (tuning[i_prev].ee_threshold, tuning[i_curr].ee_threshold,
107                           tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);
108 
109     ee_result->set_standard_result (ee_config);
110     output.push_back (ee_result);
111 
112     if(i_curr < 3)
113         memcpy(bnr_config.table, table_0_0_5, XCAM_BNR_TABLE_SIZE * sizeof(double));
114     else
115         memcpy(bnr_config.table, table_2_0, XCAM_BNR_TABLE_SIZE * sizeof(double));
116 
117     bnr_result->set_standard_result (bnr_config);
118     output.push_back (bnr_result);
119 
120     return ret;
121 }
122 
123 };
124 
125