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/Unit.cpp
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     Unit.cpp
44
 *  \brief    defines unit as a set of blocks and basic unit types (coding, prediction, transform)
45
 */
46
47
#include "Unit.h"
48
49
#include "Buffer.h"
50
#include "Picture.h"
51
#include "ChromaFormat.h"
52
53
#include "UnitTools.h"
54
#include "UnitPartitioner.h"
55
56
namespace vvdec
57
{
58
59
 // ---------------------------------------------------------------------------
60
 // block method definitions
61
 // ---------------------------------------------------------------------------
62
63
Position CompArea::chromaPos( const ChromaFormat chromaFormat ) const
64
0
{
65
0
  if (isLuma(compID()))
66
0
  {
67
0
    uint32_t scaleX = getComponentScaleX(compID(), chromaFormat);
68
0
    uint32_t scaleY = getComponentScaleY(compID(), chromaFormat);
69
70
0
    return Position(x >> scaleX, y >> scaleY);
71
0
  }
72
0
  else
73
0
  {
74
0
    return *this;
75
0
  }
76
0
}
77
78
Size CompArea::lumaSize( const ChromaFormat chromaFormat ) const
79
0
{
80
0
  if( isChroma( compID() ) )
81
0
  {
82
0
    uint32_t scaleX = getComponentScaleX( compID(), chromaFormat );
83
0
    uint32_t scaleY = getComponentScaleY( compID(), chromaFormat );
84
85
0
    return Size( width << scaleX, height << scaleY );
86
0
  }
87
0
  else
88
0
  {
89
0
    return *this;
90
0
  }
91
0
}
92
93
Size CompArea::chromaSize( const ChromaFormat chromaFormat ) const
94
0
{
95
0
  if( isLuma( compID() ) )
96
0
  {
97
0
    uint32_t scaleX = getComponentScaleX( compID(), chromaFormat );
98
0
    uint32_t scaleY = getComponentScaleY( compID(), chromaFormat );
99
100
0
    return Size( width >> scaleX, height >> scaleY );
101
0
  }
102
0
  else
103
0
  {
104
0
    return *this;
105
0
  }
106
0
}
107
108
Position CompArea::lumaPos( const ChromaFormat chromaFormat ) const
109
0
{
110
0
  if( isChroma( compID() ) )
111
0
  {
112
0
    uint32_t scaleX = getComponentScaleX( compID(), chromaFormat );
113
0
    uint32_t scaleY = getComponentScaleY( compID(), chromaFormat );
114
115
0
    return Position( x << scaleX, y << scaleY );
116
0
  }
117
0
  else
118
0
  {
119
0
    return *this;
120
0
  }
121
0
}
122
123
Position CompArea::compPos( const ChromaFormat chromaFormat, const ComponentID compID ) const
124
0
{
125
0
  return isLuma( compID ) ? lumaPos( chromaFormat ) : chromaPos( chromaFormat );
126
0
}
127
128
Position CompArea::chanPos( const ChromaFormat chromaFormat, const ChannelType chType ) const
129
0
{
130
0
  return isLuma( chType ) ? lumaPos( chromaFormat ) : chromaPos( chromaFormat );
131
0
}
132
133
// ---------------------------------------------------------------------------
134
// unit method definitions
135
// ---------------------------------------------------------------------------
136
137
0
UnitArea::UnitArea(const ChromaFormat _chromaFormat) : chromaFormat(_chromaFormat) { }
138
139
0
UnitArea::UnitArea(const ChromaFormat _chromaFormat, const Area &_area) : chromaFormat(_chromaFormat)
140
0
{
141
0
  const uint32_t numCh = getNumberValidComponents( chromaFormat );
142
143
0
  blocks.resize_noinit( numCh );
144
145
0
  if( !numCh ) return;
146
147
0
  blocks[0]._compID      = COMPONENT_Y;
148
0
  blocks[0].x            = _area.x;
149
0
  blocks[0].y            = _area.y;
150
0
  blocks[0].width        = _area.width;
151
0
  blocks[0].height       = _area.height;
152
153
0
  if( numCh == 1 ) return;
154
155
0
  const int csx = getChannelTypeScaleX( CH_C, chromaFormat );
156
0
  const int csy = getChannelTypeScaleY( CH_C, chromaFormat );
157
  
158
0
  blocks[1]._compID      = COMPONENT_Cb;
159
0
  blocks[2]._compID      = COMPONENT_Cr;
160
0
  blocks[1].x            = blocks[2].x            = ( _area.x >> csx );
161
0
  blocks[1].y            = blocks[2].y            = ( _area.y >> csy );
162
0
  blocks[1].width        = blocks[2].width        = ( _area.width  >> csx );
163
0
  blocks[1].height       = blocks[2].height       = ( _area.height >> csy );
164
0
}
165
166
0
UnitArea::UnitArea(const ChromaFormat _chromaFormat, const CompArea &blkY) : chromaFormat(_chromaFormat), blocks { blkY } {}
167
168
0
UnitArea::UnitArea(const ChromaFormat _chromaFormat,       CompArea &&blkY) : chromaFormat(_chromaFormat), blocks { std::forward<CompArea>(blkY) } {}
169
170
0
UnitArea::UnitArea(const ChromaFormat _chromaFormat, const CompArea &blkY, const CompArea &blkCb, const CompArea &blkCr)  : chromaFormat(_chromaFormat), blocks { blkY, blkCb, blkCr } {}
171
172
0
UnitArea::UnitArea(const ChromaFormat _chromaFormat,       CompArea &&blkY,      CompArea &&blkCb,      CompArea &&blkCr) : chromaFormat(_chromaFormat), blocks { std::forward<CompArea>(blkY), std::forward<CompArea>(blkCb), std::forward<CompArea>(blkCr) } {}
173
174
bool UnitArea::contains(const UnitArea& other) const
175
0
{
176
0
  bool any = false;
177
178
0
  if( blocks[0].valid() && other.blocks[0].valid() )
179
0
  {
180
0
    any = true;
181
0
    if( !blocks[0].contains( other.blocks[0] ) ) return false;
182
0
  }
183
184
0
  if( blocks[1].valid() && other.blocks[1].valid() )
185
0
  {
186
0
    any = true;
187
0
    if( !blocks[1].contains( other.blocks[1] ) ) return false;
188
0
  }
189
190
0
  if( blocks[2].valid() && other.blocks[2].valid() )
191
0
  {
192
0
    any = true;
193
0
    if( !blocks[2].contains( other.blocks[2] ) ) return false;
194
0
  }
195
196
0
  return any;
197
0
}
198
199
bool UnitArea::contains( const UnitArea& other, const ChannelType chType ) const
200
0
{
201
0
  if( chType == CH_L && blocks[0].valid() && other.blocks[0].valid() )
202
0
  {
203
0
    if( !blocks[0].contains( other.blocks[0] ) ) return false;
204
0
    return true;
205
0
  }
206
207
0
  if( chType == CH_L ) return false;
208
209
0
  bool any = false;
210
211
0
  if( blocks[1].valid() && other.blocks[1].valid() )
212
0
  {
213
0
    any = true;
214
0
    if( !blocks[1].contains( other.blocks[1] ) ) return false;
215
0
  }
216
217
0
  if( blocks[2].valid() && other.blocks[2].valid() )
218
0
  {
219
0
    any = true;
220
0
    if( !blocks[2].contains( other.blocks[2] ) ) return false;
221
0
  }
222
223
0
  return any;
224
0
}
225
226
void UnitArea::repositionTo(const UnitArea& unitArea)
227
0
{
228
0
  for(uint32_t i = 0; i < blocks.size(); i++)
229
0
  {
230
0
    blocks[i].repositionTo(unitArea.blocks[i]);
231
0
  }
232
0
}
233
234
const UnitArea UnitArea::singleComp(const ComponentID compID) const
235
0
{
236
0
  UnitArea ret = *this;
237
238
0
  for( auto &blk : ret.blocks )
239
0
  {
240
0
    if( blk.compID() != compID )
241
0
    {
242
0
      new ( &blk ) CompArea();
243
0
    }
244
0
  }
245
246
0
  return ret;
247
0
}
248
249
const UnitArea UnitArea::singleChan(const ChannelType chType) const
250
0
{
251
0
#if 1
252
0
  UnitArea ret(chromaFormat);
253
254
0
  for (const auto &blk : blocks)
255
0
  {
256
0
    if (toChannelType( blk.compID() ) == chType)
257
0
    {
258
0
      ret.blocks.push_back(blk);
259
0
    }
260
0
    else
261
0
    {
262
0
      ret.blocks.push_back(CompArea());
263
0
    }
264
0
  }
265
#else
266
  UnitArea ret = *this;
267
268
  for( auto &blk : ret.blocks )
269
  {
270
    if( toChannelType( blk.compID ) != chType )
271
    {
272
      new ( &blk ) CompArea();
273
    }
274
  }
275
#endif
276
0
  return ret;
277
0
}
278
279
// ---------------------------------------------------------------------------
280
// coding unit method definitions
281
// ---------------------------------------------------------------------------
282
283
void CodingUnit::minInit( const UnitArea &unit )
284
0
{
285
0
  static_cast<UnitArea &>( *this ) = unit;
286
287
0
  intraDir[0] = DC_IDX;
288
289
0
  refIdx[0]   = refIdx[1] = -1;
290
0
}
291
292
// ---------------------------------------------------------------------------
293
// prediction unit method definitions
294
// ---------------------------------------------------------------------------
295
296
CodingUnit& CodingUnit::operator=( const MotionInfo& mi )
297
0
{
298
0
  setInterDir( mi.interDir() );
299
300
0
  for( uint32_t i = 0; i < NUM_REF_PIC_LIST_01; i++ )
301
0
  {
302
0
    refIdx[i] = mi.miRefIdx[i];
303
0
    mv [i][0] = mi.mv      [i];
304
0
  }
305
306
0
  return *this;
307
0
}
308
309
const MotionInfo& CodingUnit::getMotionInfo() const
310
0
{
311
0
  return ctuData->motion[cs->inCtuPos( lumaPos(), CH_L )];
312
0
}
313
314
const MotionInfo& CodingUnit::getMotionInfo( const Position& pos ) const
315
0
{
316
0
  CHECKD( !Y().contains( pos ), "Trying to access motion info outsied of PU" );
317
0
  return ctuData->motion[cs->inCtuPos( pos, CH_L )];
318
0
}
319
320
MotionBuf CodingUnit::getMotionBuf()
321
0
{
322
0
  return MotionBuf( &ctuData->motion[cs->inCtuPos( lumaPos(), CH_L )], cs->get4x4MapStride(), g_miScaling.scaleHor( lwidth() ), g_miScaling.scaleVer( lheight() ) );
323
0
}
324
325
CMotionBuf CodingUnit::getMotionBuf() const
326
0
{
327
0
  return CMotionBuf( &getMotionInfo(), cs->get4x4MapStride(), g_miScaling.scaleHor( lwidth() ), g_miScaling.scaleVer( lheight() ) );
328
0
}
329
330
}