1 /***************************************************************************** 2 * Copyright (C) 2013-2020 MulticoreWare, Inc 3 * 4 * Authors: Deepthi Nandakumar <deepthi@multicorewareinc.com> 5 * Min Chen <chenm003@163.com> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 20 * 21 * This program is also available under a commercial proprietary license. 22 * For more information, contact us at license @ x265.com. 23 *****************************************************************************/ 24 25 #ifndef X265_PREDICT_H 26 #define X265_PREDICT_H 27 28 #include "common.h" 29 #include "frame.h" 30 #include "quant.h" 31 #include "shortyuv.h" 32 #include "yuv.h" 33 34 namespace X265_NS { 35 36 class CUData; 37 class Slice; 38 struct CUGeom; 39 40 struct PredictionUnit 41 { 42 uint32_t ctuAddr; // raster index of current CTU within its picture 43 uint32_t cuAbsPartIdx; // z-order offset of current CU within its CTU 44 uint32_t puAbsPartIdx; // z-order offset of current PU with its CU 45 int width; 46 int height; 47 48 PredictionUnit(const CUData& cu, const CUGeom& cuGeom, int puIdx); 49 }; 50 51 class Predict 52 { 53 public: 54 55 enum { ADI_BUF_STRIDE = (2 * MAX_CU_SIZE + 1 + 15) }; // alignment to 16 bytes 56 57 /* Weighted prediction scaling values built from slice parameters (bitdepth scaled) */ 58 struct WeightValues 59 { 60 int w, o, offset, shift, round; 61 }; 62 63 struct IntraNeighbors 64 { 65 int numIntraNeighbor; 66 int totalUnits; 67 int aboveUnits; 68 int leftUnits; 69 int unitWidth; 70 int unitHeight; 71 int log2TrSize; 72 bool bNeighborFlags[4 * MAX_NUM_SPU_W + 1]; 73 }; 74 75 ShortYuv m_predShortYuv[2]; /* temporary storage for weighted prediction */ 76 77 // Unfiltered/filtered neighbours of the current partition. 78 pixel intraNeighbourBuf[2][258]; 79 80 /* Slice information */ 81 int m_csp; 82 int m_hChromaShift; 83 int m_vChromaShift; 84 85 Predict(); 86 ~Predict(); 87 88 bool allocBuffers(int csp); 89 90 // motion compensation functions 91 void predInterLumaPixel(const PredictionUnit& pu, Yuv& dstYuv, const PicYuv& refPic, const MV& mv) const; 92 void predInterChromaPixel(const PredictionUnit& pu, Yuv& dstYuv, const PicYuv& refPic, const MV& mv) const; 93 94 void predInterLumaShort(const PredictionUnit& pu, ShortYuv& dstSYuv, const PicYuv& refPic, const MV& mv) const; 95 void predInterChromaShort(const PredictionUnit& pu, ShortYuv& dstSYuv, const PicYuv& refPic, const MV& mv) const; 96 97 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; 98 void addWeightUni(const PredictionUnit& pu, Yuv& predYuv, const ShortYuv& srcYuv, const WeightValues wp[3], bool bLuma, bool bChroma) const; 99 100 void motionCompensation(const CUData& cu, const PredictionUnit& pu, Yuv& predYuv, bool bLuma, bool bChroma); 101 102 /* Angular Intra */ 103 void predIntraLumaAng(uint32_t dirMode, pixel* pred, intptr_t stride, uint32_t log2TrSize); 104 void predIntraChromaAng(uint32_t dirMode, pixel* pred, intptr_t stride, uint32_t log2TrSizeC); 105 void initAdiPattern(const CUData& cu, const CUGeom& cuGeom, uint32_t puAbsPartIdx, const IntraNeighbors& intraNeighbors, int dirMode); 106 void initAdiPatternChroma(const CUData& cu, const CUGeom& cuGeom, uint32_t puAbsPartIdx, const IntraNeighbors& intraNeighbors, uint32_t chromaId); 107 108 /* Intra prediction helper functions */ 109 static void initIntraNeighbors(const CUData& cu, uint32_t absPartIdx, uint32_t tuDepth, bool isLuma, IntraNeighbors *IntraNeighbors); 110 static void fillReferenceSamples(const pixel* adiOrigin, intptr_t picStride, const IntraNeighbors& intraNeighbors, pixel dst[258]); 111 template<bool cip> 112 static bool isAboveLeftAvailable(const CUData& cu, uint32_t partIdxLT); 113 template<bool cip> 114 static int isAboveAvailable(const CUData& cu, uint32_t partIdxLT, uint32_t partIdxRT, bool* bValidFlags); 115 template<bool cip> 116 static int isLeftAvailable(const CUData& cu, uint32_t partIdxLT, uint32_t partIdxLB, bool* bValidFlags); 117 template<bool cip> 118 static int isAboveRightAvailable(const CUData& cu, uint32_t partIdxRT, bool* bValidFlags, uint32_t numUnits); 119 template<bool cip> 120 static int isBelowLeftAvailable(const CUData& cu, uint32_t partIdxLB, bool* bValidFlags, uint32_t numUnits); 121 }; 122 } 123 124 #endif // ifndef X265_PREDICT_H 125