Coverage Report

Created: 2026-12-01 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/vvenc/source/Lib/CommonLib/SampleAdaptiveOffset.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     SampleAdaptiveOffset.h
43
    \brief    sample adaptive offset class (header)
44
*/
45
46
#pragma once
47
48
#include "CommonDef.h"
49
#include "Unit.h"
50
51
//! \ingroup CommonLib
52
//! \{
53
54
namespace vvenc {
55
56
#if defined(TARGET_SIMD_X86)  && ENABLE_SIMD_OPT_SAO
57
using namespace x86_simd;
58
#endif
59
60
template<typename T> static inline int sgn( T val )
61
204M
{
62
204M
  return ( T( 0 ) < val ) - ( val < T( 0 ) );
63
204M
}
SampleAdaptiveOffset.cpp:int vvenc::sgn<int>(int)
Line
Count
Source
61
202M
{
62
202M
  return ( T( 0 ) < val ) - ( val < T( 0 ) );
63
202M
}
EncSampleAdaptiveOffset.cpp:int vvenc::sgn<int>(int)
Line
Count
Source
61
2.30M
{
62
2.30M
  return ( T( 0 ) < val ) - ( val < T( 0 ) );
63
2.30M
}
64
65
// ====================================================================================================================
66
// Constants
67
// ====================================================================================================================
68
69
139k
#define MAX_SAO_TRUNCATED_BITDEPTH     10
70
71
// ====================================================================================================================
72
// Class definition
73
// ====================================================================================================================
74
75
  enum Available
76
  {
77
    LeftAvail = 1,
78
    RightAvail = 2,
79
    AboveAvail = 4,
80
    BelowAvail = 8,
81
    AboveLeftAvail = 16,
82
    AboveRightAvail = 32,
83
    BelowLeftAvail = 64,
84
    BelowRightAvail = 128,
85
  };
86
87
class SampleAdaptiveOffset
88
{
89
public:
90
  SampleAdaptiveOffset( bool enableOpt = true );
91
  virtual ~SampleAdaptiveOffset();
92
  void        init            ( ChromaFormat format, uint32_t maxCUWidth, uint32_t maxCUHeight, uint32_t lumaBitShift, uint32_t chromaBitShift );
93
139k
  static int  getMaxOffsetQVal( const int channelBitDepth) { return (1<<(std::min<int>(channelBitDepth,MAX_SAO_TRUNCATED_BITDEPTH)-5))-1; } //Table 9-32, inclusive
94
95
  void ( *calcSaoStatisticsBo )( int width, int endX, int endY, Pel* srcLine, Pel* orgLine, int srcStride,
96
                                 int orgStride, int channelBitDepth, int64_t* count, int64_t* diff );
97
  void ( *calcSaoStatisticsEo0 )( int width, int startX, int endX, int endY, Pel* srcLine, Pel* orgLine,
98
                                  int srcStride, int orgStride, int64_t* count, int64_t* diff );
99
  void ( *calcSaoStatisticsEo90 )( int width, int endX, int startY, int endY, Pel* srcLine, Pel* orgLine,
100
                                   int srcStride, int orgStride, int64_t* count, int64_t* diff, int8_t* signUpLine );
101
  void ( *calcSaoStatisticsEo135 )( int width, int startX, int endX, int endY, Pel* srcLine, Pel* orgLine,
102
                                    int srcStride, int orgStride, int64_t* count, int64_t* diff, int8_t* signUpLine,
103
                                    int8_t* signDownLine );
104
  void ( *calcSaoStatisticsEo45 )( int width, int startX, int endX, int endY, Pel* srcLine, Pel* orgLine,
105
                                   int srcStride, int orgStride, int64_t* count, int64_t* diff, int8_t* signUpLine );
106
107
protected:
108
  void deriveLoopFilterBoundaryAvailibility( CodingStructure& cs, const Position& pos, uint8_t& availMask ) const;
109
110
  void (*offsetBlock) ( const int     channelBitDepth,
111
                        const ClpRng& clpRng,
112
                        int           typeIdx,
113
                        int*          offset,
114
                        int           startIdx,
115
                        const Pel*    srcBlk,
116
                        Pel*          resBlk,
117
                        ptrdiff_t     srcStride,
118
                        ptrdiff_t     resStride,
119
                        int           width,
120
                        int           height,
121
                        uint8_t       availMask,
122
                        std::vector<int8_t> &signLineBuf1,
123
                        std::vector<int8_t> &signLineBuf2);
124
125
  void invertQuantOffsets       (ComponentID compIdx, int typeIdc, int typeAuxInfo, int* dstOffsets, int* srcOffsets);
126
  void reconstructBlkSAOParam   (SAOBlkParam& recParam, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES]);
127
  int  getMergeList             (CodingStructure& cs, int ctuRsAddr, SAOBlkParam* blkParams, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES]);
128
  // srcCtu holds the pre-SAO samples of the CTU at area, starting at its first sample, with at least
129
  // one sample of border around it.
130
  void offsetCTU                (const UnitArea& area, const CPelUnitBuf& srcCtu, PelUnitBuf& res, SAOBlkParam& saoblkParam, CodingStructure& cs);
131
  void xReconstructBlkSAOParams (CodingStructure& cs, SAOBlkParam* saoBlkParams);
132
133
#if defined(TARGET_SIMD_X86)  && ENABLE_SIMD_OPT_SAO
134
  void initSampleAdaptiveOffsetX86();
135
  template <X86_VEXT vext>
136
  void _initSampleAdaptiveOffsetX86();
137
#endif
138
#if defined( TARGET_SIMD_ARM ) && ENABLE_SIMD_OPT_SAO
139
  void initSampleAdaptiveOffsetARM();
140
  template<ARM_VEXT vext>
141
  void _initSampleAdaptiveOffsetARM();
142
#endif
143
144
protected:
145
  uint32_t    m_offsetStepLog2[MAX_NUM_COMP]; //offset step
146
  uint32_t    m_numberOfComponents;
147
148
  std::vector<int8_t> m_signLineBuf1;
149
  std::vector<int8_t> m_signLineBuf2;
150
151
private:
152
  bool m_picSAOEnabled[MAX_NUM_COMP];
153
};
154
155
} // namespace vvenc
156
157
//! \}
158