Coverage Report

Created: 2026-04-01 07:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vvenc/source/Lib/EncoderLib/BitAllocation.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     BitAllocation.h
43
\brief    Bit allocation class for QP adaptation and, possibly, rate control (header)
44
*/
45
46
#pragma once
47
48
#include "CommonLib/Slice.h"
49
#include "CommonLib/Unit.h"
50
51
//! \ingroup EncoderLib
52
//! \{
53
54
namespace vvenc {
55
56
  // visual activity
57
  struct VisAct
58
  {
59
    VisAct()
60
0
      : hpSpatAct( 0.0 )
61
0
      , hpTempAct( 0.0 )
62
0
      , hpVisAct ( 0.0 )
63
0
      , spatAct  ( 0 )
64
0
      , tempAct  ( 0 )
65
0
      , visAct   ( 0 )
66
0
      , minAct   ( 0 )
67
0
    {
68
0
    }
69
70
    double   hpSpatAct;  // spatial high precision
71
    double   hpTempAct;  // temporal high precision
72
    double   hpVisAct;   // visual activity high precision
73
    unsigned spatAct;    // spatial  in 12 bit
74
    unsigned tempAct;    // temporal in 12 bit
75
    unsigned visAct;     // visual activity 12 bit
76
    unsigned minAct;     // minimal activity
77
  };
78
79
  void calcSpatialVisAct ( const Pel* pSrc,
80
                           const int iSrcStride,
81
                           const int height,
82
                           const int width,
83
                           const uint32_t bitDepth,
84
                           const bool isUHD,
85
                           VisAct& va );
86
87
  void calcTemporalVisAct ( const Pel* pSrc,
88
                            const int iSrcStride,
89
                            const int height,
90
                            const int width,
91
                            const Pel* pSM1,
92
                            const int iSM1Stride,
93
                            const Pel* pSM2,
94
                            const int iSM2Stride,
95
                            uint32_t frameRate,
96
                            const uint32_t bitDepth,
97
                            const bool isUHD,
98
                            VisAct& va );
99
100
  void updateVisAct ( VisAct& va, const uint32_t bitDepth );
101
102
  double filterAndCalculateAverageActivity ( const Pel* pSrc,
103
                                             const int iSrcStride,
104
                                             const int height,
105
                                             const int width,
106
                                             const Pel* pSM1,
107
                                             const int iSM1Stride,
108
                                             const Pel* pSM2,
109
                                             const int iSM2Stride,
110
                                             uint32_t frameRate,
111
                                             const uint32_t bitDepth,
112
                                             const bool isUHD,
113
                                             unsigned* minVisAct,
114
                                             unsigned* spVisAct );
115
116
  // BitAllocation functions
117
  namespace BitAllocation
118
  {
119
    int applyQPAdaptationSlice ( const Slice* slice,
120
                                 const VVEncCfg* encCfg,
121
                                 const int sliceQP,
122
                                 const double sliceLambda,
123
                                 uint16_t* const picVisActLuma,
124
                                 std::vector<int>& ctuPumpRedQP,
125
                                 std::vector<uint8_t>* ctuRCQPMemory,
126
                                 int* const optChromaQPOffsets,
127
                                 const uint8_t* minNoiseLevels,
128
                                 const uint32_t ctuStartAddr,
129
                                 const uint32_t ctuBoundingAddr );
130
    int applyQPAdaptationSubCtu( const Slice* slice,
131
                                 const VVEncCfg* encCfg,
132
                                 const Area& lumaArea,
133
                                 const uint8_t* minNoiseLevels );
134
    int getCtuPumpingReducingQP( const Slice* slice,
135
                                 const CPelBuf& origY,
136
                                 const Distortion uiSadBestForQPA,
137
                                 std::vector<int>& ctuPumpRedQP,
138
                                 const uint32_t ctuRsAddr,
139
                                 const int baseQP,
140
                                 const bool isBIM );
141
  }
142
143
} // namespace vvenc
144
145
//! \}