Parent Directory
|
Revision Log
Revision 851 - (view) (download)
1 : | edgomez | 851 | /****************************************************************************** |
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 : | Isibaar | 3 | |
30 : | edgomez | 851 | /****************************************************************************** |
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 : | * 29.03.2002 interlacing speedup - used transfer strides instead of * | ||
46 : | * manual field-to-frame conversion * | ||
47 : | * 26.03.2002 interlacing support - moved transfers outside loops * | ||
48 : | * 22.12.2001 get_dc_scaler() moved to common.h * | ||
49 : | * 19.11.2001 introduced coefficient thresholding (Isibaar) * | ||
50 : | * 17.11.2001 initial version * | ||
51 : | * * | ||
52 : | ******************************************************************************/ | ||
53 : | |||
54 : | edgomez | 78 | #include <string.h> |
55 : | |||
56 : | Isibaar | 3 | #include "../portab.h" |
57 : | #include "mbfunctions.h" | ||
58 : | |||
59 : | #include "../global.h" | ||
60 : | #include "mem_transfer.h" | ||
61 : | #include "timer.h" | ||
62 : | #include "../dct/fdct.h" | ||
63 : | #include "../dct/idct.h" | ||
64 : | #include "../quant/quant_mpeg4.h" | ||
65 : | #include "../quant/quant_h263.h" | ||
66 : | #include "../encoder.h" | ||
67 : | |||
68 : | edgomez | 851 | #include "../image/reduced.h" |
69 : | Isibaar | 3 | |
70 : | edgomez | 851 | MBFIELDTEST_PTR MBFieldTest; |
71 : | Isibaar | 3 | |
72 : | edgomez | 851 | #define TOOSMALL_LIMIT 1 /* skip blocks having a coefficient sum below this value */ |
73 : | Isibaar | 3 | |
74 : | edgomez | 195 | void |
75 : | MBTransQuantIntra(const MBParam * pParam, | ||
76 : | FRAMEINFO * frame, | ||
77 : | MACROBLOCK * pMB, | ||
78 : | const uint32_t x_pos, | ||
79 : | const uint32_t y_pos, | ||
80 : | int16_t data[6 * 64], | ||
81 : | int16_t qcoeff[6 * 64]) | ||
82 : | Isibaar | 3 | { |
83 : | edgomez | 78 | |
84 : | h | 82 | uint32_t stride = pParam->edged_width; |
85 : | uint32_t stride2 = stride / 2; | ||
86 : | edgomez | 851 | uint32_t next_block = stride * ((frame->global_flags & XVID_REDUCED)?16:8); |
87 : | Isibaar | 3 | uint32_t i; |
88 : | suxen_drol | 136 | uint32_t iQuant = frame->quant; |
89 : | Isibaar | 3 | uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
90 : | edgomez | 195 | IMAGE *pCurrent = &frame->image; |
91 : | Isibaar | 3 | |
92 : | edgomez | 851 | start_timer(); |
93 : | if ((frame->global_flags & XVID_REDUCED)) | ||
94 : | { | ||
95 : | pY_Cur = pCurrent->y + (y_pos << 5) * stride + (x_pos << 5); | ||
96 : | pU_Cur = pCurrent->u + (y_pos << 4) * stride2 + (x_pos << 4); | ||
97 : | pV_Cur = pCurrent->v + (y_pos << 4) * stride2 + (x_pos << 4); | ||
98 : | h | 69 | |
99 : | edgomez | 851 | filter_18x18_to_8x8(&data[0 * 64], pY_Cur, stride); |
100 : | filter_18x18_to_8x8(&data[1 * 64], pY_Cur + 16, stride); | ||
101 : | filter_18x18_to_8x8(&data[2 * 64], pY_Cur + next_block, stride); | ||
102 : | filter_18x18_to_8x8(&data[3 * 64], pY_Cur + next_block + 16, stride); | ||
103 : | filter_18x18_to_8x8(&data[4 * 64], pU_Cur, stride2); | ||
104 : | filter_18x18_to_8x8(&data[5 * 64], pV_Cur, stride2); | ||
105 : | }else{ | ||
106 : | pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); | ||
107 : | pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); | ||
108 : | pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3); | ||
109 : | |||
110 : | transfer_8to16copy(&data[0 * 64], pY_Cur, stride); | ||
111 : | transfer_8to16copy(&data[1 * 64], pY_Cur + 8, stride); | ||
112 : | transfer_8to16copy(&data[2 * 64], pY_Cur + next_block, stride); | ||
113 : | transfer_8to16copy(&data[3 * 64], pY_Cur + next_block + 8, stride); | ||
114 : | transfer_8to16copy(&data[4 * 64], pU_Cur, stride2); | ||
115 : | transfer_8to16copy(&data[5 * 64], pV_Cur, stride2); | ||
116 : | } | ||
117 : | h | 69 | stop_transfer_timer(); |
118 : | |||
119 : | edgomez | 851 | /* XXX: rrv+interlacing is buggy */ |
120 : | h | 69 | start_timer(); |
121 : | pMB->field_dct = 0; | ||
122 : | h | 390 | if ((frame->global_flags & XVID_INTERLACING) && |
123 : | (x_pos>0) && (x_pos<pParam->mb_width-1) && | ||
124 : | (y_pos>0) && (y_pos<pParam->mb_height-1)) { | ||
125 : | h | 69 | pMB->field_dct = MBDecideFieldDCT(data); |
126 : | } | ||
127 : | stop_interlacing_timer(); | ||
128 : | |||
129 : | edgomez | 195 | for (i = 0; i < 6; i++) { |
130 : | Isibaar | 3 | uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
131 : | |||
132 : | start_timer(); | ||
133 : | edgomez | 195 | fdct(&data[i * 64]); |
134 : | Isibaar | 3 | stop_dct_timer(); |
135 : | |||
136 : | edgomez | 195 | if (pParam->m_quant_type == H263_QUANT) { |
137 : | Isibaar | 3 | start_timer(); |
138 : | edgomez | 195 | quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler); |
139 : | Isibaar | 3 | stop_quant_timer(); |
140 : | edgomez | 195 | } else { |
141 : | Isibaar | 3 | start_timer(); |
142 : | edgomez | 195 | quant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler); |
143 : | Isibaar | 3 | stop_quant_timer(); |
144 : | edgomez | 851 | } |
145 : | Isibaar | 3 | |
146 : | edgomez | 851 | /* speedup: dont decode when encoding only ivops */ |
147 : | if (pParam->iMaxKeyInterval != 1 || pParam->max_bframes > 0) | ||
148 : | { | ||
149 : | if (pParam->m_quant_type == H263_QUANT) { | ||
150 : | start_timer(); | ||
151 : | dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler); | ||
152 : | stop_iquant_timer(); | ||
153 : | } else { | ||
154 : | start_timer(); | ||
155 : | dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler); | ||
156 : | stop_iquant_timer(); | ||
157 : | } | ||
158 : | |||
159 : | Isibaar | 3 | start_timer(); |
160 : | edgomez | 851 | idct(&data[i * 64]); |
161 : | stop_idct_timer(); | ||
162 : | Isibaar | 3 | } |
163 : | edgomez | 851 | } |
164 : | Isibaar | 3 | |
165 : | edgomez | 851 | /* speedup: dont decode when encoding only ivops */ |
166 : | if (pParam->iMaxKeyInterval != 1 || pParam->max_bframes > 0) | ||
167 : | { | ||
168 : | |||
169 : | if (pMB->field_dct) { | ||
170 : | next_block = stride; | ||
171 : | stride *= 2; | ||
172 : | } | ||
173 : | |||
174 : | Isibaar | 3 | start_timer(); |
175 : | edgomez | 851 | if ((frame->global_flags & XVID_REDUCED)) |
176 : | { | ||
177 : | copy_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride); | ||
178 : | copy_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride); | ||
179 : | copy_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride); | ||
180 : | copy_upsampled_8x8_16to8(pY_Cur + next_block + 16, &data[3 * 64], stride); | ||
181 : | copy_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2); | ||
182 : | copy_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2); | ||
183 : | Isibaar | 3 | |
184 : | edgomez | 851 | }else{ |
185 : | transfer_16to8copy(pY_Cur, &data[0 * 64], stride); | ||
186 : | transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride); | ||
187 : | transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride); | ||
188 : | transfer_16to8copy(pY_Cur + next_block + 8, &data[3 * 64], stride); | ||
189 : | transfer_16to8copy(pU_Cur, &data[4 * 64], stride2); | ||
190 : | transfer_16to8copy(pV_Cur, &data[5 * 64], stride2); | ||
191 : | } | ||
192 : | stop_transfer_timer(); | ||
193 : | h | 69 | } |
194 : | |||
195 : | Isibaar | 3 | } |
196 : | |||
197 : | |||
198 : | edgomez | 195 | uint8_t |
199 : | MBTransQuantInter(const MBParam * pParam, | ||
200 : | FRAMEINFO * frame, | ||
201 : | MACROBLOCK * pMB, | ||
202 : | const uint32_t x_pos, | ||
203 : | const uint32_t y_pos, | ||
204 : | int16_t data[6 * 64], | ||
205 : | int16_t qcoeff[6 * 64]) | ||
206 : | Isibaar | 3 | { |
207 : | edgomez | 78 | |
208 : | h | 82 | uint32_t stride = pParam->edged_width; |
209 : | uint32_t stride2 = stride / 2; | ||
210 : | edgomez | 851 | uint32_t next_block = stride * ((frame->global_flags & XVID_REDUCED)?16:8); |
211 : | edgomez | 78 | uint32_t i; |
212 : | suxen_drol | 136 | uint32_t iQuant = frame->quant; |
213 : | Isibaar | 3 | uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
214 : | edgomez | 78 | uint8_t cbp = 0; |
215 : | Isibaar | 3 | uint32_t sum; |
216 : | edgomez | 195 | IMAGE *pCurrent = &frame->image; |
217 : | |||
218 : | edgomez | 851 | if ((frame->global_flags & XVID_REDUCED)) |
219 : | { | ||
220 : | pY_Cur = pCurrent->y + (y_pos << 5) * stride + (x_pos << 5); | ||
221 : | pU_Cur = pCurrent->u + (y_pos << 4) * stride2 + (x_pos << 4); | ||
222 : | pV_Cur = pCurrent->v + (y_pos << 4) * stride2 + (x_pos << 4); | ||
223 : | }else{ | ||
224 : | pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); | ||
225 : | pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); | ||
226 : | pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3); | ||
227 : | } | ||
228 : | Isibaar | 3 | |
229 : | h | 69 | start_timer(); |
230 : | pMB->field_dct = 0; | ||
231 : | h | 390 | if ((frame->global_flags & XVID_INTERLACING) && |
232 : | (x_pos>0) && (x_pos<pParam->mb_width-1) && | ||
233 : | (y_pos>0) && (y_pos<pParam->mb_height-1)) { | ||
234 : | h | 69 | pMB->field_dct = MBDecideFieldDCT(data); |
235 : | } | ||
236 : | stop_interlacing_timer(); | ||
237 : | |||
238 : | edgomez | 195 | for (i = 0; i < 6; i++) { |
239 : | edgomez | 851 | uint32_t increase_limit = (iQuant == 1) ? 1 : 0; |
240 : | |||
241 : | Isibaar | 3 | /* |
242 : | edgomez | 78 | * no need to transfer 8->16-bit |
243 : | * (this is performed already in motion compensation) | ||
244 : | */ | ||
245 : | Isibaar | 3 | start_timer(); |
246 : | edgomez | 195 | fdct(&data[i * 64]); |
247 : | Isibaar | 3 | stop_dct_timer(); |
248 : | |||
249 : | edgomez | 195 | if (pParam->m_quant_type == 0) { |
250 : | Isibaar | 3 | start_timer(); |
251 : | edgomez | 195 | sum = quant_inter(&qcoeff[i * 64], &data[i * 64], iQuant); |
252 : | Isibaar | 3 | stop_quant_timer(); |
253 : | edgomez | 195 | } else { |
254 : | Isibaar | 3 | start_timer(); |
255 : | edgomez | 195 | sum = quant4_inter(&qcoeff[i * 64], &data[i * 64], iQuant); |
256 : | Isibaar | 3 | stop_quant_timer(); |
257 : | } | ||
258 : | |||
259 : | edgomez | 851 | if ((sum >= TOOSMALL_LIMIT + increase_limit) || (qcoeff[i*64] != 0) || |
260 : | Isibaar | 375 | (qcoeff[i*64+1] != 0) || (qcoeff[i*64+8] != 0)) { |
261 : | Isibaar | 3 | |
262 : | edgomez | 195 | if (pParam->m_quant_type == H263_QUANT) { |
263 : | Isibaar | 3 | start_timer(); |
264 : | edgomez | 195 | dequant_inter(&data[i * 64], &qcoeff[i * 64], iQuant); |
265 : | Isibaar | 3 | stop_iquant_timer(); |
266 : | edgomez | 195 | } else { |
267 : | Isibaar | 3 | start_timer(); |
268 : | edgomez | 195 | dequant4_inter(&data[i * 64], &qcoeff[i * 64], iQuant); |
269 : | Isibaar | 3 | stop_iquant_timer(); |
270 : | } | ||
271 : | |||
272 : | cbp |= 1 << (5 - i); | ||
273 : | |||
274 : | start_timer(); | ||
275 : | edgomez | 195 | idct(&data[i * 64]); |
276 : | Isibaar | 3 | stop_idct_timer(); |
277 : | } | ||
278 : | } | ||
279 : | h | 69 | |
280 : | edgomez | 195 | if (pMB->field_dct) { |
281 : | h | 82 | next_block = stride; |
282 : | stride *= 2; | ||
283 : | h | 69 | } |
284 : | |||
285 : | start_timer(); | ||
286 : | edgomez | 851 | if ((frame->global_flags & XVID_REDUCED)) |
287 : | { | ||
288 : | if (cbp & 32) | ||
289 : | add_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride); | ||
290 : | if (cbp & 16) | ||
291 : | add_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride); | ||
292 : | if (cbp & 8) | ||
293 : | add_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride); | ||
294 : | if (cbp & 4) | ||
295 : | add_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride); | ||
296 : | if (cbp & 2) | ||
297 : | add_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2); | ||
298 : | if (cbp & 1) | ||
299 : | add_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2); | ||
300 : | }else{ | ||
301 : | if (cbp & 32) | ||
302 : | transfer_16to8add(pY_Cur, &data[0 * 64], stride); | ||
303 : | if (cbp & 16) | ||
304 : | transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride); | ||
305 : | if (cbp & 8) | ||
306 : | transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride); | ||
307 : | if (cbp & 4) | ||
308 : | transfer_16to8add(pY_Cur + next_block + 8, &data[3 * 64], stride); | ||
309 : | if (cbp & 2) | ||
310 : | transfer_16to8add(pU_Cur, &data[4 * 64], stride2); | ||
311 : | if (cbp & 1) | ||
312 : | transfer_16to8add(pV_Cur, &data[5 * 64], stride2); | ||
313 : | } | ||
314 : | h | 69 | stop_transfer_timer(); |
315 : | |||
316 : | edgomez | 78 | return cbp; |
317 : | |||
318 : | Isibaar | 3 | } |
319 : | h | 69 | |
320 : | chl | 368 | void |
321 : | MBTransQuantIntra2(const MBParam * pParam, | ||
322 : | FRAMEINFO * frame, | ||
323 : | MACROBLOCK * pMB, | ||
324 : | const uint32_t x_pos, | ||
325 : | const uint32_t y_pos, | ||
326 : | int16_t data[6 * 64], | ||
327 : | int16_t qcoeff[6 * 64]) | ||
328 : | { | ||
329 : | MBTrans(pParam,frame,pMB,x_pos,y_pos,data); | ||
330 : | MBfDCT(pParam,frame,pMB,data); | ||
331 : | MBQuantIntra(pParam,frame,pMB,data,qcoeff); | ||
332 : | MBDeQuantIntra(pParam,frame->quant,data,qcoeff); | ||
333 : | MBiDCT(data,0x3F); | ||
334 : | MBTransAdd(pParam,frame,pMB,x_pos,y_pos,data,0x3F); | ||
335 : | } | ||
336 : | h | 69 | |
337 : | chl | 368 | |
338 : | uint8_t | ||
339 : | MBTransQuantInter2(const MBParam * pParam, | ||
340 : | FRAMEINFO * frame, | ||
341 : | MACROBLOCK * pMB, | ||
342 : | const uint32_t x_pos, | ||
343 : | const uint32_t y_pos, | ||
344 : | int16_t data[6 * 64], | ||
345 : | int16_t qcoeff[6 * 64]) | ||
346 : | { | ||
347 : | uint8_t cbp; | ||
348 : | |||
349 : | /* there is no MBTrans for Inter block, that's done in motion compensation already */ | ||
350 : | |||
351 : | MBfDCT(pParam,frame,pMB,data); | ||
352 : | cbp = MBQuantInter(pParam,frame->quant,data,qcoeff); | ||
353 : | MBDeQuantInter(pParam,frame->quant,data,qcoeff,cbp); | ||
354 : | MBiDCT(data,cbp); | ||
355 : | MBTransAdd(pParam,frame,pMB,x_pos,y_pos,data,cbp); | ||
356 : | |||
357 : | return cbp; | ||
358 : | } | ||
359 : | |||
360 : | uint8_t | ||
361 : | MBTransQuantInterBVOP(const MBParam * pParam, | ||
362 : | FRAMEINFO * frame, | ||
363 : | MACROBLOCK * pMB, | ||
364 : | int16_t data[6 * 64], | ||
365 : | int16_t qcoeff[6 * 64]) | ||
366 : | { | ||
367 : | uint8_t cbp; | ||
368 : | |||
369 : | /* there is no MBTrans for Inter block, that's done in motion compensation already */ | ||
370 : | |||
371 : | MBfDCT(pParam,frame,pMB,data); | ||
372 : | cbp = MBQuantInter(pParam,frame->quant,data,qcoeff); | ||
373 : | |||
374 : | /* we don't have to DeQuant, iDCT and Transfer back data for B-frames */ | ||
375 : | |||
376 : | return cbp; | ||
377 : | } | ||
378 : | |||
379 : | |||
380 : | void | ||
381 : | MBfDCT(const MBParam * pParam, | ||
382 : | FRAMEINFO * frame, | ||
383 : | MACROBLOCK * pMB, | ||
384 : | int16_t data[6 * 64]) | ||
385 : | { | ||
386 : | int i; | ||
387 : | |||
388 : | start_timer(); | ||
389 : | pMB->field_dct = 0; | ||
390 : | if ((frame->global_flags & XVID_INTERLACING)) { | ||
391 : | pMB->field_dct = MBDecideFieldDCT(data); | ||
392 : | } | ||
393 : | stop_interlacing_timer(); | ||
394 : | |||
395 : | for (i = 0; i < 6; i++) { | ||
396 : | start_timer(); | ||
397 : | fdct(&data[i * 64]); | ||
398 : | stop_dct_timer(); | ||
399 : | } | ||
400 : | } | ||
401 : | |||
402 : | void | ||
403 : | MBQuantDeQuantIntra(const MBParam * pParam, | ||
404 : | FRAMEINFO * frame, | ||
405 : | MACROBLOCK * pMB, | ||
406 : | int16_t qcoeff[6 * 64], | ||
407 : | int16_t data[6*64]) | ||
408 : | { | ||
409 : | int i; | ||
410 : | int iQuant = frame->quant; | ||
411 : | |||
412 : | start_timer(); | ||
413 : | pMB->field_dct = 0; | ||
414 : | if ((frame->global_flags & XVID_INTERLACING)) { | ||
415 : | pMB->field_dct = MBDecideFieldDCT(data); | ||
416 : | } | ||
417 : | stop_interlacing_timer(); | ||
418 : | |||
419 : | for (i = 0; i < 6; i++) { | ||
420 : | uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); | ||
421 : | |||
422 : | if (pParam->m_quant_type == H263_QUANT) { | ||
423 : | start_timer(); | ||
424 : | quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler); | ||
425 : | stop_quant_timer(); | ||
426 : | |||
427 : | start_timer(); | ||
428 : | dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler); | ||
429 : | stop_iquant_timer(); | ||
430 : | } else { | ||
431 : | start_timer(); | ||
432 : | quant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler); | ||
433 : | stop_quant_timer(); | ||
434 : | |||
435 : | start_timer(); | ||
436 : | dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler); | ||
437 : | stop_iquant_timer(); | ||
438 : | } | ||
439 : | } | ||
440 : | } | ||
441 : | |||
442 : | void | ||
443 : | MBQuantIntra(const MBParam * pParam, | ||
444 : | FRAMEINFO * frame, | ||
445 : | MACROBLOCK *pMB, | ||
446 : | edgomez | 851 | int16_t qcoeff[6 * 64], |
447 : | int16_t data[6*64]) | ||
448 : | chl | 368 | { |
449 : | int i; | ||
450 : | int iQuant = frame->quant; | ||
451 : | |||
452 : | start_timer(); | ||
453 : | pMB->field_dct = 0; | ||
454 : | if ((frame->global_flags & XVID_INTERLACING)) { | ||
455 : | pMB->field_dct = MBDecideFieldDCT(data); | ||
456 : | } | ||
457 : | stop_interlacing_timer(); | ||
458 : | |||
459 : | for (i = 0; i < 6; i++) { | ||
460 : | uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); | ||
461 : | |||
462 : | if (pParam->m_quant_type == H263_QUANT) { | ||
463 : | start_timer(); | ||
464 : | quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler); | ||
465 : | stop_quant_timer(); | ||
466 : | } else { | ||
467 : | start_timer(); | ||
468 : | quant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler); | ||
469 : | stop_quant_timer(); | ||
470 : | } | ||
471 : | } | ||
472 : | } | ||
473 : | |||
474 : | void | ||
475 : | MBDeQuantIntra(const MBParam * pParam, | ||
476 : | const int iQuant, | ||
477 : | int16_t qcoeff[6 * 64], | ||
478 : | int16_t data[6*64]) | ||
479 : | { | ||
480 : | int i; | ||
481 : | |||
482 : | for (i = 0; i < 6; i++) { | ||
483 : | uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); | ||
484 : | |||
485 : | if (pParam->m_quant_type == H263_QUANT) { | ||
486 : | start_timer(); | ||
487 : | dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler); | ||
488 : | stop_iquant_timer(); | ||
489 : | } else { | ||
490 : | start_timer(); | ||
491 : | dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler); | ||
492 : | stop_iquant_timer(); | ||
493 : | } | ||
494 : | } | ||
495 : | } | ||
496 : | |||
497 : | uint8_t | ||
498 : | MBQuantInter(const MBParam * pParam, | ||
499 : | const int iQuant, | ||
500 : | int16_t data[6 * 64], | ||
501 : | int16_t qcoeff[6 * 64]) | ||
502 : | { | ||
503 : | |||
504 : | int i; | ||
505 : | uint8_t cbp = 0; | ||
506 : | int sum; | ||
507 : | |||
508 : | for (i = 0; i < 6; i++) { | ||
509 : | |||
510 : | if (pParam->m_quant_type == 0) { | ||
511 : | start_timer(); | ||
512 : | sum = quant_inter(&qcoeff[i * 64], &data[i * 64], iQuant); | ||
513 : | stop_quant_timer(); | ||
514 : | } else { | ||
515 : | start_timer(); | ||
516 : | sum = quant4_inter(&qcoeff[i * 64], &data[i * 64], iQuant); | ||
517 : | stop_quant_timer(); | ||
518 : | } | ||
519 : | |||
520 : | edgomez | 851 | if (sum >= TOOSMALL_LIMIT) { // skip block ? |
521 : | chl | 368 | cbp |= 1 << (5 - i); |
522 : | } | ||
523 : | } | ||
524 : | return cbp; | ||
525 : | } | ||
526 : | |||
527 : | void | ||
528 : | MBDeQuantInter( const MBParam * pParam, | ||
529 : | const int iQuant, | ||
530 : | int16_t data[6 * 64], | ||
531 : | int16_t qcoeff[6 * 64], | ||
532 : | const uint8_t cbp) | ||
533 : | { | ||
534 : | int i; | ||
535 : | |||
536 : | for (i = 0; i < 6; i++) { | ||
537 : | if (cbp & (1 << (5 - i))) | ||
538 : | { | ||
539 : | if (pParam->m_quant_type == H263_QUANT) { | ||
540 : | start_timer(); | ||
541 : | dequant_inter(&data[i * 64], &qcoeff[i * 64], iQuant); | ||
542 : | stop_iquant_timer(); | ||
543 : | } else { | ||
544 : | start_timer(); | ||
545 : | dequant4_inter(&data[i * 64], &qcoeff[i * 64], iQuant); | ||
546 : | stop_iquant_timer(); | ||
547 : | } | ||
548 : | } | ||
549 : | } | ||
550 : | } | ||
551 : | |||
552 : | void | ||
553 : | MBiDCT( int16_t data[6 * 64], | ||
554 : | const uint8_t cbp) | ||
555 : | { | ||
556 : | int i; | ||
557 : | |||
558 : | for (i = 0; i < 6; i++) { | ||
559 : | if (cbp & (1 << (5 - i))) | ||
560 : | { | ||
561 : | start_timer(); | ||
562 : | idct(&data[i * 64]); | ||
563 : | stop_idct_timer(); | ||
564 : | |||
565 : | } | ||
566 : | } | ||
567 : | } | ||
568 : | |||
569 : | |||
570 : | void | ||
571 : | MBTrans(const MBParam * pParam, | ||
572 : | FRAMEINFO * frame, | ||
573 : | MACROBLOCK * pMB, | ||
574 : | const uint32_t x_pos, | ||
575 : | const uint32_t y_pos, | ||
576 : | int16_t data[6 * 64]) | ||
577 : | { | ||
578 : | uint32_t stride = pParam->edged_width; | ||
579 : | uint32_t stride2 = stride / 2; | ||
580 : | uint32_t next_block = stride * 8; | ||
581 : | uint8_t *pY_Cur, *pU_Cur, *pV_Cur; | ||
582 : | IMAGE *pCurrent = &frame->image; | ||
583 : | |||
584 : | pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); | ||
585 : | pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); | ||
586 : | pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3); | ||
587 : | |||
588 : | start_timer(); | ||
589 : | transfer_8to16copy(&data[0 * 64], pY_Cur, stride); | ||
590 : | transfer_8to16copy(&data[1 * 64], pY_Cur + 8, stride); | ||
591 : | transfer_8to16copy(&data[2 * 64], pY_Cur + next_block, stride); | ||
592 : | transfer_8to16copy(&data[3 * 64], pY_Cur + next_block + 8, stride); | ||
593 : | transfer_8to16copy(&data[4 * 64], pU_Cur, stride2); | ||
594 : | transfer_8to16copy(&data[5 * 64], pV_Cur, stride2); | ||
595 : | stop_transfer_timer(); | ||
596 : | } | ||
597 : | |||
598 : | void | ||
599 : | MBTransAdd(const MBParam * pParam, | ||
600 : | FRAMEINFO * frame, | ||
601 : | MACROBLOCK * pMB, | ||
602 : | const uint32_t x_pos, | ||
603 : | const uint32_t y_pos, | ||
604 : | int16_t data[6 * 64], | ||
605 : | const uint8_t cbp) | ||
606 : | { | ||
607 : | uint8_t *pY_Cur, *pU_Cur, *pV_Cur; | ||
608 : | uint32_t stride = pParam->edged_width; | ||
609 : | uint32_t stride2 = stride / 2; | ||
610 : | uint32_t next_block = stride * 8; | ||
611 : | IMAGE *pCurrent = &frame->image; | ||
612 : | |||
613 : | pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); | ||
614 : | pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); | ||
615 : | pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3); | ||
616 : | |||
617 : | if (pMB->field_dct) { | ||
618 : | next_block = stride; | ||
619 : | stride *= 2; | ||
620 : | } | ||
621 : | |||
622 : | start_timer(); | ||
623 : | if (cbp & 32) | ||
624 : | transfer_16to8add(pY_Cur, &data[0 * 64], stride); | ||
625 : | if (cbp & 16) | ||
626 : | transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride); | ||
627 : | if (cbp & 8) | ||
628 : | transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride); | ||
629 : | if (cbp & 4) | ||
630 : | transfer_16to8add(pY_Cur + next_block + 8, &data[3 * 64], stride); | ||
631 : | if (cbp & 2) | ||
632 : | transfer_16to8add(pU_Cur, &data[4 * 64], stride2); | ||
633 : | if (cbp & 1) | ||
634 : | transfer_16to8add(pV_Cur, &data[5 * 64], stride2); | ||
635 : | stop_transfer_timer(); | ||
636 : | } | ||
637 : | |||
638 : | |||
639 : | |||
640 : | edgomez | 851 | /* permute block and return field dct choice */ |
641 : | h | 69 | |
642 : | |||
643 : | edgomez | 195 | uint32_t |
644 : | MBDecideFieldDCT(int16_t data[6 * 64]) | ||
645 : | h | 69 | { |
646 : | edgomez | 851 | uint32_t field = MBFieldTest(data); |
647 : | h | 69 | |
648 : | edgomez | 851 | if (field) { |
649 : | MBFrameToField(data); | ||
650 : | } | ||
651 : | |||
652 : | return field; | ||
653 : | } | ||
654 : | |||
655 : | |||
656 : | /* if sum(diff between field lines) < sum(diff between frame lines), use field dct */ | ||
657 : | |||
658 : | uint32_t | ||
659 : | MBFieldTest_c(int16_t data[6 * 64]) | ||
660 : | { | ||
661 : | edgomez | 195 | const uint8_t blocks[] = |
662 : | { 0 * 64, 0 * 64, 0 * 64, 0 * 64, 2 * 64, 2 * 64, 2 * 64, 2 * 64 }; | ||
663 : | const uint8_t lines[] = { 0, 16, 32, 48, 0, 16, 32, 48 }; | ||
664 : | edgomez | 78 | |
665 : | h | 69 | int frame = 0, field = 0; |
666 : | int i, j; | ||
667 : | |||
668 : | edgomez | 195 | for (i = 0; i < 7; ++i) { |
669 : | for (j = 0; j < 8; ++j) { | ||
670 : | frame += | ||
671 : | ABS(data[0 * 64 + (i + 1) * 8 + j] - data[0 * 64 + i * 8 + j]); | ||
672 : | frame += | ||
673 : | ABS(data[1 * 64 + (i + 1) * 8 + j] - data[1 * 64 + i * 8 + j]); | ||
674 : | frame += | ||
675 : | ABS(data[2 * 64 + (i + 1) * 8 + j] - data[2 * 64 + i * 8 + j]); | ||
676 : | frame += | ||
677 : | ABS(data[3 * 64 + (i + 1) * 8 + j] - data[3 * 64 + i * 8 + j]); | ||
678 : | h | 69 | |
679 : | edgomez | 195 | field += |
680 : | ABS(data[blocks[i + 1] + lines[i + 1] + j] - | ||
681 : | data[blocks[i] + lines[i] + j]); | ||
682 : | field += | ||
683 : | ABS(data[blocks[i + 1] + lines[i + 1] + 8 + j] - | ||
684 : | data[blocks[i] + lines[i] + 8 + j]); | ||
685 : | field += | ||
686 : | ABS(data[blocks[i + 1] + 64 + lines[i + 1] + j] - | ||
687 : | data[blocks[i] + 64 + lines[i] + j]); | ||
688 : | field += | ||
689 : | ABS(data[blocks[i + 1] + 64 + lines[i + 1] + 8 + j] - | ||
690 : | data[blocks[i] + 64 + lines[i] + 8 + j]); | ||
691 : | h | 69 | } |
692 : | } | ||
693 : | |||
694 : | edgomez | 851 | return (frame >= (field + 350)); |
695 : | h | 69 | } |
696 : | |||
697 : | |||
698 : | /* deinterlace Y blocks vertically */ | ||
699 : | |||
700 : | #define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp)) | ||
701 : | edgomez | 78 | #define LINE(X,Y) &data[X*64 + Y*8] |
702 : | h | 69 | |
703 : | edgomez | 195 | void |
704 : | MBFrameToField(int16_t data[6 * 64]) | ||
705 : | h | 69 | { |
706 : | int16_t tmp[8]; | ||
707 : | |||
708 : | /* left blocks */ | ||
709 : | |||
710 : | edgomez | 851 | // 1=2, 2=4, 4=8, 8=1 |
711 : | edgomez | 195 | MOVLINE(tmp, LINE(0, 1)); |
712 : | MOVLINE(LINE(0, 1), LINE(0, 2)); | ||
713 : | MOVLINE(LINE(0, 2), LINE(0, 4)); | ||
714 : | MOVLINE(LINE(0, 4), LINE(2, 0)); | ||
715 : | MOVLINE(LINE(2, 0), tmp); | ||
716 : | h | 69 | |
717 : | edgomez | 851 | // 3=6, 6=12, 12=9, 9=3 |
718 : | edgomez | 195 | MOVLINE(tmp, LINE(0, 3)); |
719 : | MOVLINE(LINE(0, 3), LINE(0, 6)); | ||
720 : | MOVLINE(LINE(0, 6), LINE(2, 4)); | ||
721 : | MOVLINE(LINE(2, 4), LINE(2, 1)); | ||
722 : | MOVLINE(LINE(2, 1), tmp); | ||
723 : | h | 69 | |
724 : | edgomez | 851 | // 5=10, 10=5 |
725 : | edgomez | 195 | MOVLINE(tmp, LINE(0, 5)); |
726 : | MOVLINE(LINE(0, 5), LINE(2, 2)); | ||
727 : | MOVLINE(LINE(2, 2), tmp); | ||
728 : | h | 69 | |
729 : | edgomez | 851 | // 7=14, 14=13, 13=11, 11=7 |
730 : | edgomez | 195 | MOVLINE(tmp, LINE(0, 7)); |
731 : | MOVLINE(LINE(0, 7), LINE(2, 6)); | ||
732 : | MOVLINE(LINE(2, 6), LINE(2, 5)); | ||
733 : | MOVLINE(LINE(2, 5), LINE(2, 3)); | ||
734 : | MOVLINE(LINE(2, 3), tmp); | ||
735 : | h | 69 | |
736 : | /* right blocks */ | ||
737 : | |||
738 : | edgomez | 851 | // 1=2, 2=4, 4=8, 8=1 |
739 : | edgomez | 195 | MOVLINE(tmp, LINE(1, 1)); |
740 : | MOVLINE(LINE(1, 1), LINE(1, 2)); | ||
741 : | MOVLINE(LINE(1, 2), LINE(1, 4)); | ||
742 : | MOVLINE(LINE(1, 4), LINE(3, 0)); | ||
743 : | MOVLINE(LINE(3, 0), tmp); | ||
744 : | h | 69 | |
745 : | edgomez | 851 | // 3=6, 6=12, 12=9, 9=3 |
746 : | edgomez | 195 | MOVLINE(tmp, LINE(1, 3)); |
747 : | MOVLINE(LINE(1, 3), LINE(1, 6)); | ||
748 : | MOVLINE(LINE(1, 6), LINE(3, 4)); | ||
749 : | MOVLINE(LINE(3, 4), LINE(3, 1)); | ||
750 : | MOVLINE(LINE(3, 1), tmp); | ||
751 : | h | 69 | |
752 : | edgomez | 851 | // 5=10, 10=5 |
753 : | edgomez | 195 | MOVLINE(tmp, LINE(1, 5)); |
754 : | MOVLINE(LINE(1, 5), LINE(3, 2)); | ||
755 : | MOVLINE(LINE(3, 2), tmp); | ||
756 : | h | 69 | |
757 : | edgomez | 851 | // 7=14, 14=13, 13=11, 11=7 |
758 : | edgomez | 195 | MOVLINE(tmp, LINE(1, 7)); |
759 : | MOVLINE(LINE(1, 7), LINE(3, 6)); | ||
760 : | MOVLINE(LINE(3, 6), LINE(3, 5)); | ||
761 : | MOVLINE(LINE(3, 5), LINE(3, 3)); | ||
762 : | MOVLINE(LINE(3, 3), tmp); | ||
763 : | h | 69 | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |