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"
32 typedef struct ThreadData {
65 typedef struct GraticuleLine {
70 typedef struct GraticuleLines {
71 struct GraticuleLine line[4];
74 typedef struct WaveformContext {
101 uint8_t grat_yuva_color[4];
102 int shift_w[4], shift_h[4];
103 GraticuleLines *glines;
107 int (*waveform_slice)(AVFilterContext *ctx, void *arg,
108 int jobnr, int nb_jobs);
109 void (*graticulef)(struct WaveformContext *s, AVFrame *out);
110 const AVPixFmtDescriptor *desc;
111 const AVPixFmtDescriptor *odesc;
114 #define OFFSET(x) offsetof(WaveformContext, x)
115 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
117 static const AVOption waveform_options[] = {
118 { "mode", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "mode" },
119 { "m", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "mode" },
120 { "row", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "mode" },
121 { "column", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "mode" },
122 { "intensity", "set intensity", OFFSET(fintensity), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 1, FLAGS },
123 { "i", "set intensity", OFFSET(fintensity), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 1, FLAGS },
124 { "mirror", "set mirroring", OFFSET(mirror), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
125 { "r", "set mirroring", OFFSET(mirror), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
126 { "display", "set display mode", OFFSET(display), AV_OPT_TYPE_INT, {.i64=STACK}, 0, NB_DISPLAYS-1, FLAGS, "display" },
127 { "d", "set display mode", OFFSET(display), AV_OPT_TYPE_INT, {.i64=STACK}, 0, NB_DISPLAYS-1, FLAGS, "display" },
128 { "overlay", NULL, 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY}, 0, 0, FLAGS, "display" },
129 { "stack", NULL, 0, AV_OPT_TYPE_CONST, {.i64=STACK}, 0, 0, FLAGS, "display" },
130 { "parade", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PARADE}, 0, 0, FLAGS, "display" },
131 { "components", "set components to display", OFFSET(pcomp), AV_OPT_TYPE_INT, {.i64=1}, 1, 15, FLAGS },
132 { "c", "set components to display", OFFSET(pcomp), AV_OPT_TYPE_INT, {.i64=1}, 1, 15, FLAGS },
133 { "envelope", "set envelope to display", OFFSET(envelope), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "envelope" },
134 { "e", "set envelope to display", OFFSET(envelope), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "envelope" },
135 { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "envelope" },
136 { "instant", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "envelope" },
137 { "peak", NULL, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "envelope" },
138 { "peak+instant", NULL, 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, FLAGS, "envelope" },
139 { "filter", "set filter", OFFSET(filter), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_FILTERS-1, FLAGS, "filter" },
140 { "f", "set filter", OFFSET(filter), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_FILTERS-1, FLAGS, "filter" },
141 { "lowpass", NULL, 0, AV_OPT_TYPE_CONST, {.i64=LOWPASS}, 0, 0, FLAGS, "filter" },
142 { "flat" , NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAT}, 0, 0, FLAGS, "filter" },
143 { "aflat" , NULL, 0, AV_OPT_TYPE_CONST, {.i64=AFLAT}, 0, 0, FLAGS, "filter" },
144 { "chroma", NULL, 0, AV_OPT_TYPE_CONST, {.i64=CHROMA}, 0, 0, FLAGS, "filter" },
145 { "color", NULL, 0, AV_OPT_TYPE_CONST, {.i64=COLOR}, 0, 0, FLAGS, "filter" },
146 { "acolor", NULL, 0, AV_OPT_TYPE_CONST, {.i64=ACOLOR}, 0, 0, FLAGS, "filter" },
147 { "xflat", NULL, 0, AV_OPT_TYPE_CONST, {.i64=XFLAT}, 0, 0, FLAGS, "filter" },
148 { "graticule", "set graticule", OFFSET(graticule), AV_OPT_TYPE_INT, {.i64=0}, 0, 2, FLAGS, "graticule" },
149 { "g", "set graticule", OFFSET(graticule), AV_OPT_TYPE_INT, {.i64=0}, 0, 2, FLAGS, "graticule" },
150 { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "graticule" },
151 { "green", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "graticule" },
152 { "orange", NULL, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "graticule" },
153 { "opacity", "set graticule opacity", OFFSET(opacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
154 { "o", "set graticule opacity", OFFSET(opacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
155 { "flags", "set graticule flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64=1}, 0, 3, FLAGS, "flags" },
156 { "fl", "set graticule flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64=1}, 0, 3, FLAGS, "flags" },
157 { "numbers", "draw numbers", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "flags" },
158 { "dots", "draw dots instead of lines", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "flags" },
159 { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SCALES-1, FLAGS, "scale" },
160 { "s", "set scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SCALES-1, FLAGS, "scale" },
161 { "digital", NULL, 0, AV_OPT_TYPE_CONST, {.i64=DIGITAL}, 0, 0, FLAGS, "scale" },
162 { "millivolts", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MILLIVOLTS}, 0, 0, FLAGS, "scale" },
163 { "ire", NULL, 0, AV_OPT_TYPE_CONST, {.i64=IRE}, 0, 0, FLAGS, "scale" },
164 { "bgopacity", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
165 { "b", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
169 AVFILTER_DEFINE_CLASS(waveform);
171 static const enum AVPixelFormat in_lowpass_pix_fmts[] = {
172 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
173 AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12,
174 AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
175 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
176 AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P,
177 AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
178 AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
179 AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
180 AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY9, AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12,
181 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9,
182 AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9,
183 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10,
184 AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10,
185 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV440P12,
189 static const enum AVPixelFormat in_color_pix_fmts[] = {
190 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
191 AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12,
192 AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
193 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
195 AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
196 AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
197 AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
198 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9,
199 AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9,
200 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10,
201 AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10,
202 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV440P12,
206 static const enum AVPixelFormat in_flat_pix_fmts[] = {
207 AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
208 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
210 AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
211 AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
212 AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
213 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9,
214 AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9,
215 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10,
216 AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10,
217 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV440P12,
221 static const enum AVPixelFormat out_rgb8_lowpass_pix_fmts[] = {
222 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
226 static const enum AVPixelFormat out_rgb9_lowpass_pix_fmts[] = {
231 static const enum AVPixelFormat out_rgb10_lowpass_pix_fmts[] = {
232 AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10,
236 static const enum AVPixelFormat out_rgb12_lowpass_pix_fmts[] = {
237 AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12,
241 static const enum AVPixelFormat out_yuv8_lowpass_pix_fmts[] = {
242 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVA444P,
246 static const enum AVPixelFormat out_yuv9_lowpass_pix_fmts[] = {
247 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUVA444P9,
251 static const enum AVPixelFormat out_yuv10_lowpass_pix_fmts[] = {
252 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUVA444P10,
256 static const enum AVPixelFormat out_yuv12_lowpass_pix_fmts[] = {
257 AV_PIX_FMT_YUV444P12,
261 static const enum AVPixelFormat out_gray8_lowpass_pix_fmts[] = {
266 static const enum AVPixelFormat out_gray9_lowpass_pix_fmts[] = {
271 static const enum AVPixelFormat out_gray10_lowpass_pix_fmts[] = {
276 static const enum AVPixelFormat out_gray12_lowpass_pix_fmts[] = {
281 static const enum AVPixelFormat flat_pix_fmts[] = {
282 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P,
283 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV444P10,
284 AV_PIX_FMT_YUV444P12,
288 static int query_formats(AVFilterContext *ctx)
290 WaveformContext *s = ctx->priv;
291 const enum AVPixelFormat *out_pix_fmts;
292 const enum AVPixelFormat *in_pix_fmts;
293 const AVPixFmtDescriptor *desc;
294 AVFilterFormats *avff;
295 int depth, rgb, i, ret, ncomp;
297 if (!ctx->inputs[0]->in_formats ||
298 !ctx->inputs[0]->in_formats->nb_formats) {
299 return AVERROR(EAGAIN);
303 case LOWPASS: in_pix_fmts = in_lowpass_pix_fmts; break;
307 case FLAT: in_pix_fmts = in_flat_pix_fmts; break;
309 case COLOR: in_pix_fmts = in_color_pix_fmts; break;
310 default: return AVERROR_BUG;
313 if (!ctx->inputs[0]->out_formats) {
314 if ((ret = ff_formats_ref(ff_make_format_list(in_pix_fmts), &ctx->inputs[0]->out_formats)) < 0)
318 avff = ctx->inputs[0]->in_formats;
319 desc = av_pix_fmt_desc_get(avff->formats[0]);
320 ncomp = desc->nb_components;
321 rgb = desc->flags & AV_PIX_FMT_FLAG_RGB;
322 depth = desc->comp[0].depth;
323 for (i = 1; i < avff->nb_formats; i++) {
324 desc = av_pix_fmt_desc_get(avff->formats[i]);
325 if (rgb != (desc->flags & AV_PIX_FMT_FLAG_RGB) ||
326 depth != desc->comp[0].depth)
327 return AVERROR(EAGAIN);
330 if (s->filter == LOWPASS && ncomp == 1 && depth == 8)
331 out_pix_fmts = out_gray8_lowpass_pix_fmts;
332 else if (s->filter == LOWPASS && ncomp == 1 && depth == 9)
333 out_pix_fmts = out_gray9_lowpass_pix_fmts;
334 else if (s->filter == LOWPASS && ncomp == 1 && depth == 10)
335 out_pix_fmts = out_gray10_lowpass_pix_fmts;
336 else if (s->filter == LOWPASS && ncomp == 1 && depth == 12)
337 out_pix_fmts = out_gray12_lowpass_pix_fmts;
338 else if (rgb && depth == 8 && ncomp > 2)
339 out_pix_fmts = out_rgb8_lowpass_pix_fmts;
340 else if (rgb && depth == 9 && ncomp > 2)
341 out_pix_fmts = out_rgb9_lowpass_pix_fmts;
342 else if (rgb && depth == 10 && ncomp > 2)
343 out_pix_fmts = out_rgb10_lowpass_pix_fmts;
344 else if (rgb && depth == 12 && ncomp > 2)
345 out_pix_fmts = out_rgb12_lowpass_pix_fmts;
346 else if (depth == 8 && ncomp > 2)
347 out_pix_fmts = out_yuv8_lowpass_pix_fmts;
348 else if (depth == 9 && ncomp > 2)
349 out_pix_fmts = out_yuv9_lowpass_pix_fmts;
350 else if (depth == 10 && ncomp > 2)
351 out_pix_fmts = out_yuv10_lowpass_pix_fmts;
352 else if (depth == 12 && ncomp > 2)
353 out_pix_fmts = out_yuv12_lowpass_pix_fmts;
355 return AVERROR(EAGAIN);
356 if ((ret = ff_formats_ref(ff_make_format_list(out_pix_fmts), &ctx->outputs[0]->in_formats)) < 0)
362 static void envelope_instant16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
364 const int dst_linesize = out->linesize[component] / 2;
365 const int bg = s->bg_color[component] * (s->max / 256);
366 const int limit = s->max - 1;
367 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
368 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
369 const int start = s->estart[plane];
370 const int end = s->eend[plane];
375 for (x = offset; x < offset + dst_w; x++) {
376 for (y = start; y < end; y++) {
377 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
383 for (y = end - 1; y >= start; y--) {
384 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
392 for (y = offset; y < offset + dst_h; y++) {
393 dst = (uint16_t *)out->data[component] + y * dst_linesize;
394 for (x = start; x < end; x++) {
400 for (x = end - 1; x >= start; x--) {
410 static void envelope_instant(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
412 const int dst_linesize = out->linesize[component];
413 const uint8_t bg = s->bg_color[component];
414 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
415 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
416 const int start = s->estart[plane];
417 const int end = s->eend[plane];
422 for (x = offset; x < offset + dst_w; x++) {
423 for (y = start; y < end; y++) {
424 dst = out->data[component] + y * dst_linesize + x;
430 for (y = end - 1; y >= start; y--) {
431 dst = out->data[component] + y * dst_linesize + x;
439 for (y = offset; y < offset + dst_h; y++) {
440 dst = out->data[component] + y * dst_linesize;
441 for (x = start; x < end; x++) {
447 for (x = end - 1; x >= start; x--) {
457 static void envelope_peak16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
459 const int dst_linesize = out->linesize[component] / 2;
460 const int bg = s->bg_color[component] * (s->max / 256);
461 const int limit = s->max - 1;
462 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
463 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
464 const int start = s->estart[plane];
465 const int end = s->eend[plane];
466 int *emax = s->emax[plane][component];
467 int *emin = s->emin[plane][component];
472 for (x = offset; x < offset + dst_w; x++) {
473 for (y = start; y < end && y < emin[x - offset]; y++) {
474 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
476 emin[x - offset] = y;
480 for (y = end - 1; y >= start && y >= emax[x - offset]; y--) {
481 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
483 emax[x - offset] = y;
489 if (s->envelope == 3)
490 envelope_instant16(s, out, plane, component, offset);
492 for (x = offset; x < offset + dst_w; x++) {
493 dst = (uint16_t *)out->data[component] + emin[x - offset] * dst_linesize + x;
495 dst = (uint16_t *)out->data[component] + emax[x - offset] * dst_linesize + x;
499 for (y = offset; y < offset + dst_h; y++) {
500 dst = (uint16_t *)out->data[component] + y * dst_linesize;
501 for (x = start; x < end && x < emin[y - offset]; x++) {
503 emin[y - offset] = x;
507 for (x = end - 1; x >= start && x >= emax[y - offset]; x--) {
509 emax[y - offset] = x;
515 if (s->envelope == 3)
516 envelope_instant16(s, out, plane, component, offset);
518 for (y = offset; y < offset + dst_h; y++) {
519 dst = (uint16_t *)out->data[component] + y * dst_linesize + emin[y - offset];
521 dst = (uint16_t *)out->data[component] + y * dst_linesize + emax[y - offset];
527 static void envelope_peak(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
529 const int dst_linesize = out->linesize[component];
530 const int bg = s->bg_color[component];
531 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
532 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
533 const int start = s->estart[plane];
534 const int end = s->eend[plane];
535 int *emax = s->emax[plane][component];
536 int *emin = s->emin[plane][component];
541 for (x = offset; x < offset + dst_w; x++) {
542 for (y = start; y < end && y < emin[x - offset]; y++) {
543 dst = out->data[component] + y * dst_linesize + x;
545 emin[x - offset] = y;
549 for (y = end - 1; y >= start && y >= emax[x - offset]; y--) {
550 dst = out->data[component] + y * dst_linesize + x;
552 emax[x - offset] = y;
558 if (s->envelope == 3)
559 envelope_instant(s, out, plane, component, offset);
561 for (x = offset; x < offset + dst_w; x++) {
562 dst = out->data[component] + emin[x - offset] * dst_linesize + x;
564 dst = out->data[component] + emax[x - offset] * dst_linesize + x;
568 for (y = offset; y < offset + dst_h; y++) {
569 dst = out->data[component] + y * dst_linesize;
570 for (x = start; x < end && x < emin[y - offset]; x++) {
572 emin[y - offset] = x;
576 for (x = end - 1; x >= start && x >= emax[y - offset]; x--) {
578 emax[y - offset] = x;
584 if (s->envelope == 3)
585 envelope_instant(s, out, plane, component, offset);
587 for (y = offset; y < offset + dst_h; y++) {
588 dst = out->data[component] + y * dst_linesize + emin[y - offset];
590 dst = out->data[component] + y * dst_linesize + emax[y - offset];
596 static void envelope16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
598 if (s->envelope == 0) {
600 } else if (s->envelope == 1) {
601 envelope_instant16(s, out, plane, component, offset);
603 envelope_peak16(s, out, plane, component, offset);
607 static void envelope(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
609 if (s->envelope == 0) {
611 } else if (s->envelope == 1) {
612 envelope_instant(s, out, plane, component, offset);
614 envelope_peak(s, out, plane, component, offset);
618 static void update16(uint16_t *target, int max, int intensity, int limit)
621 *target += intensity;
626 static void update(uint8_t *target, int max, int intensity)
629 *target += intensity;
634 static void update_cr(uint8_t *target, int unused, int intensity)
636 if (*target - intensity > 0)
637 *target -= intensity;
642 static void update16_cr(uint16_t *target, int unused, int intensity, int limit)
644 if (*target - intensity > 0)
645 *target -= intensity;
650 static av_always_inline void lowpass16(WaveformContext *s,
651 AVFrame *in, AVFrame *out,
652 int component, int intensity,
653 int offset_y, int offset_x,
654 int column, int mirror,
655 int jobnr, int nb_jobs)
657 const int plane = s->desc->comp[component].plane;
658 const int shift_w = s->shift_w[component];
659 const int shift_h = s->shift_h[component];
660 const int src_linesize = in->linesize[plane] / 2;
661 const int dst_linesize = out->linesize[plane] / 2;
662 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
663 const int limit = s->max - 1;
664 const int max = limit - intensity;
665 const int src_h = AV_CEIL_RSHIFT(in->height, shift_h);
666 const int src_w = AV_CEIL_RSHIFT(in->width, shift_w);
667 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
668 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
669 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
670 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
671 const int step = column ? 1 << shift_w : 1 << shift_h;
672 const uint16_t *src_data = (const uint16_t *)in->data[plane] + sliceh_start * src_linesize;
673 uint16_t *dst_data = (uint16_t *)out->data[plane] + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
674 uint16_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
675 uint16_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
679 if (!column && mirror)
682 for (y = sliceh_start; y < sliceh_end; y++) {
683 const uint16_t *src_data_end = src_data + slicew_end;
684 uint16_t *dst = dst_line + slicew_start * step;
686 for (p = src_data + slicew_start; p < src_data_end; p++) {
688 int i = 0, v = FFMIN(*p, limit);
692 target = dst++ + dst_signed_linesize * v;
693 update16(target, max, intensity, limit);
694 } while (++i < step);
696 uint16_t *row = dst_data;
699 target = row - v - 1;
702 update16(target, max, intensity, limit);
704 } while (++i < step);
707 src_data += src_linesize;
708 dst_data += dst_linesize * step;
712 #define LOWPASS16_FUNC(name, column, mirror) \
713 static int lowpass16_##name(AVFilterContext *ctx, \
714 void *arg, int jobnr, \
717 WaveformContext *s = ctx->priv; \
718 ThreadData *td = arg; \
719 AVFrame *in = td->in; \
720 AVFrame *out = td->out; \
721 int component = td->component; \
722 int offset_y = td->offset_y; \
723 int offset_x = td->offset_x; \
725 lowpass16(s, in, out, component, s->intensity, \
726 offset_y, offset_x, column, mirror, \
732 LOWPASS16_FUNC(column_mirror, 1, 1)
733 LOWPASS16_FUNC(column, 1, 0)
734 LOWPASS16_FUNC(row_mirror, 0, 1)
735 LOWPASS16_FUNC(row, 0, 0)
737 static av_always_inline void lowpass(WaveformContext *s,
738 AVFrame *in, AVFrame *out,
739 int component, int intensity,
740 int offset_y, int offset_x,
741 int column, int mirror,
742 int jobnr, int nb_jobs)
744 const int plane = s->desc->comp[component].plane;
745 const int shift_w = s->shift_w[component];
746 const int shift_h = s->shift_h[component];
747 const int src_linesize = in->linesize[plane];
748 const int dst_linesize = out->linesize[plane];
749 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
750 const int max = 255 - intensity;
751 const int src_h = AV_CEIL_RSHIFT(in->height, shift_h);
752 const int src_w = AV_CEIL_RSHIFT(in->width, shift_w);
753 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
754 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
755 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
756 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
757 const int step = column ? 1 << shift_w : 1 << shift_h;
758 const uint8_t *src_data = in->data[plane] + sliceh_start * src_linesize;
759 uint8_t *dst_data = out->data[plane] + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
760 uint8_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
761 uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
765 if (!column && mirror)
768 for (y = sliceh_start; y < sliceh_end; y++) {
769 const uint8_t *src_data_end = src_data + slicew_end;
770 uint8_t *dst = dst_line + slicew_start * step;
772 for (p = src_data + slicew_start; p < src_data_end; p++) {
775 target = dst + dst_signed_linesize * *p;
777 update(target, max, intensity);
779 uint8_t *row = dst_data;
781 target = row - *p - 1;
784 update(target, max, intensity);
788 src_data += src_linesize;
789 dst_data += dst_linesize * step;
792 if (column && step > 1) {
793 const int dst_h = 256;
797 dst = out->data[plane] + offset_y * dst_linesize + offset_x;
798 for (y = 0; y < dst_h; y++) {
799 for (x = slicew_start * step; x < slicew_end * step; x+=step) {
800 for (z = 1; z < step; z++) {
806 } else if (step > 1) {
807 const int dst_w = 256;
811 dst = out->data[plane] + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
812 for (y = sliceh_start * step; y < sliceh_end * step; y+=step) {
813 for (z = 1; z < step; z++)
814 memcpy(dst + dst_linesize * z, dst, dst_w);
815 dst += dst_linesize * step;
820 #define LOWPASS_FUNC(name, column, mirror) \
821 static int lowpass_##name(AVFilterContext *ctx, \
822 void *arg, int jobnr, \
825 WaveformContext *s = ctx->priv; \
826 ThreadData *td = arg; \
827 AVFrame *in = td->in; \
828 AVFrame *out = td->out; \
829 int component = td->component; \
830 int offset_y = td->offset_y; \
831 int offset_x = td->offset_x; \
833 lowpass(s, in, out, component, s->intensity, \
834 offset_y, offset_x, column, mirror, \
840 LOWPASS_FUNC(column_mirror, 1, 1)
841 LOWPASS_FUNC(column, 1, 0)
842 LOWPASS_FUNC(row_mirror, 0, 1)
843 LOWPASS_FUNC(row, 0, 0)
845 static av_always_inline void flat16(WaveformContext *s,
846 AVFrame *in, AVFrame *out,
847 int component, int intensity,
848 int offset_y, int offset_x,
849 int column, int mirror,
850 int jobnr, int nb_jobs)
852 const int plane = s->desc->comp[component].plane;
853 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
854 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
855 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
856 const int c0_shift_w = s->shift_w[ component + 0 ];
857 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
858 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
859 const int c0_shift_h = s->shift_h[ component + 0 ];
860 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
861 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
862 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
863 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
864 const int limit = s->max - 1;
865 const int max = limit - intensity;
866 const int mid = s->max / 2;
867 const int src_h = in->height;
868 const int src_w = in->width;
869 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
870 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
871 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
872 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
876 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
877 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
879 for (x = slicew_start; x < slicew_end; x++) {
880 const uint16_t *c0_data = (uint16_t *)in->data[plane + 0];
881 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
882 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
883 uint16_t *d0_data = (uint16_t *)(out->data[plane]) + offset_y * d0_linesize + offset_x;
884 uint16_t *d1_data = (uint16_t *)(out->data[(plane + 1) % s->ncomp]) + offset_y * d1_linesize + offset_x;
885 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
886 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
887 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
888 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
890 for (y = 0; y < src_h; y++) {
891 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + s->max;
892 const int c1 = FFMIN(FFABS(c1_data[x >> c1_shift_w] - mid) + FFABS(c2_data[x >> c2_shift_w] - mid), limit);
895 target = d0 + x + d0_signed_linesize * c0;
896 update16(target, max, intensity, limit);
897 target = d1 + x + d1_signed_linesize * (c0 - c1);
898 update16(target, max, intensity, limit);
899 target = d1 + x + d1_signed_linesize * (c0 + c1);
900 update16(target, max, intensity, limit);
902 if (!c0_shift_h || (y & c0_shift_h))
903 c0_data += c0_linesize;
904 if (!c1_shift_h || (y & c1_shift_h))
905 c1_data += c1_linesize;
906 if (!c2_shift_h || (y & c2_shift_h))
907 c2_data += c2_linesize;
908 d0_data += d0_linesize;
909 d1_data += d1_linesize;
913 const uint16_t *c0_data = (uint16_t *)(in->data[plane]) + (sliceh_start >> c0_shift_h) * c0_linesize;
914 const uint16_t *c1_data = (uint16_t *)(in->data[(plane + 1) % s->ncomp]) + (sliceh_start >> c1_shift_h) * c1_linesize;
915 const uint16_t *c2_data = (uint16_t *)(in->data[(plane + 2) % s->ncomp]) + (sliceh_start >> c2_shift_h) * c2_linesize;
916 uint16_t *d0_data = (uint16_t *)(out->data[plane]) + (offset_y + sliceh_start) * d0_linesize + offset_x;
917 uint16_t *d1_data = (uint16_t *)(out->data[(plane + 1) % s->ncomp]) + (offset_y + sliceh_start) * d1_linesize + offset_x;
920 d0_data += s->size - 1;
921 d1_data += s->size - 1;
924 for (y = sliceh_start; y < sliceh_end; y++) {
925 for (x = 0; x < src_w; x++) {
926 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + s->max;
927 const int c1 = FFMIN(FFABS(c1_data[x >> c1_shift_w] - mid) + FFABS(c2_data[x >> c2_shift_w] - mid), limit);
931 target = d0_data - c0;
932 update16(target, max, intensity, limit);
933 target = d1_data - (c0 - c1);
934 update16(target, max, intensity, limit);
935 target = d1_data - (c0 + c1);
936 update16(target, max, intensity, limit);
938 target = d0_data + c0;
939 update16(target, max, intensity, limit);
940 target = d1_data + (c0 - c1);
941 update16(target, max, intensity, limit);
942 target = d1_data + (c0 + c1);
943 update16(target, max, intensity, limit);
947 if (!c0_shift_h || (y & c0_shift_h))
948 c0_data += c0_linesize;
949 if (!c1_shift_h || (y & c1_shift_h))
950 c1_data += c1_linesize;
951 if (!c2_shift_h || (y & c2_shift_h))
952 c2_data += c2_linesize;
953 d0_data += d0_linesize;
954 d1_data += d1_linesize;
959 #define FLAT16_FUNC(name, column, mirror) \
960 static int flat16_##name(AVFilterContext *ctx, \
961 void *arg, int jobnr, \
964 WaveformContext *s = ctx->priv; \
965 ThreadData *td = arg; \
966 AVFrame *in = td->in; \
967 AVFrame *out = td->out; \
968 int component = td->component; \
969 int offset_y = td->offset_y; \
970 int offset_x = td->offset_x; \
972 flat16(s, in, out, component, s->intensity, \
973 offset_y, offset_x, column, mirror, \
979 FLAT16_FUNC(column_mirror, 1, 1)
980 FLAT16_FUNC(column, 1, 0)
981 FLAT16_FUNC(row_mirror, 0, 1)
982 FLAT16_FUNC(row, 0, 0)
984 static av_always_inline void flat(WaveformContext *s,
985 AVFrame *in, AVFrame *out,
986 int component, int intensity,
987 int offset_y, int offset_x,
988 int column, int mirror,
989 int jobnr, int nb_jobs)
991 const int plane = s->desc->comp[component].plane;
992 const int c0_linesize = in->linesize[ plane + 0 ];
993 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
994 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
995 const int c0_shift_w = s->shift_w[ component + 0 ];
996 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
997 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
998 const int c0_shift_h = s->shift_h[ component + 0 ];
999 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1000 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1001 const int d0_linesize = out->linesize[ plane + 0 ];
1002 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
1003 const int max = 255 - intensity;
1004 const int src_h = in->height;
1005 const int src_w = in->width;
1006 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
1007 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
1008 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
1009 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
1013 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1014 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1016 for (x = slicew_start; x < slicew_end; x++) {
1017 const uint8_t *c0_data = in->data[plane + 0];
1018 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1019 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1020 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1021 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1022 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1023 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1024 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1025 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1027 for (y = 0; y < src_h; y++) {
1028 const int c0 = c0_data[x >> c0_shift_w] + 256;
1029 const int c1 = FFABS(c1_data[x >> c1_shift_w] - 128) + FFABS(c2_data[x >> c2_shift_w] - 128);
1032 target = d0 + x + d0_signed_linesize * c0;
1033 update(target, max, intensity);
1034 target = d1 + x + d1_signed_linesize * (c0 - c1);
1035 update(target, max, intensity);
1036 target = d1 + x + d1_signed_linesize * (c0 + c1);
1037 update(target, max, intensity);
1039 if (!c0_shift_h || (y & c0_shift_h))
1040 c0_data += c0_linesize;
1041 if (!c1_shift_h || (y & c1_shift_h))
1042 c1_data += c1_linesize;
1043 if (!c2_shift_h || (y & c2_shift_h))
1044 c2_data += c2_linesize;
1045 d0_data += d0_linesize;
1046 d1_data += d1_linesize;
1050 const uint8_t *c0_data = in->data[plane] + (sliceh_start >> c0_shift_h) * c0_linesize;
1051 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize;
1052 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize;
1053 uint8_t *d0_data = out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x;
1054 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x;
1057 d0_data += s->size - 1;
1058 d1_data += s->size - 1;
1061 for (y = sliceh_start; y < sliceh_end; y++) {
1062 for (x = 0; x < src_w; x++) {
1063 const int c0 = c0_data[x >> c0_shift_w] + 256;
1064 const int c1 = FFABS(c1_data[x >> c1_shift_w] - 128) + FFABS(c2_data[x >> c2_shift_w] - 128);
1068 target = d0_data - c0;
1069 update(target, max, intensity);
1070 target = d1_data - (c0 - c1);
1071 update(target, max, intensity);
1072 target = d1_data - (c0 + c1);
1073 update(target, max, intensity);
1075 target = d0_data + c0;
1076 update(target, max, intensity);
1077 target = d1_data + (c0 - c1);
1078 update(target, max, intensity);
1079 target = d1_data + (c0 + c1);
1080 update(target, max, intensity);
1084 if (!c0_shift_h || (y & c0_shift_h))
1085 c0_data += c0_linesize;
1086 if (!c1_shift_h || (y & c1_shift_h))
1087 c1_data += c1_linesize;
1088 if (!c2_shift_h || (y & c2_shift_h))
1089 c2_data += c2_linesize;
1090 d0_data += d0_linesize;
1091 d1_data += d1_linesize;
1096 #define FLAT_FUNC(name, column, mirror) \
1097 static int flat_##name(AVFilterContext *ctx, \
1098 void *arg, int jobnr, \
1101 WaveformContext *s = ctx->priv; \
1102 ThreadData *td = arg; \
1103 AVFrame *in = td->in; \
1104 AVFrame *out = td->out; \
1105 int component = td->component; \
1106 int offset_y = td->offset_y; \
1107 int offset_x = td->offset_x; \
1109 flat(s, in, out, component, s->intensity, \
1110 offset_y, offset_x, column, mirror, \
1116 FLAT_FUNC(column_mirror, 1, 1)
1117 FLAT_FUNC(column, 1, 0)
1118 FLAT_FUNC(row_mirror, 0, 1)
1119 FLAT_FUNC(row, 0, 0)
1121 #define AFLAT16(name, update_cr, column, mirror) \
1122 static int name(AVFilterContext *ctx, \
1123 void *arg, int jobnr, \
1126 WaveformContext *s = ctx->priv; \
1127 ThreadData *td = arg; \
1128 AVFrame *in = td->in; \
1129 AVFrame *out = td->out; \
1130 int component = td->component; \
1131 int offset_y = td->offset_y; \
1132 int offset_x = td->offset_x; \
1133 const int intensity = s->intensity; \
1134 const int plane = s->desc->comp[component].plane; \
1135 const int c0_linesize = in->linesize[ plane + 0 ] / 2; \
1136 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2; \
1137 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2; \
1138 const int c0_shift_w = s->shift_w[ component + 0 ]; \
1139 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp]; \
1140 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp]; \
1141 const int c0_shift_h = s->shift_h[ component + 0 ]; \
1142 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp]; \
1143 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp]; \
1144 const int d0_linesize = out->linesize[ plane + 0 ] / 2; \
1145 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2; \
1146 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2; \
1147 const int limit = s->max - 1; \
1148 const int max = limit - intensity; \
1149 const int mid = s->max / 2; \
1150 const int src_h = in->height; \
1151 const int src_w = in->width; \
1152 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0; \
1153 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h; \
1154 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0; \
1155 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w; \
1159 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1); \
1160 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1); \
1161 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1); \
1163 for (x = slicew_start; x < slicew_end; x++) { \
1164 const uint16_t *c0_data = (uint16_t *)in->data[plane + 0]; \
1165 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp]; \
1166 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp]; \
1167 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x; \
1168 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x; \
1169 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x; \
1170 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1); \
1171 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data); \
1172 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1); \
1173 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data); \
1174 uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1); \
1175 uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data); \
1177 for (y = 0; y < src_h; y++) { \
1178 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + mid; \
1179 const int c1 = FFMIN(c1_data[x >> c1_shift_w], limit) - mid; \
1180 const int c2 = FFMIN(c2_data[x >> c2_shift_w], limit) - mid; \
1183 target = d0 + x + d0_signed_linesize * c0; \
1184 update16(target, max, intensity, limit); \
1186 target = d1 + x + d1_signed_linesize * (c0 + c1); \
1187 update16(target, max, intensity, limit); \
1189 target = d2 + x + d2_signed_linesize * (c0 + c2); \
1190 update_cr(target, max, intensity, limit); \
1192 if (!c0_shift_h || (y & c0_shift_h)) \
1193 c0_data += c0_linesize; \
1194 if (!c1_shift_h || (y & c1_shift_h)) \
1195 c1_data += c1_linesize; \
1196 if (!c2_shift_h || (y & c2_shift_h)) \
1197 c2_data += c2_linesize; \
1198 d0_data += d0_linesize; \
1199 d1_data += d1_linesize; \
1200 d2_data += d2_linesize; \
1204 const uint16_t *c0_data = (uint16_t *)in->data[plane] + (sliceh_start >> c0_shift_h) * c0_linesize; \
1205 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize; \
1206 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize; \
1207 uint16_t *d0_data = (uint16_t *)out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x; \
1208 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x; \
1209 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + (offset_y + sliceh_start) * d2_linesize + offset_x; \
1212 d0_data += s->size - 1; \
1213 d1_data += s->size - 1; \
1214 d2_data += s->size - 1; \
1217 for (y = sliceh_start; y < sliceh_end; y++) { \
1218 for (x = 0; x < src_w; x++) { \
1219 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + mid; \
1220 const int c1 = FFMIN(c1_data[x >> c1_shift_w], limit) - mid; \
1221 const int c2 = FFMIN(c2_data[x >> c2_shift_w], limit) - mid; \
1225 target = d0_data - c0; \
1226 update16(target, max, intensity, limit); \
1227 target = d1_data - (c0 + c1); \
1228 update16(target, max, intensity, limit); \
1229 target = d2_data - (c0 + c2); \
1230 update_cr(target, max, intensity, limit); \
1232 target = d0_data + c0; \
1233 update16(target, max, intensity, limit); \
1234 target = d1_data + (c0 + c1); \
1235 update16(target, max, intensity, limit); \
1236 target = d2_data + (c0 + c2); \
1237 update_cr(target, max, intensity, limit); \
1241 if (!c0_shift_h || (y & c0_shift_h)) \
1242 c0_data += c0_linesize; \
1243 if (!c1_shift_h || (y & c1_shift_h)) \
1244 c1_data += c1_linesize; \
1245 if (!c2_shift_h || (y & c2_shift_h)) \
1246 c2_data += c2_linesize; \
1247 d0_data += d0_linesize; \
1248 d1_data += d1_linesize; \
1249 d2_data += d2_linesize; \
1255 #define AFLAT(name, update_cr, column, mirror) \
1256 static int name(AVFilterContext *ctx, \
1257 void *arg, int jobnr, \
1260 WaveformContext *s = ctx->priv; \
1261 ThreadData *td = arg; \
1262 AVFrame *in = td->in; \
1263 AVFrame *out = td->out; \
1264 int component = td->component; \
1265 int offset_y = td->offset_y; \
1266 int offset_x = td->offset_x; \
1267 const int src_h = in->height; \
1268 const int src_w = in->width; \
1269 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0; \
1270 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h; \
1271 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0; \
1272 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w; \
1273 const int intensity = s->intensity; \
1274 const int plane = s->desc->comp[component].plane; \
1275 const int c0_linesize = in->linesize[ plane + 0 ]; \
1276 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp]; \
1277 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp]; \
1278 const int c0_shift_w = s->shift_w[ component + 0 ]; \
1279 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp]; \
1280 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp]; \
1281 const int c0_shift_h = s->shift_h[ component + 0 ]; \
1282 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp]; \
1283 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp]; \
1284 const int d0_linesize = out->linesize[ plane + 0 ]; \
1285 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp]; \
1286 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp]; \
1287 const int max = 255 - intensity; \
1291 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1); \
1292 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1); \
1293 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1); \
1295 for (x = slicew_start; x < slicew_end; x++) { \
1296 const uint8_t *c0_data = in->data[plane + 0]; \
1297 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp]; \
1298 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp]; \
1299 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x; \
1300 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x; \
1301 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x; \
1302 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1); \
1303 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data); \
1304 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1); \
1305 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data); \
1306 uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1); \
1307 uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data); \
1309 for (y = 0; y < src_h; y++) { \
1310 const int c0 = c0_data[x >> c0_shift_w] + 128; \
1311 const int c1 = c1_data[x >> c1_shift_w] - 128; \
1312 const int c2 = c2_data[x >> c2_shift_w] - 128; \
1315 target = d0 + x + d0_signed_linesize * c0; \
1316 update(target, max, intensity); \
1318 target = d1 + x + d1_signed_linesize * (c0 + c1); \
1319 update(target, max, intensity); \
1321 target = d2 + x + d2_signed_linesize * (c0 + c2); \
1322 update_cr(target, max, intensity); \
1324 if (!c0_shift_h || (y & c0_shift_h)) \
1325 c0_data += c0_linesize; \
1326 if (!c1_shift_h || (y & c1_shift_h)) \
1327 c1_data += c1_linesize; \
1328 if (!c1_shift_h || (y & c1_shift_h)) \
1329 c2_data += c1_linesize; \
1330 d0_data += d0_linesize; \
1331 d1_data += d1_linesize; \
1332 d2_data += d2_linesize; \
1336 const uint8_t *c0_data = in->data[plane] + (sliceh_start >> c0_shift_h) * c0_linesize; \
1337 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize; \
1338 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize; \
1339 uint8_t *d0_data = out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x; \
1340 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x; \
1341 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + (offset_y + sliceh_start) * d2_linesize + offset_x; \
1344 d0_data += s->size - 1; \
1345 d1_data += s->size - 1; \
1346 d2_data += s->size - 1; \
1349 for (y = sliceh_start; y < sliceh_end; y++) { \
1350 for (x = 0; x < src_w; x++) { \
1351 const int c0 = c0_data[x >> c0_shift_w] + 128; \
1352 const int c1 = c1_data[x >> c1_shift_w] - 128; \
1353 const int c2 = c2_data[x >> c2_shift_w] - 128; \
1357 target = d0_data - c0; \
1358 update(target, max, intensity); \
1359 target = d1_data - (c0 + c1); \
1360 update(target, max, intensity); \
1361 target = d2_data - (c0 + c2); \
1362 update_cr(target, max, intensity); \
1364 target = d0_data + c0; \
1365 update(target, max, intensity); \
1366 target = d1_data + (c0 + c1); \
1367 update(target, max, intensity); \
1368 target = d2_data + (c0 + c2); \
1369 update_cr(target, max, intensity); \
1373 if (!c0_shift_h || (y & c0_shift_h)) \
1374 c0_data += c0_linesize; \
1375 if (!c1_shift_h || (y & c1_shift_h)) \
1376 c1_data += c1_linesize; \
1377 if (!c2_shift_h || (y & c2_shift_h)) \
1378 c2_data += c2_linesize; \
1379 d0_data += d0_linesize; \
1380 d1_data += d1_linesize; \
1381 d2_data += d2_linesize; \
1387 AFLAT16(aflat16_row, update16, 0, 0)
1388 AFLAT16(aflat16_row_mirror, update16, 0, 1)
1389 AFLAT16(aflat16_column, update16, 1, 0)
1390 AFLAT16(aflat16_column_mirror, update16, 1, 1)
1391 AFLAT16(xflat16_row, update16_cr, 0, 0)
1392 AFLAT16(xflat16_row_mirror, update16_cr, 0, 1)
1393 AFLAT16(xflat16_column, update16_cr, 1, 0)
1394 AFLAT16(xflat16_column_mirror, update16_cr, 1, 1)
1396 AFLAT(aflat_row, update, 0, 0)
1397 AFLAT(aflat_row_mirror, update, 0, 1)
1398 AFLAT(aflat_column, update, 1, 0)
1399 AFLAT(aflat_column_mirror, update, 1, 1)
1400 AFLAT(xflat_row, update_cr, 0, 0)
1401 AFLAT(xflat_row_mirror, update_cr, 0, 1)
1402 AFLAT(xflat_column, update_cr, 1, 0)
1403 AFLAT(xflat_column_mirror, update_cr, 1, 1)
1405 static av_always_inline void chroma16(WaveformContext *s,
1406 AVFrame *in, AVFrame *out,
1407 int component, int intensity,
1408 int offset_y, int offset_x,
1409 int column, int mirror,
1410 int jobnr, int nb_jobs)
1412 const int plane = s->desc->comp[component].plane;
1413 const int c0_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1414 const int c1_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1415 const int dst_linesize = out->linesize[plane] / 2;
1416 const int limit = s->max - 1;
1417 const int max = limit - intensity;
1418 const int mid = s->max / 2;
1419 const int c0_shift_w = s->shift_w[(component + 1) % s->ncomp];
1420 const int c1_shift_w = s->shift_w[(component + 2) % s->ncomp];
1421 const int c0_shift_h = s->shift_h[(component + 1) % s->ncomp];
1422 const int c1_shift_h = s->shift_h[(component + 2) % s->ncomp];
1423 const int src_h = in->height;
1424 const int src_w = in->width;
1425 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
1426 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
1427 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
1428 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
1432 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
1434 for (x = slicew_start; x < slicew_end; x++) {
1435 const uint16_t *c0_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1436 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1437 uint16_t *dst_data = (uint16_t *)out->data[plane] + offset_y * dst_linesize + offset_x;
1438 uint16_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
1439 uint16_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
1440 uint16_t *dst = dst_line;
1442 for (y = 0; y < src_h; y++) {
1443 const int sum = FFMIN(FFABS(c0_data[x >> c0_shift_w] - mid) + FFABS(c1_data[x >> c1_shift_w] - mid - 1), limit);
1446 target = dst + x + dst_signed_linesize * sum;
1447 update16(target, max, intensity, limit);
1449 if (!c0_shift_h || (y & c0_shift_h))
1450 c0_data += c0_linesize;
1451 if (!c1_shift_h || (y & c1_shift_h))
1452 c1_data += c1_linesize;
1453 dst_data += dst_linesize;
1457 const uint16_t *c0_data = (uint16_t *)in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c0_shift_h) * c0_linesize;
1458 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize;
1459 uint16_t *dst_data = (uint16_t *)out->data[plane] + (offset_y + sliceh_start) * dst_linesize + offset_x;
1462 dst_data += s->size - 1;
1463 for (y = sliceh_start; y < sliceh_end; y++) {
1464 for (x = 0; x < src_w; x++) {
1465 const int sum = FFMIN(FFABS(c0_data[x >> c0_shift_w] - mid) + FFABS(c1_data[x >> c1_shift_w] - mid - 1), limit);
1469 target = dst_data - sum;
1470 update16(target, max, intensity, limit);
1472 target = dst_data + sum;
1473 update16(target, max, intensity, limit);
1477 if (!c0_shift_h || (y & c0_shift_h))
1478 c0_data += c0_linesize;
1479 if (!c1_shift_h || (y & c1_shift_h))
1480 c1_data += c1_linesize;
1481 dst_data += dst_linesize;
1486 #define CHROMA16_FUNC(name, column, mirror) \
1487 static int chroma16_##name(AVFilterContext *ctx, \
1488 void *arg, int jobnr, \
1491 WaveformContext *s = ctx->priv; \
1492 ThreadData *td = arg; \
1493 AVFrame *in = td->in; \
1494 AVFrame *out = td->out; \
1495 int component = td->component; \
1496 int offset_y = td->offset_y; \
1497 int offset_x = td->offset_x; \
1499 chroma16(s, in, out, component, s->intensity,\
1500 offset_y, offset_x, column, mirror, \
1506 CHROMA16_FUNC(column_mirror, 1, 1)
1507 CHROMA16_FUNC(column, 1, 0)
1508 CHROMA16_FUNC(row_mirror, 0, 1)
1509 CHROMA16_FUNC(row, 0, 0)
1511 static av_always_inline void chroma(WaveformContext *s,
1512 AVFrame *in, AVFrame *out,
1513 int component, int intensity,
1514 int offset_y, int offset_x,
1515 int column, int mirror,
1516 int jobnr, int nb_jobs)
1518 const int plane = s->desc->comp[component].plane;
1519 const int src_h = in->height;
1520 const int src_w = in->width;
1521 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
1522 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
1523 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
1524 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
1525 const int c0_linesize = in->linesize[(plane + 1) % s->ncomp];
1526 const int c1_linesize = in->linesize[(plane + 2) % s->ncomp];
1527 const int dst_linesize = out->linesize[plane];
1528 const int max = 255 - intensity;
1529 const int c0_shift_w = s->shift_w[(component + 1) % s->ncomp];
1530 const int c1_shift_w = s->shift_w[(component + 2) % s->ncomp];
1531 const int c0_shift_h = s->shift_h[(component + 1) % s->ncomp];
1532 const int c1_shift_h = s->shift_h[(component + 2) % s->ncomp];
1536 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
1538 for (x = slicew_start; x < slicew_end; x++) {
1539 const uint8_t *c0_data = in->data[(plane + 1) % s->ncomp];
1540 const uint8_t *c1_data = in->data[(plane + 2) % s->ncomp];
1541 uint8_t *dst_data = out->data[plane] + offset_y * dst_linesize + offset_x;
1542 uint8_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
1543 uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
1544 uint8_t *dst = dst_line;
1546 for (y = 0; y < src_h; y++) {
1547 const int sum = FFABS(c0_data[x >> c0_shift_w] - 128) + FFABS(c1_data[x >> c1_shift_w] - 127);
1550 target = dst + x + dst_signed_linesize * sum;
1551 update(target, max, intensity);
1553 if (!c0_shift_h || (y & c0_shift_h))
1554 c0_data += c0_linesize;
1555 if (!c1_shift_h || (y & c1_shift_h))
1556 c1_data += c1_linesize;
1557 dst_data += dst_linesize;
1561 const uint8_t *c0_data = in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c0_shift_h) * c0_linesize;
1562 const uint8_t *c1_data = in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize;
1563 uint8_t *dst_data = out->data[plane] + (offset_y + sliceh_start) * dst_linesize + offset_x;
1566 dst_data += s->size - 1;
1567 for (y = sliceh_start; y < sliceh_end; y++) {
1568 for (x = 0; x < src_w; x++) {
1569 const int sum = FFABS(c0_data[x >> c0_shift_w] - 128) + FFABS(c1_data[x >> c1_shift_w] - 127);
1573 target = dst_data - sum;
1574 update(target, max, intensity);
1576 target = dst_data + sum;
1577 update(target, max, intensity);
1581 if (!c0_shift_h || (y & c0_shift_h))
1582 c0_data += c0_linesize;
1583 if (!c1_shift_h || (y & c1_shift_h))
1584 c1_data += c1_linesize;
1585 dst_data += dst_linesize;
1590 #define CHROMA_FUNC(name, column, mirror) \
1591 static int chroma_##name(AVFilterContext *ctx, \
1592 void *arg, int jobnr, \
1595 WaveformContext *s = ctx->priv; \
1596 ThreadData *td = arg; \
1597 AVFrame *in = td->in; \
1598 AVFrame *out = td->out; \
1599 int component = td->component; \
1600 int offset_y = td->offset_y; \
1601 int offset_x = td->offset_x; \
1603 chroma(s, in, out, component, s->intensity, \
1604 offset_y, offset_x, column, mirror, \
1610 CHROMA_FUNC(column_mirror, 1, 1)
1611 CHROMA_FUNC(column, 1, 0)
1612 CHROMA_FUNC(row_mirror, 0, 1)
1613 CHROMA_FUNC(row, 0, 0)
1615 static av_always_inline void color16(WaveformContext *s,
1616 AVFrame *in, AVFrame *out,
1617 int component, int intensity,
1618 int offset_y, int offset_x,
1619 int column, int mirror,
1620 int jobnr, int nb_jobs)
1622 const int plane = s->desc->comp[component].plane;
1623 const int limit = s->max - 1;
1624 const int src_h = in->height;
1625 const int src_w = in->width;
1626 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
1627 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
1628 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
1629 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
1630 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
1631 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1632 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1633 const int c0_shift_h = s->shift_h[ component + 0 ];
1634 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1635 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1636 const uint16_t *c0_data = (const uint16_t *)in->data[plane + 0] + (sliceh_start >> c0_shift_h) * c0_linesize;
1637 const uint16_t *c1_data = (const uint16_t *)in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize;
1638 const uint16_t *c2_data = (const uint16_t *)in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize;
1639 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
1640 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
1641 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2;
1642 const int c0_shift_w = s->shift_w[ component + 0 ];
1643 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1644 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1648 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1649 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1650 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1651 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1652 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1653 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1654 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1655 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1656 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1657 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1658 uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1659 uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1661 for (y = 0; y < src_h; y++) {
1662 for (x = slicew_start; x < slicew_end; x++) {
1663 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1664 const int c1 = c1_data[x >> c1_shift_w];
1665 const int c2 = c2_data[x >> c2_shift_w];
1667 *(d0 + d0_signed_linesize * c0 + x) = c0;
1668 *(d1 + d1_signed_linesize * c0 + x) = c1;
1669 *(d2 + d2_signed_linesize * c0 + x) = c2;
1672 if (!c0_shift_h || (y & c0_shift_h))
1673 c0_data += c0_linesize;
1674 if (!c1_shift_h || (y & c1_shift_h))
1675 c1_data += c1_linesize;
1676 if (!c2_shift_h || (y & c2_shift_h))
1677 c2_data += c2_linesize;
1678 d0_data += d0_linesize;
1679 d1_data += d1_linesize;
1680 d2_data += d2_linesize;
1683 uint16_t *d0_data = (uint16_t *)out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x;
1684 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x;
1685 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + (offset_y + sliceh_start) * d2_linesize + offset_x;
1688 d0_data += s->size - 1;
1689 d1_data += s->size - 1;
1690 d2_data += s->size - 1;
1693 for (y = sliceh_start; y < sliceh_end; y++) {
1694 for (x = 0; x < src_w; x++) {
1695 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1696 const int c1 = c1_data[x >> c1_shift_w];
1697 const int c2 = c2_data[x >> c2_shift_w];
1700 *(d0_data - c0) = c0;
1701 *(d1_data - c0) = c1;
1702 *(d2_data - c0) = c2;
1704 *(d0_data + c0) = c0;
1705 *(d1_data + c0) = c1;
1706 *(d2_data + c0) = c2;
1710 if (!c0_shift_h || (y & c0_shift_h))
1711 c0_data += c0_linesize;
1712 if (!c1_shift_h || (y & c1_shift_h))
1713 c1_data += c1_linesize;
1714 if (!c2_shift_h || (y & c2_shift_h))
1715 c2_data += c2_linesize;
1716 d0_data += d0_linesize;
1717 d1_data += d1_linesize;
1718 d2_data += d2_linesize;
1723 #define COLOR16_FUNC(name, column, mirror) \
1724 static int color16_##name(AVFilterContext *ctx, \
1725 void *arg, int jobnr, \
1728 WaveformContext *s = ctx->priv; \
1729 ThreadData *td = arg; \
1730 AVFrame *in = td->in; \
1731 AVFrame *out = td->out; \
1732 int component = td->component; \
1733 int offset_y = td->offset_y; \
1734 int offset_x = td->offset_x; \
1736 color16(s, in, out, component, s->intensity, \
1737 offset_y, offset_x, column, mirror, \
1743 COLOR16_FUNC(column_mirror, 1, 1)
1744 COLOR16_FUNC(column, 1, 0)
1745 COLOR16_FUNC(row_mirror, 0, 1)
1746 COLOR16_FUNC(row, 0, 0)
1748 static av_always_inline void color(WaveformContext *s,
1749 AVFrame *in, AVFrame *out,
1750 int component, int intensity,
1751 int offset_y, int offset_x,
1752 int column, int mirror,
1753 int jobnr, int nb_jobs)
1755 const int plane = s->desc->comp[component].plane;
1756 const int src_h = in->height;
1757 const int src_w = in->width;
1758 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
1759 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
1760 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
1761 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
1762 const int c0_linesize = in->linesize[ plane + 0 ];
1763 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
1764 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
1765 const int c0_shift_h = s->shift_h[ component + 0 ];
1766 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1767 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1768 const uint8_t *c0_data = in->data[plane] + (sliceh_start >> c0_shift_h) * c0_linesize;
1769 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize;
1770 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize;
1771 const int d0_linesize = out->linesize[ plane + 0 ];
1772 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
1773 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp];
1774 const int c0_shift_w = s->shift_w[ component + 0 ];
1775 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1776 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1780 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1781 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1782 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1783 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1784 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1785 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1786 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1787 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1788 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1789 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1790 uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1791 uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1793 for (y = 0; y < src_h; y++) {
1794 for (x = slicew_start; x < slicew_end; x++) {
1795 const int c0 = c0_data[x >> c0_shift_w];
1796 const int c1 = c1_data[x >> c1_shift_w];
1797 const int c2 = c2_data[x >> c2_shift_w];
1799 *(d0 + d0_signed_linesize * c0 + x) = c0;
1800 *(d1 + d1_signed_linesize * c0 + x) = c1;
1801 *(d2 + d2_signed_linesize * c0 + x) = c2;
1804 if (!c0_shift_h || (y & c0_shift_h))
1805 c0_data += c0_linesize;
1806 if (!c1_shift_h || (y & c1_shift_h))
1807 c1_data += c1_linesize;
1808 if (!c2_shift_h || (y & c2_shift_h))
1809 c2_data += c2_linesize;
1810 d0_data += d0_linesize;
1811 d1_data += d1_linesize;
1812 d2_data += d2_linesize;
1815 uint8_t *d0_data = out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x;
1816 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x;
1817 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + (offset_y + sliceh_start) * d2_linesize + offset_x;
1820 d0_data += s->size - 1;
1821 d1_data += s->size - 1;
1822 d2_data += s->size - 1;
1825 for (y = sliceh_start; y < sliceh_end; y++) {
1826 for (x = 0; x < src_w; x++) {
1827 const int c0 = c0_data[x >> c0_shift_w];
1828 const int c1 = c1_data[x >> c1_shift_w];
1829 const int c2 = c2_data[x >> c2_shift_w];
1832 *(d0_data - c0) = c0;
1833 *(d1_data - c0) = c1;
1834 *(d2_data - c0) = c2;
1836 *(d0_data + c0) = c0;
1837 *(d1_data + c0) = c1;
1838 *(d2_data + c0) = c2;
1842 if (!c0_shift_h || (y & c0_shift_h))
1843 c0_data += c0_linesize;
1844 if (!c1_shift_h || (y & c1_shift_h))
1845 c1_data += c1_linesize;
1846 if (!c2_shift_h || (y & c2_shift_h))
1847 c2_data += c2_linesize;
1848 d0_data += d0_linesize;
1849 d1_data += d1_linesize;
1850 d2_data += d2_linesize;
1855 #define COLOR_FUNC(name, column, mirror) \
1856 static int color_##name(AVFilterContext *ctx, \
1857 void *arg, int jobnr, \
1860 WaveformContext *s = ctx->priv; \
1861 ThreadData *td = arg; \
1862 AVFrame *in = td->in; \
1863 AVFrame *out = td->out; \
1864 int component = td->component; \
1865 int offset_y = td->offset_y; \
1866 int offset_x = td->offset_x; \
1868 color(s, in, out, component, s->intensity, \
1869 offset_y, offset_x, column, mirror, \
1875 COLOR_FUNC(column_mirror, 1, 1)
1876 COLOR_FUNC(column, 1, 0)
1877 COLOR_FUNC(row_mirror, 0, 1)
1878 COLOR_FUNC(row, 0, 0)
1880 static av_always_inline void acolor16(WaveformContext *s,
1881 AVFrame *in, AVFrame *out,
1882 int component, int intensity,
1883 int offset_y, int offset_x,
1884 int column, int mirror,
1885 int jobnr, int nb_jobs)
1887 const int plane = s->desc->comp[component].plane;
1888 const int limit = s->max - 1;
1889 const int max = limit - intensity;
1890 const int src_h = in->height;
1891 const int src_w = in->width;
1892 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
1893 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
1894 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
1895 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
1896 const int c0_shift_h = s->shift_h[ component + 0 ];
1897 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1898 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1899 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
1900 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1901 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1902 const uint16_t *c0_data = (const uint16_t *)in->data[plane + 0] + (sliceh_start >> c0_shift_h) * c0_linesize;
1903 const uint16_t *c1_data = (const uint16_t *)in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize;
1904 const uint16_t *c2_data = (const uint16_t *)in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize;
1905 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
1906 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
1907 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2;
1908 const int c0_shift_w = s->shift_w[ component + 0 ];
1909 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1910 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1914 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1915 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1916 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1917 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1918 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1919 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1920 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1921 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1922 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1923 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1924 uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1925 uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1927 for (y = 0; y < src_h; y++) {
1928 for (x = slicew_start; x < slicew_end; x++) {
1929 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1930 const int c1 = c1_data[x >> c1_shift_w];
1931 const int c2 = c2_data[x >> c2_shift_w];
1933 update16(d0 + d0_signed_linesize * c0 + x, max, intensity, limit);
1934 *(d1 + d1_signed_linesize * c0 + x) = c1;
1935 *(d2 + d2_signed_linesize * c0 + x) = c2;
1938 if (!c0_shift_h || (y & c0_shift_h))
1939 c0_data += c0_linesize;
1940 if (!c1_shift_h || (y & c1_shift_h))
1941 c1_data += c1_linesize;
1942 if (!c2_shift_h || (y & c2_shift_h))
1943 c2_data += c2_linesize;
1944 d0_data += d0_linesize;
1945 d1_data += d1_linesize;
1946 d2_data += d2_linesize;
1949 uint16_t *d0_data = (uint16_t *)out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x;
1950 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x;
1951 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + (offset_y + sliceh_start) * d2_linesize + offset_x;
1954 d0_data += s->size - 1;
1955 d1_data += s->size - 1;
1956 d2_data += s->size - 1;
1959 for (y = sliceh_start; y < sliceh_end; y++) {
1960 for (x = 0; x < src_w; x++) {
1961 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1962 const int c1 = c1_data[x >> c1_shift_w];
1963 const int c2 = c2_data[x >> c2_shift_w];
1966 update16(d0_data - c0, max, intensity, limit);
1967 *(d1_data - c0) = c1;
1968 *(d2_data - c0) = c2;
1970 update16(d0_data + c0, max, intensity, limit);
1971 *(d1_data + c0) = c1;
1972 *(d2_data + c0) = c2;
1976 if (!c0_shift_h || (y & c0_shift_h))
1977 c0_data += c0_linesize;
1978 if (!c1_shift_h || (y & c1_shift_h))
1979 c1_data += c1_linesize;
1980 if (!c2_shift_h || (y & c2_shift_h))
1981 c2_data += c2_linesize;
1982 d0_data += d0_linesize;
1983 d1_data += d1_linesize;
1984 d2_data += d2_linesize;
1989 #define ACOLOR16_FUNC(name, column, mirror) \
1990 static int acolor16_##name(AVFilterContext *ctx, \
1991 void *arg, int jobnr, \
1994 WaveformContext *s = ctx->priv; \
1995 ThreadData *td = arg; \
1996 AVFrame *in = td->in; \
1997 AVFrame *out = td->out; \
1998 int component = td->component; \
1999 int offset_y = td->offset_y; \
2000 int offset_x = td->offset_x; \
2002 acolor16(s, in, out, component, s->intensity,\
2003 offset_y, offset_x, column, mirror, \
2009 ACOLOR16_FUNC(column_mirror, 1, 1)
2010 ACOLOR16_FUNC(column, 1, 0)
2011 ACOLOR16_FUNC(row_mirror, 0, 1)
2012 ACOLOR16_FUNC(row, 0, 0)
2014 static av_always_inline void acolor(WaveformContext *s,
2015 AVFrame *in, AVFrame *out,
2016 int component, int intensity,
2017 int offset_y, int offset_x,
2018 int column, int mirror,
2019 int jobnr, int nb_jobs)
2021 const int plane = s->desc->comp[component].plane;
2022 const int src_h = in->height;
2023 const int src_w = in->width;
2024 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
2025 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
2026 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
2027 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
2028 const int c0_shift_w = s->shift_w[ component + 0 ];
2029 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
2030 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
2031 const int c0_shift_h = s->shift_h[ component + 0 ];
2032 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
2033 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
2034 const int c0_linesize = in->linesize[ plane + 0 ];
2035 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
2036 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
2037 const uint8_t *c0_data = in->data[plane + 0] + (sliceh_start >> c0_shift_h) * c0_linesize;
2038 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize;
2039 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize;
2040 const int d0_linesize = out->linesize[ plane + 0 ];
2041 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
2042 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp];
2043 const int max = 255 - intensity;
2047 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
2048 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
2049 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
2050 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
2051 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
2052 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
2053 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
2054 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
2055 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
2056 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
2057 uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
2058 uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data);
2060 for (y = 0; y < src_h; y++) {
2061 for (x = slicew_start; x < slicew_end; x++) {
2062 const int c0 = c0_data[x >> c0_shift_w];
2063 const int c1 = c1_data[x >> c1_shift_w];
2064 const int c2 = c2_data[x >> c2_shift_w];
2066 update(d0 + d0_signed_linesize * c0 + x, max, intensity);
2067 *(d1 + d1_signed_linesize * c0 + x) = c1;
2068 *(d2 + d2_signed_linesize * c0 + x) = c2;
2071 if (!c0_shift_h || (y & c0_shift_h))
2072 c0_data += c0_linesize;
2073 if (!c1_shift_h || (y & c1_shift_h))
2074 c1_data += c1_linesize;
2075 if (!c2_shift_h || (y & c2_shift_h))
2076 c2_data += c2_linesize;
2077 d0_data += d0_linesize;
2078 d1_data += d1_linesize;
2079 d2_data += d2_linesize;
2082 uint8_t *d0_data = out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x;
2083 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x;
2084 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + (offset_y + sliceh_start) * d2_linesize + offset_x;
2087 d0_data += s->size - 1;
2088 d1_data += s->size - 1;
2089 d2_data += s->size - 1;
2092 for (y = sliceh_start; y < sliceh_end; y++) {
2093 for (x = 0; x < src_w; x++) {
2094 const int c0 = c0_data[x >> c0_shift_w];
2095 const int c1 = c1_data[x >> c1_shift_w];
2096 const int c2 = c2_data[x >> c2_shift_w];
2099 update(d0_data - c0, max, intensity);
2100 *(d1_data - c0) = c1;
2101 *(d2_data - c0) = c2;
2103 update(d0_data + c0, max, intensity);
2104 *(d1_data + c0) = c1;
2105 *(d2_data + c0) = c2;
2109 if (!c0_shift_h || (y & c0_shift_h))
2110 c0_data += c0_linesize;
2111 if (!c1_shift_h || (y & c1_shift_h))
2112 c1_data += c1_linesize;
2113 if (!c2_shift_h || (y & c2_shift_h))
2114 c2_data += c2_linesize;
2115 d0_data += d0_linesize;
2116 d1_data += d1_linesize;
2117 d2_data += d2_linesize;
2122 #define ACOLOR_FUNC(name, column, mirror) \
2123 static int acolor_##name(AVFilterContext *ctx, \
2124 void *arg, int jobnr, \
2127 WaveformContext *s = ctx->priv; \
2128 ThreadData *td = arg; \
2129 AVFrame *in = td->in; \
2130 AVFrame *out = td->out; \
2131 int component = td->component; \
2132 int offset_y = td->offset_y; \
2133 int offset_x = td->offset_x; \
2135 acolor(s, in, out, component, s->intensity, \
2136 offset_y, offset_x, column, mirror, \
2142 ACOLOR_FUNC(column_mirror, 1, 1)
2143 ACOLOR_FUNC(column, 1, 0)
2144 ACOLOR_FUNC(row_mirror, 0, 1)
2145 ACOLOR_FUNC(row, 0, 0)
2147 static const uint8_t black_yuva_color[4] = { 0, 127, 127, 255 };
2148 static const uint8_t black_gbrp_color[4] = { 0, 0, 0, 255 };
2150 static const GraticuleLines aflat_digital8[] = {
2151 { { { "16", 16+128 }, { "16", 16+128 }, { "16", 16+128 }, { "0", 0+128 } } },
2152 { { { "128", 128+128 }, { "128", 128+128 }, { "128", 128+128 }, { "128", 128+128 } } },
2153 { { { "235", 235+128 }, { "240", 240+128 }, { "240", 240+128 }, { "255", 255+128 } } },
2156 static const GraticuleLines aflat_digital9[] = {
2157 { { { "32", 32+256 }, { "32", 32+256 }, { "32", 32+256 }, { "0", 0+256 } } },
2158 { { { "256", 256+256 }, { "256", 256+256 }, { "256", 256+256 }, { "256", 256+256 } } },
2159 { { { "470", 470+256 }, { "480", 480+256 }, { "480", 480+256 }, { "511", 511+256 } } },
2162 static const GraticuleLines aflat_digital10[] = {
2163 { { { "64", 64+512 }, { "64", 64+512 }, { "64", 64+512 }, { "0", 0+512 } } },
2164 { { { "512", 512+512 }, { "512", 512+512 }, { "512", 512+512 }, { "512", 512+512 } } },
2165 { { { "940", 940+512 }, { "960", 960+512 }, { "960", 960+512 }, { "1023", 1023+512 } } },
2168 static const GraticuleLines aflat_digital12[] = {
2169 { { { "256", 256+2048 }, { "256", 256+2048 }, { "256", 256+2048 }, { "0", 0+2048 } } },
2170 { { { "2048", 2048+2048 }, { "2048", 2048+2048 }, { "2048", 2048+2048 }, { "2048", 2048+2048 } } },
2171 { { { "3760", 3760+2048 }, { "3840", 3840+2048 }, { "3840", 3840+2048 }, { "4095", 4095+2048 } } },
2174 static const GraticuleLines aflat_millivolts8[] = {
2175 { { { "0", 16+128 }, { "0", 16+128 }, { "0", 16+128 }, { "0", 0+128 } } },
2176 { { { "175", 71+128 }, { "175", 72+128 }, { "175", 72+128 }, { "175", 64+128 } } },
2177 { { { "350", 126+128 }, { "350", 128+128 }, { "350", 128+128 }, { "350", 128+128 } } },
2178 { { { "525", 180+128 }, { "525", 184+128 }, { "525", 184+128 }, { "525", 192+128 } } },
2179 { { { "700", 235+128 }, { "700", 240+128 }, { "700", 240+128 }, { "700", 255+128 } } },
2182 static const GraticuleLines aflat_millivolts9[] = {
2183 { { { "0", 32+256 }, { "0", 32+256 }, { "0", 32+256 }, { "0", 0+256 } } },
2184 { { { "175", 142+256 }, { "175", 144+256 }, { "175", 144+256 }, { "175", 128+256 } } },
2185 { { { "350", 251+256 }, { "350", 256+256 }, { "350", 256+256 }, { "350", 256+256 } } },
2186 { { { "525", 361+256 }, { "525", 368+256 }, { "525", 368+256 }, { "525", 384+256 } } },
2187 { { { "700", 470+256 }, { "700", 480+256 }, { "700", 480+256 }, { "700", 511+256 } } },
2190 static const GraticuleLines aflat_millivolts10[] = {
2191 { { { "0", 64+512 }, { "0", 64+512 }, { "0", 64+512 }, { "0", 0+512 } } },
2192 { { { "175", 283+512 }, { "175", 288+512 }, { "175", 288+512 }, { "175", 256+512 } } },
2193 { { { "350", 502+512 }, { "350", 512+512 }, { "350", 512+512 }, { "350", 512+512 } } },
2194 { { { "525", 721+512 }, { "525", 736+512 }, { "525", 736+512 }, { "525", 768+512 } } },
2195 { { { "700", 940+512 }, { "700", 960+512 }, { "700", 960+512 }, { "700", 1023+512 } } },
2198 static const GraticuleLines aflat_millivolts12[] = {
2199 { { { "0", 256+2048 }, { "0", 256+2048 }, { "0", 256+2048 }, { "0", 0+2048 } } },
2200 { { { "175", 1132+2048 }, { "175", 1152+2048 }, { "175", 1152+2048 }, { "175", 1024+2048 } } },
2201 { { { "350", 2008+2048 }, { "350", 2048+2048 }, { "350", 2048+2048 }, { "350", 2048+2048 } } },
2202 { { { "525", 2884+2048 }, { "525", 2944+2048 }, { "525", 2944+2048 }, { "525", 3072+2048 } } },
2203 { { { "700", 3760+2048 }, { "700", 3840+2048 }, { "700", 3840+2048 }, { "700", 4095+2048 } } },
2206 static const GraticuleLines aflat_ire8[] = {
2207 { { { "-25", -39+128 }, { "-25", -40+128 }, { "-25", -40+128 }, { "-25", -64+128 } } },
2208 { { { "0", 16+128 }, { "0", 16+128 }, { "0", 16+128 }, { "0", 0+128 } } },
2209 { { { "25", 71+128 }, { "25", 72+128 }, { "25", 72+128 }, { "25", 64+128 } } },
2210 { { { "50", 126+128 }, { "50", 128+128 }, { "50", 128+128 }, { "50", 128+128 } } },
2211 { { { "75", 180+128 }, { "75", 184+128 }, { "75", 184+128 }, { "75", 192+128 } } },
2212 { { { "100", 235+128 }, { "100", 240+128 }, { "100", 240+128 }, { "100", 256+128 } } },
2213 { { { "125", 290+128 }, { "125", 296+128 }, { "125", 296+128 }, { "125", 320+128 } } },
2216 static const GraticuleLines aflat_ire9[] = {
2217 { { { "-25", -78+256 }, { "-25", -80+256 }, { "-25", -80+256 }, { "-25",-128+256 } } },
2218 { { { "0", 32+256 }, { "0", 32+256 }, { "0", 32+256 }, { "0", 0+256 } } },
2219 { { { "25", 142+256 }, { "25", 144+256 }, { "25", 144+256 }, { "25", 128+256 } } },
2220 { { { "50", 251+256 }, { "50", 256+256 }, { "50", 256+256 }, { "50", 256+256 } } },
2221 { { { "75", 361+256 }, { "75", 368+256 }, { "75", 368+256 }, { "75", 384+256 } } },
2222 { { { "100", 470+256 }, { "100", 480+256 }, { "100", 480+256 }, { "100", 512+256 } } },
2223 { { { "125", 580+256 }, { "125", 592+256 }, { "125", 592+256 }, { "125", 640+256 } } },
2226 static const GraticuleLines aflat_ire10[] = {
2227 { { { "-25",-156+512 }, { "-25",-160+512 }, { "-25",-160+512 }, { "-25", -256+512 } } },
2228 { { { "0", 64+512 }, { "0", 64+512 }, { "0", 64+512 }, { "0", 0+512 } } },
2229 { { { "25", 283+512 }, { "25", 288+512 }, { "25", 288+512 }, { "25", 256+512 } } },
2230 { { { "50", 502+512 }, { "50", 512+512 }, { "50", 512+512 }, { "50", 512+512 } } },
2231 { { { "75", 721+512 }, { "75", 736+512 }, { "75", 736+512 }, { "75", 768+512 } } },
2232 { { { "100", 940+512 }, { "100", 960+512 }, { "100", 960+512 }, { "100", 1024+512 } } },
2233 { { { "125",1160+512 }, { "125",1184+512 }, { "125",1184+512 }, { "125", 1280+512 } } },
2236 static const GraticuleLines aflat_ire12[] = {
2237 { { { "-25", -624+2048 }, { "-25", -640+2048 }, { "-25", -640+2048 }, { "-25",-1024+2048 } } },
2238 { { { "0", 256+2048 }, { "0", 256+2048 }, { "0", 256+2048 }, { "0", 0+2048 } } },
2239 { { { "25", 1132+2048 }, { "25", 1152+2048 }, { "25", 1152+2048 }, { "25", 1024+2048 } } },
2240 { { { "50", 2008+2048 }, { "50", 2048+2048 }, { "50", 2048+2048 }, { "50", 2048+2048 } } },
2241 { { { "75", 2884+2048 }, { "75", 2944+2048 }, { "75", 2944+2048 }, { "75", 3072+2048 } } },
2242 { { { "100", 3760+2048 }, { "100", 3840+2048 }, { "100", 3840+2048 }, { "100", 4096+2048 } } },
2243 { { { "125", 4640+2048 }, { "125", 4736+2048 }, { "125", 4736+2048 }, { "125", 5120+2048 } } },
2246 static const GraticuleLines flat_digital8[] = {
2247 { { { "16", 16+256 }, { "16", 16+256 }, { "16", 16+256 }, { "0", 0+256 } } },
2248 { { { "128", 128+256 }, { "128", 128+256 }, { "128", 128+256 }, { "128", 128+256 } } },
2249 { { { "235", 235+256 }, { "240", 240+256 }, { "240", 240+256 }, { "255", 255+256 } } },
2252 static const GraticuleLines flat_digital9[] = {
2253 { { { "32", 32+512 }, { "32", 32+512 }, { "32", 32+512 }, { "0", 0+512 } } },
2254 { { { "256", 256+512 }, { "256", 256+512 }, { "256", 256+512 }, { "256", 256+512 } } },
2255 { { { "470", 470+512 }, { "480", 480+512 }, { "480", 480+512 }, { "511", 511+512 } } },
2258 static const GraticuleLines flat_digital10[] = {
2259 { { { "64", 64+1024 }, { "64", 64+1024 }, { "64", 64+1024 }, { "0", 0+1024 } } },
2260 { { { "512", 512+1024 }, { "512", 512+1024 }, { "512", 512+1024 }, { "512", 512+1024 } } },
2261 { { { "940", 940+1024 }, { "960", 960+1024 }, { "960", 960+1024 }, { "1023", 1023+1024 } } },
2264 static const GraticuleLines flat_digital12[] = {
2265 { { { "256", 256+4096 }, { "256", 256+4096 }, { "256", 256+4096 }, { "0", 0+4096 } } },
2266 { { { "2048", 2048+4096 }, { "2048", 2048+4096 }, { "2048", 2048+4096 }, { "2048", 2048+4096 } } },
2267 { { { "3760", 3760+4096 }, { "3840", 3840+4096 }, { "3840", 3840+4096 }, { "4095", 4095+4096 } } },
2270 static const GraticuleLines flat_millivolts8[] = {
2271 { { { "0", 16+256 }, { "0", 16+256 }, { "0", 16+256 }, { "0", 0+256 } } },
2272 { { { "175", 71+256 }, { "175", 72+256 }, { "175", 72+256 }, { "175", 64+256 } } },
2273 { { { "350", 126+256 }, { "350", 128+256 }, { "350", 128+256 }, { "350", 128+256 } } },
2274 { { { "525", 180+256 }, { "525", 184+256 }, { "525", 184+256 }, { "525", 192+256 } } },
2275 { { { "700", 235+256 }, { "700", 240+256 }, { "700", 240+256 }, { "700", 255+256 } } },
2278 static const GraticuleLines flat_millivolts9[] = {
2279 { { { "0", 32+512 }, { "0", 32+512 }, { "0", 32+512 }, { "0", 0+512 } } },
2280 { { { "175", 142+512 }, { "175", 144+512 }, { "175", 144+512 }, { "175", 128+512 } } },
2281 { { { "350", 251+512 }, { "350", 256+512 }, { "350", 256+512 }, { "350", 256+512 } } },
2282 { { { "525", 361+512 }, { "525", 368+512 }, { "525", 368+512 }, { "525", 384+512 } } },
2283 { { { "700", 470+512 }, { "700", 480+512 }, { "700", 480+512 }, { "700", 511+512 } } },
2286 static const GraticuleLines flat_millivolts10[] = {
2287 { { { "0", 64+1024 }, { "0", 64+1024 }, { "0", 64+1024 }, { "0", 0+1024 } } },
2288 { { { "175", 283+1024 }, { "175", 288+1024 }, { "175", 288+1024 }, { "175", 256+1024 } } },
2289 { { { "350", 502+1024 }, { "350", 512+1024 }, { "350", 512+1024 }, { "350", 512+1024 } } },
2290 { { { "525", 721+1024 }, { "525", 736+1024 }, { "525", 736+1024 }, { "525", 768+1024 } } },
2291 { { { "700", 940+1024 }, { "700", 960+1024 }, { "700", 960+1024 }, { "700", 1023+1024 } } },
2294 static const GraticuleLines flat_millivolts12[] = {
2295 { { { "0", 256+4096 }, { "0", 256+4096 }, { "0", 256+4096 }, { "0", 0+4096 } } },
2296 { { { "175", 1132+4096 }, { "175", 1152+4096 }, { "175", 1152+4096 }, { "175", 1024+4096 } } },
2297 { { { "350", 2008+4096 }, { "350", 2048+4096 }, { "350", 2048+4096 }, { "350", 2048+4096 } } },
2298 { { { "525", 2884+4096 }, { "525", 2944+4096 }, { "525", 2944+4096 }, { "525", 3072+4096 } } },
2299 { { { "700", 3760+4096 }, { "700", 3840+4096 }, { "700", 3840+4096 }, { "700", 4095+4096 } } },
2302 static const GraticuleLines flat_ire8[] = {
2303 { { { "-25", -39+256 }, { "-25", -40+256 }, { "-25", -40+256 }, { "-25", -64+256 } } },
2304 { { { "0", 16+256 }, { "0", 16+256 }, { "0", 16+256 }, { "0", 0+256 } } },
2305 { { { "25", 71+256 }, { "25", 72+256 }, { "25", 72+256 }, { "25", 64+256 } } },
2306 { { { "50", 126+256 }, { "50", 128+256 }, { "50", 128+256 }, { "50", 128+256 } } },
2307 { { { "75", 180+256 }, { "75", 184+256 }, { "75", 184+256 }, { "75", 192+256 } } },
2308 { { { "100", 235+256 }, { "100", 240+256 }, { "100", 240+256 }, { "100", 256+256 } } },
2309 { { { "125", 290+256 }, { "125", 296+256 }, { "125", 296+256 }, { "125", 320+256 } } },
2312 static const GraticuleLines flat_ire9[] = {
2313 { { { "-25", -78+512 }, { "-25", -80+512 }, { "-25", -80+512 }, { "-25",-128+512 } } },
2314 { { { "0", 32+512 }, { "0", 32+512 }, { "0", 32+512 }, { "0", 0+512 } } },
2315 { { { "25", 142+512 }, { "25", 144+512 }, { "25", 144+512 }, { "25", 128+512 } } },
2316 { { { "50", 251+512 }, { "50", 256+512 }, { "50", 256+512 }, { "50", 256+512 } } },
2317 { { { "75", 361+512 }, { "75", 368+512 }, { "75", 368+512 }, { "75", 384+512 } } },
2318 { { { "100", 470+512 }, { "100", 480+512 }, { "100", 480+512 }, { "100", 512+512 } } },
2319 { { { "125", 580+512 }, { "125", 592+512 }, { "125", 592+512 }, { "125", 640+512 } } },
2322 static const GraticuleLines flat_ire10[] = {
2323 { { { "-25",-156+1024 }, { "-25",-160+1024 }, { "-25",-160+1024 }, { "-25", -256+1024 } } },
2324 { { { "0", 64+1024 }, { "0", 64+1024 }, { "0", 64+1024 }, { "0", 0+1024 } } },
2325 { { { "25", 283+1024 }, { "25", 288+1024 }, { "25", 288+1024 }, { "25", 256+1024 } } },
2326 { { { "50", 502+1024 }, { "50", 512+1024 }, { "50", 512+1024 }, { "50", 512+1024 } } },
2327 { { { "75", 721+1024 }, { "75", 736+1024 }, { "75", 736+1024 }, { "75", 768+1024 } } },
2328 { { { "100", 940+1024 }, { "100", 960+1024 }, { "100", 960+1024 }, { "100", 1024+1024 } } },
2329 { { { "125",1160+1024 }, { "125",1184+1024 }, { "125",1184+1024 }, { "125", 1280+1024 } } },
2332 static const GraticuleLines flat_ire12[] = {
2333 { { { "-25", -624+4096 }, { "-25", -640+4096 }, { "-25", -640+4096 }, { "-25",-1024+4096 } } },
2334 { { { "0", 256+4096 }, { "0", 256+4096 }, { "0", 256+4096 }, { "0", 0+4096 } } },
2335 { { { "25", 1132+4096 }, { "25", 1152+4096 }, { "25", 1152+4096 }, { "25", 1024+4096 } } },
2336 { { { "50", 2008+4096 }, { "50", 2048+4096 }, { "50", 2048+4096 }, { "50", 2048+4096 } } },
2337 { { { "75", 2884+4096 }, { "75", 2944+4096 }, { "75", 2944+4096 }, { "75", 3072+4096 } } },
2338 { { { "100", 3760+4096 }, { "100", 3840+4096 }, { "100", 3840+4096 }, { "100", 4096+4096 } } },
2339 { { { "125", 4640+4096 }, { "125", 4736+4096 }, { "125", 4736+4096 }, { "125", 5120+4096 } } },
2342 static const GraticuleLines digital8[] = {
2343 { { { "16", 16 }, { "16", 16 }, { "16", 16 }, { "0", 0 } } },
2344 { { { "128", 128 }, { "128", 128 }, { "128", 128 }, { "128", 128 } } },
2345 { { { "235", 235 }, { "240", 240 }, { "240", 240 }, { "255", 255 } } },
2348 static const GraticuleLines digital9[] = {
2349 { { { "32", 32 }, { "32", 32 }, { "32", 32 }, { "0", 0 } } },
2350 { { { "256", 256 }, { "256", 256 }, { "256", 256 }, { "256", 256 } } },
2351 { { { "470", 470 }, { "480", 480 }, { "480", 480 }, { "511", 511 } } },
2354 static const GraticuleLines digital10[] = {
2355 { { { "64", 64 }, { "64", 64 }, { "64", 64 }, { "0", 0 } } },
2356 { { { "512", 512 }, { "512", 512 }, { "512", 512 }, { "512", 512 } } },
2357 { { { "940", 940 }, { "960", 960 }, { "960", 960 }, { "1023", 1023 } } },
2360 static const GraticuleLines digital12[] = {
2361 { { { "256", 256 }, { "256", 256 }, { "256", 256 }, { "0", 0 } } },
2362 { { { "2048", 2048 }, { "2048", 2048 }, { "2048", 2048 }, { "2048", 2048 } } },
2363 { { { "3760", 3760 }, { "3840", 3840 }, { "3840", 3840 }, { "4095", 4095 } } },
2366 static const GraticuleLines millivolts8[] = {
2367 { { { "0", 16 }, { "0", 16 }, { "0", 16 }, { "0", 0 } } },
2368 { { { "175", 71 }, { "175", 72 }, { "175", 72 }, { "175", 64 } } },
2369 { { { "350", 126 }, { "350", 128 }, { "350", 128 }, { "350", 128 } } },
2370 { { { "525", 180 }, { "525", 184 }, { "525", 184 }, { "525", 192 } } },
2371 { { { "700", 235 }, { "700", 240 }, { "700", 240 }, { "700", 255 } } },
2374 static const GraticuleLines millivolts9[] = {
2375 { { { "0", 32 }, { "0", 32 }, { "0", 32 }, { "0", 0 } } },
2376 { { { "175", 142 }, { "175", 144 }, { "175", 144 }, { "175", 128 } } },
2377 { { { "350", 251 }, { "350", 256 }, { "350", 256 }, { "350", 256 } } },
2378 { { { "525", 361 }, { "525", 368 }, { "525", 368 }, { "525", 384 } } },
2379 { { { "700", 470 }, { "700", 480 }, { "700", 480 }, { "700", 511 } } },
2382 static const GraticuleLines millivolts10[] = {
2383 { { { "0", 64 }, { "0", 64 }, { "0", 64 }, { "0", 0 } } },
2384 { { { "175", 283 }, { "175", 288 }, { "175", 288 }, { "175", 256 } } },
2385 { { { "350", 502 }, { "350", 512 }, { "350", 512 }, { "350", 512 } } },
2386 { { { "525", 721 }, { "525", 736 }, { "525", 736 }, { "525", 768 } } },
2387 { { { "700", 940 }, { "700", 960 }, { "700", 960 }, { "700", 1023 } } },
2390 static const GraticuleLines millivolts12[] = {
2391 { { { "0", 256 }, { "0", 256 }, { "0", 256 }, { "0", 0 } } },
2392 { { { "175", 1132 }, { "175", 1152 }, { "175", 1152 }, { "175", 1024 } } },
2393 { { { "350", 2008 }, { "350", 2048 }, { "350", 2048 }, { "350", 2048 } } },
2394 { { { "525", 2884 }, { "525", 2944 }, { "525", 2944 }, { "525", 3072 } } },
2395 { { { "700", 3760 }, { "700", 3840 }, { "700", 3840 }, { "700", 4095 } } },
2398 static const GraticuleLines ire8[] = {
2399 { { { "0", 16 }, { "0", 16 }, { "0", 16 }, { "0", 0 } } },
2400 { { { "25", 71 }, { "25", 72 }, { "25", 72 }, { "25", 64 } } },
2401 { { { "50", 126 }, { "50", 128 }, { "50", 128 }, { "50", 128 } } },
2402 { { { "75", 180 }, { "75", 184 }, { "75", 184 }, { "75", 192 } } },
2403 { { { "100", 235 }, { "100", 240 }, { "100", 240 }, { "100", 255 } } },
2406 static const GraticuleLines ire9[] = {
2407 { { { "0", 32 }, { "0", 32 }, { "0", 32 }, { "0", 0 } } },
2408 { { { "25", 142 }, { "25", 144 }, { "25", 144 }, { "25", 128 } } },
2409 { { { "50", 251 }, { "50", 256 }, { "50", 256 }, { "50", 256 } } },
2410 { { { "75", 361 }, { "75", 368 }, { "75", 368 }, { "75", 384 } } },
2411 { { { "100", 470 }, { "100", 480 }, { "100", 480 }, { "100", 511 } } },
2414 static const GraticuleLines ire10[] = {
2415 { { { "0", 64 }, { "0", 64 }, { "0", 64 }, { "0", 0 } } },
2416 { { { "25", 283 }, { "25", 288 }, { "25", 288 }, { "25", 256 } } },
2417 { { { "50", 502 }, { "50", 512 }, { "50", 512 }, { "50", 512 } } },
2418 { { { "75", 721 }, { "75", 736 }, { "75", 736 }, { "75", 768 } } },
2419 { { { "100", 940 }, { "100", 960 }, { "100", 960 }, { "100", 1023 } } },
2422 static const GraticuleLines ire12[] = {
2423 { { { "0", 256 }, { "0", 256 }, { "0", 256 }, { "0", 0 } } },
2424 { { { "25", 1132 }, { "25", 1152 }, { "25", 1152 }, { "25", 1024 } } },
2425 { { { "50", 2008 }, { "50", 2048 }, { "50", 2048 }, { "50", 2048 } } },
2426 { { { "75", 2884 }, { "75", 2944 }, { "75", 2944 }, { "75", 3072 } } },
2427 { { { "100", 3760 }, { "100", 3840 }, { "100", 3840 }, { "100", 4095 } } },
2430 static const GraticuleLines chroma_digital8[] = {
2431 { { { "50", 50 }, { "50", 50 }, { "50", 50 }, { "50", 50 } } },
2432 { { { "100", 100 }, { "100", 100 }, { "100", 100 }, { "100", 100 } } },
2433 { { { "150", 150 }, { "150", 150 }, { "150", 150 }, { "150", 150 } } },
2434 { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2435 { { { "255", 255 }, { "255", 255 }, { "255", 255 }, { "255", 255 } } },
2438 static const GraticuleLines chroma_digital9[] = {
2439 { { { "100", 100 }, { "100", 100 }, { "100", 100 }, { "100", 100 } } },
2440 { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2441 { { { "300", 300 }, { "300", 300 }, { "300", 300 }, { "300", 300 } } },
2442 { { { "400", 400 }, { "400", 400 }, { "400", 400 }, { "400", 400 } } },
2443 { { { "500", 500 }, { "500", 500 }, { "500", 500 }, { "500", 500 } } },
2446 static const GraticuleLines chroma_digital10[] = {
2447 { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2448 { { { "400", 400 }, { "400", 400 }, { "400", 400 }, { "400", 400 } } },
2449 { { { "600", 600 }, { "600", 600 }, { "600", 600 }, { "600", 600 } } },
2450 { { { "800", 800 }, { "800", 800 }, { "800", 800 }, { "800", 800 } } },
2451 { { {"1000",1000 }, {"1000",1000 }, {"1000",1000 }, {"1000",1000 } } },
2454 static const GraticuleLines chroma_digital12[] = {
2455 { { { "800", 800 }, { "800", 800 }, { "800", 800 }, { "800", 800 } } },
2456 { { { "1600", 1600 }, { "1600", 1600 }, { "1600", 1600 }, { "1600", 1600 } } },
2457 { { { "2400", 2400 }, { "2400", 2400 }, { "2400", 2400 }, { "2400", 2400 } } },
2458 { { { "3200", 3200 }, { "3200", 3200 }, { "3200", 3200 }, { "3200", 3200 } } },
2459 { { { "4000", 4000 }, { "4000", 4000 }, { "4000", 4000 }, { "4000", 4000 } } },
2462 static void blend_vline(uint8_t *dst, int height, int linesize, float o1, float o2, int v, int step)
2466 for (y = 0; y < height; y += step) {
2467 dst[0] = v * o1 + dst[0] * o2;
2469 dst += linesize * step;
2473 static void blend_vline16(uint16_t *dst, int height, int linesize, float o1, float o2, int v, int step)
2477 for (y = 0; y < height; y += step) {
2478 dst[0] = v * o1 + dst[0] * o2;
2480 dst += (linesize / 2) * step;
2484 static void blend_hline(uint8_t *dst, int width, float o1, float o2, int v, int step)
2488 for (x = 0; x < width; x += step) {
2489 dst[x] = v * o1 + dst[x] * o2;
2493 static void blend_hline16(uint16_t *dst, int width, float o1, float o2, int v, int step)
2497 for (x = 0; x < width; x += step) {
2498 dst[x] = v * o1 + dst[x] * o2;
2502 static void draw_htext(AVFrame *out, int x, int y, float o1, float o2, const char *txt, const uint8_t color[4])
2504 const uint8_t *font;
2508 font = avpriv_cga_font, font_height = 8;
2510 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2511 for (i = 0; txt[i]; i++) {
2513 int v = color[plane];
2515 uint8_t *p = out->data[plane] + y * out->linesize[plane] + (x + i * 8);
2516 for (char_y = 0; char_y < font_height; char_y++) {
2517 for (mask = 0x80; mask; mask >>= 1) {
2518 if (font[txt[i] * font_height + char_y] & mask)
2519 p[0] = p[0] * o2 + v * o1;
2522 p += out->linesize[plane] - 8;
2528 static void draw_htext16(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
2530 const uint8_t *font;
2534 font = avpriv_cga_font, font_height = 8;
2536 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2537 for (i = 0; txt[i]; i++) {
2539 int v = color[plane] * mult;
2541 uint16_t *p = (uint16_t *)(out->data[plane] + y * out->linesize[plane]) + (x + i * 8);
2542 for (char_y = 0; char_y < font_height; char_y++) {
2543 for (mask = 0x80; mask; mask >>= 1) {
2544 if (font[txt[i] * font_height + char_y] & mask)
2545 p[0] = p[0] * o2 + v * o1;
2548 p += out->linesize[plane] / 2 - 8;
2554 static void draw_vtext(AVFrame *out, int x, int y, float o1, float o2, const char *txt, const uint8_t color[4])
2556 const uint8_t *font;
2560 font = avpriv_cga_font, font_height = 8;
2562 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2563 for (i = 0; txt[i]; i++) {
2565 int v = color[plane];
2567 for (char_y = font_height - 1; char_y >= 0; char_y--) {
2568 uint8_t *p = out->data[plane] + (y + i * 10) * out->linesize[plane] + x;
2569 for (mask = 0x80; mask; mask >>= 1) {
2570 if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
2571 p[char_y] = p[char_y] * o2 + v * o1;
2572 p += out->linesize[plane];
2579 static void draw_vtext16(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
2581 const uint8_t *font;
2585 font = avpriv_cga_font, font_height = 8;
2587 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2588 for (i = 0; txt[i]; i++) {
2590 int v = color[plane] * mult;
2592 for (char_y = 0; char_y < font_height; char_y++) {
2593 uint16_t *p = (uint16_t *)(out->data[plane] + (y + i * 10) * out->linesize[plane]) + x;
2594 for (mask = 0x80; mask; mask >>= 1) {
2595 if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
2596 p[char_y] = p[char_y] * o2 + v * o1;
2597 p += out->linesize[plane] / 2;
2604 static void graticule_none(WaveformContext *s, AVFrame *out)
2608 static void graticule_row(WaveformContext *s, AVFrame *out)
2610 const int step = (s->flags & 2) + 1;
2611 const float o1 = s->opacity;
2612 const float o2 = 1. - o1;
2613 const int height = s->display == PARADE ? out->height / s->acomp : out->height;
2614 int C, k = 0, c, p, l, offset_x = 0, offset_y = 0;
2616 for (c = 0; c < s->ncomp; c++) {
2617 if (!((1 << c) & s->pcomp) || (!s->display && k > 0))
2622 for (p = 0; p < s->ncomp; p++) {
2623 const int v = s->grat_yuva_color[p];
2624 for (l = 0; l < s->nb_glines; l++) {
2625 const uint16_t pos = s->glines[l].line[C].pos;
2626 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos);
2627 uint8_t *dst = out->data[p] + offset_y * out->linesize[p] + x;
2629 blend_vline(dst, height, out->linesize[p], o1, o2, v, step);
2633 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2634 const char *name = s->glines[l].line[C].name;
2635 const uint16_t pos = s->glines[l].line[C].pos;
2636 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos) - 10;
2641 draw_vtext(out, x, offset_y + 2, o1, o2, name, s->grat_yuva_color);
2644 offset_x += s->size * (s->display == STACK);
2645 offset_y += height * (s->display == PARADE);
2649 static void graticule16_row(WaveformContext *s, AVFrame *out)
2651 const int step = (s->flags & 2) + 1;
2652 const float o1 = s->opacity;
2653 const float o2 = 1. - o1;
2654 const int mult = s->max / 256;
2655 const int height = s->display == PARADE ? out->height / s->acomp : out->height;
2656 int C, k = 0, c, p, l, offset_x = 0, offset_y = 0;
2658 for (c = 0; c < s->ncomp; c++) {
2659 if (!((1 << c) & s->pcomp) || (!s->display && k > 0))
2664 for (p = 0; p < s->ncomp; p++) {
2665 const int v = s->grat_yuva_color[p] * mult;
2666 for (l = 0; l < s->nb_glines ; l++) {
2667 const uint16_t pos = s->glines[l].line[C].pos;
2668 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos);
2669 uint16_t *dst = (uint16_t *)(out->data[p] + offset_y * out->linesize[p]) + x;
2671 blend_vline16(dst, height, out->linesize[p], o1, o2, v, step);
2675 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2676 const char *name = s->glines[l].line[C].name;
2677 const uint16_t pos = s->glines[l].line[C].pos;
2678 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos) - 10;
2683 draw_vtext16(out, x, offset_y + 2, mult, o1, o2, name, s->grat_yuva_color);
2686 offset_x += s->size * (s->display == STACK);
2687 offset_y += height * (s->display == PARADE);
2691 static void graticule_column(WaveformContext *s, AVFrame *out)
2693 const int step = (s->flags & 2) + 1;
2694 const float o1 = s->opacity;
2695 const float o2 = 1. - o1;
2696 const int width = s->display == PARADE ? out->width / s->acomp : out->width;
2697 int C, k = 0, c, p, l, offset_y = 0, offset_x = 0;
2699 for (c = 0; c < s->ncomp; c++) {
2700 if ((!((1 << c) & s->pcomp) || (!s->display && k > 0)))
2705 for (p = 0; p < s->ncomp; p++) {
2706 const int v = s->grat_yuva_color[p];
2707 for (l = 0; l < s->nb_glines ; l++) {
2708 const uint16_t pos = s->glines[l].line[C].pos;
2709 int y = offset_y + (s->mirror ? s->size - 1 - pos : pos);
2710 uint8_t *dst = out->data[p] + y * out->linesize[p] + offset_x;
2712 blend_hline(dst, width, o1, o2, v, step);
2716 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2717 const char *name = s->glines[l].line[C].name;
2718 const uint16_t pos = s->glines[l].line[C].pos;
2719 int y = offset_y + (s->mirror ? s->size - 1 - pos : pos) - 10;
2724 draw_htext(out, 2 + offset_x, y, o1, o2, name, s->grat_yuva_color);
2727 offset_y += s->size * (s->display == STACK);
2728 offset_x += width * (s->display == PARADE);
2732 static void graticule16_column(WaveformContext *s, AVFrame *out)
2734 const int step = (s->flags & 2) + 1;
2735 const float o1 = s->opacity;
2736 const float o2 = 1. - o1;
2737 const int mult = s->max / 256;
2738 const int width = s->display == PARADE ? out->width / s->acomp : out->width;
2739 int C, k = 0, c, p, l, offset_x = 0, offset_y = 0;
2741 for (c = 0; c < s->ncomp; c++) {
2742 if ((!((1 << c) & s->pcomp) || (!s->display && k > 0)))
2747 for (p = 0; p < s->ncomp; p++) {
2748 const int v = s->grat_yuva_color[p] * mult;
2749 for (l = 0; l < s->nb_glines ; l++) {
2750 const uint16_t pos = s->glines[l].line[C].pos;
2751 int y = offset_y + (s->mirror ? s->size - 1 - pos : pos);
2752 uint16_t *dst = (uint16_t *)(out->data[p] + y * out->linesize[p]) + offset_x;
2754 blend_hline16(dst, width, o1, o2, v, step);
2758 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2759 const char *name = s->glines[l].line[C].name;
2760 const uint16_t pos = s->glines[l].line[C].pos;
2761 int y = offset_y + (s->mirror ? s->size - 1 - pos: pos) - 10;
2766 draw_htext16(out, 2 + offset_x, y, mult, o1, o2, name, s->grat_yuva_color);
2769 offset_y += s->size * (s->display == STACK);
2770 offset_x += width * (s->display == PARADE);
2774 static int config_input(AVFilterLink *inlink)
2776 AVFilterContext *ctx = inlink->dst;
2777 WaveformContext *s = ctx->priv;
2779 s->desc = av_pix_fmt_desc_get(inlink->format);
2780 s->ncomp = s->desc->nb_components;
2781 s->bits = s->desc->comp[0].depth;
2782 s->max = 1 << s->bits;
2783 s->intensity = s->fintensity * (s->max - 1);
2785 s->shift_w[0] = s->shift_w[3] = 0;
2786 s->shift_h[0] = s->shift_h[3] = 0;
2787 s->shift_w[1] = s->shift_w[2] = s->desc->log2_chroma_w;
2788 s->shift_h[1] = s->shift_h[2] = s->desc->log2_chroma_h;
2790 s->graticulef = graticule_none;
2792 switch (s->filter) {
2794 case AFLAT: s->size = 256 * 2; break;
2795 case FLAT: s->size = 256 * 3; break;
2796 default: s->size = 256; break;
2799 switch (s->filter | ((s->bits > 8) << 4) |
2800 (s->mode << 8) | (s->mirror << 12)) {
2801 case 0x1100: s->waveform_slice = lowpass_column_mirror; break;
2802 case 0x1000: s->waveform_slice = lowpass_row_mirror; break;
2803 case 0x0100: s->waveform_slice = lowpass_column; break;
2804 case 0x0000: s->waveform_slice = lowpass_row; break;
2805 case 0x1110: s->waveform_slice = lowpass16_column_mirror; break;
2806 case 0x1010: s->waveform_slice = lowpass16_row_mirror; break;
2807 case 0x0110: s->waveform_slice = lowpass16_column; break;
2808 case 0x0010: s->waveform_slice = lowpass16_row; break;
2809 case 0x1101: s->waveform_slice = flat_column_mirror; break;
2810 case 0x1001: s->waveform_slice = flat_row_mirror; break;
2811 case 0x0101: s->waveform_slice = flat_column; break;
2812 case 0x0001: s->waveform_slice = flat_row; break;
2813 case 0x1111: s->waveform_slice = flat16_column_mirror; break;
2814 case 0x1011: s->waveform_slice = flat16_row_mirror; break;
2815 case 0x0111: s->waveform_slice = flat16_column; break;
2816 case 0x0011: s->waveform_slice = flat16_row; break;
2817 case 0x1102: s->waveform_slice = aflat_column_mirror; break;
2818 case 0x1002: s->waveform_slice = aflat_row_mirror; break;
2819 case 0x0102: s->waveform_slice = aflat_column; break;
2820 case 0x0002: s->waveform_slice = aflat_row; break;
2821 case 0x1112: s->waveform_slice = aflat16_column_mirror; break;
2822 case 0x1012: s->waveform_slice = aflat16_row_mirror; break;
2823 case 0x0112: s->waveform_slice = aflat16_column; break;
2824 case 0x0012: s->waveform_slice = aflat16_row; break;
2825 case 0x1103: s->waveform_slice = chroma_column_mirror; break;
2826 case 0x1003: s->waveform_slice = chroma_row_mirror; break;
2827 case 0x0103: s->waveform_slice = chroma_column; break;
2828 case 0x0003: s->waveform_slice = chroma_row; break;
2829 case 0x1113: s->waveform_slice = chroma16_column_mirror; break;
2830 case 0x1013: s->waveform_slice = chroma16_row_mirror; break;
2831 case 0x0113: s->waveform_slice = chroma16_column; break;
2832 case 0x0013: s->waveform_slice = chroma16_row; break;
2833 case 0x1104: s->waveform_slice = color_column_mirror; break;
2834 case 0x1004: s->waveform_slice = color_row_mirror; break;
2835 case 0x0104: s->waveform_slice = color_column; break;
2836 case 0x0004: s->waveform_slice = color_row; break;
2837 case 0x1114: s->waveform_slice = color16_column_mirror; break;
2838 case 0x1014: s->waveform_slice = color16_row_mirror; break;
2839 case 0x0114: s->waveform_slice = color16_column; break;
2840 case 0x0014: s->waveform_slice = color16_row; break;
2841 case 0x1105: s->waveform_slice = acolor_column_mirror; break;
2842 case 0x1005: s->waveform_slice = acolor_row_mirror; break;
2843 case 0x0105: s->waveform_slice = acolor_column; break;
2844 case 0x0005: s->waveform_slice = acolor_row; break;
2845 case 0x1115: s->waveform_slice = acolor16_column_mirror; break;
2846 case 0x1015: s->waveform_slice = acolor16_row_mirror; break;
2847 case 0x0115: s->waveform_slice = acolor16_column; break;
2848 case 0x0015: s->waveform_slice = acolor16_row; break;
2849 case 0x1106: s->waveform_slice = xflat_column_mirror; break;
2850 case 0x1006: s->waveform_slice = xflat_row_mirror; break;
2851 case 0x0106: s->waveform_slice = xflat_column; break;
2852 case 0x0006: s->waveform_slice = xflat_row; break;
2853 case 0x1116: s->waveform_slice = xflat16_column_mirror; break;
2854 case 0x1016: s->waveform_slice = xflat16_row_mirror; break;
2855 case 0x0116: s->waveform_slice = xflat16_column; break;
2856 case 0x0016: s->waveform_slice = xflat16_row; break;
2859 s->grat_yuva_color[0] = 255;
2860 s->grat_yuva_color[2] = s->graticule == 2 ? 255 : 0;
2861 s->grat_yuva_color[3] = 255;
2863 switch (s->filter) {
2871 if (s->graticule && s->mode == 1)
2872 s->graticulef = s->bits > 8 ? graticule16_column : graticule_column;
2873 else if (s->graticule && s->mode == 0)
2874 s->graticulef = s->bits > 8 ? graticule16_row : graticule_row;
2878 switch (s->filter) {
2885 case 8: s->glines = (GraticuleLines *)digital8; s->nb_glines = FF_ARRAY_ELEMS(digital8); break;
2886 case 9: s->glines = (GraticuleLines *)digital9; s->nb_glines = FF_ARRAY_ELEMS(digital9); break;
2887 case 10: s->glines = (GraticuleLines *)digital10; s->nb_glines = FF_ARRAY_ELEMS(digital10); break;
2888 case 12: s->glines = (GraticuleLines *)digital12; s->nb_glines = FF_ARRAY_ELEMS(digital12); break;
2893 case 8: s->glines = (GraticuleLines *)millivolts8; s->nb_glines = FF_ARRAY_ELEMS(millivolts8); break;
2894 case 9: s->glines = (GraticuleLines *)millivolts9; s->nb_glines = FF_ARRAY_ELEMS(millivolts9); break;
2895 case 10: s->glines = (GraticuleLines *)millivolts10; s->nb_glines = FF_ARRAY_ELEMS(millivolts10); break;
2896 case 12: s->glines = (GraticuleLines *)millivolts12; s->nb_glines = FF_ARRAY_ELEMS(millivolts12); break;
2901 case 8: s->glines = (GraticuleLines *)ire8; s->nb_glines = FF_ARRAY_ELEMS(ire8); break;
2902 case 9: s->glines = (GraticuleLines *)ire9; s->nb_glines = FF_ARRAY_ELEMS(ire9); break;
2903 case 10: s->glines = (GraticuleLines *)ire10; s->nb_glines = FF_ARRAY_ELEMS(ire10); break;
2904 case 12: s->glines = (GraticuleLines *)ire12; s->nb_glines = FF_ARRAY_ELEMS(ire12); break;
2913 case 8: s->glines = (GraticuleLines *)chroma_digital8; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital8); break;
2914 case 9: s->glines = (GraticuleLines *)chroma_digital9; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital9); break;
2915 case 10: s->glines = (GraticuleLines *)chroma_digital10; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital10); break;
2916 case 12: s->glines = (GraticuleLines *)chroma_digital12; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital12); break;
2921 case 8: s->glines = (GraticuleLines *)millivolts8; s->nb_glines = FF_ARRAY_ELEMS(millivolts8); break;
2922 case 9: s->glines = (GraticuleLines *)millivolts9; s->nb_glines = FF_ARRAY_ELEMS(millivolts9); break;
2923 case 10: s->glines = (GraticuleLines *)millivolts10; s->nb_glines = FF_ARRAY_ELEMS(millivolts10); break;
2924 case 12: s->glines = (GraticuleLines *)millivolts12; s->nb_glines = FF_ARRAY_ELEMS(millivolts12); break;
2929 case 8: s->glines = (GraticuleLines *)ire8; s->nb_glines = FF_ARRAY_ELEMS(ire8); break;
2930 case 9: s->glines = (GraticuleLines *)ire9; s->nb_glines = FF_ARRAY_ELEMS(ire9); break;
2931 case 10: s->glines = (GraticuleLines *)ire10; s->nb_glines = FF_ARRAY_ELEMS(ire10); break;
2932 case 12: s->glines = (GraticuleLines *)ire12; s->nb_glines = FF_ARRAY_ELEMS(ire12); break;
2942 case 8: s->glines = (GraticuleLines *)aflat_digital8; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital8); break;
2943 case 9: s->glines = (GraticuleLines *)aflat_digital9; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital9); break;
2944 case 10: s->glines = (GraticuleLines *)aflat_digital10; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital10); break;
2945 case 12: s->glines = (GraticuleLines *)aflat_digital12; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital12); break;
2950 case 8: s->glines = (GraticuleLines *)aflat_millivolts8; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts8); break;
2951 case 9: s->glines = (GraticuleLines *)aflat_millivolts9; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts9); break;
2952 case 10: s->glines = (GraticuleLines *)aflat_millivolts10; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts10); break;
2953 case 12: s->glines = (GraticuleLines *)aflat_millivolts12; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts12); break;
2958 case 8: s->glines = (GraticuleLines *)aflat_ire8; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire8); break;
2959 case 9: s->glines = (GraticuleLines *)aflat_ire9; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire9); break;
2960 case 10: s->glines = (GraticuleLines *)aflat_ire10; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire10); break;
2961 case 12: s->glines = (GraticuleLines *)aflat_ire12; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire12); break;
2970 case 8: s->glines = (GraticuleLines *)flat_digital8; s->nb_glines = FF_ARRAY_ELEMS(flat_digital8); break;
2971 case 9: s->glines = (GraticuleLines *)flat_digital9; s->nb_glines = FF_ARRAY_ELEMS(flat_digital9); break;
2972 case 10: s->glines = (GraticuleLines *)flat_digital10; s->nb_glines = FF_ARRAY_ELEMS(flat_digital10); break;
2973 case 12: s->glines = (GraticuleLines *)flat_digital12; s->nb_glines = FF_ARRAY_ELEMS(flat_digital12); break;
2978 case 8: s->glines = (GraticuleLines *)flat_millivolts8; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts8); break;
2979 case 9: s->glines = (GraticuleLines *)flat_millivolts9; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts9); break;
2980 case 10: s->glines = (GraticuleLines *)flat_millivolts10; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts10); break;
2981 case 12: s->glines = (GraticuleLines *)flat_millivolts12; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts12); break;
2986 case 8: s->glines = (GraticuleLines *)flat_ire8; s->nb_glines = FF_ARRAY_ELEMS(flat_ire8); break;
2987 case 9: s->glines = (GraticuleLines *)flat_ire9; s->nb_glines = FF_ARRAY_ELEMS(flat_ire9); break;
2988 case 10: s->glines = (GraticuleLines *)flat_ire10; s->nb_glines = FF_ARRAY_ELEMS(flat_ire10); break;
2989 case 12: s->glines = (GraticuleLines *)flat_ire12; s->nb_glines = FF_ARRAY_ELEMS(flat_ire12); break;
2996 s->size = s->size << (s->bits - 8);
2998 switch (inlink->format) {
2999 case AV_PIX_FMT_GBRAP:
3000 case AV_PIX_FMT_GBRP:
3001 case AV_PIX_FMT_GBRP9:
3002 case AV_PIX_FMT_GBRP10:
3003 case AV_PIX_FMT_GBRP12:
3005 memcpy(s->bg_color, black_gbrp_color, sizeof(s->bg_color));
3008 memcpy(s->bg_color, black_yuva_color, sizeof(s->bg_color));
3011 s->bg_color[3] *= s->bgopacity;
3016 static int config_output(AVFilterLink *outlink)
3018 AVFilterContext *ctx = outlink->src;
3019 AVFilterLink *inlink = ctx->inputs[0];
3020 WaveformContext *s = ctx->priv;
3021 int comp = 0, i, j = 0, k, p, size;
3023 for (i = 0; i < s->ncomp; i++) {
3024 if ((1 << i) & s->pcomp)
3029 return AVERROR(EINVAL);
3031 s->odesc = av_pix_fmt_desc_get(outlink->format);
3032 s->dcomp = s->odesc->nb_components;
3037 outlink->h = s->size * FFMAX(comp * (s->display == STACK), 1);
3038 outlink->w = inlink->w * FFMAX(comp * (s->display == PARADE), 1);
3041 outlink->w = s->size * FFMAX(comp * (s->display == STACK), 1);
3042 outlink->h = inlink->h * FFMAX(comp * (s->display == PARADE), 1);
3046 s->peak = av_malloc_array(size, 32 * sizeof(*s->peak));
3048 return AVERROR(ENOMEM);
3050 for (p = 0; p < s->ncomp; p++) {
3051 const int plane = s->desc->comp[p].plane;
3054 if (!((1 << p) & s->pcomp))
3057 for (k = 0; k < 4; k++) {
3058 s->emax[plane][k] = s->peak + size * (plane * 4 + k + 0);
3059 s->emin[plane][k] = s->peak + size * (plane * 4 + k + 16);
3062 offset = j++ * s->size * (s->display == STACK);
3063 s->estart[plane] = offset;
3064 s->eend[plane] = (offset + s->size - 1);
3065 for (i = 0; i < size; i++) {
3066 for (k = 0; k < 4; k++) {
3067 s->emax[plane][k][i] = s->estart[plane];
3068 s->emin[plane][k][i] = s->eend[plane];
3073 outlink->sample_aspect_ratio = (AVRational){1,1};
3078 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
3080 AVFilterContext *ctx = inlink->dst;
3081 WaveformContext *s = ctx->priv;
3082 AVFilterLink *outlink = ctx->outputs[0];
3086 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
3089 return AVERROR(ENOMEM);
3092 out->color_range = AVCOL_RANGE_JPEG;
3094 for (k = 0; k < s->dcomp; k++) {
3096 for (i = 0; i < outlink->h ; i++)
3097 memset(out->data[s->odesc->comp[k].plane] +
3098 i * out->linesize[s->odesc->comp[k].plane],
3099 s->bg_color[k], outlink->w);
3101 const int mult = s->max / 256;
3102 uint16_t *dst = (uint16_t *)out->data[s->odesc->comp[k].plane];
3104 for (i = 0; i < outlink->h ; i++) {
3105 for (j = 0; j < outlink->w; j++)
3106 dst[j] = s->bg_color[k] * mult;
3107 dst += out->linesize[s->odesc->comp[k].plane] / 2;
3112 for (k = 0, i = 0; k < s->ncomp; k++) {
3113 if ((1 << k) & s->pcomp) {
3114 const int plane = s->desc->comp[k].plane;
3119 if (s->display == PARADE) {
3120 offset_x = s->mode ? i++ * inlink->w : 0;
3121 offset_y = s->mode ? 0 : i++ * inlink->h;
3123 offset_y = s->mode ? i++ * s->size * !!s->display : 0;
3124 offset_x = s->mode ? 0 : i++ * s->size * !!s->display;
3130 td.offset_y = offset_y;
3131 td.offset_x = offset_x;
3132 ctx->internal->execute(ctx, s->waveform_slice, &td, NULL, ff_filter_get_nb_threads(ctx));
3133 switch (s->filter) {
3139 envelope(s, out, plane, plane, s->mode ? offset_x : offset_y);
3141 envelope16(s, out, plane, plane, s->mode ? offset_x : offset_y);
3145 envelope(s, out, plane, plane, s->mode ? offset_x : offset_y);
3146 envelope(s, out, plane, (plane + 1) % s->ncomp, s->mode ? offset_x : offset_y);
3148 envelope16(s, out, plane, plane, s->mode ? offset_x : offset_y);
3149 envelope16(s, out, plane, (plane + 1) % s->ncomp, s->mode ? offset_x : offset_y);
3155 envelope(s, out, plane, (plane + 0) % s->ncomp, s->mode ? offset_x : offset_y);
3156 envelope(s, out, plane, (plane + 1) % s->ncomp, s->mode ? offset_x : offset_y);
3157 envelope(s, out, plane, (plane + 2) % s->ncomp, s->mode ? offset_x : offset_y);
3159 envelope16(s, out, plane, (plane + 0) % s->ncomp, s->mode ? offset_x : offset_y);
3160 envelope16(s, out, plane, (plane + 1) % s->ncomp, s->mode ? offset_x : offset_y);
3161 envelope16(s, out, plane, (plane + 2) % s->ncomp, s->mode ? offset_x : offset_y);
3167 s->graticulef(s, out);
3170 return ff_filter_frame(outlink, out);
3173 static av_cold void uninit(AVFilterContext *ctx)
3175 WaveformContext *s = ctx->priv;
3180 static const AVFilterPad inputs[] = {
3183 .type = AVMEDIA_TYPE_VIDEO,
3184 .filter_frame = filter_frame,
3185 .config_props = config_input,
3190 static const AVFilterPad outputs[] = {
3193 .type = AVMEDIA_TYPE_VIDEO,
3194 .config_props = config_output,
3199 AVFilter ff_vf_waveform = {
3201 .description = NULL_IF_CONFIG_SMALL("Video waveform monitor."),
3202 .priv_size = sizeof(WaveformContext),
3203 .priv_class = &waveform_class,
3204 .query_formats = query_formats,
3208 .flags = AVFILTER_FLAG_SLICE_THREADS,