33 #define SUB_PIXEL_BITS 8
34 #define SUB_PIXELS (1 << SUB_PIXEL_BITS)
55 void *
arg,
int job,
int nb_jobs);
58 #define OFFSET(x) offsetof(PerspectiveContext, x)
59 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
85 {
"source",
"specify locations in source to send to corners in destination",
87 {
"destination",
"specify locations in destination to send corners of source",
120 coeff = (1.0 - (
A + 3.0) * d * d + (
A + 2.0) * d * d * d);
122 coeff = (-4.0 *
A + 8.0 *
A * d - 5.0 *
A * d * d +
A * d * d * d);
136 double (*
ref)[2] =
s->ref;
141 const int h = values[
VAR_H];
142 const int w = values[
VAR_W];
143 double x0, x1, x2, x3, x4, x5, x6, x7, x8, q;
147 for (
i = 0;
i < 4;
i++) {
148 for (j = 0; j < 2; j++) {
149 if (!
s->expr_str[
i][j])
170 q = (
ref[1][0] -
ref[3][0]) * (
ref[2][1] -
ref[3][1]) -
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;
212 for (y = 0; y <
h; y++){
213 for (x = 0; x <
w; x++){
217 (x6 * x + x7 * y + x8));
219 (x6 * x + x7 * y + x8));
221 s->pv[x + y *
w][0] =
u;
222 s->pv[x + y *
w][1] = v;
237 s->hsub =
desc->log2_chroma_w;
238 s->vsub =
desc->log2_chroma_h;
244 s->height[0] =
s->height[3] = inlink->
h;
261 for (j = 0; j < 4; j++)
264 for (j = 0; j < 4; j++)
267 for (j = 0; j < 4; j++)
284 int job,
int nb_jobs)
289 int dst_linesize =
td->dst_linesize;
291 int src_linesize =
td->src_linesize;
298 const int linesize =
s->linesize[0];
301 for (y = start; y < end; y++) {
303 for (x = 0; x <
w; x++) {
304 int u, v, subU, subV, sum, sx;
307 u =
s->pv[sx + sy * linesize][0] >>
hsub;
308 v =
s->pv[sx + sy * linesize][1] >> vsub;
314 if (
u > 0 && v > 0 &&
u <
w - 2 && v <
h - 2){
315 const int index =
u + v*src_linesize;
316 const int a =
s->coeff[subU][0];
317 const int b =
s->coeff[subU][1];
318 const int c =
s->coeff[subU][2];
319 const int d =
s->coeff[subU][3];
321 sum =
s->coeff[subV][0] * (
a *
src[
index - 1 - src_linesize] +
b *
src[
index - 0 - src_linesize] +
325 s->coeff[subV][2] * (
a *
src[
index - 1 + src_linesize] +
b *
src[
index - 0 + src_linesize] +
327 s->coeff[subV][3] * (
a *
src[
index - 1 + 2 * src_linesize] +
b *
src[
index - 0 + 2 * src_linesize] +
334 for (dy = 0; dy < 4; dy++) {
341 for (dx = 0; dx < 4; dx++) {
349 sum +=
s->coeff[subU][dx] *
s->coeff[subV][dy] *
src[ ix + iy * src_linesize];
356 dst[x + y * dst_linesize] = sum;
363 int job,
int nb_jobs)
368 int dst_linesize =
td->dst_linesize;
370 int src_linesize =
td->src_linesize;
377 const int linesize =
s->linesize[0];
380 for (y = start; y < end; y++){
382 for (x = 0; x <
w; x++){
383 int u, v, subU, subV, sum, sx,
index, subUI, subVI;
386 u =
s->pv[sx + sy * linesize][0] >>
hsub;
387 v =
s->pv[sx + sy * linesize][1] >> vsub;
393 index =
u + v * src_linesize;
397 if ((
unsigned)
u < (unsigned)(
w - 1)){
398 if((
unsigned)v < (unsigned)(
h - 1)){
400 subV * (subUI *
src[
index + src_linesize] + subU *
src[
index + src_linesize + 1]);
407 index =
u + v * src_linesize;
416 if ((
unsigned)v < (unsigned)(
h - 1)){
417 index =
u + v * src_linesize;
425 index =
u + v * src_linesize;
431 dst[x + y * dst_linesize] = sum;
441 switch (
s->interpolation) {
472 for (plane = 0; plane <
s->nb_planes; plane++) {
473 int hsub = plane == 1 || plane == 2 ?
s->hsub : 0;
474 int vsub = plane == 1 || plane == 2 ?
s->vsub : 0;
476 .dst_linesize =
out->linesize[plane],
479 .w =
s->linesize[plane],
480 .h =
s->height[plane],
516 .
name =
"perspective",
524 .priv_class = &perspective_class,
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
static int interpolation(DeclickChannel *c, const double *src, int ar_order, double *acoefficients, int *index, int nb_errors, double *auxiliary, double *interpolated)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Main libavfilter public API header.
#define flags(name, subs,...)
#define u(width, name, range_min, range_max)
#define AV_CEIL_RSHIFT(a, b)
static __device__ float fabs(float a)
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.
simple arithmetic expression evaluator
static int ff_slice_pos(int total, int jobnr, int nb_jobs)
Compute the boundary index for a slice when work of size total is split into nb_jobs slices.
#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 AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
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.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Describe the class of an AVClass context structure.
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
int64_t frame_count_in
Number of past frames sent through the link.
AVFilterContext * dst
dest filter
int format
agreed upon media format
A filter pad used for either input or output.
const char * name
Pad name.
const char * name
Filter name.
AVFormatInternal * internal
An opaque field for libavformat internal usage.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
int(* perspective)(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
int32_t coeff[SUB_PIXELS][4]
Used for passing data between threads.
#define av_realloc_f(p, o, n)
static int ref[MAX_W *MAX_W]
static const double coeff[2][5]
static int resample_cubic(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
static const AVFilterPad perspective_inputs[]
AVFilter ff_vf_perspective
static int calc_persp_luts(AVFilterContext *ctx, AVFilterLink *inlink)
static int query_formats(AVFilterContext *ctx)
static int config_input(AVFilterLink *inlink)
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
static double get_coeff(double d)
static const AVFilterPad perspective_outputs[]
static int resample_linear(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
static const AVOption perspective_options[]
static const char *const var_names[]
static av_cold int init(AVFilterContext *ctx)
static av_cold void uninit(AVFilterContext *ctx)
@ PERSPECTIVE_SENSE_DESTINATION
coordinates give locations in destination of corners of source.
@ PERSPECTIVE_SENSE_SOURCE
coordinates give locations in source of corners of destination.
AVFILTER_DEFINE_CLASS(perspective)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.