FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
transform.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 Georg Martius <georg.martius@web.de>
3  * Copyright (C) 2010 Daniel G. Taylor <dan@programmer-art.org>
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 #ifndef AVFILTER_TRANSFORM_H
23 #define AVFILTER_TRANSFORM_H
24 
25 #include <stdint.h>
26 
27 /**
28  * @file
29  * transform input video
30  *
31  * All matrices are defined as a single 9-item block of contiguous memory. For
32  * example, the identity matrix would be:
33  *
34  * float *matrix = {1, 0, 0,
35  * 0, 1, 0,
36  * 0, 0, 1};
37  */
38 
40  INTERPOLATE_NEAREST, //< Nearest-neighbor (fast)
41  INTERPOLATE_BILINEAR, //< Bilinear
42  INTERPOLATE_BIQUADRATIC, //< Biquadratic (best)
43  INTERPOLATE_COUNT, //< Number of interpolation methods
44 };
45 
46 // Shortcuts for the fastest and best interpolation methods
47 #define INTERPOLATE_DEFAULT INTERPOLATE_BILINEAR
48 #define INTERPOLATE_FAST INTERPOLATE_NEAREST
49 #define INTERPOLATE_BEST INTERPOLATE_BIQUADRATIC
50 
51 enum FillMethod {
52  FILL_BLANK, //< Fill zeroes at blank locations
53  FILL_ORIGINAL, //< Original image at blank locations
54  FILL_CLAMP, //< Extruded edge value at blank locations
55  FILL_MIRROR, //< Mirrored edge at blank locations
56  FILL_COUNT, //< Number of edge fill methods
57 };
58 
59 // Shortcuts for fill methods
60 #define FILL_DEFAULT FILL_ORIGINAL
61 
62 /**
63  * Get an affine transformation matrix from a given translation, rotation, and
64  * zoom factor. The matrix will look like:
65  *
66  * [ zoom * cos(angle), -sin(angle), x_shift,
67  * sin(angle), zoom * cos(angle), y_shift,
68  * 0, 0, 1 ]
69  *
70  * @param x_shift horizontal translation
71  * @param y_shift vertical translation
72  * @param angle rotation in radians
73  * @param zoom scale percent (1.0 = 100%)
74  * @param matrix 9-item affine transformation matrix
75  */
76 void avfilter_get_matrix(float x_shift, float y_shift, float angle, float zoom, float *matrix);
77 
78 /**
79  * Add two matrices together. result = m1 + m2.
80  *
81  * @param m1 9-item transformation matrix
82  * @param m2 9-item transformation matrix
83  * @param result 9-item transformation matrix
84  */
85 void avfilter_add_matrix(const float *m1, const float *m2, float *result);
86 
87 /**
88  * Subtract one matrix from another. result = m1 - m2.
89  *
90  * @param m1 9-item transformation matrix
91  * @param m2 9-item transformation matrix
92  * @param result 9-item transformation matrix
93  */
94 void avfilter_sub_matrix(const float *m1, const float *m2, float *result);
95 
96 /**
97  * Multiply a matrix by a scalar value. result = m1 * scalar.
98  *
99  * @param m1 9-item transformation matrix
100  * @param scalar a number
101  * @param result 9-item transformation matrix
102  */
103 void avfilter_mul_matrix(const float *m1, float scalar, float *result);
104 
105 /**
106  * Do an affine transformation with the given interpolation method. This
107  * multiplies each vector [x,y,1] by the matrix and then interpolates to
108  * get the final value.
109  *
110  * @param src source image
111  * @param dst destination image
112  * @param src_stride source image line size in bytes
113  * @param dst_stride destination image line size in bytes
114  * @param width image width in pixels
115  * @param height image height in pixels
116  * @param matrix 9-item affine transformation matrix
117  * @param interpolate pixel interpolation method
118  * @param fill edge fill method
119  * @return negative on error
120  */
121 int avfilter_transform(const uint8_t *src, uint8_t *dst,
122  int src_stride, int dst_stride,
123  int width, int height, const float *matrix,
125  enum FillMethod fill);
126 
127 #endif /* AVFILTER_TRANSFORM_H */
void avfilter_get_matrix(float x_shift, float y_shift, float angle, float zoom, float *matrix)
Get an affine transformation matrix from a given translation, rotation, and zoom factor.
Definition: transform.c:106
void avfilter_add_matrix(const float *m1, const float *m2, float *result)
Add two matrices together.
Definition: transform.c:118
InterpolateMethod
Definition: transform.h:39
uint8_t
static void interpolate(float *out, float v1, float v2, int size)
Definition: twinvq.c:84
void avfilter_mul_matrix(const float *m1, float scalar, float *result)
Multiply a matrix by a scalar value.
Definition: transform.c:132
int avfilter_transform(const uint8_t *src, uint8_t *dst, int src_stride, int dst_stride, int width, int height, const float *matrix, enum InterpolateMethod interpolate, enum FillMethod fill)
Do an affine transformation with the given interpolation method.
Definition: transform.c:139
FillMethod
Definition: transform.h:51
void avfilter_sub_matrix(const float *m1, const float *m2, float *result)
Subtract one matrix from another.
Definition: transform.c:125
#define src
Definition: vp9dsp.c:530
BYTE int const BYTE int int int height
Definition: avisynth_c.h:676
static int width