FFmpeg
tx.h
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef AVUTIL_TX_H
20 #define AVUTIL_TX_H
21 
22 #include <stdint.h>
23 #include <stddef.h>
24 
25 typedef struct AVTXContext AVTXContext;
26 
27 typedef struct AVComplexFloat {
28  float re, im;
30 
31 typedef struct AVComplexDouble {
32  double re, im;
34 
35 typedef struct AVComplexInt32 {
38 
39 enum AVTXType {
40  /**
41  * Standard complex to complex FFT with sample data type of AVComplexFloat,
42  * AVComplexDouble or AVComplexInt32, for each respective variant.
43  *
44  * Output is not 1/len normalized. Scaling currently unsupported.
45  * The stride parameter must be set to the size of a single sample in bytes.
46  */
50 
51  /**
52  * Standard MDCT with a sample data type of float, double or int32_t,
53  * respecively. For the float and int32 variants, the scale type is
54  * 'float', while for the double variant, it's 'double'.
55  * If scale is NULL, 1.0 will be used as a default.
56  *
57  * Length is the frame size, not the window size (which is 2x frame).
58  * For forward transforms, the stride specifies the spacing between each
59  * sample in the output array in bytes. The input must be a flat array.
60  *
61  * For inverse transforms, the stride specifies the spacing between each
62  * sample in the input array in bytes. The output must be a flat array.
63  *
64  * NOTE: the inverse transform is half-length, meaning the output will not
65  * contain redundant data. This is what most codecs work with. To do a full
66  * inverse transform, set the AV_TX_FULL_IMDCT flag on init.
67  */
71 
72  /**
73  * Real to complex and complex to real DFTs.
74  * For the float and int32 variants, the scale type is 'float', while for
75  * the double variant, it's a 'double'. If scale is NULL, 1.0 will be used
76  * as a default.
77  *
78  * For forward transforms (R2C), stride must be the spacing between two
79  * samples in bytes. For inverse transforms, the stride must be set
80  * to the spacing between two complex values in bytes.
81  *
82  * The forward transform performs a real-to-complex DFT of N samples to
83  * N/2+1 complex values.
84  *
85  * The inverse transform performs a complex-to-real DFT of N/2+1 complex
86  * values to N real samples. The output is not normalized, but can be
87  * made so by setting the scale value to 1.0/len.
88  * NOTE: the inverse transform always overwrites the input.
89  */
93 
94  /**
95  * Real to real (DCT) transforms.
96  *
97  * The forward transform is a DCT-II.
98  * The inverse transform is a DCT-III.
99  *
100  * The input array is always overwritten. DCT-III requires that the
101  * input be padded with 2 extra samples. Stride must be set to the
102  * spacing between two samples in bytes.
103  */
107 
108  /**
109  * Discrete Cosine Transform I
110  *
111  * The forward transform is a DCT-I.
112  * The inverse transform is a DCT-I multiplied by 2/(N + 1).
113  *
114  * The input array is always overwritten.
115  */
119 
120  /**
121  * Discrete Sine Transform I
122  *
123  * The forward transform is a DST-I.
124  * The inverse transform is a DST-I multiplied by 2/(N + 1).
125  *
126  * The input array is always overwritten.
127  */
131 
132  /* Not part of the API, do not use */
134 };
135 
136 /**
137  * Function pointer to a function to perform the transform.
138  *
139  * @note Using a different context than the one allocated during av_tx_init()
140  * is not allowed.
141  *
142  * @param s the transform context
143  * @param out the output array
144  * @param in the input array
145  * @param stride the input or output stride in bytes
146  *
147  * The out and in arrays must be aligned to the maximum required by the CPU
148  * architecture unless the AV_TX_UNALIGNED flag was set in av_tx_init().
149  * The stride must follow the constraints the transform type has specified.
150  */
151 typedef void (*av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride);
152 
153 /**
154  * Flags for av_tx_init()
155  */
156 enum AVTXFlags {
157  /**
158  * Allows for in-place transformations, where input == output.
159  * May be unsupported or slower for some transform types.
160  */
161  AV_TX_INPLACE = 1ULL << 0,
162 
163  /**
164  * Relaxes alignment requirement for the in and out arrays of av_tx_fn().
165  * May be slower with certain transform types.
166  */
167  AV_TX_UNALIGNED = 1ULL << 1,
168 
169  /**
170  * Performs a full inverse MDCT rather than leaving out samples that can be
171  * derived through symmetry. Requires an output array of 'len' floats,
172  * rather than the usual 'len/2' floats.
173  * Ignored for all transforms but inverse MDCTs.
174  */
175  AV_TX_FULL_IMDCT = 1ULL << 2,
176 
177  /**
178  * Perform a real to half-complex RDFT.
179  * Only the real, or imaginary coefficients will
180  * be output, depending on the flag used. Only available for forward RDFTs.
181  * Output array must have enough space to hold N complex values
182  * (regular size for a real to complex transform).
183  */
184  AV_TX_REAL_TO_REAL = 1ULL << 3,
186 };
187 
188 /**
189  * Initialize a transform context with the given configuration
190  * (i)MDCTs with an odd length are currently not supported.
191  *
192  * @param ctx the context to allocate, will be NULL on error
193  * @param tx pointer to the transform function pointer to set
194  * @param type type the type of transform
195  * @param inv whether to do an inverse or a forward transform
196  * @param len the size of the transform in samples
197  * @param scale pointer to the value to scale the output if supported by type
198  * @param flags a bitmask of AVTXFlags or 0
199  *
200  * @return 0 on success, negative error code on failure
201  */
203  int inv, int len, const void *scale, uint64_t flags);
204 
205 /**
206  * Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
207  */
209 
210 #endif /* AVUTIL_TX_H */
AV_TX_DOUBLE_MDCT
@ AV_TX_DOUBLE_MDCT
Definition: tx.h:69
AV_TX_REAL_TO_REAL
@ AV_TX_REAL_TO_REAL
Perform a real to half-complex RDFT.
Definition: tx.h:184
out
FILE * out
Definition: movenc.c:55
AVTXContext
Definition: tx_priv.h:235
AVComplexDouble::im
double im
Definition: tx.h:32
AV_TX_DOUBLE_FFT
@ AV_TX_DOUBLE_FFT
Definition: tx.h:48
AVComplexFloat
Definition: tx.h:27
av_tx_init
int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
Definition: tx.c:903
AVComplexFloat::im
float im
Definition: tx.h:28
AV_TX_INT32_DCT_I
@ AV_TX_INT32_DCT_I
Definition: tx.h:118
AV_TX_DOUBLE_DCT
@ AV_TX_DOUBLE_DCT
Definition: tx.h:105
AVComplexInt32::re
int32_t re
Definition: tx.h:36
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
AV_TX_INT32_DST_I
@ AV_TX_INT32_DST_I
Definition: tx.h:130
AV_TX_NB
@ AV_TX_NB
Definition: tx.h:133
av_tx_fn
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
Definition: tx.h:151
AV_TX_FLOAT_MDCT
@ AV_TX_FLOAT_MDCT
Standard MDCT with a sample data type of float, double or int32_t, respecively.
Definition: tx.h:68
AVComplexInt32
Definition: tx.h:35
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_TX_DOUBLE_DCT_I
@ AV_TX_DOUBLE_DCT_I
Definition: tx.h:117
AV_TX_INT32_MDCT
@ AV_TX_INT32_MDCT
Definition: tx.h:70
AV_TX_FLOAT_FFT
@ AV_TX_FLOAT_FFT
Standard complex to complex FFT with sample data type of AVComplexFloat, AVComplexDouble or AVComplex...
Definition: tx.h:47
ctx
AVFormatContext * ctx
Definition: movenc.c:49
AV_TX_FULL_IMDCT
@ AV_TX_FULL_IMDCT
Performs a full inverse MDCT rather than leaving out samples that can be derived through symmetry.
Definition: tx.h:175
AV_TX_REAL_TO_IMAGINARY
@ AV_TX_REAL_TO_IMAGINARY
Definition: tx.h:185
AV_TX_INPLACE
@ AV_TX_INPLACE
Allows for in-place transformations, where input == output.
Definition: tx.h:161
AV_TX_UNALIGNED
@ AV_TX_UNALIGNED
Relaxes alignment requirement for the in and out arrays of av_tx_fn().
Definition: tx.h:167
AV_TX_FLOAT_DCT_I
@ AV_TX_FLOAT_DCT_I
Discrete Cosine Transform I.
Definition: tx.h:116
AVTXType
AVTXType
Definition: tx.h:39
AVComplexFloat::re
float re
Definition: tx.h:28
AV_TX_INT32_FFT
@ AV_TX_INT32_FFT
Definition: tx.h:49
AVTXFlags
AVTXFlags
Flags for av_tx_init()
Definition: tx.h:156
AV_TX_DOUBLE_DST_I
@ AV_TX_DOUBLE_DST_I
Definition: tx.h:129
av_tx_uninit
void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
Definition: tx.c:295
AV_TX_DOUBLE_RDFT
@ AV_TX_DOUBLE_RDFT
Definition: tx.h:91
len
int len
Definition: vorbis_enc_data.h:426
AVComplexDouble
Definition: tx.h:31
stride
#define stride
Definition: h264pred_template.c:537
AVComplexDouble::re
double re
Definition: tx.h:32
AVComplexInt32::im
int32_t im
Definition: tx.h:36
AV_TX_INT32_DCT
@ AV_TX_INT32_DCT
Definition: tx.h:106
AV_TX_FLOAT_RDFT
@ AV_TX_FLOAT_RDFT
Real to complex and complex to real DFTs.
Definition: tx.h:90
AV_TX_FLOAT_DST_I
@ AV_TX_FLOAT_DST_I
Discrete Sine Transform I.
Definition: tx.h:128
AV_TX_INT32_RDFT
@ AV_TX_INT32_RDFT
Definition: tx.h:92
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:291
AV_TX_FLOAT_DCT
@ AV_TX_FLOAT_DCT
Real to real (DCT) transforms.
Definition: tx.h:104
int32_t
int32_t
Definition: audioconvert.c:56
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482