]> git.sesse.net Git - ffmpeg/blob - libavfilter/transform.h
Merge remote-tracking branch 'luzero/segment'
[ffmpeg] / libavfilter / transform.h
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 /**
23  * @file
24  * transform input video
25  *
26  * All matrices are defined as a single 9-item block of contiguous memory. For
27  * example, the identity matrix would be:
28  *
29  *     float *matrix = {1, 0, 0,
30  *                      0, 1, 0,
31  *                      0, 0, 1};
32  */
33
34 enum InterpolateMethod {
35     INTERPOLATE_NEAREST,        //< Nearest-neighbor (fast)
36     INTERPOLATE_BILINEAR,       //< Bilinear
37     INTERPOLATE_BIQUADRATIC,    //< Biquadratic (best)
38     INTERPOLATE_COUNT,          //< Number of interpolation methods
39 };
40
41 // Shortcuts for the fastest and best interpolation methods
42 #define INTERPOLATE_DEFAULT INTERPOLATE_BILINEAR
43 #define INTERPOLATE_FAST    INTERPOLATE_NEAREST
44 #define INTERPOLATE_BEST    INTERPOLATE_BIQUADRATIC
45
46 enum FillMethod {
47     FILL_BLANK,         //< Fill zeroes at blank locations
48     FILL_ORIGINAL,      //< Original image at blank locations
49     FILL_CLAMP,         //< Extruded edge value at blank locations
50     FILL_MIRROR,        //< Mirrored edge at blank locations
51     FILL_COUNT,         //< Number of edge fill methods
52 };
53
54 // Shortcuts for fill methods
55 #define FILL_DEFAULT FILL_ORIGINAL
56
57 /**
58  * Get an affine transformation matrix from a given translation, rotation, and
59  * zoom factor. The matrix will look like:
60  *
61  * [ zoom * cos(angle),           -sin(angle),     x_shift,
62  *          sin(angle),     zoom * cos(angle),     y_shift,
63                      0,                     0,           1 ]
64  *
65  * Paramters:
66  *  x_shift: Horizontal translation
67  *  y_shift: Vertical translation
68  *    angle: Rotation in radians
69  *     zoom: Scale percent (1.0 = 100%)
70  *   matrix: 9-item affine transformation matrix
71  */
72 void avfilter_get_matrix(float x_shift, float y_shift, float angle, float zoom, float *matrix);
73
74 /**
75  * Add two matrices together. result = m1 + m2.
76  *
77  * Parameters:
78  *      m1: 9-item transformation matrix
79  *      m2: 9-item transformation matrix
80  *  result: 9-item transformation matrix
81  */
82 void avfilter_add_matrix(const float *m1, const float *m2, float *result);
83
84 /**
85  * Subtract one matrix from another. result = m1 - m2.
86  *
87  * Parameters:
88  *      m1: 9-item transformation matrix
89  *      m2: 9-item transformation matrix
90  *  result: 9-item transformation matrix
91  */
92 void avfilter_sub_matrix(const float *m1, const float *m2, float *result);
93
94 /**
95  * Multiply a matrix by a scalar value. result = m1 * scalar.
96  *
97  * Parameters:
98  *      m1: 9-item transformation matrix
99  *  scalar: A number
100  *  result: 9-item transformation matrix
101  */
102 void avfilter_mul_matrix(const float *m1, float scalar, float *result);
103
104 /**
105  * Do an affine transformation with the given interpolation method. This
106  * multiplies each vector [x,y,1] by the matrix and then interpolates to
107  * get the final value.
108  *
109  * Parameters:
110  *          src: Source image
111  *          dst: Destination image
112  *   src_stride: Source image line size in bytes
113  *   dst_stride: Destination image line size in bytes
114  *        width: Image width in pixels
115  *       height: Image height in pixels
116  *       matrix: 9-item affine transformation matrix
117  *  interpolate: Pixel interpolation method
118  *         fill: Edge fill method
119  */
120 void avfilter_transform(const uint8_t *src, uint8_t *dst,
121                         int src_stride, int dst_stride,
122                         int width, int height, const float *matrix,
123                         enum InterpolateMethod interpolate,
124                         enum FillMethod fill);
125