⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 macroblock.h

📁 另一个版本的x264的decoder
💻 H
📖 第 1 页 / 共 2 页
字号:
#define FF_IS_ACPRED(a)     ((a)&MB_TYPE_ACPRED)#define FF_IS_QUANT(a)      ((a)&MB_TYPE_QUANT)#define FF_IS_DIR(a, part, list) ((a) & (MB_TYPE_P0L0<<((part)+2*(list))))#define USES_LIST(a, list) ((a) & ((MB_TYPE_P0L0|MB_TYPE_P1L0)<<(2*(list)))) ///< does this mb use listX, note doesnt work if subMBs#define HAS_CBP(a)        ((a)&MB_TYPE_CBP)#define MB_TYPE_REF0       MB_TYPE_ACPRED //dirty but it fits in 16bit#define MB_TYPE_8x8DCT     0x01000000#define IS_REF0(a)       ((a)&MB_TYPE_REF0)#define IS_8x8DCT(a)     ((a)&MB_TYPE_8x8DCT)typedef struct PMbInfo{    uint16_t type;    uint8_t partition_count;} PMbInfo;static const PMbInfo p_mb_type_info[5]={{MB_TYPE_16x16|MB_TYPE_P0L0             , 1},{MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P1L0, 2},{MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P1L0, 2},{MB_TYPE_8x8  |MB_TYPE_P0L0|MB_TYPE_P1L0, 4},{MB_TYPE_8x8  |MB_TYPE_P0L0|MB_TYPE_P1L0|MB_TYPE_REF0, 4},};static const PMbInfo p_sub_mb_type_info[4]={{MB_TYPE_16x16|MB_TYPE_P0L0             , 1},{MB_TYPE_16x8 |MB_TYPE_P0L0             , 2},{MB_TYPE_8x16 |MB_TYPE_P0L0             , 2},{MB_TYPE_8x8  |MB_TYPE_P0L0             , 4},};static const PMbInfo b_mb_type_info[23]={{MB_TYPE_DIRECT2                                                  , 1, },{MB_TYPE_16x16|MB_TYPE_P0L0                                       , 1, },{MB_TYPE_16x16             |MB_TYPE_P0L1                          , 1, },{MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1                          , 1, },{MB_TYPE_16x8 |MB_TYPE_P0L0             |MB_TYPE_P1L0             , 2, },{MB_TYPE_8x16 |MB_TYPE_P0L0             |MB_TYPE_P1L0             , 2, },{MB_TYPE_16x8              |MB_TYPE_P0L1             |MB_TYPE_P1L1, 2, },{MB_TYPE_8x16              |MB_TYPE_P0L1             |MB_TYPE_P1L1, 2, },{MB_TYPE_16x8 |MB_TYPE_P0L0                          |MB_TYPE_P1L1, 2, },{MB_TYPE_8x16 |MB_TYPE_P0L0                          |MB_TYPE_P1L1, 2, },{MB_TYPE_16x8              |MB_TYPE_P0L1|MB_TYPE_P1L0             , 2, },{MB_TYPE_8x16              |MB_TYPE_P0L1|MB_TYPE_P1L0             , 2, },{MB_TYPE_16x8 |MB_TYPE_P0L0             |MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },{MB_TYPE_8x16 |MB_TYPE_P0L0             |MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },{MB_TYPE_16x8              |MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },{MB_TYPE_8x16              |MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },{MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0             , 2, },{MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0             , 2, },{MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P0L1             |MB_TYPE_P1L1, 2, },{MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P0L1             |MB_TYPE_P1L1, 2, },{MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },{MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },{MB_TYPE_8x8  |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 4, },};static const PMbInfo b_sub_mb_type_info[13]={{MB_TYPE_DIRECT2                                                  , 1, },{MB_TYPE_16x16|MB_TYPE_P0L0                                       , 1, },{MB_TYPE_16x16             |MB_TYPE_P0L1                          , 1, },{MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1                          , 1, },{MB_TYPE_16x8 |MB_TYPE_P0L0             |MB_TYPE_P1L0             , 2, },{MB_TYPE_8x16 |MB_TYPE_P0L0             |MB_TYPE_P1L0             , 2, },{MB_TYPE_16x8              |MB_TYPE_P0L1             |MB_TYPE_P1L1, 2, },{MB_TYPE_8x16              |MB_TYPE_P0L1             |MB_TYPE_P1L1, 2, },{MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },{MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },{MB_TYPE_8x8  |MB_TYPE_P0L0             |MB_TYPE_P1L0             , 4, },{MB_TYPE_8x8               |MB_TYPE_P0L1             |MB_TYPE_P1L1, 4, },{MB_TYPE_8x8  |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 4, },};void x264_macroblock_cache_init( x264_t *h );void x264_macroblock_slice_init( x264_t *h );void x264_macroblock_cache_load( x264_t *h, int i_mb_x, int i_mb_y );void x264_macroblock_cache_save( x264_t *h );void x264_macroblock_cache_end( x264_t *h );void x264_macroblock_bipred_init( x264_t *h );void x264_mb_dequant_4x4_dc( int16_t dct[4][4], int i_qscale );void x264_mb_dequant_2x2_dc( int16_t dct[2][2], int i_qscale );void x264_mb_dequant_4x4( int16_t dct[4][4], int i_qscale );/* x264_mb_predict_mv_16x16: *      set mvp with predicted mv for D_16x16 block *      h->mb. need only valid values from other blocks */void x264_mb_predict_mv_16x16( x264_t *h, int i_list, int i_ref, int mvp[2] );/* x264_mb_predict_mv_pskip: *      set mvp with predicted mv for P_SKIP *      h->mb. need only valid values from other blocks */void x264_mb_predict_mv_pskip( x264_t *h, int mv[2] );/* x264_mb_predict_mv: *      set mvp with predicted mv for all blocks except SKIP and DIRECT *      h->mb. need valid ref/partition/sub of current block to be valid *      and valid mv/ref from other blocks . */void x264_mb_predict_mv( x264_t *h, int i_list, int idx, int i_width, int mvp[2] );/* x264_mb_predict_mv_direct16x16: *      set h->mb.cache.mv and h->mb.cache.ref for B_SKIP or B_DIRECT *      h->mb. need only valid values from other blocks *      return 1 on success, 0 on failure */int x264_mb_predict_mv_direct( x264_t *h );/* x264_mb_load_mv_direct8x8: *      set h->mb.cache.mv and h->mb.cache.ref for B_DIRECT *      must be called only after x264_mb_predict_mv_direct16x16 */void x264_mb_load_mv_direct8x8( x264_t *h, int idx );/* x264_mb_predict_mv_ref16x16: *      set mvc with D_16x16 prediction. *      uses all neighbors, even those that didn't end up using this ref. *      h->mb. need only valid values from other blocks */void x264_mb_predict_mv_ref16x16( x264_t *h, int i_list, int i_ref, int mvc[5][2], int *i_mvc );static inline void x264_mb_mc_0xywh( x264_t *h, int x, int y, int width, int height );int  x264_mb_predict_intra4x4_mode( x264_t *h, int idx );int  x264_mb_predict_non_zero_code( x264_t *h, int idx );void x264_mb_encode_i4x4( x264_t *h, int idx, int i_qscale );void x264_mb_mc( x264_t *h );void x264_macroblock_cache_save( x264_t *h );int x264_macroblock_read_cabac( x264_t *h, bs_t *s );static int x264_macroblock_decode_ipcm( x264_t *h, bs_t *s );void x264_macroblock_decode_skip( x264_t *h );int x264_macroblock_read_cavlc( x264_t *h, bs_t *s );int x264_macroblock_decode( x264_t *h );void x264_mb_mc( x264_t *h );void pred_motion(x264_t * const h, int n, int part_width, int list, int ref, int *const mx, int * const my);void pred_8x16_motion(x264_t* const h, int n, int list, int ref, int * const mx, int * const my);int fetch_diagonal_mv(x264_t*h, const int16_t **C, int i, int list, int part_width);void pred_16x8_motion(x264_t* const h, int n, int list, int ref, int * const mx, int * const my);void pred_pskip_motion(x264_t* const h, int * const mx, int * const my);/** * assume littel endian in pc */static inline uint32_t pack16to32(int a, int b){#ifdef WORDS_BIGENDIAN   return (b&0xFFFF) + (a<<16);#else   return (a&0xFFFF) + (b<<16);#endif}/** * fill a rectangle. * @param h height of the rectangle, should be a constant * @param w width of the rectangle, should be a constant * @param size the size of val (1 or 4), should be a constant */static inline void  x264_fill_rectangle(void *vp, int w, int h, int stride, uint32_t val, int size){    uint8_t *p= (uint8_t*)vp;    //assert(size==1 || size==4);    w      *= size;    stride *= size;    //assert((((long)vp)&(FFMIN(w, STRIDE_ALIGN)-1)) == 0);    //assert((stride&(w-1))==0);    if(w==2 && h==2){        *(uint16_t*)(p + 0)=        *(uint16_t*)(p + stride)= size==4 ? val : val*0x0101;    }else if(w==2 && h==4){        *(uint16_t*)(p + 0*stride)=        *(uint16_t*)(p + 1*stride)=        *(uint16_t*)(p + 2*stride)=        *(uint16_t*)(p + 3*stride)= size==4 ? val : val*0x0101;    }else if(w==4 && h==1){        *(uint32_t*)(p + 0*stride)= size==4 ? val : val*0x01010101;    }else if(w==4 && h==2){        *(uint32_t*)(p + 0*stride)=        *(uint32_t*)(p + 1*stride)= size==4 ? val : val*0x01010101;    }else if(w==4 && h==4){        *(uint32_t*)(p + 0*stride)=        *(uint32_t*)(p + 1*stride)=        *(uint32_t*)(p + 2*stride)=        *(uint32_t*)(p + 3*stride)= size==4 ? val : val*0x01010101;    }else if(w==8 && h==1){        *(uint32_t*)(p + 0)=        *(uint32_t*)(p + 4)= size==4 ? val : val*0x01010101;    }else if(w==8 && h==2){        *(uint32_t*)(p + 0 + 0*stride)=        *(uint32_t*)(p + 4 + 0*stride)=        *(uint32_t*)(p + 0 + 1*stride)=        *(uint32_t*)(p + 4 + 1*stride)=  size==4 ? val : val*0x01010101;    }else if(w==8 && h==4){		uint64_t num0=0x0100000001;		uint64_t num1=0x0101010101010101;        *(uint64_t*)(p + 0*stride)=        *(uint64_t*)(p + 1*stride)=        *(uint64_t*)(p + 2*stride)=        *(uint64_t*)(p + 3*stride)= size==4 ? val*num0 : val*num1;    }else if(w==16 && h==2){		uint64_t num0=0x0100000001;		uint64_t num1=0x0101010101010101;        *(uint64_t*)(p + 0+0*stride)=        *(uint64_t*)(p + 8+0*stride)=        *(uint64_t*)(p + 0+1*stride)=        *(uint64_t*)(p + 8+1*stride)= size==4 ? val*num0 : val*num1;    }else if(w==16 && h==4){		uint64_t num0=0x0100000001;		uint64_t num1=0x0101010101010101;        *(uint64_t*)(p + 0+0*stride)=        *(uint64_t*)(p + 8+0*stride)=        *(uint64_t*)(p + 0+1*stride)=        *(uint64_t*)(p + 8+1*stride)=        *(uint64_t*)(p + 0+2*stride)=        *(uint64_t*)(p + 8+2*stride)=        *(uint64_t*)(p + 0+3*stride)=        *(uint64_t*)(p + 8+3*stride)= size==4 ? val*num0 : val*num1;    }}static inline void x264_macroblock_cache_ref( x264_t *h, int x, int y, int width, int height, int i_list, int ref ){    int dy, dx;    for( dy = 0; dy < height; dy++ )    {        for( dx = 0; dx < width; dx++ )        {            h->mb.cache.ref[i_list][X264_SCAN8_0+x+dx+8*(y+dy)] = ref;        }    }}static inline void x264_macroblock_cache_mv( x264_t *h, int x, int y, int width, int height, int i_list, int mvx, int mvy ){    int dy, dx;    for( dy = 0; dy < height; dy++ )    {        for( dx = 0; dx < width; dx++ )        {            h->mb.cache.mv[i_list][X264_SCAN8_0+x+dx+8*(y+dy)][0] = mvx;            h->mb.cache.mv[i_list][X264_SCAN8_0+x+dx+8*(y+dy)][1] = mvy;        }    }}static inline void x264_macroblock_cache_mvd( x264_t *h, int x, int y, int width, int height, int i_list, int mdx, int mdy ){    int dy, dx;    for( dy = 0; dy < height; dy++ )    {        for( dx = 0; dx < width; dx++ )        {            h->mb.cache.mvd[i_list][X264_SCAN8_0+x+dx+8*(y+dy)][0] = mdx;            h->mb.cache.mvd[i_list][X264_SCAN8_0+x+dx+8*(y+dy)][1] = mdy;        }    }}static inline void x264_macroblock_cache_skip( x264_t *h, int x, int y, int width, int height, int b_skip ){    int dy, dx;    for( dy = 0; dy < height; dy++ )    {        for( dx = 0; dx < width; dx++ )        {            h->mb.cache.skip[X264_SCAN8_0+x+dx+8*(y+dy)] = b_skip;        }    }}#endifvoid weight_pred_init(x264_t *h, int i_ref0, int i_ref1);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -