36 s->quantizer = quantizer;
45 VP56mv vect[2] = {{0,0}, {0,0}};
49 for (pos=0; pos<12; pos++) {
51 mvp.
y = row + 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 int 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);
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),
344 stride, 12, 12, x, y,
345 s->plane_width[plane],
346 s->plane_height[plane]);
347 src_block = s->edge_emu_buffer;
348 src_offset = 2 + 2*
stride;
349 }
else if (deblock_filtering) {
352 s->hdsp.put_pixels_tab[0][0](s->edge_emu_buffer,
353 src + s->block_offset[
b] + (dy-2)*stride + (dx-2),
355 src_block = s->edge_emu_buffer;
356 src_offset = 2 + 2*
stride;
359 src_offset = s->block_offset[
b] + dy*stride + dx;
362 if (deblock_filtering)
365 if (s->mv[b].x & mask)
366 overlap_offset += (s->mv[
b].x > 0) ? 1 : -1;
367 if (s->mv[b].y & mask)
368 overlap_offset += (s->mv[
b].y > 0) ? stride : -stride;
370 if (overlap_offset) {
372 s->filter(s, dst, src_block, src_offset, src_offset+overlap_offset,
373 stride, s->mv[b], mask, s->filter_selection, b<4);
375 s->vp3dsp.put_no_rnd_pixels_l2(dst, src_block+src_offset,
376 src_block+src_offset+overlap_offset,
379 s->hdsp.put_pixels_tab[1][0](dst, src_block+src_offset,
stride, 8);
385 AVFrame *frame_current, *frame_ref;
388 int b, ab, b_max, plane,
off;
406 b_max = 6 - 2*is_alpha;
410 for (b=0; b<b_max; b++) {
412 s->vp3dsp.idct_put(frame_current->
data[plane] + s->block_offset[b],
413 s->stride[plane], s->block_coeff[b]);
419 for (b=0; b<b_max; b++) {
421 off = s->block_offset[
b];
422 s->hdsp.put_pixels_tab[1][0](frame_current->
data[plane] +
off,
424 s->stride[plane], 8);
425 s->vp3dsp.idct_add(frame_current->
data[plane] + off,
426 s->stride[plane], s->block_coeff[b]);
437 for (b=0; b<b_max; b++) {
438 int x_off = b==1 || b==3 ? 8 : 0;
439 int y_off = b==2 || b==3 ? 8 : 0;
441 vp56_mc(s, b, plane, frame_ref->
data[plane], s->stride[plane],
442 16*col+x_off, 16*row+y_off);
443 s->vp3dsp.idct_add(frame_current->
data[plane] + s->block_offset[b],
444 s->stride[plane], s->block_coeff[b]);
450 s->block_coeff[4][0] = 0;
451 s->block_coeff[5][0] = 0;
461 s->plane_width[0] = s->plane_width[3] = avctx->
coded_width;
462 s->plane_width[1] = s->plane_width[2] = avctx->
coded_width/2;
463 s->plane_height[0] = s->plane_height[3] = avctx->
coded_height;
464 s->plane_height[1] = s->plane_height[2] = avctx->
coded_height/2;
472 if (s->mb_width > 1000 || s->mb_height > 1000) {
479 (4*s->mb_width+6) *
sizeof(*s->above_blocks));
481 s->mb_width*s->mb_height*
sizeof(*s->macroblocks));
482 av_free(s->edge_emu_buffer_alloc);
483 s->edge_emu_buffer_alloc =
av_malloc(16*stride);
484 s->edge_emu_buffer = s->edge_emu_buffer_alloc;
486 s->edge_emu_buffer += 15 *
stride;
488 if (s->alpha_context)
502 int remaining_buf_size = avpkt->
size;
508 if (remaining_buf_size < 3)
510 alpha_offset = bytestream_get_be24(&buf);
511 remaining_buf_size -= 3;
512 if (remaining_buf_size < alpha_offset)
516 res = s->parse_header(s, buf, remaining_buf_size);
521 for (i = 0; i < 4; i++) {
523 if (s->alpha_context)
547 int bak_w = avctx->
width;
548 int bak_h = avctx->
height;
552 remaining_buf_size -= alpha_offset;
554 res = s->alpha_context->parse_header(s->alpha_context, buf, remaining_buf_size);
558 avctx->
width = bak_w;
578 int jobnr,
int threadnr)
581 int is_alpha = (jobnr == 1);
582 VP56Context *
s = is_alpha ? s0->alpha_context :
s0;
584 int mb_row, mb_col, mb_row_flip, mb_offset = 0;
585 int block,
y, uv, stride_y, stride_uv;
590 s->default_models_init(s);
591 for (block=0; block<s->mb_height*s->mb_width; block++)
596 s->parse_vector_models(s);
600 if (s->parse_coeff_models(s))
603 memset(s->prev_dc, 0,
sizeof(s->prev_dc));
607 for (block=0; block < 4*s->mb_width+6; block++) {
609 s->above_blocks[
block].dc_coeff = 0;
610 s->above_blocks[
block].not_null_dc = 0;
622 for (mb_row=0; mb_row<s->mb_height; mb_row++) {
624 mb_row_flip = s->mb_height - mb_row - 1;
626 mb_row_flip = mb_row;
628 for (block=0; block<4; block++) {
630 s->left_block[
block].dc_coeff = 0;
631 s->left_block[
block].not_null_dc = 0;
633 memset(s->coeff_ctx, 0,
sizeof(s->coeff_ctx));
634 memset(s->coeff_ctx_last, 24,
sizeof(s->coeff_ctx_last));
636 s->above_block_idx[0] = 1;
637 s->above_block_idx[1] = 2;
638 s->above_block_idx[2] = 1;
639 s->above_block_idx[3] = 2;
640 s->above_block_idx[4] = 2*s->mb_width + 2 + 1;
641 s->above_block_idx[5] = 3*s->mb_width + 4 + 1;
643 s->block_offset[s->frbi] = (mb_row_flip*16 + mb_offset) * stride_y;
644 s->block_offset[s->srbi] = s->block_offset[s->frbi] + 8*stride_y;
645 s->block_offset[1] = s->block_offset[0] + 8;
646 s->block_offset[3] = s->block_offset[2] + 8;
647 s->block_offset[4] = (mb_row_flip*8 + mb_offset) * stride_uv;
648 s->block_offset[5] = s->block_offset[4];
650 for (mb_col=0; mb_col<s->mb_width; mb_col++) {
653 for (y=0; y<4; y++) {
654 s->above_block_idx[
y] += 2;
655 s->block_offset[
y] += 16;
658 for (uv=4; uv<6; uv++) {
659 s->above_block_idx[uv] += 1;
660 s->block_offset[uv] += 8;
685 int flip,
int has_alpha)
697 for (i = 0; i < 64; i++) {
698 #define T(x) (x >> 3) | ((x & 7) << 3)
710 s->edge_emu_buffer_alloc = NULL;
712 s->above_blocks = NULL;
713 s->macroblocks = NULL;
715 s->deblock_filtering = 1;
720 s->has_alpha = has_alpha;
722 s->modelp = &s->model;
749 av_freep(&s->edge_emu_buffer_alloc);