FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vf_waveform.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2016 Paul B Mahol
3  * Copyright (c) 2013 Marton Balint
4  *
5  * This file is part of FFmpeg.
6  *
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.
11  *
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.
16  *
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
20  */
21 
22 #include "libavutil/avassert.h"
23 #include "libavutil/opt.h"
24 #include "libavutil/parseutils.h"
25 #include "libavutil/pixdesc.h"
27 #include "avfilter.h"
28 #include "formats.h"
29 #include "internal.h"
30 #include "video.h"
31 
32 enum FilterType {
40 };
41 
47 };
48 
49 enum ScaleType {
52  IRE,
54 };
55 
56 typedef struct GraticuleLine {
57  const char *name;
58  uint16_t pos;
60 
61 typedef struct GraticuleLines {
62  struct GraticuleLine line[4];
64 
65 typedef struct WaveformContext {
66  const AVClass *class;
67  int mode;
68  int acomp;
69  int dcomp;
70  int ncomp;
71  int pcomp;
73  float fintensity;
74  int intensity;
75  int mirror;
76  int display;
77  int envelope;
78  int graticule;
79  float opacity;
80  float bgopacity;
81  int estart[4];
82  int eend[4];
83  int *emax[4][4];
84  int *emin[4][4];
85  int *peak;
86  int filter;
87  int flags;
88  int bits;
89  int max;
90  int size;
91  int scale;
92  int shift_w[4], shift_h[4];
94  int nb_glines;
96  AVFrame *in, AVFrame *out,
97  int component, int intensity,
98  int offset_y, int offset_x,
99  int column, int mirror);
104 
105 #define OFFSET(x) offsetof(WaveformContext, x)
106 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
107 
108 static const AVOption waveform_options[] = {
109  { "mode", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "mode" },
110  { "m", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "mode" },
111  { "row", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "mode" },
112  { "column", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "mode" },
113  { "intensity", "set intensity", OFFSET(fintensity), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 1, FLAGS },
114  { "i", "set intensity", OFFSET(fintensity), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 1, FLAGS },
115  { "mirror", "set mirroring", OFFSET(mirror), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
116  { "r", "set mirroring", OFFSET(mirror), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
117  { "display", "set display mode", OFFSET(display), AV_OPT_TYPE_INT, {.i64=STACK}, 0, NB_DISPLAYS-1, FLAGS, "display" },
118  { "d", "set display mode", OFFSET(display), AV_OPT_TYPE_INT, {.i64=STACK}, 0, NB_DISPLAYS-1, FLAGS, "display" },
119  { "overlay", NULL, 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY}, 0, 0, FLAGS, "display" },
120  { "stack", NULL, 0, AV_OPT_TYPE_CONST, {.i64=STACK}, 0, 0, FLAGS, "display" },
121  { "parade", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PARADE}, 0, 0, FLAGS, "display" },
122  { "components", "set components to display", OFFSET(pcomp), AV_OPT_TYPE_INT, {.i64=1}, 1, 15, FLAGS },
123  { "c", "set components to display", OFFSET(pcomp), AV_OPT_TYPE_INT, {.i64=1}, 1, 15, FLAGS },
124  { "envelope", "set envelope to display", OFFSET(envelope), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "envelope" },
125  { "e", "set envelope to display", OFFSET(envelope), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "envelope" },
126  { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "envelope" },
127  { "instant", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "envelope" },
128  { "peak", NULL, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "envelope" },
129  { "peak+instant", NULL, 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, FLAGS, "envelope" },
130  { "filter", "set filter", OFFSET(filter), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_FILTERS-1, FLAGS, "filter" },
131  { "f", "set filter", OFFSET(filter), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_FILTERS-1, FLAGS, "filter" },
132  { "lowpass", NULL, 0, AV_OPT_TYPE_CONST, {.i64=LOWPASS}, 0, 0, FLAGS, "filter" },
133  { "flat" , NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAT}, 0, 0, FLAGS, "filter" },
134  { "aflat" , NULL, 0, AV_OPT_TYPE_CONST, {.i64=AFLAT}, 0, 0, FLAGS, "filter" },
135  { "chroma", NULL, 0, AV_OPT_TYPE_CONST, {.i64=CHROMA}, 0, 0, FLAGS, "filter" },
136  { "color", NULL, 0, AV_OPT_TYPE_CONST, {.i64=COLOR}, 0, 0, FLAGS, "filter" },
137  { "acolor", NULL, 0, AV_OPT_TYPE_CONST, {.i64=ACOLOR}, 0, 0, FLAGS, "filter" },
138  { "graticule", "set graticule", OFFSET(graticule), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "graticule" },
139  { "g", "set graticule", OFFSET(graticule), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "graticule" },
140  { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "graticule" },
141  { "green", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "graticule" },
142  { "opacity", "set graticule opacity", OFFSET(opacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
143  { "o", "set graticule opacity", OFFSET(opacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
144  { "flags", "set graticule flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64=1}, 0, 3, FLAGS, "flags" },
145  { "fl", "set graticule flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64=1}, 0, 3, FLAGS, "flags" },
146  { "numbers", "draw numbers", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "flags" },
147  { "dots", "draw dots instead of lines", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "flags" },
148  { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SCALES-1, FLAGS, "scale" },
149  { "s", "set scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SCALES-1, FLAGS, "scale" },
150  { "digital", NULL, 0, AV_OPT_TYPE_CONST, {.i64=DIGITAL}, 0, 0, FLAGS, "scale" },
151  { "millivolts", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MILLIVOLTS}, 0, 0, FLAGS, "scale" },
152  { "ire", NULL, 0, AV_OPT_TYPE_CONST, {.i64=IRE}, 0, 0, FLAGS, "scale" },
153  { "bgopacity", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
154  { "b", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
155  { NULL }
156 };
157 
159 
160 static const enum AVPixelFormat in_lowpass_pix_fmts[] = {
176 };
177 
178 static const enum AVPixelFormat in_color_pix_fmts[] = {
193 };
194 
195 static const enum AVPixelFormat in_flat_pix_fmts[] = {
208 };
209 
213 };
214 
218 };
219 
223 };
224 
228 };
229 
233 };
234 
238 };
239 
243 };
244 
248 };
249 
253 };
254 
258 };
259 
263 };
264 
265 static const enum AVPixelFormat flat_pix_fmts[] = {
270 };
271 
273 {
274  WaveformContext *s = ctx->priv;
275  const enum AVPixelFormat *out_pix_fmts;
276  const enum AVPixelFormat *in_pix_fmts;
277  const AVPixFmtDescriptor *desc;
278  AVFilterFormats *avff;
279  int depth, rgb, i, ret, ncomp;
280 
281  if (!ctx->inputs[0]->in_formats ||
282  !ctx->inputs[0]->in_formats->nb_formats) {
283  return AVERROR(EAGAIN);
284  }
285 
286  switch (s->filter) {
287  case LOWPASS: in_pix_fmts = in_lowpass_pix_fmts; break;
288  case CHROMA:
289  case AFLAT:
290  case FLAT: in_pix_fmts = in_flat_pix_fmts; break;
291  case ACOLOR:
292  case COLOR: in_pix_fmts = in_color_pix_fmts; break;
293  }
294 
295  if (!ctx->inputs[0]->out_formats) {
296  if ((ret = ff_formats_ref(ff_make_format_list(in_pix_fmts), &ctx->inputs[0]->out_formats)) < 0)
297  return ret;
298  }
299 
300  avff = ctx->inputs[0]->in_formats;
301  desc = av_pix_fmt_desc_get(avff->formats[0]);
302  ncomp = desc->nb_components;
303  rgb = desc->flags & AV_PIX_FMT_FLAG_RGB;
304  depth = desc->comp[0].depth;
305  for (i = 1; i < avff->nb_formats; i++) {
306  desc = av_pix_fmt_desc_get(avff->formats[i]);
307  if (rgb != (desc->flags & AV_PIX_FMT_FLAG_RGB) ||
308  depth != desc->comp[0].depth)
309  return AVERROR(EAGAIN);
310  }
311 
312  if (s->filter == LOWPASS && ncomp == 1 && depth == 8)
313  out_pix_fmts = out_gray8_lowpass_pix_fmts;
314  else if (s->filter == LOWPASS && ncomp == 1 && depth == 10)
315  out_pix_fmts = out_gray10_lowpass_pix_fmts;
316  else if (s->filter == LOWPASS && ncomp == 1 && depth == 12)
317  out_pix_fmts = out_gray12_lowpass_pix_fmts;
318  else if (rgb && depth == 8 && ncomp > 2)
319  out_pix_fmts = out_rgb8_lowpass_pix_fmts;
320  else if (rgb && depth == 9 && ncomp > 2)
321  out_pix_fmts = out_rgb9_lowpass_pix_fmts;
322  else if (rgb && depth == 10 && ncomp > 2)
323  out_pix_fmts = out_rgb10_lowpass_pix_fmts;
324  else if (rgb && depth == 12 && ncomp > 2)
325  out_pix_fmts = out_rgb12_lowpass_pix_fmts;
326  else if (depth == 8 && ncomp > 2)
327  out_pix_fmts = out_yuv8_lowpass_pix_fmts;
328  else if (depth == 9 && ncomp > 2)
329  out_pix_fmts = out_yuv9_lowpass_pix_fmts;
330  else if (depth == 10 && ncomp > 2)
331  out_pix_fmts = out_yuv10_lowpass_pix_fmts;
332  else if (depth == 12 && ncomp > 2)
333  out_pix_fmts = out_yuv12_lowpass_pix_fmts;
334  else
335  return AVERROR(EAGAIN);
336  if ((ret = ff_formats_ref(ff_make_format_list(out_pix_fmts), &ctx->outputs[0]->in_formats)) < 0)
337  return ret;
338 
339  return 0;
340 }
341 
342 static void envelope_instant16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
343 {
344  const int dst_linesize = out->linesize[component] / 2;
345  const int bg = s->bg_color[component] * (s->max / 256);
346  const int limit = s->max - 1;
347  const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
348  const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
349  const int start = s->estart[plane];
350  const int end = s->eend[plane];
351  uint16_t *dst;
352  int x, y;
353 
354  if (s->mode) {
355  for (x = offset; x < offset + dst_w; x++) {
356  for (y = start; y < end; y++) {
357  dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
358  if (dst[0] != bg) {
359  dst[0] = limit;
360  break;
361  }
362  }
363  for (y = end - 1; y >= start; y--) {
364  dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
365  if (dst[0] != bg) {
366  dst[0] = limit;
367  break;
368  }
369  }
370  }
371  } else {
372  for (y = offset; y < offset + dst_h; y++) {
373  dst = (uint16_t *)out->data[component] + y * dst_linesize;
374  for (x = start; x < end; x++) {
375  if (dst[x] != bg) {
376  dst[x] = limit;
377  break;
378  }
379  }
380  for (x = end - 1; x >= start; x--) {
381  if (dst[x] != bg) {
382  dst[x] = limit;
383  break;
384  }
385  }
386  }
387  }
388 }
389 
390 static void envelope_instant(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
391 {
392  const int dst_linesize = out->linesize[component];
393  const uint8_t bg = s->bg_color[component];
394  const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
395  const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
396  const int start = s->estart[plane];
397  const int end = s->eend[plane];
398  uint8_t *dst;
399  int x, y;
400 
401  if (s->mode) {
402  for (x = offset; x < offset + dst_w; x++) {
403  for (y = start; y < end; y++) {
404  dst = out->data[component] + y * dst_linesize + x;
405  if (dst[0] != bg) {
406  dst[0] = 255;
407  break;
408  }
409  }
410  for (y = end - 1; y >= start; y--) {
411  dst = out->data[component] + y * dst_linesize + x;
412  if (dst[0] != bg) {
413  dst[0] = 255;
414  break;
415  }
416  }
417  }
418  } else {
419  for (y = offset; y < offset + dst_h; y++) {
420  dst = out->data[component] + y * dst_linesize;
421  for (x = start; x < end; x++) {
422  if (dst[x] != bg) {
423  dst[x] = 255;
424  break;
425  }
426  }
427  for (x = end - 1; x >= start; x--) {
428  if (dst[x] != bg) {
429  dst[x] = 255;
430  break;
431  }
432  }
433  }
434  }
435 }
436 
437 static void envelope_peak16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
438 {
439  const int dst_linesize = out->linesize[component] / 2;
440  const int bg = s->bg_color[component] * (s->max / 256);
441  const int limit = s->max - 1;
442  const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
443  const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
444  const int start = s->estart[plane];
445  const int end = s->eend[plane];
446  int *emax = s->emax[plane][component];
447  int *emin = s->emin[plane][component];
448  uint16_t *dst;
449  int x, y;
450 
451  if (s->mode) {
452  for (x = offset; x < offset + dst_w; x++) {
453  for (y = start; y < end && y < emin[x - offset]; y++) {
454  dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
455  if (dst[0] != bg) {
456  emin[x - offset] = y;
457  break;
458  }
459  }
460  for (y = end - 1; y >= start && y >= emax[x - offset]; y--) {
461  dst = (uint16_t *)out->data[component] + y * dst_linesize + x;
462  if (dst[0] != bg) {
463  emax[x - offset] = y;
464  break;
465  }
466  }
467  }
468 
469  if (s->envelope == 3)
470  envelope_instant16(s, out, plane, component, offset);
471 
472  for (x = offset; x < offset + dst_w; x++) {
473  dst = (uint16_t *)out->data[component] + emin[x - offset] * dst_linesize + x;
474  dst[0] = limit;
475  dst = (uint16_t *)out->data[component] + emax[x - offset] * dst_linesize + x;
476  dst[0] = limit;
477  }
478  } else {
479  for (y = offset; y < offset + dst_h; y++) {
480  dst = (uint16_t *)out->data[component] + y * dst_linesize;
481  for (x = start; x < end && x < emin[y - offset]; x++) {
482  if (dst[x] != bg) {
483  emin[y - offset] = x;
484  break;
485  }
486  }
487  for (x = end - 1; x >= start && x >= emax[y - offset]; x--) {
488  if (dst[x] != bg) {
489  emax[y - offset] = x;
490  break;
491  }
492  }
493  }
494 
495  if (s->envelope == 3)
496  envelope_instant16(s, out, plane, component, offset);
497 
498  for (y = offset; y < offset + dst_h; y++) {
499  dst = (uint16_t *)out->data[component] + y * dst_linesize + emin[y - offset];
500  dst[0] = limit;
501  dst = (uint16_t *)out->data[component] + y * dst_linesize + emax[y - offset];
502  dst[0] = limit;
503  }
504  }
505 }
506 
507 static void envelope_peak(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
508 {
509  const int dst_linesize = out->linesize[component];
510  const int bg = s->bg_color[component];
511  const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
512  const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
513  const int start = s->estart[plane];
514  const int end = s->eend[plane];
515  int *emax = s->emax[plane][component];
516  int *emin = s->emin[plane][component];
517  uint8_t *dst;
518  int x, y;
519 
520  if (s->mode) {
521  for (x = offset; x < offset + dst_w; x++) {
522  for (y = start; y < end && y < emin[x - offset]; y++) {
523  dst = out->data[component] + y * dst_linesize + x;
524  if (dst[0] != bg) {
525  emin[x - offset] = y;
526  break;
527  }
528  }
529  for (y = end - 1; y >= start && y >= emax[x - offset]; y--) {
530  dst = out->data[component] + y * dst_linesize + x;
531  if (dst[0] != bg) {
532  emax[x - offset] = y;
533  break;
534  }
535  }
536  }
537 
538  if (s->envelope == 3)
539  envelope_instant(s, out, plane, component, offset);
540 
541  for (x = offset; x < offset + dst_w; x++) {
542  dst = out->data[component] + emin[x - offset] * dst_linesize + x;
543  dst[0] = 255;
544  dst = out->data[component] + emax[x - offset] * dst_linesize + x;
545  dst[0] = 255;
546  }
547  } else {
548  for (y = offset; y < offset + dst_h; y++) {
549  dst = out->data[component] + y * dst_linesize;
550  for (x = start; x < end && x < emin[y - offset]; x++) {
551  if (dst[x] != bg) {
552  emin[y - offset] = x;
553  break;
554  }
555  }
556  for (x = end - 1; x >= start && x >= emax[y - offset]; x--) {
557  if (dst[x] != bg) {
558  emax[y - offset] = x;
559  break;
560  }
561  }
562  }
563 
564  if (s->envelope == 3)
565  envelope_instant(s, out, plane, component, offset);
566 
567  for (y = offset; y < offset + dst_h; y++) {
568  dst = out->data[component] + y * dst_linesize + emin[y - offset];
569  dst[0] = 255;
570  dst = out->data[component] + y * dst_linesize + emax[y - offset];
571  dst[0] = 255;
572  }
573  }
574 }
575 
576 static void envelope16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
577 {
578  if (s->envelope == 0) {
579  return;
580  } else if (s->envelope == 1) {
581  envelope_instant16(s, out, plane, component, offset);
582  } else {
583  envelope_peak16(s, out, plane, component, offset);
584  }
585 }
586 
587 static void envelope(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
588 {
589  if (s->envelope == 0) {
590  return;
591  } else if (s->envelope == 1) {
592  envelope_instant(s, out, plane, component, offset);
593  } else {
594  envelope_peak(s, out, plane, component, offset);
595  }
596 }
597 
598 static void update16(uint16_t *target, int max, int intensity, int limit)
599 {
600  if (*target <= max)
601  *target += intensity;
602  else
603  *target = limit;
604 }
605 
606 static void update(uint8_t *target, int max, int intensity)
607 {
608  if (*target <= max)
609  *target += intensity;
610  else
611  *target = 255;
612 }
613 
615  AVFrame *in, AVFrame *out,
616  int component, int intensity,
617  int offset_y, int offset_x,
618  int column, int mirror)
619 {
620  const int plane = s->desc->comp[component].plane;
621  const int shift_w = s->shift_w[component];
622  const int shift_h = s->shift_h[component];
623  const int src_linesize = in->linesize[plane] / 2;
624  const int dst_linesize = out->linesize[plane] / 2;
625  const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
626  const int limit = s->max - 1;
627  const int max = limit - intensity;
628  const int src_h = AV_CEIL_RSHIFT(in->height, shift_h);
629  const int src_w = AV_CEIL_RSHIFT(in->width, shift_w);
630  const uint16_t *src_data = (const uint16_t *)in->data[plane];
631  uint16_t *dst_data = (uint16_t *)out->data[plane] + offset_y * dst_linesize + offset_x;
632  uint16_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
633  uint16_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
634  const int step = column ? 1 << shift_w : 1 << shift_h;
635  const uint16_t *p;
636  int y;
637 
638  if (!column && mirror)
639  dst_data += s->size;
640 
641  for (y = 0; y < src_h; y++) {
642  const uint16_t *src_data_end = src_data + src_w;
643  uint16_t *dst = dst_line;
644 
645  for (p = src_data; p < src_data_end; p++) {
646  uint16_t *target;
647  int i = 0, v = FFMIN(*p, limit);
648 
649  if (column) {
650  do {
651  target = dst++ + dst_signed_linesize * v;
652  update16(target, max, intensity, limit);
653  } while (++i < step);
654  } else {
655  uint16_t *row = dst_data;
656  do {
657  if (mirror)
658  target = row - v - 1;
659  else
660  target = row + v;
661  update16(target, max, intensity, limit);
662  row += dst_linesize;
663  } while (++i < step);
664  }
665  }
666  src_data += src_linesize;
667  dst_data += dst_linesize * step;
668  }
669 
670  envelope16(s, out, plane, plane, column ? offset_x : offset_y);
671 }
672 
673 #define LOWPASS16_FUNC(name, column, mirror) \
674 static void lowpass16_##name(WaveformContext *s, \
675  AVFrame *in, AVFrame *out, \
676  int component, int intensity, \
677  int offset_y, int offset_x, \
678  int unused1, int unused2) \
679 { \
680  lowpass16(s, in, out, component, intensity, \
681  offset_y, offset_x, column, mirror); \
682 }
683 
684 LOWPASS16_FUNC(column_mirror, 1, 1)
685 LOWPASS16_FUNC(column, 1, 0)
686 LOWPASS16_FUNC(row_mirror, 0, 1)
687 LOWPASS16_FUNC(row, 0, 0)
688 
690  AVFrame *in, AVFrame *out,
691  int component, int intensity,
692  int offset_y, int offset_x,
693  int column, int mirror)
694 {
695  const int plane = s->desc->comp[component].plane;
696  const int shift_w = s->shift_w[component];
697  const int shift_h = s->shift_h[component];
698  const int src_linesize = in->linesize[plane];
699  const int dst_linesize = out->linesize[plane];
700  const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
701  const int max = 255 - intensity;
702  const int src_h = AV_CEIL_RSHIFT(in->height, shift_h);
703  const int src_w = AV_CEIL_RSHIFT(in->width, shift_w);
704  const uint8_t *src_data = in->data[plane];
705  uint8_t *dst_data = out->data[plane] + offset_y * dst_linesize + offset_x;
706  uint8_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
707  uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
708  const int step = column ? 1 << shift_w : 1 << shift_h;
709  const uint8_t *p;
710  int y;
711 
712  if (!column && mirror)
713  dst_data += s->size;
714 
715  for (y = 0; y < src_h; y++) {
716  const uint8_t *src_data_end = src_data + src_w;
717  uint8_t *dst = dst_line;
718 
719  for (p = src_data; p < src_data_end; p++) {
720  uint8_t *target;
721  if (column) {
722  target = dst + dst_signed_linesize * *p;
723  dst += step;
724  update(target, max, intensity);
725  } else {
726  uint8_t *row = dst_data;
727  if (mirror)
728  target = row - *p - 1;
729  else
730  target = row + *p;
731  update(target, max, intensity);
732  row += dst_linesize;
733  }
734  }
735  src_data += src_linesize;
736  dst_data += dst_linesize * step;
737  }
738 
739  if (column && step > 1) {
740  const int dst_w = s->display == PARADE ? out->width / s->acomp : out->width;
741  const int dst_h = 256;
742  uint8_t *dst;
743  int x, z;
744 
745  dst = out->data[plane] + offset_y * dst_linesize + offset_x;
746  for (y = 0; y < dst_h; y++) {
747  for (x = 0; x < dst_w; x+=step) {
748  for (z = 1; z < step; z++) {
749  dst[x + z] = dst[x];
750  }
751  }
752  dst += dst_linesize;
753  }
754  } else if (step > 1) {
755  const int dst_h = s->display == PARADE ? out->height / s->acomp : out->height;
756  const int dst_w = 256;
757  uint8_t *dst;
758  int z;
759 
760  dst = out->data[plane] + offset_y * dst_linesize + offset_x;
761  for (y = 0; y < dst_h; y+=step) {
762  for (z = 1; z < step; z++)
763  memcpy(dst + dst_linesize * z, dst, dst_w);
764  dst += dst_linesize * step;
765  }
766  }
767 
768  envelope(s, out, plane, plane, column ? offset_x : offset_y);
769 }
770 
771 #define LOWPASS_FUNC(name, column, mirror) \
772 static void lowpass_##name(WaveformContext *s, \
773  AVFrame *in, AVFrame *out, \
774  int component, int intensity, \
775  int offset_y, int offset_x, \
776  int unused1, int unused2) \
777 { \
778  lowpass(s, in, out, component, intensity, \
779  offset_y, offset_x, column, mirror); \
780 }
781 
782 LOWPASS_FUNC(column_mirror, 1, 1)
783 LOWPASS_FUNC(column, 1, 0)
784 LOWPASS_FUNC(row_mirror, 0, 1)
785 LOWPASS_FUNC(row, 0, 0)
786 
788  AVFrame *in, AVFrame *out,
789  int component, int intensity,
790  int offset_y, int offset_x,
791  int column, int mirror)
792 {
793  const int plane = s->desc->comp[component].plane;
794  const int c0_linesize = in->linesize[ plane + 0 ] / 2;
795  const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
796  const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
797  const int c0_shift_w = s->shift_w[ component + 0 ];
798  const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
799  const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
800  const int c0_shift_h = s->shift_h[ component + 0 ];
801  const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
802  const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
803  const int d0_linesize = out->linesize[ plane + 0 ] / 2;
804  const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
805  const int limit = s->max - 1;
806  const int max = limit - intensity;
807  const int mid = s->max / 2;
808  const int src_h = in->height;
809  const int src_w = in->width;
810  int x, y;
811 
812  if (column) {
813  const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
814  const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
815 
816  for (x = 0; x < src_w; x++) {
817  const uint16_t *c0_data = (uint16_t *)in->data[plane + 0];
818  const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
819  const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
820  uint16_t *d0_data = (uint16_t *)(out->data[plane]) + offset_y * d0_linesize + offset_x;
821  uint16_t *d1_data = (uint16_t *)(out->data[(plane + 1) % s->ncomp]) + offset_y * d1_linesize + offset_x;
822  uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
823  uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
824  uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
825  uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
826 
827  for (y = 0; y < src_h; y++) {
828  const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + s->max;
829  const int c1 = FFMIN(FFABS(c1_data[x >> c1_shift_w] - mid) + FFABS(c2_data[x >> c2_shift_w] - mid), limit);
830  uint16_t *target;
831 
832  target = d0 + x + d0_signed_linesize * c0;
833  update16(target, max, intensity, limit);
834  target = d1 + x + d1_signed_linesize * (c0 - c1);
835  update16(target, max, intensity, limit);
836  target = d1 + x + d1_signed_linesize * (c0 + c1);
837  update16(target, max, intensity, limit);
838 
839  if (!c0_shift_h || (y & c0_shift_h))
840  c0_data += c0_linesize;
841  if (!c1_shift_h || (y & c1_shift_h))
842  c1_data += c1_linesize;
843  if (!c2_shift_h || (y & c2_shift_h))
844  c2_data += c2_linesize;
845  d0_data += d0_linesize;
846  d1_data += d1_linesize;
847  }
848  }
849  } else {
850  const uint16_t *c0_data = (uint16_t *)in->data[plane];
851  const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
852  const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
853  uint16_t *d0_data = (uint16_t *)(out->data[plane]) + offset_y * d0_linesize + offset_x;
854  uint16_t *d1_data = (uint16_t *)(out->data[(plane + 1) % s->ncomp]) + offset_y * d1_linesize + offset_x;
855 
856  if (mirror) {
857  d0_data += s->size - 1;
858  d1_data += s->size - 1;
859  }
860 
861  for (y = 0; y < src_h; y++) {
862  for (x = 0; x < src_w; x++) {
863  const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + s->max;
864  const int c1 = FFMIN(FFABS(c1_data[x >> c1_shift_w] - mid) + FFABS(c2_data[x >> c2_shift_w] - mid), limit);
865  uint16_t *target;
866 
867  if (mirror) {
868  target = d0_data - c0;
869  update16(target, max, intensity, limit);
870  target = d1_data - (c0 - c1);
871  update16(target, max, intensity, limit);
872  target = d1_data - (c0 + c1);
873  update16(target, max, intensity, limit);
874  } else {
875  target = d0_data + c0;
876  update16(target, max, intensity, limit);
877  target = d1_data + (c0 - c1);
878  update16(target, max, intensity, limit);
879  target = d1_data + (c0 + c1);
880  update16(target, max, intensity, limit);
881  }
882  }
883 
884  if (!c0_shift_h || (y & c0_shift_h))
885  c0_data += c0_linesize;
886  if (!c1_shift_h || (y & c1_shift_h))
887  c1_data += c1_linesize;
888  if (!c2_shift_h || (y & c2_shift_h))
889  c2_data += c2_linesize;
890  d0_data += d0_linesize;
891  d1_data += d1_linesize;
892  }
893  }
894 
895  envelope16(s, out, plane, plane, column ? offset_x : offset_y);
896  envelope16(s, out, plane, (plane + 1) % s->ncomp, column ? offset_x : offset_y);
897 }
898 
900  AVFrame *in, AVFrame *out,
901  int component, int intensity,
902  int offset_y, int offset_x,
903  int column, int mirror)
904 {
905  const int plane = s->desc->comp[component].plane;
906  const int c0_linesize = in->linesize[ plane + 0 ];
907  const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
908  const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
909  const int c0_shift_w = s->shift_w[ component + 0 ];
910  const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
911  const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
912  const int c0_shift_h = s->shift_h[ component + 0 ];
913  const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
914  const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
915  const int d0_linesize = out->linesize[ plane + 0 ];
916  const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
917  const int max = 255 - intensity;
918  const int src_h = in->height;
919  const int src_w = in->width;
920  int x, y;
921 
922  if (column) {
923  const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
924  const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
925 
926  for (x = 0; x < src_w; x++) {
927  const uint8_t *c0_data = in->data[plane + 0];
928  const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
929  const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
930  uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
931  uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
932  uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
933  uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
934  uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
935  uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
936 
937  for (y = 0; y < src_h; y++) {
938  const int c0 = c0_data[x >> c0_shift_w] + 256;
939  const int c1 = FFABS(c1_data[x >> c1_shift_w] - 128) + FFABS(c2_data[x >> c2_shift_w] - 128);
940  uint8_t *target;
941 
942  target = d0 + x + d0_signed_linesize * c0;
943  update(target, max, intensity);
944  target = d1 + x + d1_signed_linesize * (c0 - c1);
945  update(target, max, intensity);
946  target = d1 + x + d1_signed_linesize * (c0 + c1);
947  update(target, max, intensity);
948 
949  if (!c0_shift_h || (y & c0_shift_h))
950  c0_data += c0_linesize;
951  if (!c1_shift_h || (y & c1_shift_h))
952  c1_data += c1_linesize;
953  if (!c2_shift_h || (y & c2_shift_h))
954  c2_data += c2_linesize;
955  d0_data += d0_linesize;
956  d1_data += d1_linesize;
957  }
958  }
959  } else {
960  const uint8_t *c0_data = in->data[plane];
961  const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
962  const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
963  uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
964  uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
965 
966  if (mirror) {
967  d0_data += s->size - 1;
968  d1_data += s->size - 1;
969  }
970 
971  for (y = 0; y < src_h; y++) {
972  for (x = 0; x < src_w; x++) {
973  int c0 = c0_data[x >> c0_shift_w] + 256;
974  const int c1 = FFABS(c1_data[x >> c1_shift_w] - 128) + FFABS(c2_data[x >> c2_shift_w] - 128);
975  uint8_t *target;
976 
977  if (mirror) {
978  target = d0_data - c0;
979  update(target, max, intensity);
980  target = d1_data - (c0 - c1);
981  update(target, max, intensity);
982  target = d1_data - (c0 + c1);
983  update(target, max, intensity);
984  } else {
985  target = d0_data + c0;
986  update(target, max, intensity);
987  target = d1_data + (c0 - c1);
988  update(target, max, intensity);
989  target = d1_data + (c0 + c1);
990  update(target, max, intensity);
991  }
992  }
993 
994  if (!c0_shift_h || (y & c0_shift_h))
995  c0_data += c0_linesize;
996  if (!c1_shift_h || (y & c1_shift_h))
997  c1_data += c1_linesize;
998  if (!c2_shift_h || (y & c2_shift_h))
999  c2_data += c2_linesize;
1000  d0_data += d0_linesize;
1001  d1_data += d1_linesize;
1002  }
1003  }
1004 
1005  envelope(s, out, plane, plane, column ? offset_x : offset_y);
1006  envelope(s, out, plane, (plane + 1) % s->ncomp, column ? offset_x : offset_y);
1007 }
1008 
1010  AVFrame *in, AVFrame *out,
1011  int component, int intensity,
1012  int offset_y, int offset_x,
1013  int column, int mirror)
1014 {
1015  const int plane = s->desc->comp[component].plane;
1016  const int c0_linesize = in->linesize[ plane + 0 ] / 2;
1017  const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1018  const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1019  const int c0_shift_w = s->shift_w[ component + 0 ];
1020  const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1021  const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1022  const int c0_shift_h = s->shift_h[ component + 0 ];
1023  const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1024  const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1025  const int d0_linesize = out->linesize[ plane + 0 ] / 2;
1026  const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
1027  const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2;
1028  const int limit = s->max - 1;
1029  const int max = limit - intensity;
1030  const int mid = s->max / 2;
1031  const int src_h = in->height;
1032  const int src_w = in->width;
1033  int x, y;
1034 
1035  if (column) {
1036  const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1037  const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1038  const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1039 
1040  for (x = 0; x < src_w; x++) {
1041  const uint16_t *c0_data = (uint16_t *)in->data[plane + 0];
1042  const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1043  const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1044  uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1045  uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1046  uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1047  uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1048  uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1049  uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1050  uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1051  uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1052  uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1053 
1054  for (y = 0; y < src_h; y++) {
1055  const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + mid;
1056  const int c1 = FFMIN(c1_data[x >> c1_shift_w], limit) - mid;
1057  const int c2 = FFMIN(c2_data[x >> c2_shift_w], limit) - mid;
1058  uint16_t *target;
1059 
1060  target = d0 + x + d0_signed_linesize * c0;
1061  update16(target, max, intensity, limit);
1062 
1063  target = d1 + x + d1_signed_linesize * (c0 + c1);
1064  update16(target, max, intensity, limit);
1065 
1066  target = d2 + x + d2_signed_linesize * (c0 + c2);
1067  update16(target, max, intensity, limit);
1068 
1069  if (!c0_shift_h || (y & c0_shift_h))
1070  c0_data += c0_linesize;
1071  if (!c1_shift_h || (y & c1_shift_h))
1072  c1_data += c1_linesize;
1073  if (!c2_shift_h || (y & c2_shift_h))
1074  c2_data += c2_linesize;
1075  d0_data += d0_linesize;
1076  d1_data += d1_linesize;
1077  d2_data += d2_linesize;
1078  }
1079  }
1080  } else {
1081  const uint16_t *c0_data = (uint16_t *)in->data[plane];
1082  const uint16_t *c1_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1083  const uint16_t *c2_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1084  uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1085  uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1086  uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1087 
1088  if (mirror) {
1089  d0_data += s->size - 1;
1090  d1_data += s->size - 1;
1091  d2_data += s->size - 1;
1092  }
1093 
1094  for (y = 0; y < src_h; y++) {
1095  for (x = 0; x < src_w; x++) {
1096  const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit) + mid;
1097  const int c1 = FFMIN(c1_data[x >> c1_shift_w], limit) - mid;
1098  const int c2 = FFMIN(c2_data[x >> c2_shift_w], limit) - mid;
1099  uint16_t *target;
1100 
1101  if (mirror) {
1102  target = d0_data - c0;
1103  update16(target, max, intensity, limit);
1104  target = d1_data - (c0 + c1);
1105  update16(target, max, intensity, limit);
1106  target = d2_data - (c0 + c2);
1107  update16(target, max, intensity, limit);
1108  } else {
1109  target = d0_data + c0;
1110  update16(target, max, intensity, limit);
1111  target = d1_data + (c0 + c1);
1112  update16(target, max, intensity, limit);
1113  target = d2_data + (c0 + c2);
1114  update16(target, max, intensity, limit);
1115  }
1116  }
1117 
1118  if (!c0_shift_h || (y & c0_shift_h))
1119  c0_data += c0_linesize;
1120  if (!c1_shift_h || (y & c1_shift_h))
1121  c1_data += c1_linesize;
1122  if (!c2_shift_h || (y & c2_shift_h))
1123  c2_data += c2_linesize;
1124  d0_data += d0_linesize;
1125  d1_data += d1_linesize;
1126  d2_data += d2_linesize;
1127  }
1128  }
1129 
1130  envelope16(s, out, plane, (plane + 0) % s->ncomp, column ? offset_x : offset_y);
1131  envelope16(s, out, plane, (plane + 1) % s->ncomp, column ? offset_x : offset_y);
1132  envelope16(s, out, plane, (plane + 2) % s->ncomp, column ? offset_x : offset_y);
1133 }
1134 
1136  AVFrame *in, AVFrame *out,
1137  int component, int intensity,
1138  int offset_y, int offset_x,
1139  int column, int mirror)
1140 {
1141  const int plane = s->desc->comp[component].plane;
1142  const int c0_linesize = in->linesize[ plane + 0 ];
1143  const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
1144  const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
1145  const int c0_shift_w = s->shift_w[ component + 0 ];
1146  const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1147  const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1148  const int c0_shift_h = s->shift_h[ component + 0 ];
1149  const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1150  const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1151  const int d0_linesize = out->linesize[ plane + 0 ];
1152  const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
1153  const int d2_linesize = out->linesize[(plane + 2) % s->ncomp];
1154  const int max = 255 - intensity;
1155  const int src_h = in->height;
1156  const int src_w = in->width;
1157  int x, y;
1158 
1159  if (column) {
1160  const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1161  const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1162  const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1163 
1164  for (x = 0; x < src_w; x++) {
1165  const uint8_t *c0_data = in->data[plane + 0];
1166  const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1167  const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1168  uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1169  uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1170  uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1171  uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1172  uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1173  uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1174  uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1175  uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1176  uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1177 
1178  for (y = 0; y < src_h; y++) {
1179  const int c0 = c0_data[x >> c0_shift_w] + 128;
1180  const int c1 = c1_data[x >> c1_shift_w] - 128;
1181  const int c2 = c2_data[x >> c2_shift_w] - 128;
1182  uint8_t *target;
1183 
1184  target = d0 + x + d0_signed_linesize * c0;
1185  update(target, max, intensity);
1186 
1187  target = d1 + x + d1_signed_linesize * (c0 + c1);
1188  update(target, max, intensity);
1189 
1190  target = d2 + x + d2_signed_linesize * (c0 + c2);
1191  update(target, max, intensity);
1192 
1193  if (!c0_shift_h || (y & c0_shift_h))
1194  c0_data += c0_linesize;
1195  if (!c1_shift_h || (y & c1_shift_h))
1196  c1_data += c1_linesize;
1197  if (!c1_shift_h || (y & c1_shift_h))
1198  c2_data += c1_linesize;
1199  d0_data += d0_linesize;
1200  d1_data += d1_linesize;
1201  d2_data += d2_linesize;
1202  }
1203  }
1204  } else {
1205  const uint8_t *c0_data = in->data[plane];
1206  const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1207  const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1208  uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1209  uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1210  uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1211 
1212  if (mirror) {
1213  d0_data += s->size - 1;
1214  d1_data += s->size - 1;
1215  d2_data += s->size - 1;
1216  }
1217 
1218  for (y = 0; y < src_h; y++) {
1219  for (x = 0; x < src_w; x++) {
1220  const int c0 = c0_data[x >> c0_shift_w] + 128;
1221  const int c1 = c1_data[x >> c1_shift_w] - 128;
1222  const int c2 = c2_data[x >> c2_shift_w] - 128;
1223  uint8_t *target;
1224 
1225  if (mirror) {
1226  target = d0_data - c0;
1227  update(target, max, intensity);
1228  target = d1_data - (c0 + c1);
1229  update(target, max, intensity);
1230  target = d2_data - (c0 + c2);
1231  update(target, max, intensity);
1232  } else {
1233  target = d0_data + c0;
1234  update(target, max, intensity);
1235  target = d1_data + (c0 + c1);
1236  update(target, max, intensity);
1237  target = d2_data + (c0 + c2);
1238  update(target, max, intensity);
1239  }
1240  }
1241 
1242  if (!c0_shift_h || (y & c0_shift_h))
1243  c0_data += c0_linesize;
1244  if (!c1_shift_h || (y & c1_shift_h))
1245  c1_data += c1_linesize;
1246  if (!c2_shift_h || (y & c2_shift_h))
1247  c2_data += c2_linesize;
1248  d0_data += d0_linesize;
1249  d1_data += d1_linesize;
1250  d2_data += d2_linesize;
1251  }
1252  }
1253 
1254  envelope(s, out, plane, (plane + 0) % s->ncomp, column ? offset_x : offset_y);
1255  envelope(s, out, plane, (plane + 1) % s->ncomp, column ? offset_x : offset_y);
1256  envelope(s, out, plane, (plane + 2) % s->ncomp, column ? offset_x : offset_y);
1257 }
1258 
1260  AVFrame *in, AVFrame *out,
1261  int component, int intensity,
1262  int offset_y, int offset_x,
1263  int column, int mirror)
1264 {
1265  const int plane = s->desc->comp[component].plane;
1266  const int c0_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1267  const int c1_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1268  const int dst_linesize = out->linesize[plane] / 2;
1269  const int limit = s->max - 1;
1270  const int max = limit - intensity;
1271  const int mid = s->max / 2;
1272  const int c0_shift_w = s->shift_w[(component + 1) % s->ncomp];
1273  const int c1_shift_w = s->shift_w[(component + 2) % s->ncomp];
1274  const int c0_shift_h = s->shift_h[(component + 1) % s->ncomp];
1275  const int c1_shift_h = s->shift_h[(component + 2) % s->ncomp];
1276  const int src_h = in->height;
1277  const int src_w = in->width;
1278  int x, y;
1279 
1280  if (column) {
1281  const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
1282 
1283  for (x = 0; x < src_w; x++) {
1284  const uint16_t *c0_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1285  const uint16_t *c1_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1286  uint16_t *dst_data = (uint16_t *)out->data[plane] + offset_y * dst_linesize + offset_x;
1287  uint16_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
1288  uint16_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
1289  uint16_t *dst = dst_line;
1290 
1291  for (y = 0; y < src_h; y++) {
1292  const int sum = FFMIN(FFABS(c0_data[x >> c0_shift_w] - mid) + FFABS(c1_data[x >> c1_shift_w] - mid - 1), limit);
1293  uint16_t *target;
1294 
1295  target = dst + x + dst_signed_linesize * sum;
1296  update16(target, max, intensity, limit);
1297 
1298  if (!c0_shift_h || (y & c0_shift_h))
1299  c0_data += c0_linesize;
1300  if (!c1_shift_h || (y & c1_shift_h))
1301  c1_data += c1_linesize;
1302  dst_data += dst_linesize;
1303  }
1304  }
1305  } else {
1306  const uint16_t *c0_data = (uint16_t *)in->data[(plane + 1) % s->ncomp];
1307  const uint16_t *c1_data = (uint16_t *)in->data[(plane + 2) % s->ncomp];
1308  uint16_t *dst_data = (uint16_t *)out->data[plane] + offset_y * dst_linesize + offset_x;
1309 
1310  if (mirror)
1311  dst_data += s->size - 1;
1312  for (y = 0; y < src_h; y++) {
1313  for (x = 0; x < src_w; x++) {
1314  const int sum = FFMIN(FFABS(c0_data[x >> c0_shift_w] - mid) + FFABS(c1_data[x >> c1_shift_w] - mid - 1), limit);
1315  uint16_t *target;
1316 
1317  if (mirror) {
1318  target = dst_data - sum;
1319  update16(target, max, intensity, limit);
1320  } else {
1321  target = dst_data + sum;
1322  update16(target, max, intensity, limit);
1323  }
1324  }
1325 
1326  if (!c0_shift_h || (y & c0_shift_h))
1327  c0_data += c0_linesize;
1328  if (!c1_shift_h || (y & c1_shift_h))
1329  c1_data += c1_linesize;
1330  dst_data += dst_linesize;
1331  }
1332  }
1333 
1334  envelope16(s, out, plane, plane, column ? offset_x : offset_y);
1335 }
1336 
1338  AVFrame *in, AVFrame *out,
1339  int component, int intensity,
1340  int offset_y, int offset_x,
1341  int column, int mirror)
1342 {
1343  const int plane = s->desc->comp[component].plane;
1344  const int c0_linesize = in->linesize[(plane + 1) % s->ncomp];
1345  const int c1_linesize = in->linesize[(plane + 2) % s->ncomp];
1346  const int dst_linesize = out->linesize[plane];
1347  const int max = 255 - intensity;
1348  const int c0_shift_w = s->shift_w[(component + 1) % s->ncomp];
1349  const int c1_shift_w = s->shift_w[(component + 2) % s->ncomp];
1350  const int c0_shift_h = s->shift_h[(component + 1) % s->ncomp];
1351  const int c1_shift_h = s->shift_h[(component + 2) % s->ncomp];
1352  const int src_h = in->height;
1353  const int src_w = in->width;
1354  int x, y;
1355 
1356  if (column) {
1357  const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
1358 
1359  for (x = 0; x < src_w; x++) {
1360  const uint8_t *c0_data = in->data[(plane + 1) % s->ncomp];
1361  const uint8_t *c1_data = in->data[(plane + 2) % s->ncomp];
1362  uint8_t *dst_data = out->data[plane] + offset_y * dst_linesize + offset_x;
1363  uint8_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
1364  uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
1365  uint8_t *dst = dst_line;
1366 
1367  for (y = 0; y < src_h; y++) {
1368  const int sum = FFABS(c0_data[x >> c0_shift_w] - 128) + FFABS(c1_data[x >> c1_shift_w] - 127);
1369  uint8_t *target;
1370 
1371  target = dst + x + dst_signed_linesize * sum;
1372  update(target, max, intensity);
1373 
1374  if (!c0_shift_h || (y & c0_shift_h))
1375  c0_data += c0_linesize;
1376  if (!c1_shift_h || (y & c1_shift_h))
1377  c1_data += c1_linesize;
1378  dst_data += dst_linesize;
1379  }
1380  }
1381  } else {
1382  const uint8_t *c0_data = in->data[(plane + 1) % s->ncomp];
1383  const uint8_t *c1_data = in->data[(plane + 2) % s->ncomp];
1384  uint8_t *dst_data = out->data[plane] + offset_y * dst_linesize + offset_x;
1385 
1386  if (mirror)
1387  dst_data += s->size - 1;
1388  for (y = 0; y < src_h; y++) {
1389  for (x = 0; x < src_w; x++) {
1390  const int sum = FFABS(c0_data[x >> c0_shift_w] - 128) + FFABS(c1_data[x >> c1_shift_w] - 127);
1391  uint8_t *target;
1392 
1393  if (mirror) {
1394  target = dst_data - sum;
1395  update(target, max, intensity);
1396  } else {
1397  target = dst_data + sum;
1398  update(target, max, intensity);
1399  }
1400  }
1401 
1402  if (!c0_shift_h || (y & c0_shift_h))
1403  c0_data += c0_linesize;
1404  if (!c1_shift_h || (y & c1_shift_h))
1405  c1_data += c1_linesize;
1406  dst_data += dst_linesize;
1407  }
1408  }
1409 
1410  envelope(s, out, plane, plane, column ? offset_x : offset_y);
1411 }
1412 
1414  AVFrame *in, AVFrame *out,
1415  int component, int intensity,
1416  int offset_y, int offset_x,
1417  int column, int mirror)
1418 {
1419  const int plane = s->desc->comp[component].plane;
1420  const int limit = s->max - 1;
1421  const uint16_t *c0_data = (const uint16_t *)in->data[plane + 0];
1422  const uint16_t *c1_data = (const uint16_t *)in->data[(plane + 1) % s->ncomp];
1423  const uint16_t *c2_data = (const uint16_t *)in->data[(plane + 2) % s->ncomp];
1424  const int c0_linesize = in->linesize[ plane + 0 ] / 2;
1425  const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1426  const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1427  const int d0_linesize = out->linesize[ plane + 0 ] / 2;
1428  const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
1429  const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2;
1430  const int c0_shift_w = s->shift_w[ component + 0 ];
1431  const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1432  const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1433  const int c0_shift_h = s->shift_h[ component + 0 ];
1434  const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1435  const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1436  const int src_h = in->height;
1437  const int src_w = in->width;
1438  int x, y;
1439 
1440  if (column) {
1441  const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1442  const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1443  const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1444  uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1445  uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1446  uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1447  uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1448  uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1449  uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1450  uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1451  uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1452  uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1453 
1454  for (y = 0; y < src_h; y++) {
1455  for (x = 0; x < src_w; x++) {
1456  const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1457  const int c1 = c1_data[x >> c1_shift_w];
1458  const int c2 = c2_data[x >> c2_shift_w];
1459 
1460  *(d0 + d0_signed_linesize * c0 + x) = c0;
1461  *(d1 + d1_signed_linesize * c0 + x) = c1;
1462  *(d2 + d2_signed_linesize * c0 + x) = c2;
1463  }
1464 
1465  if (!c0_shift_h || (y & c0_shift_h))
1466  c0_data += c0_linesize;
1467  if (!c1_shift_h || (y & c1_shift_h))
1468  c1_data += c1_linesize;
1469  if (!c2_shift_h || (y & c2_shift_h))
1470  c2_data += c2_linesize;
1471  d0_data += d0_linesize;
1472  d1_data += d1_linesize;
1473  d2_data += d2_linesize;
1474  }
1475  } else {
1476  uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1477  uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1478  uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1479 
1480  if (mirror) {
1481  d0_data += s->size - 1;
1482  d1_data += s->size - 1;
1483  d2_data += s->size - 1;
1484  }
1485 
1486  for (y = 0; y < src_h; y++) {
1487  for (x = 0; x < src_w; x++) {
1488  const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1489  const int c1 = c1_data[x >> c1_shift_w];
1490  const int c2 = c2_data[x >> c2_shift_w];
1491 
1492  if (mirror) {
1493  *(d0_data - c0) = c0;
1494  *(d1_data - c0) = c1;
1495  *(d2_data - c0) = c2;
1496  } else {
1497  *(d0_data + c0) = c0;
1498  *(d1_data + c0) = c1;
1499  *(d2_data + c0) = c2;
1500  }
1501  }
1502 
1503  if (!c0_shift_h || (y & c0_shift_h))
1504  c0_data += c0_linesize;
1505  if (!c1_shift_h || (y & c1_shift_h))
1506  c1_data += c1_linesize;
1507  if (!c2_shift_h || (y & c2_shift_h))
1508  c2_data += c2_linesize;
1509  d0_data += d0_linesize;
1510  d1_data += d1_linesize;
1511  d2_data += d2_linesize;
1512  }
1513  }
1514 
1515  envelope16(s, out, plane, plane, column ? offset_x : offset_y);
1516 }
1517 
1519  AVFrame *in, AVFrame *out,
1520  int component, int intensity,
1521  int offset_y, int offset_x,
1522  int column, int mirror)
1523 {
1524  const int plane = s->desc->comp[component].plane;
1525  const uint8_t *c0_data = in->data[plane + 0];
1526  const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1527  const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1528  const int c0_linesize = in->linesize[ plane + 0 ];
1529  const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
1530  const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
1531  const int d0_linesize = out->linesize[ plane + 0 ];
1532  const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
1533  const int d2_linesize = out->linesize[(plane + 2) % s->ncomp];
1534  const int c0_shift_w = s->shift_w[ component + 0 ];
1535  const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1536  const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1537  const int c0_shift_h = s->shift_h[ component + 0 ];
1538  const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1539  const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1540  const int src_h = in->height;
1541  const int src_w = in->width;
1542  int x, y;
1543 
1544  if (s->mode) {
1545  const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1546  const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1547  const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1548  uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1549  uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1550  uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1551  uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1552  uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1553  uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1554  uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1555  uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1556  uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1557 
1558  for (y = 0; y < src_h; y++) {
1559  for (x = 0; x < src_w; x++) {
1560  const int c0 = c0_data[x >> c0_shift_w];
1561  const int c1 = c1_data[x >> c1_shift_w];
1562  const int c2 = c2_data[x >> c2_shift_w];
1563 
1564  *(d0 + d0_signed_linesize * c0 + x) = c0;
1565  *(d1 + d1_signed_linesize * c0 + x) = c1;
1566  *(d2 + d2_signed_linesize * c0 + x) = c2;
1567  }
1568 
1569  if (!c0_shift_h || (y & c0_shift_h))
1570  c0_data += c0_linesize;
1571  if (!c1_shift_h || (y & c1_shift_h))
1572  c1_data += c1_linesize;
1573  if (!c2_shift_h || (y & c2_shift_h))
1574  c2_data += c2_linesize;
1575  d0_data += d0_linesize;
1576  d1_data += d1_linesize;
1577  d2_data += d2_linesize;
1578  }
1579  } else {
1580  uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1581  uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1582  uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1583 
1584  if (mirror) {
1585  d0_data += s->size - 1;
1586  d1_data += s->size - 1;
1587  d2_data += s->size - 1;
1588  }
1589 
1590  for (y = 0; y < src_h; y++) {
1591  for (x = 0; x < src_w; x++) {
1592  const int c0 = c0_data[x >> c0_shift_w];
1593  const int c1 = c1_data[x >> c1_shift_w];
1594  const int c2 = c2_data[x >> c2_shift_w];
1595 
1596  if (mirror) {
1597  *(d0_data - c0) = c0;
1598  *(d1_data - c0) = c1;
1599  *(d2_data - c0) = c2;
1600  } else {
1601  *(d0_data + c0) = c0;
1602  *(d1_data + c0) = c1;
1603  *(d2_data + c0) = c2;
1604  }
1605  }
1606 
1607  if (!c0_shift_h || (y & c0_shift_h))
1608  c0_data += c0_linesize;
1609  if (!c1_shift_h || (y & c1_shift_h))
1610  c1_data += c1_linesize;
1611  if (!c2_shift_h || (y & c2_shift_h))
1612  c2_data += c2_linesize;
1613  d0_data += d0_linesize;
1614  d1_data += d1_linesize;
1615  d2_data += d2_linesize;
1616  }
1617  }
1618 
1619  envelope(s, out, plane, plane, column ? offset_x : offset_y);
1620 }
1621 
1623  AVFrame *in, AVFrame *out,
1624  int component, int intensity,
1625  int offset_y, int offset_x,
1626  int column, int mirror)
1627 {
1628  const int plane = s->desc->comp[component].plane;
1629  const int limit = s->max - 1;
1630  const int max = limit - intensity;
1631  const uint16_t *c0_data = (const uint16_t *)in->data[plane + 0];
1632  const uint16_t *c1_data = (const uint16_t *)in->data[(plane + 1) % s->ncomp];
1633  const uint16_t *c2_data = (const uint16_t *)in->data[(plane + 2) % s->ncomp];
1634  const int c0_linesize = in->linesize[ plane + 0 ] / 2;
1635  const int c1_linesize = in->linesize[(plane + 1) % s->ncomp] / 2;
1636  const int c2_linesize = in->linesize[(plane + 2) % s->ncomp] / 2;
1637  const int d0_linesize = out->linesize[ plane + 0 ] / 2;
1638  const int d1_linesize = out->linesize[(plane + 1) % s->ncomp] / 2;
1639  const int d2_linesize = out->linesize[(plane + 2) % s->ncomp] / 2;
1640  const int c0_shift_w = s->shift_w[ component + 0 ];
1641  const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1642  const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1643  const int c0_shift_h = s->shift_h[ component + 0 ];
1644  const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1645  const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1646  const int src_h = in->height;
1647  const int src_w = in->width;
1648  int x, y;
1649 
1650  if (s->mode) {
1651  const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1652  const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1653  const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1654  uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1655  uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1656  uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1657  uint16_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1658  uint16_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1659  uint16_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1660  uint16_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1661  uint16_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1662  uint16_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1663 
1664  for (y = 0; y < src_h; y++) {
1665  for (x = 0; x < src_w; x++) {
1666  const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1667  const int c1 = c1_data[x >> c1_shift_w];
1668  const int c2 = c2_data[x >> c2_shift_w];
1669 
1670  update16(d0 + d0_signed_linesize * c0 + x, max, intensity, limit);
1671  *(d1 + d1_signed_linesize * c0 + x) = c1;
1672  *(d2 + d2_signed_linesize * c0 + x) = c2;
1673  }
1674 
1675  if (!c0_shift_h || (y & c0_shift_h))
1676  c0_data += c0_linesize;
1677  if (!c1_shift_h || (y & c1_shift_h))
1678  c1_data += c1_linesize;
1679  if (!c2_shift_h || (y & c2_shift_h))
1680  c2_data += c2_linesize;
1681  d0_data += d0_linesize;
1682  d1_data += d1_linesize;
1683  d2_data += d2_linesize;
1684  }
1685  } else {
1686  uint16_t *d0_data = (uint16_t *)out->data[plane] + offset_y * d0_linesize + offset_x;
1687  uint16_t *d1_data = (uint16_t *)out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1688  uint16_t *d2_data = (uint16_t *)out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1689 
1690  if (mirror) {
1691  d0_data += s->size - 1;
1692  d1_data += s->size - 1;
1693  d2_data += s->size - 1;
1694  }
1695 
1696  for (y = 0; y < src_h; y++) {
1697  for (x = 0; x < src_w; x++) {
1698  const int c0 = FFMIN(c0_data[x >> c0_shift_w], limit);
1699  const int c1 = c1_data[x >> c1_shift_w];
1700  const int c2 = c2_data[x >> c2_shift_w];
1701 
1702  if (mirror) {
1703  update16(d0_data - c0, max, intensity, limit);
1704  *(d1_data - c0) = c1;
1705  *(d2_data - c0) = c2;
1706  } else {
1707  update16(d0_data + c0, max, intensity, limit);
1708  *(d1_data + c0) = c1;
1709  *(d2_data + c0) = c2;
1710  }
1711  }
1712 
1713  if (!c0_shift_h || (y & c0_shift_h))
1714  c0_data += c0_linesize;
1715  if (!c1_shift_h || (y & c1_shift_h))
1716  c1_data += c1_linesize;
1717  if (!c2_shift_h || (y & c2_shift_h))
1718  c2_data += c2_linesize;
1719  d0_data += d0_linesize;
1720  d1_data += d1_linesize;
1721  d2_data += d2_linesize;
1722  }
1723  }
1724 
1725  envelope16(s, out, plane, plane, column ? offset_x : offset_y);
1726 }
1727 
1729  AVFrame *in, AVFrame *out,
1730  int component, int intensity,
1731  int offset_y, int offset_x,
1732  int column, int mirror)
1733 {
1734  const int plane = s->desc->comp[component].plane;
1735  const uint8_t *c0_data = in->data[plane + 0];
1736  const uint8_t *c1_data = in->data[(plane + 1) % s->ncomp];
1737  const uint8_t *c2_data = in->data[(plane + 2) % s->ncomp];
1738  const int c0_linesize = in->linesize[ plane + 0 ];
1739  const int c1_linesize = in->linesize[(plane + 1) % s->ncomp];
1740  const int c2_linesize = in->linesize[(plane + 2) % s->ncomp];
1741  const int d0_linesize = out->linesize[ plane + 0 ];
1742  const int d1_linesize = out->linesize[(plane + 1) % s->ncomp];
1743  const int d2_linesize = out->linesize[(plane + 2) % s->ncomp];
1744  const int c0_shift_w = s->shift_w[ component + 0 ];
1745  const int c1_shift_w = s->shift_w[(component + 1) % s->ncomp];
1746  const int c2_shift_w = s->shift_w[(component + 2) % s->ncomp];
1747  const int c0_shift_h = s->shift_h[ component + 0 ];
1748  const int c1_shift_h = s->shift_h[(component + 1) % s->ncomp];
1749  const int c2_shift_h = s->shift_h[(component + 2) % s->ncomp];
1750  const int max = 255 - intensity;
1751  const int src_h = in->height;
1752  const int src_w = in->width;
1753  int x, y;
1754 
1755  if (s->mode) {
1756  const int d0_signed_linesize = d0_linesize * (mirror == 1 ? -1 : 1);
1757  const int d1_signed_linesize = d1_linesize * (mirror == 1 ? -1 : 1);
1758  const int d2_signed_linesize = d2_linesize * (mirror == 1 ? -1 : 1);
1759  uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1760  uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1761  uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1762  uint8_t * const d0_bottom_line = d0_data + d0_linesize * (s->size - 1);
1763  uint8_t * const d0 = (mirror ? d0_bottom_line : d0_data);
1764  uint8_t * const d1_bottom_line = d1_data + d1_linesize * (s->size - 1);
1765  uint8_t * const d1 = (mirror ? d1_bottom_line : d1_data);
1766  uint8_t * const d2_bottom_line = d2_data + d2_linesize * (s->size - 1);
1767  uint8_t * const d2 = (mirror ? d2_bottom_line : d2_data);
1768 
1769  for (y = 0; y < src_h; y++) {
1770  for (x = 0; x < src_w; x++) {
1771  const int c0 = c0_data[x >> c0_shift_w];
1772  const int c1 = c1_data[x >> c1_shift_w];
1773  const int c2 = c2_data[x >> c2_shift_w];
1774 
1775  update(d0 + d0_signed_linesize * c0 + x, max, intensity);
1776  *(d1 + d1_signed_linesize * c0 + x) = c1;
1777  *(d2 + d2_signed_linesize * c0 + x) = c2;
1778  }
1779 
1780  if (!c0_shift_h || (y & c0_shift_h))
1781  c0_data += c0_linesize;
1782  if (!c1_shift_h || (y & c1_shift_h))
1783  c1_data += c1_linesize;
1784  if (!c2_shift_h || (y & c2_shift_h))
1785  c2_data += c2_linesize;
1786  d0_data += d0_linesize;
1787  d1_data += d1_linesize;
1788  d2_data += d2_linesize;
1789  }
1790  } else {
1791  uint8_t *d0_data = out->data[plane] + offset_y * d0_linesize + offset_x;
1792  uint8_t *d1_data = out->data[(plane + 1) % s->ncomp] + offset_y * d1_linesize + offset_x;
1793  uint8_t *d2_data = out->data[(plane + 2) % s->ncomp] + offset_y * d2_linesize + offset_x;
1794 
1795  if (mirror) {
1796  d0_data += s->size - 1;
1797  d1_data += s->size - 1;
1798  d2_data += s->size - 1;
1799  }
1800 
1801  for (y = 0; y < src_h; y++) {
1802  for (x = 0; x < src_w; x++) {
1803  const int c0 = c0_data[x >> c0_shift_w];
1804  const int c1 = c1_data[x >> c1_shift_w];
1805  const int c2 = c2_data[x >> c2_shift_w];
1806 
1807  if (mirror) {
1808  update(d0_data - c0, max, intensity);
1809  *(d1_data - c0) = c1;
1810  *(d2_data - c0) = c2;
1811  } else {
1812  update(d0_data + c0, max, intensity);
1813  *(d1_data + c0) = c1;
1814  *(d2_data + c0) = c2;
1815  }
1816  }
1817 
1818  if (!c0_shift_h || (y & c0_shift_h))
1819  c0_data += c0_linesize;
1820  if (!c1_shift_h || (y & c1_shift_h))
1821  c1_data += c1_linesize;
1822  if (!c2_shift_h || (y & c2_shift_h))
1823  c2_data += c2_linesize;
1824  d0_data += d0_linesize;
1825  d1_data += d1_linesize;
1826  d2_data += d2_linesize;
1827  }
1828  }
1829 
1830  envelope(s, out, plane, plane, column ? offset_x : offset_y);
1831 }
1832 
1833 static const uint8_t black_yuva_color[4] = { 0, 127, 127, 255 };
1834 static const uint8_t green_yuva_color[4] = { 255, 0, 0, 255 };
1835 static const uint8_t black_gbrp_color[4] = { 0, 0, 0, 255 };
1836 
1837 static const GraticuleLines aflat_digital8[] = {
1838  { { { "16", 16+128 }, { "16", 16+128 }, { "16", 16+128 }, { "0", 0+128 } } },
1839  { { { "128", 128+128 }, { "128", 128+128 }, { "128", 128+128 }, { "128", 128+128 } } },
1840  { { { "235", 235+128 }, { "240", 240+128 }, { "240", 240+128 }, { "255", 255+128 } } },
1841 };
1842 
1843 static const GraticuleLines aflat_digital9[] = {
1844  { { { "32", 32+256 }, { "32", 32+256 }, { "32", 32+256 }, { "0", 0+256 } } },
1845  { { { "256", 256+256 }, { "256", 256+256 }, { "256", 256+256 }, { "256", 256+256 } } },
1846  { { { "470", 470+256 }, { "480", 480+256 }, { "480", 480+256 }, { "511", 511+256 } } },
1847 };
1848 
1850  { { { "64", 64+512 }, { "64", 64+512 }, { "64", 64+512 }, { "0", 0+512 } } },
1851  { { { "512", 512+512 }, { "512", 512+512 }, { "512", 512+512 }, { "512", 512+512 } } },
1852  { { { "940", 940+512 }, { "960", 960+512 }, { "960", 960+512 }, { "1023", 1023+512 } } },
1853 };
1854 
1856  { { { "256", 256+2048 }, { "256", 256+2048 }, { "256", 256+2048 }, { "0", 0+2048 } } },
1857  { { { "2048", 2048+2048 }, { "2048", 2048+2048 }, { "2048", 2048+2048 }, { "2048", 2048+2048 } } },
1858  { { { "3760", 3760+2048 }, { "3840", 3840+2048 }, { "3840", 3840+2048 }, { "4095", 4095+2048 } } },
1859 };
1860 
1862  { { { "0", 16+128 }, { "0", 16+128 }, { "0", 16+128 }, { "0", 0+128 } } },
1863  { { { "175", 71+128 }, { "175", 72+128 }, { "175", 72+128 }, { "175", 64+128 } } },
1864  { { { "350", 126+128 }, { "350", 128+128 }, { "350", 128+128 }, { "350", 128+128 } } },
1865  { { { "525", 180+128 }, { "525", 184+128 }, { "525", 184+128 }, { "525", 192+128 } } },
1866  { { { "700", 235+128 }, { "700", 240+128 }, { "700", 240+128 }, { "700", 255+128 } } },
1867 };
1868 
1870  { { { "0", 32+256 }, { "0", 32+256 }, { "0", 32+256 }, { "0", 0+256 } } },
1871  { { { "175", 142+256 }, { "175", 144+256 }, { "175", 144+256 }, { "175", 128+256 } } },
1872  { { { "350", 251+256 }, { "350", 256+256 }, { "350", 256+256 }, { "350", 256+256 } } },
1873  { { { "525", 361+256 }, { "525", 368+256 }, { "525", 368+256 }, { "525", 384+256 } } },
1874  { { { "700", 470+256 }, { "700", 480+256 }, { "700", 480+256 }, { "700", 511+256 } } },
1875 };
1876 
1878  { { { "0", 64+512 }, { "0", 64+512 }, { "0", 64+512 }, { "0", 0+512 } } },
1879  { { { "175", 283+512 }, { "175", 288+512 }, { "175", 288+512 }, { "175", 256+512 } } },
1880  { { { "350", 502+512 }, { "350", 512+512 }, { "350", 512+512 }, { "350", 512+512 } } },
1881  { { { "525", 721+512 }, { "525", 736+512 }, { "525", 736+512 }, { "525", 768+512 } } },
1882  { { { "700", 940+512 }, { "700", 960+512 }, { "700", 960+512 }, { "700", 1023+512 } } },
1883 };
1884 
1886  { { { "0", 256+2048 }, { "0", 256+2048 }, { "0", 256+2048 }, { "0", 0+2048 } } },
1887  { { { "175", 1132+2048 }, { "175", 1152+2048 }, { "175", 1152+2048 }, { "175", 1024+2048 } } },
1888  { { { "350", 2008+2048 }, { "350", 2048+2048 }, { "350", 2048+2048 }, { "350", 2048+2048 } } },
1889  { { { "525", 2884+2048 }, { "525", 2944+2048 }, { "525", 2944+2048 }, { "525", 3072+2048 } } },
1890  { { { "700", 3760+2048 }, { "700", 3840+2048 }, { "700", 3840+2048 }, { "700", 4095+2048 } } },
1891 };
1892 
1893 static const GraticuleLines aflat_ire8[] = {
1894  { { { "-25", -39+128 }, { "-25", -40+128 }, { "-25", -40+128 }, { "-25", -64+128 } } },
1895  { { { "0", 16+128 }, { "0", 16+128 }, { "0", 16+128 }, { "0", 0+128 } } },
1896  { { { "25", 71+128 }, { "25", 72+128 }, { "25", 72+128 }, { "25", 64+128 } } },
1897  { { { "50", 126+128 }, { "50", 128+128 }, { "50", 128+128 }, { "50", 128+128 } } },
1898  { { { "75", 180+128 }, { "75", 184+128 }, { "75", 184+128 }, { "75", 192+128 } } },
1899  { { { "100", 235+128 }, { "100", 240+128 }, { "100", 240+128 }, { "100", 256+128 } } },
1900  { { { "125", 290+128 }, { "125", 296+128 }, { "125", 296+128 }, { "125", 320+128 } } },
1901 };
1902 
1903 static const GraticuleLines aflat_ire9[] = {
1904  { { { "-25", -78+256 }, { "-25", -80+256 }, { "-25", -80+256 }, { "-25",-128+256 } } },
1905  { { { "0", 32+256 }, { "0", 32+256 }, { "0", 32+256 }, { "0", 0+256 } } },
1906  { { { "25", 142+256 }, { "25", 144+256 }, { "25", 144+256 }, { "25", 128+256 } } },
1907  { { { "50", 251+256 }, { "50", 256+256 }, { "50", 256+256 }, { "50", 256+256 } } },
1908  { { { "75", 361+256 }, { "75", 368+256 }, { "75", 368+256 }, { "75", 384+256 } } },
1909  { { { "100", 470+256 }, { "100", 480+256 }, { "100", 480+256 }, { "100", 512+256 } } },
1910  { { { "125", 580+256 }, { "125", 592+256 }, { "125", 592+256 }, { "125", 640+256 } } },
1911 };
1912 
1913 static const GraticuleLines aflat_ire10[] = {
1914  { { { "-25",-156+512 }, { "-25",-160+512 }, { "-25",-160+512 }, { "-25", -256+512 } } },
1915  { { { "0", 64+512 }, { "0", 64+512 }, { "0", 64+512 }, { "0", 0+512 } } },
1916  { { { "25", 283+512 }, { "25", 288+512 }, { "25", 288+512 }, { "25", 256+512 } } },
1917  { { { "50", 502+512 }, { "50", 512+512 }, { "50", 512+512 }, { "50", 512+512 } } },
1918  { { { "75", 721+512 }, { "75", 736+512 }, { "75", 736+512 }, { "75", 768+512 } } },
1919  { { { "100", 940+512 }, { "100", 960+512 }, { "100", 960+512 }, { "100", 1024+512 } } },
1920  { { { "125",1160+512 }, { "125",1184+512 }, { "125",1184+512 }, { "125", 1280+512 } } },
1921 };
1922 
1923 static const GraticuleLines aflat_ire12[] = {
1924  { { { "-25", -624+2048 }, { "-25", -640+2048 }, { "-25", -640+2048 }, { "-25",-1024+2048 } } },
1925  { { { "0", 256+2048 }, { "0", 256+2048 }, { "0", 256+2048 }, { "0", 0+2048 } } },
1926  { { { "25", 1132+2048 }, { "25", 1152+2048 }, { "25", 1152+2048 }, { "25", 1024+2048 } } },
1927  { { { "50", 2008+2048 }, { "50", 2048+2048 }, { "50", 2048+2048 }, { "50", 2048+2048 } } },
1928  { { { "75", 2884+2048 }, { "75", 2944+2048 }, { "75", 2944+2048 }, { "75", 3072+2048 } } },
1929  { { { "100", 3760+2048 }, { "100", 3840+2048 }, { "100", 3840+2048 }, { "100", 4096+2048 } } },
1930  { { { "125", 4640+2048 }, { "125", 4736+2048 }, { "125", 4736+2048 }, { "125", 5120+2048 } } },
1931 };
1932 
1933 static const GraticuleLines flat_digital8[] = {
1934  { { { "16", 16+256 }, { "16", 16+256 }, { "16", 16+256 }, { "0", 0+256 } } },
1935  { { { "128", 128+256 }, { "128", 128+256 }, { "128", 128+256 }, { "128", 128+256 } } },
1936  { { { "235", 235+256 }, { "240", 240+256 }, { "240", 240+256 }, { "255", 255+256 } } },
1937 };
1938 
1939 static const GraticuleLines flat_digital9[] = {
1940  { { { "32", 32+512 }, { "32", 32+512 }, { "32", 32+512 }, { "0", 0+512 } } },
1941  { { { "256", 256+512 }, { "256", 256+512 }, { "256", 256+512 }, { "256", 256+512 } } },
1942  { { { "470", 470+512 }, { "480", 480+512 }, { "480", 480+512 }, { "511", 511+512 } } },
1943 };
1944 
1945 static const GraticuleLines flat_digital10[] = {
1946  { { { "64", 64+1024 }, { "64", 64+1024 }, { "64", 64+1024 }, { "0", 0+1024 } } },
1947  { { { "512", 512+1024 }, { "512", 512+1024 }, { "512", 512+1024 }, { "512", 512+1024 } } },
1948  { { { "940", 940+1024 }, { "960", 960+1024 }, { "960", 960+1024 }, { "1023", 1023+1024 } } },
1949 };
1950 
1951 static const GraticuleLines flat_digital12[] = {
1952  { { { "256", 256+4096 }, { "256", 256+4096 }, { "256", 256+4096 }, { "0", 0+4096 } } },
1953  { { { "2048", 2048+4096 }, { "2048", 2048+4096 }, { "2048", 2048+4096 }, { "2048", 2048+4096 } } },
1954  { { { "3760", 3760+4096 }, { "3840", 3840+4096 }, { "3840", 3840+4096 }, { "4095", 4095+4096 } } },
1955 };
1956 
1958  { { { "0", 16+256 }, { "0", 16+256 }, { "0", 16+256 }, { "0", 0+256 } } },
1959  { { { "175", 71+256 }, { "175", 72+256 }, { "175", 72+256 }, { "175", 64+256 } } },
1960  { { { "350", 126+256 }, { "350", 128+256 }, { "350", 128+256 }, { "350", 128+256 } } },
1961  { { { "525", 180+256 }, { "525", 184+256 }, { "525", 184+256 }, { "525", 192+256 } } },
1962  { { { "700", 235+256 }, { "700", 240+256 }, { "700", 240+256 }, { "700", 255+256 } } },
1963 };
1964 
1966  { { { "0", 32+512 }, { "0", 32+512 }, { "0", 32+512 }, { "0", 0+512 } } },
1967  { { { "175", 142+512 }, { "175", 144+512 }, { "175", 144+512 }, { "175", 128+512 } } },
1968  { { { "350", 251+512 }, { "350", 256+512 }, { "350", 256+512 }, { "350", 256+512 } } },
1969  { { { "525", 361+512 }, { "525", 368+512 }, { "525", 368+512 }, { "525", 384+512 } } },
1970  { { { "700", 470+512 }, { "700", 480+512 }, { "700", 480+512 }, { "700", 511+512 } } },
1971 };
1972 
1974  { { { "0", 64+1024 }, { "0", 64+1024 }, { "0", 64+1024 }, { "0", 0+1024 } } },
1975  { { { "175", 283+1024 }, { "175", 288+1024 }, { "175", 288+1024 }, { "175", 256+1024 } } },
1976  { { { "350", 502+1024 }, { "350", 512+1024 }, { "350", 512+1024 }, { "350", 512+1024 } } },
1977  { { { "525", 721+1024 }, { "525", 736+1024 }, { "525", 736+1024 }, { "525", 768+1024 } } },
1978  { { { "700", 940+1024 }, { "700", 960+1024 }, { "700", 960+1024 }, { "700", 1023+1024 } } },
1979 };
1980 
1982  { { { "0", 256+4096 }, { "0", 256+4096 }, { "0", 256+4096 }, { "0", 0+4096 } } },
1983  { { { "175", 1132+4096 }, { "175", 1152+4096 }, { "175", 1152+4096 }, { "175", 1024+4096 } } },
1984  { { { "350", 2008+4096 }, { "350", 2048+4096 }, { "350", 2048+4096 }, { "350", 2048+4096 } } },
1985  { { { "525", 2884+4096 }, { "525", 2944+4096 }, { "525", 2944+4096 }, { "525", 3072+4096 } } },
1986  { { { "700", 3760+4096 }, { "700", 3840+4096 }, { "700", 3840+4096 }, { "700", 4095+4096 } } },
1987 };
1988 
1989 static const GraticuleLines flat_ire8[] = {
1990  { { { "-25", -39+256 }, { "-25", -40+256 }, { "-25", -40+256 }, { "-25", -64+256 } } },
1991  { { { "0", 16+256 }, { "0", 16+256 }, { "0", 16+256 }, { "0", 0+256 } } },
1992  { { { "25", 71+256 }, { "25", 72+256 }, { "25", 72+256 }, { "25", 64+256 } } },
1993  { { { "50", 126+256 }, { "50", 128+256 }, { "50", 128+256 }, { "50", 128+256 } } },
1994  { { { "75", 180+256 }, { "75", 184+256 }, { "75", 184+256 }, { "75", 192+256 } } },
1995  { { { "100", 235+256 }, { "100", 240+256 }, { "100", 240+256 }, { "100", 256+256 } } },
1996  { { { "125", 290+256 }, { "125", 296+256 }, { "125", 296+256 }, { "125", 320+256 } } },
1997 };
1998 
1999 static const GraticuleLines flat_ire9[] = {
2000  { { { "-25", -78+512 }, { "-25", -80+512 }, { "-25", -80+512 }, { "-25",-128+512 } } },
2001  { { { "0", 32+512 }, { "0", 32+512 }, { "0", 32+512 }, { "0", 0+512 } } },
2002  { { { "25", 142+512 }, { "25", 144+512 }, { "25", 144+512 }, { "25", 128+512 } } },
2003  { { { "50", 251+512 }, { "50", 256+512 }, { "50", 256+512 }, { "50", 256+512 } } },
2004  { { { "75", 361+512 }, { "75", 368+512 }, { "75", 368+512 }, { "75", 384+512 } } },
2005  { { { "100", 470+512 }, { "100", 480+512 }, { "100", 480+512 }, { "100", 512+512 } } },
2006  { { { "125", 580+512 }, { "125", 592+512 }, { "125", 592+512 }, { "125", 640+512 } } },
2007 };
2008 
2009 static const GraticuleLines flat_ire10[] = {
2010  { { { "-25",-156+1024 }, { "-25",-160+1024 }, { "-25",-160+1024 }, { "-25", -256+1024 } } },
2011  { { { "0", 64+1024 }, { "0", 64+1024 }, { "0", 64+1024 }, { "0", 0+1024 } } },
2012  { { { "25", 283+1024 }, { "25", 288+1024 }, { "25", 288+1024 }, { "25", 256+1024 } } },
2013  { { { "50", 502+1024 }, { "50", 512+1024 }, { "50", 512+1024 }, { "50", 512+1024 } } },
2014  { { { "75", 721+1024 }, { "75", 736+1024 }, { "75", 736+1024 }, { "75", 768+1024 } } },
2015  { { { "100", 940+1024 }, { "100", 960+1024 }, { "100", 960+1024 }, { "100", 1024+1024 } } },
2016  { { { "125",1160+1024 }, { "125",1184+1024 }, { "125",1184+1024 }, { "125", 1280+1024 } } },
2017 };
2018 
2019 static const GraticuleLines flat_ire12[] = {
2020  { { { "-25", -624+4096 }, { "-25", -640+4096 }, { "-25", -640+4096 }, { "-25",-1024+4096 } } },
2021  { { { "0", 256+4096 }, { "0", 256+4096 }, { "0", 256+4096 }, { "0", 0+4096 } } },
2022  { { { "25", 1132+4096 }, { "25", 1152+4096 }, { "25", 1152+4096 }, { "25", 1024+4096 } } },
2023  { { { "50", 2008+4096 }, { "50", 2048+4096 }, { "50", 2048+4096 }, { "50", 2048+4096 } } },
2024  { { { "75", 2884+4096 }, { "75", 2944+4096 }, { "75", 2944+4096 }, { "75", 3072+4096 } } },
2025  { { { "100", 3760+4096 }, { "100", 3840+4096 }, { "100", 3840+4096 }, { "100", 4096+4096 } } },
2026  { { { "125", 4640+4096 }, { "125", 4736+4096 }, { "125", 4736+4096 }, { "125", 5120+4096 } } },
2027 };
2028 
2029 static const GraticuleLines digital8[] = {
2030  { { { "16", 16 }, { "16", 16 }, { "16", 16 }, { "0", 0 } } },
2031  { { { "128", 128 }, { "128", 128 }, { "128", 128 }, { "128", 128 } } },
2032  { { { "235", 235 }, { "240", 240 }, { "240", 240 }, { "255", 255 } } },
2033 };
2034 
2035 static const GraticuleLines digital9[] = {
2036  { { { "32", 32 }, { "32", 32 }, { "32", 32 }, { "0", 0 } } },
2037  { { { "256", 256 }, { "256", 256 }, { "256", 256 }, { "256", 256 } } },
2038  { { { "470", 470 }, { "480", 480 }, { "480", 480 }, { "511", 511 } } },
2039 };
2040 
2041 static const GraticuleLines digital10[] = {
2042  { { { "64", 64 }, { "64", 64 }, { "64", 64 }, { "0", 0 } } },
2043  { { { "512", 512 }, { "512", 512 }, { "512", 512 }, { "512", 512 } } },
2044  { { { "940", 940 }, { "960", 960 }, { "960", 960 }, { "1023", 1023 } } },
2045 };
2046 
2047 static const GraticuleLines digital12[] = {
2048  { { { "256", 256 }, { "256", 256 }, { "256", 256 }, { "0", 0 } } },
2049  { { { "2048", 2048 }, { "2048", 2048 }, { "2048", 2048 }, { "2048", 2048 } } },
2050  { { { "3760", 3760 }, { "3840", 3840 }, { "3840", 3840 }, { "4095", 4095 } } },
2051 };
2052 
2053 static const GraticuleLines millivolts8[] = {
2054  { { { "0", 16 }, { "0", 16 }, { "0", 16 }, { "0", 0 } } },
2055  { { { "175", 71 }, { "175", 72 }, { "175", 72 }, { "175", 64 } } },
2056  { { { "350", 126 }, { "350", 128 }, { "350", 128 }, { "350", 128 } } },
2057  { { { "525", 180 }, { "525", 184 }, { "525", 184 }, { "525", 192 } } },
2058  { { { "700", 235 }, { "700", 240 }, { "700", 240 }, { "700", 255 } } },
2059 };
2060 
2061 static const GraticuleLines millivolts9[] = {
2062  { { { "0", 32 }, { "0", 32 }, { "0", 32 }, { "0", 0 } } },
2063  { { { "175", 142 }, { "175", 144 }, { "175", 144 }, { "175", 128 } } },
2064  { { { "350", 251 }, { "350", 256 }, { "350", 256 }, { "350", 256 } } },
2065  { { { "525", 361 }, { "525", 368 }, { "525", 368 }, { "525", 384 } } },
2066  { { { "700", 470 }, { "700", 480 }, { "700", 480 }, { "700", 511 } } },
2067 };
2068 
2069 static const GraticuleLines millivolts10[] = {
2070  { { { "0", 64 }, { "0", 64 }, { "0", 64 }, { "0", 0 } } },
2071  { { { "175", 283 }, { "175", 288 }, { "175", 288 }, { "175", 256 } } },
2072  { { { "350", 502 }, { "350", 512 }, { "350", 512 }, { "350", 512 } } },
2073  { { { "525", 721 }, { "525", 736 }, { "525", 736 }, { "525", 768 } } },
2074  { { { "700", 940 }, { "700", 960 }, { "700", 960 }, { "700", 1023 } } },
2075 };
2076 
2077 static const GraticuleLines millivolts12[] = {
2078  { { { "0", 256 }, { "0", 256 }, { "0", 256 }, { "0", 0 } } },
2079  { { { "175", 1132 }, { "175", 1152 }, { "175", 1152 }, { "175", 1024 } } },
2080  { { { "350", 2008 }, { "350", 2048 }, { "350", 2048 }, { "350", 2048 } } },
2081  { { { "525", 2884 }, { "525", 2944 }, { "525", 2944 }, { "525", 3072 } } },
2082  { { { "700", 3760 }, { "700", 3840 }, { "700", 3840 }, { "700", 4095 } } },
2083 };
2084 
2085 static const GraticuleLines ire8[] = {
2086  { { { "0", 16 }, { "0", 16 }, { "0", 16 }, { "0", 0 } } },
2087  { { { "25", 71 }, { "25", 72 }, { "25", 72 }, { "25", 64 } } },
2088  { { { "50", 126 }, { "50", 128 }, { "50", 128 }, { "50", 128 } } },
2089  { { { "75", 180 }, { "75", 184 }, { "75", 184 }, { "75", 192 } } },
2090  { { { "100", 235 }, { "100", 240 }, { "100", 240 }, { "100", 255 } } },
2091 };
2092 
2093 static const GraticuleLines ire9[] = {
2094  { { { "0", 32 }, { "0", 32 }, { "0", 32 }, { "0", 0 } } },
2095  { { { "25", 142 }, { "25", 144 }, { "25", 144 }, { "25", 128 } } },
2096  { { { "50", 251 }, { "50", 256 }, { "50", 256 }, { "50", 256 } } },
2097  { { { "75", 361 }, { "75", 368 }, { "75", 368 }, { "75", 384 } } },
2098  { { { "100", 470 }, { "100", 480 }, { "100", 480 }, { "100", 511 } } },
2099 };
2100 
2101 static const GraticuleLines ire10[] = {
2102  { { { "0", 64 }, { "0", 64 }, { "0", 64 }, { "0", 0 } } },
2103  { { { "25", 283 }, { "25", 288 }, { "25", 288 }, { "25", 256 } } },
2104  { { { "50", 502 }, { "50", 512 }, { "50", 512 }, { "50", 512 } } },
2105  { { { "75", 721 }, { "75", 736 }, { "75", 736 }, { "75", 768 } } },
2106  { { { "100", 940 }, { "100", 960 }, { "100", 960 }, { "100", 1023 } } },
2107 };
2108 
2109 static const GraticuleLines ire12[] = {
2110  { { { "0", 256 }, { "0", 256 }, { "0", 256 }, { "0", 0 } } },
2111  { { { "25", 1132 }, { "25", 1152 }, { "25", 1152 }, { "25", 1024 } } },
2112  { { { "50", 2008 }, { "50", 2048 }, { "50", 2048 }, { "50", 2048 } } },
2113  { { { "75", 2884 }, { "75", 2944 }, { "75", 2944 }, { "75", 3072 } } },
2114  { { { "100", 3760 }, { "100", 3840 }, { "100", 3840 }, { "100", 4095 } } },
2115 };
2116 
2118  { { { "50", 50 }, { "50", 50 }, { "50", 50 }, { "50", 50 } } },
2119  { { { "100", 100 }, { "100", 100 }, { "100", 100 }, { "100", 100 } } },
2120  { { { "150", 150 }, { "150", 150 }, { "150", 150 }, { "150", 150 } } },
2121  { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2122  { { { "255", 255 }, { "255", 255 }, { "255", 255 }, { "255", 255 } } },
2123 };
2124 
2126  { { { "100", 100 }, { "100", 100 }, { "100", 100 }, { "100", 100 } } },
2127  { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2128  { { { "300", 300 }, { "300", 300 }, { "300", 300 }, { "300", 300 } } },
2129  { { { "400", 400 }, { "400", 400 }, { "400", 400 }, { "400", 400 } } },
2130  { { { "500", 500 }, { "500", 500 }, { "500", 500 }, { "500", 500 } } },
2131 };
2132 
2134  { { { "200", 200 }, { "200", 200 }, { "200", 200 }, { "200", 200 } } },
2135  { { { "400", 400 }, { "400", 400 }, { "400", 400 }, { "400", 400 } } },
2136  { { { "600", 600 }, { "600", 600 }, { "600", 600 }, { "600", 600 } } },
2137  { { { "800", 800 }, { "800", 800 }, { "800", 800 }, { "800", 800 } } },
2138  { { {"1000",1000 }, {"1000",1000 }, {"1000",1000 }, {"1000",1000 } } },
2139 };
2140 
2142  { { { "800", 800 }, { "800", 800 }, { "800", 800 }, { "800", 800 } } },
2143  { { { "1600", 1600 }, { "1600", 1600 }, { "1600", 1600 }, { "1600", 1600 } } },
2144  { { { "2400", 2400 }, { "2400", 2400 }, { "2400", 2400 }, { "2400", 2400 } } },
2145  { { { "3200", 3200 }, { "3200", 3200 }, { "3200", 3200 }, { "3200", 3200 } } },
2146  { { { "4000", 4000 }, { "4000", 4000 }, { "4000", 4000 }, { "4000", 4000 } } },
2147 };
2148 
2149 static void blend_vline(uint8_t *dst, int height, int linesize, float o1, float o2, int v, int step)
2150 {
2151  int y;
2152 
2153  for (y = 0; y < height; y += step) {
2154  dst[0] = v * o1 + dst[0] * o2;
2155 
2156  dst += linesize * step;
2157  }
2158 }
2159 
2160 static void blend_vline16(uint16_t *dst, int height, int linesize, float o1, float o2, int v, int step)
2161 {
2162  int y;
2163 
2164  for (y = 0; y < height; y += step) {
2165  dst[0] = v * o1 + dst[0] * o2;
2166 
2167  dst += (linesize / 2) * step;
2168  }
2169 }
2170 
2171 static void blend_hline(uint8_t *dst, int width, float o1, float o2, int v, int step)
2172 {
2173  int x;
2174 
2175  for (x = 0; x < width; x += step) {
2176  dst[x] = v * o1 + dst[x] * o2;
2177  }
2178 }
2179 
2180 static void blend_hline16(uint16_t *dst, int width, float o1, float o2, int v, int step)
2181 {
2182  int x;
2183 
2184  for (x = 0; x < width; x += step) {
2185  dst[x] = v * o1 + dst[x] * o2;
2186  }
2187 }
2188 
2189 static void draw_htext(AVFrame *out, int x, int y, float o1, float o2, const char *txt, const uint8_t color[4])
2190 {
2191  const uint8_t *font;
2192  int font_height;
2193  int i, plane;
2194 
2195  font = avpriv_cga_font, font_height = 8;
2196 
2197  for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2198  for (i = 0; txt[i]; i++) {
2199  int char_y, mask;
2200  int v = color[plane];
2201 
2202  uint8_t *p = out->data[plane] + y * out->linesize[plane] + (x + i * 8);
2203  for (char_y = 0; char_y < font_height; char_y++) {
2204  for (mask = 0x80; mask; mask >>= 1) {
2205  if (font[txt[i] * font_height + char_y] & mask)
2206  p[0] = p[0] * o2 + v * o1;
2207  p++;
2208  }
2209  p += out->linesize[plane] - 8;
2210  }
2211  }
2212  }
2213 }
2214 
2215 static void draw_htext16(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
2216 {
2217  const uint8_t *font;
2218  int font_height;
2219  int i, plane;
2220 
2221  font = avpriv_cga_font, font_height = 8;
2222 
2223  for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2224  for (i = 0; txt[i]; i++) {
2225  int char_y, mask;
2226  int v = color[plane] * mult;
2227 
2228  uint16_t *p = (uint16_t *)(out->data[plane] + y * out->linesize[plane]) + (x + i * 8);
2229  for (char_y = 0; char_y < font_height; char_y++) {
2230  for (mask = 0x80; mask; mask >>= 1) {
2231  if (font[txt[i] * font_height + char_y] & mask)
2232  p[0] = p[0] * o2 + v * o1;
2233  p++;
2234  }
2235  p += out->linesize[plane] / 2 - 8;
2236  }
2237  }
2238  }
2239 }
2240 
2241 static void draw_vtext(AVFrame *out, int x, int y, float o1, float o2, const char *txt, const uint8_t color[4])
2242 {
2243  const uint8_t *font;
2244  int font_height;
2245  int i, plane;
2246 
2247  font = avpriv_cga_font, font_height = 8;
2248 
2249  for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2250  for (i = 0; txt[i]; i++) {
2251  int char_y, mask;
2252  int v = color[plane];
2253 
2254  for (char_y = font_height - 1; char_y >= 0; char_y--) {
2255  uint8_t *p = out->data[plane] + (y + i * 10) * out->linesize[plane] + x;
2256  for (mask = 0x80; mask; mask >>= 1) {
2257  if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
2258  p[char_y] = p[char_y] * o2 + v * o1;
2259  p += out->linesize[plane];
2260  }
2261  }
2262  }
2263  }
2264 }
2265 
2266 static void draw_vtext16(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
2267 {
2268  const uint8_t *font;
2269  int font_height;
2270  int i, plane;
2271 
2272  font = avpriv_cga_font, font_height = 8;
2273 
2274  for (plane = 0; plane < 4 && out->data[plane]; plane++) {
2275  for (i = 0; txt[i]; i++) {
2276  int char_y, mask;
2277  int v = color[plane] * mult;
2278 
2279  for (char_y = 0; char_y < font_height; char_y++) {
2280  uint16_t *p = (uint16_t *)(out->data[plane] + (y + i * 10) * out->linesize[plane]) + x;
2281  for (mask = 0x80; mask; mask >>= 1) {
2282  if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
2283  p[char_y] = p[char_y] * o2 + v * o1;
2284  p += out->linesize[plane] / 2;
2285  }
2286  }
2287  }
2288  }
2289 }
2290 
2292 {
2293 }
2294 
2296 {
2297  const int step = (s->flags & 2) + 1;
2298  const float o1 = s->opacity;
2299  const float o2 = 1. - o1;
2300  const int height = s->display == PARADE ? out->height / s->acomp : out->height;
2301  int k = 0, c, p, l, offset_x = 0, offset_y = 0;
2302 
2303  for (c = 0; c < s->ncomp; c++) {
2304  if (!((1 << c) & s->pcomp) || (!s->display && k > 0))
2305  continue;
2306 
2307  k++;
2308  for (p = 0; p < s->ncomp; p++) {
2309  const int v = green_yuva_color[p];
2310  for (l = 0; l < s->nb_glines; l++) {
2311  const uint16_t pos = s->glines[l].line[c].pos;
2312  int x = offset_x + (s->mirror ? s->size - 1 - pos : pos);
2313  uint8_t *dst = out->data[p] + offset_y * out->linesize[p] + x;
2314 
2315  blend_vline(dst, height, out->linesize[p], o1, o2, v, step);
2316  }
2317  }
2318 
2319  for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2320  const char *name = s->glines[l].line[c].name;
2321  const uint16_t pos = s->glines[l].line[c].pos;
2322  int x = offset_x + (s->mirror ? s->size - 1 - pos : pos) - 10;
2323 
2324  if (x < 0)
2325  x = 4;
2326 
2327  draw_vtext(out, x, offset_y + 2, o1, o2, name, green_yuva_color);
2328  }
2329 
2330  offset_x += s->size * (s->display == STACK);
2331  offset_y += height * (s->display == PARADE);
2332  }
2333 }
2334 
2336 {
2337  const int step = (s->flags & 2) + 1;
2338  const float o1 = s->opacity;
2339  const float o2 = 1. - o1;
2340  const int mult = s->size / 256;
2341  const int height = s->display == PARADE ? out->height / s->acomp : out->height;
2342  int k = 0, c, p, l, offset_x = 0, offset_y = 0;
2343 
2344  for (c = 0; c < s->ncomp; c++) {
2345  if (!((1 << c) & s->pcomp) || (!s->display && k > 0))
2346  continue;
2347 
2348  k++;
2349  for (p = 0; p < s->ncomp; p++) {
2350  const int v = green_yuva_color[p] * mult;
2351  for (l = 0; l < s->nb_glines ; l++) {
2352  const uint16_t pos = s->glines[l].line[c].pos;
2353  int x = offset_x + (s->mirror ? s->size - 1 - pos : pos);
2354  uint16_t *dst = (uint16_t *)(out->data[p] + offset_y * out->linesize[p]) + x;
2355 
2356  blend_vline16(dst, height, out->linesize[p], o1, o2, v, step);
2357  }
2358  }
2359 
2360  for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2361  const char *name = s->glines[l].line[c].name;
2362  const uint16_t pos = s->glines[l].line[c].pos;
2363  int x = offset_x + (s->mirror ? s->size - 1 - pos : pos) - 10;
2364 
2365  if (x < 0)
2366  x = 4;
2367 
2368  draw_vtext16(out, x, offset_y + 2, mult, o1, o2, name, green_yuva_color);
2369  }
2370 
2371  offset_x += s->size * (s->display == STACK);
2372  offset_y += height * (s->display == PARADE);
2373  }
2374 }
2375 
2377 {
2378  const int step = (s->flags & 2) + 1;
2379  const float o1 = s->opacity;
2380  const float o2 = 1. - o1;
2381  const int width = s->display == PARADE ? out->width / s->acomp : out->width;
2382  int k = 0, c, p, l, offset_y = 0, offset_x = 0;
2383 
2384  for (c = 0; c < s->ncomp; c++) {
2385  if ((!((1 << c) & s->pcomp) || (!s->display && k > 0)))
2386  continue;
2387 
2388  k++;
2389  for (p = 0; p < s->ncomp; p++) {
2390  const int v = green_yuva_color[p];
2391  for (l = 0; l < s->nb_glines ; l++) {
2392  const uint16_t pos = s->glines[l].line[c].pos;
2393  int y = offset_y + (s->mirror ? s->size - 1 - pos : pos);
2394  uint8_t *dst = out->data[p] + y * out->linesize[p] + offset_x;
2395 
2396  blend_hline(dst, width, o1, o2, v, step);
2397  }
2398  }
2399 
2400  for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2401  const char *name = s->glines[l].line[c].name;
2402  const uint16_t pos = s->glines[l].line[c].pos;
2403  int y = offset_y + (s->mirror ? s->size - 1 - pos : pos) - 10;
2404 
2405  if (y < 0)
2406  y = 4;
2407 
2408  draw_htext(out, 2 + offset_x, y, o1, o2, name, green_yuva_color);
2409  }
2410 
2411  offset_y += s->size * (s->display == STACK);
2412  offset_x += width * (s->display == PARADE);
2413  }
2414 }
2415 
2417 {
2418  const int step = (s->flags & 2) + 1;
2419  const float o1 = s->opacity;
2420  const float o2 = 1. - o1;
2421  const int mult = s->size / 256;
2422  const int width = s->display == PARADE ? out->width / s->acomp : out->width;
2423  int k = 0, c, p, l, offset_x = 0, offset_y = 0;
2424 
2425  for (c = 0; c < s->ncomp; c++) {
2426  if ((!((1 << c) & s->pcomp) || (!s->display && k > 0)))
2427  continue;
2428 
2429  k++;
2430  for (p = 0; p < s->ncomp; p++) {
2431  const int v = green_yuva_color[p] * mult;
2432  for (l = 0; l < s->nb_glines ; l++) {
2433  const uint16_t pos = s->glines[l].line[c].pos;
2434  int y = offset_y + (s->mirror ? s->size - 1 - pos : pos);
2435  uint16_t *dst = (uint16_t *)(out->data[p] + y * out->linesize[p]) + offset_x;
2436 
2437  blend_hline16(dst, width, o1, o2, v, step);
2438  }
2439  }
2440 
2441  for (l = 0; l < s->nb_glines && (s->flags & 1); l++) {
2442  const char *name = s->glines[l].line[c].name;
2443  const uint16_t pos = s->glines[l].line[c].pos;
2444  int y = offset_y + (s->mirror ? s->size - 1 - pos: pos) - 10;
2445 
2446  if (y < 0)
2447  y = 4;
2448 
2449  draw_htext16(out, 2 + offset_x, y, mult, o1, o2, name, green_yuva_color);
2450  }
2451 
2452  offset_y += s->size * (s->display == STACK);
2453  offset_x += width * (s->display == PARADE);
2454  }
2455 }
2456 
2457 static int config_input(AVFilterLink *inlink)
2458 {
2459  AVFilterContext *ctx = inlink->dst;
2460  WaveformContext *s = ctx->priv;
2461 
2462  s->desc = av_pix_fmt_desc_get(inlink->format);
2463  s->ncomp = s->desc->nb_components;
2464  s->bits = s->desc->comp[0].depth;
2465  s->max = 1 << s->bits;
2466  s->intensity = s->fintensity * (s->max - 1);
2467 
2468  s->shift_w[0] = s->shift_w[3] = 0;
2469  s->shift_h[0] = s->shift_h[3] = 0;
2470  s->shift_w[1] = s->shift_w[2] = s->desc->log2_chroma_w;
2471  s->shift_h[1] = s->shift_h[2] = s->desc->log2_chroma_h;
2472 
2474 
2475  switch (s->filter) {
2476  case AFLAT: s->size = 256 * 2; break;
2477  case FLAT: s->size = 256 * 3; break;
2478  default: s->size = 256; break;
2479  }
2480 
2481  switch (s->filter | ((s->bits > 8) << 4) |
2482  (s->mode << 8) | (s->mirror << 12)) {
2483  case 0x1100: s->waveform = lowpass_column_mirror; break;
2484  case 0x1000: s->waveform = lowpass_row_mirror; break;
2485  case 0x0100: s->waveform = lowpass_column; break;
2486  case 0x0000: s->waveform = lowpass_row; break;
2487  case 0x1110: s->waveform = lowpass16_column_mirror; break;
2488  case 0x1010: s->waveform = lowpass16_row_mirror; break;
2489  case 0x0110: s->waveform = lowpass16_column; break;
2490  case 0x0010: s->waveform = lowpass16_row; break;
2491  case 0x1101:
2492  case 0x1001:
2493  case 0x0101:
2494  case 0x0001: s->waveform = flat; break;
2495  case 0x1111:
2496  case 0x1011:
2497  case 0x0111:
2498  case 0x0011: s->waveform = flat16; break;
2499  case 0x1102:
2500  case 0x1002:
2501  case 0x0102:
2502  case 0x0002: s->waveform = aflat; break;
2503  case 0x1112:
2504  case 0x1012:
2505  case 0x0112:
2506  case 0x0012: s->waveform = aflat16; break;
2507  case 0x1103:
2508  case 0x1003:
2509  case 0x0103:
2510  case 0x0003: s->waveform = chroma; break;
2511  case 0x1113:
2512  case 0x1013:
2513  case 0x0113:
2514  case 0x0013: s->waveform = chroma16; break;
2515  case 0x1104:
2516  case 0x1004:
2517  case 0x0104:
2518  case 0x0004: s->waveform = color; break;
2519  case 0x1114:
2520  case 0x1014:
2521  case 0x0114:
2522  case 0x0014: s->waveform = color16; break;
2523  case 0x1105:
2524  case 0x1005:
2525  case 0x0105:
2526  case 0x0005: s->waveform = acolor; break;
2527  case 0x1115:
2528  case 0x1015:
2529  case 0x0115:
2530  case 0x0015: s->waveform = acolor16; break;
2531  }
2532 
2533  switch (s->filter) {
2534  case LOWPASS:
2535  case COLOR:
2536  case ACOLOR:
2537  case CHROMA:
2538  case AFLAT:
2539  case FLAT:
2540  if (s->graticule && s->mode == 1)
2542  else if (s->graticule && s->mode == 0)
2544  break;
2545  }
2546 
2547  switch (s->filter) {
2548  case COLOR:
2549  case ACOLOR:
2550  case LOWPASS:
2551  switch (s->scale) {
2552  case DIGITAL:
2553  switch (s->bits) {
2554  case 8: s->glines = (GraticuleLines *)digital8; s->nb_glines = FF_ARRAY_ELEMS(digital8); break;
2555  case 9: s->glines = (GraticuleLines *)digital9; s->nb_glines = FF_ARRAY_ELEMS(digital9); break;
2556  case 10: s->glines = (GraticuleLines *)digital10; s->nb_glines = FF_ARRAY_ELEMS(digital10); break;
2557  case 12: s->glines = (GraticuleLines *)digital12; s->nb_glines = FF_ARRAY_ELEMS(digital12); break;
2558  }
2559  break;
2560  case MILLIVOLTS:
2561  switch (s->bits) {
2562  case 8: s->glines = (GraticuleLines *)millivolts8; s->nb_glines = FF_ARRAY_ELEMS(millivolts8); break;
2563  case 9: s->glines = (GraticuleLines *)millivolts9; s->nb_glines = FF_ARRAY_ELEMS(millivolts9); break;
2564  case 10: s->glines = (GraticuleLines *)millivolts10; s->nb_glines = FF_ARRAY_ELEMS(millivolts10); break;
2565  case 12: s->glines = (GraticuleLines *)millivolts12; s->nb_glines = FF_ARRAY_ELEMS(millivolts12); break;
2566  }
2567  break;
2568  case IRE:
2569  switch (s->bits) {
2570  case 8: s->glines = (GraticuleLines *)ire8; s->nb_glines = FF_ARRAY_ELEMS(ire8); break;
2571  case 9: s->glines = (GraticuleLines *)ire9; s->nb_glines = FF_ARRAY_ELEMS(ire9); break;
2572  case 10: s->glines = (GraticuleLines *)ire10; s->nb_glines = FF_ARRAY_ELEMS(ire10); break;
2573  case 12: s->glines = (GraticuleLines *)ire12; s->nb_glines = FF_ARRAY_ELEMS(ire12); break;
2574  }
2575  break;
2576  }
2577  break;
2578  case CHROMA:
2579  switch (s->scale) {
2580  case DIGITAL:
2581  switch (s->bits) {
2582  case 8: s->glines = (GraticuleLines *)chroma_digital8; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital8); break;
2583  case 9: s->glines = (GraticuleLines *)chroma_digital9; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital9); break;
2584  case 10: s->glines = (GraticuleLines *)chroma_digital10; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital10); break;
2585  case 12: s->glines = (GraticuleLines *)chroma_digital12; s->nb_glines = FF_ARRAY_ELEMS(chroma_digital12); break;
2586  }
2587  break;
2588  case MILLIVOLTS:
2589  switch (s->bits) {
2590  case 8: s->glines = (GraticuleLines *)millivolts8; s->nb_glines = FF_ARRAY_ELEMS(millivolts8); break;
2591  case 9: s->glines = (GraticuleLines *)millivolts9; s->nb_glines = FF_ARRAY_ELEMS(millivolts9); break;
2592  case 10: s->glines = (GraticuleLines *)millivolts10; s->nb_glines = FF_ARRAY_ELEMS(millivolts10); break;
2593  case 12: s->glines = (GraticuleLines *)millivolts12; s->nb_glines = FF_ARRAY_ELEMS(millivolts12); break;
2594  }
2595  break;
2596  case IRE:
2597  switch (s->bits) {
2598  case 8: s->glines = (GraticuleLines *)ire8; s->nb_glines = FF_ARRAY_ELEMS(ire8); break;
2599  case 9: s->glines = (GraticuleLines *)ire9; s->nb_glines = FF_ARRAY_ELEMS(ire9); break;
2600  case 10: s->glines = (GraticuleLines *)ire10; s->nb_glines = FF_ARRAY_ELEMS(ire10); break;
2601  case 12: s->glines = (GraticuleLines *)ire12; s->nb_glines = FF_ARRAY_ELEMS(ire12); break;
2602  }
2603  break;
2604  }
2605  break;
2606  case AFLAT:
2607  switch (s->scale) {
2608  case DIGITAL:
2609  switch (s->bits) {
2610  case 8: s->glines = (GraticuleLines *)aflat_digital8; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital8); break;
2611  case 9: s->glines = (GraticuleLines *)aflat_digital9; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital9); break;
2612  case 10: s->glines = (GraticuleLines *)aflat_digital10; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital10); break;
2613  case 12: s->glines = (GraticuleLines *)aflat_digital12; s->nb_glines = FF_ARRAY_ELEMS(aflat_digital12); break;
2614  }
2615  break;
2616  case MILLIVOLTS:
2617  switch (s->bits) {
2618  case 8: s->glines = (GraticuleLines *)aflat_millivolts8; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts8); break;
2619  case 9: s->glines = (GraticuleLines *)aflat_millivolts9; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts9); break;
2620  case 10: s->glines = (GraticuleLines *)aflat_millivolts10; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts10); break;
2621  case 12: s->glines = (GraticuleLines *)aflat_millivolts12; s->nb_glines = FF_ARRAY_ELEMS(aflat_millivolts12); break;
2622  }
2623  break;
2624  case IRE:
2625  switch (s->bits) {
2626  case 8: s->glines = (GraticuleLines *)aflat_ire8; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire8); break;
2627  case 9: s->glines = (GraticuleLines *)aflat_ire9; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire9); break;
2628  case 10: s->glines = (GraticuleLines *)aflat_ire10; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire10); break;
2629  case 12: s->glines = (GraticuleLines *)aflat_ire12; s->nb_glines = FF_ARRAY_ELEMS(aflat_ire12); break;
2630  }
2631  break;
2632  }
2633  break;
2634  case FLAT:
2635  switch (s->scale) {
2636  case DIGITAL:
2637  switch (s->bits) {
2638  case 8: s->glines = (GraticuleLines *)flat_digital8; s->nb_glines = FF_ARRAY_ELEMS(flat_digital8); break;
2639  case 9: s->glines = (GraticuleLines *)flat_digital9; s->nb_glines = FF_ARRAY_ELEMS(flat_digital9); break;
2640  case 10: s->glines = (GraticuleLines *)flat_digital10; s->nb_glines = FF_ARRAY_ELEMS(flat_digital10); break;
2641  case 12: s->glines = (GraticuleLines *)flat_digital12; s->nb_glines = FF_ARRAY_ELEMS(flat_digital12); break;
2642  }
2643  break;
2644  case MILLIVOLTS:
2645  switch (s->bits) {
2646  case 8: s->glines = (GraticuleLines *)flat_millivolts8; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts8); break;
2647  case 9: s->glines = (GraticuleLines *)flat_millivolts9; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts9); break;
2648  case 10: s->glines = (GraticuleLines *)flat_millivolts10; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts10); break;
2649  case 12: s->glines = (GraticuleLines *)flat_millivolts12; s->nb_glines = FF_ARRAY_ELEMS(flat_millivolts12); break;
2650  }
2651  break;
2652  case IRE:
2653  switch (s->bits) {
2654  case 8: s->glines = (GraticuleLines *)flat_ire8; s->nb_glines = FF_ARRAY_ELEMS(flat_ire8); break;
2655  case 9: s->glines = (GraticuleLines *)flat_ire9; s->nb_glines = FF_ARRAY_ELEMS(flat_ire9); break;
2656  case 10: s->glines = (GraticuleLines *)flat_ire10; s->nb_glines = FF_ARRAY_ELEMS(flat_ire10); break;
2657  case 12: s->glines = (GraticuleLines *)flat_ire12; s->nb_glines = FF_ARRAY_ELEMS(flat_ire12); break;
2658  }
2659  break;
2660  }
2661  break;
2662  }
2663 
2664  s->size = s->size << (s->bits - 8);
2665 
2666  switch (inlink->format) {
2667  case AV_PIX_FMT_GBRAP:
2668  case AV_PIX_FMT_GBRP:
2669  case AV_PIX_FMT_GBRP9:
2670  case AV_PIX_FMT_GBRP10:
2671  case AV_PIX_FMT_GBRP12:
2672  memcpy(s->bg_color, black_gbrp_color, sizeof(s->bg_color));
2674  break;
2675  default:
2676  memcpy(s->bg_color, black_yuva_color, sizeof(s->bg_color));
2677  }
2678 
2679  s->bg_color[3] *= s->bgopacity;
2680 
2681  return 0;
2682 }
2683 
2684 static int config_output(AVFilterLink *outlink)
2685 {
2686  AVFilterContext *ctx = outlink->src;
2687  AVFilterLink *inlink = ctx->inputs[0];
2688  WaveformContext *s = ctx->priv;
2689  int comp = 0, i, j = 0, k, p, size;
2690 
2691  for (i = 0; i < s->ncomp; i++) {
2692  if ((1 << i) & s->pcomp)
2693  comp++;
2694  }
2695  s->acomp = comp;
2696  s->odesc = av_pix_fmt_desc_get(outlink->format);
2697  s->dcomp = s->odesc->nb_components;
2698 
2699  av_freep(&s->peak);
2700 
2701  if (s->mode) {
2702  outlink->h = s->size * FFMAX(comp * (s->display == STACK), 1);
2703  outlink->w = inlink->w * FFMAX(comp * (s->display == PARADE), 1);
2704  size = inlink->w;
2705  } else {
2706  outlink->w = s->size * FFMAX(comp * (s->display == STACK), 1);
2707  outlink->h = inlink->h * FFMAX(comp * (s->display == PARADE), 1);
2708  size = inlink->h;
2709  }
2710 
2711  s->peak = av_malloc_array(size, 32 * sizeof(*s->peak));
2712  if (!s->peak)
2713  return AVERROR(ENOMEM);
2714 
2715  for (p = 0; p < s->ncomp; p++) {
2716  const int plane = s->desc->comp[p].plane;
2717  int offset;
2718 
2719  if (!((1 << p) & s->pcomp))
2720  continue;
2721 
2722  for (k = 0; k < 4; k++) {
2723  s->emax[plane][k] = s->peak + size * (plane * 4 + k + 0);
2724  s->emin[plane][k] = s->peak + size * (plane * 4 + k + 16);
2725  }
2726 
2727  offset = j++ * s->size * (s->display == STACK);
2728  s->estart[plane] = offset;
2729  s->eend[plane] = (offset + s->size - 1);
2730  for (i = 0; i < size; i++) {
2731  for (k = 0; k < 4; k++) {
2732  s->emax[plane][k][i] = s->estart[plane];
2733  s->emin[plane][k][i] = s->eend[plane];
2734  }
2735  }
2736  }
2737 
2738  outlink->sample_aspect_ratio = (AVRational){1,1};
2739 
2740  return 0;
2741 }
2742 
2743 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
2744 {
2745  AVFilterContext *ctx = inlink->dst;
2746  WaveformContext *s = ctx->priv;
2747  AVFilterLink *outlink = ctx->outputs[0];
2748  AVFrame *out;
2749  int i, j, k;
2750 
2751  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
2752  if (!out) {
2753  av_frame_free(&in);
2754  return AVERROR(ENOMEM);
2755  }
2756  out->pts = in->pts;
2758 
2759  for (k = 0; k < s->dcomp; k++) {
2760  if (s->bits <= 8) {
2761  for (i = 0; i < outlink->h ; i++)
2762  memset(out->data[s->odesc->comp[k].plane] +
2763  i * out->linesize[s->odesc->comp[k].plane],
2764  s->bg_color[k], outlink->w);
2765  } else {
2766  const int mult = s->max / 256;
2767  uint16_t *dst = (uint16_t *)out->data[s->odesc->comp[k].plane];
2768 
2769  for (i = 0; i < outlink->h ; i++) {
2770  for (j = 0; j < outlink->w; j++)
2771  dst[j] = s->bg_color[k] * mult;
2772  dst += out->linesize[s->odesc->comp[k].plane] / 2;
2773  }
2774  }
2775  }
2776 
2777  for (k = 0, i = 0; k < s->ncomp; k++) {
2778  if ((1 << k) & s->pcomp) {
2779  int offset_y;
2780  int offset_x;
2781 
2782  if (s->display == PARADE) {
2783  offset_x = s->mode ? i++ * inlink->w : 0;
2784  offset_y = s->mode ? 0 : i++ * inlink->h;
2785  } else {
2786  offset_y = s->mode ? i++ * s->size * !!s->display : 0;
2787  offset_x = s->mode ? 0 : i++ * s->size * !!s->display;
2788  }
2789  s->waveform(s, in, out, k, s->intensity, offset_y, offset_x, s->mode, s->mirror);
2790  }
2791  }
2792  s->graticulef(s, out);
2793 
2794  av_frame_free(&in);
2795  return ff_filter_frame(outlink, out);
2796 }
2797 
2799 {
2800  WaveformContext *s = ctx->priv;
2801 
2802  av_freep(&s->peak);
2803 }
2804 
2805 static const AVFilterPad inputs[] = {
2806  {
2807  .name = "default",
2808  .type = AVMEDIA_TYPE_VIDEO,
2809  .filter_frame = filter_frame,
2810  .config_props = config_input,
2811  },
2812  { NULL }
2813 };
2814 
2815 static const AVFilterPad outputs[] = {
2816  {
2817  .name = "default",
2818  .type = AVMEDIA_TYPE_VIDEO,
2819  .config_props = config_output,
2820  },
2821  { NULL }
2822 };
2823 
2825  .name = "waveform",
2826  .description = NULL_IF_CONFIG_SMALL("Video waveform monitor."),
2827  .priv_size = sizeof(WaveformContext),
2828  .priv_class = &waveform_class,
2830  .uninit = uninit,
2831  .inputs = inputs,
2832  .outputs = outputs,
2833 };
int plane
Definition: avisynth_c.h:422
int plane
Which of the 4 planes contains the component.
Definition: pixdesc.h:35
static const GraticuleLines aflat_digital10[]
Definition: vf_waveform.c:1849
#define NULL
Definition: coverity.c:32
static av_always_inline void lowpass16(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror)
Definition: vf_waveform.c:614
const char * s
Definition: avisynth_c.h:768
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:382
static const uint8_t green_yuva_color[4]
Definition: vf_waveform.c:1834
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2333
static av_always_inline void chroma(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror)
Definition: vf_waveform.c:1337
This structure describes decoded (raw) audio or video data.
Definition: frame.h:187
AVOption.
Definition: opt.h:246
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:384
static void envelope16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
Definition: vf_waveform.c:576
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:385
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:67
Main libavfilter public API header.
static const GraticuleLines digital8[]
Definition: vf_waveform.c:2029
static const GraticuleLines aflat_ire9[]
Definition: vf_waveform.c:1903
const char * desc
Definition: nvenc.c:60
static int config_input(AVFilterLink *inlink)
Definition: vf_waveform.c:2457
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:180
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:367
static const GraticuleLines flat_millivolts10[]
Definition: vf_waveform.c:1973
static void blend_vline16(uint16_t *dst, int height, int linesize, float o1, float o2, int v, int step)
Definition: vf_waveform.c:2160
static void update(uint8_t *target, int max, int intensity)
Definition: vf_waveform.c:606
static int config_output(AVFilterLink *outlink)
Definition: vf_waveform.c:2684
static enum AVPixelFormat in_color_pix_fmts[]
Definition: vf_waveform.c:178
static enum AVPixelFormat in_lowpass_pix_fmts[]
Definition: vf_waveform.c:160
static const GraticuleLines ire12[]
Definition: vf_waveform.c:2109
static const AVFilterPad inputs[]
Definition: vf_waveform.c:2805
static const GraticuleLines flat_millivolts12[]
Definition: vf_waveform.c:1981
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:355
static const GraticuleLines aflat_millivolts9[]
Definition: vf_waveform.c:1869
static const GraticuleLines ire10[]
Definition: vf_waveform.c:2101
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:92
static const GraticuleLines flat_ire9[]
Definition: vf_waveform.c:1999
static av_always_inline void aflat(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror)
Definition: vf_waveform.c:1135
static const GraticuleLines chroma_digital8[]
Definition: vf_waveform.c:2117
static enum AVPixelFormat out_yuv9_lowpass_pix_fmts[]
Definition: vf_waveform.c:235
static enum AVPixelFormat in_flat_pix_fmts[]
Definition: vf_waveform.c:195
static av_always_inline void lowpass(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror)
Definition: vf_waveform.c:689
static const GraticuleLines flat_ire12[]
Definition: vf_waveform.c:2019
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
static const GraticuleLines aflat_digital12[]
Definition: vf_waveform.c:1855
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:333
static av_always_inline void color16(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror)
Definition: vf_waveform.c:1413
const char * name
Pad name.
Definition: internal.h:60
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:334
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:331
#define FLAGS
Definition: vf_waveform.c:106
FilterType
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1125
static av_always_inline void acolor16(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror)
Definition: vf_waveform.c:1622
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:102
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t
#define av_cold
Definition: attributes.h:82
#define LOWPASS16_FUNC(name, column, mirror)
Definition: vf_waveform.c:673
AVOptions.
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
static int query_formats(AVFilterContext *ctx)
Definition: vf_waveform.c:272
static const uint8_t black_gbrp_color[4]
Definition: vf_waveform.c:1835
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:271
static const GraticuleLines aflat_millivolts10[]
Definition: vf_waveform.c:1877
static void filter(int16_t *output, ptrdiff_t out_stride, int16_t *low, ptrdiff_t low_stride, int16_t *high, ptrdiff_t high_stride, int len, uint8_t clip)
Definition: cfhd.c:80
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:381
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:366
static void blend_vline(uint8_t *dst, int height, int linesize, float o1, float o2, int v, int step)
Definition: vf_waveform.c:2149
static void draw_vtext16(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
Definition: vf_waveform.c:2266
#define LOWPASS_FUNC(name, column, mirror)
Definition: vf_waveform.c:771
#define height
AVFilter ff_vf_waveform
Definition: vf_waveform.c:2824
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:101
static void update16(uint16_t *target, int max, int intensity, int limit)
Definition: vf_waveform.c:598
static int flags
Definition: log.c:57
static const uint64_t c1
Definition: murmur3.c:49
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:75
ptrdiff_t size
Definition: opengl_enc.c:101
static const GraticuleLines chroma_digital10[]
Definition: vf_waveform.c:2133
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:356
static void blend_hline16(uint16_t *dst, int width, float o1, float o2, int v, int step)
Definition: vf_waveform.c:2180
void av_frame_set_color_range(AVFrame *frame, enum AVColorRange val)
A filter pad used for either input or output.
Definition: internal.h:54
static enum AVPixelFormat out_gray8_lowpass_pix_fmts[]
Definition: vf_waveform.c:250
static const GraticuleLines flat_digital9[]
Definition: vf_waveform.c:1939
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:188
int width
width and height of the video frame
Definition: frame.h:239
const uint8_t avpriv_cga_font[2048]
Definition: xga_font_data.c:29
static const GraticuleLines aflat_ire10[]
Definition: vf_waveform.c:1913
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
DisplayType
Definition: vf_waveform.c:42
static enum AVPixelFormat out_yuv12_lowpass_pix_fmts[]
Definition: vf_waveform.c:245
static const uint16_t mask[17]
Definition: lzw.c:38
struct GraticuleLine line[4]
Definition: vf_waveform.c:62
AVFILTER_DEFINE_CLASS(waveform)
#define AVERROR(e)
Definition: error.h:43
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:148
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:163
ScaleType
Definition: vf_waveform.c:49
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:179
static const GraticuleLines flat_digital10[]
Definition: vf_waveform.c:1945
void * priv
private data for use by the filter
Definition: avfilter.h:338
Definition: graph2dot.c:48
simple assert() macros that are a bit more flexible than ISO C assert().
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:354
static enum AVPixelFormat in_pix_fmts[]
Definition: vf_ciescope.c:121
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
static void graticule_none(WaveformContext *s, AVFrame *out)
Definition: vf_waveform.c:2291
#define FFMAX(a, b)
Definition: common.h:94
static const GraticuleLines ire8[]
Definition: vf_waveform.c:2085
static av_always_inline void flat(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror)
Definition: vf_waveform.c:899
int depth
Definition: v4l.c:62
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:66
static void envelope_peak16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
Definition: vf_waveform.c:437
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:106
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:349
#define OFFSET(x)
Definition: vf_waveform.c:105
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:83
static const GraticuleLines millivolts12[]
Definition: vf_waveform.c:2077
static void blend_hline(uint8_t *dst, int width, float o1, float o2, int v, int step)
Definition: vf_waveform.c:2171
#define FFMIN(a, b)
Definition: common.h:96
static enum AVPixelFormat out_gray12_lowpass_pix_fmts[]
Definition: vf_waveform.c:260
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:74
#define width
static void draw_htext(AVFrame *out, int x, int y, float o1, float o2, const char *txt, const uint8_t color[4])
Definition: vf_waveform.c:2189
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:440
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
static av_always_inline void aflat16(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror)
Definition: vf_waveform.c:1009
static enum AVPixelFormat flat_pix_fmts[]
Definition: vf_waveform.c:265
uint16_t pos
Definition: vf_waveform.c:58
AVFormatContext * ctx
Definition: movenc.c:48
static const GraticuleLines flat_digital8[]
Definition: vf_waveform.c:1933
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
static const GraticuleLines aflat_digital9[]
Definition: vf_waveform.c:1843
unsigned nb_formats
number of formats
Definition: formats.h:65
static void envelope_instant(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
Definition: vf_waveform.c:390
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:386
int * emax[4][4]
Definition: vf_waveform.c:83
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:350
#define FF_ARRAY_ELEMS(a)
static av_always_inline void chroma16(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror)
Definition: vf_waveform.c:1259
the normal 2^n-1 "JPEG" YUV ranges
Definition: pixfmt.h:476
static enum AVPixelFormat out_yuv10_lowpass_pix_fmts[]
Definition: vf_waveform.c:240
const char * name
Definition: vf_waveform.c:57
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
Definition: eamad.c:83
static const AVOption waveform_options[]
Definition: vf_waveform.c:108
static const GraticuleLines aflat_digital8[]
Definition: vf_waveform.c:1837
static const GraticuleLines flat_ire8[]
Definition: vf_waveform.c:1989
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:218
static const GraticuleLines chroma_digital9[]
Definition: vf_waveform.c:2125
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:189
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
static const AVFilterPad outputs[]
Definition: vf_waveform.c:2815
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
static void draw_vtext(AVFrame *out, int x, int y, float o1, float o2, const char *txt, const uint8_t color[4])
Definition: vf_waveform.c:2241
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_waveform.c:2798
static const GraticuleLines aflat_millivolts12[]
Definition: vf_waveform.c:1885
GraticuleLines * glines
Definition: vf_waveform.c:93
static int16_t mult(Float11 *f1, Float11 *f2)
Definition: g726.c:55
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:351
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:68
static enum AVPixelFormat out_yuv8_lowpass_pix_fmts[]
Definition: vf_waveform.c:230
static enum AVPixelFormat out_rgb9_lowpass_pix_fmts[]
Definition: vf_waveform.c:215
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:144
Rational number (pair of numerator and denominator).
Definition: rational.h:58
static void envelope_instant16(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
Definition: vf_waveform.c:342
static void graticule_green_column(WaveformContext *s, AVFrame *out)
Definition: vf_waveform.c:2376
const char * name
Filter name.
Definition: avfilter.h:148
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:357
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:348
static const GraticuleLines flat_digital12[]
Definition: vf_waveform.c:1951
misc parsing utilities
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:335
static av_always_inline void acolor(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror)
Definition: vf_waveform.c:1728
static av_always_inline void color(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror)
Definition: vf_waveform.c:1518
int * emin[4][4]
Definition: vf_waveform.c:84
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:368
static const GraticuleLines millivolts8[]
Definition: vf_waveform.c:2053
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:352
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:358
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:201
static const GraticuleLines digital12[]
Definition: vf_waveform.c:2047
uint8_t bg_color[4]
Definition: vf_waveform.c:72
static enum AVPixelFormat out_rgb12_lowpass_pix_fmts[]
Definition: vf_waveform.c:225
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:62
Y , 8bpp.
Definition: pixfmt.h:70
if(ret< 0)
Definition: vf_mcdeint.c:282
void(* graticulef)(struct WaveformContext *s, AVFrame *out)
Definition: vf_waveform.c:100
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:229
static double c[64]
static const GraticuleLines millivolts10[]
Definition: vf_waveform.c:2069
static const GraticuleLines aflat_ire12[]
Definition: vf_waveform.c:1923
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:383
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:76
static const GraticuleLines digital9[]
Definition: vf_waveform.c:2035
static const uint64_t c2
Definition: murmur3.c:50
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:69
static enum AVPixelFormat out_pix_fmts[]
Definition: vf_ciescope.c:130
static void graticule16_green_column(WaveformContext *s, AVFrame *out)
Definition: vf_waveform.c:2416
void(* waveform)(struct WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror)
Definition: vf_waveform.c:95
static const GraticuleLines digital10[]
Definition: vf_waveform.c:2041
static const GraticuleLines flat_ire10[]
Definition: vf_waveform.c:2009
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_waveform.c:2743
static const uint8_t black_yuva_color[4]
Definition: vf_waveform.c:1833
const AVPixFmtDescriptor * odesc
Definition: vf_waveform.c:102
static void envelope_peak(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
Definition: vf_waveform.c:507
static av_always_inline void flat16(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror)
Definition: vf_waveform.c:787
A list of supported formats for one end of a filter link.
Definition: formats.h:64
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:272
static const GraticuleLines flat_millivolts8[]
Definition: vf_waveform.c:1957
An instance of a filter.
Definition: avfilter.h:323
static void draw_htext16(AVFrame *out, int x, int y, int mult, float o1, float o2, const char *txt, const uint8_t color[4])
Definition: vf_waveform.c:2215
int height
Definition: frame.h:239
FILE * out
Definition: movenc.c:54
#define av_freep(p)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:100
void INT64 start
Definition: avisynth_c.h:690
#define av_always_inline
Definition: attributes.h:39
#define av_malloc_array(a, b)
static void envelope(WaveformContext *s, AVFrame *out, int plane, int component, int offset)
Definition: vf_waveform.c:587
static const GraticuleLines ire9[]
Definition: vf_waveform.c:2093
static const GraticuleLines chroma_digital12[]
Definition: vf_waveform.c:2141
static const GraticuleLines flat_millivolts9[]
Definition: vf_waveform.c:1965
internal API functions
static void graticule16_green_row(WaveformContext *s, AVFrame *out)
Definition: vf_waveform.c:2335
static enum AVPixelFormat out_gray10_lowpass_pix_fmts[]
Definition: vf_waveform.c:255
static void graticule_green_row(WaveformContext *s, AVFrame *out)
Definition: vf_waveform.c:2295
int depth
Number of bits in the component.
Definition: pixdesc.h:58
static const GraticuleLines aflat_ire8[]
Definition: vf_waveform.c:1893
static enum AVPixelFormat out_rgb8_lowpass_pix_fmts[]
Definition: vf_waveform.c:210
const AVPixFmtDescriptor * desc
Definition: vf_waveform.c:101
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
mode
Use these values in ebur128_init (or'ed).
Definition: ebur128.h:83
static const GraticuleLines millivolts9[]
Definition: vf_waveform.c:2061
for(j=16;j >0;--j)
static const GraticuleLines aflat_millivolts8[]
Definition: vf_waveform.c:1861
CGA/EGA/VGA ROM font data.
static enum AVPixelFormat out_rgb10_lowpass_pix_fmts[]
Definition: vf_waveform.c:220
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
const char * name
Definition: opengl_enc.c:103
int * formats
list of media formats
Definition: formats.h:66