| @@ -159,6 +159,55 @@ static void filter16_sobel(uint8_t *dstp, int width, · 158 unmodified lines |
| 159 | 159 | } |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | +static void filter16_kirsch(uint8_t *dstp, int width, |
| 163 | + float scale, float delta, const int *const matrix, |
| 164 | + const uint8_t *c[], int peak, int radius, |
| 165 | + int dstride, int stride) |
| 166 | +{ |
| 167 | + uint16_t *dst = (uint16_t *)dstp; |
| 168 | + const uint16_t *c0 = (const uint16_t *)c[0], *c1 = (const uint16_t *)c[1], *c2 = (const uint16_t *)c[2]; |
| 169 | + const uint16_t *c3 = (const uint16_t *)c[3], *c5 = (const uint16_t *)c[5]; |
| 170 | + const uint16_t *c6 = (const uint16_t *)c[6], *c7 = (const uint16_t *)c[7], *c8 = (const uint16_t *)c[8]; |
| 171 | + int x; |
| 172 | + |
| 173 | + for (x = 0; x < width; x++) { |
| 174 | + int sum0 = c0[x] * 5 + c1[x] * 5 + c2[x] * 5 + |
| 175 | + c3[x] * -3 + c5[x] * -3 + |
| 176 | + c6[x] * -3 + c7[x] * -3 + c8[x] * -3; |
| 177 | + int sum1 = c0[x] * -3 + c1[x] * 5 + c2[x] * 5 + |
| 178 | + c3[x] * 5 + c5[x] * -3 + |
| 179 | + c6[x] * -3 + c7[x] * -3 + c8[x] * -3; |
| 180 | + int sum2 = c0[x] * -3 + c1[x] * -3 + c2[x] * 5 + |
| 181 | + c3[x] * 5 + c5[x] * 5 + |
| 182 | + c6[x] * -3 + c7[x] * -3 + c8[x] * -3; |
| 183 | + int sum3 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 + |
| 184 | + c3[x] * 5 + c5[x] * 5 + |
| 185 | + c6[x] * 5 + c7[x] * -3 + c8[x] * -3; |
| 186 | + int sum4 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 + |
| 187 | + c3[x] * -3 + c5[x] * 5 + |
| 188 | + c6[x] * 5 + c7[x] * 5 + c8[x] * -3; |
| 189 | + int sum5 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 + |
| 190 | + c3[x] * -3 + c5[x] * -3 + |
| 191 | + c6[x] * 5 + c7[x] * 5 + c8[x] * 5; |
| 192 | + int sum6 = c0[x] * 5 + c1[x] * -3 + c2[x] * -3 + |
| 193 | + c3[x] * -3 + c5[x] * -3 + |
| 194 | + c6[x] * -3 + c7[x] * 5 + c8[x] * 5; |
| 195 | + int sum7 = c0[x] * 5 + c1[x] * 5 + c2[x] * -3 + |
| 196 | + c3[x] * -3 + c5[x] * -3 + |
| 197 | + c6[x] * -3 + c7[x] * -3 + c8[x] * 5; |
| 198 | + |
| 199 | + sum0 = FFMAX(sum0, sum1); |
| 200 | + sum2 = FFMAX(sum2, sum3); |
| 201 | + sum4 = FFMAX(sum4, sum5); |
| 202 | + sum6 = FFMAX(sum6, sum7); |
| 203 | + sum0 = FFMAX(sum0, sum2); |
| 204 | + sum4 = FFMAX(sum4, sum6); |
| 205 | + sum0 = FFMAX(sum0, sum4); |
| 206 | + |
| 207 | + dst[x] = av_clip(FFABS(sum0) * scale + delta, 0, peak); |
| 208 | + } |
| 209 | +} |
| 210 | + |
| 162 | 211 | static void filter_prewitt(uint8_t *dst, int width, |
| 163 | 212 | float scale, float delta, const int *const matrix, |
| 164 | 213 | const uint8_t *c[], int peak, int radius, |
| @@ -214,6 +263,54 @@ static void filter_sobel(uint8_t *dst, int width, · 49 unmodified lines |
| 214 | 263 | } |
| 215 | 264 | } |
| 216 | 265 | |
| 266 | +static void filter_kirsch(uint8_t *dst, int width, |
| 267 | + float scale, float delta, const int *const matrix, |
| 268 | + const uint8_t *c[], int peak, int radius, |
| 269 | + int dstride, int stride) |
| 270 | +{ |
| 271 | + const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2]; |
| 272 | + const uint8_t *c3 = c[3], *c5 = c[5]; |
| 273 | + const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8]; |
| 274 | + int x; |
| 275 | + |
| 276 | + for (x = 0; x < width; x++) { |
| 277 | + int sum0 = c0[x] * 5 + c1[x] * 5 + c2[x] * 5 + |
| 278 | + c3[x] * -3 + c5[x] * -3 + |
| 279 | + c6[x] * -3 + c7[x] * -3 + c8[x] * -3; |
| 280 | + int sum1 = c0[x] * -3 + c1[x] * 5 + c2[x] * 5 + |
| 281 | + c3[x] * 5 + c5[x] * -3 + |
| 282 | + c6[x] * -3 + c7[x] * -3 + c8[x] * -3; |
| 283 | + int sum2 = c0[x] * -3 + c1[x] * -3 + c2[x] * 5 + |
| 284 | + c3[x] * 5 + c5[x] * 5 + |
| 285 | + c6[x] * -3 + c7[x] * -3 + c8[x] * -3; |
| 286 | + int sum3 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 + |
| 287 | + c3[x] * 5 + c5[x] * 5 + |
| 288 | + c6[x] * 5 + c7[x] * -3 + c8[x] * -3; |
| 289 | + int sum4 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 + |
| 290 | + c3[x] * -3 + c5[x] * 5 + |
| 291 | + c6[x] * 5 + c7[x] * 5 + c8[x] * -3; |
| 292 | + int sum5 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 + |
| 293 | + c3[x] * -3 + c5[x] * -3 + |
| 294 | + c6[x] * 5 + c7[x] * 5 + c8[x] * 5; |
| 295 | + int sum6 = c0[x] * 5 + c1[x] * -3 + c2[x] * -3 + |
| 296 | + c3[x] * -3 + c5[x] * -3 + |
| 297 | + c6[x] * -3 + c7[x] * 5 + c8[x] * 5; |
| 298 | + int sum7 = c0[x] * 5 + c1[x] * 5 + c2[x] * -3 + |
| 299 | + c3[x] * -3 + c5[x] * -3 + |
| 300 | + c6[x] * -3 + c7[x] * -3 + c8[x] * 5; |
| 301 | + |
| 302 | + sum0 = FFMAX(sum0, sum1); |
| 303 | + sum2 = FFMAX(sum2, sum3); |
| 304 | + sum4 = FFMAX(sum4, sum5); |
| 305 | + sum6 = FFMAX(sum6, sum7); |
| 306 | + sum0 = FFMAX(sum0, sum2); |
| 307 | + sum4 = FFMAX(sum4, sum6); |
| 308 | + sum0 = FFMAX(sum0, sum4); |
| 309 | + |
| 310 | + dst[x] = av_clip_uint8(FFABS(sum0) * scale + delta); |
| 311 | + } |
| 312 | +} |
| 313 | + |
| 217 | 314 | static void filter16_3x3(uint8_t *dstp, int width, |
| 218 | 315 | float rdiv, float bias, const int *const matrix, |
| 219 | 316 | const uint8_t *c[], int peak, int radius, |
| @@ -604,6 +701,10 @@ static int config_input(AVFilterLink *inlink) · 384 unmodified lines |
| 604 | 701 | if (s->depth > 8) |
| 605 | 702 | for (p = 0; p < s->nb_planes; p++) |
| 606 | 703 | s->filter[p] = filter16_sobel; |
| 704 | + } else if (!strcmp(ctx->filter->name, "kirsch")) { |
| 705 | + if (s->depth > 8) |
| 706 | + for (p = 0; p < s->nb_planes; p++) |
| 707 | + s->filter[p] = filter16_kirsch; |
| 607 | 708 | } |
| 608 | 709 | |
| 609 | 710 | return 0; |
| @@ -744,6 +845,17 @@ static av_cold int init(AVFilterContext *ctx) · 134 unmodified lines |
| 744 | 845 | s->rdiv[i] = s->scale; |
| 745 | 846 | s->bias[i] = s->delta; |
| 746 | 847 | } |
| 848 | + } else if (!strcmp(ctx->filter->name, "kirsch")) { |
| 849 | + for (i = 0; i < 4; i++) { |
| 850 | + if ((1 << i) & s->planes) |
| 851 | + s->filter[i] = filter_kirsch; |
| 852 | + else |
| 853 | + s->copy[i] = 1; |
| 854 | + s->size[i] = 3; |
| 855 | + s->setup[i] = setup_3x3; |
| 856 | + s->rdiv[i] = s->scale; |
| 857 | + s->bias[i] = s->delta; |
| 858 | + } |
| 747 | 859 | } |
| 748 | 860 | |
| 749 | 861 | return 0; |
| @@ -864,4 +976,25 @@ AVFilter ff_vf_roberts = { · 114 unmodified lines |
| 864 | 976 | }; |
| 865 | 977 | |
| 866 | 978 | #endif /* CONFIG_ROBERTS_FILTER */ |
| 979 | + |
| 980 | +#if CONFIG_KIRSCH_FILTER |
| 981 | + |
| 982 | +#define kirsch_options prewitt_roberts_sobel_options |
| 983 | +AVFILTER_DEFINE_CLASS(kirsch); |
| 984 | + |
| 985 | +AVFilter ff_vf_kirsch = { |
| 986 | + .name = "kirsch", |
| 987 | + .description = NULL_IF_CONFIG_SMALL("Apply kirsch operator."), |
| 988 | + .priv_size = sizeof(ConvolutionContext), |
| 989 | + .priv_class = &kirsch_class, |
| 990 | + .init = init, |
| 991 | + .query_formats = query_formats, |
| 992 | + .inputs = convolution_inputs, |
| 993 | + .outputs = convolution_outputs, |
| 994 | + .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS, |
| 995 | + .process_command = process_command, |
| 996 | +}; |
| 997 | + |
| 998 | +#endif /* CONFIG_KIRSCH_FILTER */ |
| 999 | + |
| 867 | 1000 | #endif /* CONFIG_PREWITT_FILTER || CONFIG_ROBERTS_FILTER || CONFIG_SOBEL_FILTER */ |