转载自X265

最近要开始研究HEVC帧内预测和显著度的关系,所以先把HM的帧内预测理一理,有些东西总是记了忘,所以干脆写下这。HM与X265有相关,变量有的定义类似。

  1. struct PredictionUnit  
  2. {  
  3.     uint32_t     ctuAddr;      // raster index of current CTU within its picture  
  4.     uint32_t     cuAbsPartIdx; // z-order offset of current CU within its CTU  
  5.     uint32_t     puAbsPartIdx; // z-order offset of current PU with its CU  
  6.     int          width;  
  7.     int          height;  
  8.   
  9.     PredictionUnit(const CUData& cu, const CUGeom& cuGeom, int puIdx);  
  10. };  
  11.   
  12. class Predict  
  13. {  
  14. public:  
  15.   
  16.     enum { ADI_BUF_STRIDE = (2 * MAX_CU_SIZE + 1 + 15) }; // alignment to 16 bytes  
  17.   
  18.     /* Weighted prediction scaling values built from slice parameters (bitdepth scaled) */  
  19.     struct WeightValues  
  20.     {  
  21.         int w, o, offset, shift, round;  
  22.     };  
  1.  struct IntraNeighbors//Predict内部类 用于存储周边块的可用标记等信息  
  2.     {  
  3.         int      numIntraNeighbor;//统计当前预测块周边多少可用4x4相邻块  
  4.         int      totalUnits;//周边4x4块个数  左下、左边、左上角1个、上边、右上  
  5.         int      aboveUnits;//上边4x4个数:上边 右上  
  6.         int      leftUnits;//左边4x4个数:左边、左下  
  7.         int      unitWidth;//当前最小块宽度,4  
  8.         int      unitHeight;//当前最小块高度,4  
  9.         int      log2TrSize;//当前PU-TU深度  
  10.         bool     bNeighborFlags[4 * MAX_NUM_SPU_W + 1];//空间大小为65  存储周边标记是否可用  存储方式: 左下、左边(左下和左边按照离左上角由远及近存储0:左下左下像素点....左上角4x4块像素点)、左上角一点、上边、右上   
  11.         /* 
  12.         标记对应块是否可用(4x4),如当前PU为64x64: 
  13.         拥有4x4个数tuWidthInUnits = 16,tuHeightInUnits=16 
  14.         左上角参考像素点标记:bNeighborFlags[tuHeightInUnits *2]  :bNeighborFlags[32] 
  15.         上边行参考像素点标记:bNeighborFlags[tuHeightInUnits *2+1 ....tuHeightInUnits *2+tuWidthInUnits]:bNeighborFlags[33~48] 
  16.         右上边行参考像素点标记:bNeighborFlags[tuHeightInUnits *2+tuWidthInUnits+1 ....tuHeightInUnits *2+2*tuWidthInUnits]:bNeighborFlags[49~64] 
  17.         左边行参考像素点标记:bNeighborFlags[tuHeightInUnits  ....tuHeightInUnits *2-1]:bNeighborFlags[16~31] 
  18.         左下边行参考像素点标记:bNeighborFlags[0  ....tuHeightInUnits - 1]:bNeighborFlags[0~15] 
  19.         **/  
  20.     };  
  1.   ShortYuv  m_predShortYuv[2]; /* temporary storage for weighted prediction */  
  2.     int16_t*  m_immedVals;  
  3.   
  4.     // Unfiltered/filtered neighbours of the current partition.  
  5.     pixel     intraNeighbourBuf[2][258];// 存储当前周边行的数据 第一维是参考数据,第二维是经过滤波后的数据  
  6.     /* 
  7.     如当前PU为64x64: 
  8.     tuWidthInUnits = 16,tuHeightInUnits=16 
  9.     左上角参考像素点:0 
  10.     上边行参考像素点:1~16 
  11.     右上边行参考像素点:17~32 
  12.     左边行参考像素点:33~48 
  13.     左下边行参考像素点:49~64 
  14.     **/  
  15.   
  16.     /* Slice information */  
  17.     int       m_csp;  
  18.     int       m_hChromaShift;  
  19.     int       m_vChromaShift;  
  20.   
  21.     Predict();  
  22.     ~Predict();  
  23.   
  24.     bool allocBuffers(int csp);  
  25.   
  26.     // motion compensation functions  
  27.     void predInterLumaPixel(const PredictionUnit& pu, Yuv& dstYuv, const PicYuv& refPic, const MV& mv) const;  
  28.     void predInterChromaPixel(const PredictionUnit& pu, Yuv& dstYuv, const PicYuv& refPic, const MV& mv) const;  
  29.   
  30.     void predInterLumaShort(const PredictionUnit& pu, ShortYuv& dstSYuv, const PicYuv& refPic, const MV& mv) const;  
  31.     void predInterChromaShort(const PredictionUnit& pu, ShortYuv& dstSYuv, const PicYuv& refPic, const MV& mv) const;  
  32.   
  33.     void addWeightBi(const PredictionUnit& pu, Yuv& predYuv, const ShortYuv& srcYuv0, const ShortYuv& srcYuv1, const WeightValues wp0[3], const WeightValues wp1[3], bool bLuma, bool bChroma) const;  
  34.     void addWeightUni(const PredictionUnit& pu, Yuv& predYuv, const ShortYuv& srcYuv, const WeightValues wp[3], bool bLuma, bool bChroma) const;  
  35.   
  36.     void motionCompensation(const CUData& cu, const PredictionUnit& pu, Yuv& predYuv, bool bLuma, bool bChroma);  
  37.   
  38.     /* Angular Intra */  
  39.     /** 函数功能             : 按照当前的亮度预测方向获取预测值 
  40.     /*  调用范围             : 只在codeIntraLumaQT、codeIntraLumaTSkip、residualTransformQuantIntra函数中被调用 
  41.     * \参数 dirMode          : 当前亮度方向 
  42.     * \参数 dst              : PU预测块地址 
  43.     * \参数 stride           : 原始块步长 
  44.     * \参数 log2TrSize       : 当前PU的最大变换大小 
  45.     *   返回值               : null**/  
  46.     void predIntraLumaAng(uint32_t dirMode, pixel* pred, intptr_t stride, uint32_t log2TrSize);  
  47.     void predIntraChromaAng(uint32_t dirMode, pixel* pred, intptr_t stride, uint32_t log2TrSizeC);  
  48.     /** 函数功能             : 获取intra周边参考像素点 并对其滤波 
  49.     * \参数 cu               : 当前编码的CU 
  50.     * \参数 cuGeom           : 当前CU几何信息 
  51.     * \参数 puAbsPartIdx     : 为当前PU在当前CU下的zigzag标号,不是CTU下的zigzag标号 
  52.     * \参数 intraNeighbors   : 当前PU周边块的可用信息 
  53.     * \参数 dirMode          : 具体亮度模式 或者 ALL_IDX(在搜索intra方向时是此值) 
  54.     *   返回值               : null**/  
  55.     void initAdiPattern(const CUData& cu, const CUGeom& cuGeom, uint32_t puAbsPartIdx, const IntraNeighbors& intraNeighbors, int dirMode);  
  56.     void initAdiPatternChroma(const CUData& cu, const CUGeom& cuGeom, uint32_t puAbsPartIdx, const IntraNeighbors& intraNeighbors, uint32_t chromaId);  
  57.   
  58.     /* Intra prediction helper functions */  
  59.     /** 函数功能             : 返回intraNeighbors中周边可用块信息 
  60.     * \参数 cu               : 当前编码的CU 
  61.     * \参数 absPartIdx       : 为当前PU在当前CU下的zigzag标号,不是CTU下的zigzag标号 
  62.     * \参数 tuDepth          : 当前的TU深度 
  63.     * \参数 isLuma           : 当前是否为亮度模式 
  64.     * \参数 intraNeighbors   : 用于存储当前块的周边信息 
  65.     *   返回值               : null**/  
  66.     static void initIntraNeighbors(const CUData& cu, uint32_t absPartIdx, uint32_t tuDepth, bool isLuma, IntraNeighbors *IntraNeighbors);  
  67.     /** 函数功能             : 获取周边行数据 并且 填充数据 对应不可用的块 按照由远及近遍历左下、左、左上角、上边 、右上顺序填充(选择前面第一个可用位置) 
  68.     /*  调用范围             : 只在initAdiPattern和initAdiPatternChroma中调用 
  69.     * \参数 adiOrigin        : PU左上角在重构帧对应的pixel地址 
  70.     * \参数 picStride        : 重构帧步长 
  71.     * \参数 intraNeighbors   : 当前PU周边块的可用信息 
  72.     * \参数 dst[258]         : 存储周边参考像素值: 存储方式  左上角一点  上边  右上  左边  左下 
  73.     *   返回值               : null**/  
  74.     static void fillReferenceSamples(const pixel* adiOrigin, intptr_t picStride, const IntraNeighbors& intraNeighbors, pixel dst[258]);  
  75.     /** 函数功能             : 返回当前左上角像素点是否可用 
  76.     * \参数 cip              : 帧内预测是否受限(不能参考inter块) 
  77.     * \参数 cu               : 当前编码的CU 
  78.     * \参数 partIdxLT        : 当前PU左上角像素点在CTU中的zigzag标号 
  79.     *   返回值               : 返回当前左上角像素点是否可用**/  
  80.     template<bool cip>  
  81.     static bool isAboveLeftAvailable(const CUData& cu, uint32_t partIdxLT);  
  82.     template<bool cip>  
  83.     /** 函数功能             : 返回当前上边行像素点可用个数 
  84.     * \参数 cip              : 帧内预测是否受限(不能参考inter块) 
  85.     * \参数 cu               : 当前编码的CU 
  86.     * \参数 partIdxLT        : 当前PU左上角像素点在CTU中的zigzag标号 
  87.     * \参数 partIdxRT        : 当前PU右上角像素点在CTU中的zigzag标号 
  88.     * \参数 bValidFlags      : 用于存上边可用4x4块的标记 
  89.     *   返回值               : 返回上边行可用的4x4块个数**/  
  90.     static int  isAboveAvailable(const CUData& cu, uint32_t partIdxLT, uint32_t partIdxRT, bool* bValidFlags);  
  91.     /** 函数功能             : 返回当前左边行像素点可用个数 
  92.     * \参数 cip              : 帧内预测是否受限(不能参考inter块) 
  93.     * \参数 cu               : 当前编码的CU 
  94.     * \参数 partIdxLT        : 当前PU左上角像素点在CTU中的zigzag标号 
  95.     * \参数 partIdxLB        : 当前PU左下角像素点在CTU中的zigzag标号 
  96.     * \参数 bValidFlags      : 用于存边可用4x4块的标记 
  97.     *   返回值               : 返回左边行可用的4x4块个数**/  
  98.     template<bool cip>  
  99.     static int  isLeftAvailable(const CUData& cu, uint32_t partIdxLT, uint32_t partIdxLB, bool* bValidFlags);  
  100.     /** 函数功能             : 返回当前右上边行像素点可用个数 
  101.     * \参数 cip              : 帧内预测是否受限(不能参考inter块) 
  102.     * \参数 cu               : 当前编码的CU 
  103.     * \参数 partIdxRT        : 当前PU右上角像素点在CTU中的zigzag标号 
  104.     * \参数 bValidFlags      : 用于存右上边可用4x4块的标记 
  105.     * \参数 numUnits         : 当前PU宽度的4x4块个数 
  106.     *   返回值               : 返回右上边行可用的4x4块个数**/  
  107.     template<bool cip>  
  108.     static int  isAboveRightAvailable(const CUData& cu, uint32_t partIdxRT, bool* bValidFlags, uint32_t numUnits);  
  109.     /** 函数功能             : 返回当前左下边行像素点可用个数 
  110.     * \参数 cip              : 帧内预测是否受限(不能参考inter块) 
  111.     * \参数 cu               : 当前编码的CU 
  112.     * \参数 partIdxLB        : 当前PU左下角像素点在CTU中的zigzag标号 
  113.     * \参数 bValidFlags      : 用于存左下边可用4x4块的标记 
  114.     * \参数 numUnits         : 当前PU高度的4x4块个数 
  115.     *   返回值               : 返回左下边行可用的4x4块个数**/  
  116.     template<bool cip>  
  117.     static int  isBelowLeftAvailable(const CUData& cu, uint32_t partIdxLB, bool* bValidFlags, uint32_t numUnits);  
  118. };  
  119. }  
  120.   
  121. #endif // ifndef X265_PREDICT_H  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值