2 * Copyright (c) 2012-2016 Paul B Mahol
3 * Copyright (c) 2013 Marton Balint
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "libavutil/avassert.h"
23 #include "libavutil/opt.h"
24 #include "libavutil/parseutils.h"
25 #include "libavutil/pixdesc.h"
26 #include "libavutil/xga_font_data.h"
56 typedef struct GraticuleLine {
61 typedef struct GraticuleLines {
62 struct GraticuleLine line[4];
65 typedef struct WaveformContext {
92 int shift_w[4], shift_h[4];
93 GraticuleLines *glines;
95 void (*waveform)(struct WaveformContext *s,
96 AVFrame *in, AVFrame *out,
97 int component, int intensity,
98 int offset_y, int offset_x,
99 int column, int mirror);
100 void (*graticulef)(struct WaveformContext *s, AVFrame *out);
101 const AVPixFmtDescriptor *desc;
102 const AVPixFmtDescriptor *odesc;
105 #define OFFSET(x) offsetof(WaveformContext, x)
106 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
108 static const AVOption waveform_options[] = {
109 { "mode", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "mode" },
110 { "m", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "mode" },
111 { "row", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "mode" },
112 { "column", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "mode" },
113 { "intensity", "set intensity", OFFSET(fintensity), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 1, FLAGS },
114 { "i", "set intensity", OFFSET(fintensity), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 1, FLAGS },
115 { "mirror", "set mirroring", OFFSET(mirror), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
116 { "r", "set mirroring", OFFSET(mirror), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
117 { "display", "set display mode", OFFSET(display), AV_OPT_TYPE_INT, {.i64=STACK}, 0, NB_DISPLAYS-1, FLAGS, "display" },
118 { "d", "set display mode", OFFSET(display), AV_OPT_TYPE_INT, {.i64=STACK}, 0, NB_DISPLAYS-1, FLAGS, "display" },
119 { "overlay", NULL, 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY}, 0, 0, FLAGS, "display" },
120 { "stack", NULL, 0, AV_OPT_TYPE_CONST, {.i64=STACK}, 0, 0, FLAGS, "display" },
121 { "parade", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PARADE}, 0, 0, FLAGS, "display" },
122 { "components", "set components to display", OFFSET(pcomp), AV_OPT_TYPE_INT, {.i64=1}, 1, 15, FLAGS },
123 { "c", "set components to display", OFFSET(pcomp), AV_OPT_TYPE_INT, {.i64=1}, 1, 15, FLAGS },
124 { "envelope", "set envelope to display", OFFSET(envelope), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "envelope" },
125 { "e", "set envelope to display", OFFSET(envelope), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "envelope" },
126 { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "envelope" },
127 { "instant", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "envelope" },
128 { "peak", NULL, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "envelope" },
129 { "peak+instant", NULL, 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, FLAGS, "envelope" },
130 { "filter", "set filter", OFFSET(filter), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_FILTERS-1, FLAGS, "filter" },
131 { "f", "set filter", OFFSET(filter), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_FILTERS-1, FLAGS, "filter" },
132 { "lowpass", NULL, 0, AV_OPT_TYPE_CONST, {.i64=LOWPASS}, 0, 0, FLAGS, "filter" },
133 { "flat" , NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAT}, 0, 0, FLAGS, "filter" },
134 { "aflat" , NULL, 0, AV_OPT_TYPE_CONST, {.i64=AFLAT}, 0, 0, FLAGS, "filter" },
135 { "chroma", NULL, 0, AV_OPT_TYPE_CONST, {.i64=CHROMA}, 0, 0, FLAGS, "filter" },
136 { "color", NULL, 0, AV_OPT_TYPE_CONST, {.i64=COLOR}, 0, 0, FLAGS, "filter" },
137 { "acolor", NULL, 0, AV_OPT_TYPE_CONST, {.i64=ACOLOR}, 0, 0, FLAGS, "filter" },
138 { "graticule", "set graticule", OFFSET(graticule), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "graticule" },
139 { "g", "set graticule", OFFSET(graticule), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "graticule" },
140 { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "graticule" },
141 { "green", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "graticule" },
142 { "opacity", "set graticule opacity", OFFSET(opacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
143 { "o", "set graticule opacity", OFFSET(opacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
144 { "flags", "set graticule flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64=1}, 0, 3, FLAGS, "flags" },
145 { "fl", "set graticule flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64=1}, 0, 3, FLAGS, "flags" },
146 { "numbers", "draw numbers", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "flags" },
147 { "dots", "draw dots instead of lines", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "flags" },
148 { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SCALES-1, FLAGS, "scale" },
149 { "s", "set scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SCALES-1, FLAGS, "scale" },
150 { "digital", NULL, 0, AV_OPT_TYPE_CONST, {.i64=DIGITAL}, 0, 0, FLAGS, "scale" },
151 { "millivolts", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MILLIVOLTS}, 0, 0, FLAGS, "scale" },
152 { "ire", NULL, 0, AV_OPT_TYPE_CONST, {.i64=IRE}, 0, 0, FLAGS, "scale" },
153 { "bgopacity", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
154 { "b", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
158 AVFILTER_DEFINE_CLASS(waveform);
160 static const enum AVPixelFormat in_lowpass_pix_fmts[] = {
161 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
162 AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12,
163 AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
164 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
165 AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P,
166 AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
167 AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
168 AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
169 AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY9, AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12,
170 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9,
171 AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9,
172 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10,
173 AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10,
174 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV440P12,
178 static const enum AVPixelFormat in_color_pix_fmts[] = {
179 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
180 AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12,
181 AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
182 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
184 AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
185 AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
186 AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
187 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9,
188 AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9,
189 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10,
190 AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10,
191 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV440P12,
195 static const enum AVPixelFormat in_flat_pix_fmts[] = {
196 AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
197 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
199 AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
200 AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
201 AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
202 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9,
203 AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9,
204 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10,
205 AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10,
206 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV440P12,
210 static const enum AVPixelFormat out_rgb8_lowpass_pix_fmts[] = {
211 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
215 static const enum AVPixelFormat out_rgb9_lowpass_pix_fmts[] = {
220 static const enum AVPixelFormat out_rgb10_lowpass_pix_fmts[] = {
221 AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10,
225 static const enum AVPixelFormat out_rgb12_lowpass_pix_fmts[] = {
226 AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12,
230 static const enum AVPixelFormat out_yuv8_lowpass_pix_fmts[] = {
231 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVA444P,
235 static const enum AVPixelFormat out_yuv9_lowpass_pix_fmts[] = {
236 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUVA444P9,
240 static const enum AVPixelFormat out_yuv10_lowpass_pix_fmts[] = {
241 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUVA444P10,
245 static const enum AVPixelFormat out_yuv12_lowpass_pix_fmts[] = {
246 AV_PIX_FMT_YUV444P12,
250 static const enum AVPixelFormat out_gray8_lowpass_pix_fmts[] = {
255 static const enum AVPixelFormat out_gray9_lowpass_pix_fmts[] = {
260 static const enum AVPixelFormat out_gray10_lowpass_pix_fmts[] = {
265 static const enum AVPixelFormat out_gray12_lowpass_pix_fmts[] = {
270 static const enum AVPixelFormat flat_pix_fmts[] = {
271 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P,
272 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV444P10,
273 AV_PIX_FMT_YUV444P12,
277 static int query_formats(AVFilterContext *ctx)
279 WaveformContext *s = ctx->priv;
280 const enum AVPixelFormat *out_pix_fmts;
281 const enum AVPixelFormat *in_pix_fmts;
282 const AVPixFmtDescriptor *desc;
283 AVFilterFormats *avff;
284 int depth, rgb, i, ret, ncomp;
286 if (!ctx->inputs[0]->in_formats ||
287 !ctx->inputs[0]->in_formats->nb_formats) {
288 return AVERROR(EAGAIN);
292 case LOWPASS: in_pix_fmts = in_lowpass_pix_fmts; break;
295 case FLAT: in_pix_fmts = in_flat_pix_fmts; break;
297 case COLOR: in_pix_fmts = in_color_pix_fmts; break;
298 default: return AVERROR_BUG;
301 if (!ctx->inputs[0]->out_formats) {
302 if ((ret = ff_formats_ref(ff_make_format_list(in_pix_fmts), &ctx->inputs[0]->out_formats)) < 0)
306 avff = ctx->inputs[0]->in_formats;
307 desc = av_pix_fmt_desc_get(avff->formats[0]);
308 ncomp = desc->nb_components;
309 rgb = desc->flags & AV_PIX_FMT_FLAG_RGB;
310 depth = desc->comp[0].depth;
311 for (i = 1; i < avff->nb_formats; i++) {
312 desc = av_pix_fmt_desc_get(avff->formats[i]);
313 if (rgb != (desc->flags & AV_PIX_FMT_FLAG_RGB) ||
314 depth != desc->comp[0].depth)
315 return AVERROR(EAGAIN);
318 if (s->filter == LOWPASS && ncomp == 1 && depth == 8)
319 out_pix_fmts = out_gray8_lowpass_pix_fmts;
320 else if (s->filter == LOWPASS && ncomp == 1 && depth == 9)
321 out_pix_fmts = out_gray9_lowpass_pix_fmts;
322 else if (s->filter == LOWPASS && ncomp == 1 && depth == 10)
323 out_pix_fmts = out_gray10_lowpass_pix_fmts;
324 else if (s->filter == LOWPASS && ncomp == 1 && depth == 12)
325 out_pix_fmts = out_gray12_lowpass_pix_fmts;
326 else if (rgb && depth == 8 && ncomp > 2)
327 out_pix_fmts = out_rgb8_lowpass_pix_fmts;
328 else if (rgb && depth == 9 && ncomp > 2)
329 out_pix_fmts = out_rgb9_lowpass_pix_fmts;
330 else if (rgb && depth == 10 && ncomp > 2)
331 out_pix_fmts = out_rgb10_lowpass_pix_fmts;
332 else if (rgb && depth == 12 && ncomp > 2)
333 out_pix_fmts = out_rgb12_lowpass_pix_fmts;
334 else if (depth == 8 && ncomp > 2)
335 out_pix_fmts = out_yuv8_lowpass_pix_fmts;
336 else if (depth == 9 && ncomp > 2)
337 out_pix_fmts = out_yuv9_lowpass_pix_fmts;
338 else if (depth == 10 && ncomp > 2)
339 out_pix_fmts = out_yuv10_lowpass_pix_fmts;
340 else if (depth == 12 && ncomp > 2)
341 out_pix_fmts = out_yuv12_lowpass_pix_fmts;
343 return AVERROR(EAGAIN);
344 if ((ret = ff_formats_ref(ff_make_format_list(out_pix_fmts), &ctx->outputs[0]->in_formats)) < 0)
350 static void envelope_instant16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
352 const int dst_linesize = out->linesize[component] / 2;
353 const int bg = s->bg_color[component] * (s->max / 256);
354 const int limit = s->max - 1;
355 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
356 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
357 const int start = s->estart[plane];
358 const int end = s->eend[plane];
363 for (x = offset; x < offset + dst_w; x++) {
364 for (y = start; y < end; y++) {
365 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
371 for (y = end - 1; y >= start; y--) {
372 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
380 for (y = offset; y < offset + dst_h; y++) {
381 dst = (uint16_t *)out->data[component] + y * dst_linesize;
382 for (x = start; x < end; x++) {
388 for (x = end - 1; x >= start; x--) {
398 static void envelope_instant(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
400 const int dst_linesize = out->linesize[component];
401 const uint8_t bg = s->bg_color[component];
402 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
403 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
404 const int start = s->estart[plane];
405 const int end = s->eend[plane];
410 for (x = offset; x < offset + dst_w; x++) {
411 for (y = start; y < end; y++) {
412 dst = out->data[component] + y * dst_linesize + x;
418 for (y = end - 1; y >= start; y--) {
419 dst = out->data[component] + y * dst_linesize + x;
427 for (y = offset; y < offset + dst_h; y++) {
428 dst = out->data[component] + y * dst_linesize;
429 for (x = start; x < end; x++) {
435 for (x = end - 1; x >= start; x--) {
445 static void envelope_peak16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
447 const int dst_linesize = out->linesize[component] / 2;
448 const int bg = s->bg_color[component] * (s->max / 256);
449 const int limit = s->max - 1;
450 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
451 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
452 const int start = s->estart[plane];
453 const int end = s->eend[plane];
454 int *emax = s->emax[plane][component];
455 int *emin = s->emin[plane][component];
460 for (x = offset; x < offset + dst_w; x++) {
461 for (y = start; y < end && y < emin[x - offset]; y++) {
462 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
464 emin[x - offset] = y;
468 for (y = end - 1; y >= start && y >= emax[x - offset]; y--) {
469 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
471 emax[x - offset] = y;
477 if (s->envelope == 3)
478 envelope_instant16(s, out, plane, component, offset);
480 for (x = offset; x < offset + dst_w; x++) {
481 dst = (uint16_t *)out->data[component] + emin[x - offset] * dst_linesize + x;
483 dst = (uint16_t *)out->data[component] + emax[x - offset] * dst_linesize + x;
487 for (y = offset; y < offset + dst_h; y++) {
488 dst = (uint16_t *)out->data[component] + y * dst_linesize;
489 for (x = start; x < end && x < emin[y - offset]; x++) {
491 emin[y - offset] = x;
495 for (x = end - 1; x >= start && x >= emax[y - offset]; x--) {
497 emax[y - offset] = x;
503 if (s->envelope == 3)
504 envelope_instant16(s, out, plane, component, offset);
506 for (y = offset; y < offset + dst_h; y++) {
507 dst = (uint16_t *)out->data[component] + y * dst_linesize + emin[y - offset];
509 dst = (uint16_t *)out->data[component] + y * dst_linesize + emax[y - offset];
515 static void envelope_peak(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
517 const int dst_linesize = out->linesize[component];
518 const int bg = s->bg_color[component];
519 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
520 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
521 const int start = s->estart[plane];
522 const int end = s->eend[plane];
523 int *emax = s->emax[plane][component];
524 int *emin = s->emin[plane][component];
529 for (x = offset; x < offset + dst_w; x++) {
530 for (y = start; y < end && y < emin[x - offset]; y++) {
531 dst = out->data[component] + y * dst_linesize + x;
533 emin[x - offset] = y;
537 for (y = end - 1; y >= start && y >= emax[x - offset]; y--) {
538 dst = out->data[component] + y * dst_linesize + x;
540 emax[x - offset] = y;
546 if (s->envelope == 3)
547 envelope_instant(s, out, plane, component, offset);
549 for (x = offset; x < offset + dst_w; x++) {
550 dst = out->data[component] + emin[x - offset] * dst_linesize + x;
552 dst = out->data[component] + emax[x - offset] * dst_linesize + x;
556 for (y = offset; y < offset + dst_h; y++) {
557 dst = out->data[component] + y * dst_linesize;
558 for (x = start; x < end && x < emin[y - offset]; x++) {
560 emin[y - offset] = x;
564 for (x = end - 1; x >= start && x >= emax[y - offset]; x--) {
566 emax[y - offset] = x;
572 if (s->envelope == 3)
573 envelope_instant(s, out, plane, component, offset);
575 for (y = offset; y < offset + dst_h; y++) {
576 dst = out->data[component] + y * dst_linesize + emin[y - offset];
578 dst = out->data[component] + y * dst_linesize + emax[y - offset];
584 static void envelope16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
586 if (s->envelope == 0) {
588 } else if (s->envelope == 1) {
589 envelope_instant16(s, out, plane, component, offset);
591 envelope_peak16(s, out, plane, component, offset);
595 static void envelope(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
597 if (s->envelope == 0) {
599 } else if (s->envelope == 1) {
600 envelope_instant(s, out, plane, component, offset);
602 envelope_peak(s, out, plane, component, offset);
606 static void update16(uint16_t *target, int max, int intensity, int limit)
609 *target += intensity;
614 static void update(uint8_t *target, int max, int intensity)
617 *target += intensity;
622 static av_always_inline void lowpass16(WaveformContext *s,
623 AVFrame *in, AVFrame *out,
624 int component, int intensity,
625 int offset_y, int offset_x,
626 int column, int mirror)
628 const int plane = s->desc->comp[component].plane;
629 const int shift_w = s->shift_w[component];
630 const int shift_h = s->shift_h[component];
631 const int src_linesize = in->linesize[plane] / 2;
632 const int dst_linesize = out->linesize[plane] / 2;
633 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
634 const int limit = s->max - 1;
635 const int max = limit - intensity;
636 const int src_h = AV_CEIL_RSHIFT(in->height, shift_h);
637 const int src_w = AV_CEIL_RSHIFT(in->width, shift_w);
638 const uint16_t *src_data = (const uint16_t *)in->data[plane];
639 uint16_t *dst_data = (uint16_t *)out->data[plane] + offset_y * dst_linesize + offset_x;
640 uint16_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
641 uint16_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
642 const int step = column ? 1 << shift_w : 1 << shift_h;
646 if (!column && mirror)
649 for (y = 0; y < src_h; y++) {
650 const uint16_t *src_data_end = src_data + src_w;
651 uint16_t *dst = dst_line;
653 for (p = src_data; p < src_data_end; p++) {
655 int i = 0, v = FFMIN(*p, limit);
659 target = dst++ + dst_signed_linesize * v;
660 update16(target, max, intensity, limit);
661 } while (++i < step);
663 uint16_t *row = dst_data;
666 target = row - v - 1;
669 update16(target, max, intensity, limit);
671 } while (++i < step);
674 src_data += src_linesize;
675 dst_data += dst_linesize * step;
678 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
681 #define LOWPASS16_FUNC(name, column, mirror) \
682 static void lowpass16_##name(WaveformContext *s, \
683 AVFrame *in, AVFrame *out, \
684 int component, int intensity, \
685 int offset_y, int offset_x, \
686 int unused1, int unused2) \
688 lowpass16(s, in, out, component, intensity, \
689 offset_y, offset_x, column, mirror); \
692 LOWPASS16_FUNC(column_mirror, 1, 1)
693 LOWPASS16_FUNC(column, 1, 0)
694 LOWPASS16_FUNC(row_mirror, 0, 1)
695 LOWPASS16_FUNC(row, 0, 0)
697 static av_always_inline void lowpass(WaveformContext *s,
698 AVFrame *in, AVFrame *out,
699 int component, int intensity,
700 int offset_y, int offset_x,
701 int column, int mirror)
703 const int plane = s->desc->comp[component].plane;
704 const int shift_w = s->shift_w[component];
705 const int shift_h = s->shift_h[component];
706 const int src_linesize = in->linesize[plane];
707 const int dst_linesize = out->linesize[plane];
708 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
709 const int max = 255 - intensity;
710 const int src_h = AV_CEIL_RSHIFT(in->height, shift_h);
711 const int src_w = AV_CEIL_RSHIFT(in->width, shift_w);
712 const uint8_t *src_data = in->data[plane];
713 uint8_t *dst_data = out->data[plane] + offset_y * dst_linesize + offset_x;
714 uint8_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
715 uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
716 const int step = column ? 1 << shift_w : 1 << shift_h;
720 if (!column && mirror)
723 for (y = 0; y < src_h; y++) {
724 const uint8_t *src_data_end = src_data + src_w;
725 uint8_t *dst = dst_line;
727 for (p = src_data; p < src_data_end; p++) {
730 target = dst + dst_signed_linesize * *p;
732 update(target, max, intensity);
734 uint8_t *row = dst_data;
736 target = row - *p - 1;
739 update(target, max, intensity);
743 src_data += src_linesize;
744 dst_data += dst_linesize * step;
747 if (column && step > 1) {
748 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
749 const int dst_h = 256;
753 dst = out->data[plane] + offset_y * dst_linesize + offset_x;
754 for (y = 0; y < dst_h; y++) {
755 for (x = 0; x < dst_w; x+=step) {
756 for (z = 1; z < step; z++) {
762 } else if (step > 1) {
763 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
764 const int dst_w = 256;
768 dst = out->data[plane] + offset_y * dst_linesize + offset_x;
769 for (y = 0; y < dst_h; y+=step) {
770 for (z = 1; z < step; z++)
771 memcpy(dst + dst_linesize * z, dst, dst_w);
772 dst += dst_linesize * step;
776 envelope(s, out, plane, plane, column ? offset_x : offset_y);
779 #define LOWPASS_FUNC(name, column, mirror) \
780 static void lowpass_##name(WaveformContext *s, \
781 AVFrame *in, AVFrame *out, \
782 int component, int intensity, \
783 int offset_y, int offset_x, \
784 int unused1, int unused2) \
786 lowpass(s, in, out, component, intensity, \
787 offset_y, offset_x, column, mirror); \
790 LOWPASS_FUNC(column_mirror, 1, 1)
791 LOWPASS_FUNC(column, 1, 0)
792 LOWPASS_FUNC(row_mirror, 0, 1)
793 LOWPASS_FUNC(row, 0, 0)
795 static av_always_inline void flat16(WaveformContext *s,
796 AVFrame *in, AVFrame *out,
797 int component, int intensity,
798 int offset_y, int offset_x,
799 int column, int mirror)
801 const int plane = s->desc->comp[component].plane;
802 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
803 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
804 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
805 const int c0_shift_w = s->shift_w[ component + 0 ];
806 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
807 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
808 const int c0_shift_h = s->shift_h[ component + 0 ];
809 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
810 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
811 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
812 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
813 const int limit = s->max - 1;
814 const int max = limit - intensity;
815 const int mid = s->max / 2;
816 const int src_h = in->height;
817 const int src_w = in->width;
821 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
822 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
824 for (x = 0; x < src_w; x++) {
825 const uint16_t *c0_data = (uint16_t *)in->data[plane + 0];
826 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
827 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
828 uint16_t *d0_data = (uint16_t *)(out->data[plane]) + offset_y * d0_linesize + offset_x;
829 uint16_t *d1_data = (uint16_t *)(out->data[(plane + 1) % s->ncomp]) + offset_y * d1_linesize + offset_x;
830 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
831 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
832 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
833 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
835 for (y = 0; y < src_h; y++) {
836 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + s->max;
837 const int c1 = FFMIN(FFABS(c1_data[x >> c1_shift_w] - mid) + FFABS(c2_data[x >> c2_shift_w] - mid), limit);
840 target = d0 + x + d0_signed_linesize * c0;
841 update16(target, max, intensity, limit);
842 target = d1 + x + d1_signed_linesize * (c0 - c1);
843 update16(target, max, intensity, limit);
844 target = d1 + x + d1_signed_linesize * (c0 + c1);
845 update16(target, max, intensity, limit);
847 if (!c0_shift_h || (y & c0_shift_h))
848 c0_data += c0_linesize;
849 if (!c1_shift_h || (y & c1_shift_h))
850 c1_data += c1_linesize;
851 if (!c2_shift_h || (y & c2_shift_h))
852 c2_data += c2_linesize;
853 d0_data += d0_linesize;
854 d1_data += d1_linesize;
858 const uint16_t *c0_data = (uint16_t *)in->data[plane];
859 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
860 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
861 uint16_t *d0_data = (uint16_t *)(out->data[plane]) + offset_y * d0_linesize + offset_x;
862 uint16_t *d1_data = (uint16_t *)(out->data[(plane + 1) % s->ncomp]) + offset_y * d1_linesize + offset_x;
865 d0_data += s->size - 1;
866 d1_data += s->size - 1;
869 for (y = 0; y < src_h; y++) {
870 for (x = 0; x < src_w; x++) {
871 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + s->max;
872 const int c1 = FFMIN(FFABS(c1_data[x >> c1_shift_w] - mid) + FFABS(c2_data[x >> c2_shift_w] - mid), limit);
876 target = d0_data - c0;
877 update16(target, max, intensity, limit);
878 target = d1_data - (c0 - c1);
879 update16(target, max, intensity, limit);
880 target = d1_data - (c0 + c1);
881 update16(target, max, intensity, limit);
883 target = d0_data + c0;
884 update16(target, max, intensity, limit);
885 target = d1_data + (c0 - c1);
886 update16(target, max, intensity, limit);
887 target = d1_data + (c0 + c1);
888 update16(target, max, intensity, limit);
892 if (!c0_shift_h || (y & c0_shift_h))
893 c0_data += c0_linesize;
894 if (!c1_shift_h || (y & c1_shift_h))
895 c1_data += c1_linesize;
896 if (!c2_shift_h || (y & c2_shift_h))
897 c2_data += c2_linesize;
898 d0_data += d0_linesize;
899 d1_data += d1_linesize;
903 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
904 envelope16(s, out, plane, (plane + 1) % s->ncomp, column ? offset_x : offset_y);
907 static av_always_inline void flat(WaveformContext *s,
908 AVFrame *in, AVFrame *out,
909 int component, int intensity,
910 int offset_y, int offset_x,
911 int column, int mirror)
913 const int plane = s->desc->comp[component].plane;
914 const int c0_linesize = in->linesize[ plane + 0 ];
915 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
916 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
917 const int c0_shift_w = s->shift_w[ component + 0 ];
918 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
919 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
920 const int c0_shift_h = s->shift_h[ component + 0 ];
921 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
922 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
923 const int d0_linesize = out->linesize[ plane + 0 ];
924 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
925 const int max = 255 - intensity;
926 const int src_h = in->height;
927 const int src_w = in->width;
931 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
932 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
934 for (x = 0; x < src_w; x++) {
935 const uint8_t *c0_data = in->data[plane + 0];
936 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
937 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
938 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
939 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
940 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
941 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
942 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
943 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
945 for (y = 0; y < src_h; y++) {
946 const int c0 = c0_data[x >> c0_shift_w] + 256;
947 const int c1 = FFABS(c1_data[x >> c1_shift_w] - 128) + FFABS(c2_data[x >> c2_shift_w] - 128);
950 target = d0 + x + d0_signed_linesize * c0;
951 update(target, max, intensity);
952 target = d1 + x + d1_signed_linesize * (c0 - c1);
953 update(target, max, intensity);
954 target = d1 + x + d1_signed_linesize * (c0 + c1);
955 update(target, max, intensity);
957 if (!c0_shift_h || (y & c0_shift_h))
958 c0_data += c0_linesize;
959 if (!c1_shift_h || (y & c1_shift_h))
960 c1_data += c1_linesize;
961 if (!c2_shift_h || (y & c2_shift_h))
962 c2_data += c2_linesize;
963 d0_data += d0_linesize;
964 d1_data += d1_linesize;
968 const uint8_t *c0_data = in->data[plane];
969 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
970 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
971 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
972 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
975 d0_data += s->size - 1;
976 d1_data += s->size - 1;
979 for (y = 0; y < src_h; y++) {
980 for (x = 0; x < src_w; x++) {
981 int c0 = c0_data[x >> c0_shift_w] + 256;
982 const int c1 = FFABS(c1_data[x >> c1_shift_w] - 128) + FFABS(c2_data[x >> c2_shift_w] - 128);
986 target = d0_data - c0;
987 update(target, max, intensity);
988 target = d1_data - (c0 - c1);
989 update(target, max, intensity);
990 target = d1_data - (c0 + c1);
991 update(target, max, intensity);
993 target = d0_data + c0;
994 update(target, max, intensity);
995 target = d1_data + (c0 - c1);
996 update(target, max, intensity);
997 target = d1_data + (c0 + c1);
998 update(target, max, intensity);
1002 if (!c0_shift_h || (y & c0_shift_h))
1003 c0_data += c0_linesize;
1004 if (!c1_shift_h || (y & c1_shift_h))
1005 c1_data += c1_linesize;
1006 if (!c2_shift_h || (y & c2_shift_h))
1007 c2_data += c2_linesize;
1008 d0_data += d0_linesize;
1009 d1_data += d1_linesize;
1013 envelope(s, out, plane, plane, column ? offset_x : offset_y);
1014 envelope(s, out, plane, (plane + 1) % s->ncomp, column ? offset_x : offset_y);
1017 static av_always_inline void aflat16(WaveformContext *s,
1018 AVFrame *in, AVFrame *out,
1019 int component, int intensity,
1020 int offset_y, int offset_x,
1021 int column, int mirror)
1023 const int plane = s->desc->comp[component].plane;
1024 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
1025 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1026 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1027 const int c0_shift_w = s->shift_w[ component + 0 ];
1028 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1029 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1030 const int c0_shift_h = s->shift_h[ component + 0 ];
1031 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1032 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1033 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
1034 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
1035 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2;
1036 const int limit = s->max - 1;
1037 const int max = limit - intensity;
1038 const int mid = s->max / 2;
1039 const int src_h = in->height;
1040 const int src_w = in->width;
1044 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1045 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1046 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1048 for (x = 0; x < src_w; x++) {
1049 const uint16_t *c0_data = (uint16_t *)in->data[plane + 0];
1050 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1051 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1052 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1053 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1054 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1055 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1056 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1057 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1058 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1059 uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1060 uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1062 for (y = 0; y < src_h; y++) {
1063 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + mid;
1064 const int c1 = FFMIN(c1_data[x >> c1_shift_w], limit) - mid;
1065 const int c2 = FFMIN(c2_data[x >> c2_shift_w], limit) - mid;
1068 target = d0 + x + d0_signed_linesize * c0;
1069 update16(target, max, intensity, limit);
1071 target = d1 + x + d1_signed_linesize * (c0 + c1);
1072 update16(target, max, intensity, limit);
1074 target = d2 + x + d2_signed_linesize * (c0 + c2);
1075 update16(target, max, intensity, limit);
1077 if (!c0_shift_h || (y & c0_shift_h))
1078 c0_data += c0_linesize;
1079 if (!c1_shift_h || (y & c1_shift_h))
1080 c1_data += c1_linesize;
1081 if (!c2_shift_h || (y & c2_shift_h))
1082 c2_data += c2_linesize;
1083 d0_data += d0_linesize;
1084 d1_data += d1_linesize;
1085 d2_data += d2_linesize;
1089 const uint16_t *c0_data = (uint16_t *)in->data[plane];
1090 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1091 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1092 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1093 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1094 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1097 d0_data += s->size - 1;
1098 d1_data += s->size - 1;
1099 d2_data += s->size - 1;
1102 for (y = 0; y < src_h; y++) {
1103 for (x = 0; x < src_w; x++) {
1104 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + mid;
1105 const int c1 = FFMIN(c1_data[x >> c1_shift_w], limit) - mid;
1106 const int c2 = FFMIN(c2_data[x >> c2_shift_w], limit) - mid;
1110 target = d0_data - c0;
1111 update16(target, max, intensity, limit);
1112 target = d1_data - (c0 + c1);
1113 update16(target, max, intensity, limit);
1114 target = d2_data - (c0 + c2);
1115 update16(target, max, intensity, limit);
1117 target = d0_data + c0;
1118 update16(target, max, intensity, limit);
1119 target = d1_data + (c0 + c1);
1120 update16(target, max, intensity, limit);
1121 target = d2_data + (c0 + c2);
1122 update16(target, max, intensity, limit);
1126 if (!c0_shift_h || (y & c0_shift_h))
1127 c0_data += c0_linesize;
1128 if (!c1_shift_h || (y & c1_shift_h))
1129 c1_data += c1_linesize;
1130 if (!c2_shift_h || (y & c2_shift_h))
1131 c2_data += c2_linesize;
1132 d0_data += d0_linesize;
1133 d1_data += d1_linesize;
1134 d2_data += d2_linesize;
1138 envelope16(s, out, plane, (plane + 0) % s->ncomp, column ? offset_x : offset_y);
1139 envelope16(s, out, plane, (plane + 1) % s->ncomp, column ? offset_x : offset_y);
1140 envelope16(s, out, plane, (plane + 2) % s->ncomp, column ? offset_x : offset_y);
1143 static av_always_inline void aflat(WaveformContext *s,
1144 AVFrame *in, AVFrame *out,
1145 int component, int intensity,
1146 int offset_y, int offset_x,
1147 int column, int mirror)
1149 const int plane = s->desc->comp[component].plane;
1150 const int c0_linesize = in->linesize[ plane + 0 ];
1151 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
1152 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
1153 const int c0_shift_w = s->shift_w[ component + 0 ];
1154 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1155 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1156 const int c0_shift_h = s->shift_h[ component + 0 ];
1157 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1158 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1159 const int d0_linesize = out->linesize[ plane + 0 ];
1160 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
1161 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp];
1162 const int max = 255 - intensity;
1163 const int src_h = in->height;
1164 const int src_w = in->width;
1168 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1169 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1170 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1172 for (x = 0; x < src_w; x++) {
1173 const uint8_t *c0_data = in->data[plane + 0];
1174 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1175 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1176 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1177 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1178 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1179 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1180 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1181 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1182 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1183 uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1184 uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1186 for (y = 0; y < src_h; y++) {
1187 const int c0 = c0_data[x >> c0_shift_w] + 128;
1188 const int c1 = c1_data[x >> c1_shift_w] - 128;
1189 const int c2 = c2_data[x >> c2_shift_w] - 128;
1192 target = d0 + x + d0_signed_linesize * c0;
1193 update(target, max, intensity);
1195 target = d1 + x + d1_signed_linesize * (c0 + c1);
1196 update(target, max, intensity);
1198 target = d2 + x + d2_signed_linesize * (c0 + c2);
1199 update(target, max, intensity);
1201 if (!c0_shift_h || (y & c0_shift_h))
1202 c0_data += c0_linesize;
1203 if (!c1_shift_h || (y & c1_shift_h))
1204 c1_data += c1_linesize;
1205 if (!c1_shift_h || (y & c1_shift_h))
1206 c2_data += c1_linesize;
1207 d0_data += d0_linesize;
1208 d1_data += d1_linesize;
1209 d2_data += d2_linesize;
1213 const uint8_t *c0_data = in->data[plane];
1214 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1215 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1216 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1217 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1218 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1221 d0_data += s->size - 1;
1222 d1_data += s->size - 1;
1223 d2_data += s->size - 1;
1226 for (y = 0; y < src_h; y++) {
1227 for (x = 0; x < src_w; x++) {
1228 const int c0 = c0_data[x >> c0_shift_w] + 128;
1229 const int c1 = c1_data[x >> c1_shift_w] - 128;
1230 const int c2 = c2_data[x >> c2_shift_w] - 128;
1234 target = d0_data - c0;
1235 update(target, max, intensity);
1236 target = d1_data - (c0 + c1);
1237 update(target, max, intensity);
1238 target = d2_data - (c0 + c2);
1239 update(target, max, intensity);
1241 target = d0_data + c0;
1242 update(target, max, intensity);
1243 target = d1_data + (c0 + c1);
1244 update(target, max, intensity);
1245 target = d2_data + (c0 + c2);
1246 update(target, max, intensity);
1250 if (!c0_shift_h || (y & c0_shift_h))
1251 c0_data += c0_linesize;
1252 if (!c1_shift_h || (y & c1_shift_h))
1253 c1_data += c1_linesize;
1254 if (!c2_shift_h || (y & c2_shift_h))
1255 c2_data += c2_linesize;
1256 d0_data += d0_linesize;
1257 d1_data += d1_linesize;
1258 d2_data += d2_linesize;
1262 envelope(s, out, plane, (plane + 0) % s->ncomp, column ? offset_x : offset_y);
1263 envelope(s, out, plane, (plane + 1) % s->ncomp, column ? offset_x : offset_y);
1264 envelope(s, out, plane, (plane + 2) % s->ncomp, column ? offset_x : offset_y);
1267 static av_always_inline void chroma16(WaveformContext *s,
1268 AVFrame *in, AVFrame *out,
1269 int component, int intensity,
1270 int offset_y, int offset_x,
1271 int column, int mirror)
1273 const int plane = s->desc->comp[component].plane;
1274 const int c0_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1275 const int c1_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1276 const int dst_linesize = out->linesize[plane] / 2;
1277 const int limit = s->max - 1;
1278 const int max = limit - intensity;
1279 const int mid = s->max / 2;
1280 const int c0_shift_w = s->shift_w[(component + 1) % s->ncomp];
1281 const int c1_shift_w = s->shift_w[(component + 2) % s->ncomp];
1282 const int c0_shift_h = s->shift_h[(component + 1) % s->ncomp];
1283 const int c1_shift_h = s->shift_h[(component + 2) % s->ncomp];
1284 const int src_h = in->height;
1285 const int src_w = in->width;
1289 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
1291 for (x = 0; x < src_w; x++) {
1292 const uint16_t *c0_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1293 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1294 uint16_t *dst_data = (uint16_t *)out->data[plane] + offset_y * dst_linesize + offset_x;
1295 uint16_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
1296 uint16_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
1297 uint16_t *dst = dst_line;
1299 for (y = 0; y < src_h; y++) {
1300 const int sum = FFMIN(FFABS(c0_data[x >> c0_shift_w] - mid) + FFABS(c1_data[x >> c1_shift_w] - mid - 1), limit);
1303 target = dst + x + dst_signed_linesize * sum;
1304 update16(target, max, intensity, limit);
1306 if (!c0_shift_h || (y & c0_shift_h))
1307 c0_data += c0_linesize;
1308 if (!c1_shift_h || (y & c1_shift_h))
1309 c1_data += c1_linesize;
1310 dst_data += dst_linesize;
1314 const uint16_t *c0_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1315 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1316 uint16_t *dst_data = (uint16_t *)out->data[plane] + offset_y * dst_linesize + offset_x;
1319 dst_data += s->size - 1;
1320 for (y = 0; y < src_h; y++) {
1321 for (x = 0; x < src_w; x++) {
1322 const int sum = FFMIN(FFABS(c0_data[x >> c0_shift_w] - mid) + FFABS(c1_data[x >> c1_shift_w] - mid - 1), limit);
1326 target = dst_data - sum;
1327 update16(target, max, intensity, limit);
1329 target = dst_data + sum;
1330 update16(target, max, intensity, limit);
1334 if (!c0_shift_h || (y & c0_shift_h))
1335 c0_data += c0_linesize;
1336 if (!c1_shift_h || (y & c1_shift_h))
1337 c1_data += c1_linesize;
1338 dst_data += dst_linesize;
1342 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
1345 static av_always_inline void chroma(WaveformContext *s,
1346 AVFrame *in, AVFrame *out,
1347 int component, int intensity,
1348 int offset_y, int offset_x,
1349 int column, int mirror)
1351 const int plane = s->desc->comp[component].plane;
1352 const int c0_linesize = in->linesize[(plane + 1) % s->ncomp];
1353 const int c1_linesize = in->linesize[(plane + 2) % s->ncomp];
1354 const int dst_linesize = out->linesize[plane];
1355 const int max = 255 - intensity;
1356 const int c0_shift_w = s->shift_w[(component + 1) % s->ncomp];
1357 const int c1_shift_w = s->shift_w[(component + 2) % s->ncomp];
1358 const int c0_shift_h = s->shift_h[(component + 1) % s->ncomp];
1359 const int c1_shift_h = s->shift_h[(component + 2) % s->ncomp];
1360 const int src_h = in->height;
1361 const int src_w = in->width;
1365 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
1367 for (x = 0; x < src_w; x++) {
1368 const uint8_t *c0_data = in->data[(plane + 1) % s->ncomp];
1369 const uint8_t *c1_data = in->data[(plane + 2) % s->ncomp];
1370 uint8_t *dst_data = out->data[plane] + offset_y * dst_linesize + offset_x;
1371 uint8_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
1372 uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
1373 uint8_t *dst = dst_line;
1375 for (y = 0; y < src_h; y++) {
1376 const int sum = FFABS(c0_data[x >> c0_shift_w] - 128) + FFABS(c1_data[x >> c1_shift_w] - 127);
1379 target = dst + x + dst_signed_linesize * sum;
1380 update(target, max, intensity);
1382 if (!c0_shift_h || (y & c0_shift_h))
1383 c0_data += c0_linesize;
1384 if (!c1_shift_h || (y & c1_shift_h))
1385 c1_data += c1_linesize;
1386 dst_data += dst_linesize;
1390 const uint8_t *c0_data = in->data[(plane + 1) % s->ncomp];
1391 const uint8_t *c1_data = in->data[(plane + 2) % s->ncomp];
1392 uint8_t *dst_data = out->data[plane] + offset_y * dst_linesize + offset_x;
1395 dst_data += s->size - 1;
1396 for (y = 0; y < src_h; y++) {
1397 for (x = 0; x < src_w; x++) {
1398 const int sum = FFABS(c0_data[x >> c0_shift_w] - 128) + FFABS(c1_data[x >> c1_shift_w] - 127);
1402 target = dst_data - sum;
1403 update(target, max, intensity);
1405 target = dst_data + sum;
1406 update(target, max, intensity);
1410 if (!c0_shift_h || (y & c0_shift_h))
1411 c0_data += c0_linesize;
1412 if (!c1_shift_h || (y & c1_shift_h))
1413 c1_data += c1_linesize;
1414 dst_data += dst_linesize;
1418 envelope(s, out, plane, plane, column ? offset_x : offset_y);
1421 static av_always_inline void color16(WaveformContext *s,
1422 AVFrame *in, AVFrame *out,
1423 int component, int intensity,
1424 int offset_y, int offset_x,
1425 int column, int mirror)
1427 const int plane = s->desc->comp[component].plane;
1428 const int limit = s->max - 1;
1429 const uint16_t *c0_data = (const uint16_t *)in->data[plane + 0];
1430 const uint16_t *c1_data = (const uint16_t *)in->data[(plane + 1) % s->ncomp];
1431 const uint16_t *c2_data = (const uint16_t *)in->data[(plane + 2) % s->ncomp];
1432 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
1433 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1434 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1435 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
1436 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
1437 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2;
1438 const int c0_shift_w = s->shift_w[ component + 0 ];
1439 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1440 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1441 const int c0_shift_h = s->shift_h[ component + 0 ];
1442 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1443 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1444 const int src_h = in->height;
1445 const int src_w = in->width;
1449 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1450 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1451 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1452 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1453 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1454 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1455 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1456 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1457 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1458 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1459 uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1460 uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1462 for (y = 0; y < src_h; y++) {
1463 for (x = 0; x < src_w; x++) {
1464 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1465 const int c1 = c1_data[x >> c1_shift_w];
1466 const int c2 = c2_data[x >> c2_shift_w];
1468 *(d0 + d0_signed_linesize * c0 + x) = c0;
1469 *(d1 + d1_signed_linesize * c0 + x) = c1;
1470 *(d2 + d2_signed_linesize * c0 + x) = c2;
1473 if (!c0_shift_h || (y & c0_shift_h))
1474 c0_data += c0_linesize;
1475 if (!c1_shift_h || (y & c1_shift_h))
1476 c1_data += c1_linesize;
1477 if (!c2_shift_h || (y & c2_shift_h))
1478 c2_data += c2_linesize;
1479 d0_data += d0_linesize;
1480 d1_data += d1_linesize;
1481 d2_data += d2_linesize;
1484 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1485 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1486 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1489 d0_data += s->size - 1;
1490 d1_data += s->size - 1;
1491 d2_data += s->size - 1;
1494 for (y = 0; y < src_h; y++) {
1495 for (x = 0; x < src_w; x++) {
1496 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1497 const int c1 = c1_data[x >> c1_shift_w];
1498 const int c2 = c2_data[x >> c2_shift_w];
1501 *(d0_data - c0) = c0;
1502 *(d1_data - c0) = c1;
1503 *(d2_data - c0) = c2;
1505 *(d0_data + c0) = c0;
1506 *(d1_data + c0) = c1;
1507 *(d2_data + c0) = c2;
1511 if (!c0_shift_h || (y & c0_shift_h))
1512 c0_data += c0_linesize;
1513 if (!c1_shift_h || (y & c1_shift_h))
1514 c1_data += c1_linesize;
1515 if (!c2_shift_h || (y & c2_shift_h))
1516 c2_data += c2_linesize;
1517 d0_data += d0_linesize;
1518 d1_data += d1_linesize;
1519 d2_data += d2_linesize;
1523 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
1526 static av_always_inline void color(WaveformContext *s,
1527 AVFrame *in, AVFrame *out,
1528 int component, int intensity,
1529 int offset_y, int offset_x,
1530 int column, int mirror)
1532 const int plane = s->desc->comp[component].plane;
1533 const uint8_t *c0_data = in->data[plane + 0];
1534 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1535 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1536 const int c0_linesize = in->linesize[ plane + 0 ];
1537 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
1538 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
1539 const int d0_linesize = out->linesize[ plane + 0 ];
1540 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
1541 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp];
1542 const int c0_shift_w = s->shift_w[ component + 0 ];
1543 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1544 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1545 const int c0_shift_h = s->shift_h[ component + 0 ];
1546 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1547 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1548 const int src_h = in->height;
1549 const int src_w = in->width;
1553 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1554 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1555 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1556 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1557 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1558 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1559 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1560 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1561 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1562 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1563 uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1564 uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1566 for (y = 0; y < src_h; y++) {
1567 for (x = 0; x < src_w; x++) {
1568 const int c0 = c0_data[x >> c0_shift_w];
1569 const int c1 = c1_data[x >> c1_shift_w];
1570 const int c2 = c2_data[x >> c2_shift_w];
1572 *(d0 + d0_signed_linesize * c0 + x) = c0;
1573 *(d1 + d1_signed_linesize * c0 + x) = c1;
1574 *(d2 + d2_signed_linesize * c0 + x) = c2;
1577 if (!c0_shift_h || (y & c0_shift_h))
1578 c0_data += c0_linesize;
1579 if (!c1_shift_h || (y & c1_shift_h))
1580 c1_data += c1_linesize;
1581 if (!c2_shift_h || (y & c2_shift_h))
1582 c2_data += c2_linesize;
1583 d0_data += d0_linesize;
1584 d1_data += d1_linesize;
1585 d2_data += d2_linesize;
1588 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1589 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1590 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1593 d0_data += s->size - 1;
1594 d1_data += s->size - 1;
1595 d2_data += s->size - 1;
1598 for (y = 0; y < src_h; y++) {
1599 for (x = 0; x < src_w; x++) {
1600 const int c0 = c0_data[x >> c0_shift_w];
1601 const int c1 = c1_data[x >> c1_shift_w];
1602 const int c2 = c2_data[x >> c2_shift_w];
1605 *(d0_data - c0) = c0;
1606 *(d1_data - c0) = c1;
1607 *(d2_data - c0) = c2;
1609 *(d0_data + c0) = c0;
1610 *(d1_data + c0) = c1;
1611 *(d2_data + c0) = c2;
1615 if (!c0_shift_h || (y & c0_shift_h))
1616 c0_data += c0_linesize;
1617 if (!c1_shift_h || (y & c1_shift_h))
1618 c1_data += c1_linesize;
1619 if (!c2_shift_h || (y & c2_shift_h))
1620 c2_data += c2_linesize;
1621 d0_data += d0_linesize;
1622 d1_data += d1_linesize;
1623 d2_data += d2_linesize;
1627 envelope(s, out, plane, plane, column ? offset_x : offset_y);
1630 static av_always_inline void acolor16(WaveformContext *s,
1631 AVFrame *in, AVFrame *out,
1632 int component, int intensity,
1633 int offset_y, int offset_x,
1634 int column, int mirror)
1636 const int plane = s->desc->comp[component].plane;
1637 const int limit = s->max - 1;
1638 const int max = limit - intensity;
1639 const uint16_t *c0_data = (const uint16_t *)in->data[plane + 0];
1640 const uint16_t *c1_data = (const uint16_t *)in->data[(plane + 1) % s->ncomp];
1641 const uint16_t *c2_data = (const uint16_t *)in->data[(plane + 2) % s->ncomp];
1642 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
1643 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1644 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1645 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
1646 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
1647 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2;
1648 const int c0_shift_w = s->shift_w[ component + 0 ];
1649 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1650 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1651 const int c0_shift_h = s->shift_h[ component + 0 ];
1652 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1653 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1654 const int src_h = in->height;
1655 const int src_w = in->width;
1659 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1660 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1661 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1662 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1663 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1664 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1665 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1666 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1667 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1668 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1669 uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1670 uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1672 for (y = 0; y < src_h; y++) {
1673 for (x = 0; x < src_w; x++) {
1674 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1675 const int c1 = c1_data[x >> c1_shift_w];
1676 const int c2 = c2_data[x >> c2_shift_w];
1678 update16(d0 + d0_signed_linesize * c0 + x, max, intensity, limit);
1679 *(d1 + d1_signed_linesize * c0 + x) = c1;
1680 *(d2 + d2_signed_linesize * c0 + x) = c2;
1683 if (!c0_shift_h || (y & c0_shift_h))
1684 c0_data += c0_linesize;
1685 if (!c1_shift_h || (y & c1_shift_h))
1686 c1_data += c1_linesize;
1687 if (!c2_shift_h || (y & c2_shift_h))
1688 c2_data += c2_linesize;
1689 d0_data += d0_linesize;
1690 d1_data += d1_linesize;
1691 d2_data += d2_linesize;
1694 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1695 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1696 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1699 d0_data += s->size - 1;
1700 d1_data += s->size - 1;
1701 d2_data += s->size - 1;
1704 for (y = 0; y < src_h; y++) {
1705 for (x = 0; x < src_w; x++) {
1706 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1707 const int c1 = c1_data[x >> c1_shift_w];
1708 const int c2 = c2_data[x >> c2_shift_w];
1711 update16(d0_data - c0, max, intensity, limit);
1712 *(d1_data - c0) = c1;
1713 *(d2_data - c0) = c2;
1715 update16(d0_data + c0, max, intensity, limit);
1716 *(d1_data + c0) = c1;
1717 *(d2_data + c0) = c2;
1721 if (!c0_shift_h || (y & c0_shift_h))
1722 c0_data += c0_linesize;
1723 if (!c1_shift_h || (y & c1_shift_h))
1724 c1_data += c1_linesize;
1725 if (!c2_shift_h || (y & c2_shift_h))
1726 c2_data += c2_linesize;
1727 d0_data += d0_linesize;
1728 d1_data += d1_linesize;
1729 d2_data += d2_linesize;
1733 envelope16(s, out, plane, plane, column ? offset_x : offset_y);
1736 static av_always_inline void acolor(WaveformContext *s,
1737 AVFrame *in, AVFrame *out,
1738 int component, int intensity,
1739 int offset_y, int offset_x,
1740 int column, int mirror)
1742 const int plane = s->desc->comp[component].plane;
1743 const uint8_t *c0_data = in->data[plane + 0];
1744 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1745 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1746 const int c0_linesize = in->linesize[ plane + 0 ];
1747 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
1748 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
1749 const int d0_linesize = out->linesize[ plane + 0 ];
1750 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
1751 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp];
1752 const int c0_shift_w = s->shift_w[ component + 0 ];
1753 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1754 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1755 const int c0_shift_h = s->shift_h[ component + 0 ];
1756 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1757 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1758 const int max = 255 - intensity;
1759 const int src_h = in->height;
1760 const int src_w = in->width;
1764 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1765 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1766 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1767 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1768 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1769 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1770 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1771 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1772 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1773 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1774 uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1775 uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1777 for (y = 0; y < src_h; y++) {
1778 for (x = 0; x < src_w; x++) {
1779 const int c0 = c0_data[x >> c0_shift_w];
1780 const int c1 = c1_data[x >> c1_shift_w];
1781 const int c2 = c2_data[x >> c2_shift_w];
1783 update(d0 + d0_signed_linesize * c0 + x, max, intensity);
1784 *(d1 + d1_signed_linesize * c0 + x) = c1;
1785 *(d2 + d2_signed_linesize * c0 + x) = c2;
1788 if (!c0_shift_h || (y & c0_shift_h))
1789 c0_data += c0_linesize;
1790 if (!c1_shift_h || (y & c1_shift_h))
1791 c1_data += c1_linesize;
1792 if (!c2_shift_h || (y & c2_shift_h))
1793 c2_data += c2_linesize;
1794 d0_data += d0_linesize;
1795 d1_data += d1_linesize;
1796 d2_data += d2_linesize;
1799 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1800 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1801 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1804 d0_data += s->size - 1;
1805 d1_data += s->size - 1;
1806 d2_data += s->size - 1;
1809 for (y = 0; y < src_h; y++) {
1810 for (x = 0; x < src_w; x++) {
1811 const int c0 = c0_data[x >> c0_shift_w];
1812 const int c1 = c1_data[x >> c1_shift_w];
1813 const int c2 = c2_data[x >> c2_shift_w];
1816 update(d0_data - c0, max, intensity);
1817 *(d1_data - c0) = c1;
1818 *(d2_data - c0) = c2;
1820 update(d0_data + c0, max, intensity);
1821 *(d1_data + c0) = c1;
1822 *(d2_data + c0) = c2;
1826 if (!c0_shift_h || (y & c0_shift_h))
1827 c0_data += c0_linesize;
1828 if (!c1_shift_h || (y & c1_shift_h))
1829 c1_data += c1_linesize;
1830 if (!c2_shift_h || (y & c2_shift_h))
1831 c2_data += c2_linesize;
1832 d0_data += d0_linesize;
1833 d1_data += d1_linesize;
1834 d2_data += d2_linesize;
1838 envelope(s, out, plane, plane, column ? offset_x : offset_y);
1841 static const uint8_t black_yuva_color[4] = { 0, 127, 127, 255 };
1842 static const uint8_t green_yuva_color[4] = { 255, 0, 0, 255 };
1843 static const uint8_t black_gbrp_color[4] = { 0, 0, 0, 255 };
1845 static const GraticuleLines aflat_digital8[] = {
1846 { { { "16", 16+128 }, { "16", 16+128 }, { "16", 16+128 }, { "0", 0+128 } } },
1847 { { { "128", 128+128 }, { "128", 128+128 }, { "128", 128+128 }, { "128", 128+128 } } },
1848 { { { "235", 235+128 }, { "240", 240+128 }, { "240", 240+128 }, { "255", 255+128 } } },
1851 static const GraticuleLines aflat_digital9[] = {
1852 { { { "32", 32+256 }, { "32", 32+256 }, { "32", 32+256 }, { "0", 0+256 } } },
1853 { { { "256", 256+256 }, { "256", 256+256 }, { "256", 256+256 }, { "256", 256+256 } } },
1854 { { { "470", 470+256 }, { "480", 480+256 }, { "480", 480+256 }, { "511", 511+256 } } },
1857 static const GraticuleLines aflat_digital10[] = {
1858 { { { "64", 64+512 }, { "64", 64+512 }, { "64", 64+512 }, { "0", 0+512 } } },
1859 { { { "512", 512+512 }, { "512", 512+512 }, { "512", 512+512 }, { "512", 512+512 } } },
1860 { { { "940", 940+512 }, { "960", 960+512 }, { "960", 960+512 }, { "1023", 1023+512 } } },
1863 static const GraticuleLines aflat_digital12[] = {
1864 { { { "256", 256+2048 }, { "256", 256+2048 }, { "256", 256+2048 }, { "0", 0+2048 } } },
1865 { { { "2048", 2048+2048 }, { "2048", 2048+2048 }, { "2048", 2048+2048 }, { "2048", 2048+2048 } } },
1866 { { { "3760", 3760+2048 }, { "3840", 3840+2048 }, { "3840", 3840+2048 }, { "4095", 4095+2048 } } },
1869 static const GraticuleLines aflat_millivolts8[] = {
1870 { { { "0", 16+128 }, { "0", 16+128 }, { "0", 16+128 }, { "0", 0+128 } } },
1871 { { { "175", 71+128 }, { "175", 72+128 }, { "175", 72+128 }, { "175", 64+128 } } },
1872 { { { "350", 126+128 }, { "350", 128+128 }, { "350", 128+128 }, { "350", 128+128 } } },
1873 { { { "525", 180+128 }, { "525", 184+128 }, { "525", 184+128 }, { "525", 192+128 } } },
1874 { { { "700", 235+128 }, { "700", 240+128 }, { "700", 240+128 }, { "700", 255+128 } } },
1877 static const GraticuleLines aflat_millivolts9[] = {
1878 { { { "0", 32+256 }, { "0", 32+256 }, { "0", 32+256 }, { "0", 0+256 } } },
1879 { { { "175", 142+256 }, { "175", 144+256 }, { "175", 144+256 }, { "175", 128+256 } } },
1880 { { { "350", 251+256 }, { "350", 256+256 }, { "350", 256+256 }, { "350", 256+256 } } },
1881 { { { "525", 361+256 }, { "525", 368+256 }, { "525", 368+256 }, { "525", 384+256 } } },
1882 { { { "700", 470+256 }, { "700", 480+256 }, { "700", 480+256 }, { "700", 511+256 } } },
1885 static const GraticuleLines aflat_millivolts10[] = {
1886 { { { "0", 64+512 }, { "0", 64+512 }, { "0", 64+512 }, { "0", 0+512 } } },
1887 { { { "175", 283+512 }, { "175", 288+512 }, { "175", 288+512 }, { "175", 256+512 } } },
1888 { { { "350", 502+512 }, { "350", 512+512 }, { "350", 512+512 }, { "350", 512+512 } } },
1889 { { { "525", 721+512 }, { "525", 736+512 }, { "525", 736+512 }, { "525", 768+512 } } },
1890 { { { "700", 940+512 }, { "700", 960+512 }, { "700", 960+512 }, { "700", 1023+512 } } },
1893 static const GraticuleLines aflat_millivolts12[] = {
1894 { { { "0", 256+2048 }, { "0", 256+2048 }, { "0", 256+2048 }, { "0", 0+2048 } } },
1895 { { { "175", 1132+2048 }, { "175", 1152+2048 }, { "175", 1152+2048 }, { "175", 1024+2048 } } },
1896 { { { "350", 2008+2048 }, { "350", 2048+2048 }, { "350", 2048+2048 }, { "350", 2048+2048 } } },
1897 { { { "525", 2884+2048 }, { "525", 2944+2048 }, { "525", 2944+2048 }, { "525", 3072+2048 } } },
1898 { { { "700", 3760+2048 }, { "700", 3840+2048 }, { "700", 3840+2048 }, { "700", 4095+2048 } } },
1901 static const GraticuleLines aflat_ire8[] = {
1902 { { { "-25", -39+128 }, { "-25", -40+128 }, { "-25", -40+128 }, { "-25", -64+128 } } },
1903 { { { "0", 16+128 }, { "0", 16+128 }, { "0", 16+128 }, { "0", 0+128 } } },
1904 { { { "25", 71+128 }, { "25", 72+128 }, { "25", 72+128 }, { "25", 64+128 } } },
1905 { { { "50", 126+128 }, { "50", 128+128 }, { "50", 128+128 }, { "50", 128+128 } } },
1906 { { { "75", 180+128 }, { "75", 184+128 }, { "75", 184+128 }, { "75", 192+128 } } },
1907 { { { "100", 235+128 }, { "100", 240+128 }, { "100", 240+128 }, { "100", 256+128 } } },
1908 { { { "125", 290+128 }, { "125", 296+128 }, { "125", 296+128 }, { "125", 320+128 } } },
1911 static const GraticuleLines aflat_ire9[] = {
1912 { { { "-25", -78+256 }, { "-25", -80+256 }, { "-25", -80+256 }, { "-25",-128+256 } } },
1913 { { { "0", 32+256 }, { "0", 32+256 }, { "0", 32+256 }, { "0", 0+256 } } },
1914 { { { "25", 142+256 }, { "25", 144+256 }, { "25", 144+256 }, { "25", 128+256 } } },
1915 { { { "50", 251+256 }, { "50", 256+256 }, { "50", 256+256 }, { "50", 256+256 } } },
1916 { { { "75", 361+256 }, { "75", 368+256 }, { "75", 368+256 }, { "75", 384+256 } } },
1917 { { { "100", 470+256 }, { "100", 480+256 }, { "100", 480+256 }, { "100", 512+256 } } },
1918 { { { "125", 580+256 }, { "125", 592+256 }, { "125", 592+256 }, { "125", 640+256 } } },
1921 static const GraticuleLines aflat_ire10[] = {
1922 { { { "-25",-156+512 }, { "-25",-160+512 }, { "-25",-160+512 }, { "-25", -256+512 } } },
1923 { { { "0", 64+512 }, { "0", 64+512 }, { "0", 64+512 }, { "0", 0+512 } } },
1924 { { { "25", 283+512 }, { "25", 288+512 }, { "25", 288+512 }, { "25", 256+512 } } },
1925 { { { "50", 502+512 }, { "50", 512+512 }, { "50", 512+512 }, { "50", 512+512 } } },
1926 { { { "75", 721+512 }, { "75", 736+512 }, { "75", 736+512 }, { "75", 768+512 } } },
1927 { { { "100", 940+512 }, { "100", 960+512 }, { "100", 960+512 }, { "100", 1024+512 } } },
1928 { { { "125",1160+512 }, { "125",1184+512 }, { "125",1184+512 }, { "125", 1280+512 } } },
1931 static const GraticuleLines aflat_ire12[] = {
1932 { { { "-25", -624+2048 }, { "-25", -640+2048 }, { "-25", -640+2048 }, { "-25",-1024+2048 } } },
1933 { { { "0", 256+2048 }, { "0", 256+2048 }, { "0", 256+2048 }, { "0", 0+2048 } } },
1934 { { { "25", 1132+2048 }, { "25", 1152+2048 }, { "25", 1152+2048 }, { "25", 1024+2048 } } },
1935 { { { "50", 2008+2048 }, { "50", 2048+2048 }, { "50", 2048+2048 }, { "50", 2048+2048 } } },
1936 { { { "75", 2884+2048 }, { "75", 2944+2048 }, { "75", 2944+2048 }, { "75", 3072+2048 } } },
1937 { { { "100", 3760+2048 }, { "100", 3840+2048 }, { "100", 3840+2048 }, { "100", 4096+2048 } } },
1938 { { { "125", 4640+2048 }, { "125", 4736+2048 }, { "125", 4736+2048 }, { "125", 5120+2048 } } },
1941 static const GraticuleLines flat_digital8[] = {
1942 { { { "16", 16+256 }, { "16", 16+256 }, { "16", 16+256 }, { "0", 0+256 } } },
1943 { { { "128", 128+256 }, { "128", 128+256 }, { "128", 128+256 }, { "128", 128+256 } } },
1944 { { { "235", 235+256 }, { "240", 240+256 }, { "240", 240+256 }, { "255", 255+256 } } },
1947 static const GraticuleLines flat_digital9[] = {
1948 { { { "32", 32+512 }, { "32", 32+512 }, { "32", 32+512 }, { "0", 0+512 } } },
1949 { { { "256", 256+512 }, { "256", 256+512 }, { "256", 256+512 }, { "256", 256+512 } } },
1950 { { { "470", 470+512 }, { "480", 480+512 }, { "480", 480+512 }, { "511", 511+512 } } },
1953 static const GraticuleLines flat_digital10[] = {
1954 { { { "64", 64+1024 }, { "64", 64+1024 }, { "64", 64+1024 }, { "0", 0+1024 } } },
1955 { { { "512", 512+1024 }, { "512", 512+1024 }, { "512", 512+1024 }, { "512", 512+1024 } } },
1956 { { { "940", 940+1024 }, { "960", 960+1024 }, { "960", 960+1024 }, { "1023", 1023+1024 } } },
1959 static const GraticuleLines flat_digital12[] = {
1960 { { { "256", 256+4096 }, { "256", 256+4096 }, { "256", 256+4096 }, { "0", 0+4096 } } },
1961 { { { "2048", 2048+4096 }, { "2048", 2048+4096 }, { "2048", 2048+4096 }, { "2048", 2048+4096 } } },
1962 { { { "3760", 3760+4096 }, { "3840", 3840+4096 }, { "3840", 3840+4096 }, { "4095", 4095+4096 } } },
1965 static const GraticuleLines flat_millivolts8[] = {
1966 { { { "0", 16+256 }, { "0", 16+256 }, { "0", 16+256 }, { "0", 0+256 } } },
1967 { { { "175", 71+256 }, { "175", 72+256 }, { "175", 72+256 }, { "175", 64+256 } } },
1968 { { { "350", 126+256 }, { "350", 128+256 }, { "350", 128+256 }, { "350", 128+256 } } },
1969 { { { "525", 180+256 }, { "525", 184+256 }, { "525", 184+256 }, { "525", 192+256 } } },
1970 { { { "700", 235+256 }, { "700", 240+256 }, { "700", 240+256 }, { "700", 255+256 } } },
1973 static const GraticuleLines flat_millivolts9[] = {
1974 { { { "0", 32+512 }, { "0", 32+512 }, { "0", 32+512 }, { "0", 0+512 } } },
1975 { { { "175", 142+512 }, { "175", 144+512 }, { "175", 144+512 }, { "175", 128+512 } } },
1976 { { { "350", 251+512 }, { "350", 256+512 }, { "350", 256+512 }, { "350", 256+512 } } },
1977 { { { "525", 361+512 }, { "525", 368+512 }, { "525", 368+512 }, { "525", 384+512 } } },
1978 { { { "700", 470+512 }, { "700", 480+512 }, { "700", 480+512 }, { "700", 511+512 } } },
1981 static const GraticuleLines flat_millivolts10[] = {
1982 { { { "0", 64+1024 }, { "0", 64+1024 }, { "0", 64+1024 }, { "0", 0+1024 } } },
1983 { { { "175", 283+1024 }, { "175", 288+1024 }, { "175", 288+1024 }, { "175", 256+1024 } } },
1984 { { { "350", 502+1024 }, { "350", 512+1024 }, { "350", 512+1024 }, { "350", 512+1024 } } },
1985 { { { "525", 721+1024 }, { "525", 736+1024 }, { "525", 736+1024 }, { "525", 768+1024 } } },
1986 { { { "700", 940+1024 }, { "700", 960+1024 }, { "700", 960+1024 }, { "700", 1023+1024 } } },
1989 static const GraticuleLines flat_millivolts12[] = {
1990 { { { "0", 256+4096 }, { "0", 256+4096 }, { "0", 256+4096 }, { "0", 0+4096 } } },
1991 { { { "175", 1132+4096 }, { "175", 1152+4096 }, { "175", 1152+4096 }, { "175", 1024+4096 } } },
1992 { { { "350", 2008+4096 }, { "350", 2048+4096 }, { "350", 2048+4096 }, { "350", 2048+4096 } } },
1993 { { { "525", 2884+4096 }, { "525", 2944+4096 }, { "525", 2944+4096 }, { "525", 3072+4096 } } },
1994 { { { "700", 3760+4096 }, { "700", 3840+4096 }, { "700", 3840+4096 }, { "700", 4095+4096 } } },
1997 static const GraticuleLines flat_ire8[] = {
1998 { { { "-25", -39+256 }, { "-25", -40+256 }, { "-25", -40+256 }, { "-25", -64+256 } } },
1999 { { { "0", 16+256 }, { "0", 16+256 }, { "0", 16+256 }, { "0", 0+256 } } },
2000 { { { "25", 71+256 }, { "25", 72+256 }, { "25", 72+256 }, { "25", 64+256 } } },
2001 { { { "50", 126+256 }, { "50", 128+256 }, { "50", 128+256 }, { "50", 128+256 } } },
2002 { { { "75", 180+256 }, { "75", 184+256 }, { "75", 184+256 }, { "75", 192+256 } } },
2003 { { { "100", 235+256 }, { "100", 240+256 }, { "100", 240+256 }, { "100", 256+256 } } },
2004 { { { "125", 290+256 }, { "125", 296+256 }, { "125", 296+256 }, { "125", 320+256 } } },
2007 static const GraticuleLines flat_ire9[] = {
2008 { { { "-25", -78+512 }, { "-25", -80+512 }, { "-25", -80+512 }, { "-25",-128+512 } } },
2009 { { { "0", 32+512 }, { "0", 32+512 }, { "0", 32+512 }, { "0", 0+512 } } },
2010 { { { "25", 142+512 }, { "25", 144+512 }, { "25", 144+512 }, { "25", 128+512 } } },
2011 { { { "50", 251+512 }, { "50", 256+512 }, { "50", 256+512 }, { "50", 256+512 } } },
2012 { { { "75", 361+512 }, { "75", 368+512 }, { "75", 368+512 }, { "75", 384+512 } } },
2013 { { { "100", 470+512 }, { "100", 480+512 }, { "100", 480+512 }, { "100", 512+512 } } },
2014 { { { "125", 580+512 }, { "125", 592+512 }, { "125", 592+512 }, { "125", 640+512 } } },
2017 static const GraticuleLines flat_ire10[] = {
2018 { { { "-25",-156+1024 }, { "-25",-160+1024 }, { "-25",-160+1024 }, { "-25", -256+1024 } } },
2019 { { { "0", 64+1024 }, { "0", 64+1024 }, { "0", 64+1024 }, { "0", 0+1024 } } },
2020 { { { "25", 283+1024 }, { "25", 288+1024 }, { "25", 288+1024 }, { "25", 256+1024 } } },
2021 { { { "50", 502+1024 }, { "50", 512+1024 }, { "50", 512+1024 }, { "50", 512+1024 } } },
2022 { { { "75", 721+1024 }, { "75", 736+1024 }, { "75", 736+1024 }, { "75", 768+1024 } } },
2023 { { { "100", 940+1024 }, { "100", 960+1024 }, { "100", 960+1024 }, { "100", 1024+1024 } } },
2024 { { { "125",1160+1024 }, { "125",1184+1024 }, { "125",1184+1024 }, { "125", 1280+1024 } } },
2027 static const GraticuleLines flat_ire12[] = {
2028 { { { "-25", -624+4096 }, { "-25", -640+4096 }, { "-25", -640+4096 }, { "-25",-1024+4096 } } },
2029 { { { "0", 256+4096 }, { "0", 256+4096 }, { "0", 256+4096 }, { "0", 0+4096 } } },
2030 { { { "25", 1132+4096 }, { "25", 1152+4096 }, { "25", 1152+4096 }, { "25", 1024+4096 } } },
2031 { { { "50", 2008+4096 }, { "50", 2048+4096 }, { "50", 2048+4096 }, { "50", 2048+4096 } } },
2032 { { { "75", 2884+4096 }, { "75", 2944+4096 }, { "75", 2944+4096 }, { "75", 3072+4096 } } },
2033 { { { "100", 3760+4096 }, { "100", 3840+4096 }, { "100", 3840+4096 }, { "100", 4096+4096 } } },
2034 { { { "125", 4640+4096 }, { "125", 4736+4096 }, { "125", 4736+4096 }, { "125", 5120+4096 } } },
2037 static const GraticuleLines digital8[] = {
2038 { { { "16", 16 }, { "16", 16 }, { "16", 16 }, { "0", 0 } } },
2039 { { { "128", 128 }, { "128", 128 }, { "128", 128 }, { "128", 128 } } },
2040 { { { "235", 235 }, { "240", 240 }, { "240", 240 }, { "255", 255 } } },
2043 static const GraticuleLines digital9[] = {
2044 { { { "32", 32 }, { "32", 32 }, { "32", 32 }, { "0", 0 } } },
2045 { { { "256", 256 }, { "256", 256 }, { "256", 256 }, { "256", 256 } } },
2046 { { { "470", 470 }, { "480", 480 }, { "480", 480 }, { "511", 511 } } },
2049 static const GraticuleLines digital10[] = {
2050 { { { "64", 64 }, { "64", 64 }, { "64", 64 }, { "0", 0 } } },
2051 { { { "512", 512 }, { "512", 512 }, { "512", 512 }, { "512", 512 } } },
2052 { { { "940", 940 }, { "960", 960 }, { "960", 960 }, { "1023", 1023 } } },
2055 static const GraticuleLines digital12[] = {
2056 { { { "256", 256 }, { "256", 256 }, { "256", 256 }, { "0", 0 } } },
2057 { { { "2048", 2048 }, { "2048", 2048 }, { "2048", 2048 }, { "2048", 2048 } } },
2058 { { { "3760", 3760 }, { "3840", 3840 }, { "3840", 3840 }, { "4095", 4095 } } },
2061 static const GraticuleLines millivolts8[] = {
2062 { { { "0", 16 }, { "0", 16 }, { "0", 16 }, { "0", 0 } } },
2063 { { { "175", 71 }, { "175", 72 }, { "175", 72 }, { "175", 64 } } },
2064 { { { "350", 126 }, { "350", 128 }, { "350", 128 }, { "350", 128 } } },
2065 { { { "525", 180 }, { "525", 184 }, { "525", 184 }, { "525", 192 } } },
2066 { { { "700", 235 }, { "700", 240 }, { "700", 240 }, { "700", 255 } } },
2069 static const GraticuleLines millivolts9[] = {
2070 { { { "0", 32 }, { "0", 32 }, { "0", 32 }, { "0", 0 } } },
2071 { { { "175", 142 }, { "175", 144 }, { "175", 144 }, { "175", 128 } } },
2072 { { { "350", 251 }, { "350", 256 }, { "350", 256 }, { "350", 256 } } },
2073 { { { "525", 361 }, { "525", 368 }, { "525", 368 }, { "525", 384 } } },
2074 { { { "700", 470 }, { "700", 480 }, { "700", 480 }, { "700", 511 } } },
2077 static const GraticuleLines millivolts10[] = {
2078 { { { "0", 64 }, { "0", 64 }, { "0", 64 }, { "0", 0 } } },
2079 { { { "175", 283 }, { "175", 288 }, { "175", 288 }, { "175", 256 } } },
2080 { { { "350", 502 }, { "350", 512 }, { "350", 512 }, { "350", 512 } } },
2081 { { { "525", 721 }, { "525", 736 }, { "525", 736 }, { "525", 768 } } },
2082 { { { "700", 940 }, { "700", 960 }, { "700", 960 }, { "700", 1023 } } },
2085 static const GraticuleLines millivolts12[] = {
2086 { { { "0", 256 }, { "0", 256 }, { "0", 256 }, { "0", 0 } } },
2087 { { { "175", 1132 }, { "175", 1152 }, { "175", 1152 }, { "175", 1024 } } },
2088 { { { "350", 2008 }, { "350", 2048 }, { "350", 2048 }, { "350", 2048 } } },
2089 { { { "525", 2884 }, { "525", 2944 }, { "525", 2944 }, { "525", 3072 } } },
2090 { { { "700", 3760 }, { "700", 3840 }, { "700", 3840 }, { "700", 4095 } } },
2093 static const GraticuleLines ire8[] = {
2094 { { { "0", 16 }, { "0", 16 }, { "0", 16 }, { "0", 0 } } },
2095 { { { "25", 71 }, { "25", 72 }, { "25", 72 }, { "25", 64 } } },
2096 { { { "50", 126 }, { "50", 128 }, { "50", 128 }, { "50", 128 } } },
2097 { { { "75", 180 }, { "75", 184 }, { "75", 184 }, { "75", 192 } } },
2098 { { { "100", 235 }, { "100", 240 }, { "100", 240 }, { "100", 255 } } },
2101 static const GraticuleLines ire9[] = {
2102 { { { "0", 32 }, { "0", 32 }, { "0", 32 }, { "0", 0 } } },
2103 { { { "25", 142 }, { "25", 144 }, { "25", 144 }, { "25", 128 } } },
2104 { { { "50", 251 }, { "50", 256 }, { "50", 256 }, { "50", 256 } } },
2105 { { { "75", 361 }, { "75", 368 }, { "75", 368 }, { "75", 384 } } },
2106 { { { "100", 470 }, { "100", 480 }, { "100", 480 }, { "100", 511 } } },
2109 static const GraticuleLines ire10[] = {
2110 { { { "0", 64 }, { "0", 64 }, { "0", 64 }, { "0", 0 } } },
2111 { { { "25", 283 }, { "25", 288 }, { "25", 288 }, { "25", 256 } } },
2112 { { { "50", 502 }, { "50", 512 }, { "50", 512 }, { "50", 512 } } },
2113 { { { "75", 721 }, { "75", 736 }, { "75", 736 }, { "75", 768 } } },
2114 { { { "100", 940 }, { "100", 960 }, { "100", 960 }, { "100", 1023 } } },
2117 static const GraticuleLines ire12[] = {
2118 { { { "0", 256 }, { "0", 256 }, { "0", 256 }, { "0", 0 } } },
2119 { { { "25", 1132 }, { "25", 1152 }, { "25", 1152 }, { "25", 1024 } } },
2120 { { { "50", 2008 }, { "50", 2048 }, { "50", 2048 }, { "50", 2048 } } },
2121 { { { "75", 2884 }, { "75", 2944 }, { "75", 2944 }, { "75", 3072 } } },
2122 { { { "100", 3760 }, { "100", 3840 }, { "100", 3840 }, { "100", 4095 } } },
2125 static const GraticuleLines chroma_digital8[] = {
2126 { { { "50", 50 }, { "50", 50 }, { "50", 50 }, { "50", 50 } } },
2127 { { { "100", 100 }, { "100", 100 }, { "100", 100 }, { "100", 100 } } },
2128 { { { "150", 150 }, { "150", 150 }, { "150", 150 }, { "150", 150 } } },
2129 { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2130 { { { "255", 255 }, { "255", 255 }, { "255", 255 }, { "255", 255 } } },
2133 static const GraticuleLines chroma_digital9[] = {
2134 { { { "100", 100 }, { "100", 100 }, { "100", 100 }, { "100", 100 } } },
2135 { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2136 { { { "300", 300 }, { "300", 300 }, { "300", 300 }, { "300", 300 } } },
2137 { { { "400", 400 }, { "400", 400 }, { "400", 400 }, { "400", 400 } } },
2138 { { { "500", 500 }, { "500", 500 }, { "500", 500 }, { "500", 500 } } },
2141 static const GraticuleLines chroma_digital10[] = {
2142 { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2143 { { { "400", 400 }, { "400", 400 }, { "400", 400 }, { "400", 400 } } },
2144 { { { "600", 600 }, { "600", 600 }, { "600", 600 }, { "600", 600 } } },
2145 { { { "800", 800 }, { "800", 800 }, { "800", 800 }, { "800", 800 } } },
2146 { { {"1000",1000 }, {"1000",1000 }, {"1000",1000 }, {"1000",1000 } } },
2149 static const GraticuleLines chroma_digital12[] = {
2150 { { { "800", 800 }, { "800", 800 }, { "800", 800 }, { "800", 800 } } },
2151 { { { "1600", 1600 }, { "1600", 1600 }, { "1600", 1600 }, { "1600", 1600 } } },
2152 { { { "2400", 2400 }, { "2400", 2400 }, { "2400", 2400 }, { "2400", 2400 } } },
2153 { { { "3200", 3200 }, { "3200", 3200 }, { "3200", 3200 }, { "3200", 3200 } } },
2154 { { { "4000", 4000 }, { "4000", 4000 }, { "4000", 4000 }, { "4000", 4000 } } },
2157 static void blend_vline(uint8_t *dst, int height, int linesize, float o1, float o2, int v, int step)
2161 for (y = 0; y < height; y += step) {
2162 dst[0] = v * o1 + dst[0] * o2;
2164 dst += linesize * step;
2168 static void blend_vline16(uint16_t *dst, int height, int linesize, float o1, float o2, int v, int step)
2172 for (y = 0; y < height; y += step) {
2173 dst[0] = v * o1 + dst[0] * o2;
2175 dst += (linesize / 2) * step;
2179 static void blend_hline(uint8_t *dst, int width, float o1, float o2, int v, int step)
2183 for (x = 0; x < width; x += step) {
2184 dst[x] = v * o1 + dst[x] * o2;
2188 static void blend_hline16(uint16_t *dst, int width, float o1, float o2, int v, int step)
2192 for (x = 0; x < width; x += step) {
2193 dst[x] = v * o1 + dst[x] * o2;
2197 static void draw_htext(AVFrame *out, int x, int y, float o1, float o2, const char *txt, const uint8_t color[4])
2199 const uint8_t *font;
2203 font = avpriv_cga_font, font_height = 8;
2205 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2206 for (i = 0; txt[i]; i++) {
2208 int v = color[plane];
2210 uint8_t *p = out->data[plane] + y * out->linesize[plane] + (x + i * 8);
2211 for (char_y = 0; char_y < font_height; char_y++) {
2212 for (mask = 0x80; mask; mask >>= 1) {
2213 if (font[txt[i] * font_height + char_y] & mask)
2214 p[0] = p[0] * o2 + v * o1;
2217 p += out->linesize[plane] - 8;
2223 static void draw_htext16(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
2225 const uint8_t *font;
2229 font = avpriv_cga_font, font_height = 8;
2231 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2232 for (i = 0; txt[i]; i++) {
2234 int v = color[plane] * mult;
2236 uint16_t *p = (uint16_t *)(out->data[plane] + y * out->linesize[plane]) + (x + i * 8);
2237 for (char_y = 0; char_y < font_height; char_y++) {
2238 for (mask = 0x80; mask; mask >>= 1) {
2239 if (font[txt[i] * font_height + char_y] & mask)
2240 p[0] = p[0] * o2 + v * o1;
2243 p += out->linesize[plane] / 2 - 8;
2249 static void draw_vtext(AVFrame *out, int x, int y, float o1, float o2, const char *txt, const uint8_t color[4])
2251 const uint8_t *font;
2255 font = avpriv_cga_font, font_height = 8;
2257 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2258 for (i = 0; txt[i]; i++) {
2260 int v = color[plane];
2262 for (char_y = font_height - 1; char_y >= 0; char_y--) {
2263 uint8_t *p = out->data[plane] + (y + i * 10) * out->linesize[plane] + x;
2264 for (mask = 0x80; mask; mask >>= 1) {
2265 if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
2266 p[char_y] = p[char_y] * o2 + v * o1;
2267 p += out->linesize[plane];
2274 static void draw_vtext16(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
2276 const uint8_t *font;
2280 font = avpriv_cga_font, font_height = 8;
2282 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2283 for (i = 0; txt[i]; i++) {
2285 int v = color[plane] * mult;
2287 for (char_y = 0; char_y < font_height; char_y++) {
2288 uint16_t *p = (uint16_t *)(out->data[plane] + (y + i * 10) * out->linesize[plane]) + x;
2289 for (mask = 0x80; mask; mask >>= 1) {
2290 if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
2291 p[char_y] = p[char_y] * o2 + v * o1;
2292 p += out->linesize[plane] / 2;
2299 static void graticule_none(WaveformContext *s, AVFrame *out)
2303 static void graticule_green_row(WaveformContext *s, AVFrame *out)
2305 const int step = (s->flags & 2) + 1;
2306 const float o1 = s->opacity;
2307 const float o2 = 1. - o1;
2308 const int height = s->display == PARADE ? out->height / s->acomp : out->height;
2309 int k = 0, c, p, l, offset_x = 0, offset_y = 0;
2311 for (c = 0; c < s->ncomp; c++) {
2312 if (!((1 << c) & s->pcomp) || (!s->display && k > 0))
2316 for (p = 0; p < s->ncomp; p++) {
2317 const int v = green_yuva_color[p];
2318 for (l = 0; l < s->nb_glines; l++) {
2319 const uint16_t pos = s->glines[l].line[c].pos;
2320 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos);
2321 uint8_t *dst = out->data[p] + offset_y * out->linesize[p] + x;
2323 blend_vline(dst, height, out->linesize[p], o1, o2, v, step);
2327 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2328 const char *name = s->glines[l].line[c].name;
2329 const uint16_t pos = s->glines[l].line[c].pos;
2330 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos) - 10;
2335 draw_vtext(out, x, offset_y + 2, o1, o2, name, green_yuva_color);
2338 offset_x += s->size * (s->display == STACK);
2339 offset_y += height * (s->display == PARADE);
2343 static void graticule16_green_row(WaveformContext *s, AVFrame *out)
2345 const int step = (s->flags & 2) + 1;
2346 const float o1 = s->opacity;
2347 const float o2 = 1. - o1;
2348 const int mult = s->size / 256;
2349 const int height = s->display == PARADE ? out->height / s->acomp : out->height;
2350 int k = 0, c, p, l, offset_x = 0, offset_y = 0;
2352 for (c = 0; c < s->ncomp; c++) {
2353 if (!((1 << c) & s->pcomp) || (!s->display && k > 0))
2357 for (p = 0; p < s->ncomp; p++) {
2358 const int v = green_yuva_color[p] * mult;
2359 for (l = 0; l < s->nb_glines ; l++) {
2360 const uint16_t pos = s->glines[l].line[c].pos;
2361 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos);
2362 uint16_t *dst = (uint16_t *)(out->data[p] + offset_y * out->linesize[p]) + x;
2364 blend_vline16(dst, height, out->linesize[p], o1, o2, v, step);
2368 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2369 const char *name = s->glines[l].line[c].name;
2370 const uint16_t pos = s->glines[l].line[c].pos;
2371 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos) - 10;
2376 draw_vtext16(out, x, offset_y + 2, mult, o1, o2, name, green_yuva_color);
2379 offset_x += s->size * (s->display == STACK);
2380 offset_y += height * (s->display == PARADE);
2384 static void graticule_green_column(WaveformContext *s, AVFrame *out)
2386 const int step = (s->flags & 2) + 1;
2387 const float o1 = s->opacity;
2388 const float o2 = 1. - o1;
2389 const int width = s->display == PARADE ? out->width / s->acomp : out->width;
2390 int k = 0, c, p, l, offset_y = 0, offset_x = 0;
2392 for (c = 0; c < s->ncomp; c++) {
2393 if ((!((1 << c) & s->pcomp) || (!s->display && k > 0)))
2397 for (p = 0; p < s->ncomp; p++) {
2398 const int v = green_yuva_color[p];
2399 for (l = 0; l < s->nb_glines ; l++) {
2400 const uint16_t pos = s->glines[l].line[c].pos;
2401 int y = offset_y + (s->mirror ? s->size - 1 - pos : pos);
2402 uint8_t *dst = out->data[p] + y * out->linesize[p] + offset_x;
2404 blend_hline(dst, width, o1, o2, v, step);
2408 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2409 const char *name = s->glines[l].line[c].name;
2410 const uint16_t pos = s->glines[l].line[c].pos;
2411 int y = offset_y + (s->mirror ? s->size - 1 - pos : pos) - 10;
2416 draw_htext(out, 2 + offset_x, y, o1, o2, name, green_yuva_color);
2419 offset_y += s->size * (s->display == STACK);
2420 offset_x += width * (s->display == PARADE);
2424 static void graticule16_green_column(WaveformContext *s, AVFrame *out)
2426 const int step = (s->flags & 2) + 1;
2427 const float o1 = s->opacity;
2428 const float o2 = 1. - o1;
2429 const int mult = s->size / 256;
2430 const int width = s->display == PARADE ? out->width / s->acomp : out->width;
2431 int k = 0, c, p, l, offset_x = 0, offset_y = 0;
2433 for (c = 0; c < s->ncomp; c++) {
2434 if ((!((1 << c) & s->pcomp) || (!s->display && k > 0)))
2438 for (p = 0; p < s->ncomp; p++) {
2439 const int v = green_yuva_color[p] * mult;
2440 for (l = 0; l < s->nb_glines ; l++) {
2441 const uint16_t pos = s->glines[l].line[c].pos;
2442 int y = offset_y + (s->mirror ? s->size - 1 - pos : pos);
2443 uint16_t *dst = (uint16_t *)(out->data[p] + y * out->linesize[p]) + offset_x;
2445 blend_hline16(dst, width, o1, o2, v, step);
2449 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2450 const char *name = s->glines[l].line[c].name;
2451 const uint16_t pos = s->glines[l].line[c].pos;
2452 int y = offset_y + (s->mirror ? s->size - 1 - pos: pos) - 10;
2457 draw_htext16(out, 2 + offset_x, y, mult, o1, o2, name, green_yuva_color);
2460 offset_y += s->size * (s->display == STACK);
2461 offset_x += width * (s->display == PARADE);
2465 static int config_input(AVFilterLink *inlink)
2467 AVFilterContext *ctx = inlink->dst;
2468 WaveformContext *s = ctx->priv;
2470 s->desc = av_pix_fmt_desc_get(inlink->format);
2471 s->ncomp = s->desc->nb_components;
2472 s->bits = s->desc->comp[0].depth;
2473 s->max = 1 << s->bits;
2474 s->intensity = s->fintensity * (s->max - 1);
2476 s->shift_w[0] = s->shift_w[3] = 0;
2477 s->shift_h[0] = s->shift_h[3] = 0;
2478 s->shift_w[1] = s->shift_w[2] = s->desc->log2_chroma_w;
2479 s->shift_h[1] = s->shift_h[2] = s->desc->log2_chroma_h;
2481 s->graticulef = graticule_none;
2483 switch (s->filter) {
2484 case AFLAT: s->size = 256 * 2; break;
2485 case FLAT: s->size = 256 * 3; break;
2486 default: s->size = 256; break;
2489 switch (s->filter | ((s->bits > 8) << 4) |
2490 (s->mode << 8) | (s->mirror << 12)) {
2491 case 0x1100: s->waveform = lowpass_column_mirror; break;
2492 case 0x1000: s->waveform = lowpass_row_mirror; break;
2493 case 0x0100: s->waveform = lowpass_column; break;
2494 case 0x0000: s->waveform = lowpass_row; break;
2495 case 0x1110: s->waveform = lowpass16_column_mirror; break;
2496 case 0x1010: s->waveform = lowpass16_row_mirror; break;
2497 case 0x0110: s->waveform = lowpass16_column; break;
2498 case 0x0010: s->waveform = lowpass16_row; break;
2502 case 0x0001: s->waveform = flat; break;
2506 case 0x0011: s->waveform = flat16; break;
2510 case 0x0002: s->waveform = aflat; break;
2514 case 0x0012: s->waveform = aflat16; break;
2518 case 0x0003: s->waveform = chroma; break;
2522 case 0x0013: s->waveform = chroma16; break;
2526 case 0x0004: s->waveform = color; break;
2530 case 0x0014: s->waveform = color16; break;
2534 case 0x0005: s->waveform = acolor; break;
2538 case 0x0015: s->waveform = acolor16; break;
2541 switch (s->filter) {
2548 if (s->graticule && s->mode == 1)
2549 s->graticulef = s->bits > 8 ? graticule16_green_column : graticule_green_column;
2550 else if (s->graticule && s->mode == 0)
2551 s->graticulef = s->bits > 8 ? graticule16_green_row : graticule_green_row;
2555 switch (s->filter) {
2562 case 8: s->glines = (GraticuleLines *)digital8; s->nb_glines = FF_ARRAY_ELEMS(digital8); break;
2563 case 9: s->glines = (GraticuleLines *)digital9; s->nb_glines = FF_ARRAY_ELEMS(digital9); break;
2564 case 10: s->glines = (GraticuleLines *)digital10; s->nb_glines = FF_ARRAY_ELEMS(digital10); break;
2565 case 12: s->glines = (GraticuleLines *)digital12; s->nb_glines = FF_ARRAY_ELEMS(digital12); break;
2570 case 8: s->glines = (GraticuleLines *)millivolts8; s->nb_glines = FF_ARRAY_ELEMS(millivolts8); break;
2571 case 9: s->glines = (GraticuleLines *)millivolts9; s->nb_glines = FF_ARRAY_ELEMS(millivolts9); break;
2572 case 10: s->glines = (GraticuleLines *)millivolts10; s->nb_glines = FF_ARRAY_ELEMS(millivolts10); break;
2573 case 12: s->glines = (GraticuleLines *)millivolts12; s->nb_glines = FF_ARRAY_ELEMS(millivolts12); break;
2578 case 8: s->glines = (GraticuleLines *)ire8; s->nb_glines = FF_ARRAY_ELEMS(ire8); break;
2579 case 9: s->glines = (GraticuleLines *)ire9; s->nb_glines = FF_ARRAY_ELEMS(ire9); break;
2580 case 10: s->glines = (GraticuleLines *)ire10; s->nb_glines = FF_ARRAY_ELEMS(ire10); break;
2581 case 12: s->glines = (GraticuleLines *)ire12; s->nb_glines = FF_ARRAY_ELEMS(ire12); break;
2590 case 8: s->glines = (GraticuleLines *)chroma_digital8; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital8); break;
2591 case 9: s->glines = (GraticuleLines *)chroma_digital9; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital9); break;
2592 case 10: s->glines = (GraticuleLines *)chroma_digital10; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital10); break;
2593 case 12: s->glines = (GraticuleLines *)chroma_digital12; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital12); break;
2598 case 8: s->glines = (GraticuleLines *)millivolts8; s->nb_glines = FF_ARRAY_ELEMS(millivolts8); break;
2599 case 9: s->glines = (GraticuleLines *)millivolts9; s->nb_glines = FF_ARRAY_ELEMS(millivolts9); break;
2600 case 10: s->glines = (GraticuleLines *)millivolts10; s->nb_glines = FF_ARRAY_ELEMS(millivolts10); break;
2601 case 12: s->glines = (GraticuleLines *)millivolts12; s->nb_glines = FF_ARRAY_ELEMS(millivolts12); break;
2606 case 8: s->glines = (GraticuleLines *)ire8; s->nb_glines = FF_ARRAY_ELEMS(ire8); break;
2607 case 9: s->glines = (GraticuleLines *)ire9; s->nb_glines = FF_ARRAY_ELEMS(ire9); break;
2608 case 10: s->glines = (GraticuleLines *)ire10; s->nb_glines = FF_ARRAY_ELEMS(ire10); break;
2609 case 12: s->glines = (GraticuleLines *)ire12; s->nb_glines = FF_ARRAY_ELEMS(ire12); break;
2618 case 8: s->glines = (GraticuleLines *)aflat_digital8; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital8); break;
2619 case 9: s->glines = (GraticuleLines *)aflat_digital9; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital9); break;
2620 case 10: s->glines = (GraticuleLines *)aflat_digital10; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital10); break;
2621 case 12: s->glines = (GraticuleLines *)aflat_digital12; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital12); break;
2626 case 8: s->glines = (GraticuleLines *)aflat_millivolts8; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts8); break;
2627 case 9: s->glines = (GraticuleLines *)aflat_millivolts9; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts9); break;
2628 case 10: s->glines = (GraticuleLines *)aflat_millivolts10; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts10); break;
2629 case 12: s->glines = (GraticuleLines *)aflat_millivolts12; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts12); break;
2634 case 8: s->glines = (GraticuleLines *)aflat_ire8; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire8); break;
2635 case 9: s->glines = (GraticuleLines *)aflat_ire9; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire9); break;
2636 case 10: s->glines = (GraticuleLines *)aflat_ire10; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire10); break;
2637 case 12: s->glines = (GraticuleLines *)aflat_ire12; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire12); break;
2646 case 8: s->glines = (GraticuleLines *)flat_digital8; s->nb_glines = FF_ARRAY_ELEMS(flat_digital8); break;
2647 case 9: s->glines = (GraticuleLines *)flat_digital9; s->nb_glines = FF_ARRAY_ELEMS(flat_digital9); break;
2648 case 10: s->glines = (GraticuleLines *)flat_digital10; s->nb_glines = FF_ARRAY_ELEMS(flat_digital10); break;
2649 case 12: s->glines = (GraticuleLines *)flat_digital12; s->nb_glines = FF_ARRAY_ELEMS(flat_digital12); break;
2654 case 8: s->glines = (GraticuleLines *)flat_millivolts8; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts8); break;
2655 case 9: s->glines = (GraticuleLines *)flat_millivolts9; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts9); break;
2656 case 10: s->glines = (GraticuleLines *)flat_millivolts10; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts10); break;
2657 case 12: s->glines = (GraticuleLines *)flat_millivolts12; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts12); break;
2662 case 8: s->glines = (GraticuleLines *)flat_ire8; s->nb_glines = FF_ARRAY_ELEMS(flat_ire8); break;
2663 case 9: s->glines = (GraticuleLines *)flat_ire9; s->nb_glines = FF_ARRAY_ELEMS(flat_ire9); break;
2664 case 10: s->glines = (GraticuleLines *)flat_ire10; s->nb_glines = FF_ARRAY_ELEMS(flat_ire10); break;
2665 case 12: s->glines = (GraticuleLines *)flat_ire12; s->nb_glines = FF_ARRAY_ELEMS(flat_ire12); break;
2672 s->size = s->size << (s->bits - 8);
2674 switch (inlink->format) {
2675 case AV_PIX_FMT_GBRAP:
2676 case AV_PIX_FMT_GBRP:
2677 case AV_PIX_FMT_GBRP9:
2678 case AV_PIX_FMT_GBRP10:
2679 case AV_PIX_FMT_GBRP12:
2680 memcpy(s->bg_color, black_gbrp_color, sizeof(s->bg_color));
2681 s->graticulef = graticule_none;
2684 memcpy(s->bg_color, black_yuva_color, sizeof(s->bg_color));
2687 s->bg_color[3] *= s->bgopacity;
2692 static int config_output(AVFilterLink *outlink)
2694 AVFilterContext *ctx = outlink->src;
2695 AVFilterLink *inlink = ctx->inputs[0];
2696 WaveformContext *s = ctx->priv;
2697 int comp = 0, i, j = 0, k, p, size;
2699 for (i = 0; i < s->ncomp; i++) {
2700 if ((1 << i) & s->pcomp)
2704 s->odesc = av_pix_fmt_desc_get(outlink->format);
2705 s->dcomp = s->odesc->nb_components;
2710 outlink->h = s->size * FFMAX(comp * (s->display == STACK), 1);
2711 outlink->w = inlink->w * FFMAX(comp * (s->display == PARADE), 1);
2714 outlink->w = s->size * FFMAX(comp * (s->display == STACK), 1);
2715 outlink->h = inlink->h * FFMAX(comp * (s->display == PARADE), 1);
2719 s->peak = av_malloc_array(size, 32 * sizeof(*s->peak));
2721 return AVERROR(ENOMEM);
2723 for (p = 0; p < s->ncomp; p++) {
2724 const int plane = s->desc->comp[p].plane;
2727 if (!((1 << p) & s->pcomp))
2730 for (k = 0; k < 4; k++) {
2731 s->emax[plane][k] = s->peak + size * (plane * 4 + k + 0);
2732 s->emin[plane][k] = s->peak + size * (plane * 4 + k + 16);
2735 offset = j++ * s->size * (s->display == STACK);
2736 s->estart[plane] = offset;
2737 s->eend[plane] = (offset + s->size - 1);
2738 for (i = 0; i < size; i++) {
2739 for (k = 0; k < 4; k++) {
2740 s->emax[plane][k][i] = s->estart[plane];
2741 s->emin[plane][k][i] = s->eend[plane];
2746 outlink->sample_aspect_ratio = (AVRational){1,1};
2751 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
2753 AVFilterContext *ctx = inlink->dst;
2754 WaveformContext *s = ctx->priv;
2755 AVFilterLink *outlink = ctx->outputs[0];
2759 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
2762 return AVERROR(ENOMEM);
2765 out->color_range = AVCOL_RANGE_JPEG;
2767 for (k = 0; k < s->dcomp; k++) {
2769 for (i = 0; i < outlink->h ; i++)
2770 memset(out->data[s->odesc->comp[k].plane] +
2771 i * out->linesize[s->odesc->comp[k].plane],
2772 s->bg_color[k], outlink->w);
2774 const int mult = s->max / 256;
2775 uint16_t *dst = (uint16_t *)out->data[s->odesc->comp[k].plane];
2777 for (i = 0; i < outlink->h ; i++) {
2778 for (j = 0; j < outlink->w; j++)
2779 dst[j] = s->bg_color[k] * mult;
2780 dst += out->linesize[s->odesc->comp[k].plane] / 2;
2785 for (k = 0, i = 0; k < s->ncomp; k++) {
2786 if ((1 << k) & s->pcomp) {
2790 if (s->display == PARADE) {
2791 offset_x = s->mode ? i++ * inlink->w : 0;
2792 offset_y = s->mode ? 0 : i++ * inlink->h;
2794 offset_y = s->mode ? i++ * s->size * !!s->display : 0;
2795 offset_x = s->mode ? 0 : i++ * s->size * !!s->display;
2797 s->waveform(s, in, out, k, s->intensity, offset_y, offset_x, s->mode, s->mirror);
2800 s->graticulef(s, out);
2803 return ff_filter_frame(outlink, out);
2806 static av_cold void uninit(AVFilterContext *ctx)
2808 WaveformContext *s = ctx->priv;
2813 static const AVFilterPad inputs[] = {
2816 .type = AVMEDIA_TYPE_VIDEO,
2817 .filter_frame = filter_frame,
2818 .config_props = config_input,
2823 static const AVFilterPad outputs[] = {
2826 .type = AVMEDIA_TYPE_VIDEO,
2827 .config_props = config_output,
2832 AVFilter ff_vf_waveform = {
2834 .description = NULL_IF_CONFIG_SMALL("Video waveform monitor."),
2835 .priv_size = sizeof(WaveformContext),
2836 .priv_class = &waveform_class,
2837 .query_formats = query_formats,