vf_hflip.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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/hflip.h"
  21. #include "libavutil/intreadwrite.h"
  22. #define WIDTH 256
  23. #define WIDTH_PADDED 256 + 32
  24. #define randomize_buffers(buf, size) \
  25. do { \
  26. int j; \
  27. uint8_t *tmp_buf = (uint8_t *)buf;\
  28. for (j = 0; j < size; j++) \
  29. tmp_buf[j] = rnd() & 0xFF; \
  30. } while (0)
  31. static void check_hflip(int step, const char * report_name){
  32. LOCAL_ALIGNED_32(uint8_t, src, [WIDTH_PADDED]);
  33. LOCAL_ALIGNED_32(uint8_t, dst_ref, [WIDTH_PADDED]);
  34. LOCAL_ALIGNED_32(uint8_t, dst_new, [WIDTH_PADDED]);
  35. int w = WIDTH;
  36. int i;
  37. int step_array[4] = {1, 1, 1, 1};
  38. FlipContext s;
  39. declare_func(void, const uint8_t *src, uint8_t *dst, int w);
  40. memset(src, 0, WIDTH_PADDED);
  41. memset(dst_ref, 0, WIDTH_PADDED);
  42. memset(dst_new, 0, WIDTH_PADDED);
  43. randomize_buffers(src, WIDTH_PADDED);
  44. if (step == 2) {
  45. w /= 2;
  46. for (i = 0; i < 4; i++)
  47. step_array[i] = step;
  48. }
  49. ff_hflip_init(&s, step_array, 4);
  50. if (check_func(s.flip_line[0], "hflip_%s", report_name)) {
  51. for (i = 1; i < w; i++) {
  52. call_ref(src + (w - 1) * step, dst_ref, i);
  53. call_new(src + (w - 1) * step, dst_new, i);
  54. if (memcmp(dst_ref, dst_new, i * step))
  55. fail();
  56. }
  57. bench_new(src + (w - 1) * step, dst_new, w);
  58. }
  59. }
  60. void checkasm_check_vf_hflip(void)
  61. {
  62. check_hflip(1, "byte");
  63. report("hflip_byte");
  64. check_hflip(2, "short");
  65. report("hflip_short");
  66. }