Coverage Report

Created: 2026-12-01 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/vvenc/source/Lib/CommonLib/IntraPrediction.cpp
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
43
44
/** \file     Prediction.cpp
45
    \brief    prediction class
46
*/
47
48
#include "IntraPrediction.h"
49
#include "Unit.h"
50
#include "UnitTools.h"
51
#include "Rom.h"
52
#include "InterpolationFilter.h"
53
#include "dtrace_next.h"
54
55
#include <memory.h>
56
57
//! \ingroup CommonLib
58
//! \{
59
60
namespace vvenc {
61
62
// ====================================================================================================================
63
// Tables
64
// ====================================================================================================================
65
66
const uint8_t IntraPrediction::m_aucIntraFilter[MAX_INTRA_FILTER_DEPTHS] =
67
{
68
  24, //   1xn
69
  24, //   2xn
70
  24, //   4xn
71
  14, //   8xn
72
  2,  //  16xn
73
  0,  //  32xn
74
  0,  //  64xn
75
  0   // 128xn
76
};
77
78
//NOTE: Bit-Limit - 24-bit source
79
void xPredIntraPlanar_Core( PelBuf& pDst, const CPelBuf& pSrc )
80
143k
{
81
143k
  const uint32_t width  = pDst.width;
82
143k
  const uint32_t height = pDst.height;
83
143k
  const uint32_t log2W  = Log2(width);
84
143k
  const uint32_t log2H  = Log2(height);
85
86
143k
  int leftColumn[MAX_TB_SIZEY + 1], topRow[MAX_TB_SIZEY + 1], bottomRow[MAX_TB_SIZEY], rightColumn[MAX_TB_SIZEY];
87
143k
  const uint32_t offset = 1 << (log2W + log2H);
88
89
  // Get left and above reference column and row
90
2.95M
  for( int k = 0; k < width + 1; k++ )
91
2.81M
  {
92
2.81M
    topRow[k] = pSrc.at( k + 1, 0 );
93
2.81M
  }
94
95
2.94M
  for( int k = 0; k < height + 1; k++ )
96
2.79M
  {
97
2.79M
    leftColumn[k] = pSrc.at( k + 1, 1 );
98
2.79M
  }
99
100
  // Prepare intermediate variables used in interpolation
101
143k
  int bottomLeft = leftColumn[height];
102
143k
  int topRight = topRow[width];
103
104
  // with some optimizations gcc-8 gives spurious "-Wmaybe-uninitialized" warnings here (says leftColumn or topRow would be uninitialized here)
105
143k
  GCC_WARNING_DISABLE_maybe_uninitialized
106
2.81M
  for( int k = 0; k < width; k++ )
107
2.67M
  {
108
2.67M
    bottomRow[k] = bottomLeft - topRow[k];
109
2.67M
    topRow[k]    = topRow[k] << log2H;
110
2.67M
  }
111
112
2.79M
  for( int k = 0; k < height; k++ )
113
2.65M
  {
114
2.65M
    rightColumn[k] = topRight - leftColumn[k];
115
2.65M
    leftColumn[k]  = leftColumn[k] << log2W;
116
2.65M
  }
117
143k
  GCC_WARNING_RESET
118
119
143k
  const uint32_t finalShift = 1 + log2W + log2H;
120
143k
  const uint32_t stride     = pDst.stride;
121
143k
  Pel*       pred       = pDst.buf;
122
2.79M
  for( int y = 0; y < height; y++, pred += stride )
123
2.65M
  {
124
2.65M
    int horPred = leftColumn[y];
125
126
64.2M
    for( int x = 0; x < width; x++ )
127
61.5M
    {
128
61.5M
      horPred += rightColumn[y];
129
61.5M
      topRow[x] += bottomRow[x];
130
131
61.5M
      int vertPred = topRow[x];
132
61.5M
      pred[x]      = ( ( horPred << log2H ) + ( vertPred << log2W ) + offset ) >> finalShift;
133
61.5M
    }
134
2.65M
  }
135
143k
}
136
137
void  IntraPredSampleFilter_Core(PelBuf& dstBuf, const CPelBuf& pSrc)
138
298k
{
139
298k
  const int iWidth  = dstBuf.width;
140
298k
  const int iHeight = dstBuf.height;
141
142
298k
  const int scale = ((Log2(iWidth*iHeight) - 2) >> 2);
143
298k
  CHECK(scale < 0 || scale > 31, "PDPC: scale < 0 || scale > 31");
144
145
5.79M
  for (int y = 0; y < iHeight; y++)
146
5.49M
  {
147
5.49M
    const int wT   = 32 >> std::min(31, ((y << 1) >> scale));
148
5.49M
    const Pel left = pSrc.at(y + 1, 1);
149
134M
    for (int x = 0; x < iWidth; x++)
150
128M
    {
151
128M
      const int wL    = 32 >> std::min(31, ((x << 1) >> scale));
152
128M
      const Pel top   = pSrc.at(x + 1, 0);
153
128M
      const Pel val   = dstBuf.at(x, y);
154
128M
      dstBuf.at(x, y) = val + ((wL * (left - val) + wT * (top - val) + 32) >> 6);
155
128M
    }
156
5.49M
  }
157
298k
}
158
159
void IntraHorVerPDPC_Core(Pel* pDsty,const int dstStride,Pel* refSide,const int width,const int height,int scale,const Pel* refMain, const ClpRng& clpRng)
160
260k
{
161
260k
  const Pel topLeft = refMain[0];
162
163
4.08M
  for( int y = 0; y < height; y++ )
164
3.82M
  {
165
3.82M
    memcpy(pDsty,&refMain[1],width*sizeof(Pel));
166
3.82M
    const Pel left    = refSide[1 + y];
167
29.6M
    for (int x = 0; x < std::min(3 << scale, width); x++)
168
25.8M
    {
169
25.8M
      const int wL  = 32 >> (2 * x >> scale);
170
25.8M
      const Pel val = pDsty[x];
171
25.8M
      pDsty[x]      = ClipPel(val + ((wL * (left - topLeft) + 32) >> 6), clpRng);
172
25.8M
    }
173
3.82M
    pDsty += dstStride;
174
3.82M
  }
175
260k
}
176
void IntraAnglePDPC_Core(Pel* pDsty,const int dstStride,Pel* refSide,const int width,const int height,int scale,int invAngle)
177
426k
{
178
10.5M
  for (int y = 0; y<height; y++, pDsty += dstStride)
179
10.1M
  {
180
10.1M
    int       invAngleSum = 256;
181
108M
    for (int x = 0; x < std::min(3 << scale, width); x++)
182
98.7M
    {
183
98.7M
      invAngleSum += invAngle;
184
98.7M
      int wL   = 32 >> (2 * x >> scale);
185
98.7M
      Pel left = refSide[y + (invAngleSum >> 9) + 1];
186
98.7M
      pDsty[x] = pDsty[x] + ((wL * (left - pDsty[x]) + 32) >> 6);
187
98.7M
    }
188
10.1M
  }
189
426k
}
190
191
void IntraPredAngleLuma_Core(Pel* pDstBuf,const ptrdiff_t dstStride,Pel* refMain,int width,int height,int deltaPos,int intraPredAngle,const TFilterCoeff *ff_unused,const bool useCubicFilter,const ClpRng& clpRng)
192
657k
{
193
19.5M
  for (int y = 0; y<height; y++ )
194
18.9M
  {
195
18.9M
    const int deltaInt   = deltaPos >> 5;
196
18.9M
    const int deltaFract = deltaPos & ( 32 - 1 );
197
198
18.9M
    const TFilterCoeff      intraSmoothingFilter[4] = {TFilterCoeff(16 - (deltaFract >> 1)), TFilterCoeff(32 - (deltaFract >> 1)), TFilterCoeff(16 + (deltaFract >> 1)), TFilterCoeff(deltaFract >> 1)};
199
18.9M
    const TFilterCoeff *f = useCubicFilter ? InterpolationFilter::getChromaFilterTable(deltaFract) : intraSmoothingFilter;
200
201
18.9M
    Pel p[4];
202
203
18.9M
    int refMainIndex = deltaInt + 1;
204
205
 //   const TFilterCoeff *f = &ff[deltaFract << 2];
206
207
783M
    for( int x = 0; x < width; x++, refMainIndex++ )
208
764M
    {
209
764M
      p[0] = refMain[refMainIndex - 1];
210
764M
      p[1] = refMain[refMainIndex    ];
211
764M
      p[2] = refMain[refMainIndex + 1];
212
764M
      p[3] = refMain[refMainIndex + 2];
213
214
764M
      pDstBuf[y*dstStride + x] = static_cast<Pel>((static_cast<int>(f[0] * p[0]) + static_cast<int>(f[1] * p[1]) + static_cast<int>(f[2] * p[2]) + static_cast<int>(f[3] * p[3]) + 32) >> 6);
215
216
764M
      if( useCubicFilter ) // only cubic filter has negative coefficients and requires clipping
217
101M
      {
218
101M
        pDstBuf[y*dstStride + x] = ClipPel( pDstBuf[y*dstStride + x], clpRng );
219
101M
      }
220
764M
    }
221
18.9M
    deltaPos += intraPredAngle;
222
18.9M
  }
223
657k
}
224
225
void IntraPredAngleChroma_Core(Pel* pDstBuf,const ptrdiff_t dstStride,int16_t* pBorder,int width,int height,int deltaPos,int intraPredAngle)
226
39.6k
{
227
325k
  for (int y = 0; y<height; y++)
228
285k
  {
229
285k
    const int deltaInt   = deltaPos >> 5;
230
285k
    const int deltaFract = deltaPos & (32 - 1);
231
232
    // Do linear filtering
233
285k
    const Pel* pRM = pBorder + deltaInt + 1;
234
285k
    int lastRefMainPel = *pRM++;
235
236
7.26M
    for( int x = 0; x < width; pRM++, x++ )
237
6.97M
    {
238
6.97M
      int thisRefMainPel = *pRM;
239
6.97M
      pDstBuf[x + 0] = ( Pel ) ( ( ( 32 - deltaFract )*lastRefMainPel + deltaFract*thisRefMainPel + 16 ) >> 5 );
240
6.97M
      lastRefMainPel = thisRefMainPel;
241
6.97M
    }
242
285k
    deltaPos += intraPredAngle;
243
285k
    pDstBuf += dstStride;
244
285k
  }
245
39.6k
}
246
247
// ====================================================================================================================
248
// Constructor / destructor / initialize
249
// ====================================================================================================================
250
251
static void IntraFilterRefSamples_Core( const Pel* src, Pel* dst, const int length )
252
140k
{
253
8.11M
  for( int i = 1; i < length; i++ )
254
7.97M
  {
255
7.97M
    dst[i] = ( src[i - 1] + 2 * src[i] + src[i + 1] + 2 ) >> 2;
256
7.97M
  }
257
140k
}
258
259
static void LMLumaDownsample420_Core( const Pel* src, const ptrdiff_t srcStride, Pel* dst, const ptrdiff_t dstStride, const int width, const int height, const bool leftAvailable )
260
93.1k
{
261
1.08M
  for( int y = 0; y < height; y++, src += 2 * srcStride, dst += dstStride )
262
990k
  {
263
17.0M
    for( int i = 0; i < width; i++ )
264
16.0M
    {
265
16.0M
      const int left = ( i == 0 && !leftAvailable ) ? 0 : 1;
266
267
16.0M
      int s = 4;
268
16.0M
      s += src[2 * i] * 2;
269
16.0M
      s += src[2 * i + 1];
270
16.0M
      s += src[2 * i - left];
271
16.0M
      s += src[2 * i + srcStride] * 2;
272
16.0M
      s += src[2 * i + 1 + srcStride];
273
16.0M
      s += src[2 * i + srcStride - left];
274
16.0M
      dst[i] = s >> 3;
275
16.0M
    }
276
990k
  }
277
93.1k
}
278
279
IntraPrediction::IntraPrediction( bool enableOpt )
280
5.72k
:  m_pMdlmTemp( nullptr )
281
5.72k
,  m_currChromaFormat( NUM_CHROMA_FORMAT )
282
5.72k
{
283
5.72k
  IntraPredAngleLuma    = IntraPredAngleLuma_Core;
284
5.72k
  IntraPredAngleChroma  = IntraPredAngleChroma_Core;
285
5.72k
  IntraAnglePDPC        = IntraAnglePDPC_Core;
286
5.72k
  IntraHorVerPDPC       = IntraHorVerPDPC_Core;
287
5.72k
  IntraPredAngleLumaHor = nullptr;
288
5.72k
  IntraPredSampleFilter = IntraPredSampleFilter_Core;
289
5.72k
  xPredIntraPlanar      = xPredIntraPlanar_Core;
290
5.72k
  LMLumaDownsample420   = LMLumaDownsample420_Core;
291
5.72k
  IntraFilterRefSamples = IntraFilterRefSamples_Core;
292
293
5.72k
#if ENABLE_SIMD_OPT_INTRAPRED
294
5.72k
  if( enableOpt )
295
5.72k
  {
296
#if defined( TARGET_SIMD_X86 )
297
    initIntraPredictionX86();
298
#endif
299
#if defined( TARGET_SIMD_ARM )
300
    initIntraPredictionARM();
301
#endif
302
5.72k
  }
303
5.72k
#endif // ENABLE_SIMD_OPT_INTRAPRED
304
5.72k
}
305
306
IntraPrediction::~IntraPrediction()
307
5.72k
{
308
5.72k
  destroy();
309
5.72k
}
310
311
void IntraPrediction::destroy()
312
5.72k
{
313
5.72k
  delete[] m_pMdlmTemp;
314
5.72k
  m_pMdlmTemp = nullptr;
315
5.72k
}
316
317
void IntraPrediction::init(ChromaFormat chromaFormatIDC, const unsigned bitDepthY)
318
5.72k
{
319
5.72k
  m_currChromaFormat = chromaFormatIDC;
320
321
5.72k
  if (m_pMdlmTemp == nullptr)
322
5.72k
  {
323
5.72k
    m_pMdlmTemp = new Pel[(2 * MAX_TB_SIZEY + 1)*(2 * MAX_TB_SIZEY + 1)];//MDLM will use top-above and left-below samples.
324
5.72k
  }
325
5.72k
}
326
327
// ====================================================================================================================
328
// Public member functions
329
// ====================================================================================================================
330
331
// Function for calculating DC value of the reference samples used in Intra prediction
332
//NOTE: Bit-Limit - 25-bit source
333
Pel IntraPrediction::xGetPredValDc( const CPelBuf& pSrc, const Size& dstSize )
334
200k
{
335
200k
  CHECK( dstSize.width == 0 || dstSize.height == 0, "Empty area provided" );
336
337
200k
  int idx, sum = 0;
338
200k
  Pel dcVal;
339
200k
  const int width  = dstSize.width;
340
200k
  const int height = dstSize.height;
341
200k
  const auto denom     = (width == height) ? (width << 1) : std::max(width,height);
342
200k
  const auto divShift  = Log2(denom);
343
200k
  const auto divOffset = (denom >> 1);
344
200k
  const int off = m_ipaParam.multiRefIndex + 1;
345
346
347
200k
  if ( width >= height )
348
141k
  {
349
3.49M
    for( idx = 0; idx < width; idx++ )
350
3.35M
    {
351
3.35M
      sum += pSrc.at( off + idx, 0);
352
3.35M
    }
353
141k
  }
354
200k
  if ( width <= height )
355
137k
  {
356
3.49M
    for( idx = 0; idx < height; idx++ )
357
3.35M
    {
358
3.35M
      sum += pSrc.at( off + idx, 1);
359
3.35M
    }
360
137k
  }
361
362
200k
  dcVal = (sum + divOffset) >> divShift;
363
200k
  return dcVal;
364
200k
}
365
366
int IntraPrediction::getWideAngle( int width, int height, int predMode )
367
1.63M
{
368
1.63M
  if ( predMode > DC_IDX && predMode <= VDIA_IDX )
369
987k
  {
370
987k
    int modeShift[] = { 0, 6, 10, 12, 14, 15 };
371
987k
    int deltaSize = abs(Log2(width) - Log2(height));
372
987k
    if (width > height && predMode < 2 + modeShift[deltaSize])
373
2.10k
    {
374
2.10k
      predMode += (VDIA_IDX - 1);
375
2.10k
    }
376
985k
    else if (height > width && predMode > VDIA_IDX - modeShift[deltaSize])
377
69.2k
    {
378
69.2k
      predMode -= (VDIA_IDX - 1);
379
69.2k
    }
380
987k
  }
381
1.63M
  return predMode;
382
1.63M
}
383
384
void IntraPrediction::predIntraAng( const ComponentID compId, PelBuf& piPred, const CodingUnit& cu)
385
1.59M
{
386
1.59M
  const ComponentID    compID       = compId;
387
1.59M
  const ChannelType    channelType  = toChannelType( compID );
388
1.59M
  const uint32_t       uiDirMode = cu.bdpcmM[channelType] ? BDPCM_IDX
389
1.59M
                                   : isLuma( channelType ) ? cu.intraDir[CH_L]   // what getFinalIntraMode gives for luma
390
1.50M
                                   : CU::getFinalIntraMode(cu, channelType);
391
392
1.59M
  CHECK( Log2(piPred.width) > 7, "Size not allowed" );
393
394
//  const int multiRefIdx = m_ipaParam.multiRefIndex;
395
1.59M
  const int srcStride  = m_refBufferStride[compID];
396
1.59M
  const int srcHStride = 2;
397
398
1.59M
  const CPelBuf& srcBuf = CPelBuf(getPredictorPtr(compID), srcStride, srcHStride);
399
1.59M
  const ClpRng& clpRng(cu.cs->slice->clpRngs[compID]);
400
401
1.59M
  switch (uiDirMode)
402
1.59M
  {
403
143k
    case(PLANAR_IDX): xPredIntraPlanar(piPred, srcBuf); break;
404
200k
    case(DC_IDX):     xPredIntraDc    ( piPred, srcBuf ); break;
405
98.4k
    case(BDPCM_IDX):  xPredIntraBDPCM ( piPred, srcBuf, cu.bdpcmM[channelType], clpRng); break;
406
1.15M
    default:          xPredIntraAng   ( piPred, srcBuf, compID, clpRng); break;
407
1.59M
  }
408
409
1.59M
  if (m_ipaParam.applyPDPC)
410
1.07M
  {
411
1.07M
    if (uiDirMode == PLANAR_IDX || uiDirMode == DC_IDX)
412
298k
    {
413
298k
      IntraPredSampleFilter(piPred, srcBuf);
414
298k
    }
415
1.07M
  }
416
1.59M
}
417
418
void IntraPrediction::predIntraChromaLM(const ComponentID compID, PelBuf& piPred, const CodingUnit& cu, const CompArea& chromaArea, int intraDir)
419
242k
{
420
242k
  CHECK( piPred.width > MAX_TB_SIZEY || piPred.height > MAX_TB_SIZEY, "not enough memory");
421
242k
  const int iLumaStride = 2 * MAX_TB_SIZEY + 1;
422
242k
  PelBuf Temp = PelBuf(m_pMdlmTemp + iLumaStride + 1, iLumaStride, Size(chromaArea));
423
424
242k
  int a, b, iShift;
425
242k
  xGetLMParameters(cu, compID, chromaArea, a, b, iShift); // th shift result is unsigned
426
427
  ////// final prediction
428
242k
  piPred.copyFrom(Temp);
429
242k
  piPred.linearTransform(a, iShift, b, true, cu.cs->slice->clpRngs[compID]);
430
242k
}
431
432
/** Function for deriving planar intra prediction. This function derives the prediction samples for planar mode (intra coding).
433
 */
434
435
void IntraPrediction::xPredIntraDc( PelBuf& pDst, const CPelBuf& pSrc )
436
200k
{
437
200k
  const Pel dcval = xGetPredValDc( pSrc, pDst );
438
200k
  pDst.fill( dcval );
439
200k
}
440
441
// Function for initialization of intra prediction parameters
442
void IntraPrediction::initPredIntraParams(const CodingUnit& cu, const CompArea area, const SPS& sps)
443
1.63M
{
444
1.63M
  const ComponentID compId = area.compID;
445
1.63M
  const ChannelType chType = toChannelType(compId);
446
447
1.63M
  const bool useISP = NOT_INTRA_SUBPARTITIONS != cu.ispMode && isLuma( chType );
448
1.63M
  const Size cuSize = Size( cu.blocks[compId].width, cu.blocks[compId].height );
449
1.63M
  const Size puSize = Size( area.width, area.height );
450
451
1.63M
  xDerivePredIntraParams( m_ipaParam, chType, useISP ? cuSize : puSize, puSize, CU::getFinalIntraMode( cu, chType ),
452
1.63M
                          isLuma( chType ) ? cu.multiRefIdx : 0, useISP, CU::isMIP( cu, chType ), cu.bdpcmM[chType] );
453
1.63M
}
454
455
const IntraPrediction::LumaModeParam* IntraPrediction::getLumaParamRow( const CodingUnit& cu ) const
456
30.0k
{
457
30.0k
  struct Table
458
30.0k
  {
459
30.0k
    LumaModeParam param[MAX_CU_DEPTH - 1][MAX_CU_DEPTH - 1][NUM_LUMA_MODE];   // [log2 width - 2][log2 height - 2][mode]
460
461
30.0k
    Table()
462
30.0k
    {
463
7
      for( int log2W = 2; log2W <= MAX_CU_DEPTH; log2W++ )
464
6
      {
465
42
        for( int log2H = 2; log2H <= MAX_CU_DEPTH; log2H++ )
466
36
        {
467
36
          const Size size( 1 << log2W, 1 << log2H );
468
2.44k
          for( int mode = 0; mode < NUM_LUMA_MODE; mode++ )
469
2.41k
          {
470
2.41k
            IntraPredParam p;
471
2.41k
            xDerivePredIntraParams( p, CH_L, size, size, mode, 0, false, false, false );
472
2.41k
            const bool angular = mode > DC_IDX;
473
2.41k
            CHECK( p.multiRefIndex || p.angularScale < -128 || p.angularScale > 127 || ( angular && ( abs( p.intraPredAngle ) > 32767 || p.absInvAngle > 32767 ) ),
474
2.41k
                   "intra parameters do not fit the table" );
475
2.41k
            LumaModeParam& e = param[log2W - 2][log2H - 2][mode];
476
2.41k
            e.intraPredAngle = int16_t( angular ? p.intraPredAngle : 0 );
477
2.41k
            e.absInvAngle    = int16_t( angular ? p.absInvAngle : 0 );
478
2.41k
            e.angularScale   = int8_t( p.angularScale );
479
2.41k
            e.flags          = uint8_t( ( p.isModeVer ? 1 : 0 ) | ( p.applyPDPC ? 2 : 0 ) | ( p.refFilterFlag ? 4 : 0 ) | ( p.interpolationFlag ? 8 : 0 ) );
480
2.41k
            e.unused         = 0;
481
2.41k
          }
482
36
        }
483
6
      }
484
1
    }
485
30.0k
  };
486
30.0k
  static const Table table;
487
488
30.0k
  if( cu.ispMode != NOT_INTRA_SUBPARTITIONS || cu.mipFlag || cu.multiRefIdx || cu.bdpcmM[CH_L] )
489
0
  {
490
0
    return nullptr;
491
0
  }
492
30.0k
  const int w = cu.lwidth(), h = cu.lheight();
493
30.0k
  if( w < 4 || h < 4 || w > MAX_CU_SIZE || h > MAX_CU_SIZE || ( w & ( w - 1 ) ) || ( h & ( h - 1 ) ) )
494
0
  {
495
0
    return nullptr;
496
0
  }
497
30.0k
  return table.param[floorLog2( w ) - 2][floorLog2( h ) - 2];
498
30.0k
}
499
500
// Sets the fields of param for one block; for planar, DC and some angular modes it leaves the angle fields as they are,
501
// which only xPredIntraAng reads, for the angular modes that set them
502
void IntraPrediction::xDerivePredIntraParams( IntraPredParam& param, const ChannelType chType, const Size& blockSize, const Size& puSize, const int dirMode,
503
                                              const int multiRefIdx, const bool useISP, const bool isMIP, const bool bdpcm )
504
1.63M
{
505
1.63M
  const int     predMode = getWideAngle( blockSize.width, blockSize.height, dirMode );
506
507
1.63M
  param.isModeVer            = predMode >= DIA_IDX;
508
1.63M
  param.multiRefIndex        = multiRefIdx;
509
1.63M
  param.refFilterFlag        = false;
510
1.63M
  param.interpolationFlag    = false;
511
1.63M
  param.applyPDPC            = (puSize.width >= MIN_TB_SIZEY && puSize.height >= MIN_TB_SIZEY) && param.multiRefIndex == 0;
512
513
1.63M
  const int    intraPredAngleMode = (param.isModeVer) ? predMode - VER_IDX : -(predMode - HOR_IDX);
514
515
516
1.63M
  int absAng = 0;
517
1.63M
  if (dirMode > DC_IDX && dirMode < NUM_LUMA_MODE) // intraPredAngle for directional modes
518
987k
  {
519
987k
    static const int angTable[32]    = { 0,    1,    2,    3,    4,    6,     8,   10,   12,   14,   16,   18,   20,   23,   26,   29,   32,   35,   39,  45,  51,  57,  64,  73,  86, 102, 128, 171, 256, 341, 512, 1024 };
520
987k
    static const int invAngTable[32] = {
521
987k
      0,   16384, 8192, 5461, 4096, 2731, 2048, 1638, 1365, 1170, 1024, 910, 819, 712, 630, 565,
522
987k
      512, 468,   420,  364,  321,  287,  256,  224,  191,  161,  128,  96,  64,  48,  32,  16
523
987k
    };   // (512 * 32) / Angle
524
525
987k
    const int     absAngMode         = abs(intraPredAngleMode);
526
987k
    const int     signAng            = intraPredAngleMode < 0 ? -1 : 1;
527
987k
                  absAng             = angTable  [absAngMode];
528
529
987k
    param.absInvAngle           = invAngTable[absAngMode];
530
987k
    param.intraPredAngle        = signAng * absAng;
531
987k
    if (intraPredAngleMode < 0)
532
40.0k
    {
533
40.0k
      param.applyPDPC = false;
534
40.0k
    }
535
947k
    else if (intraPredAngleMode > 0)
536
287k
    {
537
287k
      const int sideSize = param.isModeVer ? puSize.height : puSize.width;
538
287k
      const int maxScale = 2;
539
540
287k
      param.angularScale = std::min(maxScale, floorLog2(sideSize) - (floorLog2(3 * param.absInvAngle - 2) - 8));
541
287k
      param.applyPDPC &= param.angularScale >= 0;
542
287k
    }
543
987k
  }
544
545
  // high level conditions and DC intra prediction
546
1.63M
  if( !isLuma( chType )
547
278k
    || useISP
548
255k
    || isMIP //th remove this
549
201k
    || param.multiRefIndex
550
20.7k
    || DC_IDX == dirMode
551
1.63M
    )
552
1.61M
  {
553
1.61M
  }
554
17.8k
  else if (bdpcm)
555
8.29k
  {
556
8.29k
    param.refFilterFlag = false;
557
8.29k
  }
558
9.57k
  else if (dirMode == PLANAR_IDX) // Planar intra prediction
559
4.36k
  {
560
4.36k
    param.refFilterFlag = puSize.width * puSize.height > 32 ? true : false;
561
4.36k
  }
562
5.21k
  else if (!useISP)// HOR, VER and angular modes (MDIS)
563
5.21k
  {
564
5.21k
    bool filterFlag = false;
565
5.21k
    {
566
5.21k
      const int diff = std::min<int>( abs( predMode - HOR_IDX ), abs( predMode - VER_IDX ) );
567
5.21k
      const int log2Size = (Log2(puSize.width * puSize.height) >> 1);
568
5.21k
      CHECK( log2Size >= MAX_INTRA_FILTER_DEPTHS, "Size not supported" );
569
5.21k
      filterFlag = (diff > m_aucIntraFilter[log2Size]);
570
5.21k
    }
571
572
    // Selelection of either ([1 2 1] / 4 ) refrence filter OR Gaussian 4-tap interpolation filter
573
5.21k
    if (filterFlag)
574
1.77k
    {
575
1.77k
      const bool isRefFilter       =  isIntegerSlope(absAng);
576
1.77k
      CHECK( puSize.width * puSize.height <= 32, "DCT-IF interpolation filter is always used for 4x4, 4x8, and 8x4 luma CB" );
577
1.77k
      param.refFilterFlag     =  isRefFilter;
578
1.77k
      param.interpolationFlag = !isRefFilter;
579
1.77k
    }
580
5.21k
  }
581
1.63M
}
582
583
}   // namespace vvenc
584
585
#ifdef TARGET_SIMD_X86
586
#include "x86/CommonDefX86.h"
587
#endif
588
589
namespace vvenc {
590
591
/** Function for deriving the simplified angular intra predictions.
592
*
593
* This function derives the prediction samples for the angular mode based on the prediction direction indicated by
594
* the prediction mode index. The prediction direction is given by the displacement of the bottom row of the block and
595
* the reference row above the block in the case of vertical prediction or displacement of the rightmost column
596
* of the block and reference column left from the block in the case of the horizontal prediction. The displacement
597
* is signalled at 1/32 pixel accuracy. When projection of the predicted pixel falls inbetween reference samples,
598
* the predicted value for the pixel is linearly interpolated from the reference samples. All reference samples are taken
599
* from the extended main reference.
600
*/
601
//NOTE: Bit-Limit - 25-bit source
602
603
IntraPrediction::ExtRefRows& IntraPrediction::xGetExtRefRows( const ComponentID compID, const CPelBuf& pSrc, const int width, const int height, const int multiRefIdx )
604
1.15M
{
605
1.15M
  ExtRefRows& ext = m_extRef[compID][m_ipaParam.refFilterFlag ? PRED_BUF_FILTERED : PRED_BUF_UNFILTERED];
606
607
1.15M
  if( ext.generation == m_refGeneration && ext.multiRefIdx == multiRefIdx && ext.width == width && ext.height == height
608
933k
      && ext.topRefLength == m_topRefLength && ext.leftRefLength == m_leftRefLength )
609
933k
  {
610
933k
    return ext;
611
933k
  }
612
613
223k
  const int aboveLength = m_topRefLength  + multiRefIdx + 1;
614
223k
  const int leftLength  = m_leftRefLength + multiRefIdx + 1;
615
223k
  Pel* above = ext.above + EXT_REF_MARGIN;
616
223k
  Pel* left  = ext.left  + EXT_REF_MARGIN;
617
223k
  memcpy( above, pSrc.buf,               aboveLength * sizeof( Pel ) );
618
223k
  memcpy( left,  pSrc.buf + pSrc.stride, leftLength  * sizeof( Pel ) );
619
620
  // replicate the last sample as far as a positive angle reads with this row as the main reference
621
223k
  const int log2Ratio = Log2( width ) - Log2( height );
622
223k
  std::fill_n( above + aboveLength, ( multiRefIdx << std::max( 0,  log2Ratio ) ) + 2, above[aboveLength - 1] );
623
223k
  std::fill_n( left  + leftLength,  ( multiRefIdx << std::max( 0, -log2Ratio ) ) + 2, left [leftLength  - 1] );
624
625
223k
  ext.generation    = m_refGeneration;
626
223k
  ext.multiRefIdx   = multiRefIdx;
627
223k
  ext.width         = width;
628
223k
  ext.height        = height;
629
223k
  ext.topRefLength  = m_topRefLength;
630
223k
  ext.leftRefLength = m_leftRefLength;
631
223k
  return ext;
632
1.15M
}
633
634
void IntraPrediction::xPredIntraAng( PelBuf& pDst, const CPelBuf& pSrc, const ComponentID compID, const ClpRng& clpRng)
635
1.15M
{
636
1.15M
  int width =int(pDst.width);
637
1.15M
  int height=int(pDst.height);
638
639
1.15M
  const bool bIsModeVer     = m_ipaParam.isModeVer;
640
1.15M
  const int  multiRefIdx    = m_ipaParam.multiRefIndex;
641
1.15M
  const int  intraPredAngle = m_ipaParam.intraPredAngle;
642
1.15M
  const int  absInvAngle    = m_ipaParam.absInvAngle;
643
644
  // the reference rows, extended to the right for positive angles
645
1.15M
  ExtRefRows& ext = xGetExtRefRows( compID, pSrc, width, height, multiRefIdx );
646
1.15M
  Pel* refMain = ( bIsModeVer ? ext.above : ext.left  ) + EXT_REF_MARGIN;
647
1.15M
  Pel* refSide = ( bIsModeVer ? ext.left  : ext.above ) + EXT_REF_MARGIN;
648
649
1.15M
  if (intraPredAngle < 0)
650
281k
  {
651
    // Extend the Main reference to the left.
652
281k
    int sizeSide = bIsModeVer ? height : width;
653
8.81M
    for (int k = -sizeSide; k <= -1; k++)
654
8.53M
    {
655
8.53M
      refMain[k] = refSide[std::min((-k * absInvAngle + 256) >> 9, sizeSide)];
656
8.53M
    }
657
281k
  }
658
659
  // swap width/height if we are doing a horizontal mode:
660
1.15M
  if (!bIsModeVer)
661
549k
  {
662
549k
    std::swap(width, height);
663
549k
  }
664
1.15M
  const int dstStride = bIsModeVer ? pDst.stride : MAX_CU_SIZE;
665
1.15M
  Pel* pDstBuf = bIsModeVer ? pDst.buf : m_tempArray;
666
667
  // compensate for line offset in reference line buffers
668
1.15M
  refMain += multiRefIdx;
669
1.15M
  refSide += multiRefIdx;
670
671
  // horizontal luma modes with a fractional |angle| <= 29 in the block's own orientation: no temporary block and no
672
  // transpose (width / height are the transposed block's here)
673
1.15M
  if( !bIsModeVer && IntraPredAngleLumaHor && isLuma( compID ) && height >= 8 && width >= 4 && abs( intraPredAngle ) <= 29
674
0
      && !isIntegerSlope( abs( intraPredAngle ) ) )
675
0
  {
676
0
    IntraPredAngleLumaHor( pDst.buf, pDst.stride, refMain, refSide, height, width, intraPredAngle, multiRefIdx, m_ipaParam.angularScale, absInvAngle,
677
0
                           !m_ipaParam.interpolationFlag, m_ipaParam.applyPDPC, clpRng );
678
0
    return;
679
0
  }
680
681
1.15M
  Pel* pDsty = pDstBuf;
682
683
1.15M
  if( intraPredAngle == 0 )  // pure vertical or pure horizontal
684
341k
  {
685
341k
    if (m_ipaParam.applyPDPC)
686
260k
    {
687
260k
      const int scale   = (Log2(width * height) - 2) >> 2;
688
260k
      IntraHorVerPDPC(pDsty,dstStride,refSide,width,height,scale,refMain,clpRng);
689
260k
    }
690
80.9k
    else
691
80.9k
    {
692
2.16M
      for( int y = 0; y < height; y++ )
693
2.08M
      {
694
2.08M
        memcpy(pDsty,&refMain[1],width*sizeof(Pel));
695
2.08M
        pDsty += dstStride;
696
2.08M
      }
697
80.9k
    }
698
341k
  }
699
814k
  else
700
814k
  {
701
814k
    if( !isIntegerSlope( abs( intraPredAngle ) ) )
702
697k
    {
703
697k
      int deltaPos = intraPredAngle * ( 1 + multiRefIdx );
704
697k
      if( isLuma( compID ) )
705
657k
      {
706
657k
        if( width <= 2 )
707
0
        {
708
0
          for( int y = 0, deltaPos = intraPredAngle * ( 1 + multiRefIdx );
709
0
               y < height;
710
0
               y++, deltaPos += intraPredAngle, pDsty += dstStride )
711
0
          {
712
0
            const int deltaInt   = deltaPos >> 5;
713
0
            const int deltaFract = deltaPos & 31;
714
715
0
            if( !isIntegerSlope( abs( intraPredAngle ) ) )
716
0
            {
717
0
              const bool useCubicFilter = !m_ipaParam.interpolationFlag;
718
719
0
              const TFilterCoeff intraSmoothingFilter[4] = { TFilterCoeff( 16 - ( deltaFract >> 1 ) ),
720
0
                                                             TFilterCoeff( 32 - ( deltaFract >> 1 ) ),
721
0
                                                             TFilterCoeff( 16 + ( deltaFract >> 1 ) ),
722
0
                                                             TFilterCoeff(      ( deltaFract >> 1 ) ) };
723
0
              const TFilterCoeff* const f =
724
0
                ( useCubicFilter ) ? InterpolationFilter::getChromaFilterTable( deltaFract ) : intraSmoothingFilter;
725
726
0
              for( int x = 0; x < width; x++ )
727
0
              {
728
0
                Pel p[4];
729
730
0
                p[0] = refMain[deltaInt + x + 0];
731
0
                p[1] = refMain[deltaInt + x + 1];
732
0
                p[2] = refMain[deltaInt + x + 2];
733
0
                p[3] = refMain[deltaInt + x + 3];
734
735
0
                Pel val = ( f[0] * p[0] + f[1] * p[1] + f[2] * p[2] + f[3] * p[3] + 32 ) >> 6;
736
737
0
                pDsty[x] = ClipPel( val, clpRng );   // always clip even though not always needed
738
0
              }
739
0
            }
740
0
          }
741
0
        }
742
657k
        else
743
657k
        {
744
657k
          IntraPredAngleLuma(pDstBuf, dstStride, refMain, width, height, deltaPos, intraPredAngle, nullptr, !m_ipaParam.interpolationFlag, clpRng);
745
657k
        }
746
657k
      }
747
39.6k
      else
748
39.6k
      {
749
39.6k
        IntraPredAngleChroma(pDstBuf,dstStride,refMain,width,height,deltaPos,intraPredAngle);
750
39.6k
      }
751
697k
    }
752
117k
    else
753
117k
    {
754
1.85M
      for (int y = 0, deltaPos = intraPredAngle * (1 + multiRefIdx); y<height; y++, deltaPos += intraPredAngle, pDsty += dstStride)
755
1.73M
      {
756
1.73M
        const int deltaInt   = deltaPos >> 5;
757
        // Just copy the integer samples
758
1.73M
        memcpy(pDsty,refMain  + deltaInt + 1,width*sizeof(Pel));
759
1.73M
      }
760
117k
    }
761
762
814k
    if (m_ipaParam.applyPDPC)
763
426k
    {
764
426k
      pDsty = pDstBuf;
765
426k
      IntraAnglePDPC(pDsty,dstStride,refSide,width,height,m_ipaParam.angularScale,absInvAngle);
766
426k
    }
767
814k
  } // else
768
769
  // Flip the block if this is the horizontal mode
770
1.15M
  if( !bIsModeVer )
771
549k
  {
772
549k
    pDst.transposedFrom( CPelBuf( pDstBuf, dstStride, width, height) );
773
549k
  }
774
1.15M
}
775
776
void IntraPrediction::xPredIntraBDPCM(PelBuf& pDst, const CPelBuf& pSrc, const uint32_t dirMode, const ClpRng& clpRng)
777
98.4k
{
778
98.4k
  const int wdt = pDst.width;
779
98.4k
  const int hgt = pDst.height;
780
781
98.4k
  const int strideP = pDst.stride;
782
98.4k
  const int strideS = pSrc.stride;
783
784
98.4k
  CHECK(!(dirMode == 1 || dirMode == 2), "Incorrect BDPCM mode parameter.");
785
786
98.4k
  Pel* pred = &pDst.buf[0];
787
98.4k
  if (dirMode == 1)
788
4.14k
  {
789
4.14k
    Pel  val;
790
57.0k
    for (int y = 0; y < hgt; y++)
791
52.9k
    {
792
52.9k
      val = pSrc.buf[(y + 1) + strideS];
793
760k
      for (int x = 0; x < wdt; x++)
794
707k
      {
795
707k
        pred[x] = val;
796
707k
      }
797
52.9k
      pred += strideP;
798
52.9k
    }
799
4.14k
  }
800
94.3k
  else
801
94.3k
  {
802
976k
    for (int y = 0; y < hgt; y++)
803
882k
    {
804
9.93M
      for (int x = 0; x < wdt; x++)
805
9.05M
      {
806
9.05M
        pred[x] = pSrc.buf[x + 1];
807
9.05M
      }
808
882k
      pred += strideP;
809
882k
    }
810
94.3k
  }
811
98.4k
}
812
813
inline bool isAboveLeftAvailable  ( const CodingUnit &cu, const ChannelType& chType, const Position& posLT );
814
inline int  isAboveAvailable      ( const CodingUnit &cu, const ChannelType& chType, const Position& posLT, const uint32_t numUnits, const uint32_t unitWidth, bool *validFlags );
815
inline int  isLeftAvailable       ( const CodingUnit &cu, const ChannelType& chType, const Position& posLT, const uint32_t numUnits, const uint32_t unitWidth, bool *validFlags );
816
inline int  isAboveRightAvailable ( const CodingUnit &cu, const ChannelType& chType, const Position& posRT, const uint32_t numUnits, const uint32_t unitHeight, bool *validFlags );
817
inline int  isBelowLeftAvailable  ( const CodingUnit &cu, const ChannelType& chType, const Position& posLB, const uint32_t numUnits, const uint32_t unitHeight, bool *validFlags );
818
819
void IntraPrediction::initIntraPatternChType(const CodingUnit &cu, const CompArea& area, const bool forceRefFilterFlag)
820
276k
{
821
276k
  const CodingStructure& cs   = *cu.cs;
822
823
276k
  if (!forceRefFilterFlag)
824
210k
  {
825
210k
    initPredIntraParams(cu, area, *cs.sps);
826
210k
  }
827
828
276k
  Pel *refBufUnfiltered = m_refBuffer[area.compID][PRED_BUF_UNFILTERED];
829
276k
  Pel *refBufFiltered   = m_refBuffer[area.compID][PRED_BUF_FILTERED];
830
831
276k
  setReferenceArrayLengths(area);
832
833
  // ----- Step 1: unfiltered reference samples -----
834
276k
  xFillReferenceSamples( cs.picture->getRecoBuf( area ), refBufUnfiltered, area, cu );
835
  // ----- Step 2: filtered reference samples -----
836
276k
  if( m_ipaParam.refFilterFlag || forceRefFilterFlag )
837
70.2k
  {
838
70.2k
    xFilterReferenceSamples( refBufUnfiltered, refBufFiltered, area, *cs.sps, cu.multiRefIdx );
839
70.2k
  }
840
276k
  m_refGeneration++;
841
276k
}
842
843
// The samples around a block don't change while the encoder tests its modes, so only what depends on the mode is redone.
844
void IntraPrediction::keepIntraPatternChType(const CodingUnit &cu, const CompArea& area)
845
675k
{
846
675k
  const SPS& sps = *cu.cs->sps;
847
848
675k
  initPredIntraParams(cu, area, sps);
849
850
675k
  if( m_ipaParam.refFilterFlag )
851
0
  {
852
0
    xFilterReferenceSamples( m_refBuffer[area.compID][PRED_BUF_UNFILTERED], m_refBuffer[area.compID][PRED_BUF_FILTERED], area, sps, cu.multiRefIdx );
853
0
    m_refGeneration++;
854
0
  }
855
675k
}
856
857
void IntraPrediction::reset()
858
98.3k
{
859
98.3k
  m_lastCh = MAX_NUM_CH;
860
98.3k
  m_lastArea = Area(0,0,0,0);
861
98.3k
}
862
863
void IntraPrediction::xFillReferenceSamples( const CPelBuf& recoBuf, Pel* refBufUnfiltered, const CompArea& area, const CodingUnit &cu )
864
294k
{
865
294k
  const ChannelType      chType = toChannelType( area.compID );
866
294k
  const CodingStructure &cs     = *cu.cs;
867
294k
  const SPS             &sps    = *cs.sps;
868
294k
  const PreCalcValues   &pcv    = *cs.pcv;
869
870
294k
  const int multiRefIdx         = (area.compID == COMP_Y) ? cu.multiRefIdx : 0;
871
872
294k
  const int  tuWidth            = area.width;
873
294k
  const int  tuHeight           = area.height;
874
294k
  const int  predSize           = m_topRefLength;
875
294k
  const int  predHSize          = m_leftRefLength;
876
294k
  const int predStride = predSize + 1 + multiRefIdx;
877
294k
  m_refBufferStride[area.compID] = predStride;
878
879
294k
  const int  unitWidth          = tuWidth  <= 2 && cu.ispMode && isLuma(area.compID) ? tuWidth  : pcv.minCUSize >> getComponentScaleX(area.compID, sps.chromaFormatIdc);
880
294k
  const int  unitHeight         = tuHeight <= 2 && cu.ispMode && isLuma(area.compID) ? tuHeight : pcv.minCUSize >> getComponentScaleY(area.compID, sps.chromaFormatIdc);
881
882
294k
  const int  totalAboveUnits    = (predSize + (unitWidth - 1)) / unitWidth;
883
294k
  const int  totalLeftUnits     = (predHSize + (unitHeight - 1)) / unitHeight;
884
294k
  const int  totalUnits         = totalAboveUnits + totalLeftUnits + 1; //+1 for top-left
885
886
294k
  if( m_lastArea != area || m_lastCh != chType )
887
98.3k
  {
888
98.3k
    m_lastCh = chType;
889
98.3k
    m_lastArea = area;
890
98.3k
    const int  numAboveUnits      = std::max<int>( tuWidth / unitWidth, 1 );
891
98.3k
    const int  numLeftUnits       = std::max<int>( tuHeight / unitHeight, 1 );
892
98.3k
    const int  numAboveRightUnits = totalAboveUnits - numAboveUnits;
893
98.3k
    const int  numLeftBelowUnits  = totalLeftUnits - numLeftUnits;
894
895
98.3k
    CHECK( numAboveUnits <= 0 || numLeftUnits <= 0 || numAboveRightUnits <= 0 || numLeftBelowUnits <= 0, "Size not supported" );
896
897
    // ----- Step 1: analyze neighborhood -----
898
98.3k
    const Position posLT          = area;
899
98.3k
    const Position posRT          = area.topRight();
900
98.3k
    const Position posLB          = area.bottomLeft();
901
902
98.3k
    m_numIntraNeighbor = 0;
903
904
98.3k
    memset( m_neighborFlags, 0, totalUnits );
905
906
98.3k
    m_neighborFlags[totalLeftUnits] = isAboveLeftAvailable( cu, chType, posLT );
907
98.3k
    m_numIntraNeighbor += m_neighborFlags[totalLeftUnits] ? 1 : 0;
908
98.3k
    m_numIntraNeighbor += isAboveAvailable     ( cu, chType, posLT, numAboveUnits,      unitWidth,  (m_neighborFlags + totalLeftUnits + 1) );
909
98.3k
    m_numIntraNeighbor += isAboveRightAvailable( cu, chType, posRT, numAboveRightUnits, unitWidth,  (m_neighborFlags + totalLeftUnits + 1 + numAboveUnits) );
910
98.3k
    m_numIntraNeighbor += isLeftAvailable      ( cu, chType, posLT, numLeftUnits,       unitHeight, (m_neighborFlags + totalLeftUnits - 1) );
911
98.3k
    m_numIntraNeighbor += isBelowLeftAvailable ( cu, chType, posLB, numLeftBelowUnits,  unitHeight, (m_neighborFlags + totalLeftUnits - 1 - numLeftUnits) );
912
98.3k
  }
913
  // ----- Step 2: fill reference samples (depending on neighborhood) -----
914
915
294k
  const Pel*  srcBuf    = recoBuf.buf;
916
294k
  const int   srcStride = recoBuf.stride;
917
294k
        Pel*  ptrDst    = refBufUnfiltered;
918
294k
  const Pel   valueDC   = 1 << (sps.bitDepths[ chType ] - 1);
919
920
  // srcRef: the top-left reference sample, left row r at srcRef[r * srcStride]. The above row with that corner, srcTop[c], lies
921
  // at a CTU top in the CTU line above, which may be deblocked meanwhile: it is read as that line was encoded.
922
294k
  const Pel* srcRef = srcBuf - ( 1 + multiRefIdx ) * srcStride - ( 1 + multiRefIdx );
923
294k
  const Pel* srcTop = srcRef;
924
294k
  if( area.y > 0 && ( area.y & ( ( pcv.maxCUSize >> getComponentScaleY( area.compID, sps.chromaFormatIdc ) ) - 1 ) ) == 0 )
925
33.2k
  {
926
33.2k
    CHECKD( multiRefIdx, "multiple reference lines at a CTU top" );
927
33.2k
    srcTop = cs.picture->getRecoAboveCtuTop( CompArea( area.compID, area.chromaFormat, Position( area.x - 1, area.y - 1 ), Size( predSize + 1, 1 ) ) ).buf;
928
33.2k
  }
929
930
294k
  if( m_numIntraNeighbor == 0 )
931
72.4k
  {
932
    // Fill border with DC value
933
3.13M
    for (int j = 0; j <= predSize + multiRefIdx; j++) { ptrDst[j] = valueDC; }
934
3.04M
    for (int i = 0; i <= predHSize + multiRefIdx; i++) { ptrDst[i+predStride] = valueDC; }
935
72.4k
  }
936
222k
  else if( m_numIntraNeighbor == totalUnits )
937
575
  {
938
    // Fill top-left border and top and top right with rec. samples
939
60.0k
    for (int j = 0; j <= predSize + multiRefIdx; j++) { ptrDst[j] = srcTop[j]; }
940
575
    ptrDst[predStride] = srcTop[0];
941
59.4k
    for (int i = 1; i <= predHSize + multiRefIdx; i++)
942
58.8k
    {
943
58.8k
      ptrDst[i + predStride] = srcRef[i * srcStride];
944
58.8k
    }
945
575
  }
946
221k
  else // reference samples are partially available
947
221k
  {
948
    // Substitution in scan order: up the left column (below-left first), the top-left corner, then along the above row.
949
    // A unit that is not available takes the last sample before it, the units before the first available one the first
950
    // sample of that one. Units are handled in runs of equal availability, each run with one copy or one fill.
951
    // left row r >= 1: srcRef[r * srcStride], above column c (row 0, the corner c = 0): srcTop[c]
952
221k
    Pel* const dstLeft = refBufUnfiltered + predStride;
953
221k
    Pel* const dstTop  = refBufUnfiltered;
954
221k
    const bool* flags  = m_neighborFlags;
955
956
    // left unit u (0: the bottom one) covers rows leftTop( u ) .. leftBottom( u ), above unit u columns aboveFirst( u ) .. aboveLast( u )
957
643k
    const auto leftTop    = [&]( int u ) { return 1 + multiRefIdx + ( totalLeftUnits - 1 - u ) * unitHeight; };
958
515k
    const auto leftBottom = [&]( int u ) { return u == 0 ? predHSize + multiRefIdx : leftTop( u ) + unitHeight - 1; };
959
562k
    const auto aboveFirst = [&]( int u ) { return 1 + multiRefIdx + ( u - totalLeftUnits - 1 ) * unitWidth; };
960
357k
    const auto aboveLast  = [&]( int u ) { return u == totalUnits - 1 ? predSize + multiRefIdx : aboveFirst( u ) + unitWidth - 1; };
961
962
221k
    int firstAvail = 0;
963
2.19M
    while( !flags[firstAvail] )
964
1.97M
    {
965
1.97M
      firstAvail++;
966
1.97M
    }
967
221k
    Pel last = firstAvail < totalLeftUnits  ? srcRef[leftBottom( firstAvail ) * srcStride]
968
221k
             : firstAvail == totalLeftUnits ? ( multiRefIdx ? srcRef[multiRefIdx * srcStride] : srcTop[0] )
969
68.6k
             :                                srcTop[aboveFirst( firstAvail )];
970
971
221k
    int u = 0;
972
583k
    while( u < totalLeftUnits )
973
362k
    {
974
362k
      int end = u;
975
3.28M
      while( end + 1 < totalLeftUnits && flags[end + 1] == flags[u] )
976
2.92M
      {
977
2.92M
        end++;
978
2.92M
      }
979
362k
      const int top = leftTop( end ), bottom = leftBottom( u );
980
362k
      if( flags[u] )
981
152k
      {
982
4.56M
        for( int r = top; r <= bottom; r++ )
983
4.40M
        {
984
4.40M
          dstLeft[r] = srcRef[r * srcStride];
985
4.40M
        }
986
152k
        last = dstLeft[top];
987
152k
      }
988
209k
      else
989
209k
      {
990
209k
        std::fill( dstLeft + top, dstLeft + bottom + 1, last );
991
209k
      }
992
362k
      u = end + 1;
993
362k
    }
994
995
    // the top-left corner: rows 0 .. multiRefIdx of the left column and columns 0 .. multiRefIdx of the above row
996
221k
    if( flags[u] )
997
106k
    {
998
257k
      for( int i = 0; i <= multiRefIdx; i++ )
999
150k
      {
1000
150k
        dstLeft[i] = i ? srcRef[i * srcStride] : srcTop[0];
1001
150k
        dstTop [i] = srcTop[i];
1002
150k
      }
1003
106k
      last = dstTop[multiRefIdx];
1004
106k
    }
1005
114k
    else
1006
114k
    {
1007
114k
      std::fill_n( dstLeft, multiRefIdx + 1, last );
1008
114k
      std::fill_n( dstTop,  multiRefIdx + 1, last );
1009
114k
    }
1010
221k
    u++;
1011
1012
579k
    while( u < totalUnits )
1013
357k
    {
1014
357k
      int end = u;
1015
3.29M
      while( end + 1 < totalUnits && flags[end + 1] == flags[u] )
1016
2.93M
      {
1017
2.93M
        end++;
1018
2.93M
      }
1019
357k
      const int first = aboveFirst( u ), lastCol = aboveLast( end );
1020
357k
      if( flags[u] )
1021
175k
      {
1022
175k
        memcpy( dstTop + first, srcTop + first, ( lastCol - first + 1 ) * sizeof( Pel ) );
1023
175k
        last = dstTop[lastCol];
1024
175k
      }
1025
182k
      else
1026
182k
      {
1027
182k
        std::fill( dstTop + first, dstTop + lastCol + 1, last );
1028
182k
      }
1029
357k
      u = end + 1;
1030
357k
    }
1031
221k
  }
1032
294k
}
1033
1034
void IntraPrediction::xFilterReferenceSamples( const Pel* refBufUnfiltered, Pel* refBufFiltered, const CompArea& area, const SPS &sps
1035
  , int multiRefIdx
1036
  , int stride
1037
)
1038
70.2k
{
1039
70.2k
  if (area.compID != COMP_Y)
1040
0
  {
1041
0
    multiRefIdx = 0;
1042
0
  }
1043
70.2k
  const int predSize = m_topRefLength + multiRefIdx;
1044
70.2k
  const int predHSize = m_leftRefLength + multiRefIdx;
1045
70.2k
  const int predStride = stride == 0 ? predSize + 1 : stride;
1046
1047
1048
70.2k
  const Pel topLeft =
1049
70.2k
    (refBufUnfiltered[0] + refBufUnfiltered[1] + refBufUnfiltered[predStride] + refBufUnfiltered[predStride + 1] + 2)
1050
70.2k
    >> 2;
1051
1052
70.2k
  refBufFiltered[0] = topLeft;
1053
1054
70.2k
  IntraFilterRefSamples( refBufUnfiltered, refBufFiltered, predSize );
1055
70.2k
  refBufFiltered[predSize] = refBufUnfiltered[predSize];
1056
1057
70.2k
  refBufFiltered += predStride;
1058
70.2k
  refBufUnfiltered += predStride;
1059
1060
70.2k
  refBufFiltered[0] = topLeft;
1061
1062
70.2k
  IntraFilterRefSamples( refBufUnfiltered, refBufFiltered, predHSize );
1063
70.2k
  refBufFiltered[predHSize] = refBufUnfiltered[predHSize];
1064
70.2k
}
1065
1066
bool isAboveLeftAvailable(const CodingUnit &cu, const ChannelType& chType, const Position& posLT)
1067
98.3k
{
1068
98.3k
  const CodingStructure& cs = *cu.cs;
1069
98.3k
  const Position refPos = posLT.offset(-1, -1);
1070
1071
98.3k
  return (cs.getCURestricted(refPos, cu, chType) != NULL);
1072
98.3k
}
1073
1074
int isAboveAvailable(const CodingUnit &cu, const ChannelType& chType, const Position& posLT, const uint32_t numUnits, const uint32_t unitWidth, bool *bValidFlags)
1075
409k
{
1076
409k
  const CodingStructure& cs = *cu.cs;
1077
1078
409k
  bool *    validFlags  = bValidFlags;
1079
409k
  int       numIntra    = 0;
1080
409k
  const int maxDx       = numUnits * unitWidth;
1081
409k
  unsigned  checkPosX   = 0;
1082
409k
  bool      valid       = false;
1083
1084
1.79M
  for (int dx = 0; dx < maxDx; dx += unitWidth)
1085
1.62M
  {
1086
1.62M
    if( dx >= checkPosX )
1087
411k
    {
1088
411k
      const Position refPos = posLT.offset(dx, -1);
1089
1090
411k
      const CodingUnit* cuN = cs.getCURestricted(refPos, cu, chType);
1091
411k
      valid = (cuN != NULL);
1092
411k
      if( cuN ) checkPosX = chType == CH_C ? (cuN->Cb().x + cuN->Cb().width - posLT.x) : (cuN->Y().x + cuN->Y().width - posLT.x);
1093
238k
      else break;
1094
411k
    }
1095
1096
1.38M
    numIntra += valid ? 1 : 0;
1097
1.38M
    *validFlags = valid;
1098
1099
1.38M
    validFlags++;
1100
1.38M
  }
1101
1102
409k
  return numIntra;
1103
409k
}
1104
1105
int isLeftAvailable(const CodingUnit &cu, const ChannelType& chType, const Position& posLT, const uint32_t numUnits, const uint32_t unitHeight, bool *bValidFlags)
1106
409k
{
1107
409k
  const CodingStructure& cs = *cu.cs;
1108
1109
409k
  bool *    validFlags = bValidFlags;
1110
409k
  int       numIntra   = 0;
1111
409k
  const int maxDy      = numUnits * unitHeight;
1112
409k
  unsigned checkPosY   = 0;
1113
409k
  bool     valid       = false;
1114
1115
1.68M
  for (int dy = 0; dy < maxDy; dy += unitHeight)
1116
1.52M
  {
1117
1.52M
    if( dy >= checkPosY )
1118
412k
    {
1119
412k
      const Position refPos = posLT.offset(-1, dy);
1120
1121
412k
      const CodingUnit* cuN = cs.getCURestricted(refPos, cu, chType);
1122
412k
      valid = (cuN != NULL);
1123
412k
      if( cuN ) checkPosY = chType == CH_C ? (cuN->Cb().y + cuN->Cb().height - posLT.y) : (cuN->Y().y + cuN->Y().height - posLT.y);
1124
251k
      else break;
1125
412k
    }
1126
1127
1.27M
    numIntra += valid ? 1 : 0;
1128
1.27M
    *validFlags = valid;
1129
1130
1.27M
    validFlags--;
1131
1.27M
  }
1132
1133
409k
  return numIntra;
1134
409k
}
1135
1136
int isAboveRightAvailable(const CodingUnit &cu, const ChannelType& chType, const Position& posRT, const uint32_t numUnits, const uint32_t unitWidth, bool *bValidFlags )
1137
216k
{
1138
216k
  const CodingStructure& cs = *cu.cs;
1139
1140
216k
  bool *    validFlags = bValidFlags;
1141
216k
  int       numIntra   = 0;
1142
216k
  const int maxDx      = numUnits * unitWidth;
1143
216k
  unsigned  checkPosX   = 0;
1144
216k
  bool      valid       = false;
1145
1146
709k
  for (int dx = 0; dx < maxDx; dx += unitWidth)
1147
677k
  {
1148
677k
    if( dx >= checkPosX )
1149
252k
    {
1150
252k
      const Position refPos = posRT.offset(unitWidth + dx, -1);
1151
1152
252k
      const CodingUnit* cuN = cs.getCURestricted(refPos, cu, chType);
1153
252k
      valid = (cuN != NULL);
1154
252k
      if(cuN) checkPosX = chType == CH_C ? (cuN->Cb().x + cuN->Cb().width - (posRT.x + unitWidth)) : (cuN->Y().x + cuN->Y().width - (posRT.x + unitWidth));
1155
184k
      else break;
1156
252k
    }
1157
1158
492k
    numIntra += valid ? 1 : 0;
1159
492k
    *validFlags = valid;
1160
1161
492k
    validFlags++;
1162
492k
  }
1163
1164
216k
  return numIntra;
1165
216k
}
1166
1167
int isBelowLeftAvailable(const CodingUnit &cu, const ChannelType& chType, const Position& posLB, const uint32_t numUnits, const uint32_t unitHeight, bool *bValidFlags )
1168
205k
{
1169
205k
  const CodingStructure& cs = *cu.cs;
1170
1171
205k
  bool *    validFlags = bValidFlags;
1172
205k
  int       numIntra   = 0;
1173
205k
  const int maxDy      = numUnits * unitHeight;
1174
205k
  unsigned  checkPosY   = 0;
1175
205k
  bool      valid       = false;
1176
1177
364k
  for (int dy = 0; dy < maxDy; dy += unitHeight)
1178
356k
  {
1179
356k
    if( dy >= checkPosY )
1180
225k
    {
1181
225k
      const Position refPos = posLB.offset(-1, unitHeight + dy);
1182
1183
225k
      const CodingUnit* cuN = cs.getCURestricted(refPos, cu, chType);
1184
225k
      valid = (cuN != NULL);
1185
225k
      if( cuN ) checkPosY = chType == CH_C ? (cuN->Cb().y + cuN->Cb().height - (posLB.y + unitHeight)) : (cuN->Y().y + cuN->Y().height - (posLB.y + unitHeight));
1186
198k
      else break;
1187
225k
    }
1188
1189
158k
    numIntra += valid ? 1 : 0;
1190
158k
    *validFlags = valid;
1191
1192
158k
    validFlags--;
1193
158k
  }
1194
1195
205k
  return numIntra;
1196
205k
}
1197
1198
// LumaRecPixels
1199
void IntraPrediction::loadLMLumaRecPels(const CodingUnit& cu, const CompArea& chromaArea )
1200
68.2k
{
1201
68.2k
  int iDstStride = 2 * MAX_TB_SIZEY + 1;
1202
68.2k
  Pel* pDst0 = m_pMdlmTemp + iDstStride + 1;
1203
  //assert 420 chroma subsampling
1204
68.2k
  CompArea lumaArea = CompArea( COMP_Y, cu.chromaFormat, chromaArea.lumaPos(), recalcSize( cu.chromaFormat, CH_C, CH_L, chromaArea.size() ) );//needed for correct pos/size (4x4 Tus)
1205
1206
68.2k
  CHECK(lumaArea.width == chromaArea.width && CHROMA_444 != cu.chromaFormat, "");
1207
68.2k
  CHECK(lumaArea.height == chromaArea.height && CHROMA_444 != cu.chromaFormat && CHROMA_422 != cu.chromaFormat, "");
1208
1209
68.2k
  const SizeType uiCWidth = chromaArea.width;
1210
68.2k
  const SizeType uiCHeight = chromaArea.height;
1211
1212
68.2k
  const CPelBuf Src = cu.cs->picture->getRecoBuf( lumaArea );
1213
68.2k
  Pel const* pRecSrc0   = Src.bufAt( 0, 0 );
1214
68.2k
  int iRecStride        = Src.stride;
1215
68.2k
  int logSubWidthC  = getChannelTypeScaleX(CH_C, cu.chromaFormat);
1216
68.2k
  int logSubHeightC = getChannelTypeScaleY(CH_C, cu.chromaFormat);
1217
1218
68.2k
  int iRecStride2       = iRecStride << logSubHeightC;
1219
1220
68.2k
  const CompArea& area = isChroma( cu.chType ) ? chromaArea : lumaArea;
1221
1222
68.2k
  const uint32_t uiTuWidth  = area.width;
1223
68.2k
  const uint32_t uiTuHeight = area.height;
1224
1225
68.2k
  const int  unitWidthLog2  = MIN_CU_LOG2 - getComponentScaleX( area.compID, area.chromaFormat );
1226
68.2k
  const int  unitHeightLog2 = MIN_CU_LOG2 - getComponentScaleY( area.compID, area.chromaFormat );
1227
68.2k
  const int  unitWidth  = 1<<unitWidthLog2;
1228
68.2k
  const int  unitHeight = 1<<unitHeightLog2;
1229
1230
68.2k
  const int  iTUWidthInUnits  = uiTuWidth >> unitWidthLog2;
1231
68.2k
  const int  iTUHeightInUnits = uiTuHeight >> unitHeightLog2;
1232
68.2k
  const int  iAboveUnits      = iTUWidthInUnits;
1233
68.2k
  const int  iLeftUnits       = iTUHeightInUnits;
1234
1235
68.2k
  const int  chromaUnitWidthLog2  = MIN_CU_LOG2 - logSubWidthC;
1236
68.2k
  const int  chromaUnitHeightLog2 = MIN_CU_LOG2 - logSubHeightC;
1237
68.2k
  const int  chromaUnitWidth = 1<<chromaUnitWidthLog2;
1238
68.2k
  const int  chromaUnitHeight = 1<<chromaUnitHeightLog2;
1239
68.2k
  const int  topTemplateSampNum = 2 * uiCWidth; // for MDLM, the number of template samples is 2W or 2H.
1240
68.2k
  const int  leftTemplateSampNum = 2 * uiCHeight;
1241
68.2k
  const int  totalAboveUnits = (topTemplateSampNum + (chromaUnitWidth - 1)) >> chromaUnitWidthLog2;
1242
68.2k
  const int  totalLeftUnits = (leftTemplateSampNum + (chromaUnitHeight - 1)) >> chromaUnitHeightLog2;
1243
68.2k
  const int  totalUnits = totalLeftUnits + totalAboveUnits + 1;
1244
68.2k
  const int  aboveRightUnits = totalAboveUnits - iAboveUnits;
1245
68.2k
  const int  leftBelowUnits = totalLeftUnits - iLeftUnits;
1246
1247
68.2k
  int avaiAboveRightUnits = 0;
1248
68.2k
  int avaiLeftBelowUnits = 0;
1249
68.2k
  bool  bNeighborFlags[4 * MAX_NUM_PART_IDXS_IN_CTU_WIDTH + 1];
1250
68.2k
  memset(bNeighborFlags, 0, totalUnits);
1251
68.2k
  bool aboveIsAvailable, leftIsAvailable;
1252
68.2k
  const ChannelType areaCh = toChannelType( area.compID );
1253
1254
68.2k
  int availlableUnit = isLeftAvailable(cu, areaCh, area.pos(), iLeftUnits, unitHeight, (bNeighborFlags + iLeftUnits + leftBelowUnits - 1));
1255
1256
68.2k
  leftIsAvailable = availlableUnit == iTUHeightInUnits;
1257
1258
68.2k
  availlableUnit = isAboveAvailable(cu, areaCh, area.pos(), iAboveUnits, unitWidth, (bNeighborFlags + iLeftUnits + leftBelowUnits + 1));
1259
1260
68.2k
  aboveIsAvailable = availlableUnit == iTUWidthInUnits;
1261
1262
68.2k
  if (leftIsAvailable)   // if left is not available, then the below left is not available
1263
27.3k
  {
1264
27.3k
    avaiLeftBelowUnits = isBelowLeftAvailable(cu, areaCh, area.bottomLeftComp(area.compID), leftBelowUnits, unitHeight, (bNeighborFlags + leftBelowUnits - 1));
1265
27.3k
  }
1266
1267
68.2k
  if (aboveIsAvailable)   // if above is not available, then  the above right is not available.
1268
29.2k
  {
1269
29.2k
    avaiAboveRightUnits = isAboveRightAvailable(cu, areaCh, area.topRightComp(area.compID), aboveRightUnits, unitWidth, (bNeighborFlags + iLeftUnits + leftBelowUnits + iAboveUnits + 1));
1270
29.2k
  }
1271
1272
68.2k
  Pel*       pDst  = nullptr;
1273
68.2k
  Pel const* piSrc = nullptr;
1274
1275
68.2k
  bool isFirstRowOfCtu = (lumaArea.y & ((cu.cs->sps)->CTUSize - 1)) == 0;
1276
1277
68.2k
  int addedAboveRight = 0;
1278
68.2k
  if( aboveIsAvailable && ( cu.intraDir[1] == MDLM_L_IDX || cu.intraDir[1] == MDLM_T_IDX ) )
1279
29.2k
  {
1280
29.2k
    addedAboveRight = avaiAboveRightUnits * chromaUnitWidth;
1281
29.2k
  }
1282
1283
  // the luma row above, read by the above row and, with vertically collocated 4:2:0 chroma, by the first row of the left
1284
  // column and of the inner part; at a CTU top it lies in the CTU line above, which may be deblocked meanwhile: read it as
1285
  // encoded
1286
68.2k
  const Pel* lumaAbove = pRecSrc0 - iRecStride;
1287
68.2k
  if( aboveIsAvailable && isFirstRowOfCtu )
1288
4.34k
  {
1289
4.34k
    const int colsLeft  = 1 + ( leftIsAvailable ? logSubWidthC : 0 );   // the left column's centre is x - 2 in 4:2:x
1290
4.34k
    const int colsRight = ( uiCWidth + addedAboveRight ) << logSubWidthC;
1291
4.34k
    const CompArea rowAbove( COMP_Y, cu.chromaFormat, Position( lumaArea.x - colsLeft, lumaArea.y - 1 ), Size( colsLeft + colsRight, 1 ) );
1292
4.34k
    lumaAbove = cu.cs->picture->getRecoAboveCtuTop( rowAbove ).buf + colsLeft;
1293
4.34k
  }
1294
1295
68.2k
  if (aboveIsAvailable)
1296
29.2k
  {
1297
29.2k
    pDst  = pDst0    - iDstStride;
1298
29.2k
    if( cu.chromaFormat == CHROMA_420 && !isFirstRowOfCtu && !cu.cs->sps->verCollocatedChroma )
1299
24.9k
    {
1300
24.9k
      LMLumaDownsample420( pRecSrc0 - iRecStride2, iRecStride, pDst, 0, uiCWidth + addedAboveRight, 1, leftIsAvailable );
1301
24.9k
    }
1302
4.34k
    else
1303
4.34k
    {
1304
169k
      for (int i = 0; i < uiCWidth + addedAboveRight; i++)
1305
164k
      {
1306
164k
        const bool leftPadding = i == 0 && !leftIsAvailable;
1307
164k
        if (cu.chromaFormat == CHROMA_444)
1308
0
        {
1309
0
          piSrc = lumaAbove;
1310
0
          pDst[i] = piSrc[i];
1311
0
        }
1312
164k
        else if (isFirstRowOfCtu)
1313
164k
        {
1314
164k
          piSrc   = lumaAbove;
1315
164k
          pDst[i] = (piSrc[2 * i] * 2 + piSrc[2 * i - (leftPadding ? 0 : 1)] + piSrc[2 * i + 1] + 2) >> 2;
1316
164k
        }
1317
0
        else if (cu.chromaFormat == CHROMA_422)
1318
0
        {
1319
0
          piSrc = pRecSrc0 - iRecStride2;
1320
1321
0
          int s = 2;
1322
0
          s += piSrc[2 * i] * 2;
1323
0
          s += piSrc[2 * i - (leftPadding ? 0 : 1)];
1324
0
          s += piSrc[2 * i + 1];
1325
0
          pDst[i] = s >> 2;
1326
0
        }
1327
0
        else
1328
0
        {
1329
0
          CHECKD( !cu.cs->sps->verCollocatedChroma, "the 4:2:0 6-tap case is handled by LMLumaDownsample420" );
1330
0
          piSrc = pRecSrc0 - iRecStride2;
1331
1332
0
          int s = 4;
1333
0
          s += piSrc[2 * i - iRecStride];
1334
0
          s += piSrc[2 * i] * 4;
1335
0
          s += piSrc[2 * i - (leftPadding ? 0 : 1)];
1336
0
          s += piSrc[2 * i + 1];
1337
0
          s += piSrc[2 * i + iRecStride];
1338
0
          pDst[i] = s >> 3;
1339
0
        }
1340
164k
      }
1341
4.34k
    }
1342
29.2k
  }
1343
1344
68.2k
  if (leftIsAvailable)
1345
27.3k
  {
1346
27.3k
    pDst  = pDst0    - 1;
1347
27.3k
    piSrc = pRecSrc0 - 1 - logSubWidthC;
1348
1349
27.3k
    int addedLeftBelow = 0;
1350
27.3k
    if ((cu.intraDir[1] == MDLM_L_IDX) || (cu.intraDir[1] == MDLM_T_IDX))
1351
27.3k
    {
1352
27.3k
      addedLeftBelow = avaiLeftBelowUnits*chromaUnitHeight;
1353
27.3k
    }
1354
1355
577k
    for (int j = 0; j < uiCHeight + addedLeftBelow; j++)
1356
550k
    {
1357
550k
      if (cu.chromaFormat == CHROMA_444)
1358
0
      {
1359
0
        pDst[0] = piSrc[0];
1360
0
      }
1361
550k
      else if (cu.chromaFormat == CHROMA_422)
1362
0
      {
1363
0
        int s = 2;
1364
0
        s += piSrc[0] * 2;
1365
0
        s += piSrc[-1];
1366
0
        s += piSrc[1];
1367
0
        pDst[0] = s >> 2;
1368
0
      }
1369
550k
      else if (cu.cs->sps->verCollocatedChroma)
1370
0
      {
1371
0
        int s = 4;
1372
0
        s += j > 0 ? piSrc[-iRecStride] : aboveIsAvailable ? lumaAbove[-1 - logSubWidthC] : piSrc[0];
1373
0
        s += piSrc[0] * 4;
1374
0
        s += piSrc[-1];
1375
0
        s += piSrc[1];
1376
0
        s += piSrc[iRecStride];
1377
0
        pDst[0] = s >> 3;
1378
0
      }
1379
550k
      else
1380
550k
      {
1381
550k
        int s = 4;
1382
550k
        s += piSrc[0] * 2;
1383
550k
        s += piSrc[1];
1384
550k
        s += piSrc[-1];
1385
550k
        s += piSrc[iRecStride] * 2;
1386
550k
        s += piSrc[iRecStride + 1];
1387
550k
        s += piSrc[iRecStride - 1];
1388
550k
        pDst[0] = s >> 3;
1389
550k
      }
1390
1391
550k
      piSrc += iRecStride2;
1392
550k
      pDst  += iDstStride;
1393
550k
    }
1394
27.3k
  }
1395
1396
  // inner part from reconstructed picture buffer
1397
68.2k
  if( cu.chromaFormat == CHROMA_420 && !cu.cs->sps->verCollocatedChroma )
1398
68.2k
  {
1399
68.2k
    LMLumaDownsample420( pRecSrc0, iRecStride, pDst0, iDstStride, uiCWidth, uiCHeight, leftIsAvailable );
1400
68.2k
  }
1401
0
  else
1402
0
  {
1403
0
    for( int j = 0; j < uiCHeight; j++ )
1404
0
    {
1405
0
      for( int i = 0; i < uiCWidth; i++ )
1406
0
      {
1407
0
        if (cu.chromaFormat == CHROMA_444)
1408
0
        {
1409
0
          pDst0[i] = pRecSrc0[i];
1410
0
        }
1411
0
        else if (cu.chromaFormat == CHROMA_422)
1412
0
        {
1413
0
          const bool leftPadding  = i == 0 && !leftIsAvailable;
1414
1415
0
          int s = 2;
1416
0
          s += pRecSrc0[2 * i] * 2;
1417
0
          s += pRecSrc0[2 * i - (leftPadding ? 0 : 1)];
1418
0
          s += pRecSrc0[2 * i + 1];
1419
0
          pDst0[i] = s >> 2;
1420
0
        }
1421
0
        else
1422
0
        {
1423
0
          CHECKD( !cu.cs->sps->verCollocatedChroma, "the 4:2:0 6-tap case is handled by LMLumaDownsample420" );
1424
0
          const bool leftPadding  = i == 0 && !leftIsAvailable;
1425
1426
0
          int s = 4;
1427
0
          s += j > 0 ? pRecSrc0[2 * i - iRecStride] : aboveIsAvailable ? lumaAbove[2 * i] : pRecSrc0[2 * i];
1428
0
          s += pRecSrc0[2 * i] * 4;
1429
0
          s += pRecSrc0[2 * i - (leftPadding ? 0 : 1)];
1430
0
          s += pRecSrc0[2 * i + 1];
1431
0
          s += pRecSrc0[2 * i + iRecStride];
1432
0
          pDst0[i] = s >> 3;
1433
0
        }
1434
0
      }
1435
1436
0
      pDst0    += iDstStride;
1437
0
      pRecSrc0 += iRecStride2;
1438
0
    }
1439
0
  }
1440
68.2k
}
1441
1442
void IntraPrediction::xGetLMParameters(const CodingUnit& cu, const ComponentID compID,
1443
                                              const CompArea& chromaArea,
1444
                                              int& a, int& b, int& iShift)
1445
242k
{
1446
242k
  CHECK(compID == COMP_Y, "");
1447
1448
242k
  const SizeType cWidth  = chromaArea.width;
1449
242k
  const SizeType cHeight = chromaArea.height;
1450
1451
242k
  const Position posLT = chromaArea;
1452
1453
242k
  CodingStructure & cs = *(cu.cs);
1454
1455
242k
  const SPS &        sps           = *cs.sps;
1456
242k
  const uint32_t     tuWidth     = chromaArea.width;
1457
242k
  const uint32_t     tuHeight    = chromaArea.height;
1458
242k
  const ChromaFormat nChromaFormat = sps.chromaFormatIdc;
1459
1460
242k
  const int unitWidthLog2    = MIN_CU_LOG2 - getComponentScaleX(chromaArea.compID, nChromaFormat);
1461
242k
  const int unitHeightLog2   = MIN_CU_LOG2 - getComponentScaleY(chromaArea.compID, nChromaFormat);
1462
242k
  const int unitWidth    = 1<<unitWidthLog2;
1463
242k
  const int unitHeight   = 1<<unitHeightLog2;
1464
1465
242k
  const int tuWidthInUnits  = tuWidth >> unitWidthLog2;
1466
242k
  const int tuHeightInUnits = tuHeight >> unitHeightLog2;
1467
242k
  const int aboveUnits      = tuWidthInUnits;
1468
242k
  const int leftUnits       = tuHeightInUnits;
1469
242k
  int topTemplateSampNum = 2 * cWidth; // for MDLM, the template sample number is 2W or 2H;
1470
242k
  int leftTemplateSampNum = 2 * cHeight;
1471
242k
  int totalAboveUnits = (topTemplateSampNum + (unitWidth - 1)) >> unitWidthLog2;
1472
242k
  int totalLeftUnits = (leftTemplateSampNum + (unitHeight - 1)) >> unitHeightLog2;
1473
242k
  int totalUnits = totalLeftUnits + totalAboveUnits + 1;
1474
242k
  int aboveRightUnits = totalAboveUnits - aboveUnits;
1475
242k
  int leftBelowUnits = totalLeftUnits - leftUnits;
1476
242k
  int avaiAboveRightUnits = 0;
1477
242k
  int avaiLeftBelowUnits = 0;
1478
242k
  int avaiAboveUnits = 0;
1479
242k
  int avaiLeftUnits = 0;
1480
1481
242k
  const int curChromaMode = cu.intraDir[1];
1482
242k
  bool neighborFlags[4 * MAX_NUM_PART_IDXS_IN_CTU_WIDTH + 1];
1483
242k
  memset(neighborFlags, 0, totalUnits);
1484
1485
242k
  bool aboveAvailable, leftAvailable;
1486
1487
242k
  int availableUnit = isAboveAvailable(cu, CH_C, posLT, aboveUnits, unitWidth,
1488
242k
    (neighborFlags + leftUnits + leftBelowUnits + 1));
1489
242k
  aboveAvailable = availableUnit == tuWidthInUnits;
1490
1491
242k
  availableUnit = isLeftAvailable(cu, CH_C, posLT, leftUnits, unitHeight,
1492
242k
    (neighborFlags + leftUnits + leftBelowUnits - 1));
1493
242k
  leftAvailable = availableUnit == tuHeightInUnits;
1494
242k
  if (leftAvailable) // if left is not available, then the below left is not available
1495
80.1k
  {
1496
80.1k
    avaiLeftUnits = tuHeightInUnits;
1497
80.1k
    avaiLeftBelowUnits = isBelowLeftAvailable(cu, CH_C, chromaArea.bottomLeftComp(chromaArea.compID), leftBelowUnits, unitHeight, (neighborFlags + leftBelowUnits - 1));
1498
80.1k
  }
1499
242k
  if (aboveAvailable) // if above is not available, then  the above right is not available.
1500
88.6k
  {
1501
88.6k
    avaiAboveUnits = tuWidthInUnits;
1502
88.6k
    avaiAboveRightUnits = isAboveRightAvailable(cu, CH_C, chromaArea.topRightComp(chromaArea.compID), aboveRightUnits, unitWidth, (neighborFlags + leftUnits + leftBelowUnits + aboveUnits + 1));
1503
88.6k
  }
1504
1505
242k
  const int srcStride = 2 * MAX_TB_SIZEY + 1;
1506
242k
  Pel* srcColor0 = m_pMdlmTemp + srcStride + 1;
1507
1508
242k
  Pel* curChroma0 = getPredictorPtr(compID);
1509
1510
242k
  unsigned internalBitDepth = sps.bitDepths[CH_C];
1511
1512
242k
  int minLuma[2] = {  MAX_INT, 0 };
1513
242k
  int maxLuma[2] = { -MAX_INT, 0 };
1514
1515
242k
  Pel* src = srcColor0 - srcStride;
1516
242k
  int actualTopTemplateSampNum = 0;
1517
242k
  int actualLeftTemplateSampNum = 0;
1518
242k
  if (curChromaMode == MDLM_T_IDX)
1519
97.3k
  {
1520
97.3k
    leftAvailable = 0;
1521
97.3k
    avaiAboveRightUnits = avaiAboveRightUnits > (cHeight>>unitWidthLog2) ?  cHeight>>unitWidthLog2 : avaiAboveRightUnits;
1522
97.3k
    actualTopTemplateSampNum = unitWidth*(avaiAboveUnits + avaiAboveRightUnits);
1523
97.3k
  }
1524
145k
  else if (curChromaMode == MDLM_L_IDX)
1525
97.3k
  {
1526
97.3k
    aboveAvailable = 0;
1527
97.3k
    avaiLeftBelowUnits = avaiLeftBelowUnits > (cWidth>>unitHeightLog2) ? cWidth>>unitHeightLog2 : avaiLeftBelowUnits;
1528
97.3k
    actualLeftTemplateSampNum = unitHeight*(avaiLeftUnits + avaiLeftBelowUnits);
1529
97.3k
  }
1530
48.3k
  else if (curChromaMode == LM_CHROMA_IDX)
1531
48.3k
  {
1532
48.3k
    actualTopTemplateSampNum = cWidth;
1533
48.3k
    actualLeftTemplateSampNum = cHeight;
1534
48.3k
  }
1535
242k
  int startPos[2]; //0:Above, 1: Left
1536
242k
  int pickStep[2];
1537
1538
242k
  int aboveIs4 = leftAvailable  ? 0 : 1;
1539
242k
  int leftIs4 =  aboveAvailable ? 0 : 1;
1540
1541
242k
  startPos[0] = actualTopTemplateSampNum >> (2 + aboveIs4);
1542
242k
  pickStep[0] = std::max(1, actualTopTemplateSampNum >> (1 + aboveIs4));
1543
1544
242k
  startPos[1] = actualLeftTemplateSampNum >> (2 + leftIs4);
1545
242k
  pickStep[1] = std::max(1, actualLeftTemplateSampNum >> (1 + leftIs4));
1546
1547
242k
  Pel selectLumaPix[4] = { 0, 0, 0, 0 };
1548
242k
  Pel selectChromaPix[4] = { 0, 0, 0, 0 };
1549
1550
242k
  int cntT, cntL;
1551
242k
  cntT = cntL = 0;
1552
242k
  int cnt = 0;
1553
242k
  if (aboveAvailable)
1554
48.2k
  {
1555
48.2k
    cntT = std::min(actualTopTemplateSampNum, (1 + aboveIs4) << 1);
1556
48.2k
    src = srcColor0 - srcStride;
1557
48.2k
    const Pel *cur = curChroma0 + 1;
1558
238k
    for (int pos = startPos[0]; cnt < cntT; pos += pickStep[0], cnt++)
1559
190k
    {
1560
190k
      selectLumaPix[cnt] = src[pos];
1561
190k
      selectChromaPix[cnt] = cur[pos];
1562
190k
    }
1563
48.2k
  }
1564
1565
242k
  if (leftAvailable)
1566
43.2k
  {
1567
43.2k
    cntL = std::min(actualLeftTemplateSampNum, ( 1 + leftIs4 ) << 1 );
1568
43.2k
    src = srcColor0 - 1;
1569
43.2k
    const Pel *cur = curChroma0 + m_refBufferStride[compID] + 1;
1570
213k
    for (int pos = startPos[1], cnt = 0; cnt < cntL; pos += pickStep[1], cnt++)
1571
170k
    {
1572
170k
      selectLumaPix[cnt + cntT] = src[pos * srcStride];
1573
170k
      selectChromaPix[cnt + cntT] = cur[pos];
1574
170k
    }
1575
43.2k
  }
1576
242k
  cnt = cntL + cntT;
1577
1578
242k
  if (cnt == 2)
1579
16
  {
1580
16
    selectLumaPix[3] = selectLumaPix[0]; selectChromaPix[3] = selectChromaPix[0];
1581
16
    selectLumaPix[2] = selectLumaPix[1]; selectChromaPix[2] = selectChromaPix[1];
1582
16
    selectLumaPix[0] = selectLumaPix[1]; selectChromaPix[0] = selectChromaPix[1];
1583
16
    selectLumaPix[1] = selectLumaPix[3]; selectChromaPix[1] = selectChromaPix[3];
1584
16
  }
1585
1586
242k
  int minGrpIdx[2] = { 0, 2 };
1587
242k
  int maxGrpIdx[2] = { 1, 3 };
1588
242k
  int *tmpMinGrp = minGrpIdx;
1589
242k
  int *tmpMaxGrp = maxGrpIdx;
1590
242k
  if (selectLumaPix[tmpMinGrp[0]] > selectLumaPix[tmpMinGrp[1]]) std::swap(tmpMinGrp[0], tmpMinGrp[1]);
1591
242k
  if (selectLumaPix[tmpMaxGrp[0]] > selectLumaPix[tmpMaxGrp[1]]) std::swap(tmpMaxGrp[0], tmpMaxGrp[1]);
1592
242k
  if (selectLumaPix[tmpMinGrp[0]] > selectLumaPix[tmpMaxGrp[1]]) std::swap(tmpMinGrp, tmpMaxGrp);
1593
242k
  if (selectLumaPix[tmpMinGrp[1]] > selectLumaPix[tmpMaxGrp[0]]) std::swap(tmpMinGrp[1], tmpMaxGrp[0]);
1594
1595
242k
  minLuma[0] = (selectLumaPix[tmpMinGrp[0]] + selectLumaPix[tmpMinGrp[1]] + 1 )>>1;
1596
242k
  minLuma[1] = (selectChromaPix[tmpMinGrp[0]] + selectChromaPix[tmpMinGrp[1]] + 1) >> 1;
1597
242k
  maxLuma[0] = (selectLumaPix[tmpMaxGrp[0]] + selectLumaPix[tmpMaxGrp[1]] + 1 )>>1;
1598
242k
  maxLuma[1] = (selectChromaPix[tmpMaxGrp[0]] + selectChromaPix[tmpMaxGrp[1]] + 1) >> 1;
1599
1600
242k
  if (leftAvailable || aboveAvailable)
1601
90.2k
  {
1602
90.2k
    int diff = maxLuma[0] - minLuma[0];
1603
90.2k
    if (diff > 0)
1604
476
    {
1605
476
      int diffC = maxLuma[1] - minLuma[1];
1606
476
      int x = floorLog2( diff );
1607
476
      static const uint8_t DivSigTable[1 << 4] = {
1608
        // 4bit significands - 8 ( MSB is omitted )
1609
476
        0,  7,  6,  5,  5,  4,  4,  3,  3,  2,  2,  1,  1,  1,  1,  0
1610
476
      };
1611
476
      int normDiff = (diff << 4 >> x) & 15;
1612
476
      int v = DivSigTable[normDiff] | 8;
1613
476
      x += normDiff != 0;
1614
1615
476
      int y = diffC == 0 ? 0 : floorLog2( abs( diffC ) ) + 1;
1616
476
      int add = 1 << y >> 1;
1617
476
      a = (diffC * v + add) >> y;
1618
476
      iShift = 3 + x - y;
1619
476
      if ( iShift < 1 )
1620
0
      {
1621
0
        iShift = 1;
1622
0
        a = ( (a == 0)? 0: (a < 0)? -15 : 15 );   // a=Sign(a)*15
1623
0
      }
1624
476
      b = minLuma[1] - ((a * minLuma[0]) >> iShift);
1625
476
    }
1626
89.7k
    else
1627
89.7k
    {
1628
89.7k
      a = 0;
1629
89.7k
      b = minLuma[1];
1630
89.7k
      iShift = 0;
1631
89.7k
    }
1632
90.2k
  }
1633
152k
  else
1634
152k
  {
1635
152k
    a = 0;
1636
152k
    b = 1 << (internalBitDepth - 1);
1637
152k
    iShift = 0;
1638
152k
  }
1639
242k
}
1640
1641
void IntraPrediction::initIntraMip( const CodingUnit& cu )
1642
44.9k
{
1643
44.9k
  CHECK( cu.lwidth() > cu.cs->sps->getMaxTbSize() || cu.lheight() > cu.cs->sps->getMaxTbSize(), "Error: block size not supported for MIP" );
1644
1645
  // prepare input (boundary) data for prediction
1646
44.9k
  CHECK(m_ipaParam.refFilterFlag, "ERROR: unfiltered refs expected for MIP");
1647
44.9k
  Pel *ptrSrc = getPredictorPtr(COMP_Y);
1648
44.9k
  const int srcStride  = m_refBufferStride[COMP_Y];
1649
44.9k
  const int srcHStride = 2;
1650
1651
44.9k
  m_matrixIntraPred.prepareInputForPred(CPelBuf(ptrSrc, srcStride, srcHStride), cu.Y(), cu.slice->sps->bitDepths[CH_L]);
1652
44.9k
}
1653
1654
void IntraPrediction::predIntraMip( PelBuf &piPred, const CodingUnit& cu )
1655
297k
{
1656
297k
  CHECK( cu.lwidth() > cu.cs->sps->getMaxTbSize() || cu.lheight() > cu.cs->sps->getMaxTbSize(), "Error: block size not supported for MIP" );
1657
297k
  CHECK( cu.lwidth() != (1 << floorLog2(cu.lwidth())) || cu.lheight() != (1 << floorLog2(cu.lheight())), "Error: expecting blocks of size 2^M x 2^N" );
1658
1659
  // generate mode-specific prediction
1660
297k
  const int bitDepth = cu.slice->sps->bitDepths[CH_L];
1661
1662
297k
  CHECK( cu.lwidth() != piPred.stride, " no support yet" );
1663
 
1664
297k
  m_matrixIntraPred.predBlock(piPred.buf, cu.intraDir[CH_L], cu.mipTransposedFlag, bitDepth);
1665
297k
}
1666
1667
void IntraPrediction::initIntraPatternChTypeISP(const CodingUnit& cu, const CompArea& area, PelBuf& recBuf,
1668
  const bool forceRefFilterFlag)
1669
23.0k
{
1670
23.0k
  const CodingStructure& cs = *cu.cs;
1671
1672
23.0k
  if (!forceRefFilterFlag)
1673
23.0k
  {
1674
23.0k
    initPredIntraParams(cu, area, *cs.sps);
1675
23.0k
  }
1676
1677
23.0k
  const Position posLT = area;
1678
23.0k
  bool           isLeftAvail =
1679
23.0k
    (cs.getCURestricted(posLT.offset(-1, 0), cu, CH_L) != NULL);
1680
23.0k
  bool isAboveAvail =
1681
23.0k
    (cs.getCURestricted(posLT.offset(0, -1), cu, CH_L) != NULL);
1682
  // ----- Step 1: unfiltered reference samples -----
1683
23.0k
  if (cu.blocks[area.compID].x == area.x && cu.blocks[area.compID].y == area.y)
1684
18.2k
  {
1685
18.2k
    Pel* refBufUnfiltered = m_refBuffer[area.compID][PRED_BUF_UNFILTERED];
1686
    // With the first subpartition all the CU reference samples are fetched at once in a single call to
1687
    // xFillReferenceSamples
1688
18.2k
    if (cu.ispMode == HOR_INTRA_SUBPARTITIONS)
1689
8.75k
    {
1690
8.75k
      m_leftRefLength = cu.Y().height << 1;
1691
8.75k
      m_topRefLength = cu.Y().width + area.width;
1692
8.75k
    }
1693
9.54k
    else   // if (cu.ispMode == VER_INTRA_SUBPARTITIONS)
1694
9.54k
    {
1695
9.54k
      m_leftRefLength = cu.Y().height + area.height;
1696
9.54k
      m_topRefLength = cu.Y().width << 1;
1697
9.54k
    }
1698
1699
18.2k
    xFillReferenceSamples(cs.picture->getRecoBuf(cu.Y()), refBufUnfiltered, cu.Y(), cu);
1700
1701
    // After having retrieved all the CU reference samples, the number of reference samples is now adjusted for the
1702
    // current subpartition
1703
18.2k
    m_topRefLength = cu.blocks[area.compID].width + area.width;
1704
18.2k
    m_leftRefLength = cu.blocks[area.compID].height + area.height;
1705
18.2k
  }
1706
4.75k
  else
1707
4.75k
  {
1708
4.75k
    m_topRefLength = cu.blocks[area.compID].width + area.width;
1709
4.75k
    m_leftRefLength = cu.blocks[area.compID].height + area.height;
1710
1711
4.75k
    const int predSizeHor = m_topRefLength;
1712
4.75k
    const int predSizeVer = m_leftRefLength;
1713
4.75k
    if (cu.ispMode == HOR_INTRA_SUBPARTITIONS)
1714
3.59k
    {
1715
3.59k
      Pel* src = recBuf.bufAt(0, -1);
1716
3.59k
      Pel* ref = m_refBuffer[area.compID][PRED_BUF_UNFILTERED] + m_refBufferStride[area.compID];
1717
3.59k
      if (isLeftAvail)
1718
0
      {
1719
0
        for (int i = 0; i <= 2 * cu.blocks[area.compID].height - area.height; i++)
1720
0
        {
1721
0
          ref[i] = ref[i + area.height];
1722
0
        }
1723
0
      }
1724
3.59k
      else
1725
3.59k
      {
1726
73.7k
        for (int i = 0; i <= predSizeVer; i++)
1727
70.1k
        {
1728
70.1k
          ref[i] = src[0];
1729
70.1k
        }
1730
3.59k
      }
1731
3.59k
      Pel* dst = m_refBuffer[area.compID][PRED_BUF_UNFILTERED] + 1;
1732
3.59k
      dst[-1] = ref[0];
1733
73.9k
      for (int i = 0; i < area.width; i++)
1734
70.3k
      {
1735
70.3k
        dst[i] = src[i];
1736
70.3k
      }
1737
3.59k
      Pel sample = src[area.width - 1];
1738
3.59k
      dst += area.width;
1739
73.9k
      for (int i = 0; i < predSizeHor - area.width; i++)
1740
70.3k
      {
1741
70.3k
        dst[i] = sample;
1742
70.3k
      }
1743
3.59k
    }
1744
1.16k
    else
1745
1.16k
    {
1746
1.16k
      Pel* src = recBuf.bufAt(-1, 0);
1747
1.16k
      Pel* ref = m_refBuffer[area.compID][PRED_BUF_UNFILTERED];
1748
1.16k
      if (isAboveAvail)
1749
0
      {
1750
0
        for (int i = 0; i <= 2 * cu.blocks[area.compID].width - area.width; i++)
1751
0
        {
1752
0
          ref[i] = ref[i + area.width];
1753
0
        }
1754
0
      }
1755
1.16k
      else
1756
1.16k
      {
1757
25.5k
        for (int i = 0; i <= predSizeHor; i++)
1758
24.4k
        {
1759
24.4k
          ref[i] = src[0];
1760
24.4k
        }
1761
1.16k
      }
1762
1.16k
      Pel* dst = m_refBuffer[area.compID][PRED_BUF_UNFILTERED] + m_refBufferStride[area.compID] + 1;
1763
1.16k
      dst[-1] = ref[0];
1764
25.5k
      for (int i = 0; i < area.height; i++)
1765
24.3k
      {
1766
24.3k
        *dst = *src;
1767
24.3k
        src += recBuf.stride;
1768
24.3k
        dst++;
1769
24.3k
      }
1770
1.16k
      Pel sample = src[-recBuf.stride];
1771
25.5k
      for (int i = 0; i < predSizeVer - area.height; i++)
1772
24.3k
      {
1773
24.3k
        *dst = sample;
1774
24.3k
        dst++;
1775
24.3k
      }
1776
1.16k
    }
1777
4.75k
  }
1778
  // ----- Step 2: filtered reference samples -----
1779
23.0k
  if (m_ipaParam.refFilterFlag || forceRefFilterFlag)
1780
0
  {
1781
0
    Pel* refBufUnfiltered = m_refBuffer[area.compID][PRED_BUF_UNFILTERED];
1782
0
    Pel* refBufFiltered = m_refBuffer[area.compID][PRED_BUF_FILTERED];
1783
0
    xFilterReferenceSamples(refBufUnfiltered, refBufFiltered, area, *cs.sps, cu.multiRefIdx);
1784
0
  }
1785
23.0k
  m_refGeneration++;
1786
23.0k
}
1787
1788
void IntraPrediction::setReferenceArrayLengths(const CompArea& area)
1789
276k
{
1790
  // set Top and Left reference samples length
1791
276k
  const int width = area.width;
1792
276k
  const int height = area.height;
1793
1794
276k
  m_leftRefLength = (height << 1);
1795
276k
  m_topRefLength = (width << 1);
1796
276k
}
1797
1798
} // namespace vvenc
1799
1800
//! \}
1801