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;
106 int (*waveform_slice)(AVFilterContext *ctx, void *arg,
107 int jobnr, int nb_jobs);
108 void (*graticulef)(struct WaveformContext *s, AVFrame *out);
109 const AVPixFmtDescriptor *desc;
110 const AVPixFmtDescriptor *odesc;
113 #define OFFSET(x) offsetof(WaveformContext, x)
114 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
116 static const AVOption waveform_options[] = {
117 { "mode", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "mode" },
118 { "m", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "mode" },
119 { "row", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "mode" },
120 { "column", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "mode" },
121 { "intensity", "set intensity", OFFSET(fintensity), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 1, FLAGS },
122 { "i", "set intensity", OFFSET(fintensity), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 1, FLAGS },
123 { "mirror", "set mirroring", OFFSET(mirror), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
124 { "r", "set mirroring", OFFSET(mirror), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
125 { "display", "set display mode", OFFSET(display), AV_OPT_TYPE_INT, {.i64=STACK}, 0, NB_DISPLAYS-1, FLAGS, "display" },
126 { "d", "set display mode", OFFSET(display), AV_OPT_TYPE_INT, {.i64=STACK}, 0, NB_DISPLAYS-1, FLAGS, "display" },
127 { "overlay", NULL, 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY}, 0, 0, FLAGS, "display" },
128 { "stack", NULL, 0, AV_OPT_TYPE_CONST, {.i64=STACK}, 0, 0, FLAGS, "display" },
129 { "parade", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PARADE}, 0, 0, FLAGS, "display" },
130 { "components", "set components to display", OFFSET(pcomp), AV_OPT_TYPE_INT, {.i64=1}, 1, 15, FLAGS },
131 { "c", "set components to display", OFFSET(pcomp), AV_OPT_TYPE_INT, {.i64=1}, 1, 15, FLAGS },
132 { "envelope", "set envelope to display", OFFSET(envelope), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "envelope" },
133 { "e", "set envelope to display", OFFSET(envelope), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "envelope" },
134 { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "envelope" },
135 { "instant", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "envelope" },
136 { "peak", NULL, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "envelope" },
137 { "peak+instant", NULL, 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, FLAGS, "envelope" },
138 { "filter", "set filter", OFFSET(filter), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_FILTERS-1, FLAGS, "filter" },
139 { "f", "set filter", OFFSET(filter), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_FILTERS-1, FLAGS, "filter" },
140 { "lowpass", NULL, 0, AV_OPT_TYPE_CONST, {.i64=LOWPASS}, 0, 0, FLAGS, "filter" },
141 { "flat" , NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAT}, 0, 0, FLAGS, "filter" },
142 { "aflat" , NULL, 0, AV_OPT_TYPE_CONST, {.i64=AFLAT}, 0, 0, FLAGS, "filter" },
143 { "chroma", NULL, 0, AV_OPT_TYPE_CONST, {.i64=CHROMA}, 0, 0, FLAGS, "filter" },
144 { "color", NULL, 0, AV_OPT_TYPE_CONST, {.i64=COLOR}, 0, 0, FLAGS, "filter" },
145 { "acolor", NULL, 0, AV_OPT_TYPE_CONST, {.i64=ACOLOR}, 0, 0, FLAGS, "filter" },
146 { "xflat", NULL, 0, AV_OPT_TYPE_CONST, {.i64=XFLAT}, 0, 0, FLAGS, "filter" },
147 { "graticule", "set graticule", OFFSET(graticule), AV_OPT_TYPE_INT, {.i64=0}, 0, 2, FLAGS, "graticule" },
148 { "g", "set graticule", OFFSET(graticule), AV_OPT_TYPE_INT, {.i64=0}, 0, 2, FLAGS, "graticule" },
149 { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "graticule" },
150 { "green", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "graticule" },
151 { "orange", NULL, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "graticule" },
152 { "opacity", "set graticule opacity", OFFSET(opacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
153 { "o", "set graticule opacity", OFFSET(opacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
154 { "flags", "set graticule flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64=1}, 0, 3, FLAGS, "flags" },
155 { "fl", "set graticule flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64=1}, 0, 3, FLAGS, "flags" },
156 { "numbers", "draw numbers", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "flags" },
157 { "dots", "draw dots instead of lines", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "flags" },
158 { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SCALES-1, FLAGS, "scale" },
159 { "s", "set scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SCALES-1, FLAGS, "scale" },
160 { "digital", NULL, 0, AV_OPT_TYPE_CONST, {.i64=DIGITAL}, 0, 0, FLAGS, "scale" },
161 { "millivolts", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MILLIVOLTS}, 0, 0, FLAGS, "scale" },
162 { "ire", NULL, 0, AV_OPT_TYPE_CONST, {.i64=IRE}, 0, 0, FLAGS, "scale" },
163 { "bgopacity", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
164 { "b", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
168 AVFILTER_DEFINE_CLASS(waveform);
170 static const enum AVPixelFormat in_lowpass_pix_fmts[] = {
171 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
172 AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12,
173 AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
174 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
175 AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P,
176 AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
177 AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
178 AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
179 AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY9, AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12,
180 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9,
181 AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9,
182 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10,
183 AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10,
184 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV440P12,
188 static const enum AVPixelFormat in_color_pix_fmts[] = {
189 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
190 AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12,
191 AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
192 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
194 AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
195 AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
196 AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
197 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9,
198 AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9,
199 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10,
200 AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10,
201 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV440P12,
205 static const enum AVPixelFormat in_flat_pix_fmts[] = {
206 AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
207 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
209 AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
210 AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
211 AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
212 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9,
213 AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9,
214 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10,
215 AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10,
216 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV440P12,
220 static const enum AVPixelFormat out_rgb8_lowpass_pix_fmts[] = {
221 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
225 static const enum AVPixelFormat out_rgb9_lowpass_pix_fmts[] = {
230 static const enum AVPixelFormat out_rgb10_lowpass_pix_fmts[] = {
231 AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10,
235 static const enum AVPixelFormat out_rgb12_lowpass_pix_fmts[] = {
236 AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12,
240 static const enum AVPixelFormat out_yuv8_lowpass_pix_fmts[] = {
241 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVA444P,
245 static const enum AVPixelFormat out_yuv9_lowpass_pix_fmts[] = {
246 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUVA444P9,
250 static const enum AVPixelFormat out_yuv10_lowpass_pix_fmts[] = {
251 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUVA444P10,
255 static const enum AVPixelFormat out_yuv12_lowpass_pix_fmts[] = {
256 AV_PIX_FMT_YUV444P12,
260 static const enum AVPixelFormat out_gray8_lowpass_pix_fmts[] = {
265 static const enum AVPixelFormat out_gray9_lowpass_pix_fmts[] = {
270 static const enum AVPixelFormat out_gray10_lowpass_pix_fmts[] = {
275 static const enum AVPixelFormat out_gray12_lowpass_pix_fmts[] = {
280 static const enum AVPixelFormat flat_pix_fmts[] = {
281 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P,
282 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV444P10,
283 AV_PIX_FMT_YUV444P12,
287 static int query_formats(AVFilterContext *ctx)
289 WaveformContext *s = ctx->priv;
290 const enum AVPixelFormat *out_pix_fmts;
291 const enum AVPixelFormat *in_pix_fmts;
292 const AVPixFmtDescriptor *desc;
293 AVFilterFormats *avff;
294 int depth, rgb, i, ret, ncomp;
296 if (!ctx->inputs[0]->in_formats ||
297 !ctx->inputs[0]->in_formats->nb_formats) {
298 return AVERROR(EAGAIN);
302 case LOWPASS: in_pix_fmts = in_lowpass_pix_fmts; break;
306 case FLAT: in_pix_fmts = in_flat_pix_fmts; break;
308 case COLOR: in_pix_fmts = in_color_pix_fmts; break;
309 default: return AVERROR_BUG;
312 if (!ctx->inputs[0]->out_formats) {
313 if ((ret = ff_formats_ref(ff_make_format_list(in_pix_fmts), &ctx->inputs[0]->out_formats)) < 0)
317 avff = ctx->inputs[0]->in_formats;
318 desc = av_pix_fmt_desc_get(avff->formats[0]);
319 ncomp = desc->nb_components;
320 rgb = desc->flags & AV_PIX_FMT_FLAG_RGB;
321 depth = desc->comp[0].depth;
322 for (i = 1; i < avff->nb_formats; i++) {
323 desc = av_pix_fmt_desc_get(avff->formats[i]);
324 if (rgb != (desc->flags & AV_PIX_FMT_FLAG_RGB) ||
325 depth != desc->comp[0].depth)
326 return AVERROR(EAGAIN);
329 if (s->filter == LOWPASS && ncomp == 1 && depth == 8)
330 out_pix_fmts = out_gray8_lowpass_pix_fmts;
331 else if (s->filter == LOWPASS && ncomp == 1 && depth == 9)
332 out_pix_fmts = out_gray9_lowpass_pix_fmts;
333 else if (s->filter == LOWPASS && ncomp == 1 && depth == 10)
334 out_pix_fmts = out_gray10_lowpass_pix_fmts;
335 else if (s->filter == LOWPASS && ncomp == 1 && depth == 12)
336 out_pix_fmts = out_gray12_lowpass_pix_fmts;
337 else if (rgb && depth == 8 && ncomp > 2)
338 out_pix_fmts = out_rgb8_lowpass_pix_fmts;
339 else if (rgb && depth == 9 && ncomp > 2)
340 out_pix_fmts = out_rgb9_lowpass_pix_fmts;
341 else if (rgb && depth == 10 && ncomp > 2)
342 out_pix_fmts = out_rgb10_lowpass_pix_fmts;
343 else if (rgb && depth == 12 && ncomp > 2)
344 out_pix_fmts = out_rgb12_lowpass_pix_fmts;
345 else if (depth == 8 && ncomp > 2)
346 out_pix_fmts = out_yuv8_lowpass_pix_fmts;
347 else if (depth == 9 && ncomp > 2)
348 out_pix_fmts = out_yuv9_lowpass_pix_fmts;
349 else if (depth == 10 && ncomp > 2)
350 out_pix_fmts = out_yuv10_lowpass_pix_fmts;
351 else if (depth == 12 && ncomp > 2)
352 out_pix_fmts = out_yuv12_lowpass_pix_fmts;
354 return AVERROR(EAGAIN);
355 if ((ret = ff_formats_ref(ff_make_format_list(out_pix_fmts), &ctx->outputs[0]->in_formats)) < 0)
361 static void envelope_instant16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
363 const int dst_linesize = out->linesize[component] / 2;
364 const int bg = s->bg_color[component] * (s->max / 256);
365 const int limit = s->max - 1;
366 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
367 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
368 const int start = s->estart[plane];
369 const int end = s->eend[plane];
374 for (x = offset; x < offset + dst_w; x++) {
375 for (y = start; y < end; y++) {
376 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
382 for (y = end - 1; y >= start; y--) {
383 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
391 for (y = offset; y < offset + dst_h; y++) {
392 dst = (uint16_t *)out->data[component] + y * dst_linesize;
393 for (x = start; x < end; x++) {
399 for (x = end - 1; x >= start; x--) {
409 static void envelope_instant(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
411 const int dst_linesize = out->linesize[component];
412 const uint8_t bg = s->bg_color[component];
413 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
414 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
415 const int start = s->estart[plane];
416 const int end = s->eend[plane];
421 for (x = offset; x < offset + dst_w; x++) {
422 for (y = start; y < end; y++) {
423 dst = out->data[component] + y * dst_linesize + x;
429 for (y = end - 1; y >= start; y--) {
430 dst = out->data[component] + y * dst_linesize + x;
438 for (y = offset; y < offset + dst_h; y++) {
439 dst = out->data[component] + y * dst_linesize;
440 for (x = start; x < end; x++) {
446 for (x = end - 1; x >= start; x--) {
456 static void envelope_peak16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
458 const int dst_linesize = out->linesize[component] / 2;
459 const int bg = s->bg_color[component] * (s->max / 256);
460 const int limit = s->max - 1;
461 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
462 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
463 const int start = s->estart[plane];
464 const int end = s->eend[plane];
465 int *emax = s->emax[plane][component];
466 int *emin = s->emin[plane][component];
471 for (x = offset; x < offset + dst_w; x++) {
472 for (y = start; y < end && y < emin[x - offset]; y++) {
473 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
475 emin[x - offset] = y;
479 for (y = end - 1; y >= start && y >= emax[x - offset]; y--) {
480 dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
482 emax[x - offset] = y;
488 if (s->envelope == 3)
489 envelope_instant16(s, out, plane, component, offset);
491 for (x = offset; x < offset + dst_w; x++) {
492 dst = (uint16_t *)out->data[component] + emin[x - offset] * dst_linesize + x;
494 dst = (uint16_t *)out->data[component] + emax[x - offset] * dst_linesize + x;
498 for (y = offset; y < offset + dst_h; y++) {
499 dst = (uint16_t *)out->data[component] + y * dst_linesize;
500 for (x = start; x < end && x < emin[y - offset]; x++) {
502 emin[y - offset] = x;
506 for (x = end - 1; x >= start && x >= emax[y - offset]; x--) {
508 emax[y - offset] = x;
514 if (s->envelope == 3)
515 envelope_instant16(s, out, plane, component, offset);
517 for (y = offset; y < offset + dst_h; y++) {
518 dst = (uint16_t *)out->data[component] + y * dst_linesize + emin[y - offset];
520 dst = (uint16_t *)out->data[component] + y * dst_linesize + emax[y - offset];
526 static void envelope_peak(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
528 const int dst_linesize = out->linesize[component];
529 const int bg = s->bg_color[component];
530 const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
531 const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
532 const int start = s->estart[plane];
533 const int end = s->eend[plane];
534 int *emax = s->emax[plane][component];
535 int *emin = s->emin[plane][component];
540 for (x = offset; x < offset + dst_w; x++) {
541 for (y = start; y < end && y < emin[x - offset]; y++) {
542 dst = out->data[component] + y * dst_linesize + x;
544 emin[x - offset] = y;
548 for (y = end - 1; y >= start && y >= emax[x - offset]; y--) {
549 dst = out->data[component] + y * dst_linesize + x;
551 emax[x - offset] = y;
557 if (s->envelope == 3)
558 envelope_instant(s, out, plane, component, offset);
560 for (x = offset; x < offset + dst_w; x++) {
561 dst = out->data[component] + emin[x - offset] * dst_linesize + x;
563 dst = out->data[component] + emax[x - offset] * dst_linesize + x;
567 for (y = offset; y < offset + dst_h; y++) {
568 dst = out->data[component] + y * dst_linesize;
569 for (x = start; x < end && x < emin[y - offset]; x++) {
571 emin[y - offset] = x;
575 for (x = end - 1; x >= start && x >= emax[y - offset]; x--) {
577 emax[y - offset] = x;
583 if (s->envelope == 3)
584 envelope_instant(s, out, plane, component, offset);
586 for (y = offset; y < offset + dst_h; y++) {
587 dst = out->data[component] + y * dst_linesize + emin[y - offset];
589 dst = out->data[component] + y * dst_linesize + emax[y - offset];
595 static void envelope16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
597 if (s->envelope == 0) {
599 } else if (s->envelope == 1) {
600 envelope_instant16(s, out, plane, component, offset);
602 envelope_peak16(s, out, plane, component, offset);
606 static void envelope(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
608 if (s->envelope == 0) {
610 } else if (s->envelope == 1) {
611 envelope_instant(s, out, plane, component, offset);
613 envelope_peak(s, out, plane, component, offset);
617 static void update16(uint16_t *target, int max, int intensity, int limit)
620 *target += intensity;
625 static void update(uint8_t *target, int max, int intensity)
628 *target += intensity;
633 static void update_cr(uint8_t *target, int unused, int intensity)
635 if (*target - intensity > 0)
636 *target -= intensity;
641 static void update16_cr(uint16_t *target, int unused, int intensity, int limit)
643 if (*target - intensity > 0)
644 *target -= intensity;
649 static av_always_inline void lowpass16(WaveformContext *s,
650 AVFrame *in, AVFrame *out,
651 int component, int intensity,
652 int offset_y, int offset_x,
653 int column, int mirror,
654 int jobnr, int nb_jobs)
656 const int plane = s->desc->comp[component].plane;
657 const int shift_w = s->shift_w[component];
658 const int shift_h = s->shift_h[component];
659 const int src_linesize = in->linesize[plane] / 2;
660 const int dst_linesize = out->linesize[plane] / 2;
661 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
662 const int limit = s->max - 1;
663 const int max = limit - intensity;
664 const int src_h = AV_CEIL_RSHIFT(in->height, shift_h);
665 const int src_w = AV_CEIL_RSHIFT(in->width, shift_w);
666 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
667 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
668 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
669 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
670 const int step = column ? 1 << shift_w : 1 << shift_h;
671 const uint16_t *src_data = (const uint16_t *)in->data[plane] + sliceh_start * src_linesize;
672 uint16_t *dst_data = (uint16_t *)out->data[plane] + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
673 uint16_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
674 uint16_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
678 if (!column && mirror)
681 for (y = sliceh_start; y < sliceh_end; y++) {
682 const uint16_t *src_data_end = src_data + slicew_end;
683 uint16_t *dst = dst_line + slicew_start * step;
685 for (p = src_data + slicew_start; p < src_data_end; p++) {
687 int i = 0, v = FFMIN(*p, limit);
691 target = dst++ + dst_signed_linesize * v;
692 update16(target, max, intensity, limit);
693 } while (++i < step);
695 uint16_t *row = dst_data;
698 target = row - v - 1;
701 update16(target, max, intensity, limit);
703 } while (++i < step);
706 src_data += src_linesize;
707 dst_data += dst_linesize * step;
711 #define LOWPASS16_FUNC(name, column, mirror) \
712 static int lowpass16_##name(AVFilterContext *ctx, \
713 void *arg, int jobnr, \
716 WaveformContext *s = ctx->priv; \
717 ThreadData *td = arg; \
718 AVFrame *in = td->in; \
719 AVFrame *out = td->out; \
720 int component = td->component; \
721 int offset_y = td->offset_y; \
722 int offset_x = td->offset_x; \
724 lowpass16(s, in, out, component, s->intensity, \
725 offset_y, offset_x, column, mirror, \
731 LOWPASS16_FUNC(column_mirror, 1, 1)
732 LOWPASS16_FUNC(column, 1, 0)
733 LOWPASS16_FUNC(row_mirror, 0, 1)
734 LOWPASS16_FUNC(row, 0, 0)
736 static av_always_inline void lowpass(WaveformContext *s,
737 AVFrame *in, AVFrame *out,
738 int component, int intensity,
739 int offset_y, int offset_x,
740 int column, int mirror,
741 int jobnr, int nb_jobs)
743 const int plane = s->desc->comp[component].plane;
744 const int shift_w = s->shift_w[component];
745 const int shift_h = s->shift_h[component];
746 const int src_linesize = in->linesize[plane];
747 const int dst_linesize = out->linesize[plane];
748 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
749 const int max = 255 - intensity;
750 const int src_h = AV_CEIL_RSHIFT(in->height, shift_h);
751 const int src_w = AV_CEIL_RSHIFT(in->width, shift_w);
752 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
753 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
754 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
755 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
756 const int step = column ? 1 << shift_w : 1 << shift_h;
757 const uint8_t *src_data = in->data[plane] + sliceh_start * src_linesize;
758 uint8_t *dst_data = out->data[plane] + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
759 uint8_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
760 uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
764 if (!column && mirror)
767 for (y = sliceh_start; y < sliceh_end; y++) {
768 const uint8_t *src_data_end = src_data + slicew_end;
769 uint8_t *dst = dst_line + slicew_start * step;
771 for (p = src_data + slicew_start; p < src_data_end; p++) {
774 target = dst + dst_signed_linesize * *p;
776 update(target, max, intensity);
778 uint8_t *row = dst_data;
780 target = row - *p - 1;
783 update(target, max, intensity);
787 src_data += src_linesize;
788 dst_data += dst_linesize * step;
791 if (column && step > 1) {
792 const int dst_h = 256;
796 dst = out->data[plane] + offset_y * dst_linesize + offset_x;
797 for (y = 0; y < dst_h; y++) {
798 for (x = slicew_start * step; x < slicew_end * step; x+=step) {
799 for (z = 1; z < step; z++) {
805 } else if (step > 1) {
806 const int dst_w = 256;
810 dst = out->data[plane] + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
811 for (y = sliceh_start * step; y < sliceh_end * step; y+=step) {
812 for (z = 1; z < step; z++)
813 memcpy(dst + dst_linesize * z, dst, dst_w);
814 dst += dst_linesize * step;
819 #define LOWPASS_FUNC(name, column, mirror) \
820 static int lowpass_##name(AVFilterContext *ctx, \
821 void *arg, int jobnr, \
824 WaveformContext *s = ctx->priv; \
825 ThreadData *td = arg; \
826 AVFrame *in = td->in; \
827 AVFrame *out = td->out; \
828 int component = td->component; \
829 int offset_y = td->offset_y; \
830 int offset_x = td->offset_x; \
832 lowpass(s, in, out, component, s->intensity, \
833 offset_y, offset_x, column, mirror, \
839 LOWPASS_FUNC(column_mirror, 1, 1)
840 LOWPASS_FUNC(column, 1, 0)
841 LOWPASS_FUNC(row_mirror, 0, 1)
842 LOWPASS_FUNC(row, 0, 0)
844 static av_always_inline void flat16(WaveformContext *s,
845 AVFrame *in, AVFrame *out,
846 int component, int intensity,
847 int offset_y, int offset_x,
848 int column, int mirror,
849 int jobnr, int nb_jobs)
851 const int plane = s->desc->comp[component].plane;
852 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
853 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
854 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
855 const int c0_shift_w = s->shift_w[ component + 0 ];
856 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
857 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
858 const int c0_shift_h = s->shift_h[ component + 0 ];
859 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
860 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
861 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
862 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
863 const int limit = s->max - 1;
864 const int max = limit - intensity;
865 const int mid = s->max / 2;
866 const int src_h = in->height;
867 const int src_w = in->width;
868 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
869 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
870 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
871 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
875 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
876 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
878 for (x = slicew_start; x < slicew_end; x++) {
879 const uint16_t *c0_data = (uint16_t *)in->data[plane + 0];
880 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
881 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
882 uint16_t *d0_data = (uint16_t *)(out->data[plane]) + offset_y * d0_linesize + offset_x;
883 uint16_t *d1_data = (uint16_t *)(out->data[(plane + 1) % s->ncomp]) + offset_y * d1_linesize + offset_x;
884 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
885 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
886 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
887 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
889 for (y = 0; y < src_h; y++) {
890 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + s->max;
891 const int c1 = FFMIN(FFABS(c1_data[x >> c1_shift_w] - mid) + FFABS(c2_data[x >> c2_shift_w] - mid), limit);
894 target = d0 + x + d0_signed_linesize * c0;
895 update16(target, max, intensity, limit);
896 target = d1 + x + d1_signed_linesize * (c0 - c1);
897 update16(target, max, intensity, limit);
898 target = d1 + x + d1_signed_linesize * (c0 + c1);
899 update16(target, max, intensity, limit);
901 if (!c0_shift_h || (y & c0_shift_h))
902 c0_data += c0_linesize;
903 if (!c1_shift_h || (y & c1_shift_h))
904 c1_data += c1_linesize;
905 if (!c2_shift_h || (y & c2_shift_h))
906 c2_data += c2_linesize;
907 d0_data += d0_linesize;
908 d1_data += d1_linesize;
912 const uint16_t *c0_data = (uint16_t *)(in->data[plane]) + (sliceh_start >> c0_shift_h) * c0_linesize;
913 const uint16_t *c1_data = (uint16_t *)(in->data[(plane + 1) % s->ncomp]) + (sliceh_start >> c1_shift_h) * c1_linesize;
914 const uint16_t *c2_data = (uint16_t *)(in->data[(plane + 2) % s->ncomp]) + (sliceh_start >> c2_shift_h) * c2_linesize;
915 uint16_t *d0_data = (uint16_t *)(out->data[plane]) + (offset_y + sliceh_start) * d0_linesize + offset_x;
916 uint16_t *d1_data = (uint16_t *)(out->data[(plane + 1) % s->ncomp]) + (offset_y + sliceh_start) * d1_linesize + offset_x;
919 d0_data += s->size - 1;
920 d1_data += s->size - 1;
923 for (y = sliceh_start; y < sliceh_end; y++) {
924 for (x = 0; x < src_w; x++) {
925 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + s->max;
926 const int c1 = FFMIN(FFABS(c1_data[x >> c1_shift_w] - mid) + FFABS(c2_data[x >> c2_shift_w] - mid), limit);
930 target = d0_data - c0;
931 update16(target, max, intensity, limit);
932 target = d1_data - (c0 - c1);
933 update16(target, max, intensity, limit);
934 target = d1_data - (c0 + c1);
935 update16(target, max, intensity, limit);
937 target = d0_data + c0;
938 update16(target, max, intensity, limit);
939 target = d1_data + (c0 - c1);
940 update16(target, max, intensity, limit);
941 target = d1_data + (c0 + c1);
942 update16(target, max, intensity, limit);
946 if (!c0_shift_h || (y & c0_shift_h))
947 c0_data += c0_linesize;
948 if (!c1_shift_h || (y & c1_shift_h))
949 c1_data += c1_linesize;
950 if (!c2_shift_h || (y & c2_shift_h))
951 c2_data += c2_linesize;
952 d0_data += d0_linesize;
953 d1_data += d1_linesize;
958 #define FLAT16_FUNC(name, column, mirror) \
959 static int flat16_##name(AVFilterContext *ctx, \
960 void *arg, int jobnr, \
963 WaveformContext *s = ctx->priv; \
964 ThreadData *td = arg; \
965 AVFrame *in = td->in; \
966 AVFrame *out = td->out; \
967 int component = td->component; \
968 int offset_y = td->offset_y; \
969 int offset_x = td->offset_x; \
971 flat16(s, in, out, component, s->intensity, \
972 offset_y, offset_x, column, mirror, \
978 FLAT16_FUNC(column_mirror, 1, 1)
979 FLAT16_FUNC(column, 1, 0)
980 FLAT16_FUNC(row_mirror, 0, 1)
981 FLAT16_FUNC(row, 0, 0)
983 static av_always_inline void flat(WaveformContext *s,
984 AVFrame *in, AVFrame *out,
985 int component, int intensity,
986 int offset_y, int offset_x,
987 int column, int mirror,
988 int jobnr, int nb_jobs)
990 const int plane = s->desc->comp[component].plane;
991 const int c0_linesize = in->linesize[ plane + 0 ];
992 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
993 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
994 const int c0_shift_w = s->shift_w[ component + 0 ];
995 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
996 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
997 const int c0_shift_h = s->shift_h[ component + 0 ];
998 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
999 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1000 const int d0_linesize = out->linesize[ plane + 0 ];
1001 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
1002 const int max = 255 - intensity;
1003 const int src_h = in->height;
1004 const int src_w = in->width;
1005 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
1006 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
1007 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
1008 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
1012 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1013 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1015 for (x = slicew_start; x < slicew_end; x++) {
1016 const uint8_t *c0_data = in->data[plane + 0];
1017 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1018 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1019 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1020 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1021 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1022 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1023 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1024 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1026 for (y = 0; y < src_h; y++) {
1027 const int c0 = c0_data[x >> c0_shift_w] + 256;
1028 const int c1 = FFABS(c1_data[x >> c1_shift_w] - 128) + FFABS(c2_data[x >> c2_shift_w] - 128);
1031 target = d0 + x + d0_signed_linesize * c0;
1032 update(target, max, intensity);
1033 target = d1 + x + d1_signed_linesize * (c0 - c1);
1034 update(target, max, intensity);
1035 target = d1 + x + d1_signed_linesize * (c0 + c1);
1036 update(target, max, intensity);
1038 if (!c0_shift_h || (y & c0_shift_h))
1039 c0_data += c0_linesize;
1040 if (!c1_shift_h || (y & c1_shift_h))
1041 c1_data += c1_linesize;
1042 if (!c2_shift_h || (y & c2_shift_h))
1043 c2_data += c2_linesize;
1044 d0_data += d0_linesize;
1045 d1_data += d1_linesize;
1049 const uint8_t *c0_data = in->data[plane] + (sliceh_start >> c0_shift_h) * c0_linesize;
1050 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize;
1051 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize;
1052 uint8_t *d0_data = out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x;
1053 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x;
1056 d0_data += s->size - 1;
1057 d1_data += s->size - 1;
1060 for (y = sliceh_start; y < sliceh_end; y++) {
1061 for (x = 0; x < src_w; x++) {
1062 const int c0 = c0_data[x >> c0_shift_w] + 256;
1063 const int c1 = FFABS(c1_data[x >> c1_shift_w] - 128) + FFABS(c2_data[x >> c2_shift_w] - 128);
1067 target = d0_data - c0;
1068 update(target, max, intensity);
1069 target = d1_data - (c0 - c1);
1070 update(target, max, intensity);
1071 target = d1_data - (c0 + c1);
1072 update(target, max, intensity);
1074 target = d0_data + c0;
1075 update(target, max, intensity);
1076 target = d1_data + (c0 - c1);
1077 update(target, max, intensity);
1078 target = d1_data + (c0 + c1);
1079 update(target, max, intensity);
1083 if (!c0_shift_h || (y & c0_shift_h))
1084 c0_data += c0_linesize;
1085 if (!c1_shift_h || (y & c1_shift_h))
1086 c1_data += c1_linesize;
1087 if (!c2_shift_h || (y & c2_shift_h))
1088 c2_data += c2_linesize;
1089 d0_data += d0_linesize;
1090 d1_data += d1_linesize;
1095 #define FLAT_FUNC(name, column, mirror) \
1096 static int flat_##name(AVFilterContext *ctx, \
1097 void *arg, int jobnr, \
1100 WaveformContext *s = ctx->priv; \
1101 ThreadData *td = arg; \
1102 AVFrame *in = td->in; \
1103 AVFrame *out = td->out; \
1104 int component = td->component; \
1105 int offset_y = td->offset_y; \
1106 int offset_x = td->offset_x; \
1108 flat(s, in, out, component, s->intensity, \
1109 offset_y, offset_x, column, mirror, \
1115 FLAT_FUNC(column_mirror, 1, 1)
1116 FLAT_FUNC(column, 1, 0)
1117 FLAT_FUNC(row_mirror, 0, 1)
1118 FLAT_FUNC(row, 0, 0)
1120 #define AFLAT16(name, update_cr, column, mirror) \
1121 static int name(AVFilterContext *ctx, \
1122 void *arg, int jobnr, \
1125 WaveformContext *s = ctx->priv; \
1126 ThreadData *td = arg; \
1127 AVFrame *in = td->in; \
1128 AVFrame *out = td->out; \
1129 int component = td->component; \
1130 int offset_y = td->offset_y; \
1131 int offset_x = td->offset_x; \
1132 const int intensity = s->intensity; \
1133 const int plane = s->desc->comp[component].plane; \
1134 const int c0_linesize = in->linesize[ plane + 0 ] / 2; \
1135 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2; \
1136 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2; \
1137 const int c0_shift_w = s->shift_w[ component + 0 ]; \
1138 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp]; \
1139 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp]; \
1140 const int c0_shift_h = s->shift_h[ component + 0 ]; \
1141 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp]; \
1142 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp]; \
1143 const int d0_linesize = out->linesize[ plane + 0 ] / 2; \
1144 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2; \
1145 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2; \
1146 const int limit = s->max - 1; \
1147 const int max = limit - intensity; \
1148 const int mid = s->max / 2; \
1149 const int src_h = in->height; \
1150 const int src_w = in->width; \
1151 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0; \
1152 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h; \
1153 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0; \
1154 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w; \
1158 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1); \
1159 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1); \
1160 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1); \
1162 for (x = slicew_start; x < slicew_end; x++) { \
1163 const uint16_t *c0_data = (uint16_t *)in->data[plane + 0]; \
1164 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp]; \
1165 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp]; \
1166 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x; \
1167 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x; \
1168 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x; \
1169 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1); \
1170 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data); \
1171 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1); \
1172 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data); \
1173 uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1); \
1174 uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data); \
1176 for (y = 0; y < src_h; y++) { \
1177 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + mid; \
1178 const int c1 = FFMIN(c1_data[x >> c1_shift_w], limit) - mid; \
1179 const int c2 = FFMIN(c2_data[x >> c2_shift_w], limit) - mid; \
1182 target = d0 + x + d0_signed_linesize * c0; \
1183 update16(target, max, intensity, limit); \
1185 target = d1 + x + d1_signed_linesize * (c0 + c1); \
1186 update16(target, max, intensity, limit); \
1188 target = d2 + x + d2_signed_linesize * (c0 + c2); \
1189 update_cr(target, max, intensity, limit); \
1191 if (!c0_shift_h || (y & c0_shift_h)) \
1192 c0_data += c0_linesize; \
1193 if (!c1_shift_h || (y & c1_shift_h)) \
1194 c1_data += c1_linesize; \
1195 if (!c2_shift_h || (y & c2_shift_h)) \
1196 c2_data += c2_linesize; \
1197 d0_data += d0_linesize; \
1198 d1_data += d1_linesize; \
1199 d2_data += d2_linesize; \
1203 const uint16_t *c0_data = (uint16_t *)in->data[plane] + (sliceh_start >> c0_shift_h) * c0_linesize; \
1204 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize; \
1205 const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize; \
1206 uint16_t *d0_data = (uint16_t *)out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x; \
1207 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x; \
1208 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + (offset_y + sliceh_start) * d2_linesize + offset_x; \
1211 d0_data += s->size - 1; \
1212 d1_data += s->size - 1; \
1213 d2_data += s->size - 1; \
1216 for (y = sliceh_start; y < sliceh_end; y++) { \
1217 for (x = 0; x < src_w; x++) { \
1218 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + mid; \
1219 const int c1 = FFMIN(c1_data[x >> c1_shift_w], limit) - mid; \
1220 const int c2 = FFMIN(c2_data[x >> c2_shift_w], limit) - mid; \
1224 target = d0_data - c0; \
1225 update16(target, max, intensity, limit); \
1226 target = d1_data - (c0 + c1); \
1227 update16(target, max, intensity, limit); \
1228 target = d2_data - (c0 + c2); \
1229 update_cr(target, max, intensity, limit); \
1231 target = d0_data + c0; \
1232 update16(target, max, intensity, limit); \
1233 target = d1_data + (c0 + c1); \
1234 update16(target, max, intensity, limit); \
1235 target = d2_data + (c0 + c2); \
1236 update_cr(target, max, intensity, limit); \
1240 if (!c0_shift_h || (y & c0_shift_h)) \
1241 c0_data += c0_linesize; \
1242 if (!c1_shift_h || (y & c1_shift_h)) \
1243 c1_data += c1_linesize; \
1244 if (!c2_shift_h || (y & c2_shift_h)) \
1245 c2_data += c2_linesize; \
1246 d0_data += d0_linesize; \
1247 d1_data += d1_linesize; \
1248 d2_data += d2_linesize; \
1254 #define AFLAT(name, update_cr, column, mirror) \
1255 static int name(AVFilterContext *ctx, \
1256 void *arg, int jobnr, \
1259 WaveformContext *s = ctx->priv; \
1260 ThreadData *td = arg; \
1261 AVFrame *in = td->in; \
1262 AVFrame *out = td->out; \
1263 int component = td->component; \
1264 int offset_y = td->offset_y; \
1265 int offset_x = td->offset_x; \
1266 const int src_h = in->height; \
1267 const int src_w = in->width; \
1268 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0; \
1269 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h; \
1270 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0; \
1271 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w; \
1272 const int intensity = s->intensity; \
1273 const int plane = s->desc->comp[component].plane; \
1274 const int c0_linesize = in->linesize[ plane + 0 ]; \
1275 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp]; \
1276 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp]; \
1277 const int c0_shift_w = s->shift_w[ component + 0 ]; \
1278 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp]; \
1279 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp]; \
1280 const int c0_shift_h = s->shift_h[ component + 0 ]; \
1281 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp]; \
1282 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp]; \
1283 const int d0_linesize = out->linesize[ plane + 0 ]; \
1284 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp]; \
1285 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp]; \
1286 const int max = 255 - intensity; \
1290 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1); \
1291 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1); \
1292 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1); \
1294 for (x = slicew_start; x < slicew_end; x++) { \
1295 const uint8_t *c0_data = in->data[plane + 0]; \
1296 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp]; \
1297 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp]; \
1298 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x; \
1299 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x; \
1300 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x; \
1301 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1); \
1302 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data); \
1303 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1); \
1304 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data); \
1305 uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1); \
1306 uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data); \
1308 for (y = 0; y < src_h; y++) { \
1309 const int c0 = c0_data[x >> c0_shift_w] + 128; \
1310 const int c1 = c1_data[x >> c1_shift_w] - 128; \
1311 const int c2 = c2_data[x >> c2_shift_w] - 128; \
1314 target = d0 + x + d0_signed_linesize * c0; \
1315 update(target, max, intensity); \
1317 target = d1 + x + d1_signed_linesize * (c0 + c1); \
1318 update(target, max, intensity); \
1320 target = d2 + x + d2_signed_linesize * (c0 + c2); \
1321 update_cr(target, max, intensity); \
1323 if (!c0_shift_h || (y & c0_shift_h)) \
1324 c0_data += c0_linesize; \
1325 if (!c1_shift_h || (y & c1_shift_h)) \
1326 c1_data += c1_linesize; \
1327 if (!c1_shift_h || (y & c1_shift_h)) \
1328 c2_data += c1_linesize; \
1329 d0_data += d0_linesize; \
1330 d1_data += d1_linesize; \
1331 d2_data += d2_linesize; \
1335 const uint8_t *c0_data = in->data[plane] + (sliceh_start >> c0_shift_h) * c0_linesize; \
1336 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize; \
1337 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize; \
1338 uint8_t *d0_data = out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x; \
1339 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x; \
1340 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + (offset_y + sliceh_start) * d2_linesize + offset_x; \
1343 d0_data += s->size - 1; \
1344 d1_data += s->size - 1; \
1345 d2_data += s->size - 1; \
1348 for (y = sliceh_start; y < sliceh_end; y++) { \
1349 for (x = 0; x < src_w; x++) { \
1350 const int c0 = c0_data[x >> c0_shift_w] + 128; \
1351 const int c1 = c1_data[x >> c1_shift_w] - 128; \
1352 const int c2 = c2_data[x >> c2_shift_w] - 128; \
1356 target = d0_data - c0; \
1357 update(target, max, intensity); \
1358 target = d1_data - (c0 + c1); \
1359 update(target, max, intensity); \
1360 target = d2_data - (c0 + c2); \
1361 update_cr(target, max, intensity); \
1363 target = d0_data + c0; \
1364 update(target, max, intensity); \
1365 target = d1_data + (c0 + c1); \
1366 update(target, max, intensity); \
1367 target = d2_data + (c0 + c2); \
1368 update_cr(target, max, intensity); \
1372 if (!c0_shift_h || (y & c0_shift_h)) \
1373 c0_data += c0_linesize; \
1374 if (!c1_shift_h || (y & c1_shift_h)) \
1375 c1_data += c1_linesize; \
1376 if (!c2_shift_h || (y & c2_shift_h)) \
1377 c2_data += c2_linesize; \
1378 d0_data += d0_linesize; \
1379 d1_data += d1_linesize; \
1380 d2_data += d2_linesize; \
1386 AFLAT16(aflat16_row, update16, 0, 0)
1387 AFLAT16(aflat16_row_mirror, update16, 0, 1)
1388 AFLAT16(aflat16_column, update16, 1, 0)
1389 AFLAT16(aflat16_column_mirror, update16, 1, 1)
1390 AFLAT16(xflat16_row, update16_cr, 0, 0)
1391 AFLAT16(xflat16_row_mirror, update16_cr, 0, 1)
1392 AFLAT16(xflat16_column, update16_cr, 1, 0)
1393 AFLAT16(xflat16_column_mirror, update16_cr, 1, 1)
1395 AFLAT(aflat_row, update, 0, 0)
1396 AFLAT(aflat_row_mirror, update, 0, 1)
1397 AFLAT(aflat_column, update, 1, 0)
1398 AFLAT(aflat_column_mirror, update, 1, 1)
1399 AFLAT(xflat_row, update_cr, 0, 0)
1400 AFLAT(xflat_row_mirror, update_cr, 0, 1)
1401 AFLAT(xflat_column, update_cr, 1, 0)
1402 AFLAT(xflat_column_mirror, update_cr, 1, 1)
1404 static av_always_inline void chroma16(WaveformContext *s,
1405 AVFrame *in, AVFrame *out,
1406 int component, int intensity,
1407 int offset_y, int offset_x,
1408 int column, int mirror,
1409 int jobnr, int nb_jobs)
1411 const int plane = s->desc->comp[component].plane;
1412 const int c0_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1413 const int c1_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1414 const int dst_linesize = out->linesize[plane] / 2;
1415 const int limit = s->max - 1;
1416 const int max = limit - intensity;
1417 const int mid = s->max / 2;
1418 const int c0_shift_w = s->shift_w[(component + 1) % s->ncomp];
1419 const int c1_shift_w = s->shift_w[(component + 2) % s->ncomp];
1420 const int c0_shift_h = s->shift_h[(component + 1) % s->ncomp];
1421 const int c1_shift_h = s->shift_h[(component + 2) % s->ncomp];
1422 const int src_h = in->height;
1423 const int src_w = in->width;
1424 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
1425 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
1426 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
1427 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
1431 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
1433 for (x = slicew_start; x < slicew_end; x++) {
1434 const uint16_t *c0_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1435 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1436 uint16_t *dst_data = (uint16_t *)out->data[plane] + offset_y * dst_linesize + offset_x;
1437 uint16_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
1438 uint16_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
1439 uint16_t *dst = dst_line;
1441 for (y = 0; y < src_h; y++) {
1442 const int sum = FFMIN(FFABS(c0_data[x >> c0_shift_w] - mid) + FFABS(c1_data[x >> c1_shift_w] - mid - 1), limit);
1445 target = dst + x + dst_signed_linesize * sum;
1446 update16(target, max, intensity, limit);
1448 if (!c0_shift_h || (y & c0_shift_h))
1449 c0_data += c0_linesize;
1450 if (!c1_shift_h || (y & c1_shift_h))
1451 c1_data += c1_linesize;
1452 dst_data += dst_linesize;
1456 const uint16_t *c0_data = (uint16_t *)in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c0_shift_h) * c0_linesize;
1457 const uint16_t *c1_data = (uint16_t *)in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize;
1458 uint16_t *dst_data = (uint16_t *)out->data[plane] + (offset_y + sliceh_start) * dst_linesize + offset_x;
1461 dst_data += s->size - 1;
1462 for (y = sliceh_start; y < sliceh_end; y++) {
1463 for (x = 0; x < src_w; x++) {
1464 const int sum = FFMIN(FFABS(c0_data[x >> c0_shift_w] - mid) + FFABS(c1_data[x >> c1_shift_w] - mid - 1), limit);
1468 target = dst_data - sum;
1469 update16(target, max, intensity, limit);
1471 target = dst_data + sum;
1472 update16(target, max, intensity, limit);
1476 if (!c0_shift_h || (y & c0_shift_h))
1477 c0_data += c0_linesize;
1478 if (!c1_shift_h || (y & c1_shift_h))
1479 c1_data += c1_linesize;
1480 dst_data += dst_linesize;
1485 #define CHROMA16_FUNC(name, column, mirror) \
1486 static int chroma16_##name(AVFilterContext *ctx, \
1487 void *arg, int jobnr, \
1490 WaveformContext *s = ctx->priv; \
1491 ThreadData *td = arg; \
1492 AVFrame *in = td->in; \
1493 AVFrame *out = td->out; \
1494 int component = td->component; \
1495 int offset_y = td->offset_y; \
1496 int offset_x = td->offset_x; \
1498 chroma16(s, in, out, component, s->intensity,\
1499 offset_y, offset_x, column, mirror, \
1505 CHROMA16_FUNC(column_mirror, 1, 1)
1506 CHROMA16_FUNC(column, 1, 0)
1507 CHROMA16_FUNC(row_mirror, 0, 1)
1508 CHROMA16_FUNC(row, 0, 0)
1510 static av_always_inline void chroma(WaveformContext *s,
1511 AVFrame *in, AVFrame *out,
1512 int component, int intensity,
1513 int offset_y, int offset_x,
1514 int column, int mirror,
1515 int jobnr, int nb_jobs)
1517 const int plane = s->desc->comp[component].plane;
1518 const int src_h = in->height;
1519 const int src_w = in->width;
1520 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
1521 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
1522 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
1523 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
1524 const int c0_linesize = in->linesize[(plane + 1) % s->ncomp];
1525 const int c1_linesize = in->linesize[(plane + 2) % s->ncomp];
1526 const int dst_linesize = out->linesize[plane];
1527 const int max = 255 - intensity;
1528 const int c0_shift_w = s->shift_w[(component + 1) % s->ncomp];
1529 const int c1_shift_w = s->shift_w[(component + 2) % s->ncomp];
1530 const int c0_shift_h = s->shift_h[(component + 1) % s->ncomp];
1531 const int c1_shift_h = s->shift_h[(component + 2) % s->ncomp];
1535 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
1537 for (x = slicew_start; x < slicew_end; x++) {
1538 const uint8_t *c0_data = in->data[(plane + 1) % s->ncomp];
1539 const uint8_t *c1_data = in->data[(plane + 2) % s->ncomp];
1540 uint8_t *dst_data = out->data[plane] + offset_y * dst_linesize + offset_x;
1541 uint8_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
1542 uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
1543 uint8_t *dst = dst_line;
1545 for (y = 0; y < src_h; y++) {
1546 const int sum = FFABS(c0_data[x >> c0_shift_w] - 128) + FFABS(c1_data[x >> c1_shift_w] - 127);
1549 target = dst + x + dst_signed_linesize * sum;
1550 update(target, max, intensity);
1552 if (!c0_shift_h || (y & c0_shift_h))
1553 c0_data += c0_linesize;
1554 if (!c1_shift_h || (y & c1_shift_h))
1555 c1_data += c1_linesize;
1556 dst_data += dst_linesize;
1560 const uint8_t *c0_data = in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c0_shift_h) * c0_linesize;
1561 const uint8_t *c1_data = in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize;
1562 uint8_t *dst_data = out->data[plane] + (offset_y + sliceh_start) * dst_linesize + offset_x;
1565 dst_data += s->size - 1;
1566 for (y = sliceh_start; y < sliceh_end; y++) {
1567 for (x = 0; x < src_w; x++) {
1568 const int sum = FFABS(c0_data[x >> c0_shift_w] - 128) + FFABS(c1_data[x >> c1_shift_w] - 127);
1572 target = dst_data - sum;
1573 update(target, max, intensity);
1575 target = dst_data + sum;
1576 update(target, max, intensity);
1580 if (!c0_shift_h || (y & c0_shift_h))
1581 c0_data += c0_linesize;
1582 if (!c1_shift_h || (y & c1_shift_h))
1583 c1_data += c1_linesize;
1584 dst_data += dst_linesize;
1589 #define CHROMA_FUNC(name, column, mirror) \
1590 static int chroma_##name(AVFilterContext *ctx, \
1591 void *arg, int jobnr, \
1594 WaveformContext *s = ctx->priv; \
1595 ThreadData *td = arg; \
1596 AVFrame *in = td->in; \
1597 AVFrame *out = td->out; \
1598 int component = td->component; \
1599 int offset_y = td->offset_y; \
1600 int offset_x = td->offset_x; \
1602 chroma(s, in, out, component, s->intensity, \
1603 offset_y, offset_x, column, mirror, \
1609 CHROMA_FUNC(column_mirror, 1, 1)
1610 CHROMA_FUNC(column, 1, 0)
1611 CHROMA_FUNC(row_mirror, 0, 1)
1612 CHROMA_FUNC(row, 0, 0)
1614 static av_always_inline void color16(WaveformContext *s,
1615 AVFrame *in, AVFrame *out,
1616 int component, int intensity,
1617 int offset_y, int offset_x,
1618 int column, int mirror,
1619 int jobnr, int nb_jobs)
1621 const int plane = s->desc->comp[component].plane;
1622 const int limit = s->max - 1;
1623 const int src_h = in->height;
1624 const int src_w = in->width;
1625 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
1626 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
1627 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
1628 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
1629 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
1630 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1631 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1632 const int c0_shift_h = s->shift_h[ component + 0 ];
1633 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1634 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1635 const uint16_t *c0_data = (const uint16_t *)in->data[plane + 0] + (sliceh_start >> c0_shift_h) * c0_linesize;
1636 const uint16_t *c1_data = (const uint16_t *)in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize;
1637 const uint16_t *c2_data = (const uint16_t *)in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize;
1638 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
1639 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
1640 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2;
1641 const int c0_shift_w = s->shift_w[ component + 0 ];
1642 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1643 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1647 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1648 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1649 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1650 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1651 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1652 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1653 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1654 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1655 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1656 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1657 uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1658 uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1660 for (y = 0; y < src_h; y++) {
1661 for (x = slicew_start; x < slicew_end; x++) {
1662 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1663 const int c1 = c1_data[x >> c1_shift_w];
1664 const int c2 = c2_data[x >> c2_shift_w];
1666 *(d0 + d0_signed_linesize * c0 + x) = c0;
1667 *(d1 + d1_signed_linesize * c0 + x) = c1;
1668 *(d2 + d2_signed_linesize * c0 + x) = c2;
1671 if (!c0_shift_h || (y & c0_shift_h))
1672 c0_data += c0_linesize;
1673 if (!c1_shift_h || (y & c1_shift_h))
1674 c1_data += c1_linesize;
1675 if (!c2_shift_h || (y & c2_shift_h))
1676 c2_data += c2_linesize;
1677 d0_data += d0_linesize;
1678 d1_data += d1_linesize;
1679 d2_data += d2_linesize;
1682 uint16_t *d0_data = (uint16_t *)out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x;
1683 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x;
1684 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + (offset_y + sliceh_start) * d2_linesize + offset_x;
1687 d0_data += s->size - 1;
1688 d1_data += s->size - 1;
1689 d2_data += s->size - 1;
1692 for (y = sliceh_start; y < sliceh_end; y++) {
1693 for (x = 0; x < src_w; x++) {
1694 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1695 const int c1 = c1_data[x >> c1_shift_w];
1696 const int c2 = c2_data[x >> c2_shift_w];
1699 *(d0_data - c0) = c0;
1700 *(d1_data - c0) = c1;
1701 *(d2_data - c0) = c2;
1703 *(d0_data + c0) = c0;
1704 *(d1_data + c0) = c1;
1705 *(d2_data + c0) = c2;
1709 if (!c0_shift_h || (y & c0_shift_h))
1710 c0_data += c0_linesize;
1711 if (!c1_shift_h || (y & c1_shift_h))
1712 c1_data += c1_linesize;
1713 if (!c2_shift_h || (y & c2_shift_h))
1714 c2_data += c2_linesize;
1715 d0_data += d0_linesize;
1716 d1_data += d1_linesize;
1717 d2_data += d2_linesize;
1722 #define COLOR16_FUNC(name, column, mirror) \
1723 static int color16_##name(AVFilterContext *ctx, \
1724 void *arg, int jobnr, \
1727 WaveformContext *s = ctx->priv; \
1728 ThreadData *td = arg; \
1729 AVFrame *in = td->in; \
1730 AVFrame *out = td->out; \
1731 int component = td->component; \
1732 int offset_y = td->offset_y; \
1733 int offset_x = td->offset_x; \
1735 color16(s, in, out, component, s->intensity, \
1736 offset_y, offset_x, column, mirror, \
1742 COLOR16_FUNC(column_mirror, 1, 1)
1743 COLOR16_FUNC(column, 1, 0)
1744 COLOR16_FUNC(row_mirror, 0, 1)
1745 COLOR16_FUNC(row, 0, 0)
1747 static av_always_inline void color(WaveformContext *s,
1748 AVFrame *in, AVFrame *out,
1749 int component, int intensity,
1750 int offset_y, int offset_x,
1751 int column, int mirror,
1752 int jobnr, int nb_jobs)
1754 const int plane = s->desc->comp[component].plane;
1755 const int src_h = in->height;
1756 const int src_w = in->width;
1757 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
1758 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
1759 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
1760 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
1761 const int c0_linesize = in->linesize[ plane + 0 ];
1762 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
1763 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
1764 const int c0_shift_h = s->shift_h[ component + 0 ];
1765 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1766 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1767 const uint8_t *c0_data = in->data[plane] + (sliceh_start >> c0_shift_h) * c0_linesize;
1768 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize;
1769 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize;
1770 const int d0_linesize = out->linesize[ plane + 0 ];
1771 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
1772 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp];
1773 const int c0_shift_w = s->shift_w[ component + 0 ];
1774 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1775 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1779 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1780 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1781 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1782 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1783 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1784 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1785 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1786 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1787 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1788 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1789 uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1790 uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1792 for (y = 0; y < src_h; y++) {
1793 for (x = slicew_start; x < slicew_end; x++) {
1794 const int c0 = c0_data[x >> c0_shift_w];
1795 const int c1 = c1_data[x >> c1_shift_w];
1796 const int c2 = c2_data[x >> c2_shift_w];
1798 *(d0 + d0_signed_linesize * c0 + x) = c0;
1799 *(d1 + d1_signed_linesize * c0 + x) = c1;
1800 *(d2 + d2_signed_linesize * c0 + x) = c2;
1803 if (!c0_shift_h || (y & c0_shift_h))
1804 c0_data += c0_linesize;
1805 if (!c1_shift_h || (y & c1_shift_h))
1806 c1_data += c1_linesize;
1807 if (!c2_shift_h || (y & c2_shift_h))
1808 c2_data += c2_linesize;
1809 d0_data += d0_linesize;
1810 d1_data += d1_linesize;
1811 d2_data += d2_linesize;
1814 uint8_t *d0_data = out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x;
1815 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x;
1816 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + (offset_y + sliceh_start) * d2_linesize + offset_x;
1819 d0_data += s->size - 1;
1820 d1_data += s->size - 1;
1821 d2_data += s->size - 1;
1824 for (y = sliceh_start; y < sliceh_end; y++) {
1825 for (x = 0; x < src_w; x++) {
1826 const int c0 = c0_data[x >> c0_shift_w];
1827 const int c1 = c1_data[x >> c1_shift_w];
1828 const int c2 = c2_data[x >> c2_shift_w];
1831 *(d0_data - c0) = c0;
1832 *(d1_data - c0) = c1;
1833 *(d2_data - c0) = c2;
1835 *(d0_data + c0) = c0;
1836 *(d1_data + c0) = c1;
1837 *(d2_data + c0) = c2;
1841 if (!c0_shift_h || (y & c0_shift_h))
1842 c0_data += c0_linesize;
1843 if (!c1_shift_h || (y & c1_shift_h))
1844 c1_data += c1_linesize;
1845 if (!c2_shift_h || (y & c2_shift_h))
1846 c2_data += c2_linesize;
1847 d0_data += d0_linesize;
1848 d1_data += d1_linesize;
1849 d2_data += d2_linesize;
1854 #define COLOR_FUNC(name, column, mirror) \
1855 static int color_##name(AVFilterContext *ctx, \
1856 void *arg, int jobnr, \
1859 WaveformContext *s = ctx->priv; \
1860 ThreadData *td = arg; \
1861 AVFrame *in = td->in; \
1862 AVFrame *out = td->out; \
1863 int component = td->component; \
1864 int offset_y = td->offset_y; \
1865 int offset_x = td->offset_x; \
1867 color(s, in, out, component, s->intensity, \
1868 offset_y, offset_x, column, mirror, \
1874 COLOR_FUNC(column_mirror, 1, 1)
1875 COLOR_FUNC(column, 1, 0)
1876 COLOR_FUNC(row_mirror, 0, 1)
1877 COLOR_FUNC(row, 0, 0)
1879 static av_always_inline void acolor16(WaveformContext *s,
1880 AVFrame *in, AVFrame *out,
1881 int component, int intensity,
1882 int offset_y, int offset_x,
1883 int column, int mirror,
1884 int jobnr, int nb_jobs)
1886 const int plane = s->desc->comp[component].plane;
1887 const int limit = s->max - 1;
1888 const int max = limit - intensity;
1889 const int src_h = in->height;
1890 const int src_w = in->width;
1891 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
1892 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
1893 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
1894 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
1895 const int c0_shift_h = s->shift_h[ component + 0 ];
1896 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1897 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1898 const int c0_linesize = in->linesize[ plane + 0 ] / 2;
1899 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1900 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1901 const uint16_t *c0_data = (const uint16_t *)in->data[plane + 0] + (sliceh_start >> c0_shift_h) * c0_linesize;
1902 const uint16_t *c1_data = (const uint16_t *)in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize;
1903 const uint16_t *c2_data = (const uint16_t *)in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize;
1904 const int d0_linesize = out->linesize[ plane + 0 ] / 2;
1905 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
1906 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2;
1907 const int c0_shift_w = s->shift_w[ component + 0 ];
1908 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1909 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1913 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1914 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1915 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1916 uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1917 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1918 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1919 uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1920 uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1921 uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1922 uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1923 uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1924 uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1926 for (y = 0; y < src_h; y++) {
1927 for (x = slicew_start; x < slicew_end; x++) {
1928 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1929 const int c1 = c1_data[x >> c1_shift_w];
1930 const int c2 = c2_data[x >> c2_shift_w];
1932 update16(d0 + d0_signed_linesize * c0 + x, max, intensity, limit);
1933 *(d1 + d1_signed_linesize * c0 + x) = c1;
1934 *(d2 + d2_signed_linesize * c0 + x) = c2;
1937 if (!c0_shift_h || (y & c0_shift_h))
1938 c0_data += c0_linesize;
1939 if (!c1_shift_h || (y & c1_shift_h))
1940 c1_data += c1_linesize;
1941 if (!c2_shift_h || (y & c2_shift_h))
1942 c2_data += c2_linesize;
1943 d0_data += d0_linesize;
1944 d1_data += d1_linesize;
1945 d2_data += d2_linesize;
1948 uint16_t *d0_data = (uint16_t *)out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x;
1949 uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x;
1950 uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + (offset_y + sliceh_start) * d2_linesize + offset_x;
1953 d0_data += s->size - 1;
1954 d1_data += s->size - 1;
1955 d2_data += s->size - 1;
1958 for (y = sliceh_start; y < sliceh_end; y++) {
1959 for (x = 0; x < src_w; x++) {
1960 const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1961 const int c1 = c1_data[x >> c1_shift_w];
1962 const int c2 = c2_data[x >> c2_shift_w];
1965 update16(d0_data - c0, max, intensity, limit);
1966 *(d1_data - c0) = c1;
1967 *(d2_data - c0) = c2;
1969 update16(d0_data + c0, max, intensity, limit);
1970 *(d1_data + c0) = c1;
1971 *(d2_data + c0) = c2;
1975 if (!c0_shift_h || (y & c0_shift_h))
1976 c0_data += c0_linesize;
1977 if (!c1_shift_h || (y & c1_shift_h))
1978 c1_data += c1_linesize;
1979 if (!c2_shift_h || (y & c2_shift_h))
1980 c2_data += c2_linesize;
1981 d0_data += d0_linesize;
1982 d1_data += d1_linesize;
1983 d2_data += d2_linesize;
1988 #define ACOLOR16_FUNC(name, column, mirror) \
1989 static int acolor16_##name(AVFilterContext *ctx, \
1990 void *arg, int jobnr, \
1993 WaveformContext *s = ctx->priv; \
1994 ThreadData *td = arg; \
1995 AVFrame *in = td->in; \
1996 AVFrame *out = td->out; \
1997 int component = td->component; \
1998 int offset_y = td->offset_y; \
1999 int offset_x = td->offset_x; \
2001 acolor16(s, in, out, component, s->intensity,\
2002 offset_y, offset_x, column, mirror, \
2008 ACOLOR16_FUNC(column_mirror, 1, 1)
2009 ACOLOR16_FUNC(column, 1, 0)
2010 ACOLOR16_FUNC(row_mirror, 0, 1)
2011 ACOLOR16_FUNC(row, 0, 0)
2013 static av_always_inline void acolor(WaveformContext *s,
2014 AVFrame *in, AVFrame *out,
2015 int component, int intensity,
2016 int offset_y, int offset_x,
2017 int column, int mirror,
2018 int jobnr, int nb_jobs)
2020 const int plane = s->desc->comp[component].plane;
2021 const int src_h = in->height;
2022 const int src_w = in->width;
2023 const int sliceh_start = !column ? (src_h * jobnr) / nb_jobs : 0;
2024 const int sliceh_end = !column ? (src_h * (jobnr+1)) / nb_jobs : src_h;
2025 const int slicew_start = column ? (src_w * jobnr) / nb_jobs : 0;
2026 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
2027 const int c0_shift_w = s->shift_w[ component + 0 ];
2028 const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
2029 const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
2030 const int c0_shift_h = s->shift_h[ component + 0 ];
2031 const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
2032 const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
2033 const int c0_linesize = in->linesize[ plane + 0 ];
2034 const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
2035 const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
2036 const uint8_t *c0_data = in->data[plane + 0] + (sliceh_start >> c0_shift_h) * c0_linesize;
2037 const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp] + (sliceh_start >> c1_shift_h) * c1_linesize;
2038 const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp] + (sliceh_start >> c2_shift_h) * c2_linesize;
2039 const int d0_linesize = out->linesize[ plane + 0 ];
2040 const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
2041 const int d2_linesize = out->linesize[(plane + 2) % s->ncomp];
2042 const int max = 255 - intensity;
2046 const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
2047 const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
2048 const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
2049 uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
2050 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
2051 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
2052 uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
2053 uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
2054 uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
2055 uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
2056 uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
2057 uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data);
2059 for (y = 0; y < src_h; y++) {
2060 for (x = slicew_start; x < slicew_end; x++) {
2061 const int c0 = c0_data[x >> c0_shift_w];
2062 const int c1 = c1_data[x >> c1_shift_w];
2063 const int c2 = c2_data[x >> c2_shift_w];
2065 update(d0 + d0_signed_linesize * c0 + x, max, intensity);
2066 *(d1 + d1_signed_linesize * c0 + x) = c1;
2067 *(d2 + d2_signed_linesize * c0 + x) = c2;
2070 if (!c0_shift_h || (y & c0_shift_h))
2071 c0_data += c0_linesize;
2072 if (!c1_shift_h || (y & c1_shift_h))
2073 c1_data += c1_linesize;
2074 if (!c2_shift_h || (y & c2_shift_h))
2075 c2_data += c2_linesize;
2076 d0_data += d0_linesize;
2077 d1_data += d1_linesize;
2078 d2_data += d2_linesize;
2081 uint8_t *d0_data = out->data[plane] + (offset_y + sliceh_start) * d0_linesize + offset_x;
2082 uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + (offset_y + sliceh_start) * d1_linesize + offset_x;
2083 uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + (offset_y + sliceh_start) * d2_linesize + offset_x;
2086 d0_data += s->size - 1;
2087 d1_data += s->size - 1;
2088 d2_data += s->size - 1;
2091 for (y = sliceh_start; y < sliceh_end; y++) {
2092 for (x = 0; x < src_w; x++) {
2093 const int c0 = c0_data[x >> c0_shift_w];
2094 const int c1 = c1_data[x >> c1_shift_w];
2095 const int c2 = c2_data[x >> c2_shift_w];
2098 update(d0_data - c0, max, intensity);
2099 *(d1_data - c0) = c1;
2100 *(d2_data - c0) = c2;
2102 update(d0_data + c0, max, intensity);
2103 *(d1_data + c0) = c1;
2104 *(d2_data + c0) = c2;
2108 if (!c0_shift_h || (y & c0_shift_h))
2109 c0_data += c0_linesize;
2110 if (!c1_shift_h || (y & c1_shift_h))
2111 c1_data += c1_linesize;
2112 if (!c2_shift_h || (y & c2_shift_h))
2113 c2_data += c2_linesize;
2114 d0_data += d0_linesize;
2115 d1_data += d1_linesize;
2116 d2_data += d2_linesize;
2121 #define ACOLOR_FUNC(name, column, mirror) \
2122 static int acolor_##name(AVFilterContext *ctx, \
2123 void *arg, int jobnr, \
2126 WaveformContext *s = ctx->priv; \
2127 ThreadData *td = arg; \
2128 AVFrame *in = td->in; \
2129 AVFrame *out = td->out; \
2130 int component = td->component; \
2131 int offset_y = td->offset_y; \
2132 int offset_x = td->offset_x; \
2134 acolor(s, in, out, component, s->intensity, \
2135 offset_y, offset_x, column, mirror, \
2141 ACOLOR_FUNC(column_mirror, 1, 1)
2142 ACOLOR_FUNC(column, 1, 0)
2143 ACOLOR_FUNC(row_mirror, 0, 1)
2144 ACOLOR_FUNC(row, 0, 0)
2146 static const uint8_t black_yuva_color[4] = { 0, 127, 127, 255 };
2147 static const uint8_t black_gbrp_color[4] = { 0, 0, 0, 255 };
2149 static const GraticuleLines aflat_digital8[] = {
2150 { { { "16", 16+128 }, { "16", 16+128 }, { "16", 16+128 }, { "0", 0+128 } } },
2151 { { { "128", 128+128 }, { "128", 128+128 }, { "128", 128+128 }, { "128", 128+128 } } },
2152 { { { "235", 235+128 }, { "240", 240+128 }, { "240", 240+128 }, { "255", 255+128 } } },
2155 static const GraticuleLines aflat_digital9[] = {
2156 { { { "32", 32+256 }, { "32", 32+256 }, { "32", 32+256 }, { "0", 0+256 } } },
2157 { { { "256", 256+256 }, { "256", 256+256 }, { "256", 256+256 }, { "256", 256+256 } } },
2158 { { { "470", 470+256 }, { "480", 480+256 }, { "480", 480+256 }, { "511", 511+256 } } },
2161 static const GraticuleLines aflat_digital10[] = {
2162 { { { "64", 64+512 }, { "64", 64+512 }, { "64", 64+512 }, { "0", 0+512 } } },
2163 { { { "512", 512+512 }, { "512", 512+512 }, { "512", 512+512 }, { "512", 512+512 } } },
2164 { { { "940", 940+512 }, { "960", 960+512 }, { "960", 960+512 }, { "1023", 1023+512 } } },
2167 static const GraticuleLines aflat_digital12[] = {
2168 { { { "256", 256+2048 }, { "256", 256+2048 }, { "256", 256+2048 }, { "0", 0+2048 } } },
2169 { { { "2048", 2048+2048 }, { "2048", 2048+2048 }, { "2048", 2048+2048 }, { "2048", 2048+2048 } } },
2170 { { { "3760", 3760+2048 }, { "3840", 3840+2048 }, { "3840", 3840+2048 }, { "4095", 4095+2048 } } },
2173 static const GraticuleLines aflat_millivolts8[] = {
2174 { { { "0", 16+128 }, { "0", 16+128 }, { "0", 16+128 }, { "0", 0+128 } } },
2175 { { { "175", 71+128 }, { "175", 72+128 }, { "175", 72+128 }, { "175", 64+128 } } },
2176 { { { "350", 126+128 }, { "350", 128+128 }, { "350", 128+128 }, { "350", 128+128 } } },
2177 { { { "525", 180+128 }, { "525", 184+128 }, { "525", 184+128 }, { "525", 192+128 } } },
2178 { { { "700", 235+128 }, { "700", 240+128 }, { "700", 240+128 }, { "700", 255+128 } } },
2181 static const GraticuleLines aflat_millivolts9[] = {
2182 { { { "0", 32+256 }, { "0", 32+256 }, { "0", 32+256 }, { "0", 0+256 } } },
2183 { { { "175", 142+256 }, { "175", 144+256 }, { "175", 144+256 }, { "175", 128+256 } } },
2184 { { { "350", 251+256 }, { "350", 256+256 }, { "350", 256+256 }, { "350", 256+256 } } },
2185 { { { "525", 361+256 }, { "525", 368+256 }, { "525", 368+256 }, { "525", 384+256 } } },
2186 { { { "700", 470+256 }, { "700", 480+256 }, { "700", 480+256 }, { "700", 511+256 } } },
2189 static const GraticuleLines aflat_millivolts10[] = {
2190 { { { "0", 64+512 }, { "0", 64+512 }, { "0", 64+512 }, { "0", 0+512 } } },
2191 { { { "175", 283+512 }, { "175", 288+512 }, { "175", 288+512 }, { "175", 256+512 } } },
2192 { { { "350", 502+512 }, { "350", 512+512 }, { "350", 512+512 }, { "350", 512+512 } } },
2193 { { { "525", 721+512 }, { "525", 736+512 }, { "525", 736+512 }, { "525", 768+512 } } },
2194 { { { "700", 940+512 }, { "700", 960+512 }, { "700", 960+512 }, { "700", 1023+512 } } },
2197 static const GraticuleLines aflat_millivolts12[] = {
2198 { { { "0", 256+2048 }, { "0", 256+2048 }, { "0", 256+2048 }, { "0", 0+2048 } } },
2199 { { { "175", 1132+2048 }, { "175", 1152+2048 }, { "175", 1152+2048 }, { "175", 1024+2048 } } },
2200 { { { "350", 2008+2048 }, { "350", 2048+2048 }, { "350", 2048+2048 }, { "350", 2048+2048 } } },
2201 { { { "525", 2884+2048 }, { "525", 2944+2048 }, { "525", 2944+2048 }, { "525", 3072+2048 } } },
2202 { { { "700", 3760+2048 }, { "700", 3840+2048 }, { "700", 3840+2048 }, { "700", 4095+2048 } } },
2205 static const GraticuleLines aflat_ire8[] = {
2206 { { { "-25", -39+128 }, { "-25", -40+128 }, { "-25", -40+128 }, { "-25", -64+128 } } },
2207 { { { "0", 16+128 }, { "0", 16+128 }, { "0", 16+128 }, { "0", 0+128 } } },
2208 { { { "25", 71+128 }, { "25", 72+128 }, { "25", 72+128 }, { "25", 64+128 } } },
2209 { { { "50", 126+128 }, { "50", 128+128 }, { "50", 128+128 }, { "50", 128+128 } } },
2210 { { { "75", 180+128 }, { "75", 184+128 }, { "75", 184+128 }, { "75", 192+128 } } },
2211 { { { "100", 235+128 }, { "100", 240+128 }, { "100", 240+128 }, { "100", 256+128 } } },
2212 { { { "125", 290+128 }, { "125", 296+128 }, { "125", 296+128 }, { "125", 320+128 } } },
2215 static const GraticuleLines aflat_ire9[] = {
2216 { { { "-25", -78+256 }, { "-25", -80+256 }, { "-25", -80+256 }, { "-25",-128+256 } } },
2217 { { { "0", 32+256 }, { "0", 32+256 }, { "0", 32+256 }, { "0", 0+256 } } },
2218 { { { "25", 142+256 }, { "25", 144+256 }, { "25", 144+256 }, { "25", 128+256 } } },
2219 { { { "50", 251+256 }, { "50", 256+256 }, { "50", 256+256 }, { "50", 256+256 } } },
2220 { { { "75", 361+256 }, { "75", 368+256 }, { "75", 368+256 }, { "75", 384+256 } } },
2221 { { { "100", 470+256 }, { "100", 480+256 }, { "100", 480+256 }, { "100", 512+256 } } },
2222 { { { "125", 580+256 }, { "125", 592+256 }, { "125", 592+256 }, { "125", 640+256 } } },
2225 static const GraticuleLines aflat_ire10[] = {
2226 { { { "-25",-156+512 }, { "-25",-160+512 }, { "-25",-160+512 }, { "-25", -256+512 } } },
2227 { { { "0", 64+512 }, { "0", 64+512 }, { "0", 64+512 }, { "0", 0+512 } } },
2228 { { { "25", 283+512 }, { "25", 288+512 }, { "25", 288+512 }, { "25", 256+512 } } },
2229 { { { "50", 502+512 }, { "50", 512+512 }, { "50", 512+512 }, { "50", 512+512 } } },
2230 { { { "75", 721+512 }, { "75", 736+512 }, { "75", 736+512 }, { "75", 768+512 } } },
2231 { { { "100", 940+512 }, { "100", 960+512 }, { "100", 960+512 }, { "100", 1024+512 } } },
2232 { { { "125",1160+512 }, { "125",1184+512 }, { "125",1184+512 }, { "125", 1280+512 } } },
2235 static const GraticuleLines aflat_ire12[] = {
2236 { { { "-25", -624+2048 }, { "-25", -640+2048 }, { "-25", -640+2048 }, { "-25",-1024+2048 } } },
2237 { { { "0", 256+2048 }, { "0", 256+2048 }, { "0", 256+2048 }, { "0", 0+2048 } } },
2238 { { { "25", 1132+2048 }, { "25", 1152+2048 }, { "25", 1152+2048 }, { "25", 1024+2048 } } },
2239 { { { "50", 2008+2048 }, { "50", 2048+2048 }, { "50", 2048+2048 }, { "50", 2048+2048 } } },
2240 { { { "75", 2884+2048 }, { "75", 2944+2048 }, { "75", 2944+2048 }, { "75", 3072+2048 } } },
2241 { { { "100", 3760+2048 }, { "100", 3840+2048 }, { "100", 3840+2048 }, { "100", 4096+2048 } } },
2242 { { { "125", 4640+2048 }, { "125", 4736+2048 }, { "125", 4736+2048 }, { "125", 5120+2048 } } },
2245 static const GraticuleLines flat_digital8[] = {
2246 { { { "16", 16+256 }, { "16", 16+256 }, { "16", 16+256 }, { "0", 0+256 } } },
2247 { { { "128", 128+256 }, { "128", 128+256 }, { "128", 128+256 }, { "128", 128+256 } } },
2248 { { { "235", 235+256 }, { "240", 240+256 }, { "240", 240+256 }, { "255", 255+256 } } },
2251 static const GraticuleLines flat_digital9[] = {
2252 { { { "32", 32+512 }, { "32", 32+512 }, { "32", 32+512 }, { "0", 0+512 } } },
2253 { { { "256", 256+512 }, { "256", 256+512 }, { "256", 256+512 }, { "256", 256+512 } } },
2254 { { { "470", 470+512 }, { "480", 480+512 }, { "480", 480+512 }, { "511", 511+512 } } },
2257 static const GraticuleLines flat_digital10[] = {
2258 { { { "64", 64+1024 }, { "64", 64+1024 }, { "64", 64+1024 }, { "0", 0+1024 } } },
2259 { { { "512", 512+1024 }, { "512", 512+1024 }, { "512", 512+1024 }, { "512", 512+1024 } } },
2260 { { { "940", 940+1024 }, { "960", 960+1024 }, { "960", 960+1024 }, { "1023", 1023+1024 } } },
2263 static const GraticuleLines flat_digital12[] = {
2264 { { { "256", 256+4096 }, { "256", 256+4096 }, { "256", 256+4096 }, { "0", 0+4096 } } },
2265 { { { "2048", 2048+4096 }, { "2048", 2048+4096 }, { "2048", 2048+4096 }, { "2048", 2048+4096 } } },
2266 { { { "3760", 3760+4096 }, { "3840", 3840+4096 }, { "3840", 3840+4096 }, { "4095", 4095+4096 } } },
2269 static const GraticuleLines flat_millivolts8[] = {
2270 { { { "0", 16+256 }, { "0", 16+256 }, { "0", 16+256 }, { "0", 0+256 } } },
2271 { { { "175", 71+256 }, { "175", 72+256 }, { "175", 72+256 }, { "175", 64+256 } } },
2272 { { { "350", 126+256 }, { "350", 128+256 }, { "350", 128+256 }, { "350", 128+256 } } },
2273 { { { "525", 180+256 }, { "525", 184+256 }, { "525", 184+256 }, { "525", 192+256 } } },
2274 { { { "700", 235+256 }, { "700", 240+256 }, { "700", 240+256 }, { "700", 255+256 } } },
2277 static const GraticuleLines flat_millivolts9[] = {
2278 { { { "0", 32+512 }, { "0", 32+512 }, { "0", 32+512 }, { "0", 0+512 } } },
2279 { { { "175", 142+512 }, { "175", 144+512 }, { "175", 144+512 }, { "175", 128+512 } } },
2280 { { { "350", 251+512 }, { "350", 256+512 }, { "350", 256+512 }, { "350", 256+512 } } },
2281 { { { "525", 361+512 }, { "525", 368+512 }, { "525", 368+512 }, { "525", 384+512 } } },
2282 { { { "700", 470+512 }, { "700", 480+512 }, { "700", 480+512 }, { "700", 511+512 } } },
2285 static const GraticuleLines flat_millivolts10[] = {
2286 { { { "0", 64+1024 }, { "0", 64+1024 }, { "0", 64+1024 }, { "0", 0+1024 } } },
2287 { { { "175", 283+1024 }, { "175", 288+1024 }, { "175", 288+1024 }, { "175", 256+1024 } } },
2288 { { { "350", 502+1024 }, { "350", 512+1024 }, { "350", 512+1024 }, { "350", 512+1024 } } },
2289 { { { "525", 721+1024 }, { "525", 736+1024 }, { "525", 736+1024 }, { "525", 768+1024 } } },
2290 { { { "700", 940+1024 }, { "700", 960+1024 }, { "700", 960+1024 }, { "700", 1023+1024 } } },
2293 static const GraticuleLines flat_millivolts12[] = {
2294 { { { "0", 256+4096 }, { "0", 256+4096 }, { "0", 256+4096 }, { "0", 0+4096 } } },
2295 { { { "175", 1132+4096 }, { "175", 1152+4096 }, { "175", 1152+4096 }, { "175", 1024+4096 } } },
2296 { { { "350", 2008+4096 }, { "350", 2048+4096 }, { "350", 2048+4096 }, { "350", 2048+4096 } } },
2297 { { { "525", 2884+4096 }, { "525", 2944+4096 }, { "525", 2944+4096 }, { "525", 3072+4096 } } },
2298 { { { "700", 3760+4096 }, { "700", 3840+4096 }, { "700", 3840+4096 }, { "700", 4095+4096 } } },
2301 static const GraticuleLines flat_ire8[] = {
2302 { { { "-25", -39+256 }, { "-25", -40+256 }, { "-25", -40+256 }, { "-25", -64+256 } } },
2303 { { { "0", 16+256 }, { "0", 16+256 }, { "0", 16+256 }, { "0", 0+256 } } },
2304 { { { "25", 71+256 }, { "25", 72+256 }, { "25", 72+256 }, { "25", 64+256 } } },
2305 { { { "50", 126+256 }, { "50", 128+256 }, { "50", 128+256 }, { "50", 128+256 } } },
2306 { { { "75", 180+256 }, { "75", 184+256 }, { "75", 184+256 }, { "75", 192+256 } } },
2307 { { { "100", 235+256 }, { "100", 240+256 }, { "100", 240+256 }, { "100", 256+256 } } },
2308 { { { "125", 290+256 }, { "125", 296+256 }, { "125", 296+256 }, { "125", 320+256 } } },
2311 static const GraticuleLines flat_ire9[] = {
2312 { { { "-25", -78+512 }, { "-25", -80+512 }, { "-25", -80+512 }, { "-25",-128+512 } } },
2313 { { { "0", 32+512 }, { "0", 32+512 }, { "0", 32+512 }, { "0", 0+512 } } },
2314 { { { "25", 142+512 }, { "25", 144+512 }, { "25", 144+512 }, { "25", 128+512 } } },
2315 { { { "50", 251+512 }, { "50", 256+512 }, { "50", 256+512 }, { "50", 256+512 } } },
2316 { { { "75", 361+512 }, { "75", 368+512 }, { "75", 368+512 }, { "75", 384+512 } } },
2317 { { { "100", 470+512 }, { "100", 480+512 }, { "100", 480+512 }, { "100", 512+512 } } },
2318 { { { "125", 580+512 }, { "125", 592+512 }, { "125", 592+512 }, { "125", 640+512 } } },
2321 static const GraticuleLines flat_ire10[] = {
2322 { { { "-25",-156+1024 }, { "-25",-160+1024 }, { "-25",-160+1024 }, { "-25", -256+1024 } } },
2323 { { { "0", 64+1024 }, { "0", 64+1024 }, { "0", 64+1024 }, { "0", 0+1024 } } },
2324 { { { "25", 283+1024 }, { "25", 288+1024 }, { "25", 288+1024 }, { "25", 256+1024 } } },
2325 { { { "50", 502+1024 }, { "50", 512+1024 }, { "50", 512+1024 }, { "50", 512+1024 } } },
2326 { { { "75", 721+1024 }, { "75", 736+1024 }, { "75", 736+1024 }, { "75", 768+1024 } } },
2327 { { { "100", 940+1024 }, { "100", 960+1024 }, { "100", 960+1024 }, { "100", 1024+1024 } } },
2328 { { { "125",1160+1024 }, { "125",1184+1024 }, { "125",1184+1024 }, { "125", 1280+1024 } } },
2331 static const GraticuleLines flat_ire12[] = {
2332 { { { "-25", -624+4096 }, { "-25", -640+4096 }, { "-25", -640+4096 }, { "-25",-1024+4096 } } },
2333 { { { "0", 256+4096 }, { "0", 256+4096 }, { "0", 256+4096 }, { "0", 0+4096 } } },
2334 { { { "25", 1132+4096 }, { "25", 1152+4096 }, { "25", 1152+4096 }, { "25", 1024+4096 } } },
2335 { { { "50", 2008+4096 }, { "50", 2048+4096 }, { "50", 2048+4096 }, { "50", 2048+4096 } } },
2336 { { { "75", 2884+4096 }, { "75", 2944+4096 }, { "75", 2944+4096 }, { "75", 3072+4096 } } },
2337 { { { "100", 3760+4096 }, { "100", 3840+4096 }, { "100", 3840+4096 }, { "100", 4096+4096 } } },
2338 { { { "125", 4640+4096 }, { "125", 4736+4096 }, { "125", 4736+4096 }, { "125", 5120+4096 } } },
2341 static const GraticuleLines digital8[] = {
2342 { { { "16", 16 }, { "16", 16 }, { "16", 16 }, { "0", 0 } } },
2343 { { { "128", 128 }, { "128", 128 }, { "128", 128 }, { "128", 128 } } },
2344 { { { "235", 235 }, { "240", 240 }, { "240", 240 }, { "255", 255 } } },
2347 static const GraticuleLines digital9[] = {
2348 { { { "32", 32 }, { "32", 32 }, { "32", 32 }, { "0", 0 } } },
2349 { { { "256", 256 }, { "256", 256 }, { "256", 256 }, { "256", 256 } } },
2350 { { { "470", 470 }, { "480", 480 }, { "480", 480 }, { "511", 511 } } },
2353 static const GraticuleLines digital10[] = {
2354 { { { "64", 64 }, { "64", 64 }, { "64", 64 }, { "0", 0 } } },
2355 { { { "512", 512 }, { "512", 512 }, { "512", 512 }, { "512", 512 } } },
2356 { { { "940", 940 }, { "960", 960 }, { "960", 960 }, { "1023", 1023 } } },
2359 static const GraticuleLines digital12[] = {
2360 { { { "256", 256 }, { "256", 256 }, { "256", 256 }, { "0", 0 } } },
2361 { { { "2048", 2048 }, { "2048", 2048 }, { "2048", 2048 }, { "2048", 2048 } } },
2362 { { { "3760", 3760 }, { "3840", 3840 }, { "3840", 3840 }, { "4095", 4095 } } },
2365 static const GraticuleLines millivolts8[] = {
2366 { { { "0", 16 }, { "0", 16 }, { "0", 16 }, { "0", 0 } } },
2367 { { { "175", 71 }, { "175", 72 }, { "175", 72 }, { "175", 64 } } },
2368 { { { "350", 126 }, { "350", 128 }, { "350", 128 }, { "350", 128 } } },
2369 { { { "525", 180 }, { "525", 184 }, { "525", 184 }, { "525", 192 } } },
2370 { { { "700", 235 }, { "700", 240 }, { "700", 240 }, { "700", 255 } } },
2373 static const GraticuleLines millivolts9[] = {
2374 { { { "0", 32 }, { "0", 32 }, { "0", 32 }, { "0", 0 } } },
2375 { { { "175", 142 }, { "175", 144 }, { "175", 144 }, { "175", 128 } } },
2376 { { { "350", 251 }, { "350", 256 }, { "350", 256 }, { "350", 256 } } },
2377 { { { "525", 361 }, { "525", 368 }, { "525", 368 }, { "525", 384 } } },
2378 { { { "700", 470 }, { "700", 480 }, { "700", 480 }, { "700", 511 } } },
2381 static const GraticuleLines millivolts10[] = {
2382 { { { "0", 64 }, { "0", 64 }, { "0", 64 }, { "0", 0 } } },
2383 { { { "175", 283 }, { "175", 288 }, { "175", 288 }, { "175", 256 } } },
2384 { { { "350", 502 }, { "350", 512 }, { "350", 512 }, { "350", 512 } } },
2385 { { { "525", 721 }, { "525", 736 }, { "525", 736 }, { "525", 768 } } },
2386 { { { "700", 940 }, { "700", 960 }, { "700", 960 }, { "700", 1023 } } },
2389 static const GraticuleLines millivolts12[] = {
2390 { { { "0", 256 }, { "0", 256 }, { "0", 256 }, { "0", 0 } } },
2391 { { { "175", 1132 }, { "175", 1152 }, { "175", 1152 }, { "175", 1024 } } },
2392 { { { "350", 2008 }, { "350", 2048 }, { "350", 2048 }, { "350", 2048 } } },
2393 { { { "525", 2884 }, { "525", 2944 }, { "525", 2944 }, { "525", 3072 } } },
2394 { { { "700", 3760 }, { "700", 3840 }, { "700", 3840 }, { "700", 4095 } } },
2397 static const GraticuleLines ire8[] = {
2398 { { { "0", 16 }, { "0", 16 }, { "0", 16 }, { "0", 0 } } },
2399 { { { "25", 71 }, { "25", 72 }, { "25", 72 }, { "25", 64 } } },
2400 { { { "50", 126 }, { "50", 128 }, { "50", 128 }, { "50", 128 } } },
2401 { { { "75", 180 }, { "75", 184 }, { "75", 184 }, { "75", 192 } } },
2402 { { { "100", 235 }, { "100", 240 }, { "100", 240 }, { "100", 255 } } },
2405 static const GraticuleLines ire9[] = {
2406 { { { "0", 32 }, { "0", 32 }, { "0", 32 }, { "0", 0 } } },
2407 { { { "25", 142 }, { "25", 144 }, { "25", 144 }, { "25", 128 } } },
2408 { { { "50", 251 }, { "50", 256 }, { "50", 256 }, { "50", 256 } } },
2409 { { { "75", 361 }, { "75", 368 }, { "75", 368 }, { "75", 384 } } },
2410 { { { "100", 470 }, { "100", 480 }, { "100", 480 }, { "100", 511 } } },
2413 static const GraticuleLines ire10[] = {
2414 { { { "0", 64 }, { "0", 64 }, { "0", 64 }, { "0", 0 } } },
2415 { { { "25", 283 }, { "25", 288 }, { "25", 288 }, { "25", 256 } } },
2416 { { { "50", 502 }, { "50", 512 }, { "50", 512 }, { "50", 512 } } },
2417 { { { "75", 721 }, { "75", 736 }, { "75", 736 }, { "75", 768 } } },
2418 { { { "100", 940 }, { "100", 960 }, { "100", 960 }, { "100", 1023 } } },
2421 static const GraticuleLines ire12[] = {
2422 { { { "0", 256 }, { "0", 256 }, { "0", 256 }, { "0", 0 } } },
2423 { { { "25", 1132 }, { "25", 1152 }, { "25", 1152 }, { "25", 1024 } } },
2424 { { { "50", 2008 }, { "50", 2048 }, { "50", 2048 }, { "50", 2048 } } },
2425 { { { "75", 2884 }, { "75", 2944 }, { "75", 2944 }, { "75", 3072 } } },
2426 { { { "100", 3760 }, { "100", 3840 }, { "100", 3840 }, { "100", 4095 } } },
2429 static const GraticuleLines chroma_digital8[] = {
2430 { { { "50", 50 }, { "50", 50 }, { "50", 50 }, { "50", 50 } } },
2431 { { { "100", 100 }, { "100", 100 }, { "100", 100 }, { "100", 100 } } },
2432 { { { "150", 150 }, { "150", 150 }, { "150", 150 }, { "150", 150 } } },
2433 { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2434 { { { "255", 255 }, { "255", 255 }, { "255", 255 }, { "255", 255 } } },
2437 static const GraticuleLines chroma_digital9[] = {
2438 { { { "100", 100 }, { "100", 100 }, { "100", 100 }, { "100", 100 } } },
2439 { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2440 { { { "300", 300 }, { "300", 300 }, { "300", 300 }, { "300", 300 } } },
2441 { { { "400", 400 }, { "400", 400 }, { "400", 400 }, { "400", 400 } } },
2442 { { { "500", 500 }, { "500", 500 }, { "500", 500 }, { "500", 500 } } },
2445 static const GraticuleLines chroma_digital10[] = {
2446 { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2447 { { { "400", 400 }, { "400", 400 }, { "400", 400 }, { "400", 400 } } },
2448 { { { "600", 600 }, { "600", 600 }, { "600", 600 }, { "600", 600 } } },
2449 { { { "800", 800 }, { "800", 800 }, { "800", 800 }, { "800", 800 } } },
2450 { { {"1000",1000 }, {"1000",1000 }, {"1000",1000 }, {"1000",1000 } } },
2453 static const GraticuleLines chroma_digital12[] = {
2454 { { { "800", 800 }, { "800", 800 }, { "800", 800 }, { "800", 800 } } },
2455 { { { "1600", 1600 }, { "1600", 1600 }, { "1600", 1600 }, { "1600", 1600 } } },
2456 { { { "2400", 2400 }, { "2400", 2400 }, { "2400", 2400 }, { "2400", 2400 } } },
2457 { { { "3200", 3200 }, { "3200", 3200 }, { "3200", 3200 }, { "3200", 3200 } } },
2458 { { { "4000", 4000 }, { "4000", 4000 }, { "4000", 4000 }, { "4000", 4000 } } },
2461 static void blend_vline(uint8_t *dst, int height, int linesize, float o1, float o2, int v, int step)
2465 for (y = 0; y < height; y += step) {
2466 dst[0] = v * o1 + dst[0] * o2;
2468 dst += linesize * step;
2472 static void blend_vline16(uint16_t *dst, int height, int linesize, float o1, float o2, int v, int step)
2476 for (y = 0; y < height; y += step) {
2477 dst[0] = v * o1 + dst[0] * o2;
2479 dst += (linesize / 2) * step;
2483 static void blend_hline(uint8_t *dst, int width, float o1, float o2, int v, int step)
2487 for (x = 0; x < width; x += step) {
2488 dst[x] = v * o1 + dst[x] * o2;
2492 static void blend_hline16(uint16_t *dst, int width, float o1, float o2, int v, int step)
2496 for (x = 0; x < width; x += step) {
2497 dst[x] = v * o1 + dst[x] * o2;
2501 static void draw_htext(AVFrame *out, int x, int y, float o1, float o2, const char *txt, const uint8_t color[4])
2503 const uint8_t *font;
2507 font = avpriv_cga_font, font_height = 8;
2509 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2510 for (i = 0; txt[i]; i++) {
2512 int v = color[plane];
2514 uint8_t *p = out->data[plane] + y * out->linesize[plane] + (x + i * 8);
2515 for (char_y = 0; char_y < font_height; char_y++) {
2516 for (mask = 0x80; mask; mask >>= 1) {
2517 if (font[txt[i] * font_height + char_y] & mask)
2518 p[0] = p[0] * o2 + v * o1;
2521 p += out->linesize[plane] - 8;
2527 static void draw_htext16(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
2529 const uint8_t *font;
2533 font = avpriv_cga_font, font_height = 8;
2535 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2536 for (i = 0; txt[i]; i++) {
2538 int v = color[plane] * mult;
2540 uint16_t *p = (uint16_t *)(out->data[plane] + y * out->linesize[plane]) + (x + i * 8);
2541 for (char_y = 0; char_y < font_height; char_y++) {
2542 for (mask = 0x80; mask; mask >>= 1) {
2543 if (font[txt[i] * font_height + char_y] & mask)
2544 p[0] = p[0] * o2 + v * o1;
2547 p += out->linesize[plane] / 2 - 8;
2553 static void draw_vtext(AVFrame *out, int x, int y, float o1, float o2, const char *txt, const uint8_t color[4])
2555 const uint8_t *font;
2559 font = avpriv_cga_font, font_height = 8;
2561 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2562 for (i = 0; txt[i]; i++) {
2564 int v = color[plane];
2566 for (char_y = font_height - 1; char_y >= 0; char_y--) {
2567 uint8_t *p = out->data[plane] + (y + i * 10) * out->linesize[plane] + x;
2568 for (mask = 0x80; mask; mask >>= 1) {
2569 if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
2570 p[char_y] = p[char_y] * o2 + v * o1;
2571 p += out->linesize[plane];
2578 static void draw_vtext16(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
2580 const uint8_t *font;
2584 font = avpriv_cga_font, font_height = 8;
2586 for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2587 for (i = 0; txt[i]; i++) {
2589 int v = color[plane] * mult;
2591 for (char_y = 0; char_y < font_height; char_y++) {
2592 uint16_t *p = (uint16_t *)(out->data[plane] + (y + i * 10) * out->linesize[plane]) + x;
2593 for (mask = 0x80; mask; mask >>= 1) {
2594 if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
2595 p[char_y] = p[char_y] * o2 + v * o1;
2596 p += out->linesize[plane] / 2;
2603 static void graticule_none(WaveformContext *s, AVFrame *out)
2607 static void graticule_row(WaveformContext *s, AVFrame *out)
2609 const int step = (s->flags & 2) + 1;
2610 const float o1 = s->opacity;
2611 const float o2 = 1. - o1;
2612 const int height = s->display == PARADE ? out->height / s->acomp : out->height;
2613 int k = 0, c, p, l, offset_x = 0, offset_y = 0;
2615 for (c = 0; c < s->ncomp; c++) {
2616 if (!((1 << c) & s->pcomp) || (!s->display && k > 0))
2620 for (p = 0; p < s->ncomp; p++) {
2621 const int v = s->grat_yuva_color[p];
2622 for (l = 0; l < s->nb_glines; l++) {
2623 const uint16_t pos = s->glines[l].line[c].pos;
2624 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos);
2625 uint8_t *dst = out->data[p] + offset_y * out->linesize[p] + x;
2627 blend_vline(dst, height, out->linesize[p], o1, o2, v, step);
2631 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2632 const char *name = s->glines[l].line[c].name;
2633 const uint16_t pos = s->glines[l].line[c].pos;
2634 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos) - 10;
2639 draw_vtext(out, x, offset_y + 2, o1, o2, name, s->grat_yuva_color);
2642 offset_x += s->size * (s->display == STACK);
2643 offset_y += height * (s->display == PARADE);
2647 static void graticule16_row(WaveformContext *s, AVFrame *out)
2649 const int step = (s->flags & 2) + 1;
2650 const float o1 = s->opacity;
2651 const float o2 = 1. - o1;
2652 const int mult = s->max / 256;
2653 const int height = s->display == PARADE ? out->height / s->acomp : out->height;
2654 int k = 0, c, p, l, offset_x = 0, offset_y = 0;
2656 for (c = 0; c < s->ncomp; c++) {
2657 if (!((1 << c) & s->pcomp) || (!s->display && k > 0))
2661 for (p = 0; p < s->ncomp; p++) {
2662 const int v = s->grat_yuva_color[p] * mult;
2663 for (l = 0; l < s->nb_glines ; l++) {
2664 const uint16_t pos = s->glines[l].line[c].pos;
2665 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos);
2666 uint16_t *dst = (uint16_t *)(out->data[p] + offset_y * out->linesize[p]) + x;
2668 blend_vline16(dst, height, out->linesize[p], o1, o2, v, step);
2672 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2673 const char *name = s->glines[l].line[c].name;
2674 const uint16_t pos = s->glines[l].line[c].pos;
2675 int x = offset_x + (s->mirror ? s->size - 1 - pos : pos) - 10;
2680 draw_vtext16(out, x, offset_y + 2, mult, o1, o2, name, s->grat_yuva_color);
2683 offset_x += s->size * (s->display == STACK);
2684 offset_y += height * (s->display == PARADE);
2688 static void graticule_column(WaveformContext *s, AVFrame *out)
2690 const int step = (s->flags & 2) + 1;
2691 const float o1 = s->opacity;
2692 const float o2 = 1. - o1;
2693 const int width = s->display == PARADE ? out->width / s->acomp : out->width;
2694 int k = 0, c, p, l, offset_y = 0, offset_x = 0;
2696 for (c = 0; c < s->ncomp; c++) {
2697 if ((!((1 << c) & s->pcomp) || (!s->display && k > 0)))
2701 for (p = 0; p < s->ncomp; p++) {
2702 const int v = s->grat_yuva_color[p];
2703 for (l = 0; l < s->nb_glines ; l++) {
2704 const uint16_t pos = s->glines[l].line[c].pos;
2705 int y = offset_y + (s->mirror ? s->size - 1 - pos : pos);
2706 uint8_t *dst = out->data[p] + y * out->linesize[p] + offset_x;
2708 blend_hline(dst, width, o1, o2, v, step);
2712 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2713 const char *name = s->glines[l].line[c].name;
2714 const uint16_t pos = s->glines[l].line[c].pos;
2715 int y = offset_y + (s->mirror ? s->size - 1 - pos : pos) - 10;
2720 draw_htext(out, 2 + offset_x, y, o1, o2, name, s->grat_yuva_color);
2723 offset_y += s->size * (s->display == STACK);
2724 offset_x += width * (s->display == PARADE);
2728 static void graticule16_column(WaveformContext *s, AVFrame *out)
2730 const int step = (s->flags & 2) + 1;
2731 const float o1 = s->opacity;
2732 const float o2 = 1. - o1;
2733 const int mult = s->max / 256;
2734 const int width = s->display == PARADE ? out->width / s->acomp : out->width;
2735 int k = 0, c, p, l, offset_x = 0, offset_y = 0;
2737 for (c = 0; c < s->ncomp; c++) {
2738 if ((!((1 << c) & s->pcomp) || (!s->display && k > 0)))
2742 for (p = 0; p < s->ncomp; p++) {
2743 const int v = s->grat_yuva_color[p] * mult;
2744 for (l = 0; l < s->nb_glines ; l++) {
2745 const uint16_t pos = s->glines[l].line[c].pos;
2746 int y = offset_y + (s->mirror ? s->size - 1 - pos : pos);
2747 uint16_t *dst = (uint16_t *)(out->data[p] + y * out->linesize[p]) + offset_x;
2749 blend_hline16(dst, width, o1, o2, v, step);
2753 for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2754 const char *name = s->glines[l].line[c].name;
2755 const uint16_t pos = s->glines[l].line[c].pos;
2756 int y = offset_y + (s->mirror ? s->size - 1 - pos: pos) - 10;
2761 draw_htext16(out, 2 + offset_x, y, mult, o1, o2, name, s->grat_yuva_color);
2764 offset_y += s->size * (s->display == STACK);
2765 offset_x += width * (s->display == PARADE);
2769 static int config_input(AVFilterLink *inlink)
2771 AVFilterContext *ctx = inlink->dst;
2772 WaveformContext *s = ctx->priv;
2774 s->desc = av_pix_fmt_desc_get(inlink->format);
2775 s->ncomp = s->desc->nb_components;
2776 s->bits = s->desc->comp[0].depth;
2777 s->max = 1 << s->bits;
2778 s->intensity = s->fintensity * (s->max - 1);
2780 s->shift_w[0] = s->shift_w[3] = 0;
2781 s->shift_h[0] = s->shift_h[3] = 0;
2782 s->shift_w[1] = s->shift_w[2] = s->desc->log2_chroma_w;
2783 s->shift_h[1] = s->shift_h[2] = s->desc->log2_chroma_h;
2785 s->graticulef = graticule_none;
2787 switch (s->filter) {
2789 case AFLAT: s->size = 256 * 2; break;
2790 case FLAT: s->size = 256 * 3; break;
2791 default: s->size = 256; break;
2794 switch (s->filter | ((s->bits > 8) << 4) |
2795 (s->mode << 8) | (s->mirror << 12)) {
2796 case 0x1100: s->waveform_slice = lowpass_column_mirror; break;
2797 case 0x1000: s->waveform_slice = lowpass_row_mirror; break;
2798 case 0x0100: s->waveform_slice = lowpass_column; break;
2799 case 0x0000: s->waveform_slice = lowpass_row; break;
2800 case 0x1110: s->waveform_slice = lowpass16_column_mirror; break;
2801 case 0x1010: s->waveform_slice = lowpass16_row_mirror; break;
2802 case 0x0110: s->waveform_slice = lowpass16_column; break;
2803 case 0x0010: s->waveform_slice = lowpass16_row; break;
2804 case 0x1101: s->waveform_slice = flat_column_mirror; break;
2805 case 0x1001: s->waveform_slice = flat_row_mirror; break;
2806 case 0x0101: s->waveform_slice = flat_column; break;
2807 case 0x0001: s->waveform_slice = flat_row; break;
2808 case 0x1111: s->waveform_slice = flat16_column_mirror; break;
2809 case 0x1011: s->waveform_slice = flat16_row_mirror; break;
2810 case 0x0111: s->waveform_slice = flat16_column; break;
2811 case 0x0011: s->waveform_slice = flat16_row; break;
2812 case 0x1102: s->waveform_slice = aflat_column_mirror; break;
2813 case 0x1002: s->waveform_slice = aflat_row_mirror; break;
2814 case 0x0102: s->waveform_slice = aflat_column; break;
2815 case 0x0002: s->waveform_slice = aflat_row; break;
2816 case 0x1112: s->waveform_slice = aflat16_column_mirror; break;
2817 case 0x1012: s->waveform_slice = aflat16_row_mirror; break;
2818 case 0x0112: s->waveform_slice = aflat16_column; break;
2819 case 0x0012: s->waveform_slice = aflat16_row; break;
2820 case 0x1103: s->waveform_slice = chroma_column_mirror; break;
2821 case 0x1003: s->waveform_slice = chroma_row_mirror; break;
2822 case 0x0103: s->waveform_slice = chroma_column; break;
2823 case 0x0003: s->waveform_slice = chroma_row; break;
2824 case 0x1113: s->waveform_slice = chroma16_column_mirror; break;
2825 case 0x1013: s->waveform_slice = chroma16_row_mirror; break;
2826 case 0x0113: s->waveform_slice = chroma16_column; break;
2827 case 0x0013: s->waveform_slice = chroma16_row; break;
2828 case 0x1104: s->waveform_slice = color_column_mirror; break;
2829 case 0x1004: s->waveform_slice = color_row_mirror; break;
2830 case 0x0104: s->waveform_slice = color_column; break;
2831 case 0x0004: s->waveform_slice = color_row; break;
2832 case 0x1114: s->waveform_slice = color16_column_mirror; break;
2833 case 0x1014: s->waveform_slice = color16_row_mirror; break;
2834 case 0x0114: s->waveform_slice = color16_column; break;
2835 case 0x0014: s->waveform_slice = color16_row; break;
2836 case 0x1105: s->waveform_slice = acolor_column_mirror; break;
2837 case 0x1005: s->waveform_slice = acolor_row_mirror; break;
2838 case 0x0105: s->waveform_slice = acolor_column; break;
2839 case 0x0005: s->waveform_slice = acolor_row; break;
2840 case 0x1115: s->waveform_slice = acolor16_column_mirror; break;
2841 case 0x1015: s->waveform_slice = acolor16_row_mirror; break;
2842 case 0x0115: s->waveform_slice = acolor16_column; break;
2843 case 0x0015: s->waveform_slice = acolor16_row; break;
2844 case 0x1106: s->waveform_slice = xflat_column_mirror; break;
2845 case 0x1006: s->waveform_slice = xflat_row_mirror; break;
2846 case 0x0106: s->waveform_slice = xflat_column; break;
2847 case 0x0006: s->waveform_slice = xflat_row; break;
2848 case 0x1116: s->waveform_slice = xflat16_column_mirror; break;
2849 case 0x1016: s->waveform_slice = xflat16_row_mirror; break;
2850 case 0x0116: s->waveform_slice = xflat16_column; break;
2851 case 0x0016: s->waveform_slice = xflat16_row; break;
2854 s->grat_yuva_color[0] = 255;
2855 s->grat_yuva_color[2] = s->graticule == 2 ? 255 : 0;
2856 s->grat_yuva_color[3] = 255;
2858 switch (s->filter) {
2866 if (s->graticule && s->mode == 1)
2867 s->graticulef = s->bits > 8 ? graticule16_column : graticule_column;
2868 else if (s->graticule && s->mode == 0)
2869 s->graticulef = s->bits > 8 ? graticule16_row : graticule_row;
2873 switch (s->filter) {
2880 case 8: s->glines = (GraticuleLines *)digital8; s->nb_glines = FF_ARRAY_ELEMS(digital8); break;
2881 case 9: s->glines = (GraticuleLines *)digital9; s->nb_glines = FF_ARRAY_ELEMS(digital9); break;
2882 case 10: s->glines = (GraticuleLines *)digital10; s->nb_glines = FF_ARRAY_ELEMS(digital10); break;
2883 case 12: s->glines = (GraticuleLines *)digital12; s->nb_glines = FF_ARRAY_ELEMS(digital12); break;
2888 case 8: s->glines = (GraticuleLines *)millivolts8; s->nb_glines = FF_ARRAY_ELEMS(millivolts8); break;
2889 case 9: s->glines = (GraticuleLines *)millivolts9; s->nb_glines = FF_ARRAY_ELEMS(millivolts9); break;
2890 case 10: s->glines = (GraticuleLines *)millivolts10; s->nb_glines = FF_ARRAY_ELEMS(millivolts10); break;
2891 case 12: s->glines = (GraticuleLines *)millivolts12; s->nb_glines = FF_ARRAY_ELEMS(millivolts12); break;
2896 case 8: s->glines = (GraticuleLines *)ire8; s->nb_glines = FF_ARRAY_ELEMS(ire8); break;
2897 case 9: s->glines = (GraticuleLines *)ire9; s->nb_glines = FF_ARRAY_ELEMS(ire9); break;
2898 case 10: s->glines = (GraticuleLines *)ire10; s->nb_glines = FF_ARRAY_ELEMS(ire10); break;
2899 case 12: s->glines = (GraticuleLines *)ire12; s->nb_glines = FF_ARRAY_ELEMS(ire12); break;
2908 case 8: s->glines = (GraticuleLines *)chroma_digital8; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital8); break;
2909 case 9: s->glines = (GraticuleLines *)chroma_digital9; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital9); break;
2910 case 10: s->glines = (GraticuleLines *)chroma_digital10; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital10); break;
2911 case 12: s->glines = (GraticuleLines *)chroma_digital12; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital12); break;
2916 case 8: s->glines = (GraticuleLines *)millivolts8; s->nb_glines = FF_ARRAY_ELEMS(millivolts8); break;
2917 case 9: s->glines = (GraticuleLines *)millivolts9; s->nb_glines = FF_ARRAY_ELEMS(millivolts9); break;
2918 case 10: s->glines = (GraticuleLines *)millivolts10; s->nb_glines = FF_ARRAY_ELEMS(millivolts10); break;
2919 case 12: s->glines = (GraticuleLines *)millivolts12; s->nb_glines = FF_ARRAY_ELEMS(millivolts12); break;
2924 case 8: s->glines = (GraticuleLines *)ire8; s->nb_glines = FF_ARRAY_ELEMS(ire8); break;
2925 case 9: s->glines = (GraticuleLines *)ire9; s->nb_glines = FF_ARRAY_ELEMS(ire9); break;
2926 case 10: s->glines = (GraticuleLines *)ire10; s->nb_glines = FF_ARRAY_ELEMS(ire10); break;
2927 case 12: s->glines = (GraticuleLines *)ire12; s->nb_glines = FF_ARRAY_ELEMS(ire12); break;
2937 case 8: s->glines = (GraticuleLines *)aflat_digital8; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital8); break;
2938 case 9: s->glines = (GraticuleLines *)aflat_digital9; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital9); break;
2939 case 10: s->glines = (GraticuleLines *)aflat_digital10; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital10); break;
2940 case 12: s->glines = (GraticuleLines *)aflat_digital12; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital12); break;
2945 case 8: s->glines = (GraticuleLines *)aflat_millivolts8; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts8); break;
2946 case 9: s->glines = (GraticuleLines *)aflat_millivolts9; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts9); break;
2947 case 10: s->glines = (GraticuleLines *)aflat_millivolts10; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts10); break;
2948 case 12: s->glines = (GraticuleLines *)aflat_millivolts12; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts12); break;
2953 case 8: s->glines = (GraticuleLines *)aflat_ire8; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire8); break;
2954 case 9: s->glines = (GraticuleLines *)aflat_ire9; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire9); break;
2955 case 10: s->glines = (GraticuleLines *)aflat_ire10; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire10); break;
2956 case 12: s->glines = (GraticuleLines *)aflat_ire12; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire12); break;
2965 case 8: s->glines = (GraticuleLines *)flat_digital8; s->nb_glines = FF_ARRAY_ELEMS(flat_digital8); break;
2966 case 9: s->glines = (GraticuleLines *)flat_digital9; s->nb_glines = FF_ARRAY_ELEMS(flat_digital9); break;
2967 case 10: s->glines = (GraticuleLines *)flat_digital10; s->nb_glines = FF_ARRAY_ELEMS(flat_digital10); break;
2968 case 12: s->glines = (GraticuleLines *)flat_digital12; s->nb_glines = FF_ARRAY_ELEMS(flat_digital12); break;
2973 case 8: s->glines = (GraticuleLines *)flat_millivolts8; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts8); break;
2974 case 9: s->glines = (GraticuleLines *)flat_millivolts9; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts9); break;
2975 case 10: s->glines = (GraticuleLines *)flat_millivolts10; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts10); break;
2976 case 12: s->glines = (GraticuleLines *)flat_millivolts12; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts12); break;
2981 case 8: s->glines = (GraticuleLines *)flat_ire8; s->nb_glines = FF_ARRAY_ELEMS(flat_ire8); break;
2982 case 9: s->glines = (GraticuleLines *)flat_ire9; s->nb_glines = FF_ARRAY_ELEMS(flat_ire9); break;
2983 case 10: s->glines = (GraticuleLines *)flat_ire10; s->nb_glines = FF_ARRAY_ELEMS(flat_ire10); break;
2984 case 12: s->glines = (GraticuleLines *)flat_ire12; s->nb_glines = FF_ARRAY_ELEMS(flat_ire12); break;
2991 s->size = s->size << (s->bits - 8);
2993 switch (inlink->format) {
2994 case AV_PIX_FMT_GBRAP:
2995 case AV_PIX_FMT_GBRP:
2996 case AV_PIX_FMT_GBRP9:
2997 case AV_PIX_FMT_GBRP10:
2998 case AV_PIX_FMT_GBRP12:
2999 memcpy(s->bg_color, black_gbrp_color, sizeof(s->bg_color));
3000 s->graticulef = graticule_none;
3003 memcpy(s->bg_color, black_yuva_color, sizeof(s->bg_color));
3006 s->bg_color[3] *= s->bgopacity;
3011 static int config_output(AVFilterLink *outlink)
3013 AVFilterContext *ctx = outlink->src;
3014 AVFilterLink *inlink = ctx->inputs[0];
3015 WaveformContext *s = ctx->priv;
3016 int comp = 0, i, j = 0, k, p, size;
3018 for (i = 0; i < s->ncomp; i++) {
3019 if ((1 << i) & s->pcomp)
3023 s->odesc = av_pix_fmt_desc_get(outlink->format);
3024 s->dcomp = s->odesc->nb_components;
3029 outlink->h = s->size * FFMAX(comp * (s->display == STACK), 1);
3030 outlink->w = inlink->w * FFMAX(comp * (s->display == PARADE), 1);
3033 outlink->w = s->size * FFMAX(comp * (s->display == STACK), 1);
3034 outlink->h = inlink->h * FFMAX(comp * (s->display == PARADE), 1);
3038 s->peak = av_malloc_array(size, 32 * sizeof(*s->peak));
3040 return AVERROR(ENOMEM);
3042 for (p = 0; p < s->ncomp; p++) {
3043 const int plane = s->desc->comp[p].plane;
3046 if (!((1 << p) & s->pcomp))
3049 for (k = 0; k < 4; k++) {
3050 s->emax[plane][k] = s->peak + size * (plane * 4 + k + 0);
3051 s->emin[plane][k] = s->peak + size * (plane * 4 + k + 16);
3054 offset = j++ * s->size * (s->display == STACK);
3055 s->estart[plane] = offset;
3056 s->eend[plane] = (offset + s->size - 1);
3057 for (i = 0; i < size; i++) {
3058 for (k = 0; k < 4; k++) {
3059 s->emax[plane][k][i] = s->estart[plane];
3060 s->emin[plane][k][i] = s->eend[plane];
3065 outlink->sample_aspect_ratio = (AVRational){1,1};
3070 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
3072 AVFilterContext *ctx = inlink->dst;
3073 WaveformContext *s = ctx->priv;
3074 AVFilterLink *outlink = ctx->outputs[0];
3078 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
3081 return AVERROR(ENOMEM);
3084 out->color_range = AVCOL_RANGE_JPEG;
3086 for (k = 0; k < s->dcomp; k++) {
3088 for (i = 0; i < outlink->h ; i++)
3089 memset(out->data[s->odesc->comp[k].plane] +
3090 i * out->linesize[s->odesc->comp[k].plane],
3091 s->bg_color[k], outlink->w);
3093 const int mult = s->max / 256;
3094 uint16_t *dst = (uint16_t *)out->data[s->odesc->comp[k].plane];
3096 for (i = 0; i < outlink->h ; i++) {
3097 for (j = 0; j < outlink->w; j++)
3098 dst[j] = s->bg_color[k] * mult;
3099 dst += out->linesize[s->odesc->comp[k].plane] / 2;
3104 for (k = 0, i = 0; k < s->ncomp; k++) {
3105 if ((1 << k) & s->pcomp) {
3106 const int plane = s->desc->comp[k].plane;
3111 if (s->display == PARADE) {
3112 offset_x = s->mode ? i++ * inlink->w : 0;
3113 offset_y = s->mode ? 0 : i++ * inlink->h;
3115 offset_y = s->mode ? i++ * s->size * !!s->display : 0;
3116 offset_x = s->mode ? 0 : i++ * s->size * !!s->display;
3122 td.offset_y = offset_y;
3123 td.offset_x = offset_x;
3124 ctx->internal->execute(ctx, s->waveform_slice, &td, NULL, ff_filter_get_nb_threads(ctx));
3125 switch (s->filter) {
3131 envelope(s, out, plane, plane, s->mode ? offset_x : offset_y);
3133 envelope16(s, out, plane, plane, s->mode ? offset_x : offset_y);
3137 envelope(s, out, plane, plane, s->mode ? offset_x : offset_y);
3138 envelope(s, out, plane, (plane + 1) % s->ncomp, s->mode ? offset_x : offset_y);
3140 envelope16(s, out, plane, plane, s->mode ? offset_x : offset_y);
3141 envelope16(s, out, plane, (plane + 1) % s->ncomp, s->mode ? offset_x : offset_y);
3147 envelope(s, out, plane, (plane + 0) % s->ncomp, s->mode ? offset_x : offset_y);
3148 envelope(s, out, plane, (plane + 1) % s->ncomp, s->mode ? offset_x : offset_y);
3149 envelope(s, out, plane, (plane + 2) % s->ncomp, s->mode ? offset_x : offset_y);
3151 envelope16(s, out, plane, (plane + 0) % s->ncomp, s->mode ? offset_x : offset_y);
3152 envelope16(s, out, plane, (plane + 1) % s->ncomp, s->mode ? offset_x : offset_y);
3153 envelope16(s, out, plane, (plane + 2) % s->ncomp, s->mode ? offset_x : offset_y);
3159 s->graticulef(s, out);
3162 return ff_filter_frame(outlink, out);
3165 static av_cold void uninit(AVFilterContext *ctx)
3167 WaveformContext *s = ctx->priv;
3172 static const AVFilterPad inputs[] = {
3175 .type = AVMEDIA_TYPE_VIDEO,
3176 .filter_frame = filter_frame,
3177 .config_props = config_input,
3182 static const AVFilterPad outputs[] = {
3185 .type = AVMEDIA_TYPE_VIDEO,
3186 .config_props = config_output,
3191 AVFilter ff_vf_waveform = {
3193 .description = NULL_IF_CONFIG_SMALL("Video waveform monitor."),
3194 .priv_size = sizeof(WaveformContext),
3195 .priv_class = &waveform_class,
3196 .query_formats = query_formats,
3200 .flags = AVFILTER_FLAG_SLICE_THREADS,