vf_convolution.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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/convolution.h"
  22. #include "libavutil/intreadwrite.h"
  23. #include "libavutil/mem_internal.h"
  24. #define WIDTH 512
  25. #define HEIGHT 512
  26. #define SRC_STRIDE 512
  27. #define PIXELS (WIDTH * HEIGHT)
  28. #define randomize_buffers(buf, size) \
  29. do { \
  30. int j; \
  31. uint8_t *tmp_buf = (uint8_t *)buf;\
  32. for (j = 0; j< size; j++) \
  33. tmp_buf[j] = rnd() & 0xFF; \
  34. } while (0)
  35. static void check_sobel(const char * report_name)
  36. {
  37. LOCAL_ALIGNED_32(uint8_t, src, [PIXELS]);
  38. LOCAL_ALIGNED_32(uint8_t, dst_ref, [PIXELS]);
  39. LOCAL_ALIGNED_32(uint8_t, dst_new, [PIXELS]);
  40. const int height = WIDTH;
  41. const int width = HEIGHT;
  42. const int stride = SRC_STRIDE;
  43. const int dstride = SRC_STRIDE;
  44. int mode = 0;
  45. const uint8_t *c[49];
  46. const int radius = 1;
  47. const int bpc = 1;
  48. const int step = mode == MATRIX_COLUMN ? 16 : 1;
  49. const int slice_start = 0;
  50. const int slice_end = height;
  51. int y;
  52. const int sizew = mode == MATRIX_COLUMN ? height : width;
  53. float scale = 2;
  54. float delta = 10;
  55. ConvolutionContext s;
  56. declare_func(void, uint8_t *dst, int width, float scale, float delta, const int *const matrix,
  57. const uint8_t *c[], int peak, int radius, int dstride, int stride, int size);
  58. s.scale = scale;
  59. s.delta = delta;
  60. s.depth = 8;
  61. s.nb_planes = 3;
  62. s.planes = 15;
  63. ff_sobel_init(&s, s.depth, s.nb_planes);
  64. memset(dst_ref, 0, PIXELS);
  65. memset(dst_new, 0, PIXELS);
  66. randomize_buffers(src, PIXELS);
  67. if (check_func(s.filter[0], "%s", report_name)) {
  68. for (y = slice_start; y < slice_end; y += step) {
  69. const int xoff = mode == MATRIX_COLUMN ? (y - slice_start) * bpc : radius * bpc;
  70. const int yoff = mode == MATRIX_COLUMN ? radius * dstride : 0;
  71. s.setup[0](radius, c, src, stride, radius, width, y, height, bpc);
  72. call_ref(dst_ref + yoff + xoff, sizew - 2 * radius,
  73. scale, delta, NULL, c, 0, radius,
  74. dstride, stride, slice_end - step);
  75. call_new(dst_new + yoff + xoff, sizew - 2 * radius,
  76. scale, delta, NULL, c, 0, radius,
  77. dstride, stride, slice_end - step);
  78. if (memcmp(dst_ref + yoff + xoff, dst_new + yoff + xoff, slice_end - step))
  79. fail();
  80. bench_new(dst_new + yoff + xoff, sizew - 2 * radius,
  81. scale, delta, NULL, c, 0, radius,
  82. dstride, stride, slice_end - step);
  83. if (mode != MATRIX_COLUMN)
  84. dst_ref += dstride;
  85. }
  86. }
  87. }
  88. void checkasm_check_vf_sobel(void)
  89. {
  90. check_sobel("sobel");
  91. report("convolution:sobel");
  92. }