3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* image stuff |
* image stuff |
5 |
* |
* |
6 |
|
* This program is an implementation of a part of one or more MPEG-4 |
7 |
|
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
8 |
|
* to use this software module in hardware or software products are |
9 |
|
* advised that its use may infringe existing patents or copyrights, and |
10 |
|
* any such use would be at such party's own risk. The original |
11 |
|
* developer of this software module and his/her company, and subsequent |
12 |
|
* editors and their companies, will have no liability for use of this |
13 |
|
* software or modifications or derivatives thereof. |
14 |
|
* |
15 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
16 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
17 |
* the Free Software Foundation; either version 2 of the License, or |
* the Free Software Foundation; either version 2 of the License, or |
32 |
* |
* |
33 |
* History: |
* History: |
34 |
* |
* |
35 |
|
* 05.10.2002 support for interpolated images in qpel mode - Isibaar |
36 |
* 01.05.2002 BFRAME image-based u,v interpolation |
* 01.05.2002 BFRAME image-based u,v interpolation |
37 |
* 22.04.2002 added some B-frame support |
* 22.04.2002 added some B-frame support |
38 |
* 14.04.2002 added image_dump_yuvpgm(), added image_mad() |
* 14.04.2002 added image_dump_yuvpgm(), added image_mad() |
39 |
* XVID_CSP_USER input support |
* XVID_CSP_USER input support |
40 |
* 09.04.2002 PSNR calculations |
* 09.04.2002 PSNR calculations - Isibaar |
41 |
* 06.04.2002 removed interlaced edging from U,V blocks (as per spec) |
* 06.04.2002 removed interlaced edging from U,V blocks (as per spec) |
42 |
* 26.03.2002 interlacing support (field-based edging in set_edges) |
* 26.03.2002 interlacing support (field-based edging in set_edges) |
43 |
* 26.01.2002 rgb555, rgb565 |
* 26.01.2002 rgb555, rgb565 |
161 |
uint32_t edged_width, |
uint32_t edged_width, |
162 |
uint32_t edged_height, |
uint32_t edged_height, |
163 |
uint32_t width, |
uint32_t width, |
164 |
uint32_t height, |
uint32_t height) |
|
uint32_t interlacing) |
|
165 |
{ |
{ |
166 |
const uint32_t edged_width2 = edged_width / 2; |
const uint32_t edged_width2 = edged_width / 2; |
167 |
const uint32_t width2 = width / 2; |
const uint32_t width2 = width / 2; |
174 |
src = image->y; |
src = image->y; |
175 |
|
|
176 |
for (i = 0; i < EDGE_SIZE; i++) { |
for (i = 0; i < EDGE_SIZE; i++) { |
|
/* // if interlacing, edges contain top-most data from each field |
|
|
if (interlacing && (i & 1)) { |
|
|
memset(dst, *(src + edged_width), EDGE_SIZE); |
|
|
memcpy(dst + EDGE_SIZE, src + edged_width, width); |
|
|
memset(dst + edged_width - EDGE_SIZE, |
|
|
*(src + edged_width + width - 1), EDGE_SIZE); |
|
|
} else {*/ |
|
177 |
memset(dst, *src, EDGE_SIZE); |
memset(dst, *src, EDGE_SIZE); |
178 |
memcpy(dst + EDGE_SIZE, src, width); |
memcpy(dst + EDGE_SIZE, src, width); |
179 |
memset(dst + edged_width - EDGE_SIZE, *(src + width - 1), |
memset(dst + edged_width - EDGE_SIZE, *(src + width - 1), |
180 |
EDGE_SIZE); |
EDGE_SIZE); |
|
/*}*/ |
|
181 |
dst += edged_width; |
dst += edged_width; |
182 |
} |
} |
183 |
|
|
190 |
|
|
191 |
src -= edged_width; |
src -= edged_width; |
192 |
for (i = 0; i < EDGE_SIZE; i++) { |
for (i = 0; i < EDGE_SIZE; i++) { |
|
/* // if interlacing, edges contain bottom-most data from each field |
|
|
if (interlacing && !(i & 1)) { |
|
|
memset(dst, *(src - edged_width), EDGE_SIZE); |
|
|
memcpy(dst + EDGE_SIZE, src - edged_width, width); |
|
|
memset(dst + edged_width - EDGE_SIZE, |
|
|
*(src - edged_width + width - 1), EDGE_SIZE); |
|
|
} else {*/ |
|
193 |
memset(dst, *src, EDGE_SIZE); |
memset(dst, *src, EDGE_SIZE); |
194 |
memcpy(dst + EDGE_SIZE, src, width); |
memcpy(dst + EDGE_SIZE, src, width); |
195 |
memset(dst + edged_width - EDGE_SIZE, *(src + width - 1), |
memset(dst + edged_width - EDGE_SIZE, *(src + width - 1), |
196 |
EDGE_SIZE); |
EDGE_SIZE); |
|
/*}*/ |
|
197 |
dst += edged_width; |
dst += edged_width; |
198 |
} |
} |
199 |
|
|
254 |
} |
} |
255 |
} |
} |
256 |
|
|
257 |
|
// bframe encoding requires image-based u,v interpolation |
|
// image-based y,u,v interpolation |
|
258 |
void |
void |
259 |
image_interpolate(const IMAGE * refn, |
image_interpolate(const IMAGE * refn, |
260 |
IMAGE * refh, |
IMAGE * refh, |
262 |
IMAGE * refhv, |
IMAGE * refhv, |
263 |
uint32_t edged_width, |
uint32_t edged_width, |
264 |
uint32_t edged_height, |
uint32_t edged_height, |
265 |
|
uint32_t quarterpel, |
266 |
uint32_t rounding) |
uint32_t rounding) |
267 |
{ |
{ |
268 |
const uint32_t offset = EDGE_SIZE * (edged_width + 1); |
const uint32_t offset = EDGE_SIZE * (edged_width + 1); |
269 |
const uint32_t stride_add = 7 * edged_width; |
const uint32_t stride_add = 7 * edged_width; |
270 |
|
|
271 |
/* --- u,v-image-based interpolation --- |
#ifdef BFRAMES |
272 |
const uint32_t edged_width2 = edged_width / 2; |
const uint32_t edged_width2 = edged_width / 2; |
273 |
const uint32_t edged_height2 = edged_height / 2; |
const uint32_t edged_height2 = edged_height / 2; |
274 |
const uint32_t offset2 = EDGE_SIZE2 * (edged_width2 + 1); |
const uint32_t offset2 = EDGE_SIZE2 * (edged_width2 + 1); |
275 |
const uint32_t stride_add2 = 7 * edged_width2; |
const uint32_t stride_add2 = 7 * edged_width2; |
276 |
*/ |
#endif |
277 |
|
|
278 |
uint8_t *n_ptr, *h_ptr, *v_ptr, *hv_ptr; |
uint8_t *n_ptr, *h_ptr, *v_ptr, *hv_ptr; |
279 |
uint32_t x, y; |
uint32_t x, y; |
289 |
v_ptr -= offset; |
v_ptr -= offset; |
290 |
hv_ptr -= offset; |
hv_ptr -= offset; |
291 |
|
|
292 |
|
if(quarterpel) { |
293 |
|
|
294 |
|
for (y = 0; y < edged_height; y += 8) { |
295 |
|
for (x = 0; x < edged_width; x += 8) { |
296 |
|
interpolate8x8_6tap_lowpass_h(h_ptr, n_ptr, edged_width, rounding); |
297 |
|
interpolate8x8_6tap_lowpass_v(v_ptr, n_ptr, edged_width, rounding); |
298 |
|
|
299 |
|
n_ptr += 8; |
300 |
|
h_ptr += 8; |
301 |
|
v_ptr += 8; |
302 |
|
} |
303 |
|
|
304 |
|
h_ptr += stride_add; |
305 |
|
v_ptr += stride_add; |
306 |
|
n_ptr += stride_add; |
307 |
|
} |
308 |
|
|
309 |
|
h_ptr = refh->y; |
310 |
|
h_ptr -= offset; |
311 |
|
|
312 |
for (y = 0; y < edged_height; y = y + 8) { |
for (y = 0; y < edged_height; y = y + 8) { |
313 |
for (x = 0; x < edged_width; x = x + 8) { |
for (x = 0; x < edged_width; x = x + 8) { |
314 |
|
interpolate8x8_6tap_lowpass_v(hv_ptr, h_ptr, edged_width, rounding); |
315 |
|
hv_ptr += 8; |
316 |
|
h_ptr += 8; |
317 |
|
} |
318 |
|
hv_ptr += stride_add; |
319 |
|
h_ptr += stride_add; |
320 |
|
} |
321 |
|
} |
322 |
|
else { |
323 |
|
|
324 |
|
for (y = 0; y < edged_height; y += 8) { |
325 |
|
for (x = 0; x < edged_width; x += 8) { |
326 |
interpolate8x8_halfpel_h(h_ptr, n_ptr, edged_width, rounding); |
interpolate8x8_halfpel_h(h_ptr, n_ptr, edged_width, rounding); |
327 |
interpolate8x8_halfpel_v(v_ptr, n_ptr, edged_width, rounding); |
interpolate8x8_halfpel_v(v_ptr, n_ptr, edged_width, rounding); |
328 |
interpolate8x8_halfpel_hv(hv_ptr, n_ptr, edged_width, rounding); |
interpolate8x8_halfpel_hv(hv_ptr, n_ptr, edged_width, rounding); |
332 |
v_ptr += 8; |
v_ptr += 8; |
333 |
hv_ptr += 8; |
hv_ptr += 8; |
334 |
} |
} |
335 |
|
|
336 |
h_ptr += stride_add; |
h_ptr += stride_add; |
337 |
v_ptr += stride_add; |
v_ptr += stride_add; |
338 |
hv_ptr += stride_add; |
hv_ptr += stride_add; |
339 |
n_ptr += stride_add; |
n_ptr += stride_add; |
340 |
} |
} |
341 |
|
} |
342 |
/* --- u,v-image-based interpolation --- |
/* |
343 |
|
#ifdef BFRAMES |
344 |
n_ptr = refn->u; |
n_ptr = refn->u; |
345 |
h_ptr = refh->u; |
h_ptr = refh->u; |
346 |
v_ptr = refv->u; |
v_ptr = refv->u; |
351 |
v_ptr -= offset2; |
v_ptr -= offset2; |
352 |
hv_ptr -= offset2; |
hv_ptr -= offset2; |
353 |
|
|
354 |
for (y = 0; y < edged_height2; y = y + 8) { |
for (y = 0; y < edged_height2; y += 8) { |
355 |
for (x = 0; x < edged_width2; x = x + 8) { |
for (x = 0; x < edged_width2; x += 8) { |
356 |
interpolate8x8_halfpel_h(h_ptr, n_ptr, edged_width2, rounding); |
interpolate8x8_halfpel_h(h_ptr, n_ptr, edged_width2, rounding); |
357 |
interpolate8x8_halfpel_v(v_ptr, n_ptr, edged_width2, rounding); |
interpolate8x8_halfpel_v(v_ptr, n_ptr, edged_width2, rounding); |
358 |
interpolate8x8_halfpel_hv(hv_ptr, n_ptr, edged_width2, rounding); |
interpolate8x8_halfpel_hv(hv_ptr, n_ptr, edged_width2, rounding); |
394 |
hv_ptr += stride_add2; |
hv_ptr += stride_add2; |
395 |
n_ptr += stride_add2; |
n_ptr += stride_add2; |
396 |
} |
} |
397 |
|
#endif |
398 |
|
*/ |
399 |
|
/* |
400 |
|
interpolate_halfpel_h( |
401 |
|
refh->y - offset, |
402 |
|
refn->y - offset, |
403 |
|
edged_width, edged_height, |
404 |
|
rounding); |
405 |
|
|
406 |
|
interpolate_halfpel_v( |
407 |
|
refv->y - offset, |
408 |
|
refn->y - offset, |
409 |
|
edged_width, edged_height, |
410 |
|
rounding); |
411 |
|
|
412 |
|
interpolate_halfpel_hv( |
413 |
|
refhv->y - offset, |
414 |
|
refn->y - offset, |
415 |
|
edged_width, edged_height, |
416 |
|
rounding); |
417 |
|
*/ |
418 |
|
|
419 |
|
/* uv-image-based compensation |
420 |
|
offset = EDGE_SIZE2 * (edged_width / 2 + 1); |
421 |
|
|
422 |
|
interpolate_halfpel_h( |
423 |
|
refh->u - offset, |
424 |
|
refn->u - offset, |
425 |
|
edged_width / 2, edged_height / 2, |
426 |
|
rounding); |
427 |
|
|
428 |
|
interpolate_halfpel_v( |
429 |
|
refv->u - offset, |
430 |
|
refn->u - offset, |
431 |
|
edged_width / 2, edged_height / 2, |
432 |
|
rounding); |
433 |
|
|
434 |
|
interpolate_halfpel_hv( |
435 |
|
refhv->u - offset, |
436 |
|
refn->u - offset, |
437 |
|
edged_width / 2, edged_height / 2, |
438 |
|
rounding); |
439 |
|
|
440 |
|
|
441 |
|
interpolate_halfpel_h( |
442 |
|
refh->v - offset, |
443 |
|
refn->v - offset, |
444 |
|
edged_width / 2, edged_height / 2, |
445 |
|
rounding); |
446 |
|
|
447 |
|
interpolate_halfpel_v( |
448 |
|
refv->v - offset, |
449 |
|
refn->v - offset, |
450 |
|
edged_width / 2, edged_height / 2, |
451 |
|
rounding); |
452 |
|
|
453 |
|
interpolate_halfpel_hv( |
454 |
|
refhv->v - offset, |
455 |
|
refn->v - offset, |
456 |
|
edged_width / 2, edged_height / 2, |
457 |
|
rounding); |
458 |
*/ |
*/ |
459 |
} |
} |
460 |
|
|