| /* |
| * Copyright (c) 2012-2016 Paul B Mahol |
| * Copyright (c) 2013 Marton Balint |
| * |
| * 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 |
| */ |
| |
| #include "libavutil/avassert.h" |
| #include "libavutil/opt.h" |
| #include "libavutil/parseutils.h" |
| #include "libavutil/pixdesc.h" |
| #include "libavutil/xga_font_data.h" |
| #include "avfilter.h" |
| #include "formats.h" |
| #include "internal.h" |
| #include "video.h" |
| |
| typedef struct ThreadData { |
| AVFrame *in; |
| AVFrame *out; |
| int component; |
| int offset_y; |
| int offset_x; |
| } ThreadData; |
| |
| enum FilterType { |
| LOWPASS, |
| FLAT, |
| AFLAT, |
| CHROMA, |
| COLOR, |
| ACOLOR, |
| XFLAT, |
| YFLAT, |
| NB_FILTERS |
| }; |
| |
| enum DisplayType { |
| OVERLAY, |
| STACK, |
| PARADE, |
| NB_DISPLAYS |
| }; |
| |
| enum ScaleType { |
| DIGITAL, |
| MILLIVOLTS, |
| IRE, |
| NB_SCALES |
| }; |
| |
| enum GraticuleType { |
| GRAT_NONE, |
| GRAT_GREEN, |
| GRAT_ORANGE, |
| GRAT_INVERT, |
| NB_GRATICULES |
| }; |
| |
| typedef struct GraticuleLine { |
| const char *name; |
| uint16_t pos; |
| } GraticuleLine; |
| |
| typedef struct GraticuleLines { |
| struct GraticuleLine line[4]; |
| } GraticuleLines; |
| |
| typedef struct WaveformContext { |
| const AVClass *class; |
| int mode; |
| int acomp; |
| int dcomp; |
| int ncomp; |
| int pcomp; |
| uint8_t bg_color[4]; |
| float fintensity; |
| int intensity; |
| int mirror; |
| int display; |
| int envelope; |
| int graticule; |
| float opacity; |
| float bgopacity; |
| int estart[4]; |
| int eend[4]; |
| int *emax[4][4]; |
| int *emin[4][4]; |
| int *peak; |
| int filter; |
| int flags; |
| int bits; |
| int max; |
| int size; |
| int scale; |
| uint8_t grat_yuva_color[4]; |
| int shift_w[4], shift_h[4]; |
| GraticuleLines *glines; |
| int nb_glines; |
| int rgb; |
| float ftint[2]; |
| int tint[2]; |
| |
| int (*waveform_slice)(AVFilterContext *ctx, void *arg, |
| int jobnr, int nb_jobs); |
| void (*graticulef)(struct WaveformContext *s, AVFrame *out); |
| void (*blend_line)(uint8_t *dst, int size, int linesize, float o1, float o2, |
| int v, int step); |
| void (*draw_text)(AVFrame *out, int x, int y, int mult, |
| float o1, float o2, const char *txt, |
| const uint8_t color[4]); |
| const AVPixFmtDescriptor *desc; |
| const AVPixFmtDescriptor *odesc; |
| } WaveformContext; |
| |
| #define OFFSET(x) offsetof(WaveformContext, x) |
| #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM |
| |
| static const AVOption waveform_options[] = { |
| { "mode", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "mode" }, |
| { "m", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "mode" }, |
| { "row", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "mode" }, |
| { "column", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "mode" }, |
| { "intensity", "set intensity", OFFSET(fintensity), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 1, FLAGS }, |
| { "i", "set intensity", OFFSET(fintensity), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 1, FLAGS }, |
| { "mirror", "set mirroring", OFFSET(mirror), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS }, |
| { "r", "set mirroring", OFFSET(mirror), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS }, |
| { "display", "set display mode", OFFSET(display), AV_OPT_TYPE_INT, {.i64=STACK}, 0, NB_DISPLAYS-1, FLAGS, "display" }, |
| { "d", "set display mode", OFFSET(display), AV_OPT_TYPE_INT, {.i64=STACK}, 0, NB_DISPLAYS-1, FLAGS, "display" }, |
| { "overlay", NULL, 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY}, 0, 0, FLAGS, "display" }, |
| { "stack", NULL, 0, AV_OPT_TYPE_CONST, {.i64=STACK}, 0, 0, FLAGS, "display" }, |
| { "parade", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PARADE}, 0, 0, FLAGS, "display" }, |
| { "components", "set components to display", OFFSET(pcomp), AV_OPT_TYPE_INT, {.i64=1}, 1, 15, FLAGS }, |
| { "c", "set components to display", OFFSET(pcomp), AV_OPT_TYPE_INT, {.i64=1}, 1, 15, FLAGS }, |
| { "envelope", "set envelope to display", OFFSET(envelope), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "envelope" }, |
| { "e", "set envelope to display", OFFSET(envelope), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "envelope" }, |
| { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "envelope" }, |
| { "instant", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "envelope" }, |
| { "peak", NULL, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "envelope" }, |
| { "peak+instant", NULL, 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, FLAGS, "envelope" }, |
| { "filter", "set filter", OFFSET(filter), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_FILTERS-1, FLAGS, "filter" }, |
| { "f", "set filter", OFFSET(filter), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_FILTERS-1, FLAGS, "filter" }, |
| { "lowpass", NULL, 0, AV_OPT_TYPE_CONST, {.i64=LOWPASS}, 0, 0, FLAGS, "filter" }, |
| { "flat" , NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAT}, 0, 0, FLAGS, "filter" }, |
| { "aflat" , NULL, 0, AV_OPT_TYPE_CONST, {.i64=AFLAT}, 0, 0, FLAGS, "filter" }, |
| { "chroma", NULL, 0, AV_OPT_TYPE_CONST, {.i64=CHROMA}, 0, 0, FLAGS, "filter" }, |
| { "color", NULL, 0, AV_OPT_TYPE_CONST, {.i64=COLOR}, 0, 0, FLAGS, "filter" }, |
| { "acolor", NULL, 0, AV_OPT_TYPE_CONST, {.i64=ACOLOR}, 0, 0, FLAGS, "filter" }, |
| { "xflat", NULL, 0, AV_OPT_TYPE_CONST, {.i64=XFLAT}, 0, 0, FLAGS, "filter" }, |
| { "yflat", NULL, 0, AV_OPT_TYPE_CONST, {.i64=YFLAT}, 0, 0, FLAGS, "filter" }, |
| { "graticule", "set graticule", OFFSET(graticule), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_GRATICULES-1, FLAGS, "graticule" }, |
| { "g", "set graticule", OFFSET(graticule), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_GRATICULES-1, FLAGS, "graticule" }, |
| { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=GRAT_NONE}, 0, 0, FLAGS, "graticule" }, |
| { "green", NULL, 0, AV_OPT_TYPE_CONST, {.i64=GRAT_GREEN}, 0, 0, FLAGS, "graticule" }, |
| { "orange", NULL, 0, AV_OPT_TYPE_CONST, {.i64=GRAT_ORANGE}, 0, 0, FLAGS, "graticule" }, |
| { "invert", NULL, 0, AV_OPT_TYPE_CONST, {.i64=GRAT_INVERT}, 0, 0, FLAGS, "graticule" }, |
| { "opacity", "set graticule opacity", OFFSET(opacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS }, |
| { "o", "set graticule opacity", OFFSET(opacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS }, |
| { "flags", "set graticule flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64=1}, 0, 3, FLAGS, "flags" }, |
| { "fl", "set graticule flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64=1}, 0, 3, FLAGS, "flags" }, |
| { "numbers", "draw numbers", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "flags" }, |
| { "dots", "draw dots instead of lines", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "flags" }, |
| { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SCALES-1, FLAGS, "scale" }, |
| { "s", "set scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SCALES-1, FLAGS, "scale" }, |
| { "digital", NULL, 0, AV_OPT_TYPE_CONST, {.i64=DIGITAL}, 0, 0, FLAGS, "scale" }, |
| { "millivolts", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MILLIVOLTS}, 0, 0, FLAGS, "scale" }, |
| { "ire", NULL, 0, AV_OPT_TYPE_CONST, {.i64=IRE}, 0, 0, FLAGS, "scale" }, |
| { "bgopacity", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS }, |
| { "b", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS }, |
| { "tint0", "set 1st tint", OFFSET(ftint[0]), AV_OPT_TYPE_FLOAT, {.dbl=0}, -1, 1, FLAGS}, |
| { "t0", "set 1st tint", OFFSET(ftint[0]), AV_OPT_TYPE_FLOAT, {.dbl=0}, -1, 1, FLAGS}, |
| { "tint1", "set 2nd tint", OFFSET(ftint[1]), AV_OPT_TYPE_FLOAT, {.dbl=0}, -1, 1, FLAGS}, |
| { "t1", "set 2nd tint", OFFSET(ftint[1]), AV_OPT_TYPE_FLOAT, {.dbl=0}, -1, 1, FLAGS}, |
| { NULL } |
| }; |
| |
| AVFILTER_DEFINE_CLASS(waveform); |
| |
| static const enum AVPixelFormat in_lowpass_pix_fmts[] = { |
| AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, |
| AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12, |
| AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P, |
| AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P, |
| AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P, |
| AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P, |
| AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P, |
| AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P, |
| AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY9, AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12, |
| AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9, |
| AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9, |
| AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10, |
| AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10, |
| AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV440P12, |
| AV_PIX_FMT_YUVA444P12, AV_PIX_FMT_YUVA422P12, |
| AV_PIX_FMT_NONE |
| }; |
| |
| static const enum AVPixelFormat in_color_pix_fmts[] = { |
| AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, |
| AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12, |
| AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P, |
| AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P, |
| AV_PIX_FMT_YUV411P, |
| AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P, |
| AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P, |
| AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P, |
| AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9, |
| AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9, |
| AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10, |
| AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10, |
| AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV440P12, |
| AV_PIX_FMT_YUVA444P12, AV_PIX_FMT_YUVA422P12, |
| AV_PIX_FMT_NONE |
| }; |
| |
| static const enum AVPixelFormat in_flat_pix_fmts[] = { |
| AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P, |
| AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P, |
| AV_PIX_FMT_YUV411P, |
| AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P, |
| AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P, |
| AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P, |
| AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9, |
| AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9, |
| AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10, |
| AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10, |
| AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV440P12, |
| AV_PIX_FMT_YUVA444P12, AV_PIX_FMT_YUVA422P12, |
| AV_PIX_FMT_NONE |
| }; |
| |
| static const enum AVPixelFormat out_rgb8_lowpass_pix_fmts[] = { |
| AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, |
| AV_PIX_FMT_NONE |
| }; |
| |
| static const enum AVPixelFormat out_rgb9_lowpass_pix_fmts[] = { |
| AV_PIX_FMT_GBRP9, |
| AV_PIX_FMT_NONE |
| }; |
| |
| static const enum AVPixelFormat out_rgb10_lowpass_pix_fmts[] = { |
| AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10, |
| AV_PIX_FMT_NONE |
| }; |
| |
| static const enum AVPixelFormat out_rgb12_lowpass_pix_fmts[] = { |
| AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12, |
| AV_PIX_FMT_NONE |
| }; |
| |
| static const enum AVPixelFormat out_yuv8_lowpass_pix_fmts[] = { |
| AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVA444P, |
| AV_PIX_FMT_NONE |
| }; |
| |
| static const enum AVPixelFormat out_yuv9_lowpass_pix_fmts[] = { |
| AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUVA444P9, |
| AV_PIX_FMT_NONE |
| }; |
| |
| static const enum AVPixelFormat out_yuv10_lowpass_pix_fmts[] = { |
| AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUVA444P10, |
| AV_PIX_FMT_NONE |
| }; |
| |
| static const enum AVPixelFormat out_yuv12_lowpass_pix_fmts[] = { |
| AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUVA444P12, |
| AV_PIX_FMT_NONE |
| }; |
| |
| static const enum AVPixelFormat out_gray8_lowpass_pix_fmts[] = { |
| AV_PIX_FMT_GRAY8, |
| AV_PIX_FMT_NONE |
| }; |
| |
| static const enum AVPixelFormat out_gray9_lowpass_pix_fmts[] = { |
| AV_PIX_FMT_GRAY9, |
| AV_PIX_FMT_NONE |
| }; |
| |
| static const enum AVPixelFormat out_gray10_lowpass_pix_fmts[] = { |
| AV_PIX_FMT_GRAY10, |
| AV_PIX_FMT_NONE |
| }; |
| |
| static const enum AVPixelFormat out_gray12_lowpass_pix_fmts[] = { |
| AV_PIX_FMT_GRAY12, |
| AV_PIX_FMT_NONE |
| }; |
| |
| static int query_formats(AVFilterContext *ctx) |
| { |
| WaveformContext *s = ctx->priv; |
| const enum AVPixelFormat *out_pix_fmts; |
| const enum AVPixelFormat *in_pix_fmts; |
| const AVPixFmtDescriptor *desc, *desc2; |
| AVFilterFormats *avff, *avff2; |
| int depth, depth2, rgb, i, ret, ncomp, ncomp2; |
| |
| if (!ctx->inputs[0]->incfg.formats || |
| !ctx->inputs[0]->incfg.formats->nb_formats) { |
| return AVERROR(EAGAIN); |
| } |
| |
| switch (s->filter) { |
| case LOWPASS: in_pix_fmts = in_lowpass_pix_fmts; break; |
| case CHROMA: |
| case XFLAT: |
| case YFLAT: |
| case AFLAT: |
| case FLAT: in_pix_fmts = in_flat_pix_fmts; break; |
| case ACOLOR: |
| case COLOR: in_pix_fmts = in_color_pix_fmts; break; |
| default: return AVERROR_BUG; |
| } |
| |
| if (!ctx->inputs[0]->outcfg.formats) { |
| if ((ret = ff_formats_ref(ff_make_format_list(in_pix_fmts), &ctx->inputs[0]->outcfg.formats)) < 0) |
| return ret; |
| } |
| |
| avff = ctx->inputs[0]->incfg.formats; |
| avff2 = ctx->inputs[0]->outcfg.formats; |
| desc = av_pix_fmt_desc_get(avff->formats[0]); |
| desc2 = av_pix_fmt_desc_get(avff2->formats[0]); |
| ncomp = desc->nb_components; |
| ncomp2 = desc2->nb_components; |
| rgb = desc->flags & AV_PIX_FMT_FLAG_RGB; |
| depth = desc->comp[0].depth; |
| depth2 = desc2->comp[0].depth; |
| if (ncomp != ncomp2 || depth != depth2) |
| return AVERROR(EAGAIN); |
| for (i = 1; i < avff->nb_formats; i++) { |
| desc = av_pix_fmt_desc_get(avff->formats[i]); |
| if (rgb != (desc->flags & AV_PIX_FMT_FLAG_RGB) || |
| depth != desc->comp[0].depth) |
| return AVERROR(EAGAIN); |
| } |
| |
| if (s->filter == LOWPASS && ncomp == 1 && depth == 8) |
| out_pix_fmts = out_gray8_lowpass_pix_fmts; |
| else if (s->filter == LOWPASS && ncomp == 1 && depth == 9) |
| out_pix_fmts = out_gray9_lowpass_pix_fmts; |
| else if (s->filter == LOWPASS && ncomp == 1 && depth == 10) |
| out_pix_fmts = out_gray10_lowpass_pix_fmts; |
| else if (s->filter == LOWPASS && ncomp == 1 && depth == 12) |
| out_pix_fmts = out_gray12_lowpass_pix_fmts; |
| else if (rgb && depth == 8 && ncomp > 2) |
| out_pix_fmts = out_rgb8_lowpass_pix_fmts; |
| else if (rgb && depth == 9 && ncomp > 2) |
| out_pix_fmts = out_rgb9_lowpass_pix_fmts; |
| else if (rgb && depth == 10 && ncomp > 2) |
| out_pix_fmts = out_rgb10_lowpass_pix_fmts; |
| else if (rgb && depth == 12 && ncomp > 2) |
| out_pix_fmts = out_rgb12_lowpass_pix_fmts; |
| else if (depth == 8 && ncomp > 2) |
| out_pix_fmts = out_yuv8_lowpass_pix_fmts; |
| else if (depth == 9 && ncomp > 2) |
| out_pix_fmts = out_yuv9_lowpass_pix_fmts; |
| else if (depth == 10 && ncomp > 2) |
| out_pix_fmts = out_yuv10_lowpass_pix_fmts; |
| else if (depth == 12 && ncomp > 2) |
| out_pix_fmts = out_yuv12_lowpass_pix_fmts; |
| else |
| return AVERROR(EAGAIN); |
| if ((ret = ff_formats_ref(ff_make_format_list(out_pix_fmts), &ctx->outputs[0]->incfg.formats)) < 0) |
| return ret; |
| |
| return 0; |
| } |
| |
| static void envelope_instant16(WaveformContext *s, AVFrame *out, int plane, int component, int offset) |
| { |
| const int dst_linesize = out->linesize[component] / 2; |
| const int bg = s->bg_color[component] * (s->max / 256); |
| const int limit = s->max - 1; |
| const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height; |
| const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width; |
| const int start = s->estart[plane]; |
| const int end = s->eend[plane]; |
| uint16_t *dst; |
| int x, y; |
| |
| if (s->mode) { |
| for (x = offset; x < offset + dst_w; x++) { |
| for (y = start; y < end; y++) { |
| dst = (uint16_t *)out->data[component] + y * dst_linesize + x; |
| if (dst[0] != bg) { |
| dst[0] = limit; |
| break; |
| } |
| } |
| for (y = end - 1; y >= start; y--) { |
| dst = (uint16_t *)out->data[component] + y * dst_linesize + x; |
| if (dst[0] != bg) { |
| dst[0] = limit; |
| break; |
| } |
| } |
| } |
| } else { |
| for (y = offset; y < offset + dst_h; y++) { |
| dst = (uint16_t *)out->data[component] + y * dst_linesize; |
| for (x = start; x < end; x++) { |
| if (dst[x] != bg) { |
| dst[x] = limit; |
| break; |
| } |
| } |
| for (x = end - 1; x >= start; x--) { |
| if (dst[x] != bg) { |
| dst[x] = limit; |
| break; |
| } |
| } |
| } |
| } |
| } |
| |
| static void envelope_instant(WaveformContext *s, AVFrame *out, int plane, int component, int offset) |
| { |
| const int dst_linesize = out->linesize[component]; |
| const uint8_t bg = s->bg_color[component]; |
| const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height; |
| const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width; |
| const int start = s->estart[plane]; |
| const int end = s->eend[plane]; |
| uint8_t *dst; |
| int x, y; |
| |
| if (s->mode) { |
| for (x = offset; x < offset + dst_w; x++) { |
| for (y = start; y < end; y++) { |
| dst = out->data[component] + y * dst_linesize + x; |
| if (dst[0] != bg) { |
| dst[0] = 255; |
| break; |
| } |
| } |
| for (y = end - 1; y >= start; y--) { |
| dst = out->data[component] + y * dst_linesize + x; |
| if (dst[0] != bg) { |
| dst[0] = 255; |
| break; |
| } |
| } |
| } |
| } else { |
| for (y = offset; y < offset + dst_h; y++) { |
| dst = out->data[component] + y * dst_linesize; |
| for (x = start; x < end; x++) { |
| if (dst[x] != bg) { |
| dst[x] = 255; |
| break; |
| } |
| } |
| for (x = end - 1; x >= start; x--) { |
| if (dst[x] != bg) { |
| dst[x] = 255; |
| break; |
| } |
| } |
| } |
| } |
| } |
| |
| static void envelope_peak16(WaveformContext *s, AVFrame *out, int plane, int component, int offset) |
| { |
| const int dst_linesize = out->linesize[component] / 2; |
| const int bg = s->bg_color[component] * (s->max / 256); |
| const int limit = s->max - 1; |
| const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height; |
| const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width; |
| const int start = s->estart[plane]; |
| const int end = s->eend[plane]; |
| int *emax = s->emax[plane][component]; |
| int *emin = s->emin[plane][component]; |
| uint16_t *dst; |
| int x, y; |
| |
| if (s->mode) { |
| for (x = offset; x < offset + dst_w; x++) { |
| for (y = start; y < end && y < emin[x - offset]; y++) { |
| dst = (uint16_t *)out->data[component] + y * dst_linesize + x; |
| if (dst[0] != bg) { |
| emin[x - offset] = y; |
| break; |
| } |
| } |
| for (y = end - 1; y >= start && y >= emax[x - offset]; y--) { |
| dst = (uint16_t *)out->data[component] + y * dst_linesize + x; |
| if (dst[0] != bg) { |
| emax[x - offset] = y; |
| break; |
| } |
| } |
| } |
| |
| if (s->envelope == 3) |
| envelope_instant16(s, out, plane, component, offset); |
| |
| for (x = offset; x < offset + dst_w; x++) { |
| dst = (uint16_t *)out->data[component] + emin[x - offset] * dst_linesize + x; |
| dst[0] = limit; |
| dst = (uint16_t *)out->data[component] + emax[x - offset] * dst_linesize + x; |
| dst[0] = limit; |
| } |
| } else { |
| for (y = offset; y < offset + dst_h; y++) { |
| dst = (uint16_t *)out->data[component] + y * dst_linesize; |
| for (x = start; x < end && x < emin[y - offset]; x++) { |
| if (dst[x] != bg) { |
| emin[y - offset] = x; |
| break; |
| } |
| } |
| for (x = end - 1; x >= start && x >= emax[y - offset]; x--) { |
| if (dst[x] != bg) { |
| emax[y - offset] = x; |
| break; |
| } |
| } |
| } |
| |
| if (s->envelope == 3) |
| envelope_instant16(s, out, plane, component, offset); |
| |
| for (y = offset; y < offset + dst_h; y++) { |
| dst = (uint16_t *)out->data[component] + y * dst_linesize + emin[y - offset]; |
| dst[0] = limit; |
| dst = (uint16_t *)out->data[component] + y * dst_linesize + emax[y - offset]; |
| dst[0] = limit; |
| } |
| } |
| } |
| |
| static void envelope_peak(WaveformContext *s, AVFrame *out, int plane, int component, int offset) |
| { |
| const int dst_linesize = out->linesize[component]; |
| const int bg = s->bg_color[component]; |
| const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height; |
| const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width; |
| const int start = s->estart[plane]; |
| const int end = s->eend[plane]; |
| int *emax = s->emax[plane][component]; |
| int *emin = s->emin[plane][component]; |
| uint8_t *dst; |
| int x, y; |
| |
| if (s->mode) { |
| for (x = offset; x < offset + dst_w; x++) { |
| for (y = start; y < end && y < emin[x - offset]; y++) { |
| dst = out->data[component] + y * dst_linesize + x; |
| if (dst[0] != bg) { |
| emin[x - offset] = y; |
| break; |
| } |
| } |
| for (y = end - 1; y >= start && y >= emax[x - offset]; y--) { |
| dst = out->data[component] + y * dst_linesize + x; |
| if (dst[0] != bg) { |
| emax[x - offset] = y; |
| break; |
| } |
| } |
| } |
| |
| if (s->envelope == 3) |
| envelope_instant(s, out, plane, component, offset); |
| |
| for (x = offset; x < offset + dst_w; x++) { |
| dst = out->data[component] + emin[x - offset] * dst_linesize + x; |
| dst[0] = 255; |
| dst = out->data[component] + emax[x - offset] * dst_linesize + x; |
| dst[0] = 255; |
| } |
| } else { |
| for (y = offset; y < offset + dst_h; y++) { |
| dst = out->data[component] + y * dst_linesize; |
| for (x = start; x < end && x < emin[y - offset]; x++) { |
| if (dst[x] != bg) { |
| emin[y - offset] = x; |
| break; |
| } |
| } |
| for (x = end - 1; x >= start && x >= emax[y - offset]; x--) { |
| if (dst[x] != bg) { |
| emax[y - offset] = x; |
| break; |
| } |
| } |
| } |
| |
| if (s->envelope == 3) |
| envelope_instant(s, out, plane, component, offset); |
| |
| for (y = offset; y < offset + dst_h; y++) { |
| dst = out->data[component] + y * dst_linesize + emin[y - offset]; |
| dst[0] = 255; |
| dst = out->data[component] + y * dst_linesize + emax[y - offset]; |
| dst[0] = 255; |
| } |
| } |
| } |
| |
| static void envelope16(WaveformContext *s, AVFrame *out, int plane, int component, int offset) |
| { |
| if (s->envelope == 0) { |
| return; |
| } else if (s->envelope == 1) { |
| envelope_instant16(s, out, plane, component, offset); |
| } else { |
| envelope_peak16(s, out, plane, component, offset); |
| } |
| } |
| |
| static void envelope(WaveformContext *s, AVFrame *out, int plane, int component, int offset) |
| { |
| if (s->envelope == 0) { |
| return; |
| } else if (s->envelope == 1) { |
| envelope_instant(s, out, plane, component, offset); |
| } else { |
| envelope_peak(s, out, plane, component, offset); |
| } |
| } |
| |
| static void update16(uint16_t *target, int max, int intensity, int limit) |
| { |
| if (*target <= max) |
| *target += intensity; |
| else |
| *target = limit; |
| } |
| |
| static void update(uint8_t *target, int max, int intensity) |
| { |
| if (*target <= max) |
| *target += intensity; |
| else |
| *target = 255; |
| } |
| |
| static void update_cr(uint8_t *target, int unused, int intensity) |
| { |
| if (*target - intensity > 0) |
| *target -= intensity; |
| else |
| *target = 0; |
| } |
| |
| static void update16_cr(uint16_t *target, int unused, int intensity, int limit) |
| { |
| if (*target - intensity > 0) |
| *target -= intensity; |
| else |
| *target = 0; |
| } |
| |
| static av_always_inline void lowpass16(WaveformContext *s, |
| AVFrame *in, AVFrame *out, |
| int component, int intensity, |
| int offset_y, int offset_x, |
| int column, int mirror, |
| int jobnr, int nb_jobs) |
| { |
| const int plane = s->desc->comp[component].plane; |
| const int dplane = (s->rgb || s->display == OVERLAY) ? plane : 0; |
| const int shift_w = s->shift_w[component]; |
| const int shift_h = s->shift_h[component]; |
| const int src_linesize = in->linesize[plane] / 2; |
| const int dst_linesize = out->linesize[dplane] / 2; |
| const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1); |
| const int limit = s->max - 1; |
| const int max = limit - intensity; |
| const int src_h = AV_CEIL_RSHIFT(in->height, shift_h); |
| const int src_w = AV_CEIL_RSHIFT(in->width, shift_w); |
| const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0; |
| const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h; |
| const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0; |
| const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w; |
| const int step = column ? 1 << shift_w : 1 << shift_h; |
| const uint16_t *src_data = (const uint16_t *)in->data[plane] + sliceh_start * src_linesize; |
| uint16_t *dst_data = (uint16_t *)out->data[dplane] + (offset_y + sliceh_start * step) * dst_linesize + offset_x; |
| uint16_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1); |
| uint16_t * const dst_line = (mirror ? dst_bottom_line : dst_data); |
| const uint16_t *p; |
| int y; |
| |
| if (!column && mirror) |
| dst_data += s->size; |
| |
| for (y = sliceh_start; y < sliceh_end; y++) { |
| const uint16_t *src_data_end = src_data + slicew_end; |
| uint16_t *dst = dst_line + slicew_start * step; |
| |
| for (p = src_data + slicew_start; p < src_data_end; p++) { |
| uint16_t *target; |
| int i = 0, v = FFMIN(*p, limit); |
| |
| if (column) { |
| do { |
| target = dst++ + dst_signed_linesize * v; |
| update16(target, max, intensity, limit); |
| } while (++i < step); |
| } else { |
| uint16_t *row = dst_data; |
| do { |
| if (mirror) |
| target = row - v - 1; |
| else |
| target = row + v; |
| update16(target, max, intensity, limit); |
| row += dst_linesize; |
| } while (++i < step); |
| } |
| } |
| src_data += src_linesize; |
| dst_data += dst_linesize * step; |
| } |
| |
| if (s->display != OVERLAY && column && !s->rgb) { |
| const int mult = s->max / 256; |
| const int bg = s->bg_color[0] * mult; |
| const int t0 = s->tint[0]; |
| const int t1 = s->tint[1]; |
| uint16_t *dst0, *dst1; |
| const uint16_t *src; |
| int x; |
| |
| src = (const uint16_t *)(out->data[0]) + offset_y * dst_linesize + offset_x; |
| dst0 = (uint16_t *)(out->data[1]) + offset_y * dst_linesize + offset_x; |
| dst1 = (uint16_t *)(out->data[2]) + offset_y * dst_linesize + offset_x; |
| for (y = 0; y < s->max; y++) { |
| for (x = slicew_start * step; x < slicew_end * step; x++) { |
| if (src[x] != bg) { |
| dst0[x] = t0; |
| dst1[x] = t1; |
| } |
| } |
| |
| src += dst_linesize; |
| dst0 += dst_linesize; |
| dst1 += dst_linesize; |
| } |
| } else if (s->display != OVERLAY && !s->rgb) { |
| const int mult = s->max / 256; |
| const int bg = s->bg_color[0] * mult; |
| const int t0 = s->tint[0]; |
| const int t1 = s->tint[1]; |
| uint16_t *dst0, *dst1; |
| const uint16_t *src; |
| int x; |
| |
| src = (const uint16_t *)out->data[0] + (offset_y + sliceh_start * step) * dst_linesize + offset_x; |
| dst0 = (uint16_t *)(out->data[1]) + (offset_y + sliceh_start * step) * dst_linesize + offset_x; |
| dst1 = (uint16_t *)(out->data[2]) + (offset_y + sliceh_start * step) * dst_linesize + offset_x; |
| for (y = sliceh_start * step; y < sliceh_end * step; y++) { |
| for (x = 0; x < s->max; x++) { |
| if (src[x] != bg) { |
| dst0[x] = t0; |
| dst1[x] = t1; |
| } |
| } |
| |
| src += dst_linesize; |
| dst0 += dst_linesize; |
| dst1 += dst_linesize; |
| } |
| } |
| } |
| |
| #define LOWPASS16_FUNC(name, column, mirror) \ |
| static int lowpass16_##name(AVFilterContext *ctx, \ |
| void *arg, int jobnr, \ |
| int nb_jobs) \ |
| { \ |
| WaveformContext *s = ctx->priv; \ |
| ThreadData *td = arg; \ |
| AVFrame *in = td->in; \ |
| AVFrame *out = td->out; \ |
| int component = td->component; \ |
| int offset_y = td->offset_y; \ |
| int offset_x = td->offset_x; \ |
| \ |
| lowpass16(s, in, out, component, s->intensity, \ |
| offset_y, offset_x, column, mirror, \ |
| jobnr, nb_jobs); \ |
| \ |
| return 0; \ |
| } |
| |
| LOWPASS16_FUNC(column_mirror, 1, 1) |
| LOWPASS16_FUNC(column, 1, 0) |
| LOWPASS16_FUNC(row_mirror, 0, 1) |
| LOWPASS16_FUNC(row, 0, 0) |
| |
| static av_always_inline void lowpass(WaveformContext *s, |
| AVFrame *in, AVFrame *out, |
| int component, int intensity, |
| int offset_y, int offset_x, |
| int column, int mirror, |
| int jobnr, int nb_jobs) |
| { |
| const int plane = s->desc->comp[component].plane; |
| const int dplane = (s->rgb || s->display == OVERLAY) ? plane : 0; |
| const int shift_w = s->shift_w[component]; |
| const int shift_h = s->shift_h[component]; |
| const int src_linesize = in->linesize[plane]; |
| const int dst_linesize = out->linesize[dplane]; |
| const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1); |
| const int max = 255 - intensity; |
| const int src_h = AV_CEIL_RSHIFT(in->height, shift_h); |
| const int src_w = AV_CEIL_RSHIFT(in->width, shift_w); |
| const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0; |
| const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h; |
| const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0; |
| const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w; |
| const int step = column ? 1 << shift_w : 1 << shift_h; |
| const uint8_t *src_data = in->data[plane] + sliceh_start * src_linesize; |
| uint8_t *dst_data = out->data[dplane] + (offset_y + sliceh_start * step) * dst_linesize + offset_x; |
| uint8_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1); |
| uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data); |
| const uint8_t *p; |
| int y; |
| |
| if (!column && mirror) |
| dst_data += s->size; |
| |
| for (y = sliceh_start; y < sliceh_end; y++) { |
| const uint8_t *src_data_end = src_data + slicew_end; |
| uint8_t *dst = dst_line + slicew_start * step; |
| |
| for (p = src_data + slicew_start; p < src_data_end; p++) { |
| uint8_t *target; |
| int i = 0; |
| |
| if (column) { |
| do { |
| target = dst++ + dst_signed_linesize * *p; |
| update(target, max, intensity); |
| } while (++i < step); |
| } else { |
| uint8_t *row = dst_data; |
| do { |
| if (mirror) |
| target = row - *p - 1; |
| else |
| target = row + *p; |
| update(target, max, intensity); |
| row += dst_linesize; |
| } while (++i < step); |
| } |
| } |
| src_data += src_linesize; |
| dst_data += dst_linesize * step; |
| } |
| |
| if (s->display != OVERLAY && column && !s->rgb) { |
| const int bg = s->bg_color[0]; |
| const int dst_h = 256; |
| const int t0 = s->tint[0]; |
| const int t1 = s->tint[1]; |
| uint8_t *dst0, *dst1; |
| const uint8_t *src; |
| int x; |
| |
| src = out->data[0] + offset_y * dst_linesize + offset_x; |
| dst0 = out->data[1] + offset_y * dst_linesize + offset_x; |
| dst1 = out->data[2] + offset_y * dst_linesize + offset_x; |
| for (y = 0; y < dst_h; y++) { |
| for (x = slicew_start * step; x < slicew_end * step; x++) { |
| if (src[x] != bg) { |
| dst0[x] = t0; |
| dst1[x] = t1; |
| } |
| } |
| |
| src += dst_linesize; |
| dst0 += dst_linesize; |
| dst1 += dst_linesize; |
| } |
| } else if (s->display != OVERLAY && !s->rgb) { |
| const int bg = s->bg_color[0]; |
| const int dst_w = 256; |
| const int t0 = s->tint[0]; |
| const int t1 = s->tint[1]; |
| uint8_t *dst0, *dst1; |
| const uint8_t *src; |
| int x; |
| |
| src = out->data[0] + (offset_y + sliceh_start * step) * dst_linesize + offset_x; |
| dst0 = out->data[1] + (offset_y + sliceh_start * step) * dst_linesize + offset_x; |
| dst1 = out->data[2] + (offset_y + sliceh_start * step) * dst_linesize + offset_x; |
| for (y = sliceh_start * step; y < sliceh_end * step; y++) { |
| for (x = 0; x < dst_w; x++) { |
| if (src[x] != bg) { |
| dst0[x] = t0; |
| dst1[x] = t1; |
| } |
| } |
| |
| src += dst_linesize; |
| dst0 += dst_linesize; |
| dst1 += dst_linesize; |
| } |
| } |
| } |
| |
| #define LOWPASS_FUNC(name, column, mirror) \ |
| static int lowpass_##name(AVFilterContext *ctx, \ |
| void *arg, int jobnr, \ |
| int nb_jobs) \ |
| { \ |
| WaveformContext *s = ctx->priv; \ |
| ThreadData *td = arg; \ |
| AVFrame *in = td->in; \ |
| AVFrame *out = td->out; \ |
| int component = td->component; \ |
| int offset_y = td->offset_y; \ |
| int offset_x = td->offset_x; \ |
| \ |
| lowpass(s, in, out, component, s->intensity, \ |
| offset_y, offset_x, column, mirror, \ |
| jobnr, nb_jobs); \ |
| \ |
| return 0; \ |
| } |
| |
| LOWPASS_FUNC(column_mirror, 1, 1) |
| LOWPASS_FUNC(column, 1, 0) |
| LOWPASS_FUNC(row_mirror, 0, 1) |
| LOWPASS_FUNC(row, 0, 0) |
| |
| static av_always_inline void flat16(WaveformContext *s, |
| AVFrame *in, AVFrame *out, |
| int component, int intensity, |
| int offset_y, int offset_x, |
| int column, int mirror, |
| int jobnr, int nb_jobs) |
| { |
| const int plane = s->desc->comp[component].plane; |
| const int c0_linesize = in->linesize[ plane + 0 ] / 2; |
| const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2; |
| const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2; |
| const int c0_shift_w = s->shift_w[ component + 0 ]; |
| const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp]; |
| const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp]; |
| const int c0_shift_h = s->shift_h[ component + 0 ]; |
| const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp]; |
| const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp]; |
| const int d0_linesize = out->linesize[ plane + 0 ] / 2; |
| const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2; |
| const int limit = s->max - 1; |
| const int max = limit - intensity; |
| const int mid = s->max / 2; |
| const int src_h = in->height; |
| const int src_w = in->width; |
| const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0; |
| const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h; |
| const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0; |
| const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w; |
| int x, y; |
| |
| if (column) { |
| const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1); |
| const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1); |
| |
| for (x = slicew_start; x < slicew_end; x++) { |
| const uint16_t *c0_data = (uint16_t *)in->data[plane + 0]; |
| const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp]; |
| const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp]; |
| uint16_t *d0_data = (uint16_t *)(out->data[plane]) + offset_y * d0_linesize + offset_x; |
| uint16_t *d1_data = (uint16_t *)(out->data[(plane + 1) % s->ncomp]) + offset_y * d1_linesize + offset_x; |
| uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1); |
| uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data); |
| uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1); |
| uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data); |
| |
| for (y = 0; y < src_h; y++) { |
| const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + s->max; |
| const int c1 = FFMIN(FFABS(c1_data[x >> c1_shift_w] - mid) + FFABS(c2_data[x >> c2_shift_w] - mid), limit); |
| uint16_t *target; |
| |
| target = d0 + x + d0_signed_linesize * c0; |
| update16(target, max, intensity, limit); |
| target = d1 + x + d1_signed_linesize * (c0 - c1); |
| update16(target, max, intensity, limit); |
| target = d1 + x + d1_signed_linesize * (c0 + c1); |
| update16(target, max, intensity, limit); |
| |
| if (!c0_shift_h || (y & c0_shift_h)) |
| c0_data += c0_linesize; |
| if (!c1_shift_h || (y & c1_shift_h)) |
| c1_data += c1_linesize; |
| if (!c2_shift_h || (y & c2_shift_h)) |
| c2_data += c2_linesize; |
| d0_data += d0_linesize; |
| d1_data += d1_linesize; |
| } |
| } |
| } else { |
| const uint16_t *c0_data = (uint16_t *)(in->data[plane]) + (sliceh_start >> c0_shift_h) * c0_linesize; |
| const uint16_t *c1_data = (uint16_t *)(in->data[(plane + 1) % s->ncomp]) + (sliceh_start >> c1_shift_h) * c1_linesize; |
| const uint16_t *c2_data = (uint16_t *)(in->data[(plane + 2) % s->ncomp]) + (sliceh_start >> c2_shift_h) * c2_linesize; |
| uint16_t *d0_data = (uint16_t *)(out->data[plane]) + (offset_y + sliceh_start) * d0_linesize + offset_x; |
| uint16_t *d1_data = (uint16_t *)(out->data[(plane + 1) % s->ncomp]) + (offset_y + sliceh_start) * d1_linesize + offset_x; |
| |
| if (mirror) { |
| d0_data += s->size - 1; |
| d1_data += s->size - 1; |
| } |
| |
| for (y = sliceh_start; y < sliceh_end; y++) { |
| for (x = 0; x < src_w; x++) { |
| const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + s->max; |
| const int c1 = FFMIN(FFABS(c1_data[x >> c1_shift_w] - mid) + FFABS(c2_data[x >> c2_shift_w] - mid), limit); |
| uint16_t *target; |
| |
| if (mirror) { |
| target = d0_data - c0; |
| update16(target, max, intensity, limit); |
| target = d1_data - (c0 - c1); |
| update16(target, max, intensity, limit); |
| target = d1_data - (c0 + c1); |
| update16(target, max, intensity, limit); |
| } else { |
| target = d0_data + c0; |
| update16(target, max, intensity, limit); |
| target = d1_data + (c0 - c1); |
| update16(target, max, intensity, limit); |
| target = d1_data + (c0 + c1); |
| update16(target, max, intensity, limit); |
| } |
| } |
| |
| if (!c0_shift_h || (y & c0_shift_h)) |
| c0_data += c0_linesize; |
| if (!c1_shift_h || (y & c1_shift_h)) |
| c1_data += c1_linesize; |
| if (!c2_shift_h || (y & c2_shift_h)) |
| c2_data += c2_linesize; |
| d0_data += d0_linesize; |
| d1_data += d1_linesize; |
| } |
| } |
| } |
| |
| #define FLAT16_FUNC(name, column, mirror) \ |
| static int flat16_##name(AVFilterContext *ctx, \ |
| void *arg, int jobnr, \ |
| int nb_jobs) \ |
| { \ |
| WaveformContext *s = ctx->priv; \ |
| ThreadData *td = arg; \ |
| AVFrame *in = td->in; \ |
| AVFrame *out = td->out; \ |
| int component = td->component; \ |
| int offset_y = td->offset_y; \ |
| int offset_x = td->offset_x; \ |
| \ |
| flat16(s, in, out, component, s->intensity, \ |
| offset_y, offset_x, column, mirror, \ |
| jobnr, nb_jobs); \ |
| \ |
| return 0; \ |
| } |
| |
| FLAT16_FUNC(column_mirror, 1, 1) |
| FLAT16_FUNC(column, 1, 0) |
| FLAT16_FUNC(row_mirror, 0, 1) |
| FLAT16_FUNC(row, 0, 0) |
| |
| static av_always_inline void flat(WaveformContext *s, |
| AVFrame *in, AVFrame *out, |
| int component, int intensity, |
| int offset_y, int offset_x, |
| int column, int mirror, |
| int jobnr, int nb_jobs) |
| { |
| const int plane = s->desc->comp[component].plane; |
| const int c0_linesize = in->linesize[ plane + 0 ]; |
| const int c1_linesize = in->linesize[(plane + 1) % s->ncomp]; |
| const int c2_linesize = in->linesize[(plane + 2) % s->ncomp]; |
| const int c0_shift_w = s->shift_w[ component + 0 ]; |
| const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp]; |
| const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp]; |
| const int c0_shift_h = s->shift_h[ component + 0 ]; |
| const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp]; |
| const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp]; |
| const int d0_linesize = out->linesize[ plane + 0 ]; |
| const int d1_linesize = out->linesize[(plane + 1) % s->ncomp]; |
| const int max = 255 - intensity; |
| const int src_h = in->height; |
| const int src_w = in->width; |
| const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0; |
| const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h; |
| const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0; |
| const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w; |
| int x, y; |
| |
| if (column) { |
| const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1); |
| const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1); |
| |
| for (x = slicew_start; x < slicew_end; x++) { |
| const uint8_t *c0_data = in->data[plane + 0]; |
| const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp]; |
| const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp]; |
| uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x; |
| uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x; |
| uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1); |
| uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data); |
| uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1); |
| uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data); |
| |
| for (y = 0; y < src_h; y++) { |
| const int c0 = c0_data[x >> c0_shift_w] + 256; |
| const int c1 = FFABS(c1_data[x >> c1_shift_w] - 128) + FFABS(c2_data[x >> c2_shift_w] - 128); |
| uint8_t *target; |
| |
| target = d0 + x + d0_signed_linesize * c0; |
| update(target, max, intensity); |
| target = d1 + x + d1_signed_linesize * (c0 - c1); |
| update(target, max, intensity); |
| target = d1 + x + d1_signed_linesize * (c0 + c1); |
| update(target, max, intensity); |
| |
| if (!c0_shift_h || (y & c0_shift_h)) |
| c0_data += c0_linesize; |
| if (!c1_shift_h || (y & c1_shift_h)) |
| c1_data += c1_linesize; |
| if (!c2_shift_h || (y & c2_shift_h)) |
| c2_data += c2_linesize; |
| d0_data += d0_linesize; |
| d1_data += d1_linesize; |
| } |
| } |
| } else { |
| const uint8_t *c0_data = in->data[plane] + (sliceh_start >> c0_shift_h) * c0_linesize; |
| const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize; |
| const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize; |
| uint8_t *d0_data = out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x; |
| uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x; |
| |
| if (mirror) { |
| d0_data += s->size - 1; |
| d1_data += s->size - 1; |
| } |
| |
| for (y = sliceh_start; y < sliceh_end; y++) { |
| for (x = 0; x < src_w; x++) { |
| const int c0 = c0_data[x >> c0_shift_w] + 256; |
| const int c1 = FFABS(c1_data[x >> c1_shift_w] - 128) + FFABS(c2_data[x >> c2_shift_w] - 128); |
| uint8_t *target; |
| |
| if (mirror) { |
| target = d0_data - c0; |
| update(target, max, intensity); |
| target = d1_data - (c0 - c1); |
| update(target, max, intensity); |
| target = d1_data - (c0 + c1); |
| update(target, max, intensity); |
| } else { |
| target = d0_data + c0; |
| update(target, max, intensity); |
| target = d1_data + (c0 - c1); |
| update(target, max, intensity); |
| target = d1_data + (c0 + c1); |
| update(target, max, intensity); |
| } |
| } |
| |
| if (!c0_shift_h || (y & c0_shift_h)) |
| c0_data += c0_linesize; |
| if (!c1_shift_h || (y & c1_shift_h)) |
| c1_data += c1_linesize; |
| if (!c2_shift_h || (y & c2_shift_h)) |
| c2_data += c2_linesize; |
| d0_data += d0_linesize; |
| d1_data += d1_linesize; |
| } |
| } |
| } |
| |
| #define FLAT_FUNC(name, column, mirror) \ |
| static int flat_##name(AVFilterContext *ctx, \ |
| void *arg, int jobnr, \ |
| int nb_jobs) \ |
| { \ |
| WaveformContext *s = ctx->priv; \ |
| ThreadData *td = arg; \ |
| AVFrame *in = td->in; \ |
| AVFrame *out = td->out; \ |
| int component = td->component; \ |
| int offset_y = td->offset_y; \ |
| int offset_x = td->offset_x; \ |
| \ |
| flat(s, in, out, component, s->intensity, \ |
| offset_y, offset_x, column, mirror, \ |
| jobnr, nb_jobs); \ |
| \ |
| return 0; \ |
| } |
| |
| FLAT_FUNC(column_mirror, 1, 1) |
| FLAT_FUNC(column, 1, 0) |
| FLAT_FUNC(row_mirror, 0, 1) |
| FLAT_FUNC(row, 0, 0) |
| |
| #define AFLAT16(name, update_cb, update_cr, column, mirror) \ |
| static int name(AVFilterContext *ctx, \ |
| void *arg, int jobnr, \ |
| int nb_jobs) \ |
| { \ |
| WaveformContext *s = ctx->priv; \ |
| ThreadData *td = arg; \ |
| AVFrame *in = td->in; \ |
| AVFrame *out = td->out; \ |
| int component = td->component; \ |
| int offset_y = td->offset_y; \ |
| int offset_x = td->offset_x; \ |
| const int intensity = s->intensity; \ |
| const int plane = s->desc->comp[component].plane; \ |
| const int c0_linesize = in->linesize[ plane + 0 ] / 2; \ |
| const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2; \ |
| const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2; \ |
| const int c0_shift_w = s->shift_w[ component + 0 ]; \ |
| const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp]; \ |
| const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp]; \ |
| const int c0_shift_h = s->shift_h[ component + 0 ]; \ |
| const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp]; \ |
| const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp]; \ |
| const int d0_linesize = out->linesize[ plane + 0 ] / 2; \ |
| const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2; \ |
| const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2; \ |
| const int limit = s->max - 1; \ |
| const int max = limit - intensity; \ |
| const int mid = s->max / 2; \ |
| const int src_h = in->height; \ |
| const int src_w = in->width; \ |
| const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0; \ |
| const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h; \ |
| const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0; \ |
| const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w; \ |
| int x, y; \ |
| \ |
| if (column) { \ |
| const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1); \ |
| const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1); \ |
| const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1); \ |
| \ |
| for (x = slicew_start; x < slicew_end; x++) { \ |
| const uint16_t *c0_data = (uint16_t *)in->data[plane + 0]; \ |
| const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp]; \ |
| const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp]; \ |
| uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x; \ |
| uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x; \ |
| uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x; \ |
| uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1); \ |
| uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data); \ |
| uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1); \ |
| uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data); \ |
| uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1); \ |
| uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data); \ |
| \ |
| for (y = 0; y < src_h; y++) { \ |
| const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + mid; \ |
| const int c1 = FFMIN(c1_data[x >> c1_shift_w], limit) - mid; \ |
| const int c2 = FFMIN(c2_data[x >> c2_shift_w], limit) - mid; \ |
| uint16_t *target; \ |
| \ |
| target = d0 + x + d0_signed_linesize * c0; \ |
| update16(target, max, intensity, limit); \ |
| \ |
| target = d1 + x + d1_signed_linesize * (c0 + c1); \ |
| update_cb(target, max, intensity, limit); \ |
| \ |
| target = d2 + x + d2_signed_linesize * (c0 + c2); \ |
| update_cr(target, max, intensity, limit); \ |
| \ |
| if (!c0_shift_h || (y & c0_shift_h)) \ |
| c0_data += c0_linesize; \ |
| if (!c1_shift_h || (y & c1_shift_h)) \ |
| c1_data += c1_linesize; \ |
| if (!c2_shift_h || (y & c2_shift_h)) \ |
| c2_data += c2_linesize; \ |
| d0_data += d0_linesize; \ |
| d1_data += d1_linesize; \ |
| d2_data += d2_linesize; \ |
| } \ |
| } \ |
| } else { \ |
| const uint16_t *c0_data = (uint16_t *)in->data[plane] + (sliceh_start >> c0_shift_h) * c0_linesize; \ |
| const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize; \ |
| const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize; \ |
| uint16_t *d0_data = (uint16_t *)out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x; \ |
| uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x; \ |
| uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + (offset_y + sliceh_start) * d2_linesize + offset_x; \ |
| \ |
| if (mirror) { \ |
| d0_data += s->size - 1; \ |
| d1_data += s->size - 1; \ |
| d2_data += s->size - 1; \ |
| } \ |
| \ |
| for (y = sliceh_start; y < sliceh_end; y++) { \ |
| for (x = 0; x < src_w; x++) { \ |
| const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + mid; \ |
| const int c1 = FFMIN(c1_data[x >> c1_shift_w], limit) - mid; \ |
| const int c2 = FFMIN(c2_data[x >> c2_shift_w], limit) - mid; \ |
| uint16_t *target; \ |
| \ |
| if (mirror) { \ |
| target = d0_data - c0; \ |
| update16(target, max, intensity, limit); \ |
| target = d1_data - (c0 + c1); \ |
| update_cb(target, max, intensity, limit); \ |
| target = d2_data - (c0 + c2); \ |
| update_cr(target, max, intensity, limit); \ |
| } else { \ |
| target = d0_data + c0; \ |
| update16(target, max, intensity, limit); \ |
| target = d1_data + (c0 + c1); \ |
| update_cb(target, max, intensity, limit); \ |
| target = d2_data + (c0 + c2); \ |
| update_cr(target, max, intensity, limit); \ |
| } \ |
| } \ |
| \ |
| if (!c0_shift_h || (y & c0_shift_h)) \ |
| c0_data += c0_linesize; \ |
| if (!c1_shift_h || (y & c1_shift_h)) \ |
| c1_data += c1_linesize; \ |
| if (!c2_shift_h || (y & c2_shift_h)) \ |
| c2_data += c2_linesize; \ |
| d0_data += d0_linesize; \ |
| d1_data += d1_linesize; \ |
| d2_data += d2_linesize; \ |
| } \ |
| } \ |
| return 0; \ |
| } |
| |
| #define AFLAT(name, update_cb, update_cr, column, mirror) \ |
| static int name(AVFilterContext *ctx, \ |
| void *arg, int jobnr, \ |
| int nb_jobs) \ |
| { \ |
| WaveformContext *s = ctx->priv; \ |
| ThreadData *td = arg; \ |
| AVFrame *in = td->in; \ |
| AVFrame *out = td->out; \ |
| int component = td->component; \ |
| int offset_y = td->offset_y; \ |
| int offset_x = td->offset_x; \ |
| const int src_h = in->height; \ |
| const int src_w = in->width; \ |
| const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0; \ |
| const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h; \ |
| const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0; \ |
| const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w; \ |
| const int intensity = s->intensity; \ |
| const int plane = s->desc->comp[component].plane; \ |
| const int c0_linesize = in->linesize[ plane + 0 ]; \ |
| const int c1_linesize = in->linesize[(plane + 1) % s->ncomp]; \ |
| const int c2_linesize = in->linesize[(plane + 2) % s->ncomp]; \ |
| const int c0_shift_w = s->shift_w[ component + 0 ]; \ |
| const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp]; \ |
| const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp]; \ |
| const int c0_shift_h = s->shift_h[ component + 0 ]; \ |
| const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp]; \ |
| const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp]; \ |
| const int d0_linesize = out->linesize[ plane + 0 ]; \ |
| const int d1_linesize = out->linesize[(plane + 1) % s->ncomp]; \ |
| const int d2_linesize = out->linesize[(plane + 2) % s->ncomp]; \ |
| const int max = 255 - intensity; \ |
| int x, y; \ |
| \ |
| if (column) { \ |
| const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1); \ |
| const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1); \ |
| const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1); \ |
| \ |
| for (x = slicew_start; x < slicew_end; x++) { \ |
| const uint8_t *c0_data = in->data[plane + 0]; \ |
| const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp]; \ |
| const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp]; \ |
| uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x; \ |
| uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x; \ |
| uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x; \ |
| uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1); \ |
| uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data); \ |
| uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1); \ |
| uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data); \ |
| uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1); \ |
| uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data); \ |
| \ |
| for (y = 0; y < src_h; y++) { \ |
| const int c0 = c0_data[x >> c0_shift_w] + 128; \ |
| const int c1 = c1_data[x >> c1_shift_w] - 128; \ |
| const int c2 = c2_data[x >> c2_shift_w] - 128; \ |
| uint8_t *target; \ |
| \ |
| target = d0 + x + d0_signed_linesize * c0; \ |
| update(target, max, intensity); \ |
| \ |
| target = d1 + x + d1_signed_linesize * (c0 + c1); \ |
| update_cb(target, max, intensity); \ |
| \ |
| target = d2 + x + d2_signed_linesize * (c0 + c2); \ |
| update_cr(target, max, intensity); \ |
| \ |
| if (!c0_shift_h || (y & c0_shift_h)) \ |
| c0_data += c0_linesize; \ |
| if (!c1_shift_h || (y & c1_shift_h)) \ |
| c1_data += c1_linesize; \ |
| if (!c2_shift_h || (y & c2_shift_h)) \ |
| c2_data += c2_linesize; \ |
| d0_data += d0_linesize; \ |
| d1_data += d1_linesize; \ |
| d2_data += d2_linesize; \ |
| } \ |
| } \ |
| } else { \ |
| const uint8_t *c0_data = in->data[plane] + (sliceh_start >> c0_shift_h) * c0_linesize; \ |
| const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize; \ |
| const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize; \ |
| uint8_t *d0_data = out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x; \ |
| uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x; \ |
| uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + (offset_y + sliceh_start) * d2_linesize + offset_x; \ |
| \ |
| if (mirror) { \ |
| d0_data += s->size - 1; \ |
| d1_data += s->size - 1; \ |
| d2_data += s->size - 1; \ |
| } \ |
| \ |
| for (y = sliceh_start; y < sliceh_end; y++) { \ |
| for (x = 0; x < src_w; x++) { \ |
| const int c0 = c0_data[x >> c0_shift_w] + 128; \ |
| const int c1 = c1_data[x >> c1_shift_w] - 128; \ |
| const int c2 = c2_data[x >> c2_shift_w] - 128; \ |
| uint8_t *target; \ |
| \ |
| if (mirror) { \ |
| target = d0_data - c0; \ |
| update(target, max, intensity); \ |
| target = d1_data - (c0 + c1); \ |
| update_cb(target, max, intensity); \ |
| target = d2_data - (c0 + c2); \ |
| update_cr(target, max, intensity); \ |
| } else { \ |
| target = d0_data + c0; \ |
| update(target, max, intensity); \ |
| target = d1_data + (c0 + c1); \ |
| update_cb(target, max, intensity); \ |
| target = d2_data + (c0 + c2); \ |
| update_cr(target, max, intensity); \ |
| } \ |
| } \ |
| \ |
| if (!c0_shift_h || (y & c0_shift_h)) \ |
| c0_data += c0_linesize; \ |
| if (!c1_shift_h || (y & c1_shift_h)) \ |
| c1_data += c1_linesize; \ |
| if (!c2_shift_h || (y & c2_shift_h)) \ |
| c2_data += c2_linesize; \ |
| d0_data += d0_linesize; \ |
| d1_data += d1_linesize; \ |
| d2_data += d2_linesize; \ |
| } \ |
| } \ |
| return 0; \ |
| } |
| |
| AFLAT16(aflat16_row, update16, update16, 0, 0) |
| AFLAT16(aflat16_row_mirror, update16, update16, 0, 1) |
| AFLAT16(aflat16_column, update16, update16, 1, 0) |
| AFLAT16(aflat16_column_mirror, update16, update16, 1, 1) |
| AFLAT16(xflat16_row, update16, update16_cr, 0, 0) |
| AFLAT16(xflat16_row_mirror, update16, update16_cr, 0, 1) |
| AFLAT16(xflat16_column, update16, update16_cr, 1, 0) |
| AFLAT16(xflat16_column_mirror, update16, update16_cr, 1, 1) |
| AFLAT16(yflat16_row, update16_cr, update16_cr, 0, 0) |
| AFLAT16(yflat16_row_mirror, update16_cr, update16_cr, 0, 1) |
| AFLAT16(yflat16_column, update16_cr, update16_cr, 1, 0) |
| AFLAT16(yflat16_column_mirror, update16_cr, update16_cr, 1, 1) |
| |
| AFLAT(aflat_row, update, update, 0, 0) |
| AFLAT(aflat_row_mirror, update, update, 0, 1) |
| AFLAT(aflat_column, update, update, 1, 0) |
| AFLAT(aflat_column_mirror, update, update, 1, 1) |
| AFLAT(xflat_row, update, update_cr, 0, 0) |
| AFLAT(xflat_row_mirror, update, update_cr, 0, 1) |
| AFLAT(xflat_column, update, update_cr, 1, 0) |
| AFLAT(xflat_column_mirror, update, update_cr, 1, 1) |
| AFLAT(yflat_row, update_cr, update_cr, 0, 0) |
| AFLAT(yflat_row_mirror, update_cr, update_cr, 0, 1) |
| AFLAT(yflat_column, update_cr, update_cr, 1, 0) |
| AFLAT(yflat_column_mirror, update_cr, update_cr, 1, 1) |
| |
| static av_always_inline void chroma16(WaveformContext *s, |
| AVFrame *in, AVFrame *out, |
| int component, int intensity, |
| int offset_y, int offset_x, |
| int column, int mirror, |
| int jobnr, int nb_jobs) |
| { |
| const int plane = s->desc->comp[component].plane; |
| const int c0_linesize = in->linesize[(plane + 1) % s->ncomp] / 2; |
| const int c1_linesize = in->linesize[(plane + 2) % s->ncomp] / 2; |
| const int dst_linesize = out->linesize[plane] / 2; |
| const int limit = s->max - 1; |
| const int max = limit - intensity; |
| const int mid = s->max / 2; |
| const int c0_shift_w = s->shift_w[(component + 1) % s->ncomp]; |
| const int c1_shift_w = s->shift_w[(component + 2) % s->ncomp]; |
| const int c0_shift_h = s->shift_h[(component + 1) % s->ncomp]; |
| const int c1_shift_h = s->shift_h[(component + 2) % s->ncomp]; |
| const int src_h = in->height; |
| const int src_w = in->width; |
| const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0; |
| const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h; |
| const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0; |
| const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w; |
| int x, y; |
| |
| if (column) { |
| const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1); |
| |
| for (x = slicew_start; x < slicew_end; x++) { |
| const uint16_t *c0_data = (uint16_t *)in->data[(plane + 1) % s->ncomp]; |
| const uint16_t *c1_data = (uint16_t *)in->data[(plane + 2) % s->ncomp]; |
| uint16_t *dst_data = (uint16_t *)out->data[plane] + offset_y * dst_linesize + offset_x; |
| uint16_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1); |
| uint16_t * const dst_line = (mirror ? dst_bottom_line : dst_data); |
| uint16_t *dst = dst_line; |
| |
| for (y = 0; y < src_h; y++) { |
| const int sum = FFMIN(FFABS(c0_data[x >> c0_shift_w] - mid) + FFABS(c1_data[x >> c1_shift_w] - mid - 1), limit); |
| uint16_t *target; |
| |
| target = dst + x + dst_signed_linesize * sum; |
| update16(target, max, intensity, limit); |
| |
| if (!c0_shift_h || (y & c0_shift_h)) |
| c0_data += c0_linesize; |
| if (!c1_shift_h || (y & c1_shift_h)) |
| c1_data += c1_linesize; |
| dst_data += dst_linesize; |
| } |
| } |
| } else { |
| const uint16_t *c0_data = (uint16_t *)in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c0_shift_h) * c0_linesize; |
| const uint16_t *c1_data = (uint16_t *)in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize; |
| uint16_t *dst_data = (uint16_t *)out->data[plane] + (offset_y + sliceh_start) * dst_linesize + offset_x; |
| |
| if (mirror) |
| dst_data += s->size - 1; |
| for (y = sliceh_start; y < sliceh_end; y++) { |
| for (x = 0; x < src_w; x++) { |
| const int sum = FFMIN(FFABS(c0_data[x >> c0_shift_w] - mid) + FFABS(c1_data[x >> c1_shift_w] - mid - 1), limit); |
| uint16_t *target; |
| |
| if (mirror) { |
| target = dst_data - sum; |
| update16(target, max, intensity, limit); |
| } else { |
| target = dst_data + sum; |
| update16(target, max, intensity, limit); |
| } |
| } |
| |
| if (!c0_shift_h || (y & c0_shift_h)) |
| c0_data += c0_linesize; |
| if (!c1_shift_h || (y & c1_shift_h)) |
| c1_data += c1_linesize; |
| dst_data += dst_linesize; |
| } |
| } |
| } |
| |
| #define CHROMA16_FUNC(name, column, mirror) \ |
| static int chroma16_##name(AVFilterContext *ctx, \ |
| void *arg, int jobnr, \ |
| int nb_jobs) \ |
| { \ |
| WaveformContext *s = ctx->priv; \ |
| ThreadData *td = arg; \ |
| AVFrame *in = td->in; \ |
| AVFrame *out = td->out; \ |
| int component = td->component; \ |
| int offset_y = td->offset_y; \ |
| int offset_x = td->offset_x; \ |
| \ |
| chroma16(s, in, out, component, s->intensity,\ |
| offset_y, offset_x, column, mirror, \ |
| jobnr, nb_jobs); \ |
| \ |
| return 0; \ |
| } |
| |
| CHROMA16_FUNC(column_mirror, 1, 1) |
| CHROMA16_FUNC(column, 1, 0) |
| CHROMA16_FUNC(row_mirror, 0, 1) |
| CHROMA16_FUNC(row, 0, 0) |
| |
| static av_always_inline void chroma(WaveformContext *s, |
| AVFrame *in, AVFrame *out, |
| int component, int intensity, |
| int offset_y, int offset_x, |
| int column, int mirror, |
| int jobnr, int nb_jobs) |
| { |
| const int plane = s->desc->comp[component].plane; |
| const int src_h = in->height; |
| const int src_w = in->width; |
| const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0; |
| const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h; |
| const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0; |
| const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w; |
| const int c0_linesize = in->linesize[(plane + 1) % s->ncomp]; |
| const int c1_linesize = in->linesize[(plane + 2) % s->ncomp]; |
| const int dst_linesize = out->linesize[plane]; |
| const int max = 255 - intensity; |
| const int c0_shift_w = s->shift_w[(component + 1) % s->ncomp]; |
| const int c1_shift_w = s->shift_w[(component + 2) % s->ncomp]; |
| const int c0_shift_h = s->shift_h[(component + 1) % s->ncomp]; |
| const int c1_shift_h = s->shift_h[(component + 2) % s->ncomp]; |
| int x, y; |
| |
| if (column) { |
| const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1); |
| |
| for (x = slicew_start; x < slicew_end; x++) { |
| const uint8_t *c0_data = in->data[(plane + 1) % s->ncomp]; |
| const uint8_t *c1_data = in->data[(plane + 2) % s->ncomp]; |
| uint8_t *dst_data = out->data[plane] + offset_y * dst_linesize + offset_x; |
| uint8_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1); |
| uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data); |
| uint8_t *dst = dst_line; |
| |
| for (y = 0; y < src_h; y++) { |
| const int sum = FFABS(c0_data[x >> c0_shift_w] - 128) + FFABS(c1_data[x >> c1_shift_w] - 127); |
| uint8_t *target; |
| |
| target = dst + x + dst_signed_linesize * sum; |
| update(target, max, intensity); |
| |
| if (!c0_shift_h || (y & c0_shift_h)) |
| c0_data += c0_linesize; |
| if (!c1_shift_h || (y & c1_shift_h)) |
| c1_data += c1_linesize; |
| dst_data += dst_linesize; |
| } |
| } |
| } else { |
| const uint8_t *c0_data = in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c0_shift_h) * c0_linesize; |
| const uint8_t *c1_data = in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize; |
| uint8_t *dst_data = out->data[plane] + (offset_y + sliceh_start) * dst_linesize + offset_x; |
| |
| if (mirror) |
| dst_data += s->size - 1; |
| for (y = sliceh_start; y < sliceh_end; y++) { |
| for (x = 0; x < src_w; x++) { |
| const int sum = FFABS(c0_data[x >> c0_shift_w] - 128) + FFABS(c1_data[x >> c1_shift_w] - 127); |
| uint8_t *target; |
| |
| if (mirror) { |
| target = dst_data - sum; |
| update(target, max, intensity); |
| } else { |
| target = dst_data + sum; |
| update(target, max, intensity); |
| } |
| } |
| |
| if (!c0_shift_h || (y & c0_shift_h)) |
| c0_data += c0_linesize; |
| if (!c1_shift_h || (y & c1_shift_h)) |
| c1_data += c1_linesize; |
| dst_data += dst_linesize; |
| } |
| } |
| } |
| |
| #define CHROMA_FUNC(name, column, mirror) \ |
| static int chroma_##name(AVFilterContext *ctx, \ |
| void *arg, int jobnr, \ |
| int nb_jobs) \ |
| { \ |
| WaveformContext *s = ctx->priv; \ |
| ThreadData *td = arg; \ |
| AVFrame *in = td->in; \ |
| AVFrame *out = td->out; \ |
| int component = td->component; \ |
| int offset_y = td->offset_y; \ |
| int offset_x = td->offset_x; \ |
| \ |
| chroma(s, in, out, component, s->intensity, \ |
| offset_y, offset_x, column, mirror, \ |
| jobnr, nb_jobs); \ |
| \ |
| return 0; \ |
| } |
| |
| CHROMA_FUNC(column_mirror, 1, 1) |
| CHROMA_FUNC(column, 1, 0) |
| CHROMA_FUNC(row_mirror, 0, 1) |
| CHROMA_FUNC(row, 0, 0) |
| |
| static av_always_inline void color16(WaveformContext *s, |
| AVFrame *in, AVFrame *out, |
| int component, int intensity, |
| int offset_y, int offset_x, |
| int column, int mirror, |
| int jobnr, int nb_jobs) |
| { |
| const int plane = s->desc->comp[component].plane; |
| const int limit = s->max - 1; |
| const int src_h = in->height; |
| const int src_w = in->width; |
| const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0; |
| const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h; |
| const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0; |
| const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w; |
| const int c0_linesize = in->linesize[ plane + 0 ] / 2; |
| const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2; |
| const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2; |
| const int c0_shift_h = s->shift_h[ component + 0 ]; |
| const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp]; |
| const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp]; |
| const uint16_t *c0_data = (const uint16_t *)in->data[plane + 0] + (sliceh_start >> c0_shift_h) * c0_linesize; |
| const uint16_t *c1_data = (const uint16_t *)in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize; |
| const uint16_t *c2_data = (const uint16_t *)in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize; |
| const int d0_linesize = out->linesize[ plane + 0 ] / 2; |
| const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2; |
| const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2; |
| const int c0_shift_w = s->shift_w[ component + 0 ]; |
| const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp]; |
| const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp]; |
| int x, y; |
| |
| if (column) { |
| const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1); |
| const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1); |
| const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1); |
| uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x; |
| uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x; |
| uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x; |
| uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1); |
| uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data); |
| uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1); |
| uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data); |
| uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1); |
| uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data); |
| |
| for (y = 0; y < src_h; y++) { |
| for (x = slicew_start; x < slicew_end; x++) { |
| const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit); |
| const int c1 = c1_data[x >> c1_shift_w]; |
| const int c2 = c2_data[x >> c2_shift_w]; |
| |
| *(d0 + d0_signed_linesize * c0 + x) = c0; |
| *(d1 + d1_signed_linesize * c0 + x) = c1; |
| *(d2 + d2_signed_linesize * c0 + x) = c2; |
| } |
| |
| if (!c0_shift_h || (y & c0_shift_h)) |
| c0_data += c0_linesize; |
| if (!c1_shift_h || (y & c1_shift_h)) |
| c1_data += c1_linesize; |
| if (!c2_shift_h || (y & c2_shift_h)) |
| c2_data += c2_linesize; |
| d0_data += d0_linesize; |
| d1_data += d1_linesize; |
| d2_data += d2_linesize; |
| } |
| } else { |
| uint16_t *d0_data = (uint16_t *)out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x; |
| uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x; |
| uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + (offset_y + sliceh_start) * d2_linesize + offset_x; |
| |
| if (mirror) { |
| d0_data += s->size - 1; |
| d1_data += s->size - 1; |
| d2_data += s->size - 1; |
| } |
| |
| for (y = sliceh_start; y < sliceh_end; y++) { |
| for (x = 0; x < src_w; x++) { |
| const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit); |
| const int c1 = c1_data[x >> c1_shift_w]; |
| const int c2 = c2_data[x >> c2_shift_w]; |
| |
| if (mirror) { |
| *(d0_data - c0) = c0; |
| *(d1_data - c0) = c1; |
| *(d2_data - c0) = c2; |
| } else { |
| *(d0_data + c0) = c0; |
| *(d1_data + c0) = c1; |
| *(d2_data + c0) = c2; |
| } |
| } |
| |
| if (!c0_shift_h || (y & c0_shift_h)) |
| c0_data += c0_linesize; |
| if (!c1_shift_h || (y & c1_shift_h)) |
| c1_data += c1_linesize; |
| if (!c2_shift_h || (y & c2_shift_h)) |
| c2_data += c2_linesize; |
| d0_data += d0_linesize; |
| d1_data += d1_linesize; |
| d2_data += d2_linesize; |
| } |
| } |
| } |
| |
| #define COLOR16_FUNC(name, column, mirror) \ |
| static int color16_##name(AVFilterContext *ctx, \ |
| void *arg, int jobnr, \ |
| int nb_jobs) \ |
| { \ |
| WaveformContext *s = ctx->priv; \ |
| ThreadData *td = arg; \ |
| AVFrame *in = td->in; \ |
| AVFrame *out = td->out; \ |
| int component = td->component; \ |
| int offset_y = td->offset_y; \ |
| int offset_x = td->offset_x; \ |
| \ |
| color16(s, in, out, component, s->intensity, \ |
| offset_y, offset_x, column, mirror, \ |
| jobnr, nb_jobs); \ |
| \ |
| return 0; \ |
| } |
| |
| COLOR16_FUNC(column_mirror, 1, 1) |
| COLOR16_FUNC(column, 1, 0) |
| COLOR16_FUNC(row_mirror, 0, 1) |
| COLOR16_FUNC(row, 0, 0) |
| |
| static av_always_inline void color(WaveformContext *s, |
| AVFrame *in, AVFrame *out, |
| int component, int intensity, |
| int offset_y, int offset_x, |
| int column, int mirror, |
| int jobnr, int nb_jobs) |
| { |
| const int plane = s->desc->comp[component].plane; |
| const int src_h = in->height; |
| const int src_w = in->width; |
| const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0; |
| const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h; |
| const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0; |
| const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w; |
| const int c0_linesize = in->linesize[ plane + 0 ]; |
| const int c1_linesize = in->linesize[(plane + 1) % s->ncomp]; |
| const int c2_linesize = in->linesize[(plane + 2) % s->ncomp]; |
| const int c0_shift_h = s->shift_h[ component + 0 ]; |
| const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp]; |
| const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp]; |
| const uint8_t *c0_data = in->data[plane] + (sliceh_start >> c0_shift_h) * c0_linesize; |
| const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize; |
| const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize; |
| const int d0_linesize = out->linesize[ plane + 0 ]; |
| const int d1_linesize = out->linesize[(plane + 1) % s->ncomp]; |
| const int d2_linesize = out->linesize[(plane + 2) % s->ncomp]; |
| const int c0_shift_w = s->shift_w[ component + 0 ]; |
| const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp]; |
| const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp]; |
| int x, y; |
| |
| if (column) { |
| const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1); |
| const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1); |
| const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1); |
| uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x; |
| uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x; |
| uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x; |
| uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1); |
| uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data); |
| uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1); |
| uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data); |
| uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1); |
| uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data); |
| |
| for (y = 0; y < src_h; y++) { |
| for (x = slicew_start; x < slicew_end; x++) { |
| const int c0 = c0_data[x >> c0_shift_w]; |
| const int c1 = c1_data[x >> c1_shift_w]; |
| const int c2 = c2_data[x >> c2_shift_w]; |
| |
| *(d0 + d0_signed_linesize * c0 + x) = c0; |
| *(d1 + d1_signed_linesize * c0 + x) = c1; |
| *(d2 + d2_signed_linesize * c0 + x) = c2; |
| } |
| |
| if (!c0_shift_h || (y & c0_shift_h)) |
| c0_data += c0_linesize; |
| if (!c1_shift_h || (y & c1_shift_h)) |
| c1_data += c1_linesize; |
| if (!c2_shift_h || (y & c2_shift_h)) |
| c2_data += c2_linesize; |
| d0_data += d0_linesize; |
| d1_data += d1_linesize; |
| d2_data += d2_linesize; |
| } |
| } else { |
| uint8_t *d0_data = out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x; |
| uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x; |
| uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + (offset_y + sliceh_start) * d2_linesize + offset_x; |
| |
| if (mirror) { |
| d0_data += s->size - 1; |
| d1_data += s->size - 1; |
| d2_data += s->size - 1; |
| } |
| |
| for (y = sliceh_start; y < sliceh_end; y++) { |
| for (x = 0; x < src_w; x++) { |
| const int c0 = c0_data[x >> c0_shift_w]; |
| const int c1 = c1_data[x >> c1_shift_w]; |
| const int c2 = c2_data[x >> c2_shift_w]; |
| |
| if (mirror) { |
| *(d0_data - c0) = c0; |
| *(d1_data - c0) = c1; |
| *(d2_data - c0) = c2; |
| } else { |
| *(d0_data + c0) = c0; |
| *(d1_data + c0) = c1; |
| *(d2_data + c0) = c2; |
| } |
| } |
| |
| if (!c0_shift_h || (y & c0_shift_h)) |
| c0_data += c0_linesize; |
| if (!c1_shift_h || (y & c1_shift_h)) |
| c1_data += c1_linesize; |
| if (!c2_shift_h || (y & c2_shift_h)) |
| c2_data += c2_linesize; |
| d0_data += d0_linesize; |
| d1_data += d1_linesize; |
| d2_data += d2_linesize; |
| } |
| } |
| } |
| |
| #define COLOR_FUNC(name, column, mirror) \ |
| static int color_##name(AVFilterContext *ctx, \ |
| void *arg, int jobnr, \ |
| int nb_jobs) \ |
| { \ |
| WaveformContext *s = ctx->priv; \ |
| ThreadData *td = arg; \ |
| AVFrame *in = td->in; \ |
| AVFrame *out = td->out; \ |
| int component = td->component; \ |
| int offset_y = td->offset_y; \ |
| int offset_x = td->offset_x; \ |
| \ |
| color(s, in, out, component, s->intensity, \ |
| offset_y, offset_x, column, mirror, \ |
| jobnr, nb_jobs); \ |
| \ |
| return 0; \ |
| } |
| |
| COLOR_FUNC(column_mirror, 1, 1) |
| COLOR_FUNC(column, 1, 0) |
| COLOR_FUNC(row_mirror, 0, 1) |
| COLOR_FUNC(row, 0, 0) |
| |
| static av_always_inline void acolor16(WaveformContext *s, |
| AVFrame *in, AVFrame *out, |
| int component, int intensity, |
| int offset_y, int offset_x, |
| int column, int mirror, |
| int jobnr, int nb_jobs) |
| { |
| const int plane = s->desc->comp[component].plane; |
| const int limit = s->max - 1; |
| const int max = limit - intensity; |
| const int src_h = in->height; |
| const int src_w = in->width; |
| const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0; |
| const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h; |
| const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0; |
| const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w; |
| const int c0_shift_h = s->shift_h[ component + 0 ]; |
| const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp]; |
| const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp]; |
| const int c0_linesize = in->linesize[ plane + 0 ] / 2; |
| const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2; |
| const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2; |
| const uint16_t *c0_data = (const uint16_t *)in->data[plane + 0] + (sliceh_start >> c0_shift_h) * c0_linesize; |
| const uint16_t *c1_data = (const uint16_t *)in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize; |
| const uint16_t *c2_data = (const uint16_t *)in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize; |
| const int d0_linesize = out->linesize[ plane + 0 ] / 2; |
| const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2; |
| const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2; |
| const int c0_shift_w = s->shift_w[ component + 0 ]; |
| const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp]; |
| const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp]; |
| int x, y; |
| |
| if (column) { |
| const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1); |
| const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1); |
| const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1); |
| uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x; |
| uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x; |
| uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x; |
| uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1); |
| uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data); |
| uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1); |
| uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data); |
| uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1); |
| uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data); |
| |
| for (y = 0; y < src_h; y++) { |
| for (x = slicew_start; x < slicew_end; x++) { |
| const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit); |
| const int c1 = c1_data[x >> c1_shift_w]; |
| const int c2 = c2_data[x >> c2_shift_w]; |
| |
| update16(d0 + d0_signed_linesize * c0 + x, max, intensity, limit); |
| *(d1 + d1_signed_linesize * c0 + x) = c1; |
| *(d2 + d2_signed_linesize * c0 + x)
|