2 * This file is part of FFmpeg.
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef AVCODEC_IDCTDSP_H
20 #define AVCODEC_IDCTDSP_H
29 typedef struct ScanTable {
30 const uint8_t *scantable;
31 uint8_t permutated[64];
32 uint8_t raster_end[64];
35 enum idct_permutation_type {
37 FF_IDCT_PERM_LIBMPEG2,
39 FF_IDCT_PERM_TRANSPOSE,
40 FF_IDCT_PERM_PARTTRANS,
44 void ff_init_scantable(uint8_t *permutation, ScanTable *st,
45 const uint8_t *src_scantable);
46 void ff_init_scantable_permutation(uint8_t *idct_permutation,
47 enum idct_permutation_type perm_type);
48 int ff_init_scantable_permutation_x86(uint8_t *idct_permutation,
49 enum idct_permutation_type perm_type);
51 typedef struct IDCTDSPContext {
52 /* pixel ops : interface with DCT */
53 void (*put_pixels_clamped)(const int16_t *block /* align 16 */,
54 uint8_t *pixels /* align 8 */,
56 void (*put_signed_pixels_clamped)(const int16_t *block /* align 16 */,
57 uint8_t *pixels /* align 8 */,
59 void (*add_pixels_clamped)(const int16_t *block /* align 16 */,
60 uint8_t *pixels /* align 8 */,
63 void (*idct)(int16_t *block /* align 16 */);
66 * block -> idct -> clip to unsigned 8 bit -> dest.
67 * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
68 * @param line_size size in bytes of a horizontal line of dest
70 void (*idct_put)(uint8_t *dest /* align 8 */,
71 int line_size, int16_t *block /* align 16 */);
74 * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
75 * @param line_size size in bytes of a horizontal line of dest
77 void (*idct_add)(uint8_t *dest /* align 8 */,
78 int line_size, int16_t *block /* align 16 */);
81 * IDCT input permutation.
82 * Several optimized IDCTs need a permutated input (relative to the
83 * normal order of the reference IDCT).
84 * This permutation must be performed before the idct_put/add.
85 * Note, normally this can be merged with the zigzag/alternate scan<br>
86 * An example to avoid confusion:
87 * - (->decode coeffs -> zigzag reorder -> dequant -> reference IDCT -> ...)
88 * - (x -> reference DCT -> reference IDCT -> x)
89 * - (x -> reference DCT -> simple_mmx_perm = idct_permutation
90 * -> simple_idct_mmx -> x)
91 * - (-> decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant
92 * -> simple_idct_mmx -> ...)
94 uint8_t idct_permutation[64];
95 enum idct_permutation_type perm_type;
98 void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx);
100 void ff_idctdsp_init_alpha(IDCTDSPContext *c, AVCodecContext *avctx,
101 unsigned high_bit_depth);
102 void ff_idctdsp_init_arm(IDCTDSPContext *c, AVCodecContext *avctx,
103 unsigned high_bit_depth);
104 void ff_idctdsp_init_ppc(IDCTDSPContext *c, AVCodecContext *avctx,
105 unsigned high_bit_depth);
106 void ff_idctdsp_init_x86(IDCTDSPContext *c, AVCodecContext *avctx,
107 unsigned high_bit_depth);
109 static inline void put_pixels_clamped_c(const int16_t *block, uint8_t *av_restrict pixels,
114 /* read the pixels */
115 for (i = 0; i < 8; i++) {
116 pixels[0] = av_clip_uint8(block[0]);
117 pixels[1] = av_clip_uint8(block[1]);
118 pixels[2] = av_clip_uint8(block[2]);
119 pixels[3] = av_clip_uint8(block[3]);
120 pixels[4] = av_clip_uint8(block[4]);
121 pixels[5] = av_clip_uint8(block[5]);
122 pixels[6] = av_clip_uint8(block[6]);
123 pixels[7] = av_clip_uint8(block[7]);
130 static inline void add_pixels_clamped_c(const int16_t *block, uint8_t *av_restrict pixels,
135 /* read the pixels */
136 for (i = 0; i < 8; i++) {
137 pixels[0] = av_clip_uint8(pixels[0] + block[0]);
138 pixels[1] = av_clip_uint8(pixels[1] + block[1]);
139 pixels[2] = av_clip_uint8(pixels[2] + block[2]);
140 pixels[3] = av_clip_uint8(pixels[3] + block[3]);
141 pixels[4] = av_clip_uint8(pixels[4] + block[4]);
142 pixels[5] = av_clip_uint8(pixels[5] + block[5]);
143 pixels[6] = av_clip_uint8(pixels[6] + block[6]);
144 pixels[7] = av_clip_uint8(pixels[7] + block[7]);
150 #endif /* AVCODEC_IDCTDSP_H */