• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * x3a_ciq_tnr_tuning_handler.cpp - x3a Common IQ TNR tuning handler
3  *
4  *  Copyright (c) 2014-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: Zong Wei <wei.zong@intel.com>
19  */
20 
21 #include "x3a_analyzer.h"
22 #include "x3a_ciq_tuning_handler.h"
23 #include "x3a_ciq_tnr_tuning_handler.h"
24 
25 namespace XCam {
26 
27 typedef struct _X3aCiqTnrTuningStaticData {
28     double analog_gain;
29     double yuv_gain;
30     double y_threshold;
31     double uv_threshold;
32     double rgb_gain;
33     double r_threshold;
34     double g_threshold;
35     double b_threshold;
36 } X3aCiqTnrTuningStaticData;
37 
38 const X3aCiqTnrTuningStaticData imx185_tuning[X3A_CIQ_GAIN_STEPS] = {
39     {1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0},
40     {16.98, 0.8, 0.0081, 0.00725, 0.2, 0.0253, 0.0158, 0.0168},
41     {49.55, 0.5, 0.0146, 0.0128, 0.4, 0.0434, 0.0274, 0.0317},
42     {139.63, 0.3, 0.0247, 0.0253, 0.8, 0.0602, 0.0377, 0.0445},
43     {X3A_CIQ_GAIN_MAX, 0.2, 0.0358, 0.0329, 1.0, 0.0994, 0.0696, 0.0924},
44 };
45 
X3aCiqTnrTuningHandler()46 X3aCiqTnrTuningHandler::X3aCiqTnrTuningHandler ()
47     : X3aCiqTuningHandler ("X3aCiqTnrTuningHandler")
48 {
49 }
50 
~X3aCiqTnrTuningHandler()51 X3aCiqTnrTuningHandler::~X3aCiqTnrTuningHandler ()
52 {
53 }
54 
55 XCamReturn
analyze(X3aResultList & output)56 X3aCiqTnrTuningHandler::analyze (X3aResultList &output)
57 {
58     XCamReturn ret = XCAM_RETURN_NO_ERROR;
59 
60     const X3aCiqTnrTuningStaticData* tuning = imx185_tuning;
61     if (NULL != _tuning_data) {
62         tuning = (X3aCiqTnrTuningStaticData*)_tuning_data;;
63     }
64 
65     XCam3aResultTemporalNoiseReduction config;
66     SmartPtr<X3aTemporalNoiseReduction> nr_result = new X3aTemporalNoiseReduction (XCAM_3A_RESULT_3D_NOISE_REDUCTION);
67     SmartPtr<X3aTemporalNoiseReduction> yuv_result = new X3aTemporalNoiseReduction (XCAM_3A_RESULT_TEMPORAL_NOISE_REDUCTION_YUV);
68 
69     int64_t et = get_current_exposure_time ();
70     double analog_gain = get_current_analog_gain ();
71     double max_analog_gain = get_max_analog_gain ();
72     XCAM_UNUSED (et);
73     XCAM_UNUSED (max_analog_gain);
74     XCAM_LOG_DEBUG ("get current AG = (%f), max AG = (%f), et = (%" PRId64 ")", analog_gain, max_analog_gain, et);
75 
76     uint8_t i_curr = 0;
77     uint8_t i_prev = 0;
78     for (i_curr = 0; i_curr < X3A_CIQ_GAIN_STEPS; i_curr++) {
79         if (analog_gain <= tuning[i_curr].analog_gain) {
80             break;
81         }
82         i_prev = i_curr;
83     }
84     if (i_curr >= X3A_CIQ_GAIN_STEPS) {
85         i_curr = X3A_CIQ_GAIN_STEPS - 1;
86     }
87 
88     //Calculate YUV config
89     xcam_mem_clear (config);
90     config.gain = linear_interpolate_p2 (tuning[i_prev].yuv_gain, tuning[i_curr].yuv_gain,
91                                          tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);
92 
93     config.threshold[0] = linear_interpolate_p2 (tuning[i_prev].y_threshold, tuning[i_curr].y_threshold,
94                           tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);
95 
96     config.threshold[1] = linear_interpolate_p2 (tuning[i_prev].uv_threshold, tuning[i_curr].uv_threshold,
97                           tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);
98 
99     config.threshold[2] = 0.0;
100     XCAM_LOG_DEBUG ("Calculate YUV temporal noise reduction config: yuv_gain(%f), y_threshold(%f), uv_threshold(%f)",
101                     config.gain, config.threshold[0], config.threshold[1]);
102 
103     yuv_result->set_standard_result (config);
104     output.push_back (yuv_result);
105 
106     //Calculate 3D NR config
107     xcam_mem_clear (config);
108     config.gain = linear_interpolate_p2 (tuning[i_prev].rgb_gain, tuning[i_curr].rgb_gain,
109                                          tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);
110 
111     config.threshold[0] = linear_interpolate_p2 (tuning[i_prev].r_threshold, tuning[i_curr].r_threshold,
112                           tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);
113 
114     config.threshold[1] = linear_interpolate_p2 (tuning[i_prev].g_threshold, tuning[i_curr].g_threshold,
115                           tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);
116 
117     config.threshold[2] = linear_interpolate_p2 (tuning[i_prev].b_threshold, tuning[i_curr].b_threshold,
118                           tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);
119 
120     XCAM_LOG_DEBUG ("Calculate 3D noise reduction config: gain(%f), y_threshold(%f), uv_threshold(%f)",
121                     config.gain, config.threshold[0], config.threshold[1]);
122 
123     nr_result->set_standard_result (config);
124     output.push_back (nr_result);
125 
126     return ret;
127 }
128 
129 };
130