• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * x3a_result_factory.cpp - 3A result factory
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: Wind Yuan <feng.yuan@intel.com>
19  */
20 
21 #include "x3a_result_factory.h"
22 
23 namespace XCam {
24 
25 #define XCAM_3A_RESULT_FACTORY(DataType, res_type, from)            \
26     DataType *ret =                                                 \
27         new DataType (res_type);                                    \
28     if (from) {                                                     \
29         uint32_t type = xcam_3a_result_type (from);                 \
30         if (type != XCAM_3A_RESULT_NULL && type != res_type) {      \
31             XCAM_ASSERT (false);                                    \
32             XCAM_LOG_WARNING ("create result from wrong type:%d to type:%d", type, res_type);    \
33         }                                                           \
34         ret->set_standard_result (*from);                           \
35     }                                                               \
36     return ret;
37 
38 
39 Mutex X3aResultFactory::_mutex;
40 SmartPtr<X3aResultFactory> X3aResultFactory::_instance (NULL);
41 
42 SmartPtr<X3aResultFactory>
instance()43 X3aResultFactory::instance ()
44 {
45     SmartLock locker (_mutex);
46     if (_instance.ptr ())
47         return _instance;
48 
49     _instance = new X3aResultFactory;
50     return _instance;
51 }
52 
X3aResultFactory()53 X3aResultFactory::X3aResultFactory ()
54 {
55 }
56 
~X3aResultFactory()57 X3aResultFactory::~X3aResultFactory ()
58 {
59 }
60 
61 SmartPtr<X3aResult>
create_3a_result(XCam3aResultHead * from)62 X3aResultFactory::create_3a_result (XCam3aResultHead *from)
63 {
64     SmartPtr<X3aResult> result (NULL);
65 
66     XCAM_ASSERT (from);
67     if (!from)
68         return result;
69 
70     uint32_t type = xcam_3a_result_type (from);
71 
72     switch (type) {
73     case XCAM_3A_RESULT_WHITE_BALANCE:
74         result = create_whitebalance ((XCam3aResultWhiteBalance*)from);
75         break;
76     case XCAM_3A_RESULT_BLACK_LEVEL:
77         result = create_blacklevel ((XCam3aResultBlackLevel*)from);
78         break;
79     case XCAM_3A_RESULT_YUV2RGB_MATRIX:
80         result = create_yuv2rgb_colormatrix ((XCam3aResultColorMatrix*)from);
81         break;
82     case XCAM_3A_RESULT_RGB2YUV_MATRIX:
83         result = create_rgb2yuv_colormatrix ((XCam3aResultColorMatrix*)from);
84         break;
85     case XCAM_3A_RESULT_EXPOSURE:
86         result = create_exposure ((XCam3aResultExposure*)from);
87         break;
88     case XCAM_3A_RESULT_FOCUS:
89         result = create_focus ((XCam3aResultFocus*)from);
90         break;
91     case XCAM_3A_RESULT_DEMOSAIC:
92         result = create_demosaicing ((XCam3aResultDemosaic*)from);
93         break;
94     case XCAM_3A_RESULT_DEFECT_PIXEL_CORRECTION:
95         result = create_defectpixel ((XCam3aResultDefectPixel*)from);
96         break;
97     case XCAM_3A_RESULT_NOISE_REDUCTION:
98         result = create_noise_reduction ((XCam3aResultNoiseReduction*)from);
99         break;
100     case XCAM_3A_RESULT_3D_NOISE_REDUCTION:
101         result = create_3d_noise_reduction ((XCam3aResultTemporalNoiseReduction*)from);
102         break;
103     case XCAM_3A_RESULT_TEMPORAL_NOISE_REDUCTION_YUV:
104         result = create_yuv_temp_noise_reduction ((XCam3aResultTemporalNoiseReduction*)from);
105         break;
106     case XCAM_3A_RESULT_EDGE_ENHANCEMENT:
107         result = create_edge_enhancement ((XCam3aResultEdgeEnhancement*)from);
108         break;
109     case XCAM_3A_RESULT_MACC:
110         result = create_macc ((XCam3aResultMaccMatrix*)from);
111         break;
112     case XCAM_3A_RESULT_CHROMA_TONE_CONTROL:
113         result = create_chroma_tone_control ((XCam3aResultChromaToneControl*)from);
114         break;
115     case XCAM_3A_RESULT_Y_GAMMA:
116         result = create_y_gamma_table ((XCam3aResultGammaTable*)from);
117         break;
118     case XCAM_3A_RESULT_R_GAMMA:
119         result = create_r_gamma_table ((XCam3aResultGammaTable*)from);
120         break;
121     case XCAM_3A_RESULT_G_GAMMA:
122         result = create_g_gamma_table ((XCam3aResultGammaTable*)from);
123         break;
124     case XCAM_3A_RESULT_B_GAMMA:
125         result = create_b_gamma_table ((XCam3aResultGammaTable*)from);
126         break;
127     case XCAM_3A_RESULT_BAYER_NOISE_REDUCTION:
128         result = create_bayer_noise_reduction ((XCam3aResultBayerNoiseReduction*)from);
129         break;
130     case XCAM_3A_RESULT_BRIGHTNESS:
131         result = create_brightness ((XCam3aResultBrightness*)from);
132         break;
133     case XCAM_3A_RESULT_WAVELET_NOISE_REDUCTION:
134         result = create_wavelet_noise_reduction ((XCam3aResultWaveletNoiseReduction*)from);
135         break;
136     case XCAM_3A_RESULT_FACE_DETECTION:
137         result = create_face_detection ((XCamFDResult*)from);
138         break;
139     case XCAM_3A_RESULT_DVS:
140         result = create_digital_video_stabilizer ((XCamDVSResult*)from);
141         break;
142     default:
143         XCAM_LOG_WARNING ("create 3a result with unknown result type:%d", type);
144         break;
145     }
146 
147     return result;
148 }
149 
150 SmartPtr<X3aWhiteBalanceResult>
create_whitebalance(XCam3aResultWhiteBalance * from)151 X3aResultFactory::create_whitebalance (XCam3aResultWhiteBalance *from)
152 {
153     XCAM_3A_RESULT_FACTORY (X3aWhiteBalanceResult, XCAM_3A_RESULT_WHITE_BALANCE, from);
154 }
155 
156 SmartPtr<X3aBlackLevelResult>
create_blacklevel(XCam3aResultBlackLevel * from)157 X3aResultFactory::create_blacklevel (XCam3aResultBlackLevel *from)
158 {
159     XCAM_3A_RESULT_FACTORY (X3aBlackLevelResult, XCAM_3A_RESULT_BLACK_LEVEL, from);
160 }
161 
162 SmartPtr<X3aColorMatrixResult>
create_rgb2yuv_colormatrix(XCam3aResultColorMatrix * from)163 X3aResultFactory::create_rgb2yuv_colormatrix (XCam3aResultColorMatrix *from)
164 {
165     XCAM_3A_RESULT_FACTORY (X3aColorMatrixResult, XCAM_3A_RESULT_RGB2YUV_MATRIX, from);
166 }
167 
168 SmartPtr<X3aColorMatrixResult>
create_yuv2rgb_colormatrix(XCam3aResultColorMatrix * from)169 X3aResultFactory::create_yuv2rgb_colormatrix (XCam3aResultColorMatrix *from)
170 {
171     XCAM_3A_RESULT_FACTORY (X3aColorMatrixResult, XCAM_3A_RESULT_YUV2RGB_MATRIX, from);
172 }
173 
174 SmartPtr<X3aExposureResult>
create_exposure(XCam3aResultExposure * from)175 X3aResultFactory::create_exposure (XCam3aResultExposure *from)
176 {
177     XCAM_3A_RESULT_FACTORY (X3aExposureResult, XCAM_3A_RESULT_EXPOSURE, from);
178 }
179 
180 SmartPtr<X3aFocusResult>
create_focus(XCam3aResultFocus * from)181 X3aResultFactory::create_focus (XCam3aResultFocus *from)
182 {
183     XCAM_3A_RESULT_FACTORY (X3aFocusResult, XCAM_3A_RESULT_FOCUS, from);
184 }
185 
186 SmartPtr<X3aDemosaicResult>
create_demosaicing(XCam3aResultDemosaic * from)187 X3aResultFactory::create_demosaicing (XCam3aResultDemosaic *from)
188 {
189     XCAM_3A_RESULT_FACTORY (X3aDemosaicResult, XCAM_3A_RESULT_DEMOSAIC, from);
190 }
191 
192 SmartPtr<X3aDefectPixelResult>
create_defectpixel(XCam3aResultDefectPixel * from)193 X3aResultFactory::create_defectpixel (XCam3aResultDefectPixel *from)
194 {
195     XCAM_3A_RESULT_FACTORY (X3aDefectPixelResult, XCAM_3A_RESULT_DEFECT_PIXEL_CORRECTION, from);
196 }
197 
198 SmartPtr<X3aNoiseReductionResult>
create_noise_reduction(XCam3aResultNoiseReduction * from)199 X3aResultFactory::create_noise_reduction (XCam3aResultNoiseReduction *from)
200 {
201     XCAM_3A_RESULT_FACTORY (X3aNoiseReductionResult, XCAM_3A_RESULT_NOISE_REDUCTION, from);
202 }
203 
204 SmartPtr<X3aTemporalNoiseReduction>
create_3d_noise_reduction(XCam3aResultTemporalNoiseReduction * from)205 X3aResultFactory::create_3d_noise_reduction (XCam3aResultTemporalNoiseReduction *from)
206 {
207     XCAM_3A_RESULT_FACTORY (X3aTemporalNoiseReduction, XCAM_3A_RESULT_3D_NOISE_REDUCTION, from);
208 }
209 
210 SmartPtr<X3aTemporalNoiseReduction>
create_yuv_temp_noise_reduction(XCam3aResultTemporalNoiseReduction * from)211 X3aResultFactory::create_yuv_temp_noise_reduction (XCam3aResultTemporalNoiseReduction *from)
212 {
213     XCAM_3A_RESULT_FACTORY (X3aTemporalNoiseReduction, XCAM_3A_RESULT_TEMPORAL_NOISE_REDUCTION_YUV, from);
214 }
215 
216 SmartPtr<X3aEdgeEnhancementResult>
create_edge_enhancement(XCam3aResultEdgeEnhancement * from)217 X3aResultFactory::create_edge_enhancement (XCam3aResultEdgeEnhancement *from)
218 {
219     XCAM_3A_RESULT_FACTORY (X3aEdgeEnhancementResult, XCAM_3A_RESULT_EDGE_ENHANCEMENT, from);
220 }
221 
222 SmartPtr<X3aGammaTableResult>
create_y_gamma_table(XCam3aResultGammaTable * from)223 X3aResultFactory::create_y_gamma_table (XCam3aResultGammaTable *from)
224 {
225     XCAM_3A_RESULT_FACTORY (X3aGammaTableResult, XCAM_3A_RESULT_Y_GAMMA, from);
226 }
227 
228 SmartPtr<X3aGammaTableResult>
create_r_gamma_table(XCam3aResultGammaTable * from)229 X3aResultFactory::create_r_gamma_table (XCam3aResultGammaTable *from)
230 {
231     XCAM_3A_RESULT_FACTORY (X3aGammaTableResult, XCAM_3A_RESULT_R_GAMMA, from);
232 }
233 
234 SmartPtr<X3aGammaTableResult>
create_g_gamma_table(XCam3aResultGammaTable * from)235 X3aResultFactory::create_g_gamma_table (XCam3aResultGammaTable *from)
236 {
237     XCAM_3A_RESULT_FACTORY (X3aGammaTableResult, XCAM_3A_RESULT_G_GAMMA, from);
238 }
239 
240 SmartPtr<X3aGammaTableResult>
create_b_gamma_table(XCam3aResultGammaTable * from)241 X3aResultFactory::create_b_gamma_table (XCam3aResultGammaTable *from)
242 {
243     XCAM_3A_RESULT_FACTORY (X3aGammaTableResult, XCAM_3A_RESULT_B_GAMMA, from);
244 }
245 
246 SmartPtr<X3aMaccMatrixResult>
create_macc(XCam3aResultMaccMatrix * from)247 X3aResultFactory::create_macc (XCam3aResultMaccMatrix *from)
248 {
249     XCAM_3A_RESULT_FACTORY (X3aMaccMatrixResult, XCAM_3A_RESULT_MACC, from);
250 }
251 
252 SmartPtr<X3aChromaToneControlResult>
create_chroma_tone_control(XCam3aResultChromaToneControl * from)253 X3aResultFactory::create_chroma_tone_control (XCam3aResultChromaToneControl *from)
254 {
255     XCAM_3A_RESULT_FACTORY (X3aChromaToneControlResult, XCAM_3A_RESULT_CHROMA_TONE_CONTROL, from);
256 }
257 
258 SmartPtr<X3aBayerNoiseReduction>
create_bayer_noise_reduction(XCam3aResultBayerNoiseReduction * from)259 X3aResultFactory::create_bayer_noise_reduction (XCam3aResultBayerNoiseReduction *from)
260 {
261     XCAM_3A_RESULT_FACTORY (X3aBayerNoiseReduction, XCAM_3A_RESULT_BAYER_NOISE_REDUCTION, from);
262 }
263 
264 SmartPtr<X3aBrightnessResult>
create_brightness(XCam3aResultBrightness * from)265 X3aResultFactory::create_brightness (XCam3aResultBrightness *from)
266 {
267     XCAM_3A_RESULT_FACTORY (X3aBrightnessResult, XCAM_3A_RESULT_BRIGHTNESS, from);
268 }
269 
270 SmartPtr<X3aWaveletNoiseReduction>
create_wavelet_noise_reduction(XCam3aResultWaveletNoiseReduction * from)271 X3aResultFactory::create_wavelet_noise_reduction (XCam3aResultWaveletNoiseReduction *from)
272 {
273     XCAM_3A_RESULT_FACTORY (X3aWaveletNoiseReduction, XCAM_3A_RESULT_WAVELET_NOISE_REDUCTION, from);
274 }
275 
276 SmartPtr<X3aFaceDetectionResult>
create_face_detection(XCamFDResult * from)277 X3aResultFactory::create_face_detection (XCamFDResult *from)
278 {
279     uint32_t type = xcam_3a_result_type (from);
280     if (type != XCAM_3A_RESULT_FACE_DETECTION) {
281         XCAM_ASSERT (false);
282         XCAM_LOG_WARNING ("X3aResultFactory create face detection failed with wrong type");
283     }
284 
285     X3aFaceDetectionResult *fd_res = new X3aFaceDetectionResult (
286         XCAM_3A_RESULT_FACE_DETECTION,
287         from->head.process_type,
288         from->face_num * sizeof (XCamFaceInfo));
289     fd_res->set_standard_result (*from);
290 
291     return fd_res;
292 }
293 
294 SmartPtr<X3aDVSResult>
create_digital_video_stabilizer(XCamDVSResult * from)295 X3aResultFactory::create_digital_video_stabilizer (XCamDVSResult *from)
296 {
297     XCAM_3A_RESULT_FACTORY (X3aDVSResult, XCAM_3A_RESULT_DVS, from);
298 }
299 };
300 
301 
302