]> git.sesse.net Git - ffmpeg/blob - libavcodec/idctdsp.c
proresenc_kostya: remove unneeded parameters
[ffmpeg] / libavcodec / idctdsp.c
1 /*
2  * This file is part of FFmpeg.
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include "config.h"
20 #include "libavutil/attributes.h"
21 #include "libavutil/common.h"
22 #include "avcodec.h"
23 #include "dct.h"
24 #include "faanidct.h"
25 #include "idctdsp.h"
26 #include "simple_idct.h"
27 #include "xvididct.h"
28
29 av_cold void ff_init_scantable(uint8_t *permutation, ScanTable *st,
30                                const uint8_t *src_scantable)
31 {
32     int i, end;
33
34     st->scantable = src_scantable;
35
36     for (i = 0; i < 64; i++) {
37         int j = src_scantable[i];
38         st->permutated[i] = permutation[j];
39     }
40
41     end = -1;
42     for (i = 0; i < 64; i++) {
43         int j = st->permutated[i];
44         if (j > end)
45             end = j;
46         st->raster_end[i] = end;
47     }
48 }
49
50 av_cold void ff_init_scantable_permutation(uint8_t *idct_permutation,
51                                            enum idct_permutation_type perm_type)
52 {
53     int i;
54
55     if (ARCH_X86)
56         if (ff_init_scantable_permutation_x86(idct_permutation,
57                                               perm_type))
58             return;
59
60     switch (perm_type) {
61     case FF_IDCT_PERM_NONE:
62         for (i = 0; i < 64; i++)
63             idct_permutation[i] = i;
64         break;
65     case FF_IDCT_PERM_LIBMPEG2:
66         for (i = 0; i < 64; i++)
67             idct_permutation[i] = (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
68         break;
69     case FF_IDCT_PERM_TRANSPOSE:
70         for (i = 0; i < 64; i++)
71             idct_permutation[i] = ((i & 7) << 3) | (i >> 3);
72         break;
73     case FF_IDCT_PERM_PARTTRANS:
74         for (i = 0; i < 64; i++)
75             idct_permutation[i] = (i & 0x24) | ((i & 3) << 3) | ((i >> 3) & 3);
76         break;
77     default:
78         av_log(NULL, AV_LOG_ERROR,
79                "Internal error, IDCT permutation not set\n");
80     }
81 }
82
83 static void put_pixels_clamped4_c(const int16_t *block, uint8_t *av_restrict pixels,
84                                  int line_size)
85 {
86     int i;
87
88     /* read the pixels */
89     for(i=0;i<4;i++) {
90         pixels[0] = av_clip_uint8(block[0]);
91         pixels[1] = av_clip_uint8(block[1]);
92         pixels[2] = av_clip_uint8(block[2]);
93         pixels[3] = av_clip_uint8(block[3]);
94
95         pixels += line_size;
96         block += 8;
97     }
98 }
99
100 static void put_pixels_clamped2_c(const int16_t *block, uint8_t *av_restrict pixels,
101                                  int line_size)
102 {
103     int i;
104
105     /* read the pixels */
106     for(i=0;i<2;i++) {
107         pixels[0] = av_clip_uint8(block[0]);
108         pixels[1] = av_clip_uint8(block[1]);
109
110         pixels += line_size;
111         block += 8;
112     }
113 }
114
115 static void put_signed_pixels_clamped_c(const int16_t *block,
116                                         uint8_t *av_restrict pixels,
117                                         int line_size)
118 {
119     int i, j;
120
121     for (i = 0; i < 8; i++) {
122         for (j = 0; j < 8; j++) {
123             if (*block < -128)
124                 *pixels = 0;
125             else if (*block > 127)
126                 *pixels = 255;
127             else
128                 *pixels = (uint8_t) (*block + 128);
129             block++;
130             pixels++;
131         }
132         pixels += (line_size - 8);
133     }
134 }
135
136 static void add_pixels_clamped4_c(const int16_t *block, uint8_t *av_restrict pixels,
137                           int line_size)
138 {
139     int i;
140
141     /* read the pixels */
142     for(i=0;i<4;i++) {
143         pixels[0] = av_clip_uint8(pixels[0] + block[0]);
144         pixels[1] = av_clip_uint8(pixels[1] + block[1]);
145         pixels[2] = av_clip_uint8(pixels[2] + block[2]);
146         pixels[3] = av_clip_uint8(pixels[3] + block[3]);
147         pixels += line_size;
148         block += 8;
149     }
150 }
151
152 static void add_pixels_clamped2_c(const int16_t *block, uint8_t *av_restrict pixels,
153                           int line_size)
154 {
155     int i;
156
157     /* read the pixels */
158     for(i=0;i<2;i++) {
159         pixels[0] = av_clip_uint8(pixels[0] + block[0]);
160         pixels[1] = av_clip_uint8(pixels[1] + block[1]);
161         pixels += line_size;
162         block += 8;
163     }
164 }
165
166 static void jref_idct_put(uint8_t *dest, int line_size, int16_t *block)
167 {
168     ff_j_rev_dct(block);
169     put_pixels_clamped_c(block, dest, line_size);
170 }
171
172 static void jref_idct_add(uint8_t *dest, int line_size, int16_t *block)
173 {
174     ff_j_rev_dct(block);
175     add_pixels_clamped_c(block, dest, line_size);
176 }
177 static void ff_jref_idct4_put(uint8_t *dest, int line_size, int16_t *block)
178 {
179     ff_j_rev_dct4 (block);
180     put_pixels_clamped4_c(block, dest, line_size);
181 }
182 static void ff_jref_idct4_add(uint8_t *dest, int line_size, int16_t *block)
183 {
184     ff_j_rev_dct4 (block);
185     add_pixels_clamped4_c(block, dest, line_size);
186 }
187
188 static void ff_jref_idct2_put(uint8_t *dest, int line_size, int16_t *block)
189 {
190     ff_j_rev_dct2 (block);
191     put_pixels_clamped2_c(block, dest, line_size);
192 }
193 static void ff_jref_idct2_add(uint8_t *dest, int line_size, int16_t *block)
194 {
195     ff_j_rev_dct2 (block);
196     add_pixels_clamped2_c(block, dest, line_size);
197 }
198
199 static void ff_jref_idct1_put(uint8_t *dest, int line_size, int16_t *block)
200 {
201     dest[0] = av_clip_uint8((block[0] + 4)>>3);
202 }
203 static void ff_jref_idct1_add(uint8_t *dest, int line_size, int16_t *block)
204 {
205     dest[0] = av_clip_uint8(dest[0] + ((block[0] + 4)>>3));
206 }
207
208 av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
209 {
210     const unsigned high_bit_depth = avctx->bits_per_raw_sample > 8;
211
212     if (avctx->lowres==1) {
213         c->idct_put  = ff_jref_idct4_put;
214         c->idct_add  = ff_jref_idct4_add;
215         c->idct      = ff_j_rev_dct4;
216         c->perm_type = FF_IDCT_PERM_NONE;
217     } else if (avctx->lowres==2) {
218         c->idct_put  = ff_jref_idct2_put;
219         c->idct_add  = ff_jref_idct2_add;
220         c->idct      = ff_j_rev_dct2;
221         c->perm_type = FF_IDCT_PERM_NONE;
222     } else if (avctx->lowres==3) {
223         c->idct_put  = ff_jref_idct1_put;
224         c->idct_add  = ff_jref_idct1_add;
225         c->idct      = ff_j_rev_dct1;
226         c->perm_type = FF_IDCT_PERM_NONE;
227     } else {
228         if (avctx->bits_per_raw_sample == 10) {
229             c->idct_put              = ff_simple_idct_put_10;
230             c->idct_add              = ff_simple_idct_add_10;
231             c->idct                  = ff_simple_idct_10;
232             c->perm_type             = FF_IDCT_PERM_NONE;
233         } else if (avctx->bits_per_raw_sample == 12) {
234             c->idct_put              = ff_simple_idct_put_12;
235             c->idct_add              = ff_simple_idct_add_12;
236             c->idct                  = ff_simple_idct_12;
237             c->perm_type             = FF_IDCT_PERM_NONE;
238         } else {
239             if (avctx->idct_algo == FF_IDCT_INT) {
240                 c->idct_put  = jref_idct_put;
241                 c->idct_add  = jref_idct_add;
242                 c->idct      = ff_j_rev_dct;
243                 c->perm_type = FF_IDCT_PERM_LIBMPEG2;
244             } else if (avctx->idct_algo == FF_IDCT_FAAN) {
245                 c->idct_put  = ff_faanidct_put;
246                 c->idct_add  = ff_faanidct_add;
247                 c->idct      = ff_faanidct;
248                 c->perm_type = FF_IDCT_PERM_NONE;
249             } else { // accurate/default
250                 c->idct_put  = ff_simple_idct_put_8;
251                 c->idct_add  = ff_simple_idct_add_8;
252                 c->idct      = ff_simple_idct_8;
253                 c->perm_type = FF_IDCT_PERM_NONE;
254             }
255         }
256     }
257
258     c->put_pixels_clamped        = put_pixels_clamped_c;
259     c->put_signed_pixels_clamped = put_signed_pixels_clamped_c;
260     c->add_pixels_clamped        = add_pixels_clamped_c;
261
262     if (CONFIG_MPEG4_DECODER && avctx->idct_algo == FF_IDCT_XVID)
263         ff_xvididct_init(c, avctx);
264
265     if (ARCH_ALPHA)
266         ff_idctdsp_init_alpha(c, avctx, high_bit_depth);
267     if (ARCH_ARM)
268         ff_idctdsp_init_arm(c, avctx, high_bit_depth);
269     if (ARCH_PPC)
270         ff_idctdsp_init_ppc(c, avctx, high_bit_depth);
271     if (ARCH_X86)
272         ff_idctdsp_init_x86(c, avctx, high_bit_depth);
273
274     ff_init_scantable_permutation(c->idct_permutation,
275                                   c->perm_type);
276 }