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 void (*ff_put_pixels_clamped)(const int16_t *block, uint8_t *pixels, int line_size);
83 void (*ff_add_pixels_clamped)(const int16_t *block, uint8_t *pixels, int line_size);
85 static void put_pixels_clamped_c(const int16_t *block, uint8_t *restrict pixels,
91 for (i = 0; i < 8; i++) {
92 pixels[0] = av_clip_uint8(block[0]);
93 pixels[1] = av_clip_uint8(block[1]);
94 pixels[2] = av_clip_uint8(block[2]);
95 pixels[3] = av_clip_uint8(block[3]);
96 pixels[4] = av_clip_uint8(block[4]);
97 pixels[5] = av_clip_uint8(block[5]);
98 pixels[6] = av_clip_uint8(block[6]);
99 pixels[7] = av_clip_uint8(block[7]);
106 static void put_signed_pixels_clamped_c(const int16_t *block,
107 uint8_t *restrict pixels,
112 for (i = 0; i < 8; i++) {
113 for (j = 0; j < 8; j++) {
116 else if (*block > 127)
119 *pixels = (uint8_t) (*block + 128);
123 pixels += (line_size - 8);
127 static void add_pixels_clamped_c(const int16_t *block, uint8_t *restrict pixels,
132 /* read the pixels */
133 for (i = 0; i < 8; i++) {
134 pixels[0] = av_clip_uint8(pixels[0] + block[0]);
135 pixels[1] = av_clip_uint8(pixels[1] + block[1]);
136 pixels[2] = av_clip_uint8(pixels[2] + block[2]);
137 pixels[3] = av_clip_uint8(pixels[3] + block[3]);
138 pixels[4] = av_clip_uint8(pixels[4] + block[4]);
139 pixels[5] = av_clip_uint8(pixels[5] + block[5]);
140 pixels[6] = av_clip_uint8(pixels[6] + block[6]);
141 pixels[7] = av_clip_uint8(pixels[7] + block[7]);
147 av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
149 const unsigned high_bit_depth = avctx->bits_per_raw_sample > 8;
151 if (avctx->bits_per_raw_sample == 10) {
152 c->idct_put = ff_simple_idct_put_10;
153 c->idct_add = ff_simple_idct_add_10;
154 c->idct = ff_simple_idct_10;
155 c->perm_type = FF_IDCT_PERM_NONE;
156 } else if (avctx->idct_algo == FF_IDCT_INT) {
157 c->idct_put = ff_jref_idct_put;
158 c->idct_add = ff_jref_idct_add;
159 c->idct = ff_j_rev_dct;
160 c->perm_type = FF_IDCT_PERM_LIBMPEG2;
162 } else if (avctx->idct_algo == FF_IDCT_FAAN) {
163 c->idct_put = ff_faanidct_put;
164 c->idct_add = ff_faanidct_add;
165 c->idct = ff_faanidct;
166 c->perm_type = FF_IDCT_PERM_NONE;
167 #endif /* CONFIG_FAANIDCT */
168 } else { // accurate/default
169 c->idct_put = ff_simple_idct_put_8;
170 c->idct_add = ff_simple_idct_add_8;
171 c->idct = ff_simple_idct_8;
172 c->perm_type = FF_IDCT_PERM_NONE;
175 c->put_pixels_clamped = put_pixels_clamped_c;
176 c->put_signed_pixels_clamped = put_signed_pixels_clamped_c;
177 c->add_pixels_clamped = add_pixels_clamped_c;
179 ff_put_pixels_clamped = c->put_pixels_clamped;
180 ff_add_pixels_clamped = c->add_pixels_clamped;
183 ff_idctdsp_init_arm(c, avctx, high_bit_depth);
185 ff_idctdsp_init_ppc(c, avctx, high_bit_depth);
187 ff_idctdsp_init_x86(c, avctx, high_bit_depth);
189 ff_init_scantable_permutation(c->idct_permutation,