FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
idctdsp.c
Go to the documentation of this file.
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 
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;
66  for (i = 0; i < 64; i++)
67  idct_permutation[i] = (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
68  break;
70  for (i = 0; i < 64; i++)
71  idct_permutation[i] = ((i & 7) << 3) | (i >> 3);
72  break;
74  for (i = 0; i < 64; i++)
75  idct_permutation[i] = (i & 0x24) | ((i & 3) << 3) | ((i >> 3) & 3);
76  break;
77  default:
79  "Internal error, IDCT permutation not set\n");
80  }
81 }
82 
83 void (*ff_put_pixels_clamped)(const int16_t *block, uint8_t *pixels, ptrdiff_t line_size);
84 void (*ff_add_pixels_clamped)(const int16_t *block, uint8_t *pixels, ptrdiff_t line_size);
85 
86 static void put_pixels_clamped_c(const int16_t *block, uint8_t *av_restrict pixels,
87  ptrdiff_t line_size)
88 {
89  int i;
90 
91  /* read the pixels */
92  for (i = 0; i < 8; i++) {
93  pixels[0] = av_clip_uint8(block[0]);
94  pixels[1] = av_clip_uint8(block[1]);
95  pixels[2] = av_clip_uint8(block[2]);
96  pixels[3] = av_clip_uint8(block[3]);
97  pixels[4] = av_clip_uint8(block[4]);
98  pixels[5] = av_clip_uint8(block[5]);
99  pixels[6] = av_clip_uint8(block[6]);
100  pixels[7] = av_clip_uint8(block[7]);
101 
102  pixels += line_size;
103  block += 8;
104  }
105 }
106 
107 static void put_pixels_clamped4_c(const int16_t *block, uint8_t *av_restrict pixels,
108  int line_size)
109 {
110  int i;
111 
112  /* read the pixels */
113  for(i=0;i<4;i++) {
114  pixels[0] = av_clip_uint8(block[0]);
115  pixels[1] = av_clip_uint8(block[1]);
116  pixels[2] = av_clip_uint8(block[2]);
117  pixels[3] = av_clip_uint8(block[3]);
118 
119  pixels += line_size;
120  block += 8;
121  }
122 }
123 
124 static void put_pixels_clamped2_c(const int16_t *block, uint8_t *av_restrict pixels,
125  int line_size)
126 {
127  int i;
128 
129  /* read the pixels */
130  for(i=0;i<2;i++) {
131  pixels[0] = av_clip_uint8(block[0]);
132  pixels[1] = av_clip_uint8(block[1]);
133 
134  pixels += line_size;
135  block += 8;
136  }
137 }
138 
139 static void put_signed_pixels_clamped_c(const int16_t *block,
140  uint8_t *av_restrict pixels,
141  ptrdiff_t line_size)
142 {
143  int i, j;
144 
145  for (i = 0; i < 8; i++) {
146  for (j = 0; j < 8; j++) {
147  if (*block < -128)
148  *pixels = 0;
149  else if (*block > 127)
150  *pixels = 255;
151  else
152  *pixels = (uint8_t) (*block + 128);
153  block++;
154  pixels++;
155  }
156  pixels += (line_size - 8);
157  }
158 }
159 
160 static void add_pixels_clamped_c(const int16_t *block, uint8_t *av_restrict pixels,
161  ptrdiff_t line_size)
162 {
163  int i;
164 
165  /* read the pixels */
166  for (i = 0; i < 8; i++) {
167  pixels[0] = av_clip_uint8(pixels[0] + block[0]);
168  pixels[1] = av_clip_uint8(pixels[1] + block[1]);
169  pixels[2] = av_clip_uint8(pixels[2] + block[2]);
170  pixels[3] = av_clip_uint8(pixels[3] + block[3]);
171  pixels[4] = av_clip_uint8(pixels[4] + block[4]);
172  pixels[5] = av_clip_uint8(pixels[5] + block[5]);
173  pixels[6] = av_clip_uint8(pixels[6] + block[6]);
174  pixels[7] = av_clip_uint8(pixels[7] + block[7]);
175  pixels += line_size;
176  block += 8;
177  }
178 }
179 
180 static void add_pixels_clamped4_c(const int16_t *block, uint8_t *av_restrict pixels,
181  int line_size)
182 {
183  int i;
184 
185  /* read the pixels */
186  for(i=0;i<4;i++) {
187  pixels[0] = av_clip_uint8(pixels[0] + block[0]);
188  pixels[1] = av_clip_uint8(pixels[1] + block[1]);
189  pixels[2] = av_clip_uint8(pixels[2] + block[2]);
190  pixels[3] = av_clip_uint8(pixels[3] + block[3]);
191  pixels += line_size;
192  block += 8;
193  }
194 }
195 
196 static void add_pixels_clamped2_c(const int16_t *block, uint8_t *av_restrict pixels,
197  int line_size)
198 {
199  int i;
200 
201  /* read the pixels */
202  for(i=0;i<2;i++) {
203  pixels[0] = av_clip_uint8(pixels[0] + block[0]);
204  pixels[1] = av_clip_uint8(pixels[1] + block[1]);
205  pixels += line_size;
206  block += 8;
207  }
208 }
209 
210 static void ff_jref_idct4_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
211 {
212  ff_j_rev_dct4 (block);
213  put_pixels_clamped4_c(block, dest, line_size);
214 }
215 static void ff_jref_idct4_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
216 {
217  ff_j_rev_dct4 (block);
218  add_pixels_clamped4_c(block, dest, line_size);
219 }
220 
221 static void ff_jref_idct2_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
222 {
223  ff_j_rev_dct2 (block);
224  put_pixels_clamped2_c(block, dest, line_size);
225 }
226 static void ff_jref_idct2_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
227 {
228  ff_j_rev_dct2 (block);
229  add_pixels_clamped2_c(block, dest, line_size);
230 }
231 
232 static void ff_jref_idct1_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
233 {
234  dest[0] = av_clip_uint8((block[0] + 4)>>3);
235 }
236 static void ff_jref_idct1_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
237 {
238  dest[0] = av_clip_uint8(dest[0] + ((block[0] + 4)>>3));
239 }
240 
242 {
243  const unsigned high_bit_depth = avctx->bits_per_raw_sample > 8;
244 
245  if (avctx->lowres==1) {
248  c->idct = ff_j_rev_dct4;
250  } else if (avctx->lowres==2) {
253  c->idct = ff_j_rev_dct2;
255  } else if (avctx->lowres==3) {
258  c->idct = ff_j_rev_dct1;
260  } else {
261  if (avctx->bits_per_raw_sample == 10 || avctx->bits_per_raw_sample == 9) {
264  c->idct = ff_simple_idct_10;
266  } else if (avctx->bits_per_raw_sample == 12) {
269  c->idct = ff_simple_idct_12;
271  } else {
272  if (avctx->idct_algo == FF_IDCT_INT) {
275  c->idct = ff_j_rev_dct;
277 #if CONFIG_FAANIDCT
278  } else if (avctx->idct_algo == FF_IDCT_FAAN) {
281  c->idct = ff_faanidct;
283 #endif /* CONFIG_FAANIDCT */
284  } else { // accurate/default
287  c->idct = ff_simple_idct_8;
289  }
290  }
291  }
292 
296 
297  if (CONFIG_MPEG4_DECODER && avctx->idct_algo == FF_IDCT_XVID)
298  ff_xvid_idct_init(c, avctx);
299 
300  if (ARCH_AARCH64)
301  ff_idctdsp_init_aarch64(c, avctx, high_bit_depth);
302  if (ARCH_ALPHA)
303  ff_idctdsp_init_alpha(c, avctx, high_bit_depth);
304  if (ARCH_ARM)
305  ff_idctdsp_init_arm(c, avctx, high_bit_depth);
306  if (ARCH_PPC)
307  ff_idctdsp_init_ppc(c, avctx, high_bit_depth);
308  if (ARCH_X86)
309  ff_idctdsp_init_x86(c, avctx, high_bit_depth);
310  if (ARCH_MIPS)
311  ff_idctdsp_init_mips(c, avctx, high_bit_depth);
312 
315 
317  c->perm_type);
318 }
void ff_idctdsp_init_x86(IDCTDSPContext *c, AVCodecContext *avctx, unsigned high_bit_depth)
Definition: idctdsp_init.c:61
int ff_init_scantable_permutation_x86(uint8_t *idct_permutation, enum idct_permutation_type perm_type)
Definition: idctdsp_init.c:42
idct_permutation_type
Definition: idctdsp.h:37
#define NULL
Definition: coverity.c:32
void(* ff_put_pixels_clamped)(const int16_t *block, uint8_t *pixels, ptrdiff_t line_size)
Definition: idctdsp.c:83
static void put_pixels_clamped4_c(const int16_t *block, uint8_t *av_restrict pixels, int line_size)
Definition: idctdsp.c:107
void ff_j_rev_dct4(int16_t *data)
void ff_simple_idct_add_12(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
void ff_faanidct_put(uint8_t *dest, ptrdiff_t line_size, int16_t block[64])
Definition: faanidct.c:154
Scantable.
Definition: idctdsp.h:31
uint8_t raster_end[64]
Definition: idctdsp.h:34
uint8_t permutated[64]
Definition: idctdsp.h:33
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:3133
Macro definitions for various function/variable attributes.
static void add_pixels_clamped4_c(const int16_t *block, uint8_t *av_restrict pixels, int line_size)
Definition: idctdsp.c:180
av_cold void ff_idctdsp_init_ppc(IDCTDSPContext *c, AVCodecContext *avctx, unsigned high_bit_depth)
Definition: idctdsp.c:256
static int16_t block[64]
Definition: dct.c:115
uint8_t
#define av_cold
Definition: attributes.h:82
#define FF_IDCT_INT
Definition: avcodec.h:3093
void ff_faanidct(int16_t block[64])
Definition: faanidct.c:127
void(* add_pixels_clamped)(const int16_t *block, uint8_t *av_restrict pixels, ptrdiff_t line_size)
Definition: idctdsp.h:61
void(* ff_add_pixels_clamped)(const int16_t *block, uint8_t *pixels, ptrdiff_t line_size)
Definition: idctdsp.c:84
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
static void ff_jref_idct2_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
Definition: idctdsp.c:226
static void put_signed_pixels_clamped_c(const int16_t *block, uint8_t *av_restrict pixels, ptrdiff_t line_size)
Definition: idctdsp.c:139
const uint8_t * scantable
Definition: idctdsp.h:32
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
Definition: avcodec.h:3141
#define av_log(a,...)
void(* put_pixels_clamped)(const int16_t *block, uint8_t *av_restrict pixels, ptrdiff_t line_size)
Definition: idctdsp.h:55
void ff_jref_idct_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
Definition: jrevdct.c:1159
av_cold void ff_xvid_idct_init(IDCTDSPContext *c, AVCodecContext *avctx)
Definition: xvididct.c:333
#define FF_IDCT_XVID
Definition: avcodec.h:3105
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
void ff_simple_idct_put_12(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
void ff_simple_idct_add_10(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
void ff_jref_idct_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
Definition: jrevdct.c:1165
void ff_idctdsp_init_mips(IDCTDSPContext *c, AVCodecContext *avctx, unsigned high_bit_depth)
void ff_faanidct_add(uint8_t *dest, ptrdiff_t line_size, int16_t block[64])
Definition: faanidct.c:140
static void ff_jref_idct1_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
Definition: idctdsp.c:236
av_cold void ff_init_scantable_permutation(uint8_t *idct_permutation, enum idct_permutation_type perm_type)
Definition: idctdsp.c:50
av_cold void ff_idctdsp_init_alpha(IDCTDSPContext *c, AVCodecContext *avctx, unsigned high_bit_depth)
int idct_algo
IDCT algorithm, see FF_IDCT_* below.
Definition: avcodec.h:3091
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
uint8_t idct_permutation[64]
IDCT input permutation.
Definition: idctdsp.h:96
static void put_pixels_clamped2_c(const int16_t *block, uint8_t *av_restrict pixels, int line_size)
Definition: idctdsp.c:124
void ff_simple_idct_10(int16_t *block)
void ff_j_rev_dct1(int16_t *data)
void ff_j_rev_dct(int16_t *data)
static void add_pixels_clamped_c(const int16_t *block, uint8_t *av_restrict pixels, ptrdiff_t line_size)
Definition: idctdsp.c:160
Libavcodec external API header.
void ff_simple_idct_put_10(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
main external API structure.
Definition: avcodec.h:1732
void ff_simple_idct_12(int16_t *block)
static void ff_jref_idct4_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
Definition: idctdsp.c:210
void(* idct_add)(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
Definition: idctdsp.h:79
av_cold void ff_idctdsp_init_arm(IDCTDSPContext *c, AVCodecContext *avctx, unsigned high_bit_depth)
static void add_pixels_clamped2_c(const int16_t *block, uint8_t *av_restrict pixels, int line_size)
Definition: idctdsp.c:196
av_cold void ff_idctdsp_init_aarch64(IDCTDSPContext *c, AVCodecContext *avctx, unsigned high_bit_depth)
void ff_j_rev_dct2(int16_t *data)
static void ff_jref_idct4_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
Definition: idctdsp.c:215
common internal and external API header
void(* put_signed_pixels_clamped)(const int16_t *block, uint8_t *av_restrict pixels, ptrdiff_t line_size)
Definition: idctdsp.h:58
void(* idct_put)(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
block -> idct -> clip to unsigned 8 bit -> dest.
Definition: idctdsp.h:72
static double c[64]
void ff_simple_idct_add_8(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
#define FF_IDCT_FAAN
Definition: avcodec.h:3114
av_cold void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
Definition: idctdsp.c:29
int pixels
Definition: avisynth_c.h:429
av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
Definition: idctdsp.c:241
simple idct header.
void ff_simple_idct_put_8(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
static void put_pixels_clamped_c(const int16_t *block, uint8_t *av_restrict pixels, ptrdiff_t line_size)
Definition: idctdsp.c:86
static void ff_jref_idct2_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
Definition: idctdsp.c:221
static void ff_jref_idct1_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
Definition: idctdsp.c:232
void ff_simple_idct_8(int16_t *block)
enum idct_permutation_type perm_type
Definition: idctdsp.h:97
void(* idct)(int16_t *block)
Definition: idctdsp.h:65