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 {
71 const uint8_t *bg_color;
90 int shift_w[4], shift_h[4];
91 GraticuleLines *glines;
93 void (*waveform)(struct WaveformContext *s,
94 AVFrame *in, AVFrame *out,
95 int component, int intensity,
96 int offset_y, int offset_x,
97 int column, int mirror);
98 void (*graticulef)(struct WaveformContext *s, AVFrame *out);
99 const AVPixFmtDescriptor *desc;
102 #define OFFSET(x) offsetof(WaveformContext, x)
103 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
105 static const AVOption waveform_options[] = {
106 { "mode", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "mode" },
107 { "m", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "mode" },
108 { "row", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "mode" },
109 { "column", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "mode" },
110 { "intensity", "set intensity", OFFSET(fintensity), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 1, FLAGS },
111 { "i", "set intensity", OFFSET(fintensity), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 1, FLAGS },
112 { "mirror", "set mirroring", OFFSET(mirror), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
113 { "r", "set mirroring", OFFSET(mirror), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
114 { "display", "set display mode", OFFSET(display), AV_OPT_TYPE_INT, {.i64=STACK}, 0, NB_DISPLAYS-1, FLAGS, "display" },
115 { "d", "set display mode", OFFSET(display), AV_OPT_TYPE_INT, {.i64=STACK}, 0, NB_DISPLAYS-1, FLAGS, "display" },
116 { "overlay", NULL, 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY}, 0, 0, FLAGS, "display" },
117 { "stack", NULL, 0, AV_OPT_TYPE_CONST, {.i64=STACK}, 0, 0, FLAGS, "display" },
118 { "parade", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PARADE}, 0, 0, FLAGS, "display" },
119 { "components", "set components to display", OFFSET(pcomp), AV_OPT_TYPE_INT, {.i64=1}, 1, 15, FLAGS },
120 { "c", "set components to display", OFFSET(pcomp), AV_OPT_TYPE_INT, {.i64=1}, 1, 15, FLAGS },
121 { "envelope", "set envelope to display", OFFSET(envelope), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "envelope" },
122 { "e", "set envelope to display", OFFSET(envelope), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "envelope" },
123 { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "envelope" },
124 { "instant", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "envelope" },
125 { "peak", NULL, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "envelope" },
126 { "peak+instant", NULL, 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, FLAGS, "envelope" },
127 { "filter", "set filter", OFFSET(filter), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_FILTERS-1, FLAGS, "filter" },
128 { "f", "set filter", OFFSET(filter), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_FILTERS-1, FLAGS, "filter" },
129 { "lowpass", NULL, 0, AV_OPT_TYPE_CONST, {.i64=LOWPASS}, 0, 0, FLAGS, "filter" },
130 { "flat" , NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAT}, 0, 0, FLAGS, "filter" },
131 { "aflat" , NULL, 0, AV_OPT_TYPE_CONST, {.i64=AFLAT}, 0, 0, FLAGS, "filter" },
132 { "chroma", NULL, 0, AV_OPT_TYPE_CONST, {.i64=CHROMA}, 0, 0, FLAGS, "filter" },
133 { "color", NULL, 0, AV_OPT_TYPE_CONST, {.i64=COLOR}, 0, 0, FLAGS, "filter" },
134 { "acolor", NULL, 0, AV_OPT_TYPE_CONST, {.i64=ACOLOR}, 0, 0, FLAGS, "filter" },
135 { "graticule", "set graticule", OFFSET(graticule), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "graticule" },
136 { "g", "set graticule", OFFSET(graticule), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "graticule" },
137 { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "graticule" },
138 { "green", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "graticule" },
139 { "opacity", "set graticule opacity", OFFSET(opacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
140 { "o", "set graticule opacity", OFFSET(opacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
141 { "flags", "set graticule flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64=1}, 0, 3, FLAGS, "flags" },
142 { "fl", "set graticule flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64=1}, 0, 3, FLAGS, "flags" },
143 { "numbers", "draw numbers", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "flags" },
144 { "dots", "draw dots instead of lines", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "flags" },
145 { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SCALES-1, FLAGS, "scale" },
146 { "s", "set scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SCALES-1, FLAGS, "scale" },
147 { "digital", NULL, 0, AV_OPT_TYPE_CONST, {.i64=DIGITAL}, 0, 0, FLAGS, "scale" },
148 { "millivolts", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MILLIVOLTS}, 0, 0, FLAGS, "scale" },
149 { "ire", NULL, 0, AV_OPT_TYPE_CONST, {.i64=IRE}, 0, 0, FLAGS, "scale" },
153 AVFILTER_DEFINE_CLASS(waveform);
155 static const enum AVPixelFormat in_lowpass_pix_fmts[] = {
156 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
157 AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12,
158 AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
159 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
160 AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P,
161 AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
162 AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
163 AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
165 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9,
166 AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9,
167 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10,
168 AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10,
169 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV440P12,
173 static const enum AVPixelFormat in_color_pix_fmts[] = {
174 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
175 AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12,
176 AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
177 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
179 AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
180 AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
181 AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
182 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9,
183 AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9,
184 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10,
185 AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10,
186 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV440P12,
190 static const enum AVPixelFormat in_flat_pix_fmts[] = {
191 AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
192 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
194 AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
195 AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
196 AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
197 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9,
198 AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9,
199 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10,
200 AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10,
201 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV440P12,
205 static const enum AVPixelFormat out_rgb8_lowpass_pix_fmts[] = {
206 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
210 static const enum AVPixelFormat out_rgb9_lowpass_pix_fmts[] = {
215 static const enum AVPixelFormat out_rgb10_lowpass_pix_fmts[] = {
220 static const enum AVPixelFormat out_rgb12_lowpass_pix_fmts[] = {
225 static const enum AVPixelFormat out_yuv8_lowpass_pix_fmts[] = {
226 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVA444P,
230 static const enum AVPixelFormat out_yuv9_lowpass_pix_fmts[] = {
231 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUVA444P9,
235 static const enum AVPixelFormat out_yuv10_lowpass_pix_fmts[] = {
236 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUVA444P10,
240 static const enum AVPixelFormat out_yuv12_lowpass_pix_fmts[] = {
241 AV_PIX_FMT_YUV444P12,
245 static const enum AVPixelFormat out_gray8_lowpass_pix_fmts[] = {
250 static const enum AVPixelFormat flat_pix_fmts[] = {
251 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P,
252 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV444P10,
253 AV_PIX_FMT_YUV444P12,
257 static int query_formats(AVFilterContext *ctx)
259 WaveformContext *s = ctx->priv;
260 const enum AVPixelFormat *out_pix_fmts;
261 const enum AVPixelFormat *in_pix_fmts;
262 const AVPixFmtDescriptor *desc;
263 AVFilterFormats *avff;
264 int depth, rgb, i, ret, ncomp;
266 if (!ctx->inputs[0]->in_formats ||
267 !ctx->inputs[0]->in_formats->nb_formats) {
268 return AVERROR(EAGAIN);
272 case LOWPASS: in_pix_fmts = in_lowpass_pix_fmts; break;
275 case FLAT: in_pix_fmts = in_flat_pix_fmts; break;
277 case COLOR: in_pix_fmts = in_color_pix_fmts; break;
280 if (!ctx->inputs[0]->out_formats) {
281 if ((ret = ff_formats_ref(ff_make_format_list(in_pix_fmts), &ctx->inputs[0]->out_formats)) < 0)
285 avff = ctx->inputs[0]->in_formats;
286 desc = av_pix_fmt_desc_get(avff->formats[0]);
287 ncomp = desc->nb_components;
288 rgb = desc->flags & AV_PIX_FMT_FLAG_RGB;
289 depth = desc->comp[0].depth;
290 for (i = 1; i < avff->nb_formats; i++) {
291 desc = av_pix_fmt_desc_get(avff->formats[i]);
292 if (rgb != (desc->flags & AV_PIX_FMT_FLAG_RGB) ||
293 depth != desc->comp[0].depth)
294 return AVERROR(EAGAIN);
297 if (s->filter == LOWPASS && ncomp == 1 && depth == 8)
298 out_pix_fmts = out_gray8_lowpass_pix_fmts;
299 else if (rgb && depth == 8 && ncomp > 2)
300 out_pix_fmts = out_rgb8_lowpass_pix_fmts;
301 else if (rgb && depth == 9 && ncomp > 2)
302 out_pix_fmts = out_rgb9_lowpass_pix_fmts;
303 else if (rgb && depth == 10 && ncomp > 2)
304 out_pix_fmts = out_rgb10_lowpass_pix_fmts;
305 else if (rgb && depth == 12 && ncomp > 2)
306 out_pix_fmts = out_rgb12_lowpass_pix_fmts;
307 else if (depth == 8 && ncomp > 2)
308 out_pix_fmts = out_yuv8_lowpass_pix_fmts;
309 else if (depth == 9 && ncomp > 2)
310 out_pix_fmts = out_yuv9_lowpass_pix_fmts;
311 else if (depth == 10 && ncomp > 2)
312 out_pix_fmts = out_yuv10_lowpass_pix_fmts;
313 else if (depth == 12 && ncomp > 2)
314 out_pix_fmts = out_yuv12_lowpass_pix_fmts;
316 return AVERROR(EAGAIN);
317 if ((ret = ff_formats_ref(ff_make_format_list(out_pix_fmts), &ctx->outputs[0]->in_formats)) < 0)
323 static void envelope_instant16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
325 const int dst_linesize = out->linesize[component] / 2;
326 const int bg = s->bg_color[component] * (s->max / 256);
327 const int limit = s->max - 1;
328 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
329 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
330 const int start = s->estart[plane];
331 const int end = s->eend[plane];
336 for (x = offset; x < offset + dst_w; x++) {
337 for (y = start; y < end; y++) {
338 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
344 for (y = end - 1; y >= start; y--) {
345 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
353 for (y = offset; y < offset + dst_h; y++) {
354 dst = (uint16_t *)out->data[component] + y * dst_linesize;
355 for (x = start; x < end; x++) {
361 for (x = end - 1; x >= start; x--) {
371 static void envelope_instant(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
373 const int dst_linesize = out->linesize[component];
374 const uint8_t bg = s->bg_color[component];
375 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
376 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
377 const int start = s->estart[plane];
378 const int end = s->eend[plane];
383 for (x = offset; x < offset + dst_w; x++) {
384 for (y = start; y < end; y++) {
385 dst = out->data[component] + y * dst_linesize + x;
391 for (y = end - 1; y >= start; y--) {
392 dst = out->data[component] + y * dst_linesize + x;
400 for (y = offset; y < offset + dst_h; y++) {
401 dst = out->data[component] + y * dst_linesize;
402 for (x = start; x < end; x++) {
408 for (x = end - 1; x >= start; x--) {
418 static void envelope_peak16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
420 const int dst_linesize = out->linesize[component] / 2;
421 const int bg = s->bg_color[component] * (s->max / 256);
422 const int limit = s->max - 1;
423 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
424 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
425 const int start = s->estart[plane];
426 const int end = s->eend[plane];
427 int *emax = s->emax[plane][component];
428 int *emin = s->emin[plane][component];
433 for (x = offset; x < offset + dst_w; x++) {
434 for (y = start; y < end && y < emin[x - offset]; y++) {
435 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
437 emin[x - offset] = y;
441 for (y = end - 1; y >= start && y >= emax[x - offset]; y--) {
442 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
444 emax[x - offset] = y;
450 if (s->envelope == 3)
451 envelope_instant16(s, out, plane, component, offset);
453 for (x = offset; x < offset + dst_w; x++) {
454 dst = (uint16_t *)out->data[component] + emin[x - offset] * dst_linesize + x;
456 dst = (uint16_t *)out->data[component] + emax[x - offset] * dst_linesize + x;
460 for (y = offset; y < offset + dst_h; y++) {
461 dst = (uint16_t *)out->data[component] + y * dst_linesize;
462 for (x = start; x < end && x < emin[y - offset]; x++) {
464 emin[y - offset] = x;
468 for (x = end - 1; x >= start && x >= emax[y - offset]; x--) {
470 emax[y - offset] = x;
476 if (s->envelope == 3)
477 envelope_instant16(s, out, plane, component, offset);
479 for (y = offset; y < offset + dst_h; y++) {
480 dst = (uint16_t *)out->data[component] + y * dst_linesize + emin[y - offset];
482 dst = (uint16_t *)out->data[component] + y * dst_linesize + emax[y - offset];
488 static void envelope_peak(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
490 const int dst_linesize = out->linesize[component];
491 const int bg = s->bg_color[component];
492 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
493 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
494 const int start = s->estart[plane];
495 const int end = s->eend[plane];
496 int *emax = s->emax[plane][component];
497 int *emin = s->emin[plane][component];
502 for (x = offset; x < offset + dst_w; x++) {
503 for (y = start; y < end && y < emin[x - offset]; y++) {
504 dst = out->data[component] + y * dst_linesize + x;
506 emin[x - offset] = y;
510 for (y = end - 1; y >= start && y >= emax[x - offset]; y--) {
511 dst = out->data[component] + y * dst_linesize + x;
513 emax[x - offset] = y;
519 if (s->envelope == 3)
520 envelope_instant(s, out, plane, component, offset);
522 for (x = offset; x < offset + dst_w; x++) {
523 dst = out->data[component] + emin[x - offset] * dst_linesize + x;
525 dst = out->data[component] + emax[x - offset] * dst_linesize + x;
529 for (y = offset; y < offset + dst_h; y++) {
530 dst = out->data[component] + y * dst_linesize;
531 for (x = start; x < end && x < emin[y - offset]; x++) {
533 emin[y - offset] = x;
537 for (x = end - 1; x >= start && x >= emax[y - offset]; x--) {
539 emax[y - offset] = x;
545 if (s->envelope == 3)
546 envelope_instant(s, out, plane, component, offset);
548 for (y = offset; y < offset + dst_h; y++) {
549 dst = out->data[component] + y * dst_linesize + emin[y - offset];
551 dst = out->data[component] + y * dst_linesize + emax[y - offset];
557 static void envelope16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
559 if (s->envelope == 0) {
561 } else if (s->envelope == 1) {
562 envelope_instant16(s, out, plane, component, offset);
564 envelope_peak16(s, out, plane, component, offset);
568 static void envelope(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
570 if (s->envelope == 0) {
572 } else if (s->envelope == 1) {
573 envelope_instant(s, out, plane, component, offset);
575 envelope_peak(s, out, plane, component, offset);
579 static void update16(uint16_t *target, int max, int intensity, int limit)
582 *target += intensity;
587 static void update(uint8_t *target, int max, int intensity)
590 *target += intensity;
595 static av_always_inline void lowpass16(WaveformContext *s,
596 AVFrame *in, AVFrame *out,
597 int component, int intensity,
598 int offset_y, int offset_x,
599 int column, int mirror)
601 const int plane = s->desc->comp[component].plane;
602 const int shift_w = s->shift_w[component];
603 const int shift_h = s->shift_h[component];
604 const int src_linesize = in->linesize[plane] / 2;
605 const int dst_linesize = out->linesize[plane] / 2;
606 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
607 const int limit = s->max - 1;
608 const int max = limit - intensity;
609 const int src_h = AV_CEIL_RSHIFT(in->height, shift_h);
610 const int src_w = AV_CEIL_RSHIFT(in->width, shift_w);
611 const uint16_t *src_data = (const uint16_t *)in->data[plane];
612 uint16_t *dst_data = (uint16_t *)out->data[plane] + offset_y * dst_linesize + offset_x;
613 uint16_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
614 uint16_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
615 const int step = column ? 1 << shift_w : 1 << shift_h;
619 if (!column && mirror)
622 for (y = 0; y < src_h; y++) {
623 const uint16_t *src_data_end = src_data + src_w;
624 uint16_t *dst = dst_line;
626 for (p = src_data; p < src_data_end; p++) {
628 int i = 0, v = FFMIN(*p, limit);
632 target = dst++ + dst_signed_linesize * v;
633 update16(target, max, intensity, limit);
634 } while (++i < step);
636 uint16_t *row = dst_data;
639 target = row - v - 1;
642 update16(target, max, intensity, limit);
644 } while (++i < step);
647 src_data += src_linesize;
648 dst_data += dst_linesize * step;
651 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
654 #define LOWPASS16_FUNC(name, column, mirror) \
655 static void lowpass16_##name(WaveformContext *s, \
656 AVFrame *in, AVFrame *out, \
657 int component, int intensity, \
658 int offset_y, int offset_x, \
659 int unused1, int unused2) \
661 lowpass16(s, in, out, component, intensity, \
662 offset_y, offset_x, column, mirror); \
665 LOWPASS16_FUNC(column_mirror, 1, 1)
666 LOWPASS16_FUNC(column, 1, 0)
667 LOWPASS16_FUNC(row_mirror, 0, 1)
668 LOWPASS16_FUNC(row, 0, 0)
670 static av_always_inline void lowpass(WaveformContext *s,
671 AVFrame *in, AVFrame *out,
672 int component, int intensity,
673 int offset_y, int offset_x,
674 int column, int mirror)
676 const int plane = s->desc->comp[component].plane;
677 const int shift_w = s->shift_w[component];
678 const int shift_h = s->shift_h[component];
679 const int src_linesize = in->linesize[plane];
680 const int dst_linesize = out->linesize[plane];
681 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
682 const int max = 255 - intensity;
683 const int src_h = AV_CEIL_RSHIFT(in->height, shift_h);
684 const int src_w = AV_CEIL_RSHIFT(in->width, shift_w);
685 const uint8_t *src_data = in->data[plane];
686 uint8_t *dst_data = out->data[plane] + offset_y * dst_linesize + offset_x;
687 uint8_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
688 uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
689 const int step = column ? 1 << shift_w : 1 << shift_h;
693 if (!column && mirror)
696 for (y = 0; y < src_h; y++) {
697 const uint8_t *src_data_end = src_data + src_w;
698 uint8_t *dst = dst_line;
700 for (p = src_data; p < src_data_end; p++) {
703 target = dst + dst_signed_linesize * *p;
705 update(target, max, intensity);
707 uint8_t *row = dst_data;
709 target = row - *p - 1;
712 update(target, max, intensity);
716 src_data += src_linesize;
717 dst_data += dst_linesize * step;
720 if (column && step > 1) {
721 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
722 const int dst_h = 256;
726 dst = out->data[plane] + offset_y * dst_linesize + offset_x;
727 for (y = 0; y < dst_h; y++) {
728 for (x = 0; x < dst_w; x+=step) {
729 for (z = 1; z < step; z++) {
735 } else if (step > 1) {
736 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
737 const int dst_w = 256;
741 dst = out->data[plane] + offset_y * dst_linesize + offset_x;
742 for (y = 0; y < dst_h; y+=step) {
743 for (z = 1; z < step; z++)
744 memcpy(dst + dst_linesize * z, dst, dst_w);
745 dst += dst_linesize * step;
749 envelope(s, out, plane, plane, column ? offset_x : offset_y);
752 #define LOWPASS_FUNC(name, column, mirror) \
753 static void lowpass_##name(WaveformContext *s, \
754 AVFrame *in, AVFrame *out, \
755 int component, int intensity, \
756 int offset_y, int offset_x, \
757 int unused1, int unused2) \
759 lowpass(s, in, out, component, intensity, \
760 offset_y, offset_x, column, mirror); \
763 LOWPASS_FUNC(column_mirror, 1, 1)
764 LOWPASS_FUNC(column, 1, 0)
765 LOWPASS_FUNC(row_mirror, 0, 1)
766 LOWPASS_FUNC(row, 0, 0)
768 static av_always_inline void flat16(WaveformContext *s,
769 AVFrame *in, AVFrame *out,
770 int component, int intensity,
771 int offset_y, int offset_x,
772 int column, int mirror)
774 const int plane = s->desc->comp[component].plane;
775 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
776 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
777 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
778 const int c0_shift_w = s->shift_w[ component + 0 ];
779 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
780 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
781 const int c0_shift_h = s->shift_h[ component + 0 ];
782 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
783 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
784 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
785 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
786 const int limit = s->max - 1;
787 const int max = limit - intensity;
788 const int mid = s->max / 2;
789 const int src_h = in->height;
790 const int src_w = in->width;
794 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
795 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
797 for (x = 0; x < src_w; x++) {
798 const uint16_t *c0_data = (uint16_t *)in->data[plane + 0];
799 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
800 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
801 uint16_t *d0_data = (uint16_t *)(out->data[plane]) + offset_y * d0_linesize + offset_x;
802 uint16_t *d1_data = (uint16_t *)(out->data[(plane + 1) % s->ncomp]) + offset_y * d1_linesize + offset_x;
803 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
804 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
805 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
806 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
808 for (y = 0; y < src_h; y++) {
809 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + s->max;
810 const int c1 = FFMIN(FFABS(c1_data[x >> c1_shift_w] - mid) + FFABS(c2_data[x >> c2_shift_w] - mid), limit);
813 target = d0 + x + d0_signed_linesize * c0;
814 update16(target, max, intensity, limit);
815 target = d1 + x + d1_signed_linesize * (c0 - c1);
816 update16(target, max, intensity, limit);
817 target = d1 + x + d1_signed_linesize * (c0 + c1);
818 update16(target, max, intensity, limit);
820 if (!c0_shift_h || (y & c0_shift_h))
821 c0_data += c0_linesize;
822 if (!c1_shift_h || (y & c1_shift_h))
823 c1_data += c1_linesize;
824 if (!c2_shift_h || (y & c2_shift_h))
825 c2_data += c2_linesize;
826 d0_data += d0_linesize;
827 d1_data += d1_linesize;
831 const uint16_t *c0_data = (uint16_t *)in->data[plane];
832 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
833 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
834 uint16_t *d0_data = (uint16_t *)(out->data[plane]) + offset_y * d0_linesize + offset_x;
835 uint16_t *d1_data = (uint16_t *)(out->data[(plane + 1) % s->ncomp]) + offset_y * d1_linesize + offset_x;
838 d0_data += s->size - 1;
839 d1_data += s->size - 1;
842 for (y = 0; y < src_h; y++) {
843 for (x = 0; x < src_w; x++) {
844 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + s->max;
845 const int c1 = FFMIN(FFABS(c1_data[x >> c1_shift_w] - mid) + FFABS(c2_data[x >> c2_shift_w] - mid), limit);
849 target = d0_data - c0;
850 update16(target, max, intensity, limit);
851 target = d1_data - (c0 - c1);
852 update16(target, max, intensity, limit);
853 target = d1_data - (c0 + c1);
854 update16(target, max, intensity, limit);
856 target = d0_data + c0;
857 update16(target, max, intensity, limit);
858 target = d1_data + (c0 - c1);
859 update16(target, max, intensity, limit);
860 target = d1_data + (c0 + c1);
861 update16(target, max, intensity, limit);
865 if (!c0_shift_h || (y & c0_shift_h))
866 c0_data += c0_linesize;
867 if (!c1_shift_h || (y & c1_shift_h))
868 c1_data += c1_linesize;
869 if (!c2_shift_h || (y & c2_shift_h))
870 c2_data += c2_linesize;
871 d0_data += d0_linesize;
872 d1_data += d1_linesize;
876 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
877 envelope16(s, out, plane, (plane + 1) % s->ncomp, column ? offset_x : offset_y);
880 static av_always_inline void flat(WaveformContext *s,
881 AVFrame *in, AVFrame *out,
882 int component, int intensity,
883 int offset_y, int offset_x,
884 int column, int mirror)
886 const int plane = s->desc->comp[component].plane;
887 const int c0_linesize = in->linesize[ plane + 0 ];
888 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
889 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
890 const int c0_shift_w = s->shift_w[ component + 0 ];
891 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
892 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
893 const int c0_shift_h = s->shift_h[ component + 0 ];
894 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
895 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
896 const int d0_linesize = out->linesize[ plane + 0 ];
897 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
898 const int max = 255 - intensity;
899 const int src_h = in->height;
900 const int src_w = in->width;
904 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
905 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
907 for (x = 0; x < src_w; x++) {
908 const uint8_t *c0_data = in->data[plane + 0];
909 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
910 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
911 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
912 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
913 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
914 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
915 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
916 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
918 for (y = 0; y < src_h; y++) {
919 const int c0 = c0_data[x >> c0_shift_w] + 256;
920 const int c1 = FFABS(c1_data[x >> c1_shift_w] - 128) + FFABS(c2_data[x >> c2_shift_w] - 128);
923 target = d0 + x + d0_signed_linesize * c0;
924 update(target, max, intensity);
925 target = d1 + x + d1_signed_linesize * (c0 - c1);
926 update(target, max, intensity);
927 target = d1 + x + d1_signed_linesize * (c0 + c1);
928 update(target, max, intensity);
930 if (!c0_shift_h || (y & c0_shift_h))
931 c0_data += c0_linesize;
932 if (!c1_shift_h || (y & c1_shift_h))
933 c1_data += c1_linesize;
934 if (!c2_shift_h || (y & c2_shift_h))
935 c2_data += c2_linesize;
936 d0_data += d0_linesize;
937 d1_data += d1_linesize;
941 const uint8_t *c0_data = in->data[plane];
942 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
943 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
944 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
945 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
948 d0_data += s->size - 1;
949 d1_data += s->size - 1;
952 for (y = 0; y < src_h; y++) {
953 for (x = 0; x < src_w; x++) {
954 int c0 = c0_data[x >> c0_shift_w] + 256;
955 const int c1 = FFABS(c1_data[x >> c1_shift_w] - 128) + FFABS(c2_data[x >> c2_shift_w] - 128);
959 target = d0_data - c0;
960 update(target, max, intensity);
961 target = d1_data - (c0 - c1);
962 update(target, max, intensity);
963 target = d1_data - (c0 + c1);
964 update(target, max, intensity);
966 target = d0_data + c0;
967 update(target, max, intensity);
968 target = d1_data + (c0 - c1);
969 update(target, max, intensity);
970 target = d1_data + (c0 + c1);
971 update(target, max, intensity);
975 if (!c0_shift_h || (y & c0_shift_h))
976 c0_data += c0_linesize;
977 if (!c1_shift_h || (y & c1_shift_h))
978 c1_data += c1_linesize;
979 if (!c2_shift_h || (y & c2_shift_h))
980 c2_data += c2_linesize;
981 d0_data += d0_linesize;
982 d1_data += d1_linesize;
986 envelope(s, out, plane, plane, column ? offset_x : offset_y);
987 envelope(s, out, plane, (plane + 1) % s->ncomp, column ? offset_x : offset_y);
990 static av_always_inline void aflat16(WaveformContext *s,
991 AVFrame *in, AVFrame *out,
992 int component, int intensity,
993 int offset_y, int offset_x,
994 int column, int mirror)
996 const int plane = s->desc->comp[component].plane;
997 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
998 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
999 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1000 const int c0_shift_w = s->shift_w[ component + 0 ];
1001 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1002 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1003 const int c0_shift_h = s->shift_h[ component + 0 ];
1004 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1005 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1006 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
1007 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
1008 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2;
1009 const int limit = s->max - 1;
1010 const int max = limit - intensity;
1011 const int mid = s->max / 2;
1012 const int src_h = in->height;
1013 const int src_w = in->width;
1017 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1018 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1019 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1021 for (x = 0; x < src_w; x++) {
1022 const uint16_t *c0_data = (uint16_t *)in->data[plane + 0];
1023 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1024 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1025 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1026 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1027 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1028 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1029 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1030 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1031 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1032 uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1033 uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1035 for (y = 0; y < src_h; y++) {
1036 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + mid;
1037 const int c1 = FFMIN(c1_data[x >> c1_shift_w], limit) - mid;
1038 const int c2 = FFMIN(c2_data[x >> c2_shift_w], limit) - mid;
1041 target = d0 + x + d0_signed_linesize * c0;
1042 update16(target, max, intensity, limit);
1044 target = d1 + x + d1_signed_linesize * (c0 + c1);
1045 update16(target, max, intensity, limit);
1047 target = d2 + x + d2_signed_linesize * (c0 + c2);
1048 update16(target, max, intensity, limit);
1050 if (!c0_shift_h || (y & c0_shift_h))
1051 c0_data += c0_linesize;
1052 if (!c1_shift_h || (y & c1_shift_h))
1053 c1_data += c1_linesize;
1054 if (!c2_shift_h || (y & c2_shift_h))
1055 c2_data += c2_linesize;
1056 d0_data += d0_linesize;
1057 d1_data += d1_linesize;
1058 d2_data += d2_linesize;
1062 const uint16_t *c0_data = (uint16_t *)in->data[plane];
1063 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1064 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1065 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1066 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1067 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1070 d0_data += s->size - 1;
1071 d1_data += s->size - 1;
1072 d2_data += s->size - 1;
1075 for (y = 0; y < src_h; y++) {
1076 for (x = 0; x < src_w; x++) {
1077 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + mid;
1078 const int c1 = FFMIN(c1_data[x >> c1_shift_w], limit) - mid;
1079 const int c2 = FFMIN(c2_data[x >> c2_shift_w], limit) - mid;
1083 target = d0_data - c0;
1084 update16(target, max, intensity, limit);
1085 target = d1_data - (c0 + c1);
1086 update16(target, max, intensity, limit);
1087 target = d2_data - (c0 + c2);
1088 update16(target, max, intensity, limit);
1090 target = d0_data + c0;
1091 update16(target, max, intensity, limit);
1092 target = d1_data + (c0 + c1);
1093 update16(target, max, intensity, limit);
1094 target = d2_data + (c0 + c2);
1095 update16(target, max, intensity, limit);
1099 if (!c0_shift_h || (y & c0_shift_h))
1100 c0_data += c0_linesize;
1101 if (!c1_shift_h || (y & c1_shift_h))
1102 c1_data += c1_linesize;
1103 if (!c2_shift_h || (y & c2_shift_h))
1104 c2_data += c2_linesize;
1105 d0_data += d0_linesize;
1106 d1_data += d1_linesize;
1107 d2_data += d2_linesize;
1111 envelope16(s, out, plane, (plane + 0) % s->ncomp, column ? offset_x : offset_y);
1112 envelope16(s, out, plane, (plane + 1) % s->ncomp, column ? offset_x : offset_y);
1113 envelope16(s, out, plane, (plane + 2) % s->ncomp, column ? offset_x : offset_y);
1116 static av_always_inline void aflat(WaveformContext *s,
1117 AVFrame *in, AVFrame *out,
1118 int component, int intensity,
1119 int offset_y, int offset_x,
1120 int column, int mirror)
1122 const int plane = s->desc->comp[component].plane;
1123 const int c0_linesize = in->linesize[ plane + 0 ];
1124 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
1125 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
1126 const int c0_shift_w = s->shift_w[ component + 0 ];
1127 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1128 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1129 const int c0_shift_h = s->shift_h[ component + 0 ];
1130 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1131 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1132 const int d0_linesize = out->linesize[ plane + 0 ];
1133 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
1134 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp];
1135 const int max = 255 - intensity;
1136 const int src_h = in->height;
1137 const int src_w = in->width;
1141 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1142 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1143 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1145 for (x = 0; x < src_w; x++) {
1146 const uint8_t *c0_data = in->data[plane + 0];
1147 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1148 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1149 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1150 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1151 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1152 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1153 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1154 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1155 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1156 uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1157 uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1159 for (y = 0; y < src_h; y++) {
1160 const int c0 = c0_data[x >> c0_shift_w] + 128;
1161 const int c1 = c1_data[x >> c1_shift_w] - 128;
1162 const int c2 = c2_data[x >> c2_shift_w] - 128;
1165 target = d0 + x + d0_signed_linesize * c0;
1166 update(target, max, intensity);
1168 target = d1 + x + d1_signed_linesize * (c0 + c1);
1169 update(target, max, intensity);
1171 target = d2 + x + d2_signed_linesize * (c0 + c2);
1172 update(target, max, intensity);
1174 if (!c0_shift_h || (y & c0_shift_h))
1175 c0_data += c0_linesize;
1176 if (!c1_shift_h || (y & c1_shift_h))
1177 c1_data += c1_linesize;
1178 if (!c1_shift_h || (y & c1_shift_h))
1179 c2_data += c1_linesize;
1180 d0_data += d0_linesize;
1181 d1_data += d1_linesize;
1182 d2_data += d2_linesize;
1186 const uint8_t *c0_data = in->data[plane];
1187 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1188 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1189 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1190 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1191 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1194 d0_data += s->size - 1;
1195 d1_data += s->size - 1;
1196 d2_data += s->size - 1;
1199 for (y = 0; y < src_h; y++) {
1200 for (x = 0; x < src_w; x++) {
1201 const int c0 = c0_data[x >> c0_shift_w] + 128;
1202 const int c1 = c1_data[x >> c1_shift_w] - 128;
1203 const int c2 = c2_data[x >> c2_shift_w] - 128;
1207 target = d0_data - c0;
1208 update(target, max, intensity);
1209 target = d1_data - (c0 + c1);
1210 update(target, max, intensity);
1211 target = d2_data - (c0 + c2);
1212 update(target, max, intensity);
1214 target = d0_data + c0;
1215 update(target, max, intensity);
1216 target = d1_data + (c0 + c1);
1217 update(target, max, intensity);
1218 target = d2_data + (c0 + c2);
1219 update(target, max, intensity);
1223 if (!c0_shift_h || (y & c0_shift_h))
1224 c0_data += c0_linesize;
1225 if (!c1_shift_h || (y & c1_shift_h))
1226 c1_data += c1_linesize;
1227 if (!c2_shift_h || (y & c2_shift_h))
1228 c2_data += c2_linesize;
1229 d0_data += d0_linesize;
1230 d1_data += d1_linesize;
1231 d2_data += d2_linesize;
1235 envelope(s, out, plane, (plane + 0) % s->ncomp, column ? offset_x : offset_y);
1236 envelope(s, out, plane, (plane + 1) % s->ncomp, column ? offset_x : offset_y);
1237 envelope(s, out, plane, (plane + 2) % s->ncomp, column ? offset_x : offset_y);
1240 static av_always_inline void chroma16(WaveformContext *s,
1241 AVFrame *in, AVFrame *out,
1242 int component, int intensity,
1243 int offset_y, int offset_x,
1244 int column, int mirror)
1246 const int plane = s->desc->comp[component].plane;
1247 const int c0_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1248 const int c1_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1249 const int dst_linesize = out->linesize[plane] / 2;
1250 const int limit = s->max - 1;
1251 const int max = limit - intensity;
1252 const int mid = s->max / 2;
1253 const int c0_shift_w = s->shift_w[(component + 1) % s->ncomp];
1254 const int c1_shift_w = s->shift_w[(component + 2) % s->ncomp];
1255 const int c0_shift_h = s->shift_h[(component + 1) % s->ncomp];
1256 const int c1_shift_h = s->shift_h[(component + 2) % s->ncomp];
1257 const int src_h = in->height;
1258 const int src_w = in->width;
1262 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
1264 for (x = 0; x < src_w; x++) {
1265 const uint16_t *c0_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1266 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1267 uint16_t *dst_data = (uint16_t *)out->data[plane] + offset_y * dst_linesize + offset_x;
1268 uint16_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
1269 uint16_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
1270 uint16_t *dst = dst_line;
1272 for (y = 0; y < src_h; y++) {
1273 const int sum = FFMIN(FFABS(c0_data[x >> c0_shift_w] - mid) + FFABS(c1_data[x >> c1_shift_w] - mid - 1), limit);
1276 target = dst + x + dst_signed_linesize * sum;
1277 update16(target, max, intensity, limit);
1279 if (!c0_shift_h || (y & c0_shift_h))
1280 c0_data += c0_linesize;
1281 if (!c1_shift_h || (y & c1_shift_h))
1282 c1_data += c1_linesize;
1283 dst_data += dst_linesize;
1287 const uint16_t *c0_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1288 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1289 uint16_t *dst_data = (uint16_t *)out->data[plane] + offset_y * dst_linesize + offset_x;
1292 dst_data += s->size - 1;
1293 for (y = 0; y < src_h; y++) {
1294 for (x = 0; x < src_w; x++) {
1295 const int sum = FFMIN(FFABS(c0_data[x >> c0_shift_w] - mid) + FFABS(c1_data[x >> c1_shift_w] - mid - 1), limit);
1299 target = dst_data - sum;
1300 update16(target, max, intensity, limit);
1302 target = dst_data + sum;
1303 update16(target, max, intensity, limit);
1307 if (!c0_shift_h || (y & c0_shift_h))
1308 c0_data += c0_linesize;
1309 if (!c1_shift_h || (y & c1_shift_h))
1310 c1_data += c1_linesize;
1311 dst_data += dst_linesize;
1315 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
1318 static av_always_inline void chroma(WaveformContext *s,
1319 AVFrame *in, AVFrame *out,
1320 int component, int intensity,
1321 int offset_y, int offset_x,
1322 int column, int mirror)
1324 const int plane = s->desc->comp[component].plane;
1325 const int c0_linesize = in->linesize[(plane + 1) % s->ncomp];
1326 const int c1_linesize = in->linesize[(plane + 2) % s->ncomp];
1327 const int dst_linesize = out->linesize[plane];
1328 const int max = 255 - intensity;
1329 const int c0_shift_w = s->shift_w[(component + 1) % s->ncomp];
1330 const int c1_shift_w = s->shift_w[(component + 2) % s->ncomp];
1331 const int c0_shift_h = s->shift_h[(component + 1) % s->ncomp];
1332 const int c1_shift_h = s->shift_h[(component + 2) % s->ncomp];
1333 const int src_h = in->height;
1334 const int src_w = in->width;
1338 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
1340 for (x = 0; x < src_w; x++) {
1341 const uint8_t *c0_data = in->data[(plane + 1) % s->ncomp];
1342 const uint8_t *c1_data = in->data[(plane + 2) % s->ncomp];
1343 uint8_t *dst_data = out->data[plane] + offset_y * dst_linesize + offset_x;
1344 uint8_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
1345 uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
1346 uint8_t *dst = dst_line;
1348 for (y = 0; y < src_h; y++) {
1349 const int sum = FFABS(c0_data[x >> c0_shift_w] - 128) + FFABS(c1_data[x >> c1_shift_w] - 127);
1352 target = dst + x + dst_signed_linesize * sum;
1353 update(target, max, intensity);
1355 if (!c0_shift_h || (y & c0_shift_h))
1356 c0_data += c0_linesize;
1357 if (!c1_shift_h || (y & c1_shift_h))
1358 c1_data += c1_linesize;
1359 dst_data += dst_linesize;
1363 const uint8_t *c0_data = in->data[(plane + 1) % s->ncomp];
1364 const uint8_t *c1_data = in->data[(plane + 2) % s->ncomp];
1365 uint8_t *dst_data = out->data[plane] + offset_y * dst_linesize + offset_x;
1368 dst_data += s->size - 1;
1369 for (y = 0; y < src_h; y++) {
1370 for (x = 0; x < src_w; x++) {
1371 const int sum = FFABS(c0_data[x >> c0_shift_w] - 128) + FFABS(c1_data[x >> c1_shift_w] - 127);
1375 target = dst_data - sum;
1376 update(target, max, intensity);
1378 target = dst_data + sum;
1379 update(target, max, intensity);
1383 if (!c0_shift_h || (y & c0_shift_h))
1384 c0_data += c0_linesize;
1385 if (!c1_shift_h || (y & c1_shift_h))
1386 c1_data += c1_linesize;
1387 dst_data += dst_linesize;
1391 envelope(s, out, plane, plane, column ? offset_x : offset_y);
1394 static av_always_inline void color16(WaveformContext *s,
1395 AVFrame *in, AVFrame *out,
1396 int component, int intensity,
1397 int offset_y, int offset_x,
1398 int column, int mirror)
1400 const int plane = s->desc->comp[component].plane;
1401 const int limit = s->max - 1;
1402 const uint16_t *c0_data = (const uint16_t *)in->data[plane + 0];
1403 const uint16_t *c1_data = (const uint16_t *)in->data[(plane + 1) % s->ncomp];
1404 const uint16_t *c2_data = (const uint16_t *)in->data[(plane + 2) % s->ncomp];
1405 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
1406 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1407 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1408 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
1409 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
1410 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2;
1411 const int c0_shift_w = s->shift_w[ component + 0 ];
1412 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1413 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1414 const int c0_shift_h = s->shift_h[ component + 0 ];
1415 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1416 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1417 const int src_h = in->height;
1418 const int src_w = in->width;
1422 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1423 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1424 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1425 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1426 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1427 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1428 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1429 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1430 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1431 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1432 uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1433 uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1435 for (y = 0; y < src_h; y++) {
1436 for (x = 0; x < src_w; x++) {
1437 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1438 const int c1 = c1_data[x >> c1_shift_w];
1439 const int c2 = c2_data[x >> c2_shift_w];
1441 *(d0 + d0_signed_linesize * c0 + x) = c0;
1442 *(d1 + d1_signed_linesize * c0 + x) = c1;
1443 *(d2 + d2_signed_linesize * c0 + x) = c2;
1446 if (!c0_shift_h || (y & c0_shift_h))
1447 c0_data += c0_linesize;
1448 if (!c1_shift_h || (y & c1_shift_h))
1449 c1_data += c1_linesize;
1450 if (!c2_shift_h || (y & c2_shift_h))
1451 c2_data += c2_linesize;
1452 d0_data += d0_linesize;
1453 d1_data += d1_linesize;
1454 d2_data += d2_linesize;
1457 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1458 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1459 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1462 d0_data += s->size - 1;
1463 d1_data += s->size - 1;
1464 d2_data += s->size - 1;
1467 for (y = 0; y < src_h; y++) {
1468 for (x = 0; x < src_w; x++) {
1469 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1470 const int c1 = c1_data[x >> c1_shift_w];
1471 const int c2 = c2_data[x >> c2_shift_w];
1474 *(d0_data - c0) = c0;
1475 *(d1_data - c0) = c1;
1476 *(d2_data - c0) = c2;
1478 *(d0_data + c0) = c0;
1479 *(d1_data + c0) = c1;
1480 *(d2_data + c0) = c2;
1484 if (!c0_shift_h || (y & c0_shift_h))
1485 c0_data += c0_linesize;
1486 if (!c1_shift_h || (y & c1_shift_h))
1487 c1_data += c1_linesize;
1488 if (!c2_shift_h || (y & c2_shift_h))
1489 c2_data += c2_linesize;
1490 d0_data += d0_linesize;
1491 d1_data += d1_linesize;
1492 d2_data += d2_linesize;
1496 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
1499 static av_always_inline void color(WaveformContext *s,
1500 AVFrame *in, AVFrame *out,
1501 int component, int intensity,
1502 int offset_y, int offset_x,
1503 int column, int mirror)
1505 const int plane = s->desc->comp[component].plane;
1506 const uint8_t *c0_data = in->data[plane + 0];
1507 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1508 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1509 const int c0_linesize = in->linesize[ plane + 0 ];
1510 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
1511 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
1512 const int d0_linesize = out->linesize[ plane + 0 ];
1513 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
1514 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp];
1515 const int c0_shift_w = s->shift_w[ component + 0 ];
1516 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1517 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1518 const int c0_shift_h = s->shift_h[ component + 0 ];
1519 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1520 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1521 const int src_h = in->height;
1522 const int src_w = in->width;
1526 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1527 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1528 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1529 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1530 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1531 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1532 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1533 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1534 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1535 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1536 uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1537 uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1539 for (y = 0; y < src_h; y++) {
1540 for (x = 0; x < src_w; x++) {
1541 const int c0 = c0_data[x >> c0_shift_w];
1542 const int c1 = c1_data[x >> c1_shift_w];
1543 const int c2 = c2_data[x >> c2_shift_w];
1545 *(d0 + d0_signed_linesize * c0 + x) = c0;
1546 *(d1 + d1_signed_linesize * c0 + x) = c1;
1547 *(d2 + d2_signed_linesize * c0 + x) = c2;
1550 if (!c0_shift_h || (y & c0_shift_h))
1551 c0_data += c0_linesize;
1552 if (!c1_shift_h || (y & c1_shift_h))
1553 c1_data += c1_linesize;
1554 if (!c2_shift_h || (y & c2_shift_h))
1555 c2_data += c2_linesize;
1556 d0_data += d0_linesize;
1557 d1_data += d1_linesize;
1558 d2_data += d2_linesize;
1561 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1562 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1563 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1566 d0_data += s->size - 1;
1567 d1_data += s->size - 1;
1568 d2_data += s->size - 1;
1571 for (y = 0; y < src_h; y++) {
1572 for (x = 0; x < src_w; x++) {
1573 const int c0 = c0_data[x >> c0_shift_w];
1574 const int c1 = c1_data[x >> c1_shift_w];
1575 const int c2 = c2_data[x >> c2_shift_w];
1578 *(d0_data - c0) = c0;
1579 *(d1_data - c0) = c1;
1580 *(d2_data - c0) = c2;
1582 *(d0_data + c0) = c0;
1583 *(d1_data + c0) = c1;
1584 *(d2_data + c0) = c2;
1588 if (!c0_shift_h || (y & c0_shift_h))
1589 c0_data += c0_linesize;
1590 if (!c1_shift_h || (y & c1_shift_h))
1591 c1_data += c1_linesize;
1592 if (!c2_shift_h || (y & c2_shift_h))
1593 c2_data += c2_linesize;
1594 d0_data += d0_linesize;
1595 d1_data += d1_linesize;
1596 d2_data += d2_linesize;
1600 envelope(s, out, plane, plane, column ? offset_x : offset_y);
1603 static av_always_inline void acolor16(WaveformContext *s,
1604 AVFrame *in, AVFrame *out,
1605 int component, int intensity,
1606 int offset_y, int offset_x,
1607 int column, int mirror)
1609 const int plane = s->desc->comp[component].plane;
1610 const int limit = s->max - 1;
1611 const int max = limit - intensity;
1612 const uint16_t *c0_data = (const uint16_t *)in->data[plane + 0];
1613 const uint16_t *c1_data = (const uint16_t *)in->data[(plane + 1) % s->ncomp];
1614 const uint16_t *c2_data = (const uint16_t *)in->data[(plane + 2) % s->ncomp];
1615 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
1616 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1617 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1618 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
1619 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
1620 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2;
1621 const int c0_shift_w = s->shift_w[ component + 0 ];
1622 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1623 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1624 const int c0_shift_h = s->shift_h[ component + 0 ];
1625 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1626 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1627 const int src_h = in->height;
1628 const int src_w = in->width;
1632 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1633 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1634 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1635 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1636 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1637 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1638 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1639 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1640 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1641 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1642 uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1643 uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1645 for (y = 0; y < src_h; y++) {
1646 for (x = 0; x < src_w; x++) {
1647 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1648 const int c1 = c1_data[x >> c1_shift_w];
1649 const int c2 = c2_data[x >> c2_shift_w];
1651 update16(d0 + d0_signed_linesize * c0 + x, max, intensity, limit);
1652 *(d1 + d1_signed_linesize * c0 + x) = c1;
1653 *(d2 + d2_signed_linesize * c0 + x) = c2;
1656 if (!c0_shift_h || (y & c0_shift_h))
1657 c0_data += c0_linesize;
1658 if (!c1_shift_h || (y & c1_shift_h))
1659 c1_data += c1_linesize;
1660 if (!c2_shift_h || (y & c2_shift_h))
1661 c2_data += c2_linesize;
1662 d0_data += d0_linesize;
1663 d1_data += d1_linesize;
1664 d2_data += d2_linesize;
1667 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1668 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1669 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1672 d0_data += s->size - 1;
1673 d1_data += s->size - 1;
1674 d2_data += s->size - 1;
1677 for (y = 0; y < src_h; y++) {
1678 for (x = 0; x < src_w; x++) {
1679 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1680 const int c1 = c1_data[x >> c1_shift_w];
1681 const int c2 = c2_data[x >> c2_shift_w];
1684 update16(d0_data - c0, max, intensity, limit);
1685 *(d1_data - c0) = c1;
1686 *(d2_data - c0) = c2;
1688 update16(d0_data + c0, max, intensity, limit);
1689 *(d1_data + c0) = c1;
1690 *(d2_data + c0) = c2;
1694 if (!c0_shift_h || (y & c0_shift_h))
1695 c0_data += c0_linesize;
1696 if (!c1_shift_h || (y & c1_shift_h))
1697 c1_data += c1_linesize;
1698 if (!c2_shift_h || (y & c2_shift_h))
1699 c2_data += c2_linesize;
1700 d0_data += d0_linesize;
1701 d1_data += d1_linesize;
1702 d2_data += d2_linesize;
1706 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
1709 static av_always_inline void acolor(WaveformContext *s,
1710 AVFrame *in, AVFrame *out,
1711 int component, int intensity,
1712 int offset_y, int offset_x,
1713 int column, int mirror)
1715 const int plane = s->desc->comp[component].plane;
1716 const uint8_t *c0_data = in->data[plane + 0];
1717 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1718 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1719 const int c0_linesize = in->linesize[ plane + 0 ];
1720 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
1721 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
1722 const int d0_linesize = out->linesize[ plane + 0 ];
1723 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
1724 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp];
1725 const int c0_shift_w = s->shift_w[ component + 0 ];
1726 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1727 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1728 const int c0_shift_h = s->shift_h[ component + 0 ];
1729 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1730 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1731 const int max = 255 - intensity;
1732 const int src_h = in->height;
1733 const int src_w = in->width;
1737 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1738 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1739 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1740 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1741 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1742 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1743 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1744 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1745 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1746 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1747 uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1748 uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1750 for (y = 0; y < src_h; y++) {
1751 for (x = 0; x < src_w; x++) {
1752 const int c0 = c0_data[x >> c0_shift_w];
1753 const int c1 = c1_data[x >> c1_shift_w];
1754 const int c2 = c2_data[x >> c2_shift_w];
1756 update(d0 + d0_signed_linesize * c0 + x, max, intensity);
1757 *(d1 + d1_signed_linesize * c0 + x) = c1;
1758 *(d2 + d2_signed_linesize * c0 + x) = c2;
1761 if (!c0_shift_h || (y & c0_shift_h))
1762 c0_data += c0_linesize;
1763 if (!c1_shift_h || (y & c1_shift_h))
1764 c1_data += c1_linesize;
1765 if (!c2_shift_h || (y & c2_shift_h))
1766 c2_data += c2_linesize;
1767 d0_data += d0_linesize;
1768 d1_data += d1_linesize;
1769 d2_data += d2_linesize;
1772 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1773 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1774 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1777 d0_data += s->size - 1;
1778 d1_data += s->size - 1;
1779 d2_data += s->size - 1;
1782 for (y = 0; y < src_h; y++) {
1783 for (x = 0; x < src_w; x++) {
1784 const int c0 = c0_data[x >> c0_shift_w];
1785 const int c1 = c1_data[x >> c1_shift_w];
1786 const int c2 = c2_data[x >> c2_shift_w];
1789 update(d0_data - c0, max, intensity);
1790 *(d1_data - c0) = c1;
1791 *(d2_data - c0) = c2;
1793 update(d0_data + c0, max, intensity);
1794 *(d1_data + c0) = c1;
1795 *(d2_data + c0) = c2;
1799 if (!c0_shift_h || (y & c0_shift_h))
1800 c0_data += c0_linesize;
1801 if (!c1_shift_h || (y & c1_shift_h))
1802 c1_data += c1_linesize;
1803 if (!c2_shift_h || (y & c2_shift_h))
1804 c2_data += c2_linesize;
1805 d0_data += d0_linesize;
1806 d1_data += d1_linesize;
1807 d2_data += d2_linesize;
1811 envelope(s, out, plane, plane, column ? offset_x : offset_y);
1814 static const uint8_t black_yuva_color[4] = { 0, 127, 127, 255 };
1815 static const uint8_t green_yuva_color[4] = { 255, 0, 0, 255 };
1816 static const uint8_t black_gbrp_color[4] = { 0, 0, 0, 255 };
1818 static const GraticuleLines aflat_digital8[] = {
1819 { { { "16", 16+128 }, { "16", 16+128 }, { "16", 16+128 }, { "0", 0+128 } } },
1820 { { { "128", 128+128 }, { "128", 128+128 }, { "128", 128+128 }, { "128", 128+128 } } },
1821 { { { "235", 235+128 }, { "240", 240+128 }, { "240", 240+128 }, { "255", 255+128 } } },
1824 static const GraticuleLines aflat_digital9[] = {
1825 { { { "32", 32+256 }, { "32", 32+256 }, { "32", 32+256 }, { "0", 0+256 } } },
1826 { { { "256", 256+256 }, { "256", 256+256 }, { "256", 256+256 }, { "256", 256+256 } } },
1827 { { { "470", 470+256 }, { "480", 480+256 }, { "480", 480+256 }, { "511", 511+256 } } },
1830 static const GraticuleLines aflat_digital10[] = {
1831 { { { "64", 64+512 }, { "64", 64+512 }, { "64", 64+512 }, { "0", 0+512 } } },
1832 { { { "512", 512+512 }, { "512", 512+512 }, { "512", 512+512 }, { "512", 512+512 } } },
1833 { { { "940", 940+512 }, { "960", 960+512 }, { "960", 960+512 }, { "1023", 1023+512 } } },
1836 static const GraticuleLines aflat_digital12[] = {
1837 { { { "256", 256+2048 }, { "256", 256+2048 }, { "256", 256+2048 }, { "0", 0+2048 } } },
1838 { { { "2048", 2048+2048 }, { "2048", 2048+2048 }, { "2048", 2048+2048 }, { "2048", 2048+2048 } } },
1839 { { { "3760", 3760+2048 }, { "3840", 3840+2048 }, { "3840", 3840+2048 }, { "4095", 4095+2048 } } },
1842 static const GraticuleLines aflat_millivolts8[] = {
1843 { { { "0", 16+128 }, { "0", 16+128 }, { "0", 16+128 }, { "0", 0+128 } } },
1844 { { { "175", 71+128 }, { "175", 72+128 }, { "175", 72+128 }, { "175", 64+128 } } },
1845 { { { "350", 126+128 }, { "350", 128+128 }, { "350", 128+128 }, { "350", 128+128 } } },
1846 { { { "525", 180+128 }, { "525", 184+128 }, { "525", 184+128 }, { "525", 192+128 } } },
1847 { { { "700", 235+128 }, { "700", 240+128 }, { "700", 240+128 }, { "700", 255+128 } } },
1850 static const GraticuleLines aflat_millivolts9[] = {
1851 { { { "0", 32+256 }, { "0", 32+256 }, { "0", 32+256 }, { "0", 0+256 } } },
1852 { { { "175", 142+256 }, { "175", 144+256 }, { "175", 144+256 }, { "175", 128+256 } } },
1853 { { { "350", 251+256 }, { "350", 256+256 }, { "350", 256+256 }, { "350", 256+256 } } },
1854 { { { "525", 361+256 }, { "525", 368+256 }, { "525", 368+256 }, { "525", 384+256 } } },
1855 { { { "700", 470+256 }, { "700", 480+256 }, { "700", 480+256 }, { "700", 511+256 } } },
1858 static const GraticuleLines aflat_millivolts10[] = {
1859 { { { "0", 64+512 }, { "0", 64+512 }, { "0", 64+512 }, { "0", 0+512 } } },
1860 { { { "175", 283+512 }, { "175", 288+512 }, { "175", 288+512 }, { "175", 256+512 } } },
1861 { { { "350", 502+512 }, { "350", 512+512 }, { "350", 512+512 }, { "350", 512+512 } } },
1862 { { { "525", 721+512 }, { "525", 736+512 }, { "525", 736+512 }, { "525", 768+512 } } },
1863 { { { "700", 940+512 }, { "700", 960+512 }, { "700", 960+512 }, { "700", 1023+512 } } },
1866 static const GraticuleLines aflat_millivolts12[] = {
1867 { { { "0", 256+2048 }, { "0", 256+2048 }, { "0", 256+2048 }, { "0", 0+2048 } } },
1868 { { { "175", 1132+2048 }, { "175", 1152+2048 }, { "175", 1152+2048 }, { "175", 1024+2048 } } },
1869 { { { "350", 2008+2048 }, { "350", 2048+2048 }, { "350", 2048+2048 }, { "350", 2048+2048 } } },
1870 { { { "525", 2884+2048 }, { "525", 2944+2048 }, { "525", 2944+2048 }, { "525", 3072+2048 } } },
1871 { { { "700", 3760+2048 }, { "700", 3840+2048 }, { "700", 3840+2048 }, { "700", 4095+2048 } } },
1874 static const GraticuleLines aflat_ire8[] = {
1875 { { { "-25", -39+128 }, { "-25", -40+128 }, { "-25", -40+128 }, { "-25", -64+128 } } },
1876 { { { "0", 16+128 }, { "0", 16+128 }, { "0", 16+128 }, { "0", 0+128 } } },
1877 { { { "25", 71+128 }, { "25", 72+128 }, { "25", 72+128 }, { "25", 64+128 } } },
1878 { { { "50", 126+128 }, { "50", 128+128 }, { "50", 128+128 }, { "50", 128+128 } } },
1879 { { { "75", 180+128 }, { "75", 184+128 }, { "75", 184+128 }, { "75", 192+128 } } },
1880 { { { "100", 235+128 }, { "100", 240+128 }, { "100", 240+128 }, { "100", 256+128 } } },
1881 { { { "125", 290+128 }, { "125", 296+128 }, { "125", 296+128 }, { "125", 320+128 } } },
1884 static const GraticuleLines aflat_ire9[] = {
1885 { { { "-25", -78+256 }, { "-25", -80+256 }, { "-25", -80+256 }, { "-25",-128+256 } } },
1886 { { { "0", 32+256 }, { "0", 32+256 }, { "0", 32+256 }, { "0", 0+256 } } },
1887 { { { "25", 142+256 }, { "25", 144+256 }, { "25", 144+256 }, { "25", 128+256 } } },
1888 { { { "50", 251+256 }, { "50", 256+256 }, { "50", 256+256 }, { "50", 256+256 } } },
1889 { { { "75", 361+256 }, { "75", 368+256 }, { "75", 368+256 }, { "75", 384+256 } } },
1890 { { { "100", 470+256 }, { "100", 480+256 }, { "100", 480+256 }, { "100", 512+256 } } },
1891 { { { "125", 580+256 }, { "125", 592+256 }, { "125", 592+256 }, { "125", 640+256 } } },
1894 static const GraticuleLines aflat_ire10[] = {
1895 { { { "-25",-156+512 }, { "-25",-160+512 }, { "-25",-160+512 }, { "-25", -256+512 } } },
1896 { { { "0", 64+512 }, { "0", 64+512 }, { "0", 64+512 }, { "0", 0+512 } } },
1897 { { { "25", 283+512 }, { "25", 288+512 }, { "25", 288+512 }, { "25", 256+512 } } },
1898 { { { "50", 502+512 }, { "50", 512+512 }, { "50", 512+512 }, { "50", 512+512 } } },
1899 { { { "75", 721+512 }, { "75", 736+512 }, { "75", 736+512 }, { "75", 768+512 } } },
1900 { { { "100", 940+512 }, { "100", 960+512 }, { "100", 960+512 }, { "100", 1024+512 } } },
1901 { { { "125",1160+512 }, { "125",1184+512 }, { "125",1184+512 }, { "125", 1280+512 } } },
1904 static const GraticuleLines aflat_ire12[] = {
1905 { { { "-25", -624+2048 }, { "-25", -640+2048 }, { "-25", -640+2048 }, { "-25",-1024+2048 } } },
1906 { { { "0", 256+2048 }, { "0", 256+2048 }, { "0", 256+2048 }, { "0", 0+2048 } } },
1907 { { { "25", 1132+2048 }, { "25", 1152+2048 }, { "25", 1152+2048 }, { "25", 1024+2048 } } },
1908 { { { "50", 2008+2048 }, { "50", 2048+2048 }, { "50", 2048+2048 }, { "50", 2048+2048 } } },
1909 { { { "75", 2884+2048 }, { "75", 2944+2048 }, { "75", 2944+2048 }, { "75", 3072+2048 } } },
1910 { { { "100", 3760+2048 }, { "100", 3840+2048 }, { "100", 3840+2048 }, { "100", 4096+2048 } } },
1911 { { { "125", 4640+2048 }, { "125", 4736+2048 }, { "125", 4736+2048 }, { "125", 5120+2048 } } },
1914 static const GraticuleLines flat_digital8[] = {
1915 { { { "16", 16+256 }, { "16", 16+256 }, { "16", 16+256 }, { "0", 0+256 } } },
1916 { { { "128", 128+256 }, { "128", 128+256 }, { "128", 128+256 }, { "128", 128+256 } } },
1917 { { { "235", 235+256 }, { "240", 240+256 }, { "240", 240+256 }, { "255", 255+256 } } },
1920 static const GraticuleLines flat_digital9[] = {
1921 { { { "32", 32+512 }, { "32", 32+512 }, { "32", 32+512 }, { "0", 0+512 } } },
1922 { { { "256", 256+512 }, { "256", 256+512 }, { "256", 256+512 }, { "256", 256+512 } } },
1923 { { { "470", 470+512 }, { "480", 480+512 }, { "480", 480+512 }, { "511", 511+512 } } },
1926 static const GraticuleLines flat_digital10[] = {
1927 { { { "64", 64+1024 }, { "64", 64+1024 }, { "64", 64+1024 }, { "0", 0+1024 } } },
1928 { { { "512", 512+1024 }, { "512", 512+1024 }, { "512", 512+1024 }, { "512", 512+1024 } } },
1929 { { { "940", 940+1024 }, { "960", 960+1024 }, { "960", 960+1024 }, { "1023", 1023+1024 } } },
1932 static const GraticuleLines flat_digital12[] = {
1933 { { { "256", 256+4096 }, { "256", 256+4096 }, { "256", 256+4096 }, { "0", 0+4096 } } },
1934 { { { "2048", 2048+4096 }, { "2048", 2048+4096 }, { "2048", 2048+4096 }, { "2048", 2048+4096 } } },
1935 { { { "3760", 3760+4096 }, { "3840", 3840+4096 }, { "3840", 3840+4096 }, { "4095", 4095+4096 } } },
1938 static const GraticuleLines flat_millivolts8[] = {
1939 { { { "0", 16+256 }, { "0", 16+256 }, { "0", 16+256 }, { "0", 0+256 } } },
1940 { { { "175", 71+256 }, { "175", 72+256 }, { "175", 72+256 }, { "175", 64+256 } } },
1941 { { { "350", 126+256 }, { "350", 128+256 }, { "350", 128+256 }, { "350", 128+256 } } },
1942 { { { "525", 180+256 }, { "525", 184+256 }, { "525", 184+256 }, { "525", 192+256 } } },
1943 { { { "700", 235+256 }, { "700", 240+256 }, { "700", 240+256 }, { "700", 255+256 } } },
1946 static const GraticuleLines flat_millivolts9[] = {
1947 { { { "0", 32+512 }, { "0", 32+512 }, { "0", 32+512 }, { "0", 0+512 } } },
1948 { { { "175", 142+512 }, { "175", 144+512 }, { "175", 144+512 }, { "175", 128+512 } } },
1949 { { { "350", 251+512 }, { "350", 256+512 }, { "350", 256+512 }, { "350", 256+512 } } },
1950 { { { "525", 361+512 }, { "525", 368+512 }, { "525", 368+512 }, { "525", 384+512 } } },
1951 { { { "700", 470+512 }, { "700", 480+512 }, { "700", 480+512 }, { "700", 511+512 } } },
1954 static const GraticuleLines flat_millivolts10[] = {
1955 { { { "0", 64+1024 }, { "0", 64+1024 }, { "0", 64+1024 }, { "0", 0+1024 } } },
1956 { { { "175", 283+1024 }, { "175", 288+1024 }, { "175", 288+1024 }, { "175", 256+1024 } } },
1957 { { { "350", 502+1024 }, { "350", 512+1024 }, { "350", 512+1024 }, { "350", 512+1024 } } },
1958 { { { "525", 721+1024 }, { "525", 736+1024 }, { "525", 736+1024 }, { "525", 768+1024 } } },
1959 { { { "700", 940+1024 }, { "700", 960+1024 }, { "700", 960+1024 }, { "700", 1023+1024 } } },
1962 static const GraticuleLines flat_millivolts12[] = {
1963 { { { "0", 256+4096 }, { "0", 256+4096 }, { "0", 256+4096 }, { "0", 0+4096 } } },
1964 { { { "175", 1132+4096 }, { "175", 1152+4096 }, { "175", 1152+4096 }, { "175", 1024+4096 } } },
1965 { { { "350", 2008+4096 }, { "350", 2048+4096 }, { "350", 2048+4096 }, { "350", 2048+4096 } } },
1966 { { { "525", 2884+4096 }, { "525", 2944+4096 }, { "525", 2944+4096 }, { "525", 3072+4096 } } },
1967 { { { "700", 3760+4096 }, { "700", 3840+4096 }, { "700", 3840+4096 }, { "700", 4095+4096 } } },
1970 static const GraticuleLines flat_ire8[] = {
1971 { { { "-25", -39+256 }, { "-25", -40+256 }, { "-25", -40+256 }, { "-25", -64+256 } } },
1972 { { { "0", 16+256 }, { "0", 16+256 }, { "0", 16+256 }, { "0", 0+256 } } },
1973 { { { "25", 71+256 }, { "25", 72+256 }, { "25", 72+256 }, { "25", 64+256 } } },
1974 { { { "50", 126+256 }, { "50", 128+256 }, { "50", 128+256 }, { "50", 128+256 } } },
1975 { { { "75", 180+256 }, { "75", 184+256 }, { "75", 184+256 }, { "75", 192+256 } } },
1976 { { { "100", 235+256 }, { "100", 240+256 }, { "100", 240+256 }, { "100", 256+256 } } },
1977 { { { "125", 290+256 }, { "125", 296+256 }, { "125", 296+256 }, { "125", 320+256 } } },
1980 static const GraticuleLines flat_ire9[] = {
1981 { { { "-25", -78+512 }, { "-25", -80+512 }, { "-25", -80+512 }, { "-25",-128+512 } } },
1982 { { { "0", 32+512 }, { "0", 32+512 }, { "0", 32+512 }, { "0", 0+512 } } },
1983 { { { "25", 142+512 }, { "25", 144+512 }, { "25", 144+512 }, { "25", 128+512 } } },
1984 { { { "50", 251+512 }, { "50", 256+512 }, { "50", 256+512 }, { "50", 256+512 } } },
1985 { { { "75", 361+512 }, { "75", 368+512 }, { "75", 368+512 }, { "75", 384+512 } } },
1986 { { { "100", 470+512 }, { "100", 480+512 }, { "100", 480+512 }, { "100", 512+512 } } },
1987 { { { "125", 580+512 }, { "125", 592+512 }, { "125", 592+512 }, { "125", 640+512 } } },
1990 static const GraticuleLines flat_ire10[] = {
1991 { { { "-25",-156+1024 }, { "-25",-160+1024 }, { "-25",-160+1024 }, { "-25", -256+1024 } } },
1992 { { { "0", 64+1024 }, { "0", 64+1024 }, { "0", 64+1024 }, { "0", 0+1024 } } },
1993 { { { "25", 283+1024 }, { "25", 288+1024 }, { "25", 288+1024 }, { "25", 256+1024 } } },
1994 { { { "50", 502+1024 }, { "50", 512+1024 }, { "50", 512+1024 }, { "50", 512+1024 } } },
1995 { { { "75", 721+1024 }, { "75", 736+1024 }, { "75", 736+1024 }, { "75", 768+1024 } } },
1996 { { { "100", 940+1024 }, { "100", 960+1024 }, { "100", 960+1024 }, { "100", 1024+1024 } } },
1997 { { { "125",1160+1024 }, { "125",1184+1024 }, { "125",1184+1024 }, { "125", 1280+1024 } } },
2000 static const GraticuleLines flat_ire12[] = {
2001 { { { "-25", -624+4096 }, { "-25", -640+4096 }, { "-25", -640+4096 }, { "-25",-1024+4096 } } },
2002 { { { "0", 256+4096 }, { "0", 256+4096 }, { "0", 256+4096 }, { "0", 0+4096 } } },
2003 { { { "25", 1132+4096 }, { "25", 1152+4096 }, { "25", 1152+4096 }, { "25", 1024+4096 } } },
2004 { { { "50", 2008+4096 }, { "50", 2048+4096 }, { "50", 2048+4096 }, { "50", 2048+4096 } } },
2005 { { { "75", 2884+4096 }, { "75", 2944+4096 }, { "75", 2944+4096 }, { "75", 3072+4096 } } },
2006 { { { "100", 3760+4096 }, { "100", 3840+4096 }, { "100", 3840+4096 }, { "100", 4096+4096 } } },
2007 { { { "125", 4640+4096 }, { "125", 4736+4096 }, { "125", 4736+4096 }, { "125", 5120+4096 } } },
2010 static const GraticuleLines digital8[] = {
2011 { { { "16", 16 }, { "16", 16 }, { "16", 16 }, { "0", 0 } } },
2012 { { { "128", 128 }, { "128", 128 }, { "128", 128 }, { "128", 128 } } },
2013 { { { "235", 235 }, { "240", 240 }, { "240", 240 }, { "255", 255 } } },
2016 static const GraticuleLines digital9[] = {
2017 { { { "32", 32 }, { "32", 32 }, { "32", 32 }, { "0", 0 } } },
2018 { { { "256", 256 }, { "256", 256 }, { "256", 256 }, { "256", 256 } } },
2019 { { { "470", 470 }, { "480", 480 }, { "480", 480 }, { "511", 511 } } },
2022 static const GraticuleLines digital10[] = {
2023 { { { "64", 64 }, { "64", 64 }, { "64", 64 }, { "0", 0 } } },
2024 { { { "512", 512 }, { "512", 512 }, { "512", 512 }, { "512", 512 } } },
2025 { { { "940", 940 }, { "960", 960 }, { "960", 960 }, { "1023", 1023 } } },
2028 static const GraticuleLines digital12[] = {
2029 { { { "256", 256 }, { "256", 256 }, { "256", 256 }, { "0", 0 } } },
2030 { { { "2048", 2048 }, { "2048", 2048 }, { "2048", 2048 }, { "2048", 2048 } } },
2031 { { { "3760", 3760 }, { "3840", 3840 }, { "3840", 3840 }, { "4095", 4095 } } },
2034 static const GraticuleLines millivolts8[] = {
2035 { { { "0", 16 }, { "0", 16 }, { "0", 16 }, { "0", 0 } } },
2036 { { { "175", 71 }, { "175", 72 }, { "175", 72 }, { "175", 64 } } },
2037 { { { "350", 126 }, { "350", 128 }, { "350", 128 }, { "350", 128 } } },
2038 { { { "525", 180 }, { "525", 184 }, { "525", 184 }, { "525", 192 } } },
2039 { { { "700", 235 }, { "700", 240 }, { "700", 240 }, { "700", 255 } } },
2042 static const GraticuleLines millivolts9[] = {
2043 { { { "0", 32 }, { "0", 32 }, { "0", 32 }, { "0", 0 } } },
2044 { { { "175", 142 }, { "175", 144 }, { "175", 144 }, { "175", 128 } } },
2045 { { { "350", 251 }, { "350", 256 }, { "350", 256 }, { "350", 256 } } },
2046 { { { "525", 361 }, { "525", 368 }, { "525", 368 }, { "525", 384 } } },
2047 { { { "700", 470 }, { "700", 480 }, { "700", 480 }, { "700", 511 } } },
2050 static const GraticuleLines millivolts10[] = {
2051 { { { "0", 64 }, { "0", 64 }, { "0", 64 }, { "0", 0 } } },
2052 { { { "175", 283 }, { "175", 288 }, { "175", 288 }, { "175", 256 } } },
2053 { { { "350", 502 }, { "350", 512 }, { "350", 512 }, { "350", 512 } } },
2054 { { { "525", 721 }, { "525", 736 }, { "525", 736 }, { "525", 768 } } },
2055 { { { "700", 940 }, { "700", 960 }, { "700", 960 }, { "700", 1023 } } },
2058 static const GraticuleLines millivolts12[] = {
2059 { { { "0", 256 }, { "0", 256 }, { "0", 256 }, { "0", 0 } } },
2060 { { { "175", 1132 }, { "175", 1152 }, { "175", 1152 }, { "175", 1024 } } },
2061 { { { "350", 2008 }, { "350", 2048 }, { "350", 2048 }, { "350", 2048 } } },
2062 { { { "525", 2884 }, { "525", 2944 }, { "525", 2944 }, { "525", 3072 } } },
2063 { { { "700", 3760 }, { "700", 3840 }, { "700", 3840 }, { "700", 4095 } } },
2066 static const GraticuleLines ire8[] = {
2067 { { { "0", 16 }, { "0", 16 }, { "0", 16 }, { "0", 0 } } },
2068 { { { "25", 71 }, { "25", 72 }, { "25", 72 }, { "25", 64 } } },
2069 { { { "50", 126 }, { "50", 128 }, { "50", 128 }, { "50", 128 } } },
2070 { { { "75", 180 }, { "75", 184 }, { "75", 184 }, { "75", 192 } } },
2071 { { { "100", 235 }, { "100", 240 }, { "100", 240 }, { "100", 255 } } },
2074 static const GraticuleLines ire9[] = {
2075 { { { "0", 32 }, { "0", 32 }, { "0", 32 }, { "0", 0 } } },
2076 { { { "25", 142 }, { "25", 144 }, { "25", 144 }, { "25", 128 } } },
2077 { { { "50", 251 }, { "50", 256 }, { "50", 256 }, { "50", 256 } } },
2078 { { { "75", 361 }, { "75", 368 }, { "75", 368 }, { "75", 384 } } },
2079 { { { "100", 470 }, { "100", 480 }, { "100", 480 }, { "100", 511 } } },
2082 static const GraticuleLines ire10[] = {
2083 { { { "0", 64 }, { "0", 64 }, { "0", 64 }, { "0", 0 } } },
2084 { { { "25", 283 }, { "25", 288 }, { "25", 288 }, { "25", 256 } } },
2085 { { { "50", 502 }, { "50", 512 }, { "50", 512 }, { "50", 512 } } },
2086 { { { "75", 721 }, { "75", 736 }, { "75", 736 }, { "75", 768 } } },
2087 { { { "100", 940 }, { "100", 960 }, { "100", 960 }, { "100", 1023 } } },
2090 static const GraticuleLines ire12[] = {
2091 { { { "0", 256 }, { "0", 256 }, { "0", 256 }, { "0", 0 } } },
2092 { { { "25", 1132 }, { "25", 1152 }, { "25", 1152 }, { "25", 1024 } } },
2093 { { { "50", 2008 }, { "50", 2048 }, { "50", 2048 }, { "50", 2048 } } },
2094 { { { "75", 2884 }, { "75", 2944 }, { "75", 2944 }, { "75", 3072 } } },
2095 { { { "100", 3760 }, { "100", 3840 }, { "100", 3840 }, { "100", 4095 } } },
2098 static const GraticuleLines chroma_digital8[] = {
2099 { { { "50", 50 }, { "50", 50 }, { "50", 50 }, { "50", 50 } } },
2100 { { { "100", 100 }, { "100", 100 }, { "100", 100 }, { "100", 100 } } },
2101 { { { "150", 150 }, { "150", 150 }, { "150", 150 }, { "150", 150 } } },
2102 { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2103 { { { "255", 255 }, { "255", 255 }, { "255", 255 }, { "255", 255 } } },
2106 static const GraticuleLines chroma_digital9[] = {
2107 { { { "100", 100 }, { "100", 100 }, { "100", 100 }, { "100", 100 } } },
2108 { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2109 { { { "300", 300 }, { "300", 300 }, { "300", 300 }, { "300", 300 } } },
2110 { { { "400", 400 }, { "400", 400 }, { "400", 400 }, { "400", 400 } } },
2111 { { { "500", 500 }, { "500", 500 }, { "500", 500 }, { "500", 500 } } },
2114 static const GraticuleLines chroma_digital10[] = {
2115 { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2116 { { { "400", 400 }, { "400", 400 }, { "400", 400 }, { "400", 400 } } },
2117 { { { "600", 600 }, { "600", 600 }, { "600", 600 }, { "600", 600 } } },
2118 { { { "800", 800 }, { "800", 800 }, { "800", 800 }, { "800", 800 } } },
2119 { { {"1000",1000 }, {"1000",1000 }, {"1000",1000 }, {"1000",1000 } } },
2122 static const GraticuleLines chroma_digital12[] = {
2123 { { { "800", 800 }, { "800", 800 }, { "800", 800 }, { "800", 800 } } },
2124 { { { "1600", 1600 }, { "1600", 1600 }, { "1600", 1600 }, { "1600", 1600 } } },
2125 { { { "2400", 2400 }, { "2400", 2400 }, { "2400", 2400 }, { "2400", 2400 } } },
2126 { { { "3200", 3200 }, { "3200", 3200 }, { "3200", 3200 }, { "3200", 3200 } } },
2127 { { { "4000", 4000 }, { "4000", 4000 }, { "4000", 4000 }, { "4000", 4000 } } },
2130 static void blend_vline(uint8_t *dst, int height, int linesize, float o1, float o2, int v, int step)
2134 for (y = 0; y < height; y += step) {
2135 dst[0] = v * o1 + dst[0] * o2;
2137 dst += linesize * step;
2141 static void blend_vline16(uint16_t *dst, int height, int linesize, float o1, float o2, int v, int step)
2145 for (y = 0; y < height; y += step) {
2146 dst[0] = v * o1 + dst[0] * o2;
2148 dst += (linesize / 2) * step;
2152 static void blend_hline(uint8_t *dst, int width, float o1, float o2, int v, int step)
2156 for (x = 0; x < width; x += step) {
2157 dst[x] = v * o1 + dst[x] * o2;
2161 static void blend_hline16(uint16_t *dst, int width, float o1, float o2, int v, int step)
2165 for (x = 0; x < width; x += step) {
2166 dst[x] = v * o1 + dst[x] * o2;
2170 static void draw_htext(AVFrame *out, int x, int y, float o1, float o2, const char *txt, const uint8_t color[4])
2172 const uint8_t *font;
2176 font = avpriv_cga_font, font_height = 8;
2178 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2179 for (i = 0; txt[i]; i++) {
2181 int v = color[plane];
2183 uint8_t *p = out->data[plane] + y * out->linesize[plane] + (x + i * 8);
2184 for (char_y = 0; char_y < font_height; char_y++) {
2185 for (mask = 0x80; mask; mask >>= 1) {
2186 if (font[txt[i] * font_height + char_y] & mask)
2187 p[0] = p[0] * o2 + v * o1;
2190 p += out->linesize[plane] - 8;
2196 static void draw_htext16(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
2198 const uint8_t *font;
2202 font = avpriv_cga_font, font_height = 8;
2204 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2205 for (i = 0; txt[i]; i++) {
2207 int v = color[plane] * mult;
2209 uint16_t *p = (uint16_t *)(out->data[plane] + y * out->linesize[plane]) + (x + i * 8);
2210 for (char_y = 0; char_y < font_height; char_y++) {
2211 for (mask = 0x80; mask; mask >>= 1) {
2212 if (font[txt[i] * font_height + char_y] & mask)
2213 p[0] = p[0] * o2 + v * o1;
2216 p += out->linesize[plane] / 2 - 8;
2222 static void draw_vtext(AVFrame *out, int x, int y, float o1, float o2, const char *txt, const uint8_t color[4])
2224 const uint8_t *font;
2228 font = avpriv_cga_font, font_height = 8;
2230 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2231 for (i = 0; txt[i]; i++) {
2233 int v = color[plane];
2235 for (char_y = font_height - 1; char_y >= 0; char_y--) {
2236 uint8_t *p = out->data[plane] + (y + i * 10) * out->linesize[plane] + x;
2237 for (mask = 0x80; mask; mask >>= 1) {
2238 if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
2239 p[char_y] = p[char_y] * o2 + v * o1;
2240 p += out->linesize[plane];
2247 static void draw_vtext16(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
2249 const uint8_t *font;
2253 font = avpriv_cga_font, font_height = 8;
2255 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2256 for (i = 0; txt[i]; i++) {
2258 int v = color[plane] * mult;
2260 for (char_y = 0; char_y < font_height; char_y++) {
2261 uint16_t *p = (uint16_t *)(out->data[plane] + (y + i * 10) * out->linesize[plane]) + x;
2262 for (mask = 0x80; mask; mask >>= 1) {
2263 if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
2264 p[char_y] = p[char_y] * o2 + v * o1;
2265 p += out->linesize[plane] / 2;
2272 static void graticule_none(WaveformContext *s, AVFrame *out)
2276 static void graticule_green_row(WaveformContext *s, AVFrame *out)
2278 const int step = (s->flags & 2) + 1;
2279 const float o1 = s->opacity;
2280 const float o2 = 1. - o1;
2281 const int height = s->display == PARADE ? out->height / s->acomp : out->height;
2282 int k = 0, c, p, l, offset_x = 0, offset_y = 0;
2284 for (c = 0; c < s->ncomp; c++) {
2285 if (!((1 << c) & s->pcomp) || (!s->display && k > 0))
2289 for (p = 0; p < s->ncomp; p++) {
2290 const int v = green_yuva_color[p];
2291 for (l = 0; l < s->nb_glines; l++) {
2292 const uint16_t pos = s->glines[l].line[c].pos;
2293 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos);
2294 uint8_t *dst = out->data[p] + offset_y * out->linesize[p] + x;
2296 blend_vline(dst, height, out->linesize[p], o1, o2, v, step);
2300 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2301 const char *name = s->glines[l].line[c].name;
2302 const uint16_t pos = s->glines[l].line[c].pos;
2303 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos) - 10;
2308 draw_vtext(out, x, offset_y + 2, o1, o2, name, green_yuva_color);
2311 offset_x += s->size * (s->display == STACK);
2312 offset_y += height * (s->display == PARADE);
2316 static void graticule16_green_row(WaveformContext *s, AVFrame *out)
2318 const int step = (s->flags & 2) + 1;
2319 const float o1 = s->opacity;
2320 const float o2 = 1. - o1;
2321 const int mult = s->size / 256;
2322 const int height = s->display == PARADE ? out->height / s->acomp : out->height;
2323 int k = 0, c, p, l, offset_x = 0, offset_y = 0;
2325 for (c = 0; c < s->ncomp; c++) {
2326 if (!((1 << c) & s->pcomp) || (!s->display && k > 0))
2330 for (p = 0; p < s->ncomp; p++) {
2331 const int v = green_yuva_color[p] * mult;
2332 for (l = 0; l < s->nb_glines ; l++) {
2333 const uint16_t pos = s->glines[l].line[c].pos;
2334 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos);
2335 uint16_t *dst = (uint16_t *)(out->data[p] + offset_y * out->linesize[p]) + x;
2337 blend_vline16(dst, height, out->linesize[p], o1, o2, v, step);
2341 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2342 const char *name = s->glines[l].line[c].name;
2343 const uint16_t pos = s->glines[l].line[c].pos;
2344 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos) - 10;
2349 draw_vtext16(out, x, offset_y + 2, mult, o1, o2, name, green_yuva_color);
2352 offset_x += s->size * (s->display == STACK);
2353 offset_y += height * (s->display == PARADE);
2357 static void graticule_green_column(WaveformContext *s, AVFrame *out)
2359 const int step = (s->flags & 2) + 1;
2360 const float o1 = s->opacity;
2361 const float o2 = 1. - o1;
2362 const int width = s->display == PARADE ? out->width / s->acomp : out->width;
2363 int k = 0, c, p, l, offset_y = 0, offset_x = 0;
2365 for (c = 0; c < s->ncomp; c++) {
2366 if ((!((1 << c) & s->pcomp) || (!s->display && k > 0)))
2370 for (p = 0; p < s->ncomp; p++) {
2371 const int v = green_yuva_color[p];
2372 for (l = 0; l < s->nb_glines ; l++) {
2373 const uint16_t pos = s->glines[l].line[c].pos;
2374 int y = offset_y + (s->mirror ? s->size - 1 - pos : pos);
2375 uint8_t *dst = out->data[p] + y * out->linesize[p] + offset_x;
2377 blend_hline(dst, width, o1, o2, v, step);
2381 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2382 const char *name = s->glines[l].line[c].name;
2383 const uint16_t pos = s->glines[l].line[c].pos;
2384 int y = offset_y + (s->mirror ? s->size - 1 - pos : pos) - 10;
2389 draw_htext(out, 2 + offset_x, y, o1, o2, name, green_yuva_color);
2392 offset_y += s->size * (s->display == STACK);
2393 offset_x += width * (s->display == PARADE);
2397 static void graticule16_green_column(WaveformContext *s, AVFrame *out)
2399 const int step = (s->flags & 2) + 1;
2400 const float o1 = s->opacity;
2401 const float o2 = 1. - o1;
2402 const int mult = s->size / 256;
2403 const int width = s->display == PARADE ? out->width / s->acomp : out->width;
2404 int k = 0, c, p, l, offset_x = 0, offset_y = 0;
2406 for (c = 0; c < s->ncomp; c++) {
2407 if ((!((1 << c) & s->pcomp) || (!s->display && k > 0)))
2411 for (p = 0; p < s->ncomp; p++) {
2412 const int v = green_yuva_color[p] * mult;
2413 for (l = 0; l < s->nb_glines ; l++) {
2414 const uint16_t pos = s->glines[l].line[c].pos;
2415 int y = offset_y + (s->mirror ? s->size - 1 - pos : pos);
2416 uint16_t *dst = (uint16_t *)(out->data[p] + y * out->linesize[p]) + offset_x;
2418 blend_hline16(dst, width, o1, o2, v, step);
2422 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2423 const char *name = s->glines[l].line[c].name;
2424 const uint16_t pos = s->glines[l].line[c].pos;
2425 int y = offset_y + (s->mirror ? s->size - 1 - pos: pos) - 10;
2430 draw_htext16(out, 2 + offset_x, y, mult, o1, o2, name, green_yuva_color);
2433 offset_y += s->size * (s->display == STACK);
2434 offset_x += width * (s->display == PARADE);
2438 static int config_input(AVFilterLink *inlink)
2440 AVFilterContext *ctx = inlink->dst;
2441 WaveformContext *s = ctx->priv;
2443 s->desc = av_pix_fmt_desc_get(inlink->format);
2444 s->ncomp = s->desc->nb_components;
2445 s->bits = s->desc->comp[0].depth;
2446 s->max = 1 << s->bits;
2447 s->intensity = s->fintensity * (s->max - 1);
2449 s->shift_w[0] = s->shift_w[3] = 0;
2450 s->shift_h[0] = s->shift_h[3] = 0;
2451 s->shift_w[1] = s->shift_w[2] = s->desc->log2_chroma_w;
2452 s->shift_h[1] = s->shift_h[2] = s->desc->log2_chroma_h;
2454 s->graticulef = graticule_none;
2456 switch (s->filter) {
2457 case AFLAT: s->size = 256 * 2; break;
2458 case FLAT: s->size = 256 * 3; break;
2459 default: s->size = 256; break;
2462 switch (s->filter | ((s->bits > 8) << 4) |
2463 (s->mode << 8) | (s->mirror << 12)) {
2464 case 0x1100: s->waveform = lowpass_column_mirror; break;
2465 case 0x1000: s->waveform = lowpass_row_mirror; break;
2466 case 0x0100: s->waveform = lowpass_column; break;
2467 case 0x0000: s->waveform = lowpass_row; break;
2468 case 0x1110: s->waveform = lowpass16_column_mirror; break;
2469 case 0x1010: s->waveform = lowpass16_row_mirror; break;
2470 case 0x0110: s->waveform = lowpass16_column; break;
2471 case 0x0010: s->waveform = lowpass16_row; break;
2475 case 0x0001: s->waveform = flat; break;
2479 case 0x0011: s->waveform = flat16; break;
2483 case 0x0002: s->waveform = aflat; break;
2487 case 0x0012: s->waveform = aflat16; break;
2491 case 0x0003: s->waveform = chroma; break;
2495 case 0x0013: s->waveform = chroma16; break;
2499 case 0x0004: s->waveform = color; break;
2503 case 0x0014: s->waveform = color16; break;
2507 case 0x0005: s->waveform = acolor; break;
2511 case 0x0015: s->waveform = acolor16; break;
2514 switch (s->filter) {
2521 if (s->graticule && s->mode == 1)
2522 s->graticulef = s->bits > 8 ? graticule16_green_column : graticule_green_column;
2523 else if (s->graticule && s->mode == 0)
2524 s->graticulef = s->bits > 8 ? graticule16_green_row : graticule_green_row;
2528 switch (s->filter) {
2535 case 8: s->glines = (GraticuleLines *)digital8; s->nb_glines = FF_ARRAY_ELEMS(digital8); break;
2536 case 9: s->glines = (GraticuleLines *)digital9; s->nb_glines = FF_ARRAY_ELEMS(digital9); break;
2537 case 10: s->glines = (GraticuleLines *)digital10; s->nb_glines = FF_ARRAY_ELEMS(digital10); break;
2538 case 12: s->glines = (GraticuleLines *)digital12; s->nb_glines = FF_ARRAY_ELEMS(digital12); break;
2543 case 8: s->glines = (GraticuleLines *)millivolts8; s->nb_glines = FF_ARRAY_ELEMS(millivolts8); break;
2544 case 9: s->glines = (GraticuleLines *)millivolts9; s->nb_glines = FF_ARRAY_ELEMS(millivolts9); break;
2545 case 10: s->glines = (GraticuleLines *)millivolts10; s->nb_glines = FF_ARRAY_ELEMS(millivolts10); break;
2546 case 12: s->glines = (GraticuleLines *)millivolts12; s->nb_glines = FF_ARRAY_ELEMS(millivolts12); break;
2551 case 8: s->glines = (GraticuleLines *)ire8; s->nb_glines = FF_ARRAY_ELEMS(ire8); break;
2552 case 9: s->glines = (GraticuleLines *)ire9; s->nb_glines = FF_ARRAY_ELEMS(ire9); break;
2553 case 10: s->glines = (GraticuleLines *)ire10; s->nb_glines = FF_ARRAY_ELEMS(ire10); break;
2554 case 12: s->glines = (GraticuleLines *)ire12; s->nb_glines = FF_ARRAY_ELEMS(ire12); break;
2563 case 8: s->glines = (GraticuleLines *)chroma_digital8; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital8); break;
2564 case 9: s->glines = (GraticuleLines *)chroma_digital9; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital9); break;
2565 case 10: s->glines = (GraticuleLines *)chroma_digital10; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital10); break;
2566 case 12: s->glines = (GraticuleLines *)chroma_digital12; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital12); break;
2571 case 8: s->glines = (GraticuleLines *)millivolts8; s->nb_glines = FF_ARRAY_ELEMS(millivolts8); break;
2572 case 9: s->glines = (GraticuleLines *)millivolts9; s->nb_glines = FF_ARRAY_ELEMS(millivolts9); break;
2573 case 10: s->glines = (GraticuleLines *)millivolts10; s->nb_glines = FF_ARRAY_ELEMS(millivolts10); break;
2574 case 12: s->glines = (GraticuleLines *)millivolts12; s->nb_glines = FF_ARRAY_ELEMS(millivolts12); break;
2579 case 8: s->glines = (GraticuleLines *)ire8; s->nb_glines = FF_ARRAY_ELEMS(ire8); break;
2580 case 9: s->glines = (GraticuleLines *)ire9; s->nb_glines = FF_ARRAY_ELEMS(ire9); break;
2581 case 10: s->glines = (GraticuleLines *)ire10; s->nb_glines = FF_ARRAY_ELEMS(ire10); break;
2582 case 12: s->glines = (GraticuleLines *)ire12; s->nb_glines = FF_ARRAY_ELEMS(ire12); break;
2591 case 8: s->glines = (GraticuleLines *)aflat_digital8; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital8); break;
2592 case 9: s->glines = (GraticuleLines *)aflat_digital9; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital9); break;
2593 case 10: s->glines = (GraticuleLines *)aflat_digital10; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital10); break;
2594 case 12: s->glines = (GraticuleLines *)aflat_digital12; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital12); break;
2599 case 8: s->glines = (GraticuleLines *)aflat_millivolts8; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts8); break;
2600 case 9: s->glines = (GraticuleLines *)aflat_millivolts9; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts9); break;
2601 case 10: s->glines = (GraticuleLines *)aflat_millivolts10; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts10); break;
2602 case 12: s->glines = (GraticuleLines *)aflat_millivolts12; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts12); break;
2607 case 8: s->glines = (GraticuleLines *)aflat_ire8; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire8); break;
2608 case 9: s->glines = (GraticuleLines *)aflat_ire9; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire9); break;
2609 case 10: s->glines = (GraticuleLines *)aflat_ire10; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire10); break;
2610 case 12: s->glines = (GraticuleLines *)aflat_ire12; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire12); break;
2619 case 8: s->glines = (GraticuleLines *)flat_digital8; s->nb_glines = FF_ARRAY_ELEMS(flat_digital8); break;
2620 case 9: s->glines = (GraticuleLines *)flat_digital9; s->nb_glines = FF_ARRAY_ELEMS(flat_digital9); break;
2621 case 10: s->glines = (GraticuleLines *)flat_digital10; s->nb_glines = FF_ARRAY_ELEMS(flat_digital10); break;
2622 case 12: s->glines = (GraticuleLines *)flat_digital12; s->nb_glines = FF_ARRAY_ELEMS(flat_digital12); break;
2627 case 8: s->glines = (GraticuleLines *)flat_millivolts8; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts8); break;
2628 case 9: s->glines = (GraticuleLines *)flat_millivolts9; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts9); break;
2629 case 10: s->glines = (GraticuleLines *)flat_millivolts10; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts10); break;
2630 case 12: s->glines = (GraticuleLines *)flat_millivolts12; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts12); break;
2635 case 8: s->glines = (GraticuleLines *)flat_ire8; s->nb_glines = FF_ARRAY_ELEMS(flat_ire8); break;
2636 case 9: s->glines = (GraticuleLines *)flat_ire9; s->nb_glines = FF_ARRAY_ELEMS(flat_ire9); break;
2637 case 10: s->glines = (GraticuleLines *)flat_ire10; s->nb_glines = FF_ARRAY_ELEMS(flat_ire10); break;
2638 case 12: s->glines = (GraticuleLines *)flat_ire12; s->nb_glines = FF_ARRAY_ELEMS(flat_ire12); break;
2645 s->size = s->size << (s->bits - 8);
2647 switch (inlink->format) {
2648 case AV_PIX_FMT_GBRAP:
2649 case AV_PIX_FMT_GBRP:
2650 case AV_PIX_FMT_GBRP9:
2651 case AV_PIX_FMT_GBRP10:
2652 case AV_PIX_FMT_GBRP12:
2653 s->bg_color = black_gbrp_color;
2654 s->graticulef = graticule_none;
2657 s->bg_color = black_yuva_color;
2663 static int config_output(AVFilterLink *outlink)
2665 AVFilterContext *ctx = outlink->src;
2666 AVFilterLink *inlink = ctx->inputs[0];
2667 WaveformContext *s = ctx->priv;
2668 int comp = 0, i, j = 0, k, p, size;
2670 for (i = 0; i < s->ncomp; i++) {
2671 if ((1 << i) & s->pcomp)
2679 outlink->h = s->size * FFMAX(comp * (s->display == STACK), 1);
2680 outlink->w = inlink->w * FFMAX(comp * (s->display == PARADE), 1);
2683 outlink->w = s->size * FFMAX(comp * (s->display == STACK), 1);
2684 outlink->h = inlink->h * FFMAX(comp * (s->display == PARADE), 1);
2688 s->peak = av_malloc_array(size, 32 * sizeof(*s->peak));
2690 return AVERROR(ENOMEM);
2692 for (p = 0; p < s->ncomp; p++) {
2693 const int plane = s->desc->comp[p].plane;
2696 if (!((1 << p) & s->pcomp))
2699 for (k = 0; k < 4; k++) {
2700 s->emax[plane][k] = s->peak + size * (plane * 4 + k + 0);
2701 s->emin[plane][k] = s->peak + size * (plane * 4 + k + 16);
2704 offset = j++ * s->size * (s->display == STACK);
2705 s->estart[plane] = offset;
2706 s->eend[plane] = (offset + s->size - 1);
2707 for (i = 0; i < size; i++) {
2708 for (k = 0; k < 4; k++) {
2709 s->emax[plane][k][i] = s->estart[plane];
2710 s->emin[plane][k][i] = s->eend[plane];
2715 outlink->sample_aspect_ratio = (AVRational){1,1};
2720 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
2722 AVFilterContext *ctx = inlink->dst;
2723 WaveformContext *s = ctx->priv;
2724 AVFilterLink *outlink = ctx->outputs[0];
2728 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
2731 return AVERROR(ENOMEM);
2734 av_frame_set_color_range(out, AVCOL_RANGE_JPEG);
2736 for (k = 0; k < s->ncomp; k++) {
2738 for (i = 0; i < outlink->h ; i++)
2739 memset(out->data[s->desc->comp[k].plane] +
2740 i * out->linesize[s->desc->comp[k].plane],
2741 s->bg_color[k], outlink->w);
2743 const int mult = s->max / 256;
2744 uint16_t *dst = (uint16_t *)out->data[s->desc->comp[k].plane];
2746 for (i = 0; i < outlink->h ; i++) {
2747 for (j = 0; j < outlink->w; j++)
2748 dst[j] = s->bg_color[k] * mult;
2749 dst += out->linesize[s->desc->comp[k].plane] / 2;
2754 for (k = 0, i = 0; k < s->ncomp; k++) {
2755 if ((1 << k) & s->pcomp) {
2759 if (s->display == PARADE) {
2760 offset_x = s->mode ? i++ * inlink->w : 0;
2761 offset_y = s->mode ? 0 : i++ * inlink->h;
2763 offset_y = s->mode ? i++ * s->size * !!s->display : 0;
2764 offset_x = s->mode ? 0 : i++ * s->size * !!s->display;
2766 s->waveform(s, in, out, k, s->intensity, offset_y, offset_x, s->mode, s->mirror);
2769 s->graticulef(s, out);
2772 return ff_filter_frame(outlink, out);
2775 static av_cold void uninit(AVFilterContext *ctx)
2777 WaveformContext *s = ctx->priv;
2782 static const AVFilterPad inputs[] = {
2785 .type = AVMEDIA_TYPE_VIDEO,
2786 .filter_frame = filter_frame,
2787 .config_props = config_input,
2792 static const AVFilterPad outputs[] = {
2795 .type = AVMEDIA_TYPE_VIDEO,
2796 .config_props = config_output,
2801 AVFilter ff_vf_waveform = {
2803 .description = NULL_IF_CONFIG_SMALL("Video waveform monitor."),
2804 .priv_size = sizeof(WaveformContext),
2805 .priv_class = &waveform_class,
2806 .query_formats = query_formats,