2 * Copyright (c) 2012-2016 Paul B Mahol
3 * Copyright (c) 2013 Marton Balint
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "libavutil/avassert.h"
23 #include "libavutil/opt.h"
24 #include "libavutil/parseutils.h"
25 #include "libavutil/pixdesc.h"
26 #include "libavutil/xga_font_data.h"
32 typedef struct ThreadData {
74 typedef struct GraticuleLine {
79 typedef struct GraticuleLines {
80 struct GraticuleLine line[4];
83 typedef struct WaveformContext {
110 uint8_t grat_yuva_color[4];
111 int shift_w[4], shift_h[4];
112 GraticuleLines *glines;
118 int (*waveform_slice)(AVFilterContext *ctx, void *arg,
119 int jobnr, int nb_jobs);
120 void (*graticulef)(struct WaveformContext *s, AVFrame *out);
121 void (*blend_line)(uint8_t *dst, int size, int linesize, float o1, float o2,
123 void (*draw_text)(AVFrame *out, int x, int y, int mult,
124 float o1, float o2, const char *txt,
125 const uint8_t color[4]);
126 const AVPixFmtDescriptor *desc;
127 const AVPixFmtDescriptor *odesc;
130 #define OFFSET(x) offsetof(WaveformContext, x)
131 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
133 static const AVOption waveform_options[] = {
134 { "mode", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "mode" },
135 { "m", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "mode" },
136 { "row", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "mode" },
137 { "column", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "mode" },
138 { "intensity", "set intensity", OFFSET(fintensity), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 1, FLAGS },
139 { "i", "set intensity", OFFSET(fintensity), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 1, FLAGS },
140 { "mirror", "set mirroring", OFFSET(mirror), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
141 { "r", "set mirroring", OFFSET(mirror), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
142 { "display", "set display mode", OFFSET(display), AV_OPT_TYPE_INT, {.i64=STACK}, 0, NB_DISPLAYS-1, FLAGS, "display" },
143 { "d", "set display mode", OFFSET(display), AV_OPT_TYPE_INT, {.i64=STACK}, 0, NB_DISPLAYS-1, FLAGS, "display" },
144 { "overlay", NULL, 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY}, 0, 0, FLAGS, "display" },
145 { "stack", NULL, 0, AV_OPT_TYPE_CONST, {.i64=STACK}, 0, 0, FLAGS, "display" },
146 { "parade", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PARADE}, 0, 0, FLAGS, "display" },
147 { "components", "set components to display", OFFSET(pcomp), AV_OPT_TYPE_INT, {.i64=1}, 1, 15, FLAGS },
148 { "c", "set components to display", OFFSET(pcomp), AV_OPT_TYPE_INT, {.i64=1}, 1, 15, FLAGS },
149 { "envelope", "set envelope to display", OFFSET(envelope), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "envelope" },
150 { "e", "set envelope to display", OFFSET(envelope), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "envelope" },
151 { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "envelope" },
152 { "instant", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "envelope" },
153 { "peak", NULL, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "envelope" },
154 { "peak+instant", NULL, 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, FLAGS, "envelope" },
155 { "filter", "set filter", OFFSET(filter), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_FILTERS-1, FLAGS, "filter" },
156 { "f", "set filter", OFFSET(filter), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_FILTERS-1, FLAGS, "filter" },
157 { "lowpass", NULL, 0, AV_OPT_TYPE_CONST, {.i64=LOWPASS}, 0, 0, FLAGS, "filter" },
158 { "flat" , NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAT}, 0, 0, FLAGS, "filter" },
159 { "aflat" , NULL, 0, AV_OPT_TYPE_CONST, {.i64=AFLAT}, 0, 0, FLAGS, "filter" },
160 { "chroma", NULL, 0, AV_OPT_TYPE_CONST, {.i64=CHROMA}, 0, 0, FLAGS, "filter" },
161 { "color", NULL, 0, AV_OPT_TYPE_CONST, {.i64=COLOR}, 0, 0, FLAGS, "filter" },
162 { "acolor", NULL, 0, AV_OPT_TYPE_CONST, {.i64=ACOLOR}, 0, 0, FLAGS, "filter" },
163 { "xflat", NULL, 0, AV_OPT_TYPE_CONST, {.i64=XFLAT}, 0, 0, FLAGS, "filter" },
164 { "yflat", NULL, 0, AV_OPT_TYPE_CONST, {.i64=YFLAT}, 0, 0, FLAGS, "filter" },
165 { "graticule", "set graticule", OFFSET(graticule), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_GRATICULES-1, FLAGS, "graticule" },
166 { "g", "set graticule", OFFSET(graticule), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_GRATICULES-1, FLAGS, "graticule" },
167 { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=GRAT_NONE}, 0, 0, FLAGS, "graticule" },
168 { "green", NULL, 0, AV_OPT_TYPE_CONST, {.i64=GRAT_GREEN}, 0, 0, FLAGS, "graticule" },
169 { "orange", NULL, 0, AV_OPT_TYPE_CONST, {.i64=GRAT_ORANGE}, 0, 0, FLAGS, "graticule" },
170 { "invert", NULL, 0, AV_OPT_TYPE_CONST, {.i64=GRAT_INVERT}, 0, 0, FLAGS, "graticule" },
171 { "opacity", "set graticule opacity", OFFSET(opacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
172 { "o", "set graticule opacity", OFFSET(opacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
173 { "flags", "set graticule flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64=1}, 0, 3, FLAGS, "flags" },
174 { "fl", "set graticule flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64=1}, 0, 3, FLAGS, "flags" },
175 { "numbers", "draw numbers", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "flags" },
176 { "dots", "draw dots instead of lines", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "flags" },
177 { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SCALES-1, FLAGS, "scale" },
178 { "s", "set scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SCALES-1, FLAGS, "scale" },
179 { "digital", NULL, 0, AV_OPT_TYPE_CONST, {.i64=DIGITAL}, 0, 0, FLAGS, "scale" },
180 { "millivolts", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MILLIVOLTS}, 0, 0, FLAGS, "scale" },
181 { "ire", NULL, 0, AV_OPT_TYPE_CONST, {.i64=IRE}, 0, 0, FLAGS, "scale" },
182 { "bgopacity", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
183 { "b", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
184 { "tint0", "set 1st tint", OFFSET(ftint[0]), AV_OPT_TYPE_FLOAT, {.dbl=0}, -1, 1, FLAGS},
185 { "t0", "set 1st tint", OFFSET(ftint[0]), AV_OPT_TYPE_FLOAT, {.dbl=0}, -1, 1, FLAGS},
186 { "tint1", "set 2nd tint", OFFSET(ftint[1]), AV_OPT_TYPE_FLOAT, {.dbl=0}, -1, 1, FLAGS},
187 { "t1", "set 2nd tint", OFFSET(ftint[1]), AV_OPT_TYPE_FLOAT, {.dbl=0}, -1, 1, FLAGS},
191 AVFILTER_DEFINE_CLASS(waveform);
193 static const enum AVPixelFormat in_lowpass_pix_fmts[] = {
194 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
195 AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12,
196 AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
197 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
198 AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P,
199 AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
200 AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
201 AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
202 AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY9, AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12,
203 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9,
204 AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9,
205 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10,
206 AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10,
207 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV440P12,
211 static const enum AVPixelFormat in_color_pix_fmts[] = {
212 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
213 AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12,
214 AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
215 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
217 AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
218 AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
219 AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
220 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9,
221 AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9,
222 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10,
223 AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10,
224 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV440P12,
228 static const enum AVPixelFormat in_flat_pix_fmts[] = {
229 AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
230 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
232 AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
233 AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
234 AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
235 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9,
236 AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9,
237 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10,
238 AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10,
239 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV440P12,
243 static const enum AVPixelFormat out_rgb8_lowpass_pix_fmts[] = {
244 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
248 static const enum AVPixelFormat out_rgb9_lowpass_pix_fmts[] = {
253 static const enum AVPixelFormat out_rgb10_lowpass_pix_fmts[] = {
254 AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10,
258 static const enum AVPixelFormat out_rgb12_lowpass_pix_fmts[] = {
259 AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12,
263 static const enum AVPixelFormat out_yuv8_lowpass_pix_fmts[] = {
264 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVA444P,
268 static const enum AVPixelFormat out_yuv9_lowpass_pix_fmts[] = {
269 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUVA444P9,
273 static const enum AVPixelFormat out_yuv10_lowpass_pix_fmts[] = {
274 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUVA444P10,
278 static const enum AVPixelFormat out_yuv12_lowpass_pix_fmts[] = {
279 AV_PIX_FMT_YUV444P12,
283 static const enum AVPixelFormat out_gray8_lowpass_pix_fmts[] = {
288 static const enum AVPixelFormat out_gray9_lowpass_pix_fmts[] = {
293 static const enum AVPixelFormat out_gray10_lowpass_pix_fmts[] = {
298 static const enum AVPixelFormat out_gray12_lowpass_pix_fmts[] = {
303 static const enum AVPixelFormat flat_pix_fmts[] = {
304 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P,
305 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV444P10,
306 AV_PIX_FMT_YUV444P12,
310 static int query_formats(AVFilterContext *ctx)
312 WaveformContext *s = ctx->priv;
313 const enum AVPixelFormat *out_pix_fmts;
314 const enum AVPixelFormat *in_pix_fmts;
315 const AVPixFmtDescriptor *desc, *desc2;
316 AVFilterFormats *avff, *avff2;
317 int depth, depth2, rgb, i, ret, ncomp, ncomp2;
319 if (!ctx->inputs[0]->in_formats ||
320 !ctx->inputs[0]->in_formats->nb_formats) {
321 return AVERROR(EAGAIN);
325 case LOWPASS: in_pix_fmts = in_lowpass_pix_fmts; break;
330 case FLAT: in_pix_fmts = in_flat_pix_fmts; break;
332 case COLOR: in_pix_fmts = in_color_pix_fmts; break;
333 default: return AVERROR_BUG;
336 if (!ctx->inputs[0]->out_formats) {
337 if ((ret = ff_formats_ref(ff_make_format_list(in_pix_fmts), &ctx->inputs[0]->out_formats)) < 0)
341 avff = ctx->inputs[0]->in_formats;
342 avff2 = ctx->inputs[0]->out_formats;
343 desc = av_pix_fmt_desc_get(avff->formats[0]);
344 desc2 = av_pix_fmt_desc_get(avff2->formats[0]);
345 ncomp = desc->nb_components;
346 ncomp2 = desc2->nb_components;
347 rgb = desc->flags & AV_PIX_FMT_FLAG_RGB;
348 depth = desc->comp[0].depth;
349 depth2 = desc2->comp[0].depth;
350 if (ncomp != ncomp2 || depth != depth2)
351 return AVERROR(EAGAIN);
352 for (i = 1; i < avff->nb_formats; i++) {
353 desc = av_pix_fmt_desc_get(avff->formats[i]);
354 if (rgb != (desc->flags & AV_PIX_FMT_FLAG_RGB) ||
355 depth != desc->comp[0].depth)
356 return AVERROR(EAGAIN);
359 if (s->filter == LOWPASS && ncomp == 1 && depth == 8)
360 out_pix_fmts = out_gray8_lowpass_pix_fmts;
361 else if (s->filter == LOWPASS && ncomp == 1 && depth == 9)
362 out_pix_fmts = out_gray9_lowpass_pix_fmts;
363 else if (s->filter == LOWPASS && ncomp == 1 && depth == 10)
364 out_pix_fmts = out_gray10_lowpass_pix_fmts;
365 else if (s->filter == LOWPASS && ncomp == 1 && depth == 12)
366 out_pix_fmts = out_gray12_lowpass_pix_fmts;
367 else if (rgb && depth == 8 && ncomp > 2)
368 out_pix_fmts = out_rgb8_lowpass_pix_fmts;
369 else if (rgb && depth == 9 && ncomp > 2)
370 out_pix_fmts = out_rgb9_lowpass_pix_fmts;
371 else if (rgb && depth == 10 && ncomp > 2)
372 out_pix_fmts = out_rgb10_lowpass_pix_fmts;
373 else if (rgb && depth == 12 && ncomp > 2)
374 out_pix_fmts = out_rgb12_lowpass_pix_fmts;
375 else if (depth == 8 && ncomp > 2)
376 out_pix_fmts = out_yuv8_lowpass_pix_fmts;
377 else if (depth == 9 && ncomp > 2)
378 out_pix_fmts = out_yuv9_lowpass_pix_fmts;
379 else if (depth == 10 && ncomp > 2)
380 out_pix_fmts = out_yuv10_lowpass_pix_fmts;
381 else if (depth == 12 && ncomp > 2)
382 out_pix_fmts = out_yuv12_lowpass_pix_fmts;
384 return AVERROR(EAGAIN);
385 if ((ret = ff_formats_ref(ff_make_format_list(out_pix_fmts), &ctx->outputs[0]->in_formats)) < 0)
391 static void envelope_instant16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
393 const int dst_linesize = out->linesize[component] / 2;
394 const int bg = s->bg_color[component] * (s->max / 256);
395 const int limit = s->max - 1;
396 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
397 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
398 const int start = s->estart[plane];
399 const int end = s->eend[plane];
404 for (x = offset; x < offset + dst_w; x++) {
405 for (y = start; y < end; y++) {
406 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
412 for (y = end - 1; y >= start; y--) {
413 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
421 for (y = offset; y < offset + dst_h; y++) {
422 dst = (uint16_t *)out->data[component] + y * dst_linesize;
423 for (x = start; x < end; x++) {
429 for (x = end - 1; x >= start; x--) {
439 static void envelope_instant(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
441 const int dst_linesize = out->linesize[component];
442 const uint8_t bg = s->bg_color[component];
443 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
444 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
445 const int start = s->estart[plane];
446 const int end = s->eend[plane];
451 for (x = offset; x < offset + dst_w; x++) {
452 for (y = start; y < end; y++) {
453 dst = out->data[component] + y * dst_linesize + x;
459 for (y = end - 1; y >= start; y--) {
460 dst = out->data[component] + y * dst_linesize + x;
468 for (y = offset; y < offset + dst_h; y++) {
469 dst = out->data[component] + y * dst_linesize;
470 for (x = start; x < end; x++) {
476 for (x = end - 1; x >= start; x--) {
486 static void envelope_peak16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
488 const int dst_linesize = out->linesize[component] / 2;
489 const int bg = s->bg_color[component] * (s->max / 256);
490 const int limit = s->max - 1;
491 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
492 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
493 const int start = s->estart[plane];
494 const int end = s->eend[plane];
495 int *emax = s->emax[plane][component];
496 int *emin = s->emin[plane][component];
501 for (x = offset; x < offset + dst_w; x++) {
502 for (y = start; y < end && y < emin[x - offset]; y++) {
503 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
505 emin[x - offset] = y;
509 for (y = end - 1; y >= start && y >= emax[x - offset]; y--) {
510 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
512 emax[x - offset] = y;
518 if (s->envelope == 3)
519 envelope_instant16(s, out, plane, component, offset);
521 for (x = offset; x < offset + dst_w; x++) {
522 dst = (uint16_t *)out->data[component] + emin[x - offset] * dst_linesize + x;
524 dst = (uint16_t *)out->data[component] + emax[x - offset] * dst_linesize + x;
528 for (y = offset; y < offset + dst_h; y++) {
529 dst = (uint16_t *)out->data[component] + y * dst_linesize;
530 for (x = start; x < end && x < emin[y - offset]; x++) {
532 emin[y - offset] = x;
536 for (x = end - 1; x >= start && x >= emax[y - offset]; x--) {
538 emax[y - offset] = x;
544 if (s->envelope == 3)
545 envelope_instant16(s, out, plane, component, offset);
547 for (y = offset; y < offset + dst_h; y++) {
548 dst = (uint16_t *)out->data[component] + y * dst_linesize + emin[y - offset];
550 dst = (uint16_t *)out->data[component] + y * dst_linesize + emax[y - offset];
556 static void envelope_peak(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
558 const int dst_linesize = out->linesize[component];
559 const int bg = s->bg_color[component];
560 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
561 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
562 const int start = s->estart[plane];
563 const int end = s->eend[plane];
564 int *emax = s->emax[plane][component];
565 int *emin = s->emin[plane][component];
570 for (x = offset; x < offset + dst_w; x++) {
571 for (y = start; y < end && y < emin[x - offset]; y++) {
572 dst = out->data[component] + y * dst_linesize + x;
574 emin[x - offset] = y;
578 for (y = end - 1; y >= start && y >= emax[x - offset]; y--) {
579 dst = out->data[component] + y * dst_linesize + x;
581 emax[x - offset] = y;
587 if (s->envelope == 3)
588 envelope_instant(s, out, plane, component, offset);
590 for (x = offset; x < offset + dst_w; x++) {
591 dst = out->data[component] + emin[x - offset] * dst_linesize + x;
593 dst = out->data[component] + emax[x - offset] * dst_linesize + x;
597 for (y = offset; y < offset + dst_h; y++) {
598 dst = out->data[component] + y * dst_linesize;
599 for (x = start; x < end && x < emin[y - offset]; x++) {
601 emin[y - offset] = x;
605 for (x = end - 1; x >= start && x >= emax[y - offset]; x--) {
607 emax[y - offset] = x;
613 if (s->envelope == 3)
614 envelope_instant(s, out, plane, component, offset);
616 for (y = offset; y < offset + dst_h; y++) {
617 dst = out->data[component] + y * dst_linesize + emin[y - offset];
619 dst = out->data[component] + y * dst_linesize + emax[y - offset];
625 static void envelope16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
627 if (s->envelope == 0) {
629 } else if (s->envelope == 1) {
630 envelope_instant16(s, out, plane, component, offset);
632 envelope_peak16(s, out, plane, component, offset);
636 static void envelope(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
638 if (s->envelope == 0) {
640 } else if (s->envelope == 1) {
641 envelope_instant(s, out, plane, component, offset);
643 envelope_peak(s, out, plane, component, offset);
647 static void update16(uint16_t *target, int max, int intensity, int limit)
650 *target += intensity;
655 static void update(uint8_t *target, int max, int intensity)
658 *target += intensity;
663 static void update_cr(uint8_t *target, int unused, int intensity)
665 if (*target - intensity > 0)
666 *target -= intensity;
671 static void update16_cr(uint16_t *target, int unused, int intensity, int limit)
673 if (*target - intensity > 0)
674 *target -= intensity;
679 static av_always_inline void lowpass16(WaveformContext *s,
680 AVFrame *in, AVFrame *out,
681 int component, int intensity,
682 int offset_y, int offset_x,
683 int column, int mirror,
684 int jobnr, int nb_jobs)
686 const int plane = s->desc->comp[component].plane;
687 const int dplane = (s->rgb || s->display == OVERLAY) ? plane : 0;
688 const int shift_w = s->shift_w[component];
689 const int shift_h = s->shift_h[component];
690 const int src_linesize = in->linesize[plane] / 2;
691 const int dst_linesize = out->linesize[dplane] / 2;
692 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
693 const int limit = s->max - 1;
694 const int max = limit - intensity;
695 const int src_h = AV_CEIL_RSHIFT(in->height, shift_h);
696 const int src_w = AV_CEIL_RSHIFT(in->width, shift_w);
697 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
698 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
699 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
700 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
701 const int step = column ? 1 << shift_w : 1 << shift_h;
702 const uint16_t *src_data = (const uint16_t *)in->data[plane] + sliceh_start * src_linesize;
703 uint16_t *dst_data = (uint16_t *)out->data[dplane] + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
704 uint16_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
705 uint16_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
709 if (!column && mirror)
712 for (y = sliceh_start; y < sliceh_end; y++) {
713 const uint16_t *src_data_end = src_data + slicew_end;
714 uint16_t *dst = dst_line + slicew_start * step;
716 for (p = src_data + slicew_start; p < src_data_end; p++) {
718 int i = 0, v = FFMIN(*p, limit);
722 target = dst++ + dst_signed_linesize * v;
723 update16(target, max, intensity, limit);
724 } while (++i < step);
726 uint16_t *row = dst_data;
729 target = row - v - 1;
732 update16(target, max, intensity, limit);
734 } while (++i < step);
737 src_data += src_linesize;
738 dst_data += dst_linesize * step;
741 if (s->display != OVERLAY && column && !s->rgb) {
742 const int mult = s->max / 256;
743 const int bg = s->bg_color[0] * mult;
744 const int t0 = s->tint[0];
745 const int t1 = s->tint[1];
746 uint16_t *dst0, *dst1;
750 src = (const uint16_t *)(out->data[0]) + offset_y * dst_linesize + offset_x;
751 dst0 = (uint16_t *)(out->data[1]) + offset_y * dst_linesize + offset_x;
752 dst1 = (uint16_t *)(out->data[2]) + offset_y * dst_linesize + offset_x;
753 for (y = 0; y < s->max; y++) {
754 for (x = slicew_start * step; x < slicew_end * step; x++) {
762 dst0 += dst_linesize;
763 dst1 += dst_linesize;
765 } else if (s->display != OVERLAY && !s->rgb) {
766 const int mult = s->max / 256;
767 const int bg = s->bg_color[0] * mult;
768 const int t0 = s->tint[0];
769 const int t1 = s->tint[1];
770 uint16_t *dst0, *dst1;
774 src = (const uint16_t *)out->data[0] + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
775 dst0 = (uint16_t *)(out->data[1]) + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
776 dst1 = (uint16_t *)(out->data[2]) + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
777 for (y = sliceh_start * step; y < sliceh_end * step; y++) {
778 for (x = 0; x < s->max; x++) {
786 dst0 += dst_linesize;
787 dst1 += dst_linesize;
792 #define LOWPASS16_FUNC(name, column, mirror) \
793 static int lowpass16_##name(AVFilterContext *ctx, \
794 void *arg, int jobnr, \
797 WaveformContext *s = ctx->priv; \
798 ThreadData *td = arg; \
799 AVFrame *in = td->in; \
800 AVFrame *out = td->out; \
801 int component = td->component; \
802 int offset_y = td->offset_y; \
803 int offset_x = td->offset_x; \
805 lowpass16(s, in, out, component, s->intensity, \
806 offset_y, offset_x, column, mirror, \
812 LOWPASS16_FUNC(column_mirror, 1, 1)
813 LOWPASS16_FUNC(column, 1, 0)
814 LOWPASS16_FUNC(row_mirror, 0, 1)
815 LOWPASS16_FUNC(row, 0, 0)
817 static av_always_inline void lowpass(WaveformContext *s,
818 AVFrame *in, AVFrame *out,
819 int component, int intensity,
820 int offset_y, int offset_x,
821 int column, int mirror,
822 int jobnr, int nb_jobs)
824 const int plane = s->desc->comp[component].plane;
825 const int dplane = (s->rgb || s->display == OVERLAY) ? plane : 0;
826 const int shift_w = s->shift_w[component];
827 const int shift_h = s->shift_h[component];
828 const int src_linesize = in->linesize[plane];
829 const int dst_linesize = out->linesize[dplane];
830 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
831 const int max = 255 - intensity;
832 const int src_h = AV_CEIL_RSHIFT(in->height, shift_h);
833 const int src_w = AV_CEIL_RSHIFT(in->width, shift_w);
834 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
835 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
836 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
837 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
838 const int step = column ? 1 << shift_w : 1 << shift_h;
839 const uint8_t *src_data = in->data[plane] + sliceh_start * src_linesize;
840 uint8_t *dst_data = out->data[dplane] + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
841 uint8_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
842 uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
846 if (!column && mirror)
849 for (y = sliceh_start; y < sliceh_end; y++) {
850 const uint8_t *src_data_end = src_data + slicew_end;
851 uint8_t *dst = dst_line + slicew_start * step;
853 for (p = src_data + slicew_start; p < src_data_end; p++) {
859 target = dst++ + dst_signed_linesize * *p;
860 update(target, max, intensity);
861 } while (++i < step);
863 uint8_t *row = dst_data;
866 target = row - *p - 1;
869 update(target, max, intensity);
871 } while (++i < step);
874 src_data += src_linesize;
875 dst_data += dst_linesize * step;
878 if (s->display != OVERLAY && column && !s->rgb) {
879 const int bg = s->bg_color[0];
880 const int dst_h = 256;
881 const int t0 = s->tint[0];
882 const int t1 = s->tint[1];
883 uint8_t *dst0, *dst1;
887 src = out->data[0] + offset_y * dst_linesize + offset_x;
888 dst0 = out->data[1] + offset_y * dst_linesize + offset_x;
889 dst1 = out->data[2] + offset_y * dst_linesize + offset_x;
890 for (y = 0; y < dst_h; y++) {
891 for (x = slicew_start * step; x < slicew_end * step; x++) {
899 dst0 += dst_linesize;
900 dst1 += dst_linesize;
902 } else if (s->display != OVERLAY && !s->rgb) {
903 const int bg = s->bg_color[0];
904 const int dst_w = 256;
905 const int t0 = s->tint[0];
906 const int t1 = s->tint[1];
907 uint8_t *dst0, *dst1;
911 src = out->data[0] + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
912 dst0 = out->data[1] + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
913 dst1 = out->data[2] + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
914 for (y = sliceh_start * step; y < sliceh_end * step; y++) {
915 for (x = 0; x < dst_w; x++) {
923 dst0 += dst_linesize;
924 dst1 += dst_linesize;
929 #define LOWPASS_FUNC(name, column, mirror) \
930 static int lowpass_##name(AVFilterContext *ctx, \
931 void *arg, int jobnr, \
934 WaveformContext *s = ctx->priv; \
935 ThreadData *td = arg; \
936 AVFrame *in = td->in; \
937 AVFrame *out = td->out; \
938 int component = td->component; \
939 int offset_y = td->offset_y; \
940 int offset_x = td->offset_x; \
942 lowpass(s, in, out, component, s->intensity, \
943 offset_y, offset_x, column, mirror, \
949 LOWPASS_FUNC(column_mirror, 1, 1)
950 LOWPASS_FUNC(column, 1, 0)
951 LOWPASS_FUNC(row_mirror, 0, 1)
952 LOWPASS_FUNC(row, 0, 0)
954 static av_always_inline void flat16(WaveformContext *s,
955 AVFrame *in, AVFrame *out,
956 int component, int intensity,
957 int offset_y, int offset_x,
958 int column, int mirror,
959 int jobnr, int nb_jobs)
961 const int plane = s->desc->comp[component].plane;
962 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
963 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
964 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
965 const int c0_shift_w = s->shift_w[ component + 0 ];
966 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
967 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
968 const int c0_shift_h = s->shift_h[ component + 0 ];
969 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
970 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
971 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
972 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
973 const int limit = s->max - 1;
974 const int max = limit - intensity;
975 const int mid = s->max / 2;
976 const int src_h = in->height;
977 const int src_w = in->width;
978 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
979 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
980 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
981 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
985 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
986 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
988 for (x = slicew_start; x < slicew_end; x++) {
989 const uint16_t *c0_data = (uint16_t *)in->data[plane + 0];
990 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
991 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
992 uint16_t *d0_data = (uint16_t *)(out->data[plane]) + offset_y * d0_linesize + offset_x;
993 uint16_t *d1_data = (uint16_t *)(out->data[(plane + 1) % s->ncomp]) + offset_y * d1_linesize + offset_x;
994 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
995 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
996 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
997 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
999 for (y = 0; y < src_h; y++) {
1000 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + s->max;
1001 const int c1 = FFMIN(FFABS(c1_data[x >> c1_shift_w] - mid) + FFABS(c2_data[x >> c2_shift_w] - mid), limit);
1004 target = d0 + x + d0_signed_linesize * c0;
1005 update16(target, max, intensity, limit);
1006 target = d1 + x + d1_signed_linesize * (c0 - c1);
1007 update16(target, max, intensity, limit);
1008 target = d1 + x + d1_signed_linesize * (c0 + c1);
1009 update16(target, max, intensity, limit);
1011 if (!c0_shift_h || (y & c0_shift_h))
1012 c0_data += c0_linesize;
1013 if (!c1_shift_h || (y & c1_shift_h))
1014 c1_data += c1_linesize;
1015 if (!c2_shift_h || (y & c2_shift_h))
1016 c2_data += c2_linesize;
1017 d0_data += d0_linesize;
1018 d1_data += d1_linesize;
1022 const uint16_t *c0_data = (uint16_t *)(in->data[plane]) + (sliceh_start >> c0_shift_h) * c0_linesize;
1023 const uint16_t *c1_data = (uint16_t *)(in->data[(plane + 1) % s->ncomp]) + (sliceh_start >> c1_shift_h) * c1_linesize;
1024 const uint16_t *c2_data = (uint16_t *)(in->data[(plane + 2) % s->ncomp]) + (sliceh_start >> c2_shift_h) * c2_linesize;
1025 uint16_t *d0_data = (uint16_t *)(out->data[plane]) + (offset_y + sliceh_start) * d0_linesize + offset_x;
1026 uint16_t *d1_data = (uint16_t *)(out->data[(plane + 1) % s->ncomp]) + (offset_y + sliceh_start) * d1_linesize + offset_x;
1029 d0_data += s->size - 1;
1030 d1_data += s->size - 1;
1033 for (y = sliceh_start; y < sliceh_end; y++) {
1034 for (x = 0; x < src_w; x++) {
1035 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + s->max;
1036 const int c1 = FFMIN(FFABS(c1_data[x >> c1_shift_w] - mid) + FFABS(c2_data[x >> c2_shift_w] - mid), limit);
1040 target = d0_data - c0;
1041 update16(target, max, intensity, limit);
1042 target = d1_data - (c0 - c1);
1043 update16(target, max, intensity, limit);
1044 target = d1_data - (c0 + c1);
1045 update16(target, max, intensity, limit);
1047 target = d0_data + c0;
1048 update16(target, max, intensity, limit);
1049 target = d1_data + (c0 - c1);
1050 update16(target, max, intensity, limit);
1051 target = d1_data + (c0 + c1);
1052 update16(target, max, intensity, limit);
1056 if (!c0_shift_h || (y & c0_shift_h))
1057 c0_data += c0_linesize;
1058 if (!c1_shift_h || (y & c1_shift_h))
1059 c1_data += c1_linesize;
1060 if (!c2_shift_h || (y & c2_shift_h))
1061 c2_data += c2_linesize;
1062 d0_data += d0_linesize;
1063 d1_data += d1_linesize;
1068 #define FLAT16_FUNC(name, column, mirror) \
1069 static int flat16_##name(AVFilterContext *ctx, \
1070 void *arg, int jobnr, \
1073 WaveformContext *s = ctx->priv; \
1074 ThreadData *td = arg; \
1075 AVFrame *in = td->in; \
1076 AVFrame *out = td->out; \
1077 int component = td->component; \
1078 int offset_y = td->offset_y; \
1079 int offset_x = td->offset_x; \
1081 flat16(s, in, out, component, s->intensity, \
1082 offset_y, offset_x, column, mirror, \
1088 FLAT16_FUNC(column_mirror, 1, 1)
1089 FLAT16_FUNC(column, 1, 0)
1090 FLAT16_FUNC(row_mirror, 0, 1)
1091 FLAT16_FUNC(row, 0, 0)
1093 static av_always_inline void flat(WaveformContext *s,
1094 AVFrame *in, AVFrame *out,
1095 int component, int intensity,
1096 int offset_y, int offset_x,
1097 int column, int mirror,
1098 int jobnr, int nb_jobs)
1100 const int plane = s->desc->comp[component].plane;
1101 const int c0_linesize = in->linesize[ plane + 0 ];
1102 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
1103 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
1104 const int c0_shift_w = s->shift_w[ component + 0 ];
1105 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1106 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1107 const int c0_shift_h = s->shift_h[ component + 0 ];
1108 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1109 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1110 const int d0_linesize = out->linesize[ plane + 0 ];
1111 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
1112 const int max = 255 - intensity;
1113 const int src_h = in->height;
1114 const int src_w = in->width;
1115 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
1116 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
1117 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
1118 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
1122 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1123 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1125 for (x = slicew_start; x < slicew_end; x++) {
1126 const uint8_t *c0_data = in->data[plane + 0];
1127 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1128 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1129 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1130 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1131 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1132 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1133 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1134 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1136 for (y = 0; y < src_h; y++) {
1137 const int c0 = c0_data[x >> c0_shift_w] + 256;
1138 const int c1 = FFABS(c1_data[x >> c1_shift_w] - 128) + FFABS(c2_data[x >> c2_shift_w] - 128);
1141 target = d0 + x + d0_signed_linesize * c0;
1142 update(target, max, intensity);
1143 target = d1 + x + d1_signed_linesize * (c0 - c1);
1144 update(target, max, intensity);
1145 target = d1 + x + d1_signed_linesize * (c0 + c1);
1146 update(target, max, intensity);
1148 if (!c0_shift_h || (y & c0_shift_h))
1149 c0_data += c0_linesize;
1150 if (!c1_shift_h || (y & c1_shift_h))
1151 c1_data += c1_linesize;
1152 if (!c2_shift_h || (y & c2_shift_h))
1153 c2_data += c2_linesize;
1154 d0_data += d0_linesize;
1155 d1_data += d1_linesize;
1159 const uint8_t *c0_data = in->data[plane] + (sliceh_start >> c0_shift_h) * c0_linesize;
1160 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize;
1161 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize;
1162 uint8_t *d0_data = out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x;
1163 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x;
1166 d0_data += s->size - 1;
1167 d1_data += s->size - 1;
1170 for (y = sliceh_start; y < sliceh_end; y++) {
1171 for (x = 0; x < src_w; x++) {
1172 const int c0 = c0_data[x >> c0_shift_w] + 256;
1173 const int c1 = FFABS(c1_data[x >> c1_shift_w] - 128) + FFABS(c2_data[x >> c2_shift_w] - 128);
1177 target = d0_data - c0;
1178 update(target, max, intensity);
1179 target = d1_data - (c0 - c1);
1180 update(target, max, intensity);
1181 target = d1_data - (c0 + c1);
1182 update(target, max, intensity);
1184 target = d0_data + c0;
1185 update(target, max, intensity);
1186 target = d1_data + (c0 - c1);
1187 update(target, max, intensity);
1188 target = d1_data + (c0 + c1);
1189 update(target, max, intensity);
1193 if (!c0_shift_h || (y & c0_shift_h))
1194 c0_data += c0_linesize;
1195 if (!c1_shift_h || (y & c1_shift_h))
1196 c1_data += c1_linesize;
1197 if (!c2_shift_h || (y & c2_shift_h))
1198 c2_data += c2_linesize;
1199 d0_data += d0_linesize;
1200 d1_data += d1_linesize;
1205 #define FLAT_FUNC(name, column, mirror) \
1206 static int flat_##name(AVFilterContext *ctx, \
1207 void *arg, int jobnr, \
1210 WaveformContext *s = ctx->priv; \
1211 ThreadData *td = arg; \
1212 AVFrame *in = td->in; \
1213 AVFrame *out = td->out; \
1214 int component = td->component; \
1215 int offset_y = td->offset_y; \
1216 int offset_x = td->offset_x; \
1218 flat(s, in, out, component, s->intensity, \
1219 offset_y, offset_x, column, mirror, \
1225 FLAT_FUNC(column_mirror, 1, 1)
1226 FLAT_FUNC(column, 1, 0)
1227 FLAT_FUNC(row_mirror, 0, 1)
1228 FLAT_FUNC(row, 0, 0)
1230 #define AFLAT16(name, update_cb, update_cr, column, mirror) \
1231 static int name(AVFilterContext *ctx, \
1232 void *arg, int jobnr, \
1235 WaveformContext *s = ctx->priv; \
1236 ThreadData *td = arg; \
1237 AVFrame *in = td->in; \
1238 AVFrame *out = td->out; \
1239 int component = td->component; \
1240 int offset_y = td->offset_y; \
1241 int offset_x = td->offset_x; \
1242 const int intensity = s->intensity; \
1243 const int plane = s->desc->comp[component].plane; \
1244 const int c0_linesize = in->linesize[ plane + 0 ] / 2; \
1245 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2; \
1246 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2; \
1247 const int c0_shift_w = s->shift_w[ component + 0 ]; \
1248 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp]; \
1249 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp]; \
1250 const int c0_shift_h = s->shift_h[ component + 0 ]; \
1251 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp]; \
1252 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp]; \
1253 const int d0_linesize = out->linesize[ plane + 0 ] / 2; \
1254 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2; \
1255 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2; \
1256 const int limit = s->max - 1; \
1257 const int max = limit - intensity; \
1258 const int mid = s->max / 2; \
1259 const int src_h = in->height; \
1260 const int src_w = in->width; \
1261 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0; \
1262 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h; \
1263 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0; \
1264 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w; \
1268 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1); \
1269 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1); \
1270 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1); \
1272 for (x = slicew_start; x < slicew_end; x++) { \
1273 const uint16_t *c0_data = (uint16_t *)in->data[plane + 0]; \
1274 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp]; \
1275 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp]; \
1276 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x; \
1277 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x; \
1278 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x; \
1279 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1); \
1280 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data); \
1281 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1); \
1282 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data); \
1283 uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1); \
1284 uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data); \
1286 for (y = 0; y < src_h; y++) { \
1287 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + mid; \
1288 const int c1 = FFMIN(c1_data[x >> c1_shift_w], limit) - mid; \
1289 const int c2 = FFMIN(c2_data[x >> c2_shift_w], limit) - mid; \
1292 target = d0 + x + d0_signed_linesize * c0; \
1293 update16(target, max, intensity, limit); \
1295 target = d1 + x + d1_signed_linesize * (c0 + c1); \
1296 update_cb(target, max, intensity, limit); \
1298 target = d2 + x + d2_signed_linesize * (c0 + c2); \
1299 update_cr(target, max, intensity, limit); \
1301 if (!c0_shift_h || (y & c0_shift_h)) \
1302 c0_data += c0_linesize; \
1303 if (!c1_shift_h || (y & c1_shift_h)) \
1304 c1_data += c1_linesize; \
1305 if (!c2_shift_h || (y & c2_shift_h)) \
1306 c2_data += c2_linesize; \
1307 d0_data += d0_linesize; \
1308 d1_data += d1_linesize; \
1309 d2_data += d2_linesize; \
1313 const uint16_t *c0_data = (uint16_t *)in->data[plane] + (sliceh_start >> c0_shift_h) * c0_linesize; \
1314 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize; \
1315 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize; \
1316 uint16_t *d0_data = (uint16_t *)out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x; \
1317 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x; \
1318 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + (offset_y + sliceh_start) * d2_linesize + offset_x; \
1321 d0_data += s->size - 1; \
1322 d1_data += s->size - 1; \
1323 d2_data += s->size - 1; \
1326 for (y = sliceh_start; y < sliceh_end; y++) { \
1327 for (x = 0; x < src_w; x++) { \
1328 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + mid; \
1329 const int c1 = FFMIN(c1_data[x >> c1_shift_w], limit) - mid; \
1330 const int c2 = FFMIN(c2_data[x >> c2_shift_w], limit) - mid; \
1334 target = d0_data - c0; \
1335 update16(target, max, intensity, limit); \
1336 target = d1_data - (c0 + c1); \
1337 update_cb(target, max, intensity, limit); \
1338 target = d2_data - (c0 + c2); \
1339 update_cr(target, max, intensity, limit); \
1341 target = d0_data + c0; \
1342 update16(target, max, intensity, limit); \
1343 target = d1_data + (c0 + c1); \
1344 update_cb(target, max, intensity, limit); \
1345 target = d2_data + (c0 + c2); \
1346 update_cr(target, max, intensity, limit); \
1350 if (!c0_shift_h || (y & c0_shift_h)) \
1351 c0_data += c0_linesize; \
1352 if (!c1_shift_h || (y & c1_shift_h)) \
1353 c1_data += c1_linesize; \
1354 if (!c2_shift_h || (y & c2_shift_h)) \
1355 c2_data += c2_linesize; \
1356 d0_data += d0_linesize; \
1357 d1_data += d1_linesize; \
1358 d2_data += d2_linesize; \
1364 #define AFLAT(name, update_cb, update_cr, column, mirror) \
1365 static int name(AVFilterContext *ctx, \
1366 void *arg, int jobnr, \
1369 WaveformContext *s = ctx->priv; \
1370 ThreadData *td = arg; \
1371 AVFrame *in = td->in; \
1372 AVFrame *out = td->out; \
1373 int component = td->component; \
1374 int offset_y = td->offset_y; \
1375 int offset_x = td->offset_x; \
1376 const int src_h = in->height; \
1377 const int src_w = in->width; \
1378 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0; \
1379 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h; \
1380 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0; \
1381 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w; \
1382 const int intensity = s->intensity; \
1383 const int plane = s->desc->comp[component].plane; \
1384 const int c0_linesize = in->linesize[ plane + 0 ]; \
1385 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp]; \
1386 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp]; \
1387 const int c0_shift_w = s->shift_w[ component + 0 ]; \
1388 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp]; \
1389 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp]; \
1390 const int c0_shift_h = s->shift_h[ component + 0 ]; \
1391 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp]; \
1392 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp]; \
1393 const int d0_linesize = out->linesize[ plane + 0 ]; \
1394 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp]; \
1395 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp]; \
1396 const int max = 255 - intensity; \
1400 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1); \
1401 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1); \
1402 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1); \
1404 for (x = slicew_start; x < slicew_end; x++) { \
1405 const uint8_t *c0_data = in->data[plane + 0]; \
1406 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp]; \
1407 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp]; \
1408 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x; \
1409 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x; \
1410 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x; \
1411 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1); \
1412 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data); \
1413 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1); \
1414 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data); \
1415 uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1); \
1416 uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data); \
1418 for (y = 0; y < src_h; y++) { \
1419 const int c0 = c0_data[x >> c0_shift_w] + 128; \
1420 const int c1 = c1_data[x >> c1_shift_w] - 128; \
1421 const int c2 = c2_data[x >> c2_shift_w] - 128; \
1424 target = d0 + x + d0_signed_linesize * c0; \
1425 update(target, max, intensity); \
1427 target = d1 + x + d1_signed_linesize * (c0 + c1); \
1428 update_cb(target, max, intensity); \
1430 target = d2 + x + d2_signed_linesize * (c0 + c2); \
1431 update_cr(target, max, intensity); \
1433 if (!c0_shift_h || (y & c0_shift_h)) \
1434 c0_data += c0_linesize; \
1435 if (!c1_shift_h || (y & c1_shift_h)) \
1436 c1_data += c1_linesize; \
1437 if (!c2_shift_h || (y & c2_shift_h)) \
1438 c2_data += c2_linesize; \
1439 d0_data += d0_linesize; \
1440 d1_data += d1_linesize; \
1441 d2_data += d2_linesize; \
1445 const uint8_t *c0_data = in->data[plane] + (sliceh_start >> c0_shift_h) * c0_linesize; \
1446 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize; \
1447 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize; \
1448 uint8_t *d0_data = out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x; \
1449 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x; \
1450 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + (offset_y + sliceh_start) * d2_linesize + offset_x; \
1453 d0_data += s->size - 1; \
1454 d1_data += s->size - 1; \
1455 d2_data += s->size - 1; \
1458 for (y = sliceh_start; y < sliceh_end; y++) { \
1459 for (x = 0; x < src_w; x++) { \
1460 const int c0 = c0_data[x >> c0_shift_w] + 128; \
1461 const int c1 = c1_data[x >> c1_shift_w] - 128; \
1462 const int c2 = c2_data[x >> c2_shift_w] - 128; \
1466 target = d0_data - c0; \
1467 update(target, max, intensity); \
1468 target = d1_data - (c0 + c1); \
1469 update_cb(target, max, intensity); \
1470 target = d2_data - (c0 + c2); \
1471 update_cr(target, max, intensity); \
1473 target = d0_data + c0; \
1474 update(target, max, intensity); \
1475 target = d1_data + (c0 + c1); \
1476 update_cb(target, max, intensity); \
1477 target = d2_data + (c0 + c2); \
1478 update_cr(target, max, intensity); \
1482 if (!c0_shift_h || (y & c0_shift_h)) \
1483 c0_data += c0_linesize; \
1484 if (!c1_shift_h || (y & c1_shift_h)) \
1485 c1_data += c1_linesize; \
1486 if (!c2_shift_h || (y & c2_shift_h)) \
1487 c2_data += c2_linesize; \
1488 d0_data += d0_linesize; \
1489 d1_data += d1_linesize; \
1490 d2_data += d2_linesize; \
1496 AFLAT16(aflat16_row, update16, update16, 0, 0)
1497 AFLAT16(aflat16_row_mirror, update16, update16, 0, 1)
1498 AFLAT16(aflat16_column, update16, update16, 1, 0)
1499 AFLAT16(aflat16_column_mirror, update16, update16, 1, 1)
1500 AFLAT16(xflat16_row, update16, update16_cr, 0, 0)
1501 AFLAT16(xflat16_row_mirror, update16, update16_cr, 0, 1)
1502 AFLAT16(xflat16_column, update16, update16_cr, 1, 0)
1503 AFLAT16(xflat16_column_mirror, update16, update16_cr, 1, 1)
1504 AFLAT16(yflat16_row, update16_cr, update16_cr, 0, 0)
1505 AFLAT16(yflat16_row_mirror, update16_cr, update16_cr, 0, 1)
1506 AFLAT16(yflat16_column, update16_cr, update16_cr, 1, 0)
1507 AFLAT16(yflat16_column_mirror, update16_cr, update16_cr, 1, 1)
1509 AFLAT(aflat_row, update, update, 0, 0)
1510 AFLAT(aflat_row_mirror, update, update, 0, 1)
1511 AFLAT(aflat_column, update, update, 1, 0)
1512 AFLAT(aflat_column_mirror, update, update, 1, 1)
1513 AFLAT(xflat_row, update, update_cr, 0, 0)
1514 AFLAT(xflat_row_mirror, update, update_cr, 0, 1)
1515 AFLAT(xflat_column, update, update_cr, 1, 0)
1516 AFLAT(xflat_column_mirror, update, update_cr, 1, 1)
1517 AFLAT(yflat_row, update_cr, update_cr, 0, 0)
1518 AFLAT(yflat_row_mirror, update_cr, update_cr, 0, 1)
1519 AFLAT(yflat_column, update_cr, update_cr, 1, 0)
1520 AFLAT(yflat_column_mirror, update_cr, update_cr, 1, 1)
1522 static av_always_inline void chroma16(WaveformContext *s,
1523 AVFrame *in, AVFrame *out,
1524 int component, int intensity,
1525 int offset_y, int offset_x,
1526 int column, int mirror,
1527 int jobnr, int nb_jobs)
1529 const int plane = s->desc->comp[component].plane;
1530 const int c0_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1531 const int c1_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1532 const int dst_linesize = out->linesize[plane] / 2;
1533 const int limit = s->max - 1;
1534 const int max = limit - intensity;
1535 const int mid = s->max / 2;
1536 const int c0_shift_w = s->shift_w[(component + 1) % s->ncomp];
1537 const int c1_shift_w = s->shift_w[(component + 2) % s->ncomp];
1538 const int c0_shift_h = s->shift_h[(component + 1) % s->ncomp];
1539 const int c1_shift_h = s->shift_h[(component + 2) % s->ncomp];
1540 const int src_h = in->height;
1541 const int src_w = in->width;
1542 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
1543 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
1544 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
1545 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
1549 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
1551 for (x = slicew_start; x < slicew_end; x++) {
1552 const uint16_t *c0_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1553 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1554 uint16_t *dst_data = (uint16_t *)out->data[plane] + offset_y * dst_linesize + offset_x;
1555 uint16_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
1556 uint16_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
1557 uint16_t *dst = dst_line;
1559 for (y = 0; y < src_h; y++) {
1560 const int sum = FFMIN(FFABS(c0_data[x >> c0_shift_w] - mid) + FFABS(c1_data[x >> c1_shift_w] - mid - 1), limit);
1563 target = dst + x + dst_signed_linesize * sum;
1564 update16(target, max, intensity, limit);
1566 if (!c0_shift_h || (y & c0_shift_h))
1567 c0_data += c0_linesize;
1568 if (!c1_shift_h || (y & c1_shift_h))
1569 c1_data += c1_linesize;
1570 dst_data += dst_linesize;
1574 const uint16_t *c0_data = (uint16_t *)in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c0_shift_h) * c0_linesize;
1575 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize;
1576 uint16_t *dst_data = (uint16_t *)out->data[plane] + (offset_y + sliceh_start) * dst_linesize + offset_x;
1579 dst_data += s->size - 1;
1580 for (y = sliceh_start; y < sliceh_end; y++) {
1581 for (x = 0; x < src_w; x++) {
1582 const int sum = FFMIN(FFABS(c0_data[x >> c0_shift_w] - mid) + FFABS(c1_data[x >> c1_shift_w] - mid - 1), limit);
1586 target = dst_data - sum;
1587 update16(target, max, intensity, limit);
1589 target = dst_data + sum;
1590 update16(target, max, intensity, limit);
1594 if (!c0_shift_h || (y & c0_shift_h))
1595 c0_data += c0_linesize;
1596 if (!c1_shift_h || (y & c1_shift_h))
1597 c1_data += c1_linesize;
1598 dst_data += dst_linesize;
1603 #define CHROMA16_FUNC(name, column, mirror) \
1604 static int chroma16_##name(AVFilterContext *ctx, \
1605 void *arg, int jobnr, \
1608 WaveformContext *s = ctx->priv; \
1609 ThreadData *td = arg; \
1610 AVFrame *in = td->in; \
1611 AVFrame *out = td->out; \
1612 int component = td->component; \
1613 int offset_y = td->offset_y; \
1614 int offset_x = td->offset_x; \
1616 chroma16(s, in, out, component, s->intensity,\
1617 offset_y, offset_x, column, mirror, \
1623 CHROMA16_FUNC(column_mirror, 1, 1)
1624 CHROMA16_FUNC(column, 1, 0)
1625 CHROMA16_FUNC(row_mirror, 0, 1)
1626 CHROMA16_FUNC(row, 0, 0)
1628 static av_always_inline void chroma(WaveformContext *s,
1629 AVFrame *in, AVFrame *out,
1630 int component, int intensity,
1631 int offset_y, int offset_x,
1632 int column, int mirror,
1633 int jobnr, int nb_jobs)
1635 const int plane = s->desc->comp[component].plane;
1636 const int src_h = in->height;
1637 const int src_w = in->width;
1638 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
1639 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
1640 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
1641 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
1642 const int c0_linesize = in->linesize[(plane + 1) % s->ncomp];
1643 const int c1_linesize = in->linesize[(plane + 2) % s->ncomp];
1644 const int dst_linesize = out->linesize[plane];
1645 const int max = 255 - intensity;
1646 const int c0_shift_w = s->shift_w[(component + 1) % s->ncomp];
1647 const int c1_shift_w = s->shift_w[(component + 2) % s->ncomp];
1648 const int c0_shift_h = s->shift_h[(component + 1) % s->ncomp];
1649 const int c1_shift_h = s->shift_h[(component + 2) % s->ncomp];
1653 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
1655 for (x = slicew_start; x < slicew_end; x++) {
1656 const uint8_t *c0_data = in->data[(plane + 1) % s->ncomp];
1657 const uint8_t *c1_data = in->data[(plane + 2) % s->ncomp];
1658 uint8_t *dst_data = out->data[plane] + offset_y * dst_linesize + offset_x;
1659 uint8_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
1660 uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
1661 uint8_t *dst = dst_line;
1663 for (y = 0; y < src_h; y++) {
1664 const int sum = FFABS(c0_data[x >> c0_shift_w] - 128) + FFABS(c1_data[x >> c1_shift_w] - 127);
1667 target = dst + x + dst_signed_linesize * sum;
1668 update(target, max, intensity);
1670 if (!c0_shift_h || (y & c0_shift_h))
1671 c0_data += c0_linesize;
1672 if (!c1_shift_h || (y & c1_shift_h))
1673 c1_data += c1_linesize;
1674 dst_data += dst_linesize;
1678 const uint8_t *c0_data = in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c0_shift_h) * c0_linesize;
1679 const uint8_t *c1_data = in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize;
1680 uint8_t *dst_data = out->data[plane] + (offset_y + sliceh_start) * dst_linesize + offset_x;
1683 dst_data += s->size - 1;
1684 for (y = sliceh_start; y < sliceh_end; y++) {
1685 for (x = 0; x < src_w; x++) {
1686 const int sum = FFABS(c0_data[x >> c0_shift_w] - 128) + FFABS(c1_data[x >> c1_shift_w] - 127);
1690 target = dst_data - sum;
1691 update(target, max, intensity);
1693 target = dst_data + sum;
1694 update(target, max, intensity);
1698 if (!c0_shift_h || (y & c0_shift_h))
1699 c0_data += c0_linesize;
1700 if (!c1_shift_h || (y & c1_shift_h))
1701 c1_data += c1_linesize;
1702 dst_data += dst_linesize;
1707 #define CHROMA_FUNC(name, column, mirror) \
1708 static int chroma_##name(AVFilterContext *ctx, \
1709 void *arg, int jobnr, \
1712 WaveformContext *s = ctx->priv; \
1713 ThreadData *td = arg; \
1714 AVFrame *in = td->in; \
1715 AVFrame *out = td->out; \
1716 int component = td->component; \
1717 int offset_y = td->offset_y; \
1718 int offset_x = td->offset_x; \
1720 chroma(s, in, out, component, s->intensity, \
1721 offset_y, offset_x, column, mirror, \
1727 CHROMA_FUNC(column_mirror, 1, 1)
1728 CHROMA_FUNC(column, 1, 0)
1729 CHROMA_FUNC(row_mirror, 0, 1)
1730 CHROMA_FUNC(row, 0, 0)
1732 static av_always_inline void color16(WaveformContext *s,
1733 AVFrame *in, AVFrame *out,
1734 int component, int intensity,
1735 int offset_y, int offset_x,
1736 int column, int mirror,
1737 int jobnr, int nb_jobs)
1739 const int plane = s->desc->comp[component].plane;
1740 const int limit = s->max - 1;
1741 const int src_h = in->height;
1742 const int src_w = in->width;
1743 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
1744 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
1745 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
1746 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
1747 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
1748 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1749 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1750 const int c0_shift_h = s->shift_h[ component + 0 ];
1751 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1752 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1753 const uint16_t *c0_data = (const uint16_t *)in->data[plane + 0] + (sliceh_start >> c0_shift_h) * c0_linesize;
1754 const uint16_t *c1_data = (const uint16_t *)in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize;
1755 const uint16_t *c2_data = (const uint16_t *)in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize;
1756 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
1757 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
1758 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2;
1759 const int c0_shift_w = s->shift_w[ component + 0 ];
1760 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1761 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1765 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1766 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1767 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1768 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1769 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1770 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1771 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1772 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1773 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1774 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1775 uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1776 uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1778 for (y = 0; y < src_h; y++) {
1779 for (x = slicew_start; x < slicew_end; x++) {
1780 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1781 const int c1 = c1_data[x >> c1_shift_w];
1782 const int c2 = c2_data[x >> c2_shift_w];
1784 *(d0 + d0_signed_linesize * c0 + x) = c0;
1785 *(d1 + d1_signed_linesize * c0 + x) = c1;
1786 *(d2 + d2_signed_linesize * c0 + x) = c2;
1789 if (!c0_shift_h || (y & c0_shift_h))
1790 c0_data += c0_linesize;
1791 if (!c1_shift_h || (y & c1_shift_h))
1792 c1_data += c1_linesize;
1793 if (!c2_shift_h || (y & c2_shift_h))
1794 c2_data += c2_linesize;
1795 d0_data += d0_linesize;
1796 d1_data += d1_linesize;
1797 d2_data += d2_linesize;
1800 uint16_t *d0_data = (uint16_t *)out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x;
1801 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x;
1802 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + (offset_y + sliceh_start) * d2_linesize + offset_x;
1805 d0_data += s->size - 1;
1806 d1_data += s->size - 1;
1807 d2_data += s->size - 1;
1810 for (y = sliceh_start; y < sliceh_end; y++) {
1811 for (x = 0; x < src_w; x++) {
1812 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1813 const int c1 = c1_data[x >> c1_shift_w];
1814 const int c2 = c2_data[x >> c2_shift_w];
1817 *(d0_data - c0) = c0;
1818 *(d1_data - c0) = c1;
1819 *(d2_data - c0) = c2;
1821 *(d0_data + c0) = c0;
1822 *(d1_data + c0) = c1;
1823 *(d2_data + c0) = c2;
1827 if (!c0_shift_h || (y & c0_shift_h))
1828 c0_data += c0_linesize;
1829 if (!c1_shift_h || (y & c1_shift_h))
1830 c1_data += c1_linesize;
1831 if (!c2_shift_h || (y & c2_shift_h))
1832 c2_data += c2_linesize;
1833 d0_data += d0_linesize;
1834 d1_data += d1_linesize;
1835 d2_data += d2_linesize;
1840 #define COLOR16_FUNC(name, column, mirror) \
1841 static int color16_##name(AVFilterContext *ctx, \
1842 void *arg, int jobnr, \
1845 WaveformContext *s = ctx->priv; \
1846 ThreadData *td = arg; \
1847 AVFrame *in = td->in; \
1848 AVFrame *out = td->out; \
1849 int component = td->component; \
1850 int offset_y = td->offset_y; \
1851 int offset_x = td->offset_x; \
1853 color16(s, in, out, component, s->intensity, \
1854 offset_y, offset_x, column, mirror, \
1860 COLOR16_FUNC(column_mirror, 1, 1)
1861 COLOR16_FUNC(column, 1, 0)
1862 COLOR16_FUNC(row_mirror, 0, 1)
1863 COLOR16_FUNC(row, 0, 0)
1865 static av_always_inline void color(WaveformContext *s,
1866 AVFrame *in, AVFrame *out,
1867 int component, int intensity,
1868 int offset_y, int offset_x,
1869 int column, int mirror,
1870 int jobnr, int nb_jobs)
1872 const int plane = s->desc->comp[component].plane;
1873 const int src_h = in->height;
1874 const int src_w = in->width;
1875 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
1876 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
1877 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
1878 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
1879 const int c0_linesize = in->linesize[ plane + 0 ];
1880 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
1881 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
1882 const int c0_shift_h = s->shift_h[ component + 0 ];
1883 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1884 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1885 const uint8_t *c0_data = in->data[plane] + (sliceh_start >> c0_shift_h) * c0_linesize;
1886 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize;
1887 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize;
1888 const int d0_linesize = out->linesize[ plane + 0 ];
1889 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
1890 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp];
1891 const int c0_shift_w = s->shift_w[ component + 0 ];
1892 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1893 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1897 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1898 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1899 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1900 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1901 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1902 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1903 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1904 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1905 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1906 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1907 uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1908 uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1910 for (y = 0; y < src_h; y++) {
1911 for (x = slicew_start; x < slicew_end; x++) {
1912 const int c0 = c0_data[x >> c0_shift_w];
1913 const int c1 = c1_data[x >> c1_shift_w];
1914 const int c2 = c2_data[x >> c2_shift_w];
1916 *(d0 + d0_signed_linesize * c0 + x) = c0;
1917 *(d1 + d1_signed_linesize * c0 + x) = c1;
1918 *(d2 + d2_signed_linesize * c0 + x) = c2;
1921 if (!c0_shift_h || (y & c0_shift_h))
1922 c0_data += c0_linesize;
1923 if (!c1_shift_h || (y & c1_shift_h))
1924 c1_data += c1_linesize;
1925 if (!c2_shift_h || (y & c2_shift_h))
1926 c2_data += c2_linesize;
1927 d0_data += d0_linesize;
1928 d1_data += d1_linesize;
1929 d2_data += d2_linesize;
1932 uint8_t *d0_data = out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x;
1933 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x;
1934 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + (offset_y + sliceh_start) * d2_linesize + offset_x;
1937 d0_data += s->size - 1;
1938 d1_data += s->size - 1;
1939 d2_data += s->size - 1;
1942 for (y = sliceh_start; y < sliceh_end; y++) {
1943 for (x = 0; x < src_w; x++) {
1944 const int c0 = c0_data[x >> c0_shift_w];
1945 const int c1 = c1_data[x >> c1_shift_w];
1946 const int c2 = c2_data[x >> c2_shift_w];
1949 *(d0_data - c0) = c0;
1950 *(d1_data - c0) = c1;
1951 *(d2_data - c0) = c2;
1953 *(d0_data + c0) = c0;
1954 *(d1_data + c0) = c1;
1955 *(d2_data + c0) = c2;
1959 if (!c0_shift_h || (y & c0_shift_h))
1960 c0_data += c0_linesize;
1961 if (!c1_shift_h || (y & c1_shift_h))
1962 c1_data += c1_linesize;
1963 if (!c2_shift_h || (y & c2_shift_h))
1964 c2_data += c2_linesize;
1965 d0_data += d0_linesize;
1966 d1_data += d1_linesize;
1967 d2_data += d2_linesize;
1972 #define COLOR_FUNC(name, column, mirror) \
1973 static int color_##name(AVFilterContext *ctx, \
1974 void *arg, int jobnr, \
1977 WaveformContext *s = ctx->priv; \
1978 ThreadData *td = arg; \
1979 AVFrame *in = td->in; \
1980 AVFrame *out = td->out; \
1981 int component = td->component; \
1982 int offset_y = td->offset_y; \
1983 int offset_x = td->offset_x; \
1985 color(s, in, out, component, s->intensity, \
1986 offset_y, offset_x, column, mirror, \
1992 COLOR_FUNC(column_mirror, 1, 1)
1993 COLOR_FUNC(column, 1, 0)
1994 COLOR_FUNC(row_mirror, 0, 1)
1995 COLOR_FUNC(row, 0, 0)
1997 static av_always_inline void acolor16(WaveformContext *s,
1998 AVFrame *in, AVFrame *out,
1999 int component, int intensity,
2000 int offset_y, int offset_x,
2001 int column, int mirror,
2002 int jobnr, int nb_jobs)
2004 const int plane = s->desc->comp[component].plane;
2005 const int limit = s->max - 1;
2006 const int max = limit - intensity;
2007 const int src_h = in->height;
2008 const int src_w = in->width;
2009 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
2010 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
2011 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
2012 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
2013 const int c0_shift_h = s->shift_h[ component + 0 ];
2014 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
2015 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
2016 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
2017 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
2018 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
2019 const uint16_t *c0_data = (const uint16_t *)in->data[plane + 0] + (sliceh_start >> c0_shift_h) * c0_linesize;
2020 const uint16_t *c1_data = (const uint16_t *)in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize;
2021 const uint16_t *c2_data = (const uint16_t *)in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize;
2022 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
2023 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
2024 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2;
2025 const int c0_shift_w = s->shift_w[ component + 0 ];
2026 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
2027 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
2031 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
2032 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
2033 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
2034 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
2035 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
2036 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
2037 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
2038 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
2039 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
2040 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
2041 uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
2042 uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data);
2044 for (y = 0; y < src_h; y++) {
2045 for (x = slicew_start; x < slicew_end; x++) {
2046 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
2047 const int c1 = c1_data[x >> c1_shift_w];
2048 const int c2 = c2_data[x >> c2_shift_w];
2050 update16(d0 + d0_signed_linesize * c0 + x, max, intensity, limit);
2051 *(d1 + d1_signed_linesize * c0 + x) = c1;
2052 *(d2 + d2_signed_linesize * c0 + x) = c2;
2055 if (!c0_shift_h || (y & c0_shift_h))
2056 c0_data += c0_linesize;
2057 if (!c1_shift_h || (y & c1_shift_h))
2058 c1_data += c1_linesize;
2059 if (!c2_shift_h || (y & c2_shift_h))
2060 c2_data += c2_linesize;
2061 d0_data += d0_linesize;
2062 d1_data += d1_linesize;
2063 d2_data += d2_linesize;
2066 uint16_t *d0_data = (uint16_t *)out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x;
2067 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x;
2068 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + (offset_y + sliceh_start) * d2_linesize + offset_x;
2071 d0_data += s->size - 1;
2072 d1_data += s->size - 1;
2073 d2_data += s->size - 1;
2076 for (y = sliceh_start; y < sliceh_end; y++) {
2077 for (x = 0; x < src_w; x++) {
2078 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
2079 const int c1 = c1_data[x >> c1_shift_w];
2080 const int c2 = c2_data[x >> c2_shift_w];
2083 update16(d0_data - c0, max, intensity, limit);
2084 *(d1_data - c0) = c1;
2085 *(d2_data - c0) = c2;
2087 update16(d0_data + c0, max, intensity, limit);
2088 *(d1_data + c0) = c1;
2089 *(d2_data + c0) = c2;
2093 if (!c0_shift_h || (y & c0_shift_h))
2094 c0_data += c0_linesize;
2095 if (!c1_shift_h || (y & c1_shift_h))
2096 c1_data += c1_linesize;
2097 if (!c2_shift_h || (y & c2_shift_h))
2098 c2_data += c2_linesize;
2099 d0_data += d0_linesize;
2100 d1_data += d1_linesize;
2101 d2_data += d2_linesize;
2106 #define ACOLOR16_FUNC(name, column, mirror) \
2107 static int acolor16_##name(AVFilterContext *ctx, \
2108 void *arg, int jobnr, \
2111 WaveformContext *s = ctx->priv; \
2112 ThreadData *td = arg; \
2113 AVFrame *in = td->in; \
2114 AVFrame *out = td->out; \
2115 int component = td->component; \
2116 int offset_y = td->offset_y; \
2117 int offset_x = td->offset_x; \
2119 acolor16(s, in, out, component, s->intensity,\
2120 offset_y, offset_x, column, mirror, \
2126 ACOLOR16_FUNC(column_mirror, 1, 1)
2127 ACOLOR16_FUNC(column, 1, 0)
2128 ACOLOR16_FUNC(row_mirror, 0, 1)
2129 ACOLOR16_FUNC(row, 0, 0)
2131 static av_always_inline void acolor(WaveformContext *s,
2132 AVFrame *in, AVFrame *out,
2133 int component, int intensity,
2134 int offset_y, int offset_x,
2135 int column, int mirror,
2136 int jobnr, int nb_jobs)
2138 const int plane = s->desc->comp[component].plane;
2139 const int src_h = in->height;
2140 const int src_w = in->width;
2141 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
2142 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
2143 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
2144 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
2145 const int c0_shift_w = s->shift_w[ component + 0 ];
2146 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
2147 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
2148 const int c0_shift_h = s->shift_h[ component + 0 ];
2149 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
2150 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
2151 const int c0_linesize = in->linesize[ plane + 0 ];
2152 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
2153 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
2154 const uint8_t *c0_data = in->data[plane + 0] + (sliceh_start >> c0_shift_h) * c0_linesize;
2155 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize;
2156 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize;
2157 const int d0_linesize = out->linesize[ plane + 0 ];
2158 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
2159 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp];
2160 const int max = 255 - intensity;
2164 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
2165 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
2166 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
2167 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
2168 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
2169 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
2170 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
2171 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
2172 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
2173 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
2174 uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
2175 uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data);
2177 for (y = 0; y < src_h; y++) {
2178 for (x = slicew_start; x < slicew_end; x++) {
2179 const int c0 = c0_data[x >> c0_shift_w];
2180 const int c1 = c1_data[x >> c1_shift_w];
2181 const int c2 = c2_data[x >> c2_shift_w];
2183 update(d0 + d0_signed_linesize * c0 + x, max, intensity);
2184 *(d1 + d1_signed_linesize * c0 + x) = c1;
2185 *(d2 + d2_signed_linesize * c0 + x) = c2;
2188 if (!c0_shift_h || (y & c0_shift_h))
2189 c0_data += c0_linesize;
2190 if (!c1_shift_h || (y & c1_shift_h))
2191 c1_data += c1_linesize;
2192 if (!c2_shift_h || (y & c2_shift_h))
2193 c2_data += c2_linesize;
2194 d0_data += d0_linesize;
2195 d1_data += d1_linesize;
2196 d2_data += d2_linesize;
2199 uint8_t *d0_data = out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x;
2200 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x;
2201 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + (offset_y + sliceh_start) * d2_linesize + offset_x;
2204 d0_data += s->size - 1;
2205 d1_data += s->size - 1;
2206 d2_data += s->size - 1;
2209 for (y = sliceh_start; y < sliceh_end; y++) {
2210 for (x = 0; x < src_w; x++) {
2211 const int c0 = c0_data[x >> c0_shift_w];
2212 const int c1 = c1_data[x >> c1_shift_w];
2213 const int c2 = c2_data[x >> c2_shift_w];
2216 update(d0_data - c0, max, intensity);
2217 *(d1_data - c0) = c1;
2218 *(d2_data - c0) = c2;
2220 update(d0_data + c0, max, intensity);
2221 *(d1_data + c0) = c1;
2222 *(d2_data + c0) = c2;
2226 if (!c0_shift_h || (y & c0_shift_h))
2227 c0_data += c0_linesize;
2228 if (!c1_shift_h || (y & c1_shift_h))
2229 c1_data += c1_linesize;
2230 if (!c2_shift_h || (y & c2_shift_h))
2231 c2_data += c2_linesize;
2232 d0_data += d0_linesize;
2233 d1_data += d1_linesize;
2234 d2_data += d2_linesize;
2239 #define ACOLOR_FUNC(name, column, mirror) \
2240 static int acolor_##name(AVFilterContext *ctx, \
2241 void *arg, int jobnr, \
2244 WaveformContext *s = ctx->priv; \
2245 ThreadData *td = arg; \
2246 AVFrame *in = td->in; \
2247 AVFrame *out = td->out; \
2248 int component = td->component; \
2249 int offset_y = td->offset_y; \
2250 int offset_x = td->offset_x; \
2252 acolor(s, in, out, component, s->intensity, \
2253 offset_y, offset_x, column, mirror, \
2259 ACOLOR_FUNC(column_mirror, 1, 1)
2260 ACOLOR_FUNC(column, 1, 0)
2261 ACOLOR_FUNC(row_mirror, 0, 1)
2262 ACOLOR_FUNC(row, 0, 0)
2264 static const uint8_t black_yuva_color[4] = { 0, 127, 127, 255 };
2265 static const uint8_t black_gbrp_color[4] = { 0, 0, 0, 255 };
2267 static const GraticuleLines aflat_digital8[] = {
2268 { { { "16", 16+128 }, { "16", 16+128 }, { "16", 16+128 }, { "0", 0+128 } } },
2269 { { { "128", 128+128 }, { "128", 128+128 }, { "128", 128+128 }, { "128", 128+128 } } },
2270 { { { "235", 235+128 }, { "240", 240+128 }, { "240", 240+128 }, { "255", 255+128 } } },
2273 static const GraticuleLines aflat_digital9[] = {
2274 { { { "32", 32+256 }, { "32", 32+256 }, { "32", 32+256 }, { "0", 0+256 } } },
2275 { { { "256", 256+256 }, { "256", 256+256 }, { "256", 256+256 }, { "256", 256+256 } } },
2276 { { { "470", 470+256 }, { "480", 480+256 }, { "480", 480+256 }, { "511", 511+256 } } },
2279 static const GraticuleLines aflat_digital10[] = {
2280 { { { "64", 64+512 }, { "64", 64+512 }, { "64", 64+512 }, { "0", 0+512 } } },
2281 { { { "512", 512+512 }, { "512", 512+512 }, { "512", 512+512 }, { "512", 512+512 } } },
2282 { { { "940", 940+512 }, { "960", 960+512 }, { "960", 960+512 }, { "1023", 1023+512 } } },
2285 static const GraticuleLines aflat_digital12[] = {
2286 { { { "256", 256+2048 }, { "256", 256+2048 }, { "256", 256+2048 }, { "0", 0+2048 } } },
2287 { { { "2048", 2048+2048 }, { "2048", 2048+2048 }, { "2048", 2048+2048 }, { "2048", 2048+2048 } } },
2288 { { { "3760", 3760+2048 }, { "3840", 3840+2048 }, { "3840", 3840+2048 }, { "4095", 4095+2048 } } },
2291 static const GraticuleLines aflat_millivolts8[] = {
2292 { { { "0", 16+128 }, { "0", 16+128 }, { "0", 16+128 }, { "0", 0+128 } } },
2293 { { { "175", 71+128 }, { "175", 72+128 }, { "175", 72+128 }, { "175", 64+128 } } },
2294 { { { "350", 126+128 }, { "350", 128+128 }, { "350", 128+128 }, { "350", 128+128 } } },
2295 { { { "525", 180+128 }, { "525", 184+128 }, { "525", 184+128 }, { "525", 192+128 } } },
2296 { { { "700", 235+128 }, { "700", 240+128 }, { "700", 240+128 }, { "700", 255+128 } } },
2299 static const GraticuleLines aflat_millivolts9[] = {
2300 { { { "0", 32+256 }, { "0", 32+256 }, { "0", 32+256 }, { "0", 0+256 } } },
2301 { { { "175", 142+256 }, { "175", 144+256 }, { "175", 144+256 }, { "175", 128+256 } } },
2302 { { { "350", 251+256 }, { "350", 256+256 }, { "350", 256+256 }, { "350", 256+256 } } },
2303 { { { "525", 361+256 }, { "525", 368+256 }, { "525", 368+256 }, { "525", 384+256 } } },
2304 { { { "700", 470+256 }, { "700", 480+256 }, { "700", 480+256 }, { "700", 511+256 } } },
2307 static const GraticuleLines aflat_millivolts10[] = {
2308 { { { "0", 64+512 }, { "0", 64+512 }, { "0", 64+512 }, { "0", 0+512 } } },
2309 { { { "175", 283+512 }, { "175", 288+512 }, { "175", 288+512 }, { "175", 256+512 } } },
2310 { { { "350", 502+512 }, { "350", 512+512 }, { "350", 512+512 }, { "350", 512+512 } } },
2311 { { { "525", 721+512 }, { "525", 736+512 }, { "525", 736+512 }, { "525", 768+512 } } },
2312 { { { "700", 940+512 }, { "700", 960+512 }, { "700", 960+512 }, { "700", 1023+512 } } },
2315 static const GraticuleLines aflat_millivolts12[] = {
2316 { { { "0", 256+2048 }, { "0", 256+2048 }, { "0", 256+2048 }, { "0", 0+2048 } } },
2317 { { { "175", 1132+2048 }, { "175", 1152+2048 }, { "175", 1152+2048 }, { "175", 1024+2048 } } },
2318 { { { "350", 2008+2048 }, { "350", 2048+2048 }, { "350", 2048+2048 }, { "350", 2048+2048 } } },
2319 { { { "525", 2884+2048 }, { "525", 2944+2048 }, { "525", 2944+2048 }, { "525", 3072+2048 } } },
2320 { { { "700", 3760+2048 }, { "700", 3840+2048 }, { "700", 3840+2048 }, { "700", 4095+2048 } } },
2323 static const GraticuleLines aflat_ire8[] = {
2324 { { { "-25", -39+128 }, { "-25", -40+128 }, { "-25", -40+128 }, { "-25", -64+128 } } },
2325 { { { "0", 16+128 }, { "0", 16+128 }, { "0", 16+128 }, { "0", 0+128 } } },
2326 { { { "25", 71+128 }, { "25", 72+128 }, { "25", 72+128 }, { "25", 64+128 } } },
2327 { { { "50", 126+128 }, { "50", 128+128 }, { "50", 128+128 }, { "50", 128+128 } } },
2328 { { { "75", 180+128 }, { "75", 184+128 }, { "75", 184+128 }, { "75", 192+128 } } },
2329 { { { "100", 235+128 }, { "100", 240+128 }, { "100", 240+128 }, { "100", 256+128 } } },
2330 { { { "125", 290+128 }, { "125", 296+128 }, { "125", 296+128 }, { "125", 320+128 } } },
2333 static const GraticuleLines aflat_ire9[] = {
2334 { { { "-25", -78+256 }, { "-25", -80+256 }, { "-25", -80+256 }, { "-25",-128+256 } } },
2335 { { { "0", 32+256 }, { "0", 32+256 }, { "0", 32+256 }, { "0", 0+256 } } },
2336 { { { "25", 142+256 }, { "25", 144+256 }, { "25", 144+256 }, { "25", 128+256 } } },
2337 { { { "50", 251+256 }, { "50", 256+256 }, { "50", 256+256 }, { "50", 256+256 } } },
2338 { { { "75", 361+256 }, { "75", 368+256 }, { "75", 368+256 }, { "75", 384+256 } } },
2339 { { { "100", 470+256 }, { "100", 480+256 }, { "100", 480+256 }, { "100", 512+256 } } },
2340 { { { "125", 580+256 }, { "125", 592+256 }, { "125", 592+256 }, { "125", 640+256 } } },
2343 static const GraticuleLines aflat_ire10[] = {
2344 { { { "-25",-156+512 }, { "-25",-160+512 }, { "-25",-160+512 }, { "-25", -256+512 } } },
2345 { { { "0", 64+512 }, { "0", 64+512 }, { "0", 64+512 }, { "0", 0+512 } } },
2346 { { { "25", 283+512 }, { "25", 288+512 }, { "25", 288+512 }, { "25", 256+512 } } },
2347 { { { "50", 502+512 }, { "50", 512+512 }, { "50", 512+512 }, { "50", 512+512 } } },
2348 { { { "75", 721+512 }, { "75", 736+512 }, { "75", 736+512 }, { "75", 768+512 } } },
2349 { { { "100", 940+512 }, { "100", 960+512 }, { "100", 960+512 }, { "100", 1024+512 } } },
2350 { { { "125",1160+512 }, { "125",1184+512 }, { "125",1184+512 }, { "125", 1280+512 } } },
2353 static const GraticuleLines aflat_ire12[] = {
2354 { { { "-25", -624+2048 }, { "-25", -640+2048 }, { "-25", -640+2048 }, { "-25",-1024+2048 } } },
2355 { { { "0", 256+2048 }, { "0", 256+2048 }, { "0", 256+2048 }, { "0", 0+2048 } } },
2356 { { { "25", 1132+2048 }, { "25", 1152+2048 }, { "25", 1152+2048 }, { "25", 1024+2048 } } },
2357 { { { "50", 2008+2048 }, { "50", 2048+2048 }, { "50", 2048+2048 }, { "50", 2048+2048 } } },
2358 { { { "75", 2884+2048 }, { "75", 2944+2048 }, { "75", 2944+2048 }, { "75", 3072+2048 } } },
2359 { { { "100", 3760+2048 }, { "100", 3840+2048 }, { "100", 3840+2048 }, { "100", 4096+2048 } } },
2360 { { { "125", 4640+2048 }, { "125", 4736+2048 }, { "125", 4736+2048 }, { "125", 5120+2048 } } },
2363 static const GraticuleLines flat_digital8[] = {
2364 { { { "16", 16+256 }, { "16", 16+256 }, { "16", 16+256 }, { "0", 0+256 } } },
2365 { { { "128", 128+256 }, { "128", 128+256 }, { "128", 128+256 }, { "128", 128+256 } } },
2366 { { { "235", 235+256 }, { "240", 240+256 }, { "240", 240+256 }, { "255", 255+256 } } },
2369 static const GraticuleLines flat_digital9[] = {
2370 { { { "32", 32+512 }, { "32", 32+512 }, { "32", 32+512 }, { "0", 0+512 } } },
2371 { { { "256", 256+512 }, { "256", 256+512 }, { "256", 256+512 }, { "256", 256+512 } } },
2372 { { { "470", 470+512 }, { "480", 480+512 }, { "480", 480+512 }, { "511", 511+512 } } },
2375 static const GraticuleLines flat_digital10[] = {
2376 { { { "64", 64+1024 }, { "64", 64+1024 }, { "64", 64+1024 }, { "0", 0+1024 } } },
2377 { { { "512", 512+1024 }, { "512", 512+1024 }, { "512", 512+1024 }, { "512", 512+1024 } } },
2378 { { { "940", 940+1024 }, { "960", 960+1024 }, { "960", 960+1024 }, { "1023", 1023+1024 } } },
2381 static const GraticuleLines flat_digital12[] = {
2382 { { { "256", 256+4096 }, { "256", 256+4096 }, { "256", 256+4096 }, { "0", 0+4096 } } },
2383 { { { "2048", 2048+4096 }, { "2048", 2048+4096 }, { "2048", 2048+4096 }, { "2048", 2048+4096 } } },
2384 { { { "3760", 3760+4096 }, { "3840", 3840+4096 }, { "3840", 3840+4096 }, { "4095", 4095+4096 } } },
2387 static const GraticuleLines flat_millivolts8[] = {
2388 { { { "0", 16+256 }, { "0", 16+256 }, { "0", 16+256 }, { "0", 0+256 } } },
2389 { { { "175", 71+256 }, { "175", 72+256 }, { "175", 72+256 }, { "175", 64+256 } } },
2390 { { { "350", 126+256 }, { "350", 128+256 }, { "350", 128+256 }, { "350", 128+256 } } },
2391 { { { "525", 180+256 }, { "525", 184+256 }, { "525", 184+256 }, { "525", 192+256 } } },
2392 { { { "700", 235+256 }, { "700", 240+256 }, { "700", 240+256 }, { "700", 255+256 } } },
2395 static const GraticuleLines flat_millivolts9[] = {
2396 { { { "0", 32+512 }, { "0", 32+512 }, { "0", 32+512 }, { "0", 0+512 } } },
2397 { { { "175", 142+512 }, { "175", 144+512 }, { "175", 144+512 }, { "175", 128+512 } } },
2398 { { { "350", 251+512 }, { "350", 256+512 }, { "350", 256+512 }, { "350", 256+512 } } },
2399 { { { "525", 361+512 }, { "525", 368+512 }, { "525", 368+512 }, { "525", 384+512 } } },
2400 { { { "700", 470+512 }, { "700", 480+512 }, { "700", 480+512 }, { "700", 511+512 } } },
2403 static const GraticuleLines flat_millivolts10[] = {
2404 { { { "0", 64+1024 }, { "0", 64+1024 }, { "0", 64+1024 }, { "0", 0+1024 } } },
2405 { { { "175", 283+1024 }, { "175", 288+1024 }, { "175", 288+1024 }, { "175", 256+1024 } } },
2406 { { { "350", 502+1024 }, { "350", 512+1024 }, { "350", 512+1024 }, { "350", 512+1024 } } },
2407 { { { "525", 721+1024 }, { "525", 736+1024 }, { "525", 736+1024 }, { "525", 768+1024 } } },
2408 { { { "700", 940+1024 }, { "700", 960+1024 }, { "700", 960+1024 }, { "700", 1023+1024 } } },
2411 static const GraticuleLines flat_millivolts12[] = {
2412 { { { "0", 256+4096 }, { "0", 256+4096 }, { "0", 256+4096 }, { "0", 0+4096 } } },
2413 { { { "175", 1132+4096 }, { "175", 1152+4096 }, { "175", 1152+4096 }, { "175", 1024+4096 } } },
2414 { { { "350", 2008+4096 }, { "350", 2048+4096 }, { "350", 2048+4096 }, { "350", 2048+4096 } } },
2415 { { { "525", 2884+4096 }, { "525", 2944+4096 }, { "525", 2944+4096 }, { "525", 3072+4096 } } },
2416 { { { "700", 3760+4096 }, { "700", 3840+4096 }, { "700", 3840+4096 }, { "700", 4095+4096 } } },
2419 static const GraticuleLines flat_ire8[] = {
2420 { { { "-25", -39+256 }, { "-25", -40+256 }, { "-25", -40+256 }, { "-25", -64+256 } } },
2421 { { { "0", 16+256 }, { "0", 16+256 }, { "0", 16+256 }, { "0", 0+256 } } },
2422 { { { "25", 71+256 }, { "25", 72+256 }, { "25", 72+256 }, { "25", 64+256 } } },
2423 { { { "50", 126+256 }, { "50", 128+256 }, { "50", 128+256 }, { "50", 128+256 } } },
2424 { { { "75", 180+256 }, { "75", 184+256 }, { "75", 184+256 }, { "75", 192+256 } } },
2425 { { { "100", 235+256 }, { "100", 240+256 }, { "100", 240+256 }, { "100", 256+256 } } },
2426 { { { "125", 290+256 }, { "125", 296+256 }, { "125", 296+256 }, { "125", 320+256 } } },
2429 static const GraticuleLines flat_ire9[] = {
2430 { { { "-25", -78+512 }, { "-25", -80+512 }, { "-25", -80+512 }, { "-25",-128+512 } } },
2431 { { { "0", 32+512 }, { "0", 32+512 }, { "0", 32+512 }, { "0", 0+512 } } },
2432 { { { "25", 142+512 }, { "25", 144+512 }, { "25", 144+512 }, { "25", 128+512 } } },
2433 { { { "50", 251+512 }, { "50", 256+512 }, { "50", 256+512 }, { "50", 256+512 } } },
2434 { { { "75", 361+512 }, { "75", 368+512 }, { "75", 368+512 }, { "75", 384+512 } } },
2435 { { { "100", 470+512 }, { "100", 480+512 }, { "100", 480+512 }, { "100", 512+512 } } },
2436 { { { "125", 580+512 }, { "125", 592+512 }, { "125", 592+512 }, { "125", 640+512 } } },
2439 static const GraticuleLines flat_ire10[] = {
2440 { { { "-25",-156+1024 }, { "-25",-160+1024 }, { "-25",-160+1024 }, { "-25", -256+1024 } } },
2441 { { { "0", 64+1024 }, { "0", 64+1024 }, { "0", 64+1024 }, { "0", 0+1024 } } },
2442 { { { "25", 283+1024 }, { "25", 288+1024 }, { "25", 288+1024 }, { "25", 256+1024 } } },
2443 { { { "50", 502+1024 }, { "50", 512+1024 }, { "50", 512+1024 }, { "50", 512+1024 } } },
2444 { { { "75", 721+1024 }, { "75", 736+1024 }, { "75", 736+1024 }, { "75", 768+1024 } } },
2445 { { { "100", 940+1024 }, { "100", 960+1024 }, { "100", 960+1024 }, { "100", 1024+1024 } } },
2446 { { { "125",1160+1024 }, { "125",1184+1024 }, { "125",1184+1024 }, { "125", 1280+1024 } } },
2449 static const GraticuleLines flat_ire12[] = {
2450 { { { "-25", -624+4096 }, { "-25", -640+4096 }, { "-25", -640+4096 }, { "-25",-1024+4096 } } },
2451 { { { "0", 256+4096 }, { "0", 256+4096 }, { "0", 256+4096 }, { "0", 0+4096 } } },
2452 { { { "25", 1132+4096 }, { "25", 1152+4096 }, { "25", 1152+4096 }, { "25", 1024+4096 } } },
2453 { { { "50", 2008+4096 }, { "50", 2048+4096 }, { "50", 2048+4096 }, { "50", 2048+4096 } } },
2454 { { { "75", 2884+4096 }, { "75", 2944+4096 }, { "75", 2944+4096 }, { "75", 3072+4096 } } },
2455 { { { "100", 3760+4096 }, { "100", 3840+4096 }, { "100", 3840+4096 }, { "100", 4096+4096 } } },
2456 { { { "125", 4640+4096 }, { "125", 4736+4096 }, { "125", 4736+4096 }, { "125", 5120+4096 } } },
2459 static const GraticuleLines digital8[] = {
2460 { { { "16", 16 }, { "16", 16 }, { "16", 16 }, { "0", 0 } } },
2461 { { { "128", 128 }, { "128", 128 }, { "128", 128 }, { "128", 128 } } },
2462 { { { "235", 235 }, { "240", 240 }, { "240", 240 }, { "255", 255 } } },
2465 static const GraticuleLines digital9[] = {
2466 { { { "32", 32 }, { "32", 32 }, { "32", 32 }, { "0", 0 } } },
2467 { { { "256", 256 }, { "256", 256 }, { "256", 256 }, { "256", 256 } } },
2468 { { { "470", 470 }, { "480", 480 }, { "480", 480 }, { "511", 511 } } },
2471 static const GraticuleLines digital10[] = {
2472 { { { "64", 64 }, { "64", 64 }, { "64", 64 }, { "0", 0 } } },
2473 { { { "512", 512 }, { "512", 512 }, { "512", 512 }, { "512", 512 } } },
2474 { { { "940", 940 }, { "960", 960 }, { "960", 960 }, { "1023", 1023 } } },
2477 static const GraticuleLines digital12[] = {
2478 { { { "256", 256 }, { "256", 256 }, { "256", 256 }, { "0", 0 } } },
2479 { { { "2048", 2048 }, { "2048", 2048 }, { "2048", 2048 }, { "2048", 2048 } } },
2480 { { { "3760", 3760 }, { "3840", 3840 }, { "3840", 3840 }, { "4095", 4095 } } },
2483 static const GraticuleLines millivolts8[] = {
2484 { { { "0", 16 }, { "0", 16 }, { "0", 16 }, { "0", 0 } } },
2485 { { { "175", 71 }, { "175", 72 }, { "175", 72 }, { "175", 64 } } },
2486 { { { "350", 126 }, { "350", 128 }, { "350", 128 }, { "350", 128 } } },
2487 { { { "525", 180 }, { "525", 184 }, { "525", 184 }, { "525", 192 } } },
2488 { { { "700", 235 }, { "700", 240 }, { "700", 240 }, { "700", 255 } } },
2491 static const GraticuleLines millivolts9[] = {
2492 { { { "0", 32 }, { "0", 32 }, { "0", 32 }, { "0", 0 } } },
2493 { { { "175", 142 }, { "175", 144 }, { "175", 144 }, { "175", 128 } } },
2494 { { { "350", 251 }, { "350", 256 }, { "350", 256 }, { "350", 256 } } },
2495 { { { "525", 361 }, { "525", 368 }, { "525", 368 }, { "525", 384 } } },
2496 { { { "700", 470 }, { "700", 480 }, { "700", 480 }, { "700", 511 } } },
2499 static const GraticuleLines millivolts10[] = {
2500 { { { "0", 64 }, { "0", 64 }, { "0", 64 }, { "0", 0 } } },
2501 { { { "175", 283 }, { "175", 288 }, { "175", 288 }, { "175", 256 } } },
2502 { { { "350", 502 }, { "350", 512 }, { "350", 512 }, { "350", 512 } } },
2503 { { { "525", 721 }, { "525", 736 }, { "525", 736 }, { "525", 768 } } },
2504 { { { "700", 940 }, { "700", 960 }, { "700", 960 }, { "700", 1023 } } },
2507 static const GraticuleLines millivolts12[] = {
2508 { { { "0", 256 }, { "0", 256 }, { "0", 256 }, { "0", 0 } } },
2509 { { { "175", 1132 }, { "175", 1152 }, { "175", 1152 }, { "175", 1024 } } },
2510 { { { "350", 2008 }, { "350", 2048 }, { "350", 2048 }, { "350", 2048 } } },
2511 { { { "525", 2884 }, { "525", 2944 }, { "525", 2944 }, { "525", 3072 } } },
2512 { { { "700", 3760 }, { "700", 3840 }, { "700", 3840 }, { "700", 4095 } } },
2515 static const GraticuleLines ire8[] = {
2516 { { { "0", 16 }, { "0", 16 }, { "0", 16 }, { "0", 0 } } },
2517 { { { "25", 71 }, { "25", 72 }, { "25", 72 }, { "25", 64 } } },
2518 { { { "50", 126 }, { "50", 128 }, { "50", 128 }, { "50", 128 } } },
2519 { { { "75", 180 }, { "75", 184 }, { "75", 184 }, { "75", 192 } } },
2520 { { { "100", 235 }, { "100", 240 }, { "100", 240 }, { "100", 255 } } },
2523 static const GraticuleLines ire9[] = {
2524 { { { "0", 32 }, { "0", 32 }, { "0", 32 }, { "0", 0 } } },
2525 { { { "25", 142 }, { "25", 144 }, { "25", 144 }, { "25", 128 } } },
2526 { { { "50", 251 }, { "50", 256 }, { "50", 256 }, { "50", 256 } } },
2527 { { { "75", 361 }, { "75", 368 }, { "75", 368 }, { "75", 384 } } },
2528 { { { "100", 470 }, { "100", 480 }, { "100", 480 }, { "100", 511 } } },
2531 static const GraticuleLines ire10[] = {
2532 { { { "0", 64 }, { "0", 64 }, { "0", 64 }, { "0", 0 } } },
2533 { { { "25", 283 }, { "25", 288 }, { "25", 288 }, { "25", 256 } } },
2534 { { { "50", 502 }, { "50", 512 }, { "50", 512 }, { "50", 512 } } },
2535 { { { "75", 721 }, { "75", 736 }, { "75", 736 }, { "75", 768 } } },
2536 { { { "100", 940 }, { "100", 960 }, { "100", 960 }, { "100", 1023 } } },
2539 static const GraticuleLines ire12[] = {
2540 { { { "0", 256 }, { "0", 256 }, { "0", 256 }, { "0", 0 } } },
2541 { { { "25", 1132 }, { "25", 1152 }, { "25", 1152 }, { "25", 1024 } } },
2542 { { { "50", 2008 }, { "50", 2048 }, { "50", 2048 }, { "50", 2048 } } },
2543 { { { "75", 2884 }, { "75", 2944 }, { "75", 2944 }, { "75", 3072 } } },
2544 { { { "100", 3760 }, { "100", 3840 }, { "100", 3840 }, { "100", 4095 } } },
2547 static const GraticuleLines chroma_digital8[] = {
2548 { { { "50", 50 }, { "50", 50 }, { "50", 50 }, { "50", 50 } } },
2549 { { { "100", 100 }, { "100", 100 }, { "100", 100 }, { "100", 100 } } },
2550 { { { "150", 150 }, { "150", 150 }, { "150", 150 }, { "150", 150 } } },
2551 { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2552 { { { "255", 255 }, { "255", 255 }, { "255", 255 }, { "255", 255 } } },
2555 static const GraticuleLines chroma_digital9[] = {
2556 { { { "100", 100 }, { "100", 100 }, { "100", 100 }, { "100", 100 } } },
2557 { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2558 { { { "300", 300 }, { "300", 300 }, { "300", 300 }, { "300", 300 } } },
2559 { { { "400", 400 }, { "400", 400 }, { "400", 400 }, { "400", 400 } } },
2560 { { { "500", 500 }, { "500", 500 }, { "500", 500 }, { "500", 500 } } },
2563 static const GraticuleLines chroma_digital10[] = {
2564 { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2565 { { { "400", 400 }, { "400", 400 }, { "400", 400 }, { "400", 400 } } },
2566 { { { "600", 600 }, { "600", 600 }, { "600", 600 }, { "600", 600 } } },
2567 { { { "800", 800 }, { "800", 800 }, { "800", 800 }, { "800", 800 } } },
2568 { { {"1000",1000 }, {"1000",1000 }, {"1000",1000 }, {"1000",1000 } } },
2571 static const GraticuleLines chroma_digital12[] = {
2572 { { { "800", 800 }, { "800", 800 }, { "800", 800 }, { "800", 800 } } },
2573 { { { "1600", 1600 }, { "1600", 1600 }, { "1600", 1600 }, { "1600", 1600 } } },
2574 { { { "2400", 2400 }, { "2400", 2400 }, { "2400", 2400 }, { "2400", 2400 } } },
2575 { { { "3200", 3200 }, { "3200", 3200 }, { "3200", 3200 }, { "3200", 3200 } } },
2576 { { { "4000", 4000 }, { "4000", 4000 }, { "4000", 4000 }, { "4000", 4000 } } },
2579 static void blend_vline(uint8_t *dst, int height, int linesize, float o1, float o2, int v, int step)
2583 for (y = 0; y < height; y += step) {
2584 dst[0] = v * o1 + dst[0] * o2;
2586 dst += linesize * step;
2590 static void blend_vline16(uint8_t *ddst, int height, int linesize, float o1, float o2, int v, int step)
2592 uint16_t *dst = (uint16_t *)ddst;
2595 for (y = 0; y < height; y += step) {
2596 dst[0] = v * o1 + dst[0] * o2;
2598 dst += (linesize / 2) * step;
2602 static void blend_hline(uint8_t *dst, int width, int unused, float o1, float o2, int v, int step)
2606 for (x = 0; x < width; x += step) {
2607 dst[x] = v * o1 + dst[x] * o2;
2611 static void blend_hline16(uint8_t *ddst, int width, int unused, float o1, float o2, int v, int step)
2613 uint16_t *dst = (uint16_t *)ddst;
2616 for (x = 0; x < width; x += step) {
2617 dst[x] = v * o1 + dst[x] * o2;
2621 static void draw_htext(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
2623 const uint8_t *font;
2627 font = avpriv_cga_font, font_height = 8;
2629 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2630 for (i = 0; txt[i]; i++) {
2632 int v = color[plane];
2634 uint8_t *p = out->data[plane] + y * out->linesize[plane] + (x + i * 8);
2635 for (char_y = 0; char_y < font_height; char_y++) {
2636 for (mask = 0x80; mask; mask >>= 1) {
2637 if (font[txt[i] * font_height + char_y] & mask)
2638 p[0] = p[0] * o2 + v * o1;
2641 p += out->linesize[plane] - 8;
2647 static void draw_htext16(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
2649 const uint8_t *font;
2653 font = avpriv_cga_font, font_height = 8;
2655 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2656 for (i = 0; txt[i]; i++) {
2658 int v = color[plane] * mult;
2660 uint16_t *p = (uint16_t *)(out->data[plane] + y * out->linesize[plane]) + (x + i * 8);
2661 for (char_y = 0; char_y < font_height; char_y++) {
2662 for (mask = 0x80; mask; mask >>= 1) {
2663 if (font[txt[i] * font_height + char_y] & mask)
2664 p[0] = p[0] * o2 + v * o1;
2667 p += out->linesize[plane] / 2 - 8;
2673 static void draw_vtext(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
2675 const uint8_t *font;
2679 font = avpriv_cga_font, font_height = 8;
2681 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2682 for (i = 0; txt[i]; i++) {
2684 int v = color[plane];
2686 for (char_y = font_height - 1; char_y >= 0; char_y--) {
2687 uint8_t *p = out->data[plane] + (y + i * 10) * out->linesize[plane] + x;
2688 for (mask = 0x80; mask; mask >>= 1) {
2689 if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
2690 p[char_y] = p[char_y] * o2 + v * o1;
2691 p += out->linesize[plane];
2698 static void draw_vtext16(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
2700 const uint8_t *font;
2704 font = avpriv_cga_font, font_height = 8;
2706 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2707 for (i = 0; txt[i]; i++) {
2709 int v = color[plane] * mult;
2711 for (char_y = 0; char_y < font_height; char_y++) {
2712 uint16_t *p = (uint16_t *)(out->data[plane] + (y + i * 10) * out->linesize[plane]) + x;
2713 for (mask = 0x80; mask; mask >>= 1) {
2714 if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
2715 p[char_y] = p[char_y] * o2 + v * o1;
2716 p += out->linesize[plane] / 2;
2723 static void iblend_vline(uint8_t *dst, int height, int linesize, float o1, float o2, int v, int step)
2727 for (y = 0; y < height; y += step) {
2728 dst[0] = (v - dst[0]) * o1 + dst[0] * o2;
2730 dst += linesize * step;
2734 static void iblend_vline16(uint8_t *ddst, int height, int linesize, float o1, float o2, int v, int step)
2736 uint16_t *dst = (uint16_t *)ddst;
2739 for (y = 0; y < height; y += step) {
2740 dst[0] = (v - dst[0]) * o1 + dst[0] * o2;
2742 dst += (linesize / 2) * step;
2746 static void iblend_hline(uint8_t *dst, int width, int unused, float o1, float o2, int v, int step)
2750 for (x = 0; x < width; x += step) {
2751 dst[x] = (v - dst[x]) * o1 + dst[x] * o2;
2755 static void iblend_hline16(uint8_t *ddst, int width, int unused, float o1, float o2, int v, int step)
2757 uint16_t *dst = (uint16_t *)ddst;
2760 for (x = 0; x < width; x += step) {
2761 dst[x] = (v - dst[x]) * o1 + dst[x] * o2;
2765 static void idraw_htext(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
2767 const uint8_t *font;
2771 font = avpriv_cga_font, font_height = 8;
2773 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2774 for (i = 0; txt[i]; i++) {
2776 int v = color[plane];
2778 uint8_t *p = out->data[plane] + y * out->linesize[plane] + (x + i * 8);
2779 for (char_y = 0; char_y < font_height; char_y++) {
2780 for (mask = 0x80; mask; mask >>= 1) {
2781 if (font[txt[i] * font_height + char_y] & mask)
2782 p[0] = p[0] * o2 + (v - p[0]) * o1;
2785 p += out->linesize[plane] - 8;
2791 static void idraw_htext16(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
2793 const uint8_t *font;
2797 font = avpriv_cga_font, font_height = 8;
2799 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2800 for (i = 0; txt[i]; i++) {
2802 int v = color[plane] * mult;
2804 uint16_t *p = (uint16_t *)(out->data[plane] + y * out->linesize[plane]) + (x + i * 8);
2805 for (char_y = 0; char_y < font_height; char_y++) {
2806 for (mask = 0x80; mask; mask >>= 1) {
2807 if (font[txt[i] * font_height + char_y] & mask)
2808 p[0] = p[0] * o2 + (v - p[0]) * o1;
2811 p += out->linesize[plane] / 2 - 8;
2817 static void idraw_vtext(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
2819 const uint8_t *font;
2823 font = avpriv_cga_font, font_height = 8;
2825 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2826 for (i = 0; txt[i]; i++) {
2828 int v = color[plane];
2830 for (char_y = font_height - 1; char_y >= 0; char_y--) {
2831 uint8_t *p = out->data[plane] + (y + i * 10) * out->linesize[plane] + x;
2832 for (mask = 0x80; mask; mask >>= 1) {
2833 if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
2834 p[char_y] = p[char_y] * o2 + (v - p[char_y]) * o1;
2835 p += out->linesize[plane];
2842 static void idraw_vtext16(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
2844 const uint8_t *font;
2848 font = avpriv_cga_font, font_height = 8;
2850 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2851 for (i = 0; txt[i]; i++) {
2853 int v = color[plane] * mult;
2855 for (char_y = 0; char_y < font_height; char_y++) {
2856 uint16_t *p = (uint16_t *)(out->data[plane] + (y + i * 10) * out->linesize[plane]) + x;
2857 for (mask = 0x80; mask; mask >>= 1) {
2858 if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
2859 p[char_y] = p[char_y] * o2 + (v - p[char_y]) * o1;
2860 p += out->linesize[plane] / 2;
2867 static void graticule_none(WaveformContext *s, AVFrame *out)
2871 static void graticule_row(WaveformContext *s, AVFrame *out)
2873 const int step = (s->flags & 2) + 1;
2874 const float o1 = s->opacity;
2875 const float o2 = 1. - o1;
2876 const int height = s->display == PARADE ? out->height / s->acomp : out->height;
2877 int C, k = 0, c, p, l, offset_x = 0, offset_y = 0;
2879 for (c = 0; c < s->ncomp; c++) {
2880 if (!((1 << c) & s->pcomp) || (!s->display && k > 0))
2885 for (p = 0; p < s->ncomp; p++) {
2886 const int v = s->grat_yuva_color[p];
2887 for (l = 0; l < s->nb_glines; l++) {
2888 const uint16_t pos = s->glines[l].line[C].pos;
2889 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos);
2890 uint8_t *dst = out->data[p] + offset_y * out->linesize[p] + x;
2892 s->blend_line(dst, height, out->linesize[p], o1, o2, v, step);
2896 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2897 const char *name = s->glines[l].line[C].name;
2898 const uint16_t pos = s->glines[l].line[C].pos;
2899 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos) - 10;
2904 s->draw_text(out, x, offset_y + 2, 1, o1, o2, name, s->grat_yuva_color);
2907 offset_x += s->size * (s->display == STACK);
2908 offset_y += height * (s->display == PARADE);
2912 static void graticule16_row(WaveformContext *s, AVFrame *out)
2914 const int step = (s->flags & 2) + 1;
2915 const float o1 = s->opacity;
2916 const float o2 = 1. - o1;
2917 const int mult = s->max / 256;
2918 const int height = s->display == PARADE ? out->height / s->acomp : out->height;
2919 int C, k = 0, c, p, l, offset_x = 0, offset_y = 0;
2921 for (c = 0; c < s->ncomp; c++) {
2922 if (!((1 << c) & s->pcomp) || (!s->display && k > 0))
2927 for (p = 0; p < s->ncomp; p++) {
2928 const int v = s->grat_yuva_color[p] * mult;
2929 for (l = 0; l < s->nb_glines ; l++) {
2930 const uint16_t pos = s->glines[l].line[C].pos;
2931 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos);
2932 uint8_t *dst = (uint8_t *)(out->data[p] + offset_y * out->linesize[p]) + x * 2;
2934 s->blend_line(dst, height, out->linesize[p], o1, o2, v, step);
2938 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2939 const char *name = s->glines[l].line[C].name;
2940 const uint16_t pos = s->glines[l].line[C].pos;
2941 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos) - 10;
2946 s->draw_text(out, x, offset_y + 2, mult, o1, o2, name, s->grat_yuva_color);
2949 offset_x += s->size * (s->display == STACK);
2950 offset_y += height * (s->display == PARADE);
2954 static void graticule_column(WaveformContext *s, AVFrame *out)
2956 const int step = (s->flags & 2) + 1;
2957 const float o1 = s->opacity;
2958 const float o2 = 1. - o1;
2959 const int width = s->display == PARADE ? out->width / s->acomp : out->width;
2960 int C, k = 0, c, p, l, offset_y = 0, offset_x = 0;
2962 for (c = 0; c < s->ncomp; c++) {
2963 if ((!((1 << c) & s->pcomp) || (!s->display && k > 0)))
2968 for (p = 0; p < s->ncomp; p++) {
2969 const int v = s->grat_yuva_color[p];
2970 for (l = 0; l < s->nb_glines ; l++) {
2971 const uint16_t pos = s->glines[l].line[C].pos;
2972 int y = offset_y + (s->mirror ? s->size - 1 - pos : pos);
2973 uint8_t *dst = out->data[p] + y * out->linesize[p] + offset_x;
2975 s->blend_line(dst, width, 1, o1, o2, v, step);
2979 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2980 const char *name = s->glines[l].line[C].name;
2981 const uint16_t pos = s->glines[l].line[C].pos;
2982 int y = offset_y + (s->mirror ? s->size - 1 - pos : pos) - 10;
2987 s->draw_text(out, 2 + offset_x, y, 1, o1, o2, name, s->grat_yuva_color);
2990 offset_y += s->size * (s->display == STACK);
2991 offset_x += width * (s->display == PARADE);
2995 static void graticule16_column(WaveformContext *s, AVFrame *out)
2997 const int step = (s->flags & 2) + 1;
2998 const float o1 = s->opacity;
2999 const float o2 = 1. - o1;
3000 const int mult = s->max / 256;
3001 const int width = s->display == PARADE ? out->width / s->acomp : out->width;
3002 int C, k = 0, c, p, l, offset_x = 0, offset_y = 0;
3004 for (c = 0; c < s->ncomp; c++) {
3005 if ((!((1 << c) & s->pcomp) || (!s->display && k > 0)))
3010 for (p = 0; p < s->ncomp; p++) {
3011 const int v = s->grat_yuva_color[p] * mult;
3012 for (l = 0; l < s->nb_glines ; l++) {
3013 const uint16_t pos = s->glines[l].line[C].pos;
3014 int y = offset_y + (s->mirror ? s->size - 1 - pos : pos);
3015 uint8_t *dst = (uint8_t *)(out->data[p] + y * out->linesize[p]) + offset_x * 2;
3017 s->blend_line(dst, width, 1, o1, o2, v, step);
3021 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
3022 const char *name = s->glines[l].line[C].name;
3023 const uint16_t pos = s->glines[l].line[C].pos;
3024 int y = offset_y + (s->mirror ? s->size - 1 - pos: pos) - 10;
3029 s->draw_text(out, 2 + offset_x, y, mult, o1, o2, name, s->grat_yuva_color);
3032 offset_y += s->size * (s->display == STACK);
3033 offset_x += width * (s->display == PARADE);
3037 static int config_input(AVFilterLink *inlink)
3039 AVFilterContext *ctx = inlink->dst;
3040 WaveformContext *s = ctx->priv;
3042 s->desc = av_pix_fmt_desc_get(inlink->format);
3043 s->ncomp = s->desc->nb_components;
3044 s->bits = s->desc->comp[0].depth;
3045 s->max = 1 << s->bits;
3046 s->intensity = s->fintensity * (s->max - 1);
3048 s->shift_w[0] = s->shift_w[3] = 0;
3049 s->shift_h[0] = s->shift_h[3] = 0;
3050 s->shift_w[1] = s->shift_w[2] = s->desc->log2_chroma_w;
3051 s->shift_h[1] = s->shift_h[2] = s->desc->log2_chroma_h;
3053 s->graticulef = graticule_none;
3055 switch (s->filter) {
3058 case AFLAT: s->size = 256 * 2; break;
3059 case FLAT: s->size = 256 * 3; break;
3060 default: s->size = 256; break;
3063 switch (s->filter | ((s->bits > 8) << 4) |
3064 (s->mode << 8) | (s->mirror << 12)) {
3065 case 0x1100: s->waveform_slice = lowpass_column_mirror; break;
3066 case 0x1000: s->waveform_slice = lowpass_row_mirror; break;
3067 case 0x0100: s->waveform_slice = lowpass_column; break;
3068 case 0x0000: s->waveform_slice = lowpass_row; break;
3069 case 0x1110: s->waveform_slice = lowpass16_column_mirror; break;
3070 case 0x1010: s->waveform_slice = lowpass16_row_mirror; break;
3071 case 0x0110: s->waveform_slice = lowpass16_column; break;
3072 case 0x0010: s->waveform_slice = lowpass16_row; break;
3073 case 0x1101: s->waveform_slice = flat_column_mirror; break;
3074 case 0x1001: s->waveform_slice = flat_row_mirror; break;
3075 case 0x0101: s->waveform_slice = flat_column; break;
3076 case 0x0001: s->waveform_slice = flat_row; break;
3077 case 0x1111: s->waveform_slice = flat16_column_mirror; break;
3078 case 0x1011: s->waveform_slice = flat16_row_mirror; break;
3079 case 0x0111: s->waveform_slice = flat16_column; break;
3080 case 0x0011: s->waveform_slice = flat16_row; break;
3081 case 0x1102: s->waveform_slice = aflat_column_mirror; break;
3082 case 0x1002: s->waveform_slice = aflat_row_mirror; break;
3083 case 0x0102: s->waveform_slice = aflat_column; break;
3084 case 0x0002: s->waveform_slice = aflat_row; break;
3085 case 0x1112: s->waveform_slice = aflat16_column_mirror; break;
3086 case 0x1012: s->waveform_slice = aflat16_row_mirror; break;
3087 case 0x0112: s->waveform_slice = aflat16_column; break;
3088 case 0x0012: s->waveform_slice = aflat16_row; break;
3089 case 0x1103: s->waveform_slice = chroma_column_mirror; break;
3090 case 0x1003: s->waveform_slice = chroma_row_mirror; break;
3091 case 0x0103: s->waveform_slice = chroma_column; break;
3092 case 0x0003: s->waveform_slice = chroma_row; break;
3093 case 0x1113: s->waveform_slice = chroma16_column_mirror; break;
3094 case 0x1013: s->waveform_slice = chroma16_row_mirror; break;
3095 case 0x0113: s->waveform_slice = chroma16_column; break;
3096 case 0x0013: s->waveform_slice = chroma16_row; break;
3097 case 0x1104: s->waveform_slice = color_column_mirror; break;
3098 case 0x1004: s->waveform_slice = color_row_mirror; break;
3099 case 0x0104: s->waveform_slice = color_column; break;
3100 case 0x0004: s->waveform_slice = color_row; break;
3101 case 0x1114: s->waveform_slice = color16_column_mirror; break;
3102 case 0x1014: s->waveform_slice = color16_row_mirror; break;
3103 case 0x0114: s->waveform_slice = color16_column; break;
3104 case 0x0014: s->waveform_slice = color16_row; break;
3105 case 0x1105: s->waveform_slice = acolor_column_mirror; break;
3106 case 0x1005: s->waveform_slice = acolor_row_mirror; break;
3107 case 0x0105: s->waveform_slice = acolor_column; break;
3108 case 0x0005: s->waveform_slice = acolor_row; break;
3109 case 0x1115: s->waveform_slice = acolor16_column_mirror; break;
3110 case 0x1015: s->waveform_slice = acolor16_row_mirror; break;
3111 case 0x0115: s->waveform_slice = acolor16_column; break;
3112 case 0x0015: s->waveform_slice = acolor16_row; break;
3113 case 0x1106: s->waveform_slice = xflat_column_mirror; break;
3114 case 0x1006: s->waveform_slice = xflat_row_mirror; break;
3115 case 0x0106: s->waveform_slice = xflat_column; break;
3116 case 0x0006: s->waveform_slice = xflat_row; break;
3117 case 0x1116: s->waveform_slice = xflat16_column_mirror; break;
3118 case 0x1016: s->waveform_slice = xflat16_row_mirror; break;
3119 case 0x0116: s->waveform_slice = xflat16_column; break;
3120 case 0x0016: s->waveform_slice = xflat16_row; break;
3121 case 0x1107: s->waveform_slice = yflat_column_mirror; break;
3122 case 0x1007: s->waveform_slice = yflat_row_mirror; break;
3123 case 0x0107: s->waveform_slice = yflat_column; break;
3124 case 0x0007: s->waveform_slice = yflat_row; break;
3125 case 0x1117: s->waveform_slice = yflat16_column_mirror; break;
3126 case 0x1017: s->waveform_slice = yflat16_row_mirror; break;
3127 case 0x0117: s->waveform_slice = yflat16_column; break;
3128 case 0x0017: s->waveform_slice = yflat16_row; break;
3131 s->grat_yuva_color[0] = 255;
3132 s->grat_yuva_color[1] = s->graticule == GRAT_INVERT ? 255 : 0;
3133 s->grat_yuva_color[2] = s->graticule == GRAT_ORANGE || s->graticule == GRAT_INVERT ? 255 : 0;
3134 s->grat_yuva_color[3] = 255;
3136 if (s->mode == 0 && s->graticule != GRAT_INVERT) {
3137 s->blend_line = s->bits <= 8 ? blend_vline : blend_vline16;
3138 s->draw_text = s->bits <= 8 ? draw_vtext : draw_vtext16;
3139 } else if (s->graticule != GRAT_INVERT) {
3140 s->blend_line = s->bits <= 8 ? blend_hline : blend_hline16;
3141 s->draw_text = s->bits <= 8 ? draw_htext : draw_htext16;
3142 } else if (s->mode == 0 && s->graticule == GRAT_INVERT) {
3143 s->blend_line = s->bits <= 8 ? iblend_vline : iblend_vline16;
3144 s->draw_text = s->bits <= 8 ? idraw_vtext : idraw_vtext16;
3145 } else if (s->graticule == GRAT_INVERT) {
3146 s->blend_line = s->bits <= 8 ? iblend_hline : iblend_hline16;
3147 s->draw_text = s->bits <= 8 ? idraw_htext : idraw_htext16;
3150 switch (s->filter) {
3159 if (s->graticule > GRAT_NONE && s->mode == 1)
3160 s->graticulef = s->bits > 8 ? graticule16_column : graticule_column;
3161 else if (s->graticule > GRAT_NONE && s->mode == 0)
3162 s->graticulef = s->bits > 8 ? graticule16_row : graticule_row;
3166 switch (s->filter) {
3173 case 8: s->glines = (GraticuleLines *)digital8; s->nb_glines = FF_ARRAY_ELEMS(digital8); break;
3174 case 9: s->glines = (GraticuleLines *)digital9; s->nb_glines = FF_ARRAY_ELEMS(digital9); break;
3175 case 10: s->glines = (GraticuleLines *)digital10; s->nb_glines = FF_ARRAY_ELEMS(digital10); break;
3176 case 12: s->glines = (GraticuleLines *)digital12; s->nb_glines = FF_ARRAY_ELEMS(digital12); break;
3181 case 8: s->glines = (GraticuleLines *)millivolts8; s->nb_glines = FF_ARRAY_ELEMS(millivolts8); break;
3182 case 9: s->glines = (GraticuleLines *)millivolts9; s->nb_glines = FF_ARRAY_ELEMS(millivolts9); break;
3183 case 10: s->glines = (GraticuleLines *)millivolts10; s->nb_glines = FF_ARRAY_ELEMS(millivolts10); break;
3184 case 12: s->glines = (GraticuleLines *)millivolts12; s->nb_glines = FF_ARRAY_ELEMS(millivolts12); break;
3189 case 8: s->glines = (GraticuleLines *)ire8; s->nb_glines = FF_ARRAY_ELEMS(ire8); break;
3190 case 9: s->glines = (GraticuleLines *)ire9; s->nb_glines = FF_ARRAY_ELEMS(ire9); break;
3191 case 10: s->glines = (GraticuleLines *)ire10; s->nb_glines = FF_ARRAY_ELEMS(ire10); break;
3192 case 12: s->glines = (GraticuleLines *)ire12; s->nb_glines = FF_ARRAY_ELEMS(ire12); break;
3201 case 8: s->glines = (GraticuleLines *)chroma_digital8; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital8); break;
3202 case 9: s->glines = (GraticuleLines *)chroma_digital9; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital9); break;
3203 case 10: s->glines = (GraticuleLines *)chroma_digital10; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital10); break;
3204 case 12: s->glines = (GraticuleLines *)chroma_digital12; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital12); break;
3209 case 8: s->glines = (GraticuleLines *)millivolts8; s->nb_glines = FF_ARRAY_ELEMS(millivolts8); break;
3210 case 9: s->glines = (GraticuleLines *)millivolts9; s->nb_glines = FF_ARRAY_ELEMS(millivolts9); break;
3211 case 10: s->glines = (GraticuleLines *)millivolts10; s->nb_glines = FF_ARRAY_ELEMS(millivolts10); break;
3212 case 12: s->glines = (GraticuleLines *)millivolts12; s->nb_glines = FF_ARRAY_ELEMS(millivolts12); break;
3217 case 8: s->glines = (GraticuleLines *)ire8; s->nb_glines = FF_ARRAY_ELEMS(ire8); break;
3218 case 9: s->glines = (GraticuleLines *)ire9; s->nb_glines = FF_ARRAY_ELEMS(ire9); break;
3219 case 10: s->glines = (GraticuleLines *)ire10; s->nb_glines = FF_ARRAY_ELEMS(ire10); break;
3220 case 12: s->glines = (GraticuleLines *)ire12; s->nb_glines = FF_ARRAY_ELEMS(ire12); break;
3231 case 8: s->glines = (GraticuleLines *)aflat_digital8; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital8); break;
3232 case 9: s->glines = (GraticuleLines *)aflat_digital9; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital9); break;
3233 case 10: s->glines = (GraticuleLines *)aflat_digital10; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital10); break;
3234 case 12: s->glines = (GraticuleLines *)aflat_digital12; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital12); break;
3239 case 8: s->glines = (GraticuleLines *)aflat_millivolts8; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts8); break;
3240 case 9: s->glines = (GraticuleLines *)aflat_millivolts9; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts9); break;
3241 case 10: s->glines = (GraticuleLines *)aflat_millivolts10; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts10); break;
3242 case 12: s->glines = (GraticuleLines *)aflat_millivolts12; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts12); break;
3247 case 8: s->glines = (GraticuleLines *)aflat_ire8; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire8); break;
3248 case 9: s->glines = (GraticuleLines *)aflat_ire9; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire9); break;
3249 case 10: s->glines = (GraticuleLines *)aflat_ire10; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire10); break;
3250 case 12: s->glines = (GraticuleLines *)aflat_ire12; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire12); break;
3259 case 8: s->glines = (GraticuleLines *)flat_digital8; s->nb_glines = FF_ARRAY_ELEMS(flat_digital8); break;
3260 case 9: s->glines = (GraticuleLines *)flat_digital9; s->nb_glines = FF_ARRAY_ELEMS(flat_digital9); break;
3261 case 10: s->glines = (GraticuleLines *)flat_digital10; s->nb_glines = FF_ARRAY_ELEMS(flat_digital10); break;
3262 case 12: s->glines = (GraticuleLines *)flat_digital12; s->nb_glines = FF_ARRAY_ELEMS(flat_digital12); break;
3267 case 8: s->glines = (GraticuleLines *)flat_millivolts8; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts8); break;
3268 case 9: s->glines = (GraticuleLines *)flat_millivolts9; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts9); break;
3269 case 10: s->glines = (GraticuleLines *)flat_millivolts10; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts10); break;
3270 case 12: s->glines = (GraticuleLines *)flat_millivolts12; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts12); break;
3275 case 8: s->glines = (GraticuleLines *)flat_ire8; s->nb_glines = FF_ARRAY_ELEMS(flat_ire8); break;
3276 case 9: s->glines = (GraticuleLines *)flat_ire9; s->nb_glines = FF_ARRAY_ELEMS(flat_ire9); break;
3277 case 10: s->glines = (GraticuleLines *)flat_ire10; s->nb_glines = FF_ARRAY_ELEMS(flat_ire10); break;
3278 case 12: s->glines = (GraticuleLines *)flat_ire12; s->nb_glines = FF_ARRAY_ELEMS(flat_ire12); break;
3285 s->size = s->size << (s->bits - 8);
3287 s->tint[0] = .5f * (s->ftint[0] + 1.f) * (s->size - 1);
3288 s->tint[1] = .5f * (s->ftint[1] + 1.f) * (s->size - 1);
3290 switch (inlink->format) {
3291 case AV_PIX_FMT_GBRAP:
3292 case AV_PIX_FMT_GBRP:
3293 case AV_PIX_FMT_GBRP9:
3294 case AV_PIX_FMT_GBRP10:
3295 case AV_PIX_FMT_GBRP12:
3297 memcpy(s->bg_color, black_gbrp_color, sizeof(s->bg_color));
3300 memcpy(s->bg_color, black_yuva_color, sizeof(s->bg_color));
3303 s->bg_color[3] *= s->bgopacity;
3308 static int config_output(AVFilterLink *outlink)
3310 AVFilterContext *ctx = outlink->src;
3311 AVFilterLink *inlink = ctx->inputs[0];
3312 WaveformContext *s = ctx->priv;
3313 int comp = 0, i, j = 0, k, p, size;
3315 for (i = 0; i < s->ncomp; i++) {
3316 if ((1 << i) & s->pcomp)
3321 return AVERROR(EINVAL);
3323 s->odesc = av_pix_fmt_desc_get(outlink->format);
3324 s->dcomp = s->odesc->nb_components;
3329 outlink->h = s->size * FFMAX(comp * (s->display == STACK), 1);
3330 outlink->w = inlink->w * FFMAX(comp * (s->display == PARADE), 1);
3333 outlink->w = s->size * FFMAX(comp * (s->display == STACK), 1);
3334 outlink->h = inlink->h * FFMAX(comp * (s->display == PARADE), 1);
3338 s->peak = av_malloc_array(size, 32 * sizeof(*s->peak));
3340 return AVERROR(ENOMEM);
3342 for (p = 0; p < s->ncomp; p++) {
3343 const int plane = s->desc->comp[p].plane;
3346 if (!((1 << p) & s->pcomp))
3349 for (k = 0; k < 4; k++) {
3350 s->emax[plane][k] = s->peak + size * (plane * 4 + k + 0);
3351 s->emin[plane][k] = s->peak + size * (plane * 4 + k + 16);
3354 offset = j++ * s->size * (s->display == STACK);
3355 s->estart[plane] = offset;
3356 s->eend[plane] = (offset + s->size - 1);
3357 for (i = 0; i < size; i++) {
3358 for (k = 0; k < 4; k++) {
3359 s->emax[plane][k][i] = s->estart[plane];
3360 s->emin[plane][k][i] = s->eend[plane];
3365 outlink->sample_aspect_ratio = (AVRational){1,1};
3370 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
3372 AVFilterContext *ctx = inlink->dst;
3373 WaveformContext *s = ctx->priv;
3374 AVFilterLink *outlink = ctx->outputs[0];
3378 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
3381 return AVERROR(ENOMEM);
3384 out->color_range = AVCOL_RANGE_JPEG;
3386 for (k = 0; k < s->dcomp; k++) {
3388 for (i = 0; i < outlink->h ; i++)
3389 memset(out->data[s->odesc->comp[k].plane] +
3390 i * out->linesize[s->odesc->comp[k].plane],
3391 s->bg_color[k], outlink->w);
3393 const int mult = s->max / 256;
3394 uint16_t *dst = (uint16_t *)out->data[s->odesc->comp[k].plane];
3396 for (i = 0; i < outlink->h ; i++) {
3397 for (j = 0; j < outlink->w; j++)
3398 dst[j] = s->bg_color[k] * mult;
3399 dst += out->linesize[s->odesc->comp[k].plane] / 2;
3404 for (k = 0, i = 0; k < s->ncomp; k++) {
3405 if ((1 << k) & s->pcomp) {
3406 const int plane = s->desc->comp[k].plane;
3411 if (s->display == PARADE) {
3412 offset_x = s->mode ? i++ * inlink->w : 0;
3413 offset_y = s->mode ? 0 : i++ * inlink->h;
3415 offset_y = s->mode ? i++ * s->size * !!s->display : 0;
3416 offset_x = s->mode ? 0 : i++ * s->size * !!s->display;
3422 td.offset_y = offset_y;
3423 td.offset_x = offset_x;
3424 ctx->internal->execute(ctx, s->waveform_slice, &td, NULL, ff_filter_get_nb_threads(ctx));
3425 switch (s->filter) {
3428 envelope(s, out, plane, s->rgb || s->display == OVERLAY ? plane : 0, s->mode ? offset_x : offset_y);
3430 envelope16(s, out, plane, s->rgb || s->display == OVERLAY ? plane : 0, s->mode ? offset_x : offset_y);
3436 envelope(s, out, plane, plane, s->mode ? offset_x : offset_y);
3438 envelope16(s, out, plane, plane, s->mode ? offset_x : offset_y);
3442 envelope(s, out, plane, plane, s->mode ? offset_x : offset_y);
3443 envelope(s, out, plane, (plane + 1) % s->ncomp, s->mode ? offset_x : offset_y);
3445 envelope16(s, out, plane, plane, s->mode ? offset_x : offset_y);
3446 envelope16(s, out, plane, (plane + 1) % s->ncomp, s->mode ? offset_x : offset_y);
3453 envelope(s, out, plane, (plane + 0) % s->ncomp, s->mode ? offset_x : offset_y);
3454 envelope(s, out, plane, (plane + 1) % s->ncomp, s->mode ? offset_x : offset_y);
3455 envelope(s, out, plane, (plane + 2) % s->ncomp, s->mode ? offset_x : offset_y);
3457 envelope16(s, out, plane, (plane + 0) % s->ncomp, s->mode ? offset_x : offset_y);
3458 envelope16(s, out, plane, (plane + 1) % s->ncomp, s->mode ? offset_x : offset_y);
3459 envelope16(s, out, plane, (plane + 2) % s->ncomp, s->mode ? offset_x : offset_y);
3465 s->graticulef(s, out);
3468 return ff_filter_frame(outlink, out);
3471 static av_cold void uninit(AVFilterContext *ctx)
3473 WaveformContext *s = ctx->priv;
3478 static const AVFilterPad inputs[] = {
3481 .type = AVMEDIA_TYPE_VIDEO,
3482 .filter_frame = filter_frame,
3483 .config_props = config_input,
3488 static const AVFilterPad outputs[] = {
3491 .type = AVMEDIA_TYPE_VIDEO,
3492 .config_props = config_output,
3497 AVFilter ff_vf_waveform = {
3499 .description = NULL_IF_CONFIG_SMALL("Video waveform monitor."),
3500 .priv_size = sizeof(WaveformContext),
3501 .priv_class = &waveform_class,
3502 .query_formats = query_formats,
3506 .flags = AVFILTER_FLAG_SLICE_THREADS,