Coverage Report

Created: 2026-07-16 06:32

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