Coverage Report

Created: 2026-04-01 07:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/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 );
108
  ~Quant();
109
110
  // initialize class
111
  void init( const Picture *pic );
112
public:
113
  // de-quantization
114
  void dequant           ( const TransformUnit &tu, CoeffBuf &dstCoeff, const ComponentID &compID, const QpParam &cQP );
115
116
private:
117
  void xInitScalingList   ( const Quant* other );
118
  void xDestroyScalingList();
119
  bool xSetScalingListDec( const ScalingList &scalingList, uint32_t list, uint32_t size, uint32_t scalingListId );
120
  void xSetRecScalingListDec( const ScalingList &scalingList, uint32_t list, uint32_t sizew, uint32_t sizeh, uint32_t scalingListId );
121
  bool m_scalingListEnabledFlag;
122
123
  int *m_dequantCoef   [SCALING_LIST_SIZE_NUM][SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM]; ///< array of dequantization matrix coefficient 4x4
124
  int *m_dequantCoefBuf;
125
  bool m_ownDequantCoeff;
126
127
128
  void ( *DeQuant    ) (const int maxX,const int restX,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);
129
  void ( *DeQuantPCM ) (const int maxX,const int restX,const int maxY,const int scale,      TCoeff   *const piQCoef,const size_t piQCfStride,TCoeff   *const piCoef,const int rightShift,const int inputMaximum,const TCoeff transformMaximum);
130
131
  void ( *DeQuantScaling    ) (const int maxX,const int restX,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);
132
  void ( *DeQuantScalingPCM   ) (const int maxX,const int restX,const int maxY,const int scaleQP,const int *piDequantCoef,TCoeff   *const piQCoef,const size_t piQCfStride,TCoeff   *const piCoef,const int rightShift,const int inputMaximum,const TCoeff transformMaximum);
133
134
#if ENABLE_SIMD_OPT_QUANT && defined( TARGET_SIMD_X86 )
135
  void initQuantX86();
136
  template <X86_VEXT vext>
137
  void _initQuantX86();
138
#endif
139
};// END CLASS DEFINITION Quant
140
141
}   // namespace vvdec