fdctdsp.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #include <string.h>
  19. #include "checkasm.h"
  20. #include "libavcodec/avcodec.h"
  21. #include "libavcodec/fdctdsp.h"
  22. #include "libavutil/common.h"
  23. #include "libavutil/internal.h"
  24. #include "libavutil/mem_internal.h"
  25. static int int16_cmp_off_by_n(const int16_t *ref, const int16_t *test, size_t n, int accuracy)
  26. {
  27. for (size_t i = 0; i < n; i++) {
  28. if (abs(ref[i] - test[i]) > accuracy)
  29. return 1;
  30. }
  31. return 0;
  32. }
  33. static void check_fdct(void)
  34. {
  35. LOCAL_ALIGNED_16(int16_t, block0, [64]);
  36. LOCAL_ALIGNED_16(int16_t, block1, [64]);
  37. AVCodecContext avctx = {
  38. .bits_per_raw_sample = 8,
  39. .dct_algo = FF_DCT_AUTO,
  40. };
  41. FDCTDSPContext h;
  42. ff_fdctdsp_init(&h, &avctx);
  43. if (check_func(h.fdct, "fdct")) {
  44. declare_func(void, int16_t *);
  45. for (int i = 0; i < 64; i++) {
  46. uint8_t r = rnd();
  47. block0[i] = r;
  48. block1[i] = r;
  49. }
  50. call_ref(block0);
  51. call_new(block1);
  52. if (int16_cmp_off_by_n(block0, block1, 64, 2))
  53. fail();
  54. bench_new(block1);
  55. }
  56. }
  57. void checkasm_check_fdctdsp(void)
  58. {
  59. check_fdct();
  60. report("fdctdsp");
  61. }