dsputil_template.c
Go to the documentation of this file.
1 /*
2  * DSP utils
3  * Copyright (c) 2000, 2001 Fabrice Bellard
4  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5  *
6  * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
7  *
8  * This file is part of FFmpeg.
9  *
10  * FFmpeg is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * FFmpeg is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with FFmpeg; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  */
24 
25 /**
26  * @file
27  * DSP utils
28  */
29 
30 #include "bit_depth_template.c"
31 
32 #if BIT_DEPTH == 8
33 /* draw the edges of width 'w' of an image of size width, height */
34 //FIXME check that this is ok for mpeg4 interlaced
35 static void FUNCC(draw_edges)(uint8_t *p_buf, int p_wrap, int width, int height, int w, int h, int sides)
36 {
37  pixel *buf = (pixel*)p_buf;
38  int wrap = p_wrap / sizeof(pixel);
39  pixel *ptr, *last_line;
40  int i;
41 
42  /* left and right */
43  ptr = buf;
44  for(i=0;i<height;i++) {
45  memset(ptr - w, ptr[0], w);
46  memset(ptr + width, ptr[width-1], w);
47  ptr += wrap;
48  }
49 
50  /* top and bottom + corners */
51  buf -= w;
52  last_line = buf + (height - 1) * wrap;
53  if (sides & EDGE_TOP)
54  for(i = 0; i < h; i++)
55  memcpy(buf - (i + 1) * wrap, buf, (width + w + w) * sizeof(pixel)); // top
56  if (sides & EDGE_BOTTOM)
57  for (i = 0; i < h; i++)
58  memcpy(last_line + (i + 1) * wrap, last_line, (width + w + w) * sizeof(pixel)); // bottom
59 }
60 #endif
61 
62 static void FUNCC(get_pixels)(int16_t *av_restrict block,
63  const uint8_t *_pixels,
64  int line_size)
65 {
66  const pixel *pixels = (const pixel *) _pixels;
67  int i;
68 
69  /* read the pixels */
70  for(i=0;i<8;i++) {
71  block[0] = pixels[0];
72  block[1] = pixels[1];
73  block[2] = pixels[2];
74  block[3] = pixels[3];
75  block[4] = pixels[4];
76  block[5] = pixels[5];
77  block[6] = pixels[6];
78  block[7] = pixels[7];
79  pixels += line_size / sizeof(pixel);
80  block += 8;
81  }
82 }
83 
84 #if BIT_DEPTH == 8
85 static void FUNCC(clear_block)(int16_t *block)
86 {
87  memset(block, 0, sizeof(int16_t)*64);
88 }
89 
90 static void FUNCC(clear_blocks)(int16_t *blocks)
91 {
92  memset(blocks, 0, sizeof(int16_t)*6*64);
93 }
94 #endif
95 
96 #if BIT_DEPTH == 8
97 #include "hpel_template.c"
98 #endif
99 
100 #define PIXOP2(OPNAME, OP) \
101 static inline void FUNC(OPNAME ## _no_rnd_pixels8_l2)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
102  int src_stride1, int src_stride2, int h){\
103  int i;\
104  for(i=0; i<h; i++){\
105  pixel4 a,b;\
106  a= AV_RN4P(&src1[i*src_stride1 ]);\
107  b= AV_RN4P(&src2[i*src_stride2 ]);\
108  OP(*((pixel4*)&dst[i*dst_stride ]), no_rnd_avg_pixel4(a, b));\
109  a= AV_RN4P(&src1[i*src_stride1+4*sizeof(pixel)]);\
110  b= AV_RN4P(&src2[i*src_stride2+4*sizeof(pixel)]);\
111  OP(*((pixel4*)&dst[i*dst_stride+4*sizeof(pixel)]), no_rnd_avg_pixel4(a, b));\
112  }\
113 }\
114 \
115 static inline void FUNC(OPNAME ## _no_rnd_pixels16_l2)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
116  int src_stride1, int src_stride2, int h){\
117  FUNC(OPNAME ## _no_rnd_pixels8_l2)(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
118  FUNC(OPNAME ## _no_rnd_pixels8_l2)(dst+8*sizeof(pixel), src1+8*sizeof(pixel), src2+8*sizeof(pixel), dst_stride, src_stride1, src_stride2, h);\
119 }\
120 \
121 static inline void FUNC(OPNAME ## _pixels8_l4)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, const uint8_t *src4,\
122  int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
123  /* FIXME HIGH BIT DEPTH */\
124  int i;\
125  for(i=0; i<h; i++){\
126  uint32_t a, b, c, d, l0, l1, h0, h1;\
127  a= AV_RN32(&src1[i*src_stride1]);\
128  b= AV_RN32(&src2[i*src_stride2]);\
129  c= AV_RN32(&src3[i*src_stride3]);\
130  d= AV_RN32(&src4[i*src_stride4]);\
131  l0= (a&0x03030303UL)\
132  + (b&0x03030303UL)\
133  + 0x02020202UL;\
134  h0= ((a&0xFCFCFCFCUL)>>2)\
135  + ((b&0xFCFCFCFCUL)>>2);\
136  l1= (c&0x03030303UL)\
137  + (d&0x03030303UL);\
138  h1= ((c&0xFCFCFCFCUL)>>2)\
139  + ((d&0xFCFCFCFCUL)>>2);\
140  OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
141  a= AV_RN32(&src1[i*src_stride1+4]);\
142  b= AV_RN32(&src2[i*src_stride2+4]);\
143  c= AV_RN32(&src3[i*src_stride3+4]);\
144  d= AV_RN32(&src4[i*src_stride4+4]);\
145  l0= (a&0x03030303UL)\
146  + (b&0x03030303UL)\
147  + 0x02020202UL;\
148  h0= ((a&0xFCFCFCFCUL)>>2)\
149  + ((b&0xFCFCFCFCUL)>>2);\
150  l1= (c&0x03030303UL)\
151  + (d&0x03030303UL);\
152  h1= ((c&0xFCFCFCFCUL)>>2)\
153  + ((d&0xFCFCFCFCUL)>>2);\
154  OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
155  }\
156 }\
157 \
158 static inline void FUNC(OPNAME ## _no_rnd_pixels8_l4)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, const uint8_t *src4,\
159  int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
160  /* FIXME HIGH BIT DEPTH*/\
161  int i;\
162  for(i=0; i<h; i++){\
163  uint32_t a, b, c, d, l0, l1, h0, h1;\
164  a= AV_RN32(&src1[i*src_stride1]);\
165  b= AV_RN32(&src2[i*src_stride2]);\
166  c= AV_RN32(&src3[i*src_stride3]);\
167  d= AV_RN32(&src4[i*src_stride4]);\
168  l0= (a&0x03030303UL)\
169  + (b&0x03030303UL)\
170  + 0x01010101UL;\
171  h0= ((a&0xFCFCFCFCUL)>>2)\
172  + ((b&0xFCFCFCFCUL)>>2);\
173  l1= (c&0x03030303UL)\
174  + (d&0x03030303UL);\
175  h1= ((c&0xFCFCFCFCUL)>>2)\
176  + ((d&0xFCFCFCFCUL)>>2);\
177  OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
178  a= AV_RN32(&src1[i*src_stride1+4]);\
179  b= AV_RN32(&src2[i*src_stride2+4]);\
180  c= AV_RN32(&src3[i*src_stride3+4]);\
181  d= AV_RN32(&src4[i*src_stride4+4]);\
182  l0= (a&0x03030303UL)\
183  + (b&0x03030303UL)\
184  + 0x01010101UL;\
185  h0= ((a&0xFCFCFCFCUL)>>2)\
186  + ((b&0xFCFCFCFCUL)>>2);\
187  l1= (c&0x03030303UL)\
188  + (d&0x03030303UL);\
189  h1= ((c&0xFCFCFCFCUL)>>2)\
190  + ((d&0xFCFCFCFCUL)>>2);\
191  OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
192  }\
193 }\
194 static inline void FUNC(OPNAME ## _pixels16_l4)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, const uint8_t *src4,\
195  int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
196  FUNC(OPNAME ## _pixels8_l4)(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
197  FUNC(OPNAME ## _pixels8_l4)(dst+8*sizeof(pixel), src1+8*sizeof(pixel), src2+8*sizeof(pixel), src3+8*sizeof(pixel), src4+8*sizeof(pixel), dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
198 }\
199 static inline void FUNC(OPNAME ## _no_rnd_pixels16_l4)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, const uint8_t *src4,\
200  int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
201  FUNC(OPNAME ## _no_rnd_pixels8_l4)(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
202  FUNC(OPNAME ## _no_rnd_pixels8_l4)(dst+8*sizeof(pixel), src1+8*sizeof(pixel), src2+8*sizeof(pixel), src3+8*sizeof(pixel), src4+8*sizeof(pixel), dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
203 }\
204 \
205 static inline void FUNCC(OPNAME ## _pixels8_xy2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)\
206 {\
207  /* FIXME HIGH BIT DEPTH */\
208  int j;\
209  for(j=0; j<2; j++){\
210  int i;\
211  const uint32_t a= AV_RN32(pixels );\
212  const uint32_t b= AV_RN32(pixels+1);\
213  uint32_t l0= (a&0x03030303UL)\
214  + (b&0x03030303UL)\
215  + 0x02020202UL;\
216  uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
217  + ((b&0xFCFCFCFCUL)>>2);\
218  uint32_t l1,h1;\
219 \
220  pixels+=line_size;\
221  for(i=0; i<h; i+=2){\
222  uint32_t a= AV_RN32(pixels );\
223  uint32_t b= AV_RN32(pixels+1);\
224  l1= (a&0x03030303UL)\
225  + (b&0x03030303UL);\
226  h1= ((a&0xFCFCFCFCUL)>>2)\
227  + ((b&0xFCFCFCFCUL)>>2);\
228  OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
229  pixels+=line_size;\
230  block +=line_size;\
231  a= AV_RN32(pixels );\
232  b= AV_RN32(pixels+1);\
233  l0= (a&0x03030303UL)\
234  + (b&0x03030303UL)\
235  + 0x02020202UL;\
236  h0= ((a&0xFCFCFCFCUL)>>2)\
237  + ((b&0xFCFCFCFCUL)>>2);\
238  OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
239  pixels+=line_size;\
240  block +=line_size;\
241  }\
242  pixels+=4-line_size*(h+1);\
243  block +=4-line_size*h;\
244  }\
245 }\
246 \
247 CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_xy2), FUNCC(OPNAME ## _pixels8_xy2), 8*sizeof(pixel))\
248 
249 #define op_avg(a, b) a = rnd_avg_pixel4(a, b)
250 #define op_put(a, b) a = b
251 #if BIT_DEPTH == 8
252 #define put_no_rnd_pixels8_8_c put_pixels8_8_c
253 PIXOP2(avg, op_avg)
254 PIXOP2(put, op_put)
255 #endif
256 #undef op_avg
257 #undef op_put
#define EDGE_TOP
Definition: dsputil.h:265
#define PIXOP2(OPNAME, OP)
#define wrap(func)
Definition: w64xmmtest.h:70
output residual component w
uint8_t
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call have add an so the codec calls ff_thread_report set AVCodecInternal allocate_progress The frames must then be freed with as it s useful too and the implementation is trivial when you re doing this Note that draw_edges() needs to be called before reporting progress.Before accessing a reference frame or its MVs
#define put(d, s)
Definition: dsputil_align.c:51
#define av_restrict
Definition: config.h:9
static void FUNCC() get_pixels(int16_t *av_restrict block, const uint8_t *_pixels, int line_size)
#define EDGE_BOTTOM
Definition: dsputil.h:266
static int width
Definition: tests/utils.c:158
void * buf
Definition: avisynth_c.h:594
BYTE int const BYTE int int int height
Definition: avisynth_c.h:713
synthesis window for stochastic i
#define op_put(a, b)
uint8_t pixel
Definition: tiny_ssim.c:40
#define avg(d, s)
Definition: dsputil_align.c:52
#define op_avg(a, b)
#define FUNCC(a)