]> git.sesse.net Git - ffmpeg/blob - libavcodec/dsputil.h
Merge commit 'c67b449bebbe0b35c73b203683e77a0a649bc765'
[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 struct MpegEncContext;
55 /* Motion estimation:
56  * h is limited to { width / 2, width, 2 * width },
57  * but never larger than 16 and never smaller than 2.
58  * Although currently h < 4 is not used as functions with
59  * width < 8 are neither used nor implemented. */
60 typedef int (*me_cmp_func)(struct MpegEncContext *c,
61                            uint8_t *blk1 /* align width (8 or 16) */,
62                            uint8_t *blk2 /* align 1 */, int line_size, int h);
63
64 /**
65  * Scantable.
66  */
67 typedef struct ScanTable {
68     const uint8_t *scantable;
69     uint8_t permutated[64];
70     uint8_t raster_end[64];
71 } ScanTable;
72
73 void ff_init_scantable(uint8_t *permutation, ScanTable *st,
74                        const uint8_t *src_scantable);
75 void ff_init_scantable_permutation(uint8_t *idct_permutation,
76                                    int idct_permutation_type);
77
78 /**
79  * DSPContext.
80  */
81 typedef struct DSPContext {
82     /* pixel ops : interface with DCT */
83     void (*get_pixels)(int16_t *block /* align 16 */,
84                        const uint8_t *pixels /* align 8 */,
85                        int line_size);
86     void (*diff_pixels)(int16_t *block /* align 16 */,
87                         const uint8_t *s1 /* align 8 */,
88                         const uint8_t *s2 /* align 8 */,
89                         int stride);
90     void (*put_pixels_clamped)(const int16_t *block /* align 16 */,
91                                uint8_t *pixels /* align 8 */,
92                                int line_size);
93     void (*put_signed_pixels_clamped)(const int16_t *block /* align 16 */,
94                                       uint8_t *pixels /* align 8 */,
95                                       int line_size);
96     void (*add_pixels_clamped)(const int16_t *block /* align 16 */,
97                                uint8_t *pixels /* align 8 */,
98                                int line_size);
99     int (*sum_abs_dctelem)(int16_t *block /* align 16 */);
100     /**
101      * translational global motion compensation.
102      */
103     void (*gmc1)(uint8_t *dst /* align 8 */, uint8_t *src /* align 1 */,
104                  int srcStride, int h, int x16, int y16, int rounder);
105     /**
106      * global motion compensation.
107      */
108     void (*gmc)(uint8_t *dst /* align 8 */, uint8_t *src /* align 1 */,
109                 int stride, int h, int ox, int oy,
110                 int dxx, int dxy, int dyx, int dyy,
111                 int shift, int r, int width, int height);
112
113     int (*pix_sum)(uint8_t *pix, int line_size);
114     int (*pix_norm1)(uint8_t *pix, int line_size);
115
116     me_cmp_func sad[6]; /* identical to pix_absAxA except additional void * */
117     me_cmp_func sse[6];
118     me_cmp_func hadamard8_diff[6];
119     me_cmp_func dct_sad[6];
120     me_cmp_func quant_psnr[6];
121     me_cmp_func bit[6];
122     me_cmp_func rd[6];
123     me_cmp_func vsad[6];
124     me_cmp_func vsse[6];
125     me_cmp_func nsse[6];
126     me_cmp_func w53[6];
127     me_cmp_func w97[6];
128     me_cmp_func dct_max[6];
129     me_cmp_func dct264_sad[6];
130
131     me_cmp_func me_pre_cmp[6];
132     me_cmp_func me_cmp[6];
133     me_cmp_func me_sub_cmp[6];
134     me_cmp_func mb_cmp[6];
135     me_cmp_func ildct_cmp[6]; // only width 16 used
136     me_cmp_func frame_skip_cmp[6]; // only width 8 used
137
138     me_cmp_func pix_abs[2][4];
139
140     /* (I)DCT */
141     void (*fdct)(int16_t *block /* align 16 */);
142     void (*fdct248)(int16_t *block /* align 16 */);
143
144     /* IDCT really */
145     void (*idct)(int16_t *block /* align 16 */);
146
147     /**
148      * block -> idct -> clip to unsigned 8 bit -> dest.
149      * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
150      * @param line_size size in bytes of a horizontal line of dest
151      */
152     void (*idct_put)(uint8_t *dest /* align 8 */,
153                      int line_size, int16_t *block /* align 16 */);
154
155     /**
156      * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
157      * @param line_size size in bytes of a horizontal line of dest
158      */
159     void (*idct_add)(uint8_t *dest /* align 8 */,
160                      int line_size, int16_t *block /* align 16 */);
161
162     /**
163      * IDCT input permutation.
164      * Several optimized IDCTs need a permutated input (relative to the
165      * normal order of the reference IDCT).
166      * This permutation must be performed before the idct_put/add.
167      * Note, normally this can be merged with the zigzag/alternate scan<br>
168      * An example to avoid confusion:
169      * - (->decode coeffs -> zigzag reorder -> dequant -> reference IDCT -> ...)
170      * - (x -> reference DCT -> reference IDCT -> x)
171      * - (x -> reference DCT -> simple_mmx_perm = idct_permutation
172      *    -> simple_idct_mmx -> x)
173      * - (-> decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant
174      *    -> simple_idct_mmx -> ...)
175      */
176     uint8_t idct_permutation[64];
177     int idct_permutation_type;
178 #define FF_NO_IDCT_PERM 1
179 #define FF_LIBMPEG2_IDCT_PERM 2
180 #define FF_SIMPLE_IDCT_PERM 3
181 #define FF_TRANSPOSE_IDCT_PERM 4
182 #define FF_PARTTRANS_IDCT_PERM 5
183 #define FF_SSE2_IDCT_PERM 6
184
185     int (*try_8x8basis)(int16_t rem[64], int16_t weight[64],
186                         int16_t basis[64], int scale);
187     void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
188 #define BASIS_SHIFT 16
189 #define RECON_SHIFT 6
190
191     void (*draw_edges)(uint8_t *buf, int wrap, int width, int height,
192                        int w, int h, int sides);
193 #define EDGE_WIDTH 16
194 #define EDGE_TOP    1
195 #define EDGE_BOTTOM 2
196
197     void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src,
198                       int src_wrap, int width, int height);
199 } DSPContext;
200
201 void ff_dsputil_static_init(void);
202 void ff_dsputil_init(DSPContext *p, AVCodecContext *avctx);
203 void avpriv_dsputil_init(DSPContext* p, AVCodecContext *avctx);
204 attribute_deprecated void dsputil_init(DSPContext* c, AVCodecContext *avctx);
205
206 int ff_check_alignment(void);
207
208 void ff_set_cmp(DSPContext *c, me_cmp_func *cmp, int type);
209
210 void ff_dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx);
211 void ff_dsputil_init_arm(DSPContext *c, AVCodecContext *avctx,
212                          unsigned high_bit_depth);
213 void ff_dsputil_init_ppc(DSPContext *c, AVCodecContext *avctx,
214                          unsigned high_bit_depth);
215 void ff_dsputil_init_x86(DSPContext *c, AVCodecContext *avctx,
216                          unsigned high_bit_depth);
217
218 void ff_dsputil_init_dwt(DSPContext *c);
219
220 #endif /* AVCODEC_DSPUTIL_H */