3 * Copyright (c) 2000, 2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
6 * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
8 * This file is part of FFmpeg.
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.
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.
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
30 #include "bit_depth_template.c"
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)
37 pixel *buf = (pixel*)p_buf;
38 int wrap = p_wrap / sizeof(pixel);
39 pixel *ptr, *last_line;
44 for(i=0;i<height;i++) {
45 memset(ptr - w, ptr[0], w);
46 memset(ptr + width, ptr[width-1], w);
50 /* top and bottom + corners */
52 last_line = buf + (height - 1) * wrap;
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
62 static void FUNCC(get_pixels)(int16_t *av_restrict block,
63 const uint8_t *_pixels,
66 const pixel *pixels = (const pixel *) _pixels;
79 pixels += line_size / sizeof(pixel);
85 static void FUNCC(clear_block)(int16_t *block)
87 memset(block, 0, sizeof(int16_t)*64);
90 static void FUNCC(clear_blocks)(int16_t *blocks)
92 memset(blocks, 0, sizeof(int16_t)*6*64);
97 #include "hpel_template.c"
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){\
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));\
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);\
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 */\
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)\
134 h0= ((a&0xFCFCFCFCUL)>>2)\
135 + ((b&0xFCFCFCFCUL)>>2);\
136 l1= (c&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)\
148 h0= ((a&0xFCFCFCFCUL)>>2)\
149 + ((b&0xFCFCFCFCUL)>>2);\
150 l1= (c&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));\
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*/\
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)\
171 h0= ((a&0xFCFCFCFCUL)>>2)\
172 + ((b&0xFCFCFCFCUL)>>2);\
173 l1= (c&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)\
185 h0= ((a&0xFCFCFCFCUL)>>2)\
186 + ((b&0xFCFCFCFCUL)>>2);\
187 l1= (c&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));\
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);\
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);\
205 static inline void FUNCC(OPNAME ## _pixels8_xy2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)\
207 /* FIXME HIGH BIT DEPTH */\
211 const uint32_t a= AV_RN32(pixels );\
212 const uint32_t b= AV_RN32(pixels+1);\
213 uint32_t l0= (a&0x03030303UL)\
216 uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
217 + ((b&0xFCFCFCFCUL)>>2);\
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)\
226 h1= ((a&0xFCFCFCFCUL)>>2)\
227 + ((b&0xFCFCFCFCUL)>>2);\
228 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
231 a= AV_RN32(pixels );\
232 b= AV_RN32(pixels+1);\
233 l0= (a&0x03030303UL)\
236 h0= ((a&0xFCFCFCFCUL)>>2)\
237 + ((b&0xFCFCFCFCUL)>>2);\
238 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
242 pixels+=4-line_size*(h+1);\
243 block +=4-line_size*h;\
247 CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_xy2), FUNCC(OPNAME ## _pixels8_xy2), 8*sizeof(pixel))\
249 #define op_avg(a, b) a = rnd_avg_pixel4(a, b)
250 #define op_put(a, b) a = b
252 #define put_no_rnd_pixels8_8_c put_pixels8_8_c