Coverage Report

Created: 2026-09-14 07:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libde265/libde265/fallback-motion.cc
Line
Count
Source
1
/*
2
 * H.265 video codec.
3
 * Copyright (c) 2013-2014 struktur AG, Dirk Farin <farin@struktur.de>
4
 *
5
 * This file is part of libde265.
6
 *
7
 * libde265 is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Lesser General Public License as
9
 * published by the Free Software Foundation, either version 3 of
10
 * the License, or (at your option) any later version.
11
 *
12
 * libde265 is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public License
18
 * along with libde265.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "fallback-motion.h"
22
#include "util.h"
23
24
#if defined(_MSC_VER) || defined(__MINGW32__)
25
# include <malloc.h>
26
#elif defined(HAVE_ALLOCA_H)
27
# include <alloca.h>
28
#endif
29
30
#include <assert.h>
31
#include <algorithm>
32
33
34
void put_unweighted_pred_8_fallback(uint8_t *dst, ptrdiff_t dststride,
35
                                    const int16_t *src, ptrdiff_t srcstride,
36
                                    int width, int height)
37
386k
{
38
386k
  int offset8bit = 32;
39
386k
  int shift8bit = 6;
40
41
386k
  assert((width&1)==0);
42
43
3.48M
  for (int y=0;y<height;y++) {
44
3.09M
    const int16_t* in  = &src[y*srcstride];
45
3.09M
    uint8_t* out = &dst[y*dststride];
46
47
19.0M
    for (int x=0;x<width;x+=2) {
48
15.9M
      out[0] = Clip1_8bit((in[0] + offset8bit)>>shift8bit);
49
15.9M
      out[1] = Clip1_8bit((in[1] + offset8bit)>>shift8bit);
50
15.9M
      out+=2; in+=2;
51
15.9M
    }
52
3.09M
  }
53
386k
}
54
55
56
void put_weighted_pred_8_fallback(uint8_t *dst, ptrdiff_t dststride,
57
                                  const int16_t *src, ptrdiff_t srcstride,
58
                                  int width, int height,
59
                                  int w,int o,int log2WD)
60
46.7k
{
61
46.7k
  assert(log2WD>=1); // TODO
62
63
46.7k
  const int rnd = (1<<(log2WD-1));
64
65
432k
  for (int y=0;y<height;y++) {
66
386k
    const int16_t* in  = &src[y*srcstride];
67
386k
    uint8_t* out = &dst[y*dststride];
68
69
3.87M
    for (int x=0;x<width;x++) {
70
3.48M
      out[0] = Clip1_8bit(((in[0]*w + rnd)>>log2WD) + o);
71
3.48M
      out++; in++;
72
3.48M
    }
73
386k
  }
74
46.7k
}
75
76
void put_weighted_bipred_8_fallback(uint8_t *dst, ptrdiff_t dststride,
77
                                    const int16_t *src1, const int16_t *src2, ptrdiff_t srcstride,
78
                                    int width, int height,
79
                                    int w1,int o1, int w2,int o2, int log2WD)
80
9.53k
{
81
9.53k
  assert(log2WD>=1); // TODO
82
83
9.53k
  const int rnd = static_cast<int>(static_cast<unsigned int>(o1+o2+1) << log2WD);
84
85
108k
  for (int y=0;y<height;y++) {
86
98.4k
    const int16_t* in1 = &src1[y*srcstride];
87
98.4k
    const int16_t* in2 = &src2[y*srcstride];
88
98.4k
    uint8_t* out = &dst[y*dststride];
89
90
1.52M
    for (int x=0;x<width;x++) {
91
1.42M
      out[0] = Clip1_8bit((in1[0]*w1 + in2[0]*w2 + rnd)>>(log2WD+1));
92
1.42M
      out++; in1++; in2++;
93
1.42M
    }
94
98.4k
  }
95
9.53k
}
96
97
98
void put_weighted_pred_avg_8_fallback(uint8_t *dst, ptrdiff_t dststride,
99
                                      const int16_t *src1, const int16_t *src2,
100
                                      ptrdiff_t srcstride, int width,
101
                                      int height)
102
50.7k
{
103
50.7k
  int offset8bit = 64;
104
50.7k
  int shift8bit = 7;
105
106
50.7k
  assert((width&1)==0);
107
108
  // I had a special case for 8-pixel parallel, unrolled code,
109
  // but I did not see any speedup.
110
111
#if 0
112
  for (int y=0;y<height;y++) {
113
    int16_t* in1 = &src1[y*srcstride];
114
    int16_t* in2 = &src2[y*srcstride];
115
    uint8_t* out = &dst[y*dststride];
116
117
    for (int x=0;x<width;x++) {
118
      out[0] = Clip1_8bit((in1[0] + in2[0] + offset8bit)>>shift8bit);
119
      out++; in1++; in2++;
120
    }
121
  }
122
#endif
123
124
#if 0
125
  if ((width&7)==0) {
126
    for (int y=0;y<height;y++) {
127
      int16_t* in1 = &src1[y*srcstride];
128
      int16_t* in2 = &src2[y*srcstride];
129
      uint8_t* out = &dst[y*dststride];
130
131
      for (int x=0;x<width;x+=8) {
132
        out[0] = Clip1_8bit((in1[0] + in2[0] + offset8bit)>>shift8bit);
133
        out[1] = Clip1_8bit((in1[1] + in2[1] + offset8bit)>>shift8bit);
134
        out[2] = Clip1_8bit((in1[2] + in2[2] + offset8bit)>>shift8bit);
135
        out[3] = Clip1_8bit((in1[3] + in2[3] + offset8bit)>>shift8bit);
136
        out[4] = Clip1_8bit((in1[4] + in2[4] + offset8bit)>>shift8bit);
137
        out[5] = Clip1_8bit((in1[5] + in2[5] + offset8bit)>>shift8bit);
138
        out[6] = Clip1_8bit((in1[6] + in2[6] + offset8bit)>>shift8bit);
139
        out[7] = Clip1_8bit((in1[7] + in2[7] + offset8bit)>>shift8bit);
140
        out+=8; in1+=8; in2+=8;
141
      }
142
    }
143
  }
144
  else
145
#endif
146
50.7k
    {
147
685k
      for (int y=0;y<height;y++) {
148
634k
        const int16_t* in1 = &src1[y*srcstride];
149
634k
        const int16_t* in2 = &src2[y*srcstride];
150
634k
        uint8_t* out = &dst[y*dststride];
151
152
5.65M
        for (int x=0;x<width;x+=2) {
153
5.01M
          out[0] = Clip1_8bit((in1[0] + in2[0] + offset8bit)>>shift8bit);
154
5.01M
          out[1] = Clip1_8bit((in1[1] + in2[1] + offset8bit)>>shift8bit);
155
5.01M
          out+=2; in1+=2; in2+=2;
156
5.01M
        }
157
634k
      }
158
50.7k
    }
159
50.7k
}
160
161
162
163
164
165
// The 16-bit pixel kernels are templates on the type of the intermediate
166
// prediction samples (predSamplesLX in the spec): int16_t for BitDepth <= 12,
167
// int32_t above (see acceleration.h).
168
169
template <class inter_t>
170
void put_unweighted_pred_16_fallback(uint16_t *dst, ptrdiff_t dststride,
171
                                     const inter_t *src, ptrdiff_t srcstride,
172
                                     int width, int height, int bit_depth)
173
248k
{
174
  // shift1 per HEVC v2 (10/2014) spec 8.5.3.3.4.2: Max(2, 14 - BitDepth).
175
  // The Max() was added with the Range Extensions in v2 to handle BitDepth up to 16;
176
  // the v1 (04/2013) formula was just (14 - BitDepth), valid only for BitDepth <= 14.
177
248k
  int shift1 = std::max(2, 14-bit_depth);
178
248k
  int offset1 = 1<<(shift1-1);
179
180
248k
  assert((width&1)==0);
181
182
2.16M
  for (int y=0;y<height;y++) {
183
1.91M
    const inter_t* in  = &src[y*srcstride];
184
1.91M
    uint16_t* out = &dst[y*dststride];
185
186
12.4M
    for (int x=0;x<width;x+=2) {
187
10.5M
      out[0] = Clip_BitDepth((in[0] + offset1)>>shift1, bit_depth);
188
10.5M
      out[1] = Clip_BitDepth((in[1] + offset1)>>shift1, bit_depth);
189
10.5M
      out+=2; in+=2;
190
10.5M
    }
191
1.91M
  }
192
248k
}
void put_unweighted_pred_16_fallback<short>(unsigned short*, long, short const*, long, int, int, int)
Line
Count
Source
173
190k
{
174
  // shift1 per HEVC v2 (10/2014) spec 8.5.3.3.4.2: Max(2, 14 - BitDepth).
175
  // The Max() was added with the Range Extensions in v2 to handle BitDepth up to 16;
176
  // the v1 (04/2013) formula was just (14 - BitDepth), valid only for BitDepth <= 14.
177
190k
  int shift1 = std::max(2, 14-bit_depth);
178
190k
  int offset1 = 1<<(shift1-1);
179
180
190k
  assert((width&1)==0);
181
182
1.55M
  for (int y=0;y<height;y++) {
183
1.36M
    const inter_t* in  = &src[y*srcstride];
184
1.36M
    uint16_t* out = &dst[y*dststride];
185
186
8.42M
    for (int x=0;x<width;x+=2) {
187
7.06M
      out[0] = Clip_BitDepth((in[0] + offset1)>>shift1, bit_depth);
188
7.06M
      out[1] = Clip_BitDepth((in[1] + offset1)>>shift1, bit_depth);
189
7.06M
      out+=2; in+=2;
190
7.06M
    }
191
1.36M
  }
192
190k
}
void put_unweighted_pred_16_fallback<int>(unsigned short*, long, int const*, long, int, int, int)
Line
Count
Source
173
58.3k
{
174
  // shift1 per HEVC v2 (10/2014) spec 8.5.3.3.4.2: Max(2, 14 - BitDepth).
175
  // The Max() was added with the Range Extensions in v2 to handle BitDepth up to 16;
176
  // the v1 (04/2013) formula was just (14 - BitDepth), valid only for BitDepth <= 14.
177
58.3k
  int shift1 = std::max(2, 14-bit_depth);
178
58.3k
  int offset1 = 1<<(shift1-1);
179
180
58.3k
  assert((width&1)==0);
181
182
610k
  for (int y=0;y<height;y++) {
183
552k
    const inter_t* in  = &src[y*srcstride];
184
552k
    uint16_t* out = &dst[y*dststride];
185
186
4.01M
    for (int x=0;x<width;x+=2) {
187
3.46M
      out[0] = Clip_BitDepth((in[0] + offset1)>>shift1, bit_depth);
188
3.46M
      out[1] = Clip_BitDepth((in[1] + offset1)>>shift1, bit_depth);
189
3.46M
      out+=2; in+=2;
190
3.46M
    }
191
552k
  }
192
58.3k
}
193
194
template void put_unweighted_pred_16_fallback<int16_t>(uint16_t*, ptrdiff_t, const int16_t*, ptrdiff_t, int, int, int);
195
template void put_unweighted_pred_16_fallback<int32_t>(uint16_t*, ptrdiff_t, const int32_t*, ptrdiff_t, int, int, int);
196
197
#include <stdlib.h>
198
199
template <class inter_t>
200
void put_weighted_pred_16_fallback(uint16_t *dst, ptrdiff_t dststride,
201
                                   const inter_t *src, ptrdiff_t srcstride,
202
                                   int width, int height,
203
                                   int w,int o,int log2WD, int bit_depth)
204
33.9k
{
205
33.9k
  assert(log2WD>=1); // log2WD = log2_weight_denom + Max(2, 14-BitDepth) >= 2
206
207
33.9k
  const int rnd = (1<<(log2WD-1));
208
209
303k
  for (int y=0;y<height;y++) {
210
269k
    const inter_t* in  = &src[y*srcstride];
211
269k
    uint16_t* out = &dst[y*dststride];
212
213
2.61M
    for (int x=0;x<width;x++) {
214
2.34M
      out[0] = Clip_BitDepth(((in[0]*w + rnd)>>log2WD) + o, bit_depth);
215
2.34M
      out++; in++;
216
2.34M
    }
217
269k
  }
218
33.9k
}
void put_weighted_pred_16_fallback<short>(unsigned short*, long, short const*, long, int, int, int, int, int, int)
Line
Count
Source
204
15.0k
{
205
15.0k
  assert(log2WD>=1); // log2WD = log2_weight_denom + Max(2, 14-BitDepth) >= 2
206
207
15.0k
  const int rnd = (1<<(log2WD-1));
208
209
134k
  for (int y=0;y<height;y++) {
210
119k
    const inter_t* in  = &src[y*srcstride];
211
119k
    uint16_t* out = &dst[y*dststride];
212
213
1.41M
    for (int x=0;x<width;x++) {
214
1.29M
      out[0] = Clip_BitDepth(((in[0]*w + rnd)>>log2WD) + o, bit_depth);
215
1.29M
      out++; in++;
216
1.29M
    }
217
119k
  }
218
15.0k
}
void put_weighted_pred_16_fallback<int>(unsigned short*, long, int const*, long, int, int, int, int, int, int)
Line
Count
Source
204
18.8k
{
205
18.8k
  assert(log2WD>=1); // log2WD = log2_weight_denom + Max(2, 14-BitDepth) >= 2
206
207
18.8k
  const int rnd = (1<<(log2WD-1));
208
209
168k
  for (int y=0;y<height;y++) {
210
149k
    const inter_t* in  = &src[y*srcstride];
211
149k
    uint16_t* out = &dst[y*dststride];
212
213
1.20M
    for (int x=0;x<width;x++) {
214
1.05M
      out[0] = Clip_BitDepth(((in[0]*w + rnd)>>log2WD) + o, bit_depth);
215
1.05M
      out++; in++;
216
1.05M
    }
217
149k
  }
218
18.8k
}
219
220
template void put_weighted_pred_16_fallback<int16_t>(uint16_t*, ptrdiff_t, const int16_t*, ptrdiff_t, int, int, int, int, int, int);
221
template void put_weighted_pred_16_fallback<int32_t>(uint16_t*, ptrdiff_t, const int32_t*, ptrdiff_t, int, int, int, int, int, int);
222
223
template <class inter_t>
224
void put_weighted_bipred_16_fallback(uint16_t *dst, ptrdiff_t dststride,
225
                                     const inter_t *src1, const inter_t *src2, ptrdiff_t srcstride,
226
                                     int width, int height,
227
                                     int w1,int o1, int w2,int o2, int log2WD, int bit_depth)
228
16.2k
{
229
16.2k
  assert(log2WD>=1); // log2WD = log2_weight_denom + Max(2, 14-BitDepth) >= 2
230
231
  // Worst case at BitDepth 16 (int32_t intermediates): |predSample| < 2^20, |w| <= 255,
232
  // |o1+o2+1| <= 2^16, log2WD <= 9 -> the sum stays below 2^29 and fits into int.
233
16.2k
  const int rnd = static_cast<int>(static_cast<unsigned int>(o1+o2+1) << log2WD);
234
235
193k
  for (int y=0;y<height;y++) {
236
177k
    const inter_t* in1 = &src1[y*srcstride];
237
177k
    const inter_t* in2 = &src2[y*srcstride];
238
177k
    uint16_t* out = &dst[y*dststride];
239
240
3.82M
    for (int x=0;x<width;x++) {
241
3.65M
      out[0] = Clip_BitDepth((in1[0]*w1 + in2[0]*w2 + rnd)>>(log2WD+1), bit_depth);
242
3.65M
      out++; in1++; in2++;
243
3.65M
    }
244
177k
  }
245
16.2k
}
void put_weighted_bipred_16_fallback<short>(unsigned short*, long, short const*, short const*, long, int, int, int, int, int, int, int, int)
Line
Count
Source
228
12.3k
{
229
12.3k
  assert(log2WD>=1); // log2WD = log2_weight_denom + Max(2, 14-BitDepth) >= 2
230
231
  // Worst case at BitDepth 16 (int32_t intermediates): |predSample| < 2^20, |w| <= 255,
232
  // |o1+o2+1| <= 2^16, log2WD <= 9 -> the sum stays below 2^29 and fits into int.
233
12.3k
  const int rnd = static_cast<int>(static_cast<unsigned int>(o1+o2+1) << log2WD);
234
235
154k
  for (int y=0;y<height;y++) {
236
142k
    const inter_t* in1 = &src1[y*srcstride];
237
142k
    const inter_t* in2 = &src2[y*srcstride];
238
142k
    uint16_t* out = &dst[y*dststride];
239
240
3.46M
    for (int x=0;x<width;x++) {
241
3.32M
      out[0] = Clip_BitDepth((in1[0]*w1 + in2[0]*w2 + rnd)>>(log2WD+1), bit_depth);
242
3.32M
      out++; in1++; in2++;
243
3.32M
    }
244
142k
  }
245
12.3k
}
void put_weighted_bipred_16_fallback<int>(unsigned short*, long, int const*, int const*, long, int, int, int, int, int, int, int, int)
Line
Count
Source
228
3.87k
{
229
3.87k
  assert(log2WD>=1); // log2WD = log2_weight_denom + Max(2, 14-BitDepth) >= 2
230
231
  // Worst case at BitDepth 16 (int32_t intermediates): |predSample| < 2^20, |w| <= 255,
232
  // |o1+o2+1| <= 2^16, log2WD <= 9 -> the sum stays below 2^29 and fits into int.
233
3.87k
  const int rnd = static_cast<int>(static_cast<unsigned int>(o1+o2+1) << log2WD);
234
235
38.5k
  for (int y=0;y<height;y++) {
236
34.6k
    const inter_t* in1 = &src1[y*srcstride];
237
34.6k
    const inter_t* in2 = &src2[y*srcstride];
238
34.6k
    uint16_t* out = &dst[y*dststride];
239
240
359k
    for (int x=0;x<width;x++) {
241
324k
      out[0] = Clip_BitDepth((in1[0]*w1 + in2[0]*w2 + rnd)>>(log2WD+1), bit_depth);
242
324k
      out++; in1++; in2++;
243
324k
    }
244
34.6k
  }
245
3.87k
}
246
247
template void put_weighted_bipred_16_fallback<int16_t>(uint16_t*, ptrdiff_t, const int16_t*, const int16_t*, ptrdiff_t, int, int, int, int, int, int, int, int);
248
template void put_weighted_bipred_16_fallback<int32_t>(uint16_t*, ptrdiff_t, const int32_t*, const int32_t*, ptrdiff_t, int, int, int, int, int, int, int, int);
249
250
251
template <class inter_t>
252
void put_weighted_pred_avg_16_fallback(uint16_t *dst, ptrdiff_t dststride,
253
                                       const inter_t *src1, const inter_t *src2,
254
                                       ptrdiff_t srcstride, int width,
255
                                       int height, int bit_depth)
256
44.0k
{
257
  // shift2 per HEVC v2 (10/2014) spec 8.5.3.3.4.2: Max(3, 15 - BitDepth).
258
  // The Max() was added with the Range Extensions in v2 to handle BitDepth up to 16;
259
  // the v1 (04/2013) formula was just (15 - BitDepth), valid only for BitDepth <= 14.
260
44.0k
  int shift2 = std::max(3, 15-bit_depth);
261
44.0k
  int offset2 = 1<<(shift2-1);
262
263
44.0k
  assert((width&1)==0);
264
265
559k
  for (int y=0;y<height;y++) {
266
515k
    const inter_t* in1 = &src1[y*srcstride];
267
515k
    const inter_t* in2 = &src2[y*srcstride];
268
515k
    uint16_t* out = &dst[y*dststride];
269
270
4.27M
    for (int x=0;x<width;x+=2) {
271
3.75M
      out[0] = Clip_BitDepth((in1[0] + in2[0] + offset2)>>shift2, bit_depth);
272
3.75M
      out[1] = Clip_BitDepth((in1[1] + in2[1] + offset2)>>shift2, bit_depth);
273
3.75M
      out+=2; in1+=2; in2+=2;
274
3.75M
    }
275
515k
  }
276
44.0k
}
void put_weighted_pred_avg_16_fallback<short>(unsigned short*, long, short const*, short const*, long, int, int, int)
Line
Count
Source
256
35.8k
{
257
  // shift2 per HEVC v2 (10/2014) spec 8.5.3.3.4.2: Max(3, 15 - BitDepth).
258
  // The Max() was added with the Range Extensions in v2 to handle BitDepth up to 16;
259
  // the v1 (04/2013) formula was just (15 - BitDepth), valid only for BitDepth <= 14.
260
35.8k
  int shift2 = std::max(3, 15-bit_depth);
261
35.8k
  int offset2 = 1<<(shift2-1);
262
263
35.8k
  assert((width&1)==0);
264
265
405k
  for (int y=0;y<height;y++) {
266
369k
    const inter_t* in1 = &src1[y*srcstride];
267
369k
    const inter_t* in2 = &src2[y*srcstride];
268
369k
    uint16_t* out = &dst[y*dststride];
269
270
2.74M
    for (int x=0;x<width;x+=2) {
271
2.37M
      out[0] = Clip_BitDepth((in1[0] + in2[0] + offset2)>>shift2, bit_depth);
272
2.37M
      out[1] = Clip_BitDepth((in1[1] + in2[1] + offset2)>>shift2, bit_depth);
273
2.37M
      out+=2; in1+=2; in2+=2;
274
2.37M
    }
275
369k
  }
276
35.8k
}
void put_weighted_pred_avg_16_fallback<int>(unsigned short*, long, int const*, int const*, long, int, int, int)
Line
Count
Source
256
8.10k
{
257
  // shift2 per HEVC v2 (10/2014) spec 8.5.3.3.4.2: Max(3, 15 - BitDepth).
258
  // The Max() was added with the Range Extensions in v2 to handle BitDepth up to 16;
259
  // the v1 (04/2013) formula was just (15 - BitDepth), valid only for BitDepth <= 14.
260
8.10k
  int shift2 = std::max(3, 15-bit_depth);
261
8.10k
  int offset2 = 1<<(shift2-1);
262
263
8.10k
  assert((width&1)==0);
264
265
153k
  for (int y=0;y<height;y++) {
266
145k
    const inter_t* in1 = &src1[y*srcstride];
267
145k
    const inter_t* in2 = &src2[y*srcstride];
268
145k
    uint16_t* out = &dst[y*dststride];
269
270
1.53M
    for (int x=0;x<width;x+=2) {
271
1.38M
      out[0] = Clip_BitDepth((in1[0] + in2[0] + offset2)>>shift2, bit_depth);
272
1.38M
      out[1] = Clip_BitDepth((in1[1] + in2[1] + offset2)>>shift2, bit_depth);
273
1.38M
      out+=2; in1+=2; in2+=2;
274
1.38M
    }
275
145k
  }
276
8.10k
}
277
278
template void put_weighted_pred_avg_16_fallback<int16_t>(uint16_t*, ptrdiff_t, const int16_t*, const int16_t*, ptrdiff_t, int, int, int);
279
template void put_weighted_pred_avg_16_fallback<int32_t>(uint16_t*, ptrdiff_t, const int32_t*, const int32_t*, ptrdiff_t, int, int, int);
280
281
282
283
284
285
void put_epel_8_fallback(int16_t *out, ptrdiff_t out_stride,
286
                         const uint8_t *src, ptrdiff_t src_stride,
287
                         int width, int height,
288
                         int mx, int my, int16_t* mcbuffer)
289
170k
{
290
170k
  int shift3 = 6;
291
292
1.75M
  for (int y=0;y<height;y++) {
293
1.57M
    int16_t* o = &out[y*out_stride];
294
1.57M
    const uint8_t* i = &src[y*src_stride];
295
296
21.6M
    for (int x=0;x<width;x++) {
297
20.0M
      *o = *i << shift3;
298
20.0M
      o++;
299
20.0M
      i++;
300
20.0M
    }
301
1.57M
  }
302
170k
}
303
304
305
template <class inter_t>
306
void put_epel_16_fallback(inter_t *out, ptrdiff_t out_stride,
307
                          const uint16_t *src, ptrdiff_t src_stride,
308
                          int width, int height,
309
                          int mx, int my, inter_t* mcbuffer, int bit_depth)
310
62.0k
{
311
  // shift3 per HEVC v2 (10/2014) spec 8.5.3.3.3.3 (chroma): Max(2, 14 - BitDepth).
312
  // The Max() was added with the Range Extensions in v2 to handle BitDepth up to 16;
313
  // the v1 (04/2013) formula was just (14 - BitDepth), valid only for BitDepth <= 14.
314
62.0k
  int shift3 = std::max(2, 14 - bit_depth);
315
316
693k
  for (int y=0;y<height;y++) {
317
631k
    inter_t* o = &out[y*out_stride];
318
631k
    const uint16_t* i = &src[y*src_stride];
319
320
11.0M
    for (int x=0;x<width;x++) {
321
10.4M
      *o = *i << shift3;
322
10.4M
      o++;
323
10.4M
      i++;
324
10.4M
    }
325
631k
  }
326
62.0k
}
void put_epel_16_fallback<short>(short*, long, unsigned short const*, long, int, int, int, int, short*, int)
Line
Count
Source
310
38.5k
{
311
  // shift3 per HEVC v2 (10/2014) spec 8.5.3.3.3.3 (chroma): Max(2, 14 - BitDepth).
312
  // The Max() was added with the Range Extensions in v2 to handle BitDepth up to 16;
313
  // the v1 (04/2013) formula was just (14 - BitDepth), valid only for BitDepth <= 14.
314
38.5k
  int shift3 = std::max(2, 14 - bit_depth);
315
316
400k
  for (int y=0;y<height;y++) {
317
361k
    inter_t* o = &out[y*out_stride];
318
361k
    const uint16_t* i = &src[y*src_stride];
319
320
6.84M
    for (int x=0;x<width;x++) {
321
6.48M
      *o = *i << shift3;
322
6.48M
      o++;
323
6.48M
      i++;
324
6.48M
    }
325
361k
  }
326
38.5k
}
void put_epel_16_fallback<int>(int*, long, unsigned short const*, long, int, int, int, int, int*, int)
Line
Count
Source
310
23.5k
{
311
  // shift3 per HEVC v2 (10/2014) spec 8.5.3.3.3.3 (chroma): Max(2, 14 - BitDepth).
312
  // The Max() was added with the Range Extensions in v2 to handle BitDepth up to 16;
313
  // the v1 (04/2013) formula was just (14 - BitDepth), valid only for BitDepth <= 14.
314
23.5k
  int shift3 = std::max(2, 14 - bit_depth);
315
316
293k
  for (int y=0;y<height;y++) {
317
269k
    inter_t* o = &out[y*out_stride];
318
269k
    const uint16_t* i = &src[y*src_stride];
319
320
4.22M
    for (int x=0;x<width;x++) {
321
3.95M
      *o = *i << shift3;
322
3.95M
      o++;
323
3.95M
      i++;
324
3.95M
    }
325
269k
  }
326
23.5k
}
327
328
template void put_epel_16_fallback<int16_t>(int16_t*, ptrdiff_t, const uint16_t*, ptrdiff_t, int, int, int, int, int16_t*, int);
329
template void put_epel_16_fallback<int32_t>(int32_t*, ptrdiff_t, const uint16_t*, ptrdiff_t, int, int, int, int, int32_t*, int);
330
331
332
template <class pixel_t, class inter_t>
333
void put_epel_hv_fallback(inter_t *dst, ptrdiff_t dst_stride,
334
                          const pixel_t *src, ptrdiff_t src_stride,
335
                          int nPbWC, int nPbHC,
336
                          int xFracC, int yFracC, inter_t* mcbuffer, int bit_depth)
337
218k
{
338
  // shift1 per HEVC v2 (10/2014) spec 8.5.3.3.3.3 (chroma): Min(4, BitDepth - 8).
339
  // The Min() was added with the Range Extensions in v2 for BitDepth > 12: the
340
  // intermediate samples then keep BitDepth+2 bits instead of 14 (see shift3).
341
218k
  const int shift1 = std::min(4, bit_depth-8);
342
218k
  const int shift2 = 6;
343
  //const int shift3 = 6;
344
345
218k
  int extra_left = 1;
346
218k
  int extra_top  = 1;
347
  //  int extra_right = 2;
348
218k
  int extra_bottom= 2;
349
350
351
218k
  int nPbH_extra = extra_top  + nPbHC + extra_bottom;
352
353
218k
  inter_t* tmp2buf = (inter_t*)alloca( nPbWC      * nPbH_extra * sizeof(inter_t) );
354
355
  /*
356
  int nPbW_extra = extra_left + nPbWC + extra_right;
357
358
359
  printf("x,y FracC: %d/%d\n",xFracC,yFracC);
360
361
  printf("---IN---\n");
362
363
  for (int y=-extra_top;y<nPbHC+extra_bottom;y++) {
364
    uint8_t* p = &src[y*src_stride -extra_left];
365
366
    for (int x=-extra_left;x<nPbWC+extra_right;x++) {
367
      printf("%05d ",*p << 6);
368
      p++;
369
    }
370
    printf("\n");
371
  }
372
  */
373
374
375
  // H-filters
376
377
218k
  logtrace(LogMotion,"---H---\n");
378
  //printf("---H---(%d)\n",xFracC);
379
380
2.89M
  for (int y=-extra_top;y<nPbHC+extra_bottom;y++) {
381
2.68M
    const pixel_t* p = &src[y*src_stride - extra_left];
382
383
33.6M
    for (int x=0;x<nPbWC;x++) {
384
30.9M
      int v;
385
30.9M
      switch (xFracC) {
386
8.99M
      case 0: v = p[1]; break;
387
223k
      case 1: v = (-2*p[0]+58*p[1]+10*p[2]-2*p[3])>>shift1; break;
388
8.50M
      case 2: v = (-4*p[0]+54*p[1]+16*p[2]-2*p[3])>>shift1; break;
389
132k
      case 3: v = (-6*p[0]+46*p[1]+28*p[2]-4*p[3])>>shift1; break;
390
5.90M
      case 4: v = (-4*p[0]+36*p[1]+36*p[2]-4*p[3])>>shift1; break;
391
68.4k
      case 5: v = (-4*p[0]+28*p[1]+46*p[2]-6*p[3])>>shift1; break;
392
6.90M
      case 6: v = (-2*p[0]+16*p[1]+54*p[2]-4*p[3])>>shift1; break;
393
0
      default:
394
182k
      case 7: v = (-2*p[0]+10*p[1]+58*p[2]-2*p[3])>>shift1; break;
395
30.9M
      }
396
397
      //printf("%d %d %d %d -> %d\n",p[0],p[1],p[2],p[3],v);
398
399
30.9M
      tmp2buf[y+extra_top + x*nPbH_extra] = v;
400
30.9M
      p++;
401
402
      //printf("%05d ",tmp2buf[y+extra_top + x*nPbH_extra]);
403
30.9M
    }
404
    //printf("\n");
405
2.68M
  }
406
407
  // V-filters
408
409
218k
  int vshift = (xFracC==0 ? shift1 : shift2);
410
411
2.20M
  for (int x=0;x<nPbWC;x++) {
412
1.98M
    inter_t* p = &tmp2buf[x*nPbH_extra];
413
414
26.9M
    for (int y=0;y<nPbHC;y++) {
415
24.9M
      int v;
416
      //logtrace(LogMotion,"%x %x %x  %x  %x %x %x\n",p[0],p[1],p[2],p[3],p[4],p[5],p[6]);
417
418
24.9M
      switch (yFracC) {
419
5.68M
      case 0: v = p[1]; break;
420
27.6k
      case 1: v = (-2*p[0]+58*p[1]+10*p[2]-2*p[3])>>vshift; break;
421
8.10M
      case 2: v = (-4*p[0]+54*p[1]+16*p[2]-2*p[3])>>vshift; break;
422
24.5k
      case 3: v = (-6*p[0]+46*p[1]+28*p[2]-4*p[3])>>vshift; break;
423
5.12M
      case 4: v = (-4*p[0]+36*p[1]+36*p[2]-4*p[3])>>vshift; break;
424
38.5k
      case 5: v = (-4*p[0]+28*p[1]+46*p[2]-6*p[3])>>vshift; break;
425
5.91M
      case 6: v = (-2*p[0]+16*p[1]+54*p[2]-4*p[3])>>vshift; break;
426
0
      default:
427
45.8k
      case 7: v = (-2*p[0]+10*p[1]+58*p[2]-2*p[3])>>vshift; break;
428
24.9M
      }
429
430
24.9M
      dst[x + y*dst_stride] = v;
431
24.9M
      p++;
432
24.9M
    }
433
434
1.98M
  }
435
436
  /*
437
  printf("---V---\n");
438
  for (int y=0;y<nPbHC;y++) {
439
    for (int x=0;x<nPbWC;x++) {
440
      printf("%05d ",dst[x+y*dst_stride]);
441
    }
442
    printf("\n");
443
  }
444
  */
445
218k
}
void put_epel_hv_fallback<unsigned char, short>(short*, long, unsigned char const*, long, int, int, int, int, short*, int)
Line
Count
Source
337
135k
{
338
  // shift1 per HEVC v2 (10/2014) spec 8.5.3.3.3.3 (chroma): Min(4, BitDepth - 8).
339
  // The Min() was added with the Range Extensions in v2 for BitDepth > 12: the
340
  // intermediate samples then keep BitDepth+2 bits instead of 14 (see shift3).
341
135k
  const int shift1 = std::min(4, bit_depth-8);
342
135k
  const int shift2 = 6;
343
  //const int shift3 = 6;
344
345
135k
  int extra_left = 1;
346
135k
  int extra_top  = 1;
347
  //  int extra_right = 2;
348
135k
  int extra_bottom= 2;
349
350
351
135k
  int nPbH_extra = extra_top  + nPbHC + extra_bottom;
352
353
135k
  inter_t* tmp2buf = (inter_t*)alloca( nPbWC      * nPbH_extra * sizeof(inter_t) );
354
355
  /*
356
  int nPbW_extra = extra_left + nPbWC + extra_right;
357
358
359
  printf("x,y FracC: %d/%d\n",xFracC,yFracC);
360
361
  printf("---IN---\n");
362
363
  for (int y=-extra_top;y<nPbHC+extra_bottom;y++) {
364
    uint8_t* p = &src[y*src_stride -extra_left];
365
366
    for (int x=-extra_left;x<nPbWC+extra_right;x++) {
367
      printf("%05d ",*p << 6);
368
      p++;
369
    }
370
    printf("\n");
371
  }
372
  */
373
374
375
  // H-filters
376
377
135k
  logtrace(LogMotion,"---H---\n");
378
  //printf("---H---(%d)\n",xFracC);
379
380
1.91M
  for (int y=-extra_top;y<nPbHC+extra_bottom;y++) {
381
1.77M
    const pixel_t* p = &src[y*src_stride - extra_left];
382
383
22.3M
    for (int x=0;x<nPbWC;x++) {
384
20.5M
      int v;
385
20.5M
      switch (xFracC) {
386
5.78M
      case 0: v = p[1]; break;
387
194k
      case 1: v = (-2*p[0]+58*p[1]+10*p[2]-2*p[3])>>shift1; break;
388
5.43M
      case 2: v = (-4*p[0]+54*p[1]+16*p[2]-2*p[3])>>shift1; break;
389
99.7k
      case 3: v = (-6*p[0]+46*p[1]+28*p[2]-4*p[3])>>shift1; break;
390
4.15M
      case 4: v = (-4*p[0]+36*p[1]+36*p[2]-4*p[3])>>shift1; break;
391
50.7k
      case 5: v = (-4*p[0]+28*p[1]+46*p[2]-6*p[3])>>shift1; break;
392
4.70M
      case 6: v = (-2*p[0]+16*p[1]+54*p[2]-4*p[3])>>shift1; break;
393
0
      default:
394
144k
      case 7: v = (-2*p[0]+10*p[1]+58*p[2]-2*p[3])>>shift1; break;
395
20.5M
      }
396
397
      //printf("%d %d %d %d -> %d\n",p[0],p[1],p[2],p[3],v);
398
399
20.5M
      tmp2buf[y+extra_top + x*nPbH_extra] = v;
400
20.5M
      p++;
401
402
      //printf("%05d ",tmp2buf[y+extra_top + x*nPbH_extra]);
403
20.5M
    }
404
    //printf("\n");
405
1.77M
  }
406
407
  // V-filters
408
409
135k
  int vshift = (xFracC==0 ? shift1 : shift2);
410
411
1.37M
  for (int x=0;x<nPbWC;x++) {
412
1.24M
    inter_t* p = &tmp2buf[x*nPbH_extra];
413
414
18.0M
    for (int y=0;y<nPbHC;y++) {
415
16.8M
      int v;
416
      //logtrace(LogMotion,"%x %x %x  %x  %x %x %x\n",p[0],p[1],p[2],p[3],p[4],p[5],p[6]);
417
418
16.8M
      switch (yFracC) {
419
4.04M
      case 0: v = p[1]; break;
420
15.4k
      case 1: v = (-2*p[0]+58*p[1]+10*p[2]-2*p[3])>>vshift; break;
421
5.33M
      case 2: v = (-4*p[0]+54*p[1]+16*p[2]-2*p[3])>>vshift; break;
422
8.27k
      case 3: v = (-6*p[0]+46*p[1]+28*p[2]-4*p[3])>>vshift; break;
423
3.36M
      case 4: v = (-4*p[0]+36*p[1]+36*p[2]-4*p[3])>>vshift; break;
424
7.16k
      case 5: v = (-4*p[0]+28*p[1]+46*p[2]-6*p[3])>>vshift; break;
425
4.04M
      case 6: v = (-2*p[0]+16*p[1]+54*p[2]-4*p[3])>>vshift; break;
426
0
      default:
427
21.1k
      case 7: v = (-2*p[0]+10*p[1]+58*p[2]-2*p[3])>>vshift; break;
428
16.8M
      }
429
430
16.8M
      dst[x + y*dst_stride] = v;
431
16.8M
      p++;
432
16.8M
    }
433
434
1.24M
  }
435
436
  /*
437
  printf("---V---\n");
438
  for (int y=0;y<nPbHC;y++) {
439
    for (int x=0;x<nPbWC;x++) {
440
      printf("%05d ",dst[x+y*dst_stride]);
441
    }
442
    printf("\n");
443
  }
444
  */
445
135k
}
void put_epel_hv_fallback<unsigned short, short>(short*, long, unsigned short const*, long, int, int, int, int, short*, int)
Line
Count
Source
337
61.8k
{
338
  // shift1 per HEVC v2 (10/2014) spec 8.5.3.3.3.3 (chroma): Min(4, BitDepth - 8).
339
  // The Min() was added with the Range Extensions in v2 for BitDepth > 12: the
340
  // intermediate samples then keep BitDepth+2 bits instead of 14 (see shift3).
341
61.8k
  const int shift1 = std::min(4, bit_depth-8);
342
61.8k
  const int shift2 = 6;
343
  //const int shift3 = 6;
344
345
61.8k
  int extra_left = 1;
346
61.8k
  int extra_top  = 1;
347
  //  int extra_right = 2;
348
61.8k
  int extra_bottom= 2;
349
350
351
61.8k
  int nPbH_extra = extra_top  + nPbHC + extra_bottom;
352
353
61.8k
  inter_t* tmp2buf = (inter_t*)alloca( nPbWC      * nPbH_extra * sizeof(inter_t) );
354
355
  /*
356
  int nPbW_extra = extra_left + nPbWC + extra_right;
357
358
359
  printf("x,y FracC: %d/%d\n",xFracC,yFracC);
360
361
  printf("---IN---\n");
362
363
  for (int y=-extra_top;y<nPbHC+extra_bottom;y++) {
364
    uint8_t* p = &src[y*src_stride -extra_left];
365
366
    for (int x=-extra_left;x<nPbWC+extra_right;x++) {
367
      printf("%05d ",*p << 6);
368
      p++;
369
    }
370
    printf("\n");
371
  }
372
  */
373
374
375
  // H-filters
376
377
61.8k
  logtrace(LogMotion,"---H---\n");
378
  //printf("---H---(%d)\n",xFracC);
379
380
686k
  for (int y=-extra_top;y<nPbHC+extra_bottom;y++) {
381
624k
    const pixel_t* p = &src[y*src_stride - extra_left];
382
383
7.27M
    for (int x=0;x<nPbWC;x++) {
384
6.64M
      int v;
385
6.64M
      switch (xFracC) {
386
1.87M
      case 0: v = p[1]; break;
387
20.3k
      case 1: v = (-2*p[0]+58*p[1]+10*p[2]-2*p[3])>>shift1; break;
388
2.10M
      case 2: v = (-4*p[0]+54*p[1]+16*p[2]-2*p[3])>>shift1; break;
389
30.1k
      case 3: v = (-6*p[0]+46*p[1]+28*p[2]-4*p[3])>>shift1; break;
390
1.06M
      case 4: v = (-4*p[0]+36*p[1]+36*p[2]-4*p[3])>>shift1; break;
391
16.2k
      case 5: v = (-4*p[0]+28*p[1]+46*p[2]-6*p[3])>>shift1; break;
392
1.49M
      case 6: v = (-2*p[0]+16*p[1]+54*p[2]-4*p[3])>>shift1; break;
393
0
      default:
394
27.0k
      case 7: v = (-2*p[0]+10*p[1]+58*p[2]-2*p[3])>>shift1; break;
395
6.64M
      }
396
397
      //printf("%d %d %d %d -> %d\n",p[0],p[1],p[2],p[3],v);
398
399
6.64M
      tmp2buf[y+extra_top + x*nPbH_extra] = v;
400
6.64M
      p++;
401
402
      //printf("%05d ",tmp2buf[y+extra_top + x*nPbH_extra]);
403
6.64M
    }
404
    //printf("\n");
405
624k
  }
406
407
  // V-filters
408
409
61.8k
  int vshift = (xFracC==0 ? shift1 : shift2);
410
411
598k
  for (int x=0;x<nPbWC;x++) {
412
536k
    inter_t* p = &tmp2buf[x*nPbH_extra];
413
414
5.57M
    for (int y=0;y<nPbHC;y++) {
415
5.03M
      int v;
416
      //logtrace(LogMotion,"%x %x %x  %x  %x %x %x\n",p[0],p[1],p[2],p[3],p[4],p[5],p[6]);
417
418
5.03M
      switch (yFracC) {
419
1.29M
      case 0: v = p[1]; break;
420
6.43k
      case 1: v = (-2*p[0]+58*p[1]+10*p[2]-2*p[3])>>vshift; break;
421
1.53M
      case 2: v = (-4*p[0]+54*p[1]+16*p[2]-2*p[3])>>vshift; break;
422
11.4k
      case 3: v = (-6*p[0]+46*p[1]+28*p[2]-4*p[3])>>vshift; break;
423
879k
      case 4: v = (-4*p[0]+36*p[1]+36*p[2]-4*p[3])>>vshift; break;
424
24.2k
      case 5: v = (-4*p[0]+28*p[1]+46*p[2]-6*p[3])>>vshift; break;
425
1.26M
      case 6: v = (-2*p[0]+16*p[1]+54*p[2]-4*p[3])>>vshift; break;
426
0
      default:
427
18.7k
      case 7: v = (-2*p[0]+10*p[1]+58*p[2]-2*p[3])>>vshift; break;
428
5.03M
      }
429
430
5.03M
      dst[x + y*dst_stride] = v;
431
5.03M
      p++;
432
5.03M
    }
433
434
536k
  }
435
436
  /*
437
  printf("---V---\n");
438
  for (int y=0;y<nPbHC;y++) {
439
    for (int x=0;x<nPbWC;x++) {
440
      printf("%05d ",dst[x+y*dst_stride]);
441
    }
442
    printf("\n");
443
  }
444
  */
445
61.8k
}
void put_epel_hv_fallback<unsigned short, int>(int*, long, unsigned short const*, long, int, int, int, int, int*, int)
Line
Count
Source
337
20.1k
{
338
  // shift1 per HEVC v2 (10/2014) spec 8.5.3.3.3.3 (chroma): Min(4, BitDepth - 8).
339
  // The Min() was added with the Range Extensions in v2 for BitDepth > 12: the
340
  // intermediate samples then keep BitDepth+2 bits instead of 14 (see shift3).
341
20.1k
  const int shift1 = std::min(4, bit_depth-8);
342
20.1k
  const int shift2 = 6;
343
  //const int shift3 = 6;
344
345
20.1k
  int extra_left = 1;
346
20.1k
  int extra_top  = 1;
347
  //  int extra_right = 2;
348
20.1k
  int extra_bottom= 2;
349
350
351
20.1k
  int nPbH_extra = extra_top  + nPbHC + extra_bottom;
352
353
20.1k
  inter_t* tmp2buf = (inter_t*)alloca( nPbWC      * nPbH_extra * sizeof(inter_t) );
354
355
  /*
356
  int nPbW_extra = extra_left + nPbWC + extra_right;
357
358
359
  printf("x,y FracC: %d/%d\n",xFracC,yFracC);
360
361
  printf("---IN---\n");
362
363
  for (int y=-extra_top;y<nPbHC+extra_bottom;y++) {
364
    uint8_t* p = &src[y*src_stride -extra_left];
365
366
    for (int x=-extra_left;x<nPbWC+extra_right;x++) {
367
      printf("%05d ",*p << 6);
368
      p++;
369
    }
370
    printf("\n");
371
  }
372
  */
373
374
375
  // H-filters
376
377
20.1k
  logtrace(LogMotion,"---H---\n");
378
  //printf("---H---(%d)\n",xFracC);
379
380
302k
  for (int y=-extra_top;y<nPbHC+extra_bottom;y++) {
381
282k
    const pixel_t* p = &src[y*src_stride - extra_left];
382
383
3.99M
    for (int x=0;x<nPbWC;x++) {
384
3.70M
      int v;
385
3.70M
      switch (xFracC) {
386
1.33M
      case 0: v = p[1]; break;
387
7.82k
      case 1: v = (-2*p[0]+58*p[1]+10*p[2]-2*p[3])>>shift1; break;
388
964k
      case 2: v = (-4*p[0]+54*p[1]+16*p[2]-2*p[3])>>shift1; break;
389
2.73k
      case 3: v = (-6*p[0]+46*p[1]+28*p[2]-4*p[3])>>shift1; break;
390
689k
      case 4: v = (-4*p[0]+36*p[1]+36*p[2]-4*p[3])>>shift1; break;
391
1.38k
      case 5: v = (-4*p[0]+28*p[1]+46*p[2]-6*p[3])>>shift1; break;
392
699k
      case 6: v = (-2*p[0]+16*p[1]+54*p[2]-4*p[3])>>shift1; break;
393
0
      default:
394
11.1k
      case 7: v = (-2*p[0]+10*p[1]+58*p[2]-2*p[3])>>shift1; break;
395
3.70M
      }
396
397
      //printf("%d %d %d %d -> %d\n",p[0],p[1],p[2],p[3],v);
398
399
3.70M
      tmp2buf[y+extra_top + x*nPbH_extra] = v;
400
3.70M
      p++;
401
402
      //printf("%05d ",tmp2buf[y+extra_top + x*nPbH_extra]);
403
3.70M
    }
404
    //printf("\n");
405
282k
  }
406
407
  // V-filters
408
409
20.1k
  int vshift = (xFracC==0 ? shift1 : shift2);
410
411
227k
  for (int x=0;x<nPbWC;x++) {
412
207k
    inter_t* p = &tmp2buf[x*nPbH_extra];
413
414
3.29M
    for (int y=0;y<nPbHC;y++) {
415
3.08M
      int v;
416
      //logtrace(LogMotion,"%x %x %x  %x  %x %x %x\n",p[0],p[1],p[2],p[3],p[4],p[5],p[6]);
417
418
3.08M
      switch (yFracC) {
419
344k
      case 0: v = p[1]; break;
420
5.76k
      case 1: v = (-2*p[0]+58*p[1]+10*p[2]-2*p[3])>>vshift; break;
421
1.24M
      case 2: v = (-4*p[0]+54*p[1]+16*p[2]-2*p[3])>>vshift; break;
422
4.84k
      case 3: v = (-6*p[0]+46*p[1]+28*p[2]-4*p[3])>>vshift; break;
423
875k
      case 4: v = (-4*p[0]+36*p[1]+36*p[2]-4*p[3])>>vshift; break;
424
7.10k
      case 5: v = (-4*p[0]+28*p[1]+46*p[2]-6*p[3])>>vshift; break;
425
601k
      case 6: v = (-2*p[0]+16*p[1]+54*p[2]-4*p[3])>>vshift; break;
426
0
      default:
427
6.00k
      case 7: v = (-2*p[0]+10*p[1]+58*p[2]-2*p[3])>>vshift; break;
428
3.08M
      }
429
430
3.08M
      dst[x + y*dst_stride] = v;
431
3.08M
      p++;
432
3.08M
    }
433
434
207k
  }
435
436
  /*
437
  printf("---V---\n");
438
  for (int y=0;y<nPbHC;y++) {
439
    for (int x=0;x<nPbWC;x++) {
440
      printf("%05d ",dst[x+y*dst_stride]);
441
    }
442
    printf("\n");
443
  }
444
  */
445
20.1k
}
446
447
448
template
449
void put_epel_hv_fallback<uint8_t,int16_t>(int16_t *dst, ptrdiff_t dst_stride,
450
                                           const uint8_t *src, ptrdiff_t src_stride,
451
                                           int nPbWC, int nPbHC,
452
                                           int xFracC, int yFracC, int16_t* mcbuffer, int bit_depth);
453
template
454
void put_epel_hv_fallback<uint16_t,int16_t>(int16_t *dst, ptrdiff_t dst_stride,
455
                                            const uint16_t *src, ptrdiff_t src_stride,
456
                                            int nPbWC, int nPbHC,
457
                                            int xFracC, int yFracC, int16_t* mcbuffer, int bit_depth);
458
template
459
void put_epel_hv_fallback<uint16_t,int32_t>(int32_t *dst, ptrdiff_t dst_stride,
460
                                            const uint16_t *src, ptrdiff_t src_stride,
461
                                            int nPbWC, int nPbHC,
462
                                            int xFracC, int yFracC, int32_t* mcbuffer, int bit_depth);
463
464
465
466
void put_qpel_0_0_fallback(int16_t *out, ptrdiff_t out_stride,
467
                           const uint8_t *src, ptrdiff_t srcstride,
468
                           int nPbW, int nPbH, int16_t* mcbuffer)
469
104k
{
470
  //const int shift1 = 0; // sps->BitDepth_Y-8;
471
104k
  const int shift2 = 6;
472
473
  // straight copy
474
475
956k
  for (int y=0;y<nPbH;y++) {
476
851k
      const uint8_t* p = src + srcstride*y;
477
851k
      int16_t* o = out + out_stride*y;
478
479
3.29M
      for (int x=0;x<nPbW;x+=4) {
480
481
        // does not seem to be faster...
482
2.44M
        int16_t o0,o1,o2,o3;
483
2.44M
        o0 = p[0] << shift2;
484
2.44M
        o1 = p[1] << shift2;
485
2.44M
        o2 = p[2] << shift2;
486
2.44M
        o3 = p[3] << shift2;
487
2.44M
        o[0]=o0;
488
2.44M
        o[1]=o1;
489
2.44M
        o[2]=o2;
490
2.44M
        o[3]=o3;
491
492
2.44M
        o+=4;
493
2.44M
        p+=4;
494
2.44M
      }
495
851k
  }
496
104k
}
497
498
499
template <class inter_t>
500
void put_qpel_0_0_fallback_16(inter_t *out, ptrdiff_t out_stride,
501
                              const uint16_t *src, ptrdiff_t srcstride,
502
                              int nPbW, int nPbH, inter_t* mcbuffer, int bit_depth)
503
134k
{
504
  //const int shift1 = bit_depth-8;
505
  //const int shift2 = 6;
506
  // shift3 per HEVC v2 (10/2014) spec 8.5.3.3.3.2 (luma): Max(2, 14 - BitDepth).
507
  // The Max() was added with the Range Extensions in v2 to handle BitDepth up to 16;
508
  // the v1 (04/2013) formula was just (14 - BitDepth), valid only for BitDepth <= 14.
509
134k
  const int shift3 = std::max(2, 14-bit_depth);
510
511
  // straight copy
512
513
1.31M
  for (int y=0;y<nPbH;y++) {
514
1.17M
    const uint16_t* p = src + srcstride*y;
515
1.17M
    inter_t* o = out + out_stride*y;
516
517
15.6M
    for (int x=0;x<nPbW;x++) {
518
14.4M
      *o++ = *p++ << shift3;
519
14.4M
    }
520
1.17M
  }
521
134k
}
void put_qpel_0_0_fallback_16<short>(short*, long, unsigned short const*, long, int, int, short*, int)
Line
Count
Source
503
104k
{
504
  //const int shift1 = bit_depth-8;
505
  //const int shift2 = 6;
506
  // shift3 per HEVC v2 (10/2014) spec 8.5.3.3.3.2 (luma): Max(2, 14 - BitDepth).
507
  // The Max() was added with the Range Extensions in v2 to handle BitDepth up to 16;
508
  // the v1 (04/2013) formula was just (14 - BitDepth), valid only for BitDepth <= 14.
509
104k
  const int shift3 = std::max(2, 14-bit_depth);
510
511
  // straight copy
512
513
989k
  for (int y=0;y<nPbH;y++) {
514
885k
    const uint16_t* p = src + srcstride*y;
515
885k
    inter_t* o = out + out_stride*y;
516
517
11.8M
    for (int x=0;x<nPbW;x++) {
518
10.9M
      *o++ = *p++ << shift3;
519
10.9M
    }
520
885k
  }
521
104k
}
void put_qpel_0_0_fallback_16<int>(int*, long, unsigned short const*, long, int, int, int*, int)
Line
Count
Source
503
30.1k
{
504
  //const int shift1 = bit_depth-8;
505
  //const int shift2 = 6;
506
  // shift3 per HEVC v2 (10/2014) spec 8.5.3.3.3.2 (luma): Max(2, 14 - BitDepth).
507
  // The Max() was added with the Range Extensions in v2 to handle BitDepth up to 16;
508
  // the v1 (04/2013) formula was just (14 - BitDepth), valid only for BitDepth <= 14.
509
30.1k
  const int shift3 = std::max(2, 14-bit_depth);
510
511
  // straight copy
512
513
323k
  for (int y=0;y<nPbH;y++) {
514
293k
    const uint16_t* p = src + srcstride*y;
515
293k
    inter_t* o = out + out_stride*y;
516
517
3.77M
    for (int x=0;x<nPbW;x++) {
518
3.48M
      *o++ = *p++ << shift3;
519
3.48M
    }
520
293k
  }
521
30.1k
}
522
523
template void put_qpel_0_0_fallback_16<int16_t>(int16_t*, ptrdiff_t, const uint16_t*, ptrdiff_t, int, int, int16_t*, int);
524
template void put_qpel_0_0_fallback_16<int32_t>(int32_t*, ptrdiff_t, const uint16_t*, ptrdiff_t, int, int, int32_t*, int);
525
526
527
528
static int extra_before[4] = { 0,3,3,2 };
529
static int extra_after [4] = { 0,3,4,4 };
530
531
template <class pixel_t, class inter_t>
532
void put_qpel_fallback(inter_t *out, ptrdiff_t out_stride,
533
                       const pixel_t *src, ptrdiff_t srcstride,
534
                       int nPbW, int nPbH, inter_t* mcbuffer,
535
                       int xFracL, int yFracL, int bit_depth)
536
254k
{
537
254k
  int extra_left   = extra_before[xFracL];
538
  //int extra_right  = extra_after [xFracL];
539
254k
  int extra_top    = extra_before[yFracL];
540
254k
  int extra_bottom = extra_after [yFracL];
541
542
  //int nPbW_extra = extra_left + nPbW + extra_right;
543
254k
  int nPbH_extra = extra_top  + nPbH + extra_bottom;
544
545
  // shift1 per HEVC v2 (10/2014) spec 8.5.3.3.3.2 (luma): Min(4, BitDepth - 8).
546
  // The Min() was added with the Range Extensions in v2 for BitDepth > 12: the
547
  // intermediate samples then keep BitDepth+2 bits instead of 14 (see shift3).
548
254k
  const int shift1 = std::min(4, bit_depth-8);
549
254k
  const int shift2 = 6;
550
551
552
  // H-filters
553
554
254k
  switch (xFracL) {
555
62.4k
  case 0:
556
988k
    for (int y=-extra_top;y<nPbH+extra_bottom;y++) {
557
926k
      const pixel_t* p = src + srcstride*y - extra_left;
558
926k
      inter_t* o = &mcbuffer[y+extra_top];
559
560
10.2M
      for (int x=0;x<nPbW;x++) {
561
9.37M
        *o = *p;
562
9.37M
        o += nPbH_extra;
563
9.37M
        p++;
564
9.37M
      }
565
926k
    }
566
62.4k
    break;
567
73.8k
  case 1:
568
1.00M
    for (int y=-extra_top;y<nPbH+extra_bottom;y++) {
569
935k
      const pixel_t* p = src + srcstride*y - extra_left;
570
935k
      inter_t* o = &mcbuffer[y+extra_top];
571
572
10.0M
      for (int x=0;x<nPbW;x++) {
573
9.08M
        *o = (-p[0]+4*p[1]-10*p[2]+58*p[3]+17*p[4] -5*p[5]  +p[6])>>shift1;
574
9.08M
        o += nPbH_extra;
575
9.08M
        p++;
576
9.08M
      }
577
935k
    }
578
73.8k
    break;
579
50.1k
  case 2:
580
703k
    for (int y=-extra_top;y<nPbH+extra_bottom;y++) {
581
653k
      const pixel_t* p = src + srcstride*y - extra_left;
582
653k
      inter_t* o = &mcbuffer[y+extra_top];
583
584
7.25M
      for (int x=0;x<nPbW;x++) {
585
6.59M
        *o = (-p[0]+4*p[1]-11*p[2]+40*p[3]+40*p[4]-11*p[5]+4*p[6]-p[7])>>shift1;
586
6.59M
        o += nPbH_extra;
587
6.59M
        p++;
588
6.59M
      }
589
653k
    }
590
50.1k
    break;
591
67.9k
  case 3:
592
916k
    for (int y=-extra_top;y<nPbH+extra_bottom;y++) {
593
848k
      const pixel_t* p = src + srcstride*y - extra_left;
594
848k
      inter_t* o = &mcbuffer[y+extra_top];
595
596
9.14M
      for (int x=0;x<nPbW;x++) {
597
8.30M
        *o = ( p[0]-5*p[1]+17*p[2]+58*p[3]-10*p[4] +4*p[5]  -p[6])>>shift1;
598
8.30M
        o += nPbH_extra;
599
8.30M
        p++;
600
8.30M
      }
601
848k
    }
602
67.9k
    break;
603
254k
  }
604
605
606
254k
  logtrace(LogMotion,"---H---\n");
607
608
3.61M
  for (int y=-extra_top;y<nPbH+extra_bottom;y++) {
609
36.7M
    for (int x=0;x<nPbW;x++) {
610
33.3M
      logtrace(LogMotion,"%04x ",mcbuffer[y+extra_top + x*nPbH_extra]);
611
33.3M
    }
612
3.36M
    logtrace(LogMotion,"\n");
613
3.36M
  }
614
615
  // V-filters
616
617
254k
  int vshift = (xFracL==0 ? shift1 : shift2);
618
619
254k
  switch (yFracL) {
620
57.8k
  case 0:
621
559k
    for (int x=0;x<nPbW;x++) {
622
501k
      const inter_t* p = &mcbuffer[x*nPbH_extra];
623
501k
      inter_t* o = &out[x];
624
625
5.88M
      for (int y=0;y<nPbH;y++) {
626
5.38M
        *o = *p;
627
5.38M
        o+=out_stride;
628
5.38M
        p++;
629
5.38M
      }
630
501k
    }
631
57.8k
    break;
632
81.3k
  case 1:
633
763k
    for (int x=0;x<nPbW;x++) {
634
681k
      const inter_t* p = &mcbuffer[x*nPbH_extra];
635
681k
      inter_t* o = &out[x];
636
637
7.81M
      for (int y=0;y<nPbH;y++) {
638
7.13M
        *o = (-p[0]+4*p[1]-10*p[2]+58*p[3]+17*p[4] -5*p[5]  +p[6])>>vshift;
639
7.13M
        o+=out_stride;
640
7.13M
        p++;
641
7.13M
      }
642
681k
    }
643
81.3k
    break;
644
52.0k
  case 2:
645
499k
    for (int x=0;x<nPbW;x++) {
646
447k
      const inter_t* p = &mcbuffer[x*nPbH_extra];
647
447k
      inter_t* o = &out[x];
648
649
5.16M
      for (int y=0;y<nPbH;y++) {
650
4.71M
        *o = (-p[0]+4*p[1]-11*p[2]+40*p[3]+40*p[4]-11*p[5]+4*p[6]-p[7])>>vshift;
651
4.71M
        o+=out_stride;
652
4.71M
        p++;
653
4.71M
      }
654
447k
    }
655
52.0k
    break;
656
63.2k
  case 3:
657
601k
    for (int x=0;x<nPbW;x++) {
658
537k
      const inter_t* p = &mcbuffer[x*nPbH_extra];
659
537k
      inter_t* o = &out[x];
660
661
6.20M
      for (int y=0;y<nPbH;y++) {
662
5.66M
        *o = ( p[0]-5*p[1]+17*p[2]+58*p[3]-10*p[4] +4*p[5]  -p[6])>>vshift;
663
5.66M
        o+=out_stride;
664
5.66M
        p++;
665
5.66M
      }
666
537k
    }
667
63.2k
    break;
668
254k
  }
669
670
671
254k
  logtrace(LogMotion,"---V---\n");
672
2.38M
  for (int y=0;y<nPbH;y++) {
673
25.0M
    for (int x=0;x<nPbW;x++) {
674
22.9M
      logtrace(LogMotion,"%04x ",out[x+y*out_stride]);
675
22.9M
    }
676
2.13M
    logtrace(LogMotion,"\n");
677
2.13M
  }
678
254k
}
void put_qpel_fallback<unsigned short, int>(int*, long, unsigned short const*, long, int, int, int*, int, int, int)
Line
Count
Source
536
24.3k
{
537
24.3k
  int extra_left   = extra_before[xFracL];
538
  //int extra_right  = extra_after [xFracL];
539
24.3k
  int extra_top    = extra_before[yFracL];
540
24.3k
  int extra_bottom = extra_after [yFracL];
541
542
  //int nPbW_extra = extra_left + nPbW + extra_right;
543
24.3k
  int nPbH_extra = extra_top  + nPbH + extra_bottom;
544
545
  // shift1 per HEVC v2 (10/2014) spec 8.5.3.3.3.2 (luma): Min(4, BitDepth - 8).
546
  // The Min() was added with the Range Extensions in v2 for BitDepth > 12: the
547
  // intermediate samples then keep BitDepth+2 bits instead of 14 (see shift3).
548
24.3k
  const int shift1 = std::min(4, bit_depth-8);
549
24.3k
  const int shift2 = 6;
550
551
552
  // H-filters
553
554
24.3k
  switch (xFracL) {
555
4.97k
  case 0:
556
88.8k
    for (int y=-extra_top;y<nPbH+extra_bottom;y++) {
557
83.9k
      const pixel_t* p = src + srcstride*y - extra_left;
558
83.9k
      inter_t* o = &mcbuffer[y+extra_top];
559
560
1.11M
      for (int x=0;x<nPbW;x++) {
561
1.03M
        *o = *p;
562
1.03M
        o += nPbH_extra;
563
1.03M
        p++;
564
1.03M
      }
565
83.9k
    }
566
4.97k
    break;
567
7.23k
  case 1:
568
114k
    for (int y=-extra_top;y<nPbH+extra_bottom;y++) {
569
107k
      const pixel_t* p = src + srcstride*y - extra_left;
570
107k
      inter_t* o = &mcbuffer[y+extra_top];
571
572
1.34M
      for (int x=0;x<nPbW;x++) {
573
1.23M
        *o = (-p[0]+4*p[1]-10*p[2]+58*p[3]+17*p[4] -5*p[5]  +p[6])>>shift1;
574
1.23M
        o += nPbH_extra;
575
1.23M
        p++;
576
1.23M
      }
577
107k
    }
578
7.23k
    break;
579
5.44k
  case 2:
580
84.4k
    for (int y=-extra_top;y<nPbH+extra_bottom;y++) {
581
79.0k
      const pixel_t* p = src + srcstride*y - extra_left;
582
79.0k
      inter_t* o = &mcbuffer[y+extra_top];
583
584
1.04M
      for (int x=0;x<nPbW;x++) {
585
968k
        *o = (-p[0]+4*p[1]-11*p[2]+40*p[3]+40*p[4]-11*p[5]+4*p[6]-p[7])>>shift1;
586
968k
        o += nPbH_extra;
587
968k
        p++;
588
968k
      }
589
79.0k
    }
590
5.44k
    break;
591
6.69k
  case 3:
592
107k
    for (int y=-extra_top;y<nPbH+extra_bottom;y++) {
593
100k
      const pixel_t* p = src + srcstride*y - extra_left;
594
100k
      inter_t* o = &mcbuffer[y+extra_top];
595
596
1.38M
      for (int x=0;x<nPbW;x++) {
597
1.28M
        *o = ( p[0]-5*p[1]+17*p[2]+58*p[3]-10*p[4] +4*p[5]  -p[6])>>shift1;
598
1.28M
        o += nPbH_extra;
599
1.28M
        p++;
600
1.28M
      }
601
100k
    }
602
6.69k
    break;
603
24.3k
  }
604
605
606
24.3k
  logtrace(LogMotion,"---H---\n");
607
608
395k
  for (int y=-extra_top;y<nPbH+extra_bottom;y++) {
609
4.89M
    for (int x=0;x<nPbW;x++) {
610
4.51M
      logtrace(LogMotion,"%04x ",mcbuffer[y+extra_top + x*nPbH_extra]);
611
4.51M
    }
612
370k
    logtrace(LogMotion,"\n");
613
370k
  }
614
615
  // V-filters
616
617
24.3k
  int vshift = (xFracL==0 ? shift1 : shift2);
618
619
24.3k
  switch (yFracL) {
620
5.21k
  case 0:
621
56.1k
    for (int x=0;x<nPbW;x++) {
622
50.9k
      const inter_t* p = &mcbuffer[x*nPbH_extra];
623
50.9k
      inter_t* o = &out[x];
624
625
758k
      for (int y=0;y<nPbH;y++) {
626
707k
        *o = *p;
627
707k
        o+=out_stride;
628
707k
        p++;
629
707k
      }
630
50.9k
    }
631
5.21k
    break;
632
7.46k
  case 1:
633
83.0k
    for (int x=0;x<nPbW;x++) {
634
75.6k
      const inter_t* p = &mcbuffer[x*nPbH_extra];
635
75.6k
      inter_t* o = &out[x];
636
637
1.20M
      for (int y=0;y<nPbH;y++) {
638
1.12M
        *o = (-p[0]+4*p[1]-10*p[2]+58*p[3]+17*p[4] -5*p[5]  +p[6])>>vshift;
639
1.12M
        o+=out_stride;
640
1.12M
        p++;
641
1.12M
      }
642
75.6k
    }
643
7.46k
    break;
644
5.20k
  case 2:
645
54.9k
    for (int x=0;x<nPbW;x++) {
646
49.7k
      const inter_t* p = &mcbuffer[x*nPbH_extra];
647
49.7k
      inter_t* o = &out[x];
648
649
711k
      for (int y=0;y<nPbH;y++) {
650
661k
        *o = (-p[0]+4*p[1]-11*p[2]+40*p[3]+40*p[4]-11*p[5]+4*p[6]-p[7])>>vshift;
651
661k
        o+=out_stride;
652
661k
        p++;
653
661k
      }
654
49.7k
    }
655
5.20k
    break;
656
6.47k
  case 3:
657
66.9k
    for (int x=0;x<nPbW;x++) {
658
60.4k
      const inter_t* p = &mcbuffer[x*nPbH_extra];
659
60.4k
      inter_t* o = &out[x];
660
661
917k
      for (int y=0;y<nPbH;y++) {
662
856k
        *o = ( p[0]-5*p[1]+17*p[2]+58*p[3]-10*p[4] +4*p[5]  -p[6])>>vshift;
663
856k
        o+=out_stride;
664
856k
        p++;
665
856k
      }
666
60.4k
    }
667
6.47k
    break;
668
24.3k
  }
669
670
671
24.3k
  logtrace(LogMotion,"---V---\n");
672
275k
  for (int y=0;y<nPbH;y++) {
673
3.60M
    for (int x=0;x<nPbW;x++) {
674
3.35M
      logtrace(LogMotion,"%04x ",out[x+y*out_stride]);
675
3.35M
    }
676
250k
    logtrace(LogMotion,"\n");
677
250k
  }
678
24.3k
}
void put_qpel_fallback<unsigned char, short>(short*, long, unsigned char const*, long, int, int, short*, int, int, int)
Line
Count
Source
536
136k
{
537
136k
  int extra_left   = extra_before[xFracL];
538
  //int extra_right  = extra_after [xFracL];
539
136k
  int extra_top    = extra_before[yFracL];
540
136k
  int extra_bottom = extra_after [yFracL];
541
542
  //int nPbW_extra = extra_left + nPbW + extra_right;
543
136k
  int nPbH_extra = extra_top  + nPbH + extra_bottom;
544
545
  // shift1 per HEVC v2 (10/2014) spec 8.5.3.3.3.2 (luma): Min(4, BitDepth - 8).
546
  // The Min() was added with the Range Extensions in v2 for BitDepth > 12: the
547
  // intermediate samples then keep BitDepth+2 bits instead of 14 (see shift3).
548
136k
  const int shift1 = std::min(4, bit_depth-8);
549
136k
  const int shift2 = 6;
550
551
552
  // H-filters
553
554
136k
  switch (xFracL) {
555
31.8k
  case 0:
556
491k
    for (int y=-extra_top;y<nPbH+extra_bottom;y++) {
557
459k
      const pixel_t* p = src + srcstride*y - extra_left;
558
459k
      inter_t* o = &mcbuffer[y+extra_top];
559
560
4.88M
      for (int x=0;x<nPbW;x++) {
561
4.43M
        *o = *p;
562
4.43M
        o += nPbH_extra;
563
4.43M
        p++;
564
4.43M
      }
565
459k
    }
566
31.8k
    break;
567
39.6k
  case 1:
568
533k
    for (int y=-extra_top;y<nPbH+extra_bottom;y++) {
569
494k
      const pixel_t* p = src + srcstride*y - extra_left;
570
494k
      inter_t* o = &mcbuffer[y+extra_top];
571
572
5.03M
      for (int x=0;x<nPbW;x++) {
573
4.53M
        *o = (-p[0]+4*p[1]-10*p[2]+58*p[3]+17*p[4] -5*p[5]  +p[6])>>shift1;
574
4.53M
        o += nPbH_extra;
575
4.53M
        p++;
576
4.53M
      }
577
494k
    }
578
39.6k
    break;
579
27.5k
  case 2:
580
372k
    for (int y=-extra_top;y<nPbH+extra_bottom;y++) {
581
344k
      const pixel_t* p = src + srcstride*y - extra_left;
582
344k
      inter_t* o = &mcbuffer[y+extra_top];
583
584
3.55M
      for (int x=0;x<nPbW;x++) {
585
3.21M
        *o = (-p[0]+4*p[1]-11*p[2]+40*p[3]+40*p[4]-11*p[5]+4*p[6]-p[7])>>shift1;
586
3.21M
        o += nPbH_extra;
587
3.21M
        p++;
588
3.21M
      }
589
344k
    }
590
27.5k
    break;
591
37.9k
  case 3:
592
501k
    for (int y=-extra_top;y<nPbH+extra_bottom;y++) {
593
463k
      const pixel_t* p = src + srcstride*y - extra_left;
594
463k
      inter_t* o = &mcbuffer[y+extra_top];
595
596
4.64M
      for (int x=0;x<nPbW;x++) {
597
4.18M
        *o = ( p[0]-5*p[1]+17*p[2]+58*p[3]-10*p[4] +4*p[5]  -p[6])>>shift1;
598
4.18M
        o += nPbH_extra;
599
4.18M
        p++;
600
4.18M
      }
601
463k
    }
602
37.9k
    break;
603
136k
  }
604
605
606
136k
  logtrace(LogMotion,"---H---\n");
607
608
1.89M
  for (int y=-extra_top;y<nPbH+extra_bottom;y++) {
609
18.1M
    for (int x=0;x<nPbW;x++) {
610
16.3M
      logtrace(LogMotion,"%04x ",mcbuffer[y+extra_top + x*nPbH_extra]);
611
16.3M
    }
612
1.76M
    logtrace(LogMotion,"\n");
613
1.76M
  }
614
615
  // V-filters
616
617
136k
  int vshift = (xFracL==0 ? shift1 : shift2);
618
619
136k
  switch (yFracL) {
620
30.1k
  case 0:
621
272k
    for (int x=0;x<nPbW;x++) {
622
242k
      const inter_t* p = &mcbuffer[x*nPbH_extra];
623
242k
      inter_t* o = &out[x];
624
625
2.62M
      for (int y=0;y<nPbH;y++) {
626
2.38M
        *o = *p;
627
2.38M
        o+=out_stride;
628
2.38M
        p++;
629
2.38M
      }
630
242k
    }
631
30.1k
    break;
632
42.3k
  case 1:
633
383k
    for (int x=0;x<nPbW;x++) {
634
340k
      const inter_t* p = &mcbuffer[x*nPbH_extra];
635
340k
      inter_t* o = &out[x];
636
637
3.82M
      for (int y=0;y<nPbH;y++) {
638
3.48M
        *o = (-p[0]+4*p[1]-10*p[2]+58*p[3]+17*p[4] -5*p[5]  +p[6])>>vshift;
639
3.48M
        o+=out_stride;
640
3.48M
        p++;
641
3.48M
      }
642
340k
    }
643
42.3k
    break;
644
28.3k
  case 2:
645
261k
    for (int x=0;x<nPbW;x++) {
646
233k
      const inter_t* p = &mcbuffer[x*nPbH_extra];
647
233k
      inter_t* o = &out[x];
648
649
2.49M
      for (int y=0;y<nPbH;y++) {
650
2.26M
        *o = (-p[0]+4*p[1]-11*p[2]+40*p[3]+40*p[4]-11*p[5]+4*p[6]-p[7])>>vshift;
651
2.26M
        o+=out_stride;
652
2.26M
        p++;
653
2.26M
      }
654
233k
    }
655
28.3k
    break;
656
36.0k
  case 3:
657
329k
    for (int x=0;x<nPbW;x++) {
658
292k
      const inter_t* p = &mcbuffer[x*nPbH_extra];
659
292k
      inter_t* o = &out[x];
660
661
3.08M
      for (int y=0;y<nPbH;y++) {
662
2.79M
        *o = ( p[0]-5*p[1]+17*p[2]+58*p[3]-10*p[4] +4*p[5]  -p[6])>>vshift;
663
2.79M
        o+=out_stride;
664
2.79M
        p++;
665
2.79M
      }
666
292k
    }
667
36.0k
    break;
668
136k
  }
669
670
671
136k
  logtrace(LogMotion,"---V---\n");
672
1.23M
  for (int y=0;y<nPbH;y++) {
673
12.0M
    for (int x=0;x<nPbW;x++) {
674
10.9M
      logtrace(LogMotion,"%04x ",out[x+y*out_stride]);
675
10.9M
    }
676
1.09M
    logtrace(LogMotion,"\n");
677
1.09M
  }
678
136k
}
void put_qpel_fallback<unsigned short, short>(short*, long, unsigned short const*, long, int, int, short*, int, int, int)
Line
Count
Source
536
93.1k
{
537
93.1k
  int extra_left   = extra_before[xFracL];
538
  //int extra_right  = extra_after [xFracL];
539
93.1k
  int extra_top    = extra_before[yFracL];
540
93.1k
  int extra_bottom = extra_after [yFracL];
541
542
  //int nPbW_extra = extra_left + nPbW + extra_right;
543
93.1k
  int nPbH_extra = extra_top  + nPbH + extra_bottom;
544
545
  // shift1 per HEVC v2 (10/2014) spec 8.5.3.3.3.2 (luma): Min(4, BitDepth - 8).
546
  // The Min() was added with the Range Extensions in v2 for BitDepth > 12: the
547
  // intermediate samples then keep BitDepth+2 bits instead of 14 (see shift3).
548
93.1k
  const int shift1 = std::min(4, bit_depth-8);
549
93.1k
  const int shift2 = 6;
550
551
552
  // H-filters
553
554
93.1k
  switch (xFracL) {
555
25.6k
  case 0:
556
408k
    for (int y=-extra_top;y<nPbH+extra_bottom;y++) {
557
382k
      const pixel_t* p = src + srcstride*y - extra_left;
558
382k
      inter_t* o = &mcbuffer[y+extra_top];
559
560
4.29M
      for (int x=0;x<nPbW;x++) {
561
3.90M
        *o = *p;
562
3.90M
        o += nPbH_extra;
563
3.90M
        p++;
564
3.90M
      }
565
382k
    }
566
25.6k
    break;
567
27.0k
  case 1:
568
360k
    for (int y=-extra_top;y<nPbH+extra_bottom;y++) {
569
333k
      const pixel_t* p = src + srcstride*y - extra_left;
570
333k
      inter_t* o = &mcbuffer[y+extra_top];
571
572
3.64M
      for (int x=0;x<nPbW;x++) {
573
3.31M
        *o = (-p[0]+4*p[1]-10*p[2]+58*p[3]+17*p[4] -5*p[5]  +p[6])>>shift1;
574
3.31M
        o += nPbH_extra;
575
3.31M
        p++;
576
3.31M
      }
577
333k
    }
578
27.0k
    break;
579
17.1k
  case 2:
580
246k
    for (int y=-extra_top;y<nPbH+extra_bottom;y++) {
581
229k
      const pixel_t* p = src + srcstride*y - extra_left;
582
229k
      inter_t* o = &mcbuffer[y+extra_top];
583
584
2.64M
      for (int x=0;x<nPbW;x++) {
585
2.41M
        *o = (-p[0]+4*p[1]-11*p[2]+40*p[3]+40*p[4]-11*p[5]+4*p[6]-p[7])>>shift1;
586
2.41M
        o += nPbH_extra;
587
2.41M
        p++;
588
2.41M
      }
589
229k
    }
590
17.1k
    break;
591
23.2k
  case 3:
592
307k
    for (int y=-extra_top;y<nPbH+extra_bottom;y++) {
593
283k
      const pixel_t* p = src + srcstride*y - extra_left;
594
283k
      inter_t* o = &mcbuffer[y+extra_top];
595
596
3.12M
      for (int x=0;x<nPbW;x++) {
597
2.83M
        *o = ( p[0]-5*p[1]+17*p[2]+58*p[3]-10*p[4] +4*p[5]  -p[6])>>shift1;
598
2.83M
        o += nPbH_extra;
599
2.83M
        p++;
600
2.83M
      }
601
283k
    }
602
23.2k
    break;
603
93.1k
  }
604
605
606
93.1k
  logtrace(LogMotion,"---H---\n");
607
608
1.32M
  for (int y=-extra_top;y<nPbH+extra_bottom;y++) {
609
13.7M
    for (int x=0;x<nPbW;x++) {
610
12.4M
      logtrace(LogMotion,"%04x ",mcbuffer[y+extra_top + x*nPbH_extra]);
611
12.4M
    }
612
1.22M
    logtrace(LogMotion,"\n");
613
1.22M
  }
614
615
  // V-filters
616
617
93.1k
  int vshift = (xFracL==0 ? shift1 : shift2);
618
619
93.1k
  switch (yFracL) {
620
22.4k
  case 0:
621
230k
    for (int x=0;x<nPbW;x++) {
622
208k
      const inter_t* p = &mcbuffer[x*nPbH_extra];
623
208k
      inter_t* o = &out[x];
624
625
2.50M
      for (int y=0;y<nPbH;y++) {
626
2.29M
        *o = *p;
627
2.29M
        o+=out_stride;
628
2.29M
        p++;
629
2.29M
      }
630
208k
    }
631
22.4k
    break;
632
31.5k
  case 1:
633
296k
    for (int x=0;x<nPbW;x++) {
634
265k
      const inter_t* p = &mcbuffer[x*nPbH_extra];
635
265k
      inter_t* o = &out[x];
636
637
2.79M
      for (int y=0;y<nPbH;y++) {
638
2.52M
        *o = (-p[0]+4*p[1]-10*p[2]+58*p[3]+17*p[4] -5*p[5]  +p[6])>>vshift;
639
2.52M
        o+=out_stride;
640
2.52M
        p++;
641
2.52M
      }
642
265k
    }
643
31.5k
    break;
644
18.4k
  case 2:
645
182k
    for (int x=0;x<nPbW;x++) {
646
164k
      const inter_t* p = &mcbuffer[x*nPbH_extra];
647
164k
      inter_t* o = &out[x];
648
649
1.96M
      for (int y=0;y<nPbH;y++) {
650
1.79M
        *o = (-p[0]+4*p[1]-11*p[2]+40*p[3]+40*p[4]-11*p[5]+4*p[6]-p[7])>>vshift;
651
1.79M
        o+=out_stride;
652
1.79M
        p++;
653
1.79M
      }
654
164k
    }
655
18.4k
    break;
656
20.6k
  case 3:
657
205k
    for (int x=0;x<nPbW;x++) {
658
184k
      const inter_t* p = &mcbuffer[x*nPbH_extra];
659
184k
      inter_t* o = &out[x];
660
661
2.19M
      for (int y=0;y<nPbH;y++) {
662
2.01M
        *o = ( p[0]-5*p[1]+17*p[2]+58*p[3]-10*p[4] +4*p[5]  -p[6])>>vshift;
663
2.01M
        o+=out_stride;
664
2.01M
        p++;
665
2.01M
      }
666
184k
    }
667
20.6k
    break;
668
93.1k
  }
669
670
671
93.1k
  logtrace(LogMotion,"---V---\n");
672
880k
  for (int y=0;y<nPbH;y++) {
673
9.41M
    for (int x=0;x<nPbW;x++) {
674
8.62M
      logtrace(LogMotion,"%04x ",out[x+y*out_stride]);
675
8.62M
    }
676
787k
    logtrace(LogMotion,"\n");
677
787k
  }
678
93.1k
}
679
680
681
682
#define QPEL(x,y) void put_qpel_ ## x ## _ ## y ## _fallback(int16_t *out, ptrdiff_t out_stride,    \
683
                                                             const uint8_t *src, ptrdiff_t srcstride, \
684
                                                             int nPbW, int nPbH, int16_t* mcbuffer) \
685
136k
  { put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, 8 ); }
put_qpel_0_1_fallback(short*, long, unsigned char const*, long, int, int, short*)
Line
Count
Source
685
14.3k
  { put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, 8 ); }
put_qpel_0_2_fallback(short*, long, unsigned char const*, long, int, int, short*)
Line
Count
Source
685
8.27k
  { put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, 8 ); }
put_qpel_0_3_fallback(short*, long, unsigned char const*, long, int, int, short*)
Line
Count
Source
685
9.23k
  { put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, 8 ); }
put_qpel_1_0_fallback(short*, long, unsigned char const*, long, int, int, short*)
Line
Count
Source
685
10.4k
  { put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, 8 ); }
put_qpel_1_1_fallback(short*, long, unsigned char const*, long, int, int, short*)
Line
Count
Source
685
14.0k
  { put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, 8 ); }
put_qpel_1_2_fallback(short*, long, unsigned char const*, long, int, int, short*)
Line
Count
Source
685
5.71k
  { put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, 8 ); }
put_qpel_1_3_fallback(short*, long, unsigned char const*, long, int, int, short*)
Line
Count
Source
685
9.43k
  { put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, 8 ); }
put_qpel_2_0_fallback(short*, long, unsigned char const*, long, int, int, short*)
Line
Count
Source
685
7.52k
  { put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, 8 ); }
put_qpel_2_1_fallback(short*, long, unsigned char const*, long, int, int, short*)
Line
Count
Source
685
4.93k
  { put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, 8 ); }
put_qpel_2_2_fallback(short*, long, unsigned char const*, long, int, int, short*)
Line
Count
Source
685
9.48k
  { put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, 8 ); }
put_qpel_2_3_fallback(short*, long, unsigned char const*, long, int, int, short*)
Line
Count
Source
685
5.58k
  { put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, 8 ); }
put_qpel_3_0_fallback(short*, long, unsigned char const*, long, int, int, short*)
Line
Count
Source
685
12.1k
  { put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, 8 ); }
put_qpel_3_1_fallback(short*, long, unsigned char const*, long, int, int, short*)
Line
Count
Source
685
9.09k
  { put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, 8 ); }
put_qpel_3_2_fallback(short*, long, unsigned char const*, long, int, int, short*)
Line
Count
Source
685
4.89k
  { put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, 8 ); }
put_qpel_3_3_fallback(short*, long, unsigned char const*, long, int, int, short*)
Line
Count
Source
685
11.8k
  { put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, 8 ); }
686
687
688
// The int32_t variant (BitDepth > 12) is not performance critical: one generic
689
// kernel for all fractional positions instead of 16 specialized copies.
690
void put_qpel_fallback_16_32(int32_t *out, ptrdiff_t out_stride,
691
                             const uint16_t *src, ptrdiff_t srcstride,
692
                             int nPbW, int nPbH, int32_t* mcbuffer,
693
                             int xFracL, int yFracL, int bit_depth)
694
54.4k
{
695
54.4k
  if (xFracL==0 && yFracL==0) {
696
30.1k
    put_qpel_0_0_fallback_16(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer, bit_depth);
697
30.1k
  }
698
24.3k
  else {
699
24.3k
    put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer, xFracL,yFracL, bit_depth);
700
24.3k
  }
701
54.4k
}
702
703
#define QPEL16(x,y) void put_qpel_ ## x ## _ ## y ## _fallback_16(int16_t *out, ptrdiff_t out_stride,    \
704
                                                                  const uint16_t *src, ptrdiff_t srcstride, \
705
93.1k
                                                                  int nPbW, int nPbH, int16_t* mcbuffer, int bit_depth) \
706
93.1k
{ put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, bit_depth ); }
put_qpel_0_1_fallback_16(short*, long, unsigned short const*, long, int, int, short*, int)
Line
Count
Source
705
12.9k
                                                                  int nPbW, int nPbH, int16_t* mcbuffer, int bit_depth) \
706
12.9k
{ put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, bit_depth ); }
put_qpel_0_2_fallback_16(short*, long, unsigned short const*, long, int, int, short*, int)
Line
Count
Source
705
5.46k
                                                                  int nPbW, int nPbH, int16_t* mcbuffer, int bit_depth) \
706
5.46k
{ put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, bit_depth ); }
put_qpel_0_3_fallback_16(short*, long, unsigned short const*, long, int, int, short*, int)
Line
Count
Source
705
7.27k
                                                                  int nPbW, int nPbH, int16_t* mcbuffer, int bit_depth) \
706
7.27k
{ put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, bit_depth ); }
put_qpel_1_0_fallback_16(short*, long, unsigned short const*, long, int, int, short*, int)
Line
Count
Source
705
9.67k
                                                                  int nPbW, int nPbH, int16_t* mcbuffer, int bit_depth) \
706
9.67k
{ put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, bit_depth ); }
put_qpel_1_1_fallback_16(short*, long, unsigned short const*, long, int, int, short*, int)
Line
Count
Source
705
9.40k
                                                                  int nPbW, int nPbH, int16_t* mcbuffer, int bit_depth) \
706
9.40k
{ put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, bit_depth ); }
put_qpel_1_2_fallback_16(short*, long, unsigned short const*, long, int, int, short*, int)
Line
Count
Source
705
3.31k
                                                                  int nPbW, int nPbH, int16_t* mcbuffer, int bit_depth) \
706
3.31k
{ put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, bit_depth ); }
put_qpel_1_3_fallback_16(short*, long, unsigned short const*, long, int, int, short*, int)
Line
Count
Source
705
4.63k
                                                                  int nPbW, int nPbH, int16_t* mcbuffer, int bit_depth) \
706
4.63k
{ put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, bit_depth ); }
put_qpel_2_0_fallback_16(short*, long, unsigned short const*, long, int, int, short*, int)
Line
Count
Source
705
4.90k
                                                                  int nPbW, int nPbH, int16_t* mcbuffer, int bit_depth) \
706
4.90k
{ put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, bit_depth ); }
put_qpel_2_1_fallback_16(short*, long, unsigned short const*, long, int, int, short*, int)
Line
Count
Source
705
3.34k
                                                                  int nPbW, int nPbH, int16_t* mcbuffer, int bit_depth) \
706
3.34k
{ put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, bit_depth ); }
put_qpel_2_2_fallback_16(short*, long, unsigned short const*, long, int, int, short*, int)
Line
Count
Source
705
6.25k
                                                                  int nPbW, int nPbH, int16_t* mcbuffer, int bit_depth) \
706
6.25k
{ put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, bit_depth ); }
put_qpel_2_3_fallback_16(short*, long, unsigned short const*, long, int, int, short*, int)
Line
Count
Source
705
2.63k
                                                                  int nPbW, int nPbH, int16_t* mcbuffer, int bit_depth) \
706
2.63k
{ put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, bit_depth ); }
put_qpel_3_0_fallback_16(short*, long, unsigned short const*, long, int, int, short*, int)
Line
Count
Source
705
7.89k
                                                                  int nPbW, int nPbH, int16_t* mcbuffer, int bit_depth) \
706
7.89k
{ put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, bit_depth ); }
put_qpel_3_1_fallback_16(short*, long, unsigned short const*, long, int, int, short*, int)
Line
Count
Source
705
5.85k
                                                                  int nPbW, int nPbH, int16_t* mcbuffer, int bit_depth) \
706
5.85k
{ put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, bit_depth ); }
put_qpel_3_2_fallback_16(short*, long, unsigned short const*, long, int, int, short*, int)
Line
Count
Source
705
3.40k
                                                                  int nPbW, int nPbH, int16_t* mcbuffer, int bit_depth) \
706
3.40k
{ put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, bit_depth ); }
put_qpel_3_3_fallback_16(short*, long, unsigned short const*, long, int, int, short*, int)
Line
Count
Source
705
6.10k
                                                                  int nPbW, int nPbH, int16_t* mcbuffer, int bit_depth) \
706
6.10k
{ put_qpel_fallback(out,out_stride, src,srcstride, nPbW,nPbH,mcbuffer,x,y, bit_depth ); }
707
708
/*     */ QPEL(0,1) QPEL(0,2) QPEL(0,3)
709
QPEL(1,0) QPEL(1,1) QPEL(1,2) QPEL(1,3)
710
QPEL(2,0) QPEL(2,1) QPEL(2,2) QPEL(2,3)
711
QPEL(3,0) QPEL(3,1) QPEL(3,2) QPEL(3,3)
712
713
/*       */ QPEL16(0,1) QPEL16(0,2) QPEL16(0,3)
714
QPEL16(1,0) QPEL16(1,1) QPEL16(1,2) QPEL16(1,3)
715
QPEL16(2,0) QPEL16(2,1) QPEL16(2,2) QPEL16(2,3)
716
QPEL16(3,0) QPEL16(3,1) QPEL16(3,2) QPEL16(3,3)