Coverage Report

Created: 2026-06-15 06:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/vvdec/source/Lib/CommonLib/Quant.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     Quant.h
44
    \brief    base quantization class (header)
45
*/
46
47
#pragma once
48
49
#include "CommonDef.h"
50
#include "Unit.h"
51
52
namespace vvdec
53
{
54
55
struct Picture;
56
class ScalingList;
57
58
#if ENABLE_SIMD_OPT_QUANT && defined( TARGET_SIMD_X86 )
59
using namespace x86_simd;
60
#endif
61
62
// ====================================================================================================================
63
// Constants
64
// ====================================================================================================================
65
66
#define QP_BITS                 15
67
68
// ====================================================================================================================
69
// Class definition
70
// ====================================================================================================================
71
struct TrQuantParams
72
{
73
  int     rightShift;
74
  int     qScale;
75
};
76
77
/// QP struct
78
class QpParam
79
{
80
public:
81
  short  Qps[2];
82
  int8_t pers[2];
83
  int8_t rems[2];
84
85
  QpParam(const TransformUnit& tu, const ComponentID &compID, const bool allowACTQpoffset = true);
86
87
0
  int Qp ( const bool ts ) const { return Qps [ts?1:0]; }
88
0
  int per( const bool ts ) const { return pers[ts?1:0]; }
89
0
  int rem( const bool ts ) const { return rems[ts?1:0]; }
90
91
}; // END STRUCT DEFINITION QpParam
92
93
/// transform and quantization class
94
class Quant
95
{
96
public:
97
0
  int* getDequantCoeff           ( uint32_t list, uint32_t sizeX, uint32_t sizeY ) { return m_dequantCoef[sizeX][sizeY][list]; };  //!< get DeQuant Coefficent
98
99
0
  void setUseScalingList         ( bool bUseScalingList ) { m_scalingListEnabledFlag = bUseScalingList; };
100
  bool getUseScalingList         ( bool isTransformSkip, const bool lfnstApplied, const bool disableScalingMatrixForLFNSTBlks, const bool disableSMforACT)
101
0
  {
102
0
    return( m_scalingListEnabledFlag && !isTransformSkip && (!lfnstApplied || !disableScalingMatrixForLFNSTBlks) && !disableSMforACT);
103
0
  }
104
  void setScalingListDec         ( const ScalingList &scalingList);
105
  bool processScalingListDec     ( const int *coeff, int *dequantcoeff, uint32_t height, uint32_t width, uint32_t ratio, int sizuNum, uint32_t dc);
106
107
  Quant( const Quant* other, bool enableOpt = true );
108
  ~Quant();
109
110
  // initialize class
111
  void init( const Picture *pic );
112
113
  // de-quantization
114
  void dequant           ( const TransformUnit &tu, CoeffBuf &dstCoeff, const ComponentID &compID, const QpParam &cQP );
115
116
  template<class T>
117
  static void DeQuantCore( const SizeType width,
118
                           const int      maxX,
119
                           const int      maxY,
120
                           const int      scale,
121
                           const T* const piQCoef,
122
                           const size_t   piQCfStride,
123
                           TCoeff* const  piCoef,
124
                           const int      rightShift,
125
                           const int      inputMaximum,
126
                           const TCoeff   transformMaximum );
127
  template<class T>
128
  static void DeQuantScalingCore( const SizeType width,
129
                                  const int      maxX,
130
                                  const int      maxY,
131
                                  const int      scaleQP,
132
                                  const int*     piDequantCoef,
133
                                  const T* const piQCoef,
134
                                  const size_t   piQCfStride,
135
                                  TCoeff* const  piCoef,
136
                                  const int      rightShift,
137
                                  const int      inputMaximum,
138
                                  const TCoeff   transformMaximum );
139
140
  void ( *DeQuant    )        (const SizeType width, const int maxX, const int maxY, const int scale,                             const TCoeffSig* const piQCoef, const size_t piQCfStride, TCoeff* const piCoef, const int rightShift, const int inputMaximum, const TCoeff transformMaximum);
141
  void ( *DeQuantPCM )        (const SizeType width, const int maxX, const int maxY, const int scale,                             const TCoeff   * const piQCoef, const size_t piQCfStride, TCoeff* const piCoef, const int rightShift, const int inputMaximum, const TCoeff transformMaximum);
142
143
  void ( *DeQuantScaling    ) (const SizeType width, const int maxX, const int maxY, const int scaleQP, const int* piDequantCoef, const TCoeffSig* const piQCoef, const size_t piQCfStride, TCoeff* const piCoef, const int rightShift, const int inputMaximum, const TCoeff transformMaximum);
144
  void ( *DeQuantScalingPCM ) (const SizeType width, const int maxX, const int maxY, const int scaleQP, const int* piDequantCoef, const TCoeff   * const piQCoef, const size_t piQCfStride, TCoeff* const piCoef, const int rightShift, const int inputMaximum, const TCoeff transformMaximum);
145
146
private:
147
  void xInitScalingList   ( const Quant* other );
148
  void xDestroyScalingList();
149
  bool xSetScalingListDec( const ScalingList &scalingList, uint32_t list, uint32_t size, uint32_t scalingListId );
150
  void xSetRecScalingListDec( const ScalingList &scalingList, uint32_t list, uint32_t sizew, uint32_t sizeh, uint32_t scalingListId );
151
  bool m_scalingListEnabledFlag;
152
153
  int *m_dequantCoef   [SCALING_LIST_SIZE_NUM][SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM]; ///< array of dequantization matrix coefficient 4x4
154
  int *m_dequantCoefBuf;
155
  bool m_ownDequantCoeff;
156
157
#if ENABLE_SIMD_OPT_QUANT && defined( TARGET_SIMD_X86 )
158
  void initQuantX86();
159
  template <X86_VEXT vext>
160
  void _initQuantX86();
161
#endif
162
};// END CLASS DEFINITION Quant
163
164
}   // namespace vvdec