For non-convolution filters like sobel.
Unified · Split
| @@ -699,96 +699,12 @@ static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) · 698 unmodified lines | ||
| 699 | 699 | return 0; |
| 700 | 700 | } |
| 701 | 701 | |
| 702 | −static int config_input(AVFilterLink *inlink) | |
| 702 | +static int param_init(AVFilterContext *ctx) | |
| 703 | 703 | { |
| 704 | − AVFilterContext *ctx = inlink->dst; | |
| 705 | 704 | ConvolutionContext *s = ctx->priv; |
| 705 | + AVFilterLink *inlink = ctx->inputs[0]; | |
| 706 | 706 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); |
| 707 | − int p; | |
| 708 | − | |
| 709 | − s->depth = desc->comp[0].depth; | |
| 710 | − s->max = (1 << s->depth) - 1; | |
| 711 | − | |
| 712 | − s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w); | |
| 713 | − s->planewidth[0] = s->planewidth[3] = inlink->w; | |
| 714 | − s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h); | |
| 715 | − s->planeheight[0] = s->planeheight[3] = inlink->h; | |
| 716 | − | |
| 717 | − s->nb_planes = av_pix_fmt_count_planes(inlink->format); | |
| 718 | − s->nb_threads = ff_filter_get_nb_threads(ctx); | |
| 719 | − s->bpc = (s->depth + 7) / 8; | |
| 720 | − | |
| 721 | − if (!strcmp(ctx->filter->name, "convolution")) { | |
| 722 | − if (s->depth > 8) { | |
| 723 | − for (p = 0; p < s->nb_planes; p++) { | |
| 724 | − if (s->mode[p] == MATRIX_ROW) | |
| 725 | − s->filter[p] = filter16_row; | |
| 726 | − else if (s->mode[p] == MATRIX_COLUMN) | |
| 727 | − s->filter[p] = filter16_column; | |
| 728 | − else if (s->size[p] == 3) | |
| 729 | − s->filter[p] = filter16_3x3; | |
| 730 | − else if (s->size[p] == 5) | |
| 731 | − s->filter[p] = filter16_5x5; | |
| 732 | − else if (s->size[p] == 7) | |
| 733 | − s->filter[p] = filter16_7x7; | |
| 734 | − } | |
| 735 | − } | |
| 736 | −#if CONFIG_CONVOLUTION_FILTER && ARCH_X86_64 | |
| 737 | − ff_convolution_init_x86(s); | |
| 738 | −#endif | |
| 739 | − } else if (!strcmp(ctx->filter->name, "prewitt")) { | |
| 740 | − if (s->depth > 8) | |
| 741 | − for (p = 0; p < s->nb_planes; p++) | |
| 742 | − s->filter[p] = filter16_prewitt; | |
| 743 | − } else if (!strcmp(ctx->filter->name, "roberts")) { | |
| 744 | − if (s->depth > 8) | |
| 745 | − for (p = 0; p < s->nb_planes; p++) | |
| 746 | − s->filter[p] = filter16_roberts; | |
| 747 | − } else if (!strcmp(ctx->filter->name, "sobel")) { | |
| 748 | − if (s->depth > 8) | |
| 749 | − for (p = 0; p < s->nb_planes; p++) | |
| 750 | − s->filter[p] = filter16_sobel; | |
| 751 | − } else if (!strcmp(ctx->filter->name, "kirsch")) { | |
| 752 | − if (s->depth > 8) | |
| 753 | − for (p = 0; p < s->nb_planes; p++) | |
| 754 | − s->filter[p] = filter16_kirsch; | |
| 755 | − } else if (!strcmp(ctx->filter->name, "scharr")) { | |
| 756 | − if (s->depth > 8) | |
| 757 | − for (p = 0; p < s->nb_planes; p++) | |
| 758 | − s->filter[p] = filter16_scharr; | |
| 759 | − } | |
| 760 | − | |
| 761 | − return 0; | |
| 762 | −} | |
| 763 | − | |
| 764 | −static int filter_frame(AVFilterLink *inlink, AVFrame *in) | |
| 765 | −{ | |
| 766 | − AVFilterContext *ctx = inlink->dst; | |
| 767 | − ConvolutionContext *s = ctx->priv; | |
| 768 | − AVFilterLink *outlink = ctx->outputs[0]; | |
| 769 | − AVFrame *out; | |
| 770 | − ThreadData td; | |
| 771 | − | |
| 772 | − out = ff_get_video_buffer(outlink, outlink->w, outlink->h); | |
| 773 | − if (!out) { | |
| 774 | − av_frame_free(&in); | |
| 775 | − return AVERROR(ENOMEM); | |
| 776 | − } | |
| 777 | − av_frame_copy_props(out, in); | |
| 778 | − | |
| 779 | − td.in = in; | |
| 780 | − td.out = out; | |
| 781 | − ff_filter_execute(ctx, filter_slice, &td, NULL, | |
| 782 | − FFMIN3(s->planeheight[1], s->planewidth[1], s->nb_threads)); | |
| 783 | − | |
| 784 | − av_frame_free(&in); | |
| 785 | − return ff_filter_frame(outlink, out); | |
| 786 | −} | |
| 787 | − | |
| 788 | −static av_cold int init(AVFilterContext *ctx) | |
| 789 | −{ | |
| 790 | − ConvolutionContext *s = ctx->priv; | |
| 791 | − int i; | |
| 707 | + int p, i; | |
| 792 | 708 | |
| 793 | 709 | if (!strcmp(ctx->filter->name, "convolution")) { |
| 794 | 710 | for (i = 0; i < 4; i++) { |
| @@ -866,10 +782,8 @@ static av_cold int init(AVFilterContext *ctx) · 71 unmodified lines | ||
| 866 | 782 | } |
| 867 | 783 | } else if (!strcmp(ctx->filter->name, "prewitt")) { |
| 868 | 784 | for (i = 0; i < 4; i++) { |
| 869 | − if ((1 << i) & s->planes) | |
| 870 | − s->filter[i] = filter_prewitt; | |
| 871 | − else | |
| 872 | − s->copy[i] = 1; | |
| 785 | + s->filter[i] = filter_prewitt; | |
| 786 | + s->copy[i] = !((1 << i) & s->planes); | |
| 873 | 787 | s->size[i] = 3; |
| 874 | 788 | s->setup[i] = setup_3x3; |
| 875 | 789 | s->rdiv[i] = s->scale; |
| @@ -877,10 +791,8 @@ static av_cold int init(AVFilterContext *ctx) · 1 unmodified line | ||
| 877 | 791 | } |
| 878 | 792 | } else if (!strcmp(ctx->filter->name, "roberts")) { |
| 879 | 793 | for (i = 0; i < 4; i++) { |
| 880 | − if ((1 << i) & s->planes) | |
| 881 | − s->filter[i] = filter_roberts; | |
| 882 | − else | |
| 883 | − s->copy[i] = 1; | |
| 794 | + s->filter[i] = filter_roberts; | |
| 795 | + s->copy[i] = !((1 << i) & s->planes); | |
| 884 | 796 | s->size[i] = 3; |
| 885 | 797 | s->setup[i] = setup_3x3; |
| 886 | 798 | s->rdiv[i] = s->scale; |
| @@ -888,10 +800,8 @@ static av_cold int init(AVFilterContext *ctx) · 1 unmodified line | ||
| 888 | 800 | } |
| 889 | 801 | } else if (!strcmp(ctx->filter->name, "sobel")) { |
| 890 | 802 | for (i = 0; i < 4; i++) { |
| 891 | − if ((1 << i) & s->planes) | |
| 892 | − s->filter[i] = filter_sobel; | |
| 893 | − else | |
| 894 | − s->copy[i] = 1; | |
| 803 | + s->filter[i] = filter_sobel; | |
| 804 | + s->copy[i] = !((1 << i) & s->planes); | |
| 895 | 805 | s->size[i] = 3; |
| 896 | 806 | s->setup[i] = setup_3x3; |
| 897 | 807 | s->rdiv[i] = s->scale; |
| @@ -899,10 +809,8 @@ static av_cold int init(AVFilterContext *ctx) · 1 unmodified line | ||
| 899 | 809 | } |
| 900 | 810 | } else if (!strcmp(ctx->filter->name, "kirsch")) { |
| 901 | 811 | for (i = 0; i < 4; i++) { |
| 902 | − if ((1 << i) & s->planes) | |
| 903 | − s->filter[i] = filter_kirsch; | |
| 904 | − else | |
| 905 | − s->copy[i] = 1; | |
| 812 | + s->filter[i] = filter_kirsch; | |
| 813 | + s->copy[i] = !((1 << i) & s->planes); | |
| 906 | 814 | s->size[i] = 3; |
| 907 | 815 | s->setup[i] = setup_3x3; |
| 908 | 816 | s->rdiv[i] = s->scale; |
| @@ -910,10 +818,8 @@ static av_cold int init(AVFilterContext *ctx) · 1 unmodified line | ||
| 910 | 818 | } |
| 911 | 819 | } else if (!strcmp(ctx->filter->name, "scharr")) { |
| 912 | 820 | for (i = 0; i < 4; i++) { |
| 913 | − if ((1 << i) & s->planes) | |
| 914 | − s->filter[i] = filter_scharr; | |
| 915 | − else | |
| 916 | − s->copy[i] = 1; | |
| 821 | + s->filter[i] = filter_scharr; | |
| 822 | + s->copy[i] = !((1 << i) & s->planes); | |
| 917 | 823 | s->size[i] = 3; |
| 918 | 824 | s->setup[i] = setup_3x3; |
| 919 | 825 | s->rdiv[i] = s->scale; |
| @@ -921,9 +827,91 @@ static av_cold int init(AVFilterContext *ctx) · 1 unmodified line | ||
| 921 | 827 | } |
| 922 | 828 | } |
| 923 | 829 | |
| 830 | + s->depth = desc->comp[0].depth; | |
| 831 | + s->max = (1 << s->depth) - 1; | |
| 832 | + | |
| 833 | + s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w); | |
| 834 | + s->planewidth[0] = s->planewidth[3] = inlink->w; | |
| 835 | + s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h); | |
| 836 | + s->planeheight[0] = s->planeheight[3] = inlink->h; | |
| 837 | + | |
| 838 | + s->nb_planes = av_pix_fmt_count_planes(inlink->format); | |
| 839 | + s->nb_threads = ff_filter_get_nb_threads(ctx); | |
| 840 | + s->bpc = (s->depth + 7) / 8; | |
| 841 | + | |
| 842 | + if (!strcmp(ctx->filter->name, "convolution")) { | |
| 843 | + if (s->depth > 8) { | |
| 844 | + for (p = 0; p < s->nb_planes; p++) { | |
| 845 | + if (s->mode[p] == MATRIX_ROW) | |
| 846 | + s->filter[p] = filter16_row; | |
| 847 | + else if (s->mode[p] == MATRIX_COLUMN) | |
| 848 | + s->filter[p] = filter16_column; | |
| 849 | + else if (s->size[p] == 3) | |
| 850 | + s->filter[p] = filter16_3x3; | |
| 851 | + else if (s->size[p] == 5) | |
| 852 | + s->filter[p] = filter16_5x5; | |
| 853 | + else if (s->size[p] == 7) | |
| 854 | + s->filter[p] = filter16_7x7; | |
| 855 | + } | |
| 856 | + } | |
| 857 | +#if CONFIG_CONVOLUTION_FILTER && ARCH_X86_64 | |
| 858 | + ff_convolution_init_x86(s); | |
| 859 | +#endif | |
| 860 | + } else if (!strcmp(ctx->filter->name, "prewitt")) { | |
| 861 | + if (s->depth > 8) | |
| 862 | + for (p = 0; p < s->nb_planes; p++) | |
| 863 | + s->filter[p] = filter16_prewitt; | |
| 864 | + } else if (!strcmp(ctx->filter->name, "roberts")) { | |
| 865 | + if (s->depth > 8) | |
| 866 | + for (p = 0; p < s->nb_planes; p++) | |
| 867 | + s->filter[p] = filter16_roberts; | |
| 868 | + } else if (!strcmp(ctx->filter->name, "sobel")) { | |
| 869 | + if (s->depth > 8) | |
| 870 | + for (p = 0; p < s->nb_planes; p++) | |
| 871 | + s->filter[p] = filter16_sobel; | |
| 872 | + } else if (!strcmp(ctx->filter->name, "kirsch")) { | |
| 873 | + if (s->depth > 8) | |
| 874 | + for (p = 0; p < s->nb_planes; p++) | |
| 875 | + s->filter[p] = filter16_kirsch; | |
| 876 | + } else if (!strcmp(ctx->filter->name, "scharr")) { | |
| 877 | + if (s->depth > 8) | |
| 878 | + for (p = 0; p < s->nb_planes; p++) | |
| 879 | + s->filter[p] = filter16_scharr; | |
| 880 | + } | |
| 881 | + | |
| 924 | 882 | return 0; |
| 925 | 883 | } |
| 926 | 884 | |
| 885 | +static int config_input(AVFilterLink *inlink) | |
| 886 | +{ | |
| 887 | + AVFilterContext *ctx = inlink->dst; | |
| 888 | + return param_init(ctx); | |
| 889 | +} | |
| 890 | + | |
| 891 | +static int filter_frame(AVFilterLink *inlink, AVFrame *in) | |
| 892 | +{ | |
| 893 | + AVFilterContext *ctx = inlink->dst; | |
| 894 | + ConvolutionContext *s = ctx->priv; | |
| 895 | + AVFilterLink *outlink = ctx->outputs[0]; | |
| 896 | + AVFrame *out; | |
| 897 | + ThreadData td; | |
| 898 | + | |
| 899 | + out = ff_get_video_buffer(outlink, outlink->w, outlink->h); | |
| 900 | + if (!out) { | |
| 901 | + av_frame_free(&in); | |
| 902 | + return AVERROR(ENOMEM); | |
| 903 | + } | |
| 904 | + av_frame_copy_props(out, in); | |
| 905 | + | |
| 906 | + td.in = in; | |
| 907 | + td.out = out; | |
| 908 | + ff_filter_execute(ctx, filter_slice, &td, NULL, | |
| 909 | + FFMIN3(s->planeheight[1], s->planewidth[1], s->nb_threads)); | |
| 910 | + | |
| 911 | + av_frame_free(&in); | |
| 912 | + return ff_filter_frame(outlink, out); | |
| 913 | +} | |
| 914 | + | |
| 927 | 915 | static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, |
| 928 | 916 | char *res, int res_len, int flags) |
| 929 | 917 | { |
| @@ -933,7 +921,7 @@ static int process_command(AVFilterContext *ctx, const char *cmd, const char *ar · 3 unmodified lines | ||
| 933 | 921 | if (ret < 0) |
| 934 | 922 | return ret; |
| 935 | 923 | |
| 936 | − return init(ctx); | |
| 924 | + return param_init(ctx); | |
| 937 | 925 | } |
| 938 | 926 | |
| 939 | 927 | static const AVFilterPad convolution_inputs[] = { |
| @@ -959,7 +947,6 @@ const AVFilter ff_vf_convolution = { · 19 unmodified lines | ||
| 959 | 947 | .description = NULL_IF_CONFIG_SMALL("Apply convolution filter."), |
| 960 | 948 | .priv_size = sizeof(ConvolutionContext), |
| 961 | 949 | .priv_class = &convolution_class, |
| 962 | − .init = init, | |
| 963 | 950 | FILTER_INPUTS(convolution_inputs), |
| 964 | 951 | FILTER_OUTPUTS(convolution_outputs), |
| 965 | 952 | FILTER_PIXFMTS_ARRAY(pix_fmts), |
| @@ -986,7 +973,6 @@ const AVFilter ff_vf_prewitt = { · 20 unmodified lines | ||
| 986 | 973 | .description = NULL_IF_CONFIG_SMALL("Apply prewitt operator."), |
| 987 | 974 | .priv_size = sizeof(ConvolutionContext), |
| 988 | 975 | .priv_class = &common_class, |
| 989 | − .init = init, | |
| 990 | 976 | FILTER_INPUTS(convolution_inputs), |
| 991 | 977 | FILTER_OUTPUTS(convolution_outputs), |
| 992 | 978 | FILTER_PIXFMTS_ARRAY(pix_fmts), |
| @@ -1003,7 +989,6 @@ const AVFilter ff_vf_sobel = { · 10 unmodified lines | ||
| 1003 | 989 | .description = NULL_IF_CONFIG_SMALL("Apply sobel operator."), |
| 1004 | 990 | .priv_size = sizeof(ConvolutionContext), |
| 1005 | 991 | .priv_class = &common_class, |
| 1006 | − .init = init, | |
| 1007 | 992 | FILTER_INPUTS(convolution_inputs), |
| 1008 | 993 | FILTER_OUTPUTS(convolution_outputs), |
| 1009 | 994 | FILTER_PIXFMTS_ARRAY(pix_fmts), |
| @@ -1020,7 +1005,6 @@ const AVFilter ff_vf_roberts = { · 10 unmodified lines | ||
| 1020 | 1005 | .description = NULL_IF_CONFIG_SMALL("Apply roberts cross operator."), |
| 1021 | 1006 | .priv_size = sizeof(ConvolutionContext), |
| 1022 | 1007 | .priv_class = &common_class, |
| 1023 | − .init = init, | |
| 1024 | 1008 | FILTER_INPUTS(convolution_inputs), |
| 1025 | 1009 | FILTER_OUTPUTS(convolution_outputs), |
| 1026 | 1010 | FILTER_PIXFMTS_ARRAY(pix_fmts), |
| @@ -1037,7 +1021,6 @@ const AVFilter ff_vf_kirsch = { · 10 unmodified lines | ||
| 1037 | 1021 | .description = NULL_IF_CONFIG_SMALL("Apply kirsch operator."), |
| 1038 | 1022 | .priv_size = sizeof(ConvolutionContext), |
| 1039 | 1023 | .priv_class = &common_class, |
| 1040 | − .init = init, | |
| 1041 | 1024 | FILTER_INPUTS(convolution_inputs), |
| 1042 | 1025 | FILTER_OUTPUTS(convolution_outputs), |
| 1043 | 1026 | FILTER_PIXFMTS_ARRAY(pix_fmts), |
| @@ -1054,7 +1037,6 @@ const AVFilter ff_vf_scharr = { · 10 unmodified lines | ||
| 1054 | 1037 | .description = NULL_IF_CONFIG_SMALL("Apply scharr operator."), |
| 1055 | 1038 | .priv_size = sizeof(ConvolutionContext), |
| 1056 | 1039 | .priv_class = &common_class, |
| 1057 | − .init = init, | |
| 1058 | 1040 | FILTER_INPUTS(convolution_inputs), |
| 1059 | 1041 | FILTER_OUTPUTS(convolution_outputs), |
| 1060 | 1042 | FILTER_PIXFMTS_ARRAY(pix_fmts), |