3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
6 * This file is part of Libav.
8 * Libav 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 * Libav 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 Libav; 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 struct MpegEncContext;
39 * h is limited to { width / 2, width, 2 * width },
40 * but never larger than 16 and never smaller than 2.
41 * Although currently h < 4 is not used as functions with
42 * width < 8 are neither used nor implemented. */
43 typedef int (*me_cmp_func)(struct MpegEncContext *c,
44 uint8_t *blk1 /* align width (8 or 16) */,
45 uint8_t *blk2 /* align 1 */, int line_size, int h);
50 typedef struct ScanTable {
51 const uint8_t *scantable;
52 uint8_t permutated[64];
53 uint8_t raster_end[64];
56 void ff_init_scantable(uint8_t *permutation, ScanTable *st,
57 const uint8_t *src_scantable);
58 void ff_init_scantable_permutation(uint8_t *idct_permutation,
59 int idct_permutation_type);
64 typedef struct DSPContext {
65 /* pixel ops : interface with DCT */
66 void (*get_pixels)(int16_t *block /* align 16 */,
67 const uint8_t *pixels /* align 8 */,
69 void (*diff_pixels)(int16_t *block /* align 16 */,
70 const uint8_t *s1 /* align 8 */,
71 const uint8_t *s2 /* align 8 */,
73 void (*put_pixels_clamped)(const int16_t *block /* align 16 */,
74 uint8_t *pixels /* align 8 */,
76 void (*put_signed_pixels_clamped)(const int16_t *block /* align 16 */,
77 uint8_t *pixels /* align 8 */,
79 void (*add_pixels_clamped)(const int16_t *block /* align 16 */,
80 uint8_t *pixels /* align 8 */,
82 int (*sum_abs_dctelem)(int16_t *block /* align 16 */);
84 int (*pix_sum)(uint8_t *pix, int line_size);
85 int (*pix_norm1)(uint8_t *pix, int line_size);
87 me_cmp_func sad[6]; /* identical to pix_absAxA except additional void * */
89 me_cmp_func hadamard8_diff[6];
90 me_cmp_func dct_sad[6];
91 me_cmp_func quant_psnr[6];
97 me_cmp_func dct_max[6];
98 me_cmp_func dct264_sad[6];
100 me_cmp_func me_pre_cmp[6];
101 me_cmp_func me_cmp[6];
102 me_cmp_func me_sub_cmp[6];
103 me_cmp_func mb_cmp[6];
104 me_cmp_func ildct_cmp[6]; // only width 16 used
105 me_cmp_func frame_skip_cmp[6]; // only width 8 used
107 me_cmp_func pix_abs[2][4];
110 void (*fdct)(int16_t *block /* align 16 */);
111 void (*fdct248)(int16_t *block /* align 16 */);
114 void (*idct)(int16_t *block /* align 16 */);
117 * block -> idct -> clip to unsigned 8 bit -> dest.
118 * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
119 * @param line_size size in bytes of a horizontal line of dest
121 void (*idct_put)(uint8_t *dest /* align 8 */,
122 int line_size, int16_t *block /* align 16 */);
125 * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
126 * @param line_size size in bytes of a horizontal line of dest
128 void (*idct_add)(uint8_t *dest /* align 8 */,
129 int line_size, int16_t *block /* align 16 */);
132 * IDCT input permutation.
133 * Several optimized IDCTs need a permutated input (relative to the
134 * normal order of the reference IDCT).
135 * This permutation must be performed before the idct_put/add.
136 * Note, normally this can be merged with the zigzag/alternate scan<br>
137 * An example to avoid confusion:
138 * - (->decode coeffs -> zigzag reorder -> dequant -> reference IDCT -> ...)
139 * - (x -> reference DCT -> reference IDCT -> x)
140 * - (x -> reference DCT -> simple_mmx_perm = idct_permutation
141 * -> simple_idct_mmx -> x)
142 * - (-> decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant
143 * -> simple_idct_mmx -> ...)
145 uint8_t idct_permutation[64];
146 int idct_permutation_type;
147 #define FF_NO_IDCT_PERM 1
148 #define FF_LIBMPEG2_IDCT_PERM 2
149 #define FF_SIMPLE_IDCT_PERM 3
150 #define FF_TRANSPOSE_IDCT_PERM 4
151 #define FF_PARTTRANS_IDCT_PERM 5
152 #define FF_SSE2_IDCT_PERM 6
154 int (*try_8x8basis)(int16_t rem[64], int16_t weight[64],
155 int16_t basis[64], int scale);
156 void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
157 #define BASIS_SHIFT 16
158 #define RECON_SHIFT 6
160 void (*draw_edges)(uint8_t *buf, int wrap, int width, int height,
161 int w, int h, int sides);
162 #define EDGE_WIDTH 16
164 #define EDGE_BOTTOM 2
166 void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src,
167 int src_wrap, int width, int height);
170 void ff_dsputil_static_init(void);
171 void ff_dsputil_init(DSPContext *p, AVCodecContext *avctx);
173 void ff_set_cmp(DSPContext *c, me_cmp_func *cmp, int type);
175 void ff_dsputil_init_arm(DSPContext *c, AVCodecContext *avctx,
176 unsigned high_bit_depth);
177 void ff_dsputil_init_ppc(DSPContext *c, AVCodecContext *avctx,
178 unsigned high_bit_depth);
179 void ff_dsputil_init_x86(DSPContext *c, AVCodecContext *avctx,
180 unsigned high_bit_depth);
182 #endif /* AVCODEC_DSPUTIL_H */