Coverage Report

Created: 2026-05-30 06:10

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