vf_gblur.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 <float.h>
  19. #include <string.h>
  20. #include "checkasm.h"
  21. #include "libavutil/mem.h"
  22. #include "libavfilter/vf_gblur_init.h"
  23. #define WIDTH 256
  24. #define HEIGHT 256
  25. #define PIXELS (WIDTH * HEIGHT)
  26. #define BUF_SIZE (PIXELS * 4)
  27. #define randomize_buffers(buf, size) \
  28. do { \
  29. int j; \
  30. float *tmp_buf = (float *)buf; \
  31. for (j = 0; j < size; j++) \
  32. tmp_buf[j] = (float)(rnd() & 0xFF); \
  33. } while (0)
  34. static void check_horiz_slice(float *dst_ref, float *dst_new, float *localbuf)
  35. {
  36. int steps = 2;
  37. float nu = 0.101f;
  38. float bscale = 1.112f;
  39. declare_func(void, float *dst, int w, int h, int steps, float nu, float bscale, float *localbuf);
  40. call_ref(dst_ref, WIDTH, HEIGHT, steps, nu, bscale, localbuf);
  41. call_new(dst_new, WIDTH, HEIGHT, steps, nu, bscale, localbuf);
  42. if (!float_near_abs_eps_array(dst_ref, dst_new, 0.01f, PIXELS)) {
  43. fail();
  44. }
  45. bench_new(dst_new, WIDTH, HEIGHT, 1, nu, bscale, localbuf);
  46. }
  47. static void check_verti_slice(float *dst_ref, float *dst_new)
  48. {
  49. int steps = 2;
  50. float nu = 0.101f;
  51. float bscale = 1.112f;
  52. declare_func(void, float *buffer, int width, int height, int column_begin,
  53. int column_end, int steps, float nu, float bscale);
  54. call_ref(dst_ref, WIDTH, HEIGHT, 0, WIDTH, steps, nu, bscale);
  55. call_new(dst_new, WIDTH, HEIGHT, 0, WIDTH, steps, nu, bscale);
  56. if (!float_near_abs_eps_array(dst_ref, dst_new, 0.01f, PIXELS)) {
  57. fail();
  58. }
  59. bench_new(dst_new, WIDTH, HEIGHT, 0, WIDTH, 1, nu, bscale);
  60. }
  61. static void check_postscale_slice(float *dst_ref, float *dst_new)
  62. {
  63. float postscale = 0.0603f;
  64. declare_func(void, float *dst, int len, float postscale, float min, float max);
  65. call_ref(dst_ref, PIXELS, postscale, -FLT_MAX, FLT_MAX);
  66. call_new(dst_new, PIXELS, postscale, -FLT_MAX, FLT_MAX);
  67. if (!float_near_abs_eps_array(dst_ref, dst_new, FLT_EPSILON, PIXELS)) {
  68. fail();
  69. }
  70. bench_new(dst_new, PIXELS, postscale, -FLT_MAX, FLT_MAX);
  71. }
  72. void checkasm_check_vf_gblur(void)
  73. {
  74. float *dst_ref = av_malloc(BUF_SIZE);
  75. float *dst_new = av_malloc(BUF_SIZE);
  76. GBlurContext s;
  77. randomize_buffers(dst_ref, PIXELS);
  78. memcpy(dst_new, dst_ref, BUF_SIZE);
  79. s.planewidth[0] = WIDTH;
  80. s.planeheight[0] = HEIGHT;
  81. ff_gblur_init(&s);
  82. if (check_func(s.horiz_slice, "horiz_slice")) {
  83. check_horiz_slice(dst_ref, dst_new, s.localbuf);
  84. }
  85. report("horiz_slice");
  86. randomize_buffers(dst_ref, PIXELS);
  87. memcpy(dst_new, dst_ref, BUF_SIZE);
  88. if (check_func(s.postscale_slice, "postscale_slice")) {
  89. check_postscale_slice(dst_ref, dst_new);
  90. }
  91. report("postscale_slice");
  92. randomize_buffers(dst_ref, PIXELS);
  93. memcpy(dst_new, dst_ref, BUF_SIZE);
  94. if (check_func(s.verti_slice, "verti_slice")) {
  95. check_verti_slice(dst_ref, dst_new);
  96. }
  97. report("verti_slice");
  98. if (s.localbuf)
  99. av_free(s.localbuf);
  100. av_freep(&dst_ref);
  101. av_freep(&dst_new);
  102. }