.. _program_listing_file__tmp_ws_src_vitis_common_include_common_xf_video_types.hpp: Program Listing for File xf_video_types.hpp =========================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/vitis_common/include/common/xf_video_types.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. */ // This code is derived from OpenCV: // opencv/modules/core/include/opencv2/core/types_c.h /*M/////////////////////////////////////////////////////////////////////////////////////// // // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. // // By downloading, copying, installing or using the software you agree to this license. // If you do not agree to this license, do not download, install, // copy or use the software. // // // License Agreement // For Open Source Computer Vision Library // // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. // Copyright (C) 2009, Willow Garage Inc., all rights reserved. // Third party copyrights are property of their respective owners. // // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: // // * Redistribution's of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // * Redistribution's in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // * The name of the copyright holders may not be used to endorse or promote products // derived from this software without specific prior written permission. // // This software is provided by the copyright holders and contributors "as is" and // any express or implied warranties, including, but not limited to, the implied // warranties of merchantability and fitness for a particular purpose are disclaimed. // In no event shall the Intel Corporation or contributors be liable for any direct, // indirect, incidental, special, exemplary, or consequential damages // (including, but not limited to, procurement of substitute goods or services; // loss of use, data, or profits; or business interruption) however caused // and on any theory of liability, whether in contract, strict liability, // or tort (including negligence or otherwise) arising in any way out of // the use of this software, even if advised of the possibility of such damage. // //M*/ /* * HLS Video Types Header File */ #ifndef ___XF__VIDEO_TYPES__ #define ___XF__VIDEO_TYPES__ #include //#define __INTERVAL(LB,x,RB) ( ( (x) > RB ) ? RB : ( (x) < LB ) ? LB : (x) ) //#define XF_CN_MAX 512 //#define XF_CN_SHIFT 11 //#define XF_DEPTH_MAX (1 << HLS_CN_SHIFT) // #define XF_8U 0 #define XF_8S 1 #define XF_16U 2 #define XF_16S 3 #define XF_32S 4 #define XF_32F 5 #define XF_64F 6 #define XF_USRTYPE1 7 #define XF_10U 8 #define XF_10S 9 #define XF_12U 10 #define XF_12S 11 // //#define XF_MAT_DEPTH_MASK (XF_DEPTH_MAX - 1) //#define XF_MAT_DEPTH(flags) ((flags) & XF_MAT_DEPTH_MASK) // //#define XF_MAKETYPE(depth,cn) (XF_MAT_DEPTH(depth) + (((cn)-1) << XF_CN_SHIFT)) //#define XF_MAKE_TYPE XF_MAKETYPE // //#define HLS_8UC1 HLS_MAKETYPE(HLS_8U,1) //#define HLS_8UC2 HLS_MAKETYPE(HLS_8U,2) //#define HLS_8UC3 HLS_MAKETYPE(HLS_8U,3) //#define HLS_8UC4 HLS_MAKETYPE(HLS_8U,4) // //#define HLS_8SC1 HLS_MAKETYPE(HLS_8S,1) //#define HLS_8SC2 HLS_MAKETYPE(HLS_8S,2) //#define HLS_8SC3 HLS_MAKETYPE(HLS_8S,3) //#define HLS_8SC4 HLS_MAKETYPE(HLS_8S,4) // //#define HLS_10UC1 HLS_MAKETYPE(HLS_10U,1) //#define HLS_10UC2 HLS_MAKETYPE(HLS_10U,2) //#define HLS_10UC3 HLS_MAKETYPE(HLS_10U,3) //#define HLS_10UC4 HLS_MAKETYPE(HLS_10U,4) // //#define HLS_10SC1 HLS_MAKETYPE(HLS_10S,1) //#define HLS_10SC2 HLS_MAKETYPE(HLS_10S,2) //#define HLS_10SC3 HLS_MAKETYPE(HLS_10S,3) //#define HLS_10SC4 HLS_MAKETYPE(HLS_10S,4) // //#define HLS_12UC1 HLS_MAKETYPE(HLS_12U,1) //#define HLS_12UC2 HLS_MAKETYPE(HLS_12U,2) //#define HLS_12UC3 HLS_MAKETYPE(HLS_12U,3) //#define HLS_12UC4 HLS_MAKETYPE(HLS_12U,4) // //#define HLS_12SC1 HLS_MAKETYPE(HLS_12S,1) //#define HLS_12SC2 HLS_MAKETYPE(HLS_12S,2) //#define HLS_12SC3 HLS_MAKETYPE(HLS_12S,3) //#define HLS_12SC4 HLS_MAKETYPE(HLS_12S,4) // //#define HLS_16UC1 HLS_MAKETYPE(HLS_16U,1) //#define HLS_16UC2 HLS_MAKETYPE(HLS_16U,2) //#define HLS_16UC3 HLS_MAKETYPE(HLS_16U,3) //#define HLS_16UC4 HLS_MAKETYPE(HLS_16U,4) // //#define HLS_16SC1 HLS_MAKETYPE(HLS_16S,1) //#define HLS_16SC2 HLS_MAKETYPE(HLS_16S,2) //#define HLS_16SC3 HLS_MAKETYPE(HLS_16S,3) //#define HLS_16SC4 HLS_MAKETYPE(HLS_16S,4) // //#define HLS_32SC1 HLS_MAKETYPE(HLS_32S,1) //#define HLS_32SC2 HLS_MAKETYPE(HLS_32S,2) //#define HLS_32SC3 HLS_MAKETYPE(HLS_32S,3) //#define HLS_32SC4 HLS_MAKETYPE(HLS_32S,4) // //#define HLS_32FC1 HLS_MAKETYPE(HLS_32F,1) //#define HLS_32FC2 HLS_MAKETYPE(HLS_32F,2) //#define HLS_32FC3 HLS_MAKETYPE(HLS_32F,3) //#define HLS_32FC4 HLS_MAKETYPE(HLS_32F,4) // //#define HLS_64FC1 HLS_MAKETYPE(HLS_64F,1) //#define HLS_64FC2 HLS_MAKETYPE(HLS_64F,2) //#define HLS_64FC3 HLS_MAKETYPE(HLS_64F,3) //#define HLS_64FC4 HLS_MAKETYPE(HLS_64F,4) // //#define HLS_SC(BITDEPTH,CN) HLS_MAKETYPE(BITDEPTH+12,CN) // //#define HLS_MAT_CN_MASK ((HLS_CN_MAX - 1) << HLS_CN_SHIFT) //#define HLS_MAT_CN(flags) ((((flags) & HLS_MAT_CN_MASK) >> HLS_CN_SHIFT) + 1) //#define HLS_MAT_TYPE_MASK (HLS_DEPTH_MAX*HLS_CN_MAX - 1) //#define HLS_MAT_TYPE(flags) ((flags) & HLS_MAT_TYPE_MASK) // //#define HLS_ARE_TYPES_EQ(type1, type2) \ // (((type1 ^ type2) & HLS_MAT_TYPE_MASK) == 0) // //#define HLS_ARE_SIZES_EQ(mat1, mat2) \ // ((mat1).rows == (mat2).rows && (mat1).cols == (mat2).cols) template struct Type { typedef ap_int name; static const int bitdepth = T - 12; }; template <> struct Type { typedef unsigned char name; static const int bitdepth = 8; }; template <> struct Type { typedef char name; static const int bitdepth = 8; }; template <> struct Type { typedef ap_uint<10> name; static const int bitdepth = 10; }; template <> struct Type { typedef ap_int<10> name; static const int bitdepth = 10; }; template <> struct Type { typedef ap_uint<12> name; static const int bitdepth = 12; }; template <> struct Type { typedef ap_int<12> name; static const int bitdepth = 12; }; template <> struct Type { typedef unsigned short name; static const int bitdepth = 16; }; template <> struct Type { typedef short name; static const int bitdepth = 16; }; template <> struct Type { typedef int name; static const int bitdepth = 32; }; template <> struct Type { typedef float name; static const int bitdepth = 32; }; template <> struct Type { typedef double name; static const int bitdepth = 64; }; template struct pixel_op_type { typedef PIXEL_T T; }; template <> struct pixel_op_type { typedef ap_uint<8> T; }; template <> struct pixel_op_type { typedef ap_int<8> T; }; template <> struct pixel_op_type { typedef ap_uint<16> T; }; template <> struct pixel_op_type { typedef ap_int<16> T; }; template <> struct pixel_op_type { typedef ap_uint<32> T; }; template <> struct pixel_op_type { typedef ap_int<32> T; }; template struct pixel_op_type > { typedef ap_int T; }; template struct pixel_op_type > { typedef ap_uint T; }; #define HLS_TNAME(flags) typename Type::name #define HLS_TBITDEPTH(flags) Type::bitdepth #define XF_8U_MIN 0 #define XF_8U_MAX 255 #define XF_8S_MIN -127 #define XF_8S_MAX 127 #define XF_10U_MIN 0 #define XF_10U_MAX 1023 #define XF_10S_MIN -511 #define XF_10S_MAX 511 #define XF_12U_MIN 0 #define XF_12U_MAX 4095 #define XF_12S_MIN -2047 #define XF_12S_MAX 2047 #define XF_16U_MIN 0 #define XF_16U_MAX 65535 #define XF_16S_MIN -32767 #define XF_16S_MAX 32767 #define XF_32S_MIN -2147483647 #define XF_32S_MAX 2147483647 template struct Name { static const int _min = XF_32S_MIN; static const int _max = XF_32S_MAX; }; template <> struct Name { static const int _min = XF_8U_MIN; static const int _max = XF_8U_MAX; }; template <> struct Name { static const int _min = XF_8S_MIN; static const int _max = XF_8S_MAX; }; template <> struct Name { static const int _min = XF_16U_MIN; static const int _max = XF_16U_MAX; }; template <> struct Name { static const int _min = XF_16S_MIN; static const int _max = XF_16S_MAX; }; template <> struct Name { static const int _min = XF_32S_MIN; static const int _max = XF_32S_MAX; }; template unsigned char Convert2uchar(T v) { unsigned char result = XF_8U_MIN; if (v >= XF_8U_MAX) { result = XF_8U_MAX; } else if (v >= XF_8U_MIN && v < XF_8U_MAX) { ap_fixed<9, 9, AP_RND> temp = v; result = temp; } return result; } template char Convert2char(T v) { char result = XF_8S_MIN; if (v >= XF_8S_MAX) { result = XF_8S_MAX; } else if (v >= XF_8S_MIN && v < XF_8S_MAX) { ap_fixed<9, 9, AP_RND> temp = v; result = temp; } return result; } template unsigned short Convert2ushort(T v) { unsigned short result = XF_16U_MIN; if (v >= XF_16U_MAX) { result = XF_16U_MAX; } else if (v >= XF_16U_MIN && v < XF_16U_MAX) { ap_fixed<17, 17, AP_RND> temp = v; result = temp; } return result; } template short Convert2short(T v) { short result = XF_16S_MIN; if (v >= XF_16S_MAX) { result = XF_16S_MAX; } else if (v >= XF_16S_MIN && v < XF_16S_MAX) { ap_fixed<17, 17, AP_RND> temp = v; result = temp; } return result; } template int Convert2int(T v) { int result = XF_32S_MIN; if (v >= XF_32S_MAX) { result = XF_32S_MAX; } else if (v >= XF_32S_MIN && v < XF_32S_MAX) { ap_fixed<32, 32, AP_RND> temp = v; result = temp; } return result; } // The type is redefined, in previous versions it was ap_int<12> typedef ap_uint<32> XF_SIZE_T; typedef ap_uint<5> XF_CHANNEL_T; namespace xf { namespace cv { /* sr_cast: saturate and round cast: T1 -> T2 */ template class sr_cast_class {}; template <> class sr_cast_class { public: template inline float operator()(T1 v) { return v; } inline float operator()(double v) { return HLS_FPO_DTOF(v); } }; template <> class sr_cast_class { public: template inline double operator()(T1 v) { return v; } inline double operator()(float v) { return HLS_FPO_FTOD(v); } }; template class sr_cast_class > { public: template inline ap_int operator()(ap_int v) { return ap_fixed(v); } template inline ap_int operator()(ap_uint v) { return ap_fixed(v); } template inline ap_int operator()(ap_fixed v) { return ap_fixed(v); } template inline ap_int operator()(ap_ufixed v) { return ap_fixed(v); } template inline ap_int operator()(ap_fixed_base v) { return ap_fixed(v); } template inline ap_int operator()(ap_fixed_base v) { return ap_fixed(v); } inline ap_int operator()(float v) { if (::hls::__isnan(v)) return 0; else return ap_fixed(v); } inline ap_int operator()(double v) { if (::hls::__isnan(v)) return 0; else return ap_fixed(v); } inline ap_int operator()(unsigned char v) { return operator()(ap_uint<8>(v)); } inline ap_int operator()(char v) { return operator()(ap_int<8>(v)); } inline ap_int operator()(unsigned short v) { return operator()(ap_uint<16>(v)); } inline ap_int operator()(short v) { return operator()(ap_int<16>(v)); } inline ap_int operator()(unsigned int v) { return operator()(ap_uint<32>(v)); } inline ap_int operator()(int v) { return operator()(ap_int<32>(v)); } inline ap_int operator()(unsigned long long v) { return operator()(ap_uint<64>(v)); } inline ap_int operator()(long long v) { return operator()(ap_int<64>(v)); } }; template class sr_cast_class > { public: template inline ap_uint operator()(ap_int v) { return ap_ufixed(v); } template inline ap_uint operator()(ap_uint v) { return ap_ufixed(v); } template inline ap_uint operator()(ap_fixed v) { return ap_ufixed(v); } template inline ap_uint operator()(ap_ufixed v) { return ap_ufixed(v); } template inline ap_uint operator()(ap_fixed_base v) { return ap_ufixed(v); } template inline ap_uint operator()(ap_fixed_base v) { return ap_ufixed(v); } inline ap_uint operator()(float v) { if (::hls::__isnan(v)) return 0; else return ap_ufixed(v); } inline ap_uint operator()(double v) { if (::hls::__isnan(v)) return 0; else return ap_ufixed(v); } inline ap_uint operator()(unsigned char v) { return operator()(ap_uint<8>(v)); } inline ap_uint operator()(char v) { return operator()(ap_int<8>(v)); } inline ap_uint operator()(unsigned short v) { return operator()(ap_uint<16>(v)); } inline ap_uint operator()(short v) { return operator()(ap_int<16>(v)); } inline ap_uint operator()(unsigned int v) { return operator()(ap_uint<32>(v)); } inline ap_uint operator()(int v) { return operator()(ap_int<32>(v)); } inline ap_uint operator()(unsigned long long v) { return operator()(ap_uint<64>(v)); } inline ap_uint operator()(long long v) { return operator()(ap_int<64>(v)); } }; template <> class sr_cast_class : public sr_cast_class > { public: using sr_cast_class >::operator(); }; template <> class sr_cast_class : public sr_cast_class > { public: using sr_cast_class >::operator(); }; template <> class sr_cast_class : public sr_cast_class > { public: using sr_cast_class >::operator(); }; template <> class sr_cast_class : public sr_cast_class > { public: using sr_cast_class >::operator(); }; template <> class sr_cast_class : public sr_cast_class > { public: using sr_cast_class >::operator(); }; template <> class sr_cast_class : public sr_cast_class > { public: using sr_cast_class >::operator(); }; template <> class sr_cast_class : public sr_cast_class > { public: using sr_cast_class >::operator(); }; template <> class sr_cast_class : public sr_cast_class > { public: using sr_cast_class >::operator(); }; template inline T2 sr_cast(T1 v) { ::xf::cv::sr_cast_class V; return V(v); } } // namespace cv } // namespace xf #endif