📄 mpegvideo_common.h
字号:
uvdxy = dxy; uvsrc_x = src_x; uvsrc_y = src_y; } } } ptr_y = ref_picture[0] + src_y * linesize + src_x; ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; if( (unsigned)src_x > s->h_edge_pos - (motion_x&1) - 16 || (unsigned)src_y > v_edge_pos - (motion_y&1) - h){ if(is_mpeg12 || s->codec_id == CODEC_ID_MPEG2VIDEO || s->codec_id == CODEC_ID_MPEG1VIDEO){ av_log(s->avctx,AV_LOG_DEBUG, "MPEG motion vector out of boundary\n"); return ; } ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based, src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos); ptr_y = s->edge_emu_buffer; if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize; ff_emulated_edge_mc(uvbuf , ptr_cb, s->uvlinesize, 9, 9+field_based, uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); ff_emulated_edge_mc(uvbuf+16, ptr_cr, s->uvlinesize, 9, 9+field_based, uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); ptr_cb= uvbuf; ptr_cr= uvbuf+16; } } if(bottom_field){ //FIXME use this for field pix too instead of the obnoxious hack which changes picture.data dest_y += s->linesize; dest_cb+= s->uvlinesize; dest_cr+= s->uvlinesize; } if(field_select){ ptr_y += s->linesize; ptr_cb+= s->uvlinesize; ptr_cr+= s->uvlinesize; } pix_op[0][dxy](dest_y, ptr_y, linesize, h); if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ pix_op[s->chroma_x_shift][uvdxy] (dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift); pix_op[s->chroma_x_shift][uvdxy] (dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift); } if(!is_mpeg12 && (CONFIG_H261_ENCODER || CONFIG_H261_DECODER) && s->out_format == FMT_H261){ }}/* apply one mpeg motion vector to the three components */static av_always_inlinevoid mpeg_motion(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int field_based, int bottom_field, int field_select, uint8_t **ref_picture, op_pixels_func (*pix_op)[4], int motion_x, int motion_y, int h){#if !CONFIG_SMALL if(s->out_format == FMT_MPEG1) mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, field_based, bottom_field, field_select, ref_picture, pix_op, motion_x, motion_y, h, 1); else#endif mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, field_based, bottom_field, field_select, ref_picture, pix_op, motion_x, motion_y, h, 0);}//FIXME move to dsputil, avg variant, 16x16 versionstatic _inline void put_obmc(uint8_t *dst, uint8_t *src[5], int stride){ int x; uint8_t * const top = src[1]; uint8_t * const left = src[2]; uint8_t * const mid = src[0]; uint8_t * const right = src[3]; uint8_t * const bottom= src[4];#define OBMC_FILTER(x, t, l, m, r, b)\ dst[x]= (t*top[x] + l*left[x] + m*mid[x] + r*right[x] + b*bottom[x] + 4)>>3#define OBMC_FILTER4(x, t, l, m, r, b)\ OBMC_FILTER(x , t, l, m, r, b);\ OBMC_FILTER(x+1 , t, l, m, r, b);\ OBMC_FILTER(x +stride, t, l, m, r, b);\ OBMC_FILTER(x+1+stride, t, l, m, r, b); x=0; OBMC_FILTER (x , 2, 2, 4, 0, 0); OBMC_FILTER (x+1, 2, 1, 5, 0, 0); OBMC_FILTER4(x+2, 2, 1, 5, 0, 0); OBMC_FILTER4(x+4, 2, 0, 5, 1, 0); OBMC_FILTER (x+6, 2, 0, 5, 1, 0); OBMC_FILTER (x+7, 2, 0, 4, 2, 0); x+= stride; OBMC_FILTER (x , 1, 2, 5, 0, 0); OBMC_FILTER (x+1, 1, 2, 5, 0, 0); OBMC_FILTER (x+6, 1, 0, 5, 2, 0); OBMC_FILTER (x+7, 1, 0, 5, 2, 0); x+= stride; OBMC_FILTER4(x , 1, 2, 5, 0, 0); OBMC_FILTER4(x+2, 1, 1, 6, 0, 0); OBMC_FILTER4(x+4, 1, 0, 6, 1, 0); OBMC_FILTER4(x+6, 1, 0, 5, 2, 0); x+= 2*stride; OBMC_FILTER4(x , 0, 2, 5, 0, 1); OBMC_FILTER4(x+2, 0, 1, 6, 0, 1); OBMC_FILTER4(x+4, 0, 0, 6, 1, 1); OBMC_FILTER4(x+6, 0, 0, 5, 2, 1); x+= 2*stride; OBMC_FILTER (x , 0, 2, 5, 0, 1); OBMC_FILTER (x+1, 0, 2, 5, 0, 1); OBMC_FILTER4(x+2, 0, 1, 5, 0, 2); OBMC_FILTER4(x+4, 0, 0, 5, 1, 2); OBMC_FILTER (x+6, 0, 0, 5, 2, 1); OBMC_FILTER (x+7, 0, 0, 5, 2, 1); x+= stride; OBMC_FILTER (x , 0, 2, 4, 0, 2); OBMC_FILTER (x+1, 0, 1, 5, 0, 2); OBMC_FILTER (x+6, 0, 0, 5, 1, 2); OBMC_FILTER (x+7, 0, 0, 4, 2, 2);}/* obmc for 1 8x8 luma block */static _inline void obmc_motion(MpegEncContext *s, uint8_t *dest, uint8_t *src, int src_x, int src_y, op_pixels_func *pix_op, int16_t mv[5][2]/* mid top left right bottom*/)#define MID 0{ int i; uint8_t *ptr[5]; assert(s->quarter_sample==0); for(i=0; i<5; i++){ if(i && mv[i][0]==mv[MID][0] && mv[i][1]==mv[MID][1]){ ptr[i]= ptr[MID]; }else{ ptr[i]= s->obmc_scratchpad + 8*(i&1) + s->linesize*8*(i>>1); hpel_motion(s, ptr[i], src, 0, 0, src_x, src_y, s->width, s->height, s->linesize, s->h_edge_pos, s->v_edge_pos, 8, 8, pix_op, mv[i][0], mv[i][1]); } } put_obmc(dest, ptr, s->linesize);}static _inline void qpel_motion(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int field_based, int bottom_field, int field_select, uint8_t **ref_picture, op_pixels_func (*pix_op)[4], qpel_mc_func (*qpix_op)[16], int motion_x, int motion_y, int h){ uint8_t *ptr_y, *ptr_cb, *ptr_cr; int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y, v_edge_pos, linesize, uvlinesize; dxy = ((motion_y & 3) << 2) | (motion_x & 3); src_x = s->mb_x * 16 + (motion_x >> 2); src_y = s->mb_y * (16 >> field_based) + (motion_y >> 2); v_edge_pos = s->v_edge_pos >> field_based; linesize = s->linesize << field_based; uvlinesize = s->uvlinesize << field_based; if(field_based){ mx= motion_x/2; my= motion_y>>1; }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA2){ static const int rtab[8]= {0,0,1,1,0,0,0,1}; mx= (motion_x>>1) + rtab[motion_x&7]; my= (motion_y>>1) + rtab[motion_y&7]; }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA){ mx= (motion_x>>1)|(motion_x&1); my= (motion_y>>1)|(motion_y&1); }else{ mx= motion_x/2; my= motion_y/2; } mx= (mx>>1)|(mx&1); my= (my>>1)|(my&1); uvdxy= (mx&1) | ((my&1)<<1); mx>>=1; my>>=1; uvsrc_x = s->mb_x * 8 + mx; uvsrc_y = s->mb_y * (8 >> field_based) + my; ptr_y = ref_picture[0] + src_y * linesize + src_x; ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; if( (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 16 || (unsigned)src_y > v_edge_pos - (motion_y&3) - h ){ ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based, src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos); ptr_y= s->edge_emu_buffer; if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ uint8_t *uvbuf= s->edge_emu_buffer + 18*s->linesize; ff_emulated_edge_mc(uvbuf, ptr_cb, s->uvlinesize, 9, 9 + field_based, uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); ff_emulated_edge_mc(uvbuf + 16, ptr_cr, s->uvlinesize, 9, 9 + field_based, uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); ptr_cb= uvbuf; ptr_cr= uvbuf + 16; } } if(!field_based) qpix_op[0][dxy](dest_y, ptr_y, linesize); else{ if(bottom_field){ dest_y += s->linesize; dest_cb+= s->uvlinesize; dest_cr+= s->uvlinesize; } if(field_select){ ptr_y += s->linesize; ptr_cb += s->uvlinesize; ptr_cr += s->uvlinesize; } //damn interlaced mode //FIXME boundary mirroring is not exactly correct here qpix_op[1][dxy](dest_y , ptr_y , linesize); qpix_op[1][dxy](dest_y+8, ptr_y+8, linesize); } if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ pix_op[1][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> 1); pix_op[1][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> 1); }}/** * h263 chroma 4mv motion compensation. */static _inline void chroma_4mv_motion(MpegEncContext *s, uint8_t *dest_cb, uint8_t *dest_cr, uint8_t **ref_picture, op_pixels_func *pix_op, int mx, int my){ int dxy, emu=0, src_x, src_y, offset; uint8_t *ptr; /* In case of 8X8, we construct a single chroma motion vector with a special rounding */ mx= ff_h263_round_chroma(mx); my= ff_h263_round_chroma(my); dxy = ((my & 1) << 1) | (mx & 1); mx >>= 1; my >>= 1; src_x = s->mb_x * 8 + mx; src_y = s->mb_y * 8 + my; src_x = av_clip(src_x, -8, s->width/2); if (src_x == s->width/2) dxy &= ~1; src_y = av_clip(src_y, -8, s->height/2); if (src_y == s->height/2) dxy &= ~2; offset = (src_y * (s->uvlinesize)) + src_x; ptr = ref_picture[1] + offset; if(s->flags&CODEC_FLAG_EMU_EDGE){ if( (unsigned)src_x > (s->h_edge_pos>>1) - (dxy &1) - 8 || (unsigned)src_y > (s->v_edge_pos>>1) - (dxy>>1) - 8){ ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); ptr= s->edge_emu_buffer; emu=1; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -