Coverage Report

Created: 2026-04-01 07:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vvenc/source/Lib/CommonLib/IntraPrediction.h
Line
Count
Source
1
/* -----------------------------------------------------------------------------
2
The copyright in this software is being made available under the Clear BSD
3
License, included below. No patent rights, trademark rights and/or 
4
other Intellectual Property Rights other than the copyrights concerning 
5
the Software are granted under this license.
6
7
The Clear BSD License
8
9
Copyright (c) 2019-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVenC Authors.
10
All rights reserved.
11
12
Redistribution and use in source and binary forms, with or without modification,
13
are permitted (subject to the limitations in the disclaimer below) provided that
14
the following conditions are met:
15
16
     * Redistributions of source code must retain the above copyright notice,
17
     this list of conditions and the following disclaimer.
18
19
     * Redistributions in binary form must reproduce the above copyright
20
     notice, this list of conditions and the following disclaimer in the
21
     documentation and/or other materials provided with the distribution.
22
23
     * Neither the name of the copyright holder nor the names of its
24
     contributors may be used to endorse or promote products derived from this
25
     software without specific prior written permission.
26
27
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
28
THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
29
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
31
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
32
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
35
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
36
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38
POSSIBILITY OF SUCH DAMAGE.
39
40
41
------------------------------------------------------------------------------------------- */
42
/** \file     IntraPrediction.h
43
    \brief    prediction class (header)
44
*/
45
46
#pragma once
47
48
#include "Unit.h"
49
#include "Picture.h"
50
#include "MatrixIntraPrediction.h"
51
52
//! \ingroup CommonLib
53
//! \{
54
55
namespace vvenc {
56
57
#if ENABLE_SIMD_OPT_INTRAPRED && defined( TARGET_SIMD_X86 )
58
using namespace x86_simd;
59
#endif
60
#if ENABLE_SIMD_OPT_INTRAPRED && defined( TARGET_SIMD_ARM )
61
using namespace arm_simd;
62
#endif
63
64
// ====================================================================================================================
65
// Class definition
66
// ====================================================================================================================
67
68
/// prediction class
69
enum PredBuf
70
{
71
  PRED_BUF_UNFILTERED = 0,
72
  PRED_BUF_FILTERED   = 1,
73
  NUM_PRED_BUF        = 2
74
};
75
76
static const uint32_t MAX_INTRA_FILTER_DEPTHS=8;
77
78
class IntraPrediction
79
{
80
private:
81
  Pel         m_refBuffer[MAX_NUM_COMP][NUM_PRED_BUF][(MAX_CU_SIZE * 2 + 1 + MAX_REF_LINE_IDX) * 2];
82
  uint32_t    m_refBufferStride[MAX_NUM_COMP];
83
  int         m_numIntraNeighbor;
84
  bool        m_neighborFlags[4 * MAX_NUM_PART_IDXS_IN_CTU_WIDTH + 1];
85
  Area        m_lastArea;
86
  ChannelType m_lastCh;
87
88
  static const uint8_t m_aucIntraFilter[MAX_INTRA_FILTER_DEPTHS];
89
90
  struct IntraPredParam //parameters of Intra Prediction
91
  {
92
    bool refFilterFlag;
93
    bool applyPDPC;
94
    bool isModeVer;
95
    int  multiRefIndex;
96
    int  intraPredAngle;
97
    int  absInvAngle;
98
    bool interpolationFlag;
99
    int  angularScale;
100
101
    IntraPredParam()
102
0
      : refFilterFlag     (false)
103
0
      , applyPDPC         (false)
104
0
      , isModeVer         (false)
105
0
      , multiRefIndex     (-1)
106
0
      , intraPredAngle    (std::numeric_limits<int>::max())
107
0
      , absInvAngle       (std::numeric_limits<int>::max())
108
0
      , interpolationFlag (false)
109
0
      , angularScale      (-1)
110
0
    {
111
0
    }
112
  };
113
114
  IntraPredParam        m_ipaParam;
115
  Pel*                  m_pMdlmTemp; // for MDLM mode
116
  MatrixIntraPrediction m_matrixIntraPred;
117
118
protected:
119
  ChromaFormat          m_currChromaFormat;
120
121
  int                   m_topRefLength;
122
  int                   m_leftRefLength;
123
  void setReferenceArrayLengths(const CompArea& area);
124
125
private:
126
0
  static bool isIntegerSlope      ( const int absAng) { return (0 == (absAng & 0x1F)); }
127
  static int getWideAngle         ( int width, int height, int predMode );
128
129
  // prediction
130
  void xPredIntraDc               ( PelBuf& pDst, const CPelBuf& pSrc );
131
  void xPredIntraAng              ( PelBuf& pDst, const CPelBuf& pSrc, const ChannelType channelType, const ClpRng& clpRng);
132
  Pel  xGetPredValDc              ( const CPelBuf& pSrc, const Size& dstSize );
133
  void xPredIntraBDPCM            ( PelBuf& pDst, const CPelBuf& pSrc, const uint32_t dirMode, const ClpRng& clpRng );
134
135
  void xFillReferenceSamples      ( const CPelBuf& recoBuf,      Pel* refBufUnfiltered, const CompArea& area, const CodingUnit &cu );
136
  void xFilterReferenceSamples    ( const Pel* refBufUnfiltered, Pel* refBufFiltered, const CompArea& area, const SPS &sps, int multiRefIdx, int predStride = 0 );
137
  void xGetLMParameters(const CodingUnit& cu, const ComponentID compID, const CompArea& chromaArea, int& a, int& b, int& iShift);
138
139
#if ENABLE_SIMD_OPT_INTRAPRED && defined( TARGET_SIMD_X86 )
140
  void initIntraPredictionX86();
141
  template <X86_VEXT vext>
142
  void _initIntraPredictionX86();
143
#endif
144
145
#if ENABLE_SIMD_OPT_INTRAPRED && defined( TARGET_SIMD_ARM )
146
  void initIntraPredictionARM();
147
  template <ARM_VEXT vext>
148
  void _initIntraPredictionARM();
149
#endif
150
151
public:
152
  IntraPrediction( bool enableOpt = true );
153
  virtual ~IntraPrediction();
154
155
  void init                   ( ChromaFormat chromaFormatIDC, const unsigned bitDepthY);
156
  void reset                  ();
157
  void destroy                ();
158
159
  void initPredIntraParams    ( const CodingUnit& cu,  const CompArea compArea, const SPS& sps );
160
161
  // Angular Intra
162
  void predIntraAng           ( const ComponentID compId, PelBuf& piPred, const CodingUnit& cu);
163
0
  Pel* getPredictorPtr        ( const ComponentID compId ) { return m_refBuffer[compId][m_ipaParam.refFilterFlag ? PRED_BUF_FILTERED : PRED_BUF_UNFILTERED]; }
164
165
  // Cross-component Chroma
166
  void predIntraChromaLM      ( const ComponentID compID, PelBuf& piPred, const CodingUnit& cu, const CompArea& chromaArea, int intraDir);
167
  void loadLMLumaRecPels      ( const CodingUnit& cu, const CompArea& chromaArea );
168
  /// set parameters from CU data for accessing intra data
169
  void initIntraPatternChType ( const CodingUnit &cu, const CompArea& area, const bool forceRefFilterFlag = false); // use forceRefFilterFlag to get both filtered and unfiltered buffers
170
  void initIntraPatternChTypeISP( const CodingUnit& cu, const CompArea& area, PelBuf& piReco, const bool forceRefFilterFlag = false );
171
172
  // Matrix-based intra prediction
173
  void initIntraMip           ( const CodingUnit& cu);
174
  void predIntraMip           ( PelBuf &piPred, const CodingUnit& cu);
175
176
  int getNumIntraCiip         ( const CodingUnit& cu )
177
0
  {
178
0
    const Position posBL = cu.Y().bottomLeft();
179
0
    const Position posTR = cu.Y().topRight();
180
0
    const CodingUnit *neigh0 = cu.cs->getCURestricted(posBL.offset(-1, 0), cu, CH_L);
181
0
    const CodingUnit *neigh1 = cu.cs->getCURestricted(posTR.offset(0, -1), cu, CH_L);
182
183
0
    int numIntra = 0;
184
0
    numIntra += (neigh0 && (neigh0->predMode == MODE_INTRA))?1:0;
185
0
    numIntra += (neigh1 && (neigh1->predMode == MODE_INTRA))?1:0;
186
187
0
    return numIntra;
188
0
  }
189
190
  void ( *IntraPredAngleLuma )    ( Pel* pDstBuf, const ptrdiff_t dstStride, Pel* refMain, int width, int height, int deltaPos, int intraPredAngle, const TFilterCoeff* ff, const bool useCubicFilter, const ClpRng& clpRng );
191
  void ( *IntraPredAngleChroma )  ( Pel* pDst, const ptrdiff_t dstStride, Pel* pBorder, int width, int height, int deltaPos, int intraPredAngle );
192
  void ( *IntraAnglePDPC )        ( Pel* pDsty, const int dstStride, Pel* refSide, const int width, const int height, int scale, int invAngle );
193
  void ( *IntraHorVerPDPC )       ( Pel* pDsty, const int dstStride, Pel* refSide, const int width, const int height, int scale, const Pel* refMain, const ClpRng& clpRng );
194
  void ( *IntraPredSampleFilter ) ( PelBuf& piPred, const CPelBuf& pSrc );
195
  void ( *xPredIntraPlanar )      ( PelBuf& pDst, const CPelBuf& pSrc );
196
};
197
198
} // namespace vvenc
199
200
//! \}
201