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);
60 int ff_init_scantable_permutation_x86(uint8_t *idct_permutation,
61 int idct_permutation_type);
66 typedef struct DSPContext {
67 /* pixel ops : interface with DCT */
68 void (*get_pixels)(int16_t *block /* align 16 */,
69 const uint8_t *pixels /* align 8 */,
71 void (*diff_pixels)(int16_t *block /* align 16 */,
72 const uint8_t *s1 /* align 8 */,
73 const uint8_t *s2 /* align 8 */,
75 void (*put_pixels_clamped)(const int16_t *block /* align 16 */,
76 uint8_t *pixels /* align 8 */,
78 void (*put_signed_pixels_clamped)(const int16_t *block /* align 16 */,
79 uint8_t *pixels /* align 8 */,
81 void (*add_pixels_clamped)(const int16_t *block /* align 16 */,
82 uint8_t *pixels /* align 8 */,
84 int (*sum_abs_dctelem)(int16_t *block /* align 16 */);
86 int (*pix_sum)(uint8_t *pix, int line_size);
87 int (*pix_norm1)(uint8_t *pix, int line_size);
89 me_cmp_func sad[6]; /* identical to pix_absAxA except additional void * */
91 me_cmp_func hadamard8_diff[6];
92 me_cmp_func dct_sad[6];
93 me_cmp_func quant_psnr[6];
99 me_cmp_func dct_max[6];
100 me_cmp_func dct264_sad[6];
102 me_cmp_func me_pre_cmp[6];
103 me_cmp_func me_cmp[6];
104 me_cmp_func me_sub_cmp[6];
105 me_cmp_func mb_cmp[6];
106 me_cmp_func ildct_cmp[6]; // only width 16 used
107 me_cmp_func frame_skip_cmp[6]; // only width 8 used
109 me_cmp_func pix_abs[2][4];
112 void (*fdct)(int16_t *block /* align 16 */);
113 void (*fdct248)(int16_t *block /* align 16 */);
116 void (*idct)(int16_t *block /* align 16 */);
119 * block -> idct -> clip to unsigned 8 bit -> dest.
120 * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
121 * @param line_size size in bytes of a horizontal line of dest
123 void (*idct_put)(uint8_t *dest /* align 8 */,
124 int line_size, int16_t *block /* align 16 */);
127 * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
128 * @param line_size size in bytes of a horizontal line of dest
130 void (*idct_add)(uint8_t *dest /* align 8 */,
131 int line_size, int16_t *block /* align 16 */);
134 * IDCT input permutation.
135 * Several optimized IDCTs need a permutated input (relative to the
136 * normal order of the reference IDCT).
137 * This permutation must be performed before the idct_put/add.
138 * Note, normally this can be merged with the zigzag/alternate scan<br>
139 * An example to avoid confusion:
140 * - (->decode coeffs -> zigzag reorder -> dequant -> reference IDCT -> ...)
141 * - (x -> reference DCT -> reference IDCT -> x)
142 * - (x -> reference DCT -> simple_mmx_perm = idct_permutation
143 * -> simple_idct_mmx -> x)
144 * - (-> decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant
145 * -> simple_idct_mmx -> ...)
147 uint8_t idct_permutation[64];
148 int idct_permutation_type;
149 #define FF_NO_IDCT_PERM 1
150 #define FF_LIBMPEG2_IDCT_PERM 2
151 #define FF_SIMPLE_IDCT_PERM 3
152 #define FF_TRANSPOSE_IDCT_PERM 4
153 #define FF_PARTTRANS_IDCT_PERM 5
154 #define FF_SSE2_IDCT_PERM 6
156 int (*try_8x8basis)(int16_t rem[64], int16_t weight[64],
157 int16_t basis[64], int scale);
158 void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
159 #define BASIS_SHIFT 16
160 #define RECON_SHIFT 6
162 void (*draw_edges)(uint8_t *buf, int wrap, int width, int height,
163 int w, int h, int sides);
164 #define EDGE_WIDTH 16
166 #define EDGE_BOTTOM 2
168 void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src,
169 int src_wrap, int width, int height);
172 void ff_dsputil_static_init(void);
173 void ff_dsputil_init(DSPContext *p, AVCodecContext *avctx);
175 void ff_set_cmp(DSPContext *c, me_cmp_func *cmp, int type);
177 void ff_dsputil_init_arm(DSPContext *c, AVCodecContext *avctx,
178 unsigned high_bit_depth);
179 void ff_dsputil_init_ppc(DSPContext *c, AVCodecContext *avctx,
180 unsigned high_bit_depth);
181 void ff_dsputil_init_x86(DSPContext *c, AVCodecContext *avctx,
182 unsigned high_bit_depth);
184 #endif /* AVCODEC_DSPUTIL_H */