Parent Directory
|
Revision Log
Revision 1.6 - (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 : | h | 1.4 | * 29.03.2002 interlacing speedup - used transfer strides instead of |
46 : | * manual field-to-frame conversion | ||
47 : | h | 1.2 | * 26.03.2002 interlacing support - moved transfers outside loops |
48 : | Isibaar | 1.1 | * 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 | 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 : | #define TOOSMALL_LIMIT 1 /* skip blocks having a coefficient sum below this value */ | ||
72 : | |||
73 : | /* this isnt pretty, but its better than 20 ifdefs */ | ||
74 : | |||
75 : | void MBTransQuantIntra(const MBParam *pParam, | ||
76 : | suxen_drol | 1.6 | FRAMEINFO * frame, |
77 : | edgomez | 1.3 | MACROBLOCK * pMB, |
78 : | Isibaar | 1.1 | const uint32_t x_pos, |
79 : | const uint32_t y_pos, | ||
80 : | edgomez | 1.3 | int16_t data[6*64], |
81 : | suxen_drol | 1.6 | int16_t qcoeff[6*64]) |
82 : | Isibaar | 1.1 | |
83 : | { | ||
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 : | suxen_drol | 1.6 | 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 : | h | 1.4 | 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 : | suxen_drol | 1.6 | if ((frame->global_flags & XVID_INTERLACING)) |
109 : | h | 1.2 | { |
110 : | pMB->field_dct = MBDecideFieldDCT(data); | ||
111 : | } | ||
112 : | stop_interlacing_timer(); | ||
113 : | |||
114 : | for(i = 0; i < 6; i++) | ||
115 : | { | ||
116 : | Isibaar | 1.1 | uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
117 : | |||
118 : | start_timer(); | ||
119 : | edgomez | 1.3 | fdct(&data[i*64]); |
120 : | Isibaar | 1.1 | stop_dct_timer(); |
121 : | |||
122 : | suxen_drol | 1.6 | if (pParam->m_quant_type == H263_QUANT) |
123 : | Isibaar | 1.1 | { |
124 : | start_timer(); | ||
125 : | edgomez | 1.3 | quant_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler); |
126 : | Isibaar | 1.1 | stop_quant_timer(); |
127 : | |||
128 : | start_timer(); | ||
129 : | edgomez | 1.3 | dequant_intra(&data[i*64], &qcoeff[i*64], iQuant, iDcScaler); |
130 : | Isibaar | 1.1 | stop_iquant_timer(); |
131 : | } | ||
132 : | else | ||
133 : | { | ||
134 : | start_timer(); | ||
135 : | edgomez | 1.3 | quant4_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler); |
136 : | Isibaar | 1.1 | stop_quant_timer(); |
137 : | |||
138 : | start_timer(); | ||
139 : | edgomez | 1.3 | dequant4_intra(&data[i*64], &qcoeff[i*64], iQuant, iDcScaler); |
140 : | Isibaar | 1.1 | stop_iquant_timer(); |
141 : | } | ||
142 : | |||
143 : | start_timer(); | ||
144 : | edgomez | 1.3 | idct(&data[i*64]); |
145 : | Isibaar | 1.1 | stop_idct_timer(); |
146 : | edgomez | 1.3 | } |
147 : | h | 1.2 | |
148 : | if (pMB->field_dct) | ||
149 : | { | ||
150 : | h | 1.4 | next_block = stride; |
151 : | stride *= 2; | ||
152 : | h | 1.2 | } |
153 : | Isibaar | 1.1 | |
154 : | h | 1.2 | start_timer(); |
155 : | edgomez | 1.3 | transfer_16to8copy(pY_Cur, &data[0*64], stride); |
156 : | transfer_16to8copy(pY_Cur + 8, &data[1*64], stride); | ||
157 : | h | 1.4 | transfer_16to8copy(pY_Cur + next_block, &data[2*64], stride); |
158 : | transfer_16to8copy(pY_Cur + next_block + 8, &data[3*64], stride); | ||
159 : | transfer_16to8copy(pU_Cur, &data[4*64], stride2); | ||
160 : | transfer_16to8copy(pV_Cur, &data[5*64], stride2); | ||
161 : | h | 1.2 | stop_transfer_timer(); |
162 : | edgomez | 1.3 | |
163 : | Isibaar | 1.1 | } |
164 : | |||
165 : | |||
166 : | uint8_t MBTransQuantInter(const MBParam *pParam, | ||
167 : | suxen_drol | 1.6 | FRAMEINFO * frame, |
168 : | edgomez | 1.3 | MACROBLOCK * pMB, |
169 : | const uint32_t x_pos, const uint32_t y_pos, | ||
170 : | int16_t data[6*64], | ||
171 : | suxen_drol | 1.6 | int16_t qcoeff[6*64]) |
172 : | Isibaar | 1.1 | |
173 : | { | ||
174 : | edgomez | 1.3 | |
175 : | h | 1.4 | uint32_t stride = pParam->edged_width; |
176 : | uint32_t stride2 = stride / 2; | ||
177 : | uint32_t next_block = stride * 8; | ||
178 : | edgomez | 1.3 | uint32_t i; |
179 : | suxen_drol | 1.6 | uint32_t iQuant = frame->quant; |
180 : | Isibaar | 1.1 | uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
181 : | edgomez | 1.3 | uint8_t cbp = 0; |
182 : | Isibaar | 1.1 | uint32_t sum; |
183 : | suxen_drol | 1.6 | IMAGE * pCurrent = &frame->image; |
184 : | Isibaar | 1.1 | |
185 : | edgomez | 1.3 | pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
186 : | h | 1.4 | pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); |
187 : | pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3); | ||
188 : | Isibaar | 1.1 | |
189 : | h | 1.2 | start_timer(); |
190 : | pMB->field_dct = 0; | ||
191 : | suxen_drol | 1.6 | if ((frame->global_flags & XVID_INTERLACING)) |
192 : | h | 1.2 | { |
193 : | pMB->field_dct = MBDecideFieldDCT(data); | ||
194 : | } | ||
195 : | stop_interlacing_timer(); | ||
196 : | |||
197 : | edgomez | 1.3 | for(i = 0; i < 6; i++) |
198 : | h | 1.2 | { |
199 : | Isibaar | 1.1 | /* |
200 : | edgomez | 1.3 | * no need to transfer 8->16-bit |
201 : | * (this is performed already in motion compensation) | ||
202 : | */ | ||
203 : | Isibaar | 1.1 | start_timer(); |
204 : | edgomez | 1.3 | fdct(&data[i*64]); |
205 : | Isibaar | 1.1 | stop_dct_timer(); |
206 : | |||
207 : | suxen_drol | 1.6 | if (pParam->m_quant_type == 0) |
208 : | Isibaar | 1.1 | { |
209 : | start_timer(); | ||
210 : | edgomez | 1.3 | sum = quant_inter(&qcoeff[i*64], &data[i*64], iQuant); |
211 : | Isibaar | 1.1 | stop_quant_timer(); |
212 : | } | ||
213 : | else | ||
214 : | { | ||
215 : | start_timer(); | ||
216 : | edgomez | 1.3 | sum = quant4_inter(&qcoeff[i*64], &data[i*64], iQuant); |
217 : | Isibaar | 1.1 | stop_quant_timer(); |
218 : | } | ||
219 : | |||
220 : | if(sum >= TOOSMALL_LIMIT) { // skip block ? | ||
221 : | |||
222 : | suxen_drol | 1.6 | if (pParam->m_quant_type == H263_QUANT) |
223 : | Isibaar | 1.1 | { |
224 : | start_timer(); | ||
225 : | edgomez | 1.3 | dequant_inter(&data[i*64], &qcoeff[i*64], iQuant); |
226 : | Isibaar | 1.1 | stop_iquant_timer(); |
227 : | } | ||
228 : | else | ||
229 : | { | ||
230 : | start_timer(); | ||
231 : | edgomez | 1.3 | dequant4_inter(&data[i*64], &qcoeff[i*64], iQuant); |
232 : | Isibaar | 1.1 | stop_iquant_timer(); |
233 : | } | ||
234 : | |||
235 : | cbp |= 1 << (5 - i); | ||
236 : | |||
237 : | start_timer(); | ||
238 : | edgomez | 1.3 | idct(&data[i*64]); |
239 : | Isibaar | 1.1 | stop_idct_timer(); |
240 : | h | 1.2 | } |
241 : | } | ||
242 : | |||
243 : | if (pMB->field_dct) | ||
244 : | { | ||
245 : | h | 1.4 | next_block = stride; |
246 : | stride *= 2; | ||
247 : | h | 1.2 | } |
248 : | |||
249 : | start_timer(); | ||
250 : | if (cbp & 32) | ||
251 : | edgomez | 1.3 | transfer_16to8add(pY_Cur, &data[0*64], stride); |
252 : | h | 1.2 | if (cbp & 16) |
253 : | edgomez | 1.3 | transfer_16to8add(pY_Cur + 8, &data[1*64], stride); |
254 : | h | 1.2 | if (cbp & 8) |
255 : | h | 1.4 | transfer_16to8add(pY_Cur + next_block, &data[2*64], stride); |
256 : | h | 1.2 | if (cbp & 4) |
257 : | h | 1.4 | transfer_16to8add(pY_Cur + next_block + 8, &data[3*64], stride); |
258 : | h | 1.2 | if (cbp & 2) |
259 : | h | 1.4 | transfer_16to8add(pU_Cur, &data[4*64], stride2); |
260 : | h | 1.2 | if (cbp & 1) |
261 : | h | 1.4 | transfer_16to8add(pV_Cur, &data[5*64], stride2); |
262 : | h | 1.2 | stop_transfer_timer(); |
263 : | |||
264 : | edgomez | 1.3 | return cbp; |
265 : | |||
266 : | h | 1.2 | } |
267 : | |||
268 : | |||
269 : | /* if sum(diff between field lines) < sum(diff between frame lines), use field dct */ | ||
270 : | |||
271 : | Isibaar | 1.1 | |
272 : | edgomez | 1.3 | uint32_t MBDecideFieldDCT(int16_t data[6*64]) |
273 : | h | 1.2 | { |
274 : | edgomez | 1.3 | |
275 : | const uint8_t blocks[] = {0*64, 0*64, 0*64, 0*64, 2*64, 2*64, 2*64, 2*64}; | ||
276 : | const uint8_t lines[] = {0, 16, 32, 48, 0, 16, 32, 48}; | ||
277 : | h | 1.2 | |
278 : | int frame = 0, field = 0; | ||
279 : | int i, j; | ||
280 : | |||
281 : | for (i=0 ; i<7 ; ++i) | ||
282 : | { | ||
283 : | for (j=0 ; j<8 ; ++j) | ||
284 : | { | ||
285 : | edgomez | 1.3 | frame += ABS(data[0*64 + (i+1)*8 + j] - data[0*64 + i*8 + j]); |
286 : | frame += ABS(data[1*64 + (i+1)*8 + j] - data[1*64 + i*8 + j]); | ||
287 : | frame += ABS(data[2*64 + (i+1)*8 + j] - data[2*64 + i*8 + j]); | ||
288 : | frame += ABS(data[3*64 + (i+1)*8 + j] - data[3*64 + i*8 + j]); | ||
289 : | |||
290 : | field += ABS(data[blocks[i+1] + lines[i+1] + j] -\ | ||
291 : | data[blocks[i ] + lines[i ] + j]); | ||
292 : | field += ABS(data[blocks[i+1] + lines[i+1] + 8 + j] -\ | ||
293 : | data[blocks[i ] + lines[i ] + 8 + j]); | ||
294 : | field += ABS(data[blocks[i+1] + 64 + lines[i+1] + j] -\ | ||
295 : | data[blocks[i ] + 64 + lines[i ] + j]); | ||
296 : | field += ABS(data[blocks[i+1] + 64 + lines[i+1] + 8 + j] -\ | ||
297 : | data[blocks[i ] + 64 + lines[i ] + 8 + j]); | ||
298 : | Isibaar | 1.1 | } |
299 : | } | ||
300 : | h | 1.2 | |
301 : | if (frame > field) | ||
302 : | { | ||
303 : | MBFrameToField(data); | ||
304 : | } | ||
305 : | |||
306 : | return (frame > field); | ||
307 : | } | ||
308 : | |||
309 : | |||
310 : | /* deinterlace Y blocks vertically */ | ||
311 : | |||
312 : | #define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp)) | ||
313 : | edgomez | 1.3 | #define LINE(X,Y) &data[X*64 + Y*8] |
314 : | h | 1.2 | |
315 : | edgomez | 1.3 | void MBFrameToField(int16_t data[6*64]) |
316 : | h | 1.2 | { |
317 : | int16_t tmp[8]; | ||
318 : | |||
319 : | /* left blocks */ | ||
320 : | |||
321 : | // 1=2, 2=4, 4=8, 8=1 | ||
322 : | MOVLINE(tmp, LINE(0,1)); | ||
323 : | MOVLINE(LINE(0,1), LINE(0,2)); | ||
324 : | MOVLINE(LINE(0,2), LINE(0,4)); | ||
325 : | MOVLINE(LINE(0,4), LINE(2,0)); | ||
326 : | MOVLINE(LINE(2,0), tmp); | ||
327 : | |||
328 : | // 3=6, 6=12, 12=9, 9=3 | ||
329 : | MOVLINE(tmp, LINE(0,3)); | ||
330 : | MOVLINE(LINE(0,3), LINE(0,6)); | ||
331 : | MOVLINE(LINE(0,6), LINE(2,4)); | ||
332 : | MOVLINE(LINE(2,4), LINE(2,1)); | ||
333 : | MOVLINE(LINE(2,1), tmp); | ||
334 : | |||
335 : | // 5=10, 10=5 | ||
336 : | MOVLINE(tmp, LINE(0,5)); | ||
337 : | MOVLINE(LINE(0,5), LINE(2,2)); | ||
338 : | MOVLINE(LINE(2,2), tmp); | ||
339 : | |||
340 : | // 7=14, 14=13, 13=11, 11=7 | ||
341 : | MOVLINE(tmp, LINE(0,7)); | ||
342 : | MOVLINE(LINE(0,7), LINE(2,6)); | ||
343 : | MOVLINE(LINE(2,6), LINE(2,5)); | ||
344 : | MOVLINE(LINE(2,5), LINE(2,3)); | ||
345 : | MOVLINE(LINE(2,3), tmp); | ||
346 : | |||
347 : | /* right blocks */ | ||
348 : | |||
349 : | // 1=2, 2=4, 4=8, 8=1 | ||
350 : | MOVLINE(tmp, LINE(1,1)); | ||
351 : | MOVLINE(LINE(1,1), LINE(1,2)); | ||
352 : | MOVLINE(LINE(1,2), LINE(1,4)); | ||
353 : | MOVLINE(LINE(1,4), LINE(3,0)); | ||
354 : | MOVLINE(LINE(3,0), tmp); | ||
355 : | |||
356 : | // 3=6, 6=12, 12=9, 9=3 | ||
357 : | MOVLINE(tmp, LINE(1,3)); | ||
358 : | MOVLINE(LINE(1,3), LINE(1,6)); | ||
359 : | MOVLINE(LINE(1,6), LINE(3,4)); | ||
360 : | MOVLINE(LINE(3,4), LINE(3,1)); | ||
361 : | MOVLINE(LINE(3,1), tmp); | ||
362 : | |||
363 : | // 5=10, 10=5 | ||
364 : | MOVLINE(tmp, LINE(1,5)); | ||
365 : | MOVLINE(LINE(1,5), LINE(3,2)); | ||
366 : | MOVLINE(LINE(3,2), tmp); | ||
367 : | |||
368 : | // 7=14, 14=13, 13=11, 11=7 | ||
369 : | MOVLINE(tmp, LINE(1,7)); | ||
370 : | MOVLINE(LINE(1,7), LINE(3,6)); | ||
371 : | MOVLINE(LINE(3,6), LINE(3,5)); | ||
372 : | MOVLINE(LINE(3,5), LINE(3,3)); | ||
373 : | MOVLINE(LINE(3,3), tmp); | ||
374 : | Isibaar | 1.1 | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |