FFmpeg
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 given translation, rotation, and
64  * zoom factors. The matrix will look like:
65  *
66  * [ scale_x * cos(angle), -sin(angle), x_shift,
67  * sin(angle), scale_y * 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 scale_x x scale percent (1.0 = 100%)
74  * @param scale_y y scale percent (1.0 = 100%)
75  * @param matrix 9-item affine transformation matrix
76  */
77 void ff_get_matrix(
78  float x_shift,
79  float y_shift,
80  float angle,
81  float scale_x,
82  float scale_y,
83  float *matrix
84 );
85 
86 /**
87  * Add two matrices together. result = m1 + m2.
88  *
89  * @param m1 9-item transformation matrix
90  * @param m2 9-item transformation matrix
91  * @param result 9-item transformation matrix
92  */
93 void avfilter_add_matrix(const float *m1, const float *m2, float *result);
94 
95 /**
96  * Subtract one matrix from another. result = m1 - m2.
97  *
98  * @param m1 9-item transformation matrix
99  * @param m2 9-item transformation matrix
100  * @param result 9-item transformation matrix
101  */
102 void avfilter_sub_matrix(const float *m1, const float *m2, float *result);
103 
104 /**
105  * Multiply a matrix by a scalar value. result = m1 * scalar.
106  *
107  * @param m1 9-item transformation matrix
108  * @param scalar a number
109  * @param result 9-item transformation matrix
110  */
111 void avfilter_mul_matrix(const float *m1, float scalar, float *result);
112 
113 /**
114  * Do an affine transformation with the given interpolation method. This
115  * multiplies each vector [x,y,1] by the matrix and then interpolates to
116  * get the final value.
117  *
118  * @param src source image
119  * @param dst destination image
120  * @param src_stride source image line size in bytes
121  * @param dst_stride destination image line size in bytes
122  * @param width image width in pixels
123  * @param height image height in pixels
124  * @param matrix 9-item affine transformation matrix
125  * @param interpolate pixel interpolation method
126  * @param fill edge fill method
127  * @return negative on error
128  */
129 int avfilter_transform(const uint8_t *src, uint8_t *dst,
130  int src_stride, int dst_stride,
131  int width, int height, const float *matrix,
133  enum FillMethod fill);
134 
135 #endif /* AVFILTER_TRANSFORM_H */
void avfilter_add_matrix(const float *m1, const float *m2, float *result)
Add two matrices together.
Definition: transform.c:125
#define src
Definition: vp8dsp.c:254
InterpolateMethod
Definition: transform.h:39
uint8_t
static void interpolate(float *out, float v1, float v2, int size)
Definition: twinvq.c:84
#define height
void avfilter_mul_matrix(const float *m1, float scalar, float *result)
Multiply a matrix by a scalar value.
Definition: transform.c:139
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:146
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:132
#define width
void ff_get_matrix(float x_shift, float y_shift, float angle, float scale_x, float scale_y, float *matrix)
Get an affine transformation matrix from given translation, rotation, and zoom factors.
Definition: transform.c:106
and forward the result(frame or status change) to the corresponding input.If nothing is possible