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/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) 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     SampleAdaptiveOffset.h
44
    \brief    sample adaptive offset class (header)
45
*/
46
47
#pragma once
48
49
#include "CommonDef.h"
50
#include "Unit.h"
51
#include "Reshape.h"
52
53
#include <array>
54
55
namespace vvdec
56
{
57
58
template<typename T> static inline int sgn( T val )
59
0
{
60
0
  return ( T( 0 ) < val ) - ( val < T( 0 ) );
61
0
}
Unexecuted instantiation: SampleAdaptiveOffset.cpp:int vvdec::sgn<int>(int)
Unexecuted instantiation: SampleAdaptiveOffset_sse41.cpp:int vvdec::sgn<int>(int)
Unexecuted instantiation: SampleAdaptiveOffset_avx2.cpp:int vvdec::sgn<int>(int)
62
63
// ====================================================================================================================
64
// Constants
65
// ====================================================================================================================
66
67
0
#define MAX_SAO_TRUNCATED_BITDEPTH     10
68
69
// ====================================================================================================================
70
// Class definition
71
// ====================================================================================================================
72
73
class SampleAdaptiveOffset
74
{
75
public:
76
0
  SampleAdaptiveOffset() {}
77
  ~SampleAdaptiveOffset();
78
79
  void create( int picWidth, int picHeight, ChromaFormat format, uint32_t maxCUWidth, uint32_t maxCUHeight, uint32_t maxCUDepth, uint32_t bitShift, PelUnitBuf& unitBuf );
80
  void destroy();
81
82
//  void SAOProcess( CodingStructure& cs );
83
  void SAOProcessCTU    ( CodingStructure& cs, const UnitArea& ctuArea );
84
  void SAOProcessCTULine( CodingStructure& cs, const UnitArea& lineArea );
85
  void SAOPrepareCTULine( CodingStructure& cs, const UnitArea& lineArea );
86
87
0
  static int getMaxOffsetQVal( const int channelBitDepth ) { return ( 1 << ( std::min<int>( channelBitDepth, MAX_SAO_TRUNCATED_BITDEPTH ) - 5 ) ) - 1; }   // Table 9-32, inclusive
88
0
  void setReshaper(Reshape * p) { m_pcReshape = p; }
89
90
protected:
91
  void deriveLoopFilterBoundaryAvailibility( CodingStructure& cs,
92
                                             const Position&  pos,
93
                                             bool&            isLeftAvail,
94
                                             bool&            isRightAvail,
95
                                             bool&            isAboveAvail,
96
                                             bool&            isBelowAvail,
97
                                             bool&            isAboveLeftAvail,
98
                                             bool&            isAboveRightAvail,
99
                                             bool&            isBelowLeftAvail,
100
                                             bool&            isBelowRightAvail ) const;
101
102
  static void offsetBlock_core( const int            channelBitDepth,
103
                                const ClpRng&        clpRng,
104
                                int                  typeIdx,
105
                                int*                 offset,
106
                                int                  startIdx,
107
                                const Pel*           srcBlk,
108
                                Pel*                 resBlk,
109
                                ptrdiff_t            srcStride,
110
                                ptrdiff_t            resStride,
111
                                int                  width,
112
                                int                  height,
113
                                bool                 isLeftAvail,
114
                                bool                 isRightAvail,
115
                                bool                 isAboveAvail,
116
                                bool                 isBelowAvail,
117
                                bool                 isAboveLeftAvail,
118
                                bool                 isAboveRightAvail,
119
                                bool                 isBelowLeftAvail,
120
                                bool                 isBelowRightAvail,
121
                                std::vector<int8_t>* m_signLineBuf1,
122
                                std::vector<int8_t>* m_signLineBuf2,
123
                                bool                 isCtuCrossedByVirtualBoundaries,
124
                                int                  horVirBndryPos[],
125
                                int                  verVirBndryPos[],
126
                                int                  numHorVirBndry,
127
                                int                  numVerVirBndry );
128
129
  void ( *offsetBlock )( const int            channelBitDepth,
130
                         const ClpRng&        clpRng,
131
                         int                  typeIdx,
132
                         int*                 offset,
133
                         int                  startIdx,
134
                         const Pel*           srcBlk,
135
                         Pel*                 resBlk,
136
                         ptrdiff_t            srcStride,
137
                         ptrdiff_t            resStride,
138
                         int                  width,
139
                         int                  height,
140
                         bool                 isLeftAvail,
141
                         bool                 isRightAvail,
142
                         bool                 isAboveAvail,
143
                         bool                 isBelowAvail,
144
                         bool                 isAboveLeftAvail,
145
                         bool                 isAboveRightAvail,
146
                         bool                 isBelowLeftAvail,
147
                         bool                 isBelowRightAvail,
148
                         std::vector<int8_t>* m_signLineBuf1,
149
                         std::vector<int8_t>* m_signLineBuf2,
150
                         bool                 isCtuCrossedByVirtualBoundaries,
151
                         int                  horVirBndryPos[],
152
                         int                  verVirBndryPos[],
153
                         int                  numHorVirBndry,
154
                         int                  numVerVirBndry );
155
156
  void invertQuantOffsets     ( ComponentID compIdx, int typeIdc, int typeAuxInfo, int* dstOffsets, int* srcOffsets ) const;
157
  void reconstructBlkSAOParam ( SAOBlkParam& recParam, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES] ) const;
158
  int  getMergeList           ( CodingStructure& cs, int ctuRsAddr, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES] );
159
  void offsetCTU              ( const UnitArea& area, const CPelUnitBuf& src, PelUnitBuf& res, SAOBlkParam& saoblkParam, CodingStructure& cs, std::vector<int8_t> &signLineBuf1, std::vector<int8_t> &signLineBuf2 );
160
161
  static bool isProcessDisabled( int xPos, int yPos, int numVerVirBndry, int numHorVirBndry, int verVirBndryPos[], int horVirBndryPos[] );
162
  Reshape* m_pcReshape;
163
164
165
#if defined(TARGET_SIMD_X86)  && ENABLE_SIMD_OPT_SAO
166
  void initSampleAdaptiveOffsetX86();
167
  template <X86_VEXT vext>
168
  void _initSampleAdaptiveOffsetX86();
169
#endif
170
171
172
173
protected:
174
  uint32_t   m_offsetStepLog2;   // offset step
175
  uint32_t   m_numberOfComponents;
176
  PelUnitBuf m_tempBuf;
177
};
178
179
}