vf_threshold.c 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 "libavfilter/vf_threshold_init.h"
  21. #include "libavutil/intreadwrite.h"
  22. #include "libavutil/mem_internal.h"
  23. #define WIDTH 256
  24. #define WIDTH_PADDED 256 + 32
  25. #define randomize_buffers(buf, size) \
  26. do { \
  27. int j; \
  28. uint8_t *tmp_buf = (uint8_t *)buf;\
  29. for (j = 0; j < size; j++) \
  30. tmp_buf[j] = rnd() & 0xFF; \
  31. } while (0)
  32. static void check_threshold(int depth){
  33. LOCAL_ALIGNED_32(uint8_t, in , [WIDTH_PADDED]);
  34. LOCAL_ALIGNED_32(uint8_t, threshold, [WIDTH_PADDED]);
  35. LOCAL_ALIGNED_32(uint8_t, min , [WIDTH_PADDED]);
  36. LOCAL_ALIGNED_32(uint8_t, max , [WIDTH_PADDED]);
  37. LOCAL_ALIGNED_32(uint8_t, out_ref , [WIDTH_PADDED]);
  38. LOCAL_ALIGNED_32(uint8_t, out_new , [WIDTH_PADDED]);
  39. ptrdiff_t line_size = WIDTH_PADDED;
  40. int w = WIDTH;
  41. declare_func(void, const uint8_t *in, const uint8_t *threshold,
  42. const uint8_t *min, const uint8_t *max, uint8_t *out,
  43. ptrdiff_t ilinesize, ptrdiff_t tlinesize,
  44. ptrdiff_t flinesize, ptrdiff_t slinesize,
  45. ptrdiff_t olinesize, int w, int h);
  46. ThresholdContext s;
  47. s.depth = depth;
  48. ff_threshold_init(&s);
  49. memset(in, 0, WIDTH_PADDED);
  50. memset(threshold, 0, WIDTH_PADDED);
  51. memset(min, 0, WIDTH_PADDED);
  52. memset(max, 0, WIDTH_PADDED);
  53. memset(out_ref, 0, WIDTH_PADDED);
  54. memset(out_new, 0, WIDTH_PADDED);
  55. randomize_buffers(in, WIDTH);
  56. randomize_buffers(threshold, WIDTH);
  57. randomize_buffers(min, WIDTH);
  58. randomize_buffers(max, WIDTH);
  59. if (depth == 16)
  60. w /= 2;
  61. if (check_func(s.threshold, "threshold%d", depth)) {
  62. call_ref(in, threshold, min, max, out_ref, line_size, line_size, line_size, line_size, line_size, w, 1);
  63. call_new(in, threshold, min, max, out_new, line_size, line_size, line_size, line_size, line_size, w, 1);
  64. if (memcmp(out_ref, out_new, WIDTH))
  65. fail();
  66. bench_new(in, threshold, min, max, out_new, line_size, line_size, line_size, line_size, line_size, w, 1);
  67. }
  68. }
  69. void checkasm_check_vf_threshold(void)
  70. {
  71. check_threshold(8);
  72. report("threshold8");
  73. check_threshold(16);
  74. report("threshold16");
  75. }