/*1* By downloading, copying, installing or using the software you agree to this license.2* If you do not agree to this license, do not download, install,3* copy or use the software.4*5*6* License Agreement7* For Open Source Computer Vision Library8* (3-clause BSD License)9*10* Copyright (C) 2014, NVIDIA Corporation, all rights reserved.11* Third party copyrights are property of their respective owners.12*13* Redistribution and use in source and binary forms, with or without modification,14* are permitted provided that the following conditions are met:15*16* * Redistributions of source code must retain the above copyright notice,17* this list of conditions and the following disclaimer.18*19* * Redistributions in binary form must reproduce the above copyright notice,20* this list of conditions and the following disclaimer in the documentation21* and/or other materials provided with the distribution.22*23* * Neither the names of the copyright holders nor the names of the contributors24* may be used to endorse or promote products derived from this software25* without specific prior written permission.26*27* This software is provided by the copyright holders and contributors "as is" and28* any express or implied warranties, including, but not limited to, the implied29* warranties of merchantability and fitness for a particular purpose are disclaimed.30* In no event shall copyright holders or contributors be liable for any direct,31* indirect, incidental, special, exemplary, or consequential damages32* (including, but not limited to, procurement of substitute goods or services;33* loss of use, data, or profits; or business interruption) however caused34* and on any theory of liability, whether in contract, strict liability,35* or tort (including negligence or otherwise) arising in any way out of36* the use of this software, even if advised of the possibility of such damage.37*/3839#include <cstdlib>40#include <iostream>4142#include "common.hpp"4344namespace CAROTENE_NS {4546bool isSupportedConfiguration()47{48#ifdef CAROTENE_NEON49return true;50#else51return false;52#endif53}5455namespace internal {5657void assertSupportedConfiguration(bool parametersSupported)58{59if (!isSupportedConfiguration()) {60std::cerr << "internal error: attempted to use an unavailable function" << std::endl;61std::abort();62}6364if (!parametersSupported) {65std::cerr << "internal error: attempted to use a function with unsupported parameters" << std::endl;66std::abort();67}68}6970ptrdiff_t borderInterpolate(ptrdiff_t _p, size_t _len, BORDER_MODE borderType, size_t startMargin, size_t endMargin)71{72ptrdiff_t p = _p + (ptrdiff_t)startMargin;73size_t len = _len + startMargin + endMargin;74if( (size_t)p < len )75return _p;76else if( borderType == BORDER_MODE_REPLICATE )77p = p < 0 ? 0 : (ptrdiff_t)len - 1;78else if( borderType == BORDER_MODE_REFLECT || borderType == BORDER_MODE_REFLECT101 )79{80s32 delta = borderType == BORDER_MODE_REFLECT101;81if( len == 1 )82return 0;83do84{85if( p < 0 )86p = -p - 1 + delta;87else88p = (ptrdiff_t)len - 1 - (p - (ptrdiff_t)len) - delta;89}90while( (size_t)p >= len );91}92else if( borderType == BORDER_MODE_WRAP )93{94if( p < 0 )95p -= ((p-(ptrdiff_t)len+1)/(ptrdiff_t)len)*(ptrdiff_t)len;96if( p >= (ptrdiff_t)len )97p %= (ptrdiff_t)len;98}99else if( borderType == BORDER_MODE_CONSTANT )100p = -1;101else102internal::assertSupportedConfiguration(false);103return p - (ptrdiff_t)startMargin;104}105106} // namespace internal107} // namespace CAROTENE_NS108109110