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,
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[] = {
225 static const enum AVPixelFormat out_rgb12_lowpass_pix_fmts[] = {
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 flat_pix_fmts[] = {
256 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P,
257 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV444P10,
258 AV_PIX_FMT_YUV444P12,
262 static int query_formats(AVFilterContext *ctx)
264 WaveformContext *s = ctx->priv;
265 const enum AVPixelFormat *out_pix_fmts;
266 const enum AVPixelFormat *in_pix_fmts;
267 const AVPixFmtDescriptor *desc;
268 AVFilterFormats *avff;
269 int depth, rgb, i, ret, ncomp;
271 if (!ctx->inputs[0]->in_formats ||
272 !ctx->inputs[0]->in_formats->nb_formats) {
273 return AVERROR(EAGAIN);
277 case LOWPASS: in_pix_fmts = in_lowpass_pix_fmts; break;
280 case FLAT: in_pix_fmts = in_flat_pix_fmts; break;
282 case COLOR: in_pix_fmts = in_color_pix_fmts; break;
285 if (!ctx->inputs[0]->out_formats) {
286 if ((ret = ff_formats_ref(ff_make_format_list(in_pix_fmts), &ctx->inputs[0]->out_formats)) < 0)
290 avff = ctx->inputs[0]->in_formats;
291 desc = av_pix_fmt_desc_get(avff->formats[0]);
292 ncomp = desc->nb_components;
293 rgb = desc->flags & AV_PIX_FMT_FLAG_RGB;
294 depth = desc->comp[0].depth;
295 for (i = 1; i < avff->nb_formats; i++) {
296 desc = av_pix_fmt_desc_get(avff->formats[i]);
297 if (rgb != (desc->flags & AV_PIX_FMT_FLAG_RGB) ||
298 depth != desc->comp[0].depth)
299 return AVERROR(EAGAIN);
302 if (s->filter == LOWPASS && ncomp == 1 && depth == 8)
303 out_pix_fmts = out_gray8_lowpass_pix_fmts;
304 else if (rgb && depth == 8 && ncomp > 2)
305 out_pix_fmts = out_rgb8_lowpass_pix_fmts;
306 else if (rgb && depth == 9 && ncomp > 2)
307 out_pix_fmts = out_rgb9_lowpass_pix_fmts;
308 else if (rgb && depth == 10 && ncomp > 2)
309 out_pix_fmts = out_rgb10_lowpass_pix_fmts;
310 else if (rgb && depth == 12 && ncomp > 2)
311 out_pix_fmts = out_rgb12_lowpass_pix_fmts;
312 else if (depth == 8 && ncomp > 2)
313 out_pix_fmts = out_yuv8_lowpass_pix_fmts;
314 else if (depth == 9 && ncomp > 2)
315 out_pix_fmts = out_yuv9_lowpass_pix_fmts;
316 else if (depth == 10 && ncomp > 2)
317 out_pix_fmts = out_yuv10_lowpass_pix_fmts;
318 else if (depth == 12 && ncomp > 2)
319 out_pix_fmts = out_yuv12_lowpass_pix_fmts;
321 return AVERROR(EAGAIN);
322 if ((ret = ff_formats_ref(ff_make_format_list(out_pix_fmts), &ctx->outputs[0]->in_formats)) < 0)
328 static void envelope_instant16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
330 const int dst_linesize = out->linesize[component] / 2;
331 const int bg = s->bg_color[component] * (s->max / 256);
332 const int limit = s->max - 1;
333 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
334 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
335 const int start = s->estart[plane];
336 const int end = s->eend[plane];
341 for (x = offset; x < offset + dst_w; x++) {
342 for (y = start; y < end; y++) {
343 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
349 for (y = end - 1; y >= start; y--) {
350 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
358 for (y = offset; y < offset + dst_h; y++) {
359 dst = (uint16_t *)out->data[component] + y * dst_linesize;
360 for (x = start; x < end; x++) {
366 for (x = end - 1; x >= start; x--) {
376 static void envelope_instant(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
378 const int dst_linesize = out->linesize[component];
379 const uint8_t bg = s->bg_color[component];
380 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
381 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
382 const int start = s->estart[plane];
383 const int end = s->eend[plane];
388 for (x = offset; x < offset + dst_w; x++) {
389 for (y = start; y < end; y++) {
390 dst = out->data[component] + y * dst_linesize + x;
396 for (y = end - 1; y >= start; y--) {
397 dst = out->data[component] + y * dst_linesize + x;
405 for (y = offset; y < offset + dst_h; y++) {
406 dst = out->data[component] + y * dst_linesize;
407 for (x = start; x < end; x++) {
413 for (x = end - 1; x >= start; x--) {
423 static void envelope_peak16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
425 const int dst_linesize = out->linesize[component] / 2;
426 const int bg = s->bg_color[component] * (s->max / 256);
427 const int limit = s->max - 1;
428 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
429 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
430 const int start = s->estart[plane];
431 const int end = s->eend[plane];
432 int *emax = s->emax[plane][component];
433 int *emin = s->emin[plane][component];
438 for (x = offset; x < offset + dst_w; x++) {
439 for (y = start; y < end && y < emin[x - offset]; y++) {
440 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
442 emin[x - offset] = y;
446 for (y = end - 1; y >= start && y >= emax[x - offset]; y--) {
447 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
449 emax[x - offset] = y;
455 if (s->envelope == 3)
456 envelope_instant16(s, out, plane, component, offset);
458 for (x = offset; x < offset + dst_w; x++) {
459 dst = (uint16_t *)out->data[component] + emin[x - offset] * dst_linesize + x;
461 dst = (uint16_t *)out->data[component] + emax[x - offset] * dst_linesize + x;
465 for (y = offset; y < offset + dst_h; y++) {
466 dst = (uint16_t *)out->data[component] + y * dst_linesize;
467 for (x = start; x < end && x < emin[y - offset]; x++) {
469 emin[y - offset] = x;
473 for (x = end - 1; x >= start && x >= emax[y - offset]; x--) {
475 emax[y - offset] = x;
481 if (s->envelope == 3)
482 envelope_instant16(s, out, plane, component, offset);
484 for (y = offset; y < offset + dst_h; y++) {
485 dst = (uint16_t *)out->data[component] + y * dst_linesize + emin[y - offset];
487 dst = (uint16_t *)out->data[component] + y * dst_linesize + emax[y - offset];
493 static void envelope_peak(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
495 const int dst_linesize = out->linesize[component];
496 const int bg = s->bg_color[component];
497 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
498 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
499 const int start = s->estart[plane];
500 const int end = s->eend[plane];
501 int *emax = s->emax[plane][component];
502 int *emin = s->emin[plane][component];
507 for (x = offset; x < offset + dst_w; x++) {
508 for (y = start; y < end && y < emin[x - offset]; y++) {
509 dst = out->data[component] + y * dst_linesize + x;
511 emin[x - offset] = y;
515 for (y = end - 1; y >= start && y >= emax[x - offset]; y--) {
516 dst = out->data[component] + y * dst_linesize + x;
518 emax[x - offset] = y;
524 if (s->envelope == 3)
525 envelope_instant(s, out, plane, component, offset);
527 for (x = offset; x < offset + dst_w; x++) {
528 dst = out->data[component] + emin[x - offset] * dst_linesize + x;
530 dst = out->data[component] + emax[x - offset] * dst_linesize + x;
534 for (y = offset; y < offset + dst_h; y++) {
535 dst = out->data[component] + y * dst_linesize;
536 for (x = start; x < end && x < emin[y - offset]; x++) {
538 emin[y - offset] = x;
542 for (x = end - 1; x >= start && x >= emax[y - offset]; x--) {
544 emax[y - offset] = x;
550 if (s->envelope == 3)
551 envelope_instant(s, out, plane, component, offset);
553 for (y = offset; y < offset + dst_h; y++) {
554 dst = out->data[component] + y * dst_linesize + emin[y - offset];
556 dst = out->data[component] + y * dst_linesize + emax[y - offset];
562 static void envelope16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
564 if (s->envelope == 0) {
566 } else if (s->envelope == 1) {
567 envelope_instant16(s, out, plane, component, offset);
569 envelope_peak16(s, out, plane, component, offset);
573 static void envelope(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
575 if (s->envelope == 0) {
577 } else if (s->envelope == 1) {
578 envelope_instant(s, out, plane, component, offset);
580 envelope_peak(s, out, plane, component, offset);
584 static void update16(uint16_t *target, int max, int intensity, int limit)
587 *target += intensity;
592 static void update(uint8_t *target, int max, int intensity)
595 *target += intensity;
600 static av_always_inline void lowpass16(WaveformContext *s,
601 AVFrame *in, AVFrame *out,
602 int component, int intensity,
603 int offset_y, int offset_x,
604 int column, int mirror)
606 const int plane = s->desc->comp[component].plane;
607 const int shift_w = s->shift_w[component];
608 const int shift_h = s->shift_h[component];
609 const int src_linesize = in->linesize[plane] / 2;
610 const int dst_linesize = out->linesize[plane] / 2;
611 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
612 const int limit = s->max - 1;
613 const int max = limit - intensity;
614 const int src_h = AV_CEIL_RSHIFT(in->height, shift_h);
615 const int src_w = AV_CEIL_RSHIFT(in->width, shift_w);
616 const uint16_t *src_data = (const uint16_t *)in->data[plane];
617 uint16_t *dst_data = (uint16_t *)out->data[plane] + offset_y * dst_linesize + offset_x;
618 uint16_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
619 uint16_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
620 const int step = column ? 1 << shift_w : 1 << shift_h;
624 if (!column && mirror)
627 for (y = 0; y < src_h; y++) {
628 const uint16_t *src_data_end = src_data + src_w;
629 uint16_t *dst = dst_line;
631 for (p = src_data; p < src_data_end; p++) {
633 int i = 0, v = FFMIN(*p, limit);
637 target = dst++ + dst_signed_linesize * v;
638 update16(target, max, intensity, limit);
639 } while (++i < step);
641 uint16_t *row = dst_data;
644 target = row - v - 1;
647 update16(target, max, intensity, limit);
649 } while (++i < step);
652 src_data += src_linesize;
653 dst_data += dst_linesize * step;
656 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
659 #define LOWPASS16_FUNC(name, column, mirror) \
660 static void lowpass16_##name(WaveformContext *s, \
661 AVFrame *in, AVFrame *out, \
662 int component, int intensity, \
663 int offset_y, int offset_x, \
664 int unused1, int unused2) \
666 lowpass16(s, in, out, component, intensity, \
667 offset_y, offset_x, column, mirror); \
670 LOWPASS16_FUNC(column_mirror, 1, 1)
671 LOWPASS16_FUNC(column, 1, 0)
672 LOWPASS16_FUNC(row_mirror, 0, 1)
673 LOWPASS16_FUNC(row, 0, 0)
675 static av_always_inline void lowpass(WaveformContext *s,
676 AVFrame *in, AVFrame *out,
677 int component, int intensity,
678 int offset_y, int offset_x,
679 int column, int mirror)
681 const int plane = s->desc->comp[component].plane;
682 const int shift_w = s->shift_w[component];
683 const int shift_h = s->shift_h[component];
684 const int src_linesize = in->linesize[plane];
685 const int dst_linesize = out->linesize[plane];
686 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
687 const int max = 255 - intensity;
688 const int src_h = AV_CEIL_RSHIFT(in->height, shift_h);
689 const int src_w = AV_CEIL_RSHIFT(in->width, shift_w);
690 const uint8_t *src_data = in->data[plane];
691 uint8_t *dst_data = out->data[plane] + offset_y * dst_linesize + offset_x;
692 uint8_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
693 uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
694 const int step = column ? 1 << shift_w : 1 << shift_h;
698 if (!column && mirror)
701 for (y = 0; y < src_h; y++) {
702 const uint8_t *src_data_end = src_data + src_w;
703 uint8_t *dst = dst_line;
705 for (p = src_data; p < src_data_end; p++) {
708 target = dst + dst_signed_linesize * *p;
710 update(target, max, intensity);
712 uint8_t *row = dst_data;
714 target = row - *p - 1;
717 update(target, max, intensity);
721 src_data += src_linesize;
722 dst_data += dst_linesize * step;
725 if (column && step > 1) {
726 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
727 const int dst_h = 256;
731 dst = out->data[plane] + offset_y * dst_linesize + offset_x;
732 for (y = 0; y < dst_h; y++) {
733 for (x = 0; x < dst_w; x+=step) {
734 for (z = 1; z < step; z++) {
740 } else if (step > 1) {
741 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
742 const int dst_w = 256;
746 dst = out->data[plane] + offset_y * dst_linesize + offset_x;
747 for (y = 0; y < dst_h; y+=step) {
748 for (z = 1; z < step; z++)
749 memcpy(dst + dst_linesize * z, dst, dst_w);
750 dst += dst_linesize * step;
754 envelope(s, out, plane, plane, column ? offset_x : offset_y);
757 #define LOWPASS_FUNC(name, column, mirror) \
758 static void lowpass_##name(WaveformContext *s, \
759 AVFrame *in, AVFrame *out, \
760 int component, int intensity, \
761 int offset_y, int offset_x, \
762 int unused1, int unused2) \
764 lowpass(s, in, out, component, intensity, \
765 offset_y, offset_x, column, mirror); \
768 LOWPASS_FUNC(column_mirror, 1, 1)
769 LOWPASS_FUNC(column, 1, 0)
770 LOWPASS_FUNC(row_mirror, 0, 1)
771 LOWPASS_FUNC(row, 0, 0)
773 static av_always_inline void flat16(WaveformContext *s,
774 AVFrame *in, AVFrame *out,
775 int component, int intensity,
776 int offset_y, int offset_x,
777 int column, int mirror)
779 const int plane = s->desc->comp[component].plane;
780 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
781 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
782 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
783 const int c0_shift_w = s->shift_w[ component + 0 ];
784 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
785 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
786 const int c0_shift_h = s->shift_h[ component + 0 ];
787 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
788 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
789 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
790 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
791 const int limit = s->max - 1;
792 const int max = limit - intensity;
793 const int mid = s->max / 2;
794 const int src_h = in->height;
795 const int src_w = in->width;
799 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
800 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
802 for (x = 0; x < src_w; x++) {
803 const uint16_t *c0_data = (uint16_t *)in->data[plane + 0];
804 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
805 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
806 uint16_t *d0_data = (uint16_t *)(out->data[plane]) + offset_y * d0_linesize + offset_x;
807 uint16_t *d1_data = (uint16_t *)(out->data[(plane + 1) % s->ncomp]) + offset_y * d1_linesize + offset_x;
808 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
809 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
810 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
811 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
813 for (y = 0; y < src_h; y++) {
814 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + s->max;
815 const int c1 = FFMIN(FFABS(c1_data[x >> c1_shift_w] - mid) + FFABS(c2_data[x >> c2_shift_w] - mid), limit);
818 target = d0 + x + d0_signed_linesize * c0;
819 update16(target, max, intensity, limit);
820 target = d1 + x + d1_signed_linesize * (c0 - c1);
821 update16(target, max, intensity, limit);
822 target = d1 + x + d1_signed_linesize * (c0 + c1);
823 update16(target, max, intensity, limit);
825 if (!c0_shift_h || (y & c0_shift_h))
826 c0_data += c0_linesize;
827 if (!c1_shift_h || (y & c1_shift_h))
828 c1_data += c1_linesize;
829 if (!c2_shift_h || (y & c2_shift_h))
830 c2_data += c2_linesize;
831 d0_data += d0_linesize;
832 d1_data += d1_linesize;
836 const uint16_t *c0_data = (uint16_t *)in->data[plane];
837 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
838 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
839 uint16_t *d0_data = (uint16_t *)(out->data[plane]) + offset_y * d0_linesize + offset_x;
840 uint16_t *d1_data = (uint16_t *)(out->data[(plane + 1) % s->ncomp]) + offset_y * d1_linesize + offset_x;
843 d0_data += s->size - 1;
844 d1_data += s->size - 1;
847 for (y = 0; y < src_h; y++) {
848 for (x = 0; x < src_w; x++) {
849 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + s->max;
850 const int c1 = FFMIN(FFABS(c1_data[x >> c1_shift_w] - mid) + FFABS(c2_data[x >> c2_shift_w] - mid), limit);
854 target = d0_data - c0;
855 update16(target, max, intensity, limit);
856 target = d1_data - (c0 - c1);
857 update16(target, max, intensity, limit);
858 target = d1_data - (c0 + c1);
859 update16(target, max, intensity, limit);
861 target = d0_data + c0;
862 update16(target, max, intensity, limit);
863 target = d1_data + (c0 - c1);
864 update16(target, max, intensity, limit);
865 target = d1_data + (c0 + c1);
866 update16(target, max, intensity, limit);
870 if (!c0_shift_h || (y & c0_shift_h))
871 c0_data += c0_linesize;
872 if (!c1_shift_h || (y & c1_shift_h))
873 c1_data += c1_linesize;
874 if (!c2_shift_h || (y & c2_shift_h))
875 c2_data += c2_linesize;
876 d0_data += d0_linesize;
877 d1_data += d1_linesize;
881 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
882 envelope16(s, out, plane, (plane + 1) % s->ncomp, column ? offset_x : offset_y);
885 static av_always_inline void flat(WaveformContext *s,
886 AVFrame *in, AVFrame *out,
887 int component, int intensity,
888 int offset_y, int offset_x,
889 int column, int mirror)
891 const int plane = s->desc->comp[component].plane;
892 const int c0_linesize = in->linesize[ plane + 0 ];
893 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
894 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
895 const int c0_shift_w = s->shift_w[ component + 0 ];
896 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
897 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
898 const int c0_shift_h = s->shift_h[ component + 0 ];
899 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
900 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
901 const int d0_linesize = out->linesize[ plane + 0 ];
902 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
903 const int max = 255 - intensity;
904 const int src_h = in->height;
905 const int src_w = in->width;
909 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
910 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
912 for (x = 0; x < src_w; x++) {
913 const uint8_t *c0_data = in->data[plane + 0];
914 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
915 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
916 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
917 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
918 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
919 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
920 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
921 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
923 for (y = 0; y < src_h; y++) {
924 const int c0 = c0_data[x >> c0_shift_w] + 256;
925 const int c1 = FFABS(c1_data[x >> c1_shift_w] - 128) + FFABS(c2_data[x >> c2_shift_w] - 128);
928 target = d0 + x + d0_signed_linesize * c0;
929 update(target, max, intensity);
930 target = d1 + x + d1_signed_linesize * (c0 - c1);
931 update(target, max, intensity);
932 target = d1 + x + d1_signed_linesize * (c0 + c1);
933 update(target, max, intensity);
935 if (!c0_shift_h || (y & c0_shift_h))
936 c0_data += c0_linesize;
937 if (!c1_shift_h || (y & c1_shift_h))
938 c1_data += c1_linesize;
939 if (!c2_shift_h || (y & c2_shift_h))
940 c2_data += c2_linesize;
941 d0_data += d0_linesize;
942 d1_data += d1_linesize;
946 const uint8_t *c0_data = in->data[plane];
947 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
948 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
949 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
950 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
953 d0_data += s->size - 1;
954 d1_data += s->size - 1;
957 for (y = 0; y < src_h; y++) {
958 for (x = 0; x < src_w; x++) {
959 int c0 = c0_data[x >> c0_shift_w] + 256;
960 const int c1 = FFABS(c1_data[x >> c1_shift_w] - 128) + FFABS(c2_data[x >> c2_shift_w] - 128);
964 target = d0_data - c0;
965 update(target, max, intensity);
966 target = d1_data - (c0 - c1);
967 update(target, max, intensity);
968 target = d1_data - (c0 + c1);
969 update(target, max, intensity);
971 target = d0_data + c0;
972 update(target, max, intensity);
973 target = d1_data + (c0 - c1);
974 update(target, max, intensity);
975 target = d1_data + (c0 + c1);
976 update(target, max, intensity);
980 if (!c0_shift_h || (y & c0_shift_h))
981 c0_data += c0_linesize;
982 if (!c1_shift_h || (y & c1_shift_h))
983 c1_data += c1_linesize;
984 if (!c2_shift_h || (y & c2_shift_h))
985 c2_data += c2_linesize;
986 d0_data += d0_linesize;
987 d1_data += d1_linesize;
991 envelope(s, out, plane, plane, column ? offset_x : offset_y);
992 envelope(s, out, plane, (plane + 1) % s->ncomp, column ? offset_x : offset_y);
995 static av_always_inline void aflat16(WaveformContext *s,
996 AVFrame *in, AVFrame *out,
997 int component, int intensity,
998 int offset_y, int offset_x,
999 int column, int mirror)
1001 const int plane = s->desc->comp[component].plane;
1002 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
1003 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1004 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1005 const int c0_shift_w = s->shift_w[ component + 0 ];
1006 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1007 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1008 const int c0_shift_h = s->shift_h[ component + 0 ];
1009 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1010 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1011 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
1012 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
1013 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2;
1014 const int limit = s->max - 1;
1015 const int max = limit - intensity;
1016 const int mid = s->max / 2;
1017 const int src_h = in->height;
1018 const int src_w = in->width;
1022 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1023 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1024 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1026 for (x = 0; x < src_w; x++) {
1027 const uint16_t *c0_data = (uint16_t *)in->data[plane + 0];
1028 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1029 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1030 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1031 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1032 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1033 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1034 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1035 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1036 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1037 uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1038 uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1040 for (y = 0; y < src_h; y++) {
1041 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + mid;
1042 const int c1 = FFMIN(c1_data[x >> c1_shift_w], limit) - mid;
1043 const int c2 = FFMIN(c2_data[x >> c2_shift_w], limit) - mid;
1046 target = d0 + x + d0_signed_linesize * c0;
1047 update16(target, max, intensity, limit);
1049 target = d1 + x + d1_signed_linesize * (c0 + c1);
1050 update16(target, max, intensity, limit);
1052 target = d2 + x + d2_signed_linesize * (c0 + c2);
1053 update16(target, max, intensity, limit);
1055 if (!c0_shift_h || (y & c0_shift_h))
1056 c0_data += c0_linesize;
1057 if (!c1_shift_h || (y & c1_shift_h))
1058 c1_data += c1_linesize;
1059 if (!c2_shift_h || (y & c2_shift_h))
1060 c2_data += c2_linesize;
1061 d0_data += d0_linesize;
1062 d1_data += d1_linesize;
1063 d2_data += d2_linesize;
1067 const uint16_t *c0_data = (uint16_t *)in->data[plane];
1068 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1069 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1070 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1071 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1072 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1075 d0_data += s->size - 1;
1076 d1_data += s->size - 1;
1077 d2_data += s->size - 1;
1080 for (y = 0; y < src_h; y++) {
1081 for (x = 0; x < src_w; x++) {
1082 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + mid;
1083 const int c1 = FFMIN(c1_data[x >> c1_shift_w], limit) - mid;
1084 const int c2 = FFMIN(c2_data[x >> c2_shift_w], limit) - mid;
1088 target = d0_data - c0;
1089 update16(target, max, intensity, limit);
1090 target = d1_data - (c0 + c1);
1091 update16(target, max, intensity, limit);
1092 target = d2_data - (c0 + c2);
1093 update16(target, max, intensity, limit);
1095 target = d0_data + c0;
1096 update16(target, max, intensity, limit);
1097 target = d1_data + (c0 + c1);
1098 update16(target, max, intensity, limit);
1099 target = d2_data + (c0 + c2);
1100 update16(target, max, intensity, limit);
1104 if (!c0_shift_h || (y & c0_shift_h))
1105 c0_data += c0_linesize;
1106 if (!c1_shift_h || (y & c1_shift_h))
1107 c1_data += c1_linesize;
1108 if (!c2_shift_h || (y & c2_shift_h))
1109 c2_data += c2_linesize;
1110 d0_data += d0_linesize;
1111 d1_data += d1_linesize;
1112 d2_data += d2_linesize;
1116 envelope16(s, out, plane, (plane + 0) % s->ncomp, column ? offset_x : offset_y);
1117 envelope16(s, out, plane, (plane + 1) % s->ncomp, column ? offset_x : offset_y);
1118 envelope16(s, out, plane, (plane + 2) % s->ncomp, column ? offset_x : offset_y);
1121 static av_always_inline void aflat(WaveformContext *s,
1122 AVFrame *in, AVFrame *out,
1123 int component, int intensity,
1124 int offset_y, int offset_x,
1125 int column, int mirror)
1127 const int plane = s->desc->comp[component].plane;
1128 const int c0_linesize = in->linesize[ plane + 0 ];
1129 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
1130 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
1131 const int c0_shift_w = s->shift_w[ component + 0 ];
1132 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1133 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1134 const int c0_shift_h = s->shift_h[ component + 0 ];
1135 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1136 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1137 const int d0_linesize = out->linesize[ plane + 0 ];
1138 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
1139 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp];
1140 const int max = 255 - intensity;
1141 const int src_h = in->height;
1142 const int src_w = in->width;
1146 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1147 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1148 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1150 for (x = 0; x < src_w; x++) {
1151 const uint8_t *c0_data = in->data[plane + 0];
1152 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1153 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1154 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1155 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1156 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1157 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1158 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1159 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1160 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1161 uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1162 uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1164 for (y = 0; y < src_h; y++) {
1165 const int c0 = c0_data[x >> c0_shift_w] + 128;
1166 const int c1 = c1_data[x >> c1_shift_w] - 128;
1167 const int c2 = c2_data[x >> c2_shift_w] - 128;
1170 target = d0 + x + d0_signed_linesize * c0;
1171 update(target, max, intensity);
1173 target = d1 + x + d1_signed_linesize * (c0 + c1);
1174 update(target, max, intensity);
1176 target = d2 + x + d2_signed_linesize * (c0 + c2);
1177 update(target, max, intensity);
1179 if (!c0_shift_h || (y & c0_shift_h))
1180 c0_data += c0_linesize;
1181 if (!c1_shift_h || (y & c1_shift_h))
1182 c1_data += c1_linesize;
1183 if (!c1_shift_h || (y & c1_shift_h))
1184 c2_data += c1_linesize;
1185 d0_data += d0_linesize;
1186 d1_data += d1_linesize;
1187 d2_data += d2_linesize;
1191 const uint8_t *c0_data = in->data[plane];
1192 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1193 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1194 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1195 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1196 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1199 d0_data += s->size - 1;
1200 d1_data += s->size - 1;
1201 d2_data += s->size - 1;
1204 for (y = 0; y < src_h; y++) {
1205 for (x = 0; x < src_w; x++) {
1206 const int c0 = c0_data[x >> c0_shift_w] + 128;
1207 const int c1 = c1_data[x >> c1_shift_w] - 128;
1208 const int c2 = c2_data[x >> c2_shift_w] - 128;
1212 target = d0_data - c0;
1213 update(target, max, intensity);
1214 target = d1_data - (c0 + c1);
1215 update(target, max, intensity);
1216 target = d2_data - (c0 + c2);
1217 update(target, max, intensity);
1219 target = d0_data + c0;
1220 update(target, max, intensity);
1221 target = d1_data + (c0 + c1);
1222 update(target, max, intensity);
1223 target = d2_data + (c0 + c2);
1224 update(target, max, intensity);
1228 if (!c0_shift_h || (y & c0_shift_h))
1229 c0_data += c0_linesize;
1230 if (!c1_shift_h || (y & c1_shift_h))
1231 c1_data += c1_linesize;
1232 if (!c2_shift_h || (y & c2_shift_h))
1233 c2_data += c2_linesize;
1234 d0_data += d0_linesize;
1235 d1_data += d1_linesize;
1236 d2_data += d2_linesize;
1240 envelope(s, out, plane, (plane + 0) % s->ncomp, column ? offset_x : offset_y);
1241 envelope(s, out, plane, (plane + 1) % s->ncomp, column ? offset_x : offset_y);
1242 envelope(s, out, plane, (plane + 2) % s->ncomp, column ? offset_x : offset_y);
1245 static av_always_inline void chroma16(WaveformContext *s,
1246 AVFrame *in, AVFrame *out,
1247 int component, int intensity,
1248 int offset_y, int offset_x,
1249 int column, int mirror)
1251 const int plane = s->desc->comp[component].plane;
1252 const int c0_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1253 const int c1_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1254 const int dst_linesize = out->linesize[plane] / 2;
1255 const int limit = s->max - 1;
1256 const int max = limit - intensity;
1257 const int mid = s->max / 2;
1258 const int c0_shift_w = s->shift_w[(component + 1) % s->ncomp];
1259 const int c1_shift_w = s->shift_w[(component + 2) % s->ncomp];
1260 const int c0_shift_h = s->shift_h[(component + 1) % s->ncomp];
1261 const int c1_shift_h = s->shift_h[(component + 2) % s->ncomp];
1262 const int src_h = in->height;
1263 const int src_w = in->width;
1267 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
1269 for (x = 0; x < src_w; x++) {
1270 const uint16_t *c0_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1271 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1272 uint16_t *dst_data = (uint16_t *)out->data[plane] + offset_y * dst_linesize + offset_x;
1273 uint16_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
1274 uint16_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
1275 uint16_t *dst = dst_line;
1277 for (y = 0; y < src_h; y++) {
1278 const int sum = FFMIN(FFABS(c0_data[x >> c0_shift_w] - mid) + FFABS(c1_data[x >> c1_shift_w] - mid - 1), limit);
1281 target = dst + x + dst_signed_linesize * sum;
1282 update16(target, max, intensity, limit);
1284 if (!c0_shift_h || (y & c0_shift_h))
1285 c0_data += c0_linesize;
1286 if (!c1_shift_h || (y & c1_shift_h))
1287 c1_data += c1_linesize;
1288 dst_data += dst_linesize;
1292 const uint16_t *c0_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1293 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1294 uint16_t *dst_data = (uint16_t *)out->data[plane] + offset_y * dst_linesize + offset_x;
1297 dst_data += s->size - 1;
1298 for (y = 0; y < src_h; y++) {
1299 for (x = 0; x < src_w; x++) {
1300 const int sum = FFMIN(FFABS(c0_data[x >> c0_shift_w] - mid) + FFABS(c1_data[x >> c1_shift_w] - mid - 1), limit);
1304 target = dst_data - sum;
1305 update16(target, max, intensity, limit);
1307 target = dst_data + sum;
1308 update16(target, max, intensity, limit);
1312 if (!c0_shift_h || (y & c0_shift_h))
1313 c0_data += c0_linesize;
1314 if (!c1_shift_h || (y & c1_shift_h))
1315 c1_data += c1_linesize;
1316 dst_data += dst_linesize;
1320 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
1323 static av_always_inline void chroma(WaveformContext *s,
1324 AVFrame *in, AVFrame *out,
1325 int component, int intensity,
1326 int offset_y, int offset_x,
1327 int column, int mirror)
1329 const int plane = s->desc->comp[component].plane;
1330 const int c0_linesize = in->linesize[(plane + 1) % s->ncomp];
1331 const int c1_linesize = in->linesize[(plane + 2) % s->ncomp];
1332 const int dst_linesize = out->linesize[plane];
1333 const int max = 255 - intensity;
1334 const int c0_shift_w = s->shift_w[(component + 1) % s->ncomp];
1335 const int c1_shift_w = s->shift_w[(component + 2) % s->ncomp];
1336 const int c0_shift_h = s->shift_h[(component + 1) % s->ncomp];
1337 const int c1_shift_h = s->shift_h[(component + 2) % s->ncomp];
1338 const int src_h = in->height;
1339 const int src_w = in->width;
1343 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
1345 for (x = 0; x < src_w; x++) {
1346 const uint8_t *c0_data = in->data[(plane + 1) % s->ncomp];
1347 const uint8_t *c1_data = in->data[(plane + 2) % s->ncomp];
1348 uint8_t *dst_data = out->data[plane] + offset_y * dst_linesize + offset_x;
1349 uint8_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
1350 uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
1351 uint8_t *dst = dst_line;
1353 for (y = 0; y < src_h; y++) {
1354 const int sum = FFABS(c0_data[x >> c0_shift_w] - 128) + FFABS(c1_data[x >> c1_shift_w] - 127);
1357 target = dst + x + dst_signed_linesize * sum;
1358 update(target, max, intensity);
1360 if (!c0_shift_h || (y & c0_shift_h))
1361 c0_data += c0_linesize;
1362 if (!c1_shift_h || (y & c1_shift_h))
1363 c1_data += c1_linesize;
1364 dst_data += dst_linesize;
1368 const uint8_t *c0_data = in->data[(plane + 1) % s->ncomp];
1369 const uint8_t *c1_data = in->data[(plane + 2) % s->ncomp];
1370 uint8_t *dst_data = out->data[plane] + offset_y * dst_linesize + offset_x;
1373 dst_data += s->size - 1;
1374 for (y = 0; y < src_h; y++) {
1375 for (x = 0; x < src_w; x++) {
1376 const int sum = FFABS(c0_data[x >> c0_shift_w] - 128) + FFABS(c1_data[x >> c1_shift_w] - 127);
1380 target = dst_data - sum;
1381 update(target, max, intensity);
1383 target = dst_data + sum;
1384 update(target, max, intensity);
1388 if (!c0_shift_h || (y & c0_shift_h))
1389 c0_data += c0_linesize;
1390 if (!c1_shift_h || (y & c1_shift_h))
1391 c1_data += c1_linesize;
1392 dst_data += dst_linesize;
1396 envelope(s, out, plane, plane, column ? offset_x : offset_y);
1399 static av_always_inline void color16(WaveformContext *s,
1400 AVFrame *in, AVFrame *out,
1401 int component, int intensity,
1402 int offset_y, int offset_x,
1403 int column, int mirror)
1405 const int plane = s->desc->comp[component].plane;
1406 const int limit = s->max - 1;
1407 const uint16_t *c0_data = (const uint16_t *)in->data[plane + 0];
1408 const uint16_t *c1_data = (const uint16_t *)in->data[(plane + 1) % s->ncomp];
1409 const uint16_t *c2_data = (const uint16_t *)in->data[(plane + 2) % s->ncomp];
1410 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
1411 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1412 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1413 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
1414 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
1415 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2;
1416 const int c0_shift_w = s->shift_w[ component + 0 ];
1417 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1418 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1419 const int c0_shift_h = s->shift_h[ component + 0 ];
1420 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1421 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1422 const int src_h = in->height;
1423 const int src_w = in->width;
1427 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1428 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1429 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1430 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1431 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1432 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1433 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1434 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1435 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1436 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1437 uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1438 uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1440 for (y = 0; y < src_h; y++) {
1441 for (x = 0; x < src_w; x++) {
1442 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1443 const int c1 = c1_data[x >> c1_shift_w];
1444 const int c2 = c2_data[x >> c2_shift_w];
1446 *(d0 + d0_signed_linesize * c0 + x) = c0;
1447 *(d1 + d1_signed_linesize * c0 + x) = c1;
1448 *(d2 + d2_signed_linesize * c0 + x) = c2;
1451 if (!c0_shift_h || (y & c0_shift_h))
1452 c0_data += c0_linesize;
1453 if (!c1_shift_h || (y & c1_shift_h))
1454 c1_data += c1_linesize;
1455 if (!c2_shift_h || (y & c2_shift_h))
1456 c2_data += c2_linesize;
1457 d0_data += d0_linesize;
1458 d1_data += d1_linesize;
1459 d2_data += d2_linesize;
1462 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1463 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1464 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1467 d0_data += s->size - 1;
1468 d1_data += s->size - 1;
1469 d2_data += s->size - 1;
1472 for (y = 0; y < src_h; y++) {
1473 for (x = 0; x < src_w; x++) {
1474 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1475 const int c1 = c1_data[x >> c1_shift_w];
1476 const int c2 = c2_data[x >> c2_shift_w];
1479 *(d0_data - c0) = c0;
1480 *(d1_data - c0) = c1;
1481 *(d2_data - c0) = c2;
1483 *(d0_data + c0) = c0;
1484 *(d1_data + c0) = c1;
1485 *(d2_data + c0) = c2;
1489 if (!c0_shift_h || (y & c0_shift_h))
1490 c0_data += c0_linesize;
1491 if (!c1_shift_h || (y & c1_shift_h))
1492 c1_data += c1_linesize;
1493 if (!c2_shift_h || (y & c2_shift_h))
1494 c2_data += c2_linesize;
1495 d0_data += d0_linesize;
1496 d1_data += d1_linesize;
1497 d2_data += d2_linesize;
1501 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
1504 static av_always_inline void color(WaveformContext *s,
1505 AVFrame *in, AVFrame *out,
1506 int component, int intensity,
1507 int offset_y, int offset_x,
1508 int column, int mirror)
1510 const int plane = s->desc->comp[component].plane;
1511 const uint8_t *c0_data = in->data[plane + 0];
1512 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1513 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1514 const int c0_linesize = in->linesize[ plane + 0 ];
1515 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
1516 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
1517 const int d0_linesize = out->linesize[ plane + 0 ];
1518 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
1519 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp];
1520 const int c0_shift_w = s->shift_w[ component + 0 ];
1521 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1522 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1523 const int c0_shift_h = s->shift_h[ component + 0 ];
1524 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1525 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1526 const int src_h = in->height;
1527 const int src_w = in->width;
1531 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1532 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1533 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1534 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1535 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1536 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1537 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1538 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1539 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1540 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1541 uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1542 uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1544 for (y = 0; y < src_h; y++) {
1545 for (x = 0; x < src_w; x++) {
1546 const int c0 = c0_data[x >> c0_shift_w];
1547 const int c1 = c1_data[x >> c1_shift_w];
1548 const int c2 = c2_data[x >> c2_shift_w];
1550 *(d0 + d0_signed_linesize * c0 + x) = c0;
1551 *(d1 + d1_signed_linesize * c0 + x) = c1;
1552 *(d2 + d2_signed_linesize * c0 + x) = c2;
1555 if (!c0_shift_h || (y & c0_shift_h))
1556 c0_data += c0_linesize;
1557 if (!c1_shift_h || (y & c1_shift_h))
1558 c1_data += c1_linesize;
1559 if (!c2_shift_h || (y & c2_shift_h))
1560 c2_data += c2_linesize;
1561 d0_data += d0_linesize;
1562 d1_data += d1_linesize;
1563 d2_data += d2_linesize;
1566 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1567 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1568 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1571 d0_data += s->size - 1;
1572 d1_data += s->size - 1;
1573 d2_data += s->size - 1;
1576 for (y = 0; y < src_h; y++) {
1577 for (x = 0; x < src_w; x++) {
1578 const int c0 = c0_data[x >> c0_shift_w];
1579 const int c1 = c1_data[x >> c1_shift_w];
1580 const int c2 = c2_data[x >> c2_shift_w];
1583 *(d0_data - c0) = c0;
1584 *(d1_data - c0) = c1;
1585 *(d2_data - c0) = c2;
1587 *(d0_data + c0) = c0;
1588 *(d1_data + c0) = c1;
1589 *(d2_data + c0) = c2;
1593 if (!c0_shift_h || (y & c0_shift_h))
1594 c0_data += c0_linesize;
1595 if (!c1_shift_h || (y & c1_shift_h))
1596 c1_data += c1_linesize;
1597 if (!c2_shift_h || (y & c2_shift_h))
1598 c2_data += c2_linesize;
1599 d0_data += d0_linesize;
1600 d1_data += d1_linesize;
1601 d2_data += d2_linesize;
1605 envelope(s, out, plane, plane, column ? offset_x : offset_y);
1608 static av_always_inline void acolor16(WaveformContext *s,
1609 AVFrame *in, AVFrame *out,
1610 int component, int intensity,
1611 int offset_y, int offset_x,
1612 int column, int mirror)
1614 const int plane = s->desc->comp[component].plane;
1615 const int limit = s->max - 1;
1616 const int max = limit - intensity;
1617 const uint16_t *c0_data = (const uint16_t *)in->data[plane + 0];
1618 const uint16_t *c1_data = (const uint16_t *)in->data[(plane + 1) % s->ncomp];
1619 const uint16_t *c2_data = (const uint16_t *)in->data[(plane + 2) % s->ncomp];
1620 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
1621 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1622 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1623 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
1624 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
1625 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2;
1626 const int c0_shift_w = s->shift_w[ component + 0 ];
1627 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1628 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1629 const int c0_shift_h = s->shift_h[ component + 0 ];
1630 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1631 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1632 const int src_h = in->height;
1633 const int src_w = in->width;
1637 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1638 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1639 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1640 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1641 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1642 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1643 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1644 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1645 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1646 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1647 uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1648 uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1650 for (y = 0; y < src_h; y++) {
1651 for (x = 0; x < src_w; x++) {
1652 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1653 const int c1 = c1_data[x >> c1_shift_w];
1654 const int c2 = c2_data[x >> c2_shift_w];
1656 update16(d0 + d0_signed_linesize * c0 + x, max, intensity, limit);
1657 *(d1 + d1_signed_linesize * c0 + x) = c1;
1658 *(d2 + d2_signed_linesize * c0 + x) = c2;
1661 if (!c0_shift_h || (y & c0_shift_h))
1662 c0_data += c0_linesize;
1663 if (!c1_shift_h || (y & c1_shift_h))
1664 c1_data += c1_linesize;
1665 if (!c2_shift_h || (y & c2_shift_h))
1666 c2_data += c2_linesize;
1667 d0_data += d0_linesize;
1668 d1_data += d1_linesize;
1669 d2_data += d2_linesize;
1672 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1673 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1674 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1677 d0_data += s->size - 1;
1678 d1_data += s->size - 1;
1679 d2_data += s->size - 1;
1682 for (y = 0; y < src_h; y++) {
1683 for (x = 0; x < src_w; x++) {
1684 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1685 const int c1 = c1_data[x >> c1_shift_w];
1686 const int c2 = c2_data[x >> c2_shift_w];
1689 update16(d0_data - c0, max, intensity, limit);
1690 *(d1_data - c0) = c1;
1691 *(d2_data - c0) = c2;
1693 update16(d0_data + c0, max, intensity, limit);
1694 *(d1_data + c0) = c1;
1695 *(d2_data + c0) = c2;
1699 if (!c0_shift_h || (y & c0_shift_h))
1700 c0_data += c0_linesize;
1701 if (!c1_shift_h || (y & c1_shift_h))
1702 c1_data += c1_linesize;
1703 if (!c2_shift_h || (y & c2_shift_h))
1704 c2_data += c2_linesize;
1705 d0_data += d0_linesize;
1706 d1_data += d1_linesize;
1707 d2_data += d2_linesize;
1711 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
1714 static av_always_inline void acolor(WaveformContext *s,
1715 AVFrame *in, AVFrame *out,
1716 int component, int intensity,
1717 int offset_y, int offset_x,
1718 int column, int mirror)
1720 const int plane = s->desc->comp[component].plane;
1721 const uint8_t *c0_data = in->data[plane + 0];
1722 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1723 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1724 const int c0_linesize = in->linesize[ plane + 0 ];
1725 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
1726 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
1727 const int d0_linesize = out->linesize[ plane + 0 ];
1728 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
1729 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp];
1730 const int c0_shift_w = s->shift_w[ component + 0 ];
1731 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1732 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1733 const int c0_shift_h = s->shift_h[ component + 0 ];
1734 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1735 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1736 const int max = 255 - intensity;
1737 const int src_h = in->height;
1738 const int src_w = in->width;
1742 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1743 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1744 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1745 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1746 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1747 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1748 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1749 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1750 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1751 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1752 uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1753 uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1755 for (y = 0; y < src_h; y++) {
1756 for (x = 0; x < src_w; x++) {
1757 const int c0 = c0_data[x >> c0_shift_w];
1758 const int c1 = c1_data[x >> c1_shift_w];
1759 const int c2 = c2_data[x >> c2_shift_w];
1761 update(d0 + d0_signed_linesize * c0 + x, max, intensity);
1762 *(d1 + d1_signed_linesize * c0 + x) = c1;
1763 *(d2 + d2_signed_linesize * c0 + x) = c2;
1766 if (!c0_shift_h || (y & c0_shift_h))
1767 c0_data += c0_linesize;
1768 if (!c1_shift_h || (y & c1_shift_h))
1769 c1_data += c1_linesize;
1770 if (!c2_shift_h || (y & c2_shift_h))
1771 c2_data += c2_linesize;
1772 d0_data += d0_linesize;
1773 d1_data += d1_linesize;
1774 d2_data += d2_linesize;
1777 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1778 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1779 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1782 d0_data += s->size - 1;
1783 d1_data += s->size - 1;
1784 d2_data += s->size - 1;
1787 for (y = 0; y < src_h; y++) {
1788 for (x = 0; x < src_w; x++) {
1789 const int c0 = c0_data[x >> c0_shift_w];
1790 const int c1 = c1_data[x >> c1_shift_w];
1791 const int c2 = c2_data[x >> c2_shift_w];
1794 update(d0_data - c0, max, intensity);
1795 *(d1_data - c0) = c1;
1796 *(d2_data - c0) = c2;
1798 update(d0_data + c0, max, intensity);
1799 *(d1_data + c0) = c1;
1800 *(d2_data + c0) = c2;
1804 if (!c0_shift_h || (y & c0_shift_h))
1805 c0_data += c0_linesize;
1806 if (!c1_shift_h || (y & c1_shift_h))
1807 c1_data += c1_linesize;
1808 if (!c2_shift_h || (y & c2_shift_h))
1809 c2_data += c2_linesize;
1810 d0_data += d0_linesize;
1811 d1_data += d1_linesize;
1812 d2_data += d2_linesize;
1816 envelope(s, out, plane, plane, column ? offset_x : offset_y);
1819 static const uint8_t black_yuva_color[4] = { 0, 127, 127, 255 };
1820 static const uint8_t green_yuva_color[4] = { 255, 0, 0, 255 };
1821 static const uint8_t black_gbrp_color[4] = { 0, 0, 0, 255 };
1823 static const GraticuleLines aflat_digital8[] = {
1824 { { { "16", 16+128 }, { "16", 16+128 }, { "16", 16+128 }, { "0", 0+128 } } },
1825 { { { "128", 128+128 }, { "128", 128+128 }, { "128", 128+128 }, { "128", 128+128 } } },
1826 { { { "235", 235+128 }, { "240", 240+128 }, { "240", 240+128 }, { "255", 255+128 } } },
1829 static const GraticuleLines aflat_digital9[] = {
1830 { { { "32", 32+256 }, { "32", 32+256 }, { "32", 32+256 }, { "0", 0+256 } } },
1831 { { { "256", 256+256 }, { "256", 256+256 }, { "256", 256+256 }, { "256", 256+256 } } },
1832 { { { "470", 470+256 }, { "480", 480+256 }, { "480", 480+256 }, { "511", 511+256 } } },
1835 static const GraticuleLines aflat_digital10[] = {
1836 { { { "64", 64+512 }, { "64", 64+512 }, { "64", 64+512 }, { "0", 0+512 } } },
1837 { { { "512", 512+512 }, { "512", 512+512 }, { "512", 512+512 }, { "512", 512+512 } } },
1838 { { { "940", 940+512 }, { "960", 960+512 }, { "960", 960+512 }, { "1023", 1023+512 } } },
1841 static const GraticuleLines aflat_digital12[] = {
1842 { { { "256", 256+2048 }, { "256", 256+2048 }, { "256", 256+2048 }, { "0", 0+2048 } } },
1843 { { { "2048", 2048+2048 }, { "2048", 2048+2048 }, { "2048", 2048+2048 }, { "2048", 2048+2048 } } },
1844 { { { "3760", 3760+2048 }, { "3840", 3840+2048 }, { "3840", 3840+2048 }, { "4095", 4095+2048 } } },
1847 static const GraticuleLines aflat_millivolts8[] = {
1848 { { { "0", 16+128 }, { "0", 16+128 }, { "0", 16+128 }, { "0", 0+128 } } },
1849 { { { "175", 71+128 }, { "175", 72+128 }, { "175", 72+128 }, { "175", 64+128 } } },
1850 { { { "350", 126+128 }, { "350", 128+128 }, { "350", 128+128 }, { "350", 128+128 } } },
1851 { { { "525", 180+128 }, { "525", 184+128 }, { "525", 184+128 }, { "525", 192+128 } } },
1852 { { { "700", 235+128 }, { "700", 240+128 }, { "700", 240+128 }, { "700", 255+128 } } },
1855 static const GraticuleLines aflat_millivolts9[] = {
1856 { { { "0", 32+256 }, { "0", 32+256 }, { "0", 32+256 }, { "0", 0+256 } } },
1857 { { { "175", 142+256 }, { "175", 144+256 }, { "175", 144+256 }, { "175", 128+256 } } },
1858 { { { "350", 251+256 }, { "350", 256+256 }, { "350", 256+256 }, { "350", 256+256 } } },
1859 { { { "525", 361+256 }, { "525", 368+256 }, { "525", 368+256 }, { "525", 384+256 } } },
1860 { { { "700", 470+256 }, { "700", 480+256 }, { "700", 480+256 }, { "700", 511+256 } } },
1863 static const GraticuleLines aflat_millivolts10[] = {
1864 { { { "0", 64+512 }, { "0", 64+512 }, { "0", 64+512 }, { "0", 0+512 } } },
1865 { { { "175", 283+512 }, { "175", 288+512 }, { "175", 288+512 }, { "175", 256+512 } } },
1866 { { { "350", 502+512 }, { "350", 512+512 }, { "350", 512+512 }, { "350", 512+512 } } },
1867 { { { "525", 721+512 }, { "525", 736+512 }, { "525", 736+512 }, { "525", 768+512 } } },
1868 { { { "700", 940+512 }, { "700", 960+512 }, { "700", 960+512 }, { "700", 1023+512 } } },
1871 static const GraticuleLines aflat_millivolts12[] = {
1872 { { { "0", 256+2048 }, { "0", 256+2048 }, { "0", 256+2048 }, { "0", 0+2048 } } },
1873 { { { "175", 1132+2048 }, { "175", 1152+2048 }, { "175", 1152+2048 }, { "175", 1024+2048 } } },
1874 { { { "350", 2008+2048 }, { "350", 2048+2048 }, { "350", 2048+2048 }, { "350", 2048+2048 } } },
1875 { { { "525", 2884+2048 }, { "525", 2944+2048 }, { "525", 2944+2048 }, { "525", 3072+2048 } } },
1876 { { { "700", 3760+2048 }, { "700", 3840+2048 }, { "700", 3840+2048 }, { "700", 4095+2048 } } },
1879 static const GraticuleLines aflat_ire8[] = {
1880 { { { "-25", -39+128 }, { "-25", -40+128 }, { "-25", -40+128 }, { "-25", -64+128 } } },
1881 { { { "0", 16+128 }, { "0", 16+128 }, { "0", 16+128 }, { "0", 0+128 } } },
1882 { { { "25", 71+128 }, { "25", 72+128 }, { "25", 72+128 }, { "25", 64+128 } } },
1883 { { { "50", 126+128 }, { "50", 128+128 }, { "50", 128+128 }, { "50", 128+128 } } },
1884 { { { "75", 180+128 }, { "75", 184+128 }, { "75", 184+128 }, { "75", 192+128 } } },
1885 { { { "100", 235+128 }, { "100", 240+128 }, { "100", 240+128 }, { "100", 256+128 } } },
1886 { { { "125", 290+128 }, { "125", 296+128 }, { "125", 296+128 }, { "125", 320+128 } } },
1889 static const GraticuleLines aflat_ire9[] = {
1890 { { { "-25", -78+256 }, { "-25", -80+256 }, { "-25", -80+256 }, { "-25",-128+256 } } },
1891 { { { "0", 32+256 }, { "0", 32+256 }, { "0", 32+256 }, { "0", 0+256 } } },
1892 { { { "25", 142+256 }, { "25", 144+256 }, { "25", 144+256 }, { "25", 128+256 } } },
1893 { { { "50", 251+256 }, { "50", 256+256 }, { "50", 256+256 }, { "50", 256+256 } } },
1894 { { { "75", 361+256 }, { "75", 368+256 }, { "75", 368+256 }, { "75", 384+256 } } },
1895 { { { "100", 470+256 }, { "100", 480+256 }, { "100", 480+256 }, { "100", 512+256 } } },
1896 { { { "125", 580+256 }, { "125", 592+256 }, { "125", 592+256 }, { "125", 640+256 } } },
1899 static const GraticuleLines aflat_ire10[] = {
1900 { { { "-25",-156+512 }, { "-25",-160+512 }, { "-25",-160+512 }, { "-25", -256+512 } } },
1901 { { { "0", 64+512 }, { "0", 64+512 }, { "0", 64+512 }, { "0", 0+512 } } },
1902 { { { "25", 283+512 }, { "25", 288+512 }, { "25", 288+512 }, { "25", 256+512 } } },
1903 { { { "50", 502+512 }, { "50", 512+512 }, { "50", 512+512 }, { "50", 512+512 } } },
1904 { { { "75", 721+512 }, { "75", 736+512 }, { "75", 736+512 }, { "75", 768+512 } } },
1905 { { { "100", 940+512 }, { "100", 960+512 }, { "100", 960+512 }, { "100", 1024+512 } } },
1906 { { { "125",1160+512 }, { "125",1184+512 }, { "125",1184+512 }, { "125", 1280+512 } } },
1909 static const GraticuleLines aflat_ire12[] = {
1910 { { { "-25", -624+2048 }, { "-25", -640+2048 }, { "-25", -640+2048 }, { "-25",-1024+2048 } } },
1911 { { { "0", 256+2048 }, { "0", 256+2048 }, { "0", 256+2048 }, { "0", 0+2048 } } },
1912 { { { "25", 1132+2048 }, { "25", 1152+2048 }, { "25", 1152+2048 }, { "25", 1024+2048 } } },
1913 { { { "50", 2008+2048 }, { "50", 2048+2048 }, { "50", 2048+2048 }, { "50", 2048+2048 } } },
1914 { { { "75", 2884+2048 }, { "75", 2944+2048 }, { "75", 2944+2048 }, { "75", 3072+2048 } } },
1915 { { { "100", 3760+2048 }, { "100", 3840+2048 }, { "100", 3840+2048 }, { "100", 4096+2048 } } },
1916 { { { "125", 4640+2048 }, { "125", 4736+2048 }, { "125", 4736+2048 }, { "125", 5120+2048 } } },
1919 static const GraticuleLines flat_digital8[] = {
1920 { { { "16", 16+256 }, { "16", 16+256 }, { "16", 16+256 }, { "0", 0+256 } } },
1921 { { { "128", 128+256 }, { "128", 128+256 }, { "128", 128+256 }, { "128", 128+256 } } },
1922 { { { "235", 235+256 }, { "240", 240+256 }, { "240", 240+256 }, { "255", 255+256 } } },
1925 static const GraticuleLines flat_digital9[] = {
1926 { { { "32", 32+512 }, { "32", 32+512 }, { "32", 32+512 }, { "0", 0+512 } } },
1927 { { { "256", 256+512 }, { "256", 256+512 }, { "256", 256+512 }, { "256", 256+512 } } },
1928 { { { "470", 470+512 }, { "480", 480+512 }, { "480", 480+512 }, { "511", 511+512 } } },
1931 static const GraticuleLines flat_digital10[] = {
1932 { { { "64", 64+1024 }, { "64", 64+1024 }, { "64", 64+1024 }, { "0", 0+1024 } } },
1933 { { { "512", 512+1024 }, { "512", 512+1024 }, { "512", 512+1024 }, { "512", 512+1024 } } },
1934 { { { "940", 940+1024 }, { "960", 960+1024 }, { "960", 960+1024 }, { "1023", 1023+1024 } } },
1937 static const GraticuleLines flat_digital12[] = {
1938 { { { "256", 256+4096 }, { "256", 256+4096 }, { "256", 256+4096 }, { "0", 0+4096 } } },
1939 { { { "2048", 2048+4096 }, { "2048", 2048+4096 }, { "2048", 2048+4096 }, { "2048", 2048+4096 } } },
1940 { { { "3760", 3760+4096 }, { "3840", 3840+4096 }, { "3840", 3840+4096 }, { "4095", 4095+4096 } } },
1943 static const GraticuleLines flat_millivolts8[] = {
1944 { { { "0", 16+256 }, { "0", 16+256 }, { "0", 16+256 }, { "0", 0+256 } } },
1945 { { { "175", 71+256 }, { "175", 72+256 }, { "175", 72+256 }, { "175", 64+256 } } },
1946 { { { "350", 126+256 }, { "350", 128+256 }, { "350", 128+256 }, { "350", 128+256 } } },
1947 { { { "525", 180+256 }, { "525", 184+256 }, { "525", 184+256 }, { "525", 192+256 } } },
1948 { { { "700", 235+256 }, { "700", 240+256 }, { "700", 240+256 }, { "700", 255+256 } } },
1951 static const GraticuleLines flat_millivolts9[] = {
1952 { { { "0", 32+512 }, { "0", 32+512 }, { "0", 32+512 }, { "0", 0+512 } } },
1953 { { { "175", 142+512 }, { "175", 144+512 }, { "175", 144+512 }, { "175", 128+512 } } },
1954 { { { "350", 251+512 }, { "350", 256+512 }, { "350", 256+512 }, { "350", 256+512 } } },
1955 { { { "525", 361+512 }, { "525", 368+512 }, { "525", 368+512 }, { "525", 384+512 } } },
1956 { { { "700", 470+512 }, { "700", 480+512 }, { "700", 480+512 }, { "700", 511+512 } } },
1959 static const GraticuleLines flat_millivolts10[] = {
1960 { { { "0", 64+1024 }, { "0", 64+1024 }, { "0", 64+1024 }, { "0", 0+1024 } } },
1961 { { { "175", 283+1024 }, { "175", 288+1024 }, { "175", 288+1024 }, { "175", 256+1024 } } },
1962 { { { "350", 502+1024 }, { "350", 512+1024 }, { "350", 512+1024 }, { "350", 512+1024 } } },
1963 { { { "525", 721+1024 }, { "525", 736+1024 }, { "525", 736+1024 }, { "525", 768+1024 } } },
1964 { { { "700", 940+1024 }, { "700", 960+1024 }, { "700", 960+1024 }, { "700", 1023+1024 } } },
1967 static const GraticuleLines flat_millivolts12[] = {
1968 { { { "0", 256+4096 }, { "0", 256+4096 }, { "0", 256+4096 }, { "0", 0+4096 } } },
1969 { { { "175", 1132+4096 }, { "175", 1152+4096 }, { "175", 1152+4096 }, { "175", 1024+4096 } } },
1970 { { { "350", 2008+4096 }, { "350", 2048+4096 }, { "350", 2048+4096 }, { "350", 2048+4096 } } },
1971 { { { "525", 2884+4096 }, { "525", 2944+4096 }, { "525", 2944+4096 }, { "525", 3072+4096 } } },
1972 { { { "700", 3760+4096 }, { "700", 3840+4096 }, { "700", 3840+4096 }, { "700", 4095+4096 } } },
1975 static const GraticuleLines flat_ire8[] = {
1976 { { { "-25", -39+256 }, { "-25", -40+256 }, { "-25", -40+256 }, { "-25", -64+256 } } },
1977 { { { "0", 16+256 }, { "0", 16+256 }, { "0", 16+256 }, { "0", 0+256 } } },
1978 { { { "25", 71+256 }, { "25", 72+256 }, { "25", 72+256 }, { "25", 64+256 } } },
1979 { { { "50", 126+256 }, { "50", 128+256 }, { "50", 128+256 }, { "50", 128+256 } } },
1980 { { { "75", 180+256 }, { "75", 184+256 }, { "75", 184+256 }, { "75", 192+256 } } },
1981 { { { "100", 235+256 }, { "100", 240+256 }, { "100", 240+256 }, { "100", 256+256 } } },
1982 { { { "125", 290+256 }, { "125", 296+256 }, { "125", 296+256 }, { "125", 320+256 } } },
1985 static const GraticuleLines flat_ire9[] = {
1986 { { { "-25", -78+512 }, { "-25", -80+512 }, { "-25", -80+512 }, { "-25",-128+512 } } },
1987 { { { "0", 32+512 }, { "0", 32+512 }, { "0", 32+512 }, { "0", 0+512 } } },
1988 { { { "25", 142+512 }, { "25", 144+512 }, { "25", 144+512 }, { "25", 128+512 } } },
1989 { { { "50", 251+512 }, { "50", 256+512 }, { "50", 256+512 }, { "50", 256+512 } } },
1990 { { { "75", 361+512 }, { "75", 368+512 }, { "75", 368+512 }, { "75", 384+512 } } },
1991 { { { "100", 470+512 }, { "100", 480+512 }, { "100", 480+512 }, { "100", 512+512 } } },
1992 { { { "125", 580+512 }, { "125", 592+512 }, { "125", 592+512 }, { "125", 640+512 } } },
1995 static const GraticuleLines flat_ire10[] = {
1996 { { { "-25",-156+1024 }, { "-25",-160+1024 }, { "-25",-160+1024 }, { "-25", -256+1024 } } },
1997 { { { "0", 64+1024 }, { "0", 64+1024 }, { "0", 64+1024 }, { "0", 0+1024 } } },
1998 { { { "25", 283+1024 }, { "25", 288+1024 }, { "25", 288+1024 }, { "25", 256+1024 } } },
1999 { { { "50", 502+1024 }, { "50", 512+1024 }, { "50", 512+1024 }, { "50", 512+1024 } } },
2000 { { { "75", 721+1024 }, { "75", 736+1024 }, { "75", 736+1024 }, { "75", 768+1024 } } },
2001 { { { "100", 940+1024 }, { "100", 960+1024 }, { "100", 960+1024 }, { "100", 1024+1024 } } },
2002 { { { "125",1160+1024 }, { "125",1184+1024 }, { "125",1184+1024 }, { "125", 1280+1024 } } },
2005 static const GraticuleLines flat_ire12[] = {
2006 { { { "-25", -624+4096 }, { "-25", -640+4096 }, { "-25", -640+4096 }, { "-25",-1024+4096 } } },
2007 { { { "0", 256+4096 }, { "0", 256+4096 }, { "0", 256+4096 }, { "0", 0+4096 } } },
2008 { { { "25", 1132+4096 }, { "25", 1152+4096 }, { "25", 1152+4096 }, { "25", 1024+4096 } } },
2009 { { { "50", 2008+4096 }, { "50", 2048+4096 }, { "50", 2048+4096 }, { "50", 2048+4096 } } },
2010 { { { "75", 2884+4096 }, { "75", 2944+4096 }, { "75", 2944+4096 }, { "75", 3072+4096 } } },
2011 { { { "100", 3760+4096 }, { "100", 3840+4096 }, { "100", 3840+4096 }, { "100", 4096+4096 } } },
2012 { { { "125", 4640+4096 }, { "125", 4736+4096 }, { "125", 4736+4096 }, { "125", 5120+4096 } } },
2015 static const GraticuleLines digital8[] = {
2016 { { { "16", 16 }, { "16", 16 }, { "16", 16 }, { "0", 0 } } },
2017 { { { "128", 128 }, { "128", 128 }, { "128", 128 }, { "128", 128 } } },
2018 { { { "235", 235 }, { "240", 240 }, { "240", 240 }, { "255", 255 } } },
2021 static const GraticuleLines digital9[] = {
2022 { { { "32", 32 }, { "32", 32 }, { "32", 32 }, { "0", 0 } } },
2023 { { { "256", 256 }, { "256", 256 }, { "256", 256 }, { "256", 256 } } },
2024 { { { "470", 470 }, { "480", 480 }, { "480", 480 }, { "511", 511 } } },
2027 static const GraticuleLines digital10[] = {
2028 { { { "64", 64 }, { "64", 64 }, { "64", 64 }, { "0", 0 } } },
2029 { { { "512", 512 }, { "512", 512 }, { "512", 512 }, { "512", 512 } } },
2030 { { { "940", 940 }, { "960", 960 }, { "960", 960 }, { "1023", 1023 } } },
2033 static const GraticuleLines digital12[] = {
2034 { { { "256", 256 }, { "256", 256 }, { "256", 256 }, { "0", 0 } } },
2035 { { { "2048", 2048 }, { "2048", 2048 }, { "2048", 2048 }, { "2048", 2048 } } },
2036 { { { "3760", 3760 }, { "3840", 3840 }, { "3840", 3840 }, { "4095", 4095 } } },
2039 static const GraticuleLines millivolts8[] = {
2040 { { { "0", 16 }, { "0", 16 }, { "0", 16 }, { "0", 0 } } },
2041 { { { "175", 71 }, { "175", 72 }, { "175", 72 }, { "175", 64 } } },
2042 { { { "350", 126 }, { "350", 128 }, { "350", 128 }, { "350", 128 } } },
2043 { { { "525", 180 }, { "525", 184 }, { "525", 184 }, { "525", 192 } } },
2044 { { { "700", 235 }, { "700", 240 }, { "700", 240 }, { "700", 255 } } },
2047 static const GraticuleLines millivolts9[] = {
2048 { { { "0", 32 }, { "0", 32 }, { "0", 32 }, { "0", 0 } } },
2049 { { { "175", 142 }, { "175", 144 }, { "175", 144 }, { "175", 128 } } },
2050 { { { "350", 251 }, { "350", 256 }, { "350", 256 }, { "350", 256 } } },
2051 { { { "525", 361 }, { "525", 368 }, { "525", 368 }, { "525", 384 } } },
2052 { { { "700", 470 }, { "700", 480 }, { "700", 480 }, { "700", 511 } } },
2055 static const GraticuleLines millivolts10[] = {
2056 { { { "0", 64 }, { "0", 64 }, { "0", 64 }, { "0", 0 } } },
2057 { { { "175", 283 }, { "175", 288 }, { "175", 288 }, { "175", 256 } } },
2058 { { { "350", 502 }, { "350", 512 }, { "350", 512 }, { "350", 512 } } },
2059 { { { "525", 721 }, { "525", 736 }, { "525", 736 }, { "525", 768 } } },
2060 { { { "700", 940 }, { "700", 960 }, { "700", 960 }, { "700", 1023 } } },
2063 static const GraticuleLines millivolts12[] = {
2064 { { { "0", 256 }, { "0", 256 }, { "0", 256 }, { "0", 0 } } },
2065 { { { "175", 1132 }, { "175", 1152 }, { "175", 1152 }, { "175", 1024 } } },
2066 { { { "350", 2008 }, { "350", 2048 }, { "350", 2048 }, { "350", 2048 } } },
2067 { { { "525", 2884 }, { "525", 2944 }, { "525", 2944 }, { "525", 3072 } } },
2068 { { { "700", 3760 }, { "700", 3840 }, { "700", 3840 }, { "700", 4095 } } },
2071 static const GraticuleLines ire8[] = {
2072 { { { "0", 16 }, { "0", 16 }, { "0", 16 }, { "0", 0 } } },
2073 { { { "25", 71 }, { "25", 72 }, { "25", 72 }, { "25", 64 } } },
2074 { { { "50", 126 }, { "50", 128 }, { "50", 128 }, { "50", 128 } } },
2075 { { { "75", 180 }, { "75", 184 }, { "75", 184 }, { "75", 192 } } },
2076 { { { "100", 235 }, { "100", 240 }, { "100", 240 }, { "100", 255 } } },
2079 static const GraticuleLines ire9[] = {
2080 { { { "0", 32 }, { "0", 32 }, { "0", 32 }, { "0", 0 } } },
2081 { { { "25", 142 }, { "25", 144 }, { "25", 144 }, { "25", 128 } } },
2082 { { { "50", 251 }, { "50", 256 }, { "50", 256 }, { "50", 256 } } },
2083 { { { "75", 361 }, { "75", 368 }, { "75", 368 }, { "75", 384 } } },
2084 { { { "100", 470 }, { "100", 480 }, { "100", 480 }, { "100", 511 } } },
2087 static const GraticuleLines ire10[] = {
2088 { { { "0", 64 }, { "0", 64 }, { "0", 64 }, { "0", 0 } } },
2089 { { { "25", 283 }, { "25", 288 }, { "25", 288 }, { "25", 256 } } },
2090 { { { "50", 502 }, { "50", 512 }, { "50", 512 }, { "50", 512 } } },
2091 { { { "75", 721 }, { "75", 736 }, { "75", 736 }, { "75", 768 } } },
2092 { { { "100", 940 }, { "100", 960 }, { "100", 960 }, { "100", 1023 } } },
2095 static const GraticuleLines ire12[] = {
2096 { { { "0", 256 }, { "0", 256 }, { "0", 256 }, { "0", 0 } } },
2097 { { { "25", 1132 }, { "25", 1152 }, { "25", 1152 }, { "25", 1024 } } },
2098 { { { "50", 2008 }, { "50", 2048 }, { "50", 2048 }, { "50", 2048 } } },
2099 { { { "75", 2884 }, { "75", 2944 }, { "75", 2944 }, { "75", 3072 } } },
2100 { { { "100", 3760 }, { "100", 3840 }, { "100", 3840 }, { "100", 4095 } } },
2103 static const GraticuleLines chroma_digital8[] = {
2104 { { { "50", 50 }, { "50", 50 }, { "50", 50 }, { "50", 50 } } },
2105 { { { "100", 100 }, { "100", 100 }, { "100", 100 }, { "100", 100 } } },
2106 { { { "150", 150 }, { "150", 150 }, { "150", 150 }, { "150", 150 } } },
2107 { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2108 { { { "255", 255 }, { "255", 255 }, { "255", 255 }, { "255", 255 } } },
2111 static const GraticuleLines chroma_digital9[] = {
2112 { { { "100", 100 }, { "100", 100 }, { "100", 100 }, { "100", 100 } } },
2113 { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2114 { { { "300", 300 }, { "300", 300 }, { "300", 300 }, { "300", 300 } } },
2115 { { { "400", 400 }, { "400", 400 }, { "400", 400 }, { "400", 400 } } },
2116 { { { "500", 500 }, { "500", 500 }, { "500", 500 }, { "500", 500 } } },
2119 static const GraticuleLines chroma_digital10[] = {
2120 { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2121 { { { "400", 400 }, { "400", 400 }, { "400", 400 }, { "400", 400 } } },
2122 { { { "600", 600 }, { "600", 600 }, { "600", 600 }, { "600", 600 } } },
2123 { { { "800", 800 }, { "800", 800 }, { "800", 800 }, { "800", 800 } } },
2124 { { {"1000",1000 }, {"1000",1000 }, {"1000",1000 }, {"1000",1000 } } },
2127 static const GraticuleLines chroma_digital12[] = {
2128 { { { "800", 800 }, { "800", 800 }, { "800", 800 }, { "800", 800 } } },
2129 { { { "1600", 1600 }, { "1600", 1600 }, { "1600", 1600 }, { "1600", 1600 } } },
2130 { { { "2400", 2400 }, { "2400", 2400 }, { "2400", 2400 }, { "2400", 2400 } } },
2131 { { { "3200", 3200 }, { "3200", 3200 }, { "3200", 3200 }, { "3200", 3200 } } },
2132 { { { "4000", 4000 }, { "4000", 4000 }, { "4000", 4000 }, { "4000", 4000 } } },
2135 static void blend_vline(uint8_t *dst, int height, int linesize, float o1, float o2, int v, int step)
2139 for (y = 0; y < height; y += step) {
2140 dst[0] = v * o1 + dst[0] * o2;
2142 dst += linesize * step;
2146 static void blend_vline16(uint16_t *dst, int height, int linesize, float o1, float o2, int v, int step)
2150 for (y = 0; y < height; y += step) {
2151 dst[0] = v * o1 + dst[0] * o2;
2153 dst += (linesize / 2) * step;
2157 static void blend_hline(uint8_t *dst, int width, float o1, float o2, int v, int step)
2161 for (x = 0; x < width; x += step) {
2162 dst[x] = v * o1 + dst[x] * o2;
2166 static void blend_hline16(uint16_t *dst, int width, float o1, float o2, int v, int step)
2170 for (x = 0; x < width; x += step) {
2171 dst[x] = v * o1 + dst[x] * o2;
2175 static void draw_htext(AVFrame *out, int x, int y, float o1, float o2, const char *txt, const uint8_t color[4])
2177 const uint8_t *font;
2181 font = avpriv_cga_font, font_height = 8;
2183 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2184 for (i = 0; txt[i]; i++) {
2186 int v = color[plane];
2188 uint8_t *p = out->data[plane] + y * out->linesize[plane] + (x + i * 8);
2189 for (char_y = 0; char_y < font_height; char_y++) {
2190 for (mask = 0x80; mask; mask >>= 1) {
2191 if (font[txt[i] * font_height + char_y] & mask)
2192 p[0] = p[0] * o2 + v * o1;
2195 p += out->linesize[plane] - 8;
2201 static void draw_htext16(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
2203 const uint8_t *font;
2207 font = avpriv_cga_font, font_height = 8;
2209 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2210 for (i = 0; txt[i]; i++) {
2212 int v = color[plane] * mult;
2214 uint16_t *p = (uint16_t *)(out->data[plane] + y * out->linesize[plane]) + (x + i * 8);
2215 for (char_y = 0; char_y < font_height; char_y++) {
2216 for (mask = 0x80; mask; mask >>= 1) {
2217 if (font[txt[i] * font_height + char_y] & mask)
2218 p[0] = p[0] * o2 + v * o1;
2221 p += out->linesize[plane] / 2 - 8;
2227 static void draw_vtext(AVFrame *out, int x, int y, float o1, float o2, const char *txt, const uint8_t color[4])
2229 const uint8_t *font;
2233 font = avpriv_cga_font, font_height = 8;
2235 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2236 for (i = 0; txt[i]; i++) {
2238 int v = color[plane];
2240 for (char_y = font_height - 1; char_y >= 0; char_y--) {
2241 uint8_t *p = out->data[plane] + (y + i * 10) * out->linesize[plane] + x;
2242 for (mask = 0x80; mask; mask >>= 1) {
2243 if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
2244 p[char_y] = p[char_y] * o2 + v * o1;
2245 p += out->linesize[plane];
2252 static void draw_vtext16(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
2254 const uint8_t *font;
2258 font = avpriv_cga_font, font_height = 8;
2260 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2261 for (i = 0; txt[i]; i++) {
2263 int v = color[plane] * mult;
2265 for (char_y = 0; char_y < font_height; char_y++) {
2266 uint16_t *p = (uint16_t *)(out->data[plane] + (y + i * 10) * out->linesize[plane]) + x;
2267 for (mask = 0x80; mask; mask >>= 1) {
2268 if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
2269 p[char_y] = p[char_y] * o2 + v * o1;
2270 p += out->linesize[plane] / 2;
2277 static void graticule_none(WaveformContext *s, AVFrame *out)
2281 static void graticule_green_row(WaveformContext *s, AVFrame *out)
2283 const int step = (s->flags & 2) + 1;
2284 const float o1 = s->opacity;
2285 const float o2 = 1. - o1;
2286 const int height = s->display == PARADE ? out->height / s->acomp : out->height;
2287 int k = 0, c, p, l, offset_x = 0, offset_y = 0;
2289 for (c = 0; c < s->ncomp; c++) {
2290 if (!((1 << c) & s->pcomp) || (!s->display && k > 0))
2294 for (p = 0; p < s->ncomp; p++) {
2295 const int v = green_yuva_color[p];
2296 for (l = 0; l < s->nb_glines; l++) {
2297 const uint16_t pos = s->glines[l].line[c].pos;
2298 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos);
2299 uint8_t *dst = out->data[p] + offset_y * out->linesize[p] + x;
2301 blend_vline(dst, height, out->linesize[p], o1, o2, v, step);
2305 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2306 const char *name = s->glines[l].line[c].name;
2307 const uint16_t pos = s->glines[l].line[c].pos;
2308 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos) - 10;
2313 draw_vtext(out, x, offset_y + 2, o1, o2, name, green_yuva_color);
2316 offset_x += s->size * (s->display == STACK);
2317 offset_y += height * (s->display == PARADE);
2321 static void graticule16_green_row(WaveformContext *s, AVFrame *out)
2323 const int step = (s->flags & 2) + 1;
2324 const float o1 = s->opacity;
2325 const float o2 = 1. - o1;
2326 const int mult = s->size / 256;
2327 const int height = s->display == PARADE ? out->height / s->acomp : out->height;
2328 int k = 0, c, p, l, offset_x = 0, offset_y = 0;
2330 for (c = 0; c < s->ncomp; c++) {
2331 if (!((1 << c) & s->pcomp) || (!s->display && k > 0))
2335 for (p = 0; p < s->ncomp; p++) {
2336 const int v = green_yuva_color[p] * mult;
2337 for (l = 0; l < s->nb_glines ; l++) {
2338 const uint16_t pos = s->glines[l].line[c].pos;
2339 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos);
2340 uint16_t *dst = (uint16_t *)(out->data[p] + offset_y * out->linesize[p]) + x;
2342 blend_vline16(dst, height, out->linesize[p], o1, o2, v, step);
2346 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2347 const char *name = s->glines[l].line[c].name;
2348 const uint16_t pos = s->glines[l].line[c].pos;
2349 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos) - 10;
2354 draw_vtext16(out, x, offset_y + 2, mult, o1, o2, name, green_yuva_color);
2357 offset_x += s->size * (s->display == STACK);
2358 offset_y += height * (s->display == PARADE);
2362 static void graticule_green_column(WaveformContext *s, AVFrame *out)
2364 const int step = (s->flags & 2) + 1;
2365 const float o1 = s->opacity;
2366 const float o2 = 1. - o1;
2367 const int width = s->display == PARADE ? out->width / s->acomp : out->width;
2368 int k = 0, c, p, l, offset_y = 0, offset_x = 0;
2370 for (c = 0; c < s->ncomp; c++) {
2371 if ((!((1 << c) & s->pcomp) || (!s->display && k > 0)))
2375 for (p = 0; p < s->ncomp; p++) {
2376 const int v = green_yuva_color[p];
2377 for (l = 0; l < s->nb_glines ; l++) {
2378 const uint16_t pos = s->glines[l].line[c].pos;
2379 int y = offset_y + (s->mirror ? s->size - 1 - pos : pos);
2380 uint8_t *dst = out->data[p] + y * out->linesize[p] + offset_x;
2382 blend_hline(dst, width, o1, o2, v, step);
2386 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2387 const char *name = s->glines[l].line[c].name;
2388 const uint16_t pos = s->glines[l].line[c].pos;
2389 int y = offset_y + (s->mirror ? s->size - 1 - pos : pos) - 10;
2394 draw_htext(out, 2 + offset_x, y, o1, o2, name, green_yuva_color);
2397 offset_y += s->size * (s->display == STACK);
2398 offset_x += width * (s->display == PARADE);
2402 static void graticule16_green_column(WaveformContext *s, AVFrame *out)
2404 const int step = (s->flags & 2) + 1;
2405 const float o1 = s->opacity;
2406 const float o2 = 1. - o1;
2407 const int mult = s->size / 256;
2408 const int width = s->display == PARADE ? out->width / s->acomp : out->width;
2409 int k = 0, c, p, l, offset_x = 0, offset_y = 0;
2411 for (c = 0; c < s->ncomp; c++) {
2412 if ((!((1 << c) & s->pcomp) || (!s->display && k > 0)))
2416 for (p = 0; p < s->ncomp; p++) {
2417 const int v = green_yuva_color[p] * mult;
2418 for (l = 0; l < s->nb_glines ; l++) {
2419 const uint16_t pos = s->glines[l].line[c].pos;
2420 int y = offset_y + (s->mirror ? s->size - 1 - pos : pos);
2421 uint16_t *dst = (uint16_t *)(out->data[p] + y * out->linesize[p]) + offset_x;
2423 blend_hline16(dst, width, o1, o2, v, step);
2427 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2428 const char *name = s->glines[l].line[c].name;
2429 const uint16_t pos = s->glines[l].line[c].pos;
2430 int y = offset_y + (s->mirror ? s->size - 1 - pos: pos) - 10;
2435 draw_htext16(out, 2 + offset_x, y, mult, o1, o2, name, green_yuva_color);
2438 offset_y += s->size * (s->display == STACK);
2439 offset_x += width * (s->display == PARADE);
2443 static int config_input(AVFilterLink *inlink)
2445 AVFilterContext *ctx = inlink->dst;
2446 WaveformContext *s = ctx->priv;
2448 s->desc = av_pix_fmt_desc_get(inlink->format);
2449 s->ncomp = s->desc->nb_components;
2450 s->bits = s->desc->comp[0].depth;
2451 s->max = 1 << s->bits;
2452 s->intensity = s->fintensity * (s->max - 1);
2454 s->shift_w[0] = s->shift_w[3] = 0;
2455 s->shift_h[0] = s->shift_h[3] = 0;
2456 s->shift_w[1] = s->shift_w[2] = s->desc->log2_chroma_w;
2457 s->shift_h[1] = s->shift_h[2] = s->desc->log2_chroma_h;
2459 s->graticulef = graticule_none;
2461 switch (s->filter) {
2462 case AFLAT: s->size = 256 * 2; break;
2463 case FLAT: s->size = 256 * 3; break;
2464 default: s->size = 256; break;
2467 switch (s->filter | ((s->bits > 8) << 4) |
2468 (s->mode << 8) | (s->mirror << 12)) {
2469 case 0x1100: s->waveform = lowpass_column_mirror; break;
2470 case 0x1000: s->waveform = lowpass_row_mirror; break;
2471 case 0x0100: s->waveform = lowpass_column; break;
2472 case 0x0000: s->waveform = lowpass_row; break;
2473 case 0x1110: s->waveform = lowpass16_column_mirror; break;
2474 case 0x1010: s->waveform = lowpass16_row_mirror; break;
2475 case 0x0110: s->waveform = lowpass16_column; break;
2476 case 0x0010: s->waveform = lowpass16_row; break;
2480 case 0x0001: s->waveform = flat; break;
2484 case 0x0011: s->waveform = flat16; break;
2488 case 0x0002: s->waveform = aflat; break;
2492 case 0x0012: s->waveform = aflat16; break;
2496 case 0x0003: s->waveform = chroma; break;
2500 case 0x0013: s->waveform = chroma16; break;
2504 case 0x0004: s->waveform = color; break;
2508 case 0x0014: s->waveform = color16; break;
2512 case 0x0005: s->waveform = acolor; break;
2516 case 0x0015: s->waveform = acolor16; break;
2519 switch (s->filter) {
2526 if (s->graticule && s->mode == 1)
2527 s->graticulef = s->bits > 8 ? graticule16_green_column : graticule_green_column;
2528 else if (s->graticule && s->mode == 0)
2529 s->graticulef = s->bits > 8 ? graticule16_green_row : graticule_green_row;
2533 switch (s->filter) {
2540 case 8: s->glines = (GraticuleLines *)digital8; s->nb_glines = FF_ARRAY_ELEMS(digital8); break;
2541 case 9: s->glines = (GraticuleLines *)digital9; s->nb_glines = FF_ARRAY_ELEMS(digital9); break;
2542 case 10: s->glines = (GraticuleLines *)digital10; s->nb_glines = FF_ARRAY_ELEMS(digital10); break;
2543 case 12: s->glines = (GraticuleLines *)digital12; s->nb_glines = FF_ARRAY_ELEMS(digital12); break;
2548 case 8: s->glines = (GraticuleLines *)millivolts8; s->nb_glines = FF_ARRAY_ELEMS(millivolts8); break;
2549 case 9: s->glines = (GraticuleLines *)millivolts9; s->nb_glines = FF_ARRAY_ELEMS(millivolts9); break;
2550 case 10: s->glines = (GraticuleLines *)millivolts10; s->nb_glines = FF_ARRAY_ELEMS(millivolts10); break;
2551 case 12: s->glines = (GraticuleLines *)millivolts12; s->nb_glines = FF_ARRAY_ELEMS(millivolts12); break;
2556 case 8: s->glines = (GraticuleLines *)ire8; s->nb_glines = FF_ARRAY_ELEMS(ire8); break;
2557 case 9: s->glines = (GraticuleLines *)ire9; s->nb_glines = FF_ARRAY_ELEMS(ire9); break;
2558 case 10: s->glines = (GraticuleLines *)ire10; s->nb_glines = FF_ARRAY_ELEMS(ire10); break;
2559 case 12: s->glines = (GraticuleLines *)ire12; s->nb_glines = FF_ARRAY_ELEMS(ire12); break;
2568 case 8: s->glines = (GraticuleLines *)chroma_digital8; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital8); break;
2569 case 9: s->glines = (GraticuleLines *)chroma_digital9; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital9); break;
2570 case 10: s->glines = (GraticuleLines *)chroma_digital10; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital10); break;
2571 case 12: s->glines = (GraticuleLines *)chroma_digital12; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital12); break;
2576 case 8: s->glines = (GraticuleLines *)millivolts8; s->nb_glines = FF_ARRAY_ELEMS(millivolts8); break;
2577 case 9: s->glines = (GraticuleLines *)millivolts9; s->nb_glines = FF_ARRAY_ELEMS(millivolts9); break;
2578 case 10: s->glines = (GraticuleLines *)millivolts10; s->nb_glines = FF_ARRAY_ELEMS(millivolts10); break;
2579 case 12: s->glines = (GraticuleLines *)millivolts12; s->nb_glines = FF_ARRAY_ELEMS(millivolts12); break;
2584 case 8: s->glines = (GraticuleLines *)ire8; s->nb_glines = FF_ARRAY_ELEMS(ire8); break;
2585 case 9: s->glines = (GraticuleLines *)ire9; s->nb_glines = FF_ARRAY_ELEMS(ire9); break;
2586 case 10: s->glines = (GraticuleLines *)ire10; s->nb_glines = FF_ARRAY_ELEMS(ire10); break;
2587 case 12: s->glines = (GraticuleLines *)ire12; s->nb_glines = FF_ARRAY_ELEMS(ire12); break;
2596 case 8: s->glines = (GraticuleLines *)aflat_digital8; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital8); break;
2597 case 9: s->glines = (GraticuleLines *)aflat_digital9; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital9); break;
2598 case 10: s->glines = (GraticuleLines *)aflat_digital10; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital10); break;
2599 case 12: s->glines = (GraticuleLines *)aflat_digital12; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital12); break;
2604 case 8: s->glines = (GraticuleLines *)aflat_millivolts8; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts8); break;
2605 case 9: s->glines = (GraticuleLines *)aflat_millivolts9; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts9); break;
2606 case 10: s->glines = (GraticuleLines *)aflat_millivolts10; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts10); break;
2607 case 12: s->glines = (GraticuleLines *)aflat_millivolts12; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts12); break;
2612 case 8: s->glines = (GraticuleLines *)aflat_ire8; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire8); break;
2613 case 9: s->glines = (GraticuleLines *)aflat_ire9; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire9); break;
2614 case 10: s->glines = (GraticuleLines *)aflat_ire10; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire10); break;
2615 case 12: s->glines = (GraticuleLines *)aflat_ire12; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire12); break;
2624 case 8: s->glines = (GraticuleLines *)flat_digital8; s->nb_glines = FF_ARRAY_ELEMS(flat_digital8); break;
2625 case 9: s->glines = (GraticuleLines *)flat_digital9; s->nb_glines = FF_ARRAY_ELEMS(flat_digital9); break;
2626 case 10: s->glines = (GraticuleLines *)flat_digital10; s->nb_glines = FF_ARRAY_ELEMS(flat_digital10); break;
2627 case 12: s->glines = (GraticuleLines *)flat_digital12; s->nb_glines = FF_ARRAY_ELEMS(flat_digital12); break;
2632 case 8: s->glines = (GraticuleLines *)flat_millivolts8; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts8); break;
2633 case 9: s->glines = (GraticuleLines *)flat_millivolts9; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts9); break;
2634 case 10: s->glines = (GraticuleLines *)flat_millivolts10; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts10); break;
2635 case 12: s->glines = (GraticuleLines *)flat_millivolts12; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts12); break;
2640 case 8: s->glines = (GraticuleLines *)flat_ire8; s->nb_glines = FF_ARRAY_ELEMS(flat_ire8); break;
2641 case 9: s->glines = (GraticuleLines *)flat_ire9; s->nb_glines = FF_ARRAY_ELEMS(flat_ire9); break;
2642 case 10: s->glines = (GraticuleLines *)flat_ire10; s->nb_glines = FF_ARRAY_ELEMS(flat_ire10); break;
2643 case 12: s->glines = (GraticuleLines *)flat_ire12; s->nb_glines = FF_ARRAY_ELEMS(flat_ire12); break;
2650 s->size = s->size << (s->bits - 8);
2652 switch (inlink->format) {
2653 case AV_PIX_FMT_GBRAP:
2654 case AV_PIX_FMT_GBRP:
2655 case AV_PIX_FMT_GBRP9:
2656 case AV_PIX_FMT_GBRP10:
2657 case AV_PIX_FMT_GBRP12:
2658 memcpy(s->bg_color, black_gbrp_color, sizeof(s->bg_color));
2659 s->graticulef = graticule_none;
2662 memcpy(s->bg_color, black_yuva_color, sizeof(s->bg_color));
2665 s->bg_color[3] *= s->bgopacity;
2670 static int config_output(AVFilterLink *outlink)
2672 AVFilterContext *ctx = outlink->src;
2673 AVFilterLink *inlink = ctx->inputs[0];
2674 WaveformContext *s = ctx->priv;
2675 int comp = 0, i, j = 0, k, p, size;
2677 for (i = 0; i < s->ncomp; i++) {
2678 if ((1 << i) & s->pcomp)
2682 s->odesc = av_pix_fmt_desc_get(outlink->format);
2683 s->dcomp = s->odesc->nb_components;
2688 outlink->h = s->size * FFMAX(comp * (s->display == STACK), 1);
2689 outlink->w = inlink->w * FFMAX(comp * (s->display == PARADE), 1);
2692 outlink->w = s->size * FFMAX(comp * (s->display == STACK), 1);
2693 outlink->h = inlink->h * FFMAX(comp * (s->display == PARADE), 1);
2697 s->peak = av_malloc_array(size, 32 * sizeof(*s->peak));
2699 return AVERROR(ENOMEM);
2701 for (p = 0; p < s->ncomp; p++) {
2702 const int plane = s->desc->comp[p].plane;
2705 if (!((1 << p) & s->pcomp))
2708 for (k = 0; k < 4; k++) {
2709 s->emax[plane][k] = s->peak + size * (plane * 4 + k + 0);
2710 s->emin[plane][k] = s->peak + size * (plane * 4 + k + 16);
2713 offset = j++ * s->size * (s->display == STACK);
2714 s->estart[plane] = offset;
2715 s->eend[plane] = (offset + s->size - 1);
2716 for (i = 0; i < size; i++) {
2717 for (k = 0; k < 4; k++) {
2718 s->emax[plane][k][i] = s->estart[plane];
2719 s->emin[plane][k][i] = s->eend[plane];
2724 outlink->sample_aspect_ratio = (AVRational){1,1};
2729 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
2731 AVFilterContext *ctx = inlink->dst;
2732 WaveformContext *s = ctx->priv;
2733 AVFilterLink *outlink = ctx->outputs[0];
2737 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
2740 return AVERROR(ENOMEM);
2743 av_frame_set_color_range(out, AVCOL_RANGE_JPEG);
2745 for (k = 0; k < s->dcomp; k++) {
2747 for (i = 0; i < outlink->h ; i++)
2748 memset(out->data[s->odesc->comp[k].plane] +
2749 i * out->linesize[s->odesc->comp[k].plane],
2750 s->bg_color[k], outlink->w);
2752 const int mult = s->max / 256;
2753 uint16_t *dst = (uint16_t *)out->data[s->odesc->comp[k].plane];
2755 for (i = 0; i < outlink->h ; i++) {
2756 for (j = 0; j < outlink->w; j++)
2757 dst[j] = s->bg_color[k] * mult;
2758 dst += out->linesize[s->odesc->comp[k].plane] / 2;
2763 for (k = 0, i = 0; k < s->ncomp; k++) {
2764 if ((1 << k) & s->pcomp) {
2768 if (s->display == PARADE) {
2769 offset_x = s->mode ? i++ * inlink->w : 0;
2770 offset_y = s->mode ? 0 : i++ * inlink->h;
2772 offset_y = s->mode ? i++ * s->size * !!s->display : 0;
2773 offset_x = s->mode ? 0 : i++ * s->size * !!s->display;
2775 s->waveform(s, in, out, k, s->intensity, offset_y, offset_x, s->mode, s->mirror);
2778 s->graticulef(s, out);
2781 return ff_filter_frame(outlink, out);
2784 static av_cold void uninit(AVFilterContext *ctx)
2786 WaveformContext *s = ctx->priv;
2791 static const AVFilterPad inputs[] = {
2794 .type = AVMEDIA_TYPE_VIDEO,
2795 .filter_frame = filter_frame,
2796 .config_props = config_input,
2801 static const AVFilterPad outputs[] = {
2804 .type = AVMEDIA_TYPE_VIDEO,
2805 .config_props = config_output,
2810 AVFilter ff_vf_waveform = {
2812 .description = NULL_IF_CONFIG_SMALL("Video waveform monitor."),
2813 .priv_size = sizeof(WaveformContext),
2814 .priv_class = &waveform_class,
2815 .query_formats = query_formats,