Coverage Report

Created: 2026-10-17 06:56

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
1.80M
#define INCY( ptr, stride ) { ptr += ( stride ); }
88
10.7M
#define OFFSETX( ptr, stride, x ) { ptr += ( x ); }
89
1.01M
#define OFFSETY( ptr, stride, y ) { ptr += ( y ) * ( stride ); }
90
1.92M
#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
  void ( *reco  )         ( const Pel* src0, const Pel* src1, Pel* dst, int numSamples, const ClpRng& clpRng );
98
  void ( *copyClip )      ( const Pel* src0,                  Pel* dst, int numSamples, const ClpRng& clpRng );
99
  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 );
100
  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 );
101
  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 );
102
  void ( *sub4 )          ( const Pel* src0, int src0Stride, const Pel* src1, int src1Stride, Pel* dst, int dstStride, int width, int height );
103
  void ( *sub8 )          ( const Pel* src0, int src0Stride, const Pel* src1, int src1Stride, Pel* dst, int dstStride, int width, int height );
104
  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 );
105
  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 );
106
  void ( *copyClip4 )     ( const Pel* src0, int src0Stride,                                  Pel* dst, int dstStride, int width, int height,                                   const ClpRng& clpRng );
107
  void ( *copyClip8 )     ( const Pel* src0, int src0Stride,                                  Pel* dst, int dstStride, int width, int height,                                   const ClpRng& clpRng );
108
  void ( *reco4 )         ( const Pel* src0, int src0Stride, const Pel* src1, int src1Stride, Pel* dst, int dstStride, int width, int height,                                   const ClpRng& clpRng );
109
  void ( *reco8 )         ( const Pel* src0, int src0Stride, const Pel* src1, int src1Stride, Pel* dst, int dstStride, int width, int height,                                   const ClpRng& clpRng );
110
  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 );
111
  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 );
112
  void ( *copyBuffer )    ( const char* src, int srcStride, char* dst, int dstStride, int width, int height );
113
  void ( *removeHighFreq8)( Pel* src0, int src0Stride, const Pel* src1, int src1Stride, int width, int height);
114
  void ( *removeHighFreq4)( Pel* src0, int src0Stride, const Pel* src1, int src1Stride, int width, int height);
115
  void ( *transpose4x4 )  ( const Pel* src,  int srcStride, Pel* dst, int dstStride );
116
  void ( *transpose8x8 )  ( const Pel* src,  int srcStride, Pel* dst, int dstStride );
117
  void ( *roundIntVector) ( int* v, int size, unsigned int nShift, const int dmvLimit);
118
  void ( *mipMatrixMul_4_4)( Pel* res, const Pel* input, const uint8_t* weight, const int maxVal, const int offset, bool transpose );
119
  void ( *mipMatrixMul_8_4)( Pel* res, const Pel* input, const uint8_t* weight, const int maxVal, const int offset, bool transpose );
120
  void ( *mipMatrixMul_8_8)( Pel* res, const Pel* input, const uint8_t* weight, const int maxVal, const int offset, bool transpose );
121
  void ( *weightCiip)     ( Pel* res, const Pel* intra, const int numSamples, int numIntra );
122
  void ( *fillPtrMap )    ( void** ptrMap, const ptrdiff_t mapStride, int width, int height, void* val );
123
  uint64_t ( *AvgHighPassWithDownsampling )    ( const int width, const int height, const Pel* pSrc, const int iSrcStride);
124
  uint64_t ( *AvgHighPass )    ( const int width, const int height, const Pel* pSrc, const int iSrcStride);
125
  uint64_t ( *AvgHighPassWithDownsamplingDiff1st ) (const int width, const int height, const Pel* pSrc,const Pel* pSrcM1, const int iSrcStride, const int iSrcM1Stride);
126
  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);
127
  uint64_t ( *HDHighPass) (const int width, const int height,const Pel*  pSrc,const Pel* pSM1,const int iSrcStride,const int iSM1Stride);
128
  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);
129
130
private:
131
  bool isInitSIMDDone = false;
132
133
#if ENABLE_SIMD_OPT_BUFFER && defined(TARGET_SIMD_X86)
134
  void initPelBufOpsX86();
135
  template<X86_VEXT vext>
136
  void _initPelBufOpsX86();
137
#endif
138
139
#if ENABLE_SIMD_OPT_BUFFER && defined( TARGET_SIMD_ARM )
140
  void initPelBufOpsARM();
141
  template<ARM_VEXT vext>
142
  void _initPelBufOpsARM();
143
#endif
144
};
145
146
extern PelBufferOps g_pelBufOP;
147
148
template<typename T>
149
struct AreaBuf : public Size
150
{
151
  T*        buf;
152
  int       stride;
153
  // the proper type causes awful lot of errors
154
155
6.78M
  AreaBuf()                                                                               : Size(),                  buf( NULL ), stride( 0 )          { }
vvenc::AreaBuf<short>::AreaBuf()
Line
Count
Source
155
5.83M
  AreaBuf()                                                                               : Size(),                  buf( NULL ), stride( 0 )          { }
vvenc::AreaBuf<short const>::AreaBuf()
Line
Count
Source
155
950k
  AreaBuf()                                                                               : Size(),                  buf( NULL ), stride( 0 )          { }
Unexecuted instantiation: vvenc::AreaBuf<int>::AreaBuf()
Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo>::AreaBuf()
156
6.86M
  AreaBuf( T *_buf, const Size& size )                                                    : Size( size ),            buf( _buf ), stride( size.width ) { }
vvenc::AreaBuf<short>::AreaBuf(short*, vvenc::Size const&)
Line
Count
Source
156
2.34M
  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
156
1.80M
  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
156
6.99k
  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
156
2.70M
  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&)
157
20.4M
  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
157
20.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
157
36.0k
  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
157
331k
  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
157
6.99k
  AreaBuf( T *_buf, const int& _stride, const Size& size )                                : Size( size ),            buf( _buf ), stride( _stride )    { }
158
1.70M
  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
158
46.2k
  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
158
1.66M
  AreaBuf( T *_buf, const SizeType& _width, const SizeType& _height )                     : Size( _width, _height ), buf( _buf ), stride( _width )     { }
159
2.76M
  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
159
2.18M
  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
159
572k
  AreaBuf( T *_buf, const int& _stride, const SizeType& _width, const SizeType& _height ) : Size( _width, _height ), buf( _buf ), stride( _stride )    { }
160
161
  AreaBuf( const AreaBuf& )  = default;
162
  AreaBuf(       AreaBuf&& ) = default;
163
  AreaBuf& operator=( const AreaBuf& )  = default;
164
  AreaBuf& operator=(       AreaBuf&& ) = default;
165
166
  // conversion from AreaBuf<const T> to AreaBuf<T>
167
  template<bool T_IS_CONST = std::is_const<T>::value>
168
24.6M
  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
168
21.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
168
48.8k
  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
168
2.66M
  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 ) { }
169
170
  void fill                 ( const T &val );
171
  void memset               ( const int val );
172
173
  void copyFrom             ( const AreaBuf<const T>& other );
174
  void reconstruct          ( const AreaBuf<const T>& pred, const AreaBuf<const T>& resi, const ClpRng& clpRng);
175
  void copyClip             ( const AreaBuf<const T>& src, const ClpRng& clpRng);
176
177
  void subtract             ( const AreaBuf<const T>& minuend, const AreaBuf<const T>& subtrahend );
178
  void calcVarianceSplit    ( const AreaBuf<const T>& Org, const uint32_t  size,int& varh,int& varv ) const;
179
  void extendBorderPel      ( unsigned marginX, unsigned marginY );
180
181
  void addAvg               ( const AreaBuf<const T>& other1, const AreaBuf<const T>& other2, const ClpRng& clpRng );
182
  T    getAvg               () const;
183
  void padBorderPel         ( unsigned marginX, unsigned marginY, int dir );
184
  void addWeightedAvg       ( const AreaBuf<const T>& other1, const AreaBuf<const T>& other2, const ClpRng& clpRng, const int8_t BcwIdx );
185
  void removeHighFreq       ( const AreaBuf<const T>& other, const bool bClip, const ClpRng& clpRng);
186
  void extendBorderPelTop   ( int x, int size, int margin );
187
  void extendBorderPelBot   ( int x, int size, int margin );
188
  void extendBorderPelLft   ( int y, int size, int margin );
189
  void extendBorderPelRgt   ( int y, int size, int margin );
190
191
  void linearTransform      ( const int scale, const unsigned shift, const int offset, bool bClip, const ClpRng& clpRng );
192
193
  void transposedFrom       ( const AreaBuf<const T>& other );
194
  void weightCiip           ( const AreaBuf<const T>& intra, const int numIntra );
195
196
  bool compare              ( const AreaBuf<const T>& other ) const;
197
198
244M
        T& at( const int& x, const int& y )          { return buf[y * stride + x]; }
vvenc::AreaBuf<short>::at(int const&, int const&)
Line
Count
Source
198
244M
        T& at( const int& x, const int& y )          { return buf[y * stride + x]; }
Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo>::at(int const&, int const&)
Unexecuted instantiation: vvenc::AreaBuf<int>::at(int const&, int const&)
199
1.67G
  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
199
1.66G
  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
vvenc::AreaBuf<int const>::at(int const&, int const&) const
Line
Count
Source
199
4.17M
  const T& at( const int& x, const int& y ) const    { return buf[y * stride + x]; }
200
201
1.92M
        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
201
1.91M
        T& at( const Position& pos )                 { return buf[pos.y * stride + pos.x]; }
vvenc::AreaBuf<vvenc::LoopFilterParam>::at(vvenc::Position const&)
Line
Count
Source
201
6.99k
        T& at( const Position& pos )                 { return buf[pos.y * stride + pos.x]; }
202
31.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
202
10.5k
  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
202
20.7k
  const T& at( const Position& pos ) const           { return buf[pos.y * stride + pos.x]; }
203
204
205
648k
        T* bufAt( const int& x, const int& y )       { return &at( x, y ); }
206
783k
  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
206
783k
  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
207
208
1.92M
        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
208
1.91M
        T* bufAt( const Position& pos )              { return &at( pos ); }
vvenc::AreaBuf<vvenc::LoopFilterParam>::bufAt(vvenc::Position const&)
Line
Count
Source
208
6.99k
        T* bufAt( const Position& pos )              { return &at( pos ); }
209
31.2k
  const T* bufAt( const Position& pos ) const        { return &at( pos ); }
vvenc::AreaBuf<short const>::bufAt(vvenc::Position const&) const
Line
Count
Source
209
10.5k
  const T* bufAt( const Position& pos ) const        { return &at( pos ); }
vvenc::AreaBuf<short>::bufAt(vvenc::Position const&) const
Line
Count
Source
209
20.7k
  const T* bufAt( const Position& pos ) const        { return &at( pos ); }
210
211
  AreaBuf<      T> subBuf( const Area& area )                                                         { return AreaBuf<      T>( bufAt( area ), stride, area   ); }
212
  AreaBuf<const T> subBuf( const Area& area )                                                   const { return AreaBuf<const T>( bufAt( area ), stride, area   ); }
213
6.99k
  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
213
6.99k
  AreaBuf<      T> subBuf( const Position& pos, const Size& size )                                    { return AreaBuf<      T>( bufAt( pos  ), stride, size   ); }
214
10.5k
  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
214
10.5k
  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
215
0
  AreaBuf<      T> subBuf( const int& x, const int& y, const unsigned& _w, const unsigned& _h )       { return AreaBuf<      T>( bufAt( x, y ), stride, _w, _h ); }
216
  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 ); }
217
};
218
219
typedef AreaBuf<      Pel>  PelBuf;
220
typedef AreaBuf<const Pel> CPelBuf;
221
222
typedef AreaBuf<      TCoeff>  CoeffBuf;
223
typedef AreaBuf<const TCoeff> CCoeffBuf;
224
225
typedef AreaBuf<      TCoeffSig>  CoeffSigBuf;
226
typedef AreaBuf<const TCoeffSig> CCoeffSigBuf;
227
228
typedef AreaBuf<      MotionInfo>  MotionBuf;
229
typedef AreaBuf<const MotionInfo> CMotionBuf;
230
231
typedef AreaBuf<      TCoeff>  PLTescapeBuf;
232
typedef AreaBuf<const TCoeff> CPLTescapeBuf;
233
234
typedef AreaBuf<      bool>  PLTtypeBuf;
235
typedef AreaBuf<const bool> CPLTtypeBuf;
236
237
typedef AreaBuf<      LoopFilterParam>  LFPBuf;
238
typedef AreaBuf<const LoopFilterParam> CLFPBuf;
239
240
4.96M
#define SIZE_AWARE_PER_EL_OP( OP, INC )                     \
241
4.96M
if( ( width & 7 ) == 0 )                                    \
242
3.99M
{                                                           \
243
63.3M
  for( int y = 0; y < height; y++ )                         \
244
59.3M
  {                                                         \
245
234M
    for( int x = 0; x < width; x += 8 )                     \
246
174M
    {                                                       \
247
174M
      OP( x + 0 );                                          \
248
174M
      OP( x + 1 );                                          \
249
174M
      OP( x + 2 );                                          \
250
174M
      OP( x + 3 );                                          \
251
174M
      OP( x + 4 );                                          \
252
174M
      OP( x + 5 );                                          \
253
174M
      OP( x + 6 );                                          \
254
174M
      OP( x + 7 );                                          \
255
174M
    }                                                       \
256
59.3M
                                                            \
257
59.3M
    INC;                                                    \
258
59.3M
  }                                                         \
259
3.99M
}                                                           \
260
4.96M
else if( ( width & 3 ) == 0 )                               \
261
970k
{                                                           \
262
11.8M
  for( int y = 0; y < height; y++ )                         \
263
10.8M
  {                                                         \
264
24.1M
    for( int x = 0; x < width; x += 4 )                     \
265
13.3M
    {                                                       \
266
13.3M
      OP( x + 0 );                                          \
267
13.3M
      OP( x + 1 );                                          \
268
13.3M
      OP( x + 2 );                                          \
269
13.3M
      OP( x + 3 );                                          \
270
13.3M
    }                                                       \
271
10.8M
                                                            \
272
10.8M
    INC;                                                    \
273
10.8M
  }                                                         \
274
970k
}                                                           \
275
18.4E
else if( ( width & 1 ) == 0 )                               \
276
0
{                                                           \
277
0
  for( int y = 0; y < height; y++ )                         \
278
0
  {                                                         \
279
0
    for( int x = 0; x < width; x += 2 )                     \
280
0
    {                                                       \
281
0
      OP( x + 0 );                                          \
282
0
      OP( x + 1 );                                          \
283
0
    }                                                       \
284
0
                                                            \
285
0
    INC;                                                    \
286
0
  }                                                         \
287
0
}                                                           \
288
18.4E
else                                                        \
289
18.4E
{                                                           \
290
18.4E
  for( int y = 0; y < height; y++ )                         \
291
18.4E
  {                                                         \
292
0
    for( int x = 0; x < width; x++ )                        \
293
0
    {                                                       \
294
0
      OP( x );                                              \
295
0
    }                                                       \
296
0
                                                            \
297
0
    INC;                                                    \
298
0
  }                                                         \
299
18.4E
}
300
301
302
template<typename T>
303
T AreaBuf <T> ::getAvg() const
304
23.5k
{
305
23.5k
  const T* src = buf;
306
23.5k
  int64_t  acc = 0;
307
308
23.5k
#define AVG_INC      src += stride
309
93.4M
#define AVG_OP(ADDR) acc += src[ADDR]
310
93.4M
  SIZE_AWARE_PER_EL_OP(AVG_OP, AVG_INC);
311
23.5k
#undef AVG_INC
312
23.5k
#undef AVG_OP
313
314
23.5k
  return T ((acc + (area() >> 1)) / area());
315
23.5k
}
vvenc::AreaBuf<short const>::getAvg() const
Line
Count
Source
304
22.3k
{
305
22.3k
  const T* src = buf;
306
22.3k
  int64_t  acc = 0;
307
308
22.3k
#define AVG_INC      src += stride
309
22.3k
#define AVG_OP(ADDR) acc += src[ADDR]
310
22.3k
  SIZE_AWARE_PER_EL_OP(AVG_OP, AVG_INC);
311
22.3k
#undef AVG_INC
312
22.3k
#undef AVG_OP
313
314
22.3k
  return T ((acc + (area() >> 1)) / area());
315
22.3k
}
vvenc::AreaBuf<short>::getAvg() const
Line
Count
Source
304
1.15k
{
305
1.15k
  const T* src = buf;
306
1.15k
  int64_t  acc = 0;
307
308
1.15k
#define AVG_INC      src += stride
309
1.15k
#define AVG_OP(ADDR) acc += src[ADDR]
310
1.15k
  SIZE_AWARE_PER_EL_OP(AVG_OP, AVG_INC);
311
1.15k
#undef AVG_INC
312
1.15k
#undef AVG_OP
313
314
1.15k
  return T ((acc + (area() >> 1)) / area());
315
1.15k
}
316
317
template<>
318
void AreaBuf<MotionInfo>::fill( const MotionInfo& val );
319
320
template<typename T>
321
void AreaBuf<T>::fill(const T &val)
322
1.65M
{
323
1.65M
  if( T( 0 ) == val )
324
1.55M
  {
325
1.55M
    GCC_WARNING_DISABLE_class_memaccess
326
1.55M
    if( width == stride )
327
1.54M
    {
328
1.54M
      ::memset( buf, 0, width * height * sizeof( T ) );
329
1.54M
    }
330
3.47k
    else
331
3.47k
    {
332
3.47k
      T* dest = buf;
333
3.47k
      size_t line = width * sizeof( T );
334
335
123k
      for( unsigned y = 0; y < height; y++ )
336
120k
      {
337
120k
        ::memset( dest, 0, line );
338
339
120k
        dest += stride;
340
120k
      }
341
3.47k
    }
342
1.55M
    GCC_WARNING_RESET
343
1.55M
  }
344
108k
  else
345
108k
  {
346
108k
    if( width == stride )
347
108k
    {
348
108k
      std::fill_n( buf, width * height, val );
349
108k
    }
350
0
    else
351
0
    {
352
0
      T* dest = buf;
353
354
0
      for( int y = 0; y < height; y++, dest += stride )
355
0
      {
356
0
        std::fill_n( dest, width, val );
357
0
      }
358
0
    }
359
108k
  }
360
1.65M
}
361
362
template<typename T>
363
void AreaBuf<T>::memset( const int val )
364
225k
{
365
225k
  GCC_WARNING_DISABLE_class_memaccess
366
225k
  if( width == stride )
367
220k
  {
368
220k
    ::memset( buf, val, width * height * sizeof( T ) );
369
220k
  }
370
5.09k
  else
371
5.09k
  {
372
5.09k
    T* dest = buf;
373
5.09k
    size_t line = width * sizeof( T );
374
375
118k
    for( int y = 0; y < height; y++, dest += stride )
376
113k
    {
377
113k
      ::memset( dest, val, line );
378
113k
    }
379
5.09k
  }
380
225k
  GCC_WARNING_RESET
381
225k
}
vvenc::AreaBuf<vvenc::MotionInfo>::memset(int)
Line
Count
Source
364
213k
{
365
213k
  GCC_WARNING_DISABLE_class_memaccess
366
213k
  if( width == stride )
367
213k
  {
368
213k
    ::memset( buf, val, width * height * sizeof( T ) );
369
213k
  }
370
0
  else
371
0
  {
372
0
    T* dest = buf;
373
0
    size_t line = width * sizeof( T );
374
375
0
    for( int y = 0; y < height; y++, dest += stride )
376
0
    {
377
0
      ::memset( dest, val, line );
378
0
    }
379
0
  }
380
213k
  GCC_WARNING_RESET
381
213k
}
vvenc::AreaBuf<vvenc::LoopFilterParam>::memset(int)
Line
Count
Source
364
6.99k
{
365
6.99k
  GCC_WARNING_DISABLE_class_memaccess
366
6.99k
  if( width == stride )
367
1.90k
  {
368
1.90k
    ::memset( buf, val, width * height * sizeof( T ) );
369
1.90k
  }
370
5.09k
  else
371
5.09k
  {
372
5.09k
    T* dest = buf;
373
5.09k
    size_t line = width * sizeof( T );
374
375
118k
    for( int y = 0; y < height; y++, dest += stride )
376
113k
    {
377
113k
      ::memset( dest, val, line );
378
113k
    }
379
5.09k
  }
380
6.99k
  GCC_WARNING_RESET
381
6.99k
}
vvenc::AreaBuf<short>::memset(int)
Line
Count
Source
364
5.63k
{
365
5.63k
  GCC_WARNING_DISABLE_class_memaccess
366
5.63k
  if( width == stride )
367
5.63k
  {
368
5.63k
    ::memset( buf, val, width * height * sizeof( T ) );
369
5.63k
  }
370
0
  else
371
0
  {
372
0
    T* dest = buf;
373
0
    size_t line = width * sizeof( T );
374
375
0
    for( int y = 0; y < height; y++, dest += stride )
376
0
    {
377
0
      ::memset( dest, val, line );
378
0
    }
379
0
  }
380
5.63k
  GCC_WARNING_RESET
381
5.63k
}
382
383
template<typename T>
384
void AreaBuf<T>::copyFrom( const AreaBuf<const T>& other )
385
8.02M
{
386
#if !defined(__GNUC__) || __GNUC__ > 5
387
  static_assert( std::is_trivially_copyable<T>::value, "Type T is not trivially_copyable" );
388
#endif
389
390
8.02M
  g_pelBufOP.copyBuffer( ( const char* ) other.buf, other.stride * sizeof( T ), ( char* ) buf, stride * sizeof( T ), width * sizeof( T ), height );
391
8.02M
}
vvenc::AreaBuf<vvenc::MotionInfo>::copyFrom(vvenc::AreaBuf<vvenc::MotionInfo const> const&)
Line
Count
Source
385
48.8k
{
386
#if !defined(__GNUC__) || __GNUC__ > 5
387
  static_assert( std::is_trivially_copyable<T>::value, "Type T is not trivially_copyable" );
388
#endif
389
390
48.8k
  g_pelBufOP.copyBuffer( ( const char* ) other.buf, other.stride * sizeof( T ), ( char* ) buf, stride * sizeof( T ), width * sizeof( T ), height );
391
48.8k
}
vvenc::AreaBuf<short>::copyFrom(vvenc::AreaBuf<short const> const&)
Line
Count
Source
385
7.97M
{
386
#if !defined(__GNUC__) || __GNUC__ > 5
387
  static_assert( std::is_trivially_copyable<T>::value, "Type T is not trivially_copyable" );
388
#endif
389
390
7.97M
  g_pelBufOP.copyBuffer( ( const char* ) other.buf, other.stride * sizeof( T ), ( char* ) buf, stride * sizeof( T ), width * sizeof( T ), height );
391
7.97M
}
392
393
template<typename T>
394
void AreaBuf<T>::subtract( const AreaBuf<const T>& minuend, const AreaBuf<const T>& subtrahend )
395
{
396
  THROW( "Type not supported" );
397
}
398
399
template<>
400
void AreaBuf<Pel>::subtract( const AreaBuf<const Pel>& minuend, const AreaBuf<const Pel>& subtrahend );
401
402
template<typename T>
403
void AreaBuf<T>::calcVarianceSplit( const AreaBuf<const T>& Org, const uint32_t  size,int& varh,int& varv ) const 
404
{
405
  THROW( "Type not supported" );
406
}
407
408
template<>
409
void AreaBuf<const Pel>::calcVarianceSplit( const AreaBuf<const Pel>& Org, const uint32_t  size, int& varh,int&varv ) const;
410
411
template<typename T>
412
void AreaBuf<T>::copyClip( const AreaBuf<const T>& src, const ClpRng& clpRng )
413
{
414
  THROW( "Type not supported" );
415
}
416
417
template<>
418
void AreaBuf<Pel>::copyClip( const AreaBuf<const Pel>& src, const ClpRng& clpRng );
419
420
template<typename T>
421
void AreaBuf<T>::reconstruct( const AreaBuf<const T>& pred, const AreaBuf<const T>& resi, const ClpRng& clpRng )
422
{
423
  THROW( "Type not supported" );
424
}
425
426
template<>
427
void AreaBuf<Pel>::reconstruct( const AreaBuf<const Pel>& pred, const AreaBuf<const Pel>& resi, const ClpRng& clpRng );
428
429
template<typename T>
430
void AreaBuf<T>::addAvg( const AreaBuf<const T>& other1, const AreaBuf<const T>& other2, const ClpRng& clpRng )
431
{
432
  THROW( "Type not supported" );
433
}
434
435
template<>
436
void AreaBuf<Pel>::addAvg( const AreaBuf<const Pel>& other1, const AreaBuf<const Pel>& other2, const ClpRng& clpRng );
437
438
template<typename T>
439
void AreaBuf<T>::linearTransform( const int scale, const unsigned shift, const int offset, bool bClip, const ClpRng& clpRng )
440
{
441
  THROW( "Type not supported" );
442
}
443
444
template<>
445
void AreaBuf<Pel>::linearTransform( const int scale, const unsigned shift, const int offset, bool bClip, const ClpRng& clpRng );
446
447
template<typename T>
448
void AreaBuf<T>::removeHighFreq( const AreaBuf<const T>& other, const bool bClip, const ClpRng& clpRng )
449
0
{
450
0
  const T*  src       = other.buf;
451
0
  const int srcStride = other.stride;
452
453
0
        T*  dst       = buf;
454
0
  const int dstStride = stride;
455
456
0
#if ENABLE_SIMD_OPT_BCW
457
0
  if (!bClip)
458
0
  {
459
0
    if(!(width & 7))
460
0
      g_pelBufOP.removeHighFreq8(dst, dstStride, src, srcStride, width, height);
461
0
    else if (!(width & 3))
462
0
      g_pelBufOP.removeHighFreq4(dst, dstStride, src, srcStride, width, height);
463
0
    else
464
0
      CHECK(true, "Not supported");
465
0
  }
466
0
  else
467
0
  {
468
0
#endif
469
470
0
#define REM_HF_INC  \
471
0
  src += srcStride; \
472
0
  dst += dstStride; \
473
0
474
0
#define REM_HF_OP_CLIP( ADDR ) dst[ADDR] = ClipPel<T>( 2 * dst[ADDR] - src[ADDR], clpRng )
475
0
#define REM_HF_OP( ADDR )      dst[ADDR] =             2 * dst[ADDR] - src[ADDR]
476
477
0
  if( bClip )
478
0
  {
479
0
    SIZE_AWARE_PER_EL_OP( REM_HF_OP_CLIP, REM_HF_INC );
480
0
  }
481
0
  else
482
0
  {
483
0
    SIZE_AWARE_PER_EL_OP( REM_HF_OP,      REM_HF_INC );
484
0
  }
485
486
0
#undef REM_HF_INC
487
0
#undef REM_HF_OP
488
0
#undef REM_HF_OP_CLIP
489
490
0
#if ENABLE_SIMD_OPT_BCW
491
0
  }
492
0
#endif
493
0
}
494
495
496
template<typename T>
497
void AreaBuf<T>::extendBorderPelLft( int y, int size, int margin )
498
12.2k
{
499
12.2k
  T* p = buf + y * stride;
500
12.2k
  int h = size + y;
501
502
  // do left and right margins
503
681k
  for (; y < h; y++)
504
668k
  {
505
27.6M
    for (int x = 0; x < margin; x++)
506
26.9M
    {
507
26.9M
      *(p - margin + x) = p[0];
508
26.9M
    }
509
668k
    p += stride;
510
668k
  }
511
12.2k
}
512
513
template<typename T>
514
void AreaBuf<T>::extendBorderPelTop( int x, int size, int margin )
515
9.22k
{
516
9.22k
  T* p = buf + x;
517
518
  // p is now (-marginX, 0)
519
357k
  for (int y = 0; y < margin; y++)
520
348k
  {
521
348k
    ::memcpy(p - (y + 1) * stride, p, sizeof(T) * size);
522
348k
  }
523
9.22k
}
524
525
template<typename T>
526
void AreaBuf<T>::extendBorderPelRgt( int y, int size, int margin )
527
12.2k
{
528
12.2k
  T* p = buf + y * stride;
529
12.2k
  int h = size + y;
530
531
  // do left and right margins
532
690k
  for( ; y < h; y++)
533
678k
  {
534
31.4M
    for (int x = 0; x < margin; x++)
535
30.7M
    {
536
30.7M
      p[width + x] = p[width - 1];
537
30.7M
    }
538
678k
    p += stride;
539
678k
  }
540
12.2k
}
541
542
template<typename T>
543
void AreaBuf<T>::extendBorderPelBot( int x, int size, int margin )
544
9.22k
{
545
9.22k
  T* p = buf + (height-1)*stride + x;
546
547
  // p is now the (-margin, height-1)
548
357k
  for (int y = 0; y < margin; y++)
549
348k
  {
550
348k
    ::memcpy(p + (y + 1) * stride, p, sizeof(T) * size);
551
348k
  }
552
9.22k
}
553
554
template<typename T>
555
void AreaBuf<T>::extendBorderPel(unsigned marginX, unsigned marginY)
556
3.46k
{
557
3.46k
  T* p = buf;
558
3.46k
  int h = height;
559
3.46k
  int w = width;
560
3.46k
  int s = stride;
561
562
3.46k
  CHECK((w + 2 * marginX) > s, "Size of buffer too small to extend");
563
  // do left and right margins
564
354k
  for (int y = 0; y < h; y++)
565
351k
  {
566
4.56M
    for (int x = 0; x < marginX; x++)
567
4.21M
    {
568
4.21M
      *(p - marginX + x) = p[0];
569
4.21M
      p[w + x] = p[w - 1];
570
4.21M
    }
571
351k
    p += s;
572
351k
  }
573
574
  // p is now the (0,height) (bottom left of image within bigger picture
575
3.46k
  p -= (s + marginX);
576
  // p is now the (-margin, height-1)
577
40.4k
  for (int y = 0; y < marginY; y++)
578
36.9k
  {
579
36.9k
    ::memcpy(p + (y + 1) * s, p, sizeof(T) * (w + (marginX << 1)));
580
36.9k
  }
581
582
  // p is still (-marginX, height-1)
583
3.46k
  p -= ((h - 1) * s);
584
  // p is now (-marginX, 0)
585
40.4k
  for (int y = 0; y < marginY; y++)
586
36.9k
  {
587
36.9k
    ::memcpy(p - (y + 1) * s, p, sizeof(T) * (w + (marginX << 1)));
588
36.9k
  }
589
3.46k
}
590
591
template<typename T>
592
void AreaBuf<T>::padBorderPel( unsigned marginX, unsigned marginY, int dir )
593
0
{
594
0
  T*  p = buf;
595
0
  int s = stride;
596
0
  int h = height;
597
0
  int w = width;
598
599
0
  CHECK( w  > s, "Size of buffer too small to extend" );
600
601
  // top-left margin
602
0
  if ( dir == 1 )
603
0
  {
604
0
    for( int y = 0; y < marginY; y++ )
605
0
    {
606
0
      for( int x = 0; x < marginX; x++ )
607
0
      {
608
0
        p[x] = p[marginX];
609
0
      }
610
0
      p += s;
611
0
    }
612
0
  }
613
614
  // bottom-right margin
615
0
  if ( dir == 2 )
616
0
  {
617
0
    p = buf + s * ( h - marginY ) + w - marginX;
618
619
0
    for( int y = 0; y < marginY; y++ )
620
0
    {
621
0
      for( int x = 0; x < marginX; x++ )
622
0
      {
623
0
        p[x] = p[-1];
624
0
      }
625
0
      p += s;
626
0
    }
627
0
  }
628
0
}
629
630
631
#if ENABLE_SIMD_OPT_BUFFER
632
template<> void AreaBuf<Pel>::transposedFrom( const AreaBuf<const Pel>& other );
633
#endif
634
635
template<typename T>
636
void AreaBuf<T>::transposedFrom( const AreaBuf<const T>& other )
637
{
638
  CHECK( width * height != other.width * other.height, "Incompatible size" );
639
640
        T* dst  =       buf;
641
  const T* src  = other.buf;
642
  width         = other.height;
643
  height        = other.width;
644
  stride        = stride < width ? width : stride;
645
646
  for( unsigned y = 0; y < other.height; y++ )
647
  {
648
    for( unsigned x = 0; x < other.width; x++ )
649
    {
650
      dst[y + x*stride] = src[x + y*other.stride];
651
    }
652
  }
653
}
654
655
template<typename T>
656
bool AreaBuf <T> ::compare( const AreaBuf<const T>& other ) const
657
{
658
        T* mine   =       buf;
659
  const T* theirs = other.buf;
660
  if( width != other.width) return false;
661
  if( height != other.height) return false;
662
663
  for( unsigned y = 0; y < other.height; y++ )
664
  {
665
    for( unsigned x = 0; x < other.width; x++ )
666
    {
667
      if( mine[x + y*stride] != theirs[x+y*other.stride])
668
      {
669
        return false;
670
      }
671
    }
672
  }
673
  return true;
674
}
675
676
#ifndef DONT_UNDEF_SIZE_AWARE_PER_EL_OP
677
#undef SIZE_AWARE_PER_EL_OP
678
#endif // !DONT_UNDEF_SIZE_AWARE_PER_EL_OP
679
680
// ---------------------------------------------------------------------------
681
// UnitBuf struct
682
// ---------------------------------------------------------------------------
683
684
struct UnitArea;
685
686
template<typename T>
687
struct UnitBuf
688
{
689
  typedef static_vector<AreaBuf<T>,       MAX_NUM_COMP> UnitBufBuffers;
690
  typedef static_vector<AreaBuf<const T>, MAX_NUM_COMP> ConstUnitBufBuffers;
691
692
  ChromaFormat chromaFormat;
693
  UnitBufBuffers bufs;
694
695
1.06M
  UnitBuf() : chromaFormat( NUM_CHROMA_FORMAT ) { }
vvenc::UnitBuf<short>::UnitBuf()
Line
Count
Source
695
1.06M
  UnitBuf() : chromaFormat( NUM_CHROMA_FORMAT ) { }
Unexecuted instantiation: vvenc::UnitBuf<short const>::UnitBuf()
696
  UnitBuf( const ChromaFormat _chromaFormat, const UnitBufBuffers&  _bufs ) : chromaFormat( _chromaFormat ), bufs( _bufs ) { }
697
  UnitBuf( const ChromaFormat _chromaFormat,       UnitBufBuffers&& _bufs ) : chromaFormat( _chromaFormat ), bufs( std::forward<UnitBufBuffers>( _bufs ) ) { }
698
0
  UnitBuf( const ChromaFormat _chromaFormat, const AreaBuf<T>&  blkY )      : chromaFormat( _chromaFormat ), bufs{ blkY } { }
699
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>&&)
700
3.50k
  UnitBuf( const ChromaFormat _chromaFormat, const AreaBuf<T>&  blkY, const AreaBuf<T>&  blkCb, const AreaBuf<T>  &blkCr ) : chromaFormat( _chromaFormat ), bufs{ blkY, blkCb, blkCr } { }
701
577k
  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
701
577k
  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>&&)
702
703
49.4k
  UnitBuf( const UnitBuf& other )  = default;
704
  UnitBuf(       UnitBuf&& other ) = default;
705
  UnitBuf& operator=( const UnitBuf& other )  = default;
706
  UnitBuf& operator=(       UnitBuf&& other ) = default;
707
708
  // conversion from UnitBuf<const T> to UnitBuf<T>
709
  template<bool T_IS_COST = std::is_const<T>::value>
710
294k
  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() ) { }
711
712
7.89M
        AreaBuf<T>& get( const ComponentID comp )        { return bufs[comp]; }
713
69.5k
  const AreaBuf<T>& get( const ComponentID comp )  const { return bufs[comp]; }
vvenc::UnitBuf<short>::get(vvenc::ComponentID) const
Line
Count
Source
713
62.5k
  const AreaBuf<T>& get( const ComponentID comp )  const { return bufs[comp]; }
vvenc::UnitBuf<short const>::get(vvenc::ComponentID) const
Line
Count
Source
713
7.00k
  const AreaBuf<T>& get( const ComponentID comp )  const { return bufs[comp]; }
714
715
1.59M
        AreaBuf<T>& Y()        { return bufs[0]; }
vvenc::UnitBuf<short>::Y()
Line
Count
Source
715
1.59M
        AreaBuf<T>& Y()        { return bufs[0]; }
Unexecuted instantiation: vvenc::UnitBuf<short const>::Y()
716
3.46k
  const AreaBuf<T>& Y()  const { return bufs[0]; }
717
537k
        AreaBuf<T>& Cb()       { return bufs[1]; }
718
  const AreaBuf<T>& Cb() const { return bufs[1]; }
719
537k
        AreaBuf<T>& Cr()       { return bufs[2]; }
720
  const AreaBuf<T>& Cr() const { return bufs[2]; }
721
167k
  bool valid          () const { return bufs.size() != 0; }
722
723
  void fill                 ( const T& val );
724
  void copyFrom             ( const UnitBuf<const T> &other, const bool luma = true, const bool chroma = true );
725
  void reconstruct          ( const UnitBuf<const T>& pred, const UnitBuf<const T>& resi, const ClpRngs& clpRngs );
726
  void copyClip             ( const UnitBuf<const T> &src, const ClpRngs& clpRngs, const bool lumaOnly = false, const bool chromaOnly = false );
727
  void subtract             ( const UnitBuf<const T>& minuend, const UnitBuf<const T>& subtrahend );
728
  void addAvg               ( const UnitBuf<const T>& other1, const UnitBuf<const T>& other2, const ClpRngs& clpRngs, const bool chromaOnly = false, const bool lumaOnly = false);
729
  void addWeightedAvg       ( const UnitBuf<const T>& other1, const UnitBuf<const T>& other2, const ClpRngs& clpRngs, const uint8_t BcwIdx = BCW_DEFAULT, const bool chromaOnly = false, const bool lumaOnly = false);
730
  void padBorderPel         ( unsigned margin, int dir );
731
  void extendBorderPel      ( unsigned margin, bool scale = false);
732
  void extendBorderPelTop   ( int x, int size, int margin );
733
  void extendBorderPelBot   ( int x, int size, int margin );
734
  void extendBorderPelLft   ( int y, int size, int margin );
735
  void extendBorderPelRgt   ( int y, int size, int margin );
736
737
  void removeHighFreq       ( const UnitBuf<const T>& other, const bool bClip, const ClpRngs& clpRngs);
738
739
        UnitBuf<      T> subBuf (const UnitArea& subArea);
740
  const UnitBuf<const T> subBuf (const UnitArea& subArea) const;
741
};
742
743
typedef UnitBuf<      Pel>  PelUnitBuf;
744
typedef UnitBuf<const Pel> CPelUnitBuf;
745
746
typedef UnitBuf<      TCoeff>  CoeffUnitBuf;
747
typedef UnitBuf<const TCoeff> CCoeffUnitBuf;
748
749
template<typename T>
750
void UnitBuf<T>::fill( const T &val )
751
0
{
752
0
  for( int i = 0; i < bufs.size(); i++ )
753
0
  {
754
0
    bufs[i].fill( val );
755
0
  }
756
0
}
757
758
759
template<typename T>
760
void UnitBuf<T>::copyFrom(const UnitBuf<const T> &other, const bool luma, const bool chroma)
761
396k
{
762
396k
  CHECK( chromaFormat != other.chromaFormat, "Incompatible formats" );
763
396k
  CHECK( !luma && !chroma, "At least one channel has to be selected" );
764
765
18.4E
  const size_t compStart = luma   ? 0           : 1;
766
18.4E
  const size_t compEnd   = chroma ? bufs.size() : 1;
767
768
1.58M
  for( size_t i = compStart; i < compEnd; i++ )
769
1.18M
  {
770
1.18M
    if( bufs[ i ].buf != nullptr && other.bufs[ i ].buf != nullptr )
771
799k
      bufs[i].copyFrom( other.bufs[i] );
772
1.18M
  }
773
396k
}
774
775
template<typename T>
776
void UnitBuf<T>::subtract( const UnitBuf<const T>& minuend, const UnitBuf<const T>& subtrahend )
777
0
{
778
0
  CHECK( chromaFormat != minuend.chromaFormat, "Incompatible formats" );
779
0
  CHECK( chromaFormat != subtrahend.chromaFormat, "Incompatible formats");
780
781
0
  for( int i = 0; i < bufs.size(); i++ )
782
0
  {
783
0
    bufs[i].subtract( minuend.bufs[i], subtrahend.bufs[i] );
784
0
  }
785
0
}
786
787
template<typename T>
788
void UnitBuf<T>::copyClip(const UnitBuf<const T> &src, const ClpRngs &clpRngs, const bool lumaOnly, const bool chromaOnly)
789
0
{
790
0
  CHECK( chromaFormat != src.chromaFormat, "Incompatible formats" );
791
792
0
  CHECK(lumaOnly && chromaOnly, "Not allowed to have both lumaOnly and chromaOnly selected");
793
0
  const int compStart = chromaOnly ? 1 : 0;
794
0
  const int compEnd   = lumaOnly   ? 1 : ( int ) bufs.size();
795
0
  for( int i = compStart; i < compEnd; i++ )
796
0
  {
797
0
    bufs[i].copyClip( src.bufs[i], clpRngs[i] );
798
0
  }
799
0
}
800
801
template<typename T>
802
void UnitBuf<T>::reconstruct(const UnitBuf<const T>& pred, const UnitBuf<const T>& resi, const ClpRngs& clpRngs)
803
0
{
804
0
  CHECK( chromaFormat != pred.chromaFormat, "Incompatible formats" );
805
0
  CHECK( chromaFormat != resi.chromaFormat, "Incompatible formats" );
806
807
0
  for( int i = 0; i < bufs.size(); i++ )
808
0
  {
809
0
    bufs[i].reconstruct( pred.bufs[i], resi.bufs[i], clpRngs[i] );
810
0
  }
811
0
}
812
813
template<typename T>
814
void UnitBuf<T>::addAvg(const UnitBuf<const T>& other1, const UnitBuf<const T>& other2, const ClpRngs& clpRngs, const bool chromaOnly /* = false */, const bool lumaOnly /* = false */)
815
0
{
816
0
  const int istart = chromaOnly ? 1 : 0;
817
0
  const int iend   = lumaOnly   ? 1 : ( int ) bufs.size();
818
819
0
  CHECK( lumaOnly && chromaOnly, "should not happen" );
820
821
0
  for( int i = istart; i < iend; i++)
822
0
  {
823
0
    bufs[i].addAvg( other1.bufs[i], other2.bufs[i], clpRngs[i]);
824
0
  }
825
0
}
826
827
template<typename T>
828
void UnitBuf<T>::addWeightedAvg(const UnitBuf<const T>& other1, const UnitBuf<const T>& other2, const ClpRngs& clpRngs, const uint8_t BcwIdx /* = BCW_DEFAULT */, const bool chromaOnly /* = false */, const bool lumaOnly /* = false */)
829
0
{
830
0
  const int istart = chromaOnly ? 1 : 0;
831
0
  const int iend   = lumaOnly   ? 1 : ( int ) bufs.size();
832
833
0
  CHECK( lumaOnly && chromaOnly, "should not happen" );
834
835
0
  for ( int i = istart; i < iend; i++)
836
0
  {
837
0
    bufs[i].addWeightedAvg(other1.bufs[i], other2.bufs[i], clpRngs[i], BcwIdx);
838
0
  }
839
0
}
840
841
template<typename T>
842
void UnitBuf<T>::extendBorderPelTop   ( int x, int size, int margin )
843
3.07k
{
844
12.2k
  for( int i = 0; i < bufs.size(); i++ )
845
9.22k
  {
846
9.22k
    int csx = getComponentScaleX(ComponentID(i), chromaFormat);
847
9.22k
    int csy = getComponentScaleY(ComponentID(i), chromaFormat);
848
9.22k
    bufs[i].extendBorderPelTop( x>>csx, size>>csx, margin>>csy );
849
9.22k
  }
850
3.07k
}
851
852
template<typename T>
853
void UnitBuf<T>::extendBorderPelBot   ( int x, int size, int margin )
854
3.07k
{
855
12.2k
  for( int i = 0; i < bufs.size(); i++ )
856
9.22k
  {
857
9.22k
    int csx = getComponentScaleX(ComponentID(i), chromaFormat);
858
9.22k
    int csy = getComponentScaleY(ComponentID(i), chromaFormat);
859
9.22k
    bufs[i].extendBorderPelBot( x>>csx, size>>csx, margin>>csy );
860
9.22k
  }
861
3.07k
}
862
863
template<typename T>
864
void UnitBuf<T>::extendBorderPelLft   ( int y, int size, int margin )
865
4.07k
{
866
16.2k
  for( int i = 0; i < bufs.size(); i++ )
867
12.2k
  {
868
12.2k
    int csx = getComponentScaleX(ComponentID(i), chromaFormat);
869
12.2k
    int csy = getComponentScaleY(ComponentID(i), chromaFormat);
870
12.2k
    bufs[i].extendBorderPelLft( y>>csy, size>>csy, margin>>csx );
871
12.2k
  }
872
4.07k
}
873
874
template<typename T>
875
void UnitBuf<T>::extendBorderPelRgt   ( int y, int size, int margin )
876
4.07k
{
877
16.2k
  for( int i = 0; i < bufs.size(); i++ )
878
12.2k
  {
879
12.2k
    int csx = getComponentScaleX(ComponentID(i), chromaFormat);
880
12.2k
    int csy = getComponentScaleY(ComponentID(i), chromaFormat);
881
12.2k
    bufs[i].extendBorderPelRgt( y>>csy, size>>csy, margin>>csx );
882
12.2k
  }
883
4.07k
}
884
885
template<typename T>
886
void UnitBuf<T>::extendBorderPel( unsigned margin, bool scaleMargin )
887
1.15k
{
888
1.15k
  if( ! scaleMargin )
889
0
  {
890
0
    for( int i = 0; i < bufs.size(); i++ )
891
0
    {
892
0
      bufs[i].extendBorderPel( margin, margin );
893
0
    }
894
0
  }
895
1.15k
  else
896
1.15k
  {
897
4.62k
    for ( int i = 0; i < bufs.size(); i++)
898
3.46k
    {
899
3.46k
      bufs[i].extendBorderPel(margin >> getComponentScaleX(ComponentID(i), chromaFormat), margin >> getComponentScaleY(ComponentID(i), chromaFormat));
900
3.46k
    }
901
1.15k
  }
902
1.15k
}
903
904
template<typename T>
905
void UnitBuf<T>::padBorderPel( unsigned margin, int dir )
906
0
{
907
0
  for( int i = 0; i < bufs.size(); i++ )
908
0
  {
909
0
    bufs[i].padBorderPel( margin >> getComponentScaleX( ComponentID( i ), chromaFormat ), margin >> getComponentScaleY( ComponentID( i ), chromaFormat ), dir );
910
0
  }
911
0
}
912
913
template<typename T>
914
void UnitBuf<T>::removeHighFreq( const UnitBuf<const T>& other, const bool bClip, const ClpRngs& clpRngs)
915
0
{
916
0
  bufs[0].removeHighFreq(other.bufs[0], bClip, clpRngs[0]);
917
0
}
918
919
template<typename T>
920
UnitBuf<T> UnitBuf<T>::subBuf( const UnitArea& subArea )
921
0
{
922
0
  UnitBuf<T> subBuf;
923
0
  subBuf.chromaFormat = chromaFormat;
924
0
  unsigned blockIdx = 0;
925
926
0
  for( auto &subAreaBuf : bufs )
927
0
  {
928
0
    subBuf.bufs.push_back( subAreaBuf.subBuf( subArea.blocks[blockIdx].pos(), subArea.blocks[blockIdx].size() ) );
929
0
    blockIdx++;
930
0
  }
931
932
0
  return subBuf;
933
0
}
934
935
936
template<typename T>
937
const UnitBuf<const T> UnitBuf<T>::subBuf( const UnitArea& subArea ) const
938
0
{
939
0
  UnitBuf<const T> subBuf;
940
0
  subBuf.chromaFormat = chromaFormat;
941
0
  unsigned blockIdx = 0;
942
943
0
  for( const auto &subAreaBuf : bufs )
944
0
  {
945
0
    subBuf.bufs.push_back( subAreaBuf.subBuf( subArea.blocks[blockIdx].pos(), subArea.blocks[blockIdx].size() ) );
946
0
    blockIdx++;
947
0
  }
948
949
0
  return subBuf;
950
0
}
951
952
// ---------------------------------------------------------------------------
953
// PelStorage struct (PelUnitBuf which allocates its own memory)
954
// ---------------------------------------------------------------------------
955
956
struct UnitArea;
957
struct CompArea;
958
959
struct PelStorage : public PelUnitBuf
960
{
961
  PelStorage();
962
  ~PelStorage();
963
964
  void swap( PelStorage& other );
965
  void createFromBuf( PelUnitBuf buf );
966
  void takeOwnership( PelStorage& other );
967
  void create( const UnitArea& _unit );
968
  void create( const ChromaFormat &_chromaFormat, const Area& _area );
969
  void create( const ChromaFormat &_chromaFormat, const Area& _area, const unsigned _maxCUSize, const unsigned _margin = 0, const unsigned _alignment = 0, const bool _scaleChromaMargin = true );
970
  void destroy();
971
  void compactResize( const UnitArea& area );
972
973
         PelBuf getBuf( const CompArea& blk );
974
  const CPelBuf getBuf( const CompArea& blk ) const;
975
976
         PelBuf getBuf( const ComponentID CompID );
977
  const CPelBuf getBuf( const ComponentID CompID ) const;
978
979
         PelUnitBuf getBuf( const UnitArea& unit );
980
  const CPelUnitBuf getBuf( const UnitArea& unit ) const;
981
9.24k
               Pel* getOrigin( const int id ) const { return m_origin[id]; }
982
983
         PelUnitBuf getBuf(const int strY, const int strCb, const int strCr, const UnitArea& unit);
984
  const CPelUnitBuf getBuf(const int strY, const int strCb, const int strCr, const UnitArea& unit) const;
985
986
         PelUnitBuf getBufPart( const UnitArea& unit );
987
  const CPelUnitBuf getBufPart( const UnitArea& unit ) const;
988
989
         PelUnitBuf getCompactBuf(const UnitArea& unit);
990
  const CPelUnitBuf getCompactBuf(const UnitArea& unit) const;
991
992
         PelBuf     getCompactBuf(const CompArea& blk);
993
  const CPelBuf     getCompactBuf(const CompArea& blk) const;
994
995
private:
996
997
  UnitArea m_maxArea;
998
  Pel* m_origin[MAX_NUM_COMP];
999
};
1000
1001
struct CompStorage : public PelBuf
1002
{
1003
83.2k
  ~CompStorage() { if( valid() ) delete[] m_memory; }
1004
1005
  void compactResize( const Size& size )
1006
2.68M
  {
1007
2.68M
    CHECK( size.area() > m_allocSize, "Resizing causes buffer overflow!" );
1008
2.68M
    Size::operator=( size );
1009
2.68M
    stride = size.width;
1010
2.68M
  }
1011
  void create( const Size& size )
1012
83.2k
  {
1013
83.2k
    CHECK( m_memory, "Trying to re-create an already initialized buffer" );
1014
83.2k
    m_allocSize = size.area();
1015
83.2k
    m_memory = new Pel[m_allocSize];
1016
83.2k
    PelBuf::operator=( PelBuf( m_memory, size ) );
1017
83.2k
  }
1018
  void destroy()
1019
0
  {
1020
0
    if( valid() ) delete[] m_memory;
1021
0
    m_memory    = nullptr;
1022
0
    m_allocSize = 0;
1023
0
  }
1024
591k
  bool valid() { return m_memory != nullptr; }
1025
private:
1026
  ptrdiff_t m_allocSize = 0;
1027
  Pel*      m_memory    = nullptr;
1028
};
1029
1030
template<int NumEntries>
1031
struct SortedPelUnitBufs
1032
{
1033
  void create(ChromaFormat cform, int maxWidth, int maxHeight)
1034
4.62k
  {
1035
4.62k
    m_pacBufs.resize(NumEntries + 1);
1036
4.62k
    m_acStorage.resize(NumEntries + 1);
1037
50.8k
    for (size_t i = 0; i <= NumEntries; i++)
1038
46.2k
    {
1039
46.2k
      m_acStorage[i].create(cform, Area(0, 0, maxWidth, maxHeight));
1040
46.2k
    }
1041
4.62k
  }
1042
1043
  void destroy()
1044
4.62k
  {
1045
50.8k
    for (size_t i = 0; i <= NumEntries; i++)
1046
46.2k
    {
1047
46.2k
      m_acStorage[i].destroy();
1048
46.2k
    }
1049
4.62k
  }
1050
1051
  void reset()
1052
  {
1053
    m_sortedList.clear();
1054
  }
1055
1056
  void reduceTo(int numModes)
1057
18.1k
  {
1058
18.1k
    CHECK( numModes > m_sortedList.size(), "not enough buffers");
1059
18.1k
    m_sortedList.resize(numModes);
1060
18.1k
  }
1061
1062
  void prepare( const UnitArea& ua, int numModes)
1063
23.7k
  {
1064
23.7k
    CHECK( numModes > NumEntries, "not enough buffers");
1065
23.7k
    m_sortedList.resize(numModes);
1066
113k
    for (size_t i = 0; i < numModes; i++)
1067
89.3k
    {
1068
89.3k
      m_pacBufs[i] = m_acStorage[i].getCompactBuf(ua);
1069
89.3k
      m_sortedList[i] = &m_pacBufs[i];
1070
89.3k
    }
1071
1072
23.7k
    m_pacBufs[numModes] = m_acStorage[numModes].getCompactBuf(ua);
1073
23.7k
    m_TestBuf = &m_pacBufs[numModes];
1074
23.7k
  }
1075
1076
109k
  PelUnitBuf* getBufFromSortedList( int idx)              const { return m_sortedList.size() > idx ? m_sortedList[idx]: nullptr; }
1077
23.7k
  PelBuf&     getTestBuf          ( ComponentID compId)   const { return m_TestBuf->bufs[compId]; }
1078
888k
  PelUnitBuf& getTestBuf          ()                      const { return *m_TestBuf; }
1079
1080
  void swap( unsigned pos1, unsigned pos2 )
1081
0
  {
1082
0
    CHECK( pos1 >= m_sortedList.size(), "index out of range" );
1083
0
    CHECK( pos2 >= m_sortedList.size(), "index out of range" );
1084
0
    std::swap(m_sortedList[pos1], m_sortedList[pos2]);
1085
0
  }
1086
1087
  void insert(int insertPos, int RdListSize)
1088
888k
  {
1089
888k
    if (insertPos != -1)
1090
126k
    {
1091
138k
      for (int i = RdListSize - 1; i > insertPos; i--)
1092
12.0k
      {
1093
12.0k
        std::swap(m_sortedList[i - 1], m_sortedList[i]);
1094
12.0k
      }
1095
126k
      std::swap(m_TestBuf, m_sortedList[insertPos]);
1096
126k
    }
1097
888k
  }
1098
1099
private:
1100
  PelUnitBuf*                             m_TestBuf;
1101
  static_vector<PelUnitBuf*,NumEntries>   m_sortedList;
1102
  static_vector<PelUnitBuf, NumEntries+1> m_pacBufs;
1103
  static_vector<PelStorage, NumEntries+1> m_acStorage;
1104
};
1105
1106
struct Window;
1107
1108
void copyPadToPelUnitBuf( PelUnitBuf pelUnitBuf, const vvencYUVBuffer& yuvBuffer, const ChromaFormat& chFmt );
1109
//void setupPelUnitBuf( const YUVBuffer& yuvBuffer, PelUnitBuf& pelUnitBuf, const ChromaFormat& chFmt );
1110
void setupYuvBuffer ( const PelUnitBuf& pelUnitBuf, vvencYUVBuffer& yuvBuffer, const Window* confWindow );
1111
1112
} // namespace vvenc
1113
1114
//! \}
1115