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/Buffer.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) 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
43
44
/** \file     Buffer.cpp
45
 *  \brief    Low-overhead class describing 2D memory layout
46
 */
47
48
#define DONT_UNDEF_SIZE_AWARE_PER_EL_OP
49
50
// unit needs to come first due to a forward declaration
51
#include "Unit.h"
52
#include "Slice.h"
53
#include "InterpolationFilter.h"
54
55
//! \ingroup CommonLib
56
//! \{
57
58
namespace vvenc {
59
60
void weightCiipCore( Pel* res, const Pel* src, const int numSamples, int numIntra )
61
0
{
62
0
  if( numIntra == 1 )
63
0
  {
64
0
    for (int n = 0; n < numSamples; n+=2)
65
0
    {
66
0
      res[n  ] = (res[n  ] + src[n  ] + 1) >> 1;
67
0
      res[n+1] = (res[n+1] + src[n+1] + 1) >> 1;
68
0
    }
69
0
  }
70
0
  else
71
0
  {
72
0
    const Pel* scale   = numIntra ? src : res;
73
0
    const Pel* unscale = numIntra ? res : src;
74
75
0
    for (int n = 0; n < numSamples; n+=2)
76
0
    {
77
0
      res[n  ] = (unscale[n  ] + 3*scale[n  ] + 2) >> 2;
78
0
      res[n+1] = (unscale[n+1] + 3*scale[n+1] + 2) >> 2;
79
0
    }
80
0
  }
81
0
}
82
83
template< SizeType predPredSize, unsigned log2UpsmpFactor>
84
static void mipUpsampleHorCore(Pel* const dst, const Pel* const src, const Pel* const bndry, const SizeType dstStride, const SizeType bndryStep )
85
287k
{
86
287k
  const int roundingOffset   = 1 << (log2UpsmpFactor - 1);
87
287k
  const SizeType upsmpFactor = 1 << log2UpsmpFactor;
88
89
287k
        Pel* dstLine   = dst;
90
287k
  const Pel* srcLine   = src;
91
287k
  const Pel* bndryLine = bndry + bndryStep - 1;
92
93
2.55M
  for( SizeType idxOrthDim = 0; idxOrthDim < predPredSize; idxOrthDim++ )
94
2.26M
  {
95
2.26M
    const Pel* before  = bndryLine;
96
2.26M
    const Pel* behind  = srcLine;
97
2.26M
          Pel* currDst = dstLine;
98
20.2M
    for( SizeType idxUpsmpDim = 0; idxUpsmpDim < predPredSize; idxUpsmpDim++ )
99
18.0M
    {
100
18.0M
      const int valDiff   = *behind - *before;
101
18.0M
            int scaledVal = ( ( *before ) << log2UpsmpFactor ) + roundingOffset;
102
98.7M
      for( SizeType pos = 0; pos < upsmpFactor; pos++)
103
80.6M
      {
104
80.6M
        scaledVal += valDiff;
105
80.6M
        *currDst   = scaledVal >> log2UpsmpFactor;
106
80.6M
        currDst++;
107
80.6M
      }
108
18.0M
      before = behind;
109
18.0M
      behind ++;
110
18.0M
    }
111
112
2.26M
    srcLine   += predPredSize;
113
2.26M
    dstLine   += dstStride;
114
2.26M
    bndryLine += bndryStep;
115
2.26M
  }
116
287k
}
Buffer.cpp:void vvenc::mipUpsampleHorCore<4u, 1u>(short*, short const*, short const*, unsigned int, unsigned int)
Line
Count
Source
85
7.71k
{
86
7.71k
  const int roundingOffset   = 1 << (log2UpsmpFactor - 1);
87
7.71k
  const SizeType upsmpFactor = 1 << log2UpsmpFactor;
88
89
7.71k
        Pel* dstLine   = dst;
90
7.71k
  const Pel* srcLine   = src;
91
7.71k
  const Pel* bndryLine = bndry + bndryStep - 1;
92
93
38.5k
  for( SizeType idxOrthDim = 0; idxOrthDim < predPredSize; idxOrthDim++ )
94
30.8k
  {
95
30.8k
    const Pel* before  = bndryLine;
96
30.8k
    const Pel* behind  = srcLine;
97
30.8k
          Pel* currDst = dstLine;
98
154k
    for( SizeType idxUpsmpDim = 0; idxUpsmpDim < predPredSize; idxUpsmpDim++ )
99
123k
    {
100
123k
      const int valDiff   = *behind - *before;
101
123k
            int scaledVal = ( ( *before ) << log2UpsmpFactor ) + roundingOffset;
102
370k
      for( SizeType pos = 0; pos < upsmpFactor; pos++)
103
246k
      {
104
246k
        scaledVal += valDiff;
105
246k
        *currDst   = scaledVal >> log2UpsmpFactor;
106
246k
        currDst++;
107
246k
      }
108
123k
      before = behind;
109
123k
      behind ++;
110
123k
    }
111
112
30.8k
    srcLine   += predPredSize;
113
30.8k
    dstLine   += dstStride;
114
30.8k
    bndryLine += bndryStep;
115
30.8k
  }
116
7.71k
}
Unexecuted instantiation: Buffer.cpp:void vvenc::mipUpsampleHorCore<4u, 2u>(short*, short const*, short const*, unsigned int, unsigned int)
Unexecuted instantiation: Buffer.cpp:void vvenc::mipUpsampleHorCore<4u, 3u>(short*, short const*, short const*, unsigned int, unsigned int)
Buffer.cpp:void vvenc::mipUpsampleHorCore<8u, 1u>(short*, short const*, short const*, unsigned int, unsigned int)
Line
Count
Source
85
87.7k
{
86
87.7k
  const int roundingOffset   = 1 << (log2UpsmpFactor - 1);
87
87.7k
  const SizeType upsmpFactor = 1 << log2UpsmpFactor;
88
89
87.7k
        Pel* dstLine   = dst;
90
87.7k
  const Pel* srcLine   = src;
91
87.7k
  const Pel* bndryLine = bndry + bndryStep - 1;
92
93
789k
  for( SizeType idxOrthDim = 0; idxOrthDim < predPredSize; idxOrthDim++ )
94
701k
  {
95
701k
    const Pel* before  = bndryLine;
96
701k
    const Pel* behind  = srcLine;
97
701k
          Pel* currDst = dstLine;
98
6.31M
    for( SizeType idxUpsmpDim = 0; idxUpsmpDim < predPredSize; idxUpsmpDim++ )
99
5.61M
    {
100
5.61M
      const int valDiff   = *behind - *before;
101
5.61M
            int scaledVal = ( ( *before ) << log2UpsmpFactor ) + roundingOffset;
102
16.8M
      for( SizeType pos = 0; pos < upsmpFactor; pos++)
103
11.2M
      {
104
11.2M
        scaledVal += valDiff;
105
11.2M
        *currDst   = scaledVal >> log2UpsmpFactor;
106
11.2M
        currDst++;
107
11.2M
      }
108
5.61M
      before = behind;
109
5.61M
      behind ++;
110
5.61M
    }
111
112
701k
    srcLine   += predPredSize;
113
701k
    dstLine   += dstStride;
114
701k
    bndryLine += bndryStep;
115
701k
  }
116
87.7k
}
Buffer.cpp:void vvenc::mipUpsampleHorCore<8u, 2u>(short*, short const*, short const*, unsigned int, unsigned int)
Line
Count
Source
85
112k
{
86
112k
  const int roundingOffset   = 1 << (log2UpsmpFactor - 1);
87
112k
  const SizeType upsmpFactor = 1 << log2UpsmpFactor;
88
89
112k
        Pel* dstLine   = dst;
90
112k
  const Pel* srcLine   = src;
91
112k
  const Pel* bndryLine = bndry + bndryStep - 1;
92
93
1.01M
  for( SizeType idxOrthDim = 0; idxOrthDim < predPredSize; idxOrthDim++ )
94
903k
  {
95
903k
    const Pel* before  = bndryLine;
96
903k
    const Pel* behind  = srcLine;
97
903k
          Pel* currDst = dstLine;
98
8.12M
    for( SizeType idxUpsmpDim = 0; idxUpsmpDim < predPredSize; idxUpsmpDim++ )
99
7.22M
    {
100
7.22M
      const int valDiff   = *behind - *before;
101
7.22M
            int scaledVal = ( ( *before ) << log2UpsmpFactor ) + roundingOffset;
102
36.1M
      for( SizeType pos = 0; pos < upsmpFactor; pos++)
103
28.9M
      {
104
28.9M
        scaledVal += valDiff;
105
28.9M
        *currDst   = scaledVal >> log2UpsmpFactor;
106
28.9M
        currDst++;
107
28.9M
      }
108
7.22M
      before = behind;
109
7.22M
      behind ++;
110
7.22M
    }
111
112
903k
    srcLine   += predPredSize;
113
903k
    dstLine   += dstStride;
114
903k
    bndryLine += bndryStep;
115
903k
  }
116
112k
}
Buffer.cpp:void vvenc::mipUpsampleHorCore<8u, 3u>(short*, short const*, short const*, unsigned int, unsigned int)
Line
Count
Source
85
78.7k
{
86
78.7k
  const int roundingOffset   = 1 << (log2UpsmpFactor - 1);
87
78.7k
  const SizeType upsmpFactor = 1 << log2UpsmpFactor;
88
89
78.7k
        Pel* dstLine   = dst;
90
78.7k
  const Pel* srcLine   = src;
91
78.7k
  const Pel* bndryLine = bndry + bndryStep - 1;
92
93
708k
  for( SizeType idxOrthDim = 0; idxOrthDim < predPredSize; idxOrthDim++ )
94
630k
  {
95
630k
    const Pel* before  = bndryLine;
96
630k
    const Pel* behind  = srcLine;
97
630k
          Pel* currDst = dstLine;
98
5.67M
    for( SizeType idxUpsmpDim = 0; idxUpsmpDim < predPredSize; idxUpsmpDim++ )
99
5.04M
    {
100
5.04M
      const int valDiff   = *behind - *before;
101
5.04M
            int scaledVal = ( ( *before ) << log2UpsmpFactor ) + roundingOffset;
102
45.3M
      for( SizeType pos = 0; pos < upsmpFactor; pos++)
103
40.3M
      {
104
40.3M
        scaledVal += valDiff;
105
40.3M
        *currDst   = scaledVal >> log2UpsmpFactor;
106
40.3M
        currDst++;
107
40.3M
      }
108
5.04M
      before = behind;
109
5.04M
      behind ++;
110
5.04M
    }
111
112
630k
    srcLine   += predPredSize;
113
630k
    dstLine   += dstStride;
114
630k
    bndryLine += bndryStep;
115
630k
  }
116
78.7k
}
117
118
template< SizeType inHeight, unsigned log2UpsmpFactor>
119
static void mipUpsampleVerCore(Pel* const dst, const Pel* const src, const Pel* const bndry, const SizeType outWidth, const SizeType srcStep  )
120
285k
{
121
285k
  const int roundingOffset   = 1 << (log2UpsmpFactor - 1);
122
285k
  const SizeType upsmpFactor = 1 << log2UpsmpFactor;
123
124
285k
        Pel* dstLine   = dst;
125
285k
  const Pel* srcLine   = src;
126
285k
  const Pel* bndryLine = bndry;
127
128
10.2M
  for( SizeType idxOrthDim = 0; idxOrthDim < outWidth; idxOrthDim++ )
129
10.0M
  {
130
10.0M
    const Pel* before  = bndryLine;
131
10.0M
    const Pel* behind  = srcLine;
132
10.0M
          Pel* currDst = dstLine;
133
89.8M
    for( SizeType idxUpsmpDim = 0; idxUpsmpDim < inHeight; idxUpsmpDim++ )
134
79.8M
    {
135
79.8M
      const int valDiff   = *behind - *before;
136
79.8M
            int scaledVal = ( ( *before ) << log2UpsmpFactor ) + roundingOffset;
137
138
527M
      for( SizeType pos = 0; pos < upsmpFactor; pos++)
139
447M
      {
140
447M
        scaledVal += valDiff;
141
447M
        *currDst   = scaledVal >> log2UpsmpFactor;
142
447M
        currDst += outWidth;
143
447M
      }
144
79.8M
      before = behind;
145
79.8M
      behind += srcStep;
146
79.8M
    }
147
148
10.0M
    srcLine ++;
149
10.0M
    dstLine ++;
150
10.0M
    bndryLine ++;
151
10.0M
  }
152
285k
}
Buffer.cpp:void vvenc::mipUpsampleVerCore<4u, 1u>(short*, short const*, short const*, unsigned int, unsigned int)
Line
Count
Source
120
7.71k
{
121
7.71k
  const int roundingOffset   = 1 << (log2UpsmpFactor - 1);
122
7.71k
  const SizeType upsmpFactor = 1 << log2UpsmpFactor;
123
124
7.71k
        Pel* dstLine   = dst;
125
7.71k
  const Pel* srcLine   = src;
126
7.71k
  const Pel* bndryLine = bndry;
127
128
69.4k
  for( SizeType idxOrthDim = 0; idxOrthDim < outWidth; idxOrthDim++ )
129
61.6k
  {
130
61.6k
    const Pel* before  = bndryLine;
131
61.6k
    const Pel* behind  = srcLine;
132
61.6k
          Pel* currDst = dstLine;
133
308k
    for( SizeType idxUpsmpDim = 0; idxUpsmpDim < inHeight; idxUpsmpDim++ )
134
246k
    {
135
246k
      const int valDiff   = *behind - *before;
136
246k
            int scaledVal = ( ( *before ) << log2UpsmpFactor ) + roundingOffset;
137
138
740k
      for( SizeType pos = 0; pos < upsmpFactor; pos++)
139
493k
      {
140
493k
        scaledVal += valDiff;
141
493k
        *currDst   = scaledVal >> log2UpsmpFactor;
142
493k
        currDst += outWidth;
143
493k
      }
144
246k
      before = behind;
145
246k
      behind += srcStep;
146
246k
    }
147
148
61.6k
    srcLine ++;
149
61.6k
    dstLine ++;
150
61.6k
    bndryLine ++;
151
61.6k
  }
152
7.71k
}
Unexecuted instantiation: Buffer.cpp:void vvenc::mipUpsampleVerCore<4u, 2u>(short*, short const*, short const*, unsigned int, unsigned int)
Unexecuted instantiation: Buffer.cpp:void vvenc::mipUpsampleVerCore<4u, 3u>(short*, short const*, short const*, unsigned int, unsigned int)
Buffer.cpp:void vvenc::mipUpsampleVerCore<8u, 1u>(short*, short const*, short const*, unsigned int, unsigned int)
Line
Count
Source
120
83.4k
{
121
83.4k
  const int roundingOffset   = 1 << (log2UpsmpFactor - 1);
122
83.4k
  const SizeType upsmpFactor = 1 << log2UpsmpFactor;
123
124
83.4k
        Pel* dstLine   = dst;
125
83.4k
  const Pel* srcLine   = src;
126
83.4k
  const Pel* bndryLine = bndry;
127
128
2.13M
  for( SizeType idxOrthDim = 0; idxOrthDim < outWidth; idxOrthDim++ )
129
2.04M
  {
130
2.04M
    const Pel* before  = bndryLine;
131
2.04M
    const Pel* behind  = srcLine;
132
2.04M
          Pel* currDst = dstLine;
133
18.4M
    for( SizeType idxUpsmpDim = 0; idxUpsmpDim < inHeight; idxUpsmpDim++ )
134
16.3M
    {
135
16.3M
      const int valDiff   = *behind - *before;
136
16.3M
            int scaledVal = ( ( *before ) << log2UpsmpFactor ) + roundingOffset;
137
138
49.1M
      for( SizeType pos = 0; pos < upsmpFactor; pos++)
139
32.7M
      {
140
32.7M
        scaledVal += valDiff;
141
32.7M
        *currDst   = scaledVal >> log2UpsmpFactor;
142
32.7M
        currDst += outWidth;
143
32.7M
      }
144
16.3M
      before = behind;
145
16.3M
      behind += srcStep;
146
16.3M
    }
147
148
2.04M
    srcLine ++;
149
2.04M
    dstLine ++;
150
2.04M
    bndryLine ++;
151
2.04M
  }
152
83.4k
}
Buffer.cpp:void vvenc::mipUpsampleVerCore<8u, 2u>(short*, short const*, short const*, unsigned int, unsigned int)
Line
Count
Source
120
115k
{
121
115k
  const int roundingOffset   = 1 << (log2UpsmpFactor - 1);
122
115k
  const SizeType upsmpFactor = 1 << log2UpsmpFactor;
123
124
115k
        Pel* dstLine   = dst;
125
115k
  const Pel* srcLine   = src;
126
115k
  const Pel* bndryLine = bndry;
127
128
2.98M
  for( SizeType idxOrthDim = 0; idxOrthDim < outWidth; idxOrthDim++ )
129
2.86M
  {
130
2.86M
    const Pel* before  = bndryLine;
131
2.86M
    const Pel* behind  = srcLine;
132
2.86M
          Pel* currDst = dstLine;
133
25.7M
    for( SizeType idxUpsmpDim = 0; idxUpsmpDim < inHeight; idxUpsmpDim++ )
134
22.9M
    {
135
22.9M
      const int valDiff   = *behind - *before;
136
22.9M
            int scaledVal = ( ( *before ) << log2UpsmpFactor ) + roundingOffset;
137
138
114M
      for( SizeType pos = 0; pos < upsmpFactor; pos++)
139
91.6M
      {
140
91.6M
        scaledVal += valDiff;
141
91.6M
        *currDst   = scaledVal >> log2UpsmpFactor;
142
91.6M
        currDst += outWidth;
143
91.6M
      }
144
22.9M
      before = behind;
145
22.9M
      behind += srcStep;
146
22.9M
    }
147
148
2.86M
    srcLine ++;
149
2.86M
    dstLine ++;
150
2.86M
    bndryLine ++;
151
2.86M
  }
152
115k
}
Buffer.cpp:void vvenc::mipUpsampleVerCore<8u, 3u>(short*, short const*, short const*, unsigned int, unsigned int)
Line
Count
Source
120
78.7k
{
121
78.7k
  const int roundingOffset   = 1 << (log2UpsmpFactor - 1);
122
78.7k
  const SizeType upsmpFactor = 1 << log2UpsmpFactor;
123
124
78.7k
        Pel* dstLine   = dst;
125
78.7k
  const Pel* srcLine   = src;
126
78.7k
  const Pel* bndryLine = bndry;
127
128
5.11M
  for( SizeType idxOrthDim = 0; idxOrthDim < outWidth; idxOrthDim++ )
129
5.04M
  {
130
5.04M
    const Pel* before  = bndryLine;
131
5.04M
    const Pel* behind  = srcLine;
132
5.04M
          Pel* currDst = dstLine;
133
45.3M
    for( SizeType idxUpsmpDim = 0; idxUpsmpDim < inHeight; idxUpsmpDim++ )
134
40.3M
    {
135
40.3M
      const int valDiff   = *behind - *before;
136
40.3M
            int scaledVal = ( ( *before ) << log2UpsmpFactor ) + roundingOffset;
137
138
362M
      for( SizeType pos = 0; pos < upsmpFactor; pos++)
139
322M
      {
140
322M
        scaledVal += valDiff;
141
322M
        *currDst   = scaledVal >> log2UpsmpFactor;
142
322M
        currDst += outWidth;
143
322M
      }
144
40.3M
      before = behind;
145
40.3M
      behind += srcStep;
146
40.3M
    }
147
148
5.04M
    srcLine ++;
149
5.04M
    dstLine ++;
150
5.04M
    bndryLine ++;
151
5.04M
  }
152
78.7k
}
153
154
static void mipUpsampleHorCore( Pel* dst, const Pel* src, const Pel* bndry, const SizeType dstStride, const SizeType bndryStep, const SizeType predSize, const unsigned log2Factor )
155
287k
{
156
287k
  if( predSize == 4 )
157
7.71k
  {
158
7.71k
    if     ( log2Factor == 1 ) mipUpsampleHorCore<4, 1>( dst, src, bndry, dstStride, bndryStep );
159
0
    else if( log2Factor == 2 ) mipUpsampleHorCore<4, 2>( dst, src, bndry, dstStride, bndryStep );
160
0
    else                       mipUpsampleHorCore<4, 3>( dst, src, bndry, dstStride, bndryStep );
161
7.71k
  }
162
279k
  else
163
279k
  {
164
279k
    if     ( log2Factor == 1 ) mipUpsampleHorCore<8, 1>( dst, src, bndry, dstStride, bndryStep );
165
191k
    else if( log2Factor == 2 ) mipUpsampleHorCore<8, 2>( dst, src, bndry, dstStride, bndryStep );
166
78.7k
    else                       mipUpsampleHorCore<8, 3>( dst, src, bndry, dstStride, bndryStep );
167
279k
  }
168
287k
}
169
170
static void mipUpsampleVerCore( Pel* dst, const Pel* src, const Pel* bndry, const SizeType outWidth, const SizeType srcStep, const SizeType inHeight, const unsigned log2Factor )
171
285k
{
172
285k
  if( inHeight == 4 )
173
7.71k
  {
174
7.71k
    if     ( log2Factor == 1 ) mipUpsampleVerCore<4, 1>( dst, src, bndry, outWidth, srcStep );
175
0
    else if( log2Factor == 2 ) mipUpsampleVerCore<4, 2>( dst, src, bndry, outWidth, srcStep );
176
0
    else                       mipUpsampleVerCore<4, 3>( dst, src, bndry, outWidth, srcStep );
177
7.71k
  }
178
277k
  else
179
277k
  {
180
277k
    if     ( log2Factor == 1 ) mipUpsampleVerCore<8, 1>( dst, src, bndry, outWidth, srcStep );
181
194k
    else if( log2Factor == 2 ) mipUpsampleVerCore<8, 2>( dst, src, bndry, outWidth, srcStep );
182
78.7k
    else                       mipUpsampleVerCore<8, 3>( dst, src, bndry, outWidth, srcStep );
183
277k
  }
184
285k
}
185
186
template< unsigned inputSize, unsigned outputSize >
187
void mipMatrixMulCore( Pel* res, const Pel* input, const uint8_t* weight, const int maxVal, const int inputOffset, bool transpose )
188
297k
{
189
297k
  Pel buffer[ outputSize*outputSize];
190
191
297k
  int sum = 0;
192
2.67M
  for( int i = 0; i < inputSize; i++ )
193
2.37M
  {
194
2.37M
    sum += input[i];
195
2.37M
  }
196
297k
  const int offset = (1 << (MIP_SHIFT_MATRIX - 1)) - MIP_OFFSET_MATRIX * sum + (inputOffset << MIP_SHIFT_MATRIX);
197
297k
  CHECK( inputSize != 4 * (inputSize >> 2), "Error, input size not divisible by four" );
198
199
297k
  Pel* mat = transpose ? buffer : res;
200
297k
  unsigned posRes = 0;
201
18.9M
  for( unsigned n = 0; n < outputSize*outputSize; n++ )
202
18.6M
  {
203
18.6M
    int tmp0 = input[0] * weight[0];
204
18.6M
    int tmp1 = input[1] * weight[1];
205
18.6M
    int tmp2 = input[2] * weight[2];
206
18.6M
    int tmp3 = input[3] * weight[3];
207
18.6M
    if( 8 == inputSize )
208
18.6M
    {
209
18.6M
      tmp0 += input[4] * weight[4];
210
18.6M
      tmp1 += input[5] * weight[5];
211
18.6M
      tmp2 += input[6] * weight[6];
212
18.6M
      tmp3 += input[7] * weight[7];
213
18.6M
    }
214
18.6M
    mat[posRes++] = Clip3<int>( 0, maxVal, ((tmp0 + tmp1 + tmp2 + tmp3 + offset) >> MIP_SHIFT_MATRIX) );
215
216
18.6M
    weight += inputSize;
217
18.6M
  }
218
219
297k
  if( transpose )
220
137k
  {
221
1.22M
    for( int j = 0; j < outputSize; j++ )
222
1.08M
    {
223
9.70M
      for( int i = 0; i < outputSize; i++ )
224
8.62M
      {
225
8.62M
        res[j * outputSize + i] = buffer[i * outputSize + j];
226
8.62M
      }
227
1.08M
    }
228
137k
  }
229
297k
}
Unexecuted instantiation: void vvenc::mipMatrixMulCore<4u, 4u>(short*, short const*, unsigned char const*, int, int, bool)
void vvenc::mipMatrixMulCore<8u, 4u>(short*, short const*, unsigned char const*, int, int, bool)
Line
Count
Source
188
7.71k
{
189
7.71k
  Pel buffer[ outputSize*outputSize];
190
191
7.71k
  int sum = 0;
192
69.4k
  for( int i = 0; i < inputSize; i++ )
193
61.6k
  {
194
61.6k
    sum += input[i];
195
61.6k
  }
196
7.71k
  const int offset = (1 << (MIP_SHIFT_MATRIX - 1)) - MIP_OFFSET_MATRIX * sum + (inputOffset << MIP_SHIFT_MATRIX);
197
7.71k
  CHECK( inputSize != 4 * (inputSize >> 2), "Error, input size not divisible by four" );
198
199
7.71k
  Pel* mat = transpose ? buffer : res;
200
7.71k
  unsigned posRes = 0;
201
131k
  for( unsigned n = 0; n < outputSize*outputSize; n++ )
202
123k
  {
203
123k
    int tmp0 = input[0] * weight[0];
204
123k
    int tmp1 = input[1] * weight[1];
205
123k
    int tmp2 = input[2] * weight[2];
206
123k
    int tmp3 = input[3] * weight[3];
207
123k
    if( 8 == inputSize )
208
123k
    {
209
123k
      tmp0 += input[4] * weight[4];
210
123k
      tmp1 += input[5] * weight[5];
211
123k
      tmp2 += input[6] * weight[6];
212
123k
      tmp3 += input[7] * weight[7];
213
123k
    }
214
123k
    mat[posRes++] = Clip3<int>( 0, maxVal, ((tmp0 + tmp1 + tmp2 + tmp3 + offset) >> MIP_SHIFT_MATRIX) );
215
216
123k
    weight += inputSize;
217
123k
  }
218
219
7.71k
  if( transpose )
220
3.85k
  {
221
19.2k
    for( int j = 0; j < outputSize; j++ )
222
15.4k
    {
223
77.1k
      for( int i = 0; i < outputSize; i++ )
224
61.6k
      {
225
61.6k
        res[j * outputSize + i] = buffer[i * outputSize + j];
226
61.6k
      }
227
15.4k
    }
228
3.85k
  }
229
7.71k
}
void vvenc::mipMatrixMulCore<8u, 8u>(short*, short const*, unsigned char const*, int, int, bool)
Line
Count
Source
188
289k
{
189
289k
  Pel buffer[ outputSize*outputSize];
190
191
289k
  int sum = 0;
192
2.60M
  for( int i = 0; i < inputSize; i++ )
193
2.31M
  {
194
2.31M
    sum += input[i];
195
2.31M
  }
196
289k
  const int offset = (1 << (MIP_SHIFT_MATRIX - 1)) - MIP_OFFSET_MATRIX * sum + (inputOffset << MIP_SHIFT_MATRIX);
197
289k
  CHECK( inputSize != 4 * (inputSize >> 2), "Error, input size not divisible by four" );
198
199
289k
  Pel* mat = transpose ? buffer : res;
200
289k
  unsigned posRes = 0;
201
18.8M
  for( unsigned n = 0; n < outputSize*outputSize; n++ )
202
18.5M
  {
203
18.5M
    int tmp0 = input[0] * weight[0];
204
18.5M
    int tmp1 = input[1] * weight[1];
205
18.5M
    int tmp2 = input[2] * weight[2];
206
18.5M
    int tmp3 = input[3] * weight[3];
207
18.5M
    if( 8 == inputSize )
208
18.5M
    {
209
18.5M
      tmp0 += input[4] * weight[4];
210
18.5M
      tmp1 += input[5] * weight[5];
211
18.5M
      tmp2 += input[6] * weight[6];
212
18.5M
      tmp3 += input[7] * weight[7];
213
18.5M
    }
214
18.5M
    mat[posRes++] = Clip3<int>( 0, maxVal, ((tmp0 + tmp1 + tmp2 + tmp3 + offset) >> MIP_SHIFT_MATRIX) );
215
216
18.5M
    weight += inputSize;
217
18.5M
  }
218
219
289k
  if( transpose )
220
133k
  {
221
1.20M
    for( int j = 0; j < outputSize; j++ )
222
1.07M
    {
223
9.63M
      for( int i = 0; i < outputSize; i++ )
224
8.56M
      {
225
8.56M
        res[j * outputSize + i] = buffer[i * outputSize + j];
226
8.56M
      }
227
1.07M
    }
228
133k
  }
229
289k
}
230
231
template< typename T >
232
void addAvgCore( const T* src1, int src1Stride, const T* src2, int src2Stride, T* dest, int dstStride, int width, int height, unsigned rshift, int offset, const ClpRng& clpRng )
233
0
{
234
0
#define ADD_AVG_CORE_OP( ADDR ) dest[ADDR] = ClipPel( rightShiftU( ( src1[ADDR] + src2[ADDR] + offset ), rshift ), clpRng )
235
0
#define ADD_AVG_CORE_INC    \
236
0
  src1 += src1Stride;       \
237
0
  src2 += src2Stride;       \
238
0
  dest +=  dstStride;       \
239
0
240
0
  SIZE_AWARE_PER_EL_OP( ADD_AVG_CORE_OP, ADD_AVG_CORE_INC );
241
242
0
#undef ADD_AVG_CORE_OP
243
0
#undef ADD_AVG_CORE_INC
244
0
}
245
246
template<typename T>
247
void addWeightedAvgCore( const T* src1, int src1Stride, const T* src2, int src2Stride, T* dest, int destStride, int width, int height, unsigned rshift, int offset, int w0, int w1, const ClpRng& clpRng )
248
0
{
249
0
#define ADD_WGHT_AVG_OP( ADDR ) dest[ADDR] = ClipPel( rightShiftU( ( src1[ADDR]*w0 + src2[ADDR]*w1 + offset ), rshift ), clpRng )
250
0
#define ADD_WGHT_AVG_INC     \
251
0
    src1 += src1Stride; \
252
0
    src2 += src2Stride; \
253
0
    dest += destStride; \
254
0
255
0
  SIZE_AWARE_PER_EL_OP( ADD_WGHT_AVG_OP, ADD_WGHT_AVG_INC );
256
257
0
#undef ADD_WGHT_AVG_OP
258
0
#undef ADD_WGHT_AVG_INC
259
0
}
260
261
template<typename T>
262
void subsCore( const T* src0, int src0Stride, const T* src1, int src1Stride, T* dest, int destStride, int width, int height )
263
910k
{
264
910k
#define SUBS_INC                \
265
910k
  dest += destStride;  \
266
910k
  src0 += src0Stride;  \
267
910k
  src1 += src1Stride;  \
268
910k
269
399M
#define SUBS_OP( ADDR ) dest[ADDR] = src0[ADDR] - src1[ADDR]
270
271
399M
  SIZE_AWARE_PER_EL_OP( SUBS_OP, SUBS_INC );
272
273
910k
#undef SUBS_OP
274
910k
#undef SUBS_INC
275
910k
}
276
277
void removeHighFreq(int16_t* dst, int dstStride, const int16_t* org, int orgStride, const int16_t* src, int srcStride, int width, int height)
278
0
{
279
0
#define REM_HF_INC  \
280
0
 src += srcStride; \
281
0
 org += orgStride; \
282
0
 dst += dstStride; \
283
0
284
0
#define REM_HF_OP( ADDR )      dst[ADDR] =             2 * org[ADDR] - src[ADDR]
285
286
0
 SIZE_AWARE_PER_EL_OP(REM_HF_OP, REM_HF_INC);
287
288
0
#undef REM_HF_INC
289
0
#undef REM_HF_OP
290
0
#undef REM_HF_OP_CLIP
291
0
}
292
293
template<typename T>
294
void reconstructCore( const T* src1, int src1Stride, const T* src2, int src2Stride, T* dest, int dstStride, int width, int height, const ClpRng& clpRng )
295
10.7k
{
296
4.67M
#define RECO_CORE_OP( ADDR ) dest[ADDR] = ClipPel( src1[ADDR] + src2[ADDR], clpRng )
297
10.7k
#define RECO_CORE_INC     \
298
10.7k
  src1 += src1Stride;     \
299
10.7k
  src2 += src2Stride;     \
300
10.7k
  dest +=  dstStride;     \
301
10.7k
302
4.67M
  SIZE_AWARE_PER_EL_OP( RECO_CORE_OP, RECO_CORE_INC );
303
304
10.7k
#undef RECO_CORE_OP
305
10.7k
#undef RECO_CORE_INC
306
10.7k
}
307
308
template<typename T>
309
void recoCore( const T* src1, const T* src2, T* dest, int numSamples, const ClpRng& clpRng )
310
2.64M
{
311
397M
  for( int n = 0; n < numSamples; n+=2)
312
395M
  {
313
395M
    dest[n]   = ClipPel( src1[n]   + src2[n], clpRng );
314
395M
    dest[n+1] = ClipPel( src1[n+1] + src2[n+1], clpRng );
315
395M
  }
316
2.64M
}
317
318
template<typename T>
319
void copyClipCore( const T* src, Pel* dst, int numSamples, const ClpRng& clpRng )
320
0
{
321
0
  int n = 0;
322
0
  for( ; n + 1 < numSamples; n += 2 )
323
0
  {
324
0
    dst[n]   = ClipPel( src[n]   , clpRng );
325
0
    dst[n+1] = ClipPel( src[n+1] , clpRng );
326
0
  }
327
0
  if( n < numSamples )
328
0
  {
329
0
    dst[n] = ClipPel( src[n], clpRng );
330
0
  }
331
0
}
332
333
template< typename T >
334
void addAvgCore( const T* src1, const T* src2, T* dest, int numSamples, unsigned rshift, int offset, const ClpRng& clpRng )
335
0
{
336
0
  for( int n = 0; n < numSamples; n+=2)
337
0
  {
338
0
    dest[n]   = ClipPel( rightShiftU( ( src1[n]   + src2[n]   + offset ), rshift ), clpRng );
339
0
    dest[n+1] = ClipPel( rightShiftU( ( src1[n+1] + src2[n+1] + offset ), rshift ), clpRng );
340
0
  }
341
0
}
342
343
template< typename T >
344
void roundGeoCore( const T* src, T* dest, const int numSamples, unsigned rshift, int offset, const ClpRng &clpRng)
345
0
{
346
0
  for( int i = 0; i < numSamples; i+=2)
347
0
  {
348
0
    dest[i]   = ClipPel(rightShiftU(src[i  ] + offset, rshift), clpRng);
349
0
    dest[i+1] = ClipPel(rightShiftU(src[i+1] + offset, rshift), clpRng);
350
0
  }
351
0
}
352
353
template<typename T>
354
void linTfCore( const T* src, int srcStride, Pel* dst, int dstStride, int width, int height, int scale, unsigned shift, int offset, const ClpRng& clpRng, bool bClip )
355
242k
{
356
242k
#define LINTF_CORE_INC  \
357
242k
  src += srcStride;     \
358
242k
  dst += dstStride;     \
359
242k
360
242k
  if( bClip )
361
242k
  {
362
50.2M
#define LINTF_CORE_OP( ADDR ) dst[ADDR] = ( Pel ) ClipPel( rightShiftU( scale * src[ADDR], shift ) + offset, clpRng )
363
364
50.2M
  SIZE_AWARE_PER_EL_OP( LINTF_CORE_OP, LINTF_CORE_INC );
365
366
242k
#undef LINTF_CORE_OP
367
242k
  }
368
0
  else
369
0
  {
370
0
#define LINTF_CORE_OP( ADDR ) dst[ADDR] = ( Pel ) ( rightShiftU( scale * src[ADDR], shift ) + offset )
371
372
0
  SIZE_AWARE_PER_EL_OP( LINTF_CORE_OP, LINTF_CORE_INC );
373
374
0
#undef LINTF_CORE_OP
375
0
  }
376
242k
#undef LINTF_CORE_INC
377
242k
}
378
379
template<typename T, int N>
380
void transposeNxNCore( const Pel* src, int srcStride, Pel* dst, int dstStride )
381
7.99M
{
382
70.9M
  for( int i = 0; i < N; i++ )
383
62.9M
  {
384
562M
    for( int j = 0; j < N; j++ )
385
499M
    {
386
499M
      dst[j * dstStride] = src[j];
387
499M
    }
388
389
62.9M
    dst++;
390
62.9M
    src += srcStride;
391
62.9M
  }
392
7.99M
}
void vvenc::transposeNxNCore<short, 4>(short const*, int, short*, int)
Line
Count
Source
381
251k
{
382
1.25M
  for( int i = 0; i < N; i++ )
383
1.00M
  {
384
5.02M
    for( int j = 0; j < N; j++ )
385
4.01M
    {
386
4.01M
      dst[j * dstStride] = src[j];
387
4.01M
    }
388
389
1.00M
    dst++;
390
1.00M
    src += srcStride;
391
1.00M
  }
392
251k
}
void vvenc::transposeNxNCore<short, 8>(short const*, int, short*, int)
Line
Count
Source
381
7.73M
{
382
69.6M
  for( int i = 0; i < N; i++ )
383
61.9M
  {
384
557M
    for( int j = 0; j < N; j++ )
385
495M
    {
386
495M
      dst[j * dstStride] = src[j];
387
495M
    }
388
389
61.9M
    dst++;
390
61.9M
    src += srcStride;
391
61.9M
  }
392
7.73M
}
393
394
template<typename T>
395
void copyClipCore( const T* src, int srcStride, Pel* dst, int dstStride, int width, int height, const ClpRng& clpRng )
396
0
{
397
0
#define RECO_OP( ADDR ) dst[ADDR] = ClipPel( src[ADDR], clpRng )
398
0
#define RECO_INC      \
399
0
    src += srcStride; \
400
0
    dst += dstStride; \
401
0
402
0
  SIZE_AWARE_PER_EL_OP( RECO_OP, RECO_INC );
403
404
0
#undef RECO_OP
405
0
#undef RECO_INC
406
0
}
407
408
void copyBufferCore( const char* src, int srcStride, char* dst, int dstStride, int numBytes, int height)
409
10.5M
{
410
175M
  for( int i = 0; i < height; i++, src += srcStride, dst += dstStride )
411
164M
  {
412
164M
    memcpy( dst, src, numBytes );
413
164M
  }
414
10.5M
}
415
416
void fillMapPtr_Core( void** ptrMap, const ptrdiff_t mapStride, int width, int height, void* val )
417
523k
{
418
523k
  if( width == mapStride )
419
343k
  {
420
343k
    std::fill_n( ptrMap, width * height, val );
421
343k
  }
422
180k
  else
423
180k
  {
424
1.68M
    while( height-- )
425
1.50M
    {
426
1.50M
      std::fill_n( ptrMap, width, val );
427
1.50M
      ptrMap += mapStride;
428
1.50M
    }
429
180k
  }
430
523k
}
431
432
uint64_t AvgHighPassCore( const int width, const int height, const Pel* pSrc, const int iSrcStride)
433
13.1k
{
434
13.1k
  uint64_t saAct = 0;
435
1.07M
  for (int y = 1; y < height - 1; y++)
436
1.05M
  {
437
99.9M
    for (int x = 1; x < width - 1; x++) // center cols
438
98.9M
    {
439
98.9M
      const int s = 12 * (int) pSrc[x  ] - 2 * ((int) pSrc[x-1] + (int) pSrc[x+1] + (int) pSrc[x  -iSrcStride] + (int) pSrc[x  +iSrcStride])
440
98.9M
                             - ((int) pSrc[x-1-iSrcStride] + (int) pSrc[x+1-iSrcStride] + (int) pSrc[x-1+iSrcStride] + (int) pSrc[x+1+iSrcStride]);
441
98.9M
      saAct += abs (s);
442
98.9M
    }
443
1.05M
    pSrc += iSrcStride;
444
1.05M
  }
445
13.1k
  return saAct;
446
13.1k
}
447
448
uint64_t HDHighPassCore  (const int width, const int height,const Pel*  pSrc,const Pel* pSM1,const int iSrcStride,const int iSM1Stride)
449
0
{
450
0
  uint64_t taAct = 0;
451
0
  for (int y = 1; y < height - 1; y++)
452
0
  {
453
0
    for (int x = 1; x < width - 1; x++)  // cnt cols
454
0
    {
455
0
      const int t = (int) pSrc[x] - (int) pSM1[x];
456
0
      taAct += (1 + 3 * abs (t)) >> 1;
457
0
    }
458
0
    pSrc += iSrcStride;
459
0
    pSM1 += iSM1Stride;
460
0
  }
461
0
  return taAct;
462
0
}
463
464
uint64_t  HDHighPass2Core  (const int width, const int height,const Pel*  pSrc,const Pel* pSM1,const Pel* pSM2,const int iSrcStride,const int iSM1Stride,const int iSM2Stride)
465
0
{
466
0
  uint64_t taAct = 0;
467
0
  for (int y = 1; y < height - 1; y++)
468
0
  {
469
0
    for (int x = 1; x < width - 1; x++)  // cnt cols
470
0
    {
471
0
      const int t = (int) pSrc[x] - 2 * (int) pSM1[x] + (int) pSM2[x];
472
0
      taAct += abs (t);
473
0
    }
474
0
    pSrc += iSrcStride;
475
0
    pSM1 += iSM1Stride;
476
0
    pSM2 += iSM2Stride;
477
0
  }
478
0
  return taAct;
479
0
}
480
uint64_t AvgHighPassWithDownsamplingCore( const int width, const int height, const Pel* pSrc, const int iSrcStride)
481
0
{
482
0
  uint64_t saAct = 0;
483
0
  pSrc -= iSrcStride;
484
0
  pSrc -= iSrcStride;
485
0
 for (int y = 2; y < height - 2; y += 2)
486
0
 {
487
0
   for (int x = 2; x < width - 2; x += 2)
488
0
   {
489
0
     const int f = 12 * ((int)pSrc[ y   *iSrcStride + x  ] + (int)pSrc[ y   *iSrcStride + x+1] + (int)pSrc[(y+1)*iSrcStride + x  ] + (int)pSrc[(y+1)*iSrcStride + x+1])
490
0
                  - 3 * ((int)pSrc[(y-1)*iSrcStride + x  ] + (int)pSrc[(y-1)*iSrcStride + x+1] + (int)pSrc[(y+2)*iSrcStride + x  ] + (int)pSrc[(y+2)*iSrcStride + x+1])
491
0
                  - 3 * ((int)pSrc[ y   *iSrcStride + x-1] + (int)pSrc[ y   *iSrcStride + x+2] + (int)pSrc[(y+1)*iSrcStride + x-1] + (int)pSrc[(y+1)*iSrcStride + x+2])
492
0
                  - 2 * ((int)pSrc[(y-1)*iSrcStride + x-1] + (int)pSrc[(y-1)*iSrcStride + x+2] + (int)pSrc[(y+2)*iSrcStride + x-1] + (int)pSrc[(y+2)*iSrcStride + x+2])
493
0
                      - ((int)pSrc[(y-2)*iSrcStride + x-1] + (int)pSrc[(y-2)*iSrcStride + x  ] + (int)pSrc[(y-2)*iSrcStride + x+1] + (int)pSrc[(y-2)*iSrcStride + x+2]
494
0
                       + (int)pSrc[(y+3)*iSrcStride + x-1] + (int)pSrc[(y+3)*iSrcStride + x  ] + (int)pSrc[(y+3)*iSrcStride + x+1] + (int)pSrc[(y+3)*iSrcStride + x+2]
495
0
                       + (int)pSrc[(y-1)*iSrcStride + x-2] + (int)pSrc[ y   *iSrcStride + x-2] + (int)pSrc[(y+1)*iSrcStride + x-2] + (int)pSrc[(y+2)*iSrcStride + x-2]
496
0
                       + (int)pSrc[(y-1)*iSrcStride + x+3] + (int)pSrc[ y   *iSrcStride + x+3] + (int)pSrc[(y+1)*iSrcStride + x+3] + (int)pSrc[(y+2)*iSrcStride + x+3]);
497
0
     saAct += (uint64_t) abs(f);
498
0
   }
499
0
 }
500
0
 return saAct;
501
0
}
502
uint64_t AvgHighPassWithDownsamplingDiff1stCore (const int width, const int  height, const Pel* pSrc,const Pel* pSrcM1, const int iSrcStride, const int iSrcM1Stride)
503
0
{
504
0
  uint64_t taAct = 0;
505
0
  pSrc -= iSrcStride;
506
0
  pSrc -= iSrcStride;
507
0
  pSrcM1-=iSrcM1Stride;
508
0
  pSrcM1-=iSrcM1Stride;
509
510
0
  for (uint32_t y = 2; y < height-2; y += 2)
511
0
  {
512
0
    for (uint32_t x = 2; x < width-2; x += 2)
513
0
    {
514
0
      const int t = (int)pSrc  [y*iSrcStride + x] + (int)pSrc  [y*iSrcStride + x+1] + (int)pSrc  [(y+1)*iSrcStride + x] + (int)pSrc  [(y+1)*iSrcStride + x+1]
515
0
                 - ((int)pSrcM1[y*iSrcM1Stride + x] + (int)pSrcM1[y*iSrcM1Stride + x+1] + (int)pSrcM1[(y+1)*iSrcM1Stride + x] + (int)pSrcM1[(y+1)*iSrcM1Stride + x+1]);
516
0
      taAct += (1 + 3 * abs (t)) >> 1;
517
0
    }
518
0
  }
519
0
  return (taAct );
520
0
}
521
522
uint64_t AvgHighPassWithDownsamplingDiff2ndCore (const int width,const int height,const Pel* pSrc,const Pel* pSrcM1,const Pel* pSrcM2,const int iSrcStride,const int iSM1Stride,const int iSM2Stride)
523
0
{
524
0
  uint64_t taAct = 0;
525
526
0
  pSrc -= iSrcStride;
527
0
  pSrc -= iSrcStride;
528
0
  pSrcM1-=iSM1Stride;
529
0
  pSrcM1-=iSM1Stride;
530
0
  pSrcM2-=iSM2Stride;
531
0
  pSrcM2-=iSM2Stride;
532
533
0
  for (uint32_t y = 2; y < height-2; y += 2)
534
0
  {
535
0
    for (uint32_t x = 2; x < width-2; x += 2)
536
0
    {
537
0
      const int t = (int)pSrc  [y*iSrcStride + x] + (int)pSrc  [y*iSrcStride + x+1] + (int)pSrc  [(y+1)*iSrcStride + x] + (int)pSrc  [(y+1)*iSrcStride + x+1]
538
0
                            - 2 * ((int)pSrcM1[y*iSM1Stride + x] + (int)pSrcM1[y*iSM1Stride + x+1] + (int)pSrcM1[(y+1)*iSM1Stride + x] + (int)pSrcM1[(y+1)*iSM1Stride + x+1])
539
0
                            + (int)pSrcM2[y*iSM2Stride + x] + (int)pSrcM2[y*iSM2Stride + x+1] + (int)pSrcM2[(y+1)*iSM2Stride + x] + (int)pSrcM2[(y+1)*iSM2Stride + x+1];
540
0
      taAct += (uint64_t) abs(t);
541
0
    }
542
0
  }
543
0
  return (taAct);
544
0
}
545
546
uint64_t sumSquaredErrorCore( const Pel* src0, const ptrdiff_t stride0, const Pel* src1, const ptrdiff_t stride1, const int width, const int height )
547
4.29k
{
548
4.29k
  uint64_t sum = 0;
549
448k
  for( int y = 0; y < height; y++, src0 += stride0, src1 += stride1 )
550
444k
  {
551
54.4M
    for( int x = 0; x < width; x++ )
552
54.0M
    {
553
54.0M
      const Intermediate_Int diff = src0[x] - src1[x];
554
54.0M
      sum += uint64_t( diff * diff );
555
54.0M
    }
556
444k
  }
557
4.29k
  return sum;
558
4.29k
}
559
560
static void sumSquaredErrorPartsCore( const Pel* src0, const ptrdiff_t stride0, const Pel* src1, const ptrdiff_t stride1, const int lengthX, const int lengthY, const int numX, const int numY, uint32_t sums[][4] )
561
0
{
562
0
  for( int j = 0; j < numY; j++, src0 += lengthY * stride0, src1 += lengthY * stride1 )
563
0
  {
564
0
    for( int i = 0; i < numX; i++ )
565
0
    {
566
0
      sums[j][i] = uint32_t( sumSquaredErrorCore( src0 + i * lengthX, stride0, src1 + i * lengthX, stride1, lengthX, lengthY ) );
567
0
    }
568
0
  }
569
0
}
570
571
static uint32_t pictureChecksumCore( const Pel* plane, const ptrdiff_t stride, const int width, const int height, const bool twoBytes )
572
0
{
573
0
  uint32_t checksum = 0;
574
0
  for( int y = 0; y < height; y++, plane += stride )
575
0
  {
576
0
    for( int x = 0; x < width; x++ )
577
0
    {
578
0
      const uint8_t xorMask = ( x & 0xff ) ^ ( y & 0xff ) ^ ( x >> 8 ) ^ ( y >> 8 );
579
0
      checksum += ( plane[x] & 0xff ) ^ xorMask;
580
0
      if( twoBytes )
581
0
      {
582
0
        checksum += ( plane[x] >> 8 ) ^ xorMask;
583
0
      }
584
0
    }
585
0
  }
586
0
  return checksum;
587
0
}
588
589
static int64_t sumCore( const Pel* src, const ptrdiff_t stride, const int width, const int height )
590
30.7k
{
591
30.7k
  int64_t sum = 0;
592
1.73M
  for( int y = 0; y < height; y++, src += stride )
593
1.70M
  {
594
127M
    for( int x = 0; x < width; x++ )
595
125M
    {
596
125M
      sum += src[x];
597
125M
    }
598
1.70M
  }
599
30.7k
  return sum;
600
30.7k
}
601
602
static void sumAndSumSquaresCore( const Pel* src, const ptrdiff_t stride, const int width, const int height, int64_t& sum, int64_t& sumSquares )
603
0
{
604
0
  sum        = 0;
605
0
  sumSquares = 0;
606
0
  for( int y = 0; y < height; y++, src += stride )
607
0
  {
608
0
    for( int x = 0; x < width; x++ )
609
0
    {
610
0
      sum        += src[x];
611
0
      sumSquares += src[x] * src[x];
612
0
    }
613
0
  }
614
0
}
615
616
static void padHorizontalCore( Pel* src, const ptrdiff_t stride, const int width, const int height, const int marginLeft, const int marginRight )
617
34.9k
{
618
2.21M
  for( int y = 0; y < height; y++, src += stride )
619
2.17M
  {
620
45.2M
    for( int x = 0; x < marginLeft; x++ )
621
43.0M
    {
622
43.0M
      src[x - marginLeft] = src[0];
623
43.0M
    }
624
49.3M
    for( int x = 0; x < marginRight; x++ )
625
47.2M
    {
626
47.2M
      src[width + x] = src[width - 1];
627
47.2M
    }
628
2.17M
  }
629
34.9k
}
630
631
static void downsample2x2Core( const Pel* src, const ptrdiff_t srcStride, Pel* dst, const ptrdiff_t dstStride, const int dstWidth, const int dstHeight )
632
0
{
633
0
  for( int y = 0; y < dstHeight; y++, src += 2 * srcStride, dst += dstStride )
634
0
  {
635
0
    const Pel* below = src + srcStride;
636
0
    for( int x = 0; x < dstWidth; x++ )
637
0
    {
638
0
      dst[x] = Pel( ( src[2 * x] + below[2 * x] + src[2 * x + 1] + below[2 * x + 1] + 2 ) >> 2 );
639
0
    }
640
0
  }
641
0
}
642
643
int64_t highPassCorrelationCore( const Pel* cb, const ptrdiff_t cbStride, const Pel* cr, const ptrdiff_t crStride, const int width, const int height, const int bitDepth )
644
1.43k
{
645
1.43k
  int64_t sum = 0;
646
109k
  for( int y = 0; y < height; y++, cb += cbStride, cr += crStride )
647
108k
  {
648
8.68M
    for( int x = 0; x < width; x++ )
649
8.57M
    {
650
8.57M
      const int hpCb = ( 12*(int)cb[x] - 2*((int)cb[x-1] + (int)cb[x+1] + (int)cb[x-cbStride] + (int)cb[x+cbStride]) - ((int)cb[x-1-cbStride] + (int)cb[x+1-cbStride] + (int)cb[x-1+cbStride] + (int)cb[x+1+cbStride]) );
651
8.57M
      const int hpCr = ( 12*(int)cr[x] - 2*((int)cr[x-1] + (int)cr[x+1] + (int)cr[x-crStride] + (int)cr[x+crStride]) - ((int)cr[x-1-crStride] + (int)cr[x+1-crStride] + (int)cr[x-1+crStride] + (int)cr[x+1+crStride]) );
652
8.57M
      sum += hpCb * hpCr;
653
8.57M
    }
654
108k
  }
655
1.43k
  return sum;
656
1.43k
}
657
658
void blockStats4x4Core( const Pel* src, const ptrdiff_t stride, const int numBlocks, const int bitDepth, int* sum, int* absDev )
659
55.5k
{
660
2.30M
  for( int b = 0; b < numBlocks; b++, src += 4 )
661
2.25M
  {
662
2.25M
    int s = 0;
663
11.2M
    for( int h = 0; h < 4; h++ )
664
9.00M
    {
665
45.0M
      for( int w = 0; w < 4; w++ )
666
36.0M
      {
667
36.0M
        s += src[h * stride + w];
668
36.0M
      }
669
9.00M
    }
670
2.25M
    int d = 0;
671
11.2M
    for( int h = 0; h < 4; h++ )
672
9.00M
    {
673
45.0M
      for( int w = 0; w < 4; w++ )
674
36.0M
      {
675
36.0M
        d += abs( s - ( int( src[h * stride + w] ) << 4 ) );
676
36.0M
      }
677
9.00M
    }
678
2.25M
    sum[b]    = s;
679
2.25M
    absDev[b] = d;
680
2.25M
  }
681
55.5k
}
682
683
void absGradientSumsCore( const Pel* src, const ptrdiff_t stride, const int width, const int height, int* sums )
684
34.5k
{
685
34.5k
  Intermediate_Int horVal = 0;
686
34.5k
  Intermediate_Int verVal = 0;
687
34.5k
  Intermediate_Int dowVal = 0;
688
34.5k
  Intermediate_Int dupVal = 0;
689
690
2.79M
  for( int k = 0; k < height - 1; k++, src += stride )
691
2.76M
  {
692
2.76M
    const Pel* below = src + stride;
693
252M
    for( int j = 0; j < width - 1; j++ )
694
249M
    {
695
249M
      horVal += abs( src[j + 1]   - src[j] );
696
249M
      verVal += abs( below[j]     - src[j] );
697
249M
      dowVal += abs( src[j + 1]   - below[j] );
698
249M
      dupVal += abs( below[j + 1] - src[j] );
699
249M
    }
700
2.76M
  }
701
34.5k
  sums[0] = horVal;
702
34.5k
  sums[1] = verVal;
703
34.5k
  sums[2] = dowVal;
704
34.5k
  sums[3] = dupVal;
705
34.5k
}
706
707
static uint32_t sumAbsDeviationCore( const Pel* src, const ptrdiff_t stride, const int width, const int height, const int value )
708
0
{
709
0
  uint32_t sum = 0;
710
0
  for( int y = 0; y < height; y++, src += stride )
711
0
  {
712
0
    for( int x = 0; x < width; x++ )
713
0
    {
714
0
      sum += uint32_t( abs( src[x] - value ) );
715
0
    }
716
0
  }
717
0
  return sum;
718
0
}
719
720
// One candidate after the other: the prefix sums of lane l start at prefix + l * ( width + 1 ) * height.
721
static void geoPrefixSumsCore( const Pel* org, int orgStride, const Pel* const* pred, int predStride, int width, int height, const bool* laneUsed, uint32_t* prefix )
722
0
{
723
0
  for( int lane = 0; lane < GEO_PREFIX_LANES; lane++ )
724
0
  {
725
0
    if( !laneUsed[lane] )
726
0
    {
727
0
      continue;
728
0
    }
729
0
    uint32_t* out = prefix + lane * ( width + 1 ) * height;
730
0
    for( int y = 0; y < height; y++ )
731
0
    {
732
0
      const Pel* o = org + y * orgStride;
733
0
      const Pel* p = pred[lane] + y * predStride;
734
0
      uint32_t sum = 0;
735
0
      *out++ = 0;
736
0
      for( int x = 0; x < width; x++ )
737
0
      {
738
0
        sum += abs( o[x] - p[x] );
739
0
        *out++ = sum;
740
0
      }
741
0
    }
742
0
  }
743
0
}
744
745
static void geoRunSadsCore( const uint32_t* prefix, const uint8_t* runStart, const uint8_t* runEnd, int width, int height, const bool* laneUsed, uint32_t* sad )
746
0
{
747
0
  for( int lane = 0; lane < GEO_PREFIX_LANES; lane++, prefix += ( width + 1 ) * height )
748
0
  {
749
0
    if( !laneUsed[lane] )
750
0
    {
751
0
      continue;
752
0
    }
753
0
    const uint32_t* row = prefix;
754
0
    uint32_t sum = 0;
755
0
    for( int y = 0; y < height; y++, row += width + 1 )
756
0
    {
757
0
      sum += row[runEnd[y]] - row[runStart[y]];
758
0
    }
759
0
    sad[lane] = sum;
760
0
  }
761
0
}
762
763
PelBufferOps::PelBufferOps()
764
14
{
765
14
  addAvg            = addAvgCore<Pel>;
766
14
  reco              = recoCore<Pel>;
767
14
  copyClip          = copyClipCore<Pel>;
768
14
  roundGeo          = roundGeoCore<Pel>;
769
14
  geoPrefixSums     = geoPrefixSumsCore;
770
14
  geoRunSads        = geoRunSadsCore;
771
772
14
  addAvg4           = addAvgCore<Pel>;
773
14
  addAvg8           = addAvgCore<Pel>;
774
14
  addAvg16          = addAvgCore<Pel>;
775
776
14
  sub2              = subsCore<Pel>;
777
14
  sub4              = subsCore<Pel>;
778
14
  sub8              = subsCore<Pel>;
779
780
14
  wghtAvg4          = addWeightedAvgCore<Pel>;
781
14
  wghtAvg8          = addWeightedAvgCore<Pel>;
782
783
14
  copyClip2         = copyClipCore<Pel>;
784
14
  copyClip4         = copyClipCore<Pel>;
785
14
  copyClip8         = copyClipCore<Pel>;
786
787
14
  reco2             = reconstructCore<Pel>;
788
14
  reco4             = reconstructCore<Pel>;
789
14
  reco8             = reconstructCore<Pel>;
790
791
14
  linTf4            = linTfCore<Pel>;
792
14
  linTf8            = linTfCore<Pel>;
793
794
14
  copyBuffer        = copyBufferCore;
795
796
14
  removeHighFreq8   = removeHighFreq;
797
14
  removeHighFreq4   = removeHighFreq;
798
799
14
  transpose4x4      = transposeNxNCore<Pel,4>;
800
14
  transpose8x8      = transposeNxNCore<Pel,8>;
801
14
  mipMatrixMul_4_4  = mipMatrixMulCore<4,4>;
802
14
  mipMatrixMul_8_4  = mipMatrixMulCore<8,4>;
803
14
  mipMatrixMul_8_8  = mipMatrixMulCore<8,8>;
804
14
  mipUpsampleHor    = mipUpsampleHorCore;
805
14
  mipUpsampleVer    = mipUpsampleVerCore;
806
14
  weightCiip        = weightCiipCore;
807
14
  roundIntVector    = nullptr;
808
809
14
  fillPtrMap        = fillMapPtr_Core;
810
14
  AvgHighPassWithDownsampling = AvgHighPassWithDownsamplingCore;
811
14
  AvgHighPass = AvgHighPassCore;
812
14
  AvgHighPassWithDownsamplingDiff1st = AvgHighPassWithDownsamplingDiff1stCore;
813
14
  AvgHighPassWithDownsamplingDiff2nd = AvgHighPassWithDownsamplingDiff2ndCore;
814
14
  HDHighPass = HDHighPassCore;
815
14
  HDHighPass2 = HDHighPass2Core;
816
14
  sumSquaredError  = sumSquaredErrorCore;
817
14
  sumSquaredErrorParts = sumSquaredErrorPartsCore;
818
14
  sum              = sumCore;
819
14
  sumAndSumSquares = sumAndSumSquaresCore;
820
14
  pictureChecksum  = pictureChecksumCore;
821
14
  padHorizontal    = padHorizontalCore;
822
14
  downsample2x2    = downsample2x2Core;
823
14
  highPassCorrelation = highPassCorrelationCore;
824
14
  blockStats4x4       = blockStats4x4Core;
825
14
  absGradientSums     = absGradientSumsCore;
826
14
  sumAbsDeviation     = sumAbsDeviationCore;
827
14
}
828
829
void PelBufferOps::initPelBufOps( bool enableOpt )
830
0
{
831
0
  if( isInitSIMDDone )
832
0
  {
833
0
    return;
834
0
  }
835
0
  isInitSIMDDone = true;
836
837
0
  if( enableOpt )
838
0
  {
839
0
#if ENABLE_SIMD_OPT_BUFFER
840
#  if defined( TARGET_SIMD_X86 )
841
    initPelBufOpsX86();
842
#  endif
843
#  if defined( TARGET_SIMD_ARM )
844
    initPelBufOpsARM();
845
#  endif
846
0
#endif   // ENABLE_SIMD_OPT_BUFFER
847
0
  }
848
0
}
849
850
PelBufferOps g_pelBufOP = PelBufferOps();
851
852
template<>
853
Pel AreaBuf<Pel>::getAvg() const
854
1.43k
{
855
1.43k
  return Pel( ( g_pelBufOP.sum( buf, stride, width, height ) + ( area() >> 1 ) ) / area() );
856
1.43k
}
857
858
template<>
859
const Pel AreaBuf<const Pel>::getAvg() const
860
29.3k
{
861
29.3k
  return Pel( ( g_pelBufOP.sum( buf, stride, width, height ) + ( area() >> 1 ) ) / area() );
862
29.3k
}
863
864
template<>
865
void AreaBuf<Pel>::extendBorderPelLft( int y, int size, int margin )
866
15.3k
{
867
15.3k
  g_pelBufOP.padHorizontal( buf + y * stride, stride, width, size, margin, 0 );
868
15.3k
}
869
870
template<>
871
void AreaBuf<Pel>::extendBorderPelRgt( int y, int size, int margin )
872
15.3k
{
873
15.3k
  g_pelBufOP.padHorizontal( buf + y * stride, stride, width, size, 0, margin );
874
15.3k
}
875
876
template<>
877
void AreaBuf<Pel>::extendBorderPel( unsigned marginX, unsigned marginY )
878
4.29k
{
879
4.29k
  CHECK( ( width + 2 * marginX ) > stride, "Size of buffer too small to extend" );
880
881
  // left and right margins
882
4.29k
  g_pelBufOP.padHorizontal( buf, stride, width, height, marginX, marginX );
883
884
  // top and bottom margins, copied from the extended first and last row
885
4.29k
  Pel* firstRow = buf - marginX;
886
4.29k
  Pel* lastRow  = buf - marginX + ( height - 1 ) * stride;
887
4.29k
  const size_t rowSize = sizeof( Pel ) * ( width + ( marginX << 1 ) );
888
50.1k
  for( unsigned y = 0; y < marginY; y++ )
889
45.8k
  {
890
45.8k
    ::memcpy( lastRow + ( y + 1 ) * stride, lastRow, rowSize );
891
45.8k
  }
892
50.1k
  for( unsigned y = 0; y < marginY; y++ )
893
45.8k
  {
894
45.8k
    ::memcpy( firstRow - ( y + 1 ) * stride, firstRow, rowSize );
895
45.8k
  }
896
4.29k
}
897
898
template<>
899
void AreaBuf<Pel>::addWeightedAvg(const AreaBuf<const Pel>& other1, const AreaBuf<const Pel>& other2, const ClpRng& clpRng, const int8_t BcwIdx)
900
0
{
901
0
  const int8_t w0 = getBcwWeight( BcwIdx, REF_PIC_LIST_0 );
902
0
  const int8_t w1 = getBcwWeight( BcwIdx, REF_PIC_LIST_1 );
903
0
  const int8_t log2WeightBase = g_BcwLog2WeightBase;
904
0
  const Pel* src0 = other1.buf;
905
0
  const Pel* src2 = other2.buf;
906
0
        Pel* dest =        buf;
907
908
0
  const int src1Stride = other1.stride;
909
0
  const int src2Stride = other2.stride;
910
0
  const int destStride =        stride;
911
0
  const int clipbd     = clpRng.bd;
912
0
  const int shiftNum   = std::max<int>( 2, ( IF_INTERNAL_PREC - clipbd ) ) + log2WeightBase;
913
0
  const int offset     = ( 1 << ( shiftNum - 1 ) ) + ( IF_INTERNAL_OFFS << log2WeightBase );
914
915
0
  if( ( width & 7 ) == 0 )
916
0
  {
917
0
    g_pelBufOP.wghtAvg8( src0, src1Stride, src2, src2Stride, dest, destStride, width, height, shiftNum, offset, w0, w1, clpRng );
918
0
  }
919
0
  else if( ( width & 3 ) == 0 )
920
0
  {
921
0
    g_pelBufOP.wghtAvg4( src0, src1Stride, src2, src2Stride, dest, destStride, width, height, shiftNum, offset, w0, w1, clpRng );
922
0
  }
923
0
  else
924
0
  {
925
0
#define WGHT_AVG_OP( ADDR ) dest[ADDR] = ClipPel( rightShiftU( ( src0[ADDR]*w0 + src2[ADDR]*w1 + offset ), shiftNum ), clpRng )
926
0
#define WGHT_AVG_INC    \
927
0
    src0 += src1Stride; \
928
0
    src2 += src2Stride; \
929
0
    dest += destStride; \
930
0
931
0
    SIZE_AWARE_PER_EL_OP( WGHT_AVG_OP, WGHT_AVG_INC );
932
933
0
#undef WGHT_AVG_OP
934
0
#undef WGHT_AVG_INC
935
0
  }
936
0
}
937
938
template<>
939
void AreaBuf<Pel>::addAvg( const AreaBuf<const Pel>& other1, const AreaBuf<const Pel>& other2, const ClpRng& clpRng)
940
0
{
941
0
  const Pel* src0 = other1.buf;
942
0
  const Pel* src2 = other2.buf;
943
0
        Pel* dest =        buf;
944
945
0
  const unsigned src1Stride = other1.stride;
946
0
  const unsigned src2Stride = other2.stride;
947
0
  const unsigned destStride =        stride;
948
0
  const int      clipbd     = clpRng.bd;
949
0
  const unsigned shiftNum   = std::max<int>(2, (IF_INTERNAL_PREC - clipbd)) + 1;
950
0
  const int      offset     = (1 << (shiftNum - 1)) + 2 * IF_INTERNAL_OFFS;
951
952
0
#if ENABLE_SIMD_OPT_BUFFER
953
0
  if( destStride == width )
954
0
  {
955
0
    g_pelBufOP.addAvg(src0, src2, dest, width * height, shiftNum, offset, clpRng);
956
0
  }
957
0
  else if ((width & 15) == 0)
958
0
  {
959
0
    g_pelBufOP.addAvg16(src0, src1Stride, src2, src2Stride, dest, destStride, width, height, shiftNum, offset, clpRng);
960
0
  }
961
0
  else if( ( width & 7 ) == 0 )
962
0
  {
963
0
    g_pelBufOP.addAvg8( src0, src1Stride, src2, src2Stride, dest, destStride, width, height, shiftNum, offset, clpRng );
964
0
  }
965
0
  else if( ( width & 3 ) == 0 )
966
0
  {
967
0
    g_pelBufOP.addAvg4( src0, src1Stride, src2, src2Stride, dest, destStride, width, height, shiftNum, offset, clpRng );
968
0
  }
969
0
  else
970
0
#endif
971
0
  {
972
0
#define ADD_AVG_OP( ADDR ) dest[ADDR] = ClipPel( rightShiftU( ( src0[ADDR] + src2[ADDR] + offset ), shiftNum ), clpRng )
973
0
#define ADD_AVG_INC     \
974
0
    src0 += src1Stride; \
975
0
    src2 += src2Stride; \
976
0
    dest += destStride; \
977
0
978
0
    SIZE_AWARE_PER_EL_OP( ADD_AVG_OP, ADD_AVG_INC );
979
980
0
#undef ADD_AVG_OP
981
0
#undef ADD_AVG_INC
982
0
  }
983
0
}
984
985
template<>
986
void AreaBuf<Pel>::subtract( const AreaBuf<const Pel>& minuend, const AreaBuf<const Pel>& subtrahend )
987
910k
{
988
910k
  CHECKD( width  != minuend.width,     "Incompatible size" );
989
910k
  CHECKD( height != minuend.height,    "Incompatible size" );
990
910k
  CHECKD( width  != subtrahend.width,  "Incompatible size");
991
910k
  CHECKD( height != subtrahend.height, "Incompatible size");
992
  
993
910k
        Pel* dest =            buf;
994
910k
  const Pel* mins = minuend   .buf;
995
910k
  const Pel* subs = subtrahend.buf;
996
997
998
910k
#if ENABLE_SIMD_OPT_BUFFER
999
910k
  const unsigned destStride =            stride;
1000
910k
  const unsigned minsStride = minuend.   stride;
1001
910k
  const unsigned subsStride = subtrahend.stride;
1002
1003
910k
  if( ( width & 7 ) == 0 )
1004
765k
  {
1005
765k
    g_pelBufOP.sub8( mins, minsStride, subs, subsStride, dest, destStride, width, height );
1006
765k
  }
1007
145k
  else if( ( width & 3 ) == 0 )
1008
145k
  {
1009
145k
    g_pelBufOP.sub4( mins, minsStride, subs, subsStride, dest, destStride, width, height );
1010
145k
  }
1011
0
  else if( width == 2 )
1012
0
  {
1013
0
    g_pelBufOP.sub2( mins, minsStride, subs, subsStride, dest, destStride, width, height );
1014
0
  }
1015
0
  else
1016
0
#endif
1017
0
  {
1018
0
#define SUBS_INC                \
1019
0
    dest +=            stride;  \
1020
0
    mins += minuend   .stride;  \
1021
0
    subs += subtrahend.stride;  \
1022
0
1023
0
#define SUBS_OP( ADDR ) dest[ADDR] = mins[ADDR] - subs[ADDR]
1024
1025
0
    SIZE_AWARE_PER_EL_OP( SUBS_OP, SUBS_INC );
1026
1027
0
#undef SUBS_OP
1028
0
#undef SUBS_INC
1029
0
  }
1030
910k
}
1031
1032
template<>
1033
void AreaBuf<const Pel>::calcVarianceSplit( const AreaBuf<const Pel>& Org, const uint32_t  size, int& varh,int& varv) const
1034
0
{
1035
0
  CHECK( Org.width != Org.height, "Incompatible size!" );
1036
0
  int stride = Org.stride;
1037
0
  double variance=0;
1038
0
  double mean=0;
1039
0
  int64_t sum[4]={0,0,0,0};
1040
0
  int64_t sum_sqr[4]={0,0,0,0};
1041
0
  uint32_t halfsize =size>>1;
1042
0
  uint32_t off[4]={0,halfsize,size*halfsize,size*halfsize+halfsize};
1043
1044
0
  for( int n = 0; n < 4; n++ )
1045
0
  {
1046
0
    g_pelBufOP.sumAndSumSquares( Org.buf + off[n], stride, halfsize, halfsize, sum[n], sum_sqr[n] );
1047
0
  }
1048
0
  int num=size*(size>>1);
1049
  // varhu
1050
0
  mean=(double)(sum[0]+sum[1])/(num);
1051
0
  variance =  (double)(sum_sqr[0]+sum_sqr[1])/(num) - (mean*mean);
1052
0
  varh =(int)(variance+0.5);
1053
  // varhl
1054
0
  mean=(double)(sum[2]+sum[3])/(num);
1055
0
  variance =  (double)(sum_sqr[2]+sum_sqr[3])/(num) - (mean*mean);
1056
0
  varh +=(int)(variance+0.5);
1057
  // varvl
1058
0
  mean=(double)(sum[0]+sum[2])/(num);
1059
0
  variance =  (double)(sum_sqr[0]+sum_sqr[2])/(num) - (mean*mean);
1060
0
  varv =(int)(variance+0.5);
1061
  // varvr
1062
0
  mean=(double)(sum[1]+sum[3])/(num);
1063
0
  variance =  (double)(sum_sqr[1]+sum_sqr[3])/(num) - (mean*mean);
1064
0
  varv +=(int)(variance+0.5);
1065
0
}
1066
1067
template<>
1068
void AreaBuf<Pel>::copyClip( const AreaBuf<const Pel>& src, const ClpRng& clpRng )
1069
0
{
1070
0
  const Pel* srcp = src.buf;
1071
0
        Pel* dest =     buf;
1072
1073
0
  const unsigned srcStride  = src.stride;
1074
0
  const unsigned destStride = stride;
1075
1076
0
  if( destStride == width)
1077
0
  {
1078
0
    g_pelBufOP.copyClip(srcp, dest, width * height, clpRng);
1079
0
  }
1080
0
  else if ((width & 7) == 0)
1081
0
  {
1082
0
    g_pelBufOP.copyClip8(srcp, srcStride, dest, destStride, width, height, clpRng);
1083
0
  }
1084
0
  else if ((width & 3) == 0)
1085
0
  {
1086
0
    g_pelBufOP.copyClip4(srcp, srcStride, dest, destStride, width, height, clpRng);
1087
0
  }
1088
0
  else if( height >= 8 )
1089
0
  {
1090
0
    CHECKD( width != 2, "Expecting width to be '2'!" );
1091
0
    g_pelBufOP.copyClip2( srcp, srcStride, dest, destStride, width, height, clpRng );
1092
0
  }
1093
0
  else
1094
0
  {
1095
    // for fewer rows this loop is faster than the call of copyClip2
1096
0
    CHECKD( width != 2, "Expecting width to be '2'!" );
1097
0
    for( int y = 0; y < height; y++ )
1098
0
    {
1099
0
      dest[0] = ClipPel( srcp[0], clpRng );
1100
0
      dest[1] = ClipPel( srcp[1], clpRng );
1101
0
      srcp += srcStride;
1102
0
      dest += destStride;
1103
0
    }
1104
0
  }
1105
0
}
1106
1107
template<>
1108
void AreaBuf<Pel>::reconstruct( const AreaBuf<const Pel>& pred, const AreaBuf<const Pel>& resi, const ClpRng& clpRng )
1109
2.65M
{
1110
2.65M
  const Pel* src1 = pred.buf;
1111
2.65M
  const Pel* src2 = resi.buf;
1112
2.65M
        Pel* dest =      buf;
1113
1114
2.65M
  const unsigned src1Stride = pred.stride;
1115
2.65M
  const unsigned src2Stride = resi.stride;
1116
2.65M
  const unsigned destStride =      stride;
1117
2.65M
  if( src2Stride == width )
1118
2.64M
  {
1119
2.64M
    g_pelBufOP.reco( pred.buf, resi.buf, buf, width * height, clpRng );
1120
2.64M
  }
1121
10.7k
  else if( ( width & 7 ) == 0 )
1122
6.86k
  {
1123
6.86k
    g_pelBufOP.reco8( src1, src1Stride, src2, src2Stride, dest, destStride, width, height, clpRng );
1124
6.86k
  }
1125
3.83k
  else if( ( width & 3 ) == 0 )
1126
3.83k
  {
1127
3.83k
    g_pelBufOP.reco4( src1, src1Stride, src2, src2Stride, dest, destStride, width, height, clpRng );
1128
3.83k
  }
1129
18.4E
  else if( width == 2 && height >= 8 )
1130
0
  {
1131
0
    g_pelBufOP.reco2( src1, src1Stride, src2, src2Stride, dest, destStride, width, height, clpRng );
1132
0
  }
1133
18.4E
  else if( ( width & 1 ) == 0 )
1134
0
  {
1135
    // for fewer rows this loop is faster than the call of reco2
1136
0
    for( int y = 0; y < height; y++ )
1137
0
    {
1138
0
      dest[0] = ClipPel( src1[0] + src2[0], clpRng );
1139
0
      dest[1] = ClipPel( src1[1] + src2[1], clpRng );
1140
0
      src1 += src1Stride;
1141
0
      src2 += src2Stride;
1142
0
      dest += destStride;
1143
0
    }
1144
0
  }
1145
18.4E
  else
1146
18.4E
  {
1147
18.4E
    CHECKD( width != 1, "Expecting width to be '1'!" );
1148
1149
18.4E
    for( int y = 0; y < height; y++ )
1150
0
    {
1151
0
      dest[0] = ClipPel( src1[0] + src2[0], clpRng );
1152
1153
0
      src1 += src1Stride;
1154
0
      src2 += src2Stride;
1155
0
      dest += destStride;
1156
0
    }
1157
18.4E
  }
1158
2.65M
}
1159
1160
template<>
1161
void AreaBuf<Pel>::linearTransform( const int scale, const unsigned shift, const int offset, bool bClip, const ClpRng& clpRng )
1162
242k
{
1163
242k
  const Pel* src = buf;
1164
242k
        Pel* dst = buf;
1165
1166
242k
  if( stride == width)
1167
242k
  {
1168
242k
    if( width > 2 && height > 2 )
1169
229k
    {
1170
229k
      g_pelBufOP.linTf8( src, stride<<2, dst, stride<<2, width<<2, height>>2, scale, shift, offset, clpRng, bClip );
1171
229k
    }
1172
13.7k
    else
1173
13.7k
    {
1174
13.7k
      g_pelBufOP.linTf4( src, stride<<1, dst, stride<<1, width<<1, height>>1, scale, shift, offset, clpRng, bClip );
1175
13.7k
    }
1176
242k
  }
1177
0
  else if( ( width & 7 ) == 0 )
1178
0
  {
1179
0
    g_pelBufOP.linTf8( src, stride, dst, stride, width, height, scale, shift, offset, clpRng, bClip );
1180
0
  }
1181
0
  else if( ( width & 3 ) == 0 )
1182
0
  {
1183
0
    g_pelBufOP.linTf4( src, stride, dst, stride, width, height, scale, shift, offset, clpRng, bClip );
1184
0
  }
1185
0
  else
1186
0
  {
1187
0
    if( bClip )
1188
0
    {
1189
0
      for( int y = 0; y < height; y++ )
1190
0
      {
1191
0
        dst[0] = ( Pel ) ClipPel( rightShiftU( scale * src[0], shift ) + offset, clpRng );
1192
0
        dst[1] = ( Pel ) ClipPel( rightShiftU( scale * src[1], shift ) + offset, clpRng );
1193
0
        src += stride;
1194
0
        dst += stride;
1195
0
      }
1196
0
    }
1197
0
    else
1198
0
    {
1199
0
      for( int y = 0; y < height; y++ )
1200
0
      {
1201
0
        dst[0] = ( Pel ) ( rightShiftU( scale * src[0], shift ) + offset );
1202
0
        dst[1] = ( Pel ) ( rightShiftU( scale * src[1], shift ) + offset );
1203
0
        src += stride;
1204
0
        dst += stride;
1205
0
      }
1206
0
    }
1207
0
  }
1208
242k
}
1209
1210
#if ENABLE_SIMD_OPT_BUFFER
1211
1212
template<>
1213
void AreaBuf<Pel>::transposedFrom( const AreaBuf<const Pel>& other )
1214
549k
{
1215
549k
  CHECK( width != other.height || height != other.width, "Incompatible size" );
1216
1217
549k
  if( ( ( width | height ) & 7 ) == 0 )
1218
476k
  {
1219
476k
    const Pel* src = other.buf;
1220
1221
2.06M
    for( unsigned y = 0; y < other.height; y += 8 )
1222
1.58M
    {
1223
1.58M
      Pel* dst = buf + y;
1224
1225
9.32M
      for( unsigned x = 0; x < other.width; x += 8 )
1226
7.73M
      {
1227
7.73M
        g_pelBufOP.transpose8x8( &src[x], other.stride, dst, stride );
1228
1229
7.73M
        dst += 8 * stride;
1230
7.73M
      }
1231
1232
1.58M
      src += 8 * other.stride;
1233
1.58M
    }
1234
476k
  }
1235
72.3k
  else if( ( ( width | height ) & 3 ) == 0 )
1236
66.7k
  {
1237
66.7k
    const Pel* src = other.buf;
1238
1239
197k
    for( unsigned y = 0; y < other.height; y += 4 )
1240
131k
    {
1241
131k
      Pel* dst = buf + y;
1242
1243
382k
      for( unsigned x = 0; x < other.width; x += 4 )
1244
251k
      {
1245
251k
        g_pelBufOP.transpose4x4( &src[x], other.stride, dst, stride );
1246
1247
251k
        dst += 4 * stride;
1248
251k
      }
1249
1250
131k
      src += 4 * other.stride;
1251
131k
    }
1252
66.7k
  }
1253
5.63k
  else
1254
5.63k
  {
1255
5.63k
          Pel* dst =       buf;
1256
5.63k
    const Pel* src = other.buf;
1257
5.63k
    width          = other.height;
1258
5.63k
    height         = other.width;
1259
5.63k
    stride         = stride < width ? width : stride;
1260
1261
69.7k
    for( unsigned y = 0; y < other.height; y++ )
1262
64.0k
    {
1263
192k
      for( unsigned x = 0; x < other.width; x++ )
1264
128k
      {
1265
128k
        dst[y + x*stride] = src[x + y * other.stride];
1266
128k
      }
1267
64.0k
    }
1268
5.63k
  }
1269
549k
}
1270
#endif
1271
1272
template<>
1273
void AreaBuf<Pel>::weightCiip( const AreaBuf<const Pel>& intra, const int numIntra )
1274
0
{
1275
0
  CHECK(width == 2, "Width of 2 is not supported");
1276
0
  g_pelBufOP.weightCiip( buf, intra.buf, width * height, numIntra );
1277
0
}
1278
1279
template<>
1280
void AreaBuf<MotionInfo>::fill( const MotionInfo& val )
1281
26.8k
{
1282
  // Field by field, with the values read once: assigning the whole struct (std::fill_n) makes GCC build the two refIdx
1283
  // bytes on the stack for every element and read them back as 16 bits, a failed store forward per element.
1284
26.8k
  const Mv     mv0  = val.mv[0];
1285
26.8k
  const Mv     mv1  = val.mv[1];
1286
26.8k
  const int8_t ref0 = val.miRefIdx[0];
1287
26.8k
  const int8_t ref1 = val.miRefIdx[1];
1288
1289
26.8k
  MotionInfo* dst = buf;
1290
1291
229k
  for( int y = 0; y < height; y++, dst += stride )
1292
202k
  {
1293
2.09M
    for( int x = 0; x < width; x++ )
1294
1.89M
    {
1295
1.89M
      dst[x].mv[0]       = mv0;
1296
1.89M
      dst[x].mv[1]       = mv1;
1297
1.89M
      dst[x].miRefIdx[0] = ref0;
1298
1.89M
      dst[x].miRefIdx[1] = ref1;
1299
1.89M
    }
1300
202k
  }
1301
26.8k
}
1302
1303
PelStorage::PelStorage()
1304
1.02M
{
1305
4.11M
  for( uint32_t i = 0; i < MAX_NUM_COMP; i++ )
1306
3.08M
  {
1307
3.08M
    m_origin[i] = nullptr;
1308
3.08M
  }
1309
1.02M
}
1310
1311
PelStorage::~PelStorage()
1312
1.02M
{
1313
1.02M
  destroy();
1314
1.02M
}
1315
1316
void PelStorage::create( const UnitArea& _UnitArea )
1317
538k
{
1318
538k
  create( _UnitArea.chromaFormat, _UnitArea.blocks[0] );
1319
538k
  m_maxArea = _UnitArea;
1320
538k
}
1321
1322
void PelStorage::create( const ChromaFormat &_chromaFormat, const Area& _area )
1323
847k
{
1324
847k
  CHECK( !bufs.empty(), "Trying to re-create an already initialized buffer" );
1325
1326
847k
  chromaFormat = _chromaFormat;
1327
1328
847k
  const uint32_t numComp = getNumberValidComponents( _chromaFormat );
1329
1330
847k
  uint32_t bufSize = 0;
1331
3.37M
  for( uint32_t i = 0; i < numComp; i++ )
1332
2.53M
  {
1333
2.53M
    const ComponentID compID = ComponentID( i );
1334
2.53M
    const unsigned totalWidth  = _area.width  >> getComponentScaleX( compID, _chromaFormat );
1335
2.53M
    const unsigned totalHeight = _area.height >> getComponentScaleY( compID, _chromaFormat );
1336
1337
2.53M
    const uint32_t area = totalWidth * totalHeight;
1338
2.53M
    CHECK( !area, "Trying to create a buffer with zero area" );
1339
2.53M
    bufSize += area;
1340
2.53M
  }
1341
1342
847k
  bufSize += 1; // for SIMD DMVR on the bottom right corner, which overreads the lines by 1 sample
1343
1344
  //allocate one buffer
1345
847k
  m_origin[0] = ( Pel* ) xMalloc( Pel, bufSize );
1346
1347
847k
  Pel* topLeft = m_origin[0];
1348
3.37M
  for( uint32_t i = 0; i < numComp; i++ )
1349
2.53M
  {
1350
2.53M
    const ComponentID compID = ComponentID( i );
1351
2.53M
    const unsigned totalWidth  = _area.width  >> getComponentScaleX( compID, _chromaFormat );
1352
2.53M
    const unsigned totalHeight = _area.height >> getComponentScaleY( compID, _chromaFormat );
1353
2.53M
    const uint32_t area = totalWidth * totalHeight;
1354
1355
2.53M
    bufs.push_back( PelBuf( topLeft, totalWidth, totalWidth, totalHeight ) );
1356
2.53M
    topLeft += area;
1357
2.53M
  }
1358
1359
847k
  m_maxArea = UnitArea( _chromaFormat, _area );
1360
847k
}
1361
1362
void PelStorage::create( const ChromaFormat &_chromaFormat, const Area& _area, const unsigned _maxCUSize, const unsigned _margin, const unsigned _alignment, const bool _scaleChromaMargin )
1363
71.6k
{
1364
71.6k
  CHECK( !bufs.empty(), "Trying to re-create an already initialized buffer" );
1365
1366
71.6k
  chromaFormat = _chromaFormat;
1367
1368
71.6k
  const uint32_t numComp = getNumberValidComponents( _chromaFormat );
1369
1370
71.6k
  unsigned extHeight = _area.height;
1371
71.6k
  unsigned extWidth  = _area.width;
1372
1373
71.6k
  if( _maxCUSize )
1374
18.6k
  {
1375
18.6k
    extHeight = ( ( _area.height + _maxCUSize - 1 ) / _maxCUSize ) * _maxCUSize;
1376
18.6k
    extWidth  = ( ( _area.width  + _maxCUSize - 1 ) / _maxCUSize ) * _maxCUSize;
1377
18.6k
  }
1378
1379
263k
  for( uint32_t i = 0; i < numComp; i++ )
1380
191k
  {
1381
191k
    const ComponentID compID = ComponentID( i );
1382
191k
    const unsigned scaleX = getComponentScaleX( compID, _chromaFormat );
1383
191k
    const unsigned scaleY = getComponentScaleY( compID, _chromaFormat );
1384
1385
191k
    unsigned scaledHeight = extHeight >> scaleY;
1386
191k
    unsigned scaledWidth  = extWidth  >> scaleX;
1387
191k
    unsigned ymargin      = _margin >> (_scaleChromaMargin?scaleY:0);
1388
191k
    unsigned xmargin      = _margin >> (_scaleChromaMargin?scaleX:0);
1389
191k
    unsigned totalWidth   = scaledWidth + 2*xmargin;
1390
191k
    unsigned totalHeight  = scaledHeight +2*ymargin;
1391
1392
191k
    if( _alignment )
1393
73.0k
    {
1394
      // make sure buffer lines are align
1395
73.0k
      CHECK( _alignment != MEMORY_ALIGN_DEF_SIZE, "Unsupported alignment" );
1396
73.0k
      totalWidth = ( ( totalWidth + _alignment - 1 ) / _alignment ) * _alignment;
1397
73.0k
    }
1398
191k
    uint32_t area = totalWidth * totalHeight;
1399
191k
    CHECK( !area, "Trying to create a buffer with zero area" );
1400
1401
191k
    m_origin[i] = ( Pel* ) xMalloc( Pel, area );
1402
191k
    Pel* topLeft = m_origin[i] + totalWidth * ymargin + xmargin;
1403
191k
    bufs.push_back( PelBuf( topLeft, totalWidth, _area.width >> scaleX, _area.height >> scaleY ) );
1404
191k
  }
1405
1406
71.6k
  m_maxArea = UnitArea( _chromaFormat, _area );
1407
71.6k
}
1408
1409
void PelStorage::createFromBuf( PelUnitBuf buf )
1410
1.43k
{
1411
1.43k
  chromaFormat = buf.chromaFormat;
1412
1413
1.43k
  const uint32_t numCh = getNumberValidComponents( chromaFormat );
1414
1415
1.43k
  bufs.resize(numCh);
1416
1417
5.72k
  for( uint32_t i = 0; i < numCh; i++ )
1418
4.29k
  {
1419
4.29k
    PelBuf cPelBuf = buf.get( ComponentID( i ) );
1420
4.29k
    bufs[i] = PelBuf( cPelBuf.bufAt( 0, 0 ), cPelBuf.stride, cPelBuf.width, cPelBuf.height );
1421
4.29k
  }
1422
1.43k
}
1423
1424
void PelStorage::compactResize( const UnitArea& area )
1425
1.84M
{
1426
1.84M
  CHECK( bufs.size() < area.blocks.size(), "Cannot increase buffer size when compacting!" );
1427
1428
7.37M
  for( uint32_t i = 0; i < area.blocks.size(); i++ )
1429
5.53M
  {
1430
5.53M
    CHECK( m_maxArea.blocks[i].area() < area.blocks[i].area(), "Cannot increase buffer size when compacting!" );
1431
1432
5.53M
    bufs[i].Size::operator=( area.blocks[i].size() );
1433
5.53M
    bufs[i].stride = bufs[i].width;
1434
5.53M
  }
1435
1.84M
}
1436
1437
void PelStorage::takeOwnership( PelStorage& other )
1438
0
{
1439
0
  chromaFormat = other.chromaFormat;
1440
1441
0
  const uint32_t numCh = getNumberValidComponents( chromaFormat );
1442
1443
0
  bufs.resize(numCh);
1444
1445
0
  for( uint32_t i = 0; i < numCh; i++ )
1446
0
  {
1447
0
    PelBuf cPelBuf = other.get( ComponentID( i ) );
1448
0
    bufs[i] = PelBuf( cPelBuf.bufAt( 0, 0 ), cPelBuf.stride, cPelBuf.width, cPelBuf.height );
1449
0
    std::swap( m_origin[i], other.m_origin[i]);
1450
0
  }
1451
1452
0
  m_maxArea = other.m_maxArea;
1453
1454
0
  other.destroy();
1455
0
}
1456
1457
1458
void PelStorage::swap( PelStorage& other )
1459
0
{
1460
0
  const uint32_t numCh = getNumberValidComponents( chromaFormat );
1461
1462
0
  for( uint32_t i = 0; i < numCh; i++ )
1463
0
  {
1464
    // check this otherwise it would turn out to get very weird
1465
0
    CHECK( chromaFormat                   != other.chromaFormat                  , "Incompatible formats" );
1466
0
    CHECK( get( ComponentID( i ) )        != other.get( ComponentID( i ) )       , "Incompatible formats" );
1467
0
    CHECK( get( ComponentID( i ) ).stride != other.get( ComponentID( i ) ).stride, "Incompatible formats" );
1468
1469
0
    std::swap( bufs[i].buf,    other.bufs[i].buf );
1470
0
    std::swap( bufs[i].stride, other.bufs[i].stride );
1471
0
    std::swap( m_origin[i],    other.m_origin[i] );
1472
0
  }
1473
0
}
1474
1475
void PelStorage::destroy()
1476
1.96M
{
1477
1.96M
  chromaFormat = NUM_CHROMA_FORMAT;
1478
7.84M
  for( uint32_t i = 0; i < MAX_NUM_COMP; i++ )
1479
5.88M
  {
1480
5.88M
    if( m_origin[i] )
1481
1.03M
    {
1482
1.03M
      xFree( m_origin[i] );
1483
1.03M
      m_origin[i] = nullptr;
1484
1.03M
    }
1485
5.88M
  }
1486
1.96M
  bufs.clear();
1487
1.96M
}
1488
1489
PelBuf PelStorage::getBuf( const ComponentID CompID )
1490
14.6k
{
1491
14.6k
  return bufs[CompID];
1492
14.6k
}
1493
1494
const CPelBuf PelStorage::getBuf( const ComponentID CompID ) const
1495
0
{
1496
0
  return bufs[CompID];
1497
0
}
1498
1499
PelBuf PelStorage::getBuf( const CompArea& blk )
1500
23.7M
{
1501
23.7M
  const PelBuf& r = bufs[blk.compID];
1502
23.7M
  return PelBuf( r.buf + rsAddr( blk, r.stride ), r.stride, blk );
1503
23.7M
}
1504
1505
const CPelBuf PelStorage::getBuf( const CompArea& blk ) const
1506
486k
{
1507
486k
  const PelBuf& r = bufs[blk.compID];
1508
486k
  return CPelBuf( r.buf + rsAddr( blk, r.stride ), r.stride, blk );
1509
486k
}
1510
1511
PelUnitBuf PelStorage::getBuf( const UnitArea& unit )
1512
4.65k
{
1513
4.65k
  return ( chromaFormat == CHROMA_400 ) ? PelUnitBuf( chromaFormat, getBuf( unit.Y() ) ) : PelUnitBuf( chromaFormat, getBuf( unit.Y() ), getBuf( unit.Cb() ), getBuf( unit.Cr() ) );
1514
4.65k
}
1515
1516
const CPelUnitBuf PelStorage::getBuf( const UnitArea& unit ) const
1517
0
{
1518
0
  return ( chromaFormat == CHROMA_400 ) ? CPelUnitBuf( chromaFormat, getBuf( unit.Y() ) ) : CPelUnitBuf( chromaFormat, getBuf( unit.Y() ), getBuf( unit.Cb() ), getBuf( unit.Cr() ) );
1519
0
}
1520
1521
PelUnitBuf PelStorage::getBuf(const int strY, const int strCb, const int strCr, const UnitArea& unit)
1522
0
{
1523
0
  CHECKD( unit.Y().width > bufs[COMP_Y].width && unit.Y().height > bufs[COMP_Y].height, "unsuported request" );
1524
0
  CHECKD( strY > bufs[COMP_Y].stride, "unsuported request" );
1525
0
  CHECKD( strCb > bufs[COMP_Cb].stride, "unsuported request" );
1526
0
  CHECKD( strCr > bufs[COMP_Cr].stride, "unsuported request" );
1527
0
  return (chromaFormat == CHROMA_400) ? PelUnitBuf(chromaFormat, PelBuf( bufs[COMP_Y].buf, strY, unit.Y())) : PelUnitBuf(chromaFormat, PelBuf( bufs[COMP_Y].buf, strY, unit.Y()), PelBuf( bufs[COMP_Cb].buf, strCb, unit.Cb()), PelBuf( bufs[COMP_Cr].buf, strCr, unit.Cr()));
1528
0
}
1529
1530
const CPelUnitBuf PelStorage::getBuf(const int strY, const int strCb, const int strCr, const UnitArea& unit) const
1531
0
{
1532
0
  CHECKD( unit.Y().width > bufs[COMP_Y].width && unit.Y().height > bufs[COMP_Y].height, "unsuported request" );
1533
0
  CHECKD( strY > bufs[COMP_Y].stride, "unsuported request" );
1534
0
  CHECKD( strCb > bufs[COMP_Cb].stride, "unsuported request" );
1535
0
  CHECKD( strCr > bufs[COMP_Cr].stride, "unsuported request" );
1536
0
  return (chromaFormat == CHROMA_400) ? CPelUnitBuf(chromaFormat, CPelBuf( bufs[COMP_Y].buf, strY, unit.Y())) : CPelUnitBuf(chromaFormat, CPelBuf( bufs[COMP_Y].buf, strY, unit.Y()), CPelBuf( bufs[COMP_Cb].buf, strCb, unit.Cb()), CPelBuf( bufs[COMP_Cr].buf, strCr, unit.Cr()));
1537
0
}
1538
1539
PelUnitBuf PelStorage::getBufPart(const UnitArea& unit)
1540
0
{
1541
0
  CHECKD( unit.Y().width > bufs[COMP_Y].width && unit.Y().height > bufs[COMP_Y].height, "unsuported request" );
1542
0
  return (chromaFormat == CHROMA_400) ? PelUnitBuf(chromaFormat, PelBuf( bufs[COMP_Y].buf, bufs[COMP_Y].stride, unit.Y())) : PelUnitBuf(chromaFormat, PelBuf( bufs[COMP_Y].buf, bufs[COMP_Y].stride, unit.Y()), PelBuf( bufs[COMP_Cb].buf, bufs[COMP_Cb].stride, unit.Cb()), PelBuf( bufs[COMP_Cr].buf, bufs[COMP_Cr].stride, unit.Cr()));
1543
0
}
1544
1545
const CPelUnitBuf PelStorage::getBufPart(const UnitArea& unit) const
1546
0
{
1547
0
  CHECKD(unit.Y().width > bufs[COMP_Y].width && unit.Y().height > bufs[COMP_Y].height, "unsuported request");
1548
0
  return (chromaFormat == CHROMA_400) ? CPelUnitBuf(chromaFormat, CPelBuf(bufs[COMP_Y].buf, unit.Y().width, unit.Y())) : CPelUnitBuf(chromaFormat, CPelBuf(bufs[COMP_Y].buf, unit.Y().width, unit.Y()), CPelBuf(bufs[COMP_Cb].buf, unit.Cb().width, unit.Cb()), CPelBuf(bufs[COMP_Cr].buf, unit.Cr().width, unit.Cr()));
1549
0
}
1550
1551
const CPelUnitBuf PelStorage::getCompactBuf(const UnitArea& unit) const
1552
0
{
1553
0
  CHECKD( unit.Y().width > bufs[COMP_Y].width && unit.Y().height > bufs[COMP_Y].height, "unsuported request" );
1554
1555
0
  PelUnitBuf ret;
1556
0
  ret.chromaFormat = chromaFormat;
1557
0
  ret.bufs.resize_noinit( chromaFormat == CHROMA_400 ? 1 : 3 );
1558
  
1559
0
  ret.Y   ().buf = bufs[COMP_Y ].buf; ret.Y ().width = ret.Y ().stride = unit.Y ().width; ret.Y ().height = unit.Y ().height;
1560
0
  if( chromaFormat != CHROMA_400 )
1561
0
  {
1562
0
    ret.Cb().buf = bufs[COMP_Cb].buf; ret.Cb().width = ret.Cb().stride = unit.Cb().width; ret.Cb().height = unit.Cb().height;
1563
0
    ret.Cr().buf = bufs[COMP_Cr].buf; ret.Cr().width = ret.Cr().stride = unit.Cr().width; ret.Cr().height = unit.Cr().height;
1564
0
  }
1565
1566
0
  return ret;
1567
0
}
1568
1569
PelUnitBuf PelStorage::getCompactBuf(const UnitArea& unit)
1570
169k
{
1571
169k
  CHECKD( unit.Y().width > bufs[COMP_Y].width && unit.Y().height > bufs[COMP_Y].height, "unsuported request" );
1572
1573
169k
  PelUnitBuf ret;
1574
169k
  ret.chromaFormat = chromaFormat;
1575
169k
  ret.bufs.resize_noinit( chromaFormat == CHROMA_400 ? 1 : 3 );
1576
1577
169k
  ret.Y   ().buf = bufs[COMP_Y ].buf; ret.Y ().width = ret.Y ().stride = unit.Y ().width; ret.Y ().height = unit.Y ().height;
1578
169k
  if( chromaFormat != CHROMA_400 )
1579
169k
  {
1580
169k
    ret.Cb().buf = bufs[COMP_Cb].buf; ret.Cb().width = ret.Cb().stride = unit.Cb().width; ret.Cb().height = unit.Cb().height;
1581
169k
    ret.Cr().buf = bufs[COMP_Cr].buf; ret.Cr().width = ret.Cr().stride = unit.Cr().width; ret.Cr().height = unit.Cr().height;
1582
169k
  }
1583
1584
169k
  return ret;
1585
169k
}
1586
1587
const CPelBuf PelStorage::getCompactBuf(const CompArea& carea) const
1588
0
{
1589
0
  return CPelBuf( bufs[carea.compID].buf, carea.width, carea);
1590
0
}
1591
1592
PelBuf PelStorage::getCompactBuf(const CompArea& carea)
1593
0
{
1594
0
  return PelBuf( bufs[carea.compID].buf, carea.width, carea);
1595
0
}
1596
1597
void downsampleYuv(PelBuf& dest, const vvencYUVPlane& yuvPlaneIn, int downsampleStep)
1598
0
{
1599
0
  const int widthd = dest.width;
1600
0
  const int heightd = dest.height;
1601
0
  int difStride = dest.stride - dest.width;
1602
1603
0
  const int16_t* src = yuvPlaneIn.ptr;
1604
0
  const int instride = yuvPlaneIn.stride;
1605
0
  int n = 0;
1606
0
  for (int j = 0; j < heightd; j++)
1607
0
  {
1608
0
    int i = 0;
1609
0
    for (i = 0; i < widthd; i++)
1610
0
    {
1611
0
      long int b = 0;
1612
0
      for (int r = 0; r < downsampleStep; r++)
1613
0
      {
1614
0
        int posr = instride * r;
1615
0
        for (int n = 0; n < downsampleStep; n++)
1616
0
        {
1617
0
          b += src[posr + n];
1618
0
        }
1619
0
      }
1620
0
      src += downsampleStep;
1621
0
      dest.buf[n] = (int16_t)((b + 2) / (downsampleStep << 1));
1622
0
      n++;
1623
0
    }
1624
0
    n += difStride;
1625
0
    src = src - downsampleStep * i + instride * downsampleStep;
1626
0
  }
1627
0
}
1628
1629
void copyPadToPelUnitBuf( PelUnitBuf pelUnitBuf, const vvencYUVBuffer& yuvBuffer, const ChromaFormat& chFmt )
1630
1.43k
{
1631
1.43k
  CHECK( pelUnitBuf.bufs.size() == 0, "pelUnitBuf not initialized" );
1632
1.43k
  pelUnitBuf.chromaFormat = chFmt;
1633
1.43k
  const int numComp = getNumberValidComponents( chFmt );
1634
5.72k
  for ( int i = 0; i < numComp; i++ )
1635
4.29k
  {
1636
4.29k
    const vvencYUVPlane& src = yuvBuffer.planes[ i ];
1637
4.29k
    CHECK( src.ptr == nullptr, "yuvBuffer not setup" );
1638
4.29k
    PelBuf& dest = pelUnitBuf.bufs[i];
1639
4.29k
    CHECK( dest.buf == nullptr, "yuvBuffer not setup" );
1640
1641
4.29k
    if (dest.width < src.width)
1642
0
    {
1643
0
      downsampleYuv(dest, src, 2);
1644
0
    }
1645
4.29k
    else
1646
4.29k
    {
1647
448k
      for (int y = 0; y < src.height; y++)
1648
444k
      {
1649
444k
        ::memcpy(dest.buf + y * dest.stride, src.ptr + y * src.stride, src.width * sizeof(int16_t));
1650
1651
        // pad right if required
1652
444k
        for (int x = src.width; x < dest.width; x++)
1653
0
        {
1654
0
          dest.buf[x + y * dest.stride] = dest.buf[src.width - 1 + y * dest.stride];
1655
0
        }
1656
444k
      }
1657
1658
      // pad bottom if required
1659
4.29k
      for (int y = src.height; y < dest.height; y++)
1660
0
      {
1661
0
        ::memcpy(dest.buf + y * dest.stride, dest.buf + (src.height - 1) * dest.stride, dest.width * sizeof(int16_t));
1662
0
      }
1663
4.29k
    }
1664
4.29k
  }
1665
1.43k
}
1666
1667
/*
1668
void setupPelUnitBuf( const YUVBuffer& yuvBuffer, PelUnitBuf& pelUnitBuf, const ChromaFormat& chFmt )
1669
{
1670
  CHECK( pelUnitBuf.bufs.size() != 0, "pelUnitBuf already in use" );
1671
  pelUnitBuf.chromaFormat = chFmt;
1672
  const int numComp = getNumberValidComponents( chFmt );
1673
  for ( int i = 0; i < numComp; i++ )
1674
  {
1675
    const YUVBuffer::Plane& yuvPlane = yuvBuffer.planes[ i ];
1676
    CHECK( yuvPlane.ptr == nullptr, "yuvBuffer not setup" );
1677
    PelBuf area( yuvPlane.ptr, yuvPlane.stride, yuvPlane.width, yuvPlane.height );
1678
    pelUnitBuf.bufs.push_back( area );
1679
  }
1680
}
1681
*/
1682
void setupYuvBuffer ( const PelUnitBuf& pelUnitBuf, vvencYUVBuffer& yuvBuffer, const Window* confWindow )
1683
0
{
1684
0
  const ChromaFormat chFmt = pelUnitBuf.chromaFormat;
1685
0
  const int numComp        = getNumberValidComponents( chFmt );
1686
0
  for ( int i = 0; i < numComp; i++ )
1687
0
  {
1688
0
    const ComponentID compId = ComponentID( i );
1689
0
          PelBuf area        = pelUnitBuf.get( compId );
1690
0
    const int sx             = getComponentScaleX( compId, chFmt );
1691
0
    const int sy             = getComponentScaleY( compId, chFmt );
1692
0
    vvencYUVPlane& yuvPlane = yuvBuffer.planes[ i ];
1693
0
    CHECK( yuvPlane.ptr != nullptr, "yuvBuffer already in use" );
1694
0
    yuvPlane.ptr             = area.bufAt( confWindow->winLeftOffset >> sx, confWindow->winTopOffset >> sy );
1695
0
    yuvPlane.width           = ( ( area.width  << sx ) - ( confWindow->winLeftOffset + confWindow->winRightOffset  ) ) >> sx;
1696
0
    yuvPlane.height          = ( ( area.height << sy ) - ( confWindow->winTopOffset  + confWindow->winBottomOffset ) ) >> sy;
1697
0
    yuvPlane.stride          = area.stride;
1698
0
  }
1699
0
}
1700
1701
} // namespace vvenc
1702
1703
//! \}
1704