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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1382 - (view) (download)

1 : edgomez 851 /*****************************************************************************
2 :     *
3 :     * XVID MPEG-4 VIDEO CODEC
4 :     * Reduced-Resolution utilities
5 :     *
6 :     * Copyright(C) 2002 Pascal Massimino <skal@planet-d.net>
7 :     *
8 :     * This file is part of XviD, a free MPEG-4 video encoder/decoder
9 :     *
10 :     * XviD is free software; you can redistribute it and/or modify it
11 :     * under the terms of the GNU General Public License as published by
12 :     * the Free Software Foundation; either version 2 of the License, or
13 :     * (at your option) any later version.
14 :     *
15 :     * This program 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
18 :     * GNU General Public License for more details.
19 :     *
20 :     * You should have received a copy of the GNU General Public License
21 :     * along with this program; if not, write to the Free Software
22 :     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 :     *
24 :     * Under section 8 of the GNU General Public License, the copyright
25 :     * holders of XVID explicitly forbid distribution in the following
26 :     * countries:
27 :     *
28 :     * - Japan
29 :     * - United States of America
30 :     *
31 :     * Linking XviD statically or dynamically with other modules is making a
32 :     * combined work based on XviD. Thus, the terms and conditions of the
33 :     * GNU General Public License cover the whole combination.
34 :     *
35 :     * As a special exception, the copyright holders of XviD give you
36 :     * permission to link XviD with independent modules that communicate with
37 :     * XviD solely through the VFW1.1 and DShow interfaces, regardless of the
38 :     * license terms of these independent modules, and to copy and distribute
39 :     * the resulting combined work under terms of your choice, provided that
40 :     * every copy of the combined work is accompanied by a complete copy of
41 :     * the source code of XviD (the version of XviD used to produce the
42 :     * combined work), being distributed under the terms of the GNU General
43 :     * Public License plus this exception. An independent module is a module
44 :     * which is not derived from or based on XviD.
45 :     *
46 :     * Note that people who make modified versions of XviD are not obligated
47 :     * to grant this special exception for their modified versions; it is
48 :     * their choice whether to do so. The GNU General Public License gives
49 :     * permission to release a modified version without this exception; this
50 :     * exception also makes it possible to release a modified version which
51 :     * carries forward this exception.
52 :     *
53 : edgomez 1382 * $Id: reduced.c,v 1.3 2004-03-22 22:36:24 edgomez Exp $
54 : edgomez 851 *
55 :     ****************************************************************************/
56 :    
57 :     #include "../portab.h"
58 :     #include "../global.h"
59 :     #include "reduced.h"
60 :    
61 : edgomez 1382 /* function pointers */
62 : edgomez 851 COPY_UPSAMPLED_8X8_16TO8 * copy_upsampled_8x8_16to8;
63 :     ADD_UPSAMPLED_8X8_16TO8 * add_upsampled_8x8_16to8;
64 :     VFILTER_31 * vfilter_31;
65 :     HFILTER_31 * hfilter_31;
66 :     FILTER_18X18_TO_8X8 * filter_18x18_to_8x8;
67 :     FILTER_DIFF_18X18_TO_8X8 * filter_diff_18x18_to_8x8;
68 :    
69 : edgomez 1382 /*----------------------------------------------------------------------------
70 :     * Upsampling (1/3/3/1) filter
71 :     *--------------------------------------------------------------------------*/
72 : edgomez 851
73 :     #define ADD(dst,src) (dst) = CLIP((dst)+(src), 0, 255)
74 :    
75 :     static __inline void Filter_31(uint8_t *Dst1, uint8_t *Dst2,
76 :     const int16_t *Src1, const int16_t *Src2)
77 :     {
78 :     /* Src[] is assumed to be >=0. So we can use ">>2" instead of "/2" */
79 :     int16_t a = (3*Src1[0]+ Src2[0]+2) >> 2;
80 :     int16_t b = ( Src1[0]+3*Src2[0]+2) >> 2;
81 :     Dst1[0] = CLIP(a, 0, 255);
82 :     Dst2[0] = CLIP(b, 0, 255);
83 :     }
84 :    
85 :     static __inline void Filter_9331(uint8_t *Dst1, uint8_t *Dst2,
86 :     const int16_t *Src1, const int16_t *Src2)
87 :     {
88 :     /* Src[] is assumed to be >=0. So we can use ">>4" instead of "/16" */
89 :     int16_t a = (9*Src1[0]+ 3*Src1[1]+ 3*Src2[0] + 1*Src2[1] + 8) >> 4;
90 :     int16_t b = (3*Src1[0]+ 9*Src1[1]+ 1*Src2[0] + 3*Src2[1] + 8) >> 4;
91 :     int16_t c = (3*Src1[0]+ 1*Src1[1]+ 9*Src2[0] + 3*Src2[1] + 8) >> 4;
92 :     int16_t d = (1*Src1[0]+ 3*Src1[1]+ 3*Src2[0] + 9*Src2[1] + 8) >> 4;
93 :     Dst1[0] = CLIP(a, 0, 255);
94 :     Dst1[1] = CLIP(b, 0, 255);
95 :     Dst2[0] = CLIP(c, 0, 255);
96 :     Dst2[1] = CLIP(d, 0, 255);
97 :     }
98 :    
99 :     void xvid_Copy_Upsampled_8x8_16To8_C(uint8_t *Dst, const int16_t *Src, const int BpS)
100 :     {
101 :     int x, y;
102 :    
103 :     Dst[0] = CLIP(Src[0], 0, 255);
104 :     for(x=0; x<7; ++x) Filter_31(Dst+2*x+1, Dst+2*x+2, Src+x, Src+x+1);
105 :     Dst[15] = CLIP(Src[7], 0, 255);
106 :     Dst += BpS;
107 :     for(y=0; y<7; ++y) {
108 :     uint8_t *const Dst2 = Dst + BpS;
109 :     Filter_31(Dst, Dst2, Src, Src+8);
110 :     for(x=0; x<7; ++x)
111 :     Filter_9331(Dst+2*x+1, Dst2+2*x+1, Src+x, Src+x+8);
112 :     Filter_31(Dst+15, Dst2+15, Src+7, Src+7+8);
113 : edgomez 1382 Src += 8;
114 : edgomez 851 Dst += 2*BpS;
115 :     }
116 :     Dst[0] = CLIP(Src[0], 0, 255);
117 :     for(x=0; x<7; ++x) Filter_31(Dst+2*x+1, Dst+2*x+2, Src+x, Src+x+1);
118 :     Dst[15] = CLIP(Src[7], 0, 255);
119 :     }
120 :    
121 :     static __inline void Filter_Add_31(uint8_t *Dst1, uint8_t *Dst2,
122 :     const int16_t *Src1, const int16_t *Src2)
123 :     {
124 :     /* Here, we must use "/4", since Src[] is in [-256, 255] */
125 :     int16_t a = (3*Src1[0]+ Src2[0] + 2) / 4;
126 :     int16_t b = ( Src1[0]+3*Src2[0] + 2) / 4;
127 :     ADD(Dst1[0], a);
128 :     ADD(Dst2[0], b);
129 :     }
130 :    
131 :     static __inline void Filter_Add_9331(uint8_t *Dst1, uint8_t *Dst2,
132 :     const int16_t *Src1, const int16_t *Src2)
133 :     {
134 :     int16_t a = (9*Src1[0]+ 3*Src1[1]+ 3*Src2[0] + 1*Src2[1] + 8) / 16;
135 :     int16_t b = (3*Src1[0]+ 9*Src1[1]+ 1*Src2[0] + 3*Src2[1] + 8) / 16;
136 :     int16_t c = (3*Src1[0]+ 1*Src1[1]+ 9*Src2[0] + 3*Src2[1] + 8) / 16;
137 :     int16_t d = (1*Src1[0]+ 3*Src1[1]+ 3*Src2[0] + 9*Src2[1] + 8) / 16;
138 :     ADD(Dst1[0], a);
139 :     ADD(Dst1[1], b);
140 :     ADD(Dst2[0], c);
141 :     ADD(Dst2[1], d);
142 :     }
143 :    
144 :     void xvid_Add_Upsampled_8x8_16To8_C(uint8_t *Dst, const int16_t *Src, const int BpS)
145 :     {
146 :     int x, y;
147 :    
148 :     ADD(Dst[0], Src[0]);
149 :     for(x=0; x<7; ++x) Filter_Add_31(Dst+2*x+1, Dst+2*x+2, Src+x, Src+x+1);
150 :     ADD(Dst[15], Src[7]);
151 :     Dst += BpS;
152 :     for(y=0; y<7; ++y) {
153 :     uint8_t *const Dst2 = Dst + BpS;
154 :     Filter_Add_31(Dst, Dst2, Src, Src+8);
155 :     for(x=0; x<7; ++x)
156 :     Filter_Add_9331(Dst+2*x+1, Dst2+2*x+1, Src+x, Src+x+8);
157 :     Filter_Add_31(Dst+15, Dst2+15, Src+7, Src+7+8);
158 : edgomez 1382 Src += 8;
159 : edgomez 851 Dst += 2*BpS;
160 :     }
161 :     ADD(Dst[0], Src[0]);
162 :     for(x=0; x<7; ++x) Filter_Add_31(Dst+2*x+1, Dst+2*x+2, Src+x, Src+x+1);
163 :     ADD(Dst[15], Src[7]);
164 :     }
165 :     #undef ADD
166 :    
167 : edgomez 1382 /*----------------------------------------------------------------------------
168 :     * horizontal and vertical deblocking
169 :     *--------------------------------------------------------------------------*/
170 : edgomez 851
171 :     void xvid_HFilter_31_C(uint8_t *Src1, uint8_t *Src2, int Nb_Blks)
172 :     {
173 :     Nb_Blks *= 8;
174 :     while(Nb_Blks-->0) {
175 :     uint8_t a = ( 3*Src1[0] + 1*Src2[0] + 2 ) >> 2;
176 :     uint8_t b = ( 1*Src1[0] + 3*Src2[0] + 2 ) >> 2;
177 :     *Src1++ = a;
178 :     *Src2++ = b;
179 :     }
180 :     }
181 :    
182 :     void xvid_VFilter_31_C(uint8_t *Src1, uint8_t *Src2, const int BpS, int Nb_Blks)
183 :     {
184 :     Nb_Blks *= 8;
185 :     while(Nb_Blks-->0) {
186 :     uint8_t a = ( 3*Src1[0] + 1*Src2[0] + 2 ) >> 2;
187 :     uint8_t b = ( 1*Src1[0] + 3*Src2[0] + 2 ) >> 2;
188 :     *Src1 = a;
189 :     *Src2 = b;
190 :     Src1 += BpS;
191 :     Src2 += BpS;
192 :     }
193 :     }
194 :    
195 : edgomez 1382 /*----------------------------------------------------------------------------
196 :     * 16x16 -> 8x8 (1/3/3/1) downsampling
197 :     *
198 :     * Warning! These read 1 pixel outside of the input 16x16 block!
199 :     *--------------------------------------------------------------------------*/
200 : edgomez 851
201 :     void xvid_Filter_18x18_To_8x8_C(int16_t *Dst, const uint8_t *Src, const int BpS)
202 :     {
203 :     int16_t *T, Tmp[18*8];
204 :     int i, j;
205 :    
206 :     T = Tmp;
207 :     Src -= BpS;
208 :     for(j=-1; j<17; j++) {
209 :     for(i=0; i<8; ++i)
210 :     T[i] = Src[2*i-1] + 3*Src[2*i+0] + 3*Src[2*i+1] + Src[2*i+2];
211 :     T += 8;
212 :     Src += BpS;
213 :     }
214 :     T = Tmp + 8;
215 :     for(j=0; j<8; j++) {
216 :     for(i=0; i<8; ++i)
217 :     Dst[i] = ( T[-8+i] + 3*T[0+i] + 3*T[8+i] + T[16+i] + 32 ) / 64;
218 :     Dst += 8;
219 :     T += 16;
220 :     }
221 :     }
222 :    
223 :     void xvid_Filter_Diff_18x18_To_8x8_C(int16_t *Dst, const uint8_t *Src, const int BpS)
224 :     {
225 :     int16_t *T, Tmp[18*8];
226 :     int i, j;
227 :    
228 :     T = Tmp;
229 :     Src -= BpS;
230 :     for(j=-1; j<17; j++) {
231 :     for(i=0; i<8; ++i)
232 :     T[i] = Src[2*i-1] + 3*Src[2*i+0] + 3*Src[2*i+1] + Src[2*i+2];
233 :     T += 8;
234 :     Src += BpS;
235 :     }
236 :     T = Tmp;
237 :     for(j=0; j<8; j++) {
238 :     for(i=0; i<8; ++i)
239 :     Dst[i] -= ( T[i] + 3*T[8+i] + 3*T[16+i] + T[24+i] + 32 ) / 64;
240 :     Dst += 8;
241 :     T += 16;
242 :     }
243 :     }

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