Go to the documentation of this file.
   32 #define SUB_PIXEL_BITS  8 
   33 #define SUB_PIXELS      (1 << SUB_PIXEL_BITS) 
   54                        void *
arg, 
int job, 
int nb_jobs);
 
   57 #define OFFSET(x) offsetof(PerspectiveContext, x) 
   58 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM 
   84     {       
"source", 
"specify locations in source to send to corners in destination",
 
   86     {       
"destination", 
"specify locations in destination to send corners of source",
 
  111         coeff = (1.0 - (
A + 3.0) * d * d + (
A + 2.0) * d * d * d);
 
  113         coeff = (-4.0 * 
A + 8.0 * 
A * d - 5.0 * 
A * d * d + 
A * d * d * d);
 
  136     double x0, x1, x2, x3, x4, x5, x6, x7, x8, q;
 
  137     double t0, t1, t2, t3;
 
  140     for (
i = 0; 
i < 4; 
i++) {
 
  141         for (j = 0; j < 2; j++) {
 
  142             if (!
s->expr_str[
i][j])
 
  163         q =  ( 
ref[1][0] - 
ref[3][0]) * (
ref[2][1] - 
ref[3][1]) -
 
  166         x0 = q * (
ref[1][0] - 
ref[0][0]) * 
h + x6 * 
ref[1][0];
 
  167         x1 = q * (
ref[2][0] - 
ref[0][0]) * 
w + x7 * 
ref[2][0];
 
  168         x2 = q *  
ref[0][0] * 
w * 
h;
 
  169         x3 = q * (
ref[1][1] - 
ref[0][1]) * 
h + x6 * 
ref[1][1];
 
  170         x4 = q * (
ref[2][1] - 
ref[0][1]) * 
w + x7 * 
ref[2][1];
 
  171         x5 = q *  
ref[0][1] * 
w * 
h;
 
  175         t0 = 
ref[0][0] * (
ref[3][1] - 
ref[1][1]) +
 
  178         t1 = 
ref[1][0] * (
ref[2][1] - 
ref[3][1]) +
 
  181         t2 = 
ref[0][0] * (
ref[3][1] - 
ref[2][1]) +
 
  184         t3 = 
ref[0][0] * (
ref[1][1] - 
ref[2][1]) +
 
  188         x0 = t0 * t1 * 
w * (
ref[2][1] - 
ref[0][1]);
 
  189         x1 = t0 * t1 * 
w * (
ref[0][0] - 
ref[2][0]);
 
  190         x2 = t0 * t1 * 
w * (
ref[0][1] * 
ref[2][0] - 
ref[0][0] * 
ref[2][1]);
 
  191         x3 = t1 * t2 * 
h * (
ref[1][1] - 
ref[0][1]);
 
  192         x4 = t1 * t2 * 
h * (
ref[0][0] - 
ref[1][0]);
 
  193         x5 = t1 * t2 * 
h * (
ref[0][1] * 
ref[1][0] - 
ref[0][0] * 
ref[1][1]);
 
  194         x6 = t1 * t2 * (
ref[1][1] - 
ref[0][1]) +
 
  195              t0 * t3 * (
ref[2][1] - 
ref[3][1]);
 
  196         x7 = t1 * t2 * (
ref[0][0] - 
ref[1][0]) +
 
  197              t0 * t3 * (
ref[3][0] - 
ref[2][0]);
 
  198         x8 = t1 * t2 * (
ref[0][1] * 
ref[1][0] - 
ref[0][0] * 
ref[1][1]) +
 
  199              t0 * t3 * (
ref[2][0] * 
ref[3][1] - 
ref[2][1] * 
ref[3][0]);
 
  205     for (y = 0; y < 
h; y++){
 
  206         for (x = 0; x < 
w; x++){
 
  210                                         (x6 * x + x7 * y + x8));
 
  212                                         (x6 * x + x7 * y + x8));
 
  214             s->pv[x + y * 
w][0] = 
u;
 
  215             s->pv[x + y * 
w][1] = v;
 
  230     s->hsub = 
desc->log2_chroma_w;
 
  231     s->vsub = 
desc->log2_chroma_h;
 
  237     s->height[0] = 
s->height[3] = 
inlink->h;
 
  254         for (j = 0; j < 4; j++)
 
  257         for (j = 0; j < 4; j++)
 
  260         for (j = 0; j < 4; j++)
 
  277                           int job, 
int nb_jobs)
 
  289     int start = (
h * job) / nb_jobs;
 
  290     int end   = (
h * (job+1)) / nb_jobs;
 
  291     const int linesize = 
s->linesize[0];
 
  294     for (y = start; y < end; y++) {
 
  296         for (x = 0; x < 
w; x++) {
 
  297             int u, v, subU, subV, sum, sx;
 
  300             u    = 
s->pv[sx + sy * linesize][0] >> 
hsub;
 
  301             v    = 
s->pv[sx + sy * linesize][1] >> vsub;
 
  307             if (
u > 0 && v > 0 && 
u < 
w - 2 && v < 
h - 2){
 
  308                 const int index = 
u + v*src_linesize;
 
  309                 const int a = 
s->coeff[subU][0];
 
  310                 const int b = 
s->coeff[subU][1];
 
  311                 const int c = 
s->coeff[subU][2];
 
  312                 const int d = 
s->coeff[subU][3];
 
  314                 sum = 
s->coeff[subV][0] * (
a * 
src[
index - 1 -     src_linesize] + 
b * 
src[
index - 0 -     src_linesize]  +
 
  318                       s->coeff[subV][2] * (
a * 
src[
index - 1 +     src_linesize] + 
b * 
src[
index - 0 +     src_linesize]  +
 
  320                       s->coeff[subV][3] * (
a * 
src[
index - 1 + 2 * src_linesize] + 
b * 
src[
index - 0 + 2 * src_linesize]  +
 
  327                 for (dy = 0; dy < 4; dy++) {
 
  334                     for (dx = 0; dx < 4; dx++) {
 
  342                         sum += 
s->coeff[subU][dx] * 
s->coeff[subV][dy] * 
src[ ix + iy * src_linesize];
 
  349             dst[x + y * dst_linesize] = sum;
 
  356                            int job, 
int nb_jobs)
 
  368     int start = (
h * job) / nb_jobs;
 
  369     int end   = (
h * (job+1)) / nb_jobs;
 
  370     const int linesize = 
s->linesize[0];
 
  373     for (y = start; y < end; y++){
 
  375         for (x = 0; x < 
w; x++){
 
  376             int u, v, subU, subV, sum, sx, 
index, subUI, subVI;
 
  379             u    = 
s->pv[sx + sy * linesize][0] >> 
hsub;
 
  380             v    = 
s->pv[sx + sy * linesize][1] >> vsub;
 
  386             index = 
u + v * src_linesize;
 
  390             if ((
unsigned)
u < (unsigned)(
w - 1)){
 
  391                 if((
unsigned)v < (unsigned)(
h - 1)){
 
  393                           subV  * (subUI * 
src[
index + src_linesize] + subU * 
src[
index + src_linesize + 1]);
 
  400                     index = 
u + v * src_linesize;
 
  409                 if ((
unsigned)v < (unsigned)(
h - 1)){
 
  410                     index = 
u + v * src_linesize;
 
  418                     index = 
u + v * src_linesize;
 
  424             dst[x + y * dst_linesize] = sum;
 
  434     switch (
s->interpolation) {
 
  465     for (plane = 0; plane < 
s->nb_planes; plane++) {
 
  466         int hsub = plane == 1 || plane == 2 ? 
s->hsub : 0;
 
  467         int vsub = plane == 1 || plane == 2 ? 
s->vsub : 0;
 
  469                          .dst_linesize = 
out->linesize[plane],
 
  470                          .src = 
frame->data[plane],
 
  471                          .src_linesize = 
frame->linesize[plane],
 
  472                          .w = 
s->linesize[plane],
 
  473                          .h = 
s->height[plane],
 
  501     .
name          = 
"perspective",
 
  509     .priv_class    = &perspective_class,
 
  
static double get_coeff(double d)
 
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
 
int32_t coeff[SUB_PIXELS][4]
 
AVPixelFormat
Pixel format.
 
static enum AVPixelFormat pix_fmts[]
 
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
 
#define FILTER_PIXFMTS_ARRAY(array)
 
#define u(width, name, range_min, range_max)
 
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
 
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
 
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
 
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
 
int(* perspective)(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
 
#define FILTER_INPUTS(array)
 
This structure describes decoded (raw) audio or video data.
 
static int calc_persp_luts(AVFilterContext *ctx, AVFilterLink *inlink)
 
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
 
const char * name
Filter name.
 
A link between two filters.
 
@ PERSPECTIVE_SENSE_SOURCE
coordinates give locations in source of corners of destination.
 
Link properties exposed to filter code, but not external callers.
 
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
 
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
 
A filter pad used for either input or output.
 
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
 
static av_cold int init(AVFilterContext *ctx)
 
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
 
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
 
static int resample_linear(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
 
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.
 
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
 
#define AV_CEIL_RSHIFT(a, b)
 
#define av_assert0(cond)
assert() equivalent, that is always enabled.
 
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
 
#define FILTER_OUTPUTS(array)
 
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
 
#define av_realloc_f(p, o, n)
 
static const AVOption perspective_options[]
 
static const AVFilterPad perspective_inputs[]
 
Describe the class of an AVClass context structure.
 
static __device__ float fabs(float a)
 
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
 
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
 
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
 
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
 
static FilterLink * ff_filter_link(AVFilterLink *link)
 
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
 
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.
 
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
 
const AVFilter ff_vf_perspective
 
@ PERSPECTIVE_SENSE_DESTINATION
coordinates give locations in destination of corners of source.
 
AVFILTER_DEFINE_CLASS(perspective)
 
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
 
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
 
static int interpolation(DeclickChannel *c, const double *src, int ar_order, double *acoefficients, int *index, int nb_errors, double *auxiliary, double *interpolated)
 
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
 
#define i(width, name, range_min, range_max)
 
int w
agreed upon image width
 
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
 
Used for passing data between threads.
 
static int config_input(AVFilterLink *inlink)
 
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
 
const char * name
Pad name.
 
static av_cold void uninit(AVFilterContext *ctx)
 
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
 
static int resample_cubic(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
 
int h
agreed upon image height
 
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
 
@ AV_OPT_TYPE_INT
Underlying C type is int.
 
static const char *const var_names[]
 
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return values
 
static int ref[MAX_W *MAX_W]
 
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
 
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
 
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
 
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
 
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
 
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
 
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
 
static const double coeff[2][5]
 
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
 
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
 
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
 
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
 
int64_t frame_count_in
Number of past frames sent through the link.