[svn] / branches / dev-api-4 / xvidcore / src / utils / mbtransquant.c Repository:
ViewVC logotype

Annotation of /branches/dev-api-4/xvidcore/src/utils/mbtransquant.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (view) (download)
Original Path: trunk/xvidcore/src/utils/mbtransquant.c

1 : Isibaar 3 /******************************************************************************
2 :     * *
3 :     * This file is part of XviD, a free MPEG-4 video encoder/decoder *
4 :     * *
5 :     * XviD is an implementation of a part of one or more MPEG-4 Video tools *
6 :     * as specified in ISO/IEC 14496-2 standard. Those intending to use this *
7 :     * software module in hardware or software products are advised that its *
8 :     * use may infringe existing patents or copyrights, and any such use *
9 :     * would be at such party's own risk. The original developer of this *
10 :     * software module and his/her company, and subsequent editors and their *
11 :     * companies, will have no liability for use of this software or *
12 :     * modifications or derivatives thereof. *
13 :     * *
14 :     * XviD is free software; you can redistribute it and/or modify it *
15 :     * under the terms of the GNU General Public License as published by *
16 :     * the Free Software Foundation; either version 2 of the License, or *
17 :     * (at your option) any later version. *
18 :     * *
19 :     * XviD is distributed in the hope that it will be useful, but *
20 :     * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22 :     * GNU General Public License for more details. *
23 :     * *
24 :     * You should have received a copy of the GNU General Public License *
25 :     * along with this program; if not, write to the Free Software *
26 :     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
27 :     * *
28 :     ******************************************************************************/
29 :    
30 :     /******************************************************************************
31 :     * *
32 :     * mbtransquant.c *
33 :     * *
34 :     * Copyright (C) 2001 - Peter Ross <pross@cs.rmit.edu.au> *
35 :     * Copyright (C) 2001 - Michael Militzer <isibaar@xvid.org> *
36 :     * *
37 :     * For more information visit the XviD homepage: http://www.xvid.org *
38 :     * *
39 :     ******************************************************************************/
40 :    
41 :     /******************************************************************************
42 :     * *
43 :     * Revision history: *
44 :     * *
45 :     * 22.12.2001 get_dc_scaler() moved to common.h
46 :     * 19.11.2001 introduced coefficient thresholding (Isibaar) *
47 :     * 17.11.2001 initial version *
48 :     * *
49 :     ******************************************************************************/
50 :    
51 :     #include "../portab.h"
52 :     #include "mbfunctions.h"
53 :    
54 :     #include "../global.h"
55 :     #include "mem_transfer.h"
56 :     #include "timer.h"
57 :     #include "../dct/fdct.h"
58 :     #include "../dct/idct.h"
59 :     #include "../quant/quant_mpeg4.h"
60 :     #include "../quant/quant_h263.h"
61 :     #include "../encoder.h"
62 :    
63 :     #define MIN(X, Y) ((X)<(Y)?(X):(Y))
64 :     #define MAX(X, Y) ((X)>(Y)?(X):(Y))
65 :    
66 :     #define TOOSMALL_LIMIT 1 /* skip blocks having a coefficient sum below this value */
67 :    
68 :     /* this isnt pretty, but its better than 20 ifdefs */
69 :    
70 :     void MBTransQuantIntra(const MBParam *pParam,
71 :     const uint32_t x_pos,
72 :     const uint32_t y_pos,
73 :     int16_t data[][64],
74 :     int16_t qcoeff[][64],
75 :     IMAGE * const pCurrent)
76 :    
77 :     {
78 :     const uint32_t stride = pParam->edged_width;
79 :     uint32_t i;
80 :     uint32_t iQuant = pParam->quant;
81 :     uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
82 :    
83 :     pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);
84 :     pU_Cur = pCurrent->u + (y_pos << 3) * (stride >> 1) + (x_pos << 3);
85 :     pV_Cur = pCurrent->v + (y_pos << 3) * (stride >> 1) + (x_pos << 3);
86 :    
87 :     for(i = 0; i < 6; i++) {
88 :     uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);
89 :    
90 :     start_timer();
91 :    
92 :     switch(i) {
93 :     case 0 :
94 :     transfer_8to16copy(data[0], pY_Cur, stride);
95 :     break;
96 :     case 1 :
97 :     transfer_8to16copy(data[1], pY_Cur + 8, stride);
98 :     break;
99 :     case 2 :
100 :     transfer_8to16copy(data[2], pY_Cur + 8 * stride, stride);
101 :     break;
102 :     case 3 :
103 :     transfer_8to16copy(data[3], pY_Cur + 8 * stride + 8, stride);
104 :     break;
105 :     case 4 :
106 :     transfer_8to16copy(data[4], pU_Cur, stride / 2);
107 :     break;
108 :     case 5 :
109 :     transfer_8to16copy(data[5], pV_Cur, stride / 2);
110 :     break;
111 :     }
112 :     stop_transfer_timer();
113 :    
114 :     start_timer();
115 :     fdct(data[i]);
116 :     stop_dct_timer();
117 :    
118 :     if (pParam->quant_type == H263_QUANT)
119 :     {
120 :     start_timer();
121 :     quant_intra(qcoeff[i], data[i], iQuant, iDcScaler);
122 :     stop_quant_timer();
123 :    
124 :     start_timer();
125 :     dequant_intra(data[i], qcoeff[i], iQuant, iDcScaler);
126 :     stop_iquant_timer();
127 :     }
128 :     else
129 :     {
130 :     start_timer();
131 :     quant4_intra(qcoeff[i], data[i], iQuant, iDcScaler);
132 :     stop_quant_timer();
133 :    
134 :     start_timer();
135 :     dequant4_intra(data[i], qcoeff[i], iQuant, iDcScaler);
136 :     stop_iquant_timer();
137 :     }
138 :    
139 :     start_timer();
140 :     idct(data[i]);
141 :     stop_idct_timer();
142 :    
143 :     start_timer();
144 :    
145 :     switch(i) {
146 :     case 0:
147 :     transfer_16to8copy(pY_Cur, data[0], stride);
148 :     break;
149 :     case 1:
150 :     transfer_16to8copy(pY_Cur + 8, data[1], stride);
151 :     break;
152 :     case 2:
153 :     transfer_16to8copy(pY_Cur + 8 * stride, data[2], stride);
154 :     break;
155 :     case 3:
156 :     transfer_16to8copy(pY_Cur + 8 + 8 * stride, data[3], stride);
157 :     break;
158 :     case 4:
159 :     transfer_16to8copy(pU_Cur, data[4], stride / 2);
160 :     break;
161 :     case 5:
162 :     transfer_16to8copy(pV_Cur, data[5], stride / 2);
163 :     break;
164 :     }
165 :     stop_transfer_timer();
166 :     }
167 :     }
168 :    
169 :    
170 :     uint8_t MBTransQuantInter(const MBParam *pParam,
171 :     const uint32_t x_pos, const uint32_t y_pos,
172 :     int16_t data[][64],
173 :     int16_t qcoeff[][64],
174 :     IMAGE * const pCurrent)
175 :    
176 :     {
177 :     const uint32_t stride = pParam->edged_width;
178 :     uint8_t i;
179 :     uint8_t iQuant = pParam->quant;
180 :     uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
181 :     uint8_t cbp = 0;
182 :     uint32_t sum;
183 :    
184 :     pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);
185 :     pU_Cur = pCurrent->u + (y_pos << 3) * (stride >> 1) + (x_pos << 3);
186 :     pV_Cur = pCurrent->v + (y_pos << 3) * (stride >> 1) + (x_pos << 3);
187 :    
188 :     for(i = 0; i < 6; i++) {
189 :     /*
190 :     no need to transfer 8->16-bit
191 :     (this is performed already in motion compensation)
192 :     */
193 :     start_timer();
194 :     fdct(data[i]);
195 :     stop_dct_timer();
196 :    
197 :     if (pParam->quant_type == 0)
198 :     {
199 :     start_timer();
200 :     sum = quant_inter(qcoeff[i], data[i], iQuant);
201 :     stop_quant_timer();
202 :     }
203 :     else
204 :     {
205 :     start_timer();
206 :     sum = quant4_inter(qcoeff[i], data[i], iQuant);
207 :     stop_quant_timer();
208 :     }
209 :    
210 :     if(sum >= TOOSMALL_LIMIT) { // skip block ?
211 :    
212 :     if (pParam->quant_type == H263_QUANT)
213 :     {
214 :     start_timer();
215 :     dequant_inter(data[i], qcoeff[i], iQuant);
216 :     stop_iquant_timer();
217 :     }
218 :     else
219 :     {
220 :     start_timer();
221 :     dequant4_inter(data[i], qcoeff[i], iQuant);
222 :     stop_iquant_timer();
223 :     }
224 :    
225 :     cbp |= 1 << (5 - i);
226 :    
227 :     start_timer();
228 :     idct(data[i]);
229 :     stop_idct_timer();
230 :    
231 :     start_timer();
232 :    
233 :     switch(i) {
234 :     case 0:
235 :     transfer_16to8add(pY_Cur, data[0], stride);
236 :     break;
237 :     case 1:
238 :     transfer_16to8add(pY_Cur + 8, data[1], stride);
239 :     break;
240 :     case 2:
241 :     transfer_16to8add(pY_Cur + 8 * stride, data[2], stride);
242 :     break;
243 :     case 3:
244 :     transfer_16to8add(pY_Cur + 8 + 8 * stride, data[3], stride);
245 :     break;
246 :     case 4:
247 :     transfer_16to8add(pU_Cur, data[4], stride / 2);
248 :     break;
249 :     case 5:
250 :     transfer_16to8add(pV_Cur, data[5], stride / 2);
251 :     break;
252 :     }
253 :     stop_transfer_timer();
254 :     }
255 :     }
256 :     return cbp;
257 :     }

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