Coverage Report

Created: 2026-09-01 06:57

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.84M
#define INCY( ptr, stride ) { ptr += ( stride ); }
88
11.1M
#define OFFSETX( ptr, stride, x ) { ptr += ( x ); }
89
1.04M
#define OFFSETY( ptr, stride, y ) { ptr += ( y ) * ( stride ); }
90
1.98M
#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
17.5M
  AreaBuf()                                                                               : Size(),                  buf( NULL ), stride( 0 )          { }
vvenc::AreaBuf<short>::AreaBuf()
Line
Count
Source
155
16.5M
  AreaBuf()                                                                               : Size(),                  buf( NULL ), stride( 0 )          { }
vvenc::AreaBuf<short const>::AreaBuf()
Line
Count
Source
155
1.00M
  AreaBuf()                                                                               : Size(),                  buf( NULL ), stride( 0 )          { }
Unexecuted instantiation: vvenc::AreaBuf<int>::AreaBuf()
Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo>::AreaBuf()
156
7.21M
  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.63M
  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.83M
  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
7.14k
  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.74M
  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
21.1M
  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.4M
  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.8k
  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
744k
  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
7.14k
  AreaBuf( T *_buf, const int& _stride, const Size& size )                                : Size( size ),            buf( _buf ), stride( _stride )    { }
158
1.73M
  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.8k
  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.68M
  AreaBuf( T *_buf, const SizeType& _width, const SizeType& _height )                     : Size( _width, _height ), buf( _buf ), stride( _width )     { }
159
9.97M
  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
9.39M
  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
578k
  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
25.0M
  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
22.2M
  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
49.1k
  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.71M
  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
250M
        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
250M
        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.71G
  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.71G
  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.25M
  const T& at( const int& x, const int& y ) const    { return buf[y * stride + x]; }
200
201
2.03M
        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
2.02M
        T& at( const Position& pos )                 { return buf[pos.y * stride + pos.x]; }
vvenc::AreaBuf<vvenc::LoopFilterParam>::at(vvenc::Position const&)
Line
Count
Source
201
7.14k
        T& at( const Position& pos )                 { return buf[pos.y * stride + pos.x]; }
202
32.0k
  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.7k
  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
21.3k
  const T& at( const Position& pos ) const           { return buf[pos.y * stride + pos.x]; }
203
204
205
11.2k
        T* bufAt( const int& x, const int& y )       { return &at( x, y ); }
206
171k
  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
171k
  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
2.03M
        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
2.02M
        T* bufAt( const Position& pos )              { return &at( pos ); }
vvenc::AreaBuf<vvenc::LoopFilterParam>::bufAt(vvenc::Position const&)
Line
Count
Source
208
7.14k
        T* bufAt( const Position& pos )              { return &at( pos ); }
209
32.0k
  const T* bufAt( const Position& pos ) const        { return &at( pos ); }
vvenc::AreaBuf<short const>::bufAt(vvenc::Position const&) const
Line
Count
Source
209
10.7k
  const T* bufAt( const Position& pos ) const        { return &at( pos ); }
vvenc::AreaBuf<short>::bufAt(vvenc::Position const&) const
Line
Count
Source
209
21.3k
  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
28.5k
  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&)
vvenc::AreaBuf<short>::subBuf(vvenc::Position const&, vvenc::Size const&)
Line
Count
Source
213
21.4k
  AreaBuf<      T> subBuf( const Position& pos, const Size& size )                                    { return AreaBuf<      T>( bufAt( pos  ), stride, size   ); }
vvenc::AreaBuf<vvenc::LoopFilterParam>::subBuf(vvenc::Position const&, vvenc::Size const&)
Line
Count
Source
213
7.14k
  AreaBuf<      T> subBuf( const Position& pos, const Size& size )                                    { return AreaBuf<      T>( bufAt( pos  ), stride, size   ); }
214
10.7k
  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.7k
  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
5.04M
#define SIZE_AWARE_PER_EL_OP( OP, INC )                     \
241
5.04M
if( ( width & 7 ) == 0 )                                    \
242
4.08M
{                                                           \
243
64.8M
  for( int y = 0; y < height; y++ )                         \
244
60.7M
  {                                                         \
245
241M
    for( int x = 0; x < width; x += 8 )                     \
246
180M
    {                                                       \
247
180M
      OP( x + 0 );                                          \
248
180M
      OP( x + 1 );                                          \
249
180M
      OP( x + 2 );                                          \
250
180M
      OP( x + 3 );                                          \
251
180M
      OP( x + 4 );                                          \
252
180M
      OP( x + 5 );                                          \
253
180M
      OP( x + 6 );                                          \
254
180M
      OP( x + 7 );                                          \
255
180M
    }                                                       \
256
60.7M
                                                            \
257
60.7M
    INC;                                                    \
258
60.7M
  }                                                         \
259
4.08M
}                                                           \
260
5.04M
else if( ( width & 3 ) == 0 )                               \
261
960k
{                                                           \
262
11.6M
  for( int y = 0; y < height; y++ )                         \
263
10.7M
  {                                                         \
264
23.8M
    for( int x = 0; x < width; x += 4 )                     \
265
13.1M
    {                                                       \
266
13.1M
      OP( x + 0 );                                          \
267
13.1M
      OP( x + 1 );                                          \
268
13.1M
      OP( x + 2 );                                          \
269
13.1M
      OP( x + 3 );                                          \
270
13.1M
    }                                                       \
271
10.7M
                                                            \
272
10.7M
    INC;                                                    \
273
10.7M
  }                                                         \
274
960k
}                                                           \
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.4k
{
305
23.4k
  const T* src = buf;
306
23.4k
  int64_t  acc = 0;
307
308
23.4k
#define AVG_INC      src += stride
309
96.1M
#define AVG_OP(ADDR) acc += src[ADDR]
310
96.1M
  SIZE_AWARE_PER_EL_OP(AVG_OP, AVG_INC);
311
23.4k
#undef AVG_INC
312
23.4k
#undef AVG_OP
313
314
23.4k
  return T ((acc + (area() >> 1)) / area());
315
23.4k
}
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.16k
{
305
1.16k
  const T* src = buf;
306
1.16k
  int64_t  acc = 0;
307
308
1.16k
#define AVG_INC      src += stride
309
1.16k
#define AVG_OP(ADDR) acc += src[ADDR]
310
1.16k
  SIZE_AWARE_PER_EL_OP(AVG_OP, AVG_INC);
311
1.16k
#undef AVG_INC
312
1.16k
#undef AVG_OP
313
314
1.16k
  return T ((acc + (area() >> 1)) / area());
315
1.16k
}
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.68M
{
323
1.68M
  if( T( 0 ) == val )
324
1.57M
  {
325
1.57M
    GCC_WARNING_DISABLE_class_memaccess
326
1.57M
    if( width == stride )
327
1.57M
    {
328
1.57M
      ::memset( buf, 0, width * height * sizeof( T ) );
329
1.57M
    }
330
3.39k
    else
331
3.39k
    {
332
3.39k
      T* dest = buf;
333
3.39k
      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.39k
    }
342
1.57M
    GCC_WARNING_RESET
343
1.57M
  }
344
112k
  else
345
112k
  {
346
112k
    if( width == stride )
347
112k
    {
348
112k
      std::fill_n( buf, width * height, val );
349
112k
    }
350
18.4E
    else
351
18.4E
    {
352
18.4E
      T* dest = buf;
353
354
18.4E
      for( int y = 0; y < height; y++, dest += stride )
355
0
      {
356
0
        std::fill_n( dest, width, val );
357
0
      }
358
18.4E
    }
359
112k
  }
360
1.68M
}
361
362
template<typename T>
363
void AreaBuf<T>::memset( const int val )
364
634k
{
365
634k
  GCC_WARNING_DISABLE_class_memaccess
366
634k
  if( width == stride )
367
628k
  {
368
628k
    ::memset( buf, val, width * height * sizeof( T ) );
369
628k
  }
370
5.32k
  else
371
5.32k
  {
372
5.32k
    T* dest = buf;
373
5.32k
    size_t line = width * sizeof( T );
374
375
124k
    for( int y = 0; y < height; y++, dest += stride )
376
118k
    {
377
118k
      ::memset( dest, val, line );
378
118k
    }
379
5.32k
  }
380
634k
  GCC_WARNING_RESET
381
634k
}
vvenc::AreaBuf<vvenc::MotionInfo>::memset(int)
Line
Count
Source
364
621k
{
365
621k
  GCC_WARNING_DISABLE_class_memaccess
366
621k
  if( width == stride )
367
621k
  {
368
621k
    ::memset( buf, val, width * height * sizeof( T ) );
369
621k
  }
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
621k
  GCC_WARNING_RESET
381
621k
}
vvenc::AreaBuf<vvenc::LoopFilterParam>::memset(int)
Line
Count
Source
364
7.14k
{
365
7.14k
  GCC_WARNING_DISABLE_class_memaccess
366
7.14k
  if( width == stride )
367
1.82k
  {
368
1.82k
    ::memset( buf, val, width * height * sizeof( T ) );
369
1.82k
  }
370
5.32k
  else
371
5.32k
  {
372
5.32k
    T* dest = buf;
373
5.32k
    size_t line = width * sizeof( T );
374
375
124k
    for( int y = 0; y < height; y++, dest += stride )
376
118k
    {
377
118k
      ::memset( dest, val, line );
378
118k
    }
379
5.32k
  }
380
7.14k
  GCC_WARNING_RESET
381
7.14k
}
vvenc::AreaBuf<short>::memset(int)
Line
Count
Source
364
5.62k
{
365
5.62k
  GCC_WARNING_DISABLE_class_memaccess
366
5.62k
  if( width == stride )
367
5.62k
  {
368
5.62k
    ::memset( buf, val, width * height * sizeof( T ) );
369
5.62k
  }
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.62k
  GCC_WARNING_RESET
381
5.62k
}
382
383
template<typename T>
384
void AreaBuf<T>::copyFrom( const AreaBuf<const T>& other )
385
8.16M
{
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.16M
  g_pelBufOP.copyBuffer( ( const char* ) other.buf, other.stride * sizeof( T ), ( char* ) buf, stride * sizeof( T ), width * sizeof( T ), height );
391
8.16M
}
vvenc::AreaBuf<vvenc::MotionInfo>::copyFrom(vvenc::AreaBuf<vvenc::MotionInfo const> const&)
Line
Count
Source
385
49.1k
{
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
49.1k
  g_pelBufOP.copyBuffer( ( const char* ) other.buf, other.stride * sizeof( T ), ( char* ) buf, stride * sizeof( T ), width * sizeof( T ), height );
391
49.1k
}
vvenc::AreaBuf<short>::copyFrom(vvenc::AreaBuf<short const> const&)
Line
Count
Source
385
8.11M
{
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.11M
  g_pelBufOP.copyBuffer( ( const char* ) other.buf, other.stride * sizeof( T ), ( char* ) buf, stride * sizeof( T ), width * sizeof( T ), height );
391
8.11M
}
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.1k
{
499
12.1k
  T* p = buf + y * stride;
500
12.1k
  int h = size + y;
501
502
  // do left and right margins
503
692k
  for (; y < h; y++)
504
680k
  {
505
29.0M
    for (int x = 0; x < margin; x++)
506
28.4M
    {
507
28.4M
      *(p - margin + x) = p[0];
508
28.4M
    }
509
680k
    p += stride;
510
680k
  }
511
12.1k
}
512
513
template<typename T>
514
void AreaBuf<T>::extendBorderPelTop( int x, int size, int margin )
515
9.43k
{
516
9.43k
  T* p = buf + x;
517
518
  // p is now (-marginX, 0)
519
361k
  for (int y = 0; y < margin; y++)
520
351k
  {
521
351k
    ::memcpy(p - (y + 1) * stride, p, sizeof(T) * size);
522
351k
  }
523
9.43k
}
524
525
template<typename T>
526
void AreaBuf<T>::extendBorderPelRgt( int y, int size, int margin )
527
12.1k
{
528
12.1k
  T* p = buf + y * stride;
529
12.1k
  int h = size + y;
530
531
  // do left and right margins
532
704k
  for( ; y < h; y++)
533
692k
  {
534
33.5M
    for (int x = 0; x < margin; x++)
535
32.8M
    {
536
32.8M
      p[width + x] = p[width - 1];
537
32.8M
    }
538
692k
    p += stride;
539
692k
  }
540
12.1k
}
541
542
template<typename T>
543
void AreaBuf<T>::extendBorderPelBot( int x, int size, int margin )
544
9.43k
{
545
9.43k
  T* p = buf + (height-1)*stride + x;
546
547
  // p is now the (-margin, height-1)
548
361k
  for (int y = 0; y < margin; y++)
549
351k
  {
550
351k
    ::memcpy(p + (y + 1) * stride, p, sizeof(T) * size);
551
351k
  }
552
9.43k
}
553
554
template<typename T>
555
void AreaBuf<T>::extendBorderPel(unsigned marginX, unsigned marginY)
556
3.49k
{
557
3.49k
  T* p = buf;
558
3.49k
  int h = height;
559
3.49k
  int w = width;
560
3.49k
  int s = stride;
561
562
3.49k
  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
34.0M
    for (int x = 0; x < marginX; x++)
567
33.7M
    {
568
33.7M
      *(p - marginX + x) = p[0];
569
33.7M
      p[w + x] = p[w - 1];
570
33.7M
    }
571
351k
    p += s;
572
351k
  }
573
574
  // p is now the (0,height) (bottom left of image within bigger picture
575
3.49k
  p -= (s + marginX);
576
  // p is now the (-margin, height-1)
577
301k
  for (int y = 0; y < marginY; y++)
578
298k
  {
579
298k
    ::memcpy(p + (y + 1) * s, p, sizeof(T) * (w + (marginX << 1)));
580
298k
  }
581
582
  // p is still (-marginX, height-1)
583
3.49k
  p -= ((h - 1) * s);
584
  // p is now (-marginX, 0)
585
301k
  for (int y = 0; y < marginY; y++)
586
298k
  {
587
298k
    ::memcpy(p - (y + 1) * s, p, sizeof(T) * (w + (marginX << 1)));
588
298k
  }
589
3.49k
}
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
4.51M
  UnitBuf() : chromaFormat( NUM_CHROMA_FORMAT ) { }
vvenc::UnitBuf<short>::UnitBuf()
Line
Count
Source
695
4.51M
  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.57k
  UnitBuf( const ChromaFormat _chromaFormat, const AreaBuf<T>&  blkY, const AreaBuf<T>&  blkCb, const AreaBuf<T>  &blkCr ) : chromaFormat( _chromaFormat ), bufs{ blkY, blkCb, blkCr } { }
701
583k
  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
583k
  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
69.2k
  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
301k
  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
8.01M
        AreaBuf<T>& get( const ComponentID comp )        { return bufs[comp]; }
713
60.2k
  const AreaBuf<T>& get( const ComponentID comp )  const { return bufs[comp]; }
vvenc::UnitBuf<short>::get(vvenc::ComponentID) const
Line
Count
Source
713
53.1k
  const AreaBuf<T>& get( const ComponentID comp )  const { return bufs[comp]; }
vvenc::UnitBuf<short const>::get(vvenc::ComponentID) const
Line
Count
Source
713
7.06k
  const AreaBuf<T>& get( const ComponentID comp )  const { return bufs[comp]; }
714
715
1.62M
        AreaBuf<T>& Y()        { return bufs[0]; }
vvenc::UnitBuf<short>::Y()
Line
Count
Source
715
1.62M
        AreaBuf<T>& Y()        { return bufs[0]; }
Unexecuted instantiation: vvenc::UnitBuf<short const>::Y()
716
3.49k
  const AreaBuf<T>& Y()  const { return bufs[0]; }
717
544k
        AreaBuf<T>& Cb()       { return bufs[1]; }
718
  const AreaBuf<T>& Cb() const { return bufs[1]; }
719
544k
        AreaBuf<T>& Cr()       { return bufs[2]; }
720
  const AreaBuf<T>& Cr() const { return bufs[2]; }
721
170k
  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
404k
{
762
404k
  CHECK( chromaFormat != other.chromaFormat, "Incompatible formats" );
763
404k
  CHECK( !luma && !chroma, "At least one channel has to be selected" );
764
765
404k
  const size_t compStart = luma   ? 0           : 1;
766
18.4E
  const size_t compEnd   = chroma ? bufs.size() : 1;
767
768
1.61M
  for( size_t i = compStart; i < compEnd; i++ )
769
1.21M
  {
770
1.21M
    if( bufs[ i ].buf != nullptr && other.bufs[ i ].buf != nullptr )
771
818k
      bufs[i].copyFrom( other.bufs[i] );
772
1.21M
  }
773
404k
}
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.14k
{
844
12.5k
  for( int i = 0; i < bufs.size(); i++ )
845
9.43k
  {
846
9.43k
    int csx = getComponentScaleX(ComponentID(i), chromaFormat);
847
9.43k
    int csy = getComponentScaleY(ComponentID(i), chromaFormat);
848
9.43k
    bufs[i].extendBorderPelTop( x>>csx, size>>csx, margin>>csy );
849
9.43k
  }
850
3.14k
}
851
852
template<typename T>
853
void UnitBuf<T>::extendBorderPelBot   ( int x, int size, int margin )
854
3.14k
{
855
12.5k
  for( int i = 0; i < bufs.size(); i++ )
856
9.43k
  {
857
9.43k
    int csx = getComponentScaleX(ComponentID(i), chromaFormat);
858
9.43k
    int csy = getComponentScaleY(ComponentID(i), chromaFormat);
859
9.43k
    bufs[i].extendBorderPelBot( x>>csx, size>>csx, margin>>csy );
860
9.43k
  }
861
3.14k
}
862
863
template<typename T>
864
void UnitBuf<T>::extendBorderPelLft   ( int y, int size, int margin )
865
4.06k
{
866
16.2k
  for( int i = 0; i < bufs.size(); i++ )
867
12.1k
  {
868
12.1k
    int csx = getComponentScaleX(ComponentID(i), chromaFormat);
869
12.1k
    int csy = getComponentScaleY(ComponentID(i), chromaFormat);
870
12.1k
    bufs[i].extendBorderPelLft( y>>csy, size>>csy, margin>>csx );
871
12.1k
  }
872
4.06k
}
873
874
template<typename T>
875
void UnitBuf<T>::extendBorderPelRgt   ( int y, int size, int margin )
876
4.06k
{
877
16.2k
  for( int i = 0; i < bufs.size(); i++ )
878
12.1k
  {
879
12.1k
    int csx = getComponentScaleX(ComponentID(i), chromaFormat);
880
12.1k
    int csy = getComponentScaleY(ComponentID(i), chromaFormat);
881
12.1k
    bufs[i].extendBorderPelRgt( y>>csy, size>>csy, margin>>csx );
882
12.1k
  }
883
4.06k
}
884
885
template<typename T>
886
void UnitBuf<T>::extendBorderPel( unsigned margin, bool scaleMargin )
887
1.16k
{
888
1.16k
  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.16k
  else
896
1.16k
  {
897
4.66k
    for ( int i = 0; i < bufs.size(); i++)
898
3.49k
    {
899
3.49k
      bufs[i].extendBorderPel(margin >> getComponentScaleX(ComponentID(i), chromaFormat), margin >> getComponentScaleY(ComponentID(i), chromaFormat));
900
3.49k
    }
901
1.16k
  }
902
1.16k
}
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
7.14k
{
922
7.14k
  UnitBuf<T> subBuf;
923
7.14k
  subBuf.chromaFormat = chromaFormat;
924
7.14k
  unsigned blockIdx = 0;
925
926
7.14k
  for( auto &subAreaBuf : bufs )
927
21.4k
  {
928
21.4k
    subBuf.bufs.push_back( subAreaBuf.subBuf( subArea.blocks[blockIdx].pos(), subArea.blocks[blockIdx].size() ) );
929
21.4k
    blockIdx++;
930
21.4k
  }
931
932
7.14k
  return subBuf;
933
7.14k
}
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
37.3k
               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
335k
  ~CompStorage() { if( valid() ) delete[] m_memory; }
1004
1005
  void compactResize( const Size& size )
1006
2.72M
  {
1007
2.72M
    CHECK( size.area() > m_allocSize, "Resizing causes buffer overflow!" );
1008
2.72M
    Size::operator=( size );
1009
2.72M
    stride = size.width;
1010
2.72M
  }
1011
  void create( const Size& size )
1012
335k
  {
1013
335k
    CHECK( m_memory, "Trying to re-create an already initialized buffer" );
1014
335k
    m_allocSize = size.area();
1015
335k
    m_memory = new Pel[m_allocSize];
1016
335k
    PelBuf::operator=( PelBuf( m_memory, size ) );
1017
335k
  }
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
851k
  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
18.6k
  {
1035
18.6k
    m_pacBufs.resize(NumEntries + 1);
1036
18.6k
    m_acStorage.resize(NumEntries + 1);
1037
205k
    for (size_t i = 0; i <= NumEntries; i++)
1038
186k
    {
1039
186k
      m_acStorage[i].create(cform, Area(0, 0, maxWidth, maxHeight));
1040
186k
    }
1041
18.6k
  }
1042
1043
  void destroy()
1044
18.6k
  {
1045
205k
    for (size_t i = 0; i <= NumEntries; i++)
1046
186k
    {
1047
186k
      m_acStorage[i].destroy();
1048
186k
    }
1049
18.6k
  }
1050
1051
  void reset()
1052
  {
1053
    m_sortedList.clear();
1054
  }
1055
1056
  void reduceTo(int numModes)
1057
18.4k
  {
1058
18.4k
    CHECK( numModes > m_sortedList.size(), "not enough buffers");
1059
18.4k
    m_sortedList.resize(numModes);
1060
18.4k
  }
1061
1062
  void prepare( const UnitArea& ua, int numModes)
1063
24.0k
  {
1064
24.0k
    CHECK( numModes > NumEntries, "not enough buffers");
1065
24.0k
    m_sortedList.resize(numModes);
1066
114k
    for (size_t i = 0; i < numModes; i++)
1067
90.6k
    {
1068
90.6k
      m_pacBufs[i] = m_acStorage[i].getCompactBuf(ua);
1069
90.6k
      m_sortedList[i] = &m_pacBufs[i];
1070
90.6k
    }
1071
1072
24.0k
    m_pacBufs[numModes] = m_acStorage[numModes].getCompactBuf(ua);
1073
24.0k
    m_TestBuf = &m_pacBufs[numModes];
1074
24.0k
  }
1075
1076
110k
  PelUnitBuf* getBufFromSortedList( int idx)              const { return m_sortedList.size() > idx ? m_sortedList[idx]: nullptr; }
1077
24.0k
  PelBuf&     getTestBuf          ( ComponentID compId)   const { return m_TestBuf->bufs[compId]; }
1078
900k
  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
900k
  {
1089
900k
    if (insertPos != -1)
1090
128k
    {
1091
140k
      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
128k
      std::swap(m_TestBuf, m_sortedList[insertPos]);
1096
128k
    }
1097
900k
  }
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