• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * cl_retinex_handler.h - CL retinex handler.
3  *
4  *  Copyright (c) 2016 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  *             Wind Yuan <feng.yuan@intel.com>
20  */
21 
22 #ifndef XCAM_CL_RETINEX_HANLDER_H
23 #define XCAM_CL_RETINEX_HANLDER_H
24 
25 #include <xcam_std.h>
26 #include <base/xcam_3a_result.h>
27 #include <x3a_stats_pool.h>
28 #include <ocl/cl_image_scaler.h>
29 #include <ocl/cl_gauss_handler.h>
30 
31 #define XCAM_RETINEX_MAX_SCALE 2
32 #define XCAM_RETINEX_SCALER_FACTOR 0.5
33 
34 namespace XCam {
35 
36 typedef struct {
37     float           gain;
38     float           threshold;
39     float           log_min;
40     float           log_max;
41     float           width;
42     float           height;
43 } CLRetinexConfig;
44 
45 class CLRetinexImageHandler;
46 
47 class CLRetinexScalerImageKernel
48     : public CLScalerKernel
49 {
50 public:
51     explicit CLRetinexScalerImageKernel (
52         const SmartPtr<CLContext> &context,
53         CLImageScalerMemoryLayout mem_layout,
54         SmartPtr<CLRetinexImageHandler> &retinex);
55 
56 protected:
57     //derived from CLScalerKernel
58     virtual SmartPtr<VideoBuffer> get_input_buffer ();
59     virtual SmartPtr<VideoBuffer> get_output_buffer ();
60 
61 private:
62     SmartPtr<CLRetinexImageHandler> _retinex;
63 
64 };
65 
66 class CLRetinexGaussImageKernel
67     : public CLGaussImageKernel
68 {
69 public:
70     explicit CLRetinexGaussImageKernel (
71         const SmartPtr<CLContext> &context,
72         SmartPtr<CLRetinexImageHandler> &retinex,
73         uint32_t index,
74         uint32_t radius, float sigma);
75     virtual SmartPtr<VideoBuffer> get_input_buf ();
76     virtual SmartPtr<VideoBuffer> get_output_buf ();
77 
78 
79 private:
80     SmartPtr<CLRetinexImageHandler> _retinex;
81     uint32_t                        _index;
82 
83 };
84 
85 class CLRetinexImageKernel
86     : public CLImageKernel
87 {
88 public:
89     explicit CLRetinexImageKernel (const SmartPtr<CLContext> &context, SmartPtr<CLRetinexImageHandler> &retinex);
90 
91 protected:
92     virtual XCamReturn prepare_arguments (
93         CLArgList &args, CLWorkSize &work_size);
94 
95 private:
96     SmartPtr<CLRetinexImageHandler>  _retinex;
97 };
98 
99 class CLRetinexImageHandler
100     : public CLImageHandler
101 {
102 public:
103     explicit CLRetinexImageHandler (const SmartPtr<CLContext> &context, const char *name);
104     bool set_retinex_kernel(SmartPtr<CLRetinexImageKernel> &kernel);
105     bool set_retinex_scaler_kernel(SmartPtr<CLRetinexScalerImageKernel> &kernel);
106     //bool set_retinex_gauss_kernel(SmartPtr<CLRetinexGaussImageKernel> &kernel);
get_scaler_buf1()107     SmartPtr<VideoBuffer> &get_scaler_buf1 () {
108         return _scaler_buf1;
109     };
get_gaussian_buf(uint index)110     SmartPtr<VideoBuffer> &get_gaussian_buf (uint index) {
111         XCAM_ASSERT (index < XCAM_RETINEX_MAX_SCALE);
112         return _gaussian_buf[index];
113     };
114 
115     virtual void emit_stop ();
116 
117 protected:
118     virtual XCamReturn prepare_output_buf (SmartPtr<VideoBuffer> &input, SmartPtr<VideoBuffer> &output);
119 
120 private:
121     XCamReturn prepare_scaler_buf (const VideoBufferInfo &video_info);
122 
123 private:
124     SmartPtr<CLRetinexImageKernel>        _retinex_kernel;
125     SmartPtr<CLRetinexScalerImageKernel>  _retinex_scaler_kernel;
126     //SmartPtr<CLRetinexGaussImageKernel>   _retinex_gauss_kernel;
127 
128     double                                _scaler_factor;
129     SmartPtr<BufferPool>                  _scaler_buf_pool;
130     SmartPtr<VideoBuffer>                 _scaler_buf1;
131     SmartPtr<VideoBuffer>                 _gaussian_buf[XCAM_RETINEX_MAX_SCALE];
132 
133 };
134 
135 SmartPtr<CLImageHandler>
136 create_cl_retinex_image_handler (const SmartPtr<CLContext> &context);
137 
138 };
139 
140 #endif //XCAM_CL_RETINEX_HANLDER_H
141