Coverage Report

Created: 2026-05-30 06:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/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
}
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
  SampleAdaptiveOffset( bool enableOpt = true );
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
public:
130
  void ( *offsetBlock )( const int            channelBitDepth,
131
                         const ClpRng&        clpRng,
132
                         int                  typeIdx,
133
                         int*                 offset,
134
                         int                  startIdx,
135
                         const Pel*           srcBlk,
136
                         Pel*                 resBlk,
137
                         ptrdiff_t            srcStride,
138
                         ptrdiff_t            resStride,
139
                         int                  width,
140
                         int                  height,
141
                         bool                 isLeftAvail,
142
                         bool                 isRightAvail,
143
                         bool                 isAboveAvail,
144
                         bool                 isBelowAvail,
145
                         bool                 isAboveLeftAvail,
146
                         bool                 isAboveRightAvail,
147
                         bool                 isBelowLeftAvail,
148
                         bool                 isBelowRightAvail,
149
                         std::vector<int8_t>* m_signLineBuf1,
150
                         std::vector<int8_t>* m_signLineBuf2,
151
                         bool                 isCtuCrossedByVirtualBoundaries,
152
                         int                  horVirBndryPos[],
153
                         int                  verVirBndryPos[],
154
                         int                  numHorVirBndry,
155
                         int                  numVerVirBndry );
156
157
protected:
158
  void invertQuantOffsets     ( ComponentID compIdx, int typeIdc, int typeAuxInfo, int* dstOffsets, int* srcOffsets ) const;
159
  void reconstructBlkSAOParam ( SAOBlkParam& recParam, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES] ) const;
160
  int  getMergeList           ( CodingStructure& cs, int ctuRsAddr, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES] );
161
  void offsetCTU              ( const UnitArea& area, const CPelUnitBuf& src, PelUnitBuf& res, SAOBlkParam& saoblkParam, CodingStructure& cs, std::vector<int8_t> &signLineBuf1, std::vector<int8_t> &signLineBuf2 );
162
163
  static bool isProcessDisabled( int xPos, int yPos, int numVerVirBndry, int numHorVirBndry, int verVirBndryPos[], int horVirBndryPos[] );
164
  Reshape* m_pcReshape;
165
166
167
#if defined(TARGET_SIMD_X86)  && ENABLE_SIMD_OPT_SAO
168
  void initSampleAdaptiveOffsetX86();
169
  template <X86_VEXT vext>
170
  void _initSampleAdaptiveOffsetX86();
171
#endif
172
173
174
175
protected:
176
  uint32_t   m_offsetStepLog2;   // offset step
177
  uint32_t   m_numberOfComponents;
178
  PelUnitBuf m_tempBuf;
179
};
180
181
}