FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vf_perspective.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
3  * Copyright (c) 2013 Paul B Mahol
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 General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 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
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * 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/eval.h"
24 #include "libavutil/imgutils.h"
25 #include "libavutil/pixdesc.h"
26 #include "libavutil/opt.h"
27 #include "avfilter.h"
28 #include "formats.h"
29 #include "internal.h"
30 #include "video.h"
31 
32 #define SUB_PIXEL_BITS 8
33 #define SUB_PIXELS (1 << SUB_PIXEL_BITS)
34 #define COEFF_BITS 11
35 
36 #define LINEAR 0
37 #define CUBIC 1
38 
39 typedef struct PerspectiveContext {
40  const AVClass *class;
41  char *expr_str[4][2];
42  double ref[4][2];
43  int32_t (*pv)[2];
46  int linesize[4];
47  int height[4];
48  int hsub, vsub;
49  int nb_planes;
50  int sense;
51 
53  void *arg, int job, int nb_jobs);
55 
56 #define OFFSET(x) offsetof(PerspectiveContext, x)
57 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
58 
60  PERSPECTIVE_SENSE_SOURCE = 0, ///< coordinates give locations in source of corners of destination.
61  PERSPECTIVE_SENSE_DESTINATION = 1, ///< coordinates give locations in destination of corners of source.
62 };
63 
64 static const AVOption perspective_options[] = {
65  { "x0", "set top left x coordinate", OFFSET(expr_str[0][0]), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },
66  { "y0", "set top left y coordinate", OFFSET(expr_str[0][1]), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },
67  { "x1", "set top right x coordinate", OFFSET(expr_str[1][0]), AV_OPT_TYPE_STRING, {.str="W"}, 0, 0, FLAGS },
68  { "y1", "set top right y coordinate", OFFSET(expr_str[1][1]), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },
69  { "x2", "set bottom left x coordinate", OFFSET(expr_str[2][0]), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },
70  { "y2", "set bottom left y coordinate", OFFSET(expr_str[2][1]), AV_OPT_TYPE_STRING, {.str="H"}, 0, 0, FLAGS },
71  { "x3", "set bottom right x coordinate", OFFSET(expr_str[3][0]), AV_OPT_TYPE_STRING, {.str="W"}, 0, 0, FLAGS },
72  { "y3", "set bottom right y coordinate", OFFSET(expr_str[3][1]), AV_OPT_TYPE_STRING, {.str="H"}, 0, 0, FLAGS },
73  { "interpolation", "set interpolation", OFFSET(interpolation), AV_OPT_TYPE_INT, {.i64=LINEAR}, 0, 1, FLAGS, "interpolation" },
74  { "linear", "", 0, AV_OPT_TYPE_CONST, {.i64=LINEAR}, 0, 0, FLAGS, "interpolation" },
75  { "cubic", "", 0, AV_OPT_TYPE_CONST, {.i64=CUBIC}, 0, 0, FLAGS, "interpolation" },
76  { "sense", "specify the sense of the coordinates", OFFSET(sense), AV_OPT_TYPE_INT, {.i64=PERSPECTIVE_SENSE_SOURCE}, 0, 1, FLAGS, "sense"},
77  { "source", "specify locations in source to send to corners in destination",
78  0, AV_OPT_TYPE_CONST, {.i64=PERSPECTIVE_SENSE_SOURCE}, 0, 0, FLAGS, "sense"},
79  { "destination", "specify locations in destination to send corners of source",
80  0, AV_OPT_TYPE_CONST, {.i64=PERSPECTIVE_SENSE_DESTINATION}, 0, 0, FLAGS, "sense"},
81 
82  { NULL }
83 };
84 
85 AVFILTER_DEFINE_CLASS(perspective);
86 
88 {
89  static const enum AVPixelFormat pix_fmts[] = {
94  };
95 
96  AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
97  if (!fmts_list)
98  return AVERROR(ENOMEM);
99  return ff_set_common_formats(ctx, fmts_list);
100 }
101 
102 static inline double get_coeff(double d)
103 {
104  double coeff, A = -0.60;
105 
106  d = fabs(d);
107 
108  if (d < 1.0)
109  coeff = (1.0 - (A + 3.0) * d * d + (A + 2.0) * d * d * d);
110  else if (d < 2.0)
111  coeff = (-4.0 * A + 8.0 * A * d - 5.0 * A * d * d + A * d * d * d);
112  else
113  coeff = 0.0;
114 
115  return coeff;
116 }
117 
118 static const char *const var_names[] = { "W", "H", NULL };
120 
121 static int config_input(AVFilterLink *inlink)
122 {
123  double x0, x1, x2, x3, x4, x5, x6, x7, x8, q;
124  double t0, t1, t2, t3;
125  AVFilterContext *ctx = inlink->dst;
126  PerspectiveContext *s = ctx->priv;
127  double (*ref)[2] = s->ref;
128  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
129  double values[VAR_VARS_NB] = { [VAR_W] = inlink->w, [VAR_H] = inlink->h };
130  int h = inlink->h;
131  int w = inlink->w;
132  int x, y, i, j, ret;
133 
134  for (i = 0; i < 4; i++) {
135  for (j = 0; j < 2; j++) {
136  if (!s->expr_str[i][j])
137  return AVERROR(EINVAL);
138  ret = av_expr_parse_and_eval(&s->ref[i][j], s->expr_str[i][j],
139  var_names, &values[0],
140  NULL, NULL, NULL, NULL,
141  0, 0, ctx);
142  if (ret < 0)
143  return ret;
144  }
145  }
146 
147  s->hsub = desc->log2_chroma_w;
148  s->vsub = desc->log2_chroma_h;
150  if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0)
151  return ret;
152 
153  s->height[1] = s->height[2] = FF_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
154  s->height[0] = s->height[3] = inlink->h;
155 
156  s->pv = av_realloc_f(s->pv, w * h, 2 * sizeof(*s->pv));
157  if (!s->pv)
158  return AVERROR(ENOMEM);
159 
160  switch (s->sense) {
162  x6 = ((ref[0][0] - ref[1][0] - ref[2][0] + ref[3][0]) *
163  (ref[2][1] - ref[3][1]) -
164  ( ref[0][1] - ref[1][1] - ref[2][1] + ref[3][1]) *
165  (ref[2][0] - ref[3][0])) * h;
166  x7 = ((ref[0][1] - ref[1][1] - ref[2][1] + ref[3][1]) *
167  (ref[1][0] - ref[3][0]) -
168  ( ref[0][0] - ref[1][0] - ref[2][0] + ref[3][0]) *
169  (ref[1][1] - ref[3][1])) * w;
170  q = ( ref[1][0] - ref[3][0]) * (ref[2][1] - ref[3][1]) -
171  ( ref[2][0] - ref[3][0]) * (ref[1][1] - ref[3][1]);
172 
173  x0 = q * (ref[1][0] - ref[0][0]) * h + x6 * ref[1][0];
174  x1 = q * (ref[2][0] - ref[0][0]) * w + x7 * ref[2][0];
175  x2 = q * ref[0][0] * w * h;
176  x3 = q * (ref[1][1] - ref[0][1]) * h + x6 * ref[1][1];
177  x4 = q * (ref[2][1] - ref[0][1]) * w + x7 * ref[2][1];
178  x5 = q * ref[0][1] * w * h;
179  x8 = q * w * h;
180  break;
182  t0 = ref[0][0] * (ref[3][1] - ref[1][1]) +
183  ref[1][0] * (ref[0][1] - ref[3][1]) +
184  ref[3][0] * (ref[1][1] - ref[0][1]);
185  t1 = ref[1][0] * (ref[2][1] - ref[3][1]) +
186  ref[2][0] * (ref[3][1] - ref[1][1]) +
187  ref[3][0] * (ref[1][1] - ref[2][1]);
188  t2 = ref[0][0] * (ref[3][1] - ref[2][1]) +
189  ref[2][0] * (ref[0][1] - ref[3][1]) +
190  ref[3][0] * (ref[2][1] - ref[0][1]);
191  t3 = ref[0][0] * (ref[1][1] - ref[2][1]) +
192  ref[1][0] * (ref[2][1] - ref[0][1]) +
193  ref[2][0] * (ref[0][1] - ref[1][1]);
194 
195  x0 = t0 * t1 * w * (ref[2][1] - ref[0][1]);
196  x1 = t0 * t1 * w * (ref[0][0] - ref[2][0]);
197  x2 = t0 * t1 * w * (ref[0][1] * ref[2][0] - ref[0][0] * ref[2][1]);
198  x3 = t1 * t2 * h * (ref[1][1] - ref[0][1]);
199  x4 = t1 * t2 * h * (ref[0][0] - ref[1][0]);
200  x5 = t1 * t2 * h * (ref[0][1] * ref[1][0] - ref[0][0] * ref[1][1]);
201  x6 = t1 * t2 * (ref[1][1] - ref[0][1]) +
202  t0 * t3 * (ref[2][1] - ref[3][1]);
203  x7 = t1 * t2 * (ref[0][0] - ref[1][0]) +
204  t0 * t3 * (ref[3][0] - ref[2][0]);
205  x8 = t1 * t2 * (ref[0][1] * ref[1][0] - ref[0][0] * ref[1][1]) +
206  t0 * t3 * (ref[2][0] * ref[3][1] - ref[2][1] * ref[3][0]);
207  break;
208  default:
209  av_assert0(0);
210  }
211 
212  for (y = 0; y < h; y++){
213  for (x = 0; x < w; x++){
214  int u, v;
215 
216  u = (int)floor(SUB_PIXELS * (x0 * x + x1 * y + x2) /
217  (x6 * x + x7 * y + x8) + 0.5);
218  v = (int)floor(SUB_PIXELS * (x3 * x + x4 * y + x5) /
219  (x6 * x + x7 * y + x8) + 0.5);
220 
221  s->pv[x + y * w][0] = u;
222  s->pv[x + y * w][1] = v;
223  }
224  }
225 
226  for (i = 0; i < SUB_PIXELS; i++){
227  double d = i / (double)SUB_PIXELS;
228  double temp[4];
229  double sum = 0;
230 
231  for (j = 0; j < 4; j++)
232  temp[j] = get_coeff(j - d - 1);
233 
234  for (j = 0; j < 4; j++)
235  sum += temp[j];
236 
237  for (j = 0; j < 4; j++)
238  s->coeff[i][j] = (int)floor((1 << COEFF_BITS) * temp[j] / sum + 0.5);
239  }
240 
241  return 0;
242 }
243 
244 typedef struct ThreadData {
249  int w, h;
250  int hsub, vsub;
251 } ThreadData;
252 
253 static int resample_cubic(AVFilterContext *ctx, void *arg,
254  int job, int nb_jobs)
255 {
256  PerspectiveContext *s = ctx->priv;
257  ThreadData *td = arg;
258  uint8_t *dst = td->dst;
259  int dst_linesize = td->dst_linesize;
260  uint8_t *src = td->src;
261  int src_linesize = td->src_linesize;
262  int w = td->w;
263  int h = td->h;
264  int hsub = td->hsub;
265  int vsub = td->vsub;
266  int start = (h * job) / nb_jobs;
267  int end = (h * (job+1)) / nb_jobs;
268  const int linesize = s->linesize[0];
269  int x, y;
270 
271  for (y = start; y < end; y++) {
272  int sy = y << vsub;
273  for (x = 0; x < w; x++) {
274  int u, v, subU, subV, sum, sx;
275 
276  sx = x << hsub;
277  u = s->pv[sx + sy * linesize][0] >> hsub;
278  v = s->pv[sx + sy * linesize][1] >> vsub;
279  subU = u & (SUB_PIXELS - 1);
280  subV = v & (SUB_PIXELS - 1);
281  u >>= SUB_PIXEL_BITS;
282  v >>= SUB_PIXEL_BITS;
283 
284  if (u > 0 && v > 0 && u < w - 2 && v < h - 2){
285  const int index = u + v*src_linesize;
286  const int a = s->coeff[subU][0];
287  const int b = s->coeff[subU][1];
288  const int c = s->coeff[subU][2];
289  const int d = s->coeff[subU][3];
290 
291  sum = s->coeff[subV][0] * (a * src[index - 1 - src_linesize] + b * src[index - 0 - src_linesize] +
292  c * src[index + 1 - src_linesize] + d * src[index + 2 - src_linesize]) +
293  s->coeff[subV][1] * (a * src[index - 1 ] + b * src[index - 0 ] +
294  c * src[index + 1 ] + d * src[index + 2 ]) +
295  s->coeff[subV][2] * (a * src[index - 1 + src_linesize] + b * src[index - 0 + src_linesize] +
296  c * src[index + 1 + src_linesize] + d * src[index + 2 + src_linesize]) +
297  s->coeff[subV][3] * (a * src[index - 1 + 2 * src_linesize] + b * src[index - 0 + 2 * src_linesize] +
298  c * src[index + 1 + 2 * src_linesize] + d * src[index + 2 + 2 * src_linesize]);
299  } else {
300  int dx, dy;
301 
302  sum = 0;
303 
304  for (dy = 0; dy < 4; dy++) {
305  int iy = v + dy - 1;
306 
307  if (iy < 0)
308  iy = 0;
309  else if (iy >= h)
310  iy = h-1;
311  for (dx = 0; dx < 4; dx++) {
312  int ix = u + dx - 1;
313 
314  if (ix < 0)
315  ix = 0;
316  else if (ix >= w)
317  ix = w - 1;
318 
319  sum += s->coeff[subU][dx] * s->coeff[subV][dy] * src[ ix + iy * src_linesize];
320  }
321  }
322  }
323 
324  sum = (sum + (1<<(COEFF_BITS * 2 - 1))) >> (COEFF_BITS * 2);
325  sum = av_clip_uint8(sum);
326  dst[x + y * dst_linesize] = sum;
327  }
328  }
329  return 0;
330 }
331 
332 static int resample_linear(AVFilterContext *ctx, void *arg,
333  int job, int nb_jobs)
334 {
335  PerspectiveContext *s = ctx->priv;
336  ThreadData *td = arg;
337  uint8_t *dst = td->dst;
338  int dst_linesize = td->dst_linesize;
339  uint8_t *src = td->src;
340  int src_linesize = td->src_linesize;
341  int w = td->w;
342  int h = td->h;
343  int hsub = td->hsub;
344  int vsub = td->vsub;
345  int start = (h * job) / nb_jobs;
346  int end = (h * (job+1)) / nb_jobs;
347  const int linesize = s->linesize[0];
348  int x, y;
349 
350  for (y = start; y < end; y++){
351  int sy = y << vsub;
352  for (x = 0; x < w; x++){
353  int u, v, subU, subV, sum, sx, index, subUI, subVI;
354 
355  sx = x << hsub;
356  u = s->pv[sx + sy * linesize][0] >> hsub;
357  v = s->pv[sx + sy * linesize][1] >> vsub;
358  subU = u & (SUB_PIXELS - 1);
359  subV = v & (SUB_PIXELS - 1);
360  u >>= SUB_PIXEL_BITS;
361  v >>= SUB_PIXEL_BITS;
362 
363  index = u + v * src_linesize;
364  subUI = SUB_PIXELS - subU;
365  subVI = SUB_PIXELS - subV;
366 
367  if ((unsigned)u < (unsigned)(w - 1)){
368  if((unsigned)v < (unsigned)(h - 1)){
369  sum = subVI * (subUI * src[index] + subU * src[index + 1]) +
370  subV * (subUI * src[index + src_linesize] + subU * src[index + src_linesize + 1]);
371  sum = (sum + (1 << (SUB_PIXEL_BITS * 2 - 1)))>> (SUB_PIXEL_BITS * 2);
372  } else {
373  if (v < 0)
374  v = 0;
375  else
376  v = h - 1;
377  index = u + v * src_linesize;
378  sum = subUI * src[index] + subU * src[index + 1];
379  sum = (sum + (1 << (SUB_PIXEL_BITS - 1))) >> SUB_PIXEL_BITS;
380  }
381  } else {
382  if (u < 0)
383  u = 0;
384  else
385  u = w - 1;
386  if ((unsigned)v < (unsigned)(h - 1)){
387  index = u + v * src_linesize;
388  sum = subVI * src[index] + subV * src[index + src_linesize];
389  sum = (sum + (1 << (SUB_PIXEL_BITS - 1))) >> SUB_PIXEL_BITS;
390  } else {
391  if (v < 0)
392  v = 0;
393  else
394  v = h - 1;
395  index = u + v * src_linesize;
396  sum = src[index];
397  }
398  }
399 
400  sum = av_clip_uint8(sum);
401  dst[x + y * dst_linesize] = sum;
402  }
403  }
404  return 0;
405 }
406 
407 static av_cold int init(AVFilterContext *ctx)
408 {
409  PerspectiveContext *s = ctx->priv;
410 
411  switch (s->interpolation) {
412  case LINEAR: s->perspective = resample_linear; break;
413  case CUBIC: s->perspective = resample_cubic; break;
414  }
415 
416  return 0;
417 }
418 
419 static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
420 {
421  AVFilterContext *ctx = inlink->dst;
422  AVFilterLink *outlink = ctx->outputs[0];
423  PerspectiveContext *s = ctx->priv;
424  AVFrame *out;
425  int plane;
426 
427  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
428  if (!out) {
429  av_frame_free(&frame);
430  return AVERROR(ENOMEM);
431  }
432  av_frame_copy_props(out, frame);
433 
434  for (plane = 0; plane < s->nb_planes; plane++) {
435  int hsub = plane == 1 || plane == 2 ? s->hsub : 0;
436  int vsub = plane == 1 || plane == 2 ? s->vsub : 0;
437  ThreadData td = {.dst = out->data[plane],
438  .dst_linesize = out->linesize[plane],
439  .src = frame->data[plane],
440  .src_linesize = frame->linesize[plane],
441  .w = s->linesize[plane],
442  .h = s->height[plane],
443  .hsub = hsub,
444  .vsub = vsub };
445  ctx->internal->execute(ctx, s->perspective, &td, NULL, FFMIN(td.h, ctx->graph->nb_threads));
446  }
447 
448  av_frame_free(&frame);
449  return ff_filter_frame(outlink, out);
450 }
451 
452 static av_cold void uninit(AVFilterContext *ctx)
453 {
454  PerspectiveContext *s = ctx->priv;
455 
456  av_freep(&s->pv);
457 }
458 
459 static const AVFilterPad perspective_inputs[] = {
460  {
461  .name = "default",
462  .type = AVMEDIA_TYPE_VIDEO,
463  .filter_frame = filter_frame,
464  .config_props = config_input,
465  },
466  { NULL }
467 };
468 
470  {
471  .name = "default",
472  .type = AVMEDIA_TYPE_VIDEO,
473  },
474  { NULL }
475 };
476 
478  .name = "perspective",
479  .description = NULL_IF_CONFIG_SMALL("Correct the perspective of video."),
480  .priv_size = sizeof(PerspectiveContext),
481  .init = init,
482  .uninit = uninit,
484  .inputs = perspective_inputs,
485  .outputs = perspective_outputs,
486  .priv_class = &perspective_class,
488 };
int plane
Definition: avisynth_c.h:291
#define NULL
Definition: coverity.c:32
float v
const char * s
Definition: avisynth_c.h:631
static int resample_linear(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
double ref[4][2]
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2090
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
#define av_realloc_f(p, o, n)
AVOption.
Definition: opt.h:255
const AVFrame * src
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:68
misc image utilities
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:248
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2130
Main libavfilter public API header.
else temp
Definition: vf_mcdeint.c:257
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:176
const char * b
Definition: vf_curves.c:109
AVFILTER_DEFINE_CLASS(perspective)
static int resample_cubic(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
#define COEFF_BITS
coordinates give locations in destination of corners of source.
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:109
static int query_formats(AVFilterContext *ctx)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
struct AVFilterGraph * graph
filtergraph this filter belongs to
Definition: avfilter.h:656
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition: avfilter.h:451
static int config_input(AVFilterLink *inlink)
const char * name
Pad name.
Definition: internal.h:67
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
uint8_t * src
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1145
static av_cold void uninit(AVFilterContext *ctx)
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:103
uint8_t
#define av_cold
Definition: attributes.h:74
int32_t coeff[SUB_PIXELS][4]
AVOptions.
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:67
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
#define t0
Definition: regdef.h:28
static AVFrame * frame
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:102
int nb_threads
Maximum number of threads used by filters in this graph.
Definition: avfilter.h:1203
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:76
static const AVFilterPad perspective_inputs[]
#define A(x)
Definition: vp56_arith.h:28
A filter pad used for either input or output.
Definition: internal.h:61
int32_t(* pv)[2]
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
Definition: eval.c:717
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:269
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:542
#define td
Definition: regdef.h:70
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:148
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
void * priv
private data for use by the filter
Definition: avfilter.h:654
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:442
#define t1
Definition: regdef.h:29
const char * arg
Definition: jacosubdec.c:66
simple assert() macros that are a bit more flexible than ISO C assert().
#define t3
Definition: regdef.h:31
#define FLAGS
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:67
PERSPECTIVESense
#define FFMIN(a, b)
Definition: common.h:66
float y
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:75
ret
Definition: avfilter.c:974
#define SUB_PIXELS
#define FF_CEIL_RSHIFT(a, b)
Definition: common.h:57
int32_t
float u
AVFrame * dst
Definition: vf_blend.c:85
AVS_Value src
Definition: avisynth_c.h:482
coordinates give locations in source of corners of destination.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:199
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:268
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
#define SUB_PIXEL_BITS
char * expr_str[4][2]
#define CUBIC
int(* perspective)(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
#define LINEAR
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:69
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:470
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
Definition: imgutils.c:88
int index
Definition: gxfenc.c:89
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:239
static const char *const var_names[]
#define OFFSET(x)
const char * name
Filter name.
Definition: avfilter.h:474
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:648
uint8_t * dst
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
Definition: avfilter.h:679
static int flags
Definition: cpu.c:47
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:182
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:63
Y , 8bpp.
Definition: pixfmt.h:71
static av_cold int init(AVFilterContext *ctx)
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:287
static double c[64]
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:77
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:70
avfilter_execute_func * execute
Definition: internal.h:162
static double get_coeff(double d)
AVFilter ff_vf_perspective
A list of supported formats for one end of a filter link.
Definition: formats.h:64
static const double coeff[2][5]
Definition: vf_owdenoise.c:71
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:290
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-> out
An instance of a filter.
Definition: avfilter.h:633
#define av_freep(p)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:101
static const AVFilterPad perspective_outputs[]
void INT64 start
Definition: avisynth_c.h:553
static const AVOption perspective_options[]
internal API functions
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:548
#define t2
Definition: regdef.h:30
simple arithmetic expression evaluator