Coverage Report

Created: 2026-05-16 06:41

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.91M
#define INCY( ptr, stride ) { ptr += ( stride ); }
101
11.5M
#define OFFSETX( ptr, stride, x ) { ptr += ( x ); }
102
1.08M
#define OFFSETY( ptr, stride, y ) { ptr += ( y ) * ( stride ); }
103
2.07M
#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
18.4M
  AreaBuf()                                                                               : Size(),                  buf( NULL ), stride( 0 )          { }
vvenc::AreaBuf<short>::AreaBuf()
Line
Count
Source
154
17.3M
  AreaBuf()                                                                               : Size(),                  buf( NULL ), stride( 0 )          { }
vvenc::AreaBuf<short const>::AreaBuf()
Line
Count
Source
154
1.04M
  AreaBuf()                                                                               : Size(),                  buf( NULL ), stride( 0 )          { }
Unexecuted instantiation: vvenc::AreaBuf<int>::AreaBuf()
Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo>::AreaBuf()
155
7.60M
  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.77M
  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.93M
  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
7.30k
  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.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&)
156
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
156
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
156
38.0k
  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
782k
  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
7.30k
  AreaBuf( T *_buf, const int& _stride, const Size& size )                                : Size( size ),            buf( _buf ), stride( _stride )    { }
157
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
157
49.2k
  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.77M
  AreaBuf( T *_buf, const SizeType& _width, const SizeType& _height )                     : Size( _width, _height ), buf( _buf ), stride( _width )     { }
158
10.4M
  AreaBuf( T *_buf, const int& _stride, const SizeType& _width, const SizeType& _height ) : Size( _width, _height ), buf( _buf ), stride( _stride )    { }
vvenc::AreaBuf<short>::AreaBuf(short*, int const&, unsigned int const&, unsigned int const&)
Line
Count
Source
158
9.88M
  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
608k
  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
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
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<vvenc::MotionInfo const>::AreaBuf<true>(vvenc::AreaBuf<vvenc::MotionInfo> const&, std::__1::enable_if<true, void>::type*)
Line
Count
Source
167
51.5k
  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.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 ) { }
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
261M
        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
261M
        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.77G
  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.76G
  const T& at( const int& x, const int& y ) const    { return buf[y * stride + x]; }
Unexecuted instantiation: vvenc::AreaBuf<short>::at(int const&, int const&) const
Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo const>::at(int const&, int const&) const
vvenc::AreaBuf<int const>::at(int const&, int const&) const
Line
Count
Source
201
4.49M
  const T& at( const int& x, const int& y ) const    { return buf[y * stride + x]; }
202
203
2.12M
        T& at( const Position& pos )                 { return buf[pos.y * stride + pos.x]; }
Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo>::at(vvenc::Position const&)
Unexecuted instantiation: vvenc::AreaBuf<short const>::at(vvenc::Position const&)
vvenc::AreaBuf<short>::at(vvenc::Position const&)
Line
Count
Source
203
2.11M
        T& at( const Position& pos )                 { return buf[pos.y * stride + pos.x]; }
vvenc::AreaBuf<vvenc::LoopFilterParam>::at(vvenc::Position const&)
Line
Count
Source
203
7.30k
        T& at( const Position& pos )                 { return buf[pos.y * stride + pos.x]; }
204
32.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
11.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
21.8k
  const T& at( const Position& pos ) const           { return buf[pos.y * stride + pos.x]; }
205
206
207
11.7k
        T* bufAt( const int& x, const int& y )       { return &at( x, y ); }
208
180k
  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
180k
  const T* bufAt( const int& x, const int& y ) const { return &at( x, y ); }
Unexecuted instantiation: vvenc::AreaBuf<short>::bufAt(int const&, int const&) const
209
210
2.12M
        T* bufAt( const Position& pos )              { return &at( pos ); }
Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo>::bufAt(vvenc::Position const&)
Unexecuted instantiation: vvenc::AreaBuf<short const>::bufAt(vvenc::Position const&)
vvenc::AreaBuf<short>::bufAt(vvenc::Position const&)
Line
Count
Source
210
2.11M
        T* bufAt( const Position& pos )              { return &at( pos ); }
vvenc::AreaBuf<vvenc::LoopFilterParam>::bufAt(vvenc::Position const&)
Line
Count
Source
210
7.30k
        T* bufAt( const Position& pos )              { return &at( pos ); }
211
32.8k
  const T* bufAt( const Position& pos ) const        { return &at( pos ); }
vvenc::AreaBuf<short const>::bufAt(vvenc::Position const&) const
Line
Count
Source
211
11.0k
  const T* bufAt( const Position& pos ) const        { return &at( pos ); }
vvenc::AreaBuf<short>::bufAt(vvenc::Position const&) const
Line
Count
Source
211
21.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
29.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
215
21.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
7.30k
  AreaBuf<      T> subBuf( const Position& pos, const Size& size )                                    { return AreaBuf<      T>( bufAt( pos  ), stride, size   ); }
216
10.9k
  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
10.9k
  AreaBuf<const T> subBuf( const Position& pos, const Size& size )                              const { return AreaBuf<const T>( bufAt( pos  ), stride, size   ); }
Unexecuted instantiation: vvenc::AreaBuf<short>::subBuf(vvenc::Position const&, vvenc::Size const&) const
217
0
  AreaBuf<      T> subBuf( const int& x, const int& y, const unsigned& _w, const unsigned& _h )       { return AreaBuf<      T>( bufAt( x, y ), stride, _w, _h ); }
218
  AreaBuf<const T> subBuf( const int& x, const int& y, const unsigned& _w, const unsigned& _h ) const { return AreaBuf<const T>( bufAt( x, y ), stride, _w, _h ); }
219
};
220
221
typedef AreaBuf<      Pel>  PelBuf;
222
typedef AreaBuf<const Pel> CPelBuf;
223
224
typedef AreaBuf<      TCoeff>  CoeffBuf;
225
typedef AreaBuf<const TCoeff> CCoeffBuf;
226
227
typedef AreaBuf<      TCoeffSig>  CoeffSigBuf;
228
typedef AreaBuf<const TCoeffSig> CCoeffSigBuf;
229
230
typedef AreaBuf<      MotionInfo>  MotionBuf;
231
typedef AreaBuf<const MotionInfo> CMotionBuf;
232
233
typedef AreaBuf<      TCoeff>  PLTescapeBuf;
234
typedef AreaBuf<const TCoeff> CPLTescapeBuf;
235
236
typedef AreaBuf<      bool>  PLTtypeBuf;
237
typedef AreaBuf<const bool> CPLTtypeBuf;
238
239
typedef AreaBuf<      LoopFilterParam>  LFPBuf;
240
typedef AreaBuf<const LoopFilterParam> CLFPBuf;
241
242
5.30M
#define SIZE_AWARE_PER_EL_OP( OP, INC )                     \
243
5.30M
if( ( width & 7 ) == 0 )                                    \
244
4.29M
{                                                           \
245
68.0M
  for( int y = 0; y < height; y++ )                         \
246
63.7M
  {                                                         \
247
252M
    for( int x = 0; x < width; x += 8 )                     \
248
188M
    {                                                       \
249
188M
      OP( x + 0 );                                          \
250
188M
      OP( x + 1 );                                          \
251
188M
      OP( x + 2 );                                          \
252
188M
      OP( x + 3 );                                          \
253
188M
      OP( x + 4 );                                          \
254
188M
      OP( x + 5 );                                          \
255
188M
      OP( x + 6 );                                          \
256
188M
      OP( x + 7 );                                          \
257
188M
    }                                                       \
258
63.7M
                                                            \
259
63.7M
    INC;                                                    \
260
63.7M
  }                                                         \
261
4.29M
}                                                           \
262
5.30M
else if( ( width & 3 ) == 0 )                               \
263
1.01M
{                                                           \
264
12.3M
  for( int y = 0; y < height; y++ )                         \
265
11.3M
  {                                                         \
266
25.2M
    for( int x = 0; x < width; x += 4 )                     \
267
13.9M
    {                                                       \
268
13.9M
      OP( x + 0 );                                          \
269
13.9M
      OP( x + 1 );                                          \
270
13.9M
      OP( x + 2 );                                          \
271
13.9M
      OP( x + 3 );                                          \
272
13.9M
    }                                                       \
273
11.3M
                                                            \
274
11.3M
    INC;                                                    \
275
11.3M
  }                                                         \
276
1.01M
}                                                           \
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
24.4k
{
307
24.4k
  const T* src = buf;
308
24.4k
  int64_t  acc = 0;
309
310
24.4k
#define AVG_INC      src += stride
311
99.7M
#define AVG_OP(ADDR) acc += src[ADDR]
312
99.7M
  SIZE_AWARE_PER_EL_OP(AVG_OP, AVG_INC);
313
24.4k
#undef AVG_INC
314
24.4k
#undef AVG_OP
315
316
24.4k
  return T ((acc + (area() >> 1)) / area());
317
24.4k
}
vvenc::AreaBuf<short const>::getAvg() const
Line
Count
Source
306
23.2k
{
307
23.2k
  const T* src = buf;
308
23.2k
  int64_t  acc = 0;
309
310
23.2k
#define AVG_INC      src += stride
311
23.2k
#define AVG_OP(ADDR) acc += src[ADDR]
312
23.2k
  SIZE_AWARE_PER_EL_OP(AVG_OP, AVG_INC);
313
23.2k
#undef AVG_INC
314
23.2k
#undef AVG_OP
315
316
23.2k
  return T ((acc + (area() >> 1)) / area());
317
23.2k
}
vvenc::AreaBuf<short>::getAvg() const
Line
Count
Source
306
1.22k
{
307
1.22k
  const T* src = buf;
308
1.22k
  int64_t  acc = 0;
309
310
1.22k
#define AVG_INC      src += stride
311
1.22k
#define AVG_OP(ADDR) acc += src[ADDR]
312
1.22k
  SIZE_AWARE_PER_EL_OP(AVG_OP, AVG_INC);
313
1.22k
#undef AVG_INC
314
1.22k
#undef AVG_OP
315
316
1.22k
  return T ((acc + (area() >> 1)) / area());
317
1.22k
}
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.77M
{
325
1.77M
  if( T( 0 ) == val )
326
1.65M
  {
327
1.65M
    GCC_WARNING_DISABLE_class_memaccess
328
1.65M
    if( width == stride )
329
1.65M
    {
330
1.65M
      ::memset( buf, 0, width * height * sizeof( T ) );
331
1.65M
    }
332
3.52k
    else
333
3.52k
    {
334
3.52k
      T* dest = buf;
335
3.52k
      size_t line = width * sizeof( T );
336
337
126k
      for( unsigned y = 0; y < height; y++ )
338
123k
      {
339
123k
        ::memset( dest, 0, line );
340
341
123k
        dest += stride;
342
123k
      }
343
3.52k
    }
344
1.65M
    GCC_WARNING_RESET
345
1.65M
  }
346
118k
  else
347
118k
  {
348
118k
    if( width == stride )
349
118k
    {
350
118k
      std::fill_n( buf, width * height, val );
351
118k
    }
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
118k
  }
362
1.77M
}
363
364
template<typename T>
365
void AreaBuf<T>::memset( const int val )
366
666k
{
367
666k
  GCC_WARNING_DISABLE_class_memaccess
368
666k
  if( width == stride )
369
661k
  {
370
661k
    ::memset( buf, val, width * height * sizeof( T ) );
371
661k
  }
372
5.33k
  else
373
5.33k
  {
374
5.33k
    T* dest = buf;
375
5.33k
    size_t line = width * sizeof( T );
376
377
126k
    for( int y = 0; y < height; y++, dest += stride )
378
121k
    {
379
121k
      ::memset( dest, val, line );
380
121k
    }
381
5.33k
  }
382
666k
  GCC_WARNING_RESET
383
666k
}
vvenc::AreaBuf<vvenc::MotionInfo>::memset(int)
Line
Count
Source
366
653k
{
367
653k
  GCC_WARNING_DISABLE_class_memaccess
368
653k
  if( width == stride )
369
653k
  {
370
653k
    ::memset( buf, val, width * height * sizeof( T ) );
371
653k
  }
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
653k
  GCC_WARNING_RESET
383
653k
}
vvenc::AreaBuf<vvenc::LoopFilterParam>::memset(int)
Line
Count
Source
366
7.30k
{
367
7.30k
  GCC_WARNING_DISABLE_class_memaccess
368
7.30k
  if( width == stride )
369
1.97k
  {
370
1.97k
    ::memset( buf, val, width * height * sizeof( T ) );
371
1.97k
  }
372
5.33k
  else
373
5.33k
  {
374
5.33k
    T* dest = buf;
375
5.33k
    size_t line = width * sizeof( T );
376
377
126k
    for( int y = 0; y < height; y++, dest += stride )
378
121k
    {
379
121k
      ::memset( dest, val, line );
380
121k
    }
381
5.33k
  }
382
7.30k
  GCC_WARNING_RESET
383
7.30k
}
vvenc::AreaBuf<short>::memset(int)
Line
Count
Source
366
5.86k
{
367
5.86k
  GCC_WARNING_DISABLE_class_memaccess
368
5.86k
  if( width == stride )
369
5.86k
  {
370
5.86k
    ::memset( buf, val, width * height * sizeof( T ) );
371
5.86k
  }
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.86k
  GCC_WARNING_RESET
383
5.86k
}
384
385
template<typename T>
386
void AreaBuf<T>::copyFrom( const AreaBuf<const T>& other )
387
8.59M
{
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
8.59M
  g_pelBufOP.copyBuffer( ( const char* ) other.buf, other.stride * sizeof( T ), ( char* ) buf, stride * sizeof( T ), width * sizeof( T ), height );
393
8.59M
}
vvenc::AreaBuf<vvenc::MotionInfo>::copyFrom(vvenc::AreaBuf<vvenc::MotionInfo const> const&)
Line
Count
Source
387
51.5k
{
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
51.5k
  g_pelBufOP.copyBuffer( ( const char* ) other.buf, other.stride * sizeof( T ), ( char* ) buf, stride * sizeof( T ), width * sizeof( T ), height );
393
51.5k
}
vvenc::AreaBuf<short>::copyFrom(vvenc::AreaBuf<short const> const&)
Line
Count
Source
387
8.54M
{
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
8.54M
  g_pelBufOP.copyBuffer( ( const char* ) other.buf, other.stride * sizeof( T ), ( char* ) buf, stride * sizeof( T ), width * sizeof( T ), height );
393
8.54M
}
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
12.7k
{
511
12.7k
  T* p = buf + y * stride;
512
12.7k
  int h = size + y;
513
514
  // do left and right margins
515
726k
  for (; y < h; y++)
516
713k
  {
517
30.9M
    for (int x = 0; x < margin; x++)
518
30.2M
    {
519
30.2M
      *(p - margin + x) = p[0];
520
30.2M
    }
521
713k
    p += stride;
522
713k
  }
523
12.7k
}
524
525
template<typename T>
526
void AreaBuf<T>::extendBorderPelTop( int x, int size, int margin )
527
9.77k
{
528
9.77k
  T* p = buf + x;
529
530
  // p is now (-marginX, 0)
531
379k
  for (int y = 0; y < margin; y++)
532
369k
  {
533
369k
    ::memcpy(p - (y + 1) * stride, p, sizeof(T) * size);
534
369k
  }
535
9.77k
}
536
537
template<typename T>
538
void AreaBuf<T>::extendBorderPelRgt( int y, int size, int margin )
539
12.7k
{
540
12.7k
  T* p = buf + y * stride;
541
12.7k
  int h = size + y;
542
543
  // do left and right margins
544
738k
  for( ; y < h; y++)
545
725k
  {
546
34.8M
    for (int x = 0; x < margin; x++)
547
34.1M
    {
548
34.1M
      p[width + x] = p[width - 1];
549
34.1M
    }
550
725k
    p += stride;
551
725k
  }
552
12.7k
}
553
554
template<typename T>
555
void AreaBuf<T>::extendBorderPelBot( int x, int size, int margin )
556
9.77k
{
557
9.77k
  T* p = buf + (height-1)*stride + x;
558
559
  // p is now the (-margin, height-1)
560
379k
  for (int y = 0; y < margin; y++)
561
369k
  {
562
369k
    ::memcpy(p + (y + 1) * stride, p, sizeof(T) * size);
563
369k
  }
564
9.77k
}
565
566
template<typename T>
567
void AreaBuf<T>::extendBorderPel(unsigned marginX, unsigned marginY)
568
3.67k
{
569
3.67k
  T* p = buf;
570
3.67k
  int h = height;
571
3.67k
  int w = width;
572
3.67k
  int s = stride;
573
574
3.67k
  CHECK((w + 2 * marginX) > s, "Size of buffer too small to extend");
575
  // do left and right margins
576
372k
  for (int y = 0; y < h; y++)
577
369k
  {
578
35.8M
    for (int x = 0; x < marginX; x++)
579
35.4M
    {
580
35.4M
      *(p - marginX + x) = p[0];
581
35.4M
      p[w + x] = p[w - 1];
582
35.4M
    }
583
369k
    p += s;
584
369k
  }
585
586
  // p is now the (0,height) (bottom left of image within bigger picture
587
3.67k
  p -= (s + marginX);
588
  // p is now the (-margin, height-1)
589
317k
  for (int y = 0; y < marginY; y++)
590
313k
  {
591
313k
    ::memcpy(p + (y + 1) * s, p, sizeof(T) * (w + (marginX << 1)));
592
313k
  }
593
594
  // p is still (-marginX, height-1)
595
3.67k
  p -= ((h - 1) * s);
596
  // p is now (-marginX, 0)
597
317k
  for (int y = 0; y < marginY; y++)
598
313k
  {
599
313k
    ::memcpy(p - (y + 1) * s, p, sizeof(T) * (w + (marginX << 1)));
600
313k
  }
601
3.67k
}
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.74M
  UnitBuf() : chromaFormat( NUM_CHROMA_FORMAT ) { }
vvenc::UnitBuf<short>::UnitBuf()
Line
Count
Source
707
4.74M
  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.65k
  UnitBuf( const ChromaFormat _chromaFormat, const AreaBuf<T>&  blkY, const AreaBuf<T>&  blkCb, const AreaBuf<T>  &blkCr ) : chromaFormat( _chromaFormat ), bufs{ blkY, blkCb, blkCr } { }
713
612k
  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
612k
  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
71.3k
  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
316k
  UnitBuf( const UnitBuf<typename std::remove_const<T>::type>& other, std::enable_if<T_IS_COST>* = 0 ) : chromaFormat( other.chromaFormat ), bufs( other.bufs.begin(), other.bufs.end() ) { }
723
724
8.44M
        AreaBuf<T>& get( const ComponentID comp )        { return bufs[comp]; }
vvenc::UnitBuf<short>::get(vvenc::ComponentID)
Line
Count
Source
724
8.44M
        AreaBuf<T>& get( const ComponentID comp )        { return bufs[comp]; }
Unexecuted instantiation: vvenc::UnitBuf<short const>::get(vvenc::ComponentID)
725
61.8k
  const AreaBuf<T>& get( const ComponentID comp )  const { return bufs[comp]; }
vvenc::UnitBuf<short>::get(vvenc::ComponentID) const
Line
Count
Source
725
54.4k
  const AreaBuf<T>& get( const ComponentID comp )  const { return bufs[comp]; }
vvenc::UnitBuf<short const>::get(vvenc::ComponentID) const
Line
Count
Source
725
7.42k
  const AreaBuf<T>& get( const ComponentID comp )  const { return bufs[comp]; }
726
727
1.70M
        AreaBuf<T>& Y()        { return bufs[0]; }
vvenc::UnitBuf<short>::Y()
Line
Count
Source
727
1.70M
        AreaBuf<T>& Y()        { return bufs[0]; }
Unexecuted instantiation: vvenc::UnitBuf<short const>::Y()
728
3.67k
  const AreaBuf<T>& Y()  const { return bufs[0]; }
729
571k
        AreaBuf<T>& Cb()       { return bufs[1]; }
730
  const AreaBuf<T>& Cb() const { return bufs[1]; }
731
571k
        AreaBuf<T>& Cr()       { return bufs[2]; }
732
  const AreaBuf<T>& Cr() const { return bufs[2]; }
733
179k
  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
424k
{
774
424k
  CHECK( chromaFormat != other.chromaFormat, "Incompatible formats" );
775
424k
  CHECK( !luma && !chroma, "At least one channel has to be selected" );
776
777
424k
  const size_t compStart = luma   ? 0           : 1;
778
424k
  const size_t compEnd   = chroma ? bufs.size() : 1;
779
780
1.69M
  for( size_t i = compStart; i < compEnd; i++ )
781
1.27M
  {
782
1.27M
    if( bufs[ i ].buf != nullptr && other.bufs[ i ].buf != nullptr )
783
860k
      bufs[i].copyFrom( other.bufs[i] );
784
1.27M
  }
785
424k
}
786
787
template<typename T>
788
void UnitBuf<T>::subtract( const UnitBuf<const T>& minuend, const UnitBuf<const T>& subtrahend )
789
0
{
790
0
  CHECK( chromaFormat != minuend.chromaFormat, "Incompatible formats" );
791
0
  CHECK( chromaFormat != subtrahend.chromaFormat, "Incompatible formats");
792
793
0
  for( int i = 0; i < bufs.size(); i++ )
794
0
  {
795
0
    bufs[i].subtract( minuend.bufs[i], subtrahend.bufs[i] );
796
0
  }
797
0
}
798
799
template<typename T>
800
void UnitBuf<T>::copyClip(const UnitBuf<const T> &src, const ClpRngs &clpRngs, const bool lumaOnly, const bool chromaOnly)
801
0
{
802
0
  CHECK( chromaFormat != src.chromaFormat, "Incompatible formats" );
803
804
0
  CHECK(lumaOnly && chromaOnly, "Not allowed to have both lumaOnly and chromaOnly selected");
805
0
  const int compStart = chromaOnly ? 1 : 0;
806
0
  const int compEnd   = lumaOnly   ? 1 : ( int ) bufs.size();
807
0
  for( int i = compStart; i < compEnd; i++ )
808
0
  {
809
0
    bufs[i].copyClip( src.bufs[i], clpRngs[i] );
810
0
  }
811
0
}
812
813
template<typename T>
814
void UnitBuf<T>::reconstruct(const UnitBuf<const T>& pred, const UnitBuf<const T>& resi, const ClpRngs& clpRngs)
815
0
{
816
0
  CHECK( chromaFormat != pred.chromaFormat, "Incompatible formats" );
817
0
  CHECK( chromaFormat != resi.chromaFormat, "Incompatible formats" );
818
819
0
  for( int i = 0; i < bufs.size(); i++ )
820
0
  {
821
0
    bufs[i].reconstruct( pred.bufs[i], resi.bufs[i], clpRngs[i] );
822
0
  }
823
0
}
824
825
template<typename T>
826
void UnitBuf<T>::addAvg(const UnitBuf<const T>& other1, const UnitBuf<const T>& other2, const ClpRngs& clpRngs, const bool chromaOnly /* = false */, const bool lumaOnly /* = false */)
827
0
{
828
0
  const int istart = chromaOnly ? 1 : 0;
829
0
  const int iend   = lumaOnly   ? 1 : ( int ) bufs.size();
830
831
0
  CHECK( lumaOnly && chromaOnly, "should not happen" );
832
833
0
  for( int i = istart; i < iend; i++)
834
0
  {
835
0
    bufs[i].addAvg( other1.bufs[i], other2.bufs[i], clpRngs[i]);
836
0
  }
837
0
}
838
839
template<typename T>
840
void UnitBuf<T>::addWeightedAvg(const UnitBuf<const T>& other1, const UnitBuf<const T>& other2, const ClpRngs& clpRngs, const uint8_t BcwIdx /* = BCW_DEFAULT */, const bool chromaOnly /* = false */, const bool lumaOnly /* = false */)
841
0
{
842
0
  const int istart = chromaOnly ? 1 : 0;
843
0
  const int iend   = lumaOnly   ? 1 : ( int ) bufs.size();
844
845
0
  CHECK( lumaOnly && chromaOnly, "should not happen" );
846
847
0
  for ( int i = istart; i < iend; i++)
848
0
  {
849
0
    bufs[i].addWeightedAvg(other1.bufs[i], other2.bufs[i], clpRngs[i], BcwIdx);
850
0
  }
851
0
}
852
853
template<typename T>
854
void UnitBuf<T>::extendBorderPelTop   ( int x, int size, int margin )
855
3.25k
{
856
13.0k
  for( int i = 0; i < bufs.size(); i++ )
857
9.77k
  {
858
9.77k
    int csx = getComponentScaleX(ComponentID(i), chromaFormat);
859
9.77k
    int csy = getComponentScaleY(ComponentID(i), chromaFormat);
860
9.77k
    bufs[i].extendBorderPelTop( x>>csx, size>>csx, margin>>csy );
861
9.77k
  }
862
3.25k
}
863
864
template<typename T>
865
void UnitBuf<T>::extendBorderPelBot   ( int x, int size, int margin )
866
3.25k
{
867
13.0k
  for( int i = 0; i < bufs.size(); i++ )
868
9.77k
  {
869
9.77k
    int csx = getComponentScaleX(ComponentID(i), chromaFormat);
870
9.77k
    int csy = getComponentScaleY(ComponentID(i), chromaFormat);
871
9.77k
    bufs[i].extendBorderPelBot( x>>csx, size>>csx, margin>>csy );
872
9.77k
  }
873
3.25k
}
874
875
template<typename T>
876
void UnitBuf<T>::extendBorderPelLft   ( int y, int size, int margin )
877
4.25k
{
878
17.0k
  for( int i = 0; i < bufs.size(); i++ )
879
12.7k
  {
880
12.7k
    int csx = getComponentScaleX(ComponentID(i), chromaFormat);
881
12.7k
    int csy = getComponentScaleY(ComponentID(i), chromaFormat);
882
12.7k
    bufs[i].extendBorderPelLft( y>>csy, size>>csy, margin>>csx );
883
12.7k
  }
884
4.25k
}
885
886
template<typename T>
887
void UnitBuf<T>::extendBorderPelRgt   ( int y, int size, int margin )
888
4.26k
{
889
17.0k
  for( int i = 0; i < bufs.size(); i++ )
890
12.7k
  {
891
12.7k
    int csx = getComponentScaleX(ComponentID(i), chromaFormat);
892
12.7k
    int csy = getComponentScaleY(ComponentID(i), chromaFormat);
893
12.7k
    bufs[i].extendBorderPelRgt( y>>csy, size>>csy, margin>>csx );
894
12.7k
  }
895
4.26k
}
896
897
template<typename T>
898
void UnitBuf<T>::extendBorderPel( unsigned margin, bool scaleMargin )
899
1.22k
{
900
1.22k
  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.22k
  else
908
1.22k
  {
909
4.90k
    for ( int i = 0; i < bufs.size(); i++)
910
3.67k
    {
911
3.67k
      bufs[i].extendBorderPel(margin >> getComponentScaleX(ComponentID(i), chromaFormat), margin >> getComponentScaleY(ComponentID(i), chromaFormat));
912
3.67k
    }
913
1.22k
  }
914
1.22k
}
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
7.30k
{
934
7.30k
  UnitBuf<T> subBuf;
935
7.30k
  subBuf.chromaFormat = chromaFormat;
936
7.30k
  unsigned blockIdx = 0;
937
938
7.30k
  for( auto &subAreaBuf : bufs )
939
21.9k
  {
940
21.9k
    subBuf.bufs.push_back( subAreaBuf.subBuf( subArea.blocks[blockIdx].pos(), subArea.blocks[blockIdx].size() ) );
941
21.9k
    blockIdx++;
942
21.9k
  }
943
944
7.30k
  return subBuf;
945
7.30k
}
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
39.2k
               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
353k
  ~CompStorage() { if( valid() ) delete[] m_memory; }
1016
1017
  void compactResize( const Size& size )
1018
2.87M
  {
1019
2.87M
    CHECK( size.area() > m_allocSize, "Resizing causes buffer overflow!" );
1020
2.87M
    Size::operator=( size );
1021
2.87M
    stride = size.width;
1022
2.87M
  }
1023
  void create( const Size& size )
1024
353k
  {
1025
353k
    CHECK( m_memory, "Trying to re-create an already initialized buffer" );
1026
353k
    m_allocSize = size.area();
1027
353k
    m_memory = new Pel[m_allocSize];
1028
353k
    PelBuf::operator=( PelBuf( m_memory, size ) );
1029
353k
  }
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
896k
  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
19.6k
  {
1047
19.6k
    m_pacBufs.resize(NumEntries + 1);
1048
19.6k
    m_acStorage.resize(NumEntries + 1);
1049
215k
    for (size_t i = 0; i <= NumEntries; i++)
1050
196k
    {
1051
196k
      m_acStorage[i].create(cform, Area(0, 0, maxWidth, maxHeight));
1052
196k
    }
1053
19.6k
  }
1054
1055
  void destroy()
1056
19.6k
  {
1057
215k
    for (size_t i = 0; i <= NumEntries; i++)
1058
196k
    {
1059
196k
      m_acStorage[i].destroy();
1060
196k
    }
1061
19.6k
  }
1062
1063
  void reset()
1064
  {
1065
    m_sortedList.clear();
1066
  }
1067
1068
  void reduceTo(int numModes)
1069
19.3k
  {
1070
19.3k
    CHECK( numModes > m_sortedList.size(), "not enough buffers");
1071
19.3k
    m_sortedList.resize(numModes);
1072
19.3k
  }
1073
1074
  void prepare( const UnitArea& ua, int numModes)
1075
25.2k
  {
1076
25.2k
    CHECK( numModes > NumEntries, "not enough buffers");
1077
25.2k
    m_sortedList.resize(numModes);
1078
120k
    for (size_t i = 0; i < numModes; i++)
1079
95.0k
    {
1080
95.0k
      m_pacBufs[i] = m_acStorage[i].getCompactBuf(ua);
1081
95.0k
      m_sortedList[i] = &m_pacBufs[i];
1082
95.0k
    }
1083
1084
25.2k
    m_pacBufs[numModes] = m_acStorage[numModes].getCompactBuf(ua);
1085
25.2k
    m_TestBuf = &m_pacBufs[numModes];
1086
25.2k
  }
1087
1088
116k
  PelUnitBuf* getBufFromSortedList( int idx)              const { return m_sortedList.size() > idx ? m_sortedList[idx]: nullptr; }
1089
25.2k
  PelBuf&     getTestBuf          ( ComponentID compId)   const { return m_TestBuf->bufs[compId]; }
1090
946k
  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
946k
  {
1101
946k
    if (insertPos != -1)
1102
134k
    {
1103
146k
      for (int i = RdListSize - 1; i > insertPos; i--)
1104
12.4k
      {
1105
12.4k
        std::swap(m_sortedList[i - 1], m_sortedList[i]);
1106
12.4k
      }
1107
134k
      std::swap(m_TestBuf, m_sortedList[insertPos]);
1108
134k
    }
1109
946k
  }
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