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"
57 typedef struct GraticuleLine {
62 typedef struct GraticuleLines {
63 struct GraticuleLine line[4];
66 typedef struct WaveformContext {
93 uint8_t grat_yuva_color[4];
94 int shift_w[4], shift_h[4];
95 GraticuleLines *glines;
97 void (*waveform)(struct WaveformContext *s,
98 AVFrame *in, AVFrame *out,
99 int component, int intensity,
100 int offset_y, int offset_x,
101 int column, int mirror);
102 void (*graticulef)(struct WaveformContext *s, AVFrame *out);
103 const AVPixFmtDescriptor *desc;
104 const AVPixFmtDescriptor *odesc;
107 #define OFFSET(x) offsetof(WaveformContext, x)
108 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
110 static const AVOption waveform_options[] = {
111 { "mode", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "mode" },
112 { "m", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "mode" },
113 { "row", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "mode" },
114 { "column", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "mode" },
115 { "intensity", "set intensity", OFFSET(fintensity), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 1, FLAGS },
116 { "i", "set intensity", OFFSET(fintensity), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 1, FLAGS },
117 { "mirror", "set mirroring", OFFSET(mirror), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
118 { "r", "set mirroring", OFFSET(mirror), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
119 { "display", "set display mode", OFFSET(display), AV_OPT_TYPE_INT, {.i64=STACK}, 0, NB_DISPLAYS-1, FLAGS, "display" },
120 { "d", "set display mode", OFFSET(display), AV_OPT_TYPE_INT, {.i64=STACK}, 0, NB_DISPLAYS-1, FLAGS, "display" },
121 { "overlay", NULL, 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY}, 0, 0, FLAGS, "display" },
122 { "stack", NULL, 0, AV_OPT_TYPE_CONST, {.i64=STACK}, 0, 0, FLAGS, "display" },
123 { "parade", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PARADE}, 0, 0, FLAGS, "display" },
124 { "components", "set components to display", OFFSET(pcomp), AV_OPT_TYPE_INT, {.i64=1}, 1, 15, FLAGS },
125 { "c", "set components to display", OFFSET(pcomp), AV_OPT_TYPE_INT, {.i64=1}, 1, 15, FLAGS },
126 { "envelope", "set envelope to display", OFFSET(envelope), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "envelope" },
127 { "e", "set envelope to display", OFFSET(envelope), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "envelope" },
128 { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "envelope" },
129 { "instant", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "envelope" },
130 { "peak", NULL, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "envelope" },
131 { "peak+instant", NULL, 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, FLAGS, "envelope" },
132 { "filter", "set filter", OFFSET(filter), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_FILTERS-1, FLAGS, "filter" },
133 { "f", "set filter", OFFSET(filter), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_FILTERS-1, FLAGS, "filter" },
134 { "lowpass", NULL, 0, AV_OPT_TYPE_CONST, {.i64=LOWPASS}, 0, 0, FLAGS, "filter" },
135 { "flat" , NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAT}, 0, 0, FLAGS, "filter" },
136 { "aflat" , NULL, 0, AV_OPT_TYPE_CONST, {.i64=AFLAT}, 0, 0, FLAGS, "filter" },
137 { "chroma", NULL, 0, AV_OPT_TYPE_CONST, {.i64=CHROMA}, 0, 0, FLAGS, "filter" },
138 { "color", NULL, 0, AV_OPT_TYPE_CONST, {.i64=COLOR}, 0, 0, FLAGS, "filter" },
139 { "acolor", NULL, 0, AV_OPT_TYPE_CONST, {.i64=ACOLOR}, 0, 0, FLAGS, "filter" },
140 { "xflat", NULL, 0, AV_OPT_TYPE_CONST, {.i64=XFLAT}, 0, 0, FLAGS, "filter" },
141 { "graticule", "set graticule", OFFSET(graticule), AV_OPT_TYPE_INT, {.i64=0}, 0, 2, FLAGS, "graticule" },
142 { "g", "set graticule", OFFSET(graticule), AV_OPT_TYPE_INT, {.i64=0}, 0, 2, FLAGS, "graticule" },
143 { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "graticule" },
144 { "green", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "graticule" },
145 { "orange", NULL, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "graticule" },
146 { "opacity", "set graticule opacity", OFFSET(opacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
147 { "o", "set graticule opacity", OFFSET(opacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
148 { "flags", "set graticule flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64=1}, 0, 3, FLAGS, "flags" },
149 { "fl", "set graticule flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64=1}, 0, 3, FLAGS, "flags" },
150 { "numbers", "draw numbers", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "flags" },
151 { "dots", "draw dots instead of lines", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "flags" },
152 { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SCALES-1, FLAGS, "scale" },
153 { "s", "set scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SCALES-1, FLAGS, "scale" },
154 { "digital", NULL, 0, AV_OPT_TYPE_CONST, {.i64=DIGITAL}, 0, 0, FLAGS, "scale" },
155 { "millivolts", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MILLIVOLTS}, 0, 0, FLAGS, "scale" },
156 { "ire", NULL, 0, AV_OPT_TYPE_CONST, {.i64=IRE}, 0, 0, FLAGS, "scale" },
157 { "bgopacity", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
158 { "b", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
162 AVFILTER_DEFINE_CLASS(waveform);
164 static const enum AVPixelFormat in_lowpass_pix_fmts[] = {
165 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
166 AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12,
167 AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
168 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
169 AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P,
170 AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
171 AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
172 AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
173 AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY9, AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12,
174 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9,
175 AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9,
176 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10,
177 AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10,
178 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV440P12,
182 static const enum AVPixelFormat in_color_pix_fmts[] = {
183 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
184 AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12,
185 AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
186 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
188 AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
189 AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
190 AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
191 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9,
192 AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9,
193 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10,
194 AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10,
195 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV440P12,
199 static const enum AVPixelFormat in_flat_pix_fmts[] = {
200 AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
201 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
203 AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
204 AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
205 AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
206 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9,
207 AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9,
208 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10,
209 AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10,
210 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV440P12,
214 static const enum AVPixelFormat out_rgb8_lowpass_pix_fmts[] = {
215 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
219 static const enum AVPixelFormat out_rgb9_lowpass_pix_fmts[] = {
224 static const enum AVPixelFormat out_rgb10_lowpass_pix_fmts[] = {
225 AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10,
229 static const enum AVPixelFormat out_rgb12_lowpass_pix_fmts[] = {
230 AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12,
234 static const enum AVPixelFormat out_yuv8_lowpass_pix_fmts[] = {
235 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVA444P,
239 static const enum AVPixelFormat out_yuv9_lowpass_pix_fmts[] = {
240 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUVA444P9,
244 static const enum AVPixelFormat out_yuv10_lowpass_pix_fmts[] = {
245 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUVA444P10,
249 static const enum AVPixelFormat out_yuv12_lowpass_pix_fmts[] = {
250 AV_PIX_FMT_YUV444P12,
254 static const enum AVPixelFormat out_gray8_lowpass_pix_fmts[] = {
259 static const enum AVPixelFormat out_gray9_lowpass_pix_fmts[] = {
264 static const enum AVPixelFormat out_gray10_lowpass_pix_fmts[] = {
269 static const enum AVPixelFormat out_gray12_lowpass_pix_fmts[] = {
274 static const enum AVPixelFormat flat_pix_fmts[] = {
275 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P,
276 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV444P10,
277 AV_PIX_FMT_YUV444P12,
281 static int query_formats(AVFilterContext *ctx)
283 WaveformContext *s = ctx->priv;
284 const enum AVPixelFormat *out_pix_fmts;
285 const enum AVPixelFormat *in_pix_fmts;
286 const AVPixFmtDescriptor *desc;
287 AVFilterFormats *avff;
288 int depth, rgb, i, ret, ncomp;
290 if (!ctx->inputs[0]->in_formats ||
291 !ctx->inputs[0]->in_formats->nb_formats) {
292 return AVERROR(EAGAIN);
296 case LOWPASS: in_pix_fmts = in_lowpass_pix_fmts; break;
300 case FLAT: in_pix_fmts = in_flat_pix_fmts; break;
302 case COLOR: in_pix_fmts = in_color_pix_fmts; break;
303 default: return AVERROR_BUG;
306 if (!ctx->inputs[0]->out_formats) {
307 if ((ret = ff_formats_ref(ff_make_format_list(in_pix_fmts), &ctx->inputs[0]->out_formats)) < 0)
311 avff = ctx->inputs[0]->in_formats;
312 desc = av_pix_fmt_desc_get(avff->formats[0]);
313 ncomp = desc->nb_components;
314 rgb = desc->flags & AV_PIX_FMT_FLAG_RGB;
315 depth = desc->comp[0].depth;
316 for (i = 1; i < avff->nb_formats; i++) {
317 desc = av_pix_fmt_desc_get(avff->formats[i]);
318 if (rgb != (desc->flags & AV_PIX_FMT_FLAG_RGB) ||
319 depth != desc->comp[0].depth)
320 return AVERROR(EAGAIN);
323 if (s->filter == LOWPASS && ncomp == 1 && depth == 8)
324 out_pix_fmts = out_gray8_lowpass_pix_fmts;
325 else if (s->filter == LOWPASS && ncomp == 1 && depth == 9)
326 out_pix_fmts = out_gray9_lowpass_pix_fmts;
327 else if (s->filter == LOWPASS && ncomp == 1 && depth == 10)
328 out_pix_fmts = out_gray10_lowpass_pix_fmts;
329 else if (s->filter == LOWPASS && ncomp == 1 && depth == 12)
330 out_pix_fmts = out_gray12_lowpass_pix_fmts;
331 else if (rgb && depth == 8 && ncomp > 2)
332 out_pix_fmts = out_rgb8_lowpass_pix_fmts;
333 else if (rgb && depth == 9 && ncomp > 2)
334 out_pix_fmts = out_rgb9_lowpass_pix_fmts;
335 else if (rgb && depth == 10 && ncomp > 2)
336 out_pix_fmts = out_rgb10_lowpass_pix_fmts;
337 else if (rgb && depth == 12 && ncomp > 2)
338 out_pix_fmts = out_rgb12_lowpass_pix_fmts;
339 else if (depth == 8 && ncomp > 2)
340 out_pix_fmts = out_yuv8_lowpass_pix_fmts;
341 else if (depth == 9 && ncomp > 2)
342 out_pix_fmts = out_yuv9_lowpass_pix_fmts;
343 else if (depth == 10 && ncomp > 2)
344 out_pix_fmts = out_yuv10_lowpass_pix_fmts;
345 else if (depth == 12 && ncomp > 2)
346 out_pix_fmts = out_yuv12_lowpass_pix_fmts;
348 return AVERROR(EAGAIN);
349 if ((ret = ff_formats_ref(ff_make_format_list(out_pix_fmts), &ctx->outputs[0]->in_formats)) < 0)
355 static void envelope_instant16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
357 const int dst_linesize = out->linesize[component] / 2;
358 const int bg = s->bg_color[component] * (s->max / 256);
359 const int limit = s->max - 1;
360 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
361 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
362 const int start = s->estart[plane];
363 const int end = s->eend[plane];
368 for (x = offset; x < offset + dst_w; x++) {
369 for (y = start; y < end; y++) {
370 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
376 for (y = end - 1; y >= start; y--) {
377 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
385 for (y = offset; y < offset + dst_h; y++) {
386 dst = (uint16_t *)out->data[component] + y * dst_linesize;
387 for (x = start; x < end; x++) {
393 for (x = end - 1; x >= start; x--) {
403 static void envelope_instant(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
405 const int dst_linesize = out->linesize[component];
406 const uint8_t bg = s->bg_color[component];
407 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
408 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
409 const int start = s->estart[plane];
410 const int end = s->eend[plane];
415 for (x = offset; x < offset + dst_w; x++) {
416 for (y = start; y < end; y++) {
417 dst = out->data[component] + y * dst_linesize + x;
423 for (y = end - 1; y >= start; y--) {
424 dst = out->data[component] + y * dst_linesize + x;
432 for (y = offset; y < offset + dst_h; y++) {
433 dst = out->data[component] + y * dst_linesize;
434 for (x = start; x < end; x++) {
440 for (x = end - 1; x >= start; x--) {
450 static void envelope_peak16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
452 const int dst_linesize = out->linesize[component] / 2;
453 const int bg = s->bg_color[component] * (s->max / 256);
454 const int limit = s->max - 1;
455 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
456 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
457 const int start = s->estart[plane];
458 const int end = s->eend[plane];
459 int *emax = s->emax[plane][component];
460 int *emin = s->emin[plane][component];
465 for (x = offset; x < offset + dst_w; x++) {
466 for (y = start; y < end && y < emin[x - offset]; y++) {
467 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
469 emin[x - offset] = y;
473 for (y = end - 1; y >= start && y >= emax[x - offset]; y--) {
474 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
476 emax[x - offset] = y;
482 if (s->envelope == 3)
483 envelope_instant16(s, out, plane, component, offset);
485 for (x = offset; x < offset + dst_w; x++) {
486 dst = (uint16_t *)out->data[component] + emin[x - offset] * dst_linesize + x;
488 dst = (uint16_t *)out->data[component] + emax[x - offset] * dst_linesize + x;
492 for (y = offset; y < offset + dst_h; y++) {
493 dst = (uint16_t *)out->data[component] + y * dst_linesize;
494 for (x = start; x < end && x < emin[y - offset]; x++) {
496 emin[y - offset] = x;
500 for (x = end - 1; x >= start && x >= emax[y - offset]; x--) {
502 emax[y - offset] = x;
508 if (s->envelope == 3)
509 envelope_instant16(s, out, plane, component, offset);
511 for (y = offset; y < offset + dst_h; y++) {
512 dst = (uint16_t *)out->data[component] + y * dst_linesize + emin[y - offset];
514 dst = (uint16_t *)out->data[component] + y * dst_linesize + emax[y - offset];
520 static void envelope_peak(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
522 const int dst_linesize = out->linesize[component];
523 const int bg = s->bg_color[component];
524 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
525 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
526 const int start = s->estart[plane];
527 const int end = s->eend[plane];
528 int *emax = s->emax[plane][component];
529 int *emin = s->emin[plane][component];
534 for (x = offset; x < offset + dst_w; x++) {
535 for (y = start; y < end && y < emin[x - offset]; y++) {
536 dst = out->data[component] + y * dst_linesize + x;
538 emin[x - offset] = y;
542 for (y = end - 1; y >= start && y >= emax[x - offset]; y--) {
543 dst = out->data[component] + y * dst_linesize + x;
545 emax[x - offset] = y;
551 if (s->envelope == 3)
552 envelope_instant(s, out, plane, component, offset);
554 for (x = offset; x < offset + dst_w; x++) {
555 dst = out->data[component] + emin[x - offset] * dst_linesize + x;
557 dst = out->data[component] + emax[x - offset] * dst_linesize + x;
561 for (y = offset; y < offset + dst_h; y++) {
562 dst = out->data[component] + y * dst_linesize;
563 for (x = start; x < end && x < emin[y - offset]; x++) {
565 emin[y - offset] = x;
569 for (x = end - 1; x >= start && x >= emax[y - offset]; x--) {
571 emax[y - offset] = x;
577 if (s->envelope == 3)
578 envelope_instant(s, out, plane, component, offset);
580 for (y = offset; y < offset + dst_h; y++) {
581 dst = out->data[component] + y * dst_linesize + emin[y - offset];
583 dst = out->data[component] + y * dst_linesize + emax[y - offset];
589 static void envelope16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
591 if (s->envelope == 0) {
593 } else if (s->envelope == 1) {
594 envelope_instant16(s, out, plane, component, offset);
596 envelope_peak16(s, out, plane, component, offset);
600 static void envelope(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
602 if (s->envelope == 0) {
604 } else if (s->envelope == 1) {
605 envelope_instant(s, out, plane, component, offset);
607 envelope_peak(s, out, plane, component, offset);
611 static void update16(uint16_t *target, int max, int intensity, int limit)
614 *target += intensity;
619 static void update(uint8_t *target, int max, int intensity)
622 *target += intensity;
627 static void update_cr(uint8_t *target, int unused, int intensity)
629 if (*target - intensity > 0)
630 *target -= intensity;
635 static void update16_cr(uint16_t *target, int unused, int intensity, int limit)
637 if (*target - intensity > 0)
638 *target -= intensity;
643 static av_always_inline void lowpass16(WaveformContext *s,
644 AVFrame *in, AVFrame *out,
645 int component, int intensity,
646 int offset_y, int offset_x,
647 int column, int mirror)
649 const int plane = s->desc->comp[component].plane;
650 const int shift_w = s->shift_w[component];
651 const int shift_h = s->shift_h[component];
652 const int src_linesize = in->linesize[plane] / 2;
653 const int dst_linesize = out->linesize[plane] / 2;
654 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
655 const int limit = s->max - 1;
656 const int max = limit - intensity;
657 const int src_h = AV_CEIL_RSHIFT(in->height, shift_h);
658 const int src_w = AV_CEIL_RSHIFT(in->width, shift_w);
659 const uint16_t *src_data = (const uint16_t *)in->data[plane];
660 uint16_t *dst_data = (uint16_t *)out->data[plane] + offset_y * dst_linesize + offset_x;
661 uint16_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
662 uint16_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
663 const int step = column ? 1 << shift_w : 1 << shift_h;
667 if (!column && mirror)
670 for (y = 0; y < src_h; y++) {
671 const uint16_t *src_data_end = src_data + src_w;
672 uint16_t *dst = dst_line;
674 for (p = src_data; p < src_data_end; p++) {
676 int i = 0, v = FFMIN(*p, limit);
680 target = dst++ + dst_signed_linesize * v;
681 update16(target, max, intensity, limit);
682 } while (++i < step);
684 uint16_t *row = dst_data;
687 target = row - v - 1;
690 update16(target, max, intensity, limit);
692 } while (++i < step);
695 src_data += src_linesize;
696 dst_data += dst_linesize * step;
699 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
702 #define LOWPASS16_FUNC(name, column, mirror) \
703 static void lowpass16_##name(WaveformContext *s, \
704 AVFrame *in, AVFrame *out, \
705 int component, int intensity, \
706 int offset_y, int offset_x, \
707 int unused1, int unused2) \
709 lowpass16(s, in, out, component, intensity, \
710 offset_y, offset_x, column, mirror); \
713 LOWPASS16_FUNC(column_mirror, 1, 1)
714 LOWPASS16_FUNC(column, 1, 0)
715 LOWPASS16_FUNC(row_mirror, 0, 1)
716 LOWPASS16_FUNC(row, 0, 0)
718 static av_always_inline void lowpass(WaveformContext *s,
719 AVFrame *in, AVFrame *out,
720 int component, int intensity,
721 int offset_y, int offset_x,
722 int column, int mirror)
724 const int plane = s->desc->comp[component].plane;
725 const int shift_w = s->shift_w[component];
726 const int shift_h = s->shift_h[component];
727 const int src_linesize = in->linesize[plane];
728 const int dst_linesize = out->linesize[plane];
729 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
730 const int max = 255 - intensity;
731 const int src_h = AV_CEIL_RSHIFT(in->height, shift_h);
732 const int src_w = AV_CEIL_RSHIFT(in->width, shift_w);
733 const uint8_t *src_data = in->data[plane];
734 uint8_t *dst_data = out->data[plane] + offset_y * dst_linesize + offset_x;
735 uint8_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
736 uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
737 const int step = column ? 1 << shift_w : 1 << shift_h;
741 if (!column && mirror)
744 for (y = 0; y < src_h; y++) {
745 const uint8_t *src_data_end = src_data + src_w;
746 uint8_t *dst = dst_line;
748 for (p = src_data; p < src_data_end; p++) {
751 target = dst + dst_signed_linesize * *p;
753 update(target, max, intensity);
755 uint8_t *row = dst_data;
757 target = row - *p - 1;
760 update(target, max, intensity);
764 src_data += src_linesize;
765 dst_data += dst_linesize * step;
768 if (column && step > 1) {
769 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
770 const int dst_h = 256;
774 dst = out->data[plane] + offset_y * dst_linesize + offset_x;
775 for (y = 0; y < dst_h; y++) {
776 for (x = 0; x < dst_w; x+=step) {
777 for (z = 1; z < step; z++) {
783 } else if (step > 1) {
784 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
785 const int dst_w = 256;
789 dst = out->data[plane] + offset_y * dst_linesize + offset_x;
790 for (y = 0; y < dst_h; y+=step) {
791 for (z = 1; z < step; z++)
792 memcpy(dst + dst_linesize * z, dst, dst_w);
793 dst += dst_linesize * step;
797 envelope(s, out, plane, plane, column ? offset_x : offset_y);
800 #define LOWPASS_FUNC(name, column, mirror) \
801 static void lowpass_##name(WaveformContext *s, \
802 AVFrame *in, AVFrame *out, \
803 int component, int intensity, \
804 int offset_y, int offset_x, \
805 int unused1, int unused2) \
807 lowpass(s, in, out, component, intensity, \
808 offset_y, offset_x, column, mirror); \
811 LOWPASS_FUNC(column_mirror, 1, 1)
812 LOWPASS_FUNC(column, 1, 0)
813 LOWPASS_FUNC(row_mirror, 0, 1)
814 LOWPASS_FUNC(row, 0, 0)
816 static av_always_inline void flat16(WaveformContext *s,
817 AVFrame *in, AVFrame *out,
818 int component, int intensity,
819 int offset_y, int offset_x,
820 int column, int mirror)
822 const int plane = s->desc->comp[component].plane;
823 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
824 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
825 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
826 const int c0_shift_w = s->shift_w[ component + 0 ];
827 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
828 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
829 const int c0_shift_h = s->shift_h[ component + 0 ];
830 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
831 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
832 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
833 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
834 const int limit = s->max - 1;
835 const int max = limit - intensity;
836 const int mid = s->max / 2;
837 const int src_h = in->height;
838 const int src_w = in->width;
842 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
843 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
845 for (x = 0; x < src_w; x++) {
846 const uint16_t *c0_data = (uint16_t *)in->data[plane + 0];
847 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
848 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
849 uint16_t *d0_data = (uint16_t *)(out->data[plane]) + offset_y * d0_linesize + offset_x;
850 uint16_t *d1_data = (uint16_t *)(out->data[(plane + 1) % s->ncomp]) + offset_y * d1_linesize + offset_x;
851 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
852 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
853 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
854 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
856 for (y = 0; y < src_h; y++) {
857 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + s->max;
858 const int c1 = FFMIN(FFABS(c1_data[x >> c1_shift_w] - mid) + FFABS(c2_data[x >> c2_shift_w] - mid), limit);
861 target = d0 + x + d0_signed_linesize * c0;
862 update16(target, max, intensity, limit);
863 target = d1 + x + d1_signed_linesize * (c0 - c1);
864 update16(target, max, intensity, limit);
865 target = d1 + x + d1_signed_linesize * (c0 + c1);
866 update16(target, max, intensity, limit);
868 if (!c0_shift_h || (y & c0_shift_h))
869 c0_data += c0_linesize;
870 if (!c1_shift_h || (y & c1_shift_h))
871 c1_data += c1_linesize;
872 if (!c2_shift_h || (y & c2_shift_h))
873 c2_data += c2_linesize;
874 d0_data += d0_linesize;
875 d1_data += d1_linesize;
879 const uint16_t *c0_data = (uint16_t *)in->data[plane];
880 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
881 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
882 uint16_t *d0_data = (uint16_t *)(out->data[plane]) + offset_y * d0_linesize + offset_x;
883 uint16_t *d1_data = (uint16_t *)(out->data[(plane + 1) % s->ncomp]) + offset_y * d1_linesize + offset_x;
886 d0_data += s->size - 1;
887 d1_data += s->size - 1;
890 for (y = 0; y < src_h; y++) {
891 for (x = 0; x < src_w; x++) {
892 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + s->max;
893 const int c1 = FFMIN(FFABS(c1_data[x >> c1_shift_w] - mid) + FFABS(c2_data[x >> c2_shift_w] - mid), limit);
897 target = d0_data - c0;
898 update16(target, max, intensity, limit);
899 target = d1_data - (c0 - c1);
900 update16(target, max, intensity, limit);
901 target = d1_data - (c0 + c1);
902 update16(target, max, intensity, limit);
904 target = d0_data + c0;
905 update16(target, max, intensity, limit);
906 target = d1_data + (c0 - c1);
907 update16(target, max, intensity, limit);
908 target = d1_data + (c0 + c1);
909 update16(target, max, intensity, limit);
913 if (!c0_shift_h || (y & c0_shift_h))
914 c0_data += c0_linesize;
915 if (!c1_shift_h || (y & c1_shift_h))
916 c1_data += c1_linesize;
917 if (!c2_shift_h || (y & c2_shift_h))
918 c2_data += c2_linesize;
919 d0_data += d0_linesize;
920 d1_data += d1_linesize;
924 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
925 envelope16(s, out, plane, (plane + 1) % s->ncomp, column ? offset_x : offset_y);
928 static av_always_inline void flat(WaveformContext *s,
929 AVFrame *in, AVFrame *out,
930 int component, int intensity,
931 int offset_y, int offset_x,
932 int column, int mirror)
934 const int plane = s->desc->comp[component].plane;
935 const int c0_linesize = in->linesize[ plane + 0 ];
936 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
937 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
938 const int c0_shift_w = s->shift_w[ component + 0 ];
939 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
940 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
941 const int c0_shift_h = s->shift_h[ component + 0 ];
942 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
943 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
944 const int d0_linesize = out->linesize[ plane + 0 ];
945 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
946 const int max = 255 - intensity;
947 const int src_h = in->height;
948 const int src_w = in->width;
952 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
953 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
955 for (x = 0; x < src_w; x++) {
956 const uint8_t *c0_data = in->data[plane + 0];
957 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
958 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
959 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
960 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
961 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
962 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
963 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
964 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
966 for (y = 0; y < src_h; y++) {
967 const int c0 = c0_data[x >> c0_shift_w] + 256;
968 const int c1 = FFABS(c1_data[x >> c1_shift_w] - 128) + FFABS(c2_data[x >> c2_shift_w] - 128);
971 target = d0 + x + d0_signed_linesize * c0;
972 update(target, max, intensity);
973 target = d1 + x + d1_signed_linesize * (c0 - c1);
974 update(target, max, intensity);
975 target = d1 + x + d1_signed_linesize * (c0 + c1);
976 update(target, max, intensity);
978 if (!c0_shift_h || (y & c0_shift_h))
979 c0_data += c0_linesize;
980 if (!c1_shift_h || (y & c1_shift_h))
981 c1_data += c1_linesize;
982 if (!c2_shift_h || (y & c2_shift_h))
983 c2_data += c2_linesize;
984 d0_data += d0_linesize;
985 d1_data += d1_linesize;
989 const uint8_t *c0_data = in->data[plane];
990 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
991 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
992 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
993 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
996 d0_data += s->size - 1;
997 d1_data += s->size - 1;
1000 for (y = 0; y < src_h; y++) {
1001 for (x = 0; x < src_w; x++) {
1002 int c0 = c0_data[x >> c0_shift_w] + 256;
1003 const int c1 = FFABS(c1_data[x >> c1_shift_w] - 128) + FFABS(c2_data[x >> c2_shift_w] - 128);
1007 target = d0_data - c0;
1008 update(target, max, intensity);
1009 target = d1_data - (c0 - c1);
1010 update(target, max, intensity);
1011 target = d1_data - (c0 + c1);
1012 update(target, max, intensity);
1014 target = d0_data + c0;
1015 update(target, max, intensity);
1016 target = d1_data + (c0 - c1);
1017 update(target, max, intensity);
1018 target = d1_data + (c0 + c1);
1019 update(target, max, intensity);
1023 if (!c0_shift_h || (y & c0_shift_h))
1024 c0_data += c0_linesize;
1025 if (!c1_shift_h || (y & c1_shift_h))
1026 c1_data += c1_linesize;
1027 if (!c2_shift_h || (y & c2_shift_h))
1028 c2_data += c2_linesize;
1029 d0_data += d0_linesize;
1030 d1_data += d1_linesize;
1034 envelope(s, out, plane, plane, column ? offset_x : offset_y);
1035 envelope(s, out, plane, (plane + 1) % s->ncomp, column ? offset_x : offset_y);
1038 #define AFLAT16(name, update_cr, column, mirror) \
1039 static av_always_inline void name (WaveformContext *s, \
1040 AVFrame *in, AVFrame *out, \
1041 int component, int intensity, \
1042 int offset_y, int offset_x, \
1043 int unused1, int unused2) \
1045 const int plane = s->desc->comp[component].plane; \
1046 const int c0_linesize = in->linesize[ plane + 0 ] / 2; \
1047 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2; \
1048 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2; \
1049 const int c0_shift_w = s->shift_w[ component + 0 ]; \
1050 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp]; \
1051 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp]; \
1052 const int c0_shift_h = s->shift_h[ component + 0 ]; \
1053 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp]; \
1054 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp]; \
1055 const int d0_linesize = out->linesize[ plane + 0 ] / 2; \
1056 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2; \
1057 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2; \
1058 const int limit = s->max - 1; \
1059 const int max = limit - intensity; \
1060 const int mid = s->max / 2; \
1061 const int src_h = in->height; \
1062 const int src_w = in->width; \
1066 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1); \
1067 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1); \
1068 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1); \
1070 for (x = 0; x < src_w; x++) { \
1071 const uint16_t *c0_data = (uint16_t *)in->data[plane + 0]; \
1072 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp]; \
1073 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp]; \
1074 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x; \
1075 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x; \
1076 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x; \
1077 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1); \
1078 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data); \
1079 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1); \
1080 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data); \
1081 uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1); \
1082 uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data); \
1084 for (y = 0; y < src_h; y++) { \
1085 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + mid; \
1086 const int c1 = FFMIN(c1_data[x >> c1_shift_w], limit) - mid; \
1087 const int c2 = FFMIN(c2_data[x >> c2_shift_w], limit) - mid; \
1090 target = d0 + x + d0_signed_linesize * c0; \
1091 update16(target, max, intensity, limit); \
1093 target = d1 + x + d1_signed_linesize * (c0 + c1); \
1094 update16(target, max, intensity, limit); \
1096 target = d2 + x + d2_signed_linesize * (c0 + c2); \
1097 update_cr(target, max, intensity, limit); \
1099 if (!c0_shift_h || (y & c0_shift_h)) \
1100 c0_data += c0_linesize; \
1101 if (!c1_shift_h || (y & c1_shift_h)) \
1102 c1_data += c1_linesize; \
1103 if (!c2_shift_h || (y & c2_shift_h)) \
1104 c2_data += c2_linesize; \
1105 d0_data += d0_linesize; \
1106 d1_data += d1_linesize; \
1107 d2_data += d2_linesize; \
1111 const uint16_t *c0_data = (uint16_t *)in->data[plane]; \
1112 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp]; \
1113 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp]; \
1114 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x; \
1115 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x; \
1116 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x; \
1119 d0_data += s->size - 1; \
1120 d1_data += s->size - 1; \
1121 d2_data += s->size - 1; \
1124 for (y = 0; y < src_h; y++) { \
1125 for (x = 0; x < src_w; x++) { \
1126 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + mid; \
1127 const int c1 = FFMIN(c1_data[x >> c1_shift_w], limit) - mid; \
1128 const int c2 = FFMIN(c2_data[x >> c2_shift_w], limit) - mid; \
1132 target = d0_data - c0; \
1133 update16(target, max, intensity, limit); \
1134 target = d1_data - (c0 + c1); \
1135 update16(target, max, intensity, limit); \
1136 target = d2_data - (c0 + c2); \
1137 update_cr(target, max, intensity, limit); \
1139 target = d0_data + c0; \
1140 update16(target, max, intensity, limit); \
1141 target = d1_data + (c0 + c1); \
1142 update16(target, max, intensity, limit); \
1143 target = d2_data + (c0 + c2); \
1144 update_cr(target, max, intensity, limit); \
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; \
1156 d2_data += d2_linesize; \
1160 envelope16(s, out, plane, (plane + 0) % s->ncomp, column ? offset_x : offset_y); \
1161 envelope16(s, out, plane, (plane + 1) % s->ncomp, column ? offset_x : offset_y); \
1162 envelope16(s, out, plane, (plane + 2) % s->ncomp, column ? offset_x : offset_y); \
1165 #define AFLAT(name, update_cr, column, mirror) \
1166 static av_always_inline void name(WaveformContext *s, \
1167 AVFrame *in, AVFrame *out, \
1168 int component, int intensity, \
1169 int offset_y, int offset_x, \
1170 int unused1, int unused2) \
1172 const int plane = s->desc->comp[component].plane; \
1173 const int c0_linesize = in->linesize[ plane + 0 ]; \
1174 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp]; \
1175 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp]; \
1176 const int c0_shift_w = s->shift_w[ component + 0 ]; \
1177 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp]; \
1178 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp]; \
1179 const int c0_shift_h = s->shift_h[ component + 0 ]; \
1180 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp]; \
1181 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp]; \
1182 const int d0_linesize = out->linesize[ plane + 0 ]; \
1183 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp]; \
1184 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp]; \
1185 const int max = 255 - intensity; \
1186 const int src_h = in->height; \
1187 const int src_w = in->width; \
1191 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1); \
1192 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1); \
1193 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1); \
1195 for (x = 0; x < src_w; x++) { \
1196 const uint8_t *c0_data = in->data[plane + 0]; \
1197 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp]; \
1198 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp]; \
1199 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x; \
1200 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x; \
1201 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x; \
1202 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1); \
1203 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data); \
1204 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1); \
1205 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data); \
1206 uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1); \
1207 uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data); \
1209 for (y = 0; y < src_h; y++) { \
1210 const int c0 = c0_data[x >> c0_shift_w] + 128; \
1211 const int c1 = c1_data[x >> c1_shift_w] - 128; \
1212 const int c2 = c2_data[x >> c2_shift_w] - 128; \
1215 target = d0 + x + d0_signed_linesize * c0; \
1216 update(target, max, intensity); \
1218 target = d1 + x + d1_signed_linesize * (c0 + c1); \
1219 update(target, max, intensity); \
1221 target = d2 + x + d2_signed_linesize * (c0 + c2); \
1222 update_cr(target, max, intensity); \
1224 if (!c0_shift_h || (y & c0_shift_h)) \
1225 c0_data += c0_linesize; \
1226 if (!c1_shift_h || (y & c1_shift_h)) \
1227 c1_data += c1_linesize; \
1228 if (!c1_shift_h || (y & c1_shift_h)) \
1229 c2_data += c1_linesize; \
1230 d0_data += d0_linesize; \
1231 d1_data += d1_linesize; \
1232 d2_data += d2_linesize; \
1236 const uint8_t *c0_data = in->data[plane]; \
1237 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp]; \
1238 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp]; \
1239 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x; \
1240 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x; \
1241 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x; \
1244 d0_data += s->size - 1; \
1245 d1_data += s->size - 1; \
1246 d2_data += s->size - 1; \
1249 for (y = 0; y < src_h; y++) { \
1250 for (x = 0; x < src_w; x++) { \
1251 const int c0 = c0_data[x >> c0_shift_w] + 128; \
1252 const int c1 = c1_data[x >> c1_shift_w] - 128; \
1253 const int c2 = c2_data[x >> c2_shift_w] - 128; \
1257 target = d0_data - c0; \
1258 update(target, max, intensity); \
1259 target = d1_data - (c0 + c1); \
1260 update(target, max, intensity); \
1261 target = d2_data - (c0 + c2); \
1262 update_cr(target, max, intensity); \
1264 target = d0_data + c0; \
1265 update(target, max, intensity); \
1266 target = d1_data + (c0 + c1); \
1267 update(target, max, intensity); \
1268 target = d2_data + (c0 + c2); \
1269 update_cr(target, max, intensity); \
1273 if (!c0_shift_h || (y & c0_shift_h)) \
1274 c0_data += c0_linesize; \
1275 if (!c1_shift_h || (y & c1_shift_h)) \
1276 c1_data += c1_linesize; \
1277 if (!c2_shift_h || (y & c2_shift_h)) \
1278 c2_data += c2_linesize; \
1279 d0_data += d0_linesize; \
1280 d1_data += d1_linesize; \
1281 d2_data += d2_linesize; \
1285 envelope(s, out, plane, (plane + 0) % s->ncomp, column ? offset_x : offset_y); \
1286 envelope(s, out, plane, (plane + 1) % s->ncomp, column ? offset_x : offset_y); \
1287 envelope(s, out, plane, (plane + 2) % s->ncomp, column ? offset_x : offset_y); \
1290 AFLAT16(aflat16_row, update16, 0, 0)
1291 AFLAT16(aflat16_row_mirror, update16, 0, 1)
1292 AFLAT16(aflat16_column, update16, 1, 0)
1293 AFLAT16(aflat16_column_mirror, update16, 1, 1)
1294 AFLAT16(xflat16_row, update16_cr, 0, 0)
1295 AFLAT16(xflat16_row_mirror, update16_cr, 0, 1)
1296 AFLAT16(xflat16_column, update16_cr, 1, 0)
1297 AFLAT16(xflat16_column_mirror, update16_cr, 1, 1)
1299 AFLAT(aflat_row, update, 0, 0)
1300 AFLAT(aflat_row_mirror, update, 0, 1)
1301 AFLAT(aflat_column, update, 1, 0)
1302 AFLAT(aflat_column_mirror, update, 1, 1)
1303 AFLAT(xflat_row, update_cr, 0, 0)
1304 AFLAT(xflat_row_mirror, update_cr, 0, 1)
1305 AFLAT(xflat_column, update_cr, 1, 0)
1306 AFLAT(xflat_column_mirror, update_cr, 1, 1)
1308 static av_always_inline void chroma16(WaveformContext *s,
1309 AVFrame *in, AVFrame *out,
1310 int component, int intensity,
1311 int offset_y, int offset_x,
1312 int column, int mirror)
1314 const int plane = s->desc->comp[component].plane;
1315 const int c0_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1316 const int c1_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1317 const int dst_linesize = out->linesize[plane] / 2;
1318 const int limit = s->max - 1;
1319 const int max = limit - intensity;
1320 const int mid = s->max / 2;
1321 const int c0_shift_w = s->shift_w[(component + 1) % s->ncomp];
1322 const int c1_shift_w = s->shift_w[(component + 2) % s->ncomp];
1323 const int c0_shift_h = s->shift_h[(component + 1) % s->ncomp];
1324 const int c1_shift_h = s->shift_h[(component + 2) % s->ncomp];
1325 const int src_h = in->height;
1326 const int src_w = in->width;
1330 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
1332 for (x = 0; x < src_w; x++) {
1333 const uint16_t *c0_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1334 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1335 uint16_t *dst_data = (uint16_t *)out->data[plane] + offset_y * dst_linesize + offset_x;
1336 uint16_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
1337 uint16_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
1338 uint16_t *dst = dst_line;
1340 for (y = 0; y < src_h; y++) {
1341 const int sum = FFMIN(FFABS(c0_data[x >> c0_shift_w] - mid) + FFABS(c1_data[x >> c1_shift_w] - mid - 1), limit);
1344 target = dst + x + dst_signed_linesize * sum;
1345 update16(target, max, intensity, limit);
1347 if (!c0_shift_h || (y & c0_shift_h))
1348 c0_data += c0_linesize;
1349 if (!c1_shift_h || (y & c1_shift_h))
1350 c1_data += c1_linesize;
1351 dst_data += dst_linesize;
1355 const uint16_t *c0_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1356 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1357 uint16_t *dst_data = (uint16_t *)out->data[plane] + offset_y * dst_linesize + offset_x;
1360 dst_data += s->size - 1;
1361 for (y = 0; y < src_h; y++) {
1362 for (x = 0; x < src_w; x++) {
1363 const int sum = FFMIN(FFABS(c0_data[x >> c0_shift_w] - mid) + FFABS(c1_data[x >> c1_shift_w] - mid - 1), limit);
1367 target = dst_data - sum;
1368 update16(target, max, intensity, limit);
1370 target = dst_data + sum;
1371 update16(target, max, intensity, limit);
1375 if (!c0_shift_h || (y & c0_shift_h))
1376 c0_data += c0_linesize;
1377 if (!c1_shift_h || (y & c1_shift_h))
1378 c1_data += c1_linesize;
1379 dst_data += dst_linesize;
1383 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
1386 static av_always_inline void chroma(WaveformContext *s,
1387 AVFrame *in, AVFrame *out,
1388 int component, int intensity,
1389 int offset_y, int offset_x,
1390 int column, int mirror)
1392 const int plane = s->desc->comp[component].plane;
1393 const int c0_linesize = in->linesize[(plane + 1) % s->ncomp];
1394 const int c1_linesize = in->linesize[(plane + 2) % s->ncomp];
1395 const int dst_linesize = out->linesize[plane];
1396 const int max = 255 - intensity;
1397 const int c0_shift_w = s->shift_w[(component + 1) % s->ncomp];
1398 const int c1_shift_w = s->shift_w[(component + 2) % s->ncomp];
1399 const int c0_shift_h = s->shift_h[(component + 1) % s->ncomp];
1400 const int c1_shift_h = s->shift_h[(component + 2) % s->ncomp];
1401 const int src_h = in->height;
1402 const int src_w = in->width;
1406 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
1408 for (x = 0; x < src_w; x++) {
1409 const uint8_t *c0_data = in->data[(plane + 1) % s->ncomp];
1410 const uint8_t *c1_data = in->data[(plane + 2) % s->ncomp];
1411 uint8_t *dst_data = out->data[plane] + offset_y * dst_linesize + offset_x;
1412 uint8_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
1413 uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
1414 uint8_t *dst = dst_line;
1416 for (y = 0; y < src_h; y++) {
1417 const int sum = FFABS(c0_data[x >> c0_shift_w] - 128) + FFABS(c1_data[x >> c1_shift_w] - 127);
1420 target = dst + x + dst_signed_linesize * sum;
1421 update(target, max, intensity);
1423 if (!c0_shift_h || (y & c0_shift_h))
1424 c0_data += c0_linesize;
1425 if (!c1_shift_h || (y & c1_shift_h))
1426 c1_data += c1_linesize;
1427 dst_data += dst_linesize;
1431 const uint8_t *c0_data = in->data[(plane + 1) % s->ncomp];
1432 const uint8_t *c1_data = in->data[(plane + 2) % s->ncomp];
1433 uint8_t *dst_data = out->data[plane] + offset_y * dst_linesize + offset_x;
1436 dst_data += s->size - 1;
1437 for (y = 0; y < src_h; y++) {
1438 for (x = 0; x < src_w; x++) {
1439 const int sum = FFABS(c0_data[x >> c0_shift_w] - 128) + FFABS(c1_data[x >> c1_shift_w] - 127);
1443 target = dst_data - sum;
1444 update(target, max, intensity);
1446 target = dst_data + sum;
1447 update(target, max, intensity);
1451 if (!c0_shift_h || (y & c0_shift_h))
1452 c0_data += c0_linesize;
1453 if (!c1_shift_h || (y & c1_shift_h))
1454 c1_data += c1_linesize;
1455 dst_data += dst_linesize;
1459 envelope(s, out, plane, plane, column ? offset_x : offset_y);
1462 static av_always_inline void color16(WaveformContext *s,
1463 AVFrame *in, AVFrame *out,
1464 int component, int intensity,
1465 int offset_y, int offset_x,
1466 int column, int mirror)
1468 const int plane = s->desc->comp[component].plane;
1469 const int limit = s->max - 1;
1470 const uint16_t *c0_data = (const uint16_t *)in->data[plane + 0];
1471 const uint16_t *c1_data = (const uint16_t *)in->data[(plane + 1) % s->ncomp];
1472 const uint16_t *c2_data = (const uint16_t *)in->data[(plane + 2) % s->ncomp];
1473 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
1474 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1475 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1476 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
1477 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
1478 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2;
1479 const int c0_shift_w = s->shift_w[ component + 0 ];
1480 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1481 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1482 const int c0_shift_h = s->shift_h[ component + 0 ];
1483 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1484 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1485 const int src_h = in->height;
1486 const int src_w = in->width;
1490 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1491 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1492 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1493 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1494 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1495 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1496 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1497 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1498 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1499 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1500 uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1501 uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1503 for (y = 0; y < src_h; y++) {
1504 for (x = 0; x < src_w; x++) {
1505 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1506 const int c1 = c1_data[x >> c1_shift_w];
1507 const int c2 = c2_data[x >> c2_shift_w];
1509 *(d0 + d0_signed_linesize * c0 + x) = c0;
1510 *(d1 + d1_signed_linesize * c0 + x) = c1;
1511 *(d2 + d2_signed_linesize * c0 + x) = c2;
1514 if (!c0_shift_h || (y & c0_shift_h))
1515 c0_data += c0_linesize;
1516 if (!c1_shift_h || (y & c1_shift_h))
1517 c1_data += c1_linesize;
1518 if (!c2_shift_h || (y & c2_shift_h))
1519 c2_data += c2_linesize;
1520 d0_data += d0_linesize;
1521 d1_data += d1_linesize;
1522 d2_data += d2_linesize;
1525 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1526 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1527 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1530 d0_data += s->size - 1;
1531 d1_data += s->size - 1;
1532 d2_data += s->size - 1;
1535 for (y = 0; y < src_h; y++) {
1536 for (x = 0; x < src_w; x++) {
1537 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1538 const int c1 = c1_data[x >> c1_shift_w];
1539 const int c2 = c2_data[x >> c2_shift_w];
1542 *(d0_data - c0) = c0;
1543 *(d1_data - c0) = c1;
1544 *(d2_data - c0) = c2;
1546 *(d0_data + c0) = c0;
1547 *(d1_data + c0) = c1;
1548 *(d2_data + c0) = c2;
1552 if (!c0_shift_h || (y & c0_shift_h))
1553 c0_data += c0_linesize;
1554 if (!c1_shift_h || (y & c1_shift_h))
1555 c1_data += c1_linesize;
1556 if (!c2_shift_h || (y & c2_shift_h))
1557 c2_data += c2_linesize;
1558 d0_data += d0_linesize;
1559 d1_data += d1_linesize;
1560 d2_data += d2_linesize;
1564 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
1567 static av_always_inline void color(WaveformContext *s,
1568 AVFrame *in, AVFrame *out,
1569 int component, int intensity,
1570 int offset_y, int offset_x,
1571 int column, int mirror)
1573 const int plane = s->desc->comp[component].plane;
1574 const uint8_t *c0_data = in->data[plane + 0];
1575 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1576 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1577 const int c0_linesize = in->linesize[ plane + 0 ];
1578 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
1579 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
1580 const int d0_linesize = out->linesize[ plane + 0 ];
1581 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
1582 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp];
1583 const int c0_shift_w = s->shift_w[ component + 0 ];
1584 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1585 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1586 const int c0_shift_h = s->shift_h[ component + 0 ];
1587 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1588 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1589 const int src_h = in->height;
1590 const int src_w = in->width;
1594 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1595 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1596 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1597 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1598 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1599 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1600 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1601 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1602 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1603 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1604 uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1605 uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1607 for (y = 0; y < src_h; y++) {
1608 for (x = 0; x < src_w; x++) {
1609 const int c0 = c0_data[x >> c0_shift_w];
1610 const int c1 = c1_data[x >> c1_shift_w];
1611 const int c2 = c2_data[x >> c2_shift_w];
1613 *(d0 + d0_signed_linesize * c0 + x) = c0;
1614 *(d1 + d1_signed_linesize * c0 + x) = c1;
1615 *(d2 + d2_signed_linesize * c0 + x) = c2;
1618 if (!c0_shift_h || (y & c0_shift_h))
1619 c0_data += c0_linesize;
1620 if (!c1_shift_h || (y & c1_shift_h))
1621 c1_data += c1_linesize;
1622 if (!c2_shift_h || (y & c2_shift_h))
1623 c2_data += c2_linesize;
1624 d0_data += d0_linesize;
1625 d1_data += d1_linesize;
1626 d2_data += d2_linesize;
1629 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1630 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1631 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1634 d0_data += s->size - 1;
1635 d1_data += s->size - 1;
1636 d2_data += s->size - 1;
1639 for (y = 0; y < src_h; y++) {
1640 for (x = 0; x < src_w; x++) {
1641 const int c0 = c0_data[x >> c0_shift_w];
1642 const int c1 = c1_data[x >> c1_shift_w];
1643 const int c2 = c2_data[x >> c2_shift_w];
1646 *(d0_data - c0) = c0;
1647 *(d1_data - c0) = c1;
1648 *(d2_data - c0) = c2;
1650 *(d0_data + c0) = c0;
1651 *(d1_data + c0) = c1;
1652 *(d2_data + c0) = c2;
1656 if (!c0_shift_h || (y & c0_shift_h))
1657 c0_data += c0_linesize;
1658 if (!c1_shift_h || (y & c1_shift_h))
1659 c1_data += c1_linesize;
1660 if (!c2_shift_h || (y & c2_shift_h))
1661 c2_data += c2_linesize;
1662 d0_data += d0_linesize;
1663 d1_data += d1_linesize;
1664 d2_data += d2_linesize;
1668 envelope(s, out, plane, plane, column ? offset_x : offset_y);
1671 static av_always_inline void acolor16(WaveformContext *s,
1672 AVFrame *in, AVFrame *out,
1673 int component, int intensity,
1674 int offset_y, int offset_x,
1675 int column, int mirror)
1677 const int plane = s->desc->comp[component].plane;
1678 const int limit = s->max - 1;
1679 const int max = limit - intensity;
1680 const uint16_t *c0_data = (const uint16_t *)in->data[plane + 0];
1681 const uint16_t *c1_data = (const uint16_t *)in->data[(plane + 1) % s->ncomp];
1682 const uint16_t *c2_data = (const uint16_t *)in->data[(plane + 2) % s->ncomp];
1683 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
1684 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1685 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1686 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
1687 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
1688 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2;
1689 const int c0_shift_w = s->shift_w[ component + 0 ];
1690 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1691 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1692 const int c0_shift_h = s->shift_h[ component + 0 ];
1693 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1694 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1695 const int src_h = in->height;
1696 const int src_w = in->width;
1700 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1701 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1702 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1703 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1704 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1705 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1706 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1707 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1708 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1709 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1710 uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1711 uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1713 for (y = 0; y < src_h; y++) {
1714 for (x = 0; x < src_w; x++) {
1715 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1716 const int c1 = c1_data[x >> c1_shift_w];
1717 const int c2 = c2_data[x >> c2_shift_w];
1719 update16(d0 + d0_signed_linesize * c0 + x, max, intensity, limit);
1720 *(d1 + d1_signed_linesize * c0 + x) = c1;
1721 *(d2 + d2_signed_linesize * c0 + x) = c2;
1724 if (!c0_shift_h || (y & c0_shift_h))
1725 c0_data += c0_linesize;
1726 if (!c1_shift_h || (y & c1_shift_h))
1727 c1_data += c1_linesize;
1728 if (!c2_shift_h || (y & c2_shift_h))
1729 c2_data += c2_linesize;
1730 d0_data += d0_linesize;
1731 d1_data += d1_linesize;
1732 d2_data += d2_linesize;
1735 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1736 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1737 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1740 d0_data += s->size - 1;
1741 d1_data += s->size - 1;
1742 d2_data += s->size - 1;
1745 for (y = 0; y < src_h; y++) {
1746 for (x = 0; x < src_w; x++) {
1747 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1748 const int c1 = c1_data[x >> c1_shift_w];
1749 const int c2 = c2_data[x >> c2_shift_w];
1752 update16(d0_data - c0, max, intensity, limit);
1753 *(d1_data - c0) = c1;
1754 *(d2_data - c0) = c2;
1756 update16(d0_data + c0, max, intensity, limit);
1757 *(d1_data + c0) = c1;
1758 *(d2_data + c0) = c2;
1762 if (!c0_shift_h || (y & c0_shift_h))
1763 c0_data += c0_linesize;
1764 if (!c1_shift_h || (y & c1_shift_h))
1765 c1_data += c1_linesize;
1766 if (!c2_shift_h || (y & c2_shift_h))
1767 c2_data += c2_linesize;
1768 d0_data += d0_linesize;
1769 d1_data += d1_linesize;
1770 d2_data += d2_linesize;
1774 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
1777 static av_always_inline void acolor(WaveformContext *s,
1778 AVFrame *in, AVFrame *out,
1779 int component, int intensity,
1780 int offset_y, int offset_x,
1781 int column, int mirror)
1783 const int plane = s->desc->comp[component].plane;
1784 const uint8_t *c0_data = in->data[plane + 0];
1785 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1786 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1787 const int c0_linesize = in->linesize[ plane + 0 ];
1788 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
1789 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
1790 const int d0_linesize = out->linesize[ plane + 0 ];
1791 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
1792 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp];
1793 const int c0_shift_w = s->shift_w[ component + 0 ];
1794 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1795 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1796 const int c0_shift_h = s->shift_h[ component + 0 ];
1797 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1798 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1799 const int max = 255 - intensity;
1800 const int src_h = in->height;
1801 const int src_w = in->width;
1805 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1806 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1807 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1808 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1809 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1810 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1811 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1812 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1813 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1814 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1815 uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1816 uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1818 for (y = 0; y < src_h; y++) {
1819 for (x = 0; x < src_w; x++) {
1820 const int c0 = c0_data[x >> c0_shift_w];
1821 const int c1 = c1_data[x >> c1_shift_w];
1822 const int c2 = c2_data[x >> c2_shift_w];
1824 update(d0 + d0_signed_linesize * c0 + x, max, intensity);
1825 *(d1 + d1_signed_linesize * c0 + x) = c1;
1826 *(d2 + d2_signed_linesize * c0 + x) = c2;
1829 if (!c0_shift_h || (y & c0_shift_h))
1830 c0_data += c0_linesize;
1831 if (!c1_shift_h || (y & c1_shift_h))
1832 c1_data += c1_linesize;
1833 if (!c2_shift_h || (y & c2_shift_h))
1834 c2_data += c2_linesize;
1835 d0_data += d0_linesize;
1836 d1_data += d1_linesize;
1837 d2_data += d2_linesize;
1840 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1841 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1842 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1845 d0_data += s->size - 1;
1846 d1_data += s->size - 1;
1847 d2_data += s->size - 1;
1850 for (y = 0; y < src_h; y++) {
1851 for (x = 0; x < src_w; x++) {
1852 const int c0 = c0_data[x >> c0_shift_w];
1853 const int c1 = c1_data[x >> c1_shift_w];
1854 const int c2 = c2_data[x >> c2_shift_w];
1857 update(d0_data - c0, max, intensity);
1858 *(d1_data - c0) = c1;
1859 *(d2_data - c0) = c2;
1861 update(d0_data + c0, max, intensity);
1862 *(d1_data + c0) = c1;
1863 *(d2_data + c0) = c2;
1867 if (!c0_shift_h || (y & c0_shift_h))
1868 c0_data += c0_linesize;
1869 if (!c1_shift_h || (y & c1_shift_h))
1870 c1_data += c1_linesize;
1871 if (!c2_shift_h || (y & c2_shift_h))
1872 c2_data += c2_linesize;
1873 d0_data += d0_linesize;
1874 d1_data += d1_linesize;
1875 d2_data += d2_linesize;
1879 envelope(s, out, plane, plane, column ? offset_x : offset_y);
1882 static const uint8_t black_yuva_color[4] = { 0, 127, 127, 255 };
1883 static const uint8_t black_gbrp_color[4] = { 0, 0, 0, 255 };
1885 static const GraticuleLines aflat_digital8[] = {
1886 { { { "16", 16+128 }, { "16", 16+128 }, { "16", 16+128 }, { "0", 0+128 } } },
1887 { { { "128", 128+128 }, { "128", 128+128 }, { "128", 128+128 }, { "128", 128+128 } } },
1888 { { { "235", 235+128 }, { "240", 240+128 }, { "240", 240+128 }, { "255", 255+128 } } },
1891 static const GraticuleLines aflat_digital9[] = {
1892 { { { "32", 32+256 }, { "32", 32+256 }, { "32", 32+256 }, { "0", 0+256 } } },
1893 { { { "256", 256+256 }, { "256", 256+256 }, { "256", 256+256 }, { "256", 256+256 } } },
1894 { { { "470", 470+256 }, { "480", 480+256 }, { "480", 480+256 }, { "511", 511+256 } } },
1897 static const GraticuleLines aflat_digital10[] = {
1898 { { { "64", 64+512 }, { "64", 64+512 }, { "64", 64+512 }, { "0", 0+512 } } },
1899 { { { "512", 512+512 }, { "512", 512+512 }, { "512", 512+512 }, { "512", 512+512 } } },
1900 { { { "940", 940+512 }, { "960", 960+512 }, { "960", 960+512 }, { "1023", 1023+512 } } },
1903 static const GraticuleLines aflat_digital12[] = {
1904 { { { "256", 256+2048 }, { "256", 256+2048 }, { "256", 256+2048 }, { "0", 0+2048 } } },
1905 { { { "2048", 2048+2048 }, { "2048", 2048+2048 }, { "2048", 2048+2048 }, { "2048", 2048+2048 } } },
1906 { { { "3760", 3760+2048 }, { "3840", 3840+2048 }, { "3840", 3840+2048 }, { "4095", 4095+2048 } } },
1909 static const GraticuleLines aflat_millivolts8[] = {
1910 { { { "0", 16+128 }, { "0", 16+128 }, { "0", 16+128 }, { "0", 0+128 } } },
1911 { { { "175", 71+128 }, { "175", 72+128 }, { "175", 72+128 }, { "175", 64+128 } } },
1912 { { { "350", 126+128 }, { "350", 128+128 }, { "350", 128+128 }, { "350", 128+128 } } },
1913 { { { "525", 180+128 }, { "525", 184+128 }, { "525", 184+128 }, { "525", 192+128 } } },
1914 { { { "700", 235+128 }, { "700", 240+128 }, { "700", 240+128 }, { "700", 255+128 } } },
1917 static const GraticuleLines aflat_millivolts9[] = {
1918 { { { "0", 32+256 }, { "0", 32+256 }, { "0", 32+256 }, { "0", 0+256 } } },
1919 { { { "175", 142+256 }, { "175", 144+256 }, { "175", 144+256 }, { "175", 128+256 } } },
1920 { { { "350", 251+256 }, { "350", 256+256 }, { "350", 256+256 }, { "350", 256+256 } } },
1921 { { { "525", 361+256 }, { "525", 368+256 }, { "525", 368+256 }, { "525", 384+256 } } },
1922 { { { "700", 470+256 }, { "700", 480+256 }, { "700", 480+256 }, { "700", 511+256 } } },
1925 static const GraticuleLines aflat_millivolts10[] = {
1926 { { { "0", 64+512 }, { "0", 64+512 }, { "0", 64+512 }, { "0", 0+512 } } },
1927 { { { "175", 283+512 }, { "175", 288+512 }, { "175", 288+512 }, { "175", 256+512 } } },
1928 { { { "350", 502+512 }, { "350", 512+512 }, { "350", 512+512 }, { "350", 512+512 } } },
1929 { { { "525", 721+512 }, { "525", 736+512 }, { "525", 736+512 }, { "525", 768+512 } } },
1930 { { { "700", 940+512 }, { "700", 960+512 }, { "700", 960+512 }, { "700", 1023+512 } } },
1933 static const GraticuleLines aflat_millivolts12[] = {
1934 { { { "0", 256+2048 }, { "0", 256+2048 }, { "0", 256+2048 }, { "0", 0+2048 } } },
1935 { { { "175", 1132+2048 }, { "175", 1152+2048 }, { "175", 1152+2048 }, { "175", 1024+2048 } } },
1936 { { { "350", 2008+2048 }, { "350", 2048+2048 }, { "350", 2048+2048 }, { "350", 2048+2048 } } },
1937 { { { "525", 2884+2048 }, { "525", 2944+2048 }, { "525", 2944+2048 }, { "525", 3072+2048 } } },
1938 { { { "700", 3760+2048 }, { "700", 3840+2048 }, { "700", 3840+2048 }, { "700", 4095+2048 } } },
1941 static const GraticuleLines aflat_ire8[] = {
1942 { { { "-25", -39+128 }, { "-25", -40+128 }, { "-25", -40+128 }, { "-25", -64+128 } } },
1943 { { { "0", 16+128 }, { "0", 16+128 }, { "0", 16+128 }, { "0", 0+128 } } },
1944 { { { "25", 71+128 }, { "25", 72+128 }, { "25", 72+128 }, { "25", 64+128 } } },
1945 { { { "50", 126+128 }, { "50", 128+128 }, { "50", 128+128 }, { "50", 128+128 } } },
1946 { { { "75", 180+128 }, { "75", 184+128 }, { "75", 184+128 }, { "75", 192+128 } } },
1947 { { { "100", 235+128 }, { "100", 240+128 }, { "100", 240+128 }, { "100", 256+128 } } },
1948 { { { "125", 290+128 }, { "125", 296+128 }, { "125", 296+128 }, { "125", 320+128 } } },
1951 static const GraticuleLines aflat_ire9[] = {
1952 { { { "-25", -78+256 }, { "-25", -80+256 }, { "-25", -80+256 }, { "-25",-128+256 } } },
1953 { { { "0", 32+256 }, { "0", 32+256 }, { "0", 32+256 }, { "0", 0+256 } } },
1954 { { { "25", 142+256 }, { "25", 144+256 }, { "25", 144+256 }, { "25", 128+256 } } },
1955 { { { "50", 251+256 }, { "50", 256+256 }, { "50", 256+256 }, { "50", 256+256 } } },
1956 { { { "75", 361+256 }, { "75", 368+256 }, { "75", 368+256 }, { "75", 384+256 } } },
1957 { { { "100", 470+256 }, { "100", 480+256 }, { "100", 480+256 }, { "100", 512+256 } } },
1958 { { { "125", 580+256 }, { "125", 592+256 }, { "125", 592+256 }, { "125", 640+256 } } },
1961 static const GraticuleLines aflat_ire10[] = {
1962 { { { "-25",-156+512 }, { "-25",-160+512 }, { "-25",-160+512 }, { "-25", -256+512 } } },
1963 { { { "0", 64+512 }, { "0", 64+512 }, { "0", 64+512 }, { "0", 0+512 } } },
1964 { { { "25", 283+512 }, { "25", 288+512 }, { "25", 288+512 }, { "25", 256+512 } } },
1965 { { { "50", 502+512 }, { "50", 512+512 }, { "50", 512+512 }, { "50", 512+512 } } },
1966 { { { "75", 721+512 }, { "75", 736+512 }, { "75", 736+512 }, { "75", 768+512 } } },
1967 { { { "100", 940+512 }, { "100", 960+512 }, { "100", 960+512 }, { "100", 1024+512 } } },
1968 { { { "125",1160+512 }, { "125",1184+512 }, { "125",1184+512 }, { "125", 1280+512 } } },
1971 static const GraticuleLines aflat_ire12[] = {
1972 { { { "-25", -624+2048 }, { "-25", -640+2048 }, { "-25", -640+2048 }, { "-25",-1024+2048 } } },
1973 { { { "0", 256+2048 }, { "0", 256+2048 }, { "0", 256+2048 }, { "0", 0+2048 } } },
1974 { { { "25", 1132+2048 }, { "25", 1152+2048 }, { "25", 1152+2048 }, { "25", 1024+2048 } } },
1975 { { { "50", 2008+2048 }, { "50", 2048+2048 }, { "50", 2048+2048 }, { "50", 2048+2048 } } },
1976 { { { "75", 2884+2048 }, { "75", 2944+2048 }, { "75", 2944+2048 }, { "75", 3072+2048 } } },
1977 { { { "100", 3760+2048 }, { "100", 3840+2048 }, { "100", 3840+2048 }, { "100", 4096+2048 } } },
1978 { { { "125", 4640+2048 }, { "125", 4736+2048 }, { "125", 4736+2048 }, { "125", 5120+2048 } } },
1981 static const GraticuleLines flat_digital8[] = {
1982 { { { "16", 16+256 }, { "16", 16+256 }, { "16", 16+256 }, { "0", 0+256 } } },
1983 { { { "128", 128+256 }, { "128", 128+256 }, { "128", 128+256 }, { "128", 128+256 } } },
1984 { { { "235", 235+256 }, { "240", 240+256 }, { "240", 240+256 }, { "255", 255+256 } } },
1987 static const GraticuleLines flat_digital9[] = {
1988 { { { "32", 32+512 }, { "32", 32+512 }, { "32", 32+512 }, { "0", 0+512 } } },
1989 { { { "256", 256+512 }, { "256", 256+512 }, { "256", 256+512 }, { "256", 256+512 } } },
1990 { { { "470", 470+512 }, { "480", 480+512 }, { "480", 480+512 }, { "511", 511+512 } } },
1993 static const GraticuleLines flat_digital10[] = {
1994 { { { "64", 64+1024 }, { "64", 64+1024 }, { "64", 64+1024 }, { "0", 0+1024 } } },
1995 { { { "512", 512+1024 }, { "512", 512+1024 }, { "512", 512+1024 }, { "512", 512+1024 } } },
1996 { { { "940", 940+1024 }, { "960", 960+1024 }, { "960", 960+1024 }, { "1023", 1023+1024 } } },
1999 static const GraticuleLines flat_digital12[] = {
2000 { { { "256", 256+4096 }, { "256", 256+4096 }, { "256", 256+4096 }, { "0", 0+4096 } } },
2001 { { { "2048", 2048+4096 }, { "2048", 2048+4096 }, { "2048", 2048+4096 }, { "2048", 2048+4096 } } },
2002 { { { "3760", 3760+4096 }, { "3840", 3840+4096 }, { "3840", 3840+4096 }, { "4095", 4095+4096 } } },
2005 static const GraticuleLines flat_millivolts8[] = {
2006 { { { "0", 16+256 }, { "0", 16+256 }, { "0", 16+256 }, { "0", 0+256 } } },
2007 { { { "175", 71+256 }, { "175", 72+256 }, { "175", 72+256 }, { "175", 64+256 } } },
2008 { { { "350", 126+256 }, { "350", 128+256 }, { "350", 128+256 }, { "350", 128+256 } } },
2009 { { { "525", 180+256 }, { "525", 184+256 }, { "525", 184+256 }, { "525", 192+256 } } },
2010 { { { "700", 235+256 }, { "700", 240+256 }, { "700", 240+256 }, { "700", 255+256 } } },
2013 static const GraticuleLines flat_millivolts9[] = {
2014 { { { "0", 32+512 }, { "0", 32+512 }, { "0", 32+512 }, { "0", 0+512 } } },
2015 { { { "175", 142+512 }, { "175", 144+512 }, { "175", 144+512 }, { "175", 128+512 } } },
2016 { { { "350", 251+512 }, { "350", 256+512 }, { "350", 256+512 }, { "350", 256+512 } } },
2017 { { { "525", 361+512 }, { "525", 368+512 }, { "525", 368+512 }, { "525", 384+512 } } },
2018 { { { "700", 470+512 }, { "700", 480+512 }, { "700", 480+512 }, { "700", 511+512 } } },
2021 static const GraticuleLines flat_millivolts10[] = {
2022 { { { "0", 64+1024 }, { "0", 64+1024 }, { "0", 64+1024 }, { "0", 0+1024 } } },
2023 { { { "175", 283+1024 }, { "175", 288+1024 }, { "175", 288+1024 }, { "175", 256+1024 } } },
2024 { { { "350", 502+1024 }, { "350", 512+1024 }, { "350", 512+1024 }, { "350", 512+1024 } } },
2025 { { { "525", 721+1024 }, { "525", 736+1024 }, { "525", 736+1024 }, { "525", 768+1024 } } },
2026 { { { "700", 940+1024 }, { "700", 960+1024 }, { "700", 960+1024 }, { "700", 1023+1024 } } },
2029 static const GraticuleLines flat_millivolts12[] = {
2030 { { { "0", 256+4096 }, { "0", 256+4096 }, { "0", 256+4096 }, { "0", 0+4096 } } },
2031 { { { "175", 1132+4096 }, { "175", 1152+4096 }, { "175", 1152+4096 }, { "175", 1024+4096 } } },
2032 { { { "350", 2008+4096 }, { "350", 2048+4096 }, { "350", 2048+4096 }, { "350", 2048+4096 } } },
2033 { { { "525", 2884+4096 }, { "525", 2944+4096 }, { "525", 2944+4096 }, { "525", 3072+4096 } } },
2034 { { { "700", 3760+4096 }, { "700", 3840+4096 }, { "700", 3840+4096 }, { "700", 4095+4096 } } },
2037 static const GraticuleLines flat_ire8[] = {
2038 { { { "-25", -39+256 }, { "-25", -40+256 }, { "-25", -40+256 }, { "-25", -64+256 } } },
2039 { { { "0", 16+256 }, { "0", 16+256 }, { "0", 16+256 }, { "0", 0+256 } } },
2040 { { { "25", 71+256 }, { "25", 72+256 }, { "25", 72+256 }, { "25", 64+256 } } },
2041 { { { "50", 126+256 }, { "50", 128+256 }, { "50", 128+256 }, { "50", 128+256 } } },
2042 { { { "75", 180+256 }, { "75", 184+256 }, { "75", 184+256 }, { "75", 192+256 } } },
2043 { { { "100", 235+256 }, { "100", 240+256 }, { "100", 240+256 }, { "100", 256+256 } } },
2044 { { { "125", 290+256 }, { "125", 296+256 }, { "125", 296+256 }, { "125", 320+256 } } },
2047 static const GraticuleLines flat_ire9[] = {
2048 { { { "-25", -78+512 }, { "-25", -80+512 }, { "-25", -80+512 }, { "-25",-128+512 } } },
2049 { { { "0", 32+512 }, { "0", 32+512 }, { "0", 32+512 }, { "0", 0+512 } } },
2050 { { { "25", 142+512 }, { "25", 144+512 }, { "25", 144+512 }, { "25", 128+512 } } },
2051 { { { "50", 251+512 }, { "50", 256+512 }, { "50", 256+512 }, { "50", 256+512 } } },
2052 { { { "75", 361+512 }, { "75", 368+512 }, { "75", 368+512 }, { "75", 384+512 } } },
2053 { { { "100", 470+512 }, { "100", 480+512 }, { "100", 480+512 }, { "100", 512+512 } } },
2054 { { { "125", 580+512 }, { "125", 592+512 }, { "125", 592+512 }, { "125", 640+512 } } },
2057 static const GraticuleLines flat_ire10[] = {
2058 { { { "-25",-156+1024 }, { "-25",-160+1024 }, { "-25",-160+1024 }, { "-25", -256+1024 } } },
2059 { { { "0", 64+1024 }, { "0", 64+1024 }, { "0", 64+1024 }, { "0", 0+1024 } } },
2060 { { { "25", 283+1024 }, { "25", 288+1024 }, { "25", 288+1024 }, { "25", 256+1024 } } },
2061 { { { "50", 502+1024 }, { "50", 512+1024 }, { "50", 512+1024 }, { "50", 512+1024 } } },
2062 { { { "75", 721+1024 }, { "75", 736+1024 }, { "75", 736+1024 }, { "75", 768+1024 } } },
2063 { { { "100", 940+1024 }, { "100", 960+1024 }, { "100", 960+1024 }, { "100", 1024+1024 } } },
2064 { { { "125",1160+1024 }, { "125",1184+1024 }, { "125",1184+1024 }, { "125", 1280+1024 } } },
2067 static const GraticuleLines flat_ire12[] = {
2068 { { { "-25", -624+4096 }, { "-25", -640+4096 }, { "-25", -640+4096 }, { "-25",-1024+4096 } } },
2069 { { { "0", 256+4096 }, { "0", 256+4096 }, { "0", 256+4096 }, { "0", 0+4096 } } },
2070 { { { "25", 1132+4096 }, { "25", 1152+4096 }, { "25", 1152+4096 }, { "25", 1024+4096 } } },
2071 { { { "50", 2008+4096 }, { "50", 2048+4096 }, { "50", 2048+4096 }, { "50", 2048+4096 } } },
2072 { { { "75", 2884+4096 }, { "75", 2944+4096 }, { "75", 2944+4096 }, { "75", 3072+4096 } } },
2073 { { { "100", 3760+4096 }, { "100", 3840+4096 }, { "100", 3840+4096 }, { "100", 4096+4096 } } },
2074 { { { "125", 4640+4096 }, { "125", 4736+4096 }, { "125", 4736+4096 }, { "125", 5120+4096 } } },
2077 static const GraticuleLines digital8[] = {
2078 { { { "16", 16 }, { "16", 16 }, { "16", 16 }, { "0", 0 } } },
2079 { { { "128", 128 }, { "128", 128 }, { "128", 128 }, { "128", 128 } } },
2080 { { { "235", 235 }, { "240", 240 }, { "240", 240 }, { "255", 255 } } },
2083 static const GraticuleLines digital9[] = {
2084 { { { "32", 32 }, { "32", 32 }, { "32", 32 }, { "0", 0 } } },
2085 { { { "256", 256 }, { "256", 256 }, { "256", 256 }, { "256", 256 } } },
2086 { { { "470", 470 }, { "480", 480 }, { "480", 480 }, { "511", 511 } } },
2089 static const GraticuleLines digital10[] = {
2090 { { { "64", 64 }, { "64", 64 }, { "64", 64 }, { "0", 0 } } },
2091 { { { "512", 512 }, { "512", 512 }, { "512", 512 }, { "512", 512 } } },
2092 { { { "940", 940 }, { "960", 960 }, { "960", 960 }, { "1023", 1023 } } },
2095 static const GraticuleLines digital12[] = {
2096 { { { "256", 256 }, { "256", 256 }, { "256", 256 }, { "0", 0 } } },
2097 { { { "2048", 2048 }, { "2048", 2048 }, { "2048", 2048 }, { "2048", 2048 } } },
2098 { { { "3760", 3760 }, { "3840", 3840 }, { "3840", 3840 }, { "4095", 4095 } } },
2101 static const GraticuleLines millivolts8[] = {
2102 { { { "0", 16 }, { "0", 16 }, { "0", 16 }, { "0", 0 } } },
2103 { { { "175", 71 }, { "175", 72 }, { "175", 72 }, { "175", 64 } } },
2104 { { { "350", 126 }, { "350", 128 }, { "350", 128 }, { "350", 128 } } },
2105 { { { "525", 180 }, { "525", 184 }, { "525", 184 }, { "525", 192 } } },
2106 { { { "700", 235 }, { "700", 240 }, { "700", 240 }, { "700", 255 } } },
2109 static const GraticuleLines millivolts9[] = {
2110 { { { "0", 32 }, { "0", 32 }, { "0", 32 }, { "0", 0 } } },
2111 { { { "175", 142 }, { "175", 144 }, { "175", 144 }, { "175", 128 } } },
2112 { { { "350", 251 }, { "350", 256 }, { "350", 256 }, { "350", 256 } } },
2113 { { { "525", 361 }, { "525", 368 }, { "525", 368 }, { "525", 384 } } },
2114 { { { "700", 470 }, { "700", 480 }, { "700", 480 }, { "700", 511 } } },
2117 static const GraticuleLines millivolts10[] = {
2118 { { { "0", 64 }, { "0", 64 }, { "0", 64 }, { "0", 0 } } },
2119 { { { "175", 283 }, { "175", 288 }, { "175", 288 }, { "175", 256 } } },
2120 { { { "350", 502 }, { "350", 512 }, { "350", 512 }, { "350", 512 } } },
2121 { { { "525", 721 }, { "525", 736 }, { "525", 736 }, { "525", 768 } } },
2122 { { { "700", 940 }, { "700", 960 }, { "700", 960 }, { "700", 1023 } } },
2125 static const GraticuleLines millivolts12[] = {
2126 { { { "0", 256 }, { "0", 256 }, { "0", 256 }, { "0", 0 } } },
2127 { { { "175", 1132 }, { "175", 1152 }, { "175", 1152 }, { "175", 1024 } } },
2128 { { { "350", 2008 }, { "350", 2048 }, { "350", 2048 }, { "350", 2048 } } },
2129 { { { "525", 2884 }, { "525", 2944 }, { "525", 2944 }, { "525", 3072 } } },
2130 { { { "700", 3760 }, { "700", 3840 }, { "700", 3840 }, { "700", 4095 } } },
2133 static const GraticuleLines ire8[] = {
2134 { { { "0", 16 }, { "0", 16 }, { "0", 16 }, { "0", 0 } } },
2135 { { { "25", 71 }, { "25", 72 }, { "25", 72 }, { "25", 64 } } },
2136 { { { "50", 126 }, { "50", 128 }, { "50", 128 }, { "50", 128 } } },
2137 { { { "75", 180 }, { "75", 184 }, { "75", 184 }, { "75", 192 } } },
2138 { { { "100", 235 }, { "100", 240 }, { "100", 240 }, { "100", 255 } } },
2141 static const GraticuleLines ire9[] = {
2142 { { { "0", 32 }, { "0", 32 }, { "0", 32 }, { "0", 0 } } },
2143 { { { "25", 142 }, { "25", 144 }, { "25", 144 }, { "25", 128 } } },
2144 { { { "50", 251 }, { "50", 256 }, { "50", 256 }, { "50", 256 } } },
2145 { { { "75", 361 }, { "75", 368 }, { "75", 368 }, { "75", 384 } } },
2146 { { { "100", 470 }, { "100", 480 }, { "100", 480 }, { "100", 511 } } },
2149 static const GraticuleLines ire10[] = {
2150 { { { "0", 64 }, { "0", 64 }, { "0", 64 }, { "0", 0 } } },
2151 { { { "25", 283 }, { "25", 288 }, { "25", 288 }, { "25", 256 } } },
2152 { { { "50", 502 }, { "50", 512 }, { "50", 512 }, { "50", 512 } } },
2153 { { { "75", 721 }, { "75", 736 }, { "75", 736 }, { "75", 768 } } },
2154 { { { "100", 940 }, { "100", 960 }, { "100", 960 }, { "100", 1023 } } },
2157 static const GraticuleLines ire12[] = {
2158 { { { "0", 256 }, { "0", 256 }, { "0", 256 }, { "0", 0 } } },
2159 { { { "25", 1132 }, { "25", 1152 }, { "25", 1152 }, { "25", 1024 } } },
2160 { { { "50", 2008 }, { "50", 2048 }, { "50", 2048 }, { "50", 2048 } } },
2161 { { { "75", 2884 }, { "75", 2944 }, { "75", 2944 }, { "75", 3072 } } },
2162 { { { "100", 3760 }, { "100", 3840 }, { "100", 3840 }, { "100", 4095 } } },
2165 static const GraticuleLines chroma_digital8[] = {
2166 { { { "50", 50 }, { "50", 50 }, { "50", 50 }, { "50", 50 } } },
2167 { { { "100", 100 }, { "100", 100 }, { "100", 100 }, { "100", 100 } } },
2168 { { { "150", 150 }, { "150", 150 }, { "150", 150 }, { "150", 150 } } },
2169 { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2170 { { { "255", 255 }, { "255", 255 }, { "255", 255 }, { "255", 255 } } },
2173 static const GraticuleLines chroma_digital9[] = {
2174 { { { "100", 100 }, { "100", 100 }, { "100", 100 }, { "100", 100 } } },
2175 { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2176 { { { "300", 300 }, { "300", 300 }, { "300", 300 }, { "300", 300 } } },
2177 { { { "400", 400 }, { "400", 400 }, { "400", 400 }, { "400", 400 } } },
2178 { { { "500", 500 }, { "500", 500 }, { "500", 500 }, { "500", 500 } } },
2181 static const GraticuleLines chroma_digital10[] = {
2182 { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2183 { { { "400", 400 }, { "400", 400 }, { "400", 400 }, { "400", 400 } } },
2184 { { { "600", 600 }, { "600", 600 }, { "600", 600 }, { "600", 600 } } },
2185 { { { "800", 800 }, { "800", 800 }, { "800", 800 }, { "800", 800 } } },
2186 { { {"1000",1000 }, {"1000",1000 }, {"1000",1000 }, {"1000",1000 } } },
2189 static const GraticuleLines chroma_digital12[] = {
2190 { { { "800", 800 }, { "800", 800 }, { "800", 800 }, { "800", 800 } } },
2191 { { { "1600", 1600 }, { "1600", 1600 }, { "1600", 1600 }, { "1600", 1600 } } },
2192 { { { "2400", 2400 }, { "2400", 2400 }, { "2400", 2400 }, { "2400", 2400 } } },
2193 { { { "3200", 3200 }, { "3200", 3200 }, { "3200", 3200 }, { "3200", 3200 } } },
2194 { { { "4000", 4000 }, { "4000", 4000 }, { "4000", 4000 }, { "4000", 4000 } } },
2197 static void blend_vline(uint8_t *dst, int height, int linesize, float o1, float o2, int v, int step)
2201 for (y = 0; y < height; y += step) {
2202 dst[0] = v * o1 + dst[0] * o2;
2204 dst += linesize * step;
2208 static void blend_vline16(uint16_t *dst, int height, int linesize, float o1, float o2, int v, int step)
2212 for (y = 0; y < height; y += step) {
2213 dst[0] = v * o1 + dst[0] * o2;
2215 dst += (linesize / 2) * step;
2219 static void blend_hline(uint8_t *dst, int width, float o1, float o2, int v, int step)
2223 for (x = 0; x < width; x += step) {
2224 dst[x] = v * o1 + dst[x] * o2;
2228 static void blend_hline16(uint16_t *dst, int width, float o1, float o2, int v, int step)
2232 for (x = 0; x < width; x += step) {
2233 dst[x] = v * o1 + dst[x] * o2;
2237 static void draw_htext(AVFrame *out, int x, int y, float o1, float o2, const char *txt, const uint8_t color[4])
2239 const uint8_t *font;
2243 font = avpriv_cga_font, font_height = 8;
2245 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2246 for (i = 0; txt[i]; i++) {
2248 int v = color[plane];
2250 uint8_t *p = out->data[plane] + y * out->linesize[plane] + (x + i * 8);
2251 for (char_y = 0; char_y < font_height; char_y++) {
2252 for (mask = 0x80; mask; mask >>= 1) {
2253 if (font[txt[i] * font_height + char_y] & mask)
2254 p[0] = p[0] * o2 + v * o1;
2257 p += out->linesize[plane] - 8;
2263 static void draw_htext16(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
2265 const uint8_t *font;
2269 font = avpriv_cga_font, font_height = 8;
2271 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2272 for (i = 0; txt[i]; i++) {
2274 int v = color[plane] * mult;
2276 uint16_t *p = (uint16_t *)(out->data[plane] + y * out->linesize[plane]) + (x + i * 8);
2277 for (char_y = 0; char_y < font_height; char_y++) {
2278 for (mask = 0x80; mask; mask >>= 1) {
2279 if (font[txt[i] * font_height + char_y] & mask)
2280 p[0] = p[0] * o2 + v * o1;
2283 p += out->linesize[plane] / 2 - 8;
2289 static void draw_vtext(AVFrame *out, int x, int y, float o1, float o2, const char *txt, const uint8_t color[4])
2291 const uint8_t *font;
2295 font = avpriv_cga_font, font_height = 8;
2297 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2298 for (i = 0; txt[i]; i++) {
2300 int v = color[plane];
2302 for (char_y = font_height - 1; char_y >= 0; char_y--) {
2303 uint8_t *p = out->data[plane] + (y + i * 10) * out->linesize[plane] + x;
2304 for (mask = 0x80; mask; mask >>= 1) {
2305 if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
2306 p[char_y] = p[char_y] * o2 + v * o1;
2307 p += out->linesize[plane];
2314 static void draw_vtext16(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
2316 const uint8_t *font;
2320 font = avpriv_cga_font, font_height = 8;
2322 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2323 for (i = 0; txt[i]; i++) {
2325 int v = color[plane] * mult;
2327 for (char_y = 0; char_y < font_height; char_y++) {
2328 uint16_t *p = (uint16_t *)(out->data[plane] + (y + i * 10) * out->linesize[plane]) + x;
2329 for (mask = 0x80; mask; mask >>= 1) {
2330 if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
2331 p[char_y] = p[char_y] * o2 + v * o1;
2332 p += out->linesize[plane] / 2;
2339 static void graticule_none(WaveformContext *s, AVFrame *out)
2343 static void graticule_row(WaveformContext *s, AVFrame *out)
2345 const int step = (s->flags & 2) + 1;
2346 const float o1 = s->opacity;
2347 const float o2 = 1. - o1;
2348 const int height = s->display == PARADE ? out->height / s->acomp : out->height;
2349 int k = 0, c, p, l, offset_x = 0, offset_y = 0;
2351 for (c = 0; c < s->ncomp; c++) {
2352 if (!((1 << c) & s->pcomp) || (!s->display && k > 0))
2356 for (p = 0; p < s->ncomp; p++) {
2357 const int v = s->grat_yuva_color[p];
2358 for (l = 0; l < s->nb_glines; l++) {
2359 const uint16_t pos = s->glines[l].line[c].pos;
2360 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos);
2361 uint8_t *dst = out->data[p] + offset_y * out->linesize[p] + x;
2363 blend_vline(dst, height, out->linesize[p], o1, o2, v, step);
2367 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2368 const char *name = s->glines[l].line[c].name;
2369 const uint16_t pos = s->glines[l].line[c].pos;
2370 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos) - 10;
2375 draw_vtext(out, x, offset_y + 2, o1, o2, name, s->grat_yuva_color);
2378 offset_x += s->size * (s->display == STACK);
2379 offset_y += height * (s->display == PARADE);
2383 static void graticule16_row(WaveformContext *s, AVFrame *out)
2385 const int step = (s->flags & 2) + 1;
2386 const float o1 = s->opacity;
2387 const float o2 = 1. - o1;
2388 const int mult = s->max / 256;
2389 const int height = s->display == PARADE ? out->height / s->acomp : out->height;
2390 int k = 0, c, p, l, offset_x = 0, offset_y = 0;
2392 for (c = 0; c < s->ncomp; c++) {
2393 if (!((1 << c) & s->pcomp) || (!s->display && k > 0))
2397 for (p = 0; p < s->ncomp; p++) {
2398 const int v = s->grat_yuva_color[p] * mult;
2399 for (l = 0; l < s->nb_glines ; l++) {
2400 const uint16_t pos = s->glines[l].line[c].pos;
2401 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos);
2402 uint16_t *dst = (uint16_t *)(out->data[p] + offset_y * out->linesize[p]) + x;
2404 blend_vline16(dst, height, out->linesize[p], o1, o2, v, step);
2408 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2409 const char *name = s->glines[l].line[c].name;
2410 const uint16_t pos = s->glines[l].line[c].pos;
2411 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos) - 10;
2416 draw_vtext16(out, x, offset_y + 2, mult, o1, o2, name, s->grat_yuva_color);
2419 offset_x += s->size * (s->display == STACK);
2420 offset_y += height * (s->display == PARADE);
2424 static void graticule_column(WaveformContext *s, AVFrame *out)
2426 const int step = (s->flags & 2) + 1;
2427 const float o1 = s->opacity;
2428 const float o2 = 1. - o1;
2429 const int width = s->display == PARADE ? out->width / s->acomp : out->width;
2430 int k = 0, c, p, l, offset_y = 0, offset_x = 0;
2432 for (c = 0; c < s->ncomp; c++) {
2433 if ((!((1 << c) & s->pcomp) || (!s->display && k > 0)))
2437 for (p = 0; p < s->ncomp; p++) {
2438 const int v = s->grat_yuva_color[p];
2439 for (l = 0; l < s->nb_glines ; l++) {
2440 const uint16_t pos = s->glines[l].line[c].pos;
2441 int y = offset_y + (s->mirror ? s->size - 1 - pos : pos);
2442 uint8_t *dst = out->data[p] + y * out->linesize[p] + offset_x;
2444 blend_hline(dst, width, o1, o2, v, step);
2448 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2449 const char *name = s->glines[l].line[c].name;
2450 const uint16_t pos = s->glines[l].line[c].pos;
2451 int y = offset_y + (s->mirror ? s->size - 1 - pos : pos) - 10;
2456 draw_htext(out, 2 + offset_x, y, o1, o2, name, s->grat_yuva_color);
2459 offset_y += s->size * (s->display == STACK);
2460 offset_x += width * (s->display == PARADE);
2464 static void graticule16_column(WaveformContext *s, AVFrame *out)
2466 const int step = (s->flags & 2) + 1;
2467 const float o1 = s->opacity;
2468 const float o2 = 1. - o1;
2469 const int mult = s->max / 256;
2470 const int width = s->display == PARADE ? out->width / s->acomp : out->width;
2471 int k = 0, c, p, l, offset_x = 0, offset_y = 0;
2473 for (c = 0; c < s->ncomp; c++) {
2474 if ((!((1 << c) & s->pcomp) || (!s->display && k > 0)))
2478 for (p = 0; p < s->ncomp; p++) {
2479 const int v = s->grat_yuva_color[p] * mult;
2480 for (l = 0; l < s->nb_glines ; l++) {
2481 const uint16_t pos = s->glines[l].line[c].pos;
2482 int y = offset_y + (s->mirror ? s->size - 1 - pos : pos);
2483 uint16_t *dst = (uint16_t *)(out->data[p] + y * out->linesize[p]) + offset_x;
2485 blend_hline16(dst, width, o1, o2, v, step);
2489 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2490 const char *name = s->glines[l].line[c].name;
2491 const uint16_t pos = s->glines[l].line[c].pos;
2492 int y = offset_y + (s->mirror ? s->size - 1 - pos: pos) - 10;
2497 draw_htext16(out, 2 + offset_x, y, mult, o1, o2, name, s->grat_yuva_color);
2500 offset_y += s->size * (s->display == STACK);
2501 offset_x += width * (s->display == PARADE);
2505 static int config_input(AVFilterLink *inlink)
2507 AVFilterContext *ctx = inlink->dst;
2508 WaveformContext *s = ctx->priv;
2510 s->desc = av_pix_fmt_desc_get(inlink->format);
2511 s->ncomp = s->desc->nb_components;
2512 s->bits = s->desc->comp[0].depth;
2513 s->max = 1 << s->bits;
2514 s->intensity = s->fintensity * (s->max - 1);
2516 s->shift_w[0] = s->shift_w[3] = 0;
2517 s->shift_h[0] = s->shift_h[3] = 0;
2518 s->shift_w[1] = s->shift_w[2] = s->desc->log2_chroma_w;
2519 s->shift_h[1] = s->shift_h[2] = s->desc->log2_chroma_h;
2521 s->graticulef = graticule_none;
2523 switch (s->filter) {
2525 case AFLAT: s->size = 256 * 2; break;
2526 case FLAT: s->size = 256 * 3; break;
2527 default: s->size = 256; break;
2530 switch (s->filter | ((s->bits > 8) << 4) |
2531 (s->mode << 8) | (s->mirror << 12)) {
2532 case 0x1100: s->waveform = lowpass_column_mirror; break;
2533 case 0x1000: s->waveform = lowpass_row_mirror; break;
2534 case 0x0100: s->waveform = lowpass_column; break;
2535 case 0x0000: s->waveform = lowpass_row; break;
2536 case 0x1110: s->waveform = lowpass16_column_mirror; break;
2537 case 0x1010: s->waveform = lowpass16_row_mirror; break;
2538 case 0x0110: s->waveform = lowpass16_column; break;
2539 case 0x0010: s->waveform = lowpass16_row; break;
2543 case 0x0001: s->waveform = flat; break;
2547 case 0x0011: s->waveform = flat16; break;
2548 case 0x1102: s->waveform = aflat_column_mirror; break;
2549 case 0x1002: s->waveform = aflat_row_mirror; break;
2550 case 0x0102: s->waveform = aflat_column; break;
2551 case 0x0002: s->waveform = aflat_row; break;
2552 case 0x1112: s->waveform = aflat16_column_mirror; break;
2553 case 0x1012: s->waveform = aflat16_row_mirror; break;
2554 case 0x0112: s->waveform = aflat16_column; break;
2555 case 0x0012: s->waveform = aflat16_row; break;
2559 case 0x0003: s->waveform = chroma; break;
2563 case 0x0013: s->waveform = chroma16; break;
2567 case 0x0004: s->waveform = color; break;
2571 case 0x0014: s->waveform = color16; break;
2575 case 0x0005: s->waveform = acolor; break;
2579 case 0x0015: s->waveform = acolor16; break;
2580 case 0x1106: s->waveform = xflat_column_mirror; break;
2581 case 0x1006: s->waveform = xflat_row_mirror; break;
2582 case 0x0106: s->waveform = xflat_column; break;
2583 case 0x0006: s->waveform = xflat_row; break;
2584 case 0x1116: s->waveform = xflat16_column_mirror; break;
2585 case 0x1016: s->waveform = xflat16_row_mirror; break;
2586 case 0x0116: s->waveform = xflat16_column; break;
2587 case 0x0016: s->waveform = xflat16_row; break;
2590 s->grat_yuva_color[0] = 255;
2591 s->grat_yuva_color[2] = s->graticule == 2 ? 255 : 0;
2592 s->grat_yuva_color[3] = 255;
2594 switch (s->filter) {
2602 if (s->graticule && s->mode == 1)
2603 s->graticulef = s->bits > 8 ? graticule16_column : graticule_column;
2604 else if (s->graticule && s->mode == 0)
2605 s->graticulef = s->bits > 8 ? graticule16_row : graticule_row;
2609 switch (s->filter) {
2616 case 8: s->glines = (GraticuleLines *)digital8; s->nb_glines = FF_ARRAY_ELEMS(digital8); break;
2617 case 9: s->glines = (GraticuleLines *)digital9; s->nb_glines = FF_ARRAY_ELEMS(digital9); break;
2618 case 10: s->glines = (GraticuleLines *)digital10; s->nb_glines = FF_ARRAY_ELEMS(digital10); break;
2619 case 12: s->glines = (GraticuleLines *)digital12; s->nb_glines = FF_ARRAY_ELEMS(digital12); break;
2624 case 8: s->glines = (GraticuleLines *)millivolts8; s->nb_glines = FF_ARRAY_ELEMS(millivolts8); break;
2625 case 9: s->glines = (GraticuleLines *)millivolts9; s->nb_glines = FF_ARRAY_ELEMS(millivolts9); break;
2626 case 10: s->glines = (GraticuleLines *)millivolts10; s->nb_glines = FF_ARRAY_ELEMS(millivolts10); break;
2627 case 12: s->glines = (GraticuleLines *)millivolts12; s->nb_glines = FF_ARRAY_ELEMS(millivolts12); break;
2632 case 8: s->glines = (GraticuleLines *)ire8; s->nb_glines = FF_ARRAY_ELEMS(ire8); break;
2633 case 9: s->glines = (GraticuleLines *)ire9; s->nb_glines = FF_ARRAY_ELEMS(ire9); break;
2634 case 10: s->glines = (GraticuleLines *)ire10; s->nb_glines = FF_ARRAY_ELEMS(ire10); break;
2635 case 12: s->glines = (GraticuleLines *)ire12; s->nb_glines = FF_ARRAY_ELEMS(ire12); break;
2644 case 8: s->glines = (GraticuleLines *)chroma_digital8; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital8); break;
2645 case 9: s->glines = (GraticuleLines *)chroma_digital9; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital9); break;
2646 case 10: s->glines = (GraticuleLines *)chroma_digital10; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital10); break;
2647 case 12: s->glines = (GraticuleLines *)chroma_digital12; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital12); break;
2652 case 8: s->glines = (GraticuleLines *)millivolts8; s->nb_glines = FF_ARRAY_ELEMS(millivolts8); break;
2653 case 9: s->glines = (GraticuleLines *)millivolts9; s->nb_glines = FF_ARRAY_ELEMS(millivolts9); break;
2654 case 10: s->glines = (GraticuleLines *)millivolts10; s->nb_glines = FF_ARRAY_ELEMS(millivolts10); break;
2655 case 12: s->glines = (GraticuleLines *)millivolts12; s->nb_glines = FF_ARRAY_ELEMS(millivolts12); break;
2660 case 8: s->glines = (GraticuleLines *)ire8; s->nb_glines = FF_ARRAY_ELEMS(ire8); break;
2661 case 9: s->glines = (GraticuleLines *)ire9; s->nb_glines = FF_ARRAY_ELEMS(ire9); break;
2662 case 10: s->glines = (GraticuleLines *)ire10; s->nb_glines = FF_ARRAY_ELEMS(ire10); break;
2663 case 12: s->glines = (GraticuleLines *)ire12; s->nb_glines = FF_ARRAY_ELEMS(ire12); break;
2673 case 8: s->glines = (GraticuleLines *)aflat_digital8; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital8); break;
2674 case 9: s->glines = (GraticuleLines *)aflat_digital9; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital9); break;
2675 case 10: s->glines = (GraticuleLines *)aflat_digital10; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital10); break;
2676 case 12: s->glines = (GraticuleLines *)aflat_digital12; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital12); break;
2681 case 8: s->glines = (GraticuleLines *)aflat_millivolts8; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts8); break;
2682 case 9: s->glines = (GraticuleLines *)aflat_millivolts9; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts9); break;
2683 case 10: s->glines = (GraticuleLines *)aflat_millivolts10; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts10); break;
2684 case 12: s->glines = (GraticuleLines *)aflat_millivolts12; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts12); break;
2689 case 8: s->glines = (GraticuleLines *)aflat_ire8; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire8); break;
2690 case 9: s->glines = (GraticuleLines *)aflat_ire9; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire9); break;
2691 case 10: s->glines = (GraticuleLines *)aflat_ire10; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire10); break;
2692 case 12: s->glines = (GraticuleLines *)aflat_ire12; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire12); break;
2701 case 8: s->glines = (GraticuleLines *)flat_digital8; s->nb_glines = FF_ARRAY_ELEMS(flat_digital8); break;
2702 case 9: s->glines = (GraticuleLines *)flat_digital9; s->nb_glines = FF_ARRAY_ELEMS(flat_digital9); break;
2703 case 10: s->glines = (GraticuleLines *)flat_digital10; s->nb_glines = FF_ARRAY_ELEMS(flat_digital10); break;
2704 case 12: s->glines = (GraticuleLines *)flat_digital12; s->nb_glines = FF_ARRAY_ELEMS(flat_digital12); break;
2709 case 8: s->glines = (GraticuleLines *)flat_millivolts8; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts8); break;
2710 case 9: s->glines = (GraticuleLines *)flat_millivolts9; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts9); break;
2711 case 10: s->glines = (GraticuleLines *)flat_millivolts10; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts10); break;
2712 case 12: s->glines = (GraticuleLines *)flat_millivolts12; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts12); break;
2717 case 8: s->glines = (GraticuleLines *)flat_ire8; s->nb_glines = FF_ARRAY_ELEMS(flat_ire8); break;
2718 case 9: s->glines = (GraticuleLines *)flat_ire9; s->nb_glines = FF_ARRAY_ELEMS(flat_ire9); break;
2719 case 10: s->glines = (GraticuleLines *)flat_ire10; s->nb_glines = FF_ARRAY_ELEMS(flat_ire10); break;
2720 case 12: s->glines = (GraticuleLines *)flat_ire12; s->nb_glines = FF_ARRAY_ELEMS(flat_ire12); break;
2727 s->size = s->size << (s->bits - 8);
2729 switch (inlink->format) {
2730 case AV_PIX_FMT_GBRAP:
2731 case AV_PIX_FMT_GBRP:
2732 case AV_PIX_FMT_GBRP9:
2733 case AV_PIX_FMT_GBRP10:
2734 case AV_PIX_FMT_GBRP12:
2735 memcpy(s->bg_color, black_gbrp_color, sizeof(s->bg_color));
2736 s->graticulef = graticule_none;
2739 memcpy(s->bg_color, black_yuva_color, sizeof(s->bg_color));
2742 s->bg_color[3] *= s->bgopacity;
2747 static int config_output(AVFilterLink *outlink)
2749 AVFilterContext *ctx = outlink->src;
2750 AVFilterLink *inlink = ctx->inputs[0];
2751 WaveformContext *s = ctx->priv;
2752 int comp = 0, i, j = 0, k, p, size;
2754 for (i = 0; i < s->ncomp; i++) {
2755 if ((1 << i) & s->pcomp)
2759 s->odesc = av_pix_fmt_desc_get(outlink->format);
2760 s->dcomp = s->odesc->nb_components;
2765 outlink->h = s->size * FFMAX(comp * (s->display == STACK), 1);
2766 outlink->w = inlink->w * FFMAX(comp * (s->display == PARADE), 1);
2769 outlink->w = s->size * FFMAX(comp * (s->display == STACK), 1);
2770 outlink->h = inlink->h * FFMAX(comp * (s->display == PARADE), 1);
2774 s->peak = av_malloc_array(size, 32 * sizeof(*s->peak));
2776 return AVERROR(ENOMEM);
2778 for (p = 0; p < s->ncomp; p++) {
2779 const int plane = s->desc->comp[p].plane;
2782 if (!((1 << p) & s->pcomp))
2785 for (k = 0; k < 4; k++) {
2786 s->emax[plane][k] = s->peak + size * (plane * 4 + k + 0);
2787 s->emin[plane][k] = s->peak + size * (plane * 4 + k + 16);
2790 offset = j++ * s->size * (s->display == STACK);
2791 s->estart[plane] = offset;
2792 s->eend[plane] = (offset + s->size - 1);
2793 for (i = 0; i < size; i++) {
2794 for (k = 0; k < 4; k++) {
2795 s->emax[plane][k][i] = s->estart[plane];
2796 s->emin[plane][k][i] = s->eend[plane];
2801 outlink->sample_aspect_ratio = (AVRational){1,1};
2806 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
2808 AVFilterContext *ctx = inlink->dst;
2809 WaveformContext *s = ctx->priv;
2810 AVFilterLink *outlink = ctx->outputs[0];
2814 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
2817 return AVERROR(ENOMEM);
2820 out->color_range = AVCOL_RANGE_JPEG;
2822 for (k = 0; k < s->dcomp; k++) {
2824 for (i = 0; i < outlink->h ; i++)
2825 memset(out->data[s->odesc->comp[k].plane] +
2826 i * out->linesize[s->odesc->comp[k].plane],
2827 s->bg_color[k], outlink->w);
2829 const int mult = s->max / 256;
2830 uint16_t *dst = (uint16_t *)out->data[s->odesc->comp[k].plane];
2832 for (i = 0; i < outlink->h ; i++) {
2833 for (j = 0; j < outlink->w; j++)
2834 dst[j] = s->bg_color[k] * mult;
2835 dst += out->linesize[s->odesc->comp[k].plane] / 2;
2840 for (k = 0, i = 0; k < s->ncomp; k++) {
2841 if ((1 << k) & s->pcomp) {
2845 if (s->display == PARADE) {
2846 offset_x = s->mode ? i++ * inlink->w : 0;
2847 offset_y = s->mode ? 0 : i++ * inlink->h;
2849 offset_y = s->mode ? i++ * s->size * !!s->display : 0;
2850 offset_x = s->mode ? 0 : i++ * s->size * !!s->display;
2852 s->waveform(s, in, out, k, s->intensity, offset_y, offset_x, s->mode, s->mirror);
2855 s->graticulef(s, out);
2858 return ff_filter_frame(outlink, out);
2861 static av_cold void uninit(AVFilterContext *ctx)
2863 WaveformContext *s = ctx->priv;
2868 static const AVFilterPad inputs[] = {
2871 .type = AVMEDIA_TYPE_VIDEO,
2872 .filter_frame = filter_frame,
2873 .config_props = config_input,
2878 static const AVFilterPad outputs[] = {
2881 .type = AVMEDIA_TYPE_VIDEO,
2882 .config_props = config_output,
2887 AVFilter ff_vf_waveform = {
2889 .description = NULL_IF_CONFIG_SMALL("Video waveform monitor."),
2890 .priv_size = sizeof(WaveformContext),
2891 .priv_class = &waveform_class,
2892 .query_formats = query_formats,