2
0

vpx_dsp_common.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (c) 2015 The WebM project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef VPX_VPX_DSP_VPX_DSP_COMMON_H_
  11. #define VPX_VPX_DSP_VPX_DSP_COMMON_H_
  12. #include "./vpx_config.h"
  13. #include "vpx/vpx_integer.h"
  14. #include "vpx_ports/mem.h"
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #define VPXMIN(x, y) (((x) < (y)) ? (x) : (y))
  19. #define VPXMAX(x, y) (((x) > (y)) ? (x) : (y))
  20. #define VPX_SWAP(type, a, b) \
  21. do { \
  22. type c = (b); \
  23. (b) = a; \
  24. (a) = c; \
  25. } while (0)
  26. #if CONFIG_VP9_HIGHBITDEPTH
  27. // Note:
  28. // tran_low_t is the datatype used for final transform coefficients.
  29. // tran_high_t is the datatype used for intermediate transform stages.
  30. typedef int64_t tran_high_t;
  31. typedef int32_t tran_low_t;
  32. #else
  33. // Note:
  34. // tran_low_t is the datatype used for final transform coefficients.
  35. // tran_high_t is the datatype used for intermediate transform stages.
  36. typedef int32_t tran_high_t;
  37. typedef int16_t tran_low_t;
  38. #endif // CONFIG_VP9_HIGHBITDEPTH
  39. typedef int16_t tran_coef_t;
  40. static INLINE uint8_t clip_pixel(int val) {
  41. return (val > 255) ? 255 : (val < 0) ? 0 : val;
  42. }
  43. static INLINE int clamp(int value, int low, int high) {
  44. return value < low ? low : (value > high ? high : value);
  45. }
  46. static INLINE double fclamp(double value, double low, double high) {
  47. return value < low ? low : (value > high ? high : value);
  48. }
  49. static INLINE int64_t lclamp(int64_t value, int64_t low, int64_t high) {
  50. return value < low ? low : (value > high ? high : value);
  51. }
  52. static INLINE uint16_t clip_pixel_highbd(int val, int bd) {
  53. switch (bd) {
  54. case 8:
  55. default: return (uint16_t)clamp(val, 0, 255);
  56. case 10: return (uint16_t)clamp(val, 0, 1023);
  57. case 12: return (uint16_t)clamp(val, 0, 4095);
  58. }
  59. }
  60. #ifdef __cplusplus
  61. } // extern "C"
  62. #endif
  63. #endif // VPX_VPX_DSP_VPX_DSP_COMMON_H_