dcamath.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (C) 2016 foo86
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVCODEC_DCAMATH_H
  21. #define AVCODEC_DCAMATH_H
  22. #include "libavutil/common.h"
  23. #include "libavutil/intmath.h"
  24. static inline int32_t norm__(int64_t a, int bits)
  25. {
  26. if (bits > 0)
  27. return (int32_t)((a + (INT64_C(1) << (bits - 1))) >> bits);
  28. else
  29. return (int32_t)a;
  30. }
  31. static inline int32_t mul__(int32_t a, int32_t b, int bits)
  32. {
  33. return norm__((int64_t)a * b, bits);
  34. }
  35. static inline int32_t norm13(int64_t a) { return norm__(a, 13); }
  36. static inline int32_t norm16(int64_t a) { return norm__(a, 16); }
  37. static inline int32_t norm20(int64_t a) { return norm__(a, 20); }
  38. static inline int32_t norm21(int64_t a) { return norm__(a, 21); }
  39. static inline int32_t norm23(int64_t a) { return norm__(a, 23); }
  40. static inline int32_t mul15(int32_t a, int32_t b) { return mul__(a, b, 15); }
  41. static inline int32_t mul16(int32_t a, int32_t b) { return mul__(a, b, 16); }
  42. static inline int32_t mul17(int32_t a, int32_t b) { return mul__(a, b, 17); }
  43. static inline int32_t mul22(int32_t a, int32_t b) { return mul__(a, b, 22); }
  44. static inline int32_t mul23(int32_t a, int32_t b) { return mul__(a, b, 23); }
  45. static inline int32_t mul31(int32_t a, int32_t b) { return mul__(a, b, 31); }
  46. static inline int32_t mul32(int32_t a, int32_t b) { return mul__(a, b, 32); }
  47. static inline int32_t clip23(int32_t a) { return av_clip_intp2(a, 23); }
  48. #endif