2 * This file is part of Libav.
4 * Libav 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 * Libav 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 Libav; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "libavutil/attributes.h"
21 #include "libavutil/common.h"
26 #include "simple_idct.h"
28 av_cold void ff_init_scantable(uint8_t *permutation, ScanTable *st,
29 const uint8_t *src_scantable)
33 st->scantable = src_scantable;
35 for (i = 0; i < 64; i++) {
36 int j = src_scantable[i];
37 st->permutated[i] = permutation[j];
41 for (i = 0; i < 64; i++) {
42 int j = st->permutated[i];
45 st->raster_end[i] = end;
49 av_cold void ff_init_scantable_permutation(uint8_t *idct_permutation,
50 enum idct_permutation_type perm_type)
55 if (ff_init_scantable_permutation_x86(idct_permutation,
60 case FF_IDCT_PERM_NONE:
61 for (i = 0; i < 64; i++)
62 idct_permutation[i] = i;
64 case FF_IDCT_PERM_LIBMPEG2:
65 for (i = 0; i < 64; i++)
66 idct_permutation[i] = (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
68 case FF_IDCT_PERM_TRANSPOSE:
69 for (i = 0; i < 64; i++)
70 idct_permutation[i] = ((i & 7) << 3) | (i >> 3);
72 case FF_IDCT_PERM_PARTTRANS:
73 for (i = 0; i < 64; i++)
74 idct_permutation[i] = (i & 0x24) | ((i & 3) << 3) | ((i >> 3) & 3);
77 av_log(NULL, AV_LOG_ERROR,
78 "Internal error, IDCT permutation not set\n");
82 static void put_pixels_clamped_c(const int16_t *block, uint8_t *restrict pixels,
88 for (i = 0; i < 8; i++) {
89 pixels[0] = av_clip_uint8(block[0]);
90 pixels[1] = av_clip_uint8(block[1]);
91 pixels[2] = av_clip_uint8(block[2]);
92 pixels[3] = av_clip_uint8(block[3]);
93 pixels[4] = av_clip_uint8(block[4]);
94 pixels[5] = av_clip_uint8(block[5]);
95 pixels[6] = av_clip_uint8(block[6]);
96 pixels[7] = av_clip_uint8(block[7]);
103 static void put_signed_pixels_clamped_c(const int16_t *block,
104 uint8_t *restrict pixels,
109 for (i = 0; i < 8; i++) {
110 for (j = 0; j < 8; j++) {
113 else if (*block > 127)
116 *pixels = (uint8_t) (*block + 128);
120 pixels += (line_size - 8);
124 static void add_pixels_clamped_c(const int16_t *block, uint8_t *restrict pixels,
129 /* read the pixels */
130 for (i = 0; i < 8; i++) {
131 pixels[0] = av_clip_uint8(pixels[0] + block[0]);
132 pixels[1] = av_clip_uint8(pixels[1] + block[1]);
133 pixels[2] = av_clip_uint8(pixels[2] + block[2]);
134 pixels[3] = av_clip_uint8(pixels[3] + block[3]);
135 pixels[4] = av_clip_uint8(pixels[4] + block[4]);
136 pixels[5] = av_clip_uint8(pixels[5] + block[5]);
137 pixels[6] = av_clip_uint8(pixels[6] + block[6]);
138 pixels[7] = av_clip_uint8(pixels[7] + block[7]);
144 static void jref_idct_put(uint8_t *dest, int line_size, int16_t *block)
147 put_pixels_clamped_c(block, dest, line_size);
150 static void jref_idct_add(uint8_t *dest, int line_size, int16_t *block)
153 add_pixels_clamped_c(block, dest, line_size);
156 av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
158 const unsigned high_bit_depth = avctx->bits_per_raw_sample > 8;
160 if (avctx->bits_per_raw_sample == 10) {
161 c->idct_put = ff_simple_idct_put_10;
162 c->idct_add = ff_simple_idct_add_10;
163 c->idct = ff_simple_idct_10;
164 c->perm_type = FF_IDCT_PERM_NONE;
166 if (avctx->idct_algo == FF_IDCT_INT) {
167 c->idct_put = jref_idct_put;
168 c->idct_add = jref_idct_add;
169 c->idct = ff_j_rev_dct;
170 c->perm_type = FF_IDCT_PERM_LIBMPEG2;
171 } else if (avctx->idct_algo == FF_IDCT_FAAN) {
172 c->idct_put = ff_faanidct_put;
173 c->idct_add = ff_faanidct_add;
174 c->idct = ff_faanidct;
175 c->perm_type = FF_IDCT_PERM_NONE;
176 } else { // accurate/default
177 c->idct_put = ff_simple_idct_put_8;
178 c->idct_add = ff_simple_idct_add_8;
179 c->idct = ff_simple_idct_8;
180 c->perm_type = FF_IDCT_PERM_NONE;
184 c->put_pixels_clamped = put_pixels_clamped_c;
185 c->put_signed_pixels_clamped = put_signed_pixels_clamped_c;
186 c->add_pixels_clamped = add_pixels_clamped_c;
189 ff_idctdsp_init_arm(c, avctx, high_bit_depth);
191 ff_idctdsp_init_ppc(c, avctx, high_bit_depth);
193 ff_idctdsp_init_x86(c, avctx, high_bit_depth);
195 ff_init_scantable_permutation(c->idct_permutation,