• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * x3a_ciq_wavelet_tuning_handler.cpp - x3a Common IQ Wavelet denoise 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_wavelet_tuning_handler.h"
24 
25 namespace XCam {
26 
27 typedef struct _X3aCiqWaveletTuningStaticData {
28     double analog_gain;
29     double hard_threshold;
30     double soft_threshold;
31     uint8_t  decom_levels;
32 } X3aCiqWaveletTuningStaticData;
33 
34 const X3aCiqWaveletTuningStaticData imx185_tuning[X3A_CIQ_GAIN_STEPS] = {
35     {1.0, 0.01, 1.0, 5},
36     {16.98, 0.02, 0.7, 5},
37     {49.55, 0.2, 0.5, 5},
38     {139.63, 0.3, 0.3, 5},
39     {X3A_CIQ_GAIN_MAX, 0.5, 0.2, 5},
40 };
41 
X3aCiqWaveletTuningHandler()42 X3aCiqWaveletTuningHandler::X3aCiqWaveletTuningHandler ()
43     : X3aCiqTuningHandler ("X3aCiqWaveletTuningHandler")
44 {
45 }
46 
~X3aCiqWaveletTuningHandler()47 X3aCiqWaveletTuningHandler::~X3aCiqWaveletTuningHandler ()
48 {
49 }
50 
51 XCamReturn
analyze(X3aResultList & output)52 X3aCiqWaveletTuningHandler::analyze (X3aResultList &output)
53 {
54     XCamReturn ret = XCAM_RETURN_NO_ERROR;
55 
56     const X3aCiqWaveletTuningStaticData* tuning = imx185_tuning;
57     if (NULL != _tuning_data) {
58         tuning = (X3aCiqWaveletTuningStaticData*)_tuning_data;;
59     }
60 
61     XCam3aResultWaveletNoiseReduction config;
62     SmartPtr<X3aWaveletNoiseReduction> settings = new X3aWaveletNoiseReduction (XCAM_3A_RESULT_WAVELET_NOISE_REDUCTION);
63 
64     int64_t et = get_current_exposure_time ();
65     double analog_gain = get_current_analog_gain ();
66     double max_analog_gain = get_max_analog_gain ();
67     XCAM_UNUSED (et);
68     XCAM_UNUSED (max_analog_gain);
69     XCAM_LOG_DEBUG ("get current AG = (%f), max AG = (%f), et = (%" PRId64 ")", analog_gain, max_analog_gain, et);
70 
71     uint8_t i_curr = 0;
72     uint8_t i_prev = 0;
73     for (i_curr = 0; i_curr < X3A_CIQ_GAIN_STEPS; i_curr++) {
74         if (analog_gain <= tuning[i_curr].analog_gain) {
75             break;
76         }
77         i_prev = i_curr;
78     }
79     if (i_curr >= X3A_CIQ_GAIN_STEPS) {
80         i_curr = X3A_CIQ_GAIN_STEPS - 1;
81     }
82 
83     //Calculate Wavelet denoise config
84     xcam_mem_clear (config);
85 
86     /* [0]:soft threshold / [1]:hard threshold */
87     config.threshold[0] = linear_interpolate_p2 (tuning[i_prev].soft_threshold, tuning[i_curr].soft_threshold,
88                           tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);
89 
90     config.threshold[1] = linear_interpolate_p2 (tuning[i_prev].hard_threshold, tuning[i_curr].hard_threshold,
91                           tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);
92 
93     config.decomposition_levels = 1;
94 
95     config.analog_gain = analog_gain / X3A_CIQ_GAIN_MAX;
96     XCAM_LOG_DEBUG ("Calculate Wavelet noise reduction config: soft threshold(%f), hard threshold(%f), decomposition levels(%d)",
97                     config.threshold[0], config.threshold[1], config.decomposition_levels);
98 
99     settings->set_standard_result (config);
100     output.push_back (settings);
101 
102     return ret;
103 }
104 
105 };
106