.. _program_listing_file__tmp_ws_src_vitis_common_include_imgproc_xf_paintmask.hpp: Program Listing for File xf_paintmask.hpp ========================================= |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/vitis_common/include/imgproc/xf_paintmask.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /* * Copyright 2019 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. */ #ifndef _XF_THRESHOLD_HPP_ #define _XF_THRESHOLD_HPP_ #ifndef __cplusplus #error C++ is needed to include this header #endif typedef unsigned short uint16_t; typedef unsigned char uchar; #include "hls_stream.h" #include "../common/xf_common.hpp" #include "../common/xf_utility.hpp" namespace xf { namespace cv { /*Paint mask function masks certain area of image depends on input mask */ template void xFpaintmaskKernel(xf::cv::Mat& _src_mat, xf::cv::Mat& _in_mask, xf::cv::Mat& _dst_mat, xf::cv::Scalar& color, unsigned short height, unsigned short width) { XF_SNAME(WORDWIDTH_SRC) val_src; XF_SNAME(WORDWIDTH_MASK) in_mask; XF_SNAME(WORDWIDTH_DST) val_dst; XF_PTNAME(DEPTH) p, mask; short int depth = XF_DTPIXELDEPTH(SRC_T, NPC) / XF_CHANNELS(SRC_T, NPC); XF_PTNAME(DEPTH) arr_color[XF_CHANNELS(SRC_T, NPC)]; // clang-format off #pragma HLS ARRAY_PARTITION variable=arr_color dim=1 complete // clang-format on for (int i = 0; i < (XF_CHANNELS(SRC_T, NPC)); i++) { arr_color[i] = color.val[i]; } ap_uint<13> i, j, k, planes; rowLoop: for (i = 0; i < height; i++) { // clang-format off #pragma HLS LOOP_TRIPCOUNT min=ROWS max=ROWS #pragma HLS LOOP_FLATTEN off // clang-format on ap_uint<8> channels = XF_CHANNELS(SRC_T, NPC); colLoop: for (j = 0; j < width; j++) { // clang-format off #pragma HLS LOOP_TRIPCOUNT min=COLS_TRIP max=COLS_TRIP #pragma HLS pipeline // clang-format on val_src = (XF_SNAME(WORDWIDTH_SRC))(_src_mat.read(i * width + j)); // reading the source stream _src into val_src in_mask = (XF_SNAME(WORDWIDTH_MASK))( _in_mask.read(i * width + j)); // reading the input mask stream _in_mask into in_mask for (k = 0, planes = 0; k < (XF_WORDDEPTH(WORDWIDTH_SRC)); k += depth, planes++) { // clang-format off #pragma HLS unroll // clang-format on p = val_src.range(k + (depth - 1), k); mask = in_mask.range(k + (depth - 1), k); if (mask != 0) { if (NPC != 1) val_dst.range(k + (depth - 1), k) = arr_color[0]; else val_dst.range(k + (depth - 1), k) = arr_color[planes]; } else { val_dst.range(k + (depth - 1), k) = p; } } _dst_mat.write(i * width + j, val_dst); // writing the val_dst into output stream _dst } } } /* Paint mask API call*/ template void paintmask(xf::cv::Mat& _src_mat, xf::cv::Mat& in_mask, xf::cv::Mat& _dst_mat, unsigned char _color[XF_CHANNELS(SRC_T, NPC)]) { unsigned short width = _src_mat.cols >> XF_BITSHIFT(NPC); unsigned short height = _src_mat.rows; xf::cv::Scalar color; for (int i = 0; i < XF_CHANNELS(SRC_T, NPC); i++) { color.val[i] = _color[i]; } #ifndef __SYNTHESIS__ assert((SRC_T == XF_8UC1) && "Type must be XF_8UC1"); assert(((NPC == XF_NPPC1) || (NPC == XF_NPPC8)) && "NPC must be XF_NPPC1, XF_NPPC8"); assert(((height <= ROWS) && (width <= COLS)) && "ROWS and COLS should be greater than input image"); #endif // clang-format off #pragma HLS INLINE OFF // clang-format on xFpaintmaskKernel> XF_BITSHIFT(NPC))>( _src_mat, in_mask, _dst_mat, color, height, width); } } // namespace cv } // namespace xf #endif