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/Buffer.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     Buffer.h
43
 *  \brief    Low-overhead class describing 2D memory layout
44
 */
45
46
#pragma once
47
48
#ifndef __IN_UNIT_H__
49
#error "Include Unit.h not Buffer.h"
50
#endif
51
52
#include "Common.h"
53
#include "CommonDef.h"
54
#include "MotionInfo.h"
55
56
#include <string.h>
57
#include <type_traits>
58
#include <typeinfo>
59
60
#include "vvenc/vvenc.h"
61
62
//! \ingroup CommonLib
63
//! \{
64
65
struct vvencYUVBuffer;
66
67
namespace vvenc {
68
69
#if ENABLE_SIMD_OPT_BUFFER && defined(TARGET_SIMD_X86)
70
using namespace x86_simd;
71
#endif
72
73
#if ENABLE_SIMD_OPT_BUFFER && defined(TARGET_SIMD_ARM)
74
using namespace arm_simd;
75
#endif
76
77
// ---------------------------------------------------------------------------
78
// AreaBuf struct
79
// ---------------------------------------------------------------------------
80
81
struct PelBufferOps
82
{
83
  PelBufferOps();
84
  void initPelBufOps( bool enableOpt = true );
85
86
0
#define INCX( ptr, stride ) { ptr++; }
87
2.34M
#define INCY( ptr, stride ) { ptr += ( stride ); }
88
14.6M
#define OFFSETX( ptr, stride, x ) { ptr += ( x ); }
89
1.33M
#define OFFSETY( ptr, stride, y ) { ptr += ( y ) * ( stride ); }
90
2.52M
#define OFFSET( ptr, stride, x, y ) { ptr += ( x ) + ( y ) * ( stride ); }
91
#define GET_OFFSETX( ptr, stride, x ) ( ( ptr ) + ( x ) )
92
#define GET_OFFSETY( ptr, stride, y ) ( ( ptr ) + ( y ) * ( stride ) )
93
0
#define GET_OFFSET( ptr, stride, x, y ) ( ( ptr ) + ( x ) + ( y ) * ( stride ) ) // need in loopFilter.cpp + some ARM files
94
95
  void ( *roundGeo )      ( const Pel* src, Pel* dest, const int numSamples, unsigned rshift, int offset, const ClpRng &clpRng);
96
  void ( *addAvg )        ( const Pel* src0, const Pel* src1, Pel* dst, int numsamples, unsigned shift, int offset, const ClpRng& clpRng );
97
  // GEO: per row, the prefix sums of |org - pred| of GEO_PREFIX_LANES candidates into prefix, and from them the sums over
98
  // one run per row. The layout of prefix is private to each pair of functions; it holds GEO_PREFIX_LANES * ( width + 1 )
99
  // * height values. Lanes that laneUsed marks as unused may be left out, and their sums are undefined; their pred must
100
  // still be readable.
101
  void ( *geoPrefixSums ) ( const Pel* org, int orgStride, const Pel* const* pred, int predStride, int width, int height, const bool* laneUsed, uint32_t* prefix );
102
  void ( *geoRunSads )    ( const uint32_t* prefix, const uint8_t* runStart, const uint8_t* runEnd, int width, int height, const bool* laneUsed, uint32_t* sad );
103
  void ( *reco  )         ( const Pel* src0, const Pel* src1, Pel* dst, int numSamples, const ClpRng& clpRng );
104
  void ( *copyClip )      ( const Pel* src0,                  Pel* dst, int numSamples, const ClpRng& clpRng );
105
  void ( *addAvg4 )       ( const Pel* src0, int src0Stride, const Pel* src1, int src1Stride, Pel* dst, int dstStride, int width, int height,       unsigned shift, int offset, const ClpRng& clpRng );
106
  void ( *addAvg8 )       ( const Pel* src0, int src0Stride, const Pel* src1, int src1Stride, Pel* dst, int dstStride, int width, int height,       unsigned shift, int offset, const ClpRng& clpRng );
107
  void ( *addAvg16 )      ( const Pel* src0, int src0Stride, const Pel* src1, int src1Stride, Pel* dst, int dstStride, int width, int height,       unsigned shift, int offset, const ClpRng& clpRng );
108
  void ( *sub2 )          ( const Pel* src0, int src0Stride, const Pel* src1, int src1Stride, Pel* dst, int dstStride, int width, int height );
109
  void ( *sub4 )          ( const Pel* src0, int src0Stride, const Pel* src1, int src1Stride, Pel* dst, int dstStride, int width, int height );
110
  void ( *sub8 )          ( const Pel* src0, int src0Stride, const Pel* src1, int src1Stride, Pel* dst, int dstStride, int width, int height );
111
  void ( *wghtAvg4 )      ( const Pel* src0, int src0Stride, const Pel* src1, int src1Stride, Pel *dst, int dstStride, int width, int height,       unsigned shift, int offset, int w0, int w1, const ClpRng& clpRng );
112
  void ( *wghtAvg8 )      ( const Pel* src0, int src0Stride, const Pel* src1, int src1Stride, Pel *dst, int dstStride, int width, int height,       unsigned shift, int offset, int w0, int w1, const ClpRng& clpRng );
113
  void ( *copyClip2 )     ( const Pel* src0, int src0Stride,                                  Pel* dst, int dstStride, int width, int height,                                   const ClpRng& clpRng );
114
  void ( *copyClip4 )     ( const Pel* src0, int src0Stride,                                  Pel* dst, int dstStride, int width, int height,                                   const ClpRng& clpRng );
115
  void ( *copyClip8 )     ( const Pel* src0, int src0Stride,                                  Pel* dst, int dstStride, int width, int height,                                   const ClpRng& clpRng );
116
  void ( *reco2 )         ( const Pel* src0, int src0Stride, const Pel* src1, int src1Stride, Pel* dst, int dstStride, int width, int height,                                   const ClpRng& clpRng );
117
  void ( *reco4 )         ( const Pel* src0, int src0Stride, const Pel* src1, int src1Stride, Pel* dst, int dstStride, int width, int height,                                   const ClpRng& clpRng );
118
  void ( *reco8 )         ( const Pel* src0, int src0Stride, const Pel* src1, int src1Stride, Pel* dst, int dstStride, int width, int height,                                   const ClpRng& clpRng );
119
  void ( *linTf4 )        ( const Pel* src0, int src0Stride,                                  Pel* dst, int dstStride, int width, int height, int scale, unsigned shift, int offset, const ClpRng& clpRng, bool bClip );
120
  void ( *linTf8 )        ( const Pel* src0, int src0Stride,                                  Pel* dst, int dstStride, int width, int height, int scale, unsigned shift, int offset, const ClpRng& clpRng, bool bClip );
121
  void ( *copyBuffer )    ( const char* src, int srcStride, char* dst, int dstStride, int width, int height );
122
  // the checksum of the decoded picture hash SEI for one plane: the sum, modulo 2^32, of ( p & 0xff ) ^ m and, with
123
  // twoBytes, ( p >> 8 ) ^ m, where m = ( x & 0xff ) ^ ( y & 0xff ) ^ ( x >> 8 ) ^ ( y >> 8 )
124
  uint32_t ( *pictureChecksum ) ( const Pel* plane, const ptrdiff_t stride, const int width, const int height, const bool twoBytes );
125
  void ( *removeHighFreq8)( Pel* dst, int dstStride, const Pel* org, int orgStride, const Pel* other, int otherStride, int width, int height);
126
  void ( *removeHighFreq4)( Pel* dst, int dstStride, const Pel* org, int orgStride, const Pel* other, int otherStride, int width, int height);
127
  void ( *transpose4x4 )  ( const Pel* src,  int srcStride, Pel* dst, int dstStride );
128
  void ( *transpose8x8 )  ( const Pel* src,  int srcStride, Pel* dst, int dstStride );
129
  void ( *roundIntVector) ( int* v, int size, unsigned int nShift, const int dmvLimit);
130
  void ( *mipMatrixMul_4_4)( Pel* res, const Pel* input, const uint8_t* weight, const int maxVal, const int offset, bool transpose );
131
  void ( *mipMatrixMul_8_4)( Pel* res, const Pel* input, const uint8_t* weight, const int maxVal, const int offset, bool transpose );
132
  void ( *mipMatrixMul_8_8)( Pel* res, const Pel* input, const uint8_t* weight, const int maxVal, const int offset, bool transpose );
133
  // MIP upsampling of the predSize x predSize reduced prediction by 1 << log2Factor (MatrixIntraPrediction::predBlock)
134
  void ( *mipUpsampleHor )( Pel* dst, const Pel* src, const Pel* bndry, const SizeType dstStride, const SizeType bndryStep, const SizeType predSize, const unsigned log2Factor );
135
  void ( *mipUpsampleVer )( Pel* dst, const Pel* src, const Pel* bndry, const SizeType outWidth, const SizeType srcStep, const SizeType inHeight, const unsigned log2Factor );
136
  void ( *weightCiip)     ( Pel* res, const Pel* intra, const int numSamples, int numIntra );
137
  void ( *fillPtrMap )    ( void** ptrMap, const ptrdiff_t mapStride, int width, int height, void* val );
138
  uint64_t ( *AvgHighPassWithDownsampling )    ( const int width, const int height, const Pel* pSrc, const int iSrcStride);
139
  uint64_t ( *AvgHighPass )    ( const int width, const int height, const Pel* pSrc, const int iSrcStride);
140
  uint64_t ( *AvgHighPassWithDownsamplingDiff1st ) (const int width, const int height, const Pel* pSrc,const Pel* pSrcM1, const int iSrcStride, const int iSrcM1Stride);
141
  uint64_t ( *AvgHighPassWithDownsamplingDiff2nd) (const int width,const int height,const Pel* pSrc,const Pel* pSM1,const Pel* pS21,const int iSrcStride,const int iSM1Stride,const int iSM2Stride);
142
  uint64_t ( *HDHighPass) (const int width, const int height,const Pel*  pSrc,const Pel* pSM1,const int iSrcStride,const int iSM1Stride);
143
  uint64_t ( *HDHighPass2)  (const int width, const int height,const Pel*  pSrc,const Pel* pSM1,const Pel* pSM2,const int iSrcStride,const int iSM1Stride,const int iSM2Stride);
144
  // block statistics; the sums of squares are exact for samples in 0 ... 2^15 - 1
145
  uint64_t ( *sumSquaredError )  ( const Pel* src0, const ptrdiff_t stride0, const Pel* src1, const ptrdiff_t stride1, const int width, const int height );
146
  // the sums of squared errors of the numX x numY parts of lengthX x lengthY samples of a block, in sums[j][i]; for
147
  // samples of up to 12 bits and parts of up to 16 x 16 samples, whose sums fit 32 bits. numX is 4 for the widths from
148
  // 8 up, or 2 or 1 for the widths up to 8.
149
  void     ( *sumSquaredErrorParts )( const Pel* src0, const ptrdiff_t stride0, const Pel* src1, const ptrdiff_t stride1, const int lengthX, const int lengthY, const int numX, const int numY, uint32_t sums[][4] );
150
  int64_t  ( *sum )              ( const Pel* src, const ptrdiff_t stride, const int width, const int height );
151
  void     ( *sumAndSumSquares ) ( const Pel* src, const ptrdiff_t stride, const int width, const int height, int64_t& sum, int64_t& sumSquares );
152
  // replicates the first / last sample of each row into the marginLeft / marginRight samples before / after the row
153
  void     ( *padHorizontal )    ( Pel* src, const ptrdiff_t stride, const int width, const int height, const int marginLeft, const int marginRight );
154
  // dst = ( sum of the 2x2 source samples + 2 ) >> 2
155
  void     ( *downsample2x2 )    ( const Pel* src, const ptrdiff_t srcStride, Pel* dst, const ptrdiff_t dstStride, const int dstWidth, const int dstHeight );
156
  // sum of the products of the 3x3 high-pass filtered samples of two planes (the joint Cb-Cr sign decision)
157
  int64_t  ( *highPassCorrelation )( const Pel* cb, const ptrdiff_t cbStride, const Pel* cr, const ptrdiff_t crStride, const int width, const int height, const int bitDepth );
158
  // per 4x4 block of a row of numBlocks blocks: the sample sum s and the absolute deviation sum( | s - 16 * p | )
159
  void     ( *blockStats4x4 )    ( const Pel* src, const ptrdiff_t stride, const int numBlocks, const int bitDepth, int* sum, int* absDev );
160
  // sums of the absolute differences to the right, lower, lower-left and lower-right neighbours over the
161
  // ( width - 1 ) x ( height - 1 ) top-left samples: sums[0] horizontal, [1] vertical, [2] and [3] the diagonals
162
  void     ( *absGradientSums )  ( const Pel* src, const ptrdiff_t stride, const int width, const int height, int* sums );
163
  // sum( | p - value | ) over the block
164
  uint32_t ( *sumAbsDeviation )  ( const Pel* src, const ptrdiff_t stride, const int width, const int height, const int value );
165
166
private:
167
  bool isInitSIMDDone = false;
168
169
#if ENABLE_SIMD_OPT_BUFFER && defined(TARGET_SIMD_X86)
170
  void initPelBufOpsX86();
171
  template<X86_VEXT vext>
172
  void _initPelBufOpsX86();
173
#endif
174
175
#if ENABLE_SIMD_OPT_BUFFER && defined( TARGET_SIMD_ARM )
176
  void initPelBufOpsARM();
177
  template<ARM_VEXT vext>
178
  void _initPelBufOpsARM();
179
#endif
180
};
181
182
extern PelBufferOps g_pelBufOP;
183
184
// the C version of PelBufferOps::sumSquaredError, also used by the SIMD versions for the widths 1 and 3
185
uint64_t sumSquaredErrorCore( const Pel* src0, const ptrdiff_t stride0, const Pel* src1, const ptrdiff_t stride1, const int width, const int height );
186
// the C version of PelBufferOps::highPassCorrelation, also used by the SIMD versions for the last columns and for
187
// bit depths above 10
188
int64_t highPassCorrelationCore( const Pel* cb, const ptrdiff_t cbStride, const Pel* cr, const ptrdiff_t crStride, const int width, const int height, const int bitDepth );
189
// the C version of PelBufferOps::blockStats4x4, also used by the SIMD versions for the last blocks and for bit depths
190
// above 10
191
void blockStats4x4Core( const Pel* src, const ptrdiff_t stride, const int numBlocks, const int bitDepth, int* sum, int* absDev );
192
// the C version of PelBufferOps::absGradientSums, also used by the SIMD versions for narrow blocks
193
void absGradientSumsCore( const Pel* src, const ptrdiff_t stride, const int width, const int height, int* sums );
194
195
template<typename T>
196
struct AreaBuf : public Size
197
{
198
  T*        buf;
199
  int       stride;
200
  // the proper type causes awful lot of errors
201
202
14.5M
  AreaBuf()                                                                               : Size(),                  buf( NULL ), stride( 0 )          { }
vvenc::AreaBuf<short>::AreaBuf()
Line
Count
Source
202
6.70M
  AreaBuf()                                                                               : Size(),                  buf( NULL ), stride( 0 )          { }
vvenc::AreaBuf<short const>::AreaBuf()
Line
Count
Source
202
7.88M
  AreaBuf()                                                                               : Size(),                  buf( NULL ), stride( 0 )          { }
Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo>::AreaBuf()
203
9.16M
  AreaBuf( T *_buf, const Size& size )                                                    : Size( size ),            buf( _buf ), stride( size.width ) { }
vvenc::AreaBuf<short>::AreaBuf(short*, vvenc::Size const&)
Line
Count
Source
203
3.51M
  AreaBuf( T *_buf, const Size& size )                                                    : Size( size ),            buf( _buf ), stride( size.width ) { }
vvenc::AreaBuf<short const>::AreaBuf(short const*, vvenc::Size const&)
Line
Count
Source
203
2.24M
  AreaBuf( T *_buf, const Size& size )                                                    : Size( size ),            buf( _buf ), stride( size.width ) { }
vvenc::AreaBuf<vvenc::LoopFilterParam>::AreaBuf(vvenc::LoopFilterParam*, vvenc::Size const&)
Line
Count
Source
203
9.30k
  AreaBuf( T *_buf, const Size& size )                                                    : Size( size ),            buf( _buf ), stride( size.width ) { }
Unexecuted instantiation: vvenc::AreaBuf<vvenc::LoopFilterParam const>::AreaBuf(vvenc::LoopFilterParam const*, vvenc::Size const&)
vvenc::AreaBuf<int>::AreaBuf(int*, vvenc::Size const&)
Line
Count
Source
203
3.39M
  AreaBuf( T *_buf, const Size& size )                                                    : Size( size ),            buf( _buf ), stride( size.width ) { }
Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo const>::AreaBuf(vvenc::MotionInfo const*, vvenc::Size const&)
Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo>::AreaBuf(vvenc::MotionInfo*, vvenc::Size const&)
204
24.9M
  AreaBuf( T *_buf, const int& _stride, const Size& size )                                : Size( size ),            buf( _buf ), stride( _stride )    { }
vvenc::AreaBuf<short>::AreaBuf(short*, int const&, vvenc::Size const&)
Line
Count
Source
204
24.0M
  AreaBuf( T *_buf, const int& _stride, const Size& size )                                : Size( size ),            buf( _buf ), stride( _stride )    { }
vvenc::AreaBuf<short const>::AreaBuf(short const*, int const&, vvenc::Size const&)
Line
Count
Source
204
500k
  AreaBuf( T *_buf, const int& _stride, const Size& size )                                : Size( size ),            buf( _buf ), stride( _stride )    { }
vvenc::AreaBuf<vvenc::MotionInfo>::AreaBuf(vvenc::MotionInfo*, int const&, vvenc::Size const&)
Line
Count
Source
204
417k
  AreaBuf( T *_buf, const int& _stride, const Size& size )                                : Size( size ),            buf( _buf ), stride( _stride )    { }
vvenc::AreaBuf<vvenc::LoopFilterParam>::AreaBuf(vvenc::LoopFilterParam*, int const&, vvenc::Size const&)
Line
Count
Source
204
9.30k
  AreaBuf( T *_buf, const int& _stride, const Size& size )                                : Size( size ),            buf( _buf ), stride( _stride )    { }
205
1.70M
  AreaBuf( T *_buf, const SizeType& _width, const SizeType& _height )                     : Size( _width, _height ), buf( _buf ), stride( _width )     { }
vvenc::AreaBuf<short const>::AreaBuf(short const*, unsigned int const&, unsigned int const&)
Line
Count
Source
205
1.64M
  AreaBuf( T *_buf, const SizeType& _width, const SizeType& _height )                     : Size( _width, _height ), buf( _buf ), stride( _width )     { }
vvenc::AreaBuf<short>::AreaBuf(short*, unsigned int const&, unsigned int const&)
Line
Count
Source
205
56.9k
  AreaBuf( T *_buf, const SizeType& _width, const SizeType& _height )                     : Size( _width, _height ), buf( _buf ), stride( _width )     { }
206
3.37M
  AreaBuf( T *_buf, const int& _stride, const SizeType& _width, const SizeType& _height ) : Size( _width, _height ), buf( _buf ), stride( _stride )    { }
vvenc::AreaBuf<short>::AreaBuf(short*, int const&, unsigned int const&, unsigned int const&)
Line
Count
Source
206
2.81M
  AreaBuf( T *_buf, const int& _stride, const SizeType& _width, const SizeType& _height ) : Size( _width, _height ), buf( _buf ), stride( _stride )    { }
vvenc::AreaBuf<short const>::AreaBuf(short const*, int const&, unsigned int const&, unsigned int const&)
Line
Count
Source
206
558k
  AreaBuf( T *_buf, const int& _stride, const SizeType& _width, const SizeType& _height ) : Size( _width, _height ), buf( _buf ), stride( _stride )    { }
207
208
  AreaBuf( const AreaBuf& )  = default;
209
  AreaBuf(       AreaBuf&& ) = default;
210
  AreaBuf& operator=( const AreaBuf& )  = default;
211
  AreaBuf& operator=(       AreaBuf&& ) = default;
212
213
  // conversion from AreaBuf<const T> to AreaBuf<T>
214
  template<bool T_IS_CONST = std::is_const<T>::value>
215
30.3M
  AreaBuf( const AreaBuf<typename std::remove_const_t<T>>& other, std::enable_if_t<T_IS_CONST>* = 0) : Size( other ), buf( other.buf ), stride( other.stride ) { }
vvenc::AreaBuf<short const>::AreaBuf<true>(vvenc::AreaBuf<short> const&, std::__1::enable_if<true, void>::type*)
Line
Count
Source
215
26.9M
  AreaBuf( const AreaBuf<typename std::remove_const_t<T>>& other, std::enable_if_t<T_IS_CONST>* = 0) : Size( other ), buf( other.buf ), stride( other.stride ) { }
vvenc::AreaBuf<vvenc::MotionInfo const>::AreaBuf<true>(vvenc::AreaBuf<vvenc::MotionInfo> const&, std::__1::enable_if<true, void>::type*)
Line
Count
Source
215
62.4k
  AreaBuf( const AreaBuf<typename std::remove_const_t<T>>& other, std::enable_if_t<T_IS_CONST>* = 0) : Size( other ), buf( other.buf ), stride( other.stride ) { }
vvenc::AreaBuf<int const>::AreaBuf<true>(vvenc::AreaBuf<int> const&, std::__1::enable_if<true, void>::type*)
Line
Count
Source
215
3.35M
  AreaBuf( const AreaBuf<typename std::remove_const_t<T>>& other, std::enable_if_t<T_IS_CONST>* = 0) : Size( other ), buf( other.buf ), stride( other.stride ) { }
216
217
  void fill                 ( const T &val );
218
  void memset               ( const int val );
219
220
  void copyFrom             ( const AreaBuf<const T>& other );
221
  void reconstruct          ( const AreaBuf<const T>& pred, const AreaBuf<const T>& resi, const ClpRng& clpRng);
222
  void copyClip             ( const AreaBuf<const T>& src, const ClpRng& clpRng);
223
224
  void subtract             ( const AreaBuf<const T>& minuend, const AreaBuf<const T>& subtrahend );
225
  void calcVarianceSplit    ( const AreaBuf<const T>& Org, const uint32_t  size,int& varh,int& varv ) const;
226
  void extendBorderPel      ( unsigned marginX, unsigned marginY );
227
228
  void addAvg               ( const AreaBuf<const T>& other1, const AreaBuf<const T>& other2, const ClpRng& clpRng );
229
  T    getAvg               () const;
230
  void padBorderPel         ( unsigned marginX, unsigned marginY, int dir );
231
  void addWeightedAvg       ( const AreaBuf<const T>& other1, const AreaBuf<const T>& other2, const ClpRng& clpRng, const int8_t BcwIdx );
232
  void removeHighFreq       ( const AreaBuf<const T>& org, const AreaBuf<const T>& other, const bool bClip, const ClpRng& clpRng);
233
  void extendBorderPelTop   ( int x, int size, int margin );
234
  void extendBorderPelBot   ( int x, int size, int margin );
235
  void extendBorderPelLft   ( int y, int size, int margin );
236
  void extendBorderPelRgt   ( int y, int size, int margin );
237
238
  void linearTransform      ( const int scale, const unsigned shift, const int offset, bool bClip, const ClpRng& clpRng );
239
240
  void transposedFrom       ( const AreaBuf<const T>& other );
241
  void weightCiip           ( const AreaBuf<const T>& intra, const int numIntra );
242
243
  bool compare              ( const AreaBuf<const T>& other ) const;
244
245
259M
        T& at( const int& x, const int& y )          { return buf[y * stride + x]; }
vvenc::AreaBuf<short>::at(int const&, int const&)
Line
Count
Source
245
259M
        T& at( const int& x, const int& y )          { return buf[y * stride + x]; }
Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo>::at(int const&, int const&)
vvenc::AreaBuf<short const>::at(int const&, int const&)
Line
Count
Source
245
278
        T& at( const int& x, const int& y )          { return buf[y * stride + x]; }
246
147M
  const T& at( const int& x, const int& y ) const    { return buf[y * stride + x]; }
vvenc::AreaBuf<short const>::at(int const&, int const&) const
Line
Count
Source
246
147M
  const T& at( const int& x, const int& y ) const    { return buf[y * stride + x]; }
Unexecuted instantiation: vvenc::AreaBuf<short>::at(int const&, int const&) const
Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo const>::at(int const&, int const&) const
Unexecuted instantiation: vvenc::AreaBuf<int const>::at(int const&, int const&) const
247
248
2.57M
        T& at( const Position& pos )                 { return buf[pos.y * stride + pos.x]; }
Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo>::at(vvenc::Position const&)
Unexecuted instantiation: vvenc::AreaBuf<short const>::at(vvenc::Position const&)
vvenc::AreaBuf<short>::at(vvenc::Position const&)
Line
Count
Source
248
2.56M
        T& at( const Position& pos )                 { return buf[pos.y * stride + pos.x]; }
vvenc::AreaBuf<vvenc::LoopFilterParam>::at(vvenc::Position const&)
Line
Count
Source
248
9.30k
        T& at( const Position& pos )                 { return buf[pos.y * stride + pos.x]; }
249
37.2k
  const T& at( const Position& pos ) const           { return buf[pos.y * stride + pos.x]; }
vvenc::AreaBuf<short const>::at(vvenc::Position const&) const
Line
Count
Source
249
13.9k
  const T& at( const Position& pos ) const           { return buf[pos.y * stride + pos.x]; }
vvenc::AreaBuf<short>::at(vvenc::Position const&) const
Line
Count
Source
249
23.2k
  const T& at( const Position& pos ) const           { return buf[pos.y * stride + pos.x]; }
250
251
252
948k
        T* bufAt( const int& x, const int& y )       { return &at( x, y ); }
vvenc::AreaBuf<short>::bufAt(int const&, int const&)
Line
Count
Source
252
947k
        T* bufAt( const int& x, const int& y )       { return &at( x, y ); }
vvenc::AreaBuf<short const>::bufAt(int const&, int const&)
Line
Count
Source
252
278
        T* bufAt( const int& x, const int& y )       { return &at( x, y ); }
253
998k
  const T* bufAt( const int& x, const int& y ) const { return &at( x, y ); }
vvenc::AreaBuf<short const>::bufAt(int const&, int const&) const
Line
Count
Source
253
998k
  const T* bufAt( const int& x, const int& y ) const { return &at( x, y ); }
Unexecuted instantiation: vvenc::AreaBuf<short>::bufAt(int const&, int const&) const
254
255
2.57M
        T* bufAt( const Position& pos )              { return &at( pos ); }
Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo>::bufAt(vvenc::Position const&)
Unexecuted instantiation: vvenc::AreaBuf<short const>::bufAt(vvenc::Position const&)
vvenc::AreaBuf<short>::bufAt(vvenc::Position const&)
Line
Count
Source
255
2.56M
        T* bufAt( const Position& pos )              { return &at( pos ); }
vvenc::AreaBuf<vvenc::LoopFilterParam>::bufAt(vvenc::Position const&)
Line
Count
Source
255
9.30k
        T* bufAt( const Position& pos )              { return &at( pos ); }
256
37.2k
  const T* bufAt( const Position& pos ) const        { return &at( pos ); }
vvenc::AreaBuf<short const>::bufAt(vvenc::Position const&) const
Line
Count
Source
256
13.9k
  const T* bufAt( const Position& pos ) const        { return &at( pos ); }
vvenc::AreaBuf<short>::bufAt(vvenc::Position const&) const
Line
Count
Source
256
23.2k
  const T* bufAt( const Position& pos ) const        { return &at( pos ); }
257
258
  AreaBuf<      T> subBuf( const Area& area )                                                         { return AreaBuf<      T>( bufAt( area ), stride, area   ); }
259
  AreaBuf<const T> subBuf( const Area& area )                                                   const { return AreaBuf<const T>( bufAt( area ), stride, area   ); }
260
9.30k
  AreaBuf<      T> subBuf( const Position& pos, const Size& size )                                    { return AreaBuf<      T>( bufAt( pos  ), stride, size   ); }
Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo>::subBuf(vvenc::Position const&, vvenc::Size const&)
Unexecuted instantiation: vvenc::AreaBuf<short>::subBuf(vvenc::Position const&, vvenc::Size const&)
vvenc::AreaBuf<vvenc::LoopFilterParam>::subBuf(vvenc::Position const&, vvenc::Size const&)
Line
Count
Source
260
9.30k
  AreaBuf<      T> subBuf( const Position& pos, const Size& size )                                    { return AreaBuf<      T>( bufAt( pos  ), stride, size   ); }
261
13.9k
  AreaBuf<const T> subBuf( const Position& pos, const Size& size )                              const { return AreaBuf<const T>( bufAt( pos  ), stride, size   ); }
vvenc::AreaBuf<short const>::subBuf(vvenc::Position const&, vvenc::Size const&) const
Line
Count
Source
261
13.9k
  AreaBuf<const T> subBuf( const Position& pos, const Size& size )                              const { return AreaBuf<const T>( bufAt( pos  ), stride, size   ); }
Unexecuted instantiation: vvenc::AreaBuf<short>::subBuf(vvenc::Position const&, vvenc::Size const&) const
262
81.7k
  AreaBuf<      T> subBuf( const int& x, const int& y, const unsigned& _w, const unsigned& _h )       { return AreaBuf<      T>( bufAt( x, y ), stride, _w, _h ); }
vvenc::AreaBuf<short>::subBuf(int const&, int const&, unsigned int const&, unsigned int const&)
Line
Count
Source
262
81.4k
  AreaBuf<      T> subBuf( const int& x, const int& y, const unsigned& _w, const unsigned& _h )       { return AreaBuf<      T>( bufAt( x, y ), stride, _w, _h ); }
vvenc::AreaBuf<short const>::subBuf(int const&, int const&, unsigned int const&, unsigned int const&)
Line
Count
Source
262
278
  AreaBuf<      T> subBuf( const int& x, const int& y, const unsigned& _w, const unsigned& _h )       { return AreaBuf<      T>( bufAt( x, y ), stride, _w, _h ); }
263
  AreaBuf<const T> subBuf( const int& x, const int& y, const unsigned& _w, const unsigned& _h ) const { return AreaBuf<const T>( bufAt( x, y ), stride, _w, _h ); }
264
};
265
266
typedef AreaBuf<      Pel>  PelBuf;
267
typedef AreaBuf<const Pel> CPelBuf;
268
269
typedef AreaBuf<      TCoeff>  CoeffBuf;
270
typedef AreaBuf<const TCoeff> CCoeffBuf;
271
272
typedef AreaBuf<      TCoeffSig>  CoeffSigBuf;
273
typedef AreaBuf<const TCoeffSig> CCoeffSigBuf;
274
275
typedef AreaBuf<      MotionInfo>  MotionBuf;
276
typedef AreaBuf<const MotionInfo> CMotionBuf;
277
278
typedef AreaBuf<      TCoeff>  PLTescapeBuf;
279
typedef AreaBuf<const TCoeff> CPLTescapeBuf;
280
281
typedef AreaBuf<      bool>  PLTtypeBuf;
282
typedef AreaBuf<const bool> CPLTtypeBuf;
283
284
typedef AreaBuf<      LoopFilterParam>  LFPBuf;
285
typedef AreaBuf<const LoopFilterParam> CLFPBuf;
286
287
4.01M
#define SIZE_AWARE_PER_EL_OP( OP, INC )                     \
288
4.01M
if( ( width & 7 ) == 0 )                                    \
289
3.47M
{                                                           \
290
53.8M
  for( int y = 0; y < height; y++ )                         \
291
50.3M
  {                                                         \
292
206M
    for( int x = 0; x < width; x += 8 )                     \
293
156M
    {                                                       \
294
156M
      OP( x + 0 );                                          \
295
156M
      OP( x + 1 );                                          \
296
156M
      OP( x + 2 );                                          \
297
156M
      OP( x + 3 );                                          \
298
156M
      OP( x + 4 );                                          \
299
156M
      OP( x + 5 );                                          \
300
156M
      OP( x + 6 );                                          \
301
156M
      OP( x + 7 );                                          \
302
156M
    }                                                       \
303
50.3M
                                                            \
304
50.3M
    INC;                                                    \
305
50.3M
  }                                                         \
306
3.47M
}                                                           \
307
4.01M
else if( ( width & 3 ) == 0 )                               \
308
532k
{                                                           \
309
6.80M
  for( int y = 0; y < height; y++ )                         \
310
6.26M
  {                                                         \
311
12.5M
    for( int x = 0; x < width; x += 4 )                     \
312
6.26M
    {                                                       \
313
6.26M
      OP( x + 0 );                                          \
314
6.26M
      OP( x + 1 );                                          \
315
6.26M
      OP( x + 2 );                                          \
316
6.26M
      OP( x + 3 );                                          \
317
6.26M
    }                                                       \
318
6.26M
                                                            \
319
6.26M
    INC;                                                    \
320
6.26M
  }                                                         \
321
532k
}                                                           \
322
18.4E
else if( ( width & 1 ) == 0 )                               \
323
0
{                                                           \
324
0
  for( int y = 0; y < height; y++ )                         \
325
0
  {                                                         \
326
0
    for( int x = 0; x < width; x += 2 )                     \
327
0
    {                                                       \
328
0
      OP( x + 0 );                                          \
329
0
      OP( x + 1 );                                          \
330
0
    }                                                       \
331
0
                                                            \
332
0
    INC;                                                    \
333
0
  }                                                         \
334
0
}                                                           \
335
18.4E
else                                                        \
336
18.4E
{                                                           \
337
18.4E
  for( int y = 0; y < height; y++ )                         \
338
18.4E
  {                                                         \
339
0
    for( int x = 0; x < width; x++ )                        \
340
0
    {                                                       \
341
0
      OP( x );                                              \
342
0
    }                                                       \
343
0
                                                            \
344
0
    INC;                                                    \
345
0
  }                                                         \
346
18.4E
}
347
348
349
template<typename T>
350
T AreaBuf <T> ::getAvg() const
351
{
352
  const T* src = buf;
353
  int64_t  acc = 0;
354
355
#define AVG_INC      src += stride
356
#define AVG_OP(ADDR) acc += src[ADDR]
357
  SIZE_AWARE_PER_EL_OP(AVG_OP, AVG_INC);
358
#undef AVG_INC
359
#undef AVG_OP
360
361
  return T ((acc + (area() >> 1)) / area());
362
}
363
364
template<> Pel AreaBuf<Pel>::getAvg() const;
365
template<> const Pel AreaBuf<const Pel>::getAvg() const;
366
367
template<>
368
void AreaBuf<MotionInfo>::fill( const MotionInfo& val );
369
370
template<typename T>
371
void AreaBuf<T>::fill(const T &val)
372
1.88M
{
373
1.88M
  if( T( 0 ) == val )
374
1.81M
  {
375
1.81M
    GCC_WARNING_DISABLE_class_memaccess
376
1.81M
    if( width == stride )
377
1.80M
    {
378
1.80M
      ::memset( buf, 0, width * height * sizeof( T ) );
379
1.80M
    }
380
4.32k
    else
381
4.32k
    {
382
4.32k
      T* dest = buf;
383
4.32k
      size_t line = width * sizeof( T );
384
385
154k
      for( unsigned y = 0; y < height; y++ )
386
150k
      {
387
150k
        ::memset( dest, 0, line );
388
389
150k
        dest += stride;
390
150k
      }
391
4.32k
    }
392
1.81M
    GCC_WARNING_RESET
393
1.81M
  }
394
69.1k
  else
395
69.1k
  {
396
69.1k
    if( width == stride )
397
69.1k
    {
398
69.1k
      std::fill_n( buf, width * height, val );
399
69.1k
    }
400
1
    else
401
1
    {
402
1
      T* dest = buf;
403
404
1
      for( int y = 0; y < height; y++, dest += stride )
405
0
      {
406
0
        std::fill_n( dest, width, val );
407
0
      }
408
1
    }
409
69.1k
  }
410
1.88M
}
411
412
template<typename T>
413
void AreaBuf<T>::memset( const int val )
414
281k
{
415
281k
  GCC_WARNING_DISABLE_class_memaccess
416
281k
  if( width == stride )
417
274k
  {
418
274k
    ::memset( buf, val, width * height * sizeof( T ) );
419
274k
  }
420
7.13k
  else
421
7.13k
  {
422
7.13k
    T* dest = buf;
423
7.13k
    size_t line = width * sizeof( T );
424
425
164k
    for( int y = 0; y < height; y++, dest += stride )
426
157k
    {
427
157k
      ::memset( dest, val, line );
428
157k
    }
429
7.13k
  }
430
281k
  GCC_WARNING_RESET
431
281k
}
vvenc::AreaBuf<vvenc::MotionInfo>::memset(int)
Line
Count
Source
414
265k
{
415
265k
  GCC_WARNING_DISABLE_class_memaccess
416
265k
  if( width == stride )
417
265k
  {
418
265k
    ::memset( buf, val, width * height * sizeof( T ) );
419
265k
  }
420
0
  else
421
0
  {
422
0
    T* dest = buf;
423
0
    size_t line = width * sizeof( T );
424
425
0
    for( int y = 0; y < height; y++, dest += stride )
426
0
    {
427
0
      ::memset( dest, val, line );
428
0
    }
429
0
  }
430
265k
  GCC_WARNING_RESET
431
265k
}
vvenc::AreaBuf<vvenc::LoopFilterParam>::memset(int)
Line
Count
Source
414
9.30k
{
415
9.30k
  GCC_WARNING_DISABLE_class_memaccess
416
9.30k
  if( width == stride )
417
2.17k
  {
418
2.17k
    ::memset( buf, val, width * height * sizeof( T ) );
419
2.17k
  }
420
7.13k
  else
421
7.13k
  {
422
7.13k
    T* dest = buf;
423
7.13k
    size_t line = width * sizeof( T );
424
425
164k
    for( int y = 0; y < height; y++, dest += stride )
426
157k
    {
427
157k
      ::memset( dest, val, line );
428
157k
    }
429
7.13k
  }
430
9.30k
  GCC_WARNING_RESET
431
9.30k
}
vvenc::AreaBuf<short>::memset(int)
Line
Count
Source
414
6.51k
{
415
6.51k
  GCC_WARNING_DISABLE_class_memaccess
416
6.51k
  if( width == stride )
417
6.51k
  {
418
6.51k
    ::memset( buf, val, width * height * sizeof( T ) );
419
6.51k
  }
420
0
  else
421
0
  {
422
0
    T* dest = buf;
423
0
    size_t line = width * sizeof( T );
424
425
0
    for( int y = 0; y < height; y++, dest += stride )
426
0
    {
427
0
      ::memset( dest, val, line );
428
0
    }
429
0
  }
430
6.51k
  GCC_WARNING_RESET
431
6.51k
}
432
433
template<typename T>
434
void AreaBuf<T>::copyFrom( const AreaBuf<const T>& other )
435
10.4M
{
436
#if !defined(__GNUC__) || __GNUC__ > 5
437
  static_assert( std::is_trivially_copyable<T>::value, "Type T is not trivially_copyable" );
438
#endif
439
440
10.4M
  g_pelBufOP.copyBuffer( ( const char* ) other.buf, other.stride * sizeof( T ), ( char* ) buf, stride * sizeof( T ), width * sizeof( T ), height );
441
10.4M
}
vvenc::AreaBuf<short>::copyFrom(vvenc::AreaBuf<short const> const&)
Line
Count
Source
435
10.4M
{
436
#if !defined(__GNUC__) || __GNUC__ > 5
437
  static_assert( std::is_trivially_copyable<T>::value, "Type T is not trivially_copyable" );
438
#endif
439
440
10.4M
  g_pelBufOP.copyBuffer( ( const char* ) other.buf, other.stride * sizeof( T ), ( char* ) buf, stride * sizeof( T ), width * sizeof( T ), height );
441
10.4M
}
vvenc::AreaBuf<vvenc::MotionInfo>::copyFrom(vvenc::AreaBuf<vvenc::MotionInfo const> const&)
Line
Count
Source
435
62.4k
{
436
#if !defined(__GNUC__) || __GNUC__ > 5
437
  static_assert( std::is_trivially_copyable<T>::value, "Type T is not trivially_copyable" );
438
#endif
439
440
62.4k
  g_pelBufOP.copyBuffer( ( const char* ) other.buf, other.stride * sizeof( T ), ( char* ) buf, stride * sizeof( T ), width * sizeof( T ), height );
441
62.4k
}
442
443
template<typename T>
444
void AreaBuf<T>::subtract( const AreaBuf<const T>& minuend, const AreaBuf<const T>& subtrahend )
445
{
446
  THROW( "Type not supported" );
447
}
448
449
template<>
450
void AreaBuf<Pel>::subtract( const AreaBuf<const Pel>& minuend, const AreaBuf<const Pel>& subtrahend );
451
452
template<typename T>
453
void AreaBuf<T>::calcVarianceSplit( const AreaBuf<const T>& Org, const uint32_t  size,int& varh,int& varv ) const 
454
{
455
  THROW( "Type not supported" );
456
}
457
458
template<>
459
void AreaBuf<const Pel>::calcVarianceSplit( const AreaBuf<const Pel>& Org, const uint32_t  size, int& varh,int&varv ) const;
460
461
template<typename T>
462
void AreaBuf<T>::copyClip( const AreaBuf<const T>& src, const ClpRng& clpRng )
463
{
464
  THROW( "Type not supported" );
465
}
466
467
template<>
468
void AreaBuf<Pel>::copyClip( const AreaBuf<const Pel>& src, const ClpRng& clpRng );
469
470
template<typename T>
471
void AreaBuf<T>::reconstruct( const AreaBuf<const T>& pred, const AreaBuf<const T>& resi, const ClpRng& clpRng )
472
{
473
  THROW( "Type not supported" );
474
}
475
476
template<>
477
void AreaBuf<Pel>::reconstruct( const AreaBuf<const Pel>& pred, const AreaBuf<const Pel>& resi, const ClpRng& clpRng );
478
479
template<typename T>
480
void AreaBuf<T>::addAvg( const AreaBuf<const T>& other1, const AreaBuf<const T>& other2, const ClpRng& clpRng )
481
{
482
  THROW( "Type not supported" );
483
}
484
485
template<>
486
void AreaBuf<Pel>::addAvg( const AreaBuf<const Pel>& other1, const AreaBuf<const Pel>& other2, const ClpRng& clpRng );
487
488
template<typename T>
489
void AreaBuf<T>::linearTransform( const int scale, const unsigned shift, const int offset, bool bClip, const ClpRng& clpRng )
490
{
491
  THROW( "Type not supported" );
492
}
493
494
template<>
495
void AreaBuf<Pel>::linearTransform( const int scale, const unsigned shift, const int offset, bool bClip, const ClpRng& clpRng );
496
497
template<typename T>
498
void AreaBuf<T>::removeHighFreq( const AreaBuf<const T>& org, const AreaBuf<const T>& other, const bool bClip, const ClpRng& clpRng )
499
0
{
500
0
  const T*  src       = other.buf;
501
0
  const int srcStride = other.stride;
502
0
  const T*  orgBuf    = org.buf;
503
0
  const int orgStride = org.stride;
504
505
0
        T*  dst       = buf;
506
0
  const int dstStride = stride;
507
508
0
#if ENABLE_SIMD_OPT_BCW
509
0
  if (!bClip)
510
0
  {
511
0
    if(!(width & 7))
512
0
      g_pelBufOP.removeHighFreq8(dst, dstStride, orgBuf, orgStride, src, srcStride, width, height);
513
0
    else if (!(width & 3))
514
0
      g_pelBufOP.removeHighFreq4(dst, dstStride, orgBuf, orgStride, src, srcStride, width, height);
515
0
    else
516
0
      CHECK(true, "Not supported");
517
0
  }
518
0
  else
519
0
  {
520
0
#endif
521
522
0
#define REM_HF_INC  \
523
0
  src += srcStride; \
524
0
  orgBuf += orgStride; \
525
0
  dst += dstStride; \
526
0
527
0
#define REM_HF_OP_CLIP( ADDR ) dst[ADDR] = ClipPel<T>( 2 * orgBuf[ADDR] - src[ADDR], clpRng )
528
0
#define REM_HF_OP( ADDR )      dst[ADDR] =             2 * orgBuf[ADDR] - src[ADDR]
529
530
0
  if( bClip )
531
0
  {
532
0
    SIZE_AWARE_PER_EL_OP( REM_HF_OP_CLIP, REM_HF_INC );
533
0
  }
534
0
  else
535
0
  {
536
0
    SIZE_AWARE_PER_EL_OP( REM_HF_OP,      REM_HF_INC );
537
0
  }
538
539
0
#undef REM_HF_INC
540
0
#undef REM_HF_OP
541
0
#undef REM_HF_OP_CLIP
542
543
0
#if ENABLE_SIMD_OPT_BCW
544
0
  }
545
0
#endif
546
0
}
547
548
549
template<typename T>
550
void AreaBuf<T>::extendBorderPelLft( int y, int size, int margin )
551
{
552
  T* p = buf + y * stride;
553
  int h = size + y;
554
555
  // do left and right margins
556
  for (; y < h; y++)
557
  {
558
    for (int x = 0; x < margin; x++)
559
    {
560
      *(p - margin + x) = p[0];
561
    }
562
    p += stride;
563
  }
564
}
565
566
template<typename T>
567
void AreaBuf<T>::extendBorderPelTop( int x, int size, int margin )
568
11.7k
{
569
11.7k
  T* p = buf + x;
570
571
  // p is now (-marginX, 0)
572
444k
  for (int y = 0; y < margin; y++)
573
432k
  {
574
432k
    ::memcpy(p - (y + 1) * stride, p, sizeof(T) * size);
575
432k
  }
576
11.7k
}
577
578
template<typename T>
579
void AreaBuf<T>::extendBorderPelRgt( int y, int size, int margin )
580
{
581
  T* p = buf + y * stride;
582
  int h = size + y;
583
584
  // do left and right margins
585
  for( ; y < h; y++)
586
  {
587
    for (int x = 0; x < margin; x++)
588
    {
589
      p[width + x] = p[width - 1];
590
    }
591
    p += stride;
592
  }
593
}
594
595
template<typename T>
596
void AreaBuf<T>::extendBorderPelBot( int x, int size, int margin )
597
11.7k
{
598
11.7k
  T* p = buf + (height-1)*stride + x;
599
600
  // p is now the (-margin, height-1)
601
444k
  for (int y = 0; y < margin; y++)
602
432k
  {
603
432k
    ::memcpy(p + (y + 1) * stride, p, sizeof(T) * size);
604
432k
  }
605
11.7k
}
606
607
template<typename T>
608
void AreaBuf<T>::extendBorderPel(unsigned marginX, unsigned marginY)
609
{
610
  T* p = buf;
611
  int h = height;
612
  int w = width;
613
  int s = stride;
614
615
  CHECK((w + 2 * marginX) > s, "Size of buffer too small to extend");
616
  // do left and right margins
617
  for (int y = 0; y < h; y++)
618
  {
619
    for (int x = 0; x < marginX; x++)
620
    {
621
      *(p - marginX + x) = p[0];
622
      p[w + x] = p[w - 1];
623
    }
624
    p += s;
625
  }
626
627
  // p is now the (0,height) (bottom left of image within bigger picture
628
  p -= (s + marginX);
629
  // p is now the (-margin, height-1)
630
  for (int y = 0; y < marginY; y++)
631
  {
632
    ::memcpy(p + (y + 1) * s, p, sizeof(T) * (w + (marginX << 1)));
633
  }
634
635
  // p is still (-marginX, height-1)
636
  p -= ((h - 1) * s);
637
  // p is now (-marginX, 0)
638
  for (int y = 0; y < marginY; y++)
639
  {
640
    ::memcpy(p - (y + 1) * s, p, sizeof(T) * (w + (marginX << 1)));
641
  }
642
}
643
644
template<> void AreaBuf<Pel>::extendBorderPelLft( int y, int size, int margin );
645
template<> void AreaBuf<Pel>::extendBorderPelRgt( int y, int size, int margin );
646
template<> void AreaBuf<Pel>::extendBorderPel( unsigned marginX, unsigned marginY );
647
648
template<typename T>
649
void AreaBuf<T>::padBorderPel( unsigned marginX, unsigned marginY, int dir )
650
0
{
651
0
  T*  p = buf;
652
0
  int s = stride;
653
0
  int h = height;
654
0
  int w = width;
655
656
0
  CHECK( w  > s, "Size of buffer too small to extend" );
657
658
  // top-left margin
659
0
  if ( dir == 1 )
660
0
  {
661
0
    for( int y = 0; y < marginY; y++ )
662
0
    {
663
0
      for( int x = 0; x < marginX; x++ )
664
0
      {
665
0
        p[x] = p[marginX];
666
0
      }
667
0
      p += s;
668
0
    }
669
0
  }
670
671
  // bottom-right margin
672
0
  if ( dir == 2 )
673
0
  {
674
0
    p = buf + s * ( h - marginY ) + w - marginX;
675
676
0
    for( int y = 0; y < marginY; y++ )
677
0
    {
678
0
      for( int x = 0; x < marginX; x++ )
679
0
      {
680
0
        p[x] = p[-1];
681
0
      }
682
0
      p += s;
683
0
    }
684
0
  }
685
0
}
686
687
688
#if ENABLE_SIMD_OPT_BUFFER
689
template<> void AreaBuf<Pel>::transposedFrom( const AreaBuf<const Pel>& other );
690
#endif
691
692
template<typename T>
693
void AreaBuf<T>::transposedFrom( const AreaBuf<const T>& other )
694
{
695
  CHECK( width * height != other.width * other.height, "Incompatible size" );
696
697
        T* dst  =       buf;
698
  const T* src  = other.buf;
699
  width         = other.height;
700
  height        = other.width;
701
  stride        = stride < width ? width : stride;
702
703
  for( unsigned y = 0; y < other.height; y++ )
704
  {
705
    for( unsigned x = 0; x < other.width; x++ )
706
    {
707
      dst[y + x*stride] = src[x + y*other.stride];
708
    }
709
  }
710
}
711
712
template<typename T>
713
bool AreaBuf <T> ::compare( const AreaBuf<const T>& other ) const
714
{
715
        T* mine   =       buf;
716
  const T* theirs = other.buf;
717
  if( width != other.width) return false;
718
  if( height != other.height) return false;
719
720
  for( unsigned y = 0; y < other.height; y++ )
721
  {
722
    for( unsigned x = 0; x < other.width; x++ )
723
    {
724
      if( mine[x + y*stride] != theirs[x+y*other.stride])
725
      {
726
        return false;
727
      }
728
    }
729
  }
730
  return true;
731
}
732
733
#ifndef DONT_UNDEF_SIZE_AWARE_PER_EL_OP
734
#undef SIZE_AWARE_PER_EL_OP
735
#endif // !DONT_UNDEF_SIZE_AWARE_PER_EL_OP
736
737
// ---------------------------------------------------------------------------
738
// UnitBuf struct
739
// ---------------------------------------------------------------------------
740
741
struct UnitArea;
742
743
template<typename T>
744
struct UnitBuf
745
{
746
  typedef static_vector<AreaBuf<T>,       MAX_NUM_COMP> UnitBufBuffers;
747
  typedef static_vector<AreaBuf<const T>, MAX_NUM_COMP> ConstUnitBufBuffers;
748
749
  ChromaFormat chromaFormat;
750
  UnitBufBuffers bufs;
751
752
1.31M
  UnitBuf() : chromaFormat( NUM_CHROMA_FORMAT ) { }
vvenc::UnitBuf<short>::UnitBuf()
Line
Count
Source
752
1.31M
  UnitBuf() : chromaFormat( NUM_CHROMA_FORMAT ) { }
Unexecuted instantiation: vvenc::UnitBuf<short const>::UnitBuf()
753
  UnitBuf( const ChromaFormat _chromaFormat, const UnitBufBuffers&  _bufs ) : chromaFormat( _chromaFormat ), bufs( _bufs ) { }
754
  UnitBuf( const ChromaFormat _chromaFormat,       UnitBufBuffers&& _bufs ) : chromaFormat( _chromaFormat ), bufs( std::forward<UnitBufBuffers>( _bufs ) ) { }
755
0
  UnitBuf( const ChromaFormat _chromaFormat, const AreaBuf<T>&  blkY )      : chromaFormat( _chromaFormat ), bufs{ blkY } { }
756
0
  UnitBuf( const ChromaFormat _chromaFormat,       AreaBuf<T>&& blkY )      : chromaFormat( _chromaFormat ), bufs{ std::forward<AreaBuf<T> >(blkY) } { }
Unexecuted instantiation: vvenc::UnitBuf<short>::UnitBuf(vvencChromaFormat, vvenc::AreaBuf<short>&&)
Unexecuted instantiation: vvenc::UnitBuf<short const>::UnitBuf(vvencChromaFormat, vvenc::AreaBuf<short const>&&)
757
191k
  UnitBuf( const ChromaFormat _chromaFormat, const AreaBuf<T>&  blkY, const AreaBuf<T>&  blkCb, const AreaBuf<T>  &blkCr ) : chromaFormat( _chromaFormat ), bufs{ blkY, blkCb, blkCr } { }
758
543k
  UnitBuf( const ChromaFormat _chromaFormat,       AreaBuf<T>&& blkY,       AreaBuf<T>&& blkCb,       AreaBuf<T> &&blkCr ) : chromaFormat( _chromaFormat ), bufs{ std::forward<AreaBuf<T> >(blkY), std::forward<AreaBuf<T> >(blkCb), std::forward<AreaBuf<T> >(blkCr) } { }
vvenc::UnitBuf<short>::UnitBuf(vvencChromaFormat, vvenc::AreaBuf<short>&&, vvenc::AreaBuf<short>&&, vvenc::AreaBuf<short>&&)
Line
Count
Source
758
543k
  UnitBuf( const ChromaFormat _chromaFormat,       AreaBuf<T>&& blkY,       AreaBuf<T>&& blkCb,       AreaBuf<T> &&blkCr ) : chromaFormat( _chromaFormat ), bufs{ std::forward<AreaBuf<T> >(blkY), std::forward<AreaBuf<T> >(blkCb), std::forward<AreaBuf<T> >(blkCr) } { }
Unexecuted instantiation: vvenc::UnitBuf<short const>::UnitBuf(vvencChromaFormat, vvenc::AreaBuf<short const>&&, vvenc::AreaBuf<short const>&&, vvenc::AreaBuf<short const>&&)
759
760
59.8k
  UnitBuf( const UnitBuf& other )  = default;
761
  UnitBuf(       UnitBuf&& other ) = default;
762
  UnitBuf& operator=( const UnitBuf& other )  = default;
763
  UnitBuf& operator=(       UnitBuf&& other ) = default;
764
765
  // conversion from UnitBuf<const T> to UnitBuf<T>
766
  template<bool T_IS_COST = std::is_const<T>::value>
767
13.6k
  UnitBuf( const UnitBuf<typename std::remove_const<T>::type>& other, std::enable_if<T_IS_COST>* = 0 ) : chromaFormat( other.chromaFormat ), bufs( other.bufs.begin(), other.bufs.end() ) { }
768
769
10.0M
        AreaBuf<T>& get( const ComponentID comp )        { return bufs[comp]; }
770
83.1k
  const AreaBuf<T>& get( const ComponentID comp )  const { return bufs[comp]; }
vvenc::UnitBuf<short>::get(vvenc::ComponentID) const
Line
Count
Source
770
74.4k
  const AreaBuf<T>& get( const ComponentID comp )  const { return bufs[comp]; }
vvenc::UnitBuf<short const>::get(vvenc::ComponentID) const
Line
Count
Source
770
8.64k
  const AreaBuf<T>& get( const ComponentID comp )  const { return bufs[comp]; }
771
772
1.94M
        AreaBuf<T>& Y()        { return bufs[0]; }
vvenc::UnitBuf<short>::Y()
Line
Count
Source
772
1.94M
        AreaBuf<T>& Y()        { return bufs[0]; }
Unexecuted instantiation: vvenc::UnitBuf<short const>::Y()
773
0
  const AreaBuf<T>& Y()  const { return bufs[0]; }
774
679k
        AreaBuf<T>& Cb()       { return bufs[1]; }
775
  const AreaBuf<T>& Cb() const { return bufs[1]; }
776
679k
        AreaBuf<T>& Cr()       { return bufs[2]; }
777
  const AreaBuf<T>& Cr() const { return bufs[2]; }
778
213k
  bool valid          () const { return bufs.size() != 0; }
779
780
  void fill                 ( const T& val );
781
  // the sources are templates so that a UnitBuf<T> needs no conversion to a UnitBuf<const T> temporary
782
  template<typename U>
783
  void copyFrom             ( const UnitBuf<U> &other, const bool luma = true, const bool chroma = true );
784
  void reconstruct          ( const UnitBuf<const T>& pred, const UnitBuf<const T>& resi, const ClpRngs& clpRngs );
785
  template<typename U>
786
  void copyClip             ( const UnitBuf<U> &src, const ClpRngs& clpRngs, const bool lumaOnly = false, const bool chromaOnly = false );
787
  void subtract             ( const UnitBuf<const T>& minuend, const UnitBuf<const T>& subtrahend );
788
  template<typename U, typename V>
789
  void addAvg               ( const UnitBuf<U>& other1, const UnitBuf<V>& other2, const ClpRngs& clpRngs, const bool chromaOnly = false, const bool lumaOnly = false);
790
  template<typename U, typename V>
791
  void addWeightedAvg       ( const UnitBuf<U>& other1, const UnitBuf<V>& other2, const ClpRngs& clpRngs, const uint8_t BcwIdx = BCW_DEFAULT, const bool chromaOnly = false, const bool lumaOnly = false);
792
  void padBorderPel         ( unsigned margin, int dir );
793
  void extendBorderPel      ( unsigned margin, bool scale = false);
794
  void extendBorderPelTop   ( int x, int size, int margin );
795
  void extendBorderPelBot   ( int x, int size, int margin );
796
  void extendBorderPelLft   ( int y, int size, int margin );
797
  void extendBorderPelRgt   ( int y, int size, int margin );
798
799
  template<typename U, typename V>
800
  void removeHighFreq       ( const UnitBuf<U>& org, const UnitBuf<V>& other, const bool bClip, const ClpRngs& clpRngs);
801
802
        UnitBuf<      T> subBuf (const UnitArea& subArea);
803
  const UnitBuf<const T> subBuf (const UnitArea& subArea) const;
804
};
805
806
typedef UnitBuf<      Pel>  PelUnitBuf;
807
typedef UnitBuf<const Pel> CPelUnitBuf;
808
809
typedef UnitBuf<      TCoeff>  CoeffUnitBuf;
810
typedef UnitBuf<const TCoeff> CCoeffUnitBuf;
811
812
template<typename T>
813
void UnitBuf<T>::fill( const T &val )
814
0
{
815
0
  for( int i = 0; i < bufs.size(); i++ )
816
0
  {
817
0
    bufs[i].fill( val );
818
0
  }
819
0
}
820
821
822
template<typename T>
823
template<typename U>
824
void UnitBuf<T>::copyFrom(const UnitBuf<U> &other, const bool luma, const bool chroma)
825
530k
{
826
530k
  CHECK( chromaFormat != other.chromaFormat, "Incompatible formats" );
827
530k
  CHECK( !luma && !chroma, "At least one channel has to be selected" );
828
829
530k
  const size_t compStart = luma   ? 0           : 1;
830
530k
  const size_t compEnd   = chroma ? bufs.size() : 1;
831
832
2.06M
  for( size_t i = compStart; i < compEnd; i++ )
833
1.53M
  {
834
1.53M
    if( bufs[ i ].buf != nullptr && other.bufs[ i ].buf != nullptr )
835
1.04M
      bufs[i].copyFrom( other.bufs[i] );
836
1.53M
  }
837
530k
}
void vvenc::UnitBuf<short>::copyFrom<short>(vvenc::UnitBuf<short> const&, bool, bool)
Line
Count
Source
825
200k
{
826
200k
  CHECK( chromaFormat != other.chromaFormat, "Incompatible formats" );
827
200k
  CHECK( !luma && !chroma, "At least one channel has to be selected" );
828
829
200k
  const size_t compStart = luma   ? 0           : 1;
830
200k
  const size_t compEnd   = chroma ? bufs.size() : 1;
831
832
749k
  for( size_t i = compStart; i < compEnd; i++ )
833
548k
  {
834
548k
    if( bufs[ i ].buf != nullptr && other.bufs[ i ].buf != nullptr )
835
548k
      bufs[i].copyFrom( other.bufs[i] );
836
548k
  }
837
200k
}
void vvenc::UnitBuf<short>::copyFrom<short const>(vvenc::UnitBuf<short const> const&, bool, bool)
Line
Count
Source
825
330k
{
826
330k
  CHECK( chromaFormat != other.chromaFormat, "Incompatible formats" );
827
330k
  CHECK( !luma && !chroma, "At least one channel has to be selected" );
828
829
330k
  const size_t compStart = luma   ? 0           : 1;
830
18.4E
  const size_t compEnd   = chroma ? bufs.size() : 1;
831
832
1.32M
  for( size_t i = compStart; i < compEnd; i++ )
833
990k
  {
834
990k
    if( bufs[ i ].buf != nullptr && other.bufs[ i ].buf != nullptr )
835
493k
      bufs[i].copyFrom( other.bufs[i] );
836
990k
  }
837
330k
}
838
839
template<typename T>
840
void UnitBuf<T>::subtract( const UnitBuf<const T>& minuend, const UnitBuf<const T>& subtrahend )
841
{
842
  CHECK( chromaFormat != minuend.chromaFormat, "Incompatible formats" );
843
  CHECK( chromaFormat != subtrahend.chromaFormat, "Incompatible formats");
844
845
  for( int i = 0; i < bufs.size(); i++ )
846
  {
847
    bufs[i].subtract( minuend.bufs[i], subtrahend.bufs[i] );
848
  }
849
}
850
851
template<typename T>
852
template<typename U>
853
void UnitBuf<T>::copyClip(const UnitBuf<U> &src, const ClpRngs &clpRngs, const bool lumaOnly, const bool chromaOnly)
854
0
{
855
0
  CHECK( chromaFormat != src.chromaFormat, "Incompatible formats" );
856
857
0
  CHECK(lumaOnly && chromaOnly, "Not allowed to have both lumaOnly and chromaOnly selected");
858
0
  const int compStart = chromaOnly ? 1 : 0;
859
0
  const int compEnd   = lumaOnly   ? 1 : ( int ) bufs.size();
860
0
  for( int i = compStart; i < compEnd; i++ )
861
0
  {
862
0
    bufs[i].copyClip( src.bufs[i], clpRngs[i] );
863
0
  }
864
0
}
865
866
template<typename T>
867
void UnitBuf<T>::reconstruct(const UnitBuf<const T>& pred, const UnitBuf<const T>& resi, const ClpRngs& clpRngs)
868
0
{
869
0
  CHECK( chromaFormat != pred.chromaFormat, "Incompatible formats" );
870
0
  CHECK( chromaFormat != resi.chromaFormat, "Incompatible formats" );
871
872
0
  for( int i = 0; i < bufs.size(); i++ )
873
0
  {
874
0
    bufs[i].reconstruct( pred.bufs[i], resi.bufs[i], clpRngs[i] );
875
0
  }
876
0
}
877
878
template<typename T>
879
template<typename U, typename V>
880
void UnitBuf<T>::addAvg(const UnitBuf<U>& other1, const UnitBuf<V>& other2, const ClpRngs& clpRngs, const bool chromaOnly /* = false */, const bool lumaOnly /* = false */)
881
0
{
882
0
  const int istart = chromaOnly ? 1 : 0;
883
0
  const int iend   = lumaOnly   ? 1 : ( int ) bufs.size();
884
885
0
  CHECK( lumaOnly && chromaOnly, "should not happen" );
886
887
0
  for( int i = istart; i < iend; i++)
888
0
  {
889
0
    bufs[i].addAvg( other1.bufs[i], other2.bufs[i], clpRngs[i]);
890
0
  }
891
0
}
892
893
template<typename T>
894
template<typename U, typename V>
895
void UnitBuf<T>::addWeightedAvg(const UnitBuf<U>& other1, const UnitBuf<V>& other2, const ClpRngs& clpRngs, const uint8_t BcwIdx /* = BCW_DEFAULT */, const bool chromaOnly /* = false */, const bool lumaOnly /* = false */)
896
0
{
897
0
  const int istart = chromaOnly ? 1 : 0;
898
0
  const int iend   = lumaOnly   ? 1 : ( int ) bufs.size();
899
900
0
  CHECK( lumaOnly && chromaOnly, "should not happen" );
901
902
0
  for ( int i = istart; i < iend; i++)
903
0
  {
904
0
    bufs[i].addWeightedAvg(other1.bufs[i], other2.bufs[i], clpRngs[i], BcwIdx);
905
0
  }
906
0
}
907
908
template<typename T>
909
void UnitBuf<T>::extendBorderPelTop   ( int x, int size, int margin )
910
3.92k
{
911
15.7k
  for( int i = 0; i < bufs.size(); i++ )
912
11.7k
  {
913
11.7k
    int csx = getComponentScaleX(ComponentID(i), chromaFormat);
914
11.7k
    int csy = getComponentScaleY(ComponentID(i), chromaFormat);
915
11.7k
    bufs[i].extendBorderPelTop( x>>csx, size>>csx, margin>>csy );
916
11.7k
  }
917
3.92k
}
918
919
template<typename T>
920
void UnitBuf<T>::extendBorderPelBot   ( int x, int size, int margin )
921
3.92k
{
922
15.7k
  for( int i = 0; i < bufs.size(); i++ )
923
11.7k
  {
924
11.7k
    int csx = getComponentScaleX(ComponentID(i), chromaFormat);
925
11.7k
    int csy = getComponentScaleY(ComponentID(i), chromaFormat);
926
11.7k
    bufs[i].extendBorderPelBot( x>>csx, size>>csx, margin>>csy );
927
11.7k
  }
928
3.92k
}
929
930
template<typename T>
931
void UnitBuf<T>::extendBorderPelLft   ( int y, int size, int margin )
932
5.11k
{
933
20.4k
  for( int i = 0; i < bufs.size(); i++ )
934
15.3k
  {
935
15.3k
    int csx = getComponentScaleX(ComponentID(i), chromaFormat);
936
15.3k
    int csy = getComponentScaleY(ComponentID(i), chromaFormat);
937
15.3k
    bufs[i].extendBorderPelLft( y>>csy, size>>csy, margin>>csx );
938
15.3k
  }
939
5.11k
}
940
941
template<typename T>
942
void UnitBuf<T>::extendBorderPelRgt   ( int y, int size, int margin )
943
5.11k
{
944
20.4k
  for( int i = 0; i < bufs.size(); i++ )
945
15.3k
  {
946
15.3k
    int csx = getComponentScaleX(ComponentID(i), chromaFormat);
947
15.3k
    int csy = getComponentScaleY(ComponentID(i), chromaFormat);
948
15.3k
    bufs[i].extendBorderPelRgt( y>>csy, size>>csy, margin>>csx );
949
15.3k
  }
950
5.11k
}
951
952
template<typename T>
953
void UnitBuf<T>::extendBorderPel( unsigned margin, bool scaleMargin )
954
1.43k
{
955
1.43k
  if( ! scaleMargin )
956
0
  {
957
0
    for( int i = 0; i < bufs.size(); i++ )
958
0
    {
959
0
      bufs[i].extendBorderPel( margin, margin );
960
0
    }
961
0
  }
962
1.43k
  else
963
1.43k
  {
964
5.72k
    for ( int i = 0; i < bufs.size(); i++)
965
4.29k
    {
966
4.29k
      bufs[i].extendBorderPel(margin >> getComponentScaleX(ComponentID(i), chromaFormat), margin >> getComponentScaleY(ComponentID(i), chromaFormat));
967
4.29k
    }
968
1.43k
  }
969
1.43k
}
970
971
template<typename T>
972
void UnitBuf<T>::padBorderPel( unsigned margin, int dir )
973
0
{
974
0
  for( int i = 0; i < bufs.size(); i++ )
975
0
  {
976
0
    bufs[i].padBorderPel( margin >> getComponentScaleX( ComponentID( i ), chromaFormat ), margin >> getComponentScaleY( ComponentID( i ), chromaFormat ), dir );
977
0
  }
978
0
}
979
980
template<typename T>
981
template<typename U, typename V>
982
void UnitBuf<T>::removeHighFreq( const UnitBuf<U>& org, const UnitBuf<V>& other, const bool bClip, const ClpRngs& clpRngs)
983
0
{
984
0
  bufs[0].removeHighFreq(org.bufs[0], other.bufs[0], bClip, clpRngs[0]);
985
0
}
986
987
template<typename T>
988
UnitBuf<T> UnitBuf<T>::subBuf( const UnitArea& subArea )
989
0
{
990
0
  UnitBuf<T> subBuf;
991
0
  subBuf.chromaFormat = chromaFormat;
992
0
  unsigned blockIdx = 0;
993
994
0
  for( auto &subAreaBuf : bufs )
995
0
  {
996
0
    subBuf.bufs.push_back( subAreaBuf.subBuf( subArea.blocks[blockIdx].pos(), subArea.blocks[blockIdx].size() ) );
997
0
    blockIdx++;
998
0
  }
999
1000
0
  return subBuf;
1001
0
}
1002
1003
1004
template<typename T>
1005
const UnitBuf<const T> UnitBuf<T>::subBuf( const UnitArea& subArea ) const
1006
0
{
1007
0
  UnitBuf<const T> subBuf;
1008
0
  subBuf.chromaFormat = chromaFormat;
1009
0
  unsigned blockIdx = 0;
1010
1011
0
  for( const auto &subAreaBuf : bufs )
1012
0
  {
1013
0
    subBuf.bufs.push_back( subAreaBuf.subBuf( subArea.blocks[blockIdx].pos(), subArea.blocks[blockIdx].size() ) );
1014
0
    blockIdx++;
1015
0
  }
1016
1017
0
  return subBuf;
1018
0
}
1019
1020
// ---------------------------------------------------------------------------
1021
// PelStorage struct (PelUnitBuf which allocates its own memory)
1022
// ---------------------------------------------------------------------------
1023
1024
struct UnitArea;
1025
struct CompArea;
1026
1027
struct PelStorage : public PelUnitBuf
1028
{
1029
  PelStorage();
1030
  ~PelStorage();
1031
1032
  void swap( PelStorage& other );
1033
  void createFromBuf( PelUnitBuf buf );
1034
  void takeOwnership( PelStorage& other );
1035
  void create( const UnitArea& _unit );
1036
  void create( const ChromaFormat &_chromaFormat, const Area& _area );
1037
  void create( const ChromaFormat &_chromaFormat, const Area& _area, const unsigned _maxCUSize, const unsigned _margin = 0, const unsigned _alignment = 0, const bool _scaleChromaMargin = true );
1038
  void destroy();
1039
  void compactResize( const UnitArea& area );
1040
1041
         PelBuf getBuf( const CompArea& blk );
1042
  const CPelBuf getBuf( const CompArea& blk ) const;
1043
1044
         PelBuf getBuf( const ComponentID CompID );
1045
  const CPelBuf getBuf( const ComponentID CompID ) const;
1046
1047
         PelUnitBuf getBuf( const UnitArea& unit );
1048
  const CPelUnitBuf getBuf( const UnitArea& unit ) const;
1049
17.1k
               Pel* getOrigin( const int id ) const { return m_origin[id]; }
1050
1051
         PelUnitBuf getBuf(const int strY, const int strCb, const int strCr, const UnitArea& unit);
1052
  const CPelUnitBuf getBuf(const int strY, const int strCb, const int strCr, const UnitArea& unit) const;
1053
1054
         PelUnitBuf getBufPart( const UnitArea& unit );
1055
  const CPelUnitBuf getBufPart( const UnitArea& unit ) const;
1056
1057
         PelUnitBuf getCompactBuf(const UnitArea& unit);
1058
  const CPelUnitBuf getCompactBuf(const UnitArea& unit) const;
1059
1060
         PelBuf     getCompactBuf(const CompArea& blk);
1061
  const CPelBuf     getCompactBuf(const CompArea& blk) const;
1062
1063
private:
1064
1065
  UnitArea m_maxArea;
1066
  Pel* m_origin[MAX_NUM_COMP];
1067
};
1068
1069
struct CompStorage : public PelBuf
1070
{
1071
103k
  ~CompStorage() { if( valid() ) delete[] m_memory; }
1072
1073
  void compactResize( const Size& size )
1074
3.37M
  {
1075
3.37M
    CHECK( size.area() > m_allocSize, "Resizing causes buffer overflow!" );
1076
3.37M
    Size::operator=( size );
1077
3.37M
    stride = size.width;
1078
3.37M
  }
1079
  void create( const Size& size )
1080
103k
  {
1081
103k
    CHECK( m_memory, "Trying to re-create an already initialized buffer" );
1082
103k
    m_allocSize = size.area();
1083
103k
    m_memory = new Pel[m_allocSize];
1084
103k
    PelBuf::operator=( PelBuf( m_memory, size ) );
1085
103k
  }
1086
  void destroy()
1087
0
  {
1088
0
    if( valid() ) delete[] m_memory;
1089
0
    m_memory    = nullptr;
1090
0
    m_allocSize = 0;
1091
0
  }
1092
348k
  bool valid() { return m_memory != nullptr; }
1093
private:
1094
  ptrdiff_t m_allocSize = 0;
1095
  Pel*      m_memory    = nullptr;
1096
};
1097
1098
template<int NumEntries>
1099
struct SortedPelUnitBufs
1100
{
1101
  void create(ChromaFormat cform, int maxWidth, int maxHeight)
1102
5.72k
  {
1103
5.72k
    m_pacBufs.resize(NumEntries + 1);
1104
5.72k
    m_acStorage.resize(NumEntries + 1);
1105
63.0k
    for (size_t i = 0; i <= NumEntries; i++)
1106
57.2k
    {
1107
57.2k
      m_acStorage[i].create(cform, Area(0, 0, maxWidth, maxHeight));
1108
57.2k
    }
1109
5.72k
  }
1110
1111
  void destroy()
1112
5.72k
  {
1113
63.0k
    for (size_t i = 0; i <= NumEntries; i++)
1114
57.2k
    {
1115
57.2k
      m_acStorage[i].destroy();
1116
57.2k
    }
1117
5.72k
  }
1118
1119
  void reset()
1120
  {
1121
    m_sortedList.clear();
1122
  }
1123
1124
  void reduceTo(int numModes)
1125
22.7k
  {
1126
22.7k
    CHECK( numModes > m_sortedList.size(), "not enough buffers");
1127
22.7k
    m_sortedList.resize(numModes);
1128
22.7k
  }
1129
1130
  void prepare( const UnitArea& ua, int numModes)
1131
30.0k
  {
1132
30.0k
    CHECK( numModes > NumEntries, "not enough buffers");
1133
30.0k
    m_sortedList.resize(numModes);
1134
142k
    for (size_t i = 0; i < numModes; i++)
1135
112k
    {
1136
112k
      m_pacBufs[i] = m_acStorage[i].getCompactBuf(ua);
1137
112k
      m_sortedList[i] = &m_pacBufs[i];
1138
112k
    }
1139
1140
30.0k
    m_pacBufs[numModes] = m_acStorage[numModes].getCompactBuf(ua);
1141
30.0k
    m_TestBuf = &m_pacBufs[numModes];
1142
30.0k
  }
1143
1144
137k
  PelUnitBuf* getBufFromSortedList( int idx)              const { return m_sortedList.size() > idx ? m_sortedList[idx]: nullptr; }
1145
30.0k
  PelBuf&     getTestBuf          ( ComponentID compId)   const { return m_TestBuf->bufs[compId]; }
1146
1.11M
  PelUnitBuf& getTestBuf          ()                      const { return *m_TestBuf; }
1147
1148
  void swap( unsigned pos1, unsigned pos2 )
1149
0
  {
1150
0
    CHECK( pos1 >= m_sortedList.size(), "index out of range" );
1151
0
    CHECK( pos2 >= m_sortedList.size(), "index out of range" );
1152
0
    std::swap(m_sortedList[pos1], m_sortedList[pos2]);
1153
0
  }
1154
1155
  void insert(int insertPos, int RdListSize)
1156
1.11M
  {
1157
1.11M
    if (insertPos != -1)
1158
158k
    {
1159
173k
      for (int i = RdListSize - 1; i > insertPos; i--)
1160
14.3k
      {
1161
14.3k
        std::swap(m_sortedList[i - 1], m_sortedList[i]);
1162
14.3k
      }
1163
158k
      std::swap(m_TestBuf, m_sortedList[insertPos]);
1164
158k
    }
1165
1.11M
  }
1166
1167
private:
1168
  PelUnitBuf*                             m_TestBuf;
1169
  static_vector<PelUnitBuf*,NumEntries>   m_sortedList;
1170
  static_vector<PelUnitBuf, NumEntries+1> m_pacBufs;
1171
  static_vector<PelStorage, NumEntries+1> m_acStorage;
1172
};
1173
1174
struct Window;
1175
1176
void copyPadToPelUnitBuf( PelUnitBuf pelUnitBuf, const vvencYUVBuffer& yuvBuffer, const ChromaFormat& chFmt );
1177
//void setupPelUnitBuf( const YUVBuffer& yuvBuffer, PelUnitBuf& pelUnitBuf, const ChromaFormat& chFmt );
1178
void setupYuvBuffer ( const PelUnitBuf& pelUnitBuf, vvencYUVBuffer& yuvBuffer, const Window* confWindow );
1179
1180
} // namespace vvenc
1181
1182
//! \}
1183