1 /* 2 * cl_newwavelet_denoise_handler.h - CL wavelet denoise 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_NEWWAVELET_DENOISE_HANLDER_H 22 #define XCAM_CL_NEWWAVELET_DENOISE_HANLDER_H 23 24 #include <xcam_std.h> 25 #include <ocl/cl_image_handler.h> 26 #include <base/xcam_3a_result.h> 27 28 namespace XCam { 29 30 enum CLWaveletFilterBank { 31 CL_WAVELET_HAAR_ANALYSIS = 0, 32 CL_WAVELET_HAAR_SYNTHESIS = 1, 33 }; 34 35 enum CLWaveletSubband { 36 CL_WAVELET_SUBBAND_LL = 0, 37 CL_WAVELET_SUBBAND_HL, 38 CL_WAVELET_SUBBAND_LH, 39 CL_WAVELET_SUBBAND_HH, 40 }; 41 42 /*------------------------ 43 Wavelet decomposition 44 frequency block 45 46 __ width__ 47 ___________________ 48 | | | | 49 | | | | 50 | LL | HL |height 51 | | | | 52 |_________|_________| | 53 | | | 54 | | | 55 | LH | HH | 56 | | | 57 |_________|_________| 58 --------------------------*/ 59 typedef struct _CLCLWaveletDecompBuffer { 60 int32_t width; 61 int32_t height; 62 uint32_t channel; 63 int32_t layer; 64 float noise_variance[3]; 65 SmartPtr<CLImage> ll; 66 SmartPtr<CLImage> hl[3]; 67 SmartPtr<CLImage> lh[3]; 68 SmartPtr<CLImage> hh[3]; 69 } CLWaveletDecompBuffer; 70 71 class CLNewWaveletDenoiseImageHandler; 72 73 class CLWaveletNoiseEstimateKernel 74 : public CLImageKernel 75 { 76 77 public: 78 explicit CLWaveletNoiseEstimateKernel ( 79 const SmartPtr<CLContext> &context, 80 const char *name, 81 SmartPtr<CLNewWaveletDenoiseImageHandler> &handler, 82 uint32_t channel, uint32_t subband, uint32_t layer); 83 84 SmartPtr<CLImage> get_input_buffer (); 85 SmartPtr<CLImage> get_output_buffer (); 86 87 XCamReturn estimate_noise_variance (const VideoBufferInfo & video_info, SmartPtr<CLImage> image, float* noise_var); 88 89 protected: 90 virtual XCamReturn prepare_arguments ( 91 CLArgList &args, CLWorkSize &work_size); 92 93 private: 94 uint32_t _decomposition_levels; 95 uint32_t _channel; 96 uint32_t _subband; 97 uint32_t _current_layer; 98 float _analog_gain; 99 100 SmartPtr<CLNewWaveletDenoiseImageHandler> _handler; 101 }; 102 103 class CLWaveletThresholdingKernel 104 : public CLImageKernel 105 { 106 107 public: 108 explicit CLWaveletThresholdingKernel ( 109 const SmartPtr<CLContext> &context, 110 const char *name, 111 SmartPtr<CLNewWaveletDenoiseImageHandler> &handler, 112 uint32_t channel, uint32_t layer); 113 114 protected: 115 virtual XCamReturn prepare_arguments ( 116 CLArgList &args, CLWorkSize &work_size); 117 118 private: 119 uint32_t _decomposition_levels; 120 uint32_t _channel; 121 uint32_t _current_layer; 122 SmartPtr<CLNewWaveletDenoiseImageHandler> _handler; 123 }; 124 125 class CLWaveletTransformKernel 126 : public CLImageKernel 127 { 128 129 public: 130 explicit CLWaveletTransformKernel ( 131 const SmartPtr<CLContext> &context, 132 const char *name, 133 SmartPtr<CLNewWaveletDenoiseImageHandler> &handler, 134 CLWaveletFilterBank fb, 135 uint32_t channel, 136 uint32_t layer, 137 bool bayes_shrink); 138 139 SmartPtr<CLWaveletDecompBuffer> get_decomp_buffer (uint32_t channel, int layer); 140 141 protected: 142 virtual XCamReturn prepare_arguments ( 143 CLArgList &args, CLWorkSize &work_size); 144 145 private: 146 CLWaveletFilterBank _filter_bank; 147 uint32_t _decomposition_levels; 148 uint32_t _channel; 149 uint32_t _current_layer; 150 bool _bayes_shrink; 151 152 SmartPtr<CLNewWaveletDenoiseImageHandler> _handler; 153 }; 154 155 class CLNewWaveletDenoiseImageHandler 156 : public CLImageHandler 157 { 158 typedef std::list<SmartPtr<CLWaveletDecompBuffer>> CLWaveletDecompBufferList; 159 160 public: 161 explicit CLNewWaveletDenoiseImageHandler ( 162 const SmartPtr<CLContext> &context, const char *name, uint32_t channel); 163 164 bool set_denoise_config (const XCam3aResultWaveletNoiseReduction& config); get_denoise_config()165 XCam3aResultWaveletNoiseReduction& get_denoise_config () { 166 return _config; 167 }; 168 169 SmartPtr<CLWaveletDecompBuffer> get_decomp_buffer (uint32_t channel, int layer); 170 171 void set_estimated_noise_variation (float* noise_var); 172 void get_estimated_noise_variation (float* noise_var); 173 174 void dump_coeff (SmartPtr<CLImage> image, uint32_t channel, uint32_t layer, uint32_t subband); 175 176 protected: 177 virtual XCamReturn prepare_output_buf (SmartPtr<VideoBuffer> &input, SmartPtr<VideoBuffer> &output); 178 179 private: 180 uint32_t _channel; 181 XCam3aResultWaveletNoiseReduction _config; 182 CLWaveletDecompBufferList _decompBufferList; 183 float _noise_variance[3]; 184 }; 185 186 SmartPtr<CLImageHandler> 187 create_cl_newwavelet_denoise_image_handler ( 188 const SmartPtr<CLContext> &context, uint32_t channel, bool bayes_shrink); 189 190 }; 191 192 #endif //XCAM_CL_NEWWAVELET_DENOISE_HANLDER_H 193