[svn] / trunk / xvidcore / src / image / interpolate8x8.c Repository:
ViewVC logotype

Annotation of /trunk/xvidcore/src/image/interpolate8x8.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 723 - (view) (download)

1 : chl 433 /*****************************************************************************
2 : Isibaar 333 *
3 : chl 433 * XVID MPEG-4 VIDEO CODEC
4 : edgomez 651 * - 8x8 block-based halfpel interpolation -
5 : Isibaar 333 *
6 : chl 433 * Copyright(C) 2002 Peter Ross <pross@xvid.org>
7 :     * Copyright(C) 2002 MinChen <chenm002@163.com>
8 : Isibaar 333 *
9 : edgomez 651 * This file is part of XviD, a free MPEG-4 video encoder/decoder
10 : Isibaar 333 *
11 : edgomez 651 * XviD is free software; you can redistribute it and/or modify it
12 :     * under the terms of the GNU General Public License as published by
13 : chl 433 * the Free Software Foundation; either version 2 of the License, or
14 :     * (at your option) any later version.
15 : Isibaar 333 *
16 : chl 433 * This program is distributed in the hope that it will be useful,
17 :     * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 :     * GNU General Public License for more details.
20 : Isibaar 333 *
21 : chl 433 * You should have received a copy of the GNU General Public License
22 :     * along with this program; if not, write to the Free Software
23 :     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 : Isibaar 333 *
25 : edgomez 651 * Under section 8 of the GNU General Public License, the copyright
26 :     * holders of XVID explicitly forbid distribution in the following
27 :     * countries:
28 :     *
29 :     * - Japan
30 :     * - United States of America
31 :     *
32 :     * Linking XviD statically or dynamically with other modules is making a
33 :     * combined work based on XviD. Thus, the terms and conditions of the
34 :     * GNU General Public License cover the whole combination.
35 :     *
36 :     * As a special exception, the copyright holders of XviD give you
37 :     * permission to link XviD with independent modules that communicate with
38 :     * XviD solely through the VFW1.1 and DShow interfaces, regardless of the
39 :     * license terms of these independent modules, and to copy and distribute
40 :     * the resulting combined work under terms of your choice, provided that
41 :     * every copy of the combined work is accompanied by a complete copy of
42 :     * the source code of XviD (the version of XviD used to produce the
43 :     * combined work), being distributed under the terms of the GNU General
44 :     * Public License plus this exception. An independent module is a module
45 :     * which is not derived from or based on XviD.
46 :     *
47 :     * Note that people who make modified versions of XviD are not obligated
48 :     * to grant this special exception for their modified versions; it is
49 :     * their choice whether to do so. The GNU General Public License gives
50 :     * permission to release a modified version without this exception; this
51 :     * exception also makes it possible to release a modified version which
52 :     * carries forward this exception.
53 :     *
54 : edgomez 723 * $Id: interpolate8x8.c,v 1.8 2002-12-15 01:21:12 edgomez Exp $
55 : edgomez 651 *
56 : chl 433 ****************************************************************************/
57 : Isibaar 333
58 :     #include "../portab.h"
59 :     #include "interpolate8x8.h"
60 :    
61 : edgomez 677 /* function pointers */
62 : Isibaar 333 INTERPOLATE8X8_PTR interpolate8x8_halfpel_h;
63 :     INTERPOLATE8X8_PTR interpolate8x8_halfpel_v;
64 :     INTERPOLATE8X8_PTR interpolate8x8_halfpel_hv;
65 :    
66 :    
67 : edgomez 677 /* dst = interpolate(src) */
68 : Isibaar 333
69 :     void
70 :     interpolate8x8_halfpel_h_c(uint8_t * const dst,
71 :     const uint8_t * const src,
72 :     const uint32_t stride,
73 :     const uint32_t rounding)
74 :     {
75 :     uint32_t i, j;
76 :    
77 :     for (j = 0; j < 8; j++) {
78 :     for (i = 0; i < 8; i++) {
79 :    
80 : edgomez 723 int32_t tot =
81 :     (int32_t) src[j * stride + i] + (int32_t) src[j * stride + i + 1];
82 : Isibaar 333
83 : edgomez 723 tot = (tot + 1 - rounding) >> 1;
84 : Isibaar 333 dst[j * stride + i] = (uint8_t) tot;
85 :     }
86 :     }
87 :     }
88 :    
89 :    
90 :    
91 :     void
92 :     interpolate8x8_halfpel_v_c(uint8_t * const dst,
93 :     const uint8_t * const src,
94 :     const uint32_t stride,
95 :     const uint32_t rounding)
96 :     {
97 :     uint32_t i, j;
98 :    
99 :     for (j = 0; j < 8; j++) {
100 :     for (i = 0; i < 8; i++) {
101 : edgomez 723 int32_t tot =
102 :     (int32_t)src[j * stride + i] + (int32_t)src[j * stride + i + stride];
103 : Isibaar 333
104 :     tot = ((tot + 1 - rounding) >> 1);
105 :     dst[j * stride + i] = (uint8_t) tot;
106 :     }
107 :     }
108 :     }
109 :    
110 :    
111 :     void
112 :     interpolate8x8_halfpel_hv_c(uint8_t * const dst,
113 :     const uint8_t * const src,
114 :     const uint32_t stride,
115 :     const uint32_t rounding)
116 :     {
117 :     uint32_t i, j;
118 :    
119 :     for (j = 0; j < 8; j++) {
120 :     for (i = 0; i < 8; i++) {
121 : edgomez 723 int32_t tot =
122 :     (int32_t)src[j * stride + i] + (int32_t)src[j * stride + i + 1] +
123 :     (int32_t)src[j * stride + i + stride] + (int32_t)src[j * stride + i + stride + 1];
124 : Isibaar 333 tot = ((tot + 2 - rounding) >> 2);
125 :     dst[j * stride + i] = (uint8_t) tot;
126 :     }
127 :     }
128 :     }
129 :    
130 : edgomez 677 /* add by MinChen <chenm001@163.com> */
131 :     /* interpolate8x8 two pred block */
132 : Isibaar 333 void
133 :     interpolate8x8_c(uint8_t * const dst,
134 :     const uint8_t * const src,
135 :     const uint32_t x,
136 :     const uint32_t y,
137 :     const uint32_t stride)
138 :     {
139 :     uint32_t i, j;
140 :    
141 :     for (j = 0; j < 8; j++) {
142 :     for (i = 0; i < 8; i++) {
143 :     int32_t tot =
144 : edgomez 723 (((int32_t)src[(y + j) * stride + x + i] +
145 :     (int32_t)dst[(y + j) * stride + x + i] + 1) >> 1);
146 : Isibaar 333 dst[(y + j) * stride + x + i] = (uint8_t) tot;
147 :     }
148 :     }
149 :     }
150 :    
151 :     /*************************************************************
152 :     * QPEL STUFF STARTS HERE *
153 :     *************************************************************/
154 :    
155 :     #define CLIP(X,A,B) (X < A) ? (A) : ((X > B) ? (B) : (X))
156 :    
157 :     void interpolate8x8_lowpass_h(uint8_t *dst, uint8_t *src, int32_t dst_stride, int32_t src_stride, int32_t rounding)
158 :     {
159 :     int32_t i;
160 :    
161 :     for(i = 0; i < 8; i++)
162 :     {
163 :     dst[0] = CLIP((((src[0] + src[1]) * 160 - (src[0] + src[2]) * 48 + (src[1] + src[3]) * 24 - (src[2] + src[4]) * 8 + (128 - rounding)) / 256), 0, 255);
164 :     dst[1] = CLIP((((src[1] + src[2]) * 160 - (src[0] + src[3]) * 48 + (src[0] + src[4]) * 24 - (src[1] + src[5]) * 8 + (128 - rounding)) / 256), 0, 255);
165 :     dst[2] = CLIP((((src[2] + src[3]) * 160 - (src[1] + src[4]) * 48 + (src[0] + src[5]) * 24 - (src[0] + src[6]) * 8 + (128 - rounding)) / 256), 0, 255);
166 :     dst[3] = CLIP((((src[3] + src[4]) * 160 - (src[2] + src[5]) * 48 + (src[1] + src[6]) * 24 - (src[0] + src[7]) * 8 + (128 - rounding)) / 256), 0, 255);
167 :     dst[4] = CLIP((((src[4] + src[5]) * 160 - (src[3] + src[6]) * 48 + (src[2] + src[7]) * 24 - (src[1] + src[8]) * 8 + (128 - rounding)) / 256), 0, 255);
168 :     dst[5] = CLIP((((src[5] + src[6]) * 160 - (src[4] + src[7]) * 48 + (src[3] + src[8]) * 24 - (src[2] + src[8]) * 8 + (128 - rounding)) / 256), 0, 255);
169 :     dst[6] = CLIP((((src[6] + src[7]) * 160 - (src[5] + src[8]) * 48 + (src[4] + src[8]) * 24 - (src[3] + src[7]) * 8 + (128 - rounding)) / 256), 0, 255);
170 :     dst[7] = CLIP((((src[7] + src[8]) * 160 - (src[6] + src[8]) * 48 + (src[5] + src[7]) * 24 - (src[4] + src[6]) * 8 + (128 - rounding)) / 256), 0, 255);
171 :    
172 :     dst += dst_stride;
173 :     src += src_stride;
174 :     }
175 :     }
176 :    
177 :     void interpolate8x8_lowpass_v(uint8_t *dst, uint8_t *src, int32_t dst_stride, int32_t src_stride, int32_t rounding)
178 :     {
179 :     int32_t i;
180 :    
181 :     for(i = 0; i < 8; i++)
182 :     {
183 :     int32_t src0 = src[0];
184 :     int32_t src1 = src[src_stride];
185 :     int32_t src2 = src[2 * src_stride];
186 :     int32_t src3 = src[3 * src_stride];
187 :     int32_t src4 = src[4 * src_stride];
188 :     int32_t src5 = src[5 * src_stride];
189 :     int32_t src6 = src[6 * src_stride];
190 :     int32_t src7 = src[7 * src_stride];
191 :     int32_t src8 = src[8 * src_stride];
192 :    
193 :     dst[0] = CLIP((((src0 + src1) * 160 - (src0 + src2) * 48 + (src1 + src3) * 24 - (src2 + src4) * 8 + (128 - rounding)) / 256), 0, 255);
194 :     dst[dst_stride] = CLIP((((src1 + src2) * 160 - (src0 + src3) * 48 + (src0 + src4) * 24 - (src1 + src5) * 8 + (128 - rounding)) / 256), 0, 255);
195 :     dst[2 * dst_stride] = CLIP((((src2 + src3) * 160 - (src1 + src4) * 48 + (src0 + src5) * 24 - (src0 + src6) * 8 + (128 - rounding)) / 256), 0, 255);
196 :     dst[3 * dst_stride] = CLIP((((src3 + src4) * 160 - (src2 + src5) * 48 + (src1 + src6) * 24 - (src0 + src7) * 8 + (128 - rounding)) / 256), 0, 255);
197 :     dst[4 * dst_stride] = CLIP((((src4 + src5) * 160 - (src3 + src6) * 48 + (src2 + src7) * 24 - (src1 + src8) * 8 + (128 - rounding)) / 256), 0, 255);
198 :     dst[5 * dst_stride] = CLIP((((src5 + src6) * 160 - (src4 + src7) * 48 + (src3 + src8) * 24 - (src2 + src8) * 8 + (128 - rounding)) / 256), 0, 255);
199 :     dst[6 * dst_stride] = CLIP((((src6 + src7) * 160 - (src5 + src8) * 48 + (src4 + src8) * 24 - (src3 + src7) * 8 + (128 - rounding)) / 256), 0, 255);
200 :     dst[7 * dst_stride] = CLIP((((src7 + src8) * 160 - (src6 + src8) * 48 + (src5 + src7) * 24 - (src4 + src6) * 8 + (128 - rounding)) / 256), 0, 255);
201 :    
202 :     dst++;
203 :     src++;
204 :     }
205 :     }
206 :    
207 :     void interpolate8x8_lowpass_hv(uint8_t *dst1, uint8_t *dst2, uint8_t *src, int32_t dst1_stride, int32_t dst2_stride, int32_t src_stride, int32_t rounding)
208 :     {
209 :     uint8_t data[72];
210 :    
211 :     int32_t i;
212 :    
213 :    
214 :     for(i = 0; i < 9; i++)
215 :     {
216 :     dst2[0] = data[8 * i + 0] = CLIP((((src[0] + src[1]) * 160 - (src[0] + src[2]) * 48 + (src[1] + src[3]) * 24 - (src[2] + src[4]) * 8 + (128 - rounding)) / 256), 0, 255);
217 :     dst2[1] = data[8 * i + 1] = CLIP((((src[1] + src[2]) * 160 - (src[0] + src[3]) * 48 + (src[0] + src[4]) * 24 - (src[1] + src[5]) * 8 + (128 - rounding)) / 256), 0, 255);
218 :     dst2[2] = data[8 * i + 2] = CLIP((((src[2] + src[3]) * 160 - (src[1] + src[4]) * 48 + (src[0] + src[5]) * 24 - (src[0] + src[6]) * 8 + (128 - rounding)) / 256), 0, 255);
219 :     dst2[3] = data[8 * i + 3] = CLIP((((src[3] + src[4]) * 160 - (src[2] + src[5]) * 48 + (src[1] + src[6]) * 24 - (src[0] + src[7]) * 8 + (128 - rounding)) / 256), 0, 255);
220 :     dst2[4] = data[8 * i + 4] = CLIP((((src[4] + src[5]) * 160 - (src[3] + src[6]) * 48 + (src[2] + src[7]) * 24 - (src[1] + src[8]) * 8 + (128 - rounding)) / 256), 0, 255);
221 :     dst2[5] = data[8 * i + 5] = CLIP((((src[5] + src[6]) * 160 - (src[4] + src[7]) * 48 + (src[3] + src[8]) * 24 - (src[2] + src[8]) * 8 + (128 - rounding)) / 256), 0, 255);
222 :     dst2[6] = data[8 * i + 6] = CLIP((((src[6] + src[7]) * 160 - (src[5] + src[8]) * 48 + (src[4] + src[8]) * 24 - (src[3] + src[7]) * 8 + (128 - rounding)) / 256), 0, 255);
223 :     dst2[7] = data[8 * i + 7] = CLIP((((src[7] + src[8]) * 160 - (src[6] + src[8]) * 48 + (src[5] + src[7]) * 24 - (src[4] + src[6]) * 8 + (128 - rounding)) / 256), 0, 255);
224 :    
225 :     src += src_stride;
226 :     dst2 += dst2_stride;
227 :     }
228 :    
229 :     for(i = 0; i < 8; i++)
230 :     {
231 :     int32_t src0 = data[i];
232 :     int32_t src1 = data[8 + i];
233 :     int32_t src2 = data[2 * 8 + i];
234 :     int32_t src3 = data[3 * 8 + i];
235 :     int32_t src4 = data[4 * 8 + i];
236 :     int32_t src5 = data[5 * 8 + i];
237 :     int32_t src6 = data[6 * 8 + i];
238 :     int32_t src7 = data[7 * 8 + i];
239 :     int32_t src8 = data[8 * 8 + i];
240 :    
241 :     dst1[0] = CLIP((((src0 + src1) * 160 - (src0 + src2) * 48 + (src1 + src3) * 24 - (src2 + src4) * 8 + (128 - rounding)) / 256), 0, 255);
242 :     dst1[dst1_stride] = CLIP((((src1 + src2) * 160 - (src0 + src3) * 48 + (src0 + src4) * 24 - (src1 + src5) * 8 + (128 - rounding)) / 256), 0, 255);
243 :     dst1[2 * dst1_stride] = CLIP((((src2 + src3) * 160 - (src1 + src4) * 48 + (src0 + src5) * 24 - (src0 + src6) * 8 + (128 - rounding)) / 256), 0, 255);
244 :     dst1[3 * dst1_stride] = CLIP((((src3 + src4) * 160 - (src2 + src5) * 48 + (src1 + src6) * 24 - (src0 + src7) * 8 + (128 - rounding)) / 256), 0, 255);
245 :     dst1[4 * dst1_stride] = CLIP((((src4 + src5) * 160 - (src3 + src6) * 48 + (src2 + src7) * 24 - (src1 + src8) * 8 + (128 - rounding)) / 256), 0, 255);
246 :     dst1[5 * dst1_stride] = CLIP((((src5 + src6) * 160 - (src4 + src7) * 48 + (src3 + src8) * 24 - (src2 + src8) * 8 + (128 - rounding)) / 256), 0, 255);
247 :     dst1[6 * dst1_stride] = CLIP((((src6 + src7) * 160 - (src5 + src8) * 48 + (src4 + src8) * 24 - (src3 + src7) * 8 + (128 - rounding)) / 256), 0, 255);
248 :     dst1[7 * dst1_stride] = CLIP((((src7 + src8) * 160 - (src6 + src8) * 48 + (src5 + src7) * 24 - (src4 + src6) * 8 + (128 - rounding)) / 256), 0, 255);
249 :    
250 :     dst1++;
251 :     }
252 :     }
253 :    
254 :     void interpolate8x8_bilinear2(uint8_t *dst, uint8_t *src1, uint8_t *src2, int32_t dst_stride, int32_t src_stride, int32_t rounding)
255 :     {
256 :     int32_t i;
257 :    
258 :     for(i = 0; i < 8; i++)
259 :     {
260 : edgomez 723 dst[0] = (uint8_t)((src1[0] + src2[0] + (1 - rounding)) >> 1);
261 :     dst[1] = (uint8_t)((src1[1] + src2[1] + (1 - rounding)) >> 1);
262 :     dst[2] = (uint8_t)((src1[2] + src2[2] + (1 - rounding)) >> 1);
263 :     dst[3] = (uint8_t)((src1[3] + src2[3] + (1 - rounding)) >> 1);
264 :     dst[4] = (uint8_t)((src1[4] + src2[4] + (1 - rounding)) >> 1);
265 :     dst[5] = (uint8_t)((src1[5] + src2[5] + (1 - rounding)) >> 1);
266 :     dst[6] = (uint8_t)((src1[6] + src2[6] + (1 - rounding)) >> 1);
267 :     dst[7] = (uint8_t)((src1[7] + src2[7] + (1 - rounding)) >> 1);
268 : Isibaar 333
269 :     dst += dst_stride;
270 :     src1 += src_stride;
271 :     src2 += 8;
272 :     }
273 :     }
274 :    
275 :     void interpolate8x8_bilinear4(uint8_t *dst, uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4, int32_t stride, int32_t rounding)
276 :     {
277 :     int32_t i;
278 :    
279 :     for(i = 0; i < 8; i++)
280 :     {
281 : edgomez 723 dst[0] = (uint8_t)((src1[0] + src2[0] + src3[0] + src4[0] + (2 - rounding)) >> 2);
282 :     dst[1] = (uint8_t)((src1[1] + src2[1] + src3[1] + src4[1] + (2 - rounding)) >> 2);
283 :     dst[2] = (uint8_t)((src1[2] + src2[2] + src3[2] + src4[2] + (2 - rounding)) >> 2);
284 :     dst[3] = (uint8_t)((src1[3] + src2[3] + src3[3] + src4[3] + (2 - rounding)) >> 2);
285 :     dst[4] = (uint8_t)((src1[4] + src2[4] + src3[4] + src4[4] + (2 - rounding)) >> 2);
286 :     dst[5] = (uint8_t)((src1[5] + src2[5] + src3[5] + src4[5] + (2 - rounding)) >> 2);
287 :     dst[6] = (uint8_t)((src1[6] + src2[6] + src3[6] + src4[6] + (2 - rounding)) >> 2);
288 :     dst[7] = (uint8_t)((src1[7] + src2[7] + src3[7] + src4[7] + (2 - rounding)) >> 2);
289 : Isibaar 333
290 :     dst += stride;
291 :     src1 += stride;
292 :     src2 += 8;
293 :     src3 += 8;
294 :     src4 += 8;
295 :     }
296 :     }

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4