vf_hflip.c 2.4 KB

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