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"
56 typedef struct GraticuleLine {
61 typedef struct GraticuleLines {
62 struct GraticuleLine line[4];
65 typedef struct WaveformContext {
92 int shift_w[4], shift_h[4];
93 GraticuleLines *glines;
95 void (*waveform)(struct WaveformContext *s,
96 AVFrame *in, AVFrame *out,
97 int component, int intensity,
98 int offset_y, int offset_x,
99 int column, int mirror);
100 void (*graticulef)(struct WaveformContext *s, AVFrame *out);
101 const AVPixFmtDescriptor *desc;
102 const AVPixFmtDescriptor *odesc;
105 #define OFFSET(x) offsetof(WaveformContext, x)
106 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
108 static const AVOption waveform_options[] = {
109 { "mode", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "mode" },
110 { "m", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "mode" },
111 { "row", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "mode" },
112 { "column", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "mode" },
113 { "intensity", "set intensity", OFFSET(fintensity), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 1, FLAGS },
114 { "i", "set intensity", OFFSET(fintensity), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 1, FLAGS },
115 { "mirror", "set mirroring", OFFSET(mirror), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
116 { "r", "set mirroring", OFFSET(mirror), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
117 { "display", "set display mode", OFFSET(display), AV_OPT_TYPE_INT, {.i64=STACK}, 0, NB_DISPLAYS-1, FLAGS, "display" },
118 { "d", "set display mode", OFFSET(display), AV_OPT_TYPE_INT, {.i64=STACK}, 0, NB_DISPLAYS-1, FLAGS, "display" },
119 { "overlay", NULL, 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY}, 0, 0, FLAGS, "display" },
120 { "stack", NULL, 0, AV_OPT_TYPE_CONST, {.i64=STACK}, 0, 0, FLAGS, "display" },
121 { "parade", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PARADE}, 0, 0, FLAGS, "display" },
122 { "components", "set components to display", OFFSET(pcomp), AV_OPT_TYPE_INT, {.i64=1}, 1, 15, FLAGS },
123 { "c", "set components to display", OFFSET(pcomp), AV_OPT_TYPE_INT, {.i64=1}, 1, 15, FLAGS },
124 { "envelope", "set envelope to display", OFFSET(envelope), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "envelope" },
125 { "e", "set envelope to display", OFFSET(envelope), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "envelope" },
126 { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "envelope" },
127 { "instant", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "envelope" },
128 { "peak", NULL, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "envelope" },
129 { "peak+instant", NULL, 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, FLAGS, "envelope" },
130 { "filter", "set filter", OFFSET(filter), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_FILTERS-1, FLAGS, "filter" },
131 { "f", "set filter", OFFSET(filter), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_FILTERS-1, FLAGS, "filter" },
132 { "lowpass", NULL, 0, AV_OPT_TYPE_CONST, {.i64=LOWPASS}, 0, 0, FLAGS, "filter" },
133 { "flat" , NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAT}, 0, 0, FLAGS, "filter" },
134 { "aflat" , NULL, 0, AV_OPT_TYPE_CONST, {.i64=AFLAT}, 0, 0, FLAGS, "filter" },
135 { "chroma", NULL, 0, AV_OPT_TYPE_CONST, {.i64=CHROMA}, 0, 0, FLAGS, "filter" },
136 { "color", NULL, 0, AV_OPT_TYPE_CONST, {.i64=COLOR}, 0, 0, FLAGS, "filter" },
137 { "acolor", NULL, 0, AV_OPT_TYPE_CONST, {.i64=ACOLOR}, 0, 0, FLAGS, "filter" },
138 { "graticule", "set graticule", OFFSET(graticule), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "graticule" },
139 { "g", "set graticule", OFFSET(graticule), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "graticule" },
140 { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "graticule" },
141 { "green", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "graticule" },
142 { "opacity", "set graticule opacity", OFFSET(opacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
143 { "o", "set graticule opacity", OFFSET(opacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
144 { "flags", "set graticule flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64=1}, 0, 3, FLAGS, "flags" },
145 { "fl", "set graticule flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64=1}, 0, 3, FLAGS, "flags" },
146 { "numbers", "draw numbers", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "flags" },
147 { "dots", "draw dots instead of lines", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "flags" },
148 { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SCALES-1, FLAGS, "scale" },
149 { "s", "set scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SCALES-1, FLAGS, "scale" },
150 { "digital", NULL, 0, AV_OPT_TYPE_CONST, {.i64=DIGITAL}, 0, 0, FLAGS, "scale" },
151 { "millivolts", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MILLIVOLTS}, 0, 0, FLAGS, "scale" },
152 { "ire", NULL, 0, AV_OPT_TYPE_CONST, {.i64=IRE}, 0, 0, FLAGS, "scale" },
153 { "bgopacity", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
154 { "b", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
158 AVFILTER_DEFINE_CLASS(waveform);
160 static const enum AVPixelFormat in_lowpass_pix_fmts[] = {
161 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
162 AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12,
163 AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
164 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
165 AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P,
166 AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
167 AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
168 AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
169 AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY9, AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12,
170 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9,
171 AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9,
172 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10,
173 AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10,
174 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV440P12,
178 static const enum AVPixelFormat in_color_pix_fmts[] = {
179 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
180 AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12,
181 AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
182 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
184 AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
185 AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
186 AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
187 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9,
188 AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9,
189 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10,
190 AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10,
191 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV440P12,
195 static const enum AVPixelFormat in_flat_pix_fmts[] = {
196 AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
197 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
199 AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
200 AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
201 AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
202 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9,
203 AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9,
204 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10,
205 AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10,
206 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV440P12,
210 static const enum AVPixelFormat out_rgb8_lowpass_pix_fmts[] = {
211 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
215 static const enum AVPixelFormat out_rgb9_lowpass_pix_fmts[] = {
220 static const enum AVPixelFormat out_rgb10_lowpass_pix_fmts[] = {
221 AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10,
225 static const enum AVPixelFormat out_rgb12_lowpass_pix_fmts[] = {
226 AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12,
230 static const enum AVPixelFormat out_yuv8_lowpass_pix_fmts[] = {
231 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVA444P,
235 static const enum AVPixelFormat out_yuv9_lowpass_pix_fmts[] = {
236 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUVA444P9,
240 static const enum AVPixelFormat out_yuv10_lowpass_pix_fmts[] = {
241 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUVA444P10,
245 static const enum AVPixelFormat out_yuv12_lowpass_pix_fmts[] = {
246 AV_PIX_FMT_YUV444P12,
250 static const enum AVPixelFormat out_gray8_lowpass_pix_fmts[] = {
255 static const enum AVPixelFormat out_gray9_lowpass_pix_fmts[] = {
260 static const enum AVPixelFormat out_gray10_lowpass_pix_fmts[] = {
265 static const enum AVPixelFormat out_gray12_lowpass_pix_fmts[] = {
270 static const enum AVPixelFormat flat_pix_fmts[] = {
271 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P,
272 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV444P10,
273 AV_PIX_FMT_YUV444P12,
277 static int query_formats(AVFilterContext *ctx)
279 WaveformContext *s = ctx->priv;
280 const enum AVPixelFormat *out_pix_fmts;
281 const enum AVPixelFormat *in_pix_fmts;
282 const AVPixFmtDescriptor *desc;
283 AVFilterFormats *avff;
284 int depth, rgb, i, ret, ncomp;
286 if (!ctx->inputs[0]->in_formats ||
287 !ctx->inputs[0]->in_formats->nb_formats) {
288 return AVERROR(EAGAIN);
292 case LOWPASS: in_pix_fmts = in_lowpass_pix_fmts; break;
295 case FLAT: in_pix_fmts = in_flat_pix_fmts; break;
297 case COLOR: in_pix_fmts = in_color_pix_fmts; break;
300 if (!ctx->inputs[0]->out_formats) {
301 if ((ret = ff_formats_ref(ff_make_format_list(in_pix_fmts), &ctx->inputs[0]->out_formats)) < 0)
305 avff = ctx->inputs[0]->in_formats;
306 desc = av_pix_fmt_desc_get(avff->formats[0]);
307 ncomp = desc->nb_components;
308 rgb = desc->flags & AV_PIX_FMT_FLAG_RGB;
309 depth = desc->comp[0].depth;
310 for (i = 1; i < avff->nb_formats; i++) {
311 desc = av_pix_fmt_desc_get(avff->formats[i]);
312 if (rgb != (desc->flags & AV_PIX_FMT_FLAG_RGB) ||
313 depth != desc->comp[0].depth)
314 return AVERROR(EAGAIN);
317 if (s->filter == LOWPASS && ncomp == 1 && depth == 8)
318 out_pix_fmts = out_gray8_lowpass_pix_fmts;
319 else if (s->filter == LOWPASS && ncomp == 1 && depth == 9)
320 out_pix_fmts = out_gray9_lowpass_pix_fmts;
321 else if (s->filter == LOWPASS && ncomp == 1 && depth == 10)
322 out_pix_fmts = out_gray10_lowpass_pix_fmts;
323 else if (s->filter == LOWPASS && ncomp == 1 && depth == 12)
324 out_pix_fmts = out_gray12_lowpass_pix_fmts;
325 else if (rgb && depth == 8 && ncomp > 2)
326 out_pix_fmts = out_rgb8_lowpass_pix_fmts;
327 else if (rgb && depth == 9 && ncomp > 2)
328 out_pix_fmts = out_rgb9_lowpass_pix_fmts;
329 else if (rgb && depth == 10 && ncomp > 2)
330 out_pix_fmts = out_rgb10_lowpass_pix_fmts;
331 else if (rgb && depth == 12 && ncomp > 2)
332 out_pix_fmts = out_rgb12_lowpass_pix_fmts;
333 else if (depth == 8 && ncomp > 2)
334 out_pix_fmts = out_yuv8_lowpass_pix_fmts;
335 else if (depth == 9 && ncomp > 2)
336 out_pix_fmts = out_yuv9_lowpass_pix_fmts;
337 else if (depth == 10 && ncomp > 2)
338 out_pix_fmts = out_yuv10_lowpass_pix_fmts;
339 else if (depth == 12 && ncomp > 2)
340 out_pix_fmts = out_yuv12_lowpass_pix_fmts;
342 return AVERROR(EAGAIN);
343 if ((ret = ff_formats_ref(ff_make_format_list(out_pix_fmts), &ctx->outputs[0]->in_formats)) < 0)
349 static void envelope_instant16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
351 const int dst_linesize = out->linesize[component] / 2;
352 const int bg = s->bg_color[component] * (s->max / 256);
353 const int limit = s->max - 1;
354 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
355 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
356 const int start = s->estart[plane];
357 const int end = s->eend[plane];
362 for (x = offset; x < offset + dst_w; x++) {
363 for (y = start; y < end; y++) {
364 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
370 for (y = end - 1; y >= start; y--) {
371 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
379 for (y = offset; y < offset + dst_h; y++) {
380 dst = (uint16_t *)out->data[component] + y * dst_linesize;
381 for (x = start; x < end; x++) {
387 for (x = end - 1; x >= start; x--) {
397 static void envelope_instant(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
399 const int dst_linesize = out->linesize[component];
400 const uint8_t bg = s->bg_color[component];
401 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
402 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
403 const int start = s->estart[plane];
404 const int end = s->eend[plane];
409 for (x = offset; x < offset + dst_w; x++) {
410 for (y = start; y < end; y++) {
411 dst = out->data[component] + y * dst_linesize + x;
417 for (y = end - 1; y >= start; y--) {
418 dst = out->data[component] + y * dst_linesize + x;
426 for (y = offset; y < offset + dst_h; y++) {
427 dst = out->data[component] + y * dst_linesize;
428 for (x = start; x < end; x++) {
434 for (x = end - 1; x >= start; x--) {
444 static void envelope_peak16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
446 const int dst_linesize = out->linesize[component] / 2;
447 const int bg = s->bg_color[component] * (s->max / 256);
448 const int limit = s->max - 1;
449 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
450 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
451 const int start = s->estart[plane];
452 const int end = s->eend[plane];
453 int *emax = s->emax[plane][component];
454 int *emin = s->emin[plane][component];
459 for (x = offset; x < offset + dst_w; x++) {
460 for (y = start; y < end && y < emin[x - offset]; y++) {
461 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
463 emin[x - offset] = y;
467 for (y = end - 1; y >= start && y >= emax[x - offset]; y--) {
468 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
470 emax[x - offset] = y;
476 if (s->envelope == 3)
477 envelope_instant16(s, out, plane, component, offset);
479 for (x = offset; x < offset + dst_w; x++) {
480 dst = (uint16_t *)out->data[component] + emin[x - offset] * dst_linesize + x;
482 dst = (uint16_t *)out->data[component] + emax[x - offset] * dst_linesize + x;
486 for (y = offset; y < offset + dst_h; y++) {
487 dst = (uint16_t *)out->data[component] + y * dst_linesize;
488 for (x = start; x < end && x < emin[y - offset]; x++) {
490 emin[y - offset] = x;
494 for (x = end - 1; x >= start && x >= emax[y - offset]; x--) {
496 emax[y - offset] = x;
502 if (s->envelope == 3)
503 envelope_instant16(s, out, plane, component, offset);
505 for (y = offset; y < offset + dst_h; y++) {
506 dst = (uint16_t *)out->data[component] + y * dst_linesize + emin[y - offset];
508 dst = (uint16_t *)out->data[component] + y * dst_linesize + emax[y - offset];
514 static void envelope_peak(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
516 const int dst_linesize = out->linesize[component];
517 const int bg = s->bg_color[component];
518 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
519 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
520 const int start = s->estart[plane];
521 const int end = s->eend[plane];
522 int *emax = s->emax[plane][component];
523 int *emin = s->emin[plane][component];
528 for (x = offset; x < offset + dst_w; x++) {
529 for (y = start; y < end && y < emin[x - offset]; y++) {
530 dst = out->data[component] + y * dst_linesize + x;
532 emin[x - offset] = y;
536 for (y = end - 1; y >= start && y >= emax[x - offset]; y--) {
537 dst = out->data[component] + y * dst_linesize + x;
539 emax[x - offset] = y;
545 if (s->envelope == 3)
546 envelope_instant(s, out, plane, component, offset);
548 for (x = offset; x < offset + dst_w; x++) {
549 dst = out->data[component] + emin[x - offset] * dst_linesize + x;
551 dst = out->data[component] + emax[x - offset] * dst_linesize + x;
555 for (y = offset; y < offset + dst_h; y++) {
556 dst = out->data[component] + y * dst_linesize;
557 for (x = start; x < end && x < emin[y - offset]; x++) {
559 emin[y - offset] = x;
563 for (x = end - 1; x >= start && x >= emax[y - offset]; x--) {
565 emax[y - offset] = x;
571 if (s->envelope == 3)
572 envelope_instant(s, out, plane, component, offset);
574 for (y = offset; y < offset + dst_h; y++) {
575 dst = out->data[component] + y * dst_linesize + emin[y - offset];
577 dst = out->data[component] + y * dst_linesize + emax[y - offset];
583 static void envelope16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
585 if (s->envelope == 0) {
587 } else if (s->envelope == 1) {
588 envelope_instant16(s, out, plane, component, offset);
590 envelope_peak16(s, out, plane, component, offset);
594 static void envelope(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
596 if (s->envelope == 0) {
598 } else if (s->envelope == 1) {
599 envelope_instant(s, out, plane, component, offset);
601 envelope_peak(s, out, plane, component, offset);
605 static void update16(uint16_t *target, int max, int intensity, int limit)
608 *target += intensity;
613 static void update(uint8_t *target, int max, int intensity)
616 *target += intensity;
621 static av_always_inline void lowpass16(WaveformContext *s,
622 AVFrame *in, AVFrame *out,
623 int component, int intensity,
624 int offset_y, int offset_x,
625 int column, int mirror)
627 const int plane = s->desc->comp[component].plane;
628 const int shift_w = s->shift_w[component];
629 const int shift_h = s->shift_h[component];
630 const int src_linesize = in->linesize[plane] / 2;
631 const int dst_linesize = out->linesize[plane] / 2;
632 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
633 const int limit = s->max - 1;
634 const int max = limit - intensity;
635 const int src_h = AV_CEIL_RSHIFT(in->height, shift_h);
636 const int src_w = AV_CEIL_RSHIFT(in->width, shift_w);
637 const uint16_t *src_data = (const uint16_t *)in->data[plane];
638 uint16_t *dst_data = (uint16_t *)out->data[plane] + offset_y * dst_linesize + offset_x;
639 uint16_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
640 uint16_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
641 const int step = column ? 1 << shift_w : 1 << shift_h;
645 if (!column && mirror)
648 for (y = 0; y < src_h; y++) {
649 const uint16_t *src_data_end = src_data + src_w;
650 uint16_t *dst = dst_line;
652 for (p = src_data; p < src_data_end; p++) {
654 int i = 0, v = FFMIN(*p, limit);
658 target = dst++ + dst_signed_linesize * v;
659 update16(target, max, intensity, limit);
660 } while (++i < step);
662 uint16_t *row = dst_data;
665 target = row - v - 1;
668 update16(target, max, intensity, limit);
670 } while (++i < step);
673 src_data += src_linesize;
674 dst_data += dst_linesize * step;
677 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
680 #define LOWPASS16_FUNC(name, column, mirror) \
681 static void lowpass16_##name(WaveformContext *s, \
682 AVFrame *in, AVFrame *out, \
683 int component, int intensity, \
684 int offset_y, int offset_x, \
685 int unused1, int unused2) \
687 lowpass16(s, in, out, component, intensity, \
688 offset_y, offset_x, column, mirror); \
691 LOWPASS16_FUNC(column_mirror, 1, 1)
692 LOWPASS16_FUNC(column, 1, 0)
693 LOWPASS16_FUNC(row_mirror, 0, 1)
694 LOWPASS16_FUNC(row, 0, 0)
696 static av_always_inline void lowpass(WaveformContext *s,
697 AVFrame *in, AVFrame *out,
698 int component, int intensity,
699 int offset_y, int offset_x,
700 int column, int mirror)
702 const int plane = s->desc->comp[component].plane;
703 const int shift_w = s->shift_w[component];
704 const int shift_h = s->shift_h[component];
705 const int src_linesize = in->linesize[plane];
706 const int dst_linesize = out->linesize[plane];
707 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
708 const int max = 255 - intensity;
709 const int src_h = AV_CEIL_RSHIFT(in->height, shift_h);
710 const int src_w = AV_CEIL_RSHIFT(in->width, shift_w);
711 const uint8_t *src_data = in->data[plane];
712 uint8_t *dst_data = out->data[plane] + offset_y * dst_linesize + offset_x;
713 uint8_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
714 uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
715 const int step = column ? 1 << shift_w : 1 << shift_h;
719 if (!column && mirror)
722 for (y = 0; y < src_h; y++) {
723 const uint8_t *src_data_end = src_data + src_w;
724 uint8_t *dst = dst_line;
726 for (p = src_data; p < src_data_end; p++) {
729 target = dst + dst_signed_linesize * *p;
731 update(target, max, intensity);
733 uint8_t *row = dst_data;
735 target = row - *p - 1;
738 update(target, max, intensity);
742 src_data += src_linesize;
743 dst_data += dst_linesize * step;
746 if (column && step > 1) {
747 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
748 const int dst_h = 256;
752 dst = out->data[plane] + offset_y * dst_linesize + offset_x;
753 for (y = 0; y < dst_h; y++) {
754 for (x = 0; x < dst_w; x+=step) {
755 for (z = 1; z < step; z++) {
761 } else if (step > 1) {
762 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
763 const int dst_w = 256;
767 dst = out->data[plane] + offset_y * dst_linesize + offset_x;
768 for (y = 0; y < dst_h; y+=step) {
769 for (z = 1; z < step; z++)
770 memcpy(dst + dst_linesize * z, dst, dst_w);
771 dst += dst_linesize * step;
775 envelope(s, out, plane, plane, column ? offset_x : offset_y);
778 #define LOWPASS_FUNC(name, column, mirror) \
779 static void lowpass_##name(WaveformContext *s, \
780 AVFrame *in, AVFrame *out, \
781 int component, int intensity, \
782 int offset_y, int offset_x, \
783 int unused1, int unused2) \
785 lowpass(s, in, out, component, intensity, \
786 offset_y, offset_x, column, mirror); \
789 LOWPASS_FUNC(column_mirror, 1, 1)
790 LOWPASS_FUNC(column, 1, 0)
791 LOWPASS_FUNC(row_mirror, 0, 1)
792 LOWPASS_FUNC(row, 0, 0)
794 static av_always_inline void flat16(WaveformContext *s,
795 AVFrame *in, AVFrame *out,
796 int component, int intensity,
797 int offset_y, int offset_x,
798 int column, int mirror)
800 const int plane = s->desc->comp[component].plane;
801 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
802 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
803 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
804 const int c0_shift_w = s->shift_w[ component + 0 ];
805 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
806 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
807 const int c0_shift_h = s->shift_h[ component + 0 ];
808 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
809 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
810 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
811 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
812 const int limit = s->max - 1;
813 const int max = limit - intensity;
814 const int mid = s->max / 2;
815 const int src_h = in->height;
816 const int src_w = in->width;
820 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
821 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
823 for (x = 0; x < src_w; x++) {
824 const uint16_t *c0_data = (uint16_t *)in->data[plane + 0];
825 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
826 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
827 uint16_t *d0_data = (uint16_t *)(out->data[plane]) + offset_y * d0_linesize + offset_x;
828 uint16_t *d1_data = (uint16_t *)(out->data[(plane + 1) % s->ncomp]) + offset_y * d1_linesize + offset_x;
829 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
830 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
831 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
832 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
834 for (y = 0; y < src_h; y++) {
835 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + s->max;
836 const int c1 = FFMIN(FFABS(c1_data[x >> c1_shift_w] - mid) + FFABS(c2_data[x >> c2_shift_w] - mid), limit);
839 target = d0 + x + d0_signed_linesize * c0;
840 update16(target, max, intensity, limit);
841 target = d1 + x + d1_signed_linesize * (c0 - c1);
842 update16(target, max, intensity, limit);
843 target = d1 + x + d1_signed_linesize * (c0 + c1);
844 update16(target, max, intensity, limit);
846 if (!c0_shift_h || (y & c0_shift_h))
847 c0_data += c0_linesize;
848 if (!c1_shift_h || (y & c1_shift_h))
849 c1_data += c1_linesize;
850 if (!c2_shift_h || (y & c2_shift_h))
851 c2_data += c2_linesize;
852 d0_data += d0_linesize;
853 d1_data += d1_linesize;
857 const uint16_t *c0_data = (uint16_t *)in->data[plane];
858 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
859 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
860 uint16_t *d0_data = (uint16_t *)(out->data[plane]) + offset_y * d0_linesize + offset_x;
861 uint16_t *d1_data = (uint16_t *)(out->data[(plane + 1) % s->ncomp]) + offset_y * d1_linesize + offset_x;
864 d0_data += s->size - 1;
865 d1_data += s->size - 1;
868 for (y = 0; y < src_h; y++) {
869 for (x = 0; x < src_w; x++) {
870 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + s->max;
871 const int c1 = FFMIN(FFABS(c1_data[x >> c1_shift_w] - mid) + FFABS(c2_data[x >> c2_shift_w] - mid), limit);
875 target = d0_data - c0;
876 update16(target, max, intensity, limit);
877 target = d1_data - (c0 - c1);
878 update16(target, max, intensity, limit);
879 target = d1_data - (c0 + c1);
880 update16(target, max, intensity, limit);
882 target = d0_data + c0;
883 update16(target, max, intensity, limit);
884 target = d1_data + (c0 - c1);
885 update16(target, max, intensity, limit);
886 target = d1_data + (c0 + c1);
887 update16(target, max, intensity, limit);
891 if (!c0_shift_h || (y & c0_shift_h))
892 c0_data += c0_linesize;
893 if (!c1_shift_h || (y & c1_shift_h))
894 c1_data += c1_linesize;
895 if (!c2_shift_h || (y & c2_shift_h))
896 c2_data += c2_linesize;
897 d0_data += d0_linesize;
898 d1_data += d1_linesize;
902 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
903 envelope16(s, out, plane, (plane + 1) % s->ncomp, column ? offset_x : offset_y);
906 static av_always_inline void flat(WaveformContext *s,
907 AVFrame *in, AVFrame *out,
908 int component, int intensity,
909 int offset_y, int offset_x,
910 int column, int mirror)
912 const int plane = s->desc->comp[component].plane;
913 const int c0_linesize = in->linesize[ plane + 0 ];
914 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
915 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
916 const int c0_shift_w = s->shift_w[ component + 0 ];
917 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
918 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
919 const int c0_shift_h = s->shift_h[ component + 0 ];
920 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
921 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
922 const int d0_linesize = out->linesize[ plane + 0 ];
923 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
924 const int max = 255 - intensity;
925 const int src_h = in->height;
926 const int src_w = in->width;
930 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
931 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
933 for (x = 0; x < src_w; x++) {
934 const uint8_t *c0_data = in->data[plane + 0];
935 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
936 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
937 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
938 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
939 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
940 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
941 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
942 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
944 for (y = 0; y < src_h; y++) {
945 const int c0 = c0_data[x >> c0_shift_w] + 256;
946 const int c1 = FFABS(c1_data[x >> c1_shift_w] - 128) + FFABS(c2_data[x >> c2_shift_w] - 128);
949 target = d0 + x + d0_signed_linesize * c0;
950 update(target, max, intensity);
951 target = d1 + x + d1_signed_linesize * (c0 - c1);
952 update(target, max, intensity);
953 target = d1 + x + d1_signed_linesize * (c0 + c1);
954 update(target, max, intensity);
956 if (!c0_shift_h || (y & c0_shift_h))
957 c0_data += c0_linesize;
958 if (!c1_shift_h || (y & c1_shift_h))
959 c1_data += c1_linesize;
960 if (!c2_shift_h || (y & c2_shift_h))
961 c2_data += c2_linesize;
962 d0_data += d0_linesize;
963 d1_data += d1_linesize;
967 const uint8_t *c0_data = in->data[plane];
968 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
969 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
970 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
971 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
974 d0_data += s->size - 1;
975 d1_data += s->size - 1;
978 for (y = 0; y < src_h; y++) {
979 for (x = 0; x < src_w; x++) {
980 int c0 = c0_data[x >> c0_shift_w] + 256;
981 const int c1 = FFABS(c1_data[x >> c1_shift_w] - 128) + FFABS(c2_data[x >> c2_shift_w] - 128);
985 target = d0_data - c0;
986 update(target, max, intensity);
987 target = d1_data - (c0 - c1);
988 update(target, max, intensity);
989 target = d1_data - (c0 + c1);
990 update(target, max, intensity);
992 target = d0_data + c0;
993 update(target, max, intensity);
994 target = d1_data + (c0 - c1);
995 update(target, max, intensity);
996 target = d1_data + (c0 + c1);
997 update(target, max, intensity);
1001 if (!c0_shift_h || (y & c0_shift_h))
1002 c0_data += c0_linesize;
1003 if (!c1_shift_h || (y & c1_shift_h))
1004 c1_data += c1_linesize;
1005 if (!c2_shift_h || (y & c2_shift_h))
1006 c2_data += c2_linesize;
1007 d0_data += d0_linesize;
1008 d1_data += d1_linesize;
1012 envelope(s, out, plane, plane, column ? offset_x : offset_y);
1013 envelope(s, out, plane, (plane + 1) % s->ncomp, column ? offset_x : offset_y);
1016 static av_always_inline void aflat16(WaveformContext *s,
1017 AVFrame *in, AVFrame *out,
1018 int component, int intensity,
1019 int offset_y, int offset_x,
1020 int column, int mirror)
1022 const int plane = s->desc->comp[component].plane;
1023 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
1024 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1025 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1026 const int c0_shift_w = s->shift_w[ component + 0 ];
1027 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1028 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1029 const int c0_shift_h = s->shift_h[ component + 0 ];
1030 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1031 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1032 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
1033 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
1034 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2;
1035 const int limit = s->max - 1;
1036 const int max = limit - intensity;
1037 const int mid = s->max / 2;
1038 const int src_h = in->height;
1039 const int src_w = in->width;
1043 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1044 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1045 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1047 for (x = 0; x < src_w; x++) {
1048 const uint16_t *c0_data = (uint16_t *)in->data[plane + 0];
1049 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1050 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1051 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1052 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1053 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1054 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1055 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1056 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1057 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1058 uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1059 uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1061 for (y = 0; y < src_h; y++) {
1062 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + mid;
1063 const int c1 = FFMIN(c1_data[x >> c1_shift_w], limit) - mid;
1064 const int c2 = FFMIN(c2_data[x >> c2_shift_w], limit) - mid;
1067 target = d0 + x + d0_signed_linesize * c0;
1068 update16(target, max, intensity, limit);
1070 target = d1 + x + d1_signed_linesize * (c0 + c1);
1071 update16(target, max, intensity, limit);
1073 target = d2 + x + d2_signed_linesize * (c0 + c2);
1074 update16(target, max, intensity, limit);
1076 if (!c0_shift_h || (y & c0_shift_h))
1077 c0_data += c0_linesize;
1078 if (!c1_shift_h || (y & c1_shift_h))
1079 c1_data += c1_linesize;
1080 if (!c2_shift_h || (y & c2_shift_h))
1081 c2_data += c2_linesize;
1082 d0_data += d0_linesize;
1083 d1_data += d1_linesize;
1084 d2_data += d2_linesize;
1088 const uint16_t *c0_data = (uint16_t *)in->data[plane];
1089 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1090 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1091 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1092 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1093 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1096 d0_data += s->size - 1;
1097 d1_data += s->size - 1;
1098 d2_data += s->size - 1;
1101 for (y = 0; y < src_h; y++) {
1102 for (x = 0; x < src_w; x++) {
1103 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + mid;
1104 const int c1 = FFMIN(c1_data[x >> c1_shift_w], limit) - mid;
1105 const int c2 = FFMIN(c2_data[x >> c2_shift_w], limit) - mid;
1109 target = d0_data - c0;
1110 update16(target, max, intensity, limit);
1111 target = d1_data - (c0 + c1);
1112 update16(target, max, intensity, limit);
1113 target = d2_data - (c0 + c2);
1114 update16(target, max, intensity, limit);
1116 target = d0_data + c0;
1117 update16(target, max, intensity, limit);
1118 target = d1_data + (c0 + c1);
1119 update16(target, max, intensity, limit);
1120 target = d2_data + (c0 + c2);
1121 update16(target, max, intensity, limit);
1125 if (!c0_shift_h || (y & c0_shift_h))
1126 c0_data += c0_linesize;
1127 if (!c1_shift_h || (y & c1_shift_h))
1128 c1_data += c1_linesize;
1129 if (!c2_shift_h || (y & c2_shift_h))
1130 c2_data += c2_linesize;
1131 d0_data += d0_linesize;
1132 d1_data += d1_linesize;
1133 d2_data += d2_linesize;
1137 envelope16(s, out, plane, (plane + 0) % s->ncomp, column ? offset_x : offset_y);
1138 envelope16(s, out, plane, (plane + 1) % s->ncomp, column ? offset_x : offset_y);
1139 envelope16(s, out, plane, (plane + 2) % s->ncomp, column ? offset_x : offset_y);
1142 static av_always_inline void aflat(WaveformContext *s,
1143 AVFrame *in, AVFrame *out,
1144 int component, int intensity,
1145 int offset_y, int offset_x,
1146 int column, int mirror)
1148 const int plane = s->desc->comp[component].plane;
1149 const int c0_linesize = in->linesize[ plane + 0 ];
1150 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
1151 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
1152 const int c0_shift_w = s->shift_w[ component + 0 ];
1153 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1154 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1155 const int c0_shift_h = s->shift_h[ component + 0 ];
1156 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1157 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1158 const int d0_linesize = out->linesize[ plane + 0 ];
1159 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
1160 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp];
1161 const int max = 255 - intensity;
1162 const int src_h = in->height;
1163 const int src_w = in->width;
1167 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1168 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1169 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1171 for (x = 0; x < src_w; x++) {
1172 const uint8_t *c0_data = in->data[plane + 0];
1173 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1174 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1175 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1176 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1177 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1178 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1179 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1180 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1181 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1182 uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1183 uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1185 for (y = 0; y < src_h; y++) {
1186 const int c0 = c0_data[x >> c0_shift_w] + 128;
1187 const int c1 = c1_data[x >> c1_shift_w] - 128;
1188 const int c2 = c2_data[x >> c2_shift_w] - 128;
1191 target = d0 + x + d0_signed_linesize * c0;
1192 update(target, max, intensity);
1194 target = d1 + x + d1_signed_linesize * (c0 + c1);
1195 update(target, max, intensity);
1197 target = d2 + x + d2_signed_linesize * (c0 + c2);
1198 update(target, max, intensity);
1200 if (!c0_shift_h || (y & c0_shift_h))
1201 c0_data += c0_linesize;
1202 if (!c1_shift_h || (y & c1_shift_h))
1203 c1_data += c1_linesize;
1204 if (!c1_shift_h || (y & c1_shift_h))
1205 c2_data += c1_linesize;
1206 d0_data += d0_linesize;
1207 d1_data += d1_linesize;
1208 d2_data += d2_linesize;
1212 const uint8_t *c0_data = in->data[plane];
1213 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1214 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1215 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1216 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1217 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1220 d0_data += s->size - 1;
1221 d1_data += s->size - 1;
1222 d2_data += s->size - 1;
1225 for (y = 0; y < src_h; y++) {
1226 for (x = 0; x < src_w; x++) {
1227 const int c0 = c0_data[x >> c0_shift_w] + 128;
1228 const int c1 = c1_data[x >> c1_shift_w] - 128;
1229 const int c2 = c2_data[x >> c2_shift_w] - 128;
1233 target = d0_data - c0;
1234 update(target, max, intensity);
1235 target = d1_data - (c0 + c1);
1236 update(target, max, intensity);
1237 target = d2_data - (c0 + c2);
1238 update(target, max, intensity);
1240 target = d0_data + c0;
1241 update(target, max, intensity);
1242 target = d1_data + (c0 + c1);
1243 update(target, max, intensity);
1244 target = d2_data + (c0 + c2);
1245 update(target, max, intensity);
1249 if (!c0_shift_h || (y & c0_shift_h))
1250 c0_data += c0_linesize;
1251 if (!c1_shift_h || (y & c1_shift_h))
1252 c1_data += c1_linesize;
1253 if (!c2_shift_h || (y & c2_shift_h))
1254 c2_data += c2_linesize;
1255 d0_data += d0_linesize;
1256 d1_data += d1_linesize;
1257 d2_data += d2_linesize;
1261 envelope(s, out, plane, (plane + 0) % s->ncomp, column ? offset_x : offset_y);
1262 envelope(s, out, plane, (plane + 1) % s->ncomp, column ? offset_x : offset_y);
1263 envelope(s, out, plane, (plane + 2) % s->ncomp, column ? offset_x : offset_y);
1266 static av_always_inline void chroma16(WaveformContext *s,
1267 AVFrame *in, AVFrame *out,
1268 int component, int intensity,
1269 int offset_y, int offset_x,
1270 int column, int mirror)
1272 const int plane = s->desc->comp[component].plane;
1273 const int c0_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1274 const int c1_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1275 const int dst_linesize = out->linesize[plane] / 2;
1276 const int limit = s->max - 1;
1277 const int max = limit - intensity;
1278 const int mid = s->max / 2;
1279 const int c0_shift_w = s->shift_w[(component + 1) % s->ncomp];
1280 const int c1_shift_w = s->shift_w[(component + 2) % s->ncomp];
1281 const int c0_shift_h = s->shift_h[(component + 1) % s->ncomp];
1282 const int c1_shift_h = s->shift_h[(component + 2) % s->ncomp];
1283 const int src_h = in->height;
1284 const int src_w = in->width;
1288 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
1290 for (x = 0; x < src_w; x++) {
1291 const uint16_t *c0_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1292 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1293 uint16_t *dst_data = (uint16_t *)out->data[plane] + offset_y * dst_linesize + offset_x;
1294 uint16_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
1295 uint16_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
1296 uint16_t *dst = dst_line;
1298 for (y = 0; y < src_h; y++) {
1299 const int sum = FFMIN(FFABS(c0_data[x >> c0_shift_w] - mid) + FFABS(c1_data[x >> c1_shift_w] - mid - 1), limit);
1302 target = dst + x + dst_signed_linesize * sum;
1303 update16(target, max, intensity, limit);
1305 if (!c0_shift_h || (y & c0_shift_h))
1306 c0_data += c0_linesize;
1307 if (!c1_shift_h || (y & c1_shift_h))
1308 c1_data += c1_linesize;
1309 dst_data += dst_linesize;
1313 const uint16_t *c0_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1314 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1315 uint16_t *dst_data = (uint16_t *)out->data[plane] + offset_y * dst_linesize + offset_x;
1318 dst_data += s->size - 1;
1319 for (y = 0; y < src_h; y++) {
1320 for (x = 0; x < src_w; x++) {
1321 const int sum = FFMIN(FFABS(c0_data[x >> c0_shift_w] - mid) + FFABS(c1_data[x >> c1_shift_w] - mid - 1), limit);
1325 target = dst_data - sum;
1326 update16(target, max, intensity, limit);
1328 target = dst_data + sum;
1329 update16(target, max, intensity, limit);
1333 if (!c0_shift_h || (y & c0_shift_h))
1334 c0_data += c0_linesize;
1335 if (!c1_shift_h || (y & c1_shift_h))
1336 c1_data += c1_linesize;
1337 dst_data += dst_linesize;
1341 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
1344 static av_always_inline void chroma(WaveformContext *s,
1345 AVFrame *in, AVFrame *out,
1346 int component, int intensity,
1347 int offset_y, int offset_x,
1348 int column, int mirror)
1350 const int plane = s->desc->comp[component].plane;
1351 const int c0_linesize = in->linesize[(plane + 1) % s->ncomp];
1352 const int c1_linesize = in->linesize[(plane + 2) % s->ncomp];
1353 const int dst_linesize = out->linesize[plane];
1354 const int max = 255 - intensity;
1355 const int c0_shift_w = s->shift_w[(component + 1) % s->ncomp];
1356 const int c1_shift_w = s->shift_w[(component + 2) % s->ncomp];
1357 const int c0_shift_h = s->shift_h[(component + 1) % s->ncomp];
1358 const int c1_shift_h = s->shift_h[(component + 2) % s->ncomp];
1359 const int src_h = in->height;
1360 const int src_w = in->width;
1364 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
1366 for (x = 0; x < src_w; x++) {
1367 const uint8_t *c0_data = in->data[(plane + 1) % s->ncomp];
1368 const uint8_t *c1_data = in->data[(plane + 2) % s->ncomp];
1369 uint8_t *dst_data = out->data[plane] + offset_y * dst_linesize + offset_x;
1370 uint8_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
1371 uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
1372 uint8_t *dst = dst_line;
1374 for (y = 0; y < src_h; y++) {
1375 const int sum = FFABS(c0_data[x >> c0_shift_w] - 128) + FFABS(c1_data[x >> c1_shift_w] - 127);
1378 target = dst + x + dst_signed_linesize * sum;
1379 update(target, max, intensity);
1381 if (!c0_shift_h || (y & c0_shift_h))
1382 c0_data += c0_linesize;
1383 if (!c1_shift_h || (y & c1_shift_h))
1384 c1_data += c1_linesize;
1385 dst_data += dst_linesize;
1389 const uint8_t *c0_data = in->data[(plane + 1) % s->ncomp];
1390 const uint8_t *c1_data = in->data[(plane + 2) % s->ncomp];
1391 uint8_t *dst_data = out->data[plane] + offset_y * dst_linesize + offset_x;
1394 dst_data += s->size - 1;
1395 for (y = 0; y < src_h; y++) {
1396 for (x = 0; x < src_w; x++) {
1397 const int sum = FFABS(c0_data[x >> c0_shift_w] - 128) + FFABS(c1_data[x >> c1_shift_w] - 127);
1401 target = dst_data - sum;
1402 update(target, max, intensity);
1404 target = dst_data + sum;
1405 update(target, max, intensity);
1409 if (!c0_shift_h || (y & c0_shift_h))
1410 c0_data += c0_linesize;
1411 if (!c1_shift_h || (y & c1_shift_h))
1412 c1_data += c1_linesize;
1413 dst_data += dst_linesize;
1417 envelope(s, out, plane, plane, column ? offset_x : offset_y);
1420 static av_always_inline void color16(WaveformContext *s,
1421 AVFrame *in, AVFrame *out,
1422 int component, int intensity,
1423 int offset_y, int offset_x,
1424 int column, int mirror)
1426 const int plane = s->desc->comp[component].plane;
1427 const int limit = s->max - 1;
1428 const uint16_t *c0_data = (const uint16_t *)in->data[plane + 0];
1429 const uint16_t *c1_data = (const uint16_t *)in->data[(plane + 1) % s->ncomp];
1430 const uint16_t *c2_data = (const uint16_t *)in->data[(plane + 2) % s->ncomp];
1431 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
1432 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1433 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1434 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
1435 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
1436 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2;
1437 const int c0_shift_w = s->shift_w[ component + 0 ];
1438 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1439 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1440 const int c0_shift_h = s->shift_h[ component + 0 ];
1441 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1442 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1443 const int src_h = in->height;
1444 const int src_w = in->width;
1448 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1449 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1450 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1451 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1452 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1453 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1454 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1455 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1456 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1457 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1458 uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1459 uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1461 for (y = 0; y < src_h; y++) {
1462 for (x = 0; x < src_w; x++) {
1463 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1464 const int c1 = c1_data[x >> c1_shift_w];
1465 const int c2 = c2_data[x >> c2_shift_w];
1467 *(d0 + d0_signed_linesize * c0 + x) = c0;
1468 *(d1 + d1_signed_linesize * c0 + x) = c1;
1469 *(d2 + d2_signed_linesize * c0 + x) = c2;
1472 if (!c0_shift_h || (y & c0_shift_h))
1473 c0_data += c0_linesize;
1474 if (!c1_shift_h || (y & c1_shift_h))
1475 c1_data += c1_linesize;
1476 if (!c2_shift_h || (y & c2_shift_h))
1477 c2_data += c2_linesize;
1478 d0_data += d0_linesize;
1479 d1_data += d1_linesize;
1480 d2_data += d2_linesize;
1483 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1484 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1485 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1488 d0_data += s->size - 1;
1489 d1_data += s->size - 1;
1490 d2_data += s->size - 1;
1493 for (y = 0; y < src_h; y++) {
1494 for (x = 0; x < src_w; x++) {
1495 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1496 const int c1 = c1_data[x >> c1_shift_w];
1497 const int c2 = c2_data[x >> c2_shift_w];
1500 *(d0_data - c0) = c0;
1501 *(d1_data - c0) = c1;
1502 *(d2_data - c0) = c2;
1504 *(d0_data + c0) = c0;
1505 *(d1_data + c0) = c1;
1506 *(d2_data + c0) = c2;
1510 if (!c0_shift_h || (y & c0_shift_h))
1511 c0_data += c0_linesize;
1512 if (!c1_shift_h || (y & c1_shift_h))
1513 c1_data += c1_linesize;
1514 if (!c2_shift_h || (y & c2_shift_h))
1515 c2_data += c2_linesize;
1516 d0_data += d0_linesize;
1517 d1_data += d1_linesize;
1518 d2_data += d2_linesize;
1522 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
1525 static av_always_inline void color(WaveformContext *s,
1526 AVFrame *in, AVFrame *out,
1527 int component, int intensity,
1528 int offset_y, int offset_x,
1529 int column, int mirror)
1531 const int plane = s->desc->comp[component].plane;
1532 const uint8_t *c0_data = in->data[plane + 0];
1533 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1534 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1535 const int c0_linesize = in->linesize[ plane + 0 ];
1536 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
1537 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
1538 const int d0_linesize = out->linesize[ plane + 0 ];
1539 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
1540 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp];
1541 const int c0_shift_w = s->shift_w[ component + 0 ];
1542 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1543 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1544 const int c0_shift_h = s->shift_h[ component + 0 ];
1545 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1546 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1547 const int src_h = in->height;
1548 const int src_w = in->width;
1552 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1553 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1554 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1555 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1556 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1557 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1558 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1559 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1560 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1561 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1562 uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1563 uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1565 for (y = 0; y < src_h; y++) {
1566 for (x = 0; x < src_w; x++) {
1567 const int c0 = c0_data[x >> c0_shift_w];
1568 const int c1 = c1_data[x >> c1_shift_w];
1569 const int c2 = c2_data[x >> c2_shift_w];
1571 *(d0 + d0_signed_linesize * c0 + x) = c0;
1572 *(d1 + d1_signed_linesize * c0 + x) = c1;
1573 *(d2 + d2_signed_linesize * c0 + x) = c2;
1576 if (!c0_shift_h || (y & c0_shift_h))
1577 c0_data += c0_linesize;
1578 if (!c1_shift_h || (y & c1_shift_h))
1579 c1_data += c1_linesize;
1580 if (!c2_shift_h || (y & c2_shift_h))
1581 c2_data += c2_linesize;
1582 d0_data += d0_linesize;
1583 d1_data += d1_linesize;
1584 d2_data += d2_linesize;
1587 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1588 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1589 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1592 d0_data += s->size - 1;
1593 d1_data += s->size - 1;
1594 d2_data += s->size - 1;
1597 for (y = 0; y < src_h; y++) {
1598 for (x = 0; x < src_w; x++) {
1599 const int c0 = c0_data[x >> c0_shift_w];
1600 const int c1 = c1_data[x >> c1_shift_w];
1601 const int c2 = c2_data[x >> c2_shift_w];
1604 *(d0_data - c0) = c0;
1605 *(d1_data - c0) = c1;
1606 *(d2_data - c0) = c2;
1608 *(d0_data + c0) = c0;
1609 *(d1_data + c0) = c1;
1610 *(d2_data + c0) = c2;
1614 if (!c0_shift_h || (y & c0_shift_h))
1615 c0_data += c0_linesize;
1616 if (!c1_shift_h || (y & c1_shift_h))
1617 c1_data += c1_linesize;
1618 if (!c2_shift_h || (y & c2_shift_h))
1619 c2_data += c2_linesize;
1620 d0_data += d0_linesize;
1621 d1_data += d1_linesize;
1622 d2_data += d2_linesize;
1626 envelope(s, out, plane, plane, column ? offset_x : offset_y);
1629 static av_always_inline void acolor16(WaveformContext *s,
1630 AVFrame *in, AVFrame *out,
1631 int component, int intensity,
1632 int offset_y, int offset_x,
1633 int column, int mirror)
1635 const int plane = s->desc->comp[component].plane;
1636 const int limit = s->max - 1;
1637 const int max = limit - intensity;
1638 const uint16_t *c0_data = (const uint16_t *)in->data[plane + 0];
1639 const uint16_t *c1_data = (const uint16_t *)in->data[(plane + 1) % s->ncomp];
1640 const uint16_t *c2_data = (const uint16_t *)in->data[(plane + 2) % s->ncomp];
1641 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
1642 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1643 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1644 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
1645 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
1646 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2;
1647 const int c0_shift_w = s->shift_w[ component + 0 ];
1648 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1649 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1650 const int c0_shift_h = s->shift_h[ component + 0 ];
1651 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1652 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1653 const int src_h = in->height;
1654 const int src_w = in->width;
1658 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1659 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1660 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1661 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1662 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1663 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1664 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1665 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1666 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1667 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1668 uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1669 uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1671 for (y = 0; y < src_h; y++) {
1672 for (x = 0; x < src_w; x++) {
1673 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1674 const int c1 = c1_data[x >> c1_shift_w];
1675 const int c2 = c2_data[x >> c2_shift_w];
1677 update16(d0 + d0_signed_linesize * c0 + x, max, intensity, limit);
1678 *(d1 + d1_signed_linesize * c0 + x) = c1;
1679 *(d2 + d2_signed_linesize * c0 + x) = c2;
1682 if (!c0_shift_h || (y & c0_shift_h))
1683 c0_data += c0_linesize;
1684 if (!c1_shift_h || (y & c1_shift_h))
1685 c1_data += c1_linesize;
1686 if (!c2_shift_h || (y & c2_shift_h))
1687 c2_data += c2_linesize;
1688 d0_data += d0_linesize;
1689 d1_data += d1_linesize;
1690 d2_data += d2_linesize;
1693 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1694 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1695 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1698 d0_data += s->size - 1;
1699 d1_data += s->size - 1;
1700 d2_data += s->size - 1;
1703 for (y = 0; y < src_h; y++) {
1704 for (x = 0; x < src_w; x++) {
1705 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1706 const int c1 = c1_data[x >> c1_shift_w];
1707 const int c2 = c2_data[x >> c2_shift_w];
1710 update16(d0_data - c0, max, intensity, limit);
1711 *(d1_data - c0) = c1;
1712 *(d2_data - c0) = c2;
1714 update16(d0_data + c0, max, intensity, limit);
1715 *(d1_data + c0) = c1;
1716 *(d2_data + c0) = c2;
1720 if (!c0_shift_h || (y & c0_shift_h))
1721 c0_data += c0_linesize;
1722 if (!c1_shift_h || (y & c1_shift_h))
1723 c1_data += c1_linesize;
1724 if (!c2_shift_h || (y & c2_shift_h))
1725 c2_data += c2_linesize;
1726 d0_data += d0_linesize;
1727 d1_data += d1_linesize;
1728 d2_data += d2_linesize;
1732 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
1735 static av_always_inline void acolor(WaveformContext *s,
1736 AVFrame *in, AVFrame *out,
1737 int component, int intensity,
1738 int offset_y, int offset_x,
1739 int column, int mirror)
1741 const int plane = s->desc->comp[component].plane;
1742 const uint8_t *c0_data = in->data[plane + 0];
1743 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1744 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1745 const int c0_linesize = in->linesize[ plane + 0 ];
1746 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
1747 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
1748 const int d0_linesize = out->linesize[ plane + 0 ];
1749 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
1750 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp];
1751 const int c0_shift_w = s->shift_w[ component + 0 ];
1752 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1753 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1754 const int c0_shift_h = s->shift_h[ component + 0 ];
1755 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1756 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1757 const int max = 255 - intensity;
1758 const int src_h = in->height;
1759 const int src_w = in->width;
1763 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1764 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1765 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1766 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1767 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1768 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1769 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1770 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1771 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1772 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1773 uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1774 uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1776 for (y = 0; y < src_h; y++) {
1777 for (x = 0; x < src_w; x++) {
1778 const int c0 = c0_data[x >> c0_shift_w];
1779 const int c1 = c1_data[x >> c1_shift_w];
1780 const int c2 = c2_data[x >> c2_shift_w];
1782 update(d0 + d0_signed_linesize * c0 + x, max, intensity);
1783 *(d1 + d1_signed_linesize * c0 + x) = c1;
1784 *(d2 + d2_signed_linesize * c0 + x) = c2;
1787 if (!c0_shift_h || (y & c0_shift_h))
1788 c0_data += c0_linesize;
1789 if (!c1_shift_h || (y & c1_shift_h))
1790 c1_data += c1_linesize;
1791 if (!c2_shift_h || (y & c2_shift_h))
1792 c2_data += c2_linesize;
1793 d0_data += d0_linesize;
1794 d1_data += d1_linesize;
1795 d2_data += d2_linesize;
1798 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1799 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1800 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1803 d0_data += s->size - 1;
1804 d1_data += s->size - 1;
1805 d2_data += s->size - 1;
1808 for (y = 0; y < src_h; y++) {
1809 for (x = 0; x < src_w; x++) {
1810 const int c0 = c0_data[x >> c0_shift_w];
1811 const int c1 = c1_data[x >> c1_shift_w];
1812 const int c2 = c2_data[x >> c2_shift_w];
1815 update(d0_data - c0, max, intensity);
1816 *(d1_data - c0) = c1;
1817 *(d2_data - c0) = c2;
1819 update(d0_data + c0, max, intensity);
1820 *(d1_data + c0) = c1;
1821 *(d2_data + c0) = c2;
1825 if (!c0_shift_h || (y & c0_shift_h))
1826 c0_data += c0_linesize;
1827 if (!c1_shift_h || (y & c1_shift_h))
1828 c1_data += c1_linesize;
1829 if (!c2_shift_h || (y & c2_shift_h))
1830 c2_data += c2_linesize;
1831 d0_data += d0_linesize;
1832 d1_data += d1_linesize;
1833 d2_data += d2_linesize;
1837 envelope(s, out, plane, plane, column ? offset_x : offset_y);
1840 static const uint8_t black_yuva_color[4] = { 0, 127, 127, 255 };
1841 static const uint8_t green_yuva_color[4] = { 255, 0, 0, 255 };
1842 static const uint8_t black_gbrp_color[4] = { 0, 0, 0, 255 };
1844 static const GraticuleLines aflat_digital8[] = {
1845 { { { "16", 16+128 }, { "16", 16+128 }, { "16", 16+128 }, { "0", 0+128 } } },
1846 { { { "128", 128+128 }, { "128", 128+128 }, { "128", 128+128 }, { "128", 128+128 } } },
1847 { { { "235", 235+128 }, { "240", 240+128 }, { "240", 240+128 }, { "255", 255+128 } } },
1850 static const GraticuleLines aflat_digital9[] = {
1851 { { { "32", 32+256 }, { "32", 32+256 }, { "32", 32+256 }, { "0", 0+256 } } },
1852 { { { "256", 256+256 }, { "256", 256+256 }, { "256", 256+256 }, { "256", 256+256 } } },
1853 { { { "470", 470+256 }, { "480", 480+256 }, { "480", 480+256 }, { "511", 511+256 } } },
1856 static const GraticuleLines aflat_digital10[] = {
1857 { { { "64", 64+512 }, { "64", 64+512 }, { "64", 64+512 }, { "0", 0+512 } } },
1858 { { { "512", 512+512 }, { "512", 512+512 }, { "512", 512+512 }, { "512", 512+512 } } },
1859 { { { "940", 940+512 }, { "960", 960+512 }, { "960", 960+512 }, { "1023", 1023+512 } } },
1862 static const GraticuleLines aflat_digital12[] = {
1863 { { { "256", 256+2048 }, { "256", 256+2048 }, { "256", 256+2048 }, { "0", 0+2048 } } },
1864 { { { "2048", 2048+2048 }, { "2048", 2048+2048 }, { "2048", 2048+2048 }, { "2048", 2048+2048 } } },
1865 { { { "3760", 3760+2048 }, { "3840", 3840+2048 }, { "3840", 3840+2048 }, { "4095", 4095+2048 } } },
1868 static const GraticuleLines aflat_millivolts8[] = {
1869 { { { "0", 16+128 }, { "0", 16+128 }, { "0", 16+128 }, { "0", 0+128 } } },
1870 { { { "175", 71+128 }, { "175", 72+128 }, { "175", 72+128 }, { "175", 64+128 } } },
1871 { { { "350", 126+128 }, { "350", 128+128 }, { "350", 128+128 }, { "350", 128+128 } } },
1872 { { { "525", 180+128 }, { "525", 184+128 }, { "525", 184+128 }, { "525", 192+128 } } },
1873 { { { "700", 235+128 }, { "700", 240+128 }, { "700", 240+128 }, { "700", 255+128 } } },
1876 static const GraticuleLines aflat_millivolts9[] = {
1877 { { { "0", 32+256 }, { "0", 32+256 }, { "0", 32+256 }, { "0", 0+256 } } },
1878 { { { "175", 142+256 }, { "175", 144+256 }, { "175", 144+256 }, { "175", 128+256 } } },
1879 { { { "350", 251+256 }, { "350", 256+256 }, { "350", 256+256 }, { "350", 256+256 } } },
1880 { { { "525", 361+256 }, { "525", 368+256 }, { "525", 368+256 }, { "525", 384+256 } } },
1881 { { { "700", 470+256 }, { "700", 480+256 }, { "700", 480+256 }, { "700", 511+256 } } },
1884 static const GraticuleLines aflat_millivolts10[] = {
1885 { { { "0", 64+512 }, { "0", 64+512 }, { "0", 64+512 }, { "0", 0+512 } } },
1886 { { { "175", 283+512 }, { "175", 288+512 }, { "175", 288+512 }, { "175", 256+512 } } },
1887 { { { "350", 502+512 }, { "350", 512+512 }, { "350", 512+512 }, { "350", 512+512 } } },
1888 { { { "525", 721+512 }, { "525", 736+512 }, { "525", 736+512 }, { "525", 768+512 } } },
1889 { { { "700", 940+512 }, { "700", 960+512 }, { "700", 960+512 }, { "700", 1023+512 } } },
1892 static const GraticuleLines aflat_millivolts12[] = {
1893 { { { "0", 256+2048 }, { "0", 256+2048 }, { "0", 256+2048 }, { "0", 0+2048 } } },
1894 { { { "175", 1132+2048 }, { "175", 1152+2048 }, { "175", 1152+2048 }, { "175", 1024+2048 } } },
1895 { { { "350", 2008+2048 }, { "350", 2048+2048 }, { "350", 2048+2048 }, { "350", 2048+2048 } } },
1896 { { { "525", 2884+2048 }, { "525", 2944+2048 }, { "525", 2944+2048 }, { "525", 3072+2048 } } },
1897 { { { "700", 3760+2048 }, { "700", 3840+2048 }, { "700", 3840+2048 }, { "700", 4095+2048 } } },
1900 static const GraticuleLines aflat_ire8[] = {
1901 { { { "-25", -39+128 }, { "-25", -40+128 }, { "-25", -40+128 }, { "-25", -64+128 } } },
1902 { { { "0", 16+128 }, { "0", 16+128 }, { "0", 16+128 }, { "0", 0+128 } } },
1903 { { { "25", 71+128 }, { "25", 72+128 }, { "25", 72+128 }, { "25", 64+128 } } },
1904 { { { "50", 126+128 }, { "50", 128+128 }, { "50", 128+128 }, { "50", 128+128 } } },
1905 { { { "75", 180+128 }, { "75", 184+128 }, { "75", 184+128 }, { "75", 192+128 } } },
1906 { { { "100", 235+128 }, { "100", 240+128 }, { "100", 240+128 }, { "100", 256+128 } } },
1907 { { { "125", 290+128 }, { "125", 296+128 }, { "125", 296+128 }, { "125", 320+128 } } },
1910 static const GraticuleLines aflat_ire9[] = {
1911 { { { "-25", -78+256 }, { "-25", -80+256 }, { "-25", -80+256 }, { "-25",-128+256 } } },
1912 { { { "0", 32+256 }, { "0", 32+256 }, { "0", 32+256 }, { "0", 0+256 } } },
1913 { { { "25", 142+256 }, { "25", 144+256 }, { "25", 144+256 }, { "25", 128+256 } } },
1914 { { { "50", 251+256 }, { "50", 256+256 }, { "50", 256+256 }, { "50", 256+256 } } },
1915 { { { "75", 361+256 }, { "75", 368+256 }, { "75", 368+256 }, { "75", 384+256 } } },
1916 { { { "100", 470+256 }, { "100", 480+256 }, { "100", 480+256 }, { "100", 512+256 } } },
1917 { { { "125", 580+256 }, { "125", 592+256 }, { "125", 592+256 }, { "125", 640+256 } } },
1920 static const GraticuleLines aflat_ire10[] = {
1921 { { { "-25",-156+512 }, { "-25",-160+512 }, { "-25",-160+512 }, { "-25", -256+512 } } },
1922 { { { "0", 64+512 }, { "0", 64+512 }, { "0", 64+512 }, { "0", 0+512 } } },
1923 { { { "25", 283+512 }, { "25", 288+512 }, { "25", 288+512 }, { "25", 256+512 } } },
1924 { { { "50", 502+512 }, { "50", 512+512 }, { "50", 512+512 }, { "50", 512+512 } } },
1925 { { { "75", 721+512 }, { "75", 736+512 }, { "75", 736+512 }, { "75", 768+512 } } },
1926 { { { "100", 940+512 }, { "100", 960+512 }, { "100", 960+512 }, { "100", 1024+512 } } },
1927 { { { "125",1160+512 }, { "125",1184+512 }, { "125",1184+512 }, { "125", 1280+512 } } },
1930 static const GraticuleLines aflat_ire12[] = {
1931 { { { "-25", -624+2048 }, { "-25", -640+2048 }, { "-25", -640+2048 }, { "-25",-1024+2048 } } },
1932 { { { "0", 256+2048 }, { "0", 256+2048 }, { "0", 256+2048 }, { "0", 0+2048 } } },
1933 { { { "25", 1132+2048 }, { "25", 1152+2048 }, { "25", 1152+2048 }, { "25", 1024+2048 } } },
1934 { { { "50", 2008+2048 }, { "50", 2048+2048 }, { "50", 2048+2048 }, { "50", 2048+2048 } } },
1935 { { { "75", 2884+2048 }, { "75", 2944+2048 }, { "75", 2944+2048 }, { "75", 3072+2048 } } },
1936 { { { "100", 3760+2048 }, { "100", 3840+2048 }, { "100", 3840+2048 }, { "100", 4096+2048 } } },
1937 { { { "125", 4640+2048 }, { "125", 4736+2048 }, { "125", 4736+2048 }, { "125", 5120+2048 } } },
1940 static const GraticuleLines flat_digital8[] = {
1941 { { { "16", 16+256 }, { "16", 16+256 }, { "16", 16+256 }, { "0", 0+256 } } },
1942 { { { "128", 128+256 }, { "128", 128+256 }, { "128", 128+256 }, { "128", 128+256 } } },
1943 { { { "235", 235+256 }, { "240", 240+256 }, { "240", 240+256 }, { "255", 255+256 } } },
1946 static const GraticuleLines flat_digital9[] = {
1947 { { { "32", 32+512 }, { "32", 32+512 }, { "32", 32+512 }, { "0", 0+512 } } },
1948 { { { "256", 256+512 }, { "256", 256+512 }, { "256", 256+512 }, { "256", 256+512 } } },
1949 { { { "470", 470+512 }, { "480", 480+512 }, { "480", 480+512 }, { "511", 511+512 } } },
1952 static const GraticuleLines flat_digital10[] = {
1953 { { { "64", 64+1024 }, { "64", 64+1024 }, { "64", 64+1024 }, { "0", 0+1024 } } },
1954 { { { "512", 512+1024 }, { "512", 512+1024 }, { "512", 512+1024 }, { "512", 512+1024 } } },
1955 { { { "940", 940+1024 }, { "960", 960+1024 }, { "960", 960+1024 }, { "1023", 1023+1024 } } },
1958 static const GraticuleLines flat_digital12[] = {
1959 { { { "256", 256+4096 }, { "256", 256+4096 }, { "256", 256+4096 }, { "0", 0+4096 } } },
1960 { { { "2048", 2048+4096 }, { "2048", 2048+4096 }, { "2048", 2048+4096 }, { "2048", 2048+4096 } } },
1961 { { { "3760", 3760+4096 }, { "3840", 3840+4096 }, { "3840", 3840+4096 }, { "4095", 4095+4096 } } },
1964 static const GraticuleLines flat_millivolts8[] = {
1965 { { { "0", 16+256 }, { "0", 16+256 }, { "0", 16+256 }, { "0", 0+256 } } },
1966 { { { "175", 71+256 }, { "175", 72+256 }, { "175", 72+256 }, { "175", 64+256 } } },
1967 { { { "350", 126+256 }, { "350", 128+256 }, { "350", 128+256 }, { "350", 128+256 } } },
1968 { { { "525", 180+256 }, { "525", 184+256 }, { "525", 184+256 }, { "525", 192+256 } } },
1969 { { { "700", 235+256 }, { "700", 240+256 }, { "700", 240+256 }, { "700", 255+256 } } },
1972 static const GraticuleLines flat_millivolts9[] = {
1973 { { { "0", 32+512 }, { "0", 32+512 }, { "0", 32+512 }, { "0", 0+512 } } },
1974 { { { "175", 142+512 }, { "175", 144+512 }, { "175", 144+512 }, { "175", 128+512 } } },
1975 { { { "350", 251+512 }, { "350", 256+512 }, { "350", 256+512 }, { "350", 256+512 } } },
1976 { { { "525", 361+512 }, { "525", 368+512 }, { "525", 368+512 }, { "525", 384+512 } } },
1977 { { { "700", 470+512 }, { "700", 480+512 }, { "700", 480+512 }, { "700", 511+512 } } },
1980 static const GraticuleLines flat_millivolts10[] = {
1981 { { { "0", 64+1024 }, { "0", 64+1024 }, { "0", 64+1024 }, { "0", 0+1024 } } },
1982 { { { "175", 283+1024 }, { "175", 288+1024 }, { "175", 288+1024 }, { "175", 256+1024 } } },
1983 { { { "350", 502+1024 }, { "350", 512+1024 }, { "350", 512+1024 }, { "350", 512+1024 } } },
1984 { { { "525", 721+1024 }, { "525", 736+1024 }, { "525", 736+1024 }, { "525", 768+1024 } } },
1985 { { { "700", 940+1024 }, { "700", 960+1024 }, { "700", 960+1024 }, { "700", 1023+1024 } } },
1988 static const GraticuleLines flat_millivolts12[] = {
1989 { { { "0", 256+4096 }, { "0", 256+4096 }, { "0", 256+4096 }, { "0", 0+4096 } } },
1990 { { { "175", 1132+4096 }, { "175", 1152+4096 }, { "175", 1152+4096 }, { "175", 1024+4096 } } },
1991 { { { "350", 2008+4096 }, { "350", 2048+4096 }, { "350", 2048+4096 }, { "350", 2048+4096 } } },
1992 { { { "525", 2884+4096 }, { "525", 2944+4096 }, { "525", 2944+4096 }, { "525", 3072+4096 } } },
1993 { { { "700", 3760+4096 }, { "700", 3840+4096 }, { "700", 3840+4096 }, { "700", 4095+4096 } } },
1996 static const GraticuleLines flat_ire8[] = {
1997 { { { "-25", -39+256 }, { "-25", -40+256 }, { "-25", -40+256 }, { "-25", -64+256 } } },
1998 { { { "0", 16+256 }, { "0", 16+256 }, { "0", 16+256 }, { "0", 0+256 } } },
1999 { { { "25", 71+256 }, { "25", 72+256 }, { "25", 72+256 }, { "25", 64+256 } } },
2000 { { { "50", 126+256 }, { "50", 128+256 }, { "50", 128+256 }, { "50", 128+256 } } },
2001 { { { "75", 180+256 }, { "75", 184+256 }, { "75", 184+256 }, { "75", 192+256 } } },
2002 { { { "100", 235+256 }, { "100", 240+256 }, { "100", 240+256 }, { "100", 256+256 } } },
2003 { { { "125", 290+256 }, { "125", 296+256 }, { "125", 296+256 }, { "125", 320+256 } } },
2006 static const GraticuleLines flat_ire9[] = {
2007 { { { "-25", -78+512 }, { "-25", -80+512 }, { "-25", -80+512 }, { "-25",-128+512 } } },
2008 { { { "0", 32+512 }, { "0", 32+512 }, { "0", 32+512 }, { "0", 0+512 } } },
2009 { { { "25", 142+512 }, { "25", 144+512 }, { "25", 144+512 }, { "25", 128+512 } } },
2010 { { { "50", 251+512 }, { "50", 256+512 }, { "50", 256+512 }, { "50", 256+512 } } },
2011 { { { "75", 361+512 }, { "75", 368+512 }, { "75", 368+512 }, { "75", 384+512 } } },
2012 { { { "100", 470+512 }, { "100", 480+512 }, { "100", 480+512 }, { "100", 512+512 } } },
2013 { { { "125", 580+512 }, { "125", 592+512 }, { "125", 592+512 }, { "125", 640+512 } } },
2016 static const GraticuleLines flat_ire10[] = {
2017 { { { "-25",-156+1024 }, { "-25",-160+1024 }, { "-25",-160+1024 }, { "-25", -256+1024 } } },
2018 { { { "0", 64+1024 }, { "0", 64+1024 }, { "0", 64+1024 }, { "0", 0+1024 } } },
2019 { { { "25", 283+1024 }, { "25", 288+1024 }, { "25", 288+1024 }, { "25", 256+1024 } } },
2020 { { { "50", 502+1024 }, { "50", 512+1024 }, { "50", 512+1024 }, { "50", 512+1024 } } },
2021 { { { "75", 721+1024 }, { "75", 736+1024 }, { "75", 736+1024 }, { "75", 768+1024 } } },
2022 { { { "100", 940+1024 }, { "100", 960+1024 }, { "100", 960+1024 }, { "100", 1024+1024 } } },
2023 { { { "125",1160+1024 }, { "125",1184+1024 }, { "125",1184+1024 }, { "125", 1280+1024 } } },
2026 static const GraticuleLines flat_ire12[] = {
2027 { { { "-25", -624+4096 }, { "-25", -640+4096 }, { "-25", -640+4096 }, { "-25",-1024+4096 } } },
2028 { { { "0", 256+4096 }, { "0", 256+4096 }, { "0", 256+4096 }, { "0", 0+4096 } } },
2029 { { { "25", 1132+4096 }, { "25", 1152+4096 }, { "25", 1152+4096 }, { "25", 1024+4096 } } },
2030 { { { "50", 2008+4096 }, { "50", 2048+4096 }, { "50", 2048+4096 }, { "50", 2048+4096 } } },
2031 { { { "75", 2884+4096 }, { "75", 2944+4096 }, { "75", 2944+4096 }, { "75", 3072+4096 } } },
2032 { { { "100", 3760+4096 }, { "100", 3840+4096 }, { "100", 3840+4096 }, { "100", 4096+4096 } } },
2033 { { { "125", 4640+4096 }, { "125", 4736+4096 }, { "125", 4736+4096 }, { "125", 5120+4096 } } },
2036 static const GraticuleLines digital8[] = {
2037 { { { "16", 16 }, { "16", 16 }, { "16", 16 }, { "0", 0 } } },
2038 { { { "128", 128 }, { "128", 128 }, { "128", 128 }, { "128", 128 } } },
2039 { { { "235", 235 }, { "240", 240 }, { "240", 240 }, { "255", 255 } } },
2042 static const GraticuleLines digital9[] = {
2043 { { { "32", 32 }, { "32", 32 }, { "32", 32 }, { "0", 0 } } },
2044 { { { "256", 256 }, { "256", 256 }, { "256", 256 }, { "256", 256 } } },
2045 { { { "470", 470 }, { "480", 480 }, { "480", 480 }, { "511", 511 } } },
2048 static const GraticuleLines digital10[] = {
2049 { { { "64", 64 }, { "64", 64 }, { "64", 64 }, { "0", 0 } } },
2050 { { { "512", 512 }, { "512", 512 }, { "512", 512 }, { "512", 512 } } },
2051 { { { "940", 940 }, { "960", 960 }, { "960", 960 }, { "1023", 1023 } } },
2054 static const GraticuleLines digital12[] = {
2055 { { { "256", 256 }, { "256", 256 }, { "256", 256 }, { "0", 0 } } },
2056 { { { "2048", 2048 }, { "2048", 2048 }, { "2048", 2048 }, { "2048", 2048 } } },
2057 { { { "3760", 3760 }, { "3840", 3840 }, { "3840", 3840 }, { "4095", 4095 } } },
2060 static const GraticuleLines millivolts8[] = {
2061 { { { "0", 16 }, { "0", 16 }, { "0", 16 }, { "0", 0 } } },
2062 { { { "175", 71 }, { "175", 72 }, { "175", 72 }, { "175", 64 } } },
2063 { { { "350", 126 }, { "350", 128 }, { "350", 128 }, { "350", 128 } } },
2064 { { { "525", 180 }, { "525", 184 }, { "525", 184 }, { "525", 192 } } },
2065 { { { "700", 235 }, { "700", 240 }, { "700", 240 }, { "700", 255 } } },
2068 static const GraticuleLines millivolts9[] = {
2069 { { { "0", 32 }, { "0", 32 }, { "0", 32 }, { "0", 0 } } },
2070 { { { "175", 142 }, { "175", 144 }, { "175", 144 }, { "175", 128 } } },
2071 { { { "350", 251 }, { "350", 256 }, { "350", 256 }, { "350", 256 } } },
2072 { { { "525", 361 }, { "525", 368 }, { "525", 368 }, { "525", 384 } } },
2073 { { { "700", 470 }, { "700", 480 }, { "700", 480 }, { "700", 511 } } },
2076 static const GraticuleLines millivolts10[] = {
2077 { { { "0", 64 }, { "0", 64 }, { "0", 64 }, { "0", 0 } } },
2078 { { { "175", 283 }, { "175", 288 }, { "175", 288 }, { "175", 256 } } },
2079 { { { "350", 502 }, { "350", 512 }, { "350", 512 }, { "350", 512 } } },
2080 { { { "525", 721 }, { "525", 736 }, { "525", 736 }, { "525", 768 } } },
2081 { { { "700", 940 }, { "700", 960 }, { "700", 960 }, { "700", 1023 } } },
2084 static const GraticuleLines millivolts12[] = {
2085 { { { "0", 256 }, { "0", 256 }, { "0", 256 }, { "0", 0 } } },
2086 { { { "175", 1132 }, { "175", 1152 }, { "175", 1152 }, { "175", 1024 } } },
2087 { { { "350", 2008 }, { "350", 2048 }, { "350", 2048 }, { "350", 2048 } } },
2088 { { { "525", 2884 }, { "525", 2944 }, { "525", 2944 }, { "525", 3072 } } },
2089 { { { "700", 3760 }, { "700", 3840 }, { "700", 3840 }, { "700", 4095 } } },
2092 static const GraticuleLines ire8[] = {
2093 { { { "0", 16 }, { "0", 16 }, { "0", 16 }, { "0", 0 } } },
2094 { { { "25", 71 }, { "25", 72 }, { "25", 72 }, { "25", 64 } } },
2095 { { { "50", 126 }, { "50", 128 }, { "50", 128 }, { "50", 128 } } },
2096 { { { "75", 180 }, { "75", 184 }, { "75", 184 }, { "75", 192 } } },
2097 { { { "100", 235 }, { "100", 240 }, { "100", 240 }, { "100", 255 } } },
2100 static const GraticuleLines ire9[] = {
2101 { { { "0", 32 }, { "0", 32 }, { "0", 32 }, { "0", 0 } } },
2102 { { { "25", 142 }, { "25", 144 }, { "25", 144 }, { "25", 128 } } },
2103 { { { "50", 251 }, { "50", 256 }, { "50", 256 }, { "50", 256 } } },
2104 { { { "75", 361 }, { "75", 368 }, { "75", 368 }, { "75", 384 } } },
2105 { { { "100", 470 }, { "100", 480 }, { "100", 480 }, { "100", 511 } } },
2108 static const GraticuleLines ire10[] = {
2109 { { { "0", 64 }, { "0", 64 }, { "0", 64 }, { "0", 0 } } },
2110 { { { "25", 283 }, { "25", 288 }, { "25", 288 }, { "25", 256 } } },
2111 { { { "50", 502 }, { "50", 512 }, { "50", 512 }, { "50", 512 } } },
2112 { { { "75", 721 }, { "75", 736 }, { "75", 736 }, { "75", 768 } } },
2113 { { { "100", 940 }, { "100", 960 }, { "100", 960 }, { "100", 1023 } } },
2116 static const GraticuleLines ire12[] = {
2117 { { { "0", 256 }, { "0", 256 }, { "0", 256 }, { "0", 0 } } },
2118 { { { "25", 1132 }, { "25", 1152 }, { "25", 1152 }, { "25", 1024 } } },
2119 { { { "50", 2008 }, { "50", 2048 }, { "50", 2048 }, { "50", 2048 } } },
2120 { { { "75", 2884 }, { "75", 2944 }, { "75", 2944 }, { "75", 3072 } } },
2121 { { { "100", 3760 }, { "100", 3840 }, { "100", 3840 }, { "100", 4095 } } },
2124 static const GraticuleLines chroma_digital8[] = {
2125 { { { "50", 50 }, { "50", 50 }, { "50", 50 }, { "50", 50 } } },
2126 { { { "100", 100 }, { "100", 100 }, { "100", 100 }, { "100", 100 } } },
2127 { { { "150", 150 }, { "150", 150 }, { "150", 150 }, { "150", 150 } } },
2128 { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2129 { { { "255", 255 }, { "255", 255 }, { "255", 255 }, { "255", 255 } } },
2132 static const GraticuleLines chroma_digital9[] = {
2133 { { { "100", 100 }, { "100", 100 }, { "100", 100 }, { "100", 100 } } },
2134 { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2135 { { { "300", 300 }, { "300", 300 }, { "300", 300 }, { "300", 300 } } },
2136 { { { "400", 400 }, { "400", 400 }, { "400", 400 }, { "400", 400 } } },
2137 { { { "500", 500 }, { "500", 500 }, { "500", 500 }, { "500", 500 } } },
2140 static const GraticuleLines chroma_digital10[] = {
2141 { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2142 { { { "400", 400 }, { "400", 400 }, { "400", 400 }, { "400", 400 } } },
2143 { { { "600", 600 }, { "600", 600 }, { "600", 600 }, { "600", 600 } } },
2144 { { { "800", 800 }, { "800", 800 }, { "800", 800 }, { "800", 800 } } },
2145 { { {"1000",1000 }, {"1000",1000 }, {"1000",1000 }, {"1000",1000 } } },
2148 static const GraticuleLines chroma_digital12[] = {
2149 { { { "800", 800 }, { "800", 800 }, { "800", 800 }, { "800", 800 } } },
2150 { { { "1600", 1600 }, { "1600", 1600 }, { "1600", 1600 }, { "1600", 1600 } } },
2151 { { { "2400", 2400 }, { "2400", 2400 }, { "2400", 2400 }, { "2400", 2400 } } },
2152 { { { "3200", 3200 }, { "3200", 3200 }, { "3200", 3200 }, { "3200", 3200 } } },
2153 { { { "4000", 4000 }, { "4000", 4000 }, { "4000", 4000 }, { "4000", 4000 } } },
2156 static void blend_vline(uint8_t *dst, int height, int linesize, float o1, float o2, int v, int step)
2160 for (y = 0; y < height; y += step) {
2161 dst[0] = v * o1 + dst[0] * o2;
2163 dst += linesize * step;
2167 static void blend_vline16(uint16_t *dst, int height, int linesize, float o1, float o2, int v, int step)
2171 for (y = 0; y < height; y += step) {
2172 dst[0] = v * o1 + dst[0] * o2;
2174 dst += (linesize / 2) * step;
2178 static void blend_hline(uint8_t *dst, int width, float o1, float o2, int v, int step)
2182 for (x = 0; x < width; x += step) {
2183 dst[x] = v * o1 + dst[x] * o2;
2187 static void blend_hline16(uint16_t *dst, int width, float o1, float o2, int v, int step)
2191 for (x = 0; x < width; x += step) {
2192 dst[x] = v * o1 + dst[x] * o2;
2196 static void draw_htext(AVFrame *out, int x, int y, float o1, float o2, const char *txt, const uint8_t color[4])
2198 const uint8_t *font;
2202 font = avpriv_cga_font, font_height = 8;
2204 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2205 for (i = 0; txt[i]; i++) {
2207 int v = color[plane];
2209 uint8_t *p = out->data[plane] + y * out->linesize[plane] + (x + i * 8);
2210 for (char_y = 0; char_y < font_height; char_y++) {
2211 for (mask = 0x80; mask; mask >>= 1) {
2212 if (font[txt[i] * font_height + char_y] & mask)
2213 p[0] = p[0] * o2 + v * o1;
2216 p += out->linesize[plane] - 8;
2222 static void draw_htext16(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
2224 const uint8_t *font;
2228 font = avpriv_cga_font, font_height = 8;
2230 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2231 for (i = 0; txt[i]; i++) {
2233 int v = color[plane] * mult;
2235 uint16_t *p = (uint16_t *)(out->data[plane] + y * out->linesize[plane]) + (x + i * 8);
2236 for (char_y = 0; char_y < font_height; char_y++) {
2237 for (mask = 0x80; mask; mask >>= 1) {
2238 if (font[txt[i] * font_height + char_y] & mask)
2239 p[0] = p[0] * o2 + v * o1;
2242 p += out->linesize[plane] / 2 - 8;
2248 static void draw_vtext(AVFrame *out, int x, int y, float o1, float o2, const char *txt, const uint8_t color[4])
2250 const uint8_t *font;
2254 font = avpriv_cga_font, font_height = 8;
2256 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2257 for (i = 0; txt[i]; i++) {
2259 int v = color[plane];
2261 for (char_y = font_height - 1; char_y >= 0; char_y--) {
2262 uint8_t *p = out->data[plane] + (y + i * 10) * out->linesize[plane] + x;
2263 for (mask = 0x80; mask; mask >>= 1) {
2264 if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
2265 p[char_y] = p[char_y] * o2 + v * o1;
2266 p += out->linesize[plane];
2273 static void draw_vtext16(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
2275 const uint8_t *font;
2279 font = avpriv_cga_font, font_height = 8;
2281 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2282 for (i = 0; txt[i]; i++) {
2284 int v = color[plane] * mult;
2286 for (char_y = 0; char_y < font_height; char_y++) {
2287 uint16_t *p = (uint16_t *)(out->data[plane] + (y + i * 10) * out->linesize[plane]) + x;
2288 for (mask = 0x80; mask; mask >>= 1) {
2289 if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
2290 p[char_y] = p[char_y] * o2 + v * o1;
2291 p += out->linesize[plane] / 2;
2298 static void graticule_none(WaveformContext *s, AVFrame *out)
2302 static void graticule_green_row(WaveformContext *s, AVFrame *out)
2304 const int step = (s->flags & 2) + 1;
2305 const float o1 = s->opacity;
2306 const float o2 = 1. - o1;
2307 const int height = s->display == PARADE ? out->height / s->acomp : out->height;
2308 int k = 0, c, p, l, offset_x = 0, offset_y = 0;
2310 for (c = 0; c < s->ncomp; c++) {
2311 if (!((1 << c) & s->pcomp) || (!s->display && k > 0))
2315 for (p = 0; p < s->ncomp; p++) {
2316 const int v = green_yuva_color[p];
2317 for (l = 0; l < s->nb_glines; l++) {
2318 const uint16_t pos = s->glines[l].line[c].pos;
2319 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos);
2320 uint8_t *dst = out->data[p] + offset_y * out->linesize[p] + x;
2322 blend_vline(dst, height, out->linesize[p], o1, o2, v, step);
2326 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2327 const char *name = s->glines[l].line[c].name;
2328 const uint16_t pos = s->glines[l].line[c].pos;
2329 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos) - 10;
2334 draw_vtext(out, x, offset_y + 2, o1, o2, name, green_yuva_color);
2337 offset_x += s->size * (s->display == STACK);
2338 offset_y += height * (s->display == PARADE);
2342 static void graticule16_green_row(WaveformContext *s, AVFrame *out)
2344 const int step = (s->flags & 2) + 1;
2345 const float o1 = s->opacity;
2346 const float o2 = 1. - o1;
2347 const int mult = s->size / 256;
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 = green_yuva_color[p] * mult;
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 uint16_t *dst = (uint16_t *)(out->data[p] + offset_y * out->linesize[p]) + x;
2363 blend_vline16(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_vtext16(out, x, offset_y + 2, mult, o1, o2, name, green_yuva_color);
2378 offset_x += s->size * (s->display == STACK);
2379 offset_y += height * (s->display == PARADE);
2383 static void graticule_green_column(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 width = s->display == PARADE ? out->width / s->acomp : out->width;
2389 int k = 0, c, p, l, offset_y = 0, offset_x = 0;
2391 for (c = 0; c < s->ncomp; c++) {
2392 if ((!((1 << c) & s->pcomp) || (!s->display && k > 0)))
2396 for (p = 0; p < s->ncomp; p++) {
2397 const int v = green_yuva_color[p];
2398 for (l = 0; l < s->nb_glines ; l++) {
2399 const uint16_t pos = s->glines[l].line[c].pos;
2400 int y = offset_y + (s->mirror ? s->size - 1 - pos : pos);
2401 uint8_t *dst = out->data[p] + y * out->linesize[p] + offset_x;
2403 blend_hline(dst, width, o1, o2, v, step);
2407 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2408 const char *name = s->glines[l].line[c].name;
2409 const uint16_t pos = s->glines[l].line[c].pos;
2410 int y = offset_y + (s->mirror ? s->size - 1 - pos : pos) - 10;
2415 draw_htext(out, 2 + offset_x, y, o1, o2, name, green_yuva_color);
2418 offset_y += s->size * (s->display == STACK);
2419 offset_x += width * (s->display == PARADE);
2423 static void graticule16_green_column(WaveformContext *s, AVFrame *out)
2425 const int step = (s->flags & 2) + 1;
2426 const float o1 = s->opacity;
2427 const float o2 = 1. - o1;
2428 const int mult = s->size / 256;
2429 const int width = s->display == PARADE ? out->width / s->acomp : out->width;
2430 int k = 0, c, p, l, offset_x = 0, offset_y = 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 = green_yuva_color[p] * mult;
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 uint16_t *dst = (uint16_t *)(out->data[p] + y * out->linesize[p]) + offset_x;
2444 blend_hline16(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_htext16(out, 2 + offset_x, y, mult, o1, o2, name, green_yuva_color);
2459 offset_y += s->size * (s->display == STACK);
2460 offset_x += width * (s->display == PARADE);
2464 static int config_input(AVFilterLink *inlink)
2466 AVFilterContext *ctx = inlink->dst;
2467 WaveformContext *s = ctx->priv;
2469 s->desc = av_pix_fmt_desc_get(inlink->format);
2470 s->ncomp = s->desc->nb_components;
2471 s->bits = s->desc->comp[0].depth;
2472 s->max = 1 << s->bits;
2473 s->intensity = s->fintensity * (s->max - 1);
2475 s->shift_w[0] = s->shift_w[3] = 0;
2476 s->shift_h[0] = s->shift_h[3] = 0;
2477 s->shift_w[1] = s->shift_w[2] = s->desc->log2_chroma_w;
2478 s->shift_h[1] = s->shift_h[2] = s->desc->log2_chroma_h;
2480 s->graticulef = graticule_none;
2482 switch (s->filter) {
2483 case AFLAT: s->size = 256 * 2; break;
2484 case FLAT: s->size = 256 * 3; break;
2485 default: s->size = 256; break;
2488 switch (s->filter | ((s->bits > 8) << 4) |
2489 (s->mode << 8) | (s->mirror << 12)) {
2490 case 0x1100: s->waveform = lowpass_column_mirror; break;
2491 case 0x1000: s->waveform = lowpass_row_mirror; break;
2492 case 0x0100: s->waveform = lowpass_column; break;
2493 case 0x0000: s->waveform = lowpass_row; break;
2494 case 0x1110: s->waveform = lowpass16_column_mirror; break;
2495 case 0x1010: s->waveform = lowpass16_row_mirror; break;
2496 case 0x0110: s->waveform = lowpass16_column; break;
2497 case 0x0010: s->waveform = lowpass16_row; break;
2501 case 0x0001: s->waveform = flat; break;
2505 case 0x0011: s->waveform = flat16; break;
2509 case 0x0002: s->waveform = aflat; break;
2513 case 0x0012: s->waveform = aflat16; break;
2517 case 0x0003: s->waveform = chroma; break;
2521 case 0x0013: s->waveform = chroma16; break;
2525 case 0x0004: s->waveform = color; break;
2529 case 0x0014: s->waveform = color16; break;
2533 case 0x0005: s->waveform = acolor; break;
2537 case 0x0015: s->waveform = acolor16; break;
2540 switch (s->filter) {
2547 if (s->graticule && s->mode == 1)
2548 s->graticulef = s->bits > 8 ? graticule16_green_column : graticule_green_column;
2549 else if (s->graticule && s->mode == 0)
2550 s->graticulef = s->bits > 8 ? graticule16_green_row : graticule_green_row;
2554 switch (s->filter) {
2561 case 8: s->glines = (GraticuleLines *)digital8; s->nb_glines = FF_ARRAY_ELEMS(digital8); break;
2562 case 9: s->glines = (GraticuleLines *)digital9; s->nb_glines = FF_ARRAY_ELEMS(digital9); break;
2563 case 10: s->glines = (GraticuleLines *)digital10; s->nb_glines = FF_ARRAY_ELEMS(digital10); break;
2564 case 12: s->glines = (GraticuleLines *)digital12; s->nb_glines = FF_ARRAY_ELEMS(digital12); break;
2569 case 8: s->glines = (GraticuleLines *)millivolts8; s->nb_glines = FF_ARRAY_ELEMS(millivolts8); break;
2570 case 9: s->glines = (GraticuleLines *)millivolts9; s->nb_glines = FF_ARRAY_ELEMS(millivolts9); break;
2571 case 10: s->glines = (GraticuleLines *)millivolts10; s->nb_glines = FF_ARRAY_ELEMS(millivolts10); break;
2572 case 12: s->glines = (GraticuleLines *)millivolts12; s->nb_glines = FF_ARRAY_ELEMS(millivolts12); break;
2577 case 8: s->glines = (GraticuleLines *)ire8; s->nb_glines = FF_ARRAY_ELEMS(ire8); break;
2578 case 9: s->glines = (GraticuleLines *)ire9; s->nb_glines = FF_ARRAY_ELEMS(ire9); break;
2579 case 10: s->glines = (GraticuleLines *)ire10; s->nb_glines = FF_ARRAY_ELEMS(ire10); break;
2580 case 12: s->glines = (GraticuleLines *)ire12; s->nb_glines = FF_ARRAY_ELEMS(ire12); break;
2589 case 8: s->glines = (GraticuleLines *)chroma_digital8; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital8); break;
2590 case 9: s->glines = (GraticuleLines *)chroma_digital9; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital9); break;
2591 case 10: s->glines = (GraticuleLines *)chroma_digital10; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital10); break;
2592 case 12: s->glines = (GraticuleLines *)chroma_digital12; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital12); break;
2597 case 8: s->glines = (GraticuleLines *)millivolts8; s->nb_glines = FF_ARRAY_ELEMS(millivolts8); break;
2598 case 9: s->glines = (GraticuleLines *)millivolts9; s->nb_glines = FF_ARRAY_ELEMS(millivolts9); break;
2599 case 10: s->glines = (GraticuleLines *)millivolts10; s->nb_glines = FF_ARRAY_ELEMS(millivolts10); break;
2600 case 12: s->glines = (GraticuleLines *)millivolts12; s->nb_glines = FF_ARRAY_ELEMS(millivolts12); break;
2605 case 8: s->glines = (GraticuleLines *)ire8; s->nb_glines = FF_ARRAY_ELEMS(ire8); break;
2606 case 9: s->glines = (GraticuleLines *)ire9; s->nb_glines = FF_ARRAY_ELEMS(ire9); break;
2607 case 10: s->glines = (GraticuleLines *)ire10; s->nb_glines = FF_ARRAY_ELEMS(ire10); break;
2608 case 12: s->glines = (GraticuleLines *)ire12; s->nb_glines = FF_ARRAY_ELEMS(ire12); break;
2617 case 8: s->glines = (GraticuleLines *)aflat_digital8; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital8); break;
2618 case 9: s->glines = (GraticuleLines *)aflat_digital9; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital9); break;
2619 case 10: s->glines = (GraticuleLines *)aflat_digital10; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital10); break;
2620 case 12: s->glines = (GraticuleLines *)aflat_digital12; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital12); break;
2625 case 8: s->glines = (GraticuleLines *)aflat_millivolts8; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts8); break;
2626 case 9: s->glines = (GraticuleLines *)aflat_millivolts9; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts9); break;
2627 case 10: s->glines = (GraticuleLines *)aflat_millivolts10; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts10); break;
2628 case 12: s->glines = (GraticuleLines *)aflat_millivolts12; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts12); break;
2633 case 8: s->glines = (GraticuleLines *)aflat_ire8; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire8); break;
2634 case 9: s->glines = (GraticuleLines *)aflat_ire9; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire9); break;
2635 case 10: s->glines = (GraticuleLines *)aflat_ire10; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire10); break;
2636 case 12: s->glines = (GraticuleLines *)aflat_ire12; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire12); break;
2645 case 8: s->glines = (GraticuleLines *)flat_digital8; s->nb_glines = FF_ARRAY_ELEMS(flat_digital8); break;
2646 case 9: s->glines = (GraticuleLines *)flat_digital9; s->nb_glines = FF_ARRAY_ELEMS(flat_digital9); break;
2647 case 10: s->glines = (GraticuleLines *)flat_digital10; s->nb_glines = FF_ARRAY_ELEMS(flat_digital10); break;
2648 case 12: s->glines = (GraticuleLines *)flat_digital12; s->nb_glines = FF_ARRAY_ELEMS(flat_digital12); break;
2653 case 8: s->glines = (GraticuleLines *)flat_millivolts8; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts8); break;
2654 case 9: s->glines = (GraticuleLines *)flat_millivolts9; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts9); break;
2655 case 10: s->glines = (GraticuleLines *)flat_millivolts10; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts10); break;
2656 case 12: s->glines = (GraticuleLines *)flat_millivolts12; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts12); break;
2661 case 8: s->glines = (GraticuleLines *)flat_ire8; s->nb_glines = FF_ARRAY_ELEMS(flat_ire8); break;
2662 case 9: s->glines = (GraticuleLines *)flat_ire9; s->nb_glines = FF_ARRAY_ELEMS(flat_ire9); break;
2663 case 10: s->glines = (GraticuleLines *)flat_ire10; s->nb_glines = FF_ARRAY_ELEMS(flat_ire10); break;
2664 case 12: s->glines = (GraticuleLines *)flat_ire12; s->nb_glines = FF_ARRAY_ELEMS(flat_ire12); break;
2671 s->size = s->size << (s->bits - 8);
2673 switch (inlink->format) {
2674 case AV_PIX_FMT_GBRAP:
2675 case AV_PIX_FMT_GBRP:
2676 case AV_PIX_FMT_GBRP9:
2677 case AV_PIX_FMT_GBRP10:
2678 case AV_PIX_FMT_GBRP12:
2679 memcpy(s->bg_color, black_gbrp_color, sizeof(s->bg_color));
2680 s->graticulef = graticule_none;
2683 memcpy(s->bg_color, black_yuva_color, sizeof(s->bg_color));
2686 s->bg_color[3] *= s->bgopacity;
2691 static int config_output(AVFilterLink *outlink)
2693 AVFilterContext *ctx = outlink->src;
2694 AVFilterLink *inlink = ctx->inputs[0];
2695 WaveformContext *s = ctx->priv;
2696 int comp = 0, i, j = 0, k, p, size;
2698 for (i = 0; i < s->ncomp; i++) {
2699 if ((1 << i) & s->pcomp)
2703 s->odesc = av_pix_fmt_desc_get(outlink->format);
2704 s->dcomp = s->odesc->nb_components;
2709 outlink->h = s->size * FFMAX(comp * (s->display == STACK), 1);
2710 outlink->w = inlink->w * FFMAX(comp * (s->display == PARADE), 1);
2713 outlink->w = s->size * FFMAX(comp * (s->display == STACK), 1);
2714 outlink->h = inlink->h * FFMAX(comp * (s->display == PARADE), 1);
2718 s->peak = av_malloc_array(size, 32 * sizeof(*s->peak));
2720 return AVERROR(ENOMEM);
2722 for (p = 0; p < s->ncomp; p++) {
2723 const int plane = s->desc->comp[p].plane;
2726 if (!((1 << p) & s->pcomp))
2729 for (k = 0; k < 4; k++) {
2730 s->emax[plane][k] = s->peak + size * (plane * 4 + k + 0);
2731 s->emin[plane][k] = s->peak + size * (plane * 4 + k + 16);
2734 offset = j++ * s->size * (s->display == STACK);
2735 s->estart[plane] = offset;
2736 s->eend[plane] = (offset + s->size - 1);
2737 for (i = 0; i < size; i++) {
2738 for (k = 0; k < 4; k++) {
2739 s->emax[plane][k][i] = s->estart[plane];
2740 s->emin[plane][k][i] = s->eend[plane];
2745 outlink->sample_aspect_ratio = (AVRational){1,1};
2750 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
2752 AVFilterContext *ctx = inlink->dst;
2753 WaveformContext *s = ctx->priv;
2754 AVFilterLink *outlink = ctx->outputs[0];
2758 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
2761 return AVERROR(ENOMEM);
2764 out->color_range = AVCOL_RANGE_JPEG;
2766 for (k = 0; k < s->dcomp; k++) {
2768 for (i = 0; i < outlink->h ; i++)
2769 memset(out->data[s->odesc->comp[k].plane] +
2770 i * out->linesize[s->odesc->comp[k].plane],
2771 s->bg_color[k], outlink->w);
2773 const int mult = s->max / 256;
2774 uint16_t *dst = (uint16_t *)out->data[s->odesc->comp[k].plane];
2776 for (i = 0; i < outlink->h ; i++) {
2777 for (j = 0; j < outlink->w; j++)
2778 dst[j] = s->bg_color[k] * mult;
2779 dst += out->linesize[s->odesc->comp[k].plane] / 2;
2784 for (k = 0, i = 0; k < s->ncomp; k++) {
2785 if ((1 << k) & s->pcomp) {
2789 if (s->display == PARADE) {
2790 offset_x = s->mode ? i++ * inlink->w : 0;
2791 offset_y = s->mode ? 0 : i++ * inlink->h;
2793 offset_y = s->mode ? i++ * s->size * !!s->display : 0;
2794 offset_x = s->mode ? 0 : i++ * s->size * !!s->display;
2796 s->waveform(s, in, out, k, s->intensity, offset_y, offset_x, s->mode, s->mirror);
2799 s->graticulef(s, out);
2802 return ff_filter_frame(outlink, out);
2805 static av_cold void uninit(AVFilterContext *ctx)
2807 WaveformContext *s = ctx->priv;
2812 static const AVFilterPad inputs[] = {
2815 .type = AVMEDIA_TYPE_VIDEO,
2816 .filter_frame = filter_frame,
2817 .config_props = config_input,
2822 static const AVFilterPad outputs[] = {
2825 .type = AVMEDIA_TYPE_VIDEO,
2826 .config_props = config_output,
2831 AVFilter ff_vf_waveform = {
2833 .description = NULL_IF_CONFIG_SMALL("Video waveform monitor."),
2834 .priv_size = sizeof(WaveformContext),
2835 .priv_class = &waveform_class,
2836 .query_formats = query_formats,