vf_blend.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright (c) 2016 Tiancheng "Timothy" Gu
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. #include <string.h>
  21. #include "checkasm.h"
  22. #include "libavfilter/vf_blend_init.h"
  23. #include "libavutil/common.h"
  24. #include "libavutil/internal.h"
  25. #include "libavutil/intreadwrite.h"
  26. #include "libavutil/mem.h"
  27. #define WIDTH 256
  28. #define HEIGHT 256
  29. #define BUF_UNITS 3
  30. #define SIZE_PER_UNIT (WIDTH * HEIGHT)
  31. #define BUF_SIZE (BUF_UNITS * SIZE_PER_UNIT)
  32. #define randomize_buffers() \
  33. do { \
  34. int i, j; \
  35. for (i = 0; i < HEIGHT; i++) { \
  36. for (j = 0; j < WIDTH; j++) { \
  37. top1[i * WIDTH + j] = \
  38. top2[i * WIDTH + j] = i; \
  39. bot1[i * WIDTH + j] = \
  40. bot2[i * WIDTH + j] = j; \
  41. } \
  42. } \
  43. for (i = 0; i < SIZE_PER_UNIT; i += 4) { \
  44. uint32_t r = rnd(); \
  45. AV_WN32A(dst1 + i, r); \
  46. AV_WN32A(dst2 + i, r); \
  47. } \
  48. for (; i < BUF_SIZE; i += 4) { \
  49. uint32_t r = rnd(); \
  50. AV_WN32A(top1 + i, r); \
  51. AV_WN32A(top2 + i, r); \
  52. r = rnd(); \
  53. AV_WN32A(bot1 + i, r); \
  54. AV_WN32A(bot2 + i, r); \
  55. r = rnd(); \
  56. AV_WN32A(dst1 + i, r); \
  57. AV_WN32A(dst2 + i, r); \
  58. } \
  59. } while (0)
  60. #define check_blend_func(depth) \
  61. do { \
  62. int i, w; \
  63. declare_func(void, const uint8_t *top, ptrdiff_t top_linesize, \
  64. const uint8_t *bottom, ptrdiff_t bottom_linesize, \
  65. uint8_t *dst, ptrdiff_t dst_linesize, \
  66. ptrdiff_t width, ptrdiff_t height, \
  67. struct FilterParams *param, struct SliceParams *sliceparam); \
  68. w = WIDTH / depth; \
  69. \
  70. for (i = 0; i < BUF_UNITS - 1; i++) { \
  71. int src_offset = i * SIZE_PER_UNIT + (BUF_UNITS - 1 - i) * depth; /* Test various alignments */ \
  72. int dst_offset = i * SIZE_PER_UNIT; /* dst must be aligned */ \
  73. randomize_buffers(); \
  74. call_ref(top1 + src_offset, w, bot1 + src_offset, w, \
  75. dst1 + dst_offset, w, w, HEIGHT, &param, NULL); \
  76. call_new(top2 + src_offset, w, bot2 + src_offset, w, \
  77. dst2 + dst_offset, w, w, HEIGHT, &param, NULL); \
  78. if (memcmp(top1, top2, BUF_SIZE) || memcmp(bot1, bot2, BUF_SIZE) || memcmp(dst1, dst2, BUF_SIZE)) \
  79. fail(); \
  80. } \
  81. bench_new(top2, w / 4, bot2, w / 4, dst2, w / 4, \
  82. w / 4, HEIGHT / 4, &param, NULL); \
  83. } while (0)
  84. void checkasm_check_blend(void)
  85. {
  86. uint8_t *top1 = av_malloc(BUF_SIZE);
  87. uint8_t *top2 = av_malloc(BUF_SIZE);
  88. uint8_t *bot1 = av_malloc(BUF_SIZE);
  89. uint8_t *bot2 = av_malloc(BUF_SIZE);
  90. uint8_t *dst1 = av_malloc(BUF_SIZE);
  91. uint8_t *dst2 = av_malloc(BUF_SIZE);
  92. FilterParams param = {
  93. .opacity = 1.0,
  94. };
  95. #define check_and_report(name, val, depth) \
  96. param.mode = val; \
  97. ff_blend_init(&param, depth * 8); \
  98. if (check_func(param.blend, #name)) \
  99. check_blend_func(depth);
  100. check_and_report(addition, BLEND_ADDITION, 1)
  101. check_and_report(grainmerge, BLEND_GRAINMERGE, 1)
  102. check_and_report(and, BLEND_AND, 1)
  103. check_and_report(average, BLEND_AVERAGE, 1)
  104. check_and_report(darken, BLEND_DARKEN, 1)
  105. check_and_report(grainextract, BLEND_GRAINEXTRACT, 1)
  106. check_and_report(hardmix, BLEND_HARDMIX, 1)
  107. check_and_report(lighten, BLEND_LIGHTEN, 1)
  108. check_and_report(multiply, BLEND_MULTIPLY, 1)
  109. check_and_report(or, BLEND_OR, 1)
  110. check_and_report(phoenix, BLEND_PHOENIX, 1)
  111. check_and_report(screen, BLEND_SCREEN, 1)
  112. check_and_report(subtract, BLEND_SUBTRACT, 1)
  113. check_and_report(xor, BLEND_XOR, 1)
  114. check_and_report(difference, BLEND_DIFFERENCE, 1)
  115. check_and_report(extremity, BLEND_EXTREMITY, 1)
  116. check_and_report(negation, BLEND_NEGATION, 1)
  117. report("8bit");
  118. check_and_report(addition_16, BLEND_ADDITION, 2)
  119. check_and_report(grainmerge_16, BLEND_GRAINMERGE, 2)
  120. check_and_report(and_16, BLEND_AND, 2)
  121. check_and_report(average_16, BLEND_AVERAGE, 2)
  122. check_and_report(darken_16, BLEND_DARKEN, 2)
  123. check_and_report(grainextract_16, BLEND_GRAINEXTRACT, 2)
  124. check_and_report(difference_16, BLEND_DIFFERENCE, 2)
  125. check_and_report(extremity_16, BLEND_EXTREMITY, 2)
  126. check_and_report(negation_16, BLEND_NEGATION, 2)
  127. check_and_report(lighten_16, BLEND_LIGHTEN, 2)
  128. check_and_report(or_16, BLEND_OR, 2)
  129. check_and_report(phoenix_16, BLEND_PHOENIX, 2)
  130. check_and_report(subtract_16, BLEND_SUBTRACT, 2)
  131. check_and_report(xor_16, BLEND_SUBTRACT, 2)
  132. report("16bit");
  133. av_freep(&top1);
  134. av_freep(&top2);
  135. av_freep(&bot1);
  136. av_freep(&bot2);
  137. av_freep(&dst1);
  138. av_freep(&dst2);
  139. }