/src/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 | 0 | #define INCY( ptr, stride ) { ptr += ( stride ); } |
101 | 0 | #define OFFSETX( ptr, stride, x ) { ptr += ( x ); } |
102 | 0 | #define OFFSETY( ptr, stride, y ) { ptr += ( y ) * ( stride ); } |
103 | 0 | #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 | 0 | AreaBuf() : Size(), buf( NULL ), stride( 0 ) { }Unexecuted instantiation: vvenc::AreaBuf<short>::AreaBuf() Unexecuted instantiation: vvenc::AreaBuf<short const>::AreaBuf() Unexecuted instantiation: vvenc::AreaBuf<int>::AreaBuf() Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo>::AreaBuf() |
155 | 0 | AreaBuf( T *_buf, const Size& size ) : Size( size ), buf( _buf ), stride( size.width ) { }Unexecuted instantiation: vvenc::AreaBuf<vvenc::LoopFilterParam>::AreaBuf(vvenc::LoopFilterParam*, vvenc::Size const&) Unexecuted instantiation: vvenc::AreaBuf<vvenc::LoopFilterParam const>::AreaBuf(vvenc::LoopFilterParam const*, vvenc::Size const&) Unexecuted instantiation: vvenc::AreaBuf<short const>::AreaBuf(short const*, vvenc::Size const&) Unexecuted instantiation: vvenc::AreaBuf<short>::AreaBuf(short*, vvenc::Size const&) Unexecuted instantiation: vvenc::AreaBuf<int>::AreaBuf(int*, vvenc::Size const&) 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 | 0 | AreaBuf( T *_buf, const int& _stride, const Size& size ) : Size( size ), buf( _buf ), stride( _stride ) { }Unexecuted instantiation: vvenc::AreaBuf<short>::AreaBuf(short*, int const&, vvenc::Size const&) Unexecuted instantiation: vvenc::AreaBuf<short const>::AreaBuf(short const*, int const&, vvenc::Size const&) Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo>::AreaBuf(vvenc::MotionInfo*, int const&, vvenc::Size const&) Unexecuted instantiation: vvenc::AreaBuf<vvenc::LoopFilterParam>::AreaBuf(vvenc::LoopFilterParam*, int const&, vvenc::Size const&) |
157 | 0 | AreaBuf( T *_buf, const SizeType& _width, const SizeType& _height ) : Size( _width, _height ), buf( _buf ), stride( _width ) { }Unexecuted instantiation: vvenc::AreaBuf<short>::AreaBuf(short*, unsigned int const&, unsigned int const&) Unexecuted instantiation: vvenc::AreaBuf<short const>::AreaBuf(short const*, unsigned int const&, unsigned int const&) |
158 | 0 | AreaBuf( T *_buf, const int& _stride, const SizeType& _width, const SizeType& _height ) : Size( _width, _height ), buf( _buf ), stride( _stride ) { }Unexecuted instantiation: vvenc::AreaBuf<short>::AreaBuf(short*, int const&, unsigned int const&, unsigned int const&) Unexecuted instantiation: vvenc::AreaBuf<short const>::AreaBuf(short const*, int const&, unsigned int const&, unsigned int const&) |
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 | 0 | 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 ) { }Unexecuted instantiation: vvenc::AreaBuf<short const>::AreaBuf<true>(vvenc::AreaBuf<short> const&, std::__1::enable_if<true, void>::type*) Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo const>::AreaBuf<true>(vvenc::AreaBuf<vvenc::MotionInfo> const&, std::__1::enable_if<true, void>::type*) Unexecuted instantiation: vvenc::AreaBuf<int const>::AreaBuf<true>(vvenc::AreaBuf<int> const&, std::__1::enable_if<true, void>::type*) |
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 | 0 | T& at( const int& x, const int& y ) { return buf[y * stride + x]; }Unexecuted instantiation: vvenc::AreaBuf<short>::at(int const&, int const&) Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo>::at(int const&, int const&) Unexecuted instantiation: vvenc::AreaBuf<int>::at(int const&, int const&) |
201 | 0 | const T& at( const int& x, const int& y ) const { return buf[y * stride + x]; }Unexecuted instantiation: vvenc::AreaBuf<short const>::at(int const&, int const&) const Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo const>::at(int const&, int const&) const Unexecuted instantiation: vvenc::AreaBuf<short>::at(int const&, int const&) const Unexecuted instantiation: vvenc::AreaBuf<int const>::at(int const&, int const&) const |
202 | | |
203 | 0 | 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&) Unexecuted instantiation: vvenc::AreaBuf<short>::at(vvenc::Position const&) Unexecuted instantiation: vvenc::AreaBuf<vvenc::LoopFilterParam>::at(vvenc::Position const&) |
204 | 0 | const T& at( const Position& pos ) const { return buf[pos.y * stride + pos.x]; }Unexecuted instantiation: vvenc::AreaBuf<short const>::at(vvenc::Position const&) const Unexecuted instantiation: vvenc::AreaBuf<short>::at(vvenc::Position const&) const |
205 | | |
206 | | |
207 | 0 | T* bufAt( const int& x, const int& y ) { return &at( x, y ); } |
208 | 0 | const T* bufAt( const int& x, const int& y ) const { return &at( x, y ); }Unexecuted instantiation: vvenc::AreaBuf<short const>::bufAt(int const&, int const&) const Unexecuted instantiation: vvenc::AreaBuf<short>::bufAt(int const&, int const&) const |
209 | | |
210 | 0 | 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&) Unexecuted instantiation: vvenc::AreaBuf<short>::bufAt(vvenc::Position const&) Unexecuted instantiation: vvenc::AreaBuf<vvenc::LoopFilterParam>::bufAt(vvenc::Position const&) |
211 | 0 | const T* bufAt( const Position& pos ) const { return &at( pos ); }Unexecuted instantiation: vvenc::AreaBuf<short const>::bufAt(vvenc::Position const&) const Unexecuted instantiation: vvenc::AreaBuf<short>::bufAt(vvenc::Position const&) const |
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 | 0 | 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&) Unexecuted instantiation: vvenc::AreaBuf<short>::subBuf(vvenc::Position const&, vvenc::Size const&) Unexecuted instantiation: vvenc::AreaBuf<vvenc::LoopFilterParam>::subBuf(vvenc::Position const&, vvenc::Size const&) |
216 | 0 | AreaBuf<const T> subBuf( const Position& pos, const Size& size ) const { return AreaBuf<const T>( bufAt( pos ), stride, size ); }Unexecuted instantiation: vvenc::AreaBuf<short const>::subBuf(vvenc::Position const&, vvenc::Size const&) const 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 | 0 | #define SIZE_AWARE_PER_EL_OP( OP, INC ) \ |
243 | 0 | if( ( width & 7 ) == 0 ) \ |
244 | 0 | { \ |
245 | 0 | for( int y = 0; y < height; y++ ) \ |
246 | 0 | { \ |
247 | 0 | for( int x = 0; x < width; x += 8 ) \ |
248 | 0 | { \ |
249 | 0 | OP( x + 0 ); \ |
250 | 0 | OP( x + 1 ); \ |
251 | 0 | OP( x + 2 ); \ |
252 | 0 | OP( x + 3 ); \ |
253 | 0 | OP( x + 4 ); \ |
254 | 0 | OP( x + 5 ); \ |
255 | 0 | OP( x + 6 ); \ |
256 | 0 | OP( x + 7 ); \ |
257 | 0 | } \ |
258 | 0 | \ |
259 | 0 | INC; \ |
260 | 0 | } \ |
261 | 0 | } \ |
262 | 0 | else if( ( width & 3 ) == 0 ) \ |
263 | 0 | { \ |
264 | 0 | for( int y = 0; y < height; y++ ) \ |
265 | 0 | { \ |
266 | 0 | for( int x = 0; x < width; x += 4 ) \ |
267 | 0 | { \ |
268 | 0 | OP( x + 0 ); \ |
269 | 0 | OP( x + 1 ); \ |
270 | 0 | OP( x + 2 ); \ |
271 | 0 | OP( x + 3 ); \ |
272 | 0 | } \ |
273 | 0 | \ |
274 | 0 | INC; \ |
275 | 0 | } \ |
276 | 0 | } \ |
277 | 0 | 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 | 0 | else \ |
291 | 0 | { \ |
292 | 0 | for( int y = 0; y < height; y++ ) \ |
293 | 0 | { \ |
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 | 0 | } |
302 | | |
303 | | |
304 | | template<typename T> |
305 | | T AreaBuf <T> ::getAvg() const |
306 | 0 | { |
307 | 0 | const T* src = buf; |
308 | 0 | int64_t acc = 0; |
309 | |
|
310 | 0 | #define AVG_INC src += stride |
311 | 0 | #define AVG_OP(ADDR) acc += src[ADDR] |
312 | 0 | SIZE_AWARE_PER_EL_OP(AVG_OP, AVG_INC); |
313 | 0 | #undef AVG_INC |
314 | 0 | #undef AVG_OP |
315 | |
|
316 | 0 | return T ((acc + (area() >> 1)) / area()); |
317 | 0 | } Unexecuted instantiation: vvenc::AreaBuf<short const>::getAvg() const Unexecuted instantiation: vvenc::AreaBuf<short>::getAvg() const |
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 | 0 | { |
325 | 0 | if( T( 0 ) == val ) |
326 | 0 | { |
327 | 0 | GCC_WARNING_DISABLE_class_memaccess |
328 | 0 | if( width == stride ) |
329 | 0 | { |
330 | 0 | ::memset( buf, 0, width * height * sizeof( T ) ); |
331 | 0 | } |
332 | 0 | else |
333 | 0 | { |
334 | 0 | T* dest = buf; |
335 | 0 | size_t line = width * sizeof( T ); |
336 | |
|
337 | 0 | for( unsigned y = 0; y < height; y++ ) |
338 | 0 | { |
339 | 0 | ::memset( dest, 0, line ); |
340 | |
|
341 | 0 | dest += stride; |
342 | 0 | } |
343 | 0 | } |
344 | 0 | GCC_WARNING_RESET |
345 | 0 | } |
346 | 0 | else |
347 | 0 | { |
348 | 0 | if( width == stride ) |
349 | 0 | { |
350 | 0 | std::fill_n( buf, width * height, val ); |
351 | 0 | } |
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 | 0 | } |
362 | 0 | } |
363 | | |
364 | | template<typename T> |
365 | | void AreaBuf<T>::memset( const int val ) |
366 | 0 | { |
367 | 0 | GCC_WARNING_DISABLE_class_memaccess |
368 | 0 | if( width == stride ) |
369 | 0 | { |
370 | 0 | ::memset( buf, val, width * height * sizeof( T ) ); |
371 | 0 | } |
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 | 0 | GCC_WARNING_RESET |
383 | 0 | } Unexecuted instantiation: vvenc::AreaBuf<short>::memset(int) Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo>::memset(int) Unexecuted instantiation: vvenc::AreaBuf<vvenc::LoopFilterParam>::memset(int) |
384 | | |
385 | | template<typename T> |
386 | | void AreaBuf<T>::copyFrom( const AreaBuf<const T>& other ) |
387 | 0 | { |
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 | 0 | g_pelBufOP.copyBuffer( ( const char* ) other.buf, other.stride * sizeof( T ), ( char* ) buf, stride * sizeof( T ), width * sizeof( T ), height ); |
393 | 0 | } Unexecuted instantiation: vvenc::AreaBuf<short>::copyFrom(vvenc::AreaBuf<short const> const&) Unexecuted instantiation: vvenc::AreaBuf<vvenc::MotionInfo>::copyFrom(vvenc::AreaBuf<vvenc::MotionInfo const> const&) |
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 | 0 | { |
511 | 0 | T* p = buf + y * stride; |
512 | 0 | int h = size + y; |
513 | | |
514 | | // do left and right margins |
515 | 0 | for (; y < h; y++) |
516 | 0 | { |
517 | 0 | for (int x = 0; x < margin; x++) |
518 | 0 | { |
519 | 0 | *(p - margin + x) = p[0]; |
520 | 0 | } |
521 | 0 | p += stride; |
522 | 0 | } |
523 | 0 | } |
524 | | |
525 | | template<typename T> |
526 | | void AreaBuf<T>::extendBorderPelTop( int x, int size, int margin ) |
527 | 0 | { |
528 | 0 | T* p = buf + x; |
529 | | |
530 | | // p is now (-marginX, 0) |
531 | 0 | for (int y = 0; y < margin; y++) |
532 | 0 | { |
533 | 0 | ::memcpy(p - (y + 1) * stride, p, sizeof(T) * size); |
534 | 0 | } |
535 | 0 | } |
536 | | |
537 | | template<typename T> |
538 | | void AreaBuf<T>::extendBorderPelRgt( int y, int size, int margin ) |
539 | 0 | { |
540 | 0 | T* p = buf + y * stride; |
541 | 0 | int h = size + y; |
542 | | |
543 | | // do left and right margins |
544 | 0 | for( ; y < h; y++) |
545 | 0 | { |
546 | 0 | for (int x = 0; x < margin; x++) |
547 | 0 | { |
548 | 0 | p[width + x] = p[width - 1]; |
549 | 0 | } |
550 | 0 | p += stride; |
551 | 0 | } |
552 | 0 | } |
553 | | |
554 | | template<typename T> |
555 | | void AreaBuf<T>::extendBorderPelBot( int x, int size, int margin ) |
556 | 0 | { |
557 | 0 | T* p = buf + (height-1)*stride + x; |
558 | | |
559 | | // p is now the (-margin, height-1) |
560 | 0 | for (int y = 0; y < margin; y++) |
561 | 0 | { |
562 | 0 | ::memcpy(p + (y + 1) * stride, p, sizeof(T) * size); |
563 | 0 | } |
564 | 0 | } |
565 | | |
566 | | template<typename T> |
567 | | void AreaBuf<T>::extendBorderPel(unsigned marginX, unsigned marginY) |
568 | 0 | { |
569 | 0 | T* p = buf; |
570 | 0 | int h = height; |
571 | 0 | int w = width; |
572 | 0 | int s = stride; |
573 | |
|
574 | 0 | CHECK((w + 2 * marginX) > s, "Size of buffer too small to extend"); |
575 | | // do left and right margins |
576 | 0 | for (int y = 0; y < h; y++) |
577 | 0 | { |
578 | 0 | for (int x = 0; x < marginX; x++) |
579 | 0 | { |
580 | 0 | *(p - marginX + x) = p[0]; |
581 | 0 | p[w + x] = p[w - 1]; |
582 | 0 | } |
583 | 0 | p += s; |
584 | 0 | } |
585 | | |
586 | | // p is now the (0,height) (bottom left of image within bigger picture |
587 | 0 | p -= (s + marginX); |
588 | | // p is now the (-margin, height-1) |
589 | 0 | for (int y = 0; y < marginY; y++) |
590 | 0 | { |
591 | 0 | ::memcpy(p + (y + 1) * s, p, sizeof(T) * (w + (marginX << 1))); |
592 | 0 | } |
593 | | |
594 | | // p is still (-marginX, height-1) |
595 | 0 | p -= ((h - 1) * s); |
596 | | // p is now (-marginX, 0) |
597 | 0 | for (int y = 0; y < marginY; y++) |
598 | 0 | { |
599 | 0 | ::memcpy(p - (y + 1) * s, p, sizeof(T) * (w + (marginX << 1))); |
600 | 0 | } |
601 | 0 | } |
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 | 0 | UnitBuf() : chromaFormat( NUM_CHROMA_FORMAT ) { }Unexecuted instantiation: vvenc::UnitBuf<short>::UnitBuf() 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 | 0 | UnitBuf( const ChromaFormat _chromaFormat, const AreaBuf<T>& blkY, const AreaBuf<T>& blkCb, const AreaBuf<T> &blkCr ) : chromaFormat( _chromaFormat ), bufs{ blkY, blkCb, blkCr } { } |
713 | 0 | 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>::UnitBuf(vvencChromaFormat, vvenc::AreaBuf<short>&&, vvenc::AreaBuf<short>&&, vvenc::AreaBuf<short>&&) Unexecuted instantiation: vvenc::UnitBuf<short const>::UnitBuf(vvencChromaFormat, vvenc::AreaBuf<short const>&&, vvenc::AreaBuf<short const>&&, vvenc::AreaBuf<short const>&&) |
714 | | |
715 | 0 | 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 | 0 | 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 | 0 | AreaBuf<T>& get( const ComponentID comp ) { return bufs[comp]; }Unexecuted instantiation: vvenc::UnitBuf<short>::get(vvenc::ComponentID) Unexecuted instantiation: vvenc::UnitBuf<short const>::get(vvenc::ComponentID) |
725 | 0 | const AreaBuf<T>& get( const ComponentID comp ) const { return bufs[comp]; }Unexecuted instantiation: vvenc::UnitBuf<short>::get(vvenc::ComponentID) const Unexecuted instantiation: vvenc::UnitBuf<short const>::get(vvenc::ComponentID) const |
726 | | |
727 | 0 | AreaBuf<T>& Y() { return bufs[0]; }Unexecuted instantiation: vvenc::UnitBuf<short>::Y() Unexecuted instantiation: vvenc::UnitBuf<short const>::Y() |
728 | 0 | const AreaBuf<T>& Y() const { return bufs[0]; } |
729 | 0 | AreaBuf<T>& Cb() { return bufs[1]; } |
730 | | const AreaBuf<T>& Cb() const { return bufs[1]; } |
731 | 0 | AreaBuf<T>& Cr() { return bufs[2]; } |
732 | | const AreaBuf<T>& Cr() const { return bufs[2]; } |
733 | 0 | 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 | 0 | { |
774 | 0 | CHECK( chromaFormat != other.chromaFormat, "Incompatible formats" ); |
775 | 0 | CHECK( !luma && !chroma, "At least one channel has to be selected" ); |
776 | |
|
777 | 0 | const size_t compStart = luma ? 0 : 1; |
778 | 0 | const size_t compEnd = chroma ? bufs.size() : 1; |
779 | |
|
780 | 0 | for( size_t i = compStart; i < compEnd; i++ ) |
781 | 0 | { |
782 | 0 | if( bufs[ i ].buf != nullptr && other.bufs[ i ].buf != nullptr ) |
783 | 0 | bufs[i].copyFrom( other.bufs[i] ); |
784 | 0 | } |
785 | 0 | } |
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 | 0 | { |
856 | 0 | for( int i = 0; i < bufs.size(); i++ ) |
857 | 0 | { |
858 | 0 | int csx = getComponentScaleX(ComponentID(i), chromaFormat); |
859 | 0 | int csy = getComponentScaleY(ComponentID(i), chromaFormat); |
860 | 0 | bufs[i].extendBorderPelTop( x>>csx, size>>csx, margin>>csy ); |
861 | 0 | } |
862 | 0 | } |
863 | | |
864 | | template<typename T> |
865 | | void UnitBuf<T>::extendBorderPelBot ( int x, int size, int margin ) |
866 | 0 | { |
867 | 0 | for( int i = 0; i < bufs.size(); i++ ) |
868 | 0 | { |
869 | 0 | int csx = getComponentScaleX(ComponentID(i), chromaFormat); |
870 | 0 | int csy = getComponentScaleY(ComponentID(i), chromaFormat); |
871 | 0 | bufs[i].extendBorderPelBot( x>>csx, size>>csx, margin>>csy ); |
872 | 0 | } |
873 | 0 | } |
874 | | |
875 | | template<typename T> |
876 | | void UnitBuf<T>::extendBorderPelLft ( int y, int size, int margin ) |
877 | 0 | { |
878 | 0 | for( int i = 0; i < bufs.size(); i++ ) |
879 | 0 | { |
880 | 0 | int csx = getComponentScaleX(ComponentID(i), chromaFormat); |
881 | 0 | int csy = getComponentScaleY(ComponentID(i), chromaFormat); |
882 | 0 | bufs[i].extendBorderPelLft( y>>csy, size>>csy, margin>>csx ); |
883 | 0 | } |
884 | 0 | } |
885 | | |
886 | | template<typename T> |
887 | | void UnitBuf<T>::extendBorderPelRgt ( int y, int size, int margin ) |
888 | 0 | { |
889 | 0 | for( int i = 0; i < bufs.size(); i++ ) |
890 | 0 | { |
891 | 0 | int csx = getComponentScaleX(ComponentID(i), chromaFormat); |
892 | 0 | int csy = getComponentScaleY(ComponentID(i), chromaFormat); |
893 | 0 | bufs[i].extendBorderPelRgt( y>>csy, size>>csy, margin>>csx ); |
894 | 0 | } |
895 | 0 | } |
896 | | |
897 | | template<typename T> |
898 | | void UnitBuf<T>::extendBorderPel( unsigned margin, bool scaleMargin ) |
899 | 0 | { |
900 | 0 | 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 | 0 | else |
908 | 0 | { |
909 | 0 | for ( int i = 0; i < bufs.size(); i++) |
910 | 0 | { |
911 | 0 | bufs[i].extendBorderPel(margin >> getComponentScaleX(ComponentID(i), chromaFormat), margin >> getComponentScaleY(ComponentID(i), chromaFormat)); |
912 | 0 | } |
913 | 0 | } |
914 | 0 | } |
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 | 0 | { |
934 | 0 | UnitBuf<T> subBuf; |
935 | 0 | subBuf.chromaFormat = chromaFormat; |
936 | 0 | unsigned blockIdx = 0; |
937 | |
|
938 | 0 | for( auto &subAreaBuf : bufs ) |
939 | 0 | { |
940 | 0 | subBuf.bufs.push_back( subAreaBuf.subBuf( subArea.blocks[blockIdx].pos(), subArea.blocks[blockIdx].size() ) ); |
941 | 0 | blockIdx++; |
942 | 0 | } |
943 | |
|
944 | 0 | return subBuf; |
945 | 0 | } |
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 | 0 | 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 | 0 | ~CompStorage() { if( valid() ) delete[] m_memory; } |
1016 | | |
1017 | | void compactResize( const Size& size ) |
1018 | 0 | { |
1019 | 0 | CHECK( size.area() > m_allocSize, "Resizing causes buffer overflow!" ); |
1020 | 0 | Size::operator=( size ); |
1021 | 0 | stride = size.width; |
1022 | 0 | } |
1023 | | void create( const Size& size ) |
1024 | 0 | { |
1025 | 0 | CHECK( m_memory, "Trying to re-create an already initialized buffer" ); |
1026 | 0 | m_allocSize = size.area(); |
1027 | 0 | m_memory = new Pel[m_allocSize]; |
1028 | 0 | PelBuf::operator=( PelBuf( m_memory, size ) ); |
1029 | 0 | } |
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 | 0 | 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 | 0 | { |
1047 | 0 | m_pacBufs.resize(NumEntries + 1); |
1048 | 0 | m_acStorage.resize(NumEntries + 1); |
1049 | 0 | for (size_t i = 0; i <= NumEntries; i++) |
1050 | 0 | { |
1051 | 0 | m_acStorage[i].create(cform, Area(0, 0, maxWidth, maxHeight)); |
1052 | 0 | } |
1053 | 0 | } |
1054 | | |
1055 | | void destroy() |
1056 | 0 | { |
1057 | 0 | for (size_t i = 0; i <= NumEntries; i++) |
1058 | 0 | { |
1059 | 0 | m_acStorage[i].destroy(); |
1060 | 0 | } |
1061 | 0 | } |
1062 | | |
1063 | | void reset() |
1064 | | { |
1065 | | m_sortedList.clear(); |
1066 | | } |
1067 | | |
1068 | | void reduceTo(int numModes) |
1069 | 0 | { |
1070 | 0 | CHECK( numModes > m_sortedList.size(), "not enough buffers"); |
1071 | 0 | m_sortedList.resize(numModes); |
1072 | 0 | } |
1073 | | |
1074 | | void prepare( const UnitArea& ua, int numModes) |
1075 | 0 | { |
1076 | 0 | CHECK( numModes > NumEntries, "not enough buffers"); |
1077 | 0 | m_sortedList.resize(numModes); |
1078 | 0 | for (size_t i = 0; i < numModes; i++) |
1079 | 0 | { |
1080 | 0 | m_pacBufs[i] = m_acStorage[i].getCompactBuf(ua); |
1081 | 0 | m_sortedList[i] = &m_pacBufs[i]; |
1082 | 0 | } |
1083 | |
|
1084 | 0 | m_pacBufs[numModes] = m_acStorage[numModes].getCompactBuf(ua); |
1085 | 0 | m_TestBuf = &m_pacBufs[numModes]; |
1086 | 0 | } |
1087 | | |
1088 | 0 | PelUnitBuf* getBufFromSortedList( int idx) const { return m_sortedList.size() > idx ? m_sortedList[idx]: nullptr; } |
1089 | 0 | PelBuf& getTestBuf ( ComponentID compId) const { return m_TestBuf->bufs[compId]; } |
1090 | 0 | 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 | 0 | { |
1101 | 0 | if (insertPos != -1) |
1102 | 0 | { |
1103 | 0 | for (int i = RdListSize - 1; i > insertPos; i--) |
1104 | 0 | { |
1105 | 0 | std::swap(m_sortedList[i - 1], m_sortedList[i]); |
1106 | 0 | } |
1107 | 0 | std::swap(m_TestBuf, m_sortedList[insertPos]); |
1108 | 0 | } |
1109 | 0 | } |
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 | | |