arm_bilinear_interp_f16.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_bilinear_interp_f16.c
  4. * Description: Floating-point bilinear interpolation
  5. *
  6. * $Date: 23 April 2021
  7. * $Revision: V1.9.0
  8. *
  9. * Target Processor: Cortex-M and Cortex-A cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
  13. *
  14. * SPDX-License-Identifier: Apache-2.0
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the License); you may
  17. * not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  24. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. */
  28. #include "dsp/interpolation_functions_f16.h"
  29. #if defined(ARM_FLOAT16_SUPPORTED)
  30. /**
  31. @ingroup groupInterpolation
  32. */
  33. /**
  34. * @addtogroup BilinearInterpolate
  35. * @{
  36. */
  37. /**
  38. * @brief Floating-point bilinear interpolation.
  39. * @param[in,out] S points to an instance of the interpolation structure.
  40. * @param[in] X interpolation coordinate.
  41. * @param[in] Y interpolation coordinate.
  42. * @return out interpolated value.
  43. */
  44. float16_t arm_bilinear_interp_f16(
  45. const arm_bilinear_interp_instance_f16 * S,
  46. float16_t X,
  47. float16_t Y)
  48. {
  49. float16_t out;
  50. float16_t f00, f01, f10, f11;
  51. const float16_t *pData = S->pData;
  52. int32_t xIndex, yIndex, index;
  53. float16_t xdiff, ydiff;
  54. float16_t b1, b2, b3, b4;
  55. xIndex = (int32_t) X;
  56. yIndex = (int32_t) Y;
  57. /* Care taken for table outside boundary */
  58. /* Returns zero output when values are outside table boundary */
  59. if (xIndex < 0 || xIndex > (S->numCols - 2) || yIndex < 0 || yIndex > (S->numRows - 2))
  60. {
  61. return (0);
  62. }
  63. /* Calculation of index for two nearest points in X-direction */
  64. index = (xIndex ) + (yIndex ) * S->numCols;
  65. /* Read two nearest points in X-direction */
  66. f00 = pData[index];
  67. f01 = pData[index + 1];
  68. /* Calculation of index for two nearest points in Y-direction */
  69. index = (xIndex ) + (yIndex+1) * S->numCols;
  70. /* Read two nearest points in Y-direction */
  71. f10 = pData[index];
  72. f11 = pData[index + 1];
  73. /* Calculation of intermediate values */
  74. b1 = f00;
  75. b2 = (_Float16)f01 - (_Float16)f00;
  76. b3 = (_Float16)f10 - (_Float16)f00;
  77. b4 = (_Float16)f00 - (_Float16)f01 - (_Float16)f10 + (_Float16)f11;
  78. /* Calculation of fractional part in X */
  79. xdiff = (_Float16)X - (_Float16)xIndex;
  80. /* Calculation of fractional part in Y */
  81. ydiff = (_Float16)Y - (_Float16)yIndex;
  82. /* Calculation of bi-linear interpolated output */
  83. out = (_Float16)b1 + (_Float16)b2 * (_Float16)xdiff +
  84. (_Float16)b3 * (_Float16)ydiff + (_Float16)b4 * (_Float16)xdiff * (_Float16)ydiff;
  85. /* return to application */
  86. return (out);
  87. }
  88. /**
  89. * @} end of BilinearInterpolate group
  90. */
  91. #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */