jpeg2000dsp.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (c) 2015 James Almer
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (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
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. #include "checkasm.h"
  21. #include "libavcodec/jpeg2000dsp.h"
  22. #include "libavutil/common.h"
  23. #include "libavutil/internal.h"
  24. #include "libavutil/intreadwrite.h"
  25. #include "libavutil/mem_internal.h"
  26. #define BUF_SIZE 512
  27. #define randomize_buffers() \
  28. do { \
  29. int i; \
  30. for (i = 0; i < BUF_SIZE*3; i++) \
  31. src[i] = rnd(); \
  32. } while (0)
  33. #define randomize_buffers_float() \
  34. do { \
  35. int i; \
  36. for (i = 0; i < BUF_SIZE*3; i++) \
  37. src[i] = (float)rnd() / (UINT_MAX >> 5); \
  38. } while (0)
  39. static void check_rct_int(void)
  40. {
  41. LOCAL_ALIGNED_32(int32_t, src, [BUF_SIZE*3]);
  42. LOCAL_ALIGNED_32(int32_t, ref, [BUF_SIZE*3]);
  43. LOCAL_ALIGNED_32(int32_t, new, [BUF_SIZE*3]);
  44. int32_t *ref0 = &ref[BUF_SIZE*0], *new0 = &new[BUF_SIZE*0];
  45. int32_t *ref1 = &ref[BUF_SIZE*1], *new1 = &new[BUF_SIZE*1];
  46. int32_t *ref2 = &ref[BUF_SIZE*2], *new2 = &new[BUF_SIZE*2];
  47. declare_func(void, void *src0, void *src1, void *src2, int csize);
  48. randomize_buffers();
  49. memcpy(ref, src, BUF_SIZE * 3 * sizeof(*src));
  50. memcpy(new, src, BUF_SIZE * 3 * sizeof(*src));
  51. call_ref(ref0, ref1, ref2, BUF_SIZE);
  52. call_new(new0, new1, new2, BUF_SIZE);
  53. if (memcmp(ref0, new0, BUF_SIZE * sizeof(*src)) ||
  54. memcmp(ref1, new1, BUF_SIZE * sizeof(*src)) ||
  55. memcmp(ref2, new2, BUF_SIZE * sizeof(*src)))
  56. fail();
  57. memcpy(new, src, BUF_SIZE * 3 * sizeof(*src));
  58. bench_new(new0, new1, new2, BUF_SIZE);
  59. }
  60. static void check_ict_float(void)
  61. {
  62. LOCAL_ALIGNED_32(float, src, [BUF_SIZE*3]);
  63. LOCAL_ALIGNED_32(float, ref, [BUF_SIZE*3]);
  64. LOCAL_ALIGNED_32(float, new, [BUF_SIZE*3]);
  65. float *ref0 = &ref[BUF_SIZE*0], *new0 = &new[BUF_SIZE*0];
  66. float *ref1 = &ref[BUF_SIZE*1], *new1 = &new[BUF_SIZE*1];
  67. float *ref2 = &ref[BUF_SIZE*2], *new2 = &new[BUF_SIZE*2];
  68. declare_func(void, void *src0, void *src1, void *src2, int csize);
  69. randomize_buffers_float();
  70. memcpy(ref, src, BUF_SIZE * 3 * sizeof(*src));
  71. memcpy(new, src, BUF_SIZE * 3 * sizeof(*src));
  72. call_ref(ref0, ref1, ref2, BUF_SIZE);
  73. call_new(new0, new1, new2, BUF_SIZE);
  74. if (!float_near_abs_eps_array(ref0, new0, 1.0e-5, BUF_SIZE) ||
  75. !float_near_abs_eps_array(ref1, new1, 1.0e-5, BUF_SIZE) ||
  76. !float_near_abs_eps_array(ref2, new2, 1.0e-5, BUF_SIZE))
  77. fail();
  78. memcpy(new, src, BUF_SIZE * 3 * sizeof(*src));
  79. bench_new(new0, new1, new2, BUF_SIZE);
  80. }
  81. void checkasm_check_jpeg2000dsp(void)
  82. {
  83. Jpeg2000DSPContext h;
  84. ff_jpeg2000dsp_init(&h);
  85. if (check_func(h.mct_decode[FF_DWT53], "jpeg2000_rct_int"))
  86. check_rct_int();
  87. if (check_func(h.mct_decode[FF_DWT97], "jpeg2000_ict_float"))
  88. check_ict_float();
  89. report("mct_decode");
  90. }