• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * cl_tnr_handler.h - CL tnr 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: Wei Zong <wei.zong@intel.com>
19  */
20 
21 #ifndef XCAM_CL_TNR_HANLDER_H
22 #define XCAM_CL_TNR_HANLDER_H
23 
24 #include "cl_utils.h"
25 #include "base/xcam_3a_result.h"
26 #include "x3a_stats_pool.h"
27 #include "ocl/cl_image_handler.h"
28 
29 namespace XCam {
30 
31 enum CLTnrType {
32     CL_TNR_DISABLE = 0,
33     CL_TNR_TYPE_YUV = 1 << 0,
34     CL_TNR_TYPE_RGB = 1 << 1,
35 };
36 
37 #define TNR_GRID_HOR_COUNT          8
38 #define TNR_GRID_VER_COUNT          8
39 
40 class CLTnrImageKernel
41     : public CLImageKernel
42 {
43 public:
44     explicit CLTnrImageKernel (
45         const SmartPtr<CLContext> &context, CLTnrType type);
46 
~CLTnrImageKernel()47     virtual ~CLTnrImageKernel () {
48     }
49 
50 private:
51     CLTnrType          _type;
52 };
53 
54 class CLTnrImageHandler
55     : public CLImageHandler
56 {
57 private:
58     typedef std::list<SmartPtr<CLImage>> CLImagePtrList;
59 
60     enum CLTnrHistogramType {
61         CL_TNR_HIST_BRIGHTNESS   = 0,
62         CL_TNR_HIST_HOR_PROJECTION = 1,
63         CL_TNR_HIST_VER_PROJECTION = 2,
64     };
65 
66     enum CLTnrAnalyzeDateType {
67         CL_TNR_ANALYZE_STATS = 0,
68         CL_TNR_ANALYZE_RGB   = 1,
69     };
70 
71     struct CLTnrMotionInfo {
72         int32_t hor_shift; /*!< pixel count of horizontal direction (X) shift  */
73         int32_t ver_shift; /*!< pixel count of vertical direction (Y) shift  */
74         float hor_corr;   /*!< horizontal direction (X) correlation */
75         float ver_corr;   /*!< vertical direction (Y) correlation */
76         CLTnrMotionInfo ();
77     };
78 
79     typedef std::list<CLTnrMotionInfo> CLTnrMotionInfoList;
80 
81     struct CLTnrHistogram {
82         CLTnrHistogram ();
83         CLTnrHistogram (uint32_t width, uint32_t height);
84         ~CLTnrHistogram ();
85 
86         XCAM_DEAD_COPY (CLTnrHistogram);
87 
88         float*   hor_hist_current;
89         float*   hor_hist_reference;
90         float*   ver_hist_current;
91         float*   ver_hist_reference;
92         uint32_t hor_hist_bin;
93         uint32_t ver_hist_bin;
94     };
95 
96 public:
97     explicit CLTnrImageHandler (const SmartPtr<CLContext> &context, CLTnrType type, const char *name);
98     bool set_tnr_kernel (SmartPtr<CLTnrImageKernel> &kernel);
99     bool set_framecount (uint8_t count) ;
100     bool set_rgb_config (const XCam3aResultTemporalNoiseReduction& config);
101     bool set_yuv_config (const XCam3aResultTemporalNoiseReduction& config);
get_frame_count()102     uint32_t get_frame_count () {
103         return _frame_count;
104     }
105 
106 protected:
107     virtual XCamReturn prepare_parameters (SmartPtr<VideoBuffer> &input, SmartPtr<VideoBuffer> &output);
108 
109 private:
110     XCAM_DEAD_COPY (CLTnrImageHandler);
111 
112     bool calculate_image_histogram (XCam3AStats *stats, CLTnrHistogramType type, float* histogram);
113     bool calculate_image_histogram (SmartPtr<VideoBuffer> &input, CLTnrHistogramType type, float* histogram);
114     void print_image_histogram ();
115 
116 private:
117     SmartPtr<CLTnrImageKernel>  _tnr_kernel;
118     CLTnrType                   _type;
119 
120     float                       _gain_yuv;
121     float                       _thr_y;
122     float                       _thr_uv;
123 
124     float                       _gain_rgb;
125     float                       _thr_r;
126     float                       _thr_g;
127     float                       _thr_b;
128 
129     CLTnrMotionInfo             _motion_info[TNR_GRID_HOR_COUNT * TNR_GRID_VER_COUNT];
130     CLImagePtrList              _image_in_list;
131     CLTnrHistogram              _image_histogram;
132     SmartPtr<CLImage>           _image_out_prev;
133 
134     uint8_t                     _frame_count;
135 };
136 
137 SmartPtr<CLImageHandler>
138 create_cl_tnr_image_handler (const SmartPtr<CLContext> &context, CLTnrType type);
139 
140 };
141 
142 #endif //XCAM_CL_TNR_HANLDER_H
143