vf_gblur.c 3.8 KB

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