Coverage Report

Created: 2026-07-30 06:27

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