Commit | Line | Data |
---|---|---|
72b9787e JB |
1 | /***************************************************************************** |
2 | * Copyright (C) 2013 x265 project | |
3 | * | |
4 | * Authors: Deepthi Nandakumar <deepthi@multicorewareinc.com> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. | |
19 | * | |
20 | * This program is also available under a commercial proprietary license. | |
21 | * For more information, contact us at license @ x265.com. | |
22 | *****************************************************************************/ | |
23 | ||
24 | #ifndef X265_PREDICT_H | |
25 | #define X265_PREDICT_H | |
26 | ||
27 | #include "common.h" | |
28 | #include "frame.h" | |
29 | #include "quant.h" | |
30 | #include "shortyuv.h" | |
31 | #include "yuv.h" | |
32 | ||
33 | namespace x265 { | |
34 | ||
35 | class CUData; | |
36 | class Slice; | |
37 | struct CUGeom; | |
38 | ||
39 | class Predict | |
40 | { | |
41 | public: | |
42 | ||
43 | enum { ADI_BUF_STRIDE = (2 * MAX_CU_SIZE + 1 + 15) }; // alignment to 16 bytes | |
44 | ||
45 | /* Weighted prediction scaling values built from slice parameters (bitdepth scaled) */ | |
46 | struct WeightValues | |
47 | { | |
48 | int w, o, offset, shift, round; | |
49 | }; | |
50 | ||
51 | struct IntraNeighbors | |
52 | { | |
53 | int numIntraNeighbor; | |
54 | int totalUnits; | |
55 | int aboveUnits; | |
56 | int leftUnits; | |
57 | int unitWidth; | |
58 | int unitHeight; | |
59 | int tuSize; | |
60 | uint32_t log2TrSize; | |
61 | bool bNeighborFlags[4 * MAX_NUM_SPU_W + 1]; | |
62 | }; | |
63 | ||
64 | ShortYuv m_predShortYuv[2]; /* temporary storage for weighted prediction */ | |
65 | int16_t* m_immedVals; | |
66 | ||
67 | /* Intra prediction buffers */ | |
68 | pixel* m_predBuf; | |
69 | pixel* m_refAbove; | |
70 | pixel* m_refAboveFlt; | |
71 | pixel* m_refLeft; | |
72 | pixel* m_refLeftFlt; | |
73 | ||
74 | /* Slice information */ | |
75 | const Slice* m_predSlice; | |
76 | int m_csp; | |
77 | int m_hChromaShift; | |
78 | int m_vChromaShift; | |
79 | ||
80 | /* cached CU information for prediction */ | |
81 | uint32_t m_ctuAddr; // raster index of current CTU within its picture | |
82 | uint32_t m_cuAbsPartIdx; // z-order index of current CU within its CTU | |
83 | uint32_t m_puAbsPartIdx; // z-order index of current PU with its CU | |
84 | int m_puWidth; | |
85 | int m_puHeight; | |
86 | int m_refIdx0; | |
87 | int m_refIdx1; | |
88 | ||
89 | /* TODO: Need to investigate clipping while writing into the TComDataCU fields itself */ | |
90 | MV m_clippedMv[2]; | |
91 | ||
92 | Predict(); | |
93 | ~Predict(); | |
94 | ||
95 | bool allocBuffers(int csp); | |
96 | ||
97 | // motion compensation functions | |
98 | void predInterLumaPixel(Yuv& dstYuv, const PicYuv& refPic, const MV& mv) const; | |
99 | void predInterChromaPixel(Yuv& dstYuv, const PicYuv& refPic, const MV& mv) const; | |
100 | ||
101 | void predInterLumaShort(ShortYuv& dstSYuv, const PicYuv& refPic, const MV& mv) const; | |
102 | void predInterChromaShort(ShortYuv& dstSYuv, const PicYuv& refPic, const MV& mv) const; | |
103 | ||
104 | void addWeightBi(Yuv& predYuv, const ShortYuv& srcYuv0, const ShortYuv& srcYuv1, const WeightValues wp0[3], const WeightValues wp1[3], bool bLuma, bool bChroma) const; | |
105 | void addWeightUni(Yuv& predYuv, const ShortYuv& srcYuv, const WeightValues wp[3], bool bLuma, bool bChroma) const; | |
106 | ||
107 | /* Intra prediction helper functions */ | |
108 | static void initIntraNeighbors(const CUData& cu, uint32_t zOrderIdxInPart, uint32_t partDepth, bool isLuma, IntraNeighbors *IntraNeighbors); | |
109 | static void fillReferenceSamples(const pixel* adiOrigin, intptr_t picStride, pixel* adiRef, const IntraNeighbors& intraNeighbors); | |
110 | ||
111 | static bool isAboveLeftAvailable(const CUData& cu, uint32_t partIdxLT); | |
112 | static int isAboveAvailable(const CUData& cu, uint32_t partIdxLT, uint32_t partIdxRT, bool* bValidFlags); | |
113 | static int isLeftAvailable(const CUData& cu, uint32_t partIdxLT, uint32_t partIdxLB, bool* bValidFlags); | |
114 | static int isAboveRightAvailable(const CUData& cu, uint32_t partIdxLT, uint32_t partIdxRT, bool* bValidFlags); | |
115 | static int isBelowLeftAvailable(const CUData& cu, uint32_t partIdxLT, uint32_t partIdxLB, bool* bValidFlags); | |
116 | ||
117 | public: | |
118 | ||
119 | /* prepMotionCompensation needs to be called to prepare MC with CU-relevant data */ | |
120 | void initMotionCompensation(const CUData& cu, const CUGeom& cuGeom, int partIdx); | |
121 | void prepMotionCompensation(const CUData& cu, const CUGeom& cuGeom, int partIdx); | |
122 | void motionCompensation(Yuv& predYuv, bool bLuma, bool bChroma); | |
123 | ||
124 | /* Angular Intra */ | |
125 | void predIntraLumaAng(uint32_t dirMode, pixel* pred, intptr_t stride, uint32_t log2TrSize); | |
126 | void predIntraChromaAng(pixel* src, uint32_t dirMode, pixel* pred, intptr_t stride, uint32_t log2TrSizeC, int chFmt); | |
127 | ||
128 | void initAdiPattern(const CUData& cu, const CUGeom& cuGeom, uint32_t absPartIdx, uint32_t partDepth, int dirMode); | |
129 | void initAdiPatternChroma(const CUData& cu, const CUGeom& cuGeom, uint32_t absPartIdx, uint32_t partDepth, uint32_t chromaId); | |
130 | pixel* getAdiChromaBuf(uint32_t chromaId, int tuSize) | |
131 | { | |
132 | return m_predBuf + (chromaId == 1 ? 0 : 2 * ADI_BUF_STRIDE * (tuSize * 2 + 1)); | |
133 | } | |
134 | }; | |
135 | } | |
136 | ||
137 | #endif // ifndef X265_PREDICT_H |