Showing the changes to libavfilter (1 of 2 files). Show all
Unified · Split
| @@ -35,6 +35,7 @@ typedef struct ChromaNRContext { · 34 unmodified lines | |||
| 35 | float threshold_y; | 35 | float threshold_y; |
| 36 | float threshold_u; | 36 | float threshold_u; |
| 37 | float threshold_v; | 37 | float threshold_v; |
| 38 | int distance; | ||
| 38 | int thres; | 39 | int thres; |
| 39 | int thres_y; | 40 | int thres_y; |
| 40 | int thres_u; | 41 | int thres_u; |
| @@ -79,8 +80,11 @@ static int query_formats(AVFilterContext *ctx) · 38 unmodified lines | |||
| 79 | return ff_set_common_formats(ctx, fmts_list); | 80 | return ff_set_common_formats(ctx, fmts_list); |
| 80 | } | 81 | } |
| 81 | 82 | ||
| 82 | #define FILTER_FUNC(name, type) \ | 83 | #define SQR(x) ((x)*(x)) |
| 83 | static int filter_slice##name(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \ | 84 | |
| 85 | #define FILTER_FUNC(distance, name, ctype, type, fun) \ | ||
| 86 | static int distance ## _slice##name(AVFilterContext *ctx, void *arg, \ | ||
| 87 | int jobnr, int nb_jobs) \ | ||
| 84 | { \ | 88 | { \ |
| 85 | ChromaNRContext *s = ctx->priv; \ | 89 | ChromaNRContext *s = ctx->priv; \ |
| 86 | AVFrame *in = arg; \ | 90 | AVFrame *in = arg; \ |
| @@ -146,13 +150,13 @@ static int filter_slice##name(AVFilterContext *ctx, void *arg, int jobnr, int nb · 59 unmodified lines | |||
| 146 | const type *in_vptr = (const type *)(in->data[2] + yy * in_vlinesize); \ | 150 | const type *in_vptr = (const type *)(in->data[2] + yy * in_vlinesize); \ |
| 147 | \ | 151 | \ |
| 148 | for (int xx = FFMAX(0, x - sizew); xx < FFMIN(x + sizew, w); xx += stepw) { \ | 152 | for (int xx = FFMAX(0, x - sizew); xx < FFMIN(x + sizew, w); xx += stepw) { \ |
| 149 | const int Y = in_yptr[xx * chroma_w]; \ | 153 | const ctype Y = in_yptr[xx * chroma_w]; \ |
| 150 | const int U = in_uptr[xx]; \ | 154 | const ctype U = in_uptr[xx]; \ |
| 151 | const int V = in_vptr[xx]; \ | 155 | const ctype V = in_vptr[xx]; \ |
| 152 | \ | 156 | \ |
| 153 | if (FFABS(cu - U) + FFABS(cv - V) + FFABS(cy - Y) < thres && \ | 157 | if (fun(cu - U) + fun(cv - V) + fun(cy - Y) < thres && \ |
| 154 | FFABS(cu - U) < thres_u && FFABS(cv - V) < thres_v && \ | 158 | fun(cu - U) < thres_u && fun(cv - V) < thres_v && \ |
| 155 | FFABS(cy - Y) < thres_y && \ | 159 | fun(cy - Y) < thres_y && \ |
| 156 | xx != x && yy != y) { \ | 160 | xx != x && yy != y) { \ |
| 157 | su += U; \ | 161 | su += U; \ |
| 158 | sv += V; \ | 162 | sv += V; \ |
| @@ -172,8 +176,11 @@ static int filter_slice##name(AVFilterContext *ctx, void *arg, int jobnr, int nb · 13 unmodified lines | |||
| 172 | return 0; \ | 176 | return 0; \ |
| 173 | } | 177 | } |
| 174 | 178 | ||
| 175 | FILTER_FUNC(8, uint8_t) | 179 | FILTER_FUNC(manhattan, 8, int, uint8_t, FFABS) |
| 176 | FILTER_FUNC(16, uint16_t) | 180 | FILTER_FUNC(manhattan, 16, int, uint16_t, FFABS) |
| 181 | |||
| 182 | FILTER_FUNC(euclidean, 8, int, uint8_t, SQR) | ||
| 183 | FILTER_FUNC(euclidean, 16, int64_t, uint16_t, SQR) | ||
| 177 | 184 | ||
| 178 | static int filter_frame(AVFilterLink *inlink, AVFrame *in) | 185 | static int filter_frame(AVFilterLink *inlink, AVFrame *in) |
| 179 | { | 186 | { |
| @@ -182,6 +189,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 2 unmodified lines | |||
| 182 | ChromaNRContext *s = ctx->priv; | 189 | ChromaNRContext *s = ctx->priv; |
| 183 | AVFrame *out; | 190 | AVFrame *out; |
| 184 | 191 | ||
| 192 | switch (s->distance) { | ||
| 193 | case 0: | ||
| 194 | s->filter_slice = s->depth <= 8 ? manhattan_slice8 : manhattan_slice16; | ||
| 195 | break; | ||
| 196 | case 1: | ||
| 197 | s->filter_slice = s->depth <= 8 ? euclidean_slice8 : euclidean_slice16; | ||
| 198 | break; | ||
| 199 | } | ||
| 200 | |||
| 185 | s->thres = s->threshold * (1 << (s->depth - 8)); | 201 | s->thres = s->threshold * (1 << (s->depth - 8)); |
| 186 | s->thres_y = s->threshold_y * (1 << (s->depth - 8)); | 202 | s->thres_y = s->threshold_y * (1 << (s->depth - 8)); |
| 187 | s->thres_u = s->threshold_u * (1 << (s->depth - 8)); | 203 | s->thres_u = s->threshold_u * (1 << (s->depth - 8)); |
| @@ -213,7 +229,6 @@ static int config_input(AVFilterLink *inlink) · 25 unmodified lines | |||
| 213 | 229 | ||
| 214 | s->nb_planes = desc->nb_components; | 230 | s->nb_planes = desc->nb_components; |
| 215 | s->depth = desc->comp[0].depth; | 231 | s->depth = desc->comp[0].depth; |
| 216 | s->filter_slice = s->depth <= 8 ? filter_slice8 : filter_slice16; | ||
| 217 | s->chroma_w = 1 << desc->log2_chroma_w; | 232 | s->chroma_w = 1 << desc->log2_chroma_w; |
| 218 | s->chroma_h = 1 << desc->log2_chroma_h; | 233 | s->chroma_h = 1 << desc->log2_chroma_h; |
| 219 | s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h); | 234 | s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h); |
| @@ -231,14 +246,17 @@ static int config_input(AVFilterLink *inlink) · 11 unmodified lines | |||
| 231 | #define VF AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_RUNTIME_PARAM | 246 | #define VF AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_RUNTIME_PARAM |
| 232 | 247 | ||
| 233 | static const AVOption chromanr_options[] = { | 248 | static const AVOption chromanr_options[] = { |
| 234 | { "thres", "set y+u+v threshold", OFFSET(threshold), AV_OPT_TYPE_FLOAT, {.dbl=30}, 1, 200, VF }, | 249 | { "thres", "set y+u+v threshold", OFFSET(threshold), AV_OPT_TYPE_FLOAT, {.dbl=30}, 1, 5000, VF }, |
| 235 | { "sizew", "set horizontal size", OFFSET(sizew), AV_OPT_TYPE_INT, {.i64=5}, 1, 100, VF }, | 250 | { "sizew", "set horizontal size", OFFSET(sizew), AV_OPT_TYPE_INT, {.i64=5}, 1, 100, VF }, |
| 236 | { "sizeh", "set vertical size", OFFSET(sizeh), AV_OPT_TYPE_INT, {.i64=5}, 1, 100, VF }, | 251 | { "sizeh", "set vertical size", OFFSET(sizeh), AV_OPT_TYPE_INT, {.i64=5}, 1, 100, VF }, |
| 237 | { "stepw", "set horizontal step", OFFSET(stepw), AV_OPT_TYPE_INT, {.i64=1}, 1, 50, VF }, | 252 | { "stepw", "set horizontal step", OFFSET(stepw), AV_OPT_TYPE_INT, {.i64=1}, 1, 50, VF }, |
| 238 | { "steph", "set vertical step", OFFSET(steph), AV_OPT_TYPE_INT, {.i64=1}, 1, 50, VF }, | 253 | { "steph", "set vertical step", OFFSET(steph), AV_OPT_TYPE_INT, {.i64=1}, 1, 50, VF }, |
| 239 | { "threy", "set y threshold", OFFSET(threshold_y), AV_OPT_TYPE_FLOAT, {.dbl=200},1, 200, VF }, | 254 | { "threy", "set y threshold", OFFSET(threshold_y), AV_OPT_TYPE_FLOAT, {.dbl=5000},1, 5000, VF }, |
| 240 | { "threu", "set u threshold", OFFSET(threshold_u), AV_OPT_TYPE_FLOAT, {.dbl=200},1, 200, VF }, | 255 | { "threu", "set u threshold", OFFSET(threshold_u), AV_OPT_TYPE_FLOAT, {.dbl=5000},1, 5000, VF }, |
| 241 | { "threv", "set v threshold", OFFSET(threshold_v), AV_OPT_TYPE_FLOAT, {.dbl=200},1, 200, VF }, | 256 | { "threv", "set v threshold", OFFSET(threshold_v), AV_OPT_TYPE_FLOAT, {.dbl=5000},1, 5000, VF }, |
| 257 | { "distance", "set distance type", OFFSET(distance), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, VF, "distance" }, | ||
| 258 | { "manhattan", "", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, VF, "distance" }, | ||
| 259 | { "euclidean", "", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, VF, "distance" }, | ||
| 242 | { NULL } | 260 | { NULL } |
| 243 | }; | 261 | }; |
| 244 | 262 | ||