3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
6 * This file is part of FFmpeg.
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.
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.
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
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.
30 #ifndef AVCODEC_DSPUTIL_H
31 #define AVCODEC_DSPUTIL_H
35 extern uint32_t ff_square_tab[512];
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);
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, ...
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 ...
51 * !future video codecs might need functions with less strict alignment
54 struct MpegEncContext;
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);
67 typedef struct ScanTable {
68 const uint8_t *scantable;
69 uint8_t permutated[64];
70 uint8_t raster_end[64];
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);
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 */,
86 void (*diff_pixels)(int16_t *block /* align 16 */,
87 const uint8_t *s1 /* align 8 */,
88 const uint8_t *s2 /* align 8 */,
90 void (*put_pixels_clamped)(const int16_t *block /* align 16 */,
91 uint8_t *pixels /* align 8 */,
93 void (*put_signed_pixels_clamped)(const int16_t *block /* align 16 */,
94 uint8_t *pixels /* align 8 */,
96 void (*add_pixels_clamped)(const int16_t *block /* align 16 */,
97 uint8_t *pixels /* align 8 */,
99 int (*sum_abs_dctelem)(int16_t *block /* align 16 */);
101 * translational global motion compensation.
103 void (*gmc1)(uint8_t *dst /* align 8 */, uint8_t *src /* align 1 */,
104 int srcStride, int h, int x16, int y16, int rounder);
106 * global motion compensation.
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);
113 int (*pix_sum)(uint8_t *pix, int line_size);
114 int (*pix_norm1)(uint8_t *pix, int line_size);
116 me_cmp_func sad[6]; /* identical to pix_absAxA except additional void * */
118 me_cmp_func hadamard8_diff[6];
119 me_cmp_func dct_sad[6];
120 me_cmp_func quant_psnr[6];
128 me_cmp_func dct_max[6];
129 me_cmp_func dct264_sad[6];
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
138 me_cmp_func pix_abs[2][4];
140 void (*bswap_buf)(uint32_t *dst, const uint32_t *src, int w);
141 void (*bswap16_buf)(uint16_t *dst, const uint16_t *src, int len);
143 /* assume len is a multiple of 8, and arrays are 16-byte aligned */
144 void (*vector_clipf)(float *dst /* align 16 */,
145 const float *src /* align 16 */,
146 float min, float max, int len /* align 16 */);
149 void (*fdct)(int16_t *block /* align 16 */);
150 void (*fdct248)(int16_t *block /* align 16 */);
153 void (*idct)(int16_t *block /* align 16 */);
156 * block -> idct -> clip to unsigned 8 bit -> dest.
157 * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
158 * @param line_size size in bytes of a horizontal line of dest
160 void (*idct_put)(uint8_t *dest /* align 8 */,
161 int line_size, int16_t *block /* align 16 */);
164 * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
165 * @param line_size size in bytes of a horizontal line of dest
167 void (*idct_add)(uint8_t *dest /* align 8 */,
168 int line_size, int16_t *block /* align 16 */);
171 * IDCT input permutation.
172 * Several optimized IDCTs need a permutated input (relative to the
173 * normal order of the reference IDCT).
174 * This permutation must be performed before the idct_put/add.
175 * Note, normally this can be merged with the zigzag/alternate scan<br>
176 * An example to avoid confusion:
177 * - (->decode coeffs -> zigzag reorder -> dequant -> reference IDCT -> ...)
178 * - (x -> reference DCT -> reference IDCT -> x)
179 * - (x -> reference DCT -> simple_mmx_perm = idct_permutation
180 * -> simple_idct_mmx -> x)
181 * - (-> decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant
182 * -> simple_idct_mmx -> ...)
184 uint8_t idct_permutation[64];
185 int idct_permutation_type;
186 #define FF_NO_IDCT_PERM 1
187 #define FF_LIBMPEG2_IDCT_PERM 2
188 #define FF_SIMPLE_IDCT_PERM 3
189 #define FF_TRANSPOSE_IDCT_PERM 4
190 #define FF_PARTTRANS_IDCT_PERM 5
191 #define FF_SSE2_IDCT_PERM 6
193 int (*try_8x8basis)(int16_t rem[64], int16_t weight[64],
194 int16_t basis[64], int scale);
195 void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
196 #define BASIS_SHIFT 16
197 #define RECON_SHIFT 6
199 void (*draw_edges)(uint8_t *buf, int wrap, int width, int height,
200 int w, int h, int sides);
201 #define EDGE_WIDTH 16
203 #define EDGE_BOTTOM 2
205 void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src,
206 int src_wrap, int width, int height);
209 * Calculate scalar product of two vectors.
210 * @param len length of vectors, should be multiple of 16
212 int32_t (*scalarproduct_int16)(const int16_t *v1,
213 const int16_t *v2 /* align 16 */, int len);
216 * Clip each element in an array of int32_t to a given minimum and
218 * @param dst destination array
219 * constraints: 16-byte aligned
220 * @param src source array
221 * constraints: 16-byte aligned
222 * @param min minimum value
223 * constraints: must be in the range [-(1 << 24), 1 << 24]
224 * @param max maximum value
225 * constraints: must be in the range [-(1 << 24), 1 << 24]
226 * @param len number of elements in the array
227 * constraints: multiple of 32 greater than zero
229 void (*vector_clip_int32)(int32_t *dst, const int32_t *src, int32_t min,
230 int32_t max, unsigned int len);
233 void ff_dsputil_static_init(void);
234 void ff_dsputil_init(DSPContext *p, AVCodecContext *avctx);
235 void avpriv_dsputil_init(DSPContext* p, AVCodecContext *avctx);
236 attribute_deprecated void dsputil_init(DSPContext* c, AVCodecContext *avctx);
238 int ff_check_alignment(void);
240 void ff_set_cmp(DSPContext *c, me_cmp_func *cmp, int type);
242 void ff_dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx);
243 void ff_dsputil_init_arm(DSPContext *c, AVCodecContext *avctx,
244 unsigned high_bit_depth);
245 void ff_dsputil_init_ppc(DSPContext *c, AVCodecContext *avctx,
246 unsigned high_bit_depth);
247 void ff_dsputil_init_x86(DSPContext *c, AVCodecContext *avctx,
248 unsigned high_bit_depth);
250 void ff_dsputil_init_dwt(DSPContext *c);
252 #endif /* AVCODEC_DSPUTIL_H */