30 #include "config_components.h"
53 int16_t *
block,
int n,
int qscale)
56 const uint16_t *quant_matrix;
58 nCoeffs=
s->block_last_index[n];
60 block[0] *= n < 4 ?
s->y_dc_scale :
s->c_dc_scale;
62 quant_matrix =
s->intra_matrix;
63 for(
i=1;
i<=nCoeffs;
i++) {
64 int j=
s->intra_scantable.permutated[
i];
82 int16_t *
block,
int n,
int qscale)
85 const uint16_t *quant_matrix;
87 nCoeffs=
s->block_last_index[n];
89 quant_matrix =
s->inter_matrix;
90 for(
i=0;
i<=nCoeffs;
i++) {
91 int j=
s->intra_scantable.permutated[
i];
97 ((
int) (quant_matrix[j]))) >> 4;
102 ((
int) (quant_matrix[j]))) >> 4;
111 int16_t *
block,
int n,
int qscale)
114 const uint16_t *quant_matrix;
119 if(
s->alternate_scan) nCoeffs= 63;
120 else nCoeffs=
s->block_last_index[n];
122 block[0] *= n < 4 ?
s->y_dc_scale :
s->c_dc_scale;
123 quant_matrix =
s->intra_matrix;
124 for(
i=1;
i<=nCoeffs;
i++) {
125 int j=
s->intra_scantable.permutated[
i];
141 int16_t *
block,
int n,
int qscale)
144 const uint16_t *quant_matrix;
150 if(
s->alternate_scan) nCoeffs= 63;
151 else nCoeffs=
s->block_last_index[n];
153 block[0] *= n < 4 ?
s->y_dc_scale :
s->c_dc_scale;
155 quant_matrix =
s->intra_matrix;
156 for(
i=1;
i<=nCoeffs;
i++) {
157 int j=
s->intra_scantable.permutated[
i];
175 int16_t *
block,
int n,
int qscale)
178 const uint16_t *quant_matrix;
184 if(
s->alternate_scan) nCoeffs= 63;
185 else nCoeffs=
s->block_last_index[n];
187 quant_matrix =
s->inter_matrix;
188 for(
i=0;
i<=nCoeffs;
i++) {
189 int j=
s->intra_scantable.permutated[
i];
195 ((
int) (quant_matrix[j]))) >> 5;
199 ((
int) (quant_matrix[j]))) >> 5;
209 int16_t *
block,
int n,
int qscale)
219 block[0] *= n < 4 ?
s->y_dc_scale :
s->c_dc_scale;
220 qadd = (qscale - 1) | 1;
227 nCoeffs=
s->intra_scantable.raster_end[
s->block_last_index[n] ];
229 for(
i=1;
i<=nCoeffs;
i++) {
243 int16_t *
block,
int n,
int qscale)
250 qadd = (qscale - 1) | 1;
253 nCoeffs=
s->inter_scantable.raster_end[
s->block_last_index[n] ];
255 for(
i=0;
i<=nCoeffs;
i++) {
292 for (
i=0;
i<4;
i++) {
293 s->hdsp.avg_pixels_tab[0][
i] =
gray16;
294 s->hdsp.put_pixels_tab[0][
i] =
gray16;
295 s->hdsp.put_no_rnd_pixels_tab[0][
i] =
gray16;
297 s->hdsp.avg_pixels_tab[1][
i] =
gray8;
298 s->hdsp.put_pixels_tab[1][
i] =
gray8;
299 s->hdsp.put_no_rnd_pixels_tab[1][
i] =
gray8;
312 #if HAVE_INTRINSICS_NEON
334 s->idsp.mpeg4_studio_profile =
s->studio_profile;
340 if (
s->alternate_scan) {
353 int y_size =
s->b8_stride * (2 *
s->mb_height + 1);
354 int c_size =
s->mb_stride * (
s->mb_height + 1);
355 int yc_size = y_size + 2 * c_size;
358 if (
s->mb_height & 1)
359 yc_size += 2*
s->b8_stride + 2*
s->mb_stride;
366 if (
s->noise_reduction) {
373 s->block =
s->blocks[0];
375 for (
i = 0;
i < 12;
i++) {
376 s->pblocks[
i] = &
s->block[
i];
379 if (
s->avctx->codec_tag ==
AV_RL32(
"VCR2")) {
381 FFSWAP(
void *,
s->pblocks[4],
s->pblocks[5]);
388 s->ac_val[0] =
s->ac_val_base +
s->b8_stride + 1;
389 s->ac_val[1] =
s->ac_val_base + y_size +
s->mb_stride + 1;
390 s->ac_val[2] =
s->ac_val[1] + c_size;
398 int nb_slices =
s->slice_context_count,
ret;
403 for (
int i = 1;
i < nb_slices;
i++) {
405 if (!
s->thread_context[
i])
409 s->thread_context[
i]->start_mb_y =
410 (
s->mb_height * (
i ) + nb_slices / 2) / nb_slices;
411 s->thread_context[
i]->end_mb_y =
412 (
s->mb_height * (
i + 1) + nb_slices / 2) / nb_slices;
415 s->end_mb_y = nb_slices > 1 ? (
s->mb_height + nb_slices / 2) / nb_slices
428 s->sc.rd_scratchpad =
430 s->sc.obmc_scratchpad =
NULL;
442 for (
int i = 1;
i <
s->slice_context_count;
i++) {
451 #define COPY(a) bak->a = src->a
452 COPY(sc.edge_emu_buffer);
455 COPY(sc.rd_scratchpad);
456 COPY(sc.b_scratchpad);
457 COPY(sc.obmc_scratchpad);
484 for (
i = 0;
i < 12;
i++) {
495 "scratch buffers.\n");
509 s->y_dc_scale_table =
512 s->progressive_frame = 1;
513 s->progressive_sequence = 1;
516 s->coded_picture_number = 0;
517 s->picture_number = 0;
522 s->slice_context_count = 1;
527 int y_size, c_size, yc_size,
i, mb_array_size, mv_table_size, x, y;
529 s->mb_width = (
s->width + 15) / 16;
530 s->mb_stride =
s->mb_width + 1;
531 s->b8_stride =
s->mb_width * 2 + 1;
532 mb_array_size =
s->mb_height *
s->mb_stride;
533 mv_table_size = (
s->mb_height + 2) *
s->mb_stride + 1;
537 s->h_edge_pos =
s->mb_width * 16;
538 s->v_edge_pos =
s->mb_height * 16;
540 s->mb_num =
s->mb_width *
s->mb_height;
545 s->block_wrap[3] =
s->b8_stride;
547 s->block_wrap[5] =
s->mb_stride;
549 y_size =
s->b8_stride * (2 *
s->mb_height + 1);
550 c_size =
s->mb_stride * (
s->mb_height + 1);
551 yc_size = y_size + 2 * c_size;
553 if (
s->mb_height & 1)
554 yc_size += 2*
s->b8_stride + 2*
s->mb_stride;
558 for (y = 0; y <
s->mb_height; y++)
559 for (x = 0; x <
s->mb_width; x++)
560 s->mb_index2xy[x + y *
s->mb_width] = x + y *
s->mb_stride;
562 s->mb_index2xy[
s->mb_height *
s->mb_width] = (
s->mb_height - 1) *
s->mb_stride +
s->mb_width;
573 s->p_mv_table =
s->p_mv_table_base +
s->mb_stride + 1;
574 s->b_forw_mv_table =
s->b_forw_mv_table_base +
s->mb_stride + 1;
575 s->b_back_mv_table =
s->b_back_mv_table_base +
s->mb_stride + 1;
576 s->b_bidir_forw_mv_table =
s->b_bidir_forw_mv_table_base +
s->mb_stride + 1;
577 s->b_bidir_back_mv_table =
s->b_bidir_back_mv_table_base +
s->mb_stride + 1;
578 s->b_direct_mv_table =
s->b_direct_mv_table_base +
s->mb_stride + 1;
587 #define ALLOCZ_ARRAYS(p, mult, numb) ((p) = av_calloc(numb, mult * sizeof(*(p))))
592 if (!(tmp1 =
ALLOCZ_ARRAYS(
s->b_field_mv_table_base, 8, mv_table_size)) ||
593 !(tmp2 =
ALLOCZ_ARRAYS(
s->b_field_select_table[0][0], 2 * 4, mv_table_size)) ||
597 s->p_field_select_table[1] =
s->p_field_select_table[0] + 2 * mv_table_size;
598 tmp1 +=
s->mb_stride + 1;
600 for (
int i = 0;
i < 2;
i++) {
601 for (
int j = 0; j < 2; j++) {
602 for (
int k = 0; k < 2; k++) {
603 s->b_field_mv_table[
i][j][k] = tmp1;
604 tmp1 += mv_table_size;
606 s->b_field_select_table[
i][j] = tmp2;
607 tmp2 += 2 * mv_table_size;
619 tmp +=
s->mb_stride + 1;
620 for (
int i = 0;
i < 2;
i++) {
621 for (
int j = 0; j < 2; j++) {
622 s->p_field_mv_table[
i][j] =
tmp;
623 tmp += mv_table_size;
630 if (!(
s->coded_block_base =
av_mallocz(y_size + (
s->mb_height&1)*2*
s->b8_stride)) ||
634 s->coded_block =
s->coded_block_base +
s->b8_stride + 1;
637 if (
s->h263_pred ||
s->h263_plus || !
s->encoding) {
642 s->dc_val[0] =
s->dc_val_base +
s->b8_stride + 1;
643 s->dc_val[1] =
s->dc_val_base + y_size +
s->mb_stride + 1;
644 s->dc_val[2] =
s->dc_val[1] + c_size;
645 for (
i = 0;
i < yc_size;
i++)
646 s->dc_val_base[
i] = 1024;
650 if (!(
s->mbintra_table =
av_mallocz(mb_array_size)) ||
652 !(
s->mbskip_table =
av_mallocz(mb_array_size + 2)))
654 memset(
s->mbintra_table, 1, mb_array_size);
663 memset(&
s->next_picture, 0,
sizeof(
s->next_picture));
664 memset(&
s->last_picture, 0,
sizeof(
s->last_picture));
665 memset(&
s->current_picture, 0,
sizeof(
s->current_picture));
666 memset(&
s->new_picture, 0,
sizeof(
s->new_picture));
668 memset(
s->thread_context, 0,
sizeof(
s->thread_context));
671 s->me.score_map =
NULL;
672 s->dct_error_sum =
NULL;
675 memset(
s->pblocks, 0,
sizeof(
s->pblocks));
676 s->ac_val_base =
NULL;
680 s->sc.edge_emu_buffer =
NULL;
681 s->me.scratchpad =
NULL;
683 s->sc.rd_scratchpad =
685 s->sc.obmc_scratchpad =
NULL;
688 s->bitstream_buffer =
NULL;
689 s->allocated_bitstream_buffer_size = 0;
692 s->p_mv_table_base =
NULL;
693 s->b_forw_mv_table_base =
NULL;
694 s->b_back_mv_table_base =
NULL;
695 s->b_bidir_forw_mv_table_base =
NULL;
696 s->b_bidir_back_mv_table_base =
NULL;
697 s->b_direct_mv_table_base =
NULL;
698 s->p_mv_table =
NULL;
699 s->b_forw_mv_table =
NULL;
700 s->b_back_mv_table =
NULL;
701 s->b_bidir_forw_mv_table =
NULL;
702 s->b_bidir_back_mv_table =
NULL;
703 s->b_direct_mv_table =
NULL;
704 s->b_field_mv_table_base =
NULL;
705 s->p_field_mv_table_base =
NULL;
706 for (
i = 0;
i < 2;
i++) {
707 for (j = 0; j < 2; j++) {
708 for (k = 0; k < 2; k++) {
709 s->b_field_mv_table[
i][j][k] =
NULL;
711 s->b_field_select_table[
i][j] =
NULL;
712 s->p_field_mv_table[
i][j] =
NULL;
714 s->p_field_select_table[
i] =
NULL;
717 s->dc_val_base =
NULL;
718 s->coded_block_base =
NULL;
719 s->mbintra_table =
NULL;
721 s->pred_dir_table =
NULL;
723 s->mbskip_table =
NULL;
725 s->er.error_status_table =
NULL;
726 s->er.er_temp_buffer =
NULL;
727 s->mb_index2xy =
NULL;
728 s->lambda_table =
NULL;
741 int nb_slices = (HAVE_THREADS &&
743 s->avctx->thread_count : 1;
747 if (
s->encoding &&
s->avctx->slices)
748 nb_slices =
s->avctx->slices;
751 s->mb_height = (
s->height + 31) / 32 * 2;
753 s->mb_height = (
s->height + 15) / 16;
757 "decoding to AV_PIX_FMT_NONE is not supported.\n");
761 if (nb_slices >
MAX_THREADS || (nb_slices >
s->mb_height &&
s->mb_height)) {
768 " reducing to %d\n", nb_slices, max_slices);
769 nb_slices = max_slices;
772 if ((
s->width ||
s->height) &&
789 if (!
s->picture[
i].f)
802 #if FF_API_FLAG_TRUNCATED
803 s->parse_context.state = -1;
806 s->context_initialized = 1;
807 memset(
s->thread_context, 0,
sizeof(
s->thread_context));
808 s->thread_context[0] =
s;
809 s->slice_context_count = nb_slices;
835 av_freep(&
s->b_bidir_forw_mv_table_base);
836 av_freep(&
s->b_bidir_back_mv_table_base);
838 s->p_mv_table =
NULL;
839 s->b_forw_mv_table =
NULL;
840 s->b_back_mv_table =
NULL;
841 s->b_bidir_forw_mv_table =
NULL;
842 s->b_bidir_back_mv_table =
NULL;
843 s->b_direct_mv_table =
NULL;
845 av_freep(&
s->b_field_select_table[0][0]);
848 for (
i = 0;
i < 2;
i++) {
849 for (j = 0; j < 2; j++) {
850 for (k = 0; k < 2; k++) {
851 s->b_field_mv_table[
i][j][k] =
NULL;
853 s->b_field_select_table[
i][j] =
NULL;
854 s->p_field_mv_table[
i][j] =
NULL;
856 s->p_field_select_table[
i] =
NULL;
875 s->linesize =
s->uvlinesize = 0;
885 if (
s->slice_context_count > 1)
886 s->slice_context_count = 1;
888 #if FF_API_FLAG_TRUNCATED
890 s->parse_context.buffer_size = 0;
894 s->allocated_bitstream_buffer_size = 0;
909 s->context_initialized = 0;
910 s->context_reinit = 0;
911 s->last_picture_ptr =
912 s->next_picture_ptr =
913 s->current_picture_ptr =
NULL;
914 s->linesize =
s->uvlinesize = 0;
919 uint8_t *dest, uint8_t *
src,
920 int field_based,
int field_select,
921 int src_x,
int src_y,
923 int h_edge_pos,
int v_edge_pos,
925 int motion_x,
int motion_y)
927 const int lowres =
s->avctx->lowres;
929 const int s_mask = (2 <<
lowres) - 1;
933 if (
s->quarter_sample) {
938 sx = motion_x & s_mask;
939 sy = motion_y & s_mask;
940 src_x += motion_x >>
lowres + 1;
941 src_y += motion_y >>
lowres + 1;
945 if ((
unsigned)src_x >
FFMAX( h_edge_pos - (!!sx) -
w, 0) ||
946 (unsigned)src_y >
FFMAX((v_edge_pos >> field_based) - (!!sy) -
h, 0)) {
947 s->vdsp.emulated_edge_mc(
s->sc.edge_emu_buffer,
src,
948 s->linesize,
s->linesize,
949 w + 1, (
h + 1) << field_based,
950 src_x, src_y << field_based,
951 h_edge_pos, v_edge_pos);
952 src =
s->sc.edge_emu_buffer;
960 pix_op[op_index](dest,
src,
stride,
h, sx, sy);
972 uint8_t **ref_picture,
974 int motion_x,
int motion_y,
977 uint8_t *ptr_y, *ptr_cb, *ptr_cr;
978 int mx, my, src_x, src_y, uvsrc_x, uvsrc_y, sx, sy, uvsx, uvsy;
980 const int lowres =
s->avctx->lowres;
981 const int op_index =
FFMIN(
lowres-1+
s->chroma_x_shift, 3);
982 const int block_s = 8>>
lowres;
983 const int s_mask = (2 <<
lowres) - 1;
984 const int h_edge_pos =
s->h_edge_pos >>
lowres;
985 const int v_edge_pos =
s->v_edge_pos >>
lowres;
986 linesize =
s->current_picture.f->linesize[0] << field_based;
987 uvlinesize =
s->current_picture.f->linesize[1] << field_based;
990 if (
s->quarter_sample) {
996 motion_y += (bottom_field - field_select)*((1 <<
lowres)-1);
999 sx = motion_x & s_mask;
1000 sy = motion_y & s_mask;
1001 src_x =
s->mb_x * 2 * block_s + (motion_x >>
lowres + 1);
1002 src_y = (mb_y * 2 * block_s >> field_based) + (motion_y >>
lowres + 1);
1005 uvsx = ((motion_x >> 1) & s_mask) | (sx & 1);
1006 uvsy = ((motion_y >> 1) & s_mask) | (sy & 1);
1007 uvsrc_x = src_x >> 1;
1008 uvsrc_y = src_y >> 1;
1013 uvsx = (2 * mx) & s_mask;
1014 uvsy = (2 * my) & s_mask;
1015 uvsrc_x =
s->mb_x * block_s + (mx >>
lowres);
1016 uvsrc_y = mb_y * block_s + (my >>
lowres);
1018 if(
s->chroma_y_shift){
1023 uvsrc_x =
s->mb_x * block_s + (mx >>
lowres + 1);
1024 uvsrc_y = (mb_y * block_s >> field_based) + (my >>
lowres + 1);
1026 if(
s->chroma_x_shift){
1030 uvsy = motion_y & s_mask;
1032 uvsrc_x =
s->mb_x*block_s + (mx >> (
lowres+1));
1035 uvsx = motion_x & s_mask;
1036 uvsy = motion_y & s_mask;
1043 ptr_y = ref_picture[0] + src_y *
linesize + src_x;
1044 ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
1045 ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
1047 if ((
unsigned) src_x >
FFMAX( h_edge_pos - (!!sx) - 2 * block_s, 0) || uvsrc_y<0 ||
1048 (
unsigned) src_y >
FFMAX((v_edge_pos >> field_based) - (!!sy) -
h, 0)) {
1049 s->vdsp.emulated_edge_mc(
s->sc.edge_emu_buffer, ptr_y,
1051 17, 17 + field_based,
1052 src_x, src_y << field_based, h_edge_pos,
1054 ptr_y =
s->sc.edge_emu_buffer;
1056 uint8_t *ubuf =
s->sc.edge_emu_buffer + 18 *
s->linesize;
1057 uint8_t *vbuf =ubuf + 10 *
s->uvlinesize;
1059 vbuf -=
s->uvlinesize;
1060 s->vdsp.emulated_edge_mc(ubuf, ptr_cb,
1061 uvlinesize >> field_based, uvlinesize >> field_based,
1063 uvsrc_x, uvsrc_y << field_based,
1064 h_edge_pos >> 1, v_edge_pos >> 1);
1065 s->vdsp.emulated_edge_mc(vbuf, ptr_cr,
1066 uvlinesize >> field_based,uvlinesize >> field_based,
1068 uvsrc_x, uvsrc_y << field_based,
1069 h_edge_pos >> 1, v_edge_pos >> 1);
1077 dest_y +=
s->linesize;
1078 dest_cb +=
s->uvlinesize;
1079 dest_cr +=
s->uvlinesize;
1083 ptr_y +=
s->linesize;
1084 ptr_cb +=
s->uvlinesize;
1085 ptr_cr +=
s->uvlinesize;
1088 sx = (sx << 2) >>
lowres;
1089 sy = (sy << 2) >>
lowres;
1093 int hc =
s->chroma_y_shift ? (
h+1-bottom_field)>>1 :
h;
1094 uvsx = (uvsx << 2) >>
lowres;
1095 uvsy = (uvsy << 2) >>
lowres;
1097 pix_op[op_index](dest_cb, ptr_cb, uvlinesize, hc, uvsx, uvsy);
1098 pix_op[op_index](dest_cr, ptr_cr, uvlinesize, hc, uvsx, uvsy);
1105 uint8_t *dest_cb, uint8_t *dest_cr,
1106 uint8_t **ref_picture,
1110 const int lowres =
s->avctx->lowres;
1112 const int block_s = 8 >>
lowres;
1113 const int s_mask = (2 <<
lowres) - 1;
1114 const int h_edge_pos =
s->h_edge_pos >>
lowres + 1;
1115 const int v_edge_pos =
s->v_edge_pos >>
lowres + 1;
1116 int emu = 0, src_x, src_y, sx, sy;
1120 if (
s->quarter_sample) {
1132 src_x =
s->mb_x * block_s + (mx >>
lowres + 1);
1133 src_y =
s->mb_y * block_s + (my >>
lowres + 1);
1135 offset = src_y *
s->uvlinesize + src_x;
1136 ptr = ref_picture[1] +
offset;
1137 if ((
unsigned) src_x >
FFMAX(h_edge_pos - (!!sx) - block_s, 0) ||
1138 (unsigned) src_y >
FFMAX(v_edge_pos - (!!sy) - block_s, 0)) {
1139 s->vdsp.emulated_edge_mc(
s->sc.edge_emu_buffer, ptr,
1140 s->uvlinesize,
s->uvlinesize,
1142 src_x, src_y, h_edge_pos, v_edge_pos);
1143 ptr =
s->sc.edge_emu_buffer;
1146 sx = (sx << 2) >>
lowres;
1147 sy = (sy << 2) >>
lowres;
1148 pix_op[op_index](dest_cb, ptr,
s->uvlinesize, block_s, sx, sy);
1150 ptr = ref_picture[2] +
offset;
1152 s->vdsp.emulated_edge_mc(
s->sc.edge_emu_buffer, ptr,
1153 s->uvlinesize,
s->uvlinesize,
1155 src_x, src_y, h_edge_pos, v_edge_pos);
1156 ptr =
s->sc.edge_emu_buffer;
1158 pix_op[op_index](dest_cr, ptr,
s->uvlinesize, block_s, sx, sy);
1173 uint8_t *dest_y, uint8_t *dest_cb,
1175 int dir, uint8_t **ref_picture,
1180 const int lowres =
s->avctx->lowres;
1181 const int block_s = 8 >>
lowres;
1186 switch (
s->mv_type) {
1190 ref_picture, pix_op,
1191 s->mv[dir][0][0],
s->mv[dir][0][1],
1197 for (
i = 0;
i < 4;
i++) {
1199 s->linesize) * block_s,
1200 ref_picture[0], 0, 0,
1201 (2 * mb_x + (
i & 1)) * block_s,
1202 (2 * mb_y + (
i >> 1)) * block_s,
1203 s->width,
s->height,
s->linesize,
1205 block_s, block_s, pix_op,
1206 s->mv[dir][
i][0],
s->mv[dir][
i][1]);
1208 mx +=
s->mv[dir][
i][0];
1209 my +=
s->mv[dir][
i][1];
1220 1, 0,
s->field_select[dir][0],
1221 ref_picture, pix_op,
1222 s->mv[dir][0][0],
s->mv[dir][0][1],
1226 1, 1,
s->field_select[dir][1],
1227 ref_picture, pix_op,
1228 s->mv[dir][1][0],
s->mv[dir][1][1],
1231 if (
s->picture_structure !=
s->field_select[dir][0] + 1 &&
1233 ref_picture =
s->current_picture_ptr->f->data;
1237 0, 0,
s->field_select[dir][0],
1238 ref_picture, pix_op,
1240 s->mv[dir][0][1], 2 * block_s, mb_y >> 1);
1244 for (
i = 0;
i < 2;
i++) {
1245 uint8_t **ref2picture;
1247 if (
s->picture_structure ==
s->field_select[dir][
i] + 1 ||
1249 ref2picture = ref_picture;
1251 ref2picture =
s->current_picture_ptr->f->data;
1255 0, 0,
s->field_select[dir][
i],
1256 ref2picture, pix_op,
1257 s->mv[dir][
i][0],
s->mv[dir][
i][1] +
1258 2 * block_s *
i, block_s, mb_y >> 1);
1260 dest_y += 2 * block_s *
s->linesize;
1261 dest_cb += (2 * block_s >>
s->chroma_y_shift) *
s->uvlinesize;
1262 dest_cr += (2 * block_s >>
s->chroma_y_shift) *
s->uvlinesize;
1267 for (
i = 0;
i < 2;
i++) {
1269 for (j = 0; j < 2; j++) {
1272 ref_picture, pix_op,
1273 s->mv[dir][2 *
i + j][0],
1274 s->mv[dir][2 *
i + j][1],
1277 pix_op =
s->h264chroma.avg_h264_chroma_pixels_tab;
1280 for (
i = 0;
i < 2;
i++) {
1282 0, 0,
s->picture_structure !=
i + 1,
1283 ref_picture, pix_op,
1284 s->mv[dir][2 *
i][0],
s->mv[dir][2 *
i][1],
1285 2 * block_s, mb_y >> 1);
1288 pix_op =
s->h264chroma.avg_h264_chroma_pixels_tab;
1292 if (!
s->first_field) {
1293 ref_picture =
s->current_picture_ptr->f->data;
1308 int my_max = INT_MIN, my_min = INT_MAX, qpel_shift = !
s->quarter_sample;
1309 int my, off,
i, mvs;
1314 switch (
s->mv_type) {
1328 for (
i = 0;
i < mvs;
i++) {
1329 my =
s->mv[dir][
i][1];
1330 my_max =
FFMAX(my_max, my);
1331 my_min =
FFMIN(my_min, my);
1334 off = ((
FFMAX(-my_min, my_max)<<qpel_shift) + 63) >> 6;
1336 return av_clip(
s->mb_y + off, 0,
s->mb_height - 1);
1338 return s->mb_height-1;
1343 int16_t *
block,
int i, uint8_t *dest,
int line_size,
int qscale)
1345 s->dct_unquantize_intra(
s,
block,
i, qscale);
1346 s->idsp.idct_put(dest, line_size,
block);
1351 int16_t *
block,
int i, uint8_t *dest,
int line_size)
1353 if (
s->block_last_index[
i] >= 0) {
1354 s->idsp.idct_add(dest, line_size,
block);
1359 int16_t *
block,
int i, uint8_t *dest,
int line_size,
int qscale)
1361 if (
s->block_last_index[
i] >= 0) {
1362 s->dct_unquantize_inter(
s,
block,
i, qscale);
1364 s->idsp.idct_add(dest, line_size,
block);
1373 int wrap =
s->b8_stride;
1374 int xy =
s->block_index[0];
1377 s->dc_val[0][xy + 1 ] =
1378 s->dc_val[0][xy +
wrap] =
1379 s->dc_val[0][xy + 1 +
wrap] = 1024;
1381 memset(
s->ac_val[0][xy ], 0, 32 *
sizeof(int16_t));
1382 memset(
s->ac_val[0][xy +
wrap], 0, 32 *
sizeof(int16_t));
1383 if (
s->msmpeg4_version>=3) {
1384 s->coded_block[xy ] =
1385 s->coded_block[xy + 1 ] =
1386 s->coded_block[xy +
wrap] =
1387 s->coded_block[xy + 1 +
wrap] = 0;
1390 wrap =
s->mb_stride;
1391 xy =
s->mb_x +
s->mb_y *
wrap;
1393 s->dc_val[2][xy] = 1024;
1395 memset(
s->ac_val[1][xy], 0, 16 *
sizeof(int16_t));
1396 memset(
s->ac_val[2][xy], 0, 16 *
sizeof(int16_t));
1398 s->mbintra_table[xy]= 0;
1413 int lowres_flag,
int is_mpeg12)
1415 #define IS_ENCODER(s) (CONFIG_MPEGVIDEOENC && !lowres_flag && (s)->encoding)
1416 #define IS_MPEG12(s) (CONFIG_SMALL ? ((s)->out_format == FMT_MPEG1) : is_mpeg12)
1417 const int mb_xy =
s->mb_y *
s->mb_stride +
s->mb_x;
1419 s->current_picture.qscale_table[mb_xy] =
s->qscale;
1423 if (!is_mpeg12 && (
s->h263_pred ||
s->h263_aic)) {
1424 if(
s->mbintra_table[mb_xy])
1429 s->last_dc[2] = 128 <<
s->intra_dc_precision;
1432 else if (!is_mpeg12 && (
s->h263_pred ||
s->h263_aic))
1433 s->mbintra_table[mb_xy]=1;
1438 uint8_t *dest_y, *dest_cb, *dest_cr;
1439 int dct_linesize, dct_offset;
1442 const int linesize =
s->current_picture.f->linesize[0];
1443 const int uvlinesize =
s->current_picture.f->linesize[1];
1445 const int block_size= lowres_flag ? 8>>
s->avctx->lowres : 8;
1450 uint8_t *mbskip_ptr = &
s->mbskip_table[mb_xy];
1452 if (
s->mb_skipped) {
1456 }
else if(!
s->current_picture.reference) {
1463 dct_linesize =
linesize <<
s->interlaced_dct;
1468 dest_cb=
s->dest[1];
1469 dest_cr=
s->dest[2];
1471 dest_y =
s->sc.b_scratchpad;
1472 dest_cb=
s->sc.b_scratchpad+16*
linesize;
1473 dest_cr=
s->sc.b_scratchpad+32*
linesize;
1499 op_pix =
s->h264chroma.avg_h264_chroma_pixels_tab;
1505 op_qpix =
s->me.qpel_put;
1507 op_pix =
s->hdsp.put_pixels_tab;
1509 op_pix =
s->hdsp.put_no_rnd_pixels_tab;
1512 ff_mpv_motion(
s, dest_y, dest_cb, dest_cr, 0,
s->last_picture.f->data, op_pix, op_qpix);
1513 op_pix =
s->hdsp.avg_pixels_tab;
1514 op_qpix=
s->me.qpel_avg;
1517 ff_mpv_motion(
s, dest_y, dest_cb, dest_cr, 1,
s->next_picture.f->data, op_pix, op_qpix);
1523 if(
s->avctx->skip_idct){
1539 if (
s->chroma_y_shift){
1554 add_dct(
s,
block[2], 2, dest_y + dct_offset , dct_linesize);
1555 add_dct(
s,
block[3], 3, dest_y + dct_offset + block_size, dct_linesize);
1558 if(
s->chroma_y_shift){
1563 dct_linesize = uvlinesize <<
s->interlaced_dct;
1564 dct_offset =
s->interlaced_dct ? uvlinesize : uvlinesize*block_size;
1570 if(!
s->chroma_x_shift){
1573 add_dct(
s,
block[10], 10, dest_cb+block_size+dct_offset, dct_linesize);
1574 add_dct(
s,
block[11], 11, dest_cr+block_size+dct_offset, dct_linesize);
1578 }
else if (CONFIG_WMV2_DECODER) {
1584 if (!is_mpeg12 && CONFIG_MPEG4_DECODER &&
1585 s->avctx->bits_per_raw_sample > 8) {
1587 uvlinesize, dct_linesize, dct_offset);
1592 put_dct(
s,
block[1], 1, dest_y + block_size, dct_linesize,
s->qscale);
1593 put_dct(
s,
block[2], 2, dest_y + dct_offset , dct_linesize,
s->qscale);
1594 put_dct(
s,
block[3], 3, dest_y + dct_offset + block_size, dct_linesize,
s->qscale);
1597 if(
s->chroma_y_shift){
1603 put_dct(
s,
block[4], 4, dest_cb, dct_linesize,
s->chroma_qscale);
1604 put_dct(
s,
block[5], 5, dest_cr, dct_linesize,
s->chroma_qscale);
1605 put_dct(
s,
block[6], 6, dest_cb + dct_offset, dct_linesize,
s->chroma_qscale);
1606 put_dct(
s,
block[7], 7, dest_cr + dct_offset, dct_linesize,
s->chroma_qscale);
1610 s->idsp.idct_put(dest_y, dct_linesize,
block[0]);
1611 s->idsp.idct_put(dest_y + block_size, dct_linesize,
block[1]);
1612 s->idsp.idct_put(dest_y + dct_offset, dct_linesize,
block[2]);
1613 s->idsp.idct_put(dest_y + dct_offset + block_size, dct_linesize,
block[3]);
1616 if(
s->chroma_y_shift){
1617 s->idsp.idct_put(dest_cb, uvlinesize,
block[4]);
1618 s->idsp.idct_put(dest_cr, uvlinesize,
block[5]);
1621 dct_linesize = uvlinesize <<
s->interlaced_dct;
1622 dct_offset =
s->interlaced_dct ? uvlinesize : uvlinesize*block_size;
1624 s->idsp.idct_put(dest_cb, dct_linesize,
block[4]);
1625 s->idsp.idct_put(dest_cr, dct_linesize,
block[5]);
1626 s->idsp.idct_put(dest_cb + dct_offset, dct_linesize,
block[6]);
1627 s->idsp.idct_put(dest_cr + dct_offset, dct_linesize,
block[7]);
1628 if(!
s->chroma_x_shift){
1629 s->idsp.idct_put(dest_cb + block_size, dct_linesize,
block[8]);
1630 s->idsp.idct_put(dest_cr + block_size, dct_linesize,
block[9]);
1631 s->idsp.idct_put(dest_cb + block_size + dct_offset, dct_linesize,
block[10]);
1632 s->idsp.idct_put(dest_cr + block_size + dct_offset, dct_linesize,
block[11]);
1640 s->hdsp.put_pixels_tab[0][0](
s->dest[0], dest_y ,
linesize,16);
1642 s->hdsp.put_pixels_tab[
s->chroma_x_shift][0](
s->dest[1], dest_cb, uvlinesize,16 >>
s->chroma_y_shift);
1643 s->hdsp.put_pixels_tab[
s->chroma_x_shift][0](
s->dest[2], dest_cr, uvlinesize,16 >>
s->chroma_y_shift);
1654 for (
int i = 0;
i < 6;
i++) {
1655 for (
int j = 0; j < 64; j++) {
1657 block[
i][
s->idsp.idct_permutation[j]]);
1674 const int linesize =
s->current_picture.f->linesize[0];
1675 const int uvlinesize =
s->current_picture.f->linesize[1];
1676 const int width_of_mb = (4 + (
s->avctx->bits_per_raw_sample > 8)) -
s->avctx->lowres;
1677 const int height_of_mb = 4 -
s->avctx->lowres;
1679 s->block_index[0]=
s->b8_stride*(
s->mb_y*2 ) - 2 +
s->mb_x*2;
1680 s->block_index[1]=
s->b8_stride*(
s->mb_y*2 ) - 1 +
s->mb_x*2;
1681 s->block_index[2]=
s->b8_stride*(
s->mb_y*2 + 1) - 2 +
s->mb_x*2;
1682 s->block_index[3]=
s->b8_stride*(
s->mb_y*2 + 1) - 1 +
s->mb_x*2;
1683 s->block_index[4]=
s->mb_stride*(
s->mb_y + 1) +
s->b8_stride*
s->mb_height*2 +
s->mb_x - 1;
1684 s->block_index[5]=
s->mb_stride*(
s->mb_y +
s->mb_height + 2) +
s->b8_stride*
s->mb_height*2 +
s->mb_x - 1;
1687 s->dest[0] =
s->current_picture.f->data[0] + (
int)((
s->mb_x - 1
U) << width_of_mb);
1688 s->dest[1] =
s->current_picture.f->data[1] + (
int)((
s->mb_x - 1
U) << (width_of_mb -
s->chroma_x_shift));
1689 s->dest[2] =
s->current_picture.f->data[2] + (
int)((
s->mb_x - 1
U) << (width_of_mb -
s->chroma_x_shift));
1694 s->dest[0] +=
s->mb_y *
linesize << height_of_mb;
1695 s->dest[1] +=
s->mb_y * uvlinesize << (height_of_mb -
s->chroma_y_shift);
1696 s->dest[2] +=
s->mb_y * uvlinesize << (height_of_mb -
s->chroma_y_shift);
1698 s->dest[0] += (
s->mb_y>>1) *
linesize << height_of_mb;
1699 s->dest[1] += (
s->mb_y>>1) * uvlinesize << (height_of_mb -
s->chroma_y_shift);
1700 s->dest[2] += (
s->mb_y>>1) * uvlinesize << (height_of_mb -
s->chroma_y_shift);
1713 else if (qscale > 31)
1717 s->chroma_qscale=
s->chroma_qscale_table[qscale];
1719 s->y_dc_scale=
s->y_dc_scale_table[ qscale ];
1720 s->c_dc_scale=
s->c_dc_scale_table[
s->chroma_qscale ];