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 | return 0; | 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 | ConvolutionContext *s = ctx->priv; | 704 | ConvolutionContext *s = ctx->priv; |
| 705 | AVFilterLink *inlink = ctx->inputs[0]; | ||
| 706 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); | 706 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); |
| 707 | int p; | 707 | int p, i; |
| 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; | ||
| 792 | 708 | ||
| 793 | if (!strcmp(ctx->filter->name, "convolution")) { | 709 | if (!strcmp(ctx->filter->name, "convolution")) { |
| 794 | for (i = 0; i < 4; i++) { | 710 | for (i = 0; i < 4; i++) { |
| @@ -866,10 +782,8 @@ static av_cold int init(AVFilterContext *ctx) · 71 unmodified lines | |||
| 866 | } | 782 | } |
| 867 | } else if (!strcmp(ctx->filter->name, "prewitt")) { | 783 | } else if (!strcmp(ctx->filter->name, "prewitt")) { |
| 868 | for (i = 0; i < 4; i++) { | 784 | for (i = 0; i < 4; i++) { |
| 869 | if ((1 << i) & s->planes) | 785 | s->filter[i] = filter_prewitt; |
| 870 | s->filter[i] = filter_prewitt; | 786 | s->copy[i] = !((1 << i) & s->planes); |
| 871 | else | ||
| 872 | s->copy[i] = 1; | ||
| 873 | s->size[i] = 3; | 787 | s->size[i] = 3; |
| 874 | s->setup[i] = setup_3x3; | 788 | s->setup[i] = setup_3x3; |
| 875 | s->rdiv[i] = s->scale; | 789 | s->rdiv[i] = s->scale; |
| @@ -877,10 +791,8 @@ static av_cold int init(AVFilterContext *ctx) · 1 unmodified line | |||
| 877 | } | 791 | } |
| 878 | } else if (!strcmp(ctx->filter->name, "roberts")) { | 792 | } else if (!strcmp(ctx->filter->name, "roberts")) { |
| 879 | for (i = 0; i < 4; i++) { | 793 | for (i = 0; i < 4; i++) { |
| 880 | if ((1 << i) & s->planes) | 794 | s->filter[i] = filter_roberts; |
| 881 | s->filter[i] = filter_roberts; | 795 | s->copy[i] = !((1 << i) & s->planes); |
| 882 | else | ||
| 883 | s->copy[i] = 1; | ||
| 884 | s->size[i] = 3; | 796 | s->size[i] = 3; |
| 885 | s->setup[i] = setup_3x3; | 797 | s->setup[i] = setup_3x3; |
| 886 | s->rdiv[i] = s->scale; | 798 | s->rdiv[i] = s->scale; |
| @@ -888,10 +800,8 @@ static av_cold int init(AVFilterContext *ctx) · 1 unmodified line | |||
| 888 | } | 800 | } |
| 889 | } else if (!strcmp(ctx->filter->name, "sobel")) { | 801 | } else if (!strcmp(ctx->filter->name, "sobel")) { |
| 890 | for (i = 0; i < 4; i++) { | 802 | for (i = 0; i < 4; i++) { |
| 891 | if ((1 << i) & s->planes) | 803 | s->filter[i] = filter_sobel; |
| 892 | s->filter[i] = filter_sobel; | 804 | s->copy[i] = !((1 << i) & s->planes); |
| 893 | else | ||
| 894 | s->copy[i] = 1; | ||
| 895 | s->size[i] = 3; | 805 | s->size[i] = 3; |
| 896 | s->setup[i] = setup_3x3; | 806 | s->setup[i] = setup_3x3; |
| 897 | s->rdiv[i] = s->scale; | 807 | s->rdiv[i] = s->scale; |
| @@ -899,10 +809,8 @@ static av_cold int init(AVFilterContext *ctx) · 1 unmodified line | |||
| 899 | } | 809 | } |
| 900 | } else if (!strcmp(ctx->filter->name, "kirsch")) { | 810 | } else if (!strcmp(ctx->filter->name, "kirsch")) { |
| 901 | for (i = 0; i < 4; i++) { | 811 | for (i = 0; i < 4; i++) { |
| 902 | if ((1 << i) & s->planes) | 812 | s->filter[i] = filter_kirsch; |
| 903 | s->filter[i] = filter_kirsch; | 813 | s->copy[i] = !((1 << i) & s->planes); |
| 904 | else | ||
| 905 | s->copy[i] = 1; | ||
| 906 | s->size[i] = 3; | 814 | s->size[i] = 3; |
| 907 | s->setup[i] = setup_3x3; | 815 | s->setup[i] = setup_3x3; |
| 908 | s->rdiv[i] = s->scale; | 816 | s->rdiv[i] = s->scale; |
| @@ -910,10 +818,8 @@ static av_cold int init(AVFilterContext *ctx) · 1 unmodified line | |||
| 910 | } | 818 | } |
| 911 | } else if (!strcmp(ctx->filter->name, "scharr")) { | 819 | } else if (!strcmp(ctx->filter->name, "scharr")) { |
| 912 | for (i = 0; i < 4; i++) { | 820 | for (i = 0; i < 4; i++) { |
| 913 | if ((1 << i) & s->planes) | 821 | s->filter[i] = filter_scharr; |
| 914 | s->filter[i] = filter_scharr; | 822 | s->copy[i] = !((1 << i) & s->planes); |
| 915 | else | ||
| 916 | s->copy[i] = 1; | ||
| 917 | s->size[i] = 3; | 823 | s->size[i] = 3; |
| 918 | s->setup[i] = setup_3x3; | 824 | s->setup[i] = setup_3x3; |
| 919 | s->rdiv[i] = s->scale; | 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 | return 0; | 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 | static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, | 915 | static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, |
| 928 | char *res, int res_len, int flags) | 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 | if (ret < 0) | 921 | if (ret < 0) |
| 934 | return ret; | 922 | return ret; |
| 935 | 923 | ||
| 936 | return init(ctx); | 924 | return param_init(ctx); |
| 937 | } | 925 | } |
| 938 | 926 | ||
| 939 | static const AVFilterPad convolution_inputs[] = { | 927 | static const AVFilterPad convolution_inputs[] = { |
| @@ -959,7 +947,6 @@ const AVFilter ff_vf_convolution = { · 19 unmodified lines | |||
| 959 | .description = NULL_IF_CONFIG_SMALL("Apply convolution filter."), | 947 | .description = NULL_IF_CONFIG_SMALL("Apply convolution filter."), |
| 960 | .priv_size = sizeof(ConvolutionContext), | 948 | .priv_size = sizeof(ConvolutionContext), |
| 961 | .priv_class = &convolution_class, | 949 | .priv_class = &convolution_class, |
| 962 | .init = init, | ||
| 963 | FILTER_INPUTS(convolution_inputs), | 950 | FILTER_INPUTS(convolution_inputs), |
| 964 | FILTER_OUTPUTS(convolution_outputs), | 951 | FILTER_OUTPUTS(convolution_outputs), |
| 965 | FILTER_PIXFMTS_ARRAY(pix_fmts), | 952 | FILTER_PIXFMTS_ARRAY(pix_fmts), |
| @@ -986,7 +973,6 @@ const AVFilter ff_vf_prewitt = { · 20 unmodified lines | |||
| 986 | .description = NULL_IF_CONFIG_SMALL("Apply prewitt operator."), | 973 | .description = NULL_IF_CONFIG_SMALL("Apply prewitt operator."), |
| 987 | .priv_size = sizeof(ConvolutionContext), | 974 | .priv_size = sizeof(ConvolutionContext), |
| 988 | .priv_class = &common_class, | 975 | .priv_class = &common_class, |
| 989 | .init = init, | ||
| 990 | FILTER_INPUTS(convolution_inputs), | 976 | FILTER_INPUTS(convolution_inputs), |
| 991 | FILTER_OUTPUTS(convolution_outputs), | 977 | FILTER_OUTPUTS(convolution_outputs), |
| 992 | FILTER_PIXFMTS_ARRAY(pix_fmts), | 978 | FILTER_PIXFMTS_ARRAY(pix_fmts), |
| @@ -1003,7 +989,6 @@ const AVFilter ff_vf_sobel = { · 10 unmodified lines | |||
| 1003 | .description = NULL_IF_CONFIG_SMALL("Apply sobel operator."), | 989 | .description = NULL_IF_CONFIG_SMALL("Apply sobel operator."), |
| 1004 | .priv_size = sizeof(ConvolutionContext), | 990 | .priv_size = sizeof(ConvolutionContext), |
| 1005 | .priv_class = &common_class, | 991 | .priv_class = &common_class, |
| 1006 | .init = init, | ||
| 1007 | FILTER_INPUTS(convolution_inputs), | 992 | FILTER_INPUTS(convolution_inputs), |
| 1008 | FILTER_OUTPUTS(convolution_outputs), | 993 | FILTER_OUTPUTS(convolution_outputs), |
| 1009 | FILTER_PIXFMTS_ARRAY(pix_fmts), | 994 | FILTER_PIXFMTS_ARRAY(pix_fmts), |
| @@ -1020,7 +1005,6 @@ const AVFilter ff_vf_roberts = { · 10 unmodified lines | |||
| 1020 | .description = NULL_IF_CONFIG_SMALL("Apply roberts cross operator."), | 1005 | .description = NULL_IF_CONFIG_SMALL("Apply roberts cross operator."), |
| 1021 | .priv_size = sizeof(ConvolutionContext), | 1006 | .priv_size = sizeof(ConvolutionContext), |
| 1022 | .priv_class = &common_class, | 1007 | .priv_class = &common_class, |
| 1023 | .init = init, | ||
| 1024 | FILTER_INPUTS(convolution_inputs), | 1008 | FILTER_INPUTS(convolution_inputs), |
| 1025 | FILTER_OUTPUTS(convolution_outputs), | 1009 | FILTER_OUTPUTS(convolution_outputs), |
| 1026 | FILTER_PIXFMTS_ARRAY(pix_fmts), | 1010 | FILTER_PIXFMTS_ARRAY(pix_fmts), |
| @@ -1037,7 +1021,6 @@ const AVFilter ff_vf_kirsch = { · 10 unmodified lines | |||
| 1037 | .description = NULL_IF_CONFIG_SMALL("Apply kirsch operator."), | 1021 | .description = NULL_IF_CONFIG_SMALL("Apply kirsch operator."), |
| 1038 | .priv_size = sizeof(ConvolutionContext), | 1022 | .priv_size = sizeof(ConvolutionContext), |
| 1039 | .priv_class = &common_class, | 1023 | .priv_class = &common_class, |
| 1040 | .init = init, | ||
| 1041 | FILTER_INPUTS(convolution_inputs), | 1024 | FILTER_INPUTS(convolution_inputs), |
| 1042 | FILTER_OUTPUTS(convolution_outputs), | 1025 | FILTER_OUTPUTS(convolution_outputs), |
| 1043 | FILTER_PIXFMTS_ARRAY(pix_fmts), | 1026 | FILTER_PIXFMTS_ARRAY(pix_fmts), |
| @@ -1054,7 +1037,6 @@ const AVFilter ff_vf_scharr = { · 10 unmodified lines | |||
| 1054 | .description = NULL_IF_CONFIG_SMALL("Apply scharr operator."), | 1037 | .description = NULL_IF_CONFIG_SMALL("Apply scharr operator."), |
| 1055 | .priv_size = sizeof(ConvolutionContext), | 1038 | .priv_size = sizeof(ConvolutionContext), |
| 1056 | .priv_class = &common_class, | 1039 | .priv_class = &common_class, |
| 1057 | .init = init, | ||
| 1058 | FILTER_INPUTS(convolution_inputs), | 1040 | FILTER_INPUTS(convolution_inputs), |
| 1059 | FILTER_OUTPUTS(convolution_outputs), | 1041 | FILTER_OUTPUTS(convolution_outputs), |
| 1060 | FILTER_PIXFMTS_ARRAY(pix_fmts), | 1042 | FILTER_PIXFMTS_ARRAY(pix_fmts), |