30 #ifndef AVCODEC_MPEGVIDEO_COMMON_H
31 #define AVCODEC_MPEGVIDEO_COMMON_H
57 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
58 uint8_t **ref_picture)
62 int motion_x, motion_y;
71 src_x = av_clip(src_x, -16, s->
width);
72 if (src_x == s->
width)
74 src_y = av_clip(src_y, -16, s->
height);
81 ptr = ref_picture[0] + (src_y *
linesize) + src_x;
91 if((motion_x|motion_y)&7){
92 s->
dsp.
gmc1(dest_y , ptr , linesize, 16, motion_x&15, motion_y&15, 128 - s->
no_rounding);
93 s->
dsp.
gmc1(dest_y+8, ptr+8, linesize, 16, motion_x&15, motion_y&15, 128 - s->
no_rounding);
97 dxy= ((motion_x>>3)&1) | ((motion_y>>2)&2);
113 src_x = av_clip(src_x, -8, s->
width>>1);
114 if (src_x == s->
width>>1)
116 src_y = av_clip(src_y, -8, s->
height>>1);
117 if (src_y == s->
height>>1)
121 ptr = ref_picture[1] + offset;
130 s->
dsp.
gmc1(dest_cb, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->
no_rounding);
132 ptr = ref_picture[2] + offset;
137 s->
dsp.
gmc1(dest_cr, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->
no_rounding);
143 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
144 uint8_t **ref_picture)
154 ptr = ref_picture[0];
159 s->
dsp.
gmc(dest_y, ptr, linesize, 16,
166 s->
dsp.
gmc(dest_y+8, ptr, linesize, 16,
179 ptr = ref_picture[1];
180 s->
dsp.
gmc(dest_cb, ptr, uvlinesize, 8,
188 ptr = ref_picture[2];
189 s->
dsp.
gmc(dest_cr, ptr, uvlinesize, 8,
199 uint8_t *
dest, uint8_t *src,
201 int src_x,
int src_y,
205 int motion_x,
int motion_y)
210 dxy = ((motion_y & 1) << 1) | (motion_x & 1);
211 src_x += motion_x >> 1;
212 src_y += motion_y >> 1;
215 src_x = av_clip(src_x, -16, width);
218 src_y = av_clip(src_y, -16, height);
221 src += src_y * stride + src_x;
224 if( (
unsigned)src_x >
FFMAX(h_edge_pos - (motion_x&1) - w, 0)
225 || (
unsigned)src_y >
FFMAX(v_edge_pos - (motion_y&1) - h, 0)){
227 src_x, src_y<<field_based, h_edge_pos, s->
v_edge_pos);
240 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
243 int motion_x,
int motion_y,
int h,
int is_mpeg12,
int mb_y)
245 uint8_t *ptr_y, *ptr_cb, *ptr_cr;
246 int dxy, uvdxy, mx, my, src_x, src_y,
262 dxy = ((motion_y & 1) << 1) | (motion_x & 1);
263 src_x = s->
mb_x* 16 + (motion_x >> 1);
264 src_y =( mb_y<<(4-field_based)) + (motion_y >> 1);
268 mx = (motion_x>>1)|(motion_x&1);
270 uvdxy = ((my & 1) << 1) | (mx & 1);
271 uvsrc_x = s->
mb_x* 8 + (mx >> 1);
272 uvsrc_y =( mb_y<<(3-field_based))+ (my >> 1);
274 uvdxy = dxy | (motion_y & 2) | ((motion_x & 2) >> 1);
282 uvsrc_x = s->
mb_x*8 + mx;
283 uvsrc_y = mb_y*8 + my;
288 uvdxy = ((my & 1) << 1) | (mx & 1);
289 uvsrc_x = s->
mb_x* 8 + (mx >> 1);
290 uvsrc_y =( mb_y<<(3-field_based))+ (my >> 1);
295 uvdxy = ((motion_y & 1) << 1) | (mx & 1);
296 uvsrc_x = s->
mb_x* 8 + (mx >> 1);
307 ptr_y = ref_picture[0] + src_y * linesize + src_x;
308 ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
309 ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
312 || (unsigned)src_y >
FFMAX( v_edge_pos - (motion_y&1) - h , 0)){
316 "MPEG motion vector out of boundary (%d %d)\n", src_x, src_y);
321 src_x, src_y<<field_based,
329 uvsrc_x, uvsrc_y<<field_based,
334 uvsrc_x, uvsrc_y<<field_based,
353 pix_op[0][dxy](dest_y, ptr_y,
linesize, h);
369 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
370 int field_based,
int bottom_field,
int field_select,
372 int motion_x,
int motion_y,
int h,
int mb_y)
377 bottom_field, field_select, ref_picture, pix_op,
378 motion_x, motion_y, h, 1, mb_y);
382 bottom_field, field_select, ref_picture, pix_op,
383 motion_x, motion_y, h, 0, mb_y);
389 uint8_t *
const top = src[1];
390 uint8_t *
const left = src[2];
391 uint8_t *
const mid = src[0];
392 uint8_t *
const right = src[3];
393 uint8_t *
const bottom= src[4];
394 #define OBMC_FILTER(x, t, l, m, r, b)\
395 dst[x]= (t*top[x] + l*left[x] + m*mid[x] + r*right[x] + b*bottom[x] + 4)>>3
396 #define OBMC_FILTER4(x, t, l, m, r, b)\
397 OBMC_FILTER(x , t, l, m, r, b);\
398 OBMC_FILTER(x+1 , t, l, m, r, b);\
399 OBMC_FILTER(x +stride, t, l, m, r, b);\
400 OBMC_FILTER(x+1+stride, t, l, m, r, b);
440 uint8_t *
dest, uint8_t *src,
441 int src_x,
int src_y,
452 if(i && mv[i][0]==mv[
MID][0] && mv[i][1]==mv[
MID][1]){
469 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
470 int field_based,
int bottom_field,
int field_select,
473 int motion_x,
int motion_y,
int h)
475 uint8_t *ptr_y, *ptr_cb, *ptr_cr;
476 int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y,
v_edge_pos,
linesize,
uvlinesize;
478 dxy = ((motion_y & 3) << 2) | (motion_x & 3);
479 src_x = s->
mb_x * 16 + (motion_x >> 2);
480 src_y = s->
mb_y * (16 >> field_based) + (motion_y >> 2);
483 linesize = s->
linesize << field_based;
490 static const int rtab[8]= {0,0,1,1,0,0,0,1};
491 mx= (motion_x>>1) + rtab[motion_x&7];
492 my= (motion_y>>1) + rtab[motion_y&7];
494 mx= (motion_x>>1)|(motion_x&1);
495 my= (motion_y>>1)|(motion_y&1);
503 uvdxy= (mx&1) | ((my&1)<<1);
507 uvsrc_x = s->
mb_x * 8 + mx;
508 uvsrc_y = s->
mb_y * (8 >> field_based) + my;
510 ptr_y = ref_picture[0] + src_y * linesize + src_x;
511 ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
512 ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
515 || (unsigned)src_y >
FFMAX( v_edge_pos - (motion_y&3) - h , 0)){
517 17, 17+field_based, src_x, src_y<<field_based,
524 uvsrc_x, uvsrc_y<<field_based,
528 uvsrc_x, uvsrc_y<<field_based,
536 qpix_op[0][dxy](dest_y, ptr_y,
linesize);
551 qpix_op[1][dxy](dest_y , ptr_y ,
linesize);
552 qpix_op[1][dxy](dest_y+8, ptr_y+8,
linesize);
555 pix_op[1][uvdxy](dest_cr, ptr_cr,
uvlinesize, h >> 1);
556 pix_op[1][uvdxy](dest_cb, ptr_cb,
uvlinesize, h >> 1);
564 uint8_t *dest_cb, uint8_t *dest_cr,
565 uint8_t **ref_picture,
568 int dxy, emu=0, src_x, src_y, offset;
576 dxy = ((my & 1) << 1) | (mx & 1);
580 src_x = s->
mb_x * 8 + mx;
581 src_y = s->
mb_y * 8 + my;
582 src_x = av_clip(src_x, -8, (s->
width >> 1));
583 if (src_x == (s->
width >> 1))
585 src_y = av_clip(src_y, -8, (s->
height >> 1));
586 if (src_y == (s->
height >> 1))
590 ptr = ref_picture[1] + offset;
603 ptr = ref_picture[2] + offset;
617 const int mx= (s->
mv[dir][0][0]>>shift) + 16*s->
mb_x + 8;
618 const int my= (s->
mv[dir][0][1]>>shift) + 16*s->
mb_y;
638 uint8_t *dest_y, uint8_t *dest_cb,
639 uint8_t *dest_cr,
int dir,
640 uint8_t **ref_picture,
644 int dxy, mx, my, src_x, src_y, motion_x, motion_y;
654 int16_t mv_cache[4][4][2];
657 const int mot_xy= mb_x*2 + mb_y*2*mot_stride;
666 memcpy(mv_cache[0][1], mv_cache[1][1],
sizeof(int16_t)*4);
672 AV_COPY32(mv_cache[1][0], mv_cache[1][1]);
673 AV_COPY32(mv_cache[2][0], mv_cache[2][1]);
680 AV_COPY32(mv_cache[1][3], mv_cache[1][2]);
681 AV_COPY32(mv_cache[2][3], mv_cache[2][2]);
690 const int x= (i&1)+1;
691 const int y= (i>>1)+1;
693 {mv_cache[y][x ][0], mv_cache[y][x ][1]},
694 {mv_cache[y-1][x][0], mv_cache[y-1][x][1]},
695 {mv_cache[y][x-1][0], mv_cache[y][x-1][1]},
696 {mv_cache[y][x+1][0], mv_cache[y][x+1][1]},
697 {mv_cache[y+1][x][0], mv_cache[y+1][x][1]}};
701 mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8,
727 ref_picture, pix_op, qpix_op,
728 s->
mv[dir][0][0], s->
mv[dir][0][1], 16);
733 s->
mv[dir][0][0], s->
mv[dir][0][1], 16);
739 s->
mv[dir][0][0], s->
mv[dir][0][1], 16, mb_y);
748 motion_x = s->
mv[dir][i][0];
749 motion_y = s->
mv[dir][i][1];
751 dxy = ((motion_y & 3) << 2) | (motion_x & 3);
752 src_x = mb_x * 16 + (motion_x >> 2) + (i & 1) * 8;
753 src_y = mb_y * 16 + (motion_y >> 2) + (i >>1) * 8;
756 src_x = av_clip(src_x, -16, s->
width);
757 if (src_x == s->
width)
759 src_y = av_clip(src_y, -16, s->
height);
763 ptr = ref_picture[0] + (src_y * s->
linesize) + (src_x);
774 dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->
linesize;
775 qpix_op[1][dxy](dest, ptr, s->
linesize);
777 mx += s->
mv[dir][i][0]/2;
778 my += s->
mv[dir][i][1]/2;
783 ref_picture[0], 0, 0,
784 mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8,
788 s->
mv[dir][i][0], s->
mv[dir][i][1]);
790 mx += s->
mv[dir][i][0];
791 my += s->
mv[dir][i][1];
805 ref_picture, pix_op, qpix_op,
806 s->
mv[dir][i][0], s->
mv[dir][i][1], 8);
813 s->
mv[dir][0][0], s->
mv[dir][0][1], 8, mb_y);
818 s->
mv[dir][1][0], s->
mv[dir][1][1], 8, mb_y);
828 s->
mv[dir][0][0], s->
mv[dir][0][1], 16, mb_y>>1);
833 uint8_t ** ref2picture;
837 ref2picture= ref_picture;
845 s->
mv[dir][i][0], s->
mv[dir][i][1] + 16*i, 8, mb_y>>1);
860 s->
mv[dir][2*i + j][0], s->
mv[dir][2*i + j][1], 8, mb_y);
869 s->
mv[dir][2*i][0],s->
mv[dir][2*i][1],16, mb_y>>1);
886 uint8_t *dest_y, uint8_t *dest_cb,
887 uint8_t *dest_cr,
int dir,
888 uint8_t **ref_picture,
895 ref_picture, pix_op, qpix_op, 1);
899 ref_picture, pix_op, qpix_op, 0);