FFmpeg
vf_histogram.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2013 Paul B Mahol
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "libavutil/avassert.h"
22 #include "libavutil/opt.h"
23 #include "libavutil/parseutils.h"
24 #include "libavutil/pixdesc.h"
25 #include "libavutil/imgutils.h"
26 #include "libavutil/intreadwrite.h"
27 #include "avfilter.h"
28 #include "formats.h"
29 #include "internal.h"
30 #include "video.h"
31 
32 typedef struct HistogramContext {
33  const AVClass *class; ///< AVClass context for log and options purpose
34  unsigned histogram[256*256];
36  int mult;
37  int ncomp;
38  int dncomp;
47  float fgopacity;
48  float bgopacity;
49  int planewidth[4];
50  int planeheight[4];
52 
53 #define OFFSET(x) offsetof(HistogramContext, x)
54 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
55 
56 static const AVOption histogram_options[] = {
57  { "level_height", "set level height", OFFSET(level_height), AV_OPT_TYPE_INT, {.i64=200}, 50, 2048, FLAGS},
58  { "scale_height", "set scale height", OFFSET(scale_height), AV_OPT_TYPE_INT, {.i64=12}, 0, 40, FLAGS},
59  { "display_mode", "set display mode", OFFSET(display_mode), AV_OPT_TYPE_INT, {.i64=2}, 0, 2, FLAGS, "display_mode"},
60  { "d", "set display mode", OFFSET(display_mode), AV_OPT_TYPE_INT, {.i64=2}, 0, 2, FLAGS, "display_mode"},
61  { "overlay", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "display_mode" },
62  { "parade", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "display_mode" },
63  { "stack", NULL, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "display_mode" },
64  { "levels_mode", "set levels mode", OFFSET(levels_mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "levels_mode"},
65  { "m", "set levels mode", OFFSET(levels_mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "levels_mode"},
66  { "linear", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "levels_mode" },
67  { "logarithmic", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "levels_mode" },
68  { "components", "set color components to display", OFFSET(components), AV_OPT_TYPE_INT, {.i64=7}, 1, 15, FLAGS},
69  { "c", "set color components to display", OFFSET(components), AV_OPT_TYPE_INT, {.i64=7}, 1, 15, FLAGS},
70  { "fgopacity", "set foreground opacity", OFFSET(fgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.7}, 0, 1, FLAGS},
71  { "f", "set foreground opacity", OFFSET(fgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.7}, 0, 1, FLAGS},
72  { "bgopacity", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGS},
73  { "b", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGS},
74  { NULL }
75 };
76 
77 AVFILTER_DEFINE_CLASS(histogram);
78 
79 static const enum AVPixelFormat levels_in_pix_fmts[] = {
95 };
96 
97 static const enum AVPixelFormat levels_out_yuv8_pix_fmts[] = {
100 };
101 
105 };
106 
110 };
111 
115 };
116 
120 };
121 
125 };
126 
130 };
131 
135 };
136 
138 {
139  AVFilterFormats *avff;
140  const AVPixFmtDescriptor *desc;
141  const enum AVPixelFormat *out_pix_fmts;
142  int rgb, i, bits;
143  int ret;
144 
145  if (!ctx->inputs[0]->in_formats ||
146  !ctx->inputs[0]->in_formats->nb_formats) {
147  return AVERROR(EAGAIN);
148  }
149 
150  if (!ctx->inputs[0]->out_formats)
151  if ((ret = ff_formats_ref(ff_make_format_list(levels_in_pix_fmts), &ctx->inputs[0]->out_formats)) < 0)
152  return ret;
153  avff = ctx->inputs[0]->in_formats;
154  desc = av_pix_fmt_desc_get(avff->formats[0]);
155  rgb = desc->flags & AV_PIX_FMT_FLAG_RGB;
156  bits = desc->comp[0].depth;
157  for (i = 1; i < avff->nb_formats; i++) {
158  desc = av_pix_fmt_desc_get(avff->formats[i]);
159  if ((rgb != (desc->flags & AV_PIX_FMT_FLAG_RGB)) ||
160  (bits != desc->comp[0].depth))
161  return AVERROR(EAGAIN);
162  }
163 
164  if (rgb && bits == 8)
166  else if (rgb && bits == 9)
168  else if (rgb && bits == 10)
170  else if (rgb && bits == 12)
172  else if (bits == 8)
174  else if (bits == 9)
176  else if (bits == 10)
178  else if (bits == 12)
180  else
181  return AVERROR(EAGAIN);
182  if ((ret = ff_formats_ref(ff_make_format_list(out_pix_fmts), &ctx->outputs[0]->in_formats)) < 0)
183  return ret;
184 
185  return 0;
186 }
187 
188 static const uint8_t black_yuva_color[4] = { 0, 127, 127, 255 };
189 static const uint8_t black_gbrp_color[4] = { 0, 0, 0, 255 };
190 static const uint8_t white_yuva_color[4] = { 255, 127, 127, 255 };
191 static const uint8_t white_gbrp_color[4] = { 255, 255, 255, 255 };
192 
194 {
195  HistogramContext *h = inlink->dst->priv;
196 
197  h->desc = av_pix_fmt_desc_get(inlink->format);
198  h->ncomp = h->desc->nb_components;
199  h->histogram_size = 1 << h->desc->comp[0].depth;
200  h->mult = h->histogram_size / 256;
201 
202  switch (inlink->format) {
203  case AV_PIX_FMT_GBRAP12:
204  case AV_PIX_FMT_GBRP12:
205  case AV_PIX_FMT_GBRAP10:
206  case AV_PIX_FMT_GBRP10:
207  case AV_PIX_FMT_GBRP9:
208  case AV_PIX_FMT_GBRAP:
209  case AV_PIX_FMT_GBRP:
210  memcpy(h->bg_color, black_gbrp_color, 4);
211  memcpy(h->fg_color, white_gbrp_color, 4);
212  break;
213  default:
214  memcpy(h->bg_color, black_yuva_color, 4);
215  memcpy(h->fg_color, white_yuva_color, 4);
216  }
217 
218  h->fg_color[3] = h->fgopacity * 255;
219  h->bg_color[3] = h->bgopacity * 255;
220 
221  h->planeheight[1] = h->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, h->desc->log2_chroma_h);
222  h->planeheight[0] = h->planeheight[3] = inlink->h;
223  h->planewidth[1] = h->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, h->desc->log2_chroma_w);
224  h->planewidth[0] = h->planewidth[3] = inlink->w;
225 
226  return 0;
227 }
228 
229 static int config_output(AVFilterLink *outlink)
230 {
231  AVFilterContext *ctx = outlink->src;
232  HistogramContext *h = ctx->priv;
233  int ncomp = 0, i;
234 
235  for (i = 0; i < h->ncomp; i++) {
236  if ((1 << i) & h->components)
237  ncomp++;
238  }
239  outlink->w = h->histogram_size * FFMAX(ncomp * (h->display_mode == 1), 1);
240  outlink->h = (h->level_height + h->scale_height) * FFMAX(ncomp * (h->display_mode == 2), 1);
241 
242  h->odesc = av_pix_fmt_desc_get(outlink->format);
243  h->dncomp = h->odesc->nb_components;
244  outlink->sample_aspect_ratio = (AVRational){1,1};
245 
246  return 0;
247 }
248 
250 {
251  HistogramContext *h = inlink->dst->priv;
252  AVFilterContext *ctx = inlink->dst;
253  AVFilterLink *outlink = ctx->outputs[0];
254  AVFrame *out;
255  int i, j, k, l, m;
256 
257  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
258  if (!out) {
259  av_frame_free(&in);
260  return AVERROR(ENOMEM);
261  }
262 
263  out->pts = in->pts;
264 
265  for (k = 0; k < 4 && out->data[k]; k++) {
266  const int is_chroma = (k == 1 || k == 2);
267  const int dst_h = AV_CEIL_RSHIFT(outlink->h, (is_chroma ? h->odesc->log2_chroma_h : 0));
268  const int dst_w = AV_CEIL_RSHIFT(outlink->w, (is_chroma ? h->odesc->log2_chroma_w : 0));
269 
270  if (h->histogram_size <= 256) {
271  for (i = 0; i < dst_h ; i++)
272  memset(out->data[h->odesc->comp[k].plane] +
273  i * out->linesize[h->odesc->comp[k].plane],
274  h->bg_color[k], dst_w);
275  } else {
276  const int mult = h->mult;
277 
278  for (i = 0; i < dst_h ; i++)
279  for (j = 0; j < dst_w; j++)
280  AV_WN16(out->data[h->odesc->comp[k].plane] +
281  i * out->linesize[h->odesc->comp[k].plane] + j * 2,
282  h->bg_color[k] * mult);
283  }
284  }
285 
286  for (m = 0, k = 0; k < h->ncomp; k++) {
287  const int p = h->desc->comp[k].plane;
288  const int height = h->planeheight[p];
289  const int width = h->planewidth[p];
290  double max_hval_log;
291  unsigned max_hval = 0;
292  int start, startx;
293 
294  if (!((1 << k) & h->components))
295  continue;
296  startx = m * h->histogram_size * (h->display_mode == 1);
297  start = m++ * (h->level_height + h->scale_height) * (h->display_mode == 2);
298 
299  if (h->histogram_size <= 256) {
300  for (i = 0; i < height; i++) {
301  const uint8_t *src = in->data[p] + i * in->linesize[p];
302  for (j = 0; j < width; j++)
303  h->histogram[src[j]]++;
304  }
305  } else {
306  for (i = 0; i < height; i++) {
307  const uint16_t *src = (const uint16_t *)(in->data[p] + i * in->linesize[p]);
308  for (j = 0; j < width; j++)
309  h->histogram[src[j]]++;
310  }
311  }
312 
313  for (i = 0; i < h->histogram_size; i++)
314  max_hval = FFMAX(max_hval, h->histogram[i]);
315  max_hval_log = log2(max_hval + 1);
316 
317  for (i = 0; i < h->histogram_size; i++) {
318  int col_height;
319 
320  if (h->levels_mode)
321  col_height = lrint(h->level_height * (1. - (log2(h->histogram[i] + 1) / max_hval_log)));
322  else
323  col_height = h->level_height - (h->histogram[i] * (int64_t)h->level_height + max_hval - 1) / max_hval;
324 
325  if (h->histogram_size <= 256) {
326  for (j = h->level_height - 1; j >= col_height; j--) {
327  if (h->display_mode) {
328  for (l = 0; l < h->dncomp; l++)
329  out->data[l][(j + start) * out->linesize[l] + startx + i] = h->fg_color[l];
330  } else {
331  out->data[p][(j + start) * out->linesize[p] + startx + i] = 255;
332  }
333  }
334  for (j = h->level_height + h->scale_height - 1; j >= h->level_height; j--)
335  out->data[p][(j + start) * out->linesize[p] + startx + i] = i;
336  } else {
337  const int mult = h->mult;
338 
339  for (j = h->level_height - 1; j >= col_height; j--) {
340  if (h->display_mode) {
341  for (l = 0; l < h->dncomp; l++)
342  AV_WN16(out->data[l] + (j + start) * out->linesize[l] + startx * 2 + i * 2, h->fg_color[l] * mult);
343  } else {
344  AV_WN16(out->data[p] + (j + start) * out->linesize[p] + startx * 2 + i * 2, 255 * mult);
345  }
346  }
347  for (j = h->level_height + h->scale_height - 1; j >= h->level_height; j--)
348  AV_WN16(out->data[p] + (j + start) * out->linesize[p] + startx * 2 + i * 2, i);
349  }
350  }
351 
352  memset(h->histogram, 0, h->histogram_size * sizeof(unsigned));
353  }
354 
355  av_frame_free(&in);
356  return ff_filter_frame(outlink, out);
357 }
358 
359 static const AVFilterPad inputs[] = {
360  {
361  .name = "default",
362  .type = AVMEDIA_TYPE_VIDEO,
363  .filter_frame = filter_frame,
364  .config_props = config_input,
365  },
366  { NULL }
367 };
368 
369 static const AVFilterPad outputs[] = {
370  {
371  .name = "default",
372  .type = AVMEDIA_TYPE_VIDEO,
373  .config_props = config_output,
374  },
375  { NULL }
376 };
377 
379  .name = "histogram",
380  .description = NULL_IF_CONFIG_SMALL("Compute and draw a histogram."),
381  .priv_size = sizeof(HistogramContext),
383  .inputs = inputs,
384  .outputs = outputs,
385  .priv_class = &histogram_class,
386 };
FLAGS
#define FLAGS
Definition: vf_histogram.c:54
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:99
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
HistogramContext::ncomp
int ncomp
Definition: vf_histogram.c:37
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
out
FILE * out
Definition: movenc.c:54
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
outputs
static const AVFilterPad outputs[]
Definition: vf_histogram.c:369
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2522
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
HistogramContext::odesc
const AVPixFmtDescriptor * odesc
Definition: vf_histogram.c:45
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:422
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_histogram.c:137
HistogramContext::level_height
int level_height
Definition: vf_histogram.c:41
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
pixdesc.h
black_yuva_color
static const uint8_t black_yuva_color[4]
Definition: vf_histogram.c:188
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:424
AVOption
AVOption.
Definition: opt.h:246
levels_out_yuv8_pix_fmts
static enum AVPixelFormat levels_out_yuv8_pix_fmts[]
Definition: vf_histogram.c:97
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:387
levels_out_yuv9_pix_fmts
static enum AVPixelFormat levels_out_yuv9_pix_fmts[]
Definition: vf_histogram.c:102
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_histogram.c:193
AVFilterFormats::formats
int * formats
list of media formats
Definition: formats.h:66
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_histogram.c:249
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:148
ff_vf_histogram
AVFilter ff_vf_histogram
Definition: vf_histogram.c:378
white_gbrp_color
static const uint8_t white_gbrp_color[4]
Definition: vf_histogram.c:191
video.h
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:425
HistogramContext::display_mode
int display_mode
Definition: vf_histogram.c:43
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
HistogramContext
Definition: vf_histogram.c:32
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:421
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:215
start
void INT64 start
Definition: avisynth_c.h:767
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:403
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:385
src
#define src
Definition: vp8dsp.c:254
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
levels_out_rgb10_pix_fmts
static enum AVPixelFormat levels_out_rgb10_pix_fmts[]
Definition: vf_histogram.c:127
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:390
AV_PIX_FMT_YUVJ411P
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:258
mult
static int16_t mult(Float11 *f1, Float11 *f2)
Definition: g726.c:55
avassert.h
lrint
#define lrint
Definition: tablegen.h:53
HistogramContext::levels_mode
int levels_mode
Definition: vf_histogram.c:44
AV_PIX_FMT_YUVJ422P
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:407
width
#define width
HistogramContext::scale_height
int scale_height
Definition: vf_histogram.c:42
intreadwrite.h
histogram_options
static const AVOption histogram_options[]
Definition: vf_histogram.c:56
AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:408
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
ff_formats_ref
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:440
HistogramContext::bgopacity
float bgopacity
Definition: vf_histogram.c:48
bits
uint8_t bits
Definition: vp3data.h:202
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:384
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
HistogramContext::bg_color
uint8_t bg_color[4]
Definition: vf_histogram.c:39
AV_PIX_FMT_YUVJ444P
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
HistogramContext::mult
int mult
Definition: vf_histogram.c:36
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
NULL
#define NULL
Definition: coverity.c:32
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AV_PIX_FMT_YUVJ420P
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
levels_out_rgb12_pix_fmts
static enum AVPixelFormat levels_out_rgb12_pix_fmts[]
Definition: vf_histogram.c:132
parseutils.h
AVFilterFormats::nb_formats
unsigned nb_formats
number of formats
Definition: formats.h:65
HistogramContext::histogram_size
int histogram_size
Definition: vf_histogram.c:35
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:388
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
AV_PIX_FMT_GBRP9
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:402
config_output
static int config_output(AVFilterLink *outlink)
Definition: vf_histogram.c:229
desc
const char * desc
Definition: nvenc.c:68
inputs
static const AVFilterPad inputs[]
Definition: vf_histogram.c:359
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
AV_PIX_FMT_FLAG_RGB
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:148
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(histogram)
FFMAX
#define FFMAX(a, b)
Definition: common.h:94
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:392
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:394
HistogramContext::dncomp
int dncomp
Definition: vf_histogram.c:38
OFFSET
#define OFFSET(x)
Definition: vf_histogram.c:53
height
#define height
AV_PIX_FMT_YUVA444P
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:177
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:426
levels_in_pix_fmts
static enum AVPixelFormat levels_in_pix_fmts[]
Definition: vf_histogram.c:79
internal.h
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:226
in
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;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);return NULL;} return ac;} 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;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->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);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Definition: audio_convert.c:326
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:404
HistogramContext::fgopacity
float fgopacity
Definition: vf_histogram.c:47
out_pix_fmts
static enum AVPixelFormat out_pix_fmts[]
Definition: vf_ciescope.c:130
HistogramContext::planeheight
int planeheight[4]
Definition: vf_histogram.c:50
levels_out_yuv10_pix_fmts
static enum AVPixelFormat levels_out_yuv10_pix_fmts[]
Definition: vf_histogram.c:107
uint8_t
uint8_t
Definition: audio_convert.c:194
HistogramContext::desc
const AVPixFmtDescriptor * desc
Definition: vf_histogram.c:45
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
HistogramContext::components
int components
Definition: vf_histogram.c:46
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:386
log2
#define log2(x)
Definition: libm.h:404
AVFilter
Filter definition.
Definition: avfilter.h:144
ret
ret
Definition: filter_design.txt:187
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:423
HistogramContext::fg_color
uint8_t fg_color[4]
Definition: vf_histogram.c:40
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:391
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
levels_out_rgb8_pix_fmts
static enum AVPixelFormat levels_out_rgb8_pix_fmts[]
Definition: vf_histogram.c:117
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:223
avfilter.h
HistogramContext::planewidth
int planewidth[4]
Definition: vf_histogram.c:49
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
AVFilterContext
An instance of a filter.
Definition: avfilter.h:338
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
levels_out_yuv12_pix_fmts
static enum AVPixelFormat levels_out_yuv12_pix_fmts[]
Definition: vf_histogram.c:112
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
imgutils.h
AV_PIX_FMT_YUV410P
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
levels_out_rgb9_pix_fmts
static enum AVPixelFormat levels_out_rgb9_pix_fmts[]
Definition: vf_histogram.c:122
HistogramContext::histogram
unsigned histogram[256 *256]
Definition: vf_histogram.c:34
AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:393
h
h
Definition: vp9dsp_template.c:2038
black_gbrp_color
static const uint8_t black_gbrp_color[4]
Definition: vf_histogram.c:189
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:232
AV_PIX_FMT_YUVA422P
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:176
white_yuva_color
static const uint8_t white_yuva_color[4]
Definition: vf_histogram.c:190
AV_WN16
#define AV_WN16(p, v)
Definition: intreadwrite.h:372