vpx_dsp_common.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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_DSP_VPX_DSP_COMMON_H_
  11. #define 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 uint16_t clip_pixel_highbd(int val, int bd) {
  50. switch (bd) {
  51. case 8:
  52. default: return (uint16_t)clamp(val, 0, 255);
  53. case 10: return (uint16_t)clamp(val, 0, 1023);
  54. case 12: return (uint16_t)clamp(val, 0, 4095);
  55. }
  56. }
  57. #ifdef __cplusplus
  58. } // extern "C"
  59. #endif
  60. #endif // VPX_DSP_VPX_DSP_COMMON_H_