Coverage Report

Created: 2026-08-13 07:23

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.96M
#define INCY( ptr, stride ) { ptr += ( stride ); }
88
12.1M
#define OFFSETX( ptr, stride, x ) { ptr += ( x ); }
89
1.11M
#define OFFSETY( ptr, stride, y ) { ptr += ( y ) * ( stride ); }
90
2.11M
#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
18.1M
  AreaBuf()                                                                               : Size(),                  buf( NULL ), stride( 0 )          { }
vvenc::AreaBuf<short>::AreaBuf()
Line
Count
Source
155
17.0M
  AreaBuf()                                                                               : Size(),                  buf( NULL ), stride( 0 )          { }
vvenc::AreaBuf<short const>::AreaBuf()
Line
Count
Source
155
1.05M
  AreaBuf()                                                                               : Size(),                  buf( NULL ), stride( 0 )          { }
Unexecuted instantiation: vvenc::AreaBuf<int>::AreaBuf()
Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo>::AreaBuf()
156
7.45M
  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.72M
  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.88M
  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.68k
  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.83M
  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
22.0M
  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
21.2M
  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
39.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
771k
  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.68k
  AreaBuf( T *_buf, const int& _stride, const Size& size )                                : Size( size ),            buf( _buf ), stride( _stride )    { }
158
1.80M
  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
47.9k
  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.76M
  AreaBuf( T *_buf, const SizeType& _width, const SizeType& _height )                     : Size( _width, _height ), buf( _buf ), stride( _width )     { }
159
10.2M
  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.67M
  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
606k
  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.9M
  AreaBuf( const AreaBuf<typename std::remove_const_t<T>>& other, std::enable_if_t<T_IS_CONST>* = 0) : Size( other ), buf( other.buf ), stride( other.stride ) { }
vvenc::AreaBuf<short const>::AreaBuf<true>(vvenc::AreaBuf<short> const&, std::__1::enable_if<true, void>::type*)
Line
Count
Source
168
23.1M
  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
52.3k
  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.80M
  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
267M
        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
267M
        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.84G
  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.84G
  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.36M
  const T& at( const int& x, const int& y ) const    { return buf[y * stride + x]; }
200
201
2.17M
        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.16M
        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.68k
        T& at( const Position& pos )                 { return buf[pos.y * stride + pos.x]; }
202
34.5k
  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
11.5k
  const T& at( const Position& pos ) const           { return buf[pos.y * stride + pos.x]; }
vvenc::AreaBuf<short>::at(vvenc::Position const&) const
Line
Count
Source
202
22.9k
  const T& at( const Position& pos ) const           { return buf[pos.y * stride + pos.x]; }
203
204
205
11.3k
        T* bufAt( const int& x, const int& y )       { return &at( x, y ); }
206
177k
  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
177k
  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.17M
        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.16M
        T* bufAt( const Position& pos )              { return &at( pos ); }
vvenc::AreaBuf<vvenc::LoopFilterParam>::bufAt(vvenc::Position const&)
Line
Count
Source
208
7.68k
        T* bufAt( const Position& pos )              { return &at( pos ); }
209
34.5k
  const T* bufAt( const Position& pos ) const        { return &at( pos ); }
vvenc::AreaBuf<short const>::bufAt(vvenc::Position const&) const
Line
Count
Source
209
11.5k
  const T* bufAt( const Position& pos ) const        { return &at( pos ); }
vvenc::AreaBuf<short>::bufAt(vvenc::Position const&) const
Line
Count
Source
209
22.9k
  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
30.7k
  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
23.0k
  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.68k
  AreaBuf<      T> subBuf( const Position& pos, const Size& size )                                    { return AreaBuf<      T>( bufAt( pos  ), stride, size   ); }
214
11.5k
  AreaBuf<const T> subBuf( const Position& pos, const Size& size )                              const { return AreaBuf<const T>( bufAt( pos  ), stride, size   ); }
vvenc::AreaBuf<short const>::subBuf(vvenc::Position const&, vvenc::Size const&) const
Line
Count
Source
214
11.5k
  AreaBuf<const T> subBuf( const Position& pos, const Size& size )                              const { return AreaBuf<const T>( bufAt( pos  ), stride, size   ); }
Unexecuted instantiation: vvenc::AreaBuf<short>::subBuf(vvenc::Position const&, vvenc::Size const&) const
215
0
  AreaBuf<      T> subBuf( const int& x, const int& y, const unsigned& _w, const unsigned& _h )       { return AreaBuf<      T>( bufAt( x, y ), stride, _w, _h ); }
216
  AreaBuf<const T> subBuf( const int& x, const int& y, const unsigned& _w, const unsigned& _h ) const { return AreaBuf<const T>( bufAt( x, y ), stride, _w, _h ); }
217
};
218
219
typedef AreaBuf<      Pel>  PelBuf;
220
typedef AreaBuf<const Pel> CPelBuf;
221
222
typedef AreaBuf<      TCoeff>  CoeffBuf;
223
typedef AreaBuf<const TCoeff> CCoeffBuf;
224
225
typedef AreaBuf<      TCoeffSig>  CoeffSigBuf;
226
typedef AreaBuf<const TCoeffSig> CCoeffSigBuf;
227
228
typedef AreaBuf<      MotionInfo>  MotionBuf;
229
typedef AreaBuf<const MotionInfo> CMotionBuf;
230
231
typedef AreaBuf<      TCoeff>  PLTescapeBuf;
232
typedef AreaBuf<const TCoeff> CPLTescapeBuf;
233
234
typedef AreaBuf<      bool>  PLTtypeBuf;
235
typedef AreaBuf<const bool> CPLTtypeBuf;
236
237
typedef AreaBuf<      LoopFilterParam>  LFPBuf;
238
typedef AreaBuf<const LoopFilterParam> CLFPBuf;
239
240
5.20M
#define SIZE_AWARE_PER_EL_OP( OP, INC )                     \
241
5.20M
if( ( width & 7 ) == 0 )                                    \
242
4.21M
{                                                           \
243
67.8M
  for( int y = 0; y < height; y++ )                         \
244
63.6M
  {                                                         \
245
255M
    for( int x = 0; x < width; x += 8 )                     \
246
191M
    {                                                       \
247
191M
      OP( x + 0 );                                          \
248
191M
      OP( x + 1 );                                          \
249
191M
      OP( x + 2 );                                          \
250
191M
      OP( x + 3 );                                          \
251
191M
      OP( x + 4 );                                          \
252
191M
      OP( x + 5 );                                          \
253
191M
      OP( x + 6 );                                          \
254
191M
      OP( x + 7 );                                          \
255
191M
    }                                                       \
256
63.6M
                                                            \
257
63.6M
    INC;                                                    \
258
63.6M
  }                                                         \
259
4.21M
}                                                           \
260
5.20M
else if( ( width & 3 ) == 0 )                               \
261
990k
{                                                           \
262
12.0M
  for( int y = 0; y < height; y++ )                         \
263
11.0M
  {                                                         \
264
24.9M
    for( int x = 0; x < width; x += 4 )                     \
265
13.8M
    {                                                       \
266
13.8M
      OP( x + 0 );                                          \
267
13.8M
      OP( x + 1 );                                          \
268
13.8M
      OP( x + 2 );                                          \
269
13.8M
      OP( x + 3 );                                          \
270
13.8M
    }                                                       \
271
11.0M
                                                            \
272
11.0M
    INC;                                                    \
273
11.0M
  }                                                         \
274
990k
}                                                           \
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
25.4k
{
305
25.4k
  const T* src = buf;
306
25.4k
  int64_t  acc = 0;
307
308
25.4k
#define AVG_INC      src += stride
309
104M
#define AVG_OP(ADDR) acc += src[ADDR]
310
104M
  SIZE_AWARE_PER_EL_OP(AVG_OP, AVG_INC);
311
25.4k
#undef AVG_INC
312
25.4k
#undef AVG_OP
313
314
25.4k
  return T ((acc + (area() >> 1)) / area());
315
25.4k
}
vvenc::AreaBuf<short const>::getAvg() const
Line
Count
Source
304
24.2k
{
305
24.2k
  const T* src = buf;
306
24.2k
  int64_t  acc = 0;
307
308
24.2k
#define AVG_INC      src += stride
309
24.2k
#define AVG_OP(ADDR) acc += src[ADDR]
310
24.2k
  SIZE_AWARE_PER_EL_OP(AVG_OP, AVG_INC);
311
24.2k
#undef AVG_INC
312
24.2k
#undef AVG_OP
313
314
24.2k
  return T ((acc + (area() >> 1)) / area());
315
24.2k
}
vvenc::AreaBuf<short>::getAvg() const
Line
Count
Source
304
1.20k
{
305
1.20k
  const T* src = buf;
306
1.20k
  int64_t  acc = 0;
307
308
1.20k
#define AVG_INC      src += stride
309
1.20k
#define AVG_OP(ADDR) acc += src[ADDR]
310
1.20k
  SIZE_AWARE_PER_EL_OP(AVG_OP, AVG_INC);
311
1.20k
#undef AVG_INC
312
1.20k
#undef AVG_OP
313
314
1.20k
  return T ((acc + (area() >> 1)) / area());
315
1.20k
}
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.75M
{
323
1.75M
  if( T( 0 ) == val )
324
1.64M
  {
325
1.64M
    GCC_WARNING_DISABLE_class_memaccess
326
1.64M
    if( width == stride )
327
1.64M
    {
328
1.64M
      ::memset( buf, 0, width * height * sizeof( T ) );
329
1.64M
    }
330
3.59k
    else
331
3.59k
    {
332
3.59k
      T* dest = buf;
333
3.59k
      size_t line = width * sizeof( T );
334
335
129k
      for( unsigned y = 0; y < height; y++ )
336
125k
      {
337
125k
        ::memset( dest, 0, line );
338
339
125k
        dest += stride;
340
125k
      }
341
3.59k
    }
342
1.64M
    GCC_WARNING_RESET
343
1.64M
  }
344
113k
  else
345
113k
  {
346
113k
    if( width == stride )
347
113k
    {
348
113k
      std::fill_n( buf, width * height, val );
349
113k
    }
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
113k
  }
360
1.75M
}
361
362
template<typename T>
363
void AreaBuf<T>::memset( const int val )
364
653k
{
365
653k
  GCC_WARNING_DISABLE_class_memaccess
366
653k
  if( width == stride )
367
648k
  {
368
648k
    ::memset( buf, val, width * height * sizeof( T ) );
369
648k
  }
370
5.85k
  else
371
5.85k
  {
372
5.85k
    T* dest = buf;
373
5.85k
    size_t line = width * sizeof( T );
374
375
137k
    for( int y = 0; y < height; y++, dest += stride )
376
131k
    {
377
131k
      ::memset( dest, val, line );
378
131k
    }
379
5.85k
  }
380
653k
  GCC_WARNING_RESET
381
653k
}
vvenc::AreaBuf<vvenc::MotionInfo>::memset(int)
Line
Count
Source
364
640k
{
365
640k
  GCC_WARNING_DISABLE_class_memaccess
366
640k
  if( width == stride )
367
640k
  {
368
640k
    ::memset( buf, val, width * height * sizeof( T ) );
369
640k
  }
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
640k
  GCC_WARNING_RESET
381
640k
}
vvenc::AreaBuf<vvenc::LoopFilterParam>::memset(int)
Line
Count
Source
364
7.68k
{
365
7.68k
  GCC_WARNING_DISABLE_class_memaccess
366
7.68k
  if( width == stride )
367
1.83k
  {
368
1.83k
    ::memset( buf, val, width * height * sizeof( T ) );
369
1.83k
  }
370
5.85k
  else
371
5.85k
  {
372
5.85k
    T* dest = buf;
373
5.85k
    size_t line = width * sizeof( T );
374
375
137k
    for( int y = 0; y < height; y++, dest += stride )
376
131k
    {
377
131k
      ::memset( dest, val, line );
378
131k
    }
379
5.85k
  }
380
7.68k
  GCC_WARNING_RESET
381
7.68k
}
vvenc::AreaBuf<short>::memset(int)
Line
Count
Source
364
5.76k
{
365
5.76k
  GCC_WARNING_DISABLE_class_memaccess
366
5.76k
  if( width == stride )
367
5.76k
  {
368
5.76k
    ::memset( buf, val, width * height * sizeof( T ) );
369
5.76k
  }
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.76k
  GCC_WARNING_RESET
381
5.76k
}
382
383
template<typename T>
384
void AreaBuf<T>::copyFrom( const AreaBuf<const T>& other )
385
8.48M
{
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.48M
  g_pelBufOP.copyBuffer( ( const char* ) other.buf, other.stride * sizeof( T ), ( char* ) buf, stride * sizeof( T ), width * sizeof( T ), height );
391
8.48M
}
vvenc::AreaBuf<vvenc::MotionInfo>::copyFrom(vvenc::AreaBuf<vvenc::MotionInfo const> const&)
Line
Count
Source
385
52.3k
{
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
52.3k
  g_pelBufOP.copyBuffer( ( const char* ) other.buf, other.stride * sizeof( T ), ( char* ) buf, stride * sizeof( T ), width * sizeof( T ), height );
391
52.3k
}
vvenc::AreaBuf<short>::copyFrom(vvenc::AreaBuf<short const> const&)
Line
Count
Source
385
8.43M
{
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.43M
  g_pelBufOP.copyBuffer( ( const char* ) other.buf, other.stride * sizeof( T ), ( char* ) buf, stride * sizeof( T ), width * sizeof( T ), height );
391
8.43M
}
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.8k
{
499
12.8k
  T* p = buf + y * stride;
500
12.8k
  int h = size + y;
501
502
  // do left and right margins
503
727k
  for (; y < h; y++)
504
715k
  {
505
30.3M
    for (int x = 0; x < margin; x++)
506
29.6M
    {
507
29.6M
      *(p - margin + x) = p[0];
508
29.6M
    }
509
715k
    p += stride;
510
715k
  }
511
12.8k
}
512
513
template<typename T>
514
void AreaBuf<T>::extendBorderPelTop( int x, int size, int margin )
515
9.82k
{
516
9.82k
  T* p = buf + x;
517
518
  // p is now (-marginX, 0)
519
372k
  for (int y = 0; y < margin; y++)
520
362k
  {
521
362k
    ::memcpy(p - (y + 1) * stride, p, sizeof(T) * size);
522
362k
  }
523
9.82k
}
524
525
template<typename T>
526
void AreaBuf<T>::extendBorderPelRgt( int y, int size, int margin )
527
12.8k
{
528
12.8k
  T* p = buf + y * stride;
529
12.8k
  int h = size + y;
530
531
  // do left and right margins
532
739k
  for( ; y < h; y++)
533
726k
  {
534
34.4M
    for (int x = 0; x < margin; x++)
535
33.7M
    {
536
33.7M
      p[width + x] = p[width - 1];
537
33.7M
    }
538
726k
    p += stride;
539
726k
  }
540
12.8k
}
541
542
template<typename T>
543
void AreaBuf<T>::extendBorderPelBot( int x, int size, int margin )
544
9.82k
{
545
9.82k
  T* p = buf + (height-1)*stride + x;
546
547
  // p is now the (-margin, height-1)
548
372k
  for (int y = 0; y < margin; y++)
549
362k
  {
550
362k
    ::memcpy(p + (y + 1) * stride, p, sizeof(T) * size);
551
362k
  }
552
9.82k
}
553
554
template<typename T>
555
void AreaBuf<T>::extendBorderPel(unsigned marginX, unsigned marginY)
556
3.60k
{
557
3.60k
  T* p = buf;
558
3.60k
  int h = height;
559
3.60k
  int w = width;
560
3.60k
  int s = stride;
561
562
3.60k
  CHECK((w + 2 * marginX) > s, "Size of buffer too small to extend");
563
  // do left and right margins
564
373k
  for (int y = 0; y < h; y++)
565
369k
  {
566
35.8M
    for (int x = 0; x < marginX; x++)
567
35.5M
    {
568
35.5M
      *(p - marginX + x) = p[0];
569
35.5M
      p[w + x] = p[w - 1];
570
35.5M
    }
571
369k
    p += s;
572
369k
  }
573
574
  // p is now the (0,height) (bottom left of image within bigger picture
575
3.60k
  p -= (s + marginX);
576
  // p is now the (-margin, height-1)
577
310k
  for (int y = 0; y < marginY; y++)
578
307k
  {
579
307k
    ::memcpy(p + (y + 1) * s, p, sizeof(T) * (w + (marginX << 1)));
580
307k
  }
581
582
  // p is still (-marginX, height-1)
583
3.60k
  p -= ((h - 1) * s);
584
  // p is now (-marginX, 0)
585
310k
  for (int y = 0; y < marginY; y++)
586
307k
  {
587
307k
    ::memcpy(p - (y + 1) * s, p, sizeof(T) * (w + (marginX << 1)));
588
307k
  }
589
3.60k
}
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.64M
  UnitBuf() : chromaFormat( NUM_CHROMA_FORMAT ) { }
vvenc::UnitBuf<short>::UnitBuf()
Line
Count
Source
695
4.64M
  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.84k
  UnitBuf( const ChromaFormat _chromaFormat, const AreaBuf<T>&  blkY, const AreaBuf<T>&  blkCb, const AreaBuf<T>  &blkCr ) : chromaFormat( _chromaFormat ), bufs{ blkY, blkCb, blkCr } { }
701
615k
  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
615k
  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
73.8k
  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
317k
  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.31M
        AreaBuf<T>& get( const ComponentID comp )        { return bufs[comp]; }
713
64.5k
  const AreaBuf<T>& get( const ComponentID comp )  const { return bufs[comp]; }
vvenc::UnitBuf<short>::get(vvenc::ComponentID) const
Line
Count
Source
713
57.2k
  const AreaBuf<T>& get( const ComponentID comp )  const { return bufs[comp]; }
vvenc::UnitBuf<short const>::get(vvenc::ComponentID) const
Line
Count
Source
713
7.25k
  const AreaBuf<T>& get( const ComponentID comp )  const { return bufs[comp]; }
714
715
1.70M
        AreaBuf<T>& Y()        { return bufs[0]; }
vvenc::UnitBuf<short>::Y()
Line
Count
Source
715
1.70M
        AreaBuf<T>& Y()        { return bufs[0]; }
Unexecuted instantiation: vvenc::UnitBuf<short const>::Y()
716
3.60k
  const AreaBuf<T>& Y()  const { return bufs[0]; }
717
575k
        AreaBuf<T>& Cb()       { return bufs[1]; }
718
  const AreaBuf<T>& Cb() const { return bufs[1]; }
719
575k
        AreaBuf<T>& Cr()       { return bufs[2]; }
720
  const AreaBuf<T>& Cr() const { return bufs[2]; }
721
179k
  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
426k
{
762
426k
  CHECK( chromaFormat != other.chromaFormat, "Incompatible formats" );
763
426k
  CHECK( !luma && !chroma, "At least one channel has to be selected" );
764
765
18.4E
  const size_t compStart = luma   ? 0           : 1;
766
18.4E
  const size_t compEnd   = chroma ? bufs.size() : 1;
767
768
1.70M
  for( size_t i = compStart; i < compEnd; i++ )
769
1.27M
  {
770
1.27M
    if( bufs[ i ].buf != nullptr && other.bufs[ i ].buf != nullptr )
771
862k
      bufs[i].copyFrom( other.bufs[i] );
772
1.27M
  }
773
426k
}
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.27k
{
844
13.0k
  for( int i = 0; i < bufs.size(); i++ )
845
9.82k
  {
846
9.82k
    int csx = getComponentScaleX(ComponentID(i), chromaFormat);
847
9.82k
    int csy = getComponentScaleY(ComponentID(i), chromaFormat);
848
9.82k
    bufs[i].extendBorderPelTop( x>>csx, size>>csx, margin>>csy );
849
9.82k
  }
850
3.27k
}
851
852
template<typename T>
853
void UnitBuf<T>::extendBorderPelBot   ( int x, int size, int margin )
854
3.27k
{
855
13.0k
  for( int i = 0; i < bufs.size(); i++ )
856
9.82k
  {
857
9.82k
    int csx = getComponentScaleX(ComponentID(i), chromaFormat);
858
9.82k
    int csy = getComponentScaleY(ComponentID(i), chromaFormat);
859
9.82k
    bufs[i].extendBorderPelBot( x>>csx, size>>csx, margin>>csy );
860
9.82k
  }
861
3.27k
}
862
863
template<typename T>
864
void UnitBuf<T>::extendBorderPelLft   ( int y, int size, int margin )
865
4.27k
{
866
17.0k
  for( int i = 0; i < bufs.size(); i++ )
867
12.8k
  {
868
12.8k
    int csx = getComponentScaleX(ComponentID(i), chromaFormat);
869
12.8k
    int csy = getComponentScaleY(ComponentID(i), chromaFormat);
870
12.8k
    bufs[i].extendBorderPelLft( y>>csy, size>>csy, margin>>csx );
871
12.8k
  }
872
4.27k
}
873
874
template<typename T>
875
void UnitBuf<T>::extendBorderPelRgt   ( int y, int size, int margin )
876
4.27k
{
877
17.0k
  for( int i = 0; i < bufs.size(); i++ )
878
12.8k
  {
879
12.8k
    int csx = getComponentScaleX(ComponentID(i), chromaFormat);
880
12.8k
    int csy = getComponentScaleY(ComponentID(i), chromaFormat);
881
12.8k
    bufs[i].extendBorderPelRgt( y>>csy, size>>csy, margin>>csx );
882
12.8k
  }
883
4.27k
}
884
885
template<typename T>
886
void UnitBuf<T>::extendBorderPel( unsigned margin, bool scaleMargin )
887
1.20k
{
888
1.20k
  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.20k
  else
896
1.20k
  {
897
4.80k
    for ( int i = 0; i < bufs.size(); i++)
898
3.60k
    {
899
3.60k
      bufs[i].extendBorderPel(margin >> getComponentScaleX(ComponentID(i), chromaFormat), margin >> getComponentScaleY(ComponentID(i), chromaFormat));
900
3.60k
    }
901
1.20k
  }
902
1.20k
}
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.68k
{
922
7.68k
  UnitBuf<T> subBuf;
923
7.68k
  subBuf.chromaFormat = chromaFormat;
924
7.68k
  unsigned blockIdx = 0;
925
926
7.68k
  for( auto &subAreaBuf : bufs )
927
23.0k
  {
928
23.0k
    subBuf.bufs.push_back( subAreaBuf.subBuf( subArea.blocks[blockIdx].pos(), subArea.blocks[blockIdx].size() ) );
929
23.0k
    blockIdx++;
930
23.0k
  }
931
932
7.68k
  return subBuf;
933
7.68k
}
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
38.4k
               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
345k
  ~CompStorage() { if( valid() ) delete[] m_memory; }
1004
1005
  void compactResize( const Size& size )
1006
2.82M
  {
1007
2.82M
    CHECK( size.area() > m_allocSize, "Resizing causes buffer overflow!" );
1008
2.82M
    Size::operator=( size );
1009
2.82M
    stride = size.width;
1010
2.82M
  }
1011
  void create( const Size& size )
1012
345k
  {
1013
345k
    CHECK( m_memory, "Trying to re-create an already initialized buffer" );
1014
345k
    m_allocSize = size.area();
1015
345k
    m_memory = new Pel[m_allocSize];
1016
345k
    PelBuf::operator=( PelBuf( m_memory, size ) );
1017
345k
  }
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
875k
  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
19.2k
  {
1035
19.2k
    m_pacBufs.resize(NumEntries + 1);
1036
19.2k
    m_acStorage.resize(NumEntries + 1);
1037
211k
    for (size_t i = 0; i <= NumEntries; i++)
1038
192k
    {
1039
192k
      m_acStorage[i].create(cform, Area(0, 0, maxWidth, maxHeight));
1040
192k
    }
1041
19.2k
  }
1042
1043
  void destroy()
1044
19.2k
  {
1045
211k
    for (size_t i = 0; i <= NumEntries; i++)
1046
192k
    {
1047
192k
      m_acStorage[i].destroy();
1048
192k
    }
1049
19.2k
  }
1050
1051
  void reset()
1052
  {
1053
    m_sortedList.clear();
1054
  }
1055
1056
  void reduceTo(int numModes)
1057
19.3k
  {
1058
19.3k
    CHECK( numModes > m_sortedList.size(), "not enough buffers");
1059
19.3k
    m_sortedList.resize(numModes);
1060
19.3k
  }
1061
1062
  void prepare( const UnitArea& ua, int numModes)
1063
25.4k
  {
1064
25.4k
    CHECK( numModes > NumEntries, "not enough buffers");
1065
25.4k
    m_sortedList.resize(numModes);
1066
121k
    for (size_t i = 0; i < numModes; i++)
1067
95.6k
    {
1068
95.6k
      m_pacBufs[i] = m_acStorage[i].getCompactBuf(ua);
1069
95.6k
      m_sortedList[i] = &m_pacBufs[i];
1070
95.6k
    }
1071
1072
25.4k
    m_pacBufs[numModes] = m_acStorage[numModes].getCompactBuf(ua);
1073
25.4k
    m_TestBuf = &m_pacBufs[numModes];
1074
25.4k
  }
1075
1076
116k
  PelUnitBuf* getBufFromSortedList( int idx)              const { return m_sortedList.size() > idx ? m_sortedList[idx]: nullptr; }
1077
25.4k
  PelBuf&     getTestBuf          ( ComponentID compId)   const { return m_TestBuf->bufs[compId]; }
1078
949k
  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
949k
  {
1089
949k
    if (insertPos != -1)
1090
134k
    {
1091
147k
      for (int i = RdListSize - 1; i > insertPos; i--)
1092
12.4k
      {
1093
12.4k
        std::swap(m_sortedList[i - 1], m_sortedList[i]);
1094
12.4k
      }
1095
134k
      std::swap(m_TestBuf, m_sortedList[insertPos]);
1096
134k
    }
1097
949k
  }
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