History

avfilter/vf_convolution: unbreak runtime planes option functionality

For non-convolution filters like sobel.

Paul B Mahol committed 5 years ago

Commit 9e8bb9e1 parent 70024b61 file · +96 −114Browse files

Unified · Split

libavfilter/vf_convolution.c+96−114
@@ -699,96 +699,12 @@ static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) · 698 unmodified lines
699699 return 0;
700700 }
701701
702−static int config_input(AVFilterLink *inlink)
702+static int param_init(AVFilterContext *ctx)
703703 {
704− AVFilterContext *ctx = inlink->dst;
705704 ConvolutionContext *s = ctx->priv;
705+ AVFilterLink *inlink = ctx->inputs[0];
706706 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;
792708
793709 if (!strcmp(ctx->filter->name, "convolution")) {
794710 for (i = 0; i < 4; i++) {
@@ -866,10 +782,8 @@ static av_cold int init(AVFilterContext *ctx) · 71 unmodified lines
866782 }
867783 } else if (!strcmp(ctx->filter->name, "prewitt")) {
868784 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);
873787 s->size[i] = 3;
874788 s->setup[i] = setup_3x3;
875789 s->rdiv[i] = s->scale;
@@ -877,10 +791,8 @@ static av_cold int init(AVFilterContext *ctx) · 1 unmodified line
877791 }
878792 } else if (!strcmp(ctx->filter->name, "roberts")) {
879793 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);
884796 s->size[i] = 3;
885797 s->setup[i] = setup_3x3;
886798 s->rdiv[i] = s->scale;
@@ -888,10 +800,8 @@ static av_cold int init(AVFilterContext *ctx) · 1 unmodified line
888800 }
889801 } else if (!strcmp(ctx->filter->name, "sobel")) {
890802 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);
895805 s->size[i] = 3;
896806 s->setup[i] = setup_3x3;
897807 s->rdiv[i] = s->scale;
@@ -899,10 +809,8 @@ static av_cold int init(AVFilterContext *ctx) · 1 unmodified line
899809 }
900810 } else if (!strcmp(ctx->filter->name, "kirsch")) {
901811 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);
906814 s->size[i] = 3;
907815 s->setup[i] = setup_3x3;
908816 s->rdiv[i] = s->scale;
@@ -910,10 +818,8 @@ static av_cold int init(AVFilterContext *ctx) · 1 unmodified line
910818 }
911819 } else if (!strcmp(ctx->filter->name, "scharr")) {
912820 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);
917823 s->size[i] = 3;
918824 s->setup[i] = setup_3x3;
919825 s->rdiv[i] = s->scale;
@@ -921,9 +827,91 @@ static av_cold int init(AVFilterContext *ctx) · 1 unmodified line
921827 }
922828 }
923829
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+
924882 return 0;
925883 }
926884
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+
927915 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
928916 char *res, int res_len, int flags)
929917 {
@@ -933,7 +921,7 @@ static int process_command(AVFilterContext *ctx, const char *cmd, const char *ar · 3 unmodified lines
933921 if (ret < 0)
934922 return ret;
935923
936− return init(ctx);
924+ return param_init(ctx);
937925 }
938926
939927 static const AVFilterPad convolution_inputs[] = {
@@ -959,7 +947,6 @@ const AVFilter ff_vf_convolution = { · 19 unmodified lines
959947 .description = NULL_IF_CONFIG_SMALL("Apply convolution filter."),
960948 .priv_size = sizeof(ConvolutionContext),
961949 .priv_class = &convolution_class,
962− .init = init,
963950 FILTER_INPUTS(convolution_inputs),
964951 FILTER_OUTPUTS(convolution_outputs),
965952 FILTER_PIXFMTS_ARRAY(pix_fmts),
@@ -986,7 +973,6 @@ const AVFilter ff_vf_prewitt = { · 20 unmodified lines
986973 .description = NULL_IF_CONFIG_SMALL("Apply prewitt operator."),
987974 .priv_size = sizeof(ConvolutionContext),
988975 .priv_class = &common_class,
989− .init = init,
990976 FILTER_INPUTS(convolution_inputs),
991977 FILTER_OUTPUTS(convolution_outputs),
992978 FILTER_PIXFMTS_ARRAY(pix_fmts),
@@ -1003,7 +989,6 @@ const AVFilter ff_vf_sobel = { · 10 unmodified lines
1003989 .description = NULL_IF_CONFIG_SMALL("Apply sobel operator."),
1004990 .priv_size = sizeof(ConvolutionContext),
1005991 .priv_class = &common_class,
1006− .init = init,
1007992 FILTER_INPUTS(convolution_inputs),
1008993 FILTER_OUTPUTS(convolution_outputs),
1009994 FILTER_PIXFMTS_ARRAY(pix_fmts),
@@ -1020,7 +1005,6 @@ const AVFilter ff_vf_roberts = { · 10 unmodified lines
10201005 .description = NULL_IF_CONFIG_SMALL("Apply roberts cross operator."),
10211006 .priv_size = sizeof(ConvolutionContext),
10221007 .priv_class = &common_class,
1023− .init = init,
10241008 FILTER_INPUTS(convolution_inputs),
10251009 FILTER_OUTPUTS(convolution_outputs),
10261010 FILTER_PIXFMTS_ARRAY(pix_fmts),
@@ -1037,7 +1021,6 @@ const AVFilter ff_vf_kirsch = { · 10 unmodified lines
10371021 .description = NULL_IF_CONFIG_SMALL("Apply kirsch operator."),
10381022 .priv_size = sizeof(ConvolutionContext),
10391023 .priv_class = &common_class,
1040− .init = init,
10411024 FILTER_INPUTS(convolution_inputs),
10421025 FILTER_OUTPUTS(convolution_outputs),
10431026 FILTER_PIXFMTS_ARRAY(pix_fmts),
@@ -1054,7 +1037,6 @@ const AVFilter ff_vf_scharr = { · 10 unmodified lines
10541037 .description = NULL_IF_CONFIG_SMALL("Apply scharr operator."),
10551038 .priv_size = sizeof(ConvolutionContext),
10561039 .priv_class = &common_class,
1057− .init = init,
10581040 FILTER_INPUTS(convolution_inputs),
10591041 FILTER_OUTPUTS(convolution_outputs),
10601042 FILTER_PIXFMTS_ARRAY(pix_fmts),

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t