Coverage Report

Created: 2026-10-17 06:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/vvenc/source/Lib/CommonLib/TrQuant.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.h
43
    \brief    transform and quantization class (header)
44
*/
45
46
#pragma once
47
48
#include "CommonDef.h"
49
#include "Unit.h"
50
#include "Contexts.h"
51
#include "ContextModelling.h"
52
#include "UnitPartitioner.h"
53
#include "Quant.h"
54
#include "DepQuant.h"
55
56
//! \ingroup CommonLib
57
//! \{
58
59
namespace vvenc {
60
61
#if defined(TARGET_SIMD_X86)  && (ENABLE_SIMD_OPT_QUANT || ENABLE_SIMD_TRAFO)
62
using namespace x86_simd;
63
#endif
64
65
typedef void FwdTrans(const TCoeff*, TCoeff*, int, int, int, int);
66
typedef void InvTrans(const TCoeff*, TCoeff*, int, int, int, int, const TCoeff, const TCoeff);
67
68
// ====================================================================================================================
69
// Class definition
70
// ====================================================================================================================
71
typedef std::pair<int, bool> TrMode;   // a transform type (mtsIdx) and whether to test it
72
typedef std::pair<int, int>  TrCost;
73
// Fixed-capacity lists, because a search builds them for every block: the transform types to try and their costs.
74
typedef static_vector<TrMode, NUM_TRAFO_MODES_MTS> TrModeList;
75
typedef static_vector<TrCost, NUM_TRAFO_MODES_MTS> TrCostList;
76
77
/// transform and quantization class
78
class TrQuant
79
{
80
public:
81
  TrQuant();
82
  ~TrQuant();
83
84
  // initialize class
85
  void init(
86
             const Quant* otherQuant,
87
             const int  rdoq,
88
             const bool bUseRDOQTS,
89
             const bool scalingListsEnabled,
90
             const bool bEnc,
91
             const int  thrValue            
92
           );
93
94
public:
95
  void invTransformNxN    ( TransformUnit& tu, const ComponentID compID, PelBuf& pResi, const QpParam& cQPs);
96
  void transformNxN       ( TransformUnit& tu, const ComponentID compID, const QpParam& cQP, TCoeff &uiAbsSum, const Ctx& ctx, const bool loadTr = false);
97
  void checktransformsNxN ( TransformUnit& tu, TrModeList *trModes, const int maxCand, const ComponentID compID = COMP_Y);
98
99
  void                        invTransformICT     ( const TransformUnit& tu, PelBuf& resCb, PelBuf& resCr );
100
  std::pair<int64_t,int64_t>  fwdTransformICT     ( const TransformUnit& tu, const PelBuf& resCb, const PelBuf& resCr, PelBuf& resC1, PelBuf& resC2, int jointCbCr = -1 );
101
  std::vector<int>            selectICTCandidates ( const TransformUnit& tu, CompStorage* resCb, CompStorage* resCr );
102
103
9.75k
  void   setLambdas  ( const double lambdas[MAX_NUM_COMP] )   { m_quant->setLambdas( lambdas ); }
104
1.88M
  void   selectLambda( const ComponentID compIdx )            { m_quant->selectLambda( compIdx ); }
105
0
  void   getLambdas  ( double (&lambdas)[MAX_NUM_COMP]) const { m_quant->getLambdas( lambdas ); }
106
1.36M
  void   scaleLambda ( const double scale)                    { m_quant->scaleLambda(scale);}
107
108
8.09k
  DepQuant* getQuant ()                                       { return m_quant; }
109
110
protected:
111
  TCoeff*   m_plTempCoeff;
112
  bool      m_bEnc;
113
  bool      m_scalingListEnabled;
114
  TCoeff*   m_blk;
115
  TCoeff*   m_tmp;
116
117
private:
118
  DepQuant* m_quant;          //!< Quantizer
119
  TCoeff    m_tempInMatrix[48];
120
  TCoeff    m_tempOutMatrix[48];
121
  TCoeff   *m_mtsCoeffs[NUM_TRAFO_MODES_MTS];
122
123
  static const int maxAbsIctMode = 3;
124
  void                      (*m_invICTMem[1+2*maxAbsIctMode])(PelBuf&,PelBuf&);
125
  std::pair<int64_t,int64_t>(*m_fwdICTMem[1+2*maxAbsIctMode])(const PelBuf&,const PelBuf&,PelBuf&,PelBuf&);
126
  void                      (**m_invICT)(PelBuf&,PelBuf&);
127
  std::pair<int64_t,int64_t>(**m_fwdICT)(const PelBuf&,const PelBuf&,PelBuf&,PelBuf&);
128
129
  void (*m_fwdLfnstNxN)( int* src, int* dst, const uint32_t mode, const uint32_t index, const uint32_t size, int zeroOutSize );
130
  void (*m_invLfnstNxN)( int* src, int* dst, const uint32_t mode, const uint32_t index, const uint32_t size, int zeroOutSize );
131
132
  uint32_t xGetLFNSTIntraMode( const Area& tuArea, const uint32_t dirMode );
133
  bool     xGetTransposeFlag(uint32_t intraMode);
134
  void     xFwdLfnst    ( const TransformUnit &tu, const ComponentID compID, const bool loadTr = false);
135
  void     xInvLfnst    ( const TransformUnit &tu, const ComponentID compID);
136
  void     xSetTrTypes  ( const TransformUnit& tu, const ComponentID compID, const int width, const int height, int &trTypeHor, int &trTypeVer );
137
138
  // forward Transform
139
  void xT               (const TransformUnit& tu, const ComponentID compID, const CPelBuf& resi, CoeffBuf& dstCoeff, const int width, const int height);
140
141
  // quantization
142
  void xQuant           (TransformUnit& tu, const ComponentID compID, const CCoeffBuf& pSrc, TCoeff &uiAbsSum, const QpParam& cQP, const Ctx& ctx);
143
144
  // dequantization
145
  void xDeQuant( const TransformUnit& tu,
146
                       CoeffBuf      &dstCoeff,
147
                 const ComponentID   &compID,
148
                 const QpParam       &cQP      );
149
150
  // inverse transform
151
  void xIT     ( const TransformUnit& tu, const ComponentID compID, const CCoeffBuf& pCoeff, PelBuf& pResidual );
152
  // skipping Transform
153
  void xTransformSkip(const TransformUnit& tu, const ComponentID& compID, const CPelBuf& resi, TCoeff* psCoeff);
154
  // inverse skipping transform
155
  void xITransformSkip(const CCoeffBuf& plCoef, PelBuf& pResidual, const TransformUnit& tu, const ComponentID component);
156
  
157
#if defined(TARGET_SIMD_X86)  && (ENABLE_SIMD_TRAFO )
158
  template<X86_VEXT vext>
159
  void _initTrQuantX86();
160
  void initTrQuantX86();
161
#endif
162
};// END CLASS DEFINITION TrQuant
163
164
} // namespace vvenc
165
166
//! \}
167