| @@ -30,6 +30,7 @@ · 29 unmodified lines |
| 30 | typedef struct DebandContext { | 30 | typedef struct DebandContext { |
| 31 | const AVClass *class; | 31 | const AVClass *class; |
| 32 | | 32 | |
| | 33 | int coupling; |
| 33 | float threshold[4]; | 34 | float threshold[4]; |
| 34 | int range; | 35 | int range; |
| 35 | int blur; | 36 | int blur; |
| @@ -38,6 +39,7 @@ typedef struct DebandContext { · 2 unmodified lines |
| 38 | int nb_components; | 39 | int nb_components; |
| 39 | int planewidth[4]; | 40 | int planewidth[4]; |
| 40 | int planeheight[4]; | 41 | int planeheight[4]; |
| | 42 | int shift[2]; |
| 41 | int thr[4]; | 43 | int thr[4]; |
| 42 | | 44 | |
| 43 | int *x_pos; | 45 | int *x_pos; |
| @@ -59,6 +61,9 @@ static const AVOption deband_options[] = { · 15 unmodified lines |
| 59 | { "direction", "set direction", OFFSET(direction), AV_OPT_TYPE_FLOAT, {.dbl=2*M_PI},-2*M_PI, 2*M_PI, FLAGS }, | 61 | { "direction", "set direction", OFFSET(direction), AV_OPT_TYPE_FLOAT, {.dbl=2*M_PI},-2*M_PI, 2*M_PI, FLAGS }, |
| 60 | { "d", "set direction", OFFSET(direction), AV_OPT_TYPE_FLOAT, {.dbl=2*M_PI},-2*M_PI, 2*M_PI, FLAGS }, | 62 | { "d", "set direction", OFFSET(direction), AV_OPT_TYPE_FLOAT, {.dbl=2*M_PI},-2*M_PI, 2*M_PI, FLAGS }, |
| 61 | { "blur", "set blur", OFFSET(blur), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS }, | 63 | { "blur", "set blur", OFFSET(blur), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS }, |
| | 64 | { "b", "set blur", OFFSET(blur), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS }, |
| | 65 | { "coupling", "set plane coupling", OFFSET(coupling), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS }, |
| | 66 | { "c", "set plane coupling", OFFSET(coupling), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS }, |
| 62 | { NULL } | 67 | { NULL } |
| 63 | }; | 68 | }; |
| 64 | | 69 | |
| @@ -66,6 +71,8 @@ AVFILTER_DEFINE_CLASS(deband); · 1 unmodified line |
| 66 | | 71 | |
| 67 | static int query_formats(AVFilterContext *ctx) | 72 | static int query_formats(AVFilterContext *ctx) |
| 68 | { | 73 | { |
| | 74 | DebandContext *s = ctx->priv; |
| | 75 | |
| 69 | static const enum AVPixelFormat pix_fmts[] = { | 76 | static const enum AVPixelFormat pix_fmts[] = { |
| 70 | AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY16, | 77 | AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY16, |
| 71 | AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P, | 78 | AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P, |
| @@ -86,7 +93,21 @@ static int query_formats(AVFilterContext *ctx) · 14 unmodified lines |
| 86 | AV_PIX_FMT_YUVA420P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA444P16, | 93 | AV_PIX_FMT_YUVA420P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA444P16, |
| 87 | AV_PIX_FMT_NONE | 94 | AV_PIX_FMT_NONE |
| 88 | }; | 95 | }; |
| 89 | AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts); | 96 | |
| | 97 | static const enum AVPixelFormat cpix_fmts[] = { |
| | 98 | AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P, |
| | 99 | AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUV444P9, |
| | 100 | AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA444P10, |
| | 101 | AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV444P14, |
| | 102 | AV_PIX_FMT_YUV444P16, AV_PIX_FMT_YUVA444P16, |
| | 103 | AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, |
| | 104 | AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, |
| | 105 | AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, |
| | 106 | AV_PIX_FMT_GBRP16, AV_PIX_FMT_GBRAP16, |
| | 107 | AV_PIX_FMT_NONE |
| | 108 | }; |
| | 109 | |
| | 110 | AVFilterFormats *fmts_list = ff_make_format_list(s->coupling ? cpix_fmts : pix_fmts); |
| 90 | if (!fmts_list) | 111 | if (!fmts_list) |
| 91 | return AVERROR(ENOMEM); | 112 | return AVERROR(ENOMEM); |
| 92 | | 113 | |
| @@ -158,6 +179,138 @@ static int deband_8_c(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) · 65 unmodified lines |
| 158 | return 0; | 179 | return 0; |
| 159 | } | 180 | } |
| 160 | | 181 | |
| | 182 | static int deband_8_coupling_c(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) |
| | 183 | { |
| | 184 | DebandContext *s = ctx->priv; |
| | 185 | ThreadData *td = arg; |
| | 186 | AVFrame *in = td->in; |
| | 187 | AVFrame *out = td->out; |
| | 188 | const int start = (s->planeheight[0] * jobnr ) / nb_jobs; |
| | 189 | const int end = (s->planeheight[0] * (jobnr+1)) / nb_jobs; |
| | 190 | int x, y, p; |
| | 191 | |
| | 192 | for (y = start; y < end; y++) { |
| | 193 | const int pos = y * s->planewidth[0]; |
| | 194 | |
| | 195 | for (x = 0; x < s->planewidth[p]; x++) { |
| | 196 | const int x_pos = s->x_pos[pos + x]; |
| | 197 | const int y_pos = s->y_pos[pos + x]; |
| | 198 | int avg[4], cmp[4] = { 0 }, src[4]; |
| | 199 | |
| | 200 | for (p = 0; p < s->nb_components; p++) { |
| | 201 | const uint8_t *src_ptr = (const uint8_t *)in->data[p]; |
| | 202 | const int src_linesize = in->linesize[p]; |
| | 203 | const int thr = s->thr[p]; |
| | 204 | const int w = s->planewidth[p] - 1; |
| | 205 | const int h = s->planeheight[p] - 1; |
| | 206 | const int ref0 = src_ptr[av_clip(y + y_pos, 0, h) * src_linesize + av_clip(x + x_pos, 0, w)]; |
| | 207 | const int ref1 = src_ptr[av_clip(y + -y_pos, 0, h) * src_linesize + av_clip(x + x_pos, 0, w)]; |
| | 208 | const int ref2 = src_ptr[av_clip(y + -y_pos, 0, h) * src_linesize + av_clip(x + -x_pos, 0, w)]; |
| | 209 | const int ref3 = src_ptr[av_clip(y + y_pos, 0, h) * src_linesize + av_clip(x + -x_pos, 0, w)]; |
| | 210 | const int src0 = src_ptr[y * src_linesize + x]; |
| | 211 | |
| | 212 | src[p] = src0; |
| | 213 | avg[p] = get_avg(ref0, ref1, ref2, ref3); |
| | 214 | |
| | 215 | if (s->blur) { |
| | 216 | cmp[p] = FFABS(src0 - avg[p]) < thr; |
| | 217 | } else { |
| | 218 | cmp[p] = (FFABS(src0 - ref0) < thr) && |
| | 219 | (FFABS(src0 - ref1) < thr) && |
| | 220 | (FFABS(src0 - ref2) < thr) && |
| | 221 | (FFABS(src0 - ref3) < thr); |
| | 222 | } |
| | 223 | } |
| | 224 | |
| | 225 | for (p = 0; p < s->nb_components; p++) |
| | 226 | if (!cmp[p]) |
| | 227 | break; |
| | 228 | if (p == s->nb_components) { |
| | 229 | for (p = 0; p < s->nb_components; p++) { |
| | 230 | const int dst_linesize = out->linesize[p]; |
| | 231 | |
| | 232 | out->data[p][y * dst_linesize + x] = avg[p]; |
| | 233 | } |
| | 234 | } else { |
| | 235 | for (p = 0; p < s->nb_components; p++) { |
| | 236 | const int dst_linesize = out->linesize[p]; |
| | 237 | |
| | 238 | out->data[p][y * dst_linesize + x] = src[p]; |
| | 239 | } |
| | 240 | } |
| | 241 | } |
| | 242 | } |
| | 243 | |
| | 244 | return 0; |
| | 245 | } |
| | 246 | |
| | 247 | static int deband_16_coupling_c(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) |
| | 248 | { |
| | 249 | DebandContext *s = ctx->priv; |
| | 250 | ThreadData *td = arg; |
| | 251 | AVFrame *in = td->in; |
| | 252 | AVFrame *out = td->out; |
| | 253 | const int start = (s->planeheight[0] * jobnr ) / nb_jobs; |
| | 254 | const int end = (s->planeheight[0] * (jobnr+1)) / nb_jobs; |
| | 255 | int x, y, p, z; |
| | 256 | |
| | 257 | for (y = start; y < end; y++) { |
| | 258 | const int pos = y * s->planewidth[0]; |
| | 259 | |
| | 260 | for (x = 0; x < s->planewidth[p]; x++) { |
| | 261 | const int x_pos = s->x_pos[pos + x]; |
| | 262 | const int y_pos = s->y_pos[pos + x]; |
| | 263 | int avg[4], cmp[4] = { 0 }, src[4]; |
| | 264 | |
| | 265 | for (p = 0; p < s->nb_components; p++) { |
| | 266 | const uint16_t *src_ptr = (const uint16_t *)in->data[p]; |
| | 267 | const int src_linesize = in->linesize[p] / 2; |
| | 268 | const int thr = s->thr[p]; |
| | 269 | const int w = s->planewidth[p] - 1; |
| | 270 | const int h = s->planeheight[p] - 1; |
| | 271 | const int ref0 = src_ptr[av_clip(y + y_pos, 0, h) * src_linesize + av_clip(x + x_pos, 0, w)]; |
| | 272 | const int ref1 = src_ptr[av_clip(y + -y_pos, 0, h) * src_linesize + av_clip(x + x_pos, 0, w)]; |
| | 273 | const int ref2 = src_ptr[av_clip(y + -y_pos, 0, h) * src_linesize + av_clip(x + -x_pos, 0, w)]; |
| | 274 | const int ref3 = src_ptr[av_clip(y + y_pos, 0, h) * src_linesize + av_clip(x + -x_pos, 0, w)]; |
| | 275 | const int src0 = src_ptr[y * src_linesize + x]; |
| | 276 | |
| | 277 | src[p] = src0; |
| | 278 | avg[p] = get_avg(ref0, ref1, ref2, ref3); |
| | 279 | |
| | 280 | if (s->blur) { |
| | 281 | cmp[p] = FFABS(src0 - avg[p]) < thr; |
| | 282 | } else { |
| | 283 | cmp[p] = (FFABS(src0 - ref0) < thr) && |
| | 284 | (FFABS(src0 - ref1) < thr) && |
| | 285 | (FFABS(src0 - ref2) < thr) && |
| | 286 | (FFABS(src0 - ref3) < thr); |
| | 287 | } |
| | 288 | } |
| | 289 | |
| | 290 | for (z = 0; z < s->nb_components; z++) |
| | 291 | if (!cmp[z]) |
| | 292 | break; |
| | 293 | if (z == s->nb_components) { |
| | 294 | for (p = 0; p < s->nb_components; p++) { |
| | 295 | const int dst_linesize = out->linesize[p] / 2; |
| | 296 | uint16_t *dst = (uint16_t *)out->data[p] + y * dst_linesize + x; |
| | 297 | |
| | 298 | dst[0] = avg[p]; |
| | 299 | } |
| | 300 | } else { |
| | 301 | for (p = 0; p < s->nb_components; p++) { |
| | 302 | const int dst_linesize = out->linesize[p] / 2; |
| | 303 | uint16_t *dst = (uint16_t *)out->data[p] + y * dst_linesize + x; |
| | 304 | |
| | 305 | dst[0] = src[p]; |
| | 306 | } |
| | 307 | } |
| | 308 | } |
| | 309 | } |
| | 310 | |
| | 311 | return 0; |
| | 312 | } |
| | 313 | |
| 161 | static int deband_16_c(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) | 314 | static int deband_16_c(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) |
| 162 | { | 315 | { |
| 163 | DebandContext *s = ctx->priv; | 316 | DebandContext *s = ctx->priv; |
| @@ -222,8 +375,13 @@ static int config_input(AVFilterLink *inlink) · 58 unmodified lines |
| 222 | s->planeheight[0] = s->planeheight[3] = inlink->h; | 375 | s->planeheight[0] = s->planeheight[3] = inlink->h; |
| 223 | s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w); | 376 | s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w); |
| 224 | s->planewidth[0] = s->planewidth[3] = inlink->w; | 377 | s->planewidth[0] = s->planewidth[3] = inlink->w; |
| | 378 | s->shift[0] = desc->log2_chroma_w; |
| | 379 | s->shift[1] = desc->log2_chroma_h; |
| 225 | | 380 | |
| 226 | s->deband = desc->comp[0].depth > 8 ? deband_16_c : deband_8_c; | 381 | if (s->coupling) |
| | 382 | s->deband = desc->comp[0].depth > 8 ? deband_16_coupling_c : deband_8_coupling_c; |
| | 383 | else |
| | 384 | s->deband = desc->comp[0].depth > 8 ? deband_16_c : deband_8_c; |
| 227 | | 385 | |
| 228 | s->thr[0] = ((1 << desc->comp[0].depth) - 1) * s->threshold[0]; | 386 | s->thr[0] = ((1 << desc->comp[0].depth) - 1) * s->threshold[0]; |
| 229 | s->thr[1] = ((1 << desc->comp[1].depth) - 1) * s->threshold[1]; | 387 | s->thr[1] = ((1 << desc->comp[1].depth) - 1) * s->threshold[1]; |