You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1010 lines
37KB

  1. /*
  2. * Copyright (c) 2012-2013 Oka Motofumi (chikuzen.mo at gmail dot com)
  3. * Copyright (c) 2015 Paul B Mahol
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libavutil/avstring.h"
  22. #include "libavutil/imgutils.h"
  23. #include "libavutil/intreadwrite.h"
  24. #include "libavutil/opt.h"
  25. #include "libavutil/pixdesc.h"
  26. #include "avfilter.h"
  27. #include "convolution.h"
  28. #include "formats.h"
  29. #include "internal.h"
  30. #include "video.h"
  31. #define OFFSET(x) offsetof(ConvolutionContext, x)
  32. #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
  33. static const AVOption convolution_options[] = {
  34. { "0m", "set matrix for 1st plane", OFFSET(matrix_str[0]), AV_OPT_TYPE_STRING, {.str="0 0 0 0 1 0 0 0 0"}, 0, 0, FLAGS },
  35. { "1m", "set matrix for 2nd plane", OFFSET(matrix_str[1]), AV_OPT_TYPE_STRING, {.str="0 0 0 0 1 0 0 0 0"}, 0, 0, FLAGS },
  36. { "2m", "set matrix for 3rd plane", OFFSET(matrix_str[2]), AV_OPT_TYPE_STRING, {.str="0 0 0 0 1 0 0 0 0"}, 0, 0, FLAGS },
  37. { "3m", "set matrix for 4th plane", OFFSET(matrix_str[3]), AV_OPT_TYPE_STRING, {.str="0 0 0 0 1 0 0 0 0"}, 0, 0, FLAGS },
  38. { "0rdiv", "set rdiv for 1st plane", OFFSET(rdiv[0]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
  39. { "1rdiv", "set rdiv for 2nd plane", OFFSET(rdiv[1]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
  40. { "2rdiv", "set rdiv for 3rd plane", OFFSET(rdiv[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
  41. { "3rdiv", "set rdiv for 4th plane", OFFSET(rdiv[3]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
  42. { "0bias", "set bias for 1st plane", OFFSET(bias[0]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
  43. { "1bias", "set bias for 2nd plane", OFFSET(bias[1]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
  44. { "2bias", "set bias for 3rd plane", OFFSET(bias[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
  45. { "3bias", "set bias for 4th plane", OFFSET(bias[3]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
  46. { "0mode", "set matrix mode for 1st plane", OFFSET(mode[0]), AV_OPT_TYPE_INT, {.i64=MATRIX_SQUARE}, 0, MATRIX_NBMODES-1, FLAGS, "mode" },
  47. { "1mode", "set matrix mode for 2nd plane", OFFSET(mode[1]), AV_OPT_TYPE_INT, {.i64=MATRIX_SQUARE}, 0, MATRIX_NBMODES-1, FLAGS, "mode" },
  48. { "2mode", "set matrix mode for 3rd plane", OFFSET(mode[2]), AV_OPT_TYPE_INT, {.i64=MATRIX_SQUARE}, 0, MATRIX_NBMODES-1, FLAGS, "mode" },
  49. { "3mode", "set matrix mode for 4th plane", OFFSET(mode[3]), AV_OPT_TYPE_INT, {.i64=MATRIX_SQUARE}, 0, MATRIX_NBMODES-1, FLAGS, "mode" },
  50. { "square", "square matrix", 0, AV_OPT_TYPE_CONST, {.i64=MATRIX_SQUARE}, 0, 0, FLAGS, "mode" },
  51. { "row", "single row matrix", 0, AV_OPT_TYPE_CONST, {.i64=MATRIX_ROW} , 0, 0, FLAGS, "mode" },
  52. { "column", "single column matrix", 0, AV_OPT_TYPE_CONST, {.i64=MATRIX_COLUMN}, 0, 0, FLAGS, "mode" },
  53. { NULL }
  54. };
  55. AVFILTER_DEFINE_CLASS(convolution);
  56. static const int same3x3[9] = {0, 0, 0,
  57. 0, 1, 0,
  58. 0, 0, 0};
  59. static const int same5x5[25] = {0, 0, 0, 0, 0,
  60. 0, 0, 0, 0, 0,
  61. 0, 0, 1, 0, 0,
  62. 0, 0, 0, 0, 0,
  63. 0, 0, 0, 0, 0};
  64. static const int same7x7[49] = {0, 0, 0, 0, 0, 0, 0,
  65. 0, 0, 0, 0, 0, 0, 0,
  66. 0, 0, 0, 0, 0, 0, 0,
  67. 0, 0, 0, 1, 0, 0, 0,
  68. 0, 0, 0, 0, 0, 0, 0,
  69. 0, 0, 0, 0, 0, 0, 0,
  70. 0, 0, 0, 0, 0, 0, 0};
  71. static int query_formats(AVFilterContext *ctx)
  72. {
  73. static const enum AVPixelFormat pix_fmts[] = {
  74. AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
  75. AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ440P,
  76. AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUV420P,
  77. AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ420P,
  78. AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P,
  79. AV_PIX_FMT_YUV420P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV444P9,
  80. AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10,
  81. AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV440P12,
  82. AV_PIX_FMT_YUV420P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV444P14,
  83. AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16,
  84. AV_PIX_FMT_YUVA420P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA444P9,
  85. AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA444P10,
  86. AV_PIX_FMT_YUVA422P12, AV_PIX_FMT_YUVA444P12,
  87. AV_PIX_FMT_YUVA420P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA444P16,
  88. AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10,
  89. AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,
  90. AV_PIX_FMT_GBRAP, AV_PIX_FMT_GBRAP10, AV_PIX_FMT_GBRAP12, AV_PIX_FMT_GBRAP16,
  91. AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY9, AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_GRAY16,
  92. AV_PIX_FMT_NONE
  93. };
  94. return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
  95. }
  96. typedef struct ThreadData {
  97. AVFrame *in, *out;
  98. } ThreadData;
  99. static void filter16_prewitt(uint8_t *dstp, int width,
  100. float scale, float delta, const int *const matrix,
  101. const uint8_t *c[], int peak, int radius,
  102. int dstride, int stride, int size)
  103. {
  104. uint16_t *dst = (uint16_t *)dstp;
  105. int x;
  106. for (x = 0; x < width; x++) {
  107. float suma = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[1][2 * x]) * -1 + AV_RN16A(&c[2][2 * x]) * -1 +
  108. AV_RN16A(&c[6][2 * x]) * 1 + AV_RN16A(&c[7][2 * x]) * 1 + AV_RN16A(&c[8][2 * x]) * 1;
  109. float sumb = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[2][2 * x]) * 1 + AV_RN16A(&c[3][2 * x]) * -1 +
  110. AV_RN16A(&c[5][2 * x]) * 1 + AV_RN16A(&c[6][2 * x]) * -1 + AV_RN16A(&c[8][2 * x]) * 1;
  111. dst[x] = av_clip(sqrtf(suma*suma + sumb*sumb) * scale + delta, 0, peak);
  112. }
  113. }
  114. static void filter16_roberts(uint8_t *dstp, int width,
  115. float scale, float delta, const int *const matrix,
  116. const uint8_t *c[], int peak, int radius,
  117. int dstride, int stride, int size)
  118. {
  119. uint16_t *dst = (uint16_t *)dstp;
  120. int x;
  121. for (x = 0; x < width; x++) {
  122. float suma = AV_RN16A(&c[0][2 * x]) * 1 + AV_RN16A(&c[1][2 * x]) * -1;
  123. float sumb = AV_RN16A(&c[4][2 * x]) * 1 + AV_RN16A(&c[3][2 * x]) * -1;
  124. dst[x] = av_clip(sqrtf(suma*suma + sumb*sumb) * scale + delta, 0, peak);
  125. }
  126. }
  127. static void filter16_sobel(uint8_t *dstp, int width,
  128. float scale, float delta, const int *const matrix,
  129. const uint8_t *c[], int peak, int radius,
  130. int dstride, int stride, int size)
  131. {
  132. uint16_t *dst = (uint16_t *)dstp;
  133. int x;
  134. for (x = 0; x < width; x++) {
  135. float suma = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[1][2 * x]) * -2 + AV_RN16A(&c[2][2 * x]) * -1 +
  136. AV_RN16A(&c[6][2 * x]) * 1 + AV_RN16A(&c[7][2 * x]) * 2 + AV_RN16A(&c[8][2 * x]) * 1;
  137. float sumb = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[2][2 * x]) * 1 + AV_RN16A(&c[3][2 * x]) * -2 +
  138. AV_RN16A(&c[5][2 * x]) * 2 + AV_RN16A(&c[6][2 * x]) * -1 + AV_RN16A(&c[8][2 * x]) * 1;
  139. dst[x] = av_clip(sqrtf(suma*suma + sumb*sumb) * scale + delta, 0, peak);
  140. }
  141. }
  142. static void filter16_kirsch(uint8_t *dstp, int width,
  143. float scale, float delta, const int *const matrix,
  144. const uint8_t *c[], int peak, int radius,
  145. int dstride, int stride, int size)
  146. {
  147. uint16_t *dst = (uint16_t *)dstp;
  148. const uint16_t *c0 = (const uint16_t *)c[0], *c1 = (const uint16_t *)c[1], *c2 = (const uint16_t *)c[2];
  149. const uint16_t *c3 = (const uint16_t *)c[3], *c5 = (const uint16_t *)c[5];
  150. const uint16_t *c6 = (const uint16_t *)c[6], *c7 = (const uint16_t *)c[7], *c8 = (const uint16_t *)c[8];
  151. int x;
  152. for (x = 0; x < width; x++) {
  153. int sum0 = c0[x] * 5 + c1[x] * 5 + c2[x] * 5 +
  154. c3[x] * -3 + c5[x] * -3 +
  155. c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
  156. int sum1 = c0[x] * -3 + c1[x] * 5 + c2[x] * 5 +
  157. c3[x] * 5 + c5[x] * -3 +
  158. c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
  159. int sum2 = c0[x] * -3 + c1[x] * -3 + c2[x] * 5 +
  160. c3[x] * 5 + c5[x] * 5 +
  161. c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
  162. int sum3 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
  163. c3[x] * 5 + c5[x] * 5 +
  164. c6[x] * 5 + c7[x] * -3 + c8[x] * -3;
  165. int sum4 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
  166. c3[x] * -3 + c5[x] * 5 +
  167. c6[x] * 5 + c7[x] * 5 + c8[x] * -3;
  168. int sum5 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
  169. c3[x] * -3 + c5[x] * -3 +
  170. c6[x] * 5 + c7[x] * 5 + c8[x] * 5;
  171. int sum6 = c0[x] * 5 + c1[x] * -3 + c2[x] * -3 +
  172. c3[x] * -3 + c5[x] * -3 +
  173. c6[x] * -3 + c7[x] * 5 + c8[x] * 5;
  174. int sum7 = c0[x] * 5 + c1[x] * 5 + c2[x] * -3 +
  175. c3[x] * -3 + c5[x] * -3 +
  176. c6[x] * -3 + c7[x] * -3 + c8[x] * 5;
  177. sum0 = FFMAX(sum0, sum1);
  178. sum2 = FFMAX(sum2, sum3);
  179. sum4 = FFMAX(sum4, sum5);
  180. sum6 = FFMAX(sum6, sum7);
  181. sum0 = FFMAX(sum0, sum2);
  182. sum4 = FFMAX(sum4, sum6);
  183. sum0 = FFMAX(sum0, sum4);
  184. dst[x] = av_clip(FFABS(sum0) * scale + delta, 0, peak);
  185. }
  186. }
  187. static void filter_prewitt(uint8_t *dst, int width,
  188. float scale, float delta, const int *const matrix,
  189. const uint8_t *c[], int peak, int radius,
  190. int dstride, int stride, int size)
  191. {
  192. const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2];
  193. const uint8_t *c3 = c[3], *c5 = c[5];
  194. const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8];
  195. int x;
  196. for (x = 0; x < width; x++) {
  197. float suma = c0[x] * -1 + c1[x] * -1 + c2[x] * -1 +
  198. c6[x] * 1 + c7[x] * 1 + c8[x] * 1;
  199. float sumb = c0[x] * -1 + c2[x] * 1 + c3[x] * -1 +
  200. c5[x] * 1 + c6[x] * -1 + c8[x] * 1;
  201. dst[x] = av_clip_uint8(sqrtf(suma*suma + sumb*sumb) * scale + delta);
  202. }
  203. }
  204. static void filter_roberts(uint8_t *dst, int width,
  205. float scale, float delta, const int *const matrix,
  206. const uint8_t *c[], int peak, int radius,
  207. int dstride, int stride, int size)
  208. {
  209. int x;
  210. for (x = 0; x < width; x++) {
  211. float suma = c[0][x] * 1 + c[1][x] * -1;
  212. float sumb = c[4][x] * 1 + c[3][x] * -1;
  213. dst[x] = av_clip_uint8(sqrtf(suma*suma + sumb*sumb) * scale + delta);
  214. }
  215. }
  216. static void filter_sobel(uint8_t *dst, int width,
  217. float scale, float delta, const int *const matrix,
  218. const uint8_t *c[], int peak, int radius,
  219. int dstride, int stride, int size)
  220. {
  221. const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2];
  222. const uint8_t *c3 = c[3], *c5 = c[5];
  223. const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8];
  224. int x;
  225. for (x = 0; x < width; x++) {
  226. float suma = c0[x] * -1 + c1[x] * -2 + c2[x] * -1 +
  227. c6[x] * 1 + c7[x] * 2 + c8[x] * 1;
  228. float sumb = c0[x] * -1 + c2[x] * 1 + c3[x] * -2 +
  229. c5[x] * 2 + c6[x] * -1 + c8[x] * 1;
  230. dst[x] = av_clip_uint8(sqrtf(suma*suma + sumb*sumb) * scale + delta);
  231. }
  232. }
  233. static void filter_kirsch(uint8_t *dst, int width,
  234. float scale, float delta, const int *const matrix,
  235. const uint8_t *c[], int peak, int radius,
  236. int dstride, int stride, int size)
  237. {
  238. const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2];
  239. const uint8_t *c3 = c[3], *c5 = c[5];
  240. const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8];
  241. int x;
  242. for (x = 0; x < width; x++) {
  243. int sum0 = c0[x] * 5 + c1[x] * 5 + c2[x] * 5 +
  244. c3[x] * -3 + c5[x] * -3 +
  245. c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
  246. int sum1 = c0[x] * -3 + c1[x] * 5 + c2[x] * 5 +
  247. c3[x] * 5 + c5[x] * -3 +
  248. c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
  249. int sum2 = c0[x] * -3 + c1[x] * -3 + c2[x] * 5 +
  250. c3[x] * 5 + c5[x] * 5 +
  251. c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
  252. int sum3 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
  253. c3[x] * 5 + c5[x] * 5 +
  254. c6[x] * 5 + c7[x] * -3 + c8[x] * -3;
  255. int sum4 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
  256. c3[x] * -3 + c5[x] * 5 +
  257. c6[x] * 5 + c7[x] * 5 + c8[x] * -3;
  258. int sum5 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
  259. c3[x] * -3 + c5[x] * -3 +
  260. c6[x] * 5 + c7[x] * 5 + c8[x] * 5;
  261. int sum6 = c0[x] * 5 + c1[x] * -3 + c2[x] * -3 +
  262. c3[x] * -3 + c5[x] * -3 +
  263. c6[x] * -3 + c7[x] * 5 + c8[x] * 5;
  264. int sum7 = c0[x] * 5 + c1[x] * 5 + c2[x] * -3 +
  265. c3[x] * -3 + c5[x] * -3 +
  266. c6[x] * -3 + c7[x] * -3 + c8[x] * 5;
  267. sum0 = FFMAX(sum0, sum1);
  268. sum2 = FFMAX(sum2, sum3);
  269. sum4 = FFMAX(sum4, sum5);
  270. sum6 = FFMAX(sum6, sum7);
  271. sum0 = FFMAX(sum0, sum2);
  272. sum4 = FFMAX(sum4, sum6);
  273. sum0 = FFMAX(sum0, sum4);
  274. dst[x] = av_clip_uint8(FFABS(sum0) * scale + delta);
  275. }
  276. }
  277. static void filter16_3x3(uint8_t *dstp, int width,
  278. float rdiv, float bias, const int *const matrix,
  279. const uint8_t *c[], int peak, int radius,
  280. int dstride, int stride, int size)
  281. {
  282. uint16_t *dst = (uint16_t *)dstp;
  283. int x;
  284. for (x = 0; x < width; x++) {
  285. int sum = AV_RN16A(&c[0][2 * x]) * matrix[0] +
  286. AV_RN16A(&c[1][2 * x]) * matrix[1] +
  287. AV_RN16A(&c[2][2 * x]) * matrix[2] +
  288. AV_RN16A(&c[3][2 * x]) * matrix[3] +
  289. AV_RN16A(&c[4][2 * x]) * matrix[4] +
  290. AV_RN16A(&c[5][2 * x]) * matrix[5] +
  291. AV_RN16A(&c[6][2 * x]) * matrix[6] +
  292. AV_RN16A(&c[7][2 * x]) * matrix[7] +
  293. AV_RN16A(&c[8][2 * x]) * matrix[8];
  294. sum = (int)(sum * rdiv + bias + 0.5f);
  295. dst[x] = av_clip(sum, 0, peak);
  296. }
  297. }
  298. static void filter16_5x5(uint8_t *dstp, int width,
  299. float rdiv, float bias, const int *const matrix,
  300. const uint8_t *c[], int peak, int radius,
  301. int dstride, int stride, int size)
  302. {
  303. uint16_t *dst = (uint16_t *)dstp;
  304. int x;
  305. for (x = 0; x < width; x++) {
  306. int i, sum = 0;
  307. for (i = 0; i < 25; i++)
  308. sum += AV_RN16A(&c[i][2 * x]) * matrix[i];
  309. sum = (int)(sum * rdiv + bias + 0.5f);
  310. dst[x] = av_clip(sum, 0, peak);
  311. }
  312. }
  313. static void filter16_7x7(uint8_t *dstp, int width,
  314. float rdiv, float bias, const int *const matrix,
  315. const uint8_t *c[], int peak, int radius,
  316. int dstride, int stride, int size)
  317. {
  318. uint16_t *dst = (uint16_t *)dstp;
  319. int x;
  320. for (x = 0; x < width; x++) {
  321. int i, sum = 0;
  322. for (i = 0; i < 49; i++)
  323. sum += AV_RN16A(&c[i][2 * x]) * matrix[i];
  324. sum = (int)(sum * rdiv + bias + 0.5f);
  325. dst[x] = av_clip(sum, 0, peak);
  326. }
  327. }
  328. static void filter16_row(uint8_t *dstp, int width,
  329. float rdiv, float bias, const int *const matrix,
  330. const uint8_t *c[], int peak, int radius,
  331. int dstride, int stride, int size)
  332. {
  333. uint16_t *dst = (uint16_t *)dstp;
  334. int x;
  335. for (x = 0; x < width; x++) {
  336. int i, sum = 0;
  337. for (i = 0; i < 2 * radius + 1; i++)
  338. sum += AV_RN16A(&c[i][2 * x]) * matrix[i];
  339. sum = (int)(sum * rdiv + bias + 0.5f);
  340. dst[x] = av_clip(sum, 0, peak);
  341. }
  342. }
  343. static void filter16_column(uint8_t *dstp, int height,
  344. float rdiv, float bias, const int *const matrix,
  345. const uint8_t *c[], int peak, int radius,
  346. int dstride, int stride, int size)
  347. {
  348. DECLARE_ALIGNED(64, int, sum)[16];
  349. uint16_t *dst = (uint16_t *)dstp;
  350. const int width = FFMIN(16, size);
  351. for (int y = 0; y < height; y++) {
  352. memset(sum, 0, sizeof(sum));
  353. for (int i = 0; i < 2 * radius + 1; i++) {
  354. for (int off16 = 0; off16 < width; off16++)
  355. sum[off16] += AV_RN16A(&c[i][0 + y * stride + off16 * 2]) * matrix[i];
  356. }
  357. for (int off16 = 0; off16 < width; off16++) {
  358. sum[off16] = (int)(sum[off16] * rdiv + bias + 0.5f);
  359. dst[off16] = av_clip(sum[off16], 0, peak);
  360. }
  361. dst += dstride / 2;
  362. }
  363. }
  364. static void filter_7x7(uint8_t *dst, int width,
  365. float rdiv, float bias, const int *const matrix,
  366. const uint8_t *c[], int peak, int radius,
  367. int dstride, int stride, int size)
  368. {
  369. int x;
  370. for (x = 0; x < width; x++) {
  371. int i, sum = 0;
  372. for (i = 0; i < 49; i++)
  373. sum += c[i][x] * matrix[i];
  374. sum = (int)(sum * rdiv + bias + 0.5f);
  375. dst[x] = av_clip_uint8(sum);
  376. }
  377. }
  378. static void filter_5x5(uint8_t *dst, int width,
  379. float rdiv, float bias, const int *const matrix,
  380. const uint8_t *c[], int peak, int radius,
  381. int dstride, int stride, int size)
  382. {
  383. int x;
  384. for (x = 0; x < width; x++) {
  385. int i, sum = 0;
  386. for (i = 0; i < 25; i++)
  387. sum += c[i][x] * matrix[i];
  388. sum = (int)(sum * rdiv + bias + 0.5f);
  389. dst[x] = av_clip_uint8(sum);
  390. }
  391. }
  392. static void filter_3x3(uint8_t *dst, int width,
  393. float rdiv, float bias, const int *const matrix,
  394. const uint8_t *c[], int peak, int radius,
  395. int dstride, int stride, int size)
  396. {
  397. const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2];
  398. const uint8_t *c3 = c[3], *c4 = c[4], *c5 = c[5];
  399. const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8];
  400. int x;
  401. for (x = 0; x < width; x++) {
  402. int sum = c0[x] * matrix[0] + c1[x] * matrix[1] + c2[x] * matrix[2] +
  403. c3[x] * matrix[3] + c4[x] * matrix[4] + c5[x] * matrix[5] +
  404. c6[x] * matrix[6] + c7[x] * matrix[7] + c8[x] * matrix[8];
  405. sum = (int)(sum * rdiv + bias + 0.5f);
  406. dst[x] = av_clip_uint8(sum);
  407. }
  408. }
  409. static void filter_row(uint8_t *dst, int width,
  410. float rdiv, float bias, const int *const matrix,
  411. const uint8_t *c[], int peak, int radius,
  412. int dstride, int stride, int size)
  413. {
  414. int x;
  415. for (x = 0; x < width; x++) {
  416. int i, sum = 0;
  417. for (i = 0; i < 2 * radius + 1; i++)
  418. sum += c[i][x] * matrix[i];
  419. sum = (int)(sum * rdiv + bias + 0.5f);
  420. dst[x] = av_clip_uint8(sum);
  421. }
  422. }
  423. static void filter_column(uint8_t *dst, int height,
  424. float rdiv, float bias, const int *const matrix,
  425. const uint8_t *c[], int peak, int radius,
  426. int dstride, int stride, int size)
  427. {
  428. DECLARE_ALIGNED(64, int, sum)[16];
  429. for (int y = 0; y < height; y++) {
  430. memset(sum, 0, sizeof(sum));
  431. for (int i = 0; i < 2 * radius + 1; i++) {
  432. for (int off16 = 0; off16 < 16; off16++)
  433. sum[off16] += c[i][0 + y * stride + off16] * matrix[i];
  434. }
  435. for (int off16 = 0; off16 < 16; off16++) {
  436. sum[off16] = (int)(sum[off16] * rdiv + bias + 0.5f);
  437. dst[off16] = av_clip_uint8(sum[off16]);
  438. }
  439. dst += dstride;
  440. }
  441. }
  442. static void setup_3x3(int radius, const uint8_t *c[], const uint8_t *src, int stride,
  443. int x, int w, int y, int h, int bpc)
  444. {
  445. int i;
  446. for (i = 0; i < 9; i++) {
  447. int xoff = FFABS(x + ((i % 3) - 1));
  448. int yoff = FFABS(y + (i / 3) - 1);
  449. xoff = xoff >= w ? 2 * w - 1 - xoff : xoff;
  450. yoff = yoff >= h ? 2 * h - 1 - yoff : yoff;
  451. c[i] = src + xoff * bpc + yoff * stride;
  452. }
  453. }
  454. static void setup_5x5(int radius, const uint8_t *c[], const uint8_t *src, int stride,
  455. int x, int w, int y, int h, int bpc)
  456. {
  457. int i;
  458. for (i = 0; i < 25; i++) {
  459. int xoff = FFABS(x + ((i % 5) - 2));
  460. int yoff = FFABS(y + (i / 5) - 2);
  461. xoff = xoff >= w ? 2 * w - 1 - xoff : xoff;
  462. yoff = yoff >= h ? 2 * h - 1 - yoff : yoff;
  463. c[i] = src + xoff * bpc + yoff * stride;
  464. }
  465. }
  466. static void setup_7x7(int radius, const uint8_t *c[], const uint8_t *src, int stride,
  467. int x, int w, int y, int h, int bpc)
  468. {
  469. int i;
  470. for (i = 0; i < 49; i++) {
  471. int xoff = FFABS(x + ((i % 7) - 3));
  472. int yoff = FFABS(y + (i / 7) - 3);
  473. xoff = xoff >= w ? 2 * w - 1 - xoff : xoff;
  474. yoff = yoff >= h ? 2 * h - 1 - yoff : yoff;
  475. c[i] = src + xoff * bpc + yoff * stride;
  476. }
  477. }
  478. static void setup_row(int radius, const uint8_t *c[], const uint8_t *src, int stride,
  479. int x, int w, int y, int h, int bpc)
  480. {
  481. int i;
  482. for (i = 0; i < radius * 2 + 1; i++) {
  483. int xoff = FFABS(x + i - radius);
  484. xoff = xoff >= w ? 2 * w - 1 - xoff : xoff;
  485. c[i] = src + xoff * bpc + y * stride;
  486. }
  487. }
  488. static void setup_column(int radius, const uint8_t *c[], const uint8_t *src, int stride,
  489. int x, int w, int y, int h, int bpc)
  490. {
  491. int i;
  492. for (i = 0; i < radius * 2 + 1; i++) {
  493. int xoff = FFABS(x + i - radius);
  494. xoff = xoff >= h ? 2 * h - 1 - xoff : xoff;
  495. c[i] = src + y * bpc + xoff * stride;
  496. }
  497. }
  498. static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
  499. {
  500. ConvolutionContext *s = ctx->priv;
  501. ThreadData *td = arg;
  502. AVFrame *in = td->in;
  503. AVFrame *out = td->out;
  504. int plane;
  505. for (plane = 0; plane < s->nb_planes; plane++) {
  506. const int mode = s->mode[plane];
  507. const int bpc = s->bpc;
  508. const int radius = s->size[plane] / 2;
  509. const int height = s->planeheight[plane];
  510. const int width = s->planewidth[plane];
  511. const int stride = in->linesize[plane];
  512. const int dstride = out->linesize[plane];
  513. const int sizeh = mode == MATRIX_COLUMN ? width : height;
  514. const int sizew = mode == MATRIX_COLUMN ? height : width;
  515. const int slice_start = (sizeh * jobnr) / nb_jobs;
  516. const int slice_end = (sizeh * (jobnr+1)) / nb_jobs;
  517. const float rdiv = s->rdiv[plane];
  518. const float bias = s->bias[plane];
  519. const uint8_t *src = in->data[plane];
  520. const int dst_pos = slice_start * (mode == MATRIX_COLUMN ? bpc : dstride);
  521. uint8_t *dst = out->data[plane] + dst_pos;
  522. const int *matrix = s->matrix[plane];
  523. const int step = mode == MATRIX_COLUMN ? 16 : 1;
  524. const uint8_t *c[49];
  525. int y, x;
  526. if (s->copy[plane]) {
  527. if (mode == MATRIX_COLUMN)
  528. av_image_copy_plane(dst, dstride, src + slice_start * bpc, stride,
  529. (slice_end - slice_start) * bpc, height);
  530. else
  531. av_image_copy_plane(dst, dstride, src + slice_start * stride, stride,
  532. width * bpc, slice_end - slice_start);
  533. continue;
  534. }
  535. for (y = slice_start; y < slice_end; y += step) {
  536. const int xoff = mode == MATRIX_COLUMN ? (y - slice_start) * bpc : radius * bpc;
  537. const int yoff = mode == MATRIX_COLUMN ? radius * dstride : 0;
  538. for (x = 0; x < radius; x++) {
  539. const int xoff = mode == MATRIX_COLUMN ? (y - slice_start) * bpc : x * bpc;
  540. const int yoff = mode == MATRIX_COLUMN ? x * dstride : 0;
  541. s->setup[plane](radius, c, src, stride, x, width, y, height, bpc);
  542. s->filter[plane](dst + yoff + xoff, 1, rdiv,
  543. bias, matrix, c, s->max, radius,
  544. dstride, stride, slice_end - step);
  545. }
  546. s->setup[plane](radius, c, src, stride, radius, width, y, height, bpc);
  547. s->filter[plane](dst + yoff + xoff, sizew - 2 * radius,
  548. rdiv, bias, matrix, c, s->max, radius,
  549. dstride, stride, slice_end - step);
  550. for (x = sizew - radius; x < sizew; x++) {
  551. const int xoff = mode == MATRIX_COLUMN ? (y - slice_start) * bpc : x * bpc;
  552. const int yoff = mode == MATRIX_COLUMN ? x * dstride : 0;
  553. s->setup[plane](radius, c, src, stride, x, width, y, height, bpc);
  554. s->filter[plane](dst + yoff + xoff, 1, rdiv,
  555. bias, matrix, c, s->max, radius,
  556. dstride, stride, slice_end - step);
  557. }
  558. if (mode != MATRIX_COLUMN)
  559. dst += dstride;
  560. }
  561. }
  562. return 0;
  563. }
  564. static int config_input(AVFilterLink *inlink)
  565. {
  566. AVFilterContext *ctx = inlink->dst;
  567. ConvolutionContext *s = ctx->priv;
  568. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
  569. int p;
  570. s->depth = desc->comp[0].depth;
  571. s->max = (1 << s->depth) - 1;
  572. s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
  573. s->planewidth[0] = s->planewidth[3] = inlink->w;
  574. s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
  575. s->planeheight[0] = s->planeheight[3] = inlink->h;
  576. s->nb_planes = av_pix_fmt_count_planes(inlink->format);
  577. s->nb_threads = ff_filter_get_nb_threads(ctx);
  578. s->bpc = (s->depth + 7) / 8;
  579. if (!strcmp(ctx->filter->name, "convolution")) {
  580. if (s->depth > 8) {
  581. for (p = 0; p < s->nb_planes; p++) {
  582. if (s->mode[p] == MATRIX_ROW)
  583. s->filter[p] = filter16_row;
  584. else if (s->mode[p] == MATRIX_COLUMN)
  585. s->filter[p] = filter16_column;
  586. else if (s->size[p] == 3)
  587. s->filter[p] = filter16_3x3;
  588. else if (s->size[p] == 5)
  589. s->filter[p] = filter16_5x5;
  590. else if (s->size[p] == 7)
  591. s->filter[p] = filter16_7x7;
  592. }
  593. }
  594. #if CONFIG_CONVOLUTION_FILTER && ARCH_X86_64
  595. ff_convolution_init_x86(s);
  596. #endif
  597. } else if (!strcmp(ctx->filter->name, "prewitt")) {
  598. if (s->depth > 8)
  599. for (p = 0; p < s->nb_planes; p++)
  600. s->filter[p] = filter16_prewitt;
  601. } else if (!strcmp(ctx->filter->name, "roberts")) {
  602. if (s->depth > 8)
  603. for (p = 0; p < s->nb_planes; p++)
  604. s->filter[p] = filter16_roberts;
  605. } else if (!strcmp(ctx->filter->name, "sobel")) {
  606. if (s->depth > 8)
  607. for (p = 0; p < s->nb_planes; p++)
  608. s->filter[p] = filter16_sobel;
  609. } else if (!strcmp(ctx->filter->name, "kirsch")) {
  610. if (s->depth > 8)
  611. for (p = 0; p < s->nb_planes; p++)
  612. s->filter[p] = filter16_kirsch;
  613. }
  614. return 0;
  615. }
  616. static int filter_frame(AVFilterLink *inlink, AVFrame *in)
  617. {
  618. AVFilterContext *ctx = inlink->dst;
  619. ConvolutionContext *s = ctx->priv;
  620. AVFilterLink *outlink = ctx->outputs[0];
  621. AVFrame *out;
  622. ThreadData td;
  623. out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
  624. if (!out) {
  625. av_frame_free(&in);
  626. return AVERROR(ENOMEM);
  627. }
  628. av_frame_copy_props(out, in);
  629. td.in = in;
  630. td.out = out;
  631. ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN3(s->planeheight[1], s->planewidth[1], s->nb_threads));
  632. av_frame_free(&in);
  633. return ff_filter_frame(outlink, out);
  634. }
  635. static av_cold int init(AVFilterContext *ctx)
  636. {
  637. ConvolutionContext *s = ctx->priv;
  638. int i;
  639. if (!strcmp(ctx->filter->name, "convolution")) {
  640. for (i = 0; i < 4; i++) {
  641. int *matrix = (int *)s->matrix[i];
  642. char *p, *arg, *saveptr = NULL;
  643. float sum = 0;
  644. p = s->matrix_str[i];
  645. if (p) {
  646. s->matrix_length[i] = 0;
  647. while (s->matrix_length[i] < 49) {
  648. if (!(arg = av_strtok(p, " |", &saveptr)))
  649. break;
  650. p = NULL;
  651. sscanf(arg, "%d", &matrix[s->matrix_length[i]]);
  652. sum += matrix[s->matrix_length[i]];
  653. s->matrix_length[i]++;
  654. }
  655. if (!(s->matrix_length[i] & 1)) {
  656. av_log(ctx, AV_LOG_ERROR, "number of matrix elements must be odd\n");
  657. return AVERROR(EINVAL);
  658. }
  659. }
  660. if (s->mode[i] == MATRIX_ROW) {
  661. s->filter[i] = filter_row;
  662. s->setup[i] = setup_row;
  663. s->size[i] = s->matrix_length[i];
  664. } else if (s->mode[i] == MATRIX_COLUMN) {
  665. s->filter[i] = filter_column;
  666. s->setup[i] = setup_column;
  667. s->size[i] = s->matrix_length[i];
  668. } else if (s->matrix_length[i] == 9) {
  669. s->size[i] = 3;
  670. if (!memcmp(matrix, same3x3, sizeof(same3x3))) {
  671. s->copy[i] = 1;
  672. } else {
  673. s->filter[i] = filter_3x3;
  674. s->copy[i] = 0;
  675. }
  676. s->setup[i] = setup_3x3;
  677. } else if (s->matrix_length[i] == 25) {
  678. s->size[i] = 5;
  679. if (!memcmp(matrix, same5x5, sizeof(same5x5))) {
  680. s->copy[i] = 1;
  681. } else {
  682. s->filter[i] = filter_5x5;
  683. s->copy[i] = 0;
  684. }
  685. s->setup[i] = setup_5x5;
  686. } else if (s->matrix_length[i] == 49) {
  687. s->size[i] = 7;
  688. if (!memcmp(matrix, same7x7, sizeof(same7x7))) {
  689. s->copy[i] = 1;
  690. } else {
  691. s->filter[i] = filter_7x7;
  692. s->copy[i] = 0;
  693. }
  694. s->setup[i] = setup_7x7;
  695. } else {
  696. return AVERROR(EINVAL);
  697. }
  698. if (sum == 0)
  699. sum = 1;
  700. if (s->rdiv[i] == 0)
  701. s->rdiv[i] = 1. / sum;
  702. if (s->copy[i] && (s->rdiv[i] != 1. || s->bias[i] != 0.))
  703. s->copy[i] = 0;
  704. }
  705. } else if (!strcmp(ctx->filter->name, "prewitt")) {
  706. for (i = 0; i < 4; i++) {
  707. if ((1 << i) & s->planes)
  708. s->filter[i] = filter_prewitt;
  709. else
  710. s->copy[i] = 1;
  711. s->size[i] = 3;
  712. s->setup[i] = setup_3x3;
  713. s->rdiv[i] = s->scale;
  714. s->bias[i] = s->delta;
  715. }
  716. } else if (!strcmp(ctx->filter->name, "roberts")) {
  717. for (i = 0; i < 4; i++) {
  718. if ((1 << i) & s->planes)
  719. s->filter[i] = filter_roberts;
  720. else
  721. s->copy[i] = 1;
  722. s->size[i] = 3;
  723. s->setup[i] = setup_3x3;
  724. s->rdiv[i] = s->scale;
  725. s->bias[i] = s->delta;
  726. }
  727. } else if (!strcmp(ctx->filter->name, "sobel")) {
  728. for (i = 0; i < 4; i++) {
  729. if ((1 << i) & s->planes)
  730. s->filter[i] = filter_sobel;
  731. else
  732. s->copy[i] = 1;
  733. s->size[i] = 3;
  734. s->setup[i] = setup_3x3;
  735. s->rdiv[i] = s->scale;
  736. s->bias[i] = s->delta;
  737. }
  738. } else if (!strcmp(ctx->filter->name, "kirsch")) {
  739. for (i = 0; i < 4; i++) {
  740. if ((1 << i) & s->planes)
  741. s->filter[i] = filter_kirsch;
  742. else
  743. s->copy[i] = 1;
  744. s->size[i] = 3;
  745. s->setup[i] = setup_3x3;
  746. s->rdiv[i] = s->scale;
  747. s->bias[i] = s->delta;
  748. }
  749. }
  750. return 0;
  751. }
  752. static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
  753. char *res, int res_len, int flags)
  754. {
  755. int ret;
  756. ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
  757. if (ret < 0)
  758. return ret;
  759. return init(ctx);
  760. }
  761. static const AVFilterPad convolution_inputs[] = {
  762. {
  763. .name = "default",
  764. .type = AVMEDIA_TYPE_VIDEO,
  765. .config_props = config_input,
  766. .filter_frame = filter_frame,
  767. },
  768. { NULL }
  769. };
  770. static const AVFilterPad convolution_outputs[] = {
  771. {
  772. .name = "default",
  773. .type = AVMEDIA_TYPE_VIDEO,
  774. },
  775. { NULL }
  776. };
  777. #if CONFIG_CONVOLUTION_FILTER
  778. AVFilter ff_vf_convolution = {
  779. .name = "convolution",
  780. .description = NULL_IF_CONFIG_SMALL("Apply convolution filter."),
  781. .priv_size = sizeof(ConvolutionContext),
  782. .priv_class = &convolution_class,
  783. .init = init,
  784. .query_formats = query_formats,
  785. .inputs = convolution_inputs,
  786. .outputs = convolution_outputs,
  787. .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
  788. .process_command = process_command,
  789. };
  790. #endif /* CONFIG_CONVOLUTION_FILTER */
  791. #if CONFIG_PREWITT_FILTER || CONFIG_ROBERTS_FILTER || CONFIG_SOBEL_FILTER
  792. static const AVOption prewitt_roberts_sobel_options[] = {
  793. { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=15}, 0, 15, FLAGS},
  794. { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, 0.0, 65535, FLAGS},
  795. { "delta", "set delta", OFFSET(delta), AV_OPT_TYPE_FLOAT, {.dbl=0}, -65535, 65535, FLAGS},
  796. { NULL }
  797. };
  798. #if CONFIG_PREWITT_FILTER
  799. #define prewitt_options prewitt_roberts_sobel_options
  800. AVFILTER_DEFINE_CLASS(prewitt);
  801. AVFilter ff_vf_prewitt = {
  802. .name = "prewitt",
  803. .description = NULL_IF_CONFIG_SMALL("Apply prewitt operator."),
  804. .priv_size = sizeof(ConvolutionContext),
  805. .priv_class = &prewitt_class,
  806. .init = init,
  807. .query_formats = query_formats,
  808. .inputs = convolution_inputs,
  809. .outputs = convolution_outputs,
  810. .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
  811. .process_command = process_command,
  812. };
  813. #endif /* CONFIG_PREWITT_FILTER */
  814. #if CONFIG_SOBEL_FILTER
  815. #define sobel_options prewitt_roberts_sobel_options
  816. AVFILTER_DEFINE_CLASS(sobel);
  817. AVFilter ff_vf_sobel = {
  818. .name = "sobel",
  819. .description = NULL_IF_CONFIG_SMALL("Apply sobel operator."),
  820. .priv_size = sizeof(ConvolutionContext),
  821. .priv_class = &sobel_class,
  822. .init = init,
  823. .query_formats = query_formats,
  824. .inputs = convolution_inputs,
  825. .outputs = convolution_outputs,
  826. .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
  827. .process_command = process_command,
  828. };
  829. #endif /* CONFIG_SOBEL_FILTER */
  830. #if CONFIG_ROBERTS_FILTER
  831. #define roberts_options prewitt_roberts_sobel_options
  832. AVFILTER_DEFINE_CLASS(roberts);
  833. AVFilter ff_vf_roberts = {
  834. .name = "roberts",
  835. .description = NULL_IF_CONFIG_SMALL("Apply roberts cross operator."),
  836. .priv_size = sizeof(ConvolutionContext),
  837. .priv_class = &roberts_class,
  838. .init = init,
  839. .query_formats = query_formats,
  840. .inputs = convolution_inputs,
  841. .outputs = convolution_outputs,
  842. .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
  843. .process_command = process_command,
  844. };
  845. #endif /* CONFIG_ROBERTS_FILTER */
  846. #if CONFIG_KIRSCH_FILTER
  847. #define kirsch_options prewitt_roberts_sobel_options
  848. AVFILTER_DEFINE_CLASS(kirsch);
  849. AVFilter ff_vf_kirsch = {
  850. .name = "kirsch",
  851. .description = NULL_IF_CONFIG_SMALL("Apply kirsch operator."),
  852. .priv_size = sizeof(ConvolutionContext),
  853. .priv_class = &kirsch_class,
  854. .init = init,
  855. .query_formats = query_formats,
  856. .inputs = convolution_inputs,
  857. .outputs = convolution_outputs,
  858. .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
  859. .process_command = process_command,
  860. };
  861. #endif /* CONFIG_KIRSCH_FILTER */
  862. #endif /* CONFIG_PREWITT_FILTER || CONFIG_ROBERTS_FILTER || CONFIG_SOBEL_FILTER */