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];
38 /* minimum alignment rules ;)
39 * If you notice errors in the align stuff, need more alignment for some ASM code
40 * for some CPU or need to use a function with less aligned data then send a mail
41 * to the ffmpeg-devel mailing list, ...
43 * !warning These alignments might not match reality, (missing attribute((align))
44 * stuff somewhere possible).
45 * I (Michael) did not check them, these are just the alignments which I think
46 * could be reached easily ...
48 * !future video codecs might need functions with less strict alignment
51 struct MpegEncContext;
53 * h is limited to { width / 2, width, 2 * width },
54 * but never larger than 16 and never smaller than 2.
55 * Although currently h < 4 is not used as functions with
56 * width < 8 are neither used nor implemented. */
57 typedef int (*me_cmp_func)(struct MpegEncContext *c,
58 uint8_t *blk1 /* align width (8 or 16) */,
59 uint8_t *blk2 /* align 1 */, int line_size, int h);
64 typedef struct ScanTable {
65 const uint8_t *scantable;
66 uint8_t permutated[64];
67 uint8_t raster_end[64];
70 void ff_init_scantable(uint8_t *permutation, ScanTable *st,
71 const uint8_t *src_scantable);
72 void ff_init_scantable_permutation(uint8_t *idct_permutation,
73 int idct_permutation_type);
78 typedef struct DSPContext {
79 /* pixel ops : interface with DCT */
80 void (*get_pixels)(int16_t *block /* align 16 */,
81 const uint8_t *pixels /* align 8 */,
83 void (*diff_pixels)(int16_t *block /* align 16 */,
84 const uint8_t *s1 /* align 8 */,
85 const uint8_t *s2 /* align 8 */,
87 void (*put_pixels_clamped)(const int16_t *block /* align 16 */,
88 uint8_t *pixels /* align 8 */,
90 void (*put_signed_pixels_clamped)(const int16_t *block /* align 16 */,
91 uint8_t *pixels /* align 8 */,
93 void (*add_pixels_clamped)(const int16_t *block /* align 16 */,
94 uint8_t *pixels /* align 8 */,
96 int (*sum_abs_dctelem)(int16_t *block /* align 16 */);
98 int (*pix_sum)(uint8_t *pix, int line_size);
99 int (*pix_norm1)(uint8_t *pix, int line_size);
101 me_cmp_func sad[6]; /* identical to pix_absAxA except additional void * */
103 me_cmp_func hadamard8_diff[6];
104 me_cmp_func dct_sad[6];
105 me_cmp_func quant_psnr[6];
113 me_cmp_func dct_max[6];
114 me_cmp_func dct264_sad[6];
116 me_cmp_func me_pre_cmp[6];
117 me_cmp_func me_cmp[6];
118 me_cmp_func me_sub_cmp[6];
119 me_cmp_func mb_cmp[6];
120 me_cmp_func ildct_cmp[6]; // only width 16 used
121 me_cmp_func frame_skip_cmp[6]; // only width 8 used
123 me_cmp_func pix_abs[2][4];
126 void (*fdct)(int16_t *block /* align 16 */);
127 void (*fdct248)(int16_t *block /* align 16 */);
130 void (*idct)(int16_t *block /* align 16 */);
133 * block -> idct -> clip to unsigned 8 bit -> dest.
134 * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
135 * @param line_size size in bytes of a horizontal line of dest
137 void (*idct_put)(uint8_t *dest /* align 8 */,
138 int line_size, int16_t *block /* align 16 */);
141 * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
142 * @param line_size size in bytes of a horizontal line of dest
144 void (*idct_add)(uint8_t *dest /* align 8 */,
145 int line_size, int16_t *block /* align 16 */);
148 * IDCT input permutation.
149 * Several optimized IDCTs need a permutated input (relative to the
150 * normal order of the reference IDCT).
151 * This permutation must be performed before the idct_put/add.
152 * Note, normally this can be merged with the zigzag/alternate scan<br>
153 * An example to avoid confusion:
154 * - (->decode coeffs -> zigzag reorder -> dequant -> reference IDCT -> ...)
155 * - (x -> reference DCT -> reference IDCT -> x)
156 * - (x -> reference DCT -> simple_mmx_perm = idct_permutation
157 * -> simple_idct_mmx -> x)
158 * - (-> decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant
159 * -> simple_idct_mmx -> ...)
161 uint8_t idct_permutation[64];
162 int idct_permutation_type;
163 #define FF_NO_IDCT_PERM 1
164 #define FF_LIBMPEG2_IDCT_PERM 2
165 #define FF_SIMPLE_IDCT_PERM 3
166 #define FF_TRANSPOSE_IDCT_PERM 4
167 #define FF_PARTTRANS_IDCT_PERM 5
168 #define FF_SSE2_IDCT_PERM 6
170 int (*try_8x8basis)(int16_t rem[64], int16_t weight[64],
171 int16_t basis[64], int scale);
172 void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
173 #define BASIS_SHIFT 16
174 #define RECON_SHIFT 6
176 void (*draw_edges)(uint8_t *buf, int wrap, int width, int height,
177 int w, int h, int sides);
178 #define EDGE_WIDTH 16
180 #define EDGE_BOTTOM 2
182 void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src,
183 int src_wrap, int width, int height);
186 void ff_dsputil_static_init(void);
187 void ff_dsputil_init(DSPContext *p, AVCodecContext *avctx);
188 void avpriv_dsputil_init(DSPContext* p, AVCodecContext *avctx);
189 attribute_deprecated void dsputil_init(DSPContext* c, AVCodecContext *avctx);
191 int ff_check_alignment(void);
193 void ff_set_cmp(DSPContext *c, me_cmp_func *cmp, int type);
195 void ff_dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx);
196 void ff_dsputil_init_arm(DSPContext *c, AVCodecContext *avctx,
197 unsigned high_bit_depth);
198 void ff_dsputil_init_ppc(DSPContext *c, AVCodecContext *avctx,
199 unsigned high_bit_depth);
200 void ff_dsputil_init_x86(DSPContext *c, AVCodecContext *avctx,
201 unsigned high_bit_depth);
203 void ff_dsputil_init_dwt(DSPContext *c);
205 #endif /* AVCODEC_DSPUTIL_H */