/src/vvdec/source/Lib/CommonLib/RdCost.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) 2018-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVdeC 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 | | |
43 | | /** \file RdCost.h |
44 | | \brief RD cost computation classes (header) |
45 | | */ |
46 | | |
47 | | #pragma once |
48 | | |
49 | | #include "CommonDef.h" |
50 | | #include "Buffer.h" |
51 | | |
52 | | namespace vvdec |
53 | | { |
54 | | #if defined(TARGET_SIMD_X86) && ENABLE_SIMD_OPT_DIST |
55 | | using namespace x86_simd; |
56 | | #endif |
57 | | #if defined(TARGET_SIMD_ARM) && ENABLE_SIMD_OPT_DIST |
58 | | using namespace arm_simd; |
59 | | #endif |
60 | | class DistParam; |
61 | | class EncCfg; |
62 | | |
63 | | // ==================================================================================================================== |
64 | | // Type definition |
65 | | // ==================================================================================================================== |
66 | | |
67 | | // for function pointer |
68 | | typedef Distortion (*FpDistFunc) (const DistParam&); |
69 | | typedef void (*FpDistFuncX5)(const DistParam&, Distortion*, bool); |
70 | | |
71 | | // ==================================================================================================================== |
72 | | // Class definition |
73 | | // ==================================================================================================================== |
74 | | |
75 | | /// distortion parameter class |
76 | | class DistParam |
77 | | { |
78 | | public: |
79 | | CPelBuf org; |
80 | | CPelBuf cur; |
81 | | FpDistFunc distFunc; |
82 | | FpDistFuncX5 distFuncX5; |
83 | | int bitDepth; |
84 | | |
85 | | // (vertical) subsampling shift (for reducing complexity) |
86 | | // - 0 = no subsampling, 1 = even rows, 2 = every 4th, etc. |
87 | | int subShift; |
88 | | DistParam() : |
89 | 0 | org(), cur(), bitDepth( 0 ), subShift( 0 ) |
90 | 0 | { } |
91 | | }; |
92 | | |
93 | | /// RD cost computation class |
94 | | class RdCost |
95 | | { |
96 | | private: |
97 | | // for distortion |
98 | | |
99 | | FpDistFunc m_afpDistortFunc[DF_TOTAL_FUNCTIONS]; // [eDFunc] |
100 | | FpDistFuncX5 m_afpDistortFuncX5[DF_TOTAL_FUNCTIONS]; // [eDFunc] |
101 | | |
102 | | public: |
103 | | |
104 | | RdCost( bool enableOpt = true ); |
105 | | ~RdCost(); |
106 | | |
107 | | void setDistParam( DistParam &rcDP, const Pel* pOrg, const Pel* piRefY, ptrdiff_t iOrgStride, ptrdiff_t iRefStride, int bitDepth, int width, int height, int subShiftMode = 0 ); |
108 | | |
109 | | |
110 | | static Distortion xGetSAD8 ( const DistParam& pcDtParam ); |
111 | | static Distortion xGetSAD16 ( const DistParam& pcDtParam ); |
112 | | static void xGetSAD8X5 ( const DistParam& pcDtParam, Distortion* cost, bool isCalCentrePos ); |
113 | | static void xGetSAD16X5 ( const DistParam& pcDtParam, Distortion* cost, bool isCalCentrePos ); |
114 | | |
115 | | private: |
116 | | |
117 | | #if defined(TARGET_SIMD_X86) && ENABLE_SIMD_OPT_DIST |
118 | | void initRdCostX86(); |
119 | | template<X86_VEXT vext> |
120 | | void _initRdCostX86(); |
121 | | #endif |
122 | | |
123 | | #if defined(TARGET_SIMD_ARM) && ENABLE_SIMD_OPT_DIST |
124 | | void initRdCostARM(); |
125 | | template<ARM_VEXT vext> |
126 | | void _initRdCostARM(); |
127 | | #endif // TARGET_SIMD_ARM |
128 | | |
129 | | }; // END CLASS DEFINITION RdCost |
130 | | |
131 | | } // namespace vvdec |