Coverage Report

Created: 2026-04-01 07:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/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;
72
typedef std::pair<int, int>  TrCost;
73
74
/// transform and quantization class
75
class TrQuant
76
{
77
public:
78
  TrQuant();
79
  ~TrQuant();
80
81
  // initialize class
82
  void init(
83
             const Quant* otherQuant,
84
             const int  rdoq,
85
             const bool bUseRDOQTS,
86
             const bool scalingListsEnabled,
87
             const bool bEnc,
88
             const int  thrValue            
89
           );
90
91
public:
92
  void invTransformNxN    ( TransformUnit& tu, const ComponentID compID, PelBuf& pResi, const QpParam& cQPs);
93
  void transformNxN       ( TransformUnit& tu, const ComponentID compID, const QpParam& cQP, TCoeff &uiAbsSum, const Ctx& ctx, const bool loadTr = false);
94
  void checktransformsNxN ( TransformUnit& tu, std::vector<TrMode> *trModes, const int maxCand, const ComponentID compID = COMP_Y);
95
96
  void                        invTransformICT     ( const TransformUnit& tu, PelBuf& resCb, PelBuf& resCr );
97
  std::pair<int64_t,int64_t>  fwdTransformICT     ( const TransformUnit& tu, const PelBuf& resCb, const PelBuf& resCr, PelBuf& resC1, PelBuf& resC2, int jointCbCr = -1 );
98
  std::vector<int>            selectICTCandidates ( const TransformUnit& tu, CompStorage* resCb, CompStorage* resCr );
99
100
0
  void   setLambdas  ( const double lambdas[MAX_NUM_COMP] )   { m_quant->setLambdas( lambdas ); }
101
0
  void   selectLambda( const ComponentID compIdx )            { m_quant->selectLambda( compIdx ); }
102
0
  void   getLambdas  ( double (&lambdas)[MAX_NUM_COMP]) const { m_quant->getLambdas( lambdas ); }
103
0
  void   scaleLambda ( const double scale)                    { m_quant->scaleLambda(scale);}
104
105
0
  DepQuant* getQuant ()                                       { return m_quant; }
106
107
protected:
108
  TCoeff*   m_plTempCoeff;
109
  bool      m_bEnc;
110
  bool      m_scalingListEnabled;
111
  TCoeff*   m_blk;
112
  TCoeff*   m_tmp;
113
114
private:
115
  DepQuant* m_quant;          //!< Quantizer
116
  TCoeff    m_tempInMatrix[48];
117
  TCoeff    m_tempOutMatrix[48];
118
  TCoeff   *m_mtsCoeffs[NUM_TRAFO_MODES_MTS];
119
120
  static const int maxAbsIctMode = 3;
121
  void                      (*m_invICTMem[1+2*maxAbsIctMode])(PelBuf&,PelBuf&);
122
  std::pair<int64_t,int64_t>(*m_fwdICTMem[1+2*maxAbsIctMode])(const PelBuf&,const PelBuf&,PelBuf&,PelBuf&);
123
  void                      (**m_invICT)(PelBuf&,PelBuf&);
124
  std::pair<int64_t,int64_t>(**m_fwdICT)(const PelBuf&,const PelBuf&,PelBuf&,PelBuf&);
125
126
  void (*m_fwdLfnstNxN)( int* src, int* dst, const uint32_t mode, const uint32_t index, const uint32_t size, int zeroOutSize );
127
  void (*m_invLfnstNxN)( int* src, int* dst, const uint32_t mode, const uint32_t index, const uint32_t size, int zeroOutSize );
128
129
  uint32_t xGetLFNSTIntraMode( const Area& tuArea, const uint32_t dirMode );
130
  bool     xGetTransposeFlag(uint32_t intraMode);
131
  void     xFwdLfnst    ( const TransformUnit &tu, const ComponentID compID, const bool loadTr = false);
132
  void     xInvLfnst    ( const TransformUnit &tu, const ComponentID compID);
133
  void     xSetTrTypes  ( const TransformUnit& tu, const ComponentID compID, const int width, const int height, int &trTypeHor, int &trTypeVer );
134
135
  // forward Transform
136
  void xT               (const TransformUnit& tu, const ComponentID compID, const CPelBuf& resi, CoeffBuf& dstCoeff, const int width, const int height);
137
138
  // quantization
139
  void xQuant           (TransformUnit& tu, const ComponentID compID, const CCoeffBuf& pSrc, TCoeff &uiAbsSum, const QpParam& cQP, const Ctx& ctx);
140
141
  // dequantization
142
  void xDeQuant( const TransformUnit& tu,
143
                       CoeffBuf      &dstCoeff,
144
                 const ComponentID   &compID,
145
                 const QpParam       &cQP      );
146
147
  // inverse transform
148
  void xIT     ( const TransformUnit& tu, const ComponentID compID, const CCoeffBuf& pCoeff, PelBuf& pResidual );
149
  // skipping Transform
150
  void xTransformSkip(const TransformUnit& tu, const ComponentID& compID, const CPelBuf& resi, TCoeff* psCoeff);
151
  // inverse skipping transform
152
  void xITransformSkip(const CCoeffBuf& plCoef, PelBuf& pResidual, const TransformUnit& tu, const ComponentID component);
153
  
154
#if defined(TARGET_SIMD_X86)  && (ENABLE_SIMD_TRAFO )
155
  template<X86_VEXT vext>
156
  void _initTrQuantX86();
157
  void initTrQuantX86();
158
#endif
159
};// END CLASS DEFINITION TrQuant
160
161
} // namespace vvenc
162
163
//! \}
164