/work/vvenc/source/Lib/CommonLib/TrQuant_EMT.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 TrQuant_EMT.h |
43 | | \brief transform and quantization class (header) |
44 | | */ |
45 | | |
46 | | #pragma once |
47 | | |
48 | | #include "CommonDef.h" |
49 | | |
50 | | //! \ingroup CommonLib |
51 | | //! \{ |
52 | | |
53 | | namespace vvenc { |
54 | | |
55 | | #if defined(TARGET_SIMD_X86) && ENABLE_SIMD_TRAFO |
56 | | using namespace x86_simd; |
57 | | #endif |
58 | | #if defined(TARGET_SIMD_ARM) && ENABLE_SIMD_TRAFO |
59 | | using namespace arm_simd; |
60 | | #endif |
61 | | |
62 | | #if ENABLE_SIMD_TRAFO |
63 | | struct TCoeffOps |
64 | | { |
65 | | TCoeffOps(); |
66 | | void initTCoeffOps( bool enableOpt = true ); |
67 | | |
68 | | void( *cpyResi8 ) ( const TCoeff* src, Pel* dst, ptrdiff_t stride, unsigned width, unsigned height ); |
69 | | void( *cpyResi4 ) ( const TCoeff* src, Pel* dst, ptrdiff_t stride, unsigned width, unsigned height ); |
70 | | void( *cpyCoeff8 ) ( const Pel* src, ptrdiff_t stride, TCoeff* dst, unsigned width, unsigned height ); |
71 | | void( *cpyCoeff4 ) ( const Pel* src, ptrdiff_t stride, TCoeff* dst, unsigned width, unsigned height ); |
72 | | // the inverse matrix multiply over the first rows, then the rounding shift and the clip |
73 | | void( *fastInvCore[5] ) ( const TMatrixCoeff* it, const TCoeff* src, TCoeff* dst, unsigned lines, unsigned reducedLines, unsigned rows, const TCoeff outputMin, const TCoeff outputMax, const TCoeff round, const TCoeff shift ); |
74 | | void( *fastFwdCore_2D[5] )( const TMatrixCoeff* it, const TCoeff* src, TCoeff* dst, unsigned lines, unsigned reducedLines, unsigned cutoff, int shift ); |
75 | | void( *fastFwdCore_1D[5] )( const TMatrixCoeff* it, const TCoeff* src, TCoeff* dst, unsigned lines, unsigned reducedLines, unsigned cutoff, int shift ); |
76 | | void( *roundClip8 ) ( TCoeff *dst, unsigned width, unsigned height, unsigned stride, const TCoeff outputMin, const TCoeff outputMax, const TCoeff round, const TCoeff shift ); |
77 | | // 1D transforms called directly by fastForward/InverseDCT2_B*: partial butterflies (fastInvDCT2[0..2], |
78 | | // fastFwdDCT2[0..1]) and the whole DCT-II 16/32/64 (fastInvDCT2[3..5], fastFwdDCT2[2..4]) |
79 | | // [0]: 2-pt, [1]: 4-pt, [2]: 8-pt (partial butterflies), [3]: 16-pt, [4]: 32-pt, [5]: 64-pt (by default fastInverseDCT2_MM) |
80 | | void( *fastInvDCT2[6] ) ( const TCoeff* src, TCoeff* dst, int shift, int line, int iSkipLine, int iSkipLine2, const TCoeff outputMinimum, const TCoeff outputMaximum ); |
81 | | // [0]: 2-pt, [1]: 4-pt (partial butterflies), [2]: 16-pt, [3]: 32-pt, [4]: 64-pt (by default fastForwardDCT2_MM) |
82 | | void( *fastFwdDCT2[6] ) ( const TCoeff* src, TCoeff* dst, int shift, int line, int iSkipLine, int iSkipLine2 ); // [5]: 8-pt (by default fastForwardDCT2_MM) |
83 | | void( *fastFwdDST7_4 ) ( const TCoeff* src, TCoeff* dst, int shift, int line, int iSkipLine, int iSkipLine2 ); |
84 | | void( *fastFwdDCT8_4 ) ( const TCoeff* src, TCoeff* dst, int shift, int line, int iSkipLine, int iSkipLine2 ); |
85 | | // The first stage of a 2-D forward transform reading the residual itself, by transform type and log2 of the size minus 1. |
86 | | // Where there's none (nullptr), xT widens the residual and takes fastFwdTrans. |
87 | | void( *fastFwdPel[NUM_TRANS_TYPE][6] )( const Pel* src, ptrdiff_t stride, TCoeff* dst, int shift, int line, int iSkipLine2 ); |
88 | | |
89 | | private: |
90 | | #if defined( TARGET_SIMD_X86 ) && ENABLE_SIMD_TRAFO |
91 | | void initTCoeffOpsX86(); |
92 | | template<X86_VEXT vext> |
93 | | void _initTCoeffOpsX86(); |
94 | | #endif |
95 | | #if defined( TARGET_SIMD_ARM ) && ENABLE_SIMD_TRAFO |
96 | | void initTCoeffOpsARM(); |
97 | | template<ARM_VEXT vext> |
98 | | void _initTCoeffOpsARM(); |
99 | | #endif |
100 | | }; |
101 | | |
102 | | extern TCoeffOps g_tCoeffOps; |
103 | | |
104 | | #endif |
105 | | |
106 | | // Forward DCT-II of size N (8, 16, 32 or 64) as a matrix multiply (through g_tCoeffOps.fastFwdCore_* with SIMD): the |
107 | | // default of TCoeffOps::fastFwdDCT2[2..5] and the fallback of their SIMD versions. |
108 | | template<int N> |
109 | | void fastForwardDCT2_MM( const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2 ); |
110 | | |
111 | | // Inverse DCT-II of size N (16, 32 or 64) as a matrix multiply (through g_tCoeffOps.fastInvCore and roundClip8 with |
112 | | // SIMD): the default of TCoeffOps::fastInvDCT2[3..5]. |
113 | | template<int N> |
114 | | void fastInverseDCT2_MM( const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2, const TCoeff outputMinimum, const TCoeff outputMaximum ); |
115 | | |
116 | | // Zeroes columns reducedLine .. line - 1 of the first cutoff rows, which a forward 1D transform leaves out (dst holds the |
117 | | // transform's rows of line coefficients each). The rows from cutoff on stay as they are: TrQuant::xT clears those that are read. |
118 | | static inline void fastForwardZeroSkipped( TCoeff *dst, int line, int reducedLine, int cutoff, int iSkipLine ) |
119 | 1.44M | { |
120 | 1.44M | if( iSkipLine ) |
121 | 54.3k | { |
122 | 54.3k | TCoeff *pCoef = dst + reducedLine; |
123 | 1.25M | for( int j = 0; j < cutoff; j++ ) |
124 | 1.20M | { |
125 | 1.20M | memset( pCoef, 0, sizeof( TCoeff ) * iSkipLine ); |
126 | 1.20M | pCoef += line; |
127 | 1.20M | } |
128 | 54.3k | } |
129 | 1.44M | } Unexecuted instantiation: vvencimpl.cpp:vvenc::fastForwardZeroSkipped(int*, int, int, int, int) Unexecuted instantiation: TrQuant.cpp:vvenc::fastForwardZeroSkipped(int*, int, int, int, int) TrQuant_EMT.cpp:vvenc::fastForwardZeroSkipped(int*, int, int, int, int) Line | Count | Source | 119 | 1.44M | { | 120 | 1.44M | if( iSkipLine ) | 121 | 54.3k | { | 122 | 54.3k | TCoeff *pCoef = dst + reducedLine; | 123 | 1.25M | for( int j = 0; j < cutoff; j++ ) | 124 | 1.20M | { | 125 | 1.20M | memset( pCoef, 0, sizeof( TCoeff ) * iSkipLine ); | 126 | 1.20M | pCoef += line; | 127 | 1.20M | } | 128 | 54.3k | } | 129 | 1.44M | } |
|
130 | | |
131 | | ////DCT-II transforms |
132 | | void fastForwardDCT2_B2 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2); |
133 | | void fastInverseDCT2_B2 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2, const TCoeff outputMinimum, const TCoeff outputMaximum); |
134 | | void fastForwardDCT2_B4 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2); |
135 | | void fastInverseDCT2_B4 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2, const TCoeff outputMinimum, const TCoeff outputMaximum); |
136 | | void fastForwardDCT2_B8 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2); |
137 | | void fastInverseDCT2_B8 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2, const TCoeff outputMinimum, const TCoeff outputMaximum); |
138 | | void fastForwardDCT2_B16 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2); |
139 | | void fastInverseDCT2_B16 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2, const TCoeff outputMinimum, const TCoeff outputMaximum); |
140 | | void fastForwardDCT2_B32 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2); |
141 | | void fastInverseDCT2_B32 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2, const TCoeff outputMinimum, const TCoeff outputMaximum); |
142 | | void fastForwardDCT2_B64 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2); |
143 | | void fastInverseDCT2_B64 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2, const TCoeff outputMinimum, const TCoeff outputMaximum); |
144 | | |
145 | | //DST-VII transforms (EMT) |
146 | | void fastForwardDST7_B4 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2); |
147 | | void fastInverseDST7_B4 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2, const TCoeff outputMinimum, const TCoeff outputMaximum); |
148 | | void fastForwardDST7_B8 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2); |
149 | | void fastInverseDST7_B8 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2, const TCoeff outputMinimum, const TCoeff outputMaximum); |
150 | | void fastForwardDST7_B16 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2); |
151 | | void fastInverseDST7_B16 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2, const TCoeff outputMinimum, const TCoeff outputMaximum); |
152 | | void fastForwardDST7_B32 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2); |
153 | | void fastInverseDST7_B32 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2, const TCoeff outputMinimum, const TCoeff outputMaximum); |
154 | | |
155 | | //DCT-VIII transforms (EMT) |
156 | | void fastForwardDCT8_B4 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2); |
157 | | void fastInverseDCT8_B4 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2, const TCoeff outputMinimum, const TCoeff outputMaximum); |
158 | | void fastForwardDCT8_B8 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2); |
159 | | void fastInverseDCT8_B8 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2, const TCoeff outputMinimum, const TCoeff outputMaximum); |
160 | | void fastForwardDCT8_B16 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2); |
161 | | void fastInverseDCT8_B16 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2, const TCoeff outputMinimum, const TCoeff outputMaximum); |
162 | | void fastForwardDCT8_B32 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2); |
163 | | void fastInverseDCT8_B32 (const TCoeff *src, TCoeff *dst, int shift, int line, int iSkipLine, int iSkipLine2, const TCoeff outputMinimum, const TCoeff outputMaximum); |
164 | | |
165 | | } // namespace vvenc |
166 | | |
167 | | //! \} |
168 | | |