Revision 1e76a1da libavcodec/vp3.c
libavcodec/vp3.c | ||
---|---|---|
130 | 130 |
int theora, theora_tables; |
131 | 131 |
int version; |
132 | 132 |
int width, height; |
133 |
int chroma_x_shift, chroma_y_shift; |
|
133 | 134 |
AVFrame golden_frame; |
134 | 135 |
AVFrame last_frame; |
135 | 136 |
AVFrame current_frame; |
... | ... | |
516 | 517 |
int coding_mode; |
517 | 518 |
int custom_mode_alphabet[CODING_MODE_COUNT]; |
518 | 519 |
const int *alphabet; |
520 |
Vp3Fragment *frag; |
|
519 | 521 |
|
520 | 522 |
if (s->keyframe) { |
521 | 523 |
for (i = 0; i < s->fragment_count; i++) |
... | ... | |
572 | 574 |
|
573 | 575 |
s->macroblock_coding[current_macroblock] = coding_mode; |
574 | 576 |
for (k = 0; k < 4; k++) { |
575 |
current_fragment = |
|
576 |
BLOCK_Y*s->fragment_width[0] + BLOCK_X; |
|
577 |
if (s->all_fragments[current_fragment].coding_method != |
|
578 |
MODE_COPY) |
|
579 |
s->all_fragments[current_fragment].coding_method = |
|
580 |
coding_mode; |
|
577 |
frag = s->all_fragments + BLOCK_Y*s->fragment_width[0] + BLOCK_X; |
|
578 |
if (frag->coding_method != MODE_COPY) |
|
579 |
frag->coding_method = coding_mode; |
|
581 | 580 |
} |
582 |
for (k = 0; k < 2; k++) { |
|
583 |
current_fragment = s->fragment_start[k+1] + |
|
584 |
mb_y*s->fragment_width[1] + mb_x; |
|
585 |
if (s->all_fragments[current_fragment].coding_method != |
|
586 |
MODE_COPY) |
|
587 |
s->all_fragments[current_fragment].coding_method = |
|
588 |
coding_mode; |
|
581 |
|
|
582 |
#define SET_CHROMA_MODES \ |
|
583 |
if (frag[s->fragment_start[1]].coding_method != MODE_COPY) \ |
|
584 |
frag[s->fragment_start[1]].coding_method = coding_mode;\ |
|
585 |
if (frag[s->fragment_start[2]].coding_method != MODE_COPY) \ |
|
586 |
frag[s->fragment_start[2]].coding_method = coding_mode; |
|
587 |
|
|
588 |
if (s->chroma_y_shift) { |
|
589 |
frag = s->all_fragments + mb_y*s->fragment_width[1] + mb_x; |
|
590 |
SET_CHROMA_MODES |
|
591 |
} else if (s->chroma_x_shift) { |
|
592 |
frag = s->all_fragments + 2*mb_y*s->fragment_width[1] + mb_x; |
|
593 |
for (k = 0; k < 2; k++) { |
|
594 |
SET_CHROMA_MODES |
|
595 |
frag += s->fragment_width[1]; |
|
596 |
} |
|
597 |
} else { |
|
598 |
for (k = 0; k < 4; k++) { |
|
599 |
frag = s->all_fragments + BLOCK_Y*s->fragment_width[1] + BLOCK_X; |
|
600 |
SET_CHROMA_MODES |
|
601 |
} |
|
589 | 602 |
} |
590 | 603 |
} |
591 | 604 |
} |
... | ... | |
611 | 624 |
int prior_last_motion_y = 0; |
612 | 625 |
int current_macroblock; |
613 | 626 |
int current_fragment; |
627 |
Vp3Fragment *frag; |
|
614 | 628 |
|
615 | 629 |
if (s->keyframe) |
616 | 630 |
return 0; |
... | ... | |
724 | 738 |
s->all_fragments[current_fragment].motion_y = motion_y[0]; |
725 | 739 |
} |
726 | 740 |
} |
741 |
|
|
742 |
#define SET_CHROMA_MV(mx, my) \ |
|
743 |
frag[s->fragment_start[1]].motion_x = mx; \ |
|
744 |
frag[s->fragment_start[1]].motion_y = my; \ |
|
745 |
frag[s->fragment_start[2]].motion_x = mx; \ |
|
746 |
frag[s->fragment_start[2]].motion_y = my |
|
747 |
|
|
748 |
if (s->chroma_y_shift) { |
|
727 | 749 |
if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) { |
728 | 750 |
motion_x[0] = RSHIFT(motion_x[0] + motion_x[1] + motion_x[2] + motion_x[3], 2); |
729 | 751 |
motion_y[0] = RSHIFT(motion_y[0] + motion_y[1] + motion_y[2] + motion_y[3], 2); |
730 | 752 |
} |
731 |
for (k = 0; k < 2; k++) { |
|
732 |
current_fragment = s->fragment_start[k+1] + |
|
733 |
mb_y*s->fragment_width[1] + mb_x; |
|
734 |
s->all_fragments[current_fragment].motion_x = motion_x[0]; |
|
735 |
s->all_fragments[current_fragment].motion_y = motion_y[0]; |
|
753 |
motion_x[0] = (motion_x[0]>>1) | (motion_x[0]&1); |
|
754 |
motion_y[0] = (motion_y[0]>>1) | (motion_y[0]&1); |
|
755 |
frag = s->all_fragments + mb_y*s->fragment_width[1] + mb_x; |
|
756 |
SET_CHROMA_MV(motion_x[0], motion_y[0]); |
|
757 |
} else if (s->chroma_x_shift) { |
|
758 |
if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) { |
|
759 |
motion_x[0] = RSHIFT(motion_x[0] + motion_x[1], 1); |
|
760 |
motion_y[0] = RSHIFT(motion_y[0] + motion_y[1], 1); |
|
761 |
motion_x[1] = RSHIFT(motion_x[2] + motion_x[3], 1); |
|
762 |
motion_y[1] = RSHIFT(motion_y[2] + motion_y[3], 1); |
|
763 |
} else { |
|
764 |
motion_x[1] = motion_x[0]; |
|
765 |
motion_y[1] = motion_y[0]; |
|
766 |
} |
|
767 |
motion_x[0] = (motion_x[0]>>1) | (motion_x[0]&1); |
|
768 |
motion_x[1] = (motion_x[1]>>1) | (motion_x[1]&1); |
|
769 |
|
|
770 |
frag = s->all_fragments + 2*mb_y*s->fragment_width[1] + mb_x; |
|
771 |
for (k = 0; k < 2; k++) { |
|
772 |
SET_CHROMA_MV(motion_x[k], motion_y[k]); |
|
773 |
frag += s->fragment_width[1]; |
|
774 |
} |
|
775 |
} else { |
|
776 |
for (k = 0; k < 4; k++) { |
|
777 |
frag = s->all_fragments + BLOCK_Y*s->fragment_width[1] + BLOCK_X; |
|
778 |
if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) { |
|
779 |
SET_CHROMA_MV(motion_x[k], motion_y[k]); |
|
780 |
} else { |
|
781 |
SET_CHROMA_MV(motion_x[0], motion_y[0]); |
|
782 |
} |
|
783 |
} |
|
736 | 784 |
} |
737 | 785 |
} |
738 | 786 |
} |
... | ... | |
1304 | 1352 |
uint8_t * last_plane = s-> last_frame.data [plane] + s->data_offset[plane]; |
1305 | 1353 |
uint8_t *golden_plane = s-> golden_frame.data [plane] + s->data_offset[plane]; |
1306 | 1354 |
int stride = s->current_frame.linesize[plane]; |
1307 |
int plane_width = s->width >> !!plane;
|
|
1308 |
int plane_height = s->height >> !!plane;
|
|
1355 |
int plane_width = s->width >> (plane && s->chroma_x_shift);
|
|
1356 |
int plane_height = s->height >> (plane && s->chroma_y_shift);
|
|
1309 | 1357 |
|
1310 |
int sb_x, sb_y = slice << !plane;
|
|
1311 |
int slice_height = sb_y + (plane ? 1 : 2);
|
|
1358 |
int sb_x, sb_y = slice << (!plane && s->chroma_y_shift);
|
|
1359 |
int slice_height = sb_y + 1 + (!plane && s->chroma_y_shift);
|
|
1312 | 1360 |
int slice_width = plane ? s->c_superblock_width : s->y_superblock_width; |
1313 | 1361 |
|
1314 | 1362 |
int fragment_width = s->fragment_width[!!plane]; |
... | ... | |
1362 | 1410 |
int src_x, src_y; |
1363 | 1411 |
motion_x = s->all_fragments[i].motion_x; |
1364 | 1412 |
motion_y = s->all_fragments[i].motion_y; |
1365 |
if(plane){ |
|
1366 |
motion_x= (motion_x>>1) | (motion_x&1); |
|
1367 |
motion_y= (motion_y>>1) | (motion_y&1); |
|
1368 |
} |
|
1369 | 1413 |
|
1370 | 1414 |
src_x= (motion_x>>1) + 8*x; |
1371 | 1415 |
src_y= (motion_y>>1) + 8*y; |
... | ... | |
1463 | 1507 |
int i, inter, plane; |
1464 | 1508 |
int c_width; |
1465 | 1509 |
int c_height; |
1510 |
int y_fragment_count, c_fragment_count; |
|
1466 | 1511 |
|
1467 | 1512 |
if (avctx->codec_tag == MKTAG('V','P','3','0')) |
1468 | 1513 |
s->version = 0; |
... | ... | |
1472 | 1517 |
s->avctx = avctx; |
1473 | 1518 |
s->width = FFALIGN(avctx->width, 16); |
1474 | 1519 |
s->height = FFALIGN(avctx->height, 16); |
1475 |
avctx->pix_fmt = PIX_FMT_YUV420P; |
|
1520 |
if (avctx->pix_fmt == PIX_FMT_NONE) |
|
1521 |
avctx->pix_fmt = PIX_FMT_YUV420P; |
|
1476 | 1522 |
avctx->chroma_sample_location = AVCHROMA_LOC_CENTER; |
1477 | 1523 |
if(avctx->idct_algo==FF_IDCT_AUTO) |
1478 | 1524 |
avctx->idct_algo=FF_IDCT_VP3; |
... | ... | |
1485 | 1531 |
for (i = 0; i < 3; i++) |
1486 | 1532 |
s->qps[i] = -1; |
1487 | 1533 |
|
1534 |
avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_x_shift, &s->chroma_y_shift); |
|
1535 |
|
|
1488 | 1536 |
s->y_superblock_width = (s->width + 31) / 32; |
1489 | 1537 |
s->y_superblock_height = (s->height + 31) / 32; |
1490 | 1538 |
s->y_superblock_count = s->y_superblock_width * s->y_superblock_height; |
1491 | 1539 |
|
1492 | 1540 |
/* work out the dimensions for the C planes */ |
1493 |
c_width = s->width / 2;
|
|
1494 |
c_height = s->height / 2;
|
|
1541 |
c_width = s->width >> s->chroma_x_shift;
|
|
1542 |
c_height = s->height >> s->chroma_y_shift;
|
|
1495 | 1543 |
s->c_superblock_width = (c_width + 31) / 32; |
1496 | 1544 |
s->c_superblock_height = (c_height + 31) / 32; |
1497 | 1545 |
s->c_superblock_count = s->c_superblock_width * s->c_superblock_height; |
... | ... | |
1507 | 1555 |
|
1508 | 1556 |
s->fragment_width[0] = s->width / FRAGMENT_PIXELS; |
1509 | 1557 |
s->fragment_height[0] = s->height / FRAGMENT_PIXELS; |
1510 |
s->fragment_width[1] = s->fragment_width[0] >> 1;
|
|
1511 |
s->fragment_height[1] = s->fragment_height[0] >> 1;
|
|
1558 |
s->fragment_width[1] = s->fragment_width[0] >> s->chroma_x_shift;
|
|
1559 |
s->fragment_height[1] = s->fragment_height[0] >> s->chroma_y_shift;
|
|
1512 | 1560 |
|
1513 | 1561 |
/* fragment count covers all 8x8 blocks for all 3 planes */ |
1514 |
s->fragment_count = s->fragment_width[0] * s->fragment_height[0] * 3 / 2; |
|
1515 |
s->fragment_start[1] = s->fragment_width[0] * s->fragment_height[0]; |
|
1516 |
s->fragment_start[2] = s->fragment_width[0] * s->fragment_height[0] * 5 / 4; |
|
1562 |
y_fragment_count = s->fragment_width[0] * s->fragment_height[0]; |
|
1563 |
c_fragment_count = s->fragment_width[1] * s->fragment_height[1]; |
|
1564 |
s->fragment_count = y_fragment_count + 2*c_fragment_count; |
|
1565 |
s->fragment_start[1] = y_fragment_count; |
|
1566 |
s->fragment_start[2] = y_fragment_count + c_fragment_count; |
|
1517 | 1567 |
|
1518 | 1568 |
s->all_fragments = av_malloc(s->fragment_count * sizeof(Vp3Fragment)); |
1519 | 1569 |
s->coded_fragment_list[0] = av_malloc(s->fragment_count * sizeof(int)); |
... | ... | |
1764 | 1814 |
} |
1765 | 1815 |
|
1766 | 1816 |
for (i = 0; i < 3; i++) { |
1817 |
int height = s->height >> (i && s->chroma_y_shift); |
|
1767 | 1818 |
if (s->flipped_image) |
1768 | 1819 |
s->data_offset[i] = 0; |
1769 | 1820 |
else |
1770 |
s->data_offset[i] = ((s->height>>!!i)-1) * s->current_frame.linesize[i];
|
|
1821 |
s->data_offset[i] = (height-1) * s->current_frame.linesize[i];
|
|
1771 | 1822 |
} |
1772 | 1823 |
|
1773 | 1824 |
s->last_slice_end = 0; |
... | ... | |
1776 | 1827 |
|
1777 | 1828 |
// filter the last row |
1778 | 1829 |
for (i = 0; i < 3; i++) { |
1779 |
int row = (s->height >> (3+!!i)) - 1;
|
|
1830 |
int row = (s->height >> (3+(i && s->chroma_y_shift))) - 1;
|
|
1780 | 1831 |
apply_loop_filter(s, i, row, row+1); |
1781 | 1832 |
} |
1782 | 1833 |
vp3_draw_horiz_band(s, s->height); |
... | ... | |
1883 | 1934 |
} |
1884 | 1935 |
|
1885 | 1936 |
#if CONFIG_THEORA_DECODER |
1937 |
static const enum PixelFormat theora_pix_fmts[4] = { |
|
1938 |
PIX_FMT_YUV420P, PIX_FMT_NONE, PIX_FMT_YUV422P, PIX_FMT_YUV444P |
|
1939 |
}; |
|
1940 |
|
|
1886 | 1941 |
static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb) |
1887 | 1942 |
{ |
1888 | 1943 |
Vp3DecodeContext *s = avctx->priv_data; |
... | ... | |
1931 | 1986 |
if (s->theora >= 0x030200) |
1932 | 1987 |
{ |
1933 | 1988 |
skip_bits(gb, 5); /* keyframe frequency force */ |
1934 |
skip_bits(gb, 2); /* pixel format: 420,res,422,444 */
|
|
1989 |
avctx->pix_fmt = theora_pix_fmts[get_bits(gb, 2)];
|
|
1935 | 1990 |
skip_bits(gb, 3); /* reserved */ |
1936 | 1991 |
} |
1937 | 1992 |
|
Also available in: Unified diff