[PATCH] Add negate filter.
Ported from the libavfilter-soc repo with some cosmetical change. --- doc/filters.texi | 4 ++ libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_negate.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 141 insertions(+), 0 deletions(-) create mode 100644 libavfilter/vf_negate.c diff --git a/doc/filters.texi b/doc/filters.texi index 1cba2d6..037ad78 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -360,6 +360,10 @@ The following command: will make libavfilter use a format different from "yuv420p" for the input to the vflip filter. + at section negate + +Convert a video to its negative. + @section null Pass the video source unchanged to the output. diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 210510f..4379e9a 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -27,6 +27,7 @@ OBJS-$(CONFIG_FIFO_FILTER) += vf_fifo.o OBJS-$(CONFIG_FORMAT_FILTER) += vf_format.o OBJS-$(CONFIG_FREI0R_FILTER) += vf_frei0r.o OBJS-$(CONFIG_HFLIP_FILTER) += vf_hflip.o +OBJS-$(CONFIG_NEGATE_FILTER) += vf_negate.o OBJS-$(CONFIG_NOFORMAT_FILTER) += vf_format.o OBJS-$(CONFIG_NULL_FILTER) += vf_null.o OBJS-$(CONFIG_OCV_SMOOTH_FILTER) += vf_libopencv.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index 9e3ba14..1a776ca 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -48,6 +48,7 @@ void avfilter_register_all(void) REGISTER_FILTER (FORMAT, format, vf); REGISTER_FILTER (FREI0R, frei0r, vf); REGISTER_FILTER (HFLIP, hflip, vf); + REGISTER_FILTER (NEGATE, negate, vf); REGISTER_FILTER (NOFORMAT, noformat, vf); REGISTER_FILTER (NULL, null, vf); REGISTER_FILTER (OCV_SMOOTH, ocv_smooth, vf); diff --git a/libavfilter/vf_negate.c b/libavfilter/vf_negate.c new file mode 100644 index 0000000..d3c388e --- /dev/null +++ b/libavfilter/vf_negate.c @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2007 Bobby Bingham + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * video negative filter + */ + +#include "libavutil/pixdesc.h" +#include "avfilter.h" + +typedef struct { + int off_y, off_uv; + int hsub, vsub; +} NegContext; + +static int query_formats(AVFilterContext *ctx) +{ + enum PixelFormat pix_fmts[] = { + PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV420P, + PIX_FMT_YUV411P, PIX_FMT_YUV410P, + PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ420P, + PIX_FMT_YUV440P, PIX_FMT_YUVJ440P, + PIX_FMT_MONOWHITE, PIX_FMT_MONOBLACK, + PIX_FMT_NONE + }; + + avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts)); + return 0; +} + +static int config_props(AVFilterLink *inlink) +{ + NegContext *neg = inlink->dst->priv; + + neg->hsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_w; + neg->vsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_h; + + switch (inlink->format) { + case PIX_FMT_YUVJ444P: + case PIX_FMT_YUVJ422P: + case PIX_FMT_YUVJ420P: + case PIX_FMT_YUVJ440P: + neg->off_y = + neg->off_uv = 0; + break; + default: + neg->off_y = -4; + neg->off_uv = 1; + } + + return 0; +} + +static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) +{ + NegContext *neg = inlink->dst->priv; + AVFilterLink *outlink = inlink->dst->outputs[0]; + AVFilterBufferRef *inpic = inlink ->cur_buf; + AVFilterBufferRef *outpic = outlink->out_buf; + uint8_t *inrow, *outrow; + int i, j, plane; + + if (inlink->format == PIX_FMT_MONOWHITE || inlink->format == PIX_FMT_MONOBLACK) { + inrow = inpic ->data[0] + y * inpic ->linesize[0]; + outrow = outpic->data[0] + y * outpic->linesize[0]; + for (i = 0; i < h; i++) { + for (j = 0; j < inlink->w >> 3; j++) + outrow[j] = ~inrow[j]; + inrow += inpic ->linesize[0]; + outrow += outpic->linesize[0]; + } + } else { + /* luma plane */ + inrow = inpic ->data[0] + y * inpic-> linesize[0]; + outrow = outpic->data[0] + y * outpic->linesize[0]; + for (i = 0; i < h; i ++) { + for(j = 0; j < inlink->w; j++) + outrow[j] = 255 - inrow[j] + neg->off_y; + inrow += inpic ->linesize[0]; + outrow += outpic->linesize[0]; + } + + /* chroma planes */ + for (plane = 1; plane < 3; plane++) { + inrow = inpic-> data[plane] + (y >> neg->vsub) * inpic ->linesize[plane]; + outrow = outpic->data[plane] + (y >> neg->vsub) * outpic->linesize[plane]; + + for (i = 0; i < h >> neg->vsub; i++) { + for (j = 0; j < inlink->w >> neg->hsub; j++) + outrow[j] = 255 - inrow[j] + neg->off_uv; + inrow += inpic ->linesize[plane]; + outrow += outpic->linesize[plane]; + } + } + } + + avfilter_draw_slice(outlink, y, h, slice_dir); +} + +AVFilter avfilter_vf_negate = { + .name = "negate", + .description = NULL_IF_CONFIG_SMALL("Negate the input video."), + + .priv_size = sizeof(NegContext), + + .query_formats = query_formats, + + .inputs = (AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .draw_slice = draw_slice, + .config_props = config_props, + .min_perms = AV_PERM_READ, }, + { .name = NULL}}, + .outputs = (AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, }, + { .name = NULL}}, +}; -- 1.7.1
On Fri, Nov 26, 2010 at 05:32:13PM +0100, Stefano Sabatini wrote:
Ported from the libavfilter-soc repo with some cosmetical change. --- doc/filters.texi | 4 ++ libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_negate.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 141 insertions(+), 0 deletions(-) create mode 100644 libavfilter/vf_negate.c
diff --git a/doc/filters.texi b/doc/filters.texi index 1cba2d6..037ad78 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -360,6 +360,10 @@ The following command: will make libavfilter use a format different from "yuv420p" for the input to the vflip filter.
+ at section negate + +Convert a video to its negative. + @section null
Pass the video source unchanged to the output. diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 210510f..4379e9a 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -27,6 +27,7 @@ OBJS-$(CONFIG_FIFO_FILTER) += vf_fifo.o OBJS-$(CONFIG_FORMAT_FILTER) += vf_format.o OBJS-$(CONFIG_FREI0R_FILTER) += vf_frei0r.o OBJS-$(CONFIG_HFLIP_FILTER) += vf_hflip.o +OBJS-$(CONFIG_NEGATE_FILTER) += vf_negate.o OBJS-$(CONFIG_NOFORMAT_FILTER) += vf_format.o OBJS-$(CONFIG_NULL_FILTER) += vf_null.o OBJS-$(CONFIG_OCV_SMOOTH_FILTER) += vf_libopencv.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index 9e3ba14..1a776ca 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -48,6 +48,7 @@ void avfilter_register_all(void) REGISTER_FILTER (FORMAT, format, vf); REGISTER_FILTER (FREI0R, frei0r, vf); REGISTER_FILTER (HFLIP, hflip, vf); + REGISTER_FILTER (NEGATE, negate, vf); REGISTER_FILTER (NOFORMAT, noformat, vf); REGISTER_FILTER (NULL, null, vf); REGISTER_FILTER (OCV_SMOOTH, ocv_smooth, vf); diff --git a/libavfilter/vf_negate.c b/libavfilter/vf_negate.c new file mode 100644 index 0000000..d3c388e --- /dev/null +++ b/libavfilter/vf_negate.c @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2007 Bobby Bingham + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * video negative filter + */ + +#include "libavutil/pixdesc.h" +#include "avfilter.h" + +typedef struct { + int off_y, off_uv; + int hsub, vsub; +} NegContext; + +static int query_formats(AVFilterContext *ctx) +{ + enum PixelFormat pix_fmts[] = { + PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV420P, + PIX_FMT_YUV411P, PIX_FMT_YUV410P, + PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ420P, + PIX_FMT_YUV440P, PIX_FMT_YUVJ440P, + PIX_FMT_MONOWHITE, PIX_FMT_MONOBLACK, + PIX_FMT_NONE + }; + + avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts)); + return 0; +} + +static int config_props(AVFilterLink *inlink) +{ + NegContext *neg = inlink->dst->priv; + + neg->hsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_w; + neg->vsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_h; + + switch (inlink->format) { + case PIX_FMT_YUVJ444P: + case PIX_FMT_YUVJ422P: + case PIX_FMT_YUVJ420P: + case PIX_FMT_YUVJ440P: + neg->off_y = + neg->off_uv = 0; + break; + default: + neg->off_y = -4; + neg->off_uv = 1; + } + + return 0; +} + +static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) +{ + NegContext *neg = inlink->dst->priv; + AVFilterLink *outlink = inlink->dst->outputs[0]; + AVFilterBufferRef *inpic = inlink ->cur_buf; + AVFilterBufferRef *outpic = outlink->out_buf; + uint8_t *inrow, *outrow; + int i, j, plane; + + if (inlink->format == PIX_FMT_MONOWHITE || inlink->format == PIX_FMT_MONOBLACK) { + inrow = inpic ->data[0] + y * inpic ->linesize[0]; + outrow = outpic->data[0] + y * outpic->linesize[0]; + for (i = 0; i < h; i++) { + for (j = 0; j < inlink->w >> 3; j++) + outrow[j] = ~inrow[j]; + inrow += inpic ->linesize[0]; + outrow += outpic->linesize[0]; + } + } else { + /* luma plane */ + inrow = inpic ->data[0] + y * inpic-> linesize[0]; + outrow = outpic->data[0] + y * outpic->linesize[0]; + for (i = 0; i < h; i ++) { + for(j = 0; j < inlink->w; j++) + outrow[j] = 255 - inrow[j] + neg->off_y; + inrow += inpic ->linesize[0]; + outrow += outpic->linesize[0]; + } + + /* chroma planes */ + for (plane = 1; plane < 3; plane++) { + inrow = inpic-> data[plane] + (y >> neg->vsub) * inpic ->linesize[plane]; + outrow = outpic->data[plane] + (y >> neg->vsub) * outpic->linesize[plane]; + + for (i = 0; i < h >> neg->vsub; i++) { + for (j = 0; j < inlink->w >> neg->hsub; j++) + outrow[j] = 255 - inrow[j] + neg->off_uv; + inrow += inpic ->linesize[plane]; + outrow += outpic->linesize[plane]; + } + }
the user should be able to selct which planes are negated [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB No human being will ever know the Truth, for even if they happen to say it by chance, they would not even known they had done so. -- Xenophanes
On date Sunday 2010-11-28 03:09:35 +0100, Michael Niedermayer encoded:
On Fri, Nov 26, 2010 at 05:32:13PM +0100, Stefano Sabatini wrote: [...]
+static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) +{ + NegContext *neg = inlink->dst->priv; + AVFilterLink *outlink = inlink->dst->outputs[0]; + AVFilterBufferRef *inpic = inlink ->cur_buf; + AVFilterBufferRef *outpic = outlink->out_buf; + uint8_t *inrow, *outrow; + int i, j, plane; + + if (inlink->format == PIX_FMT_MONOWHITE || inlink->format == PIX_FMT_MONOBLACK) { + inrow = inpic ->data[0] + y * inpic ->linesize[0]; + outrow = outpic->data[0] + y * outpic->linesize[0]; + for (i = 0; i < h; i++) { + for (j = 0; j < inlink->w >> 3; j++) + outrow[j] = ~inrow[j]; + inrow += inpic ->linesize[0]; + outrow += outpic->linesize[0]; + } + } else { + /* luma plane */ + inrow = inpic ->data[0] + y * inpic-> linesize[0]; + outrow = outpic->data[0] + y * outpic->linesize[0]; + for (i = 0; i < h; i ++) { + for(j = 0; j < inlink->w; j++) + outrow[j] = 255 - inrow[j] + neg->off_y; + inrow += inpic ->linesize[0]; + outrow += outpic->linesize[0]; + } + + /* chroma planes */ + for (plane = 1; plane < 3; plane++) { + inrow = inpic-> data[plane] + (y >> neg->vsub) * inpic ->linesize[plane]; + outrow = outpic->data[plane] + (y >> neg->vsub) * outpic->linesize[plane]; + + for (i = 0; i < h >> neg->vsub; i++) { + for (j = 0; j < inlink->w >> neg->hsub; j++) + outrow[j] = 255 - inrow[j] + neg->off_uv; + inrow += inpic ->linesize[plane]; + outrow += outpic->linesize[plane]; + } + }
the user should be able to selct which planes are negated
Good idea, updated. -- FFmpeg = Fast & Faithless Meaningful Powerful Extreme Guru
On Sun, Nov 28, 2010 at 12:30:09PM +0100, Stefano Sabatini wrote:
On date Sunday 2010-11-28 03:09:35 +0100, Michael Niedermayer encoded:
On Fri, Nov 26, 2010 at 05:32:13PM +0100, Stefano Sabatini wrote: [...]
+static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) +{ + NegContext *neg = inlink->dst->priv; + AVFilterLink *outlink = inlink->dst->outputs[0]; + AVFilterBufferRef *inpic = inlink ->cur_buf; + AVFilterBufferRef *outpic = outlink->out_buf; + uint8_t *inrow, *outrow; + int i, j, plane; + + if (inlink->format == PIX_FMT_MONOWHITE || inlink->format == PIX_FMT_MONOBLACK) { + inrow = inpic ->data[0] + y * inpic ->linesize[0]; + outrow = outpic->data[0] + y * outpic->linesize[0]; + for (i = 0; i < h; i++) { + for (j = 0; j < inlink->w >> 3; j++) + outrow[j] = ~inrow[j]; + inrow += inpic ->linesize[0]; + outrow += outpic->linesize[0]; + } + } else { + /* luma plane */ + inrow = inpic ->data[0] + y * inpic-> linesize[0]; + outrow = outpic->data[0] + y * outpic->linesize[0]; + for (i = 0; i < h; i ++) { + for(j = 0; j < inlink->w; j++) + outrow[j] = 255 - inrow[j] + neg->off_y; + inrow += inpic ->linesize[0]; + outrow += outpic->linesize[0]; + } + + /* chroma planes */ + for (plane = 1; plane < 3; plane++) { + inrow = inpic-> data[plane] + (y >> neg->vsub) * inpic ->linesize[plane]; + outrow = outpic->data[plane] + (y >> neg->vsub) * outpic->linesize[plane]; + + for (i = 0; i < h >> neg->vsub; i++) { + for (j = 0; j < inlink->w >> neg->hsub; j++) + outrow[j] = 255 - inrow[j] + neg->off_uv; + inrow += inpic ->linesize[plane]; + outrow += outpic->linesize[plane]; + } + }
the user should be able to selct which planes are negated
Good idea, updated. -- FFmpeg = Fast & Faithless Meaningful Powerful Extreme Guru
doc/filters.texi | 22 ++++++ libavfilter/Makefile | 1 libavfilter/allfilters.c | 1 libavfilter/vf_negate.c | 171 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 195 insertions(+) eb64b3d38766ee01540a93169fe9f72323850247 0001-Add-negate-filter.patch From 6e830a904f785b5ef8663a40ff67a3bbb7e5d524 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <stefano.sabatini-lala at poste.it> Date: Fri, 26 Nov 2010 17:31:11 +0100 Subject: [PATCH] Add negate filter.
Ported from the libavfilter-soc repo with per-component negation addition. --- doc/filters.texi | 22 ++++++ libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_negate.c | 171 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 195 insertions(+), 0 deletions(-) create mode 100644 libavfilter/vf_negate.c
diff --git a/doc/filters.texi b/doc/filters.texi index 1cba2d6..95b235e 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -360,6 +360,28 @@ The following command: will make libavfilter use a format different from "yuv420p" for the input to the vflip filter.
+ at section negate + +Convert one or more components of a video to its negative. + +This filter accepts as paramter a string containing a sequence of the +characters 'y' (luma component), 'u' (U chroma component), 'v' (V +chroma component), 'a' (alpha component). The components corresponding +to the specified characters will be negated. If the string is not +specified "yuv" is assumed. + +Follow some examples: + at example +# only negate luma +negate=y + +# negate chroma components +negate=uv + +# negate all the components +negate=yuva + at end example + @section null
Pass the video source unchanged to the output. diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 210510f..4379e9a 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -27,6 +27,7 @@ OBJS-$(CONFIG_FIFO_FILTER) += vf_fifo.o OBJS-$(CONFIG_FORMAT_FILTER) += vf_format.o OBJS-$(CONFIG_FREI0R_FILTER) += vf_frei0r.o OBJS-$(CONFIG_HFLIP_FILTER) += vf_hflip.o +OBJS-$(CONFIG_NEGATE_FILTER) += vf_negate.o OBJS-$(CONFIG_NOFORMAT_FILTER) += vf_format.o OBJS-$(CONFIG_NULL_FILTER) += vf_null.o OBJS-$(CONFIG_OCV_SMOOTH_FILTER) += vf_libopencv.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index c3067b8..3291bd1 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -48,6 +48,7 @@ void avfilter_register_all(void) REGISTER_FILTER (FORMAT, format, vf); REGISTER_FILTER (FREI0R, frei0r, vf); REGISTER_FILTER (HFLIP, hflip, vf); + REGISTER_FILTER (NEGATE, negate, vf); REGISTER_FILTER (NOFORMAT, noformat, vf); REGISTER_FILTER (NULL, null, vf); REGISTER_FILTER (OCV_SMOOTH, ocv_smooth, vf); diff --git a/libavfilter/vf_negate.c b/libavfilter/vf_negate.c new file mode 100644 index 0000000..bfd4120 --- /dev/null +++ b/libavfilter/vf_negate.c @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2007 Bobby Bingham + * Copyright (c) 2010 Stefano Sabatini + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * video negative filter + */ + +#include "libavutil/pixdesc.h" +#include "avfilter.h" + +typedef struct { + int hsub, vsub; + int plane_neg[4]; ///< tells which components to negate + int plane_off[4]; ///< plane value offset +} NegContext; + +#define Y 0 +#define U 1 +#define V 2 +#define A 3 + +static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) +{ + NegContext *neg = ctx->priv; + char plane_neg_str[16] = "yuv"; + int i; + + if (args) + sscanf(args, "%15s", plane_neg_str); + + for (i = 0; plane_neg_str[i]; i++) { + char c = plane_neg_str[i]; + switch (c) { + case 'y': neg->plane_neg[Y] = 1; break; + case 'u': neg->plane_neg[U] = 1; break; + case 'v': neg->plane_neg[V] = 1; break; + case 'a': neg->plane_neg[A] = 1; break; + default: + av_log(ctx, AV_LOG_ERROR, "Invalid character '%c' in arguments '%s'.\n", + c, args); + return AVERROR(EINVAL); + } + } + + av_log(ctx, AV_LOG_INFO, "y:%d u:%d v:%d a:%d\n", + neg->plane_neg[Y], neg->plane_neg[U], neg->plane_neg[V], neg->plane_neg[A]); + return 0; +} + +static int query_formats(AVFilterContext *ctx) +{ + enum PixelFormat pix_fmts[] = { + PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV420P, + PIX_FMT_YUV411P, PIX_FMT_YUV410P, + PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ420P, + PIX_FMT_YUV440P, PIX_FMT_YUVJ440P, + PIX_FMT_YUVA420P, + PIX_FMT_MONOWHITE, PIX_FMT_MONOBLACK, + PIX_FMT_NONE + }; + + avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts)); + return 0; +} + +static int config_props(AVFilterLink *inlink) +{ + NegContext *neg = inlink->dst->priv; + + neg->hsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_w; + neg->vsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_h; + + switch (inlink->format) { + case PIX_FMT_YUVJ444P: + case PIX_FMT_YUVJ422P: + case PIX_FMT_YUVJ420P: + case PIX_FMT_YUVJ440P: + neg->plane_off[Y] = + neg->plane_off[U] = neg->plane_off[V] = 0; + break; + default: + neg->plane_off[Y] = neg->plane_off[A] = -4; + neg->plane_off[U] = neg->plane_off[V] = 1; + } + + return 0; +} + +static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) +{ + NegContext *neg = inlink->dst->priv; + AVFilterLink *outlink = inlink->dst->outputs[0]; + AVFilterBufferRef *inpic = inlink ->cur_buf; + AVFilterBufferRef *outpic = outlink->out_buf; + uint8_t *inrow, *outrow; + int i, j, plane; + + for (plane = 0; inpic->data[plane]; plane++) { + int vsub = plane == 1 || plane == 2 ? neg->vsub : 0; + int hsub = plane == 1 || plane == 2 ? neg->hsub : 0; + + inrow = inpic ->data[plane] + (y>>vsub) * inpic ->linesize[plane]; + outrow = outpic->data[plane] + (y>>vsub) * outpic->linesize[plane]; + + if (neg->plane_neg[plane]) { + if (inlink->format == PIX_FMT_MONOWHITE || inlink->format == PIX_FMT_MONOBLACK) { + for (i = 0; i < inlink->h; i++) { + for (j = 0; j < inlink->w >> 3; j++) + outrow[j] = ~inrow[j]; + inrow += inpic ->linesize[0]; + outrow += outpic->linesize[0]; + } + } else { + for (i = 0; i < (h>>vsub); i ++) { + for (j = 0; j < (inlink->w>>hsub); j++) + outrow[j] = 255 - inrow[j] + neg->plane_off[plane];
can overflow and others likely too [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Concerning the gods, I have no means of knowing whether they exist or not or of what sort they may be, because of the obscurity of the subject, and the brevity of human life -- Protagoras
On date Monday 2010-11-29 03:21:22 +0100, Michael Niedermayer encoded:
On Sun, Nov 28, 2010 at 12:30:09PM +0100, Stefano Sabatini wrote: [...]
+static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) +{ + NegContext *neg = inlink->dst->priv; + AVFilterLink *outlink = inlink->dst->outputs[0]; + AVFilterBufferRef *inpic = inlink ->cur_buf; + AVFilterBufferRef *outpic = outlink->out_buf; + uint8_t *inrow, *outrow; + int i, j, plane; + + for (plane = 0; inpic->data[plane]; plane++) { + int vsub = plane == 1 || plane == 2 ? neg->vsub : 0; + int hsub = plane == 1 || plane == 2 ? neg->hsub : 0; + + inrow = inpic ->data[plane] + (y>>vsub) * inpic ->linesize[plane]; + outrow = outpic->data[plane] + (y>>vsub) * outpic->linesize[plane]; + + if (neg->plane_neg[plane]) { + if (inlink->format == PIX_FMT_MONOWHITE || inlink->format == PIX_FMT_MONOBLACK) { + for (i = 0; i < inlink->h; i++) { + for (j = 0; j < inlink->w >> 3; j++) + outrow[j] = ~inrow[j]; + inrow += inpic ->linesize[0]; + outrow += outpic->linesize[0]; + } + } else { + for (i = 0; i < (h>>vsub); i ++) { + for (j = 0; j < (inlink->w>>hsub); j++) + outrow[j] = 255 - inrow[j] + neg->plane_off[plane];
can overflow and others likely too
Fixed by clipping out-of-range values. Also relevant: http://thread.gmane.org/gmane.comp.video.ffmpeg.devel/94136/focus=94154 -- FFmpeg = Faithful & Fascinating Murdering Pacific Ecumenical God
On date Monday 2010-11-29 11:02:53 +0100, Stefano Sabatini encoded:
On date Monday 2010-11-29 03:21:22 +0100, Michael Niedermayer encoded:
On Sun, Nov 28, 2010 at 12:30:09PM +0100, Stefano Sabatini wrote: [...]
+static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) +{ + NegContext *neg = inlink->dst->priv; + AVFilterLink *outlink = inlink->dst->outputs[0]; + AVFilterBufferRef *inpic = inlink ->cur_buf; + AVFilterBufferRef *outpic = outlink->out_buf; + uint8_t *inrow, *outrow; + int i, j, plane; + + for (plane = 0; inpic->data[plane]; plane++) { + int vsub = plane == 1 || plane == 2 ? neg->vsub : 0; + int hsub = plane == 1 || plane == 2 ? neg->hsub : 0; + + inrow = inpic ->data[plane] + (y>>vsub) * inpic ->linesize[plane]; + outrow = outpic->data[plane] + (y>>vsub) * outpic->linesize[plane]; + + if (neg->plane_neg[plane]) { + if (inlink->format == PIX_FMT_MONOWHITE || inlink->format == PIX_FMT_MONOBLACK) { + for (i = 0; i < inlink->h; i++) { + for (j = 0; j < inlink->w >> 3; j++) + outrow[j] = ~inrow[j]; + inrow += inpic ->linesize[0]; + outrow += outpic->linesize[0]; + } + } else { + for (i = 0; i < (h>>vsub); i ++) { + for (j = 0; j < (inlink->w>>hsub); j++) + outrow[j] = 255 - inrow[j] + neg->plane_off[plane];
can overflow and others likely too
Fixed by clipping out-of-range values.
Also relevant: http://thread.gmane.org/gmane.comp.video.ffmpeg.devel/94136/focus=94154 -- FFmpeg = Faithful & Fascinating Murdering Pacific Ecumenical God
From 3c16bf49c0f9f4c3c72d9eea49ae35a47d58d961 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <stefano.sabatini-lala at poste.it> Date: Fri, 26 Nov 2010 17:31:11 +0100 Subject: [PATCH] Add negate filter.
Ported from the libavfilter-soc repo with per-component negation addition. --- doc/filters.texi | 22 ++++++ libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_negate.c | 184 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 208 insertions(+), 0 deletions(-) create mode 100644 libavfilter/vf_negate.c
I'll apply in three days unless objections. -- FFmpeg = Formidable Fostering Multipurpose Proud Energized Gorilla
On Tue, Nov 30, 2010 at 11:22:43PM +0100, Stefano Sabatini wrote:
On date Monday 2010-11-29 11:02:53 +0100, Stefano Sabatini encoded:
On date Monday 2010-11-29 03:21:22 +0100, Michael Niedermayer encoded:
On Sun, Nov 28, 2010 at 12:30:09PM +0100, Stefano Sabatini wrote: [...]
+static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) +{ + NegContext *neg = inlink->dst->priv; + AVFilterLink *outlink = inlink->dst->outputs[0]; + AVFilterBufferRef *inpic = inlink ->cur_buf; + AVFilterBufferRef *outpic = outlink->out_buf; + uint8_t *inrow, *outrow; + int i, j, plane; + + for (plane = 0; inpic->data[plane]; plane++) { + int vsub = plane == 1 || plane == 2 ? neg->vsub : 0; + int hsub = plane == 1 || plane == 2 ? neg->hsub : 0; + + inrow = inpic ->data[plane] + (y>>vsub) * inpic ->linesize[plane]; + outrow = outpic->data[plane] + (y>>vsub) * outpic->linesize[plane]; + + if (neg->plane_neg[plane]) { + if (inlink->format == PIX_FMT_MONOWHITE || inlink->format == PIX_FMT_MONOBLACK) { + for (i = 0; i < inlink->h; i++) { + for (j = 0; j < inlink->w >> 3; j++) + outrow[j] = ~inrow[j]; + inrow += inpic ->linesize[0]; + outrow += outpic->linesize[0]; + } + } else { + for (i = 0; i < (h>>vsub); i ++) { + for (j = 0; j < (inlink->w>>hsub); j++) + outrow[j] = 255 - inrow[j] + neg->plane_off[plane];
can overflow and others likely too
Fixed by clipping out-of-range values.
Also relevant: http://thread.gmane.org/gmane.comp.video.ffmpeg.devel/94136/focus=94154 -- FFmpeg = Faithful & Fascinating Murdering Pacific Ecumenical God
From 3c16bf49c0f9f4c3c72d9eea49ae35a47d58d961 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <stefano.sabatini-lala at poste.it> Date: Fri, 26 Nov 2010 17:31:11 +0100 Subject: [PATCH] Add negate filter.
Ported from the libavfilter-soc repo with per-component negation addition. --- doc/filters.texi | 22 ++++++ libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_negate.c | 184 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 208 insertions(+), 0 deletions(-) create mode 100644 libavfilter/vf_negate.c
I'll apply in three days unless objections.
is it faster than using a LUT ? [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Into a blind darkness they enter who follow after the Ignorance, they as if into a greater darkness enter who devote themselves to the Knowledge alone. -- Isha Upanishad
On date Wednesday 2010-12-01 03:25:47 +0100, Michael Niedermayer encoded:
On Tue, Nov 30, 2010 at 11:22:43PM +0100, Stefano Sabatini wrote:
On date Monday 2010-11-29 11:02:53 +0100, Stefano Sabatini encoded:
On date Monday 2010-11-29 03:21:22 +0100, Michael Niedermayer encoded:
On Sun, Nov 28, 2010 at 12:30:09PM +0100, Stefano Sabatini wrote: [...]
+static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) +{ + NegContext *neg = inlink->dst->priv; + AVFilterLink *outlink = inlink->dst->outputs[0]; + AVFilterBufferRef *inpic = inlink ->cur_buf; + AVFilterBufferRef *outpic = outlink->out_buf; + uint8_t *inrow, *outrow; + int i, j, plane; + + for (plane = 0; inpic->data[plane]; plane++) { + int vsub = plane == 1 || plane == 2 ? neg->vsub : 0; + int hsub = plane == 1 || plane == 2 ? neg->hsub : 0; + + inrow = inpic ->data[plane] + (y>>vsub) * inpic ->linesize[plane]; + outrow = outpic->data[plane] + (y>>vsub) * outpic->linesize[plane]; + + if (neg->plane_neg[plane]) { + if (inlink->format == PIX_FMT_MONOWHITE || inlink->format == PIX_FMT_MONOBLACK) { + for (i = 0; i < inlink->h; i++) { + for (j = 0; j < inlink->w >> 3; j++) + outrow[j] = ~inrow[j]; + inrow += inpic ->linesize[0]; + outrow += outpic->linesize[0]; + } + } else { + for (i = 0; i < (h>>vsub); i ++) { + for (j = 0; j < (inlink->w>>hsub); j++) + outrow[j] = 255 - inrow[j] + neg->plane_off[plane];
can overflow and others likely too
Fixed by clipping out-of-range values.
Also relevant: http://thread.gmane.org/gmane.comp.video.ffmpeg.devel/94136/focus=94154 -- FFmpeg = Faithful & Fascinating Murdering Pacific Ecumenical God
From 3c16bf49c0f9f4c3c72d9eea49ae35a47d58d961 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <stefano.sabatini-lala at poste.it> Date: Fri, 26 Nov 2010 17:31:11 +0100 Subject: [PATCH] Add negate filter.
Ported from the libavfilter-soc repo with per-component negation addition. --- doc/filters.texi | 22 ++++++ libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_negate.c | 184 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 208 insertions(+), 0 deletions(-) create mode 100644 libavfilter/vf_negate.c
I'll apply in three days unless objections.
is it faster than using a LUT ?
32246490 dezicycles in nolut, 1 runs, 0 skips 27420150 dezicycles in nolut, 2 runs, 0 skips 29323650 dezicycles in nolut, 4 runs, 0 skips 36039801 dezicycles in nolut, 8 runs, 0 skips 34124634 dezicycles in nolut, 16 runs, 0 skips 39557091 dezicycles in nolut, 32 runs, 0 skips 37006964 dezicycles in nolut, 64 runs, 0 skips 37271243 dezicycles in nolut, 128 runs, 0 skips 36437873 dezicycles in nolut, 256 runs, 0 skips 37591370 dezicycles in nolut, 512 runs, 0 skips 37119779 dezicycles in nolut, 1024 runs, 0 skips 37390082 dezicycles in nolut, 2048 runs, 0 skips 22483590 dezicycles in lut, 1 runs, 0 skips 16486965 dezicycles in lut, 2 runs, 0 skips 14703345 dezicycles in lut, 4 runs, 0 skips 13340126 dezicycles in lut, 8 runs, 0 skips 14286336 dezicycles in lut, 16 runs, 0 skips 17345394 dezicycles in lut, 32 runs, 0 skips 18178503 dezicycles in lut, 64 runs, 0 skips 18047690 dezicycles in lut, 128 runs, 0 skips 18159589 dezicycles in lut, 256 runs, 0 skips 17833263 dezicycles in lut, 512 runs, 0 skips 17624724 dezicycles in lut, 1024 runs, 0 skips 17303343 dezicycles in lut, 2048 runs, 0 skips Updated (with some simplifications). -- FFmpeg = Fast Funny Muttering Portentous Elegant Ghost
On date Wednesday 2010-12-01 20:57:19 +0100, Stefano Sabatini encoded:
On date Wednesday 2010-12-01 03:25:47 +0100, Michael Niedermayer encoded:
On Tue, Nov 30, 2010 at 11:22:43PM +0100, Stefano Sabatini wrote:
From 3c16bf49c0f9f4c3c72d9eea49ae35a47d58d961 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <stefano.sabatini-lala at poste.it> Date: Fri, 26 Nov 2010 17:31:11 +0100 Subject: [PATCH] Add negate filter.
Ported from the libavfilter-soc repo with per-component negation addition. --- doc/filters.texi | 22 ++++++ libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_negate.c | 184 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 208 insertions(+), 0 deletions(-) create mode 100644 libavfilter/vf_negate.c
I'll apply in three days unless objections.
is it faster than using a LUT ?
32246490 dezicycles in nolut, 1 runs, 0 skips 27420150 dezicycles in nolut, 2 runs, 0 skips 29323650 dezicycles in nolut, 4 runs, 0 skips 36039801 dezicycles in nolut, 8 runs, 0 skips 34124634 dezicycles in nolut, 16 runs, 0 skips 39557091 dezicycles in nolut, 32 runs, 0 skips 37006964 dezicycles in nolut, 64 runs, 0 skips 37271243 dezicycles in nolut, 128 runs, 0 skips 36437873 dezicycles in nolut, 256 runs, 0 skips 37591370 dezicycles in nolut, 512 runs, 0 skips 37119779 dezicycles in nolut, 1024 runs, 0 skips 37390082 dezicycles in nolut, 2048 runs, 0 skips
22483590 dezicycles in lut, 1 runs, 0 skips 16486965 dezicycles in lut, 2 runs, 0 skips 14703345 dezicycles in lut, 4 runs, 0 skips 13340126 dezicycles in lut, 8 runs, 0 skips 14286336 dezicycles in lut, 16 runs, 0 skips 17345394 dezicycles in lut, 32 runs, 0 skips 18178503 dezicycles in lut, 64 runs, 0 skips 18047690 dezicycles in lut, 128 runs, 0 skips 18159589 dezicycles in lut, 256 runs, 0 skips 17833263 dezicycles in lut, 512 runs, 0 skips 17624724 dezicycles in lut, 1024 runs, 0 skips 17303343 dezicycles in lut, 2048 runs, 0 skips
Updated (with some simplifications). [...]
I'll apply in few days if there are no more comments. -- FFmpeg = Frenzy and Furious Merciful Pacific Eccentric Glue
On Thu, Dec 02, 2010 at 08:45:24PM +0100, Stefano Sabatini wrote:
On date Wednesday 2010-12-01 20:57:19 +0100, Stefano Sabatini encoded:
On date Wednesday 2010-12-01 03:25:47 +0100, Michael Niedermayer encoded:
On Tue, Nov 30, 2010 at 11:22:43PM +0100, Stefano Sabatini wrote:
From 3c16bf49c0f9f4c3c72d9eea49ae35a47d58d961 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <stefano.sabatini-lala at poste.it> Date: Fri, 26 Nov 2010 17:31:11 +0100 Subject: [PATCH] Add negate filter.
Ported from the libavfilter-soc repo with per-component negation addition. --- doc/filters.texi | 22 ++++++ libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_negate.c | 184 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 208 insertions(+), 0 deletions(-) create mode 100644 libavfilter/vf_negate.c
I'll apply in three days unless objections.
is it faster than using a LUT ?
32246490 dezicycles in nolut, 1 runs, 0 skips 27420150 dezicycles in nolut, 2 runs, 0 skips 29323650 dezicycles in nolut, 4 runs, 0 skips 36039801 dezicycles in nolut, 8 runs, 0 skips 34124634 dezicycles in nolut, 16 runs, 0 skips 39557091 dezicycles in nolut, 32 runs, 0 skips 37006964 dezicycles in nolut, 64 runs, 0 skips 37271243 dezicycles in nolut, 128 runs, 0 skips 36437873 dezicycles in nolut, 256 runs, 0 skips 37591370 dezicycles in nolut, 512 runs, 0 skips 37119779 dezicycles in nolut, 1024 runs, 0 skips 37390082 dezicycles in nolut, 2048 runs, 0 skips
22483590 dezicycles in lut, 1 runs, 0 skips 16486965 dezicycles in lut, 2 runs, 0 skips 14703345 dezicycles in lut, 4 runs, 0 skips 13340126 dezicycles in lut, 8 runs, 0 skips 14286336 dezicycles in lut, 16 runs, 0 skips 17345394 dezicycles in lut, 32 runs, 0 skips 18178503 dezicycles in lut, 64 runs, 0 skips 18047690 dezicycles in lut, 128 runs, 0 skips 18159589 dezicycles in lut, 256 runs, 0 skips 17833263 dezicycles in lut, 512 runs, 0 skips 17624724 dezicycles in lut, 1024 runs, 0 skips 17303343 dezicycles in lut, 2048 runs, 0 skips
Updated (with some simplifications). [...]
I'll apply in few days if there are no more comments.
There should be a vf_lut.c that does generic LUT based filtering and vf_negate should use that filter [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The real ebay dictionary, page 3 "Rare item" - "Common item with rare defect or maybe just a lie" "Professional" - "'Toy' made in china, not functional except as doorstop" "Experts will know" - "The seller hopes you are not an expert"
On date Thursday 2010-12-02 22:55:24 +0100, Michael Niedermayer encoded:
On Thu, Dec 02, 2010 at 08:45:24PM +0100, Stefano Sabatini wrote:
On date Wednesday 2010-12-01 20:57:19 +0100, Stefano Sabatini encoded:
On date Wednesday 2010-12-01 03:25:47 +0100, Michael Niedermayer encoded:
On Tue, Nov 30, 2010 at 11:22:43PM +0100, Stefano Sabatini wrote:
From 3c16bf49c0f9f4c3c72d9eea49ae35a47d58d961 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <stefano.sabatini-lala at poste.it> Date: Fri, 26 Nov 2010 17:31:11 +0100 Subject: [PATCH] Add negate filter.
Ported from the libavfilter-soc repo with per-component negation addition. --- doc/filters.texi | 22 ++++++ libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_negate.c | 184 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 208 insertions(+), 0 deletions(-) create mode 100644 libavfilter/vf_negate.c
I'll apply in three days unless objections.
is it faster than using a LUT ?
32246490 dezicycles in nolut, 1 runs, 0 skips 27420150 dezicycles in nolut, 2 runs, 0 skips 29323650 dezicycles in nolut, 4 runs, 0 skips 36039801 dezicycles in nolut, 8 runs, 0 skips 34124634 dezicycles in nolut, 16 runs, 0 skips 39557091 dezicycles in nolut, 32 runs, 0 skips 37006964 dezicycles in nolut, 64 runs, 0 skips 37271243 dezicycles in nolut, 128 runs, 0 skips 36437873 dezicycles in nolut, 256 runs, 0 skips 37591370 dezicycles in nolut, 512 runs, 0 skips 37119779 dezicycles in nolut, 1024 runs, 0 skips 37390082 dezicycles in nolut, 2048 runs, 0 skips
22483590 dezicycles in lut, 1 runs, 0 skips 16486965 dezicycles in lut, 2 runs, 0 skips 14703345 dezicycles in lut, 4 runs, 0 skips 13340126 dezicycles in lut, 8 runs, 0 skips 14286336 dezicycles in lut, 16 runs, 0 skips 17345394 dezicycles in lut, 32 runs, 0 skips 18178503 dezicycles in lut, 64 runs, 0 skips 18047690 dezicycles in lut, 128 runs, 0 skips 18159589 dezicycles in lut, 256 runs, 0 skips 17833263 dezicycles in lut, 512 runs, 0 skips 17624724 dezicycles in lut, 1024 runs, 0 skips 17303343 dezicycles in lut, 2048 runs, 0 skips
Updated (with some simplifications). [...]
I'll apply in few days if there are no more comments.
There should be a vf_lut.c that does generic LUT based filtering and vf_negate should use that filter
Do you mean apply_lut in libmpcodecs/vf_eq2.c? Why not to implement some lut in libmpcodecs/vf_geq.c? -- FFmpeg = Fierce Fanciful Marvellous Peaceless Extended Gadget
On Thu, Dec 02, 2010 at 11:18:44PM +0100, Stefano Sabatini wrote:
On date Thursday 2010-12-02 22:55:24 +0100, Michael Niedermayer encoded:
On Thu, Dec 02, 2010 at 08:45:24PM +0100, Stefano Sabatini wrote:
On date Wednesday 2010-12-01 20:57:19 +0100, Stefano Sabatini encoded:
On date Wednesday 2010-12-01 03:25:47 +0100, Michael Niedermayer encoded:
On Tue, Nov 30, 2010 at 11:22:43PM +0100, Stefano Sabatini wrote:
> From 3c16bf49c0f9f4c3c72d9eea49ae35a47d58d961 Mon Sep 17 00:00:00 2001 > From: Stefano Sabatini <stefano.sabatini-lala at poste.it> > Date: Fri, 26 Nov 2010 17:31:11 +0100 > Subject: [PATCH] Add negate filter. > > Ported from the libavfilter-soc repo with per-component negation > addition. > --- > doc/filters.texi | 22 ++++++ > libavfilter/Makefile | 1 + > libavfilter/allfilters.c | 1 + > libavfilter/vf_negate.c | 184 ++++++++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 208 insertions(+), 0 deletions(-) > create mode 100644 libavfilter/vf_negate.c
I'll apply in three days unless objections.
is it faster than using a LUT ?
32246490 dezicycles in nolut, 1 runs, 0 skips 27420150 dezicycles in nolut, 2 runs, 0 skips 29323650 dezicycles in nolut, 4 runs, 0 skips 36039801 dezicycles in nolut, 8 runs, 0 skips 34124634 dezicycles in nolut, 16 runs, 0 skips 39557091 dezicycles in nolut, 32 runs, 0 skips 37006964 dezicycles in nolut, 64 runs, 0 skips 37271243 dezicycles in nolut, 128 runs, 0 skips 36437873 dezicycles in nolut, 256 runs, 0 skips 37591370 dezicycles in nolut, 512 runs, 0 skips 37119779 dezicycles in nolut, 1024 runs, 0 skips 37390082 dezicycles in nolut, 2048 runs, 0 skips
22483590 dezicycles in lut, 1 runs, 0 skips 16486965 dezicycles in lut, 2 runs, 0 skips 14703345 dezicycles in lut, 4 runs, 0 skips 13340126 dezicycles in lut, 8 runs, 0 skips 14286336 dezicycles in lut, 16 runs, 0 skips 17345394 dezicycles in lut, 32 runs, 0 skips 18178503 dezicycles in lut, 64 runs, 0 skips 18047690 dezicycles in lut, 128 runs, 0 skips 18159589 dezicycles in lut, 256 runs, 0 skips 17833263 dezicycles in lut, 512 runs, 0 skips 17624724 dezicycles in lut, 1024 runs, 0 skips 17303343 dezicycles in lut, 2048 runs, 0 skips
Updated (with some simplifications). [...]
I'll apply in few days if there are no more comments.
There should be a vf_lut.c that does generic LUT based filtering and vf_negate should use that filter
Do you mean apply_lut in libmpcodecs/vf_eq2.c? Why not to implement some lut in libmpcodecs/vf_geq.c?
We need a generic LUT filter, aka specify LUT entries and filter each pixel We need a generic expression filter this is not implementable as LUT as the filter can use any pixels from the input frame not just a 8bit sample but like several megabytes. 2^(2^20) is too big for a LUT filters like eq and negate should then use vf_lut.c [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Those who are too smart to engage in politics are punished by being governed by those who are dumber. -- Plato
On Thu, Dec 2, 2010 at 3:08 PM, Michael Niedermayer <michaelni at gmx.at> wrote:
On Thu, Dec 02, 2010 at 11:18:44PM +0100, Stefano Sabatini wrote:
On date Thursday 2010-12-02 22:55:24 +0100, Michael Niedermayer encoded:
On Thu, Dec 02, 2010 at 08:45:24PM +0100, Stefano Sabatini wrote:
On date Wednesday 2010-12-01 20:57:19 +0100, Stefano Sabatini encoded:
On date Wednesday 2010-12-01 03:25:47 +0100, Michael Niedermayer encoded:
On Tue, Nov 30, 2010 at 11:22:43PM +0100, Stefano Sabatini wrote: > > From 3c16bf49c0f9f4c3c72d9eea49ae35a47d58d961 Mon Sep 17 00:00:00 2001 > > From: Stefano Sabatini <stefano.sabatini-lala at poste.it> > > Date: Fri, 26 Nov 2010 17:31:11 +0100 > > Subject: [PATCH] Add negate filter. > > > > Ported from the libavfilter-soc repo with per-component negation > > addition. > > --- > > ?doc/filters.texi ? ? ? ? | ? 22 ++++++ > > ?libavfilter/Makefile ? ? | ? ?1 + > > ?libavfilter/allfilters.c | ? ?1 + > > ?libavfilter/vf_negate.c ?| ?184 ++++++++++++++++++++++++++++++++++++++++++++++ > > ?4 files changed, 208 insertions(+), 0 deletions(-) > > ?create mode 100644 libavfilter/vf_negate.c > > I'll apply in three days unless objections.
is it faster than using a LUT ?
32246490 dezicycles in nolut, 1 runs, 0 skips 27420150 dezicycles in nolut, 2 runs, 0 skips 29323650 dezicycles in nolut, 4 runs, 0 skips 36039801 dezicycles in nolut, 8 runs, 0 skips 34124634 dezicycles in nolut, 16 runs, 0 skips 39557091 dezicycles in nolut, 32 runs, 0 skips 37006964 dezicycles in nolut, 64 runs, 0 skips 37271243 dezicycles in nolut, 128 runs, 0 skips 36437873 dezicycles in nolut, 256 runs, 0 skips 37591370 dezicycles in nolut, 512 runs, 0 skips 37119779 dezicycles in nolut, 1024 runs, 0 skips 37390082 dezicycles in nolut, 2048 runs, 0 skips
22483590 dezicycles in lut, 1 runs, 0 skips 16486965 dezicycles in lut, 2 runs, 0 skips 14703345 dezicycles in lut, 4 runs, 0 skips 13340126 dezicycles in lut, 8 runs, 0 skips 14286336 dezicycles in lut, 16 runs, 0 skips 17345394 dezicycles in lut, 32 runs, 0 skips 18178503 dezicycles in lut, 64 runs, 0 skips 18047690 dezicycles in lut, 128 runs, 0 skips 18159589 dezicycles in lut, 256 runs, 0 skips 17833263 dezicycles in lut, 512 runs, 0 skips 17624724 dezicycles in lut, 1024 runs, 0 skips 17303343 dezicycles in lut, 2048 runs, 0 skips
Updated (with some simplifications). [...]
I'll apply in few days if there are no more comments.
There should be a vf_lut.c that does generic LUT based filtering and vf_negate should use that filter
Do you mean apply_lut in libmpcodecs/vf_eq2.c? Why not to implement some lut in libmpcodecs/vf_geq.c?
We need a generic LUT filter, aka specify LUT entries and filter each pixel
We need a generic expression filter this is not implementable as LUT as the filter can use any pixels from the input frame not just a 8bit sample but like several megabytes. 2^(2^20) is too big for a LUT
See mt_lut for a good existing implementation (in Avisynth Masktools). They have both a 1D and 2D LUT (obviously not a 3D one, for the reason you mentioned). Though, to be fair, for complex expressions, a 3D LUT might still be better than an expression filter. Jason
On Dec 2, 2010, at 6:38 PM, Jason Garrett-Glaser wrote:
On Thu, Dec 2, 2010 at 3:08 PM, Michael Niedermayer <michaelni at gmx.at> wrote:
On Thu, Dec 02, 2010 at 11:18:44PM +0100, Stefano Sabatini wrote:
On date Thursday 2010-12-02 22:55:24 +0100, Michael Niedermayer encoded:
On Thu, Dec 02, 2010 at 08:45:24PM +0100, Stefano Sabatini wrote:
On date Wednesday 2010-12-01 20:57:19 +0100, Stefano Sabatini encoded:
On date Wednesday 2010-12-01 03:25:47 +0100, Michael Niedermayer encoded: > On Tue, Nov 30, 2010 at 11:22:43PM +0100, Stefano Sabatini wrote: >>> From 3c16bf49c0f9f4c3c72d9eea49ae35a47d58d961 Mon Sep 17 00:00:00 2001 >>> From: Stefano Sabatini <stefano.sabatini-lala at poste.it> >>> Date: Fri, 26 Nov 2010 17:31:11 +0100 >>> Subject: [PATCH] Add negate filter. >>> >>> Ported from the libavfilter-soc repo with per-component negation >>> addition. >>> --- >>> doc/filters.texi | 22 ++++++ >>> libavfilter/Makefile | 1 + >>> libavfilter/allfilters.c | 1 + >>> libavfilter/vf_negate.c | 184 ++++++++++++++++++++++++++++++++++++++++++++++ >>> 4 files changed, 208 insertions(+), 0 deletions(-) >>> create mode 100644 libavfilter/vf_negate.c >> >> I'll apply in three days unless objections. > > is it faster than using a LUT ?
32246490 dezicycles in nolut, 1 runs, 0 skips 27420150 dezicycles in nolut, 2 runs, 0 skips 29323650 dezicycles in nolut, 4 runs, 0 skips 36039801 dezicycles in nolut, 8 runs, 0 skips 34124634 dezicycles in nolut, 16 runs, 0 skips 39557091 dezicycles in nolut, 32 runs, 0 skips 37006964 dezicycles in nolut, 64 runs, 0 skips 37271243 dezicycles in nolut, 128 runs, 0 skips 36437873 dezicycles in nolut, 256 runs, 0 skips 37591370 dezicycles in nolut, 512 runs, 0 skips 37119779 dezicycles in nolut, 1024 runs, 0 skips 37390082 dezicycles in nolut, 2048 runs, 0 skips
22483590 dezicycles in lut, 1 runs, 0 skips 16486965 dezicycles in lut, 2 runs, 0 skips 14703345 dezicycles in lut, 4 runs, 0 skips 13340126 dezicycles in lut, 8 runs, 0 skips 14286336 dezicycles in lut, 16 runs, 0 skips 17345394 dezicycles in lut, 32 runs, 0 skips 18178503 dezicycles in lut, 64 runs, 0 skips 18047690 dezicycles in lut, 128 runs, 0 skips 18159589 dezicycles in lut, 256 runs, 0 skips 17833263 dezicycles in lut, 512 runs, 0 skips 17624724 dezicycles in lut, 1024 runs, 0 skips 17303343 dezicycles in lut, 2048 runs, 0 skips
Updated (with some simplifications). [...]
I'll apply in few days if there are no more comments.
There should be a vf_lut.c that does generic LUT based filtering and vf_negate should use that filter
Do you mean apply_lut in libmpcodecs/vf_eq2.c? Why not to implement some lut in libmpcodecs/vf_geq.c?
We need a generic LUT filter, aka specify LUT entries and filter each pixel
We need a generic expression filter this is not implementable as LUT as the filter can use any pixels from the input frame not just a 8bit sample but like several megabytes. 2^(2^20) is too big for a LUT
See mt_lut for a good existing implementation (in Avisynth Masktools). They have both a 1D and 2D LUT (obviously not a 3D one, for the reason you mentioned).
Though, to be fair, for complex expressions, a 3D LUT might still be better than an expression filter.
http://manao4.free.fr/masktools-v2.0a46.zip Note that, being an AviSynth filter, it's C++/MSVC asm/GPL.
On Thu, Dec 2, 2010 at 3:38 PM, Jason Garrett-Glaser <jason at x264.com> wrote:
On Thu, Dec 2, 2010 at 3:08 PM, Michael Niedermayer <michaelni at gmx.at> wrote:
On Thu, Dec 02, 2010 at 11:18:44PM +0100, Stefano Sabatini wrote:
On date Thursday 2010-12-02 22:55:24 +0100, Michael Niedermayer encoded:
On Thu, Dec 02, 2010 at 08:45:24PM +0100, Stefano Sabatini wrote:
On date Wednesday 2010-12-01 20:57:19 +0100, Stefano Sabatini encoded:
On date Wednesday 2010-12-01 03:25:47 +0100, Michael Niedermayer encoded: > On Tue, Nov 30, 2010 at 11:22:43PM +0100, Stefano Sabatini wrote: > > > From 3c16bf49c0f9f4c3c72d9eea49ae35a47d58d961 Mon Sep 17 00:00:00 2001 > > > From: Stefano Sabatini <stefano.sabatini-lala at poste.it> > > > Date: Fri, 26 Nov 2010 17:31:11 +0100 > > > Subject: [PATCH] Add negate filter. > > > > > > Ported from the libavfilter-soc repo with per-component negation > > > addition. > > > --- > > > ?doc/filters.texi ? ? ? ? | ? 22 ++++++ > > > ?libavfilter/Makefile ? ? | ? ?1 + > > > ?libavfilter/allfilters.c | ? ?1 + > > > ?libavfilter/vf_negate.c ?| ?184 ++++++++++++++++++++++++++++++++++++++++++++++ > > > ?4 files changed, 208 insertions(+), 0 deletions(-) > > > ?create mode 100644 libavfilter/vf_negate.c > > > > I'll apply in three days unless objections. > > is it faster than using a LUT ?
32246490 dezicycles in nolut, 1 runs, 0 skips 27420150 dezicycles in nolut, 2 runs, 0 skips 29323650 dezicycles in nolut, 4 runs, 0 skips 36039801 dezicycles in nolut, 8 runs, 0 skips 34124634 dezicycles in nolut, 16 runs, 0 skips 39557091 dezicycles in nolut, 32 runs, 0 skips 37006964 dezicycles in nolut, 64 runs, 0 skips 37271243 dezicycles in nolut, 128 runs, 0 skips 36437873 dezicycles in nolut, 256 runs, 0 skips 37591370 dezicycles in nolut, 512 runs, 0 skips 37119779 dezicycles in nolut, 1024 runs, 0 skips 37390082 dezicycles in nolut, 2048 runs, 0 skips
22483590 dezicycles in lut, 1 runs, 0 skips 16486965 dezicycles in lut, 2 runs, 0 skips 14703345 dezicycles in lut, 4 runs, 0 skips 13340126 dezicycles in lut, 8 runs, 0 skips 14286336 dezicycles in lut, 16 runs, 0 skips 17345394 dezicycles in lut, 32 runs, 0 skips 18178503 dezicycles in lut, 64 runs, 0 skips 18047690 dezicycles in lut, 128 runs, 0 skips 18159589 dezicycles in lut, 256 runs, 0 skips 17833263 dezicycles in lut, 512 runs, 0 skips 17624724 dezicycles in lut, 1024 runs, 0 skips 17303343 dezicycles in lut, 2048 runs, 0 skips
Updated (with some simplifications). [...]
I'll apply in few days if there are no more comments.
There should be a vf_lut.c that does generic LUT based filtering and vf_negate should use that filter
Do you mean apply_lut in libmpcodecs/vf_eq2.c? Why not to implement some lut in libmpcodecs/vf_geq.c?
We need a generic LUT filter, aka specify LUT entries and filter each pixel
We need a generic expression filter this is not implementable as LUT as the filter can use any pixels from the input frame not just a 8bit sample but like several megabytes. 2^(2^20) is too big for a LUT
See mt_lut for a good existing implementation (in Avisynth Masktools). ?They have both a 1D and 2D LUT (obviously not a 3D one, for the reason you mentioned).
Though, to be fair, for complex expressions, a 3D LUT might still be better than an expression filter.
Jason
Also, you can interpolate a LUT, so it doesn't have to be a full 2^24 entries. Jason
On Thu, Dec 02, 2010 at 03:38:21PM -0800, Jason Garrett-Glaser wrote:
On Thu, Dec 2, 2010 at 3:08 PM, Michael Niedermayer <michaelni at gmx.at> wrote:
On Thu, Dec 02, 2010 at 11:18:44PM +0100, Stefano Sabatini wrote:
On date Thursday 2010-12-02 22:55:24 +0100, Michael Niedermayer encoded:
On Thu, Dec 02, 2010 at 08:45:24PM +0100, Stefano Sabatini wrote:
On date Wednesday 2010-12-01 20:57:19 +0100, Stefano Sabatini encoded:
On date Wednesday 2010-12-01 03:25:47 +0100, Michael Niedermayer encoded: > On Tue, Nov 30, 2010 at 11:22:43PM +0100, Stefano Sabatini wrote: > > > From 3c16bf49c0f9f4c3c72d9eea49ae35a47d58d961 Mon Sep 17 00:00:00 2001 > > > From: Stefano Sabatini <stefano.sabatini-lala at poste.it> > > > Date: Fri, 26 Nov 2010 17:31:11 +0100 > > > Subject: [PATCH] Add negate filter. > > > > > > Ported from the libavfilter-soc repo with per-component negation > > > addition. > > > --- > > > ?doc/filters.texi ? ? ? ? | ? 22 ++++++ > > > ?libavfilter/Makefile ? ? | ? ?1 + > > > ?libavfilter/allfilters.c | ? ?1 + > > > ?libavfilter/vf_negate.c ?| ?184 ++++++++++++++++++++++++++++++++++++++++++++++ > > > ?4 files changed, 208 insertions(+), 0 deletions(-) > > > ?create mode 100644 libavfilter/vf_negate.c > > > > I'll apply in three days unless objections. > > is it faster than using a LUT ?
32246490 dezicycles in nolut, 1 runs, 0 skips 27420150 dezicycles in nolut, 2 runs, 0 skips 29323650 dezicycles in nolut, 4 runs, 0 skips 36039801 dezicycles in nolut, 8 runs, 0 skips 34124634 dezicycles in nolut, 16 runs, 0 skips 39557091 dezicycles in nolut, 32 runs, 0 skips 37006964 dezicycles in nolut, 64 runs, 0 skips 37271243 dezicycles in nolut, 128 runs, 0 skips 36437873 dezicycles in nolut, 256 runs, 0 skips 37591370 dezicycles in nolut, 512 runs, 0 skips 37119779 dezicycles in nolut, 1024 runs, 0 skips 37390082 dezicycles in nolut, 2048 runs, 0 skips
22483590 dezicycles in lut, 1 runs, 0 skips 16486965 dezicycles in lut, 2 runs, 0 skips 14703345 dezicycles in lut, 4 runs, 0 skips 13340126 dezicycles in lut, 8 runs, 0 skips 14286336 dezicycles in lut, 16 runs, 0 skips 17345394 dezicycles in lut, 32 runs, 0 skips 18178503 dezicycles in lut, 64 runs, 0 skips 18047690 dezicycles in lut, 128 runs, 0 skips 18159589 dezicycles in lut, 256 runs, 0 skips 17833263 dezicycles in lut, 512 runs, 0 skips 17624724 dezicycles in lut, 1024 runs, 0 skips 17303343 dezicycles in lut, 2048 runs, 0 skips
Updated (with some simplifications). [...]
I'll apply in few days if there are no more comments.
There should be a vf_lut.c that does generic LUT based filtering and vf_negate should use that filter
Do you mean apply_lut in libmpcodecs/vf_eq2.c? Why not to implement some lut in libmpcodecs/vf_geq.c?
We need a generic LUT filter, aka specify LUT entries and filter each pixel
We need a generic expression filter this is not implementable as LUT as the filter can use any pixels from the input frame not just a 8bit sample but like several megabytes. 2^(2^20) is too big for a LUT
See mt_lut for a good existing implementation (in Avisynth Masktools). They have both a 1D and 2D LUT (obviously not a 3D one, for the reason you mentioned).
Though, to be fair, for complex expressions, a 3D LUT might still be better than an expression filter.
the expression filter has been used to draw mandelbrot fractals, to texture map videos onto moving polygons and other things i forgot. a LUT is a good idea because its a hell alot faster but theres alot for which a generic expression evaluator is needed. [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Observe your enemies, for they first find out your faults. -- Antisthenes
On date Friday 2010-12-03 02:04:47 +0100, Michael Niedermayer encoded:
On Thu, Dec 02, 2010 at 03:38:21PM -0800, Jason Garrett-Glaser wrote:
On Thu, Dec 2, 2010 at 3:08 PM, Michael Niedermayer <michaelni at gmx.at> wrote:
On Thu, Dec 02, 2010 at 11:18:44PM +0100, Stefano Sabatini wrote:
On date Thursday 2010-12-02 22:55:24 +0100, Michael Niedermayer encoded:
On Thu, Dec 02, 2010 at 08:45:24PM +0100, Stefano Sabatini wrote:
On date Wednesday 2010-12-01 20:57:19 +0100, Stefano Sabatini encoded: > On date Wednesday 2010-12-01 03:25:47 +0100, Michael Niedermayer encoded: > > On Tue, Nov 30, 2010 at 11:22:43PM +0100, Stefano Sabatini wrote: > > > > From 3c16bf49c0f9f4c3c72d9eea49ae35a47d58d961 Mon Sep 17 00:00:00 2001 > > > > From: Stefano Sabatini <stefano.sabatini-lala at poste.it> > > > > Date: Fri, 26 Nov 2010 17:31:11 +0100 > > > > Subject: [PATCH] Add negate filter. > > > > > > > > Ported from the libavfilter-soc repo with per-component negation > > > > addition. > > > > --- > > > > ?doc/filters.texi ? ? ? ? | ? 22 ++++++ > > > > ?libavfilter/Makefile ? ? | ? ?1 + > > > > ?libavfilter/allfilters.c | ? ?1 + > > > > ?libavfilter/vf_negate.c ?| ?184 ++++++++++++++++++++++++++++++++++++++++++++++ > > > > ?4 files changed, 208 insertions(+), 0 deletions(-) > > > > ?create mode 100644 libavfilter/vf_negate.c > > > > > > I'll apply in three days unless objections. > > > > is it faster than using a LUT ? > > 32246490 dezicycles in nolut, 1 runs, 0 skips > 27420150 dezicycles in nolut, 2 runs, 0 skips > 29323650 dezicycles in nolut, 4 runs, 0 skips > 36039801 dezicycles in nolut, 8 runs, 0 skips > 34124634 dezicycles in nolut, 16 runs, 0 skips > 39557091 dezicycles in nolut, 32 runs, 0 skips > 37006964 dezicycles in nolut, 64 runs, 0 skips > 37271243 dezicycles in nolut, 128 runs, 0 skips > 36437873 dezicycles in nolut, 256 runs, 0 skips > 37591370 dezicycles in nolut, 512 runs, 0 skips > 37119779 dezicycles in nolut, 1024 runs, 0 skips > 37390082 dezicycles in nolut, 2048 runs, 0 skips > > 22483590 dezicycles in lut, 1 runs, 0 skips > 16486965 dezicycles in lut, 2 runs, 0 skips > 14703345 dezicycles in lut, 4 runs, 0 skips > 13340126 dezicycles in lut, 8 runs, 0 skips > 14286336 dezicycles in lut, 16 runs, 0 skips > 17345394 dezicycles in lut, 32 runs, 0 skips > 18178503 dezicycles in lut, 64 runs, 0 skips > 18047690 dezicycles in lut, 128 runs, 0 skips > 18159589 dezicycles in lut, 256 runs, 0 skips > 17833263 dezicycles in lut, 512 runs, 0 skips > 17624724 dezicycles in lut, 1024 runs, 0 skips > 17303343 dezicycles in lut, 2048 runs, 0 skips > > Updated (with some simplifications). [...]
I'll apply in few days if there are no more comments.
There should be a vf_lut.c that does generic LUT based filtering and vf_negate should use that filter
Do you mean apply_lut in libmpcodecs/vf_eq2.c? Why not to implement some lut in libmpcodecs/vf_geq.c?
We need a generic LUT filter, aka specify LUT entries and filter each pixel
We need a generic expression filter this is not implementable as LUT as the filter can use any pixels from the input frame not just a 8bit sample but like several megabytes. 2^(2^20) is too big for a LUT
See mt_lut for a good existing implementation (in Avisynth Masktools). They have both a 1D and 2D LUT (obviously not a 3D one, for the reason you mentioned).
Though, to be fair, for complex expressions, a 3D LUT might still be better than an expression filter.
the expression filter has been used to draw mandelbrot fractals, to texture map videos onto moving polygons and other things i forgot. a LUT is a good idea because its a hell alot faster but theres alot for which a generic expression evaluator is needed.
Here it is a first scratch. This should be equivalent to the negate filter: lut='y=maxv+minv-v:u=maxv+minv-v:v=maxv+minv-v' (now I see that maybe 'v' was not a good choice for the input value). it should be also possible to "wrap" a negate filter around this by simply implementing a negate_init() function (but still lacks support for monow/monob). So having native support for monow/monob is the only reason for keeping the negate filter, but maybe I can conceive some way to support bitstream formats. -- FFmpeg = Foolish Formidable Miracolous Philosophical Enhanced Gangster
On date Friday 2010-12-03 13:02:59 +0100, Stefano Sabatini wrote:
On date Friday 2010-12-03 02:04:47 +0100, Michael Niedermayer encoded: [...]
the expression filter has been used to draw mandelbrot fractals, to texture map videos onto moving polygons and other things i forgot. a LUT is a good idea because its a hell alot faster but theres alot for which a generic expression evaluator is needed.
Here it is a first scratch.
This should be equivalent to the negate filter: lut='y=maxv+minv-v:u=maxv+minv-v:v=maxv+minv-v'
(now I see that maybe 'v' was not a good choice for the input value).
it should be also possible to "wrap" a negate filter around this by simply implementing a negate_init() function (but still lacks support for monow/monob).
So having native support for monow/monob is the only reason for keeping the negate filter, but maybe I can conceive some way to support bitstream formats. -- FFmpeg = Foolish Formidable Miracolous Philosophical Enhanced Gangster
From ecda1bb4846754d2a651d2c80414563d7a9e19a7 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <stefano.sabatini-lala@poste.it> Date: Fri, 3 Dec 2010 12:45:29 +0100 Subject: [PATCH] Implement lut filter.
Updated with RGB support and an example negate filter. Still missing documentation.
On date Saturday 2011-05-28 23:04:07 +0200, Stefano Sabatini encoded:
On date Friday 2010-12-03 13:02:59 +0100, Stefano Sabatini wrote:
On date Friday 2010-12-03 02:04:47 +0100, Michael Niedermayer encoded: [...]
the expression filter has been used to draw mandelbrot fractals, to texture map videos onto moving polygons and other things i forgot. a LUT is a good idea because its a hell alot faster but theres alot for which a generic expression evaluator is needed.
Here it is a first scratch.
This should be equivalent to the negate filter: lut='y=maxv+minv-v:u=maxv+minv-v:v=maxv+minv-v'
(now I see that maybe 'v' was not a good choice for the input value).
it should be also possible to "wrap" a negate filter around this by simply implementing a negate_init() function (but still lacks support for monow/monob).
So having native support for monow/monob is the only reason for keeping the negate filter, but maybe I can conceive some way to support bitstream formats. -- FFmpeg = Foolish Formidable Miracolous Philosophical Enhanced Gangster
From ecda1bb4846754d2a651d2c80414563d7a9e19a7 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <stefano.sabatini-lala@poste.it> Date: Fri, 3 Dec 2010 12:45:29 +0100 Subject: [PATCH] Implement lut filter.
Updated with RGB support and an example negate filter.
Still missing documentation.
From c16e66a58668cdbb863ce4ecf2eb3ff52fb7c670 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <stefano.sabatini-lala@poste.it> Date: Sat, 28 May 2011 21:51:03 +0200 Subject: [PATCH] lavfi: add LUT (LookUp Table) YUV and RGB generic filters
--- libavfilter/Makefile | 2 + libavfilter/allfilters.c | 2 + libavfilter/vf_lut.c | 313 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 317 insertions(+), 0 deletions(-) create mode 100644 libavfilter/vf_lut.c
Any comments on this? -- FFmpeg = Fostering and Furious Minimalistic Pitiless Enhanced Glue
On 28/05/11 22:04, Stefano Sabatini wrote:
+ switch (inlink->format) { + case PIX_FMT_YUV444P: + case PIX_FMT_YUV422P: + case PIX_FMT_YUV420P: + case PIX_FMT_YUV440P: + min_range[Y] = + min_range[U] = min_range[V] = 16; + max_range[Y] = 240; + max_range[U] = max_range[V] = 235; + break;
Confused. I expected Y to be 16-235 and U&V to be 16-240, not the other way round. -- Mark
On Sat, May 28, 2011 at 11:04:07PM +0200, Stefano Sabatini wrote:
On date Friday 2010-12-03 13:02:59 +0100, Stefano Sabatini wrote:
On date Friday 2010-12-03 02:04:47 +0100, Michael Niedermayer encoded: [...]
the expression filter has been used to draw mandelbrot fractals, to texture map videos onto moving polygons and other things i forgot. a LUT is a good idea because its a hell alot faster but theres alot for which a generic expression evaluator is needed.
Here it is a first scratch.
This should be equivalent to the negate filter: lut='y=maxv+minv-v:u=maxv+minv-v:v=maxv+minv-v'
(now I see that maybe 'v' was not a good choice for the input value).
it should be also possible to "wrap" a negate filter around this by simply implementing a negate_init() function (but still lacks support for monow/monob).
So having native support for monow/monob is the only reason for keeping the negate filter, but maybe I can conceive some way to support bitstream formats. -- FFmpeg = Foolish Formidable Miracolous Philosophical Enhanced Gangster
From ecda1bb4846754d2a651d2c80414563d7a9e19a7 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <stefano.sabatini-lala@poste.it> Date: Fri, 3 Dec 2010 12:45:29 +0100 Subject: [PATCH] Implement lut filter.
Updated with RGB support and an example negate filter.
Still missing documentation.
patches look good except what has been already mentioned. Also support for 9/10/...bit could be added later and great work! [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Old school: Use the lowest level language in which you can solve the problem conveniently. New school: Use the highest level language in which the latest supercomputer can solve the problem without the user falling asleep waiting.
On date Sunday 2011-06-05 22:31:43 +0200, Michael Niedermayer encoded:
On Sat, May 28, 2011 at 11:04:07PM +0200, Stefano Sabatini wrote: [...]
From ecda1bb4846754d2a651d2c80414563d7a9e19a7 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <stefano.sabatini-lala@poste.it> Date: Fri, 3 Dec 2010 12:45:29 +0100 Subject: [PATCH] Implement lut filter.
Updated with RGB support and an example negate filter.
Still missing documentation.
patches look good except what has been already mentioned.
Fixed the YUV range issue spotted by Mark, and added documentation. I'll apply in a few days if I see no more comments.
Also support for 9/10/...bit could be added later
and great work!
:) -- FFmpeg = Fascinating & Faithful Mean Philosofic Evangelical Gigant
On date Monday 2011-06-06 12:25:12 +0200, Stefano Sabatini encoded:
On date Sunday 2011-06-05 22:31:43 +0200, Michael Niedermayer encoded:
On Sat, May 28, 2011 at 11:04:07PM +0200, Stefano Sabatini wrote: [...]
From ecda1bb4846754d2a651d2c80414563d7a9e19a7 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <stefano.sabatini-lala@poste.it> Date: Fri, 3 Dec 2010 12:45:29 +0100 Subject: [PATCH] Implement lut filter.
Updated with RGB support and an example negate filter.
Still missing documentation.
patches look good except what has been already mentioned.
Fixed the YUV range issue spotted by Mark, and added documentation.
I'll apply in a few days if I see no more comments.
Also support for 9/10/...bit could be added later
and great work!
:)
Updated with a few fixes, now that I understood why pow was not working I'm trying to see how I can implement a gamma correction filter with it... -- FFmpeg = Fascinating and Formidable Multimedia Puritan Ecumenical God
On date Monday 2011-06-06 15:07:35 +0200, Stefano Sabatini encoded:
On date Monday 2011-06-06 12:25:12 +0200, Stefano Sabatini encoded:
On date Sunday 2011-06-05 22:31:43 +0200, Michael Niedermayer encoded:
On Sat, May 28, 2011 at 11:04:07PM +0200, Stefano Sabatini wrote: [...]
From ecda1bb4846754d2a651d2c80414563d7a9e19a7 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <stefano.sabatini-lala@poste.it> Date: Fri, 3 Dec 2010 12:45:29 +0100 Subject: [PATCH] Implement lut filter.
Updated with RGB support and an example negate filter.
Still missing documentation.
patches look good except what has been already mentioned.
Fixed the YUV range issue spotted by Mark, and added documentation.
I'll apply in a few days if I see no more comments.
Also support for 9/10/...bit could be added later
and great work!
:)
Updated with a few fixes, now that I understood why pow was not working I'm trying to see how I can implement a gamma correction filter with it...
lutyuv="y=pow((val-minval)/(maxval-minval)\,gamma)*(maxval-minval)+minval" ? -- FFmpeg = Frightening and Fundamental Mind-dumbing Philosophical Extravagant Glue
On Mon, Jun 06, 2011 at 03:31:47PM +0200, Stefano Sabatini wrote:
On date Monday 2011-06-06 15:07:35 +0200, Stefano Sabatini encoded:
On date Monday 2011-06-06 12:25:12 +0200, Stefano Sabatini encoded:
On date Sunday 2011-06-05 22:31:43 +0200, Michael Niedermayer encoded:
On Sat, May 28, 2011 at 11:04:07PM +0200, Stefano Sabatini wrote: [...]
From ecda1bb4846754d2a651d2c80414563d7a9e19a7 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <stefano.sabatini-lala@poste.it> Date: Fri, 3 Dec 2010 12:45:29 +0100 Subject: [PATCH] Implement lut filter.
Updated with RGB support and an example negate filter.
Still missing documentation.
patches look good except what has been already mentioned.
Fixed the YUV range issue spotted by Mark, and added documentation.
I'll apply in a few days if I see no more comments.
Also support for 9/10/...bit could be added later
and great work!
:)
Updated with a few fixes, now that I understood why pow was not working I'm trying to see how I can implement a gamma correction filter with it...
lutyuv="y=pow((val-minval)/(maxval-minval)\,gamma)*(maxval-minval)+minval"
?
gamma correction should be done in rgb space. doing it in yuv with a 8bit lut is a approximation [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I have often repented speaking, but never of holding my tongue. -- Xenocrates
On date Monday 2011-06-06 19:32:04 +0200, Michael Niedermayer encoded:
On Mon, Jun 06, 2011 at 03:31:47PM +0200, Stefano Sabatini wrote:
On date Monday 2011-06-06 15:07:35 +0200, Stefano Sabatini encoded:
On date Monday 2011-06-06 12:25:12 +0200, Stefano Sabatini encoded:
On date Sunday 2011-06-05 22:31:43 +0200, Michael Niedermayer encoded:
On Sat, May 28, 2011 at 11:04:07PM +0200, Stefano Sabatini wrote: [...]
> From ecda1bb4846754d2a651d2c80414563d7a9e19a7 Mon Sep 17 00:00:00 2001 > From: Stefano Sabatini <stefano.sabatini-lala@poste.it> > Date: Fri, 3 Dec 2010 12:45:29 +0100 > Subject: [PATCH] Implement lut filter.
Updated with RGB support and an example negate filter.
Still missing documentation.
patches look good except what has been already mentioned.
Fixed the YUV range issue spotted by Mark, and added documentation.
I'll apply in a few days if I see no more comments.
Also support for 9/10/...bit could be added later
and great work!
:)
Updated with a few fixes, now that I understood why pow was not working I'm trying to see how I can implement a gamma correction filter with it...
lutyuv="y=pow((val-minval)/(maxval-minval)\,gamma)*(maxval-minval)+minval"
?
gamma correction should be done in rgb space. doing it in yuv with a 8bit lut is a approximation
Implemented more ideas, check attachments. The idea of the lut(yuv+rgb) filter comes from the consideration that a negate filter applies the same map to each component independently of the colorspace, so a colorspace conversion should be avoided. For the same reasons it could be useful to define a lut filter on the alpha component without forcing a conversion. I also developed the idea of the gamma correction, which is implemented through an eval function. -- FFmpeg = Fascinating and Furious Monstrous Pure Extreme Goblin
On 06/06/2011 20:42, Stefano Sabatini wrote:
+#define YUV_FORMATS \ + PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV420P, \ + PIX_FMT_YUV411P, PIX_FMT_YUV410P, \ + PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ420P, \ + PIX_FMT_YUV440P, PIX_FMT_YUVJ440P, \ + PIX_FMT_YUVA420P + +#define RGB_FORMATS \ + PIX_FMT_ARGB, PIX_FMT_RGBA, \ + PIX_FMT_ABGR, PIX_FMT_BGRA, \ + PIX_FMT_RGB24, PIX_FMT_BGR24 + [...] + switch (inlink->format) { + case PIX_FMT_YUV444P: + case PIX_FMT_YUV422P: + case PIX_FMT_YUV420P: + case PIX_FMT_YUV440P: + min[Y] = min[U] = min[V] = 16; + max[Y] = 235; + max[U] = max[V] = 240; + break; + default: + min[0] = min[1] = min[2] = min[3] = 0; + max[0] = max[1] = max[2] = max[3] = 255; + }
PIX_FMT_YUV411P, PIX_FMT_YUV410P & PIX_FMT_YUVA420P should also be 16-235 ?
+ lut->is_yuv = lut->is_rgb = 0; + if (pix_fmt_is_in(inlink->format, yuv_pix_fmts)) lut->is_yuv = 1; + else if (pix_fmt_is_in(inlink->format, rgb_pix_fmts)) lut->is_rgb = 1; + + if (lut->is_rgb) { + switch (inlink->format) { + case PIX_FMT_ARGB: lut->rgba_map[A] = 0; lut->rgba_map[R] = 1; lut->rgba_map[G] = 2; lut->rgba_map[B] = 3; break; + case PIX_FMT_ABGR: lut->rgba_map[A] = 0; lut->rgba_map[B] = 1; lut->rgba_map[G] = 2; lut->rgba_map[R] = 3; break; + case PIX_FMT_RGBA: + case PIX_FMT_RGB24: lut->rgba_map[R] = 0; lut->rgba_map[G] = 1; lut->rgba_map[B] = 2; lut->rgba_map[A] = 3; break; + case PIX_FMT_BGRA: + case PIX_FMT_BGR24: lut->rgba_map[B] = 0; lut->rgba_map[G] = 1; lut->rgba_map[R] = 2; lut->rgba_map[A] = 3; break; + } + lut->step = av_get_bits_per_pixel(desc)>> 3; + }
If only all of these attributes had been wrapped into a structure. By the way - this filter looks like it'll be very useful, but to avoid banding it would be good to be able to dither. -- Mark
On date Monday 2011-06-06 22:37:14 +0100, Mark Himsley encoded:
On 06/06/2011 20:42, Stefano Sabatini wrote:
+#define YUV_FORMATS \ + PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV420P, \ + PIX_FMT_YUV411P, PIX_FMT_YUV410P, \ + PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ420P, \ + PIX_FMT_YUV440P, PIX_FMT_YUVJ440P, \ + PIX_FMT_YUVA420P + +#define RGB_FORMATS \ + PIX_FMT_ARGB, PIX_FMT_RGBA, \ + PIX_FMT_ABGR, PIX_FMT_BGRA, \ + PIX_FMT_RGB24, PIX_FMT_BGR24 + [...] + switch (inlink->format) { + case PIX_FMT_YUV444P: + case PIX_FMT_YUV422P: + case PIX_FMT_YUV420P: + case PIX_FMT_YUV440P: + min[Y] = min[U] = min[V] = 16; + max[Y] = 235; + max[U] = max[V] = 240; + break; + default: + min[0] = min[1] = min[2] = min[3] = 0; + max[0] = max[1] = max[2] = max[3] = 255; + }
PIX_FMT_YUV411P, PIX_FMT_YUV410P & PIX_FMT_YUVA420P should also be 16-235 ?
Fixed.
+ lut->is_yuv = lut->is_rgb = 0; + if (pix_fmt_is_in(inlink->format, yuv_pix_fmts)) lut->is_yuv = 1; + else if (pix_fmt_is_in(inlink->format, rgb_pix_fmts)) lut->is_rgb = 1; + + if (lut->is_rgb) { + switch (inlink->format) { + case PIX_FMT_ARGB: lut->rgba_map[A] = 0; lut->rgba_map[R] = 1; lut->rgba_map[G] = 2; lut->rgba_map[B] = 3; break; + case PIX_FMT_ABGR: lut->rgba_map[A] = 0; lut->rgba_map[B] = 1; lut->rgba_map[G] = 2; lut->rgba_map[R] = 3; break; + case PIX_FMT_RGBA: + case PIX_FMT_RGB24: lut->rgba_map[R] = 0; lut->rgba_map[G] = 1; lut->rgba_map[B] = 2; lut->rgba_map[A] = 3; break; + case PIX_FMT_BGRA: + case PIX_FMT_BGR24: lut->rgba_map[B] = 0; lut->rgba_map[G] = 1; lut->rgba_map[R] = 2; lut->rgba_map[A] = 3; break; + } + lut->step = av_get_bits_per_pixel(desc)>> 3; + }
If only all of these attributes had been wrapped into a structure.
By the way - this filter looks like it'll be very useful, but to avoid banding it would be good to be able to dither.
Maybe a separate filter? -- FFmpeg = Foolish and Freak Meaningful Proud Extended Gymnast
On Mon, Jun 06, 2011 at 10:37:14PM +0100, Mark Himsley wrote:
On 06/06/2011 20:42, Stefano Sabatini wrote:
+#define YUV_FORMATS \ + PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV420P, \ + PIX_FMT_YUV411P, PIX_FMT_YUV410P, \ + PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ420P, \ + PIX_FMT_YUV440P, PIX_FMT_YUVJ440P, \ + PIX_FMT_YUVA420P + +#define RGB_FORMATS \ + PIX_FMT_ARGB, PIX_FMT_RGBA, \ + PIX_FMT_ABGR, PIX_FMT_BGRA, \ + PIX_FMT_RGB24, PIX_FMT_BGR24 + [...] + switch (inlink->format) { + case PIX_FMT_YUV444P: + case PIX_FMT_YUV422P: + case PIX_FMT_YUV420P: + case PIX_FMT_YUV440P: + min[Y] = min[U] = min[V] = 16; + max[Y] = 235; + max[U] = max[V] = 240; + break; + default: + min[0] = min[1] = min[2] = min[3] = 0; + max[0] = max[1] = max[2] = max[3] = 255; + }
PIX_FMT_YUV411P, PIX_FMT_YUV410P & PIX_FMT_YUVA420P should also be 16-235 ?
+ lut->is_yuv = lut->is_rgb = 0; + if (pix_fmt_is_in(inlink->format, yuv_pix_fmts)) lut->is_yuv = 1; + else if (pix_fmt_is_in(inlink->format, rgb_pix_fmts)) lut->is_rgb = 1; + + if (lut->is_rgb) { + switch (inlink->format) { + case PIX_FMT_ARGB: lut->rgba_map[A] = 0; lut->rgba_map[R] = 1; lut->rgba_map[G] = 2; lut->rgba_map[B] = 3; break; + case PIX_FMT_ABGR: lut->rgba_map[A] = 0; lut->rgba_map[B] = 1; lut->rgba_map[G] = 2; lut->rgba_map[R] = 3; break; + case PIX_FMT_RGBA: + case PIX_FMT_RGB24: lut->rgba_map[R] = 0; lut->rgba_map[G] = 1; lut->rgba_map[B] = 2; lut->rgba_map[A] = 3; break; + case PIX_FMT_BGRA: + case PIX_FMT_BGR24: lut->rgba_map[B] = 0; lut->rgba_map[G] = 1; lut->rgba_map[R] = 2; lut->rgba_map[A] = 3; break; + } + lut->step = av_get_bits_per_pixel(desc)>> 3; + }
If only all of these attributes had been wrapped into a structure.
By the way - this filter looks like it'll be very useful, but to avoid banding it would be good to be able to dither.
running the filter on 10+bits data which is then converted back to 8bit would do dither automatically also the input might need debanding any good denoise filter should remove banding (overcomplete wavelets come to mind) or gradfun could be used [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB In a rich man's house there is no place to spit but his face. -- Diogenes of Sinope
On 06/06/2011 20:42, Stefano Sabatini wrote:
+ /* compute the lut */ + lut->var_values[VAR_MAXVAL] = max[comp]; + lut->var_values[VAR_MINVAL] = min[comp]; + + for (val = 0; val < 256; val++) { + lut->var_values[VAR_VAL] = av_clip(val, min[comp], max[comp]); + lut->var_values[VAR_INVVAL] = + av_clip(min[comp] + max[comp] - lut->var_values[VAR_VAL], + min[comp], max[comp]); + + res = av_expr_eval(lut->comp_expr[comp], lut->var_values, lut); + if (isnan(res)) { + av_log(ctx, AV_LOG_ERROR, + "Error when evaluating the expression '%s' for the value %d for the component #%d.\n", + lut->comp_expr_str[comp], val, comp); + return AVERROR(EINVAL); + } + lut->lut[comp][val] = av_clip((int)res, min[comp], max[comp]); + av_log(ctx, AV_LOG_DEBUG, "val[%d][%d] = %d\n", comp, val, lut->lut[comp][val]); + }
Another thought - studio level video is allowed to have excursions below 'black' and above 'white'. Am I right in my understanding that this filter will clip at black and white? -- Mark
On date Tuesday 2011-06-07 08:32:37 +0100, Mark Himsley encoded:
On 06/06/2011 20:42, Stefano Sabatini wrote:
+ /* compute the lut */ + lut->var_values[VAR_MAXVAL] = max[comp]; + lut->var_values[VAR_MINVAL] = min[comp]; + + for (val = 0; val < 256; val++) { + lut->var_values[VAR_VAL] = av_clip(val, min[comp], max[comp]); + lut->var_values[VAR_INVVAL] = + av_clip(min[comp] + max[comp] - lut->var_values[VAR_VAL], + min[comp], max[comp]); + + res = av_expr_eval(lut->comp_expr[comp], lut->var_values, lut); + if (isnan(res)) { + av_log(ctx, AV_LOG_ERROR, + "Error when evaluating the expression '%s' for the value %d for the component #%d.\n", + lut->comp_expr_str[comp], val, comp); + return AVERROR(EINVAL); + } + lut->lut[comp][val] = av_clip((int)res, min[comp], max[comp]); + av_log(ctx, AV_LOG_DEBUG, "val[%d][%d] = %d\n", comp, val, lut->lut[comp][val]); + }
Another thought - studio level video is allowed to have excursions below 'black' and above 'white'. Am I right in my understanding that this filter will clip at black and white?
That's correct. I did it since that was resulting in artifacts for out-of-band values with gamma correction (this was resulting in negative gamma-corrected values for out-of-band values). We may find a better solution or disable clipping through an option. -- FFmpeg = Frenzy and Fascinating Mind-dumbing Practical Elected Game
On Tue, Jun 07, 2011 at 10:34:36AM +0200, Stefano Sabatini wrote:
On date Tuesday 2011-06-07 08:32:37 +0100, Mark Himsley encoded:
On 06/06/2011 20:42, Stefano Sabatini wrote:
+ /* compute the lut */ + lut->var_values[VAR_MAXVAL] = max[comp]; + lut->var_values[VAR_MINVAL] = min[comp]; + + for (val = 0; val < 256; val++) { + lut->var_values[VAR_VAL] = av_clip(val, min[comp], max[comp]); + lut->var_values[VAR_INVVAL] = + av_clip(min[comp] + max[comp] - lut->var_values[VAR_VAL], + min[comp], max[comp]); + + res = av_expr_eval(lut->comp_expr[comp], lut->var_values, lut); + if (isnan(res)) { + av_log(ctx, AV_LOG_ERROR, + "Error when evaluating the expression '%s' for the value %d for the component #%d.\n", + lut->comp_expr_str[comp], val, comp); + return AVERROR(EINVAL); + } + lut->lut[comp][val] = av_clip((int)res, min[comp], max[comp]); + av_log(ctx, AV_LOG_DEBUG, "val[%d][%d] = %d\n", comp, val, lut->lut[comp][val]); + }
Another thought - studio level video is allowed to have excursions below 'black' and above 'white'. Am I right in my understanding that this filter will clip at black and white?
That's correct. I did it since that was resulting in artifacts for out-of-band values with gamma correction (this was resulting in negative gamma-corrected values for out-of-band values). We may find a better solution or disable clipping through an option.
try sign(a)|a|^b instead of a^b [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Let us carefully observe those good qualities wherein our enemies excel us and endeavor to excel them, by avoiding what is faulty, and imitating what is excellent in them. -- Plutarch
On 7 Jun 2011, at 10:34, Stefano Sabatini <stefano.sabatini-lala@poste.it> wrote:
On date Tuesday 2011-06-07 08:32:37 +0100, Mark Himsley encoded:
On 06/06/2011 20:42, Stefano Sabatini wrote:
+ /* compute the lut */ + lut->var_values[VAR_MAXVAL] = max[comp]; + lut->var_values[VAR_MINVAL] = min[comp]; + + for (val = 0; val < 256; val++) { + lut->var_values[VAR_VAL] = av_clip(val, min[comp], max[comp]); + lut->var_values[VAR_INVVAL] = + av_clip(min[comp] + max[comp] - lut->var_values[VAR_VAL], + min[comp], max[comp]); + + res = av_expr_eval(lut->comp_expr[comp], lut->var_values, lut); + if (isnan(res)) { + av_log(ctx, AV_LOG_ERROR, + "Error when evaluating the expression '%s' for the value %d for the component #%d.\n", + lut->comp_expr_str[comp], val, comp); + return AVERROR(EINVAL); + } + lut->lut[comp][val] = av_clip((int)res, min[comp], max[comp]); + av_log(ctx, AV_LOG_DEBUG, "val[%d][%d] = %d\n", comp, val, lut->lut[comp][val]); + }
Another thought - studio level video is allowed to have excursions below 'black' and above 'white'. Am I right in my understanding that this filter will clip at black and white?
That's correct. I did it since that was resulting in artifacts for out-of-band values with gamma correction (this was resulting in negative gamma-corrected values for out-of-band values). We may find a better solution or disable clipping through an option.
Shouldn't it always be possible to have the clipping explicitly in the given formula? That would make that kind of implicit clipping just a pointless limitation of what can be done with the filter...
On date Tuesday 2011-06-07 18:16:43 +0200, Reimar Döffinger encoded:
On 7 Jun 2011, at 10:34, Stefano Sabatini <stefano.sabatini-lala@poste.it> wrote: [...]
Another thought - studio level video is allowed to have excursions below 'black' and above 'white'. Am I right in my understanding that this filter will clip at black and white?
That's correct. I did it since that was resulting in artifacts for out-of-band values with gamma correction (this was resulting in negative gamma-corrected values for out-of-band values). We may find a better solution or disable clipping through an option.
Shouldn't it always be possible to have the clipping explicitly in the given formula? That would make that kind of implicit clipping just a pointless limitation of what can be done with the filter...
Uhm maybe a clipval, but then we need to add a parameter to gammaval, it will then be gamma(clip(val), gamma) or gamma(val, gamma), and we may also want clip(expr), e.g. clip(gamma(clip(val), gamma)). But I also want to know how out-of-band values may be used (and I suppose FFmpeg may clip them anyway along the processing path). -- FFmpeg = Fantastic & Fancy Mastering Pitiless Elastic Gangster
On date Tuesday 2011-06-07 18:31:22 +0200, Stefano Sabatini encoded:
On date Tuesday 2011-06-07 18:16:43 +0200, Reimar Döffinger encoded:
On 7 Jun 2011, at 10:34, Stefano Sabatini <stefano.sabatini-lala@poste.it> wrote: [...]
Another thought - studio level video is allowed to have excursions below 'black' and above 'white'. Am I right in my understanding that this filter will clip at black and white?
That's correct. I did it since that was resulting in artifacts for out-of-band values with gamma correction (this was resulting in negative gamma-corrected values for out-of-band values). We may find a better solution or disable clipping through an option.
Shouldn't it always be possible to have the clipping explicitly in the given formula? That would make that kind of implicit clipping just a pointless limitation of what can be done with the filter...
Uhm maybe a clipval, but then we need to add a parameter to gammaval, it will then be gamma(clip(val), gamma) or gamma(val, gamma), and we may also want clip(expr), e.g. clip(gamma(clip(val), gamma)).
But I also want to know how out-of-band values may be used (and I suppose FFmpeg may clip them anyway along the processing path).
Updated, now the filter won't automatically clip the val in the valid range, but it's still possible to use clipval in the expression in case it is required. The gammaval and negval all use clipped values, the user need to specify explicitely non-clipping exression in case he needs. I'm going to push the filters in few days if I see no more comments. -- FFmpeg = Faithful and Fanciful Moronic Puritan Ecumenical Governor
On date Friday 2011-06-17 15:11:58 +0200, Stefano Sabatini encoded:
On date Tuesday 2011-06-07 18:31:22 +0200, Stefano Sabatini encoded:
On date Tuesday 2011-06-07 18:16:43 +0200, Reimar Döffinger encoded:
On 7 Jun 2011, at 10:34, Stefano Sabatini <stefano.sabatini-lala@poste.it> wrote: [...]
Another thought - studio level video is allowed to have excursions below 'black' and above 'white'. Am I right in my understanding that this filter will clip at black and white?
That's correct. I did it since that was resulting in artifacts for out-of-band values with gamma correction (this was resulting in negative gamma-corrected values for out-of-band values). We may find a better solution or disable clipping through an option.
Shouldn't it always be possible to have the clipping explicitly in the given formula? That would make that kind of implicit clipping just a pointless limitation of what can be done with the filter...
Uhm maybe a clipval, but then we need to add a parameter to gammaval, it will then be gamma(clip(val), gamma) or gamma(val, gamma), and we may also want clip(expr), e.g. clip(gamma(clip(val), gamma)).
But I also want to know how out-of-band values may be used (and I suppose FFmpeg may clip them anyway along the processing path).
Updated, now the filter won't automatically clip the val in the valid range, but it's still possible to use clipval in the expression in case it is required. The gammaval and negval all use clipped values, the user need to specify explicitely non-clipping exression in case he needs.
I'm going to push the filters in few days if I see no more comments.
Pushed. -- FFmpeg = Faithless & Fundamentalist Mortal Pacific Efficient Generator
Just a thought here -- there's a practically infinite number of simple filters like this (i.e. filters for which every pixel is operated on independently). Would it not be better to port something like Avisynth's MT_LUT filter, which allows the user to specify a mathematical operation to create a LUT from, which is then applied to all pixels? This could serve as the basis for many simple filters, reducing code duplication. Jason
On date Monday 2010-11-29 00:00:06 -0800, Jason Garrett-Glaser encoded:
Just a thought here -- there's a practically infinite number of simple filters like this (i.e. filters for which every pixel is operated on independently). Would it not be better to port something like Avisynth's MT_LUT filter, which allows the user to specify a mathematical operation to create a LUT from, which is then applied to all pixels?
Uhm, something like the applyfn filter I posted yesterday?
This could serve as the basis for many simple filters, reducing code duplication.
I agree, but for some (possibly useful) filter it is still important to have a fast version, I believe negate belongs to this category. -- FFmpeg = Free and Faithless Martial Prodigious Eccentric Gadget
On Mon, Nov 29, 2010 at 2:06 AM, Stefano Sabatini <stefano.sabatini-lala at poste.it> wrote:
On date Monday 2010-11-29 00:00:06 -0800, Jason Garrett-Glaser encoded:
Just a thought here -- there's a practically infinite number of simple filters like this (i.e. filters for which every pixel is operated on independently). ?Would it not be better to port something like Avisynth's MT_LUT filter, which allows the user to specify a mathematical operation to create a LUT from, which is then applied to all pixels?
Uhm, something like the applyfn filter I posted yesterday?
Doesn't use a LUT as far as I can see, so it's way too slow to be usable for much of anything. I would think that the "naive" negate would not be much faster than a LUT-based applyfn... Jason
On date Monday 2010-11-29 02:11:23 -0800, Jason Garrett-Glaser encoded:
On Mon, Nov 29, 2010 at 2:06 AM, Stefano Sabatini <stefano.sabatini-lala at poste.it> wrote:
On date Monday 2010-11-29 00:00:06 -0800, Jason Garrett-Glaser encoded:
Just a thought here -- there's a practically infinite number of simple filters like this (i.e. filters for which every pixel is operated on independently). ?Would it not be better to port something like Avisynth's MT_LUT filter, which allows the user to specify a mathematical operation to create a LUT from, which is then applied to all pixels?
Uhm, something like the applyfn filter I posted yesterday?
Doesn't use a LUT as far as I can see, so it's way too slow to be usable for much of anything.
It can't use a lookup table because the computed value is a function of (X,Y), which allows interesting applications, but we could write another variant of the filter. I'm also interested in implementing other "generic" filter, e.g. a linear convolution filter taking the kernel matrix in input and an affine transformation filter like this one proposed by Daniel Taylor: http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2010-April/087190.html
I would think that the "naive" negate would not be much faster than a LUT-based applyfn...
Indeed... -- FFmpeg = Frenzy and Funny Murdering Programmable Enchanting Gospel
On Mon, Nov 29, 2010 at 11:35:41AM +0100, Stefano Sabatini wrote:
On date Monday 2010-11-29 02:11:23 -0800, Jason Garrett-Glaser encoded:
On Mon, Nov 29, 2010 at 2:06 AM, Stefano Sabatini <stefano.sabatini-lala at poste.it> wrote:
On date Monday 2010-11-29 00:00:06 -0800, Jason Garrett-Glaser encoded:
Just a thought here -- there's a practically infinite number of simple filters like this (i.e. filters for which every pixel is operated on independently). ?Would it not be better to port something like Avisynth's MT_LUT filter, which allows the user to specify a mathematical operation to create a LUT from, which is then applied to all pixels?
Uhm, something like the applyfn filter I posted yesterday?
Doesn't use a LUT as far as I can see, so it's way too slow to be usable for much of anything.
It can't use a lookup table because the computed value is a function of (X,Y), which allows interesting applications,
s/It can't ... because/It can't ... when/ What I mean is that the applyfn filter should use a LUT unless the function provided by the user contain X or Y.
but we could write another variant of the filter.
I'm not sure exactly what you mean but I feel like you want to write a new filter with every small variation (eg. rotate vs. rotate90).
Hi, On Mon, Nov 29, 2010 at 3:00 AM, Jason Garrett-Glaser <jason at x264.com> wrote:
Just a thought here -- there's a practically infinite number of simple filters like this (i.e. filters for which every pixel is operated on independently). ?Would it not be better to port something like Avisynth's MT_LUT filter, which allows the user to specify a mathematical operation to create a LUT from, which is then applied to all pixels? ?This could serve as the basis for many simple filters, reducing code duplication.
A LUT filter can't be SIMD-optimized though, whereas a negate filter can... Ronald
On Nov 29, 2010, at 10:30 AM, Ronald S. Bultje wrote:
Hi,
On Mon, Nov 29, 2010 at 3:00 AM, Jason Garrett-Glaser <jason at x264.com> wrote:
Just a thought here -- there's a practically infinite number of simple filters like this (i.e. filters for which every pixel is operated on independently). Would it not be better to port something like Avisynth's MT_LUT filter, which allows the user to specify a mathematical operation to create a LUT from, which is then applied to all pixels? This could serve as the basis for many simple filters, reducing code duplication.
A LUT filter can't be SIMD-optimized though, whereas a negate filter can...
Ronald
It can on PPC. Not sure where else, though. Some options: 1. generate a joint table for every two (or three) bytes 2. use multithreading 3. if there are multiple LUT filters in a row, combine them into one LUT 4. use OpenGL/OpenCL 5. write your own vector JIT Anyway, I don't think most of the LUTable filters are useful enough to optimize by hand - if they are, they can probably be reduced to eq.
participants (11)
-
astrange@ithinksw.com -
aurel@gnuage.org -
darkshikari@gmail.com -
jason@x264.com -
Mark Himsley -
Michael Niedermayer -
michaelni@gmx.at -
Reimar Döffinger -
rsbultje@gmail.com -
Stefano Sabatini -
stefano.sabatini-lala@poste.it