vf_eq.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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/avfilter.h"
  21. #include "libavfilter/vf_eq.h"
  22. #include "libavutil/intreadwrite.h"
  23. #include "libavutil/mem_internal.h"
  24. #define WIDTH 256
  25. #define HEIGHT 256
  26. #define SRC_STRIDE 256
  27. #define PIXELS (WIDTH * HEIGHT)
  28. #define RANDOM_RANGE 80000
  29. #define SCALE 10000
  30. #define randomize_buffers(buf, size) \
  31. do { \
  32. int j; \
  33. uint8_t *tmp_buf = (uint8_t *)buf;\
  34. for (j = 0; j< size; j++) \
  35. tmp_buf[j] = rnd() & 0xFF; \
  36. } while (0)
  37. static void check_eq(void)
  38. {
  39. LOCAL_ALIGNED_32(uint8_t, src, [PIXELS]);
  40. LOCAL_ALIGNED_32(uint8_t, dst_ref, [PIXELS]);
  41. LOCAL_ALIGNED_32(uint8_t, dst_new, [PIXELS]);
  42. int w = WIDTH;
  43. int h = HEIGHT;
  44. int src_stride = SRC_STRIDE;
  45. int dst_stride = SRC_STRIDE;
  46. EQParameters pa;
  47. EQContext eq;
  48. declare_func(void, EQParameters *param, uint8_t *dst, int dst_stride,
  49. const uint8_t *src, int src_stride, int w, int h);
  50. double rand_contrast = (int)(rnd() % (RANDOM_RANGE * 2) - RANDOM_RANGE) /
  51. (SCALE * 1.0);
  52. double rand_brightness = (int)(rnd() % (SCALE * 2) - SCALE) /
  53. (SCALE * 1.0);
  54. pa.contrast = rand_contrast;
  55. pa.brightness = rand_brightness;
  56. memset(dst_ref, 0, PIXELS);
  57. memset(dst_new, 0, PIXELS);
  58. randomize_buffers(src, PIXELS);
  59. ff_eq_init(&eq);
  60. if (check_func(eq.process, "process")) {
  61. call_ref(&pa, dst_ref, dst_stride, src, src_stride, w, h);
  62. call_new(&pa, dst_new, dst_stride, src, src_stride, w, h);
  63. if (memcmp(dst_ref, dst_new, PIXELS))
  64. fail();
  65. bench_new(&pa, dst_new, dst_stride, src, src_stride, w, h);
  66. }
  67. }
  68. void checkasm_check_vf_eq(void)
  69. {
  70. check_eq();
  71. report("eq");
  72. }