]> git.sesse.net Git - ffmpeg/blob - libavcodec/dsputil.h
ffmpeg_opt: fix attachment streams
[ffmpeg] / libavcodec / dsputil.h
1 /*
2  * DSP utils
3  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22
23 /**
24  * @file
25  * DSP utils.
26  * Note, many functions in here may use MMX which trashes the FPU state, it is
27  * absolutely necessary to call emms_c() between DSP & float/double code.
28  */
29
30 #ifndef AVCODEC_DSPUTIL_H
31 #define AVCODEC_DSPUTIL_H
32
33 #include "avcodec.h"
34
35 extern uint32_t ff_square_tab[512];
36
37 void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
38               int dxx, int dxy, int dyx, int dyy, int shift, int r,
39               int width, int height);
40
41 /* minimum alignment rules ;)
42  * If you notice errors in the align stuff, need more alignment for some ASM code
43  * for some CPU or need to use a function with less aligned data then send a mail
44  * to the ffmpeg-devel mailing list, ...
45  *
46  * !warning These alignments might not match reality, (missing attribute((align))
47  * stuff somewhere possible).
48  * I (Michael) did not check them, these are just the alignments which I think
49  * could be reached easily ...
50  *
51  * !future video codecs might need functions with less strict alignment
52  */
53
54 /* add and put pixel (decoding)
55  * Block sizes for op_pixels_func are 8x4,8x8 16x8 16x16.
56  * h for op_pixels_func is limited to { width / 2, width },
57  * but never larger than 16 and never smaller than 4. */
58 typedef void (*op_fill_func)(uint8_t *block /* align width (8 or 16) */,
59                              uint8_t value, int line_size, int h);
60
61 struct MpegEncContext;
62 /* Motion estimation:
63  * h is limited to { width / 2, width, 2 * width },
64  * but never larger than 16 and never smaller than 2.
65  * Although currently h < 4 is not used as functions with
66  * width < 8 are neither used nor implemented. */
67 typedef int (*me_cmp_func)(struct MpegEncContext *c,
68                            uint8_t *blk1 /* align width (8 or 16) */,
69                            uint8_t *blk2 /* align 1 */, int line_size, int h);
70
71 /**
72  * Scantable.
73  */
74 typedef struct ScanTable {
75     const uint8_t *scantable;
76     uint8_t permutated[64];
77     uint8_t raster_end[64];
78 } ScanTable;
79
80 void ff_init_scantable(uint8_t *permutation, ScanTable *st,
81                        const uint8_t *src_scantable);
82 void ff_init_scantable_permutation(uint8_t *idct_permutation,
83                                    int idct_permutation_type);
84
85 /**
86  * DSPContext.
87  */
88 typedef struct DSPContext {
89     /* pixel ops : interface with DCT */
90     void (*get_pixels)(int16_t *block /* align 16 */,
91                        const uint8_t *pixels /* align 8 */,
92                        int line_size);
93     void (*diff_pixels)(int16_t *block /* align 16 */,
94                         const uint8_t *s1 /* align 8 */,
95                         const uint8_t *s2 /* align 8 */,
96                         int stride);
97     void (*put_pixels_clamped)(const int16_t *block /* align 16 */,
98                                uint8_t *pixels /* align 8 */,
99                                int line_size);
100     void (*put_signed_pixels_clamped)(const int16_t *block /* align 16 */,
101                                       uint8_t *pixels /* align 8 */,
102                                       int line_size);
103     void (*add_pixels_clamped)(const int16_t *block /* align 16 */,
104                                uint8_t *pixels /* align 8 */,
105                                int line_size);
106     int (*sum_abs_dctelem)(int16_t *block /* align 16 */);
107     /**
108      * translational global motion compensation.
109      */
110     void (*gmc1)(uint8_t *dst /* align 8 */, uint8_t *src /* align 1 */,
111                  int srcStride, int h, int x16, int y16, int rounder);
112     /**
113      * global motion compensation.
114      */
115     void (*gmc)(uint8_t *dst /* align 8 */, uint8_t *src /* align 1 */,
116                 int stride, int h, int ox, int oy,
117                 int dxx, int dxy, int dyx, int dyy,
118                 int shift, int r, int width, int height);
119     void (*clear_block)(int16_t *block /* align 16 */);
120     void (*clear_blocks)(int16_t *blocks /* align 16 */);
121     int (*pix_sum)(uint8_t *pix, int line_size);
122     int (*pix_norm1)(uint8_t *pix, int line_size);
123
124     me_cmp_func sad[6]; /* identical to pix_absAxA except additional void * */
125     me_cmp_func sse[6];
126     me_cmp_func hadamard8_diff[6];
127     me_cmp_func dct_sad[6];
128     me_cmp_func quant_psnr[6];
129     me_cmp_func bit[6];
130     me_cmp_func rd[6];
131     me_cmp_func vsad[6];
132     me_cmp_func vsse[6];
133     me_cmp_func nsse[6];
134     me_cmp_func w53[6];
135     me_cmp_func w97[6];
136     me_cmp_func dct_max[6];
137     me_cmp_func dct264_sad[6];
138
139     me_cmp_func me_pre_cmp[6];
140     me_cmp_func me_cmp[6];
141     me_cmp_func me_sub_cmp[6];
142     me_cmp_func mb_cmp[6];
143     me_cmp_func ildct_cmp[6]; // only width 16 used
144     me_cmp_func frame_skip_cmp[6]; // only width 8 used
145
146     me_cmp_func pix_abs[2][4];
147
148     void (*bswap_buf)(uint32_t *dst, const uint32_t *src, int w);
149     void (*bswap16_buf)(uint16_t *dst, const uint16_t *src, int len);
150
151     /* assume len is a multiple of 8, and arrays are 16-byte aligned */
152     void (*vector_clipf)(float *dst /* align 16 */,
153                          const float *src /* align 16 */,
154                          float min, float max, int len /* align 16 */);
155
156     /* (I)DCT */
157     void (*fdct)(int16_t *block /* align 16 */);
158     void (*fdct248)(int16_t *block /* align 16 */);
159
160     /* IDCT really */
161     void (*idct)(int16_t *block /* align 16 */);
162
163     /**
164      * block -> idct -> clip to unsigned 8 bit -> dest.
165      * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
166      * @param line_size size in bytes of a horizontal line of dest
167      */
168     void (*idct_put)(uint8_t *dest /* align 8 */,
169                      int line_size, int16_t *block /* align 16 */);
170
171     /**
172      * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
173      * @param line_size size in bytes of a horizontal line of dest
174      */
175     void (*idct_add)(uint8_t *dest /* align 8 */,
176                      int line_size, int16_t *block /* align 16 */);
177
178     /**
179      * IDCT input permutation.
180      * Several optimized IDCTs need a permutated input (relative to the
181      * normal order of the reference IDCT).
182      * This permutation must be performed before the idct_put/add.
183      * Note, normally this can be merged with the zigzag/alternate scan<br>
184      * An example to avoid confusion:
185      * - (->decode coeffs -> zigzag reorder -> dequant -> reference IDCT -> ...)
186      * - (x -> reference DCT -> reference IDCT -> x)
187      * - (x -> reference DCT -> simple_mmx_perm = idct_permutation
188      *    -> simple_idct_mmx -> x)
189      * - (-> decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant
190      *    -> simple_idct_mmx -> ...)
191      */
192     uint8_t idct_permutation[64];
193     int idct_permutation_type;
194 #define FF_NO_IDCT_PERM 1
195 #define FF_LIBMPEG2_IDCT_PERM 2
196 #define FF_SIMPLE_IDCT_PERM 3
197 #define FF_TRANSPOSE_IDCT_PERM 4
198 #define FF_PARTTRANS_IDCT_PERM 5
199 #define FF_SSE2_IDCT_PERM 6
200
201     int (*try_8x8basis)(int16_t rem[64], int16_t weight[64],
202                         int16_t basis[64], int scale);
203     void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
204 #define BASIS_SHIFT 16
205 #define RECON_SHIFT 6
206
207     void (*draw_edges)(uint8_t *buf, int wrap, int width, int height,
208                        int w, int h, int sides);
209 #define EDGE_WIDTH 16
210 #define EDGE_TOP    1
211 #define EDGE_BOTTOM 2
212
213     void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src,
214                       int src_wrap, int width, int height);
215
216     /**
217      * Calculate scalar product of two vectors.
218      * @param len length of vectors, should be multiple of 16
219      */
220     int32_t (*scalarproduct_int16)(const int16_t *v1,
221                                    const int16_t *v2 /* align 16 */, int len);
222
223     /**
224      * Clip each element in an array of int32_t to a given minimum and
225      * maximum value.
226      * @param dst  destination array
227      *             constraints: 16-byte aligned
228      * @param src  source array
229      *             constraints: 16-byte aligned
230      * @param min  minimum value
231      *             constraints: must be in the range [-(1 << 24), 1 << 24]
232      * @param max  maximum value
233      *             constraints: must be in the range [-(1 << 24), 1 << 24]
234      * @param len  number of elements in the array
235      *             constraints: multiple of 32 greater than zero
236      */
237     void (*vector_clip_int32)(int32_t *dst, const int32_t *src, int32_t min,
238                               int32_t max, unsigned int len);
239
240     op_fill_func fill_block_tab[2];
241 } DSPContext;
242
243 void ff_dsputil_static_init(void);
244 void ff_dsputil_init(DSPContext *p, AVCodecContext *avctx);
245 void avpriv_dsputil_init(DSPContext* p, AVCodecContext *avctx);
246 attribute_deprecated void dsputil_init(DSPContext* c, AVCodecContext *avctx);
247
248 int ff_check_alignment(void);
249
250 void ff_set_cmp(DSPContext *c, me_cmp_func *cmp, int type);
251
252 void ff_dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx);
253 void ff_dsputil_init_arm(DSPContext *c, AVCodecContext *avctx,
254                          unsigned high_bit_depth);
255 void ff_dsputil_init_bfin(DSPContext *c, AVCodecContext *avctx,
256                           unsigned high_bit_depth);
257 void ff_dsputil_init_ppc(DSPContext *c, AVCodecContext *avctx,
258                          unsigned high_bit_depth);
259 void ff_dsputil_init_x86(DSPContext *c, AVCodecContext *avctx,
260                          unsigned high_bit_depth);
261
262 void ff_dsputil_init_dwt(DSPContext *c);
263
264 #endif /* AVCODEC_DSPUTIL_H */