36 s->quantizer = quantizer;
45 VP56mv vect[2] = {{0,0}, {0,0}};
49 for (pos=0; pos<12; pos++) {
51 mvp.
y = row + ff_vp56_candidate_predictor_pos[pos][1];
52 if (mvp.
x < 0 || mvp.
x >= s->mb_width ||
53 mvp.
y < 0 || mvp.
y >= s->mb_height)
55 offset = mvp.
x + s->mb_width*mvp.
y;
59 if ((s->macroblocks[offset].mv.x == vect[0].
x &&
60 s->macroblocks[offset].mv.y == vect[0].
y) ||
61 (s->macroblocks[offset].mv.x == 0 &&
62 s->macroblocks[offset].mv.y == 0))
65 vect[nb_pred++] = s->macroblocks[
offset].mv;
70 s->vector_candidate_pos = pos;
73 s->vector_candidate[0] = vect[0];
74 s->vector_candidate[1] = vect[1];
85 for (ctx=0; ctx<3; ctx++) {
93 for (type=0; type<10; type++) {
110 for (ctx=0; ctx<3; ctx++) {
113 for (type=0; type<10; type++)
116 for (type=0; type<10; type++) {
117 int p02, p34, p0234, p17, p56, p89, p5689, p156789;
132 p156789 = p17 + p5689;
134 model->
mb_type[ctx][
type][1] = 1 + 255 * p0234/(1+p0234+p156789);
135 model->
mb_type[ctx][
type][2] = 1 + 255 * p02 / (1+p0234);
136 model->
mb_type[ctx][
type][3] = 1 + 255 * p17 / (1+p156789);
137 model->
mb_type[ctx][
type][4] = 1 + 255 * p[0] / (1+p02);
138 model->
mb_type[ctx][
type][5] = 1 + 255 * p[3] / (1+p34);
139 model->
mb_type[ctx][
type][6] = 1 + 255 * p[1] / (1+p17);
140 model->
mb_type[ctx][
type][7] = 1 + 255 * p56 / (1+p5689);
141 model->
mb_type[ctx][
type][8] = 1 + 255 * p[5] / (1+p56);
142 model->
mb_type[ctx][
type][9] = 1 + 255 * p[8] / (1+p89);
151 VP56mb prev_type,
int ctx)
153 uint8_t *mb_type_model = s->modelp->mb_type[ctx][prev_type];
169 for (b=0; b<4; b++) {
176 for (b=0; b<4; b++) {
182 s->parse_vector_adjustment(s, &s->mv[b]);
185 s->mv[
b] = s->vector_candidate[0];
188 s->mv[
b] = s->vector_candidate[1];
196 s->macroblocks[row * s->mb_width + col].mv = s->mv[3];
200 s->mv[4].x = s->mv[5].x =
RSHIFT(mv.
x,2);
201 s->mv[4].y = s->mv[5].y =
RSHIFT(mv.
y,2);
203 s->mv[4] = s->mv[5] = (
VP56mv) {mv.
x/4, mv.
y/4};
214 s->macroblocks[row * s->mb_width + col].type = s->mb_type;
216 switch (s->mb_type) {
218 mv = &s->vector_candidate[0];
222 mv = &s->vector_candidate[1];
227 mv = &s->vector_candidate[0];
232 mv = &s->vector_candidate[1];
236 s->parse_vector_adjustment(s, &vect);
242 s->parse_vector_adjustment(s, &vect);
255 s->macroblocks[row*s->mb_width + col].mv = *
mv;
266 int idx = s->idct_scantable[0];
269 for (b=0; b<6; b++) {
270 VP56RefDc *ab = &s->above_blocks[s->above_block_idx[
b]];
286 if (count < 2 && ref_frame == ab[-1+2*i].ref_frame) {
295 s->block_coeff[
b][idx] +=
dc;
301 s->block_coeff[
b][idx] *= s->dequant_dc;
306 ptrdiff_t
stride,
int dx,
int dy)
309 if (dx) s->vp56dsp.edge_filter_hor(yuv + 10-dx , stride, t);
310 if (dy) s->vp56dsp.edge_filter_ver(yuv + stride*(10-dy), stride, t);
314 ptrdiff_t
stride,
int x,
int y)
319 int overlap_offset = 0;
320 int mask = s->vp56_coord_div[
b] - 1;
321 int deblock_filtering = s->deblock_filtering;
328 deblock_filtering = 0;
330 dx = s->mv[
b].x / s->vp56_coord_div[
b];
331 dy = s->mv[
b].y / s->vp56_coord_div[
b];
340 if (x<0 || x+12>=s->plane_width[plane] ||
341 y<0 || y+12>=s->plane_height[plane]) {
342 s->vdsp.emulated_edge_mc(s->edge_emu_buffer,
343 src + s->block_offset[b] + (dy-2)*stride + (dx-2),
346 s->plane_width[plane],
347 s->plane_height[plane]);
348 src_block = s->edge_emu_buffer;
349 src_offset = 2 + 2*stride;
350 }
else if (deblock_filtering) {
353 s->hdsp.put_pixels_tab[0][0](s->edge_emu_buffer,
354 src + s->block_offset[
b] + (dy-2)*stride + (dx-2),
356 src_block = s->edge_emu_buffer;
357 src_offset = 2 + 2*stride;
360 src_offset = s->block_offset[
b] + dy*stride + dx;
363 if (deblock_filtering)
366 if (s->mv[b].x & mask)
367 overlap_offset += (s->mv[
b].x > 0) ? 1 : -1;
368 if (s->mv[b].y & mask)
369 overlap_offset += (s->mv[
b].y > 0) ? stride : -stride;
371 if (overlap_offset) {
373 s->filter(s, dst, src_block, src_offset, src_offset+overlap_offset,
374 stride, s->mv[b], mask, s->filter_selection, b<4);
376 s->vp3dsp.put_no_rnd_pixels_l2(dst, src_block+src_offset,
377 src_block+src_offset+overlap_offset,
380 s->hdsp.put_pixels_tab[1][0](dst, src_block+src_offset, stride, 8);
386 AVFrame *frame_current, *frame_ref;
389 int b, ab, b_max, plane,
off;
407 b_max = 6 - 2*is_alpha;
411 for (b=0; b<b_max; b++) {
413 s->vp3dsp.idct_put(frame_current->
data[plane] + s->block_offset[b],
414 s->stride[plane], s->block_coeff[b]);
420 for (b=0; b<b_max; b++) {
422 off = s->block_offset[
b];
423 s->hdsp.put_pixels_tab[1][0](frame_current->
data[plane] +
off,
425 s->stride[plane], 8);
426 s->vp3dsp.idct_add(frame_current->
data[plane] + off,
427 s->stride[plane], s->block_coeff[b]);
438 for (b=0; b<b_max; b++) {
439 int x_off = b==1 || b==3 ? 8 : 0;
440 int y_off = b==2 || b==3 ? 8 : 0;
442 vp56_mc(s, b, plane, frame_ref->
data[plane], s->stride[plane],
443 16*col+x_off, 16*row+y_off);
444 s->vp3dsp.idct_add(frame_current->
data[plane] + s->block_offset[b],
445 s->stride[plane], s->block_coeff[b]);
451 s->block_coeff[4][0] = 0;
452 s->block_coeff[5][0] = 0;
462 s->plane_width[0] = s->plane_width[3] = avctx->
coded_width;
463 s->plane_width[1] = s->plane_width[2] = avctx->
coded_width/2;
464 s->plane_height[0] = s->plane_height[3] = avctx->
coded_height;
465 s->plane_height[1] = s->plane_height[2] = avctx->
coded_height/2;
473 if (s->mb_width > 1000 || s->mb_height > 1000) {
480 sizeof(*s->above_blocks));
482 sizeof(*s->macroblocks));
483 av_free(s->edge_emu_buffer_alloc);
484 s->edge_emu_buffer_alloc =
av_malloc(16*stride);
485 s->edge_emu_buffer = s->edge_emu_buffer_alloc;
486 if (!s->above_blocks || !s->macroblocks || !s->edge_emu_buffer_alloc)
489 s->edge_emu_buffer += 15 * stride;
491 if (s->alpha_context)
505 int remaining_buf_size = avpkt->
size;
511 if (remaining_buf_size < 3)
513 alpha_offset = bytestream_get_be24(&buf);
514 remaining_buf_size -= 3;
515 if (remaining_buf_size < alpha_offset)
519 res = s->parse_header(s, buf, remaining_buf_size);
524 for (i = 0; i < 4; i++) {
526 if (s->alpha_context)
550 int bak_w = avctx->
width;
551 int bak_h = avctx->
height;
555 remaining_buf_size -= alpha_offset;
557 res = s->alpha_context->parse_header(s->alpha_context, buf, remaining_buf_size);
561 avctx->
width = bak_w;
581 int jobnr,
int threadnr)
584 int is_alpha = (jobnr == 1);
585 VP56Context *
s = is_alpha ? s0->alpha_context :
s0;
587 int mb_row, mb_col, mb_row_flip, mb_offset = 0;
589 ptrdiff_t stride_y, stride_uv;
594 s->default_models_init(s);
595 for (block=0; block<s->mb_height*s->mb_width; block++)
600 s->parse_vector_models(s);
604 if (s->parse_coeff_models(s))
607 memset(s->prev_dc, 0,
sizeof(s->prev_dc));
611 for (block=0; block < 4*s->mb_width+6; block++) {
613 s->above_blocks[
block].dc_coeff = 0;
614 s->above_blocks[
block].not_null_dc = 0;
626 for (mb_row=0; mb_row<s->mb_height; mb_row++) {
628 mb_row_flip = s->mb_height - mb_row - 1;
630 mb_row_flip = mb_row;
632 for (block=0; block<4; block++) {
634 s->left_block[
block].dc_coeff = 0;
635 s->left_block[
block].not_null_dc = 0;
637 memset(s->coeff_ctx, 0,
sizeof(s->coeff_ctx));
638 memset(s->coeff_ctx_last, 24,
sizeof(s->coeff_ctx_last));
640 s->above_block_idx[0] = 1;
641 s->above_block_idx[1] = 2;
642 s->above_block_idx[2] = 1;
643 s->above_block_idx[3] = 2;
644 s->above_block_idx[4] = 2*s->mb_width + 2 + 1;
645 s->above_block_idx[5] = 3*s->mb_width + 4 + 1;
647 s->block_offset[s->frbi] = (mb_row_flip*16 + mb_offset) * stride_y;
648 s->block_offset[s->srbi] = s->block_offset[s->frbi] + 8*stride_y;
649 s->block_offset[1] = s->block_offset[0] + 8;
650 s->block_offset[3] = s->block_offset[2] + 8;
651 s->block_offset[4] = (mb_row_flip*8 + mb_offset) * stride_uv;
652 s->block_offset[5] = s->block_offset[4];
654 for (mb_col=0; mb_col<s->mb_width; mb_col++) {
657 for (y=0; y<4; y++) {
658 s->above_block_idx[
y] += 2;
659 s->block_offset[
y] += 16;
662 for (uv=4; uv<6; uv++) {
663 s->above_block_idx[uv] += 1;
664 s->block_offset[uv] += 8;
689 int flip,
int has_alpha)
702 for (i = 0; i < 64; i++) {
703 #define TRANSPOSE(x) (x >> 3) | ((x & 7) << 3)
715 s->edge_emu_buffer_alloc = NULL;
717 s->above_blocks = NULL;
718 s->macroblocks = NULL;
720 s->deblock_filtering = 1;
725 s->has_alpha = has_alpha;
727 s->modelp = &s->model;
754 av_freep(&s->edge_emu_buffer_alloc);