Coverage Report

Created: 2026-06-15 06:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/vvenc/source/Lib/CommonLib/Buffer.h
Line
Count
Source
1
/* -----------------------------------------------------------------------------
2
The copyright in this software is being made available under the Clear BSD
3
License, included below. No patent rights, trademark rights and/or 
4
other Intellectual Property Rights other than the copyrights concerning 
5
the Software are granted under this license.
6
7
The Clear BSD License
8
9
Copyright (c) 2019-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVenC Authors.
10
All rights reserved.
11
12
Redistribution and use in source and binary forms, with or without modification,
13
are permitted (subject to the limitations in the disclaimer below) provided that
14
the following conditions are met:
15
16
     * Redistributions of source code must retain the above copyright notice,
17
     this list of conditions and the following disclaimer.
18
19
     * Redistributions in binary form must reproduce the above copyright
20
     notice, this list of conditions and the following disclaimer in the
21
     documentation and/or other materials provided with the distribution.
22
23
     * Neither the name of the copyright holder nor the names of its
24
     contributors may be used to endorse or promote products derived from this
25
     software without specific prior written permission.
26
27
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
28
THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
29
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
31
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
32
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
35
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
36
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38
POSSIBILITY OF SUCH DAMAGE.
39
40
41
------------------------------------------------------------------------------------------- */
42
/** \file     Buffer.h
43
 *  \brief    Low-overhead class describing 2D memory layout
44
 */
45
46
#pragma once
47
48
#ifndef __IN_UNIT_H__
49
#error "Include Unit.h not Buffer.h"
50
#endif
51
52
#include "Common.h"
53
#include "CommonDef.h"
54
#include "MotionInfo.h"
55
56
#include <string.h>
57
#include <type_traits>
58
#include <typeinfo>
59
60
#include "vvenc/vvenc.h"
61
62
//! \ingroup CommonLib
63
//! \{
64
65
struct vvencYUVBuffer;
66
67
namespace vvenc {
68
69
#if ENABLE_SIMD_OPT_BUFFER && defined(TARGET_SIMD_X86)
70
using namespace x86_simd;
71
#endif
72
73
#if ENABLE_SIMD_OPT_BUFFER && defined(TARGET_SIMD_ARM)
74
using namespace arm_simd;
75
#endif
76
77
// ---------------------------------------------------------------------------
78
// AreaBuf struct
79
// ---------------------------------------------------------------------------
80
81
struct PelBufferOps
82
{
83
  PelBufferOps();
84
85
  bool isInitX86Done;
86
87
#if ENABLE_SIMD_OPT_BUFFER && defined(TARGET_SIMD_X86)
88
  void initPelBufOpsX86();
89
  template<X86_VEXT vext>
90
  void _initPelBufOpsX86();
91
#endif
92
  
93
#if ENABLE_SIMD_OPT_BUFFER && defined( TARGET_SIMD_ARM )
94
  void initPelBufOpsARM();
95
  template<ARM_VEXT vext>
96
  void _initPelBufOpsARM();
97
#endif
98
99
0
#define INCX( ptr, stride ) { ptr++; }
100
1.72M
#define INCY( ptr, stride ) { ptr += ( stride ); }
101
10.5M
#define OFFSETX( ptr, stride, x ) { ptr += ( x ); }
102
978k
#define OFFSETY( ptr, stride, y ) { ptr += ( y ) * ( stride ); }
103
1.86M
#define OFFSET( ptr, stride, x, y ) { ptr += ( x ) + ( y ) * ( stride ); }
104
#define GET_OFFSETX( ptr, stride, x ) ( ( ptr ) + ( x ) )
105
#define GET_OFFSETY( ptr, stride, y ) ( ( ptr ) + ( y ) * ( stride ) )
106
0
#define GET_OFFSET( ptr, stride, x, y ) ( ( ptr ) + ( x ) + ( y ) * ( stride ) ) // need in loopFilter.cpp + some ARM files
107
108
  void ( *roundGeo )      ( const Pel* src, Pel* dest, const int numSamples, unsigned rshift, int offset, const ClpRng &clpRng);
109
  void ( *addAvg )        ( const Pel* src0, const Pel* src1, Pel* dst, int numsamples, unsigned shift, int offset, const ClpRng& clpRng );
110
  void ( *reco  )         ( const Pel* src0, const Pel* src1, Pel* dst, int numSamples, const ClpRng& clpRng );
111
  void ( *copyClip )      ( const Pel* src0,                  Pel* dst, int numSamples, const ClpRng& clpRng );
112
  void ( *addAvg4 )       ( const Pel* src0, int src0Stride, const Pel* src1, int src1Stride, Pel* dst, int dstStride, int width, int height,       unsigned shift, int offset, const ClpRng& clpRng );
113
  void ( *addAvg8 )       ( const Pel* src0, int src0Stride, const Pel* src1, int src1Stride, Pel* dst, int dstStride, int width, int height,       unsigned shift, int offset, const ClpRng& clpRng );
114
  void ( *addAvg16 )      ( const Pel* src0, int src0Stride, const Pel* src1, int src1Stride, Pel* dst, int dstStride, int width, int height,       unsigned shift, int offset, const ClpRng& clpRng );
115
  void ( *sub4 )          ( const Pel* src0, int src0Stride, const Pel* src1, int src1Stride, Pel* dst, int dstStride, int width, int height );
116
  void ( *sub8 )          ( const Pel* src0, int src0Stride, const Pel* src1, int src1Stride, Pel* dst, int dstStride, int width, int height );
117
  void ( *wghtAvg4 )      ( const Pel* src0, int src0Stride, const Pel* src1, int src1Stride, Pel *dst, int dstStride, int width, int height,       unsigned shift, int offset, int w0, int w1, const ClpRng& clpRng );
118
  void ( *wghtAvg8 )      ( const Pel* src0, int src0Stride, const Pel* src1, int src1Stride, Pel *dst, int dstStride, int width, int height,       unsigned shift, int offset, int w0, int w1, const ClpRng& clpRng );
119
  void ( *copyClip4 )     ( const Pel* src0, int src0Stride,                                  Pel* dst, int dstStride, int width, int height,                                   const ClpRng& clpRng );
120
  void ( *copyClip8 )     ( const Pel* src0, int src0Stride,                                  Pel* dst, int dstStride, int width, int height,                                   const ClpRng& clpRng );
121
  void ( *reco4 )         ( const Pel* src0, int src0Stride, const Pel* src1, int src1Stride, Pel* dst, int dstStride, int width, int height,                                   const ClpRng& clpRng );
122
  void ( *reco8 )         ( const Pel* src0, int src0Stride, const Pel* src1, int src1Stride, Pel* dst, int dstStride, int width, int height,                                   const ClpRng& clpRng );
123
  void ( *linTf4 )        ( const Pel* src0, int src0Stride,                                  Pel* dst, int dstStride, int width, int height, int scale, unsigned shift, int offset, const ClpRng& clpRng, bool bClip );
124
  void ( *linTf8 )        ( const Pel* src0, int src0Stride,                                  Pel* dst, int dstStride, int width, int height, int scale, unsigned shift, int offset, const ClpRng& clpRng, bool bClip );
125
  void ( *copyBuffer )    ( const char* src, int srcStride, char* dst, int dstStride, int width, int height );
126
  void ( *removeHighFreq8)( Pel* src0, int src0Stride, const Pel* src1, int src1Stride, int width, int height);
127
  void ( *removeHighFreq4)( Pel* src0, int src0Stride, const Pel* src1, int src1Stride, int width, int height);
128
  void ( *transpose4x4 )  ( const Pel* src,  int srcStride, Pel* dst, int dstStride );
129
  void ( *transpose8x8 )  ( const Pel* src,  int srcStride, Pel* dst, int dstStride );
130
  void ( *roundIntVector) ( int* v, int size, unsigned int nShift, const int dmvLimit);
131
  void ( *mipMatrixMul_4_4)( Pel* res, const Pel* input, const uint8_t* weight, const int maxVal, const int offset, bool transpose );
132
  void ( *mipMatrixMul_8_4)( Pel* res, const Pel* input, const uint8_t* weight, const int maxVal, const int offset, bool transpose );
133
  void ( *mipMatrixMul_8_8)( Pel* res, const Pel* input, const uint8_t* weight, const int maxVal, const int offset, bool transpose );
134
  void ( *weightCiip)     ( Pel* res, const Pel* intra, const int numSamples, int numIntra );
135
  void ( *applyLut )      ( const Pel* src, const ptrdiff_t srcStride, Pel* dst, ptrdiff_t dstStride, int width, int height, const Pel* lut );
136
  void ( *fillPtrMap )    ( void** ptrMap, const ptrdiff_t mapStride, int width, int height, void* val );
137
  uint64_t ( *AvgHighPassWithDownsampling )    ( const int width, const int height, const Pel* pSrc, const int iSrcStride);
138
  uint64_t ( *AvgHighPass )    ( const int width, const int height, const Pel* pSrc, const int iSrcStride);
139
  uint64_t ( *AvgHighPassWithDownsamplingDiff1st ) (const int width, const int height, const Pel* pSrc,const Pel* pSrcM1, const int iSrcStride, const int iSrcM1Stride);
140
  uint64_t ( *AvgHighPassWithDownsamplingDiff2nd) (const int width,const int height,const Pel* pSrc,const Pel* pSM1,const Pel* pS21,const int iSrcStride,const int iSM1Stride,const int iSM2Stride);
141
  uint64_t ( *HDHighPass) (const int width, const int height,const Pel*  pSrc,const Pel* pSM1,const int iSrcStride,const int iSM1Stride);
142
  uint64_t ( *HDHighPass2)  (const int width, const int height,const Pel*  pSrc,const Pel* pSM1,const Pel* pSM2,const int iSrcStride,const int iSM1Stride,const int iSM2Stride);
143
};
144
145
extern PelBufferOps g_pelBufOP;
146
147
template<typename T>
148
struct AreaBuf : public Size
149
{
150
  T*        buf;
151
  int       stride;
152
  // the proper type causes awful lot of errors
153
154
16.3M
  AreaBuf()                                                                               : Size(),                  buf( NULL ), stride( 0 )          { }
vvenc::AreaBuf<short>::AreaBuf()
Line
Count
Source
154
15.4M
  AreaBuf()                                                                               : Size(),                  buf( NULL ), stride( 0 )          { }
vvenc::AreaBuf<short const>::AreaBuf()
Line
Count
Source
154
939k
  AreaBuf()                                                                               : Size(),                  buf( NULL ), stride( 0 )          { }
Unexecuted instantiation: vvenc::AreaBuf<int>::AreaBuf()
Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo>::AreaBuf()
155
6.73M
  AreaBuf( T *_buf, const Size& size )                                                    : Size( size ),            buf( _buf ), stride( size.width ) { }
vvenc::AreaBuf<short>::AreaBuf(short*, vvenc::Size const&)
Line
Count
Source
155
2.45M
  AreaBuf( T *_buf, const Size& size )                                                    : Size( size ),            buf( _buf ), stride( size.width ) { }
vvenc::AreaBuf<short const>::AreaBuf(short const*, vvenc::Size const&)
Line
Count
Source
155
1.70M
  AreaBuf( T *_buf, const Size& size )                                                    : Size( size ),            buf( _buf ), stride( size.width ) { }
vvenc::AreaBuf<vvenc::LoopFilterParam>::AreaBuf(vvenc::LoopFilterParam*, vvenc::Size const&)
Line
Count
Source
155
6.65k
  AreaBuf( T *_buf, const Size& size )                                                    : Size( size ),            buf( _buf ), stride( size.width ) { }
Unexecuted instantiation: vvenc::AreaBuf<vvenc::LoopFilterParam const>::AreaBuf(vvenc::LoopFilterParam const*, vvenc::Size const&)
vvenc::AreaBuf<int>::AreaBuf(int*, vvenc::Size const&)
Line
Count
Source
155
2.56M
  AreaBuf( T *_buf, const Size& size )                                                    : Size( size ),            buf( _buf ), stride( size.width ) { }
Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo const>::AreaBuf(vvenc::MotionInfo const*, vvenc::Size const&)
Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo>::AreaBuf(vvenc::MotionInfo*, vvenc::Size const&)
156
19.8M
  AreaBuf( T *_buf, const int& _stride, const Size& size )                                : Size( size ),            buf( _buf ), stride( _stride )    { }
vvenc::AreaBuf<short>::AreaBuf(short*, int const&, vvenc::Size const&)
Line
Count
Source
156
19.0M
  AreaBuf( T *_buf, const int& _stride, const Size& size )                                : Size( size ),            buf( _buf ), stride( _stride )    { }
vvenc::AreaBuf<short const>::AreaBuf(short const*, int const&, vvenc::Size const&)
Line
Count
Source
156
34.5k
  AreaBuf( T *_buf, const int& _stride, const Size& size )                                : Size( size ),            buf( _buf ), stride( _stride )    { }
vvenc::AreaBuf<vvenc::MotionInfo>::AreaBuf(vvenc::MotionInfo*, int const&, vvenc::Size const&)
Line
Count
Source
156
695k
  AreaBuf( T *_buf, const int& _stride, const Size& size )                                : Size( size ),            buf( _buf ), stride( _stride )    { }
vvenc::AreaBuf<vvenc::LoopFilterParam>::AreaBuf(vvenc::LoopFilterParam*, int const&, vvenc::Size const&)
Line
Count
Source
156
6.66k
  AreaBuf( T *_buf, const int& _stride, const Size& size )                                : Size( size ),            buf( _buf ), stride( _stride )    { }
157
1.62M
  AreaBuf( T *_buf, const SizeType& _width, const SizeType& _height )                     : Size( _width, _height ), buf( _buf ), stride( _width )     { }
vvenc::AreaBuf<short>::AreaBuf(short*, unsigned int const&, unsigned int const&)
Line
Count
Source
157
43.8k
  AreaBuf( T *_buf, const SizeType& _width, const SizeType& _height )                     : Size( _width, _height ), buf( _buf ), stride( _width )     { }
vvenc::AreaBuf<short const>::AreaBuf(short const*, unsigned int const&, unsigned int const&)
Line
Count
Source
157
1.58M
  AreaBuf( T *_buf, const SizeType& _width, const SizeType& _height )                     : Size( _width, _height ), buf( _buf ), stride( _width )     { }
158
9.29M
  AreaBuf( T *_buf, const int& _stride, const SizeType& _width, const SizeType& _height ) : Size( _width, _height ), buf( _buf ), stride( _stride )    { }
vvenc::AreaBuf<short>::AreaBuf(short*, int const&, unsigned int const&, unsigned int const&)
Line
Count
Source
158
8.75M
  AreaBuf( T *_buf, const int& _stride, const SizeType& _width, const SizeType& _height ) : Size( _width, _height ), buf( _buf ), stride( _stride )    { }
vvenc::AreaBuf<short const>::AreaBuf(short const*, int const&, unsigned int const&, unsigned int const&)
Line
Count
Source
158
543k
  AreaBuf( T *_buf, const int& _stride, const SizeType& _width, const SizeType& _height ) : Size( _width, _height ), buf( _buf ), stride( _stride )    { }
159
160
  AreaBuf( const AreaBuf& )  = default;
161
  AreaBuf(       AreaBuf&& ) = default;
162
  AreaBuf& operator=( const AreaBuf& )  = default;
163
  AreaBuf& operator=(       AreaBuf&& ) = default;
164
165
  // conversion from AreaBuf<const T> to AreaBuf<T>
166
  template<bool T_IS_CONST = std::is_const<T>::value>
167
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<short const>::AreaBuf<true>(vvenc::AreaBuf<short> const&, std::__1::enable_if<true, void>::type*)
Line
Count
Source
167
20.8M
  AreaBuf( const AreaBuf<typename std::remove_const_t<T>>& other, std::enable_if_t<T_IS_CONST>* = 0) : Size( other ), buf( other.buf ), stride( other.stride ) { }
vvenc::AreaBuf<vvenc::MotionInfo const>::AreaBuf<true>(vvenc::AreaBuf<vvenc::MotionInfo> const&, std::__1::enable_if<true, void>::type*)
Line
Count
Source
167
46.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
167
2.52M
  AreaBuf( const AreaBuf<typename std::remove_const_t<T>>& other, std::enable_if_t<T_IS_CONST>* = 0) : Size( other ), buf( other.buf ), stride( other.stride ) { }
168
169
  void fill                 ( const T &val );
170
  void memset               ( const int val );
171
172
  void copyFrom             ( const AreaBuf<const T>& other );
173
  void reconstruct          ( const AreaBuf<const T>& pred, const AreaBuf<const T>& resi, const ClpRng& clpRng);
174
  void copyClip             ( const AreaBuf<const T>& src, const ClpRng& clpRng);
175
176
  void subtract             ( const AreaBuf<const T>& minuend, const AreaBuf<const T>& subtrahend );
177
  void calcVarianceSplit    ( const AreaBuf<const T>& Org, const uint32_t  size,int& varh,int& varv ) const;
178
  void extendBorderPel      ( unsigned marginX, unsigned marginY );
179
180
  void addAvg               ( const AreaBuf<const T>& other1, const AreaBuf<const T>& other2, const ClpRng& clpRng );
181
  T    getAvg               () const;
182
  void padBorderPel         ( unsigned marginX, unsigned marginY, int dir );
183
  void addWeightedAvg       ( const AreaBuf<const T>& other1, const AreaBuf<const T>& other2, const ClpRng& clpRng, const int8_t BcwIdx );
184
  void removeHighFreq       ( const AreaBuf<const T>& other, const bool bClip, const ClpRng& clpRng);
185
  void extendBorderPelTop   ( int x, int size, int margin );
186
  void extendBorderPelBot   ( int x, int size, int margin );
187
  void extendBorderPelLft   ( int y, int size, int margin );
188
  void extendBorderPelRgt   ( int y, int size, int margin );
189
190
  void linearTransform      ( const int scale, const unsigned shift, const int offset, bool bClip, const ClpRng& clpRng );
191
192
  void transposedFrom       ( const AreaBuf<const T>& other );
193
  void weightCiip           ( const AreaBuf<const T>& intra, const int numIntra );
194
195
  void rspSignal            ( const Pel* pLUT );
196
  void rspSignal            ( const AreaBuf<const T>& other, const Pel* pLUT );
197
  void scaleSignal          ( const int scale, const bool dir , const ClpRng& clpRng);
198
  bool compare              ( const AreaBuf<const T>& other ) const;
199
200
234M
        T& at( const int& x, const int& y )          { return buf[y * stride + x]; }
vvenc::AreaBuf<short>::at(int const&, int const&)
Line
Count
Source
200
234M
        T& at( const int& x, const int& y )          { return buf[y * stride + x]; }
Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo>::at(int const&, int const&)
Unexecuted instantiation: vvenc::AreaBuf<int>::at(int const&, int const&)
201
1.60G
  const T& at( const int& x, const int& y ) const    { return buf[y * stride + x]; }
vvenc::AreaBuf<short const>::at(int const&, int const&) const
Line
Count
Source
201
1.60G
  const T& at( const int& x, const int& y ) const    { return buf[y * stride + x]; }
Unexecuted instantiation: vvenc::AreaBuf<short>::at(int const&, int const&) const
Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo const>::at(int const&, int const&) const
vvenc::AreaBuf<int const>::at(int const&, int const&) const
Line
Count
Source
201
3.93M
  const T& at( const int& x, const int& y ) const    { return buf[y * stride + x]; }
202
203
1.90M
        T& at( const Position& pos )                 { return buf[pos.y * stride + pos.x]; }
Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo>::at(vvenc::Position const&)
Unexecuted instantiation: vvenc::AreaBuf<short const>::at(vvenc::Position const&)
vvenc::AreaBuf<short>::at(vvenc::Position const&)
Line
Count
Source
203
1.90M
        T& at( const Position& pos )                 { return buf[pos.y * stride + pos.x]; }
vvenc::AreaBuf<vvenc::LoopFilterParam>::at(vvenc::Position const&)
Line
Count
Source
203
6.65k
        T& at( const Position& pos )                 { return buf[pos.y * stride + pos.x]; }
204
29.8k
  const T& at( const Position& pos ) const           { return buf[pos.y * stride + pos.x]; }
vvenc::AreaBuf<short const>::at(vvenc::Position const&) const
Line
Count
Source
204
10.0k
  const T& at( const Position& pos ) const           { return buf[pos.y * stride + pos.x]; }
vvenc::AreaBuf<short>::at(vvenc::Position const&) const
Line
Count
Source
204
19.8k
  const T& at( const Position& pos ) const           { return buf[pos.y * stride + pos.x]; }
205
206
207
10.6k
        T* bufAt( const int& x, const int& y )       { return &at( x, y ); }
208
160k
  const T* bufAt( const int& x, const int& y ) const { return &at( x, y ); }
vvenc::AreaBuf<short const>::bufAt(int const&, int const&) const
Line
Count
Source
208
160k
  const T* bufAt( const int& x, const int& y ) const { return &at( x, y ); }
Unexecuted instantiation: vvenc::AreaBuf<short>::bufAt(int const&, int const&) const
209
210
1.90M
        T* bufAt( const Position& pos )              { return &at( pos ); }
Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo>::bufAt(vvenc::Position const&)
Unexecuted instantiation: vvenc::AreaBuf<short const>::bufAt(vvenc::Position const&)
vvenc::AreaBuf<short>::bufAt(vvenc::Position const&)
Line
Count
Source
210
1.90M
        T* bufAt( const Position& pos )              { return &at( pos ); }
vvenc::AreaBuf<vvenc::LoopFilterParam>::bufAt(vvenc::Position const&)
Line
Count
Source
210
6.65k
        T* bufAt( const Position& pos )              { return &at( pos ); }
211
29.8k
  const T* bufAt( const Position& pos ) const        { return &at( pos ); }
vvenc::AreaBuf<short const>::bufAt(vvenc::Position const&) const
Line
Count
Source
211
10.0k
  const T* bufAt( const Position& pos ) const        { return &at( pos ); }
vvenc::AreaBuf<short>::bufAt(vvenc::Position const&) const
Line
Count
Source
211
19.8k
  const T* bufAt( const Position& pos ) const        { return &at( pos ); }
212
213
  AreaBuf<      T> subBuf( const Area& area )                                                         { return AreaBuf<      T>( bufAt( area ), stride, area   ); }
214
  AreaBuf<const T> subBuf( const Area& area )                                                   const { return AreaBuf<const T>( bufAt( area ), stride, area   ); }
215
26.6k
  AreaBuf<      T> subBuf( const Position& pos, const Size& size )                                    { return AreaBuf<      T>( bufAt( pos  ), stride, size   ); }
Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo>::subBuf(vvenc::Position const&, vvenc::Size const&)
vvenc::AreaBuf<short>::subBuf(vvenc::Position const&, vvenc::Size const&)
Line
Count
Source
215
19.9k
  AreaBuf<      T> subBuf( const Position& pos, const Size& size )                                    { return AreaBuf<      T>( bufAt( pos  ), stride, size   ); }
vvenc::AreaBuf<vvenc::LoopFilterParam>::subBuf(vvenc::Position const&, vvenc::Size const&)
Line
Count
Source
215
6.65k
  AreaBuf<      T> subBuf( const Position& pos, const Size& size )                                    { return AreaBuf<      T>( bufAt( pos  ), stride, size   ); }
216
9.99k
  AreaBuf<const T> subBuf( const Position& pos, const Size& size )                              const { return AreaBuf<const T>( bufAt( pos  ), stride, size   ); }
vvenc::AreaBuf<short const>::subBuf(vvenc::Position const&, vvenc::Size const&) const
Line
Count
Source
216
9.99k
  AreaBuf<const T> subBuf( const Position& pos, const Size& size )                              const { return AreaBuf<const T>( bufAt( pos  ), stride, size   ); }
Unexecuted instantiation: vvenc::AreaBuf<short>::subBuf(vvenc::Position const&, vvenc::Size const&) const
217
0
  AreaBuf<      T> subBuf( const int& x, const int& y, const unsigned& _w, const unsigned& _h )       { return AreaBuf<      T>( bufAt( x, y ), stride, _w, _h ); }
218
  AreaBuf<const T> subBuf( const int& x, const int& y, const unsigned& _w, const unsigned& _h ) const { return AreaBuf<const T>( bufAt( x, y ), stride, _w, _h ); }
219
};
220
221
typedef AreaBuf<      Pel>  PelBuf;
222
typedef AreaBuf<const Pel> CPelBuf;
223
224
typedef AreaBuf<      TCoeff>  CoeffBuf;
225
typedef AreaBuf<const TCoeff> CCoeffBuf;
226
227
typedef AreaBuf<      TCoeffSig>  CoeffSigBuf;
228
typedef AreaBuf<const TCoeffSig> CCoeffSigBuf;
229
230
typedef AreaBuf<      MotionInfo>  MotionBuf;
231
typedef AreaBuf<const MotionInfo> CMotionBuf;
232
233
typedef AreaBuf<      TCoeff>  PLTescapeBuf;
234
typedef AreaBuf<const TCoeff> CPLTescapeBuf;
235
236
typedef AreaBuf<      bool>  PLTtypeBuf;
237
typedef AreaBuf<const bool> CPLTtypeBuf;
238
239
typedef AreaBuf<      LoopFilterParam>  LFPBuf;
240
typedef AreaBuf<const LoopFilterParam> CLFPBuf;
241
242
4.70M
#define SIZE_AWARE_PER_EL_OP( OP, INC )                     \
243
4.70M
if( ( width & 7 ) == 0 )                                    \
244
3.79M
{                                                           \
245
60.0M
  for( int y = 0; y < height; y++ )                         \
246
56.2M
  {                                                         \
247
224M
    for( int x = 0; x < width; x += 8 )                     \
248
168M
    {                                                       \
249
168M
      OP( x + 0 );                                          \
250
168M
      OP( x + 1 );                                          \
251
168M
      OP( x + 2 );                                          \
252
168M
      OP( x + 3 );                                          \
253
168M
      OP( x + 4 );                                          \
254
168M
      OP( x + 5 );                                          \
255
168M
      OP( x + 6 );                                          \
256
168M
      OP( x + 7 );                                          \
257
168M
    }                                                       \
258
56.2M
                                                            \
259
56.2M
    INC;                                                    \
260
56.2M
  }                                                         \
261
3.79M
}                                                           \
262
4.70M
else if( ( width & 3 ) == 0 )                               \
263
913k
{                                                           \
264
10.9M
  for( int y = 0; y < height; y++ )                         \
265
10.0M
  {                                                         \
266
22.5M
    for( int x = 0; x < width; x += 4 )                     \
267
12.4M
    {                                                       \
268
12.4M
      OP( x + 0 );                                          \
269
12.4M
      OP( x + 1 );                                          \
270
12.4M
      OP( x + 2 );                                          \
271
12.4M
      OP( x + 3 );                                          \
272
12.4M
    }                                                       \
273
10.0M
                                                            \
274
10.0M
    INC;                                                    \
275
10.0M
  }                                                         \
276
913k
}                                                           \
277
18.4E
else if( ( width & 1 ) == 0 )                               \
278
0
{                                                           \
279
0
  for( int y = 0; y < height; y++ )                         \
280
0
  {                                                         \
281
0
    for( int x = 0; x < width; x += 2 )                     \
282
0
    {                                                       \
283
0
      OP( x + 0 );                                          \
284
0
      OP( x + 1 );                                          \
285
0
    }                                                       \
286
0
                                                            \
287
0
    INC;                                                    \
288
0
  }                                                         \
289
0
}                                                           \
290
18.4E
else                                                        \
291
18.4E
{                                                           \
292
18.4E
  for( int y = 0; y < height; y++ )                         \
293
18.4E
  {                                                         \
294
0
    for( int x = 0; x < width; x++ )                        \
295
0
    {                                                       \
296
0
      OP( x );                                              \
297
0
    }                                                       \
298
0
                                                            \
299
0
    INC;                                                    \
300
0
  }                                                         \
301
18.4E
}
302
303
304
template<typename T>
305
T AreaBuf <T> ::getAvg() const
306
23.1k
{
307
23.1k
  const T* src = buf;
308
23.1k
  int64_t  acc = 0;
309
310
23.1k
#define AVG_INC      src += stride
311
91.9M
#define AVG_OP(ADDR) acc += src[ADDR]
312
91.9M
  SIZE_AWARE_PER_EL_OP(AVG_OP, AVG_INC);
313
23.1k
#undef AVG_INC
314
23.1k
#undef AVG_OP
315
316
23.1k
  return T ((acc + (area() >> 1)) / area());
317
23.1k
}
vvenc::AreaBuf<short const>::getAvg() const
Line
Count
Source
306
22.0k
{
307
22.0k
  const T* src = buf;
308
22.0k
  int64_t  acc = 0;
309
310
22.0k
#define AVG_INC      src += stride
311
22.0k
#define AVG_OP(ADDR) acc += src[ADDR]
312
22.0k
  SIZE_AWARE_PER_EL_OP(AVG_OP, AVG_INC);
313
22.0k
#undef AVG_INC
314
22.0k
#undef AVG_OP
315
316
22.0k
  return T ((acc + (area() >> 1)) / area());
317
22.0k
}
vvenc::AreaBuf<short>::getAvg() const
Line
Count
Source
306
1.08k
{
307
1.08k
  const T* src = buf;
308
1.08k
  int64_t  acc = 0;
309
310
1.08k
#define AVG_INC      src += stride
311
1.08k
#define AVG_OP(ADDR) acc += src[ADDR]
312
1.08k
  SIZE_AWARE_PER_EL_OP(AVG_OP, AVG_INC);
313
1.08k
#undef AVG_INC
314
1.08k
#undef AVG_OP
315
316
1.08k
  return T ((acc + (area() >> 1)) / area());
317
1.08k
}
318
319
template<>
320
void AreaBuf<MotionInfo>::fill( const MotionInfo& val );
321
322
template<typename T>
323
void AreaBuf<T>::fill(const T &val)
324
1.57M
{
325
1.57M
  if( T( 0 ) == val )
326
1.47M
  {
327
1.47M
    GCC_WARNING_DISABLE_class_memaccess
328
1.47M
    if( width == stride )
329
1.47M
    {
330
1.47M
      ::memset( buf, 0, width * height * sizeof( T ) );
331
1.47M
    }
332
3.22k
    else
333
3.22k
    {
334
3.22k
      T* dest = buf;
335
3.22k
      size_t line = width * sizeof( T );
336
337
116k
      for( unsigned y = 0; y < height; y++ )
338
112k
      {
339
112k
        ::memset( dest, 0, line );
340
341
112k
        dest += stride;
342
112k
      }
343
3.22k
    }
344
1.47M
    GCC_WARNING_RESET
345
1.47M
  }
346
103k
  else
347
103k
  {
348
103k
    if( width == stride )
349
103k
    {
350
103k
      std::fill_n( buf, width * height, val );
351
103k
    }
352
0
    else
353
0
    {
354
0
      T* dest = buf;
355
356
0
      for( int y = 0; y < height; y++, dest += stride )
357
0
      {
358
0
        std::fill_n( dest, width, val );
359
0
      }
360
0
    }
361
103k
  }
362
1.57M
}
363
364
template<typename T>
365
void AreaBuf<T>::memset( const int val )
366
591k
{
367
591k
  GCC_WARNING_DISABLE_class_memaccess
368
591k
  if( width == stride )
369
586k
  {
370
586k
    ::memset( buf, val, width * height * sizeof( T ) );
371
586k
  }
372
4.97k
  else
373
4.97k
  {
374
4.97k
    T* dest = buf;
375
4.97k
    size_t line = width * sizeof( T );
376
377
116k
    for( int y = 0; y < height; y++, dest += stride )
378
111k
    {
379
111k
      ::memset( dest, val, line );
380
111k
    }
381
4.97k
  }
382
591k
  GCC_WARNING_RESET
383
591k
}
vvenc::AreaBuf<vvenc::MotionInfo>::memset(int)
Line
Count
Source
366
579k
{
367
579k
  GCC_WARNING_DISABLE_class_memaccess
368
579k
  if( width == stride )
369
579k
  {
370
579k
    ::memset( buf, val, width * height * sizeof( T ) );
371
579k
  }
372
0
  else
373
0
  {
374
0
    T* dest = buf;
375
0
    size_t line = width * sizeof( T );
376
377
0
    for( int y = 0; y < height; y++, dest += stride )
378
0
    {
379
0
      ::memset( dest, val, line );
380
0
    }
381
0
  }
382
579k
  GCC_WARNING_RESET
383
579k
}
vvenc::AreaBuf<vvenc::LoopFilterParam>::memset(int)
Line
Count
Source
366
6.65k
{
367
6.65k
  GCC_WARNING_DISABLE_class_memaccess
368
6.65k
  if( width == stride )
369
1.68k
  {
370
1.68k
    ::memset( buf, val, width * height * sizeof( T ) );
371
1.68k
  }
372
4.97k
  else
373
4.97k
  {
374
4.97k
    T* dest = buf;
375
4.97k
    size_t line = width * sizeof( T );
376
377
116k
    for( int y = 0; y < height; y++, dest += stride )
378
111k
    {
379
111k
      ::memset( dest, val, line );
380
111k
    }
381
4.97k
  }
382
6.65k
  GCC_WARNING_RESET
383
6.65k
}
vvenc::AreaBuf<short>::memset(int)
Line
Count
Source
366
5.32k
{
367
5.32k
  GCC_WARNING_DISABLE_class_memaccess
368
5.32k
  if( width == stride )
369
5.32k
  {
370
5.32k
    ::memset( buf, val, width * height * sizeof( T ) );
371
5.32k
  }
372
0
  else
373
0
  {
374
0
    T* dest = buf;
375
0
    size_t line = width * sizeof( T );
376
377
0
    for( int y = 0; y < height; y++, dest += stride )
378
0
    {
379
0
      ::memset( dest, val, line );
380
0
    }
381
0
  }
382
5.32k
  GCC_WARNING_RESET
383
5.32k
}
384
385
template<typename T>
386
void AreaBuf<T>::copyFrom( const AreaBuf<const T>& other )
387
7.63M
{
388
#if !defined(__GNUC__) || __GNUC__ > 5
389
  static_assert( std::is_trivially_copyable<T>::value, "Type T is not trivially_copyable" );
390
#endif
391
392
7.63M
  g_pelBufOP.copyBuffer( ( const char* ) other.buf, other.stride * sizeof( T ), ( char* ) buf, stride * sizeof( T ), width * sizeof( T ), height );
393
7.63M
}
vvenc::AreaBuf<vvenc::MotionInfo>::copyFrom(vvenc::AreaBuf<vvenc::MotionInfo const> const&)
Line
Count
Source
387
46.3k
{
388
#if !defined(__GNUC__) || __GNUC__ > 5
389
  static_assert( std::is_trivially_copyable<T>::value, "Type T is not trivially_copyable" );
390
#endif
391
392
46.3k
  g_pelBufOP.copyBuffer( ( const char* ) other.buf, other.stride * sizeof( T ), ( char* ) buf, stride * sizeof( T ), width * sizeof( T ), height );
393
46.3k
}
vvenc::AreaBuf<short>::copyFrom(vvenc::AreaBuf<short const> const&)
Line
Count
Source
387
7.58M
{
388
#if !defined(__GNUC__) || __GNUC__ > 5
389
  static_assert( std::is_trivially_copyable<T>::value, "Type T is not trivially_copyable" );
390
#endif
391
392
7.58M
  g_pelBufOP.copyBuffer( ( const char* ) other.buf, other.stride * sizeof( T ), ( char* ) buf, stride * sizeof( T ), width * sizeof( T ), height );
393
7.58M
}
394
395
template<typename T>
396
void AreaBuf<T>::subtract( const AreaBuf<const T>& minuend, const AreaBuf<const T>& subtrahend )
397
{
398
  THROW( "Type not supported" );
399
}
400
401
template<>
402
void AreaBuf<Pel>::subtract( const AreaBuf<const Pel>& minuend, const AreaBuf<const Pel>& subtrahend );
403
404
template<typename T>
405
void AreaBuf<T>::calcVarianceSplit( const AreaBuf<const T>& Org, const uint32_t  size,int& varh,int& varv ) const 
406
{
407
  THROW( "Type not supported" );
408
}
409
410
template<>
411
void AreaBuf<const Pel>::calcVarianceSplit( const AreaBuf<const Pel>& Org, const uint32_t  size, int& varh,int&varv ) const;
412
413
template<typename T>
414
void AreaBuf<T>::copyClip( const AreaBuf<const T>& src, const ClpRng& clpRng )
415
{
416
  THROW( "Type not supported" );
417
}
418
419
template<>
420
void AreaBuf<Pel>::copyClip( const AreaBuf<const Pel>& src, const ClpRng& clpRng );
421
422
template<typename T>
423
void AreaBuf<T>::reconstruct( const AreaBuf<const T>& pred, const AreaBuf<const T>& resi, const ClpRng& clpRng )
424
{
425
  THROW( "Type not supported" );
426
}
427
428
template<>
429
void AreaBuf<Pel>::reconstruct( const AreaBuf<const Pel>& pred, const AreaBuf<const Pel>& resi, const ClpRng& clpRng );
430
431
template<>
432
void AreaBuf<Pel>::rspSignal( const AreaBuf<const Pel>& other, const Pel* pLUT);
433
434
template<typename T>
435
void AreaBuf<T>::rspSignal( const AreaBuf<const T>& other, const Pel* pLUT)
436
{
437
  THROW( "Type not supported" );
438
}
439
440
441
template<typename T>
442
void AreaBuf<T>::addAvg( const AreaBuf<const T>& other1, const AreaBuf<const T>& other2, const ClpRng& clpRng )
443
{
444
  THROW( "Type not supported" );
445
}
446
447
template<>
448
void AreaBuf<Pel>::addAvg( const AreaBuf<const Pel>& other1, const AreaBuf<const Pel>& other2, const ClpRng& clpRng );
449
450
template<typename T>
451
void AreaBuf<T>::linearTransform( const int scale, const unsigned shift, const int offset, bool bClip, const ClpRng& clpRng )
452
{
453
  THROW( "Type not supported" );
454
}
455
456
template<>
457
void AreaBuf<Pel>::linearTransform( const int scale, const unsigned shift, const int offset, bool bClip, const ClpRng& clpRng );
458
459
template<typename T>
460
void AreaBuf<T>::removeHighFreq( const AreaBuf<const T>& other, const bool bClip, const ClpRng& clpRng )
461
0
{
462
0
  const T*  src       = other.buf;
463
0
  const int srcStride = other.stride;
464
465
0
        T*  dst       = buf;
466
0
  const int dstStride = stride;
467
468
0
#if ENABLE_SIMD_OPT_BCW
469
0
  if (!bClip)
470
0
  {
471
0
    if(!(width & 7))
472
0
      g_pelBufOP.removeHighFreq8(dst, dstStride, src, srcStride, width, height);
473
0
    else if (!(width & 3))
474
0
      g_pelBufOP.removeHighFreq4(dst, dstStride, src, srcStride, width, height);
475
0
    else
476
0
      CHECK(true, "Not supported");
477
0
  }
478
0
  else
479
0
  {
480
0
#endif
481
482
0
#define REM_HF_INC  \
483
0
  src += srcStride; \
484
0
  dst += dstStride; \
485
0
486
0
#define REM_HF_OP_CLIP( ADDR ) dst[ADDR] = ClipPel<T>( 2 * dst[ADDR] - src[ADDR], clpRng )
487
0
#define REM_HF_OP( ADDR )      dst[ADDR] =             2 * dst[ADDR] - src[ADDR]
488
489
0
  if( bClip )
490
0
  {
491
0
    SIZE_AWARE_PER_EL_OP( REM_HF_OP_CLIP, REM_HF_INC );
492
0
  }
493
0
  else
494
0
  {
495
0
    SIZE_AWARE_PER_EL_OP( REM_HF_OP,      REM_HF_INC );
496
0
  }
497
498
0
#undef REM_HF_INC
499
0
#undef REM_HF_OP
500
0
#undef REM_HF_OP_CLIP
501
502
0
#if ENABLE_SIMD_OPT_BCW
503
0
  }
504
0
#endif
505
0
}
506
507
508
template<typename T>
509
void AreaBuf<T>::extendBorderPelLft( int y, int size, int margin )
510
11.4k
{
511
11.4k
  T* p = buf + y * stride;
512
11.4k
  int h = size + y;
513
514
  // do left and right margins
515
650k
  for (; y < h; y++)
516
638k
  {
517
26.7M
    for (int x = 0; x < margin; x++)
518
26.1M
    {
519
26.1M
      *(p - margin + x) = p[0];
520
26.1M
    }
521
638k
    p += stride;
522
638k
  }
523
11.4k
}
524
525
template<typename T>
526
void AreaBuf<T>::extendBorderPelTop( int x, int size, int margin )
527
8.73k
{
528
8.73k
  T* p = buf + x;
529
530
  // p is now (-marginX, 0)
531
336k
  for (int y = 0; y < margin; y++)
532
327k
  {
533
327k
    ::memcpy(p - (y + 1) * stride, p, sizeof(T) * size);
534
327k
  }
535
8.73k
}
536
537
template<typename T>
538
void AreaBuf<T>::extendBorderPelRgt( int y, int size, int margin )
539
11.4k
{
540
11.4k
  T* p = buf + y * stride;
541
11.4k
  int h = size + y;
542
543
  // do left and right margins
544
652k
  for( ; y < h; y++)
545
641k
  {
546
30.2M
    for (int x = 0; x < margin; x++)
547
29.5M
    {
548
29.5M
      p[width + x] = p[width - 1];
549
29.5M
    }
550
641k
    p += stride;
551
641k
  }
552
11.4k
}
553
554
template<typename T>
555
void AreaBuf<T>::extendBorderPelBot( int x, int size, int margin )
556
8.73k
{
557
8.73k
  T* p = buf + (height-1)*stride + x;
558
559
  // p is now the (-margin, height-1)
560
336k
  for (int y = 0; y < margin; y++)
561
327k
  {
562
327k
    ::memcpy(p + (y + 1) * stride, p, sizeof(T) * size);
563
327k
  }
564
8.73k
}
565
566
template<typename T>
567
void AreaBuf<T>::extendBorderPel(unsigned marginX, unsigned marginY)
568
3.25k
{
569
3.25k
  T* p = buf;
570
3.25k
  int h = height;
571
3.25k
  int w = width;
572
3.25k
  int s = stride;
573
574
3.25k
  CHECK((w + 2 * marginX) > s, "Size of buffer too small to extend");
575
  // do left and right margins
576
329k
  for (int y = 0; y < h; y++)
577
326k
  {
578
31.6M
    for (int x = 0; x < marginX; x++)
579
31.3M
    {
580
31.3M
      *(p - marginX + x) = p[0];
581
31.3M
      p[w + x] = p[w - 1];
582
31.3M
    }
583
326k
    p += s;
584
326k
  }
585
586
  // p is now the (0,height) (bottom left of image within bigger picture
587
3.25k
  p -= (s + marginX);
588
  // p is now the (-margin, height-1)
589
281k
  for (int y = 0; y < marginY; y++)
590
278k
  {
591
278k
    ::memcpy(p + (y + 1) * s, p, sizeof(T) * (w + (marginX << 1)));
592
278k
  }
593
594
  // p is still (-marginX, height-1)
595
3.25k
  p -= ((h - 1) * s);
596
  // p is now (-marginX, 0)
597
281k
  for (int y = 0; y < marginY; y++)
598
278k
  {
599
278k
    ::memcpy(p - (y + 1) * s, p, sizeof(T) * (w + (marginX << 1)));
600
278k
  }
601
3.25k
}
602
603
template<typename T>
604
void AreaBuf<T>::padBorderPel( unsigned marginX, unsigned marginY, int dir )
605
0
{
606
0
  T*  p = buf;
607
0
  int s = stride;
608
0
  int h = height;
609
0
  int w = width;
610
611
0
  CHECK( w  > s, "Size of buffer too small to extend" );
612
613
  // top-left margin
614
0
  if ( dir == 1 )
615
0
  {
616
0
    for( int y = 0; y < marginY; y++ )
617
0
    {
618
0
      for( int x = 0; x < marginX; x++ )
619
0
      {
620
0
        p[x] = p[marginX];
621
0
      }
622
0
      p += s;
623
0
    }
624
0
  }
625
626
  // bottom-right margin
627
0
  if ( dir == 2 )
628
0
  {
629
0
    p = buf + s * ( h - marginY ) + w - marginX;
630
631
0
    for( int y = 0; y < marginY; y++ )
632
0
    {
633
0
      for( int x = 0; x < marginX; x++ )
634
0
      {
635
0
        p[x] = p[-1];
636
0
      }
637
0
      p += s;
638
0
    }
639
0
  }
640
0
}
641
642
643
#if ENABLE_SIMD_OPT_BUFFER
644
template<> void AreaBuf<Pel>::transposedFrom( const AreaBuf<const Pel>& other );
645
#endif
646
647
template<typename T>
648
void AreaBuf<T>::transposedFrom( const AreaBuf<const T>& other )
649
{
650
  CHECK( width * height != other.width * other.height, "Incompatible size" );
651
652
        T* dst  =       buf;
653
  const T* src  = other.buf;
654
  width         = other.height;
655
  height        = other.width;
656
  stride        = stride < width ? width : stride;
657
658
  for( unsigned y = 0; y < other.height; y++ )
659
  {
660
    for( unsigned x = 0; x < other.width; x++ )
661
    {
662
      dst[y + x*stride] = src[x + y*other.stride];
663
    }
664
  }
665
}
666
667
template<typename T>
668
bool AreaBuf <T> ::compare( const AreaBuf<const T>& other ) const
669
{
670
        T* mine   =       buf;
671
  const T* theirs = other.buf;
672
  if( width != other.width) return false;
673
  if( height != other.height) return false;
674
675
  for( unsigned y = 0; y < other.height; y++ )
676
  {
677
    for( unsigned x = 0; x < other.width; x++ )
678
    {
679
      if( mine[x + y*stride] != theirs[x+y*other.stride])
680
      {
681
        return false;
682
      }
683
    }
684
  }
685
  return true;
686
}
687
688
#ifndef DONT_UNDEF_SIZE_AWARE_PER_EL_OP
689
#undef SIZE_AWARE_PER_EL_OP
690
#endif // !DONT_UNDEF_SIZE_AWARE_PER_EL_OP
691
692
// ---------------------------------------------------------------------------
693
// UnitBuf struct
694
// ---------------------------------------------------------------------------
695
696
struct UnitArea;
697
698
template<typename T>
699
struct UnitBuf
700
{
701
  typedef static_vector<AreaBuf<T>,       MAX_NUM_COMP> UnitBufBuffers;
702
  typedef static_vector<AreaBuf<const T>, MAX_NUM_COMP> ConstUnitBufBuffers;
703
704
  ChromaFormat chromaFormat;
705
  UnitBufBuffers bufs;
706
707
4.20M
  UnitBuf() : chromaFormat( NUM_CHROMA_FORMAT ) { }
vvenc::UnitBuf<short>::UnitBuf()
Line
Count
Source
707
4.20M
  UnitBuf() : chromaFormat( NUM_CHROMA_FORMAT ) { }
Unexecuted instantiation: vvenc::UnitBuf<short const>::UnitBuf()
708
  UnitBuf( const ChromaFormat _chromaFormat, const UnitBufBuffers&  _bufs ) : chromaFormat( _chromaFormat ), bufs( _bufs ) { }
709
  UnitBuf( const ChromaFormat _chromaFormat,       UnitBufBuffers&& _bufs ) : chromaFormat( _chromaFormat ), bufs( std::forward<UnitBufBuffers>( _bufs ) ) { }
710
0
  UnitBuf( const ChromaFormat _chromaFormat, const AreaBuf<T>&  blkY )      : chromaFormat( _chromaFormat ), bufs{ blkY } { }
711
0
  UnitBuf( const ChromaFormat _chromaFormat,       AreaBuf<T>&& blkY )      : chromaFormat( _chromaFormat ), bufs{ std::forward<AreaBuf<T> >(blkY) } { }
Unexecuted instantiation: vvenc::UnitBuf<short>::UnitBuf(vvencChromaFormat, vvenc::AreaBuf<short>&&)
Unexecuted instantiation: vvenc::UnitBuf<short const>::UnitBuf(vvencChromaFormat, vvenc::AreaBuf<short const>&&)
712
3.33k
  UnitBuf( const ChromaFormat _chromaFormat, const AreaBuf<T>&  blkY, const AreaBuf<T>&  blkCb, const AreaBuf<T>  &blkCr ) : chromaFormat( _chromaFormat ), bufs{ blkY, blkCb, blkCr } { }
713
548k
  UnitBuf( const ChromaFormat _chromaFormat,       AreaBuf<T>&& blkY,       AreaBuf<T>&& blkCb,       AreaBuf<T> &&blkCr ) : chromaFormat( _chromaFormat ), bufs{ std::forward<AreaBuf<T> >(blkY), std::forward<AreaBuf<T> >(blkCb), std::forward<AreaBuf<T> >(blkCr) } { }
vvenc::UnitBuf<short>::UnitBuf(vvencChromaFormat, vvenc::AreaBuf<short>&&, vvenc::AreaBuf<short>&&, vvenc::AreaBuf<short>&&)
Line
Count
Source
713
548k
  UnitBuf( const ChromaFormat _chromaFormat,       AreaBuf<T>&& blkY,       AreaBuf<T>&& blkCb,       AreaBuf<T> &&blkCr ) : chromaFormat( _chromaFormat ), bufs{ std::forward<AreaBuf<T> >(blkY), std::forward<AreaBuf<T> >(blkCb), std::forward<AreaBuf<T> >(blkCr) } { }
Unexecuted instantiation: vvenc::UnitBuf<short const>::UnitBuf(vvencChromaFormat, vvenc::AreaBuf<short const>&&, vvenc::AreaBuf<short const>&&, vvenc::AreaBuf<short const>&&)
714
715
64.6k
  UnitBuf( const UnitBuf& other )  = default;
716
  UnitBuf(       UnitBuf&& other ) = default;
717
  UnitBuf& operator=( const UnitBuf& other )  = default;
718
  UnitBuf& operator=(       UnitBuf&& other ) = default;
719
720
  // conversion from UnitBuf<const T> to UnitBuf<T>
721
  template<bool T_IS_COST = std::is_const<T>::value>
722
283k
  UnitBuf( const UnitBuf<typename std::remove_const<T>::type>& other, std::enable_if<T_IS_COST>* = 0 ) : chromaFormat( other.chromaFormat ), bufs( other.bufs.begin(), other.bufs.end() ) { }
723
724
7.48M
        AreaBuf<T>& get( const ComponentID comp )        { return bufs[comp]; }
vvenc::UnitBuf<short>::get(vvenc::ComponentID)
Line
Count
Source
724
7.48M
        AreaBuf<T>& get( const ComponentID comp )        { return bufs[comp]; }
Unexecuted instantiation: vvenc::UnitBuf<short const>::get(vvenc::ComponentID)
725
56.1k
  const AreaBuf<T>& get( const ComponentID comp )  const { return bufs[comp]; }
vvenc::UnitBuf<short>::get(vvenc::ComponentID) const
Line
Count
Source
725
49.6k
  const AreaBuf<T>& get( const ComponentID comp )  const { return bufs[comp]; }
vvenc::UnitBuf<short const>::get(vvenc::ComponentID) const
Line
Count
Source
725
6.57k
  const AreaBuf<T>& get( const ComponentID comp )  const { return bufs[comp]; }
726
727
1.52M
        AreaBuf<T>& Y()        { return bufs[0]; }
vvenc::UnitBuf<short>::Y()
Line
Count
Source
727
1.52M
        AreaBuf<T>& Y()        { return bufs[0]; }
Unexecuted instantiation: vvenc::UnitBuf<short const>::Y()
728
3.25k
  const AreaBuf<T>& Y()  const { return bufs[0]; }
729
513k
        AreaBuf<T>& Cb()       { return bufs[1]; }
730
  const AreaBuf<T>& Cb() const { return bufs[1]; }
731
513k
        AreaBuf<T>& Cr()       { return bufs[2]; }
732
  const AreaBuf<T>& Cr() const { return bufs[2]; }
733
160k
  bool valid          () const { return bufs.size() != 0; }
734
735
  void fill                 ( const T& val );
736
  void copyFrom             ( const UnitBuf<const T> &other, const bool luma = true, const bool chroma = true );
737
  void reconstruct          ( const UnitBuf<const T>& pred, const UnitBuf<const T>& resi, const ClpRngs& clpRngs );
738
  void copyClip             ( const UnitBuf<const T> &src, const ClpRngs& clpRngs, const bool lumaOnly = false, const bool chromaOnly = false );
739
  void subtract             ( const UnitBuf<const T>& minuend, const UnitBuf<const T>& subtrahend );
740
  void addAvg               ( const UnitBuf<const T>& other1, const UnitBuf<const T>& other2, const ClpRngs& clpRngs, const bool chromaOnly = false, const bool lumaOnly = false);
741
  void addWeightedAvg       ( const UnitBuf<const T>& other1, const UnitBuf<const T>& other2, const ClpRngs& clpRngs, const uint8_t BcwIdx = BCW_DEFAULT, const bool chromaOnly = false, const bool lumaOnly = false);
742
  void padBorderPel         ( unsigned margin, int dir );
743
  void extendBorderPel      ( unsigned margin, bool scale = false);
744
  void extendBorderPelTop   ( int x, int size, int margin );
745
  void extendBorderPelBot   ( int x, int size, int margin );
746
  void extendBorderPelLft   ( int y, int size, int margin );
747
  void extendBorderPelRgt   ( int y, int size, int margin );
748
749
  void removeHighFreq       ( const UnitBuf<const T>& other, const bool bClip, const ClpRngs& clpRngs);
750
751
        UnitBuf<      T> subBuf (const UnitArea& subArea);
752
  const UnitBuf<const T> subBuf (const UnitArea& subArea) const;
753
};
754
755
typedef UnitBuf<      Pel>  PelUnitBuf;
756
typedef UnitBuf<const Pel> CPelUnitBuf;
757
758
typedef UnitBuf<      TCoeff>  CoeffUnitBuf;
759
typedef UnitBuf<const TCoeff> CCoeffUnitBuf;
760
761
template<typename T>
762
void UnitBuf<T>::fill( const T &val )
763
0
{
764
0
  for( int i = 0; i < bufs.size(); i++ )
765
0
  {
766
0
    bufs[i].fill( val );
767
0
  }
768
0
}
769
770
771
template<typename T>
772
void UnitBuf<T>::copyFrom(const UnitBuf<const T> &other, const bool luma, const bool chroma)
773
380k
{
774
380k
  CHECK( chromaFormat != other.chromaFormat, "Incompatible formats" );
775
380k
  CHECK( !luma && !chroma, "At least one channel has to be selected" );
776
777
18.4E
  const size_t compStart = luma   ? 0           : 1;
778
18.4E
  const size_t compEnd   = chroma ? bufs.size() : 1;
779
780
1.52M
  for( size_t i = compStart; i < compEnd; i++ )
781
1.14M
  {
782
1.14M
    if( bufs[ i ].buf != nullptr && other.bufs[ i ].buf != nullptr )
783
769k
      bufs[i].copyFrom( other.bufs[i] );
784
1.14M
  }
785
380k
}
786
787
template<typename T>
788
void UnitBuf<T>::subtract( const UnitBuf<const T>& minuend, const UnitBuf<const T>& subtrahend )
789
0
{
790
0
  CHECK( chromaFormat != minuend.chromaFormat, "Incompatible formats" );
791
0
  CHECK( chromaFormat != subtrahend.chromaFormat, "Incompatible formats");
792
793
0
  for( int i = 0; i < bufs.size(); i++ )
794
0
  {
795
0
    bufs[i].subtract( minuend.bufs[i], subtrahend.bufs[i] );
796
0
  }
797
0
}
798
799
template<typename T>
800
void UnitBuf<T>::copyClip(const UnitBuf<const T> &src, const ClpRngs &clpRngs, const bool lumaOnly, const bool chromaOnly)
801
0
{
802
0
  CHECK( chromaFormat != src.chromaFormat, "Incompatible formats" );
803
804
0
  CHECK(lumaOnly && chromaOnly, "Not allowed to have both lumaOnly and chromaOnly selected");
805
0
  const int compStart = chromaOnly ? 1 : 0;
806
0
  const int compEnd   = lumaOnly   ? 1 : ( int ) bufs.size();
807
0
  for( int i = compStart; i < compEnd; i++ )
808
0
  {
809
0
    bufs[i].copyClip( src.bufs[i], clpRngs[i] );
810
0
  }
811
0
}
812
813
template<typename T>
814
void UnitBuf<T>::reconstruct(const UnitBuf<const T>& pred, const UnitBuf<const T>& resi, const ClpRngs& clpRngs)
815
0
{
816
0
  CHECK( chromaFormat != pred.chromaFormat, "Incompatible formats" );
817
0
  CHECK( chromaFormat != resi.chromaFormat, "Incompatible formats" );
818
819
0
  for( int i = 0; i < bufs.size(); i++ )
820
0
  {
821
0
    bufs[i].reconstruct( pred.bufs[i], resi.bufs[i], clpRngs[i] );
822
0
  }
823
0
}
824
825
template<typename T>
826
void UnitBuf<T>::addAvg(const UnitBuf<const T>& other1, const UnitBuf<const T>& other2, const ClpRngs& clpRngs, const bool chromaOnly /* = false */, const bool lumaOnly /* = false */)
827
0
{
828
0
  const int istart = chromaOnly ? 1 : 0;
829
0
  const int iend   = lumaOnly   ? 1 : ( int ) bufs.size();
830
831
0
  CHECK( lumaOnly && chromaOnly, "should not happen" );
832
833
0
  for( int i = istart; i < iend; i++)
834
0
  {
835
0
    bufs[i].addAvg( other1.bufs[i], other2.bufs[i], clpRngs[i]);
836
0
  }
837
0
}
838
839
template<typename T>
840
void UnitBuf<T>::addWeightedAvg(const UnitBuf<const T>& other1, const UnitBuf<const T>& other2, const ClpRngs& clpRngs, const uint8_t BcwIdx /* = BCW_DEFAULT */, const bool chromaOnly /* = false */, const bool lumaOnly /* = false */)
841
0
{
842
0
  const int istart = chromaOnly ? 1 : 0;
843
0
  const int iend   = lumaOnly   ? 1 : ( int ) bufs.size();
844
845
0
  CHECK( lumaOnly && chromaOnly, "should not happen" );
846
847
0
  for ( int i = istart; i < iend; i++)
848
0
  {
849
0
    bufs[i].addWeightedAvg(other1.bufs[i], other2.bufs[i], clpRngs[i], BcwIdx);
850
0
  }
851
0
}
852
853
template<typename T>
854
void UnitBuf<T>::extendBorderPelTop   ( int x, int size, int margin )
855
2.91k
{
856
11.6k
  for( int i = 0; i < bufs.size(); i++ )
857
8.73k
  {
858
8.73k
    int csx = getComponentScaleX(ComponentID(i), chromaFormat);
859
8.73k
    int csy = getComponentScaleY(ComponentID(i), chromaFormat);
860
8.73k
    bufs[i].extendBorderPelTop( x>>csx, size>>csx, margin>>csy );
861
8.73k
  }
862
2.91k
}
863
864
template<typename T>
865
void UnitBuf<T>::extendBorderPelBot   ( int x, int size, int margin )
866
2.91k
{
867
11.6k
  for( int i = 0; i < bufs.size(); i++ )
868
8.73k
  {
869
8.73k
    int csx = getComponentScaleX(ComponentID(i), chromaFormat);
870
8.73k
    int csy = getComponentScaleY(ComponentID(i), chromaFormat);
871
8.73k
    bufs[i].extendBorderPelBot( x>>csx, size>>csx, margin>>csy );
872
8.73k
  }
873
2.91k
}
874
875
template<typename T>
876
void UnitBuf<T>::extendBorderPelLft   ( int y, int size, int margin )
877
3.80k
{
878
15.2k
  for( int i = 0; i < bufs.size(); i++ )
879
11.4k
  {
880
11.4k
    int csx = getComponentScaleX(ComponentID(i), chromaFormat);
881
11.4k
    int csy = getComponentScaleY(ComponentID(i), chromaFormat);
882
11.4k
    bufs[i].extendBorderPelLft( y>>csy, size>>csy, margin>>csx );
883
11.4k
  }
884
3.80k
}
885
886
template<typename T>
887
void UnitBuf<T>::extendBorderPelRgt   ( int y, int size, int margin )
888
3.80k
{
889
15.2k
  for( int i = 0; i < bufs.size(); i++ )
890
11.4k
  {
891
11.4k
    int csx = getComponentScaleX(ComponentID(i), chromaFormat);
892
11.4k
    int csy = getComponentScaleY(ComponentID(i), chromaFormat);
893
11.4k
    bufs[i].extendBorderPelRgt( y>>csy, size>>csy, margin>>csx );
894
11.4k
  }
895
3.80k
}
896
897
template<typename T>
898
void UnitBuf<T>::extendBorderPel( unsigned margin, bool scaleMargin )
899
1.08k
{
900
1.08k
  if( ! scaleMargin )
901
0
  {
902
0
    for( int i = 0; i < bufs.size(); i++ )
903
0
    {
904
0
      bufs[i].extendBorderPel( margin, margin );
905
0
    }
906
0
  }
907
1.08k
  else
908
1.08k
  {
909
4.34k
    for ( int i = 0; i < bufs.size(); i++)
910
3.25k
    {
911
3.25k
      bufs[i].extendBorderPel(margin >> getComponentScaleX(ComponentID(i), chromaFormat), margin >> getComponentScaleY(ComponentID(i), chromaFormat));
912
3.25k
    }
913
1.08k
  }
914
1.08k
}
915
916
template<typename T>
917
void UnitBuf<T>::padBorderPel( unsigned margin, int dir )
918
0
{
919
0
  for( int i = 0; i < bufs.size(); i++ )
920
0
  {
921
0
    bufs[i].padBorderPel( margin >> getComponentScaleX( ComponentID( i ), chromaFormat ), margin >> getComponentScaleY( ComponentID( i ), chromaFormat ), dir );
922
0
  }
923
0
}
924
925
template<typename T>
926
void UnitBuf<T>::removeHighFreq( const UnitBuf<const T>& other, const bool bClip, const ClpRngs& clpRngs)
927
0
{
928
0
  bufs[0].removeHighFreq(other.bufs[0], bClip, clpRngs[0]);
929
0
}
930
931
template<typename T>
932
UnitBuf<T> UnitBuf<T>::subBuf( const UnitArea& subArea )
933
6.66k
{
934
6.66k
  UnitBuf<T> subBuf;
935
6.66k
  subBuf.chromaFormat = chromaFormat;
936
6.66k
  unsigned blockIdx = 0;
937
938
6.66k
  for( auto &subAreaBuf : bufs )
939
19.9k
  {
940
19.9k
    subBuf.bufs.push_back( subAreaBuf.subBuf( subArea.blocks[blockIdx].pos(), subArea.blocks[blockIdx].size() ) );
941
19.9k
    blockIdx++;
942
19.9k
  }
943
944
6.66k
  return subBuf;
945
6.66k
}
946
947
948
template<typename T>
949
const UnitBuf<const T> UnitBuf<T>::subBuf( const UnitArea& subArea ) const
950
0
{
951
0
  UnitBuf<const T> subBuf;
952
0
  subBuf.chromaFormat = chromaFormat;
953
0
  unsigned blockIdx = 0;
954
955
0
  for( const auto &subAreaBuf : bufs )
956
0
  {
957
0
    subBuf.bufs.push_back( subAreaBuf.subBuf( subArea.blocks[blockIdx].pos(), subArea.blocks[blockIdx].size() ) );
958
0
    blockIdx++;
959
0
  }
960
961
0
  return subBuf;
962
0
}
963
964
// ---------------------------------------------------------------------------
965
// PelStorage struct (PelUnitBuf which allocates its own memory)
966
// ---------------------------------------------------------------------------
967
968
struct UnitArea;
969
struct CompArea;
970
971
struct PelStorage : public PelUnitBuf
972
{
973
  PelStorage();
974
  ~PelStorage();
975
976
  void swap( PelStorage& other );
977
  void createFromBuf( PelUnitBuf buf );
978
  void takeOwnership( PelStorage& other );
979
  void create( const UnitArea& _unit );
980
  void create( const ChromaFormat &_chromaFormat, const Area& _area );
981
  void create( const ChromaFormat &_chromaFormat, const Area& _area, const unsigned _maxCUSize, const unsigned _margin = 0, const unsigned _alignment = 0, const bool _scaleChromaMargin = true );
982
  void destroy();
983
  void compactResize( const UnitArea& area );
984
985
         PelBuf getBuf( const CompArea& blk );
986
  const CPelBuf getBuf( const CompArea& blk ) const;
987
988
         PelBuf getBuf( const ComponentID CompID );
989
  const CPelBuf getBuf( const ComponentID CompID ) const;
990
991
         PelUnitBuf getBuf( const UnitArea& unit );
992
  const CPelUnitBuf getBuf( const UnitArea& unit ) const;
993
34.7k
               Pel* getOrigin( const int id ) const { return m_origin[id]; }
994
995
         PelUnitBuf getBuf(const int strY, const int strCb, const int strCr, const UnitArea& unit);
996
  const CPelUnitBuf getBuf(const int strY, const int strCb, const int strCr, const UnitArea& unit) const;
997
998
         PelUnitBuf getBufPart( const UnitArea& unit );
999
  const CPelUnitBuf getBufPart( const UnitArea& unit ) const;
1000
1001
         PelUnitBuf getCompactBuf(const UnitArea& unit);
1002
  const CPelUnitBuf getCompactBuf(const UnitArea& unit) const;
1003
1004
         PelBuf     getCompactBuf(const CompArea& blk);
1005
  const CPelBuf     getCompactBuf(const CompArea& blk) const;
1006
1007
private:
1008
1009
  UnitArea m_maxArea;
1010
  Pel* m_origin[MAX_NUM_COMP];
1011
};
1012
1013
struct CompStorage : public PelBuf
1014
{
1015
312k
  ~CompStorage() { if( valid() ) delete[] m_memory; }
1016
1017
  void compactResize( const Size& size )
1018
2.54M
  {
1019
2.54M
    CHECK( size.area() > m_allocSize, "Resizing causes buffer overflow!" );
1020
2.54M
    Size::operator=( size );
1021
2.54M
    stride = size.width;
1022
2.54M
  }
1023
  void create( const Size& size )
1024
312k
  {
1025
312k
    CHECK( m_memory, "Trying to re-create an already initialized buffer" );
1026
312k
    m_allocSize = size.area();
1027
312k
    m_memory = new Pel[m_allocSize];
1028
312k
    PelBuf::operator=( PelBuf( m_memory, size ) );
1029
312k
  }
1030
  void destroy()
1031
0
  {
1032
0
    if( valid() ) delete[] m_memory;
1033
0
    m_memory    = nullptr;
1034
0
    m_allocSize = 0;
1035
0
  }
1036
791k
  bool valid() { return m_memory != nullptr; }
1037
private:
1038
  ptrdiff_t m_allocSize = 0;
1039
  Pel*      m_memory    = nullptr;
1040
};
1041
1042
template<int NumEntries>
1043
struct SortedPelUnitBufs
1044
{
1045
  void create(ChromaFormat cform, int maxWidth, int maxHeight)
1046
17.3k
  {
1047
17.3k
    m_pacBufs.resize(NumEntries + 1);
1048
17.3k
    m_acStorage.resize(NumEntries + 1);
1049
191k
    for (size_t i = 0; i <= NumEntries; i++)
1050
173k
    {
1051
173k
      m_acStorage[i].create(cform, Area(0, 0, maxWidth, maxHeight));
1052
173k
    }
1053
17.3k
  }
1054
1055
  void destroy()
1056
17.3k
  {
1057
191k
    for (size_t i = 0; i <= NumEntries; i++)
1058
173k
    {
1059
173k
      m_acStorage[i].destroy();
1060
173k
    }
1061
17.3k
  }
1062
1063
  void reset()
1064
  {
1065
    m_sortedList.clear();
1066
  }
1067
1068
  void reduceTo(int numModes)
1069
17.4k
  {
1070
17.4k
    CHECK( numModes > m_sortedList.size(), "not enough buffers");
1071
17.4k
    m_sortedList.resize(numModes);
1072
17.4k
  }
1073
1074
  void prepare( const UnitArea& ua, int numModes)
1075
22.7k
  {
1076
22.7k
    CHECK( numModes > NumEntries, "not enough buffers");
1077
22.7k
    m_sortedList.resize(numModes);
1078
108k
    for (size_t i = 0; i < numModes; i++)
1079
85.5k
    {
1080
85.5k
      m_pacBufs[i] = m_acStorage[i].getCompactBuf(ua);
1081
85.5k
      m_sortedList[i] = &m_pacBufs[i];
1082
85.5k
    }
1083
1084
22.7k
    m_pacBufs[numModes] = m_acStorage[numModes].getCompactBuf(ua);
1085
22.7k
    m_TestBuf = &m_pacBufs[numModes];
1086
22.7k
  }
1087
1088
104k
  PelUnitBuf* getBufFromSortedList( int idx)              const { return m_sortedList.size() > idx ? m_sortedList[idx]: nullptr; }
1089
22.7k
  PelBuf&     getTestBuf          ( ComponentID compId)   const { return m_TestBuf->bufs[compId]; }
1090
849k
  PelUnitBuf& getTestBuf          ()                      const { return *m_TestBuf; }
1091
1092
  void swap( unsigned pos1, unsigned pos2 )
1093
0
  {
1094
0
    CHECK( pos1 >= m_sortedList.size(), "index out of range" );
1095
0
    CHECK( pos2 >= m_sortedList.size(), "index out of range" );
1096
0
    std::swap(m_sortedList[pos1], m_sortedList[pos2]);
1097
0
  }
1098
1099
  void insert(int insertPos, int RdListSize)
1100
849k
  {
1101
849k
    if (insertPos != -1)
1102
120k
    {
1103
132k
      for (int i = RdListSize - 1; i > insertPos; i--)
1104
11.4k
      {
1105
11.4k
        std::swap(m_sortedList[i - 1], m_sortedList[i]);
1106
11.4k
      }
1107
120k
      std::swap(m_TestBuf, m_sortedList[insertPos]);
1108
120k
    }
1109
849k
  }
1110
1111
private:
1112
  PelUnitBuf*                             m_TestBuf;
1113
  static_vector<PelUnitBuf*,NumEntries>   m_sortedList;
1114
  static_vector<PelUnitBuf, NumEntries+1> m_pacBufs;
1115
  static_vector<PelStorage, NumEntries+1> m_acStorage;
1116
};
1117
1118
struct Window;
1119
1120
void copyPadToPelUnitBuf( PelUnitBuf pelUnitBuf, const vvencYUVBuffer& yuvBuffer, const ChromaFormat& chFmt );
1121
//void setupPelUnitBuf( const YUVBuffer& yuvBuffer, PelUnitBuf& pelUnitBuf, const ChromaFormat& chFmt );
1122
void setupYuvBuffer ( const PelUnitBuf& pelUnitBuf, vvencYUVBuffer& yuvBuffer, const Window* confWindow );
1123
1124
} // namespace vvenc
1125
1126
//! \}
1127