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