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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.2.1 - (view) (download)

1 : suxen_drol 1.1.2.1 /*****************************************************************************
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 :     * $Id: reduced.c,v 1.11 2002/11/17 00:32:06 edgomez Exp $
54 :     *
55 :     ****************************************************************************/
56 :    
57 :     #include "../portab.h"
58 :     #include "reduced.h"
59 :    
60 :     // function pointers
61 :     COPY_UPSAMPLED_8X8_16TO8 * copy_upsampled_8x8_16to8;
62 :     ADD_UPSAMPLED_8X8_16TO8 * add_upsampled_8x8_16to8;
63 :     VFILTER_31 * vfilter_31;
64 :     HFILTER_31 * hfilter_31;
65 :    
66 :     //////////////////////////////////////////////////////////
67 :     // Upsampling (1/3/3/1) filter
68 :    
69 :     #define CLIP(x) ((x)<0 ? 0 : (x)>255 ? 255 : (x))
70 :     #define ADD(dst,src) (dst) = CLIP((dst)+(src))
71 :    
72 :     static __inline void Filter_31(uint8_t *Dst1, uint8_t *Dst2,
73 :     const int16_t *Src1, const int16_t *Src2)
74 :     {
75 :     /* Src[] is assumed to be >=0. So we can use ">>2" instead of "/2" */
76 :     int16_t a = (3*Src1[0]+ Src2[0]+2) >> 2;
77 :     int16_t b = ( Src1[0]+3*Src2[0]+2) >> 2;
78 :     Dst1[0] = CLIP(a);
79 :     Dst2[0] = CLIP(b);
80 :     }
81 :    
82 :     static __inline void Filter_9331(uint8_t *Dst1, uint8_t *Dst2,
83 :     const int16_t *Src1, const int16_t *Src2)
84 :     {
85 :     /* Src[] is assumed to be >=0. So we can use ">>4" instead of "/16" */
86 :     int16_t a = (9*Src1[0]+ 3*Src1[1]+ 3*Src2[0] + 1*Src2[1] + 8) >> 4;
87 :     int16_t b = (3*Src1[0]+ 9*Src1[1]+ 1*Src2[0] + 3*Src2[1] + 8) >> 4;
88 :     int16_t c = (3*Src1[0]+ 1*Src1[1]+ 9*Src2[0] + 3*Src2[1] + 8) >> 4;
89 :     int16_t d = (1*Src1[0]+ 3*Src1[1]+ 3*Src2[0] + 9*Src2[1] + 8) >> 4;
90 :     Dst1[0] = CLIP(a);
91 :     Dst1[1] = CLIP(b);
92 :     Dst2[0] = CLIP(c);
93 :     Dst2[1] = CLIP(d);
94 :     }
95 :    
96 :     void xvid_Copy_Upsampled_8x8_16To8_C(uint8_t *Dst, const int16_t *Src, const int BpS)
97 :     {
98 :     int x, y;
99 :    
100 :     Dst[0] = CLIP(Src[0]);
101 :     for(x=0; x<7; ++x) Filter_31(Dst+2*x+1, Dst+2*x+2, Src+x, Src+x+1);
102 :     Dst[15] = CLIP(Src[7]);
103 :     Dst += BpS;
104 :     for(y=0; y<7; ++y) {
105 :     uint8_t *const Dst2 = Dst + BpS;
106 :     Filter_31(Dst, Dst2, Src, Src+8);
107 :     for(x=0; x<7; ++x)
108 :     Filter_9331(Dst+2*x+1, Dst2+2*x+1, Src+x, Src+x+8);
109 :     Filter_31(Dst+15, Dst2+15, Src+7, Src+7+8);
110 :     Src += 8;
111 :     Dst += 2*BpS;
112 :     }
113 :     Dst[0] = CLIP(Src[0]);
114 :     for(x=0; x<7; ++x) Filter_31(Dst+2*x+1, Dst+2*x+2, Src+x, Src+x+1);
115 :     Dst[15] = CLIP(Src[7]);
116 :     }
117 :    
118 :     static __inline void Filter_Add_31(uint8_t *Dst1, uint8_t *Dst2,
119 :     const int16_t *Src1, const int16_t *Src2)
120 :     {
121 :     /* Here, we must use "/4", since Src[] is in [-256, 255] */
122 :     int16_t a = (3*Src1[0]+ Src2[0] + 2) / 4;
123 :     int16_t b = ( Src1[0]+3*Src2[0] + 2) / 4;
124 :     ADD(Dst1[0], a);
125 :     ADD(Dst2[0], b);
126 :     }
127 :    
128 :     static __inline void Filter_Add_9331(uint8_t *Dst1, uint8_t *Dst2,
129 :     const int16_t *Src1, const int16_t *Src2)
130 :     {
131 :     int16_t a = (9*Src1[0]+ 3*Src1[1]+ 3*Src2[0] + 1*Src2[1] + 8) / 16;
132 :     int16_t b = (3*Src1[0]+ 9*Src1[1]+ 1*Src2[0] + 3*Src2[1] + 8) / 16;
133 :     int16_t c = (3*Src1[0]+ 1*Src1[1]+ 9*Src2[0] + 3*Src2[1] + 8) / 16;
134 :     int16_t d = (1*Src1[0]+ 3*Src1[1]+ 3*Src2[0] + 9*Src2[1] + 8) / 16;
135 :     ADD(Dst1[0], a);
136 :     ADD(Dst1[1], b);
137 :     ADD(Dst2[0], c);
138 :     ADD(Dst2[1], d);
139 :     }
140 :    
141 :     void xvid_Add_Upsampled_8x8_16To8_C(uint8_t *Dst, const int16_t *Src, const int BpS)
142 :     {
143 :     int x, y;
144 :    
145 :     ADD(Dst[0], Src[0]);
146 :     for(x=0; x<7; ++x) Filter_Add_31(Dst+2*x+1, Dst+2*x+2, Src+x, Src+x+1);
147 :     ADD(Dst[15], Src[7]);
148 :     Dst += BpS;
149 :     for(y=0; y<7; ++y) {
150 :     uint8_t *const Dst2 = Dst + BpS;
151 :     Filter_Add_31(Dst, Dst2, Src, Src+8);
152 :     for(x=0; x<7; ++x)
153 :     Filter_Add_9331(Dst+2*x+1, Dst2+2*x+1, Src+x, Src+x+8);
154 :     Filter_Add_31(Dst+15, Dst2+15, Src+7, Src+7+8);
155 :     Src += 8;
156 :     Dst += 2*BpS;
157 :     }
158 :     ADD(Dst[0], Src[0]);
159 :     for(x=0; x<7; ++x) Filter_Add_31(Dst+2*x+1, Dst+2*x+2, Src+x, Src+x+1);
160 :     ADD(Dst[15], Src[7]);
161 :     }
162 :     #undef CLIP
163 :     #undef ADD
164 :    
165 :     //////////////////////////////////////////////////////////
166 :     // horizontal and vertical deblocking
167 :    
168 :     void xvid_HFilter_31_C(uint8_t *Src1, uint8_t *Src2, int Nb_Blks)
169 :     {
170 :     Nb_Blks *= 8;
171 :     while(Nb_Blks-->0) {
172 :     uint8_t a = ( 3*Src1[0] + 1*Src2[0] + 2 ) >> 2;
173 :     uint8_t b = ( 1*Src1[0] + 3*Src2[0] + 2 ) >> 2;
174 :     *Src1++ = a;
175 :     *Src2++ = b;
176 :     }
177 :     }
178 :    
179 :     void xvid_VFilter_31_C(uint8_t *Src1, uint8_t *Src2, const int BpS, int Nb_Blks)
180 :     {
181 :     Nb_Blks *= 8;
182 :     while(Nb_Blks-->0) {
183 :     uint8_t a = ( 3*Src1[0] + 1*Src2[0] + 2 ) >> 2;
184 :     uint8_t b = ( 1*Src1[0] + 3*Src2[0] + 2 ) >> 2;
185 :     *Src1 = a;
186 :     *Src2 = b;
187 :     Src1 += BpS;
188 :     Src2 += BpS;
189 :     }
190 :     }
191 :    
192 :     //////////////////////////////////////////////////////////
193 :     // 16x16 -> 8x8 (1/3/3/1) downsampling
194 :     //
195 :     // Warning! These read 1 pixel outside of the input 16x16 block!
196 :     //
197 :     //////////////////////////////////////////////////////////
198 :    
199 :     void xvid_Filter_18x18_To_8x8_C(int16_t *Dst, const uint8_t *Src, const int BpS)
200 :     {
201 :     int16_t *T, Tmp[18*8];
202 :     int i, j;
203 :    
204 :     T = Tmp;
205 :     Src -= BpS;
206 :     for(j=-1; j<17; j++) {
207 :     for(i=0; i<8; ++i)
208 :     T[i] = Src[2*i-1] + 3*Src[2*i+0] + 3*Src[2*i+1] + Src[2*i+2];
209 :     T += 8;
210 :     Src += BpS;
211 :     }
212 :     T = Tmp + 8;
213 :     for(j=0; j<8; j++) {
214 :     for(i=0; i<8; ++i)
215 :     Dst[i] = ( T[-8+i] + 3*T[0+i] + 3*T[8+i] + T[16+i] + 32 ) / 64;
216 :     Dst += 8;
217 :     T += 16;
218 :     }
219 :     }
220 :    
221 :     void xvid_Filter_Diff_18x18_To_8x8_C(int16_t *Dst, const uint8_t *Src, const int BpS)
222 :     {
223 :     int16_t *T, Tmp[18*8];
224 :     int i, j;
225 :    
226 :     T = Tmp;
227 :     Src -= BpS;
228 :     for(j=-1; j<17; j++) {
229 :     for(i=0; i<8; ++i)
230 :     T[i] = Src[2*i-1] + 3*Src[2*i+0] + 3*Src[2*i+1] + Src[2*i+2];
231 :     T += 8;
232 :     Src += BpS;
233 :     }
234 :     T = Tmp;
235 :     for(j=0; j<8; j++) {
236 :     for(i=0; i<8; ++i)
237 :     Dst[i] -= ( T[i] + 3*T[8+i] + 3*T[16+i] + T[24+i] + 32 ) / 64;
238 :     Dst += 8;
239 :     T += 16;
240 :     }
241 :     }
242 :    
243 :     //////////////////////////////////////////////////////////

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