.. _program_listing_file__tmp_ws_src_vitis_common_include_aie_imgproc_xf_gaincontrol_aie.hpp: Program Listing for File xf_gaincontrol_aie.hpp =============================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/vitis_common/include/aie/imgproc/xf_gaincontrol_aie.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /* * Copyright 2021 Xilinx, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #ifndef _AIE_GAINCONTROL_H_ #define _AIE_GAINCONTROL_H_ namespace xf { namespace cv { namespace aie { template inline auto compute_gain_vector_even(const int16_t& gain) { ::aie::vector coeff; for (int i = 0; i < (N / 2); i++) chess_flatten_loop { coeff[2 * i] = gain; coeff[2 * i + 1] = (1 << 7); } return coeff; } template inline auto compute_gain_vector_odd(const int16_t& gain) { ::aie::vector coeff; for (int i = 0; i < (N / 2); i++) chess_flatten_loop { coeff[2 * i] = (1 << 7); coeff[2 * i + 1] = gain; } return coeff; } template class ComputeGainVector {}; template class ComputeGainVector { public: // code == 0 : RG static inline void compute_gain_kernel_coeff(const int16_t& rgain, const int16_t& bgain, ::aie::vector& coeff0, ::aie::vector& coeff1) { coeff0 = compute_gain_vector_even(rgain); coeff1 = compute_gain_vector_odd(bgain); } }; template class ComputeGainVector { public: // code == 1 : GR static inline void compute_gain_kernel_coeff(const int16_t& rgain, const int16_t& bgain, ::aie::vector& coeff0, ::aie::vector& coeff1) { coeff0 = compute_gain_vector_odd(rgain); coeff1 = compute_gain_vector_even(bgain); } }; template class ComputeGainVector { public: // code == 2 : BG static inline void compute_gain_kernel_coeff(const int16_t& rgain, const int16_t& bgain, ::aie::vector& coeff0, ::aie::vector& coeff1) { coeff0 = compute_gain_vector_even> (bgain); coeff1 = compute_gain_vector_odd(rgain); } }; template class ComputeGainVector { public: // code == 3 : GB static inline void compute_gain_kernel_coeff(const int16_t& rgain, const int16_t& bgain, ::aie::vector& coeff0, ::aie::vector& coeff1) { coeff0 = compute_gain_vector_odd(bgain); coeff1 = compute_gain_vector_even(rgain); } }; template inline void gaincontrol(const T* restrict img_in, T* restrict img_out, int image_width, int image_height, const ::aie::vector& coeff0, const ::aie::vector& coeff1) { auto it = ::aie::begin_vector(img_in); auto out = ::aie::begin_vector(img_out); for (int i = 0; i < image_height / 2; i++) chess_prepare_for_pipelining chess_loop_range(16, ) { for (int j = 0; j < image_width; j += N) // even rows chess_prepare_for_pipelining chess_loop_range(16, ) { *out++ = ::aie::mul(coeff0, *it++).template to_vector(7); } for (int j = 0; j < image_width; j += N) // odd rows chess_prepare_for_pipelining chess_loop_range(16, ) { *out++ = ::aie::mul(coeff1, *it++).template to_vector(7); } } } template void gaincontrol_api(input_window_int16* img_in, output_window_int16* img_out, const int16_t& rgain, const int16_t& bgain) { int16_t* img_in_ptr = (int16_t*)img_in->ptr; int16_t* img_out_ptr = (int16_t*)img_out->ptr; const int16_t img_width = xfcvGetTileWidth(img_in_ptr); const int16_t img_height = xfcvGetTileHeight(img_in_ptr); xfcvCopyMetaData(img_in_ptr, img_out_ptr); xfcvUnsignedSaturation(img_out_ptr); int16_t* in_ptr = (int16_t*)xfcvGetImgDataPtr(img_in_ptr); int16_t* out_ptr = (int16_t*)xfcvGetImgDataPtr(img_out_ptr); ::aie::vector coeff0; ::aie::vector coeff1; ComputeGainVector::compute_gain_kernel_coeff(rgain, bgain, coeff0, coeff1); gaincontrol(in_ptr, out_ptr, img_width, img_height, coeff0, coeff1); } } // aie } // cv } // xf #endif