1 /* 2 * soft_blender_tasks_priv.h - soft blender tasks private class 3 * 4 * Copyright (c) 2017 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 #ifndef XCAM_SOFT_BLENDER_TASKS_PRIV_H 22 #define XCAM_SOFT_BLENDER_TASKS_PRIV_H 23 24 #include <xcam_std.h> 25 #include <soft/soft_worker.h> 26 #include <soft/soft_image.h> 27 #include <soft/soft_blender.h> 28 29 #define SOFT_BLENDER_ALIGNMENT_X 8 30 #define SOFT_BLENDER_ALIGNMENT_Y 4 31 32 #define GAUSS_DOWN_SCALE_RADIUS 2 33 #define GAUSS_DOWN_SCALE_SIZE ((GAUSS_DOWN_SCALE_RADIUS)*2+1) 34 35 namespace XCam { 36 37 namespace XCamSoftTasks { 38 39 class GaussScaleGray 40 : public SoftWorker 41 { 42 public: 43 struct Args : SoftArgs { 44 SmartPtr<UcharImage> in_luma, out_luma; 45 }; 46 47 public: 48 explicit GaussScaleGray (const char *name = "GaussScaleGray", const SmartPtr<Worker::Callback> &cb = NULL) SoftWorker(name,cb)49 : SoftWorker (name, cb) 50 { 51 set_work_uint (2, 2); 52 } 53 54 private: 55 virtual XCamReturn work_range (const SmartPtr<Arguments> &args, const WorkRange &range); 56 57 protected: 58 void gauss_luma_2x2 ( 59 UcharImage *in_luma, UcharImage *out_luma, uint32_t x, uint32_t y); 60 multiply_coeff_y(float * out,const float * in,float coef)61 inline void multiply_coeff_y (float *out, const float *in, float coef) { 62 out[0] += in[0] * coef; 63 out[1] += in[1] * coef; 64 out[2] += in[2] * coef; 65 out[3] += in[3] * coef; 66 out[4] += in[4] * coef; 67 out[5] += in[5] * coef; 68 out[6] += in[6] * coef; 69 out[7] += in[7] * coef; 70 } 71 72 template<typename T> gauss_sum(const T * input)73 inline T gauss_sum (const T *input) { 74 return (input[0] * coeffs[0] + input[1] * coeffs[1] + input[2] * coeffs[2] + 75 input[3] * coeffs[3] + input[4] * coeffs[4]); 76 } 77 78 protected: 79 static const float coeffs[GAUSS_DOWN_SCALE_SIZE]; 80 }; 81 82 class GaussDownScale 83 : public GaussScaleGray 84 { 85 public: 86 struct Args : GaussScaleGray::Args { 87 SmartPtr<Uchar2Image> in_uv, out_uv; 88 const uint32_t level; 89 const SoftBlender::BufIdx idx; 90 91 SmartPtr<VideoBuffer> in_buf; 92 SmartPtr<VideoBuffer> out_buf; 93 ArgsArgs94 Args ( 95 const SmartPtr<ImageHandler::Parameters> ¶m, 96 const uint32_t l, const SoftBlender::BufIdx i, 97 const SmartPtr<VideoBuffer> &in, 98 const SmartPtr<VideoBuffer> &out) 99 : level (l) 100 , idx (i) 101 , in_buf (in) 102 , out_buf (out) 103 { 104 set_param (param); 105 } 106 }; 107 108 public: GaussDownScale(const SmartPtr<Worker::Callback> & cb)109 explicit GaussDownScale (const SmartPtr<Worker::Callback> &cb) 110 : GaussScaleGray ("GaussDownScale", cb) 111 {} 112 113 private: 114 virtual XCamReturn work_range (const SmartPtr<Arguments> &args, const WorkRange &range); 115 multiply_coeff_uv(Float2 * out,Float2 * in,float coef)116 inline void multiply_coeff_uv (Float2 *out, Float2 *in, float coef) { 117 out[0] += in[0] * coef; 118 out[1] += in[1] * coef; 119 out[2] += in[2] * coef; 120 out[3] += in[3] * coef; 121 out[4] += in[4] * coef; 122 } 123 }; 124 125 class BlendTask 126 : public SoftWorker 127 { 128 public: 129 struct Args : SoftArgs { 130 SmartPtr<UcharImage> in_luma[2], out_luma; 131 SmartPtr<Uchar2Image> in_uv[2], out_uv; 132 SmartPtr<UcharImage> mask; 133 134 SmartPtr<VideoBuffer> out_buf; 135 136 Args ( 137 const SmartPtr<ImageHandler::Parameters> ¶m, 138 const SmartPtr<UcharImage> &m, 139 const SmartPtr<VideoBuffer> &out = NULL) SoftArgsArgs140 : SoftArgs (param) 141 , mask (m) 142 , out_buf (out) 143 {} 144 }; 145 146 public: BlendTask(const SmartPtr<Worker::Callback> & cb)147 explicit BlendTask (const SmartPtr<Worker::Callback> &cb) 148 : SoftWorker ("SoftBlendTask", cb) 149 { 150 set_work_uint (8, 2); 151 } 152 153 private: 154 virtual XCamReturn work_range (const SmartPtr<Arguments> &args, const WorkRange &range); 155 }; 156 157 class LaplaceTask 158 : public SoftWorker 159 { 160 public: 161 struct Args : SoftArgs { 162 SmartPtr<UcharImage> orig_luma, gauss_luma, out_luma; 163 SmartPtr<Uchar2Image> orig_uv, gauss_uv, out_uv; 164 const uint32_t level; 165 const SoftBlender::BufIdx idx; 166 167 SmartPtr<VideoBuffer> out_buf; 168 169 Args ( 170 const SmartPtr<ImageHandler::Parameters> ¶m, 171 const uint32_t l, const SoftBlender::BufIdx i, 172 const SmartPtr<VideoBuffer> &out = NULL) SoftArgsArgs173 : SoftArgs (param) 174 , level(l) 175 , idx (i) 176 , out_buf (out) 177 {} 178 }; 179 180 public: LaplaceTask(const SmartPtr<Worker::Callback> & cb)181 explicit LaplaceTask (const SmartPtr<Worker::Callback> &cb) 182 : SoftWorker ("SoftLaplaceTask", cb) 183 { 184 set_work_uint (8, 4); 185 } 186 187 private: 188 virtual XCamReturn work_range (const SmartPtr<Arguments> &args, const WorkRange &range); 189 190 void interplate_luma_8x2 ( 191 UcharImage *orig_luma, UcharImage *gauss_luma, UcharImage *out_luma, 192 uint32_t out_x, uint32_t out_y); 193 }; 194 195 class ReconstructTask 196 : public SoftWorker 197 { 198 public: 199 struct Args : SoftArgs { 200 SmartPtr<UcharImage> gauss_luma, lap_luma[2], out_luma; 201 SmartPtr<Uchar2Image> gauss_uv, lap_uv[2], out_uv; 202 SmartPtr<UcharImage> mask; 203 const uint32_t level; 204 205 SmartPtr<VideoBuffer> out_buf; 206 207 Args ( 208 const SmartPtr<ImageHandler::Parameters> ¶m, 209 const uint32_t l, 210 const SmartPtr<VideoBuffer> &out = NULL) SoftArgsArgs211 : SoftArgs (param) 212 , level(l) 213 , out_buf (out) 214 {} 215 }; 216 217 public: ReconstructTask(const SmartPtr<Worker::Callback> & cb)218 explicit ReconstructTask (const SmartPtr<Worker::Callback> &cb) 219 : SoftWorker ("SoftReconstructTask", cb) 220 { 221 set_work_uint (8, 4); 222 } 223 224 private: 225 virtual XCamReturn work_range (const SmartPtr<Arguments> &args, const WorkRange &range); 226 }; 227 228 } 229 230 } 231 232 #endif //XCAM_SOFT_BLENDER_TASKS_PRIV_H 233