vpx_dsp_common.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #if CONFIG_VP9_HIGHBITDEPTH
  21. // Note:
  22. // tran_low_t is the datatype used for final transform coefficients.
  23. // tran_high_t is the datatype used for intermediate transform stages.
  24. typedef int64_t tran_high_t;
  25. typedef int32_t tran_low_t;
  26. #else
  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 int32_t tran_high_t;
  31. typedef int16_t tran_low_t;
  32. #endif // CONFIG_VP9_HIGHBITDEPTH
  33. static INLINE uint8_t clip_pixel(int val) {
  34. return (val > 255) ? 255 : (val < 0) ? 0 : val;
  35. }
  36. static INLINE int clamp(int value, int low, int high) {
  37. return value < low ? low : (value > high ? high : value);
  38. }
  39. static INLINE double fclamp(double value, double low, double high) {
  40. return value < low ? low : (value > high ? high : value);
  41. }
  42. #if CONFIG_VP9_HIGHBITDEPTH
  43. static INLINE uint16_t clip_pixel_highbd(int val, int bd) {
  44. switch (bd) {
  45. case 8:
  46. default:
  47. return (uint16_t)clamp(val, 0, 255);
  48. case 10:
  49. return (uint16_t)clamp(val, 0, 1023);
  50. case 12:
  51. return (uint16_t)clamp(val, 0, 4095);
  52. }
  53. }
  54. #endif // CONFIG_VP9_HIGHBITDEPTH
  55. #ifdef __cplusplus
  56. } // extern "C"
  57. #endif
  58. #endif // VPX_DSP_VPX_DSP_COMMON_H_