• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * By downloading, copying, installing or using the software you agree to this license.
3  * If you do not agree to this license, do not download, install,
4  * copy or use the software.
5  *
6  *
7  *                           License Agreement
8  *                For Open Source Computer Vision Library
9  *                        (3-clause BSD License)
10  *
11  * Copyright (C) 2014, NVIDIA Corporation, all rights reserved.
12  * Third party copyrights are property of their respective owners.
13  *
14  * Redistribution and use in source and binary forms, with or without modification,
15  * are permitted provided that the following conditions are met:
16  *
17  *   * Redistributions of source code must retain the above copyright notice,
18  *     this list of conditions and the following disclaimer.
19  *
20  *   * Redistributions in binary form must reproduce the above copyright notice,
21  *     this list of conditions and the following disclaimer in the documentation
22  *     and/or other materials provided with the distribution.
23  *
24  *   * Neither the names of the copyright holders nor the names of the contributors
25  *     may be used to endorse or promote products derived from this software
26  *     without specific prior written permission.
27  *
28  * This software is provided by the copyright holders and contributors "as is" and
29  * any express or implied warranties, including, but not limited to, the implied
30  * warranties of merchantability and fitness for a particular purpose are disclaimed.
31  * In no event shall copyright holders or contributors be liable for any direct,
32  * indirect, incidental, special, exemplary, or consequential damages
33  * (including, but not limited to, procurement of substitute goods or services;
34  * loss of use, data, or profits; or business interruption) however caused
35  * and on any theory of liability, whether in contract, strict liability,
36  * or tort (including negligence or otherwise) arising in any way out of
37  * the use of this software, even if advised of the possibility of such damage.
38  */
39 
40 #include <cstdlib>
41 #include <iostream>
42 
43 #include "common.hpp"
44 
45 namespace CAROTENE_NS {
46 
isSupportedConfiguration()47 bool isSupportedConfiguration()
48 {
49 #ifdef CAROTENE_NEON
50     return true;
51 #else
52     return false;
53 #endif
54 }
55 
56 namespace internal {
57 
assertSupportedConfiguration(bool parametersSupported)58 void assertSupportedConfiguration(bool parametersSupported)
59 {
60     if (!isSupportedConfiguration()) {
61         std::cerr << "internal error: attempted to use an unavailable function" << std::endl;
62         std::abort();
63     }
64 
65     if (!parametersSupported) {
66         std::cerr << "internal error: attempted to use a function with unsupported parameters" << std::endl;
67         std::abort();
68     }
69 }
70 
borderInterpolate(ptrdiff_t _p,size_t _len,BORDER_MODE borderType,size_t startMargin,size_t endMargin)71 ptrdiff_t borderInterpolate(ptrdiff_t _p, size_t _len, BORDER_MODE borderType, size_t startMargin, size_t endMargin)
72 {
73     ptrdiff_t p = _p + (ptrdiff_t)startMargin;
74     size_t len = _len + startMargin + endMargin;
75     if( (size_t)p < len )
76         return _p;
77     else if( borderType == BORDER_MODE_REPLICATE )
78         p = p < 0 ? 0 : (ptrdiff_t)len - 1;
79     else if( borderType == BORDER_MODE_REFLECT || borderType == BORDER_MODE_REFLECT101 )
80     {
81         s32 delta = borderType == BORDER_MODE_REFLECT101;
82         if( len == 1 )
83             return 0;
84         do
85         {
86             if( p < 0 )
87                 p = -p - 1 + delta;
88             else
89                 p = (ptrdiff_t)len - 1 - (p - (ptrdiff_t)len) - delta;
90         }
91         while( (size_t)p >= len );
92     }
93     else if( borderType == BORDER_MODE_WRAP )
94     {
95         if( p < 0 )
96             p -= ((p-(ptrdiff_t)len+1)/(ptrdiff_t)len)*(ptrdiff_t)len;
97         if( p >= (ptrdiff_t)len )
98             p %= (ptrdiff_t)len;
99     }
100     else if( borderType == BORDER_MODE_CONSTANT )
101         p = -1;
102     else
103         internal::assertSupportedConfiguration(false);
104     return p - (ptrdiff_t)startMargin;
105 }
106 
107 } // namespace internal
108 } // namespace CAROTENE_NS
109