GCC Code Coverage Report
Directory: ../../../ffmpeg/ Exec Total Coverage
File: src/libavcodec/hevcdsp_template.c Lines: 886 886 100.0 %
Date: 2019-11-20 04:07:19 Branches: 496 512 96.9 %

Line Branch Exec Source
1
/*
2
 * HEVC video decoder
3
 *
4
 * Copyright (C) 2012 - 2013 Guillaume Martres
5
 *
6
 * This file is part of FFmpeg.
7
 *
8
 * FFmpeg is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * FFmpeg is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with FFmpeg; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 */
22
23
#include "get_bits.h"
24
#include "hevcdec.h"
25
26
#include "bit_depth_template.c"
27
#include "hevcdsp.h"
28
29
37251
static void FUNC(put_pcm)(uint8_t *_dst, ptrdiff_t stride, int width, int height,
30
                          GetBitContext *gb, int pcm_bit_depth)
31
{
32
    int x, y;
33
37251
    pixel *dst = (pixel *)_dst;
34
35
37251
    stride /= sizeof(pixel);
36
37
364195
    for (y = 0; y < height; y++) {
38
4704544
        for (x = 0; x < width; x++)
39
4377600
            dst[x] = get_bits(gb, pcm_bit_depth) << (BIT_DEPTH - pcm_bit_depth);
40
326944
        dst += stride;
41
    }
42
37251
}
43
44
10906094
static av_always_inline void FUNC(add_residual)(uint8_t *_dst, int16_t *res,
45
                                                ptrdiff_t stride, int size)
46
{
47
    int x, y;
48
10906094
    pixel *dst = (pixel *)_dst;
49
50
10906094
    stride /= sizeof(pixel);
51
52
95883638
    for (y = 0; y < size; y++) {
53
1220482664
        for (x = 0; x < size; x++) {
54
1135505120
            dst[x] = av_clip_pixel(dst[x] + *res);
55
1135505120
            res++;
56
        }
57
84977544
        dst += stride;
58
    }
59
10906094
}
60
61
6215222
static void FUNC(add_residual4x4)(uint8_t *_dst, int16_t *res,
62
                                  ptrdiff_t stride)
63
{
64
6215222
    FUNC(add_residual)(_dst, res, stride, 4);
65
6215222
}
66
67
2875982
static void FUNC(add_residual8x8)(uint8_t *_dst, int16_t *res,
68
                                  ptrdiff_t stride)
69
{
70
2875982
    FUNC(add_residual)(_dst, res, stride, 8);
71
2875982
}
72
73
1310480
static void FUNC(add_residual16x16)(uint8_t *_dst, int16_t *res,
74
                                    ptrdiff_t stride)
75
{
76
1310480
    FUNC(add_residual)(_dst, res, stride, 16);
77
1310480
}
78
79
504410
static void FUNC(add_residual32x32)(uint8_t *_dst, int16_t *res,
80
                                    ptrdiff_t stride)
81
{
82
504410
    FUNC(add_residual)(_dst, res, stride, 32);
83
504410
}
84
85
12814
static void FUNC(transform_rdpcm)(int16_t *_coeffs, int16_t log2_size, int mode)
86
{
87
12814
    int16_t *coeffs = (int16_t *) _coeffs;
88
    int x, y;
89
12814
    int size = 1 << log2_size;
90
91
12814
    if (mode) {
92
6250
        coeffs += size;
93
50588
        for (y = 0; y < size - 1; y++) {
94
514278
            for (x = 0; x < size; x++)
95
469940
                coeffs[x] += coeffs[x - size];
96
44338
            coeffs += size;
97
        }
98
    } else {
99
61492
        for (y = 0; y < size; y++) {
100
676896
            for (x = 1; x < size; x++)
101
621968
                coeffs[x] += coeffs[x - 1];
102
54928
            coeffs += size;
103
        }
104
    }
105
12814
}
106
107
265848
static void FUNC(dequant)(int16_t *coeffs, int16_t log2_size)
108
{
109
265848
    int shift  = 15 - BIT_DEPTH - log2_size;
110
    int x, y;
111
265848
    int size = 1 << log2_size;
112
113
265848
    if (shift > 0) {
114
265848
        int offset = 1 << (shift - 1);
115
1402952
        for (y = 0; y < size; y++) {
116
6708464
            for (x = 0; x < size; x++) {
117
5571360
                *coeffs = (*coeffs + offset) >> shift;
118
5571360
                coeffs++;
119
            }
120
        }
121
    } else {
122
84278
        for (y = 0; y < size; y++) {
123
688496
            for (x = 0; x < size; x++) {
124
613504
                *coeffs = *(uint16_t*)coeffs << -shift;
125
613504
                coeffs++;
126
            }
127
        }
128
    }
129
265848
}
130
131
#define SET(dst, x)   (dst) = (x)
132
#define SCALE(dst, x) (dst) = av_clip_int16(((x) + add) >> shift)
133
134
#define TR_4x4_LUMA(dst, src, step, assign)                             \
135
    do {                                                                \
136
        int c0 = src[0 * step] + src[2 * step];                         \
137
        int c1 = src[2 * step] + src[3 * step];                         \
138
        int c2 = src[0 * step] - src[3 * step];                         \
139
        int c3 = 74 * src[1 * step];                                    \
140
                                                                        \
141
        assign(dst[2 * step], 74 * (src[0 * step] -                     \
142
                                    src[2 * step] +                     \
143
                                    src[3 * step]));                    \
144
        assign(dst[0 * step], 29 * c0 + 55 * c1 + c3);                  \
145
        assign(dst[1 * step], 55 * c2 - 29 * c1 + c3);                  \
146
        assign(dst[3 * step], 55 * c0 + 29 * c2 - c3);                  \
147
    } while (0)
148
149
3124664
static void FUNC(transform_4x4_luma)(int16_t *coeffs)
150
{
151
    int i;
152
3124664
    int shift    = 7;
153
3124664
    int add      = 1 << (shift - 1);
154
3124664
    int16_t *src = coeffs;
155
156
15623320
    for (i = 0; i < 4; i++) {
157
12498656
        TR_4x4_LUMA(src, src, 4, SCALE);
158
12498656
        src++;
159
    }
160
161
3124664
    shift = 20 - BIT_DEPTH;
162
3124664
    add   = 1 << (shift - 1);
163
15623320
    for (i = 0; i < 4; i++) {
164
12498656
        TR_4x4_LUMA(coeffs, coeffs, 1, SCALE);
165
12498656
        coeffs += 4;
166
    }
167
3124664
}
168
169
#undef TR_4x4_LUMA
170
171
#define TR_4(dst, src, dstep, sstep, assign, end)                 \
172
    do {                                                          \
173
        const int e0 = 64 * src[0 * sstep] + 64 * src[2 * sstep]; \
174
        const int e1 = 64 * src[0 * sstep] - 64 * src[2 * sstep]; \
175
        const int o0 = 83 * src[1 * sstep] + 36 * src[3 * sstep]; \
176
        const int o1 = 36 * src[1 * sstep] - 83 * src[3 * sstep]; \
177
                                                                  \
178
        assign(dst[0 * dstep], e0 + o0);                          \
179
        assign(dst[1 * dstep], e1 + o1);                          \
180
        assign(dst[2 * dstep], e1 - o1);                          \
181
        assign(dst[3 * dstep], e0 - o0);                          \
182
    } while (0)
183
184
#define TR_8(dst, src, dstep, sstep, assign, end)                 \
185
    do {                                                          \
186
        int i, j;                                                 \
187
        int e_8[4];                                               \
188
        int o_8[4] = { 0 };                                       \
189
        for (i = 0; i < 4; i++)                                   \
190
            for (j = 1; j < end; j += 2)                          \
191
                o_8[i] += transform[4 * j][i] * src[j * sstep];   \
192
        TR_4(e_8, src, 1, 2 * sstep, SET, 4);                     \
193
                                                                  \
194
        for (i = 0; i < 4; i++) {                                 \
195
            assign(dst[i * dstep], e_8[i] + o_8[i]);              \
196
            assign(dst[(7 - i) * dstep], e_8[i] - o_8[i]);        \
197
        }                                                         \
198
    } while (0)
199
200
#define TR_16(dst, src, dstep, sstep, assign, end)                \
201
    do {                                                          \
202
        int i, j;                                                 \
203
        int e_16[8];                                              \
204
        int o_16[8] = { 0 };                                      \
205
        for (i = 0; i < 8; i++)                                   \
206
            for (j = 1; j < end; j += 2)                          \
207
                o_16[i] += transform[2 * j][i] * src[j * sstep];  \
208
        TR_8(e_16, src, 1, 2 * sstep, SET, 8);                    \
209
                                                                  \
210
        for (i = 0; i < 8; i++) {                                 \
211
            assign(dst[i * dstep], e_16[i] + o_16[i]);            \
212
            assign(dst[(15 - i) * dstep], e_16[i] - o_16[i]);     \
213
        }                                                         \
214
    } while (0)
215
216
#define TR_32(dst, src, dstep, sstep, assign, end)                \
217
    do {                                                          \
218
        int i, j;                                                 \
219
        int e_32[16];                                             \
220
        int o_32[16] = { 0 };                                     \
221
        for (i = 0; i < 16; i++)                                  \
222
            for (j = 1; j < end; j += 2)                          \
223
                o_32[i] += transform[j][i] * src[j * sstep];      \
224
        TR_16(e_32, src, 1, 2 * sstep, SET, end / 2);             \
225
                                                                  \
226
        for (i = 0; i < 16; i++) {                                \
227
            assign(dst[i * dstep], e_32[i] + o_32[i]);            \
228
            assign(dst[(31 - i) * dstep], e_32[i] - o_32[i]);     \
229
        }                                                         \
230
    } while (0)
231
232
#define IDCT_VAR4(H)                                              \
233
    int limit2 = FFMIN(col_limit + 4, H)
234
#define IDCT_VAR8(H)                                              \
235
    int limit  = FFMIN(col_limit, H);                             \
236
    int limit2 = FFMIN(col_limit + 4, H)
237
#define IDCT_VAR16(H)   IDCT_VAR8(H)
238
#define IDCT_VAR32(H)   IDCT_VAR8(H)
239
240
#define IDCT(H)                                                   \
241
static void FUNC(idct_ ## H ## x ## H )(int16_t *coeffs,          \
242
                                        int col_limit)            \
243
{                                                                 \
244
    int i;                                                        \
245
    int      shift = 7;                                           \
246
    int      add   = 1 << (shift - 1);                            \
247
    int16_t *src   = coeffs;                                      \
248
    IDCT_VAR ## H(H);                                             \
249
                                                                  \
250
    for (i = 0; i < H; i++) {                                     \
251
        TR_ ## H(src, src, H, H, SCALE, limit2);                  \
252
        if (limit2 < H && i%4 == 0 && !!i)                        \
253
            limit2 -= 4;                                          \
254
        src++;                                                    \
255
    }                                                             \
256
                                                                  \
257
    shift = 20 - BIT_DEPTH;                                       \
258
    add   = 1 << (shift - 1);                                     \
259
    for (i = 0; i < H; i++) {                                     \
260
        TR_ ## H(coeffs, coeffs, 1, 1, SCALE, limit);             \
261
        coeffs += H;                                              \
262
    }                                                             \
263
}
264
265
#define IDCT_DC(H)                                                \
266
static void FUNC(idct_ ## H ## x ## H ## _dc)(int16_t *coeffs)    \
267
{                                                                 \
268
    int i, j;                                                     \
269
    int shift = 14 - BIT_DEPTH;                                   \
270
    int add   = 1 << (shift - 1);                                 \
271
    int coeff = (((coeffs[0] + 1) >> 1) + add) >> shift;          \
272
                                                                  \
273
    for (j = 0; j < H; j++) {                                     \
274
        for (i = 0; i < H; i++) {                                 \
275
            coeffs[i + j * H] = coeff;                            \
276
        }                                                         \
277
    }                                                             \
278
}
279
280


14092785
IDCT( 4)
281





788170469
IDCT( 8)
282








2395094178
IDCT(16)
283











4848447778
IDCT(32)
284
285

17705100
IDCT_DC( 4)
286

47622937
IDCT_DC( 8)
287

63539112
IDCT_DC(16)
288

73195136
IDCT_DC(32)
289
290
#undef TR_4
291
#undef TR_8
292
#undef TR_16
293
#undef TR_32
294
295
#undef SET
296
#undef SCALE
297
298
107695
static void FUNC(sao_band_filter)(uint8_t *_dst, uint8_t *_src,
299
                                  ptrdiff_t stride_dst, ptrdiff_t stride_src,
300
                                  int16_t *sao_offset_val, int sao_left_class,
301
                                  int width, int height)
302
{
303
107695
    pixel *dst = (pixel *)_dst;
304
107695
    pixel *src = (pixel *)_src;
305
107695
    int offset_table[32] = { 0 };
306
    int k, y, x;
307
107695
    int shift  = BIT_DEPTH - 5;
308
309
107695
    stride_dst /= sizeof(pixel);
310
107695
    stride_src /= sizeof(pixel);
311
312
538475
    for (k = 0; k < 4; k++)
313
430780
        offset_table[(k + sao_left_class) & 31] = sao_offset_val[k + 1];
314
4084463
    for (y = 0; y < height; y++) {
315
198489216
        for (x = 0; x < width; x++)
316
194512448
            dst[x] = av_clip_pixel(src[x] + offset_table[src[x] >> shift]);
317
3976768
        dst += stride_dst;
318
3976768
        src += stride_src;
319
    }
320
107695
}
321
322
#define CMP(a, b) (((a) > (b)) - ((a) < (b)))
323
324
313150
static void FUNC(sao_edge_filter)(uint8_t *_dst, uint8_t *_src, ptrdiff_t stride_dst, int16_t *sao_offset_val,
325
                                  int eo, int width, int height) {
326
327
    static const uint8_t edge_idx[] = { 1, 2, 0, 3, 4 };
328
    static const int8_t pos[4][2][2] = {
329
        { { -1,  0 }, {  1, 0 } }, // horizontal
330
        { {  0, -1 }, {  0, 1 } }, // vertical
331
        { { -1, -1 }, {  1, 1 } }, // 45 degree
332
        { {  1, -1 }, { -1, 1 } }, // 135 degree
333
    };
334
313150
    pixel *dst = (pixel *)_dst;
335
313150
    pixel *src = (pixel *)_src;
336
    int a_stride, b_stride;
337
    int x, y;
338
313150
    ptrdiff_t stride_src = (2*MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) / sizeof(pixel);
339
313150
    stride_dst /= sizeof(pixel);
340
341
313150
    a_stride = pos[eo][0][0] + pos[eo][0][1] * stride_src;
342
313150
    b_stride = pos[eo][1][0] + pos[eo][1][1] * stride_src;
343
15780662
    for (y = 0; y < height; y++) {
344
879798328
        for (x = 0; x < width; x++) {
345
864330816
            int diff0 = CMP(src[x], src[x + a_stride]);
346
864330816
            int diff1 = CMP(src[x], src[x + b_stride]);
347
864330816
            int offset_val        = edge_idx[2 + diff0 + diff1];
348
864330816
            dst[x] = av_clip_pixel(src[x] + sao_offset_val[offset_val]);
349
        }
350
15467512
        src += stride_src;
351
15467512
        dst += stride_dst;
352
    }
353
313150
}
354
355
297699
static void FUNC(sao_edge_restore_0)(uint8_t *_dst, uint8_t *_src,
356
                                    ptrdiff_t stride_dst, ptrdiff_t stride_src, SAOParams *sao,
357
                                    int *borders, int _width, int _height,
358
                                    int c_idx, uint8_t *vert_edge,
359
                                    uint8_t *horiz_edge, uint8_t *diag_edge)
360
{
361
    int x, y;
362
297699
    pixel *dst = (pixel *)_dst;
363
297699
    pixel *src = (pixel *)_src;
364
297699
    int16_t *sao_offset_val = sao->offset_val[c_idx];
365
297699
    int sao_eo_class    = sao->eo_class[c_idx];
366
297699
    int init_x = 0, width = _width, height = _height;
367
368
297699
    stride_dst /= sizeof(pixel);
369
297699
    stride_src /= sizeof(pixel);
370
371
297699
    if (sao_eo_class != SAO_EO_VERT) {
372
241033
        if (borders[0]) {
373
11818
            int offset_val = sao_offset_val[0];
374
582938
            for (y = 0; y < height; y++) {
375
571120
                dst[y * stride_dst] = av_clip_pixel(src[y * stride_src] + offset_val);
376
            }
377
11818
            init_x = 1;
378
        }
379
241033
        if (borders[2]) {
380
12546
            int offset_val = sao_offset_val[0];
381
12546
            int offset     = width - 1;
382
612370
            for (x = 0; x < height; x++) {
383
599824
                dst[x * stride_dst + offset] = av_clip_pixel(src[x * stride_src + offset] + offset_val);
384
            }
385
12546
            width--;
386
        }
387
    }
388
297699
    if (sao_eo_class != SAO_EO_HORIZ) {
389
252029
        if (borders[1]) {
390
16210
            int offset_val = sao_offset_val[0];
391
809969
            for (x = init_x; x < width; x++)
392
793759
                dst[x] = av_clip_pixel(src[x] + offset_val);
393
        }
394
252029
        if (borders[3]) {
395
21248
            int offset_val   = sao_offset_val[0];
396
21248
            ptrdiff_t y_stride_dst = stride_dst * (height - 1);
397
21248
            ptrdiff_t y_stride_src = stride_src * (height - 1);
398
1031076
            for (x = init_x; x < width; x++)
399
1009828
                dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val);
400
21248
            height--;
401
        }
402
    }
403
297699
}
404
405
16894
static void FUNC(sao_edge_restore_1)(uint8_t *_dst, uint8_t *_src,
406
                                    ptrdiff_t stride_dst, ptrdiff_t stride_src, SAOParams *sao,
407
                                    int *borders, int _width, int _height,
408
                                    int c_idx, uint8_t *vert_edge,
409
                                    uint8_t *horiz_edge, uint8_t *diag_edge)
410
{
411
    int x, y;
412
16894
    pixel *dst = (pixel *)_dst;
413
16894
    pixel *src = (pixel *)_src;
414
16894
    int16_t *sao_offset_val = sao->offset_val[c_idx];
415
16894
    int sao_eo_class    = sao->eo_class[c_idx];
416
16894
    int init_x = 0, init_y = 0, width = _width, height = _height;
417
418
16894
    stride_dst /= sizeof(pixel);
419
16894
    stride_src /= sizeof(pixel);
420
421
16894
    if (sao_eo_class != SAO_EO_VERT) {
422
11871
        if (borders[0]) {
423
1098
            int offset_val = sao_offset_val[0];
424
54714
            for (y = 0; y < height; y++) {
425
53616
                dst[y * stride_dst] = av_clip_pixel(src[y * stride_src] + offset_val);
426
            }
427
1098
            init_x = 1;
428
        }
429
11871
        if (borders[2]) {
430
662
            int offset_val = sao_offset_val[0];
431
662
            int offset     = width - 1;
432
31182
            for (x = 0; x < height; x++) {
433
30520
                dst[x * stride_dst + offset] = av_clip_pixel(src[x * stride_src + offset] + offset_val);
434
            }
435
662
            width--;
436
        }
437
    }
438
16894
    if (sao_eo_class != SAO_EO_HORIZ) {
439
11898
        if (borders[1]) {
440
1585
            int offset_val = sao_offset_val[0];
441
77962
            for (x = init_x; x < width; x++)
442
76377
                dst[x] = av_clip_pixel(src[x] + offset_val);
443
1585
            init_y = 1;
444
        }
445
11898
        if (borders[3]) {
446
1290
            int offset_val   = sao_offset_val[0];
447
1290
            ptrdiff_t y_stride_dst = stride_dst * (height - 1);
448
1290
            ptrdiff_t y_stride_src = stride_src * (height - 1);
449
60233
            for (x = init_x; x < width; x++)
450
58943
                dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val);
451
1290
            height--;
452
        }
453
    }
454
455
    {
456


16894
        int save_upper_left  = !diag_edge[0] && sao_eo_class == SAO_EO_135D && !borders[0] && !borders[1];
457


16894
        int save_upper_right = !diag_edge[1] && sao_eo_class == SAO_EO_45D  && !borders[1] && !borders[2];
458


16894
        int save_lower_right = !diag_edge[2] && sao_eo_class == SAO_EO_135D && !borders[2] && !borders[3];
459


16894
        int save_lower_left  = !diag_edge[3] && sao_eo_class == SAO_EO_45D  && !borders[0] && !borders[3];
460
461
        // Restore pixels that can't be modified
462

16894
        if(vert_edge[0] && sao_eo_class != SAO_EO_VERT) {
463
1254
            for(y = init_y+save_upper_left; y< height-save_lower_left; y++)
464
1216
                dst[y*stride_dst] = src[y*stride_src];
465
        }
466

16894
        if(vert_edge[1] && sao_eo_class != SAO_EO_VERT) {
467
2904
            for(y = init_y+save_upper_right; y< height-save_lower_right; y++)
468
2812
                dst[y*stride_dst+width-1] = src[y*stride_src+width-1];
469
        }
470
471

16894
        if(horiz_edge[0] && sao_eo_class != SAO_EO_HORIZ) {
472
3816
            for(x = init_x+save_upper_left; x < width-save_upper_right; x++)
473
3700
                dst[x] = src[x];
474
        }
475

16894
        if(horiz_edge[1] && sao_eo_class != SAO_EO_HORIZ) {
476
5922
            for(x = init_x+save_lower_left; x < width-save_lower_right; x++)
477
5742
                dst[(height-1)*stride_dst+x] = src[(height-1)*stride_src+x];
478
        }
479

16894
        if(diag_edge[0] && sao_eo_class == SAO_EO_135D)
480
56
            dst[0] = src[0];
481

16894
        if(diag_edge[1] && sao_eo_class == SAO_EO_45D)
482
106
            dst[width-1] = src[width-1];
483

16894
        if(diag_edge[2] && sao_eo_class == SAO_EO_135D)
484
108
            dst[stride_dst*(height-1)+width-1] = src[stride_src*(height-1)+width-1];
485

16894
        if(diag_edge[3] && sao_eo_class == SAO_EO_45D)
486
84
            dst[stride_dst*(height-1)] = src[stride_src*(height-1)];
487
488
    }
489
16894
}
490
491
#undef CMP
492
493
////////////////////////////////////////////////////////////////////////////////
494
//
495
////////////////////////////////////////////////////////////////////////////////
496
2135131
static void FUNC(put_hevc_pel_pixels)(int16_t *dst,
497
                                      uint8_t *_src, ptrdiff_t _srcstride,
498
                                      int height, intptr_t mx, intptr_t my, int width)
499
{
500
    int x, y;
501
2135131
    pixel *src          = (pixel *)_src;
502
2135131
    ptrdiff_t srcstride = _srcstride / sizeof(pixel);
503
504
34008623
    for (y = 0; y < height; y++) {
505
874728532
        for (x = 0; x < width; x++)
506
842855040
            dst[x] = src[x] << (14 - BIT_DEPTH);
507
31873492
        src += srcstride;
508
31873492
        dst += MAX_PB_SIZE;
509
    }
510
2135131
}
511
512
2216719
static void FUNC(put_hevc_pel_uni_pixels)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
513
                                          int height, intptr_t mx, intptr_t my, int width)
514
{
515
    int y;
516
2216719
    pixel *src          = (pixel *)_src;
517
2216719
    ptrdiff_t srcstride = _srcstride / sizeof(pixel);
518
2216719
    pixel *dst          = (pixel *)_dst;
519
2216719
    ptrdiff_t dststride = _dststride / sizeof(pixel);
520
521
26206207
    for (y = 0; y < height; y++) {
522
23989488
        memcpy(dst, src, width * sizeof(pixel));
523
23989488
        src += srcstride;
524
23989488
        dst += dststride;
525
    }
526
2216719
}
527
528
2321909
static void FUNC(put_hevc_pel_bi_pixels)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
529
                                         int16_t *src2,
530
                                         int height, intptr_t mx, intptr_t my, int width)
531
{
532
    int x, y;
533
2321909
    pixel *src          = (pixel *)_src;
534
2321909
    ptrdiff_t srcstride = _srcstride / sizeof(pixel);
535
2321909
    pixel *dst          = (pixel *)_dst;
536
2321909
    ptrdiff_t dststride = _dststride / sizeof(pixel);
537
538
2321909
    int shift = 14  + 1 - BIT_DEPTH;
539
#if BIT_DEPTH < 14
540
2321909
    int offset = 1 << (shift - 1);
541
#else
542
    int offset = 0;
543
#endif
544
545
36775361
    for (y = 0; y < height; y++) {
546
935809740
        for (x = 0; x < width; x++)
547
901356288
            dst[x] = av_clip_pixel(((src[x] << (14 - BIT_DEPTH)) + src2[x] + offset) >> shift);
548
34453452
        src  += srcstride;
549
34453452
        dst  += dststride;
550
34453452
        src2 += MAX_PB_SIZE;
551
    }
552
2321909
}
553
554
29326
static void FUNC(put_hevc_pel_uni_w_pixels)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
555
                                            int height, int denom, int wx, int ox, intptr_t mx, intptr_t my, int width)
556
{
557
    int x, y;
558
29326
    pixel *src          = (pixel *)_src;
559
29326
    ptrdiff_t srcstride = _srcstride / sizeof(pixel);
560
29326
    pixel *dst          = (pixel *)_dst;
561
29326
    ptrdiff_t dststride = _dststride / sizeof(pixel);
562
29326
    int shift = denom + 14 - BIT_DEPTH;
563
#if BIT_DEPTH < 14
564
29326
    int offset = 1 << (shift - 1);
565
#else
566
    int offset = 0;
567
#endif
568
569
29326
    ox     = ox * (1 << (BIT_DEPTH - 8));
570
630906
    for (y = 0; y < height; y++) {
571
20066396
        for (x = 0; x < width; x++)
572
19464816
            dst[x] = av_clip_pixel((((src[x] << (14 - BIT_DEPTH)) * wx + offset) >> shift) + ox);
573
601580
        src += srcstride;
574
601580
        dst += dststride;
575
    }
576
29326
}
577
578
18430
static void FUNC(put_hevc_pel_bi_w_pixels)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
579
                                           int16_t *src2,
580
                                           int height, int denom, int wx0, int wx1,
581
                                           int ox0, int ox1, intptr_t mx, intptr_t my, int width)
582
{
583
    int x, y;
584
18430
    pixel *src          = (pixel *)_src;
585
18430
    ptrdiff_t srcstride = _srcstride / sizeof(pixel);
586
18430
    pixel *dst          = (pixel *)_dst;
587
18430
    ptrdiff_t dststride = _dststride / sizeof(pixel);
588
589
18430
    int shift = 14  + 1 - BIT_DEPTH;
590
18430
    int log2Wd = denom + shift - 1;
591
592
18430
    ox0     = ox0 * (1 << (BIT_DEPTH - 8));
593
18430
    ox1     = ox1 * (1 << (BIT_DEPTH - 8));
594
387442
    for (y = 0; y < height; y++) {
595
11838004
        for (x = 0; x < width; x++) {
596
11468992
            dst[x] = av_clip_pixel(( (src[x] << (14 - BIT_DEPTH)) * wx1 + src2[x] * wx0 + (ox0 + ox1 + 1) * (1 << log2Wd)) >> (log2Wd + 1));
597
        }
598
369012
        src  += srcstride;
599
369012
        dst  += dststride;
600
369012
        src2 += MAX_PB_SIZE;
601
    }
602
18430
}
603
604
////////////////////////////////////////////////////////////////////////////////
605
//
606
////////////////////////////////////////////////////////////////////////////////
607
#define QPEL_FILTER(src, stride)                                               \
608
    (filter[0] * src[x - 3 * stride] +                                         \
609
     filter[1] * src[x - 2 * stride] +                                         \
610
     filter[2] * src[x -     stride] +                                         \
611
     filter[3] * src[x             ] +                                         \
612
     filter[4] * src[x +     stride] +                                         \
613
     filter[5] * src[x + 2 * stride] +                                         \
614
     filter[6] * src[x + 3 * stride] +                                         \
615
     filter[7] * src[x + 4 * stride])
616
617
609102
static void FUNC(put_hevc_qpel_h)(int16_t *dst,
618
                                  uint8_t *_src, ptrdiff_t _srcstride,
619
                                  int height, intptr_t mx, intptr_t my, int width)
620
{
621
    int x, y;
622
609102
    pixel        *src       = (pixel*)_src;
623
609102
    ptrdiff_t     srcstride = _srcstride / sizeof(pixel);
624
609102
    const int8_t *filter    = ff_hevc_qpel_filters[mx - 1];
625
14266398
    for (y = 0; y < height; y++) {
626
476180048
        for (x = 0; x < width; x++)
627
462522752
            dst[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
628
13657296
        src += srcstride;
629
13657296
        dst += MAX_PB_SIZE;
630
    }
631
609102
}
632
633
463712
static void FUNC(put_hevc_qpel_v)(int16_t *dst,
634
                                  uint8_t *_src, ptrdiff_t _srcstride,
635
                                  int height, intptr_t mx, intptr_t my, int width)
636
{
637
    int x, y;
638
463712
    pixel        *src       = (pixel*)_src;
639
463712
    ptrdiff_t     srcstride = _srcstride / sizeof(pixel);
640
463712
    const int8_t *filter    = ff_hevc_qpel_filters[my - 1];
641
10858448
    for (y = 0; y < height; y++)  {
642
364021040
        for (x = 0; x < width; x++)
643
353626304
            dst[x] = QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8);
644
10394736
        src += srcstride;
645
10394736
        dst += MAX_PB_SIZE;
646
    }
647
463712
}
648
649
1477357
static void FUNC(put_hevc_qpel_hv)(int16_t *dst,
650
                                   uint8_t *_src,
651
                                   ptrdiff_t _srcstride,
652
                                   int height, intptr_t mx,
653
                                   intptr_t my, int width)
654
{
655
    int x, y;
656
    const int8_t *filter;
657
1477357
    pixel *src = (pixel*)_src;
658
1477357
    ptrdiff_t srcstride = _srcstride / sizeof(pixel);
659
    int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
660
1477357
    int16_t *tmp = tmp_array;
661
662
1477357
    src   -= QPEL_EXTRA_BEFORE * srcstride;
663
1477357
    filter = ff_hevc_qpel_filters[mx - 1];
664
43863884
    for (y = 0; y < height + QPEL_EXTRA; y++) {
665
1299871015
        for (x = 0; x < width; x++)
666
1257484488
            tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
667
42386527
        src += srcstride;
668
42386527
        tmp += MAX_PB_SIZE;
669
    }
670
671
1477357
    tmp    = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
672
1477357
    filter = ff_hevc_qpel_filters[my - 1];
673
33522385
    for (y = 0; y < height; y++) {
674
1068314340
        for (x = 0; x < width; x++)
675
1036269312
            dst[x] = QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6;
676
32045028
        tmp += MAX_PB_SIZE;
677
32045028
        dst += MAX_PB_SIZE;
678
    }
679
1477357
}
680
681
752862
static void FUNC(put_hevc_qpel_uni_h)(uint8_t *_dst,  ptrdiff_t _dststride,
682
                                      uint8_t *_src, ptrdiff_t _srcstride,
683
                                      int height, intptr_t mx, intptr_t my, int width)
684
{
685
    int x, y;
686
752862
    pixel        *src       = (pixel*)_src;
687
752862
    ptrdiff_t     srcstride = _srcstride / sizeof(pixel);
688
752862
    pixel *dst          = (pixel *)_dst;
689
752862
    ptrdiff_t dststride = _dststride / sizeof(pixel);
690
752862
    const int8_t *filter    = ff_hevc_qpel_filters[mx - 1];
691
752862
    int shift = 14 - BIT_DEPTH;
692
693
#if BIT_DEPTH < 14
694
752862
    int offset = 1 << (shift - 1);
695
#else
696
    int offset = 0;
697
#endif
698
699
11799170
    for (y = 0; y < height; y++) {
700
254011396
        for (x = 0; x < width; x++)
701
242965088
            dst[x] = av_clip_pixel(((QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) + offset) >> shift);
702
11046308
        src += srcstride;
703
11046308
        dst += dststride;
704
    }
705
752862
}
706
707
585823
static void FUNC(put_hevc_qpel_bi_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
708
                                     int16_t *src2,
709
                                     int height, intptr_t mx, intptr_t my, int width)
710
{
711
    int x, y;
712
585823
    pixel        *src       = (pixel*)_src;
713
585823
    ptrdiff_t     srcstride = _srcstride / sizeof(pixel);
714
585823
    pixel *dst          = (pixel *)_dst;
715
585823
    ptrdiff_t dststride = _dststride / sizeof(pixel);
716
717
585823
    const int8_t *filter    = ff_hevc_qpel_filters[mx - 1];
718
719
585823
    int shift = 14  + 1 - BIT_DEPTH;
720
#if BIT_DEPTH < 14
721
585823
    int offset = 1 << (shift - 1);
722
#else
723
    int offset = 0;
724
#endif
725
726
13687411
    for (y = 0; y < height; y++) {
727
454789012
        for (x = 0; x < width; x++)
728
441687424
            dst[x] = av_clip_pixel(((QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) + src2[x] + offset) >> shift);
729
13101588
        src  += srcstride;
730
13101588
        dst  += dststride;
731
13101588
        src2 += MAX_PB_SIZE;
732
    }
733
585823
}
734
735
660841
static void FUNC(put_hevc_qpel_uni_v)(uint8_t *_dst,  ptrdiff_t _dststride,
736
                                     uint8_t *_src, ptrdiff_t _srcstride,
737
                                     int height, intptr_t mx, intptr_t my, int width)
738
{
739
    int x, y;
740
660841
    pixel        *src       = (pixel*)_src;
741
660841
    ptrdiff_t     srcstride = _srcstride / sizeof(pixel);
742
660841
    pixel *dst          = (pixel *)_dst;
743
660841
    ptrdiff_t dststride = _dststride / sizeof(pixel);
744
660841
    const int8_t *filter    = ff_hevc_qpel_filters[my - 1];
745
660841
    int shift = 14 - BIT_DEPTH;
746
747
#if BIT_DEPTH < 14
748
660841
    int offset = 1 << (shift - 1);
749
#else
750
    int offset = 0;
751
#endif
752
753
10623677
    for (y = 0; y < height; y++) {
754
244190900
        for (x = 0; x < width; x++)
755
234228064
            dst[x] = av_clip_pixel(((QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) + offset) >> shift);
756
9962836
        src += srcstride;
757
9962836
        dst += dststride;
758
    }
759
660841
}
760
761
762
440352
static void FUNC(put_hevc_qpel_bi_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
763
                                     int16_t *src2,
764
                                     int height, intptr_t mx, intptr_t my, int width)
765
{
766
    int x, y;
767
440352
    pixel        *src       = (pixel*)_src;
768
440352
    ptrdiff_t     srcstride = _srcstride / sizeof(pixel);
769
440352
    pixel *dst          = (pixel *)_dst;
770
440352
    ptrdiff_t dststride = _dststride / sizeof(pixel);
771
772
440352
    const int8_t *filter    = ff_hevc_qpel_filters[my - 1];
773
774
440352
    int shift = 14 + 1 - BIT_DEPTH;
775
#if BIT_DEPTH < 14
776
440352
    int offset = 1 << (shift - 1);
777
#else
778
    int offset = 0;
779
#endif
780
781
10157304
    for (y = 0; y < height; y++) {
782
333954840
        for (x = 0; x < width; x++)
783
324237888
            dst[x] = av_clip_pixel(((QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) + src2[x] + offset) >> shift);
784
9716952
        src  += srcstride;
785
9716952
        dst  += dststride;
786
9716952
        src2 += MAX_PB_SIZE;
787
    }
788
440352
}
789
790
2095329
static void FUNC(put_hevc_qpel_uni_hv)(uint8_t *_dst,  ptrdiff_t _dststride,
791
                                       uint8_t *_src, ptrdiff_t _srcstride,
792
                                       int height, intptr_t mx, intptr_t my, int width)
793
{
794
    int x, y;
795
    const int8_t *filter;
796
2095329
    pixel *src = (pixel*)_src;
797
2095329
    ptrdiff_t srcstride = _srcstride / sizeof(pixel);
798
2095329
    pixel *dst          = (pixel *)_dst;
799
2095329
    ptrdiff_t dststride = _dststride / sizeof(pixel);
800
    int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
801
2095329
    int16_t *tmp = tmp_array;
802
2095329
    int shift =  14 - BIT_DEPTH;
803
804
#if BIT_DEPTH < 14
805
2095329
    int offset = 1 << (shift - 1);
806
#else
807
    int offset = 0;
808
#endif
809
810
2095329
    src   -= QPEL_EXTRA_BEFORE * srcstride;
811
2095329
    filter = ff_hevc_qpel_filters[mx - 1];
812
47307632
    for (y = 0; y < height + QPEL_EXTRA; y++) {
813
903069055
        for (x = 0; x < width; x++)
814
857856752
            tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
815
45212303
        src += srcstride;
816
45212303
        tmp += MAX_PB_SIZE;
817
    }
818
819
2095329
    tmp    = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
820
2095329
    filter = ff_hevc_qpel_filters[my - 1];
821
822
32640329
    for (y = 0; y < height; y++) {
823
679825608
        for (x = 0; x < width; x++)
824
649280608
            dst[x] = av_clip_pixel(((QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) + offset) >> shift);
825
30545000
        tmp += MAX_PB_SIZE;
826
30545000
        dst += dststride;
827
    }
828
2095329
}
829
830
1413848
static void FUNC(put_hevc_qpel_bi_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
831
                                      int16_t *src2,
832
                                      int height, intptr_t mx, intptr_t my, int width)
833
{
834
    int x, y;
835
    const int8_t *filter;
836
1413848
    pixel *src = (pixel*)_src;
837
1413848
    ptrdiff_t srcstride = _srcstride / sizeof(pixel);
838
1413848
    pixel *dst          = (pixel *)_dst;
839
1413848
    ptrdiff_t dststride = _dststride / sizeof(pixel);
840
    int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
841
1413848
    int16_t *tmp = tmp_array;
842
1413848
    int shift = 14 + 1 - BIT_DEPTH;
843
#if BIT_DEPTH < 14
844
1413848
    int offset = 1 << (shift - 1);
845
#else
846
    int offset = 0;
847
#endif
848
849
1413848
    src   -= QPEL_EXTRA_BEFORE * srcstride;
850
1413848
    filter = ff_hevc_qpel_filters[mx - 1];
851
42215812
    for (y = 0; y < height + QPEL_EXTRA; y++) {
852
1267031492
        for (x = 0; x < width; x++)
853
1226229528
            tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
854
40801964
        src += srcstride;
855
40801964
        tmp += MAX_PB_SIZE;
856
    }
857
858
1413848
    tmp    = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
859
1413848
    filter = ff_hevc_qpel_filters[my - 1];
860
861
32318876
    for (y = 0; y < height; y++) {
862
1043629572
        for (x = 0; x < width; x++)
863
1012724544
            dst[x] = av_clip_pixel(((QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) + src2[x] + offset) >> shift);
864
30905028
        tmp  += MAX_PB_SIZE;
865
30905028
        dst  += dststride;
866
30905028
        src2 += MAX_PB_SIZE;
867
    }
868
1413848
}
869
870
12077
static void FUNC(put_hevc_qpel_uni_w_h)(uint8_t *_dst,  ptrdiff_t _dststride,
871
                                        uint8_t *_src, ptrdiff_t _srcstride,
872
                                        int height, int denom, int wx, int ox,
873
                                        intptr_t mx, intptr_t my, int width)
874
{
875
    int x, y;
876
12077
    pixel        *src       = (pixel*)_src;
877
12077
    ptrdiff_t     srcstride = _srcstride / sizeof(pixel);
878
12077
    pixel *dst          = (pixel *)_dst;
879
12077
    ptrdiff_t dststride = _dststride / sizeof(pixel);
880
12077
    const int8_t *filter    = ff_hevc_qpel_filters[mx - 1];
881
12077
    int shift = denom + 14 - BIT_DEPTH;
882
#if BIT_DEPTH < 14
883
12077
    int offset = 1 << (shift - 1);
884
#else
885
    int offset = 0;
886
#endif
887
888
12077
    ox = ox * (1 << (BIT_DEPTH - 8));
889
216733
    for (y = 0; y < height; y++) {
890
5380016
        for (x = 0; x < width; x++)
891
5175360
            dst[x] = av_clip_pixel((((QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
892
204656
        src += srcstride;
893
204656
        dst += dststride;
894
    }
895
12077
}
896
897
7011
static void FUNC(put_hevc_qpel_bi_w_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
898
                                       int16_t *src2,
899
                                       int height, int denom, int wx0, int wx1,
900
                                       int ox0, int ox1, intptr_t mx, intptr_t my, int width)
901
{
902
    int x, y;
903
7011
    pixel        *src       = (pixel*)_src;
904
7011
    ptrdiff_t     srcstride = _srcstride / sizeof(pixel);
905
7011
    pixel *dst          = (pixel *)_dst;
906
7011
    ptrdiff_t dststride = _dststride / sizeof(pixel);
907
908
7011
    const int8_t *filter    = ff_hevc_qpel_filters[mx - 1];
909
910
7011
    int shift = 14  + 1 - BIT_DEPTH;
911
7011
    int log2Wd = denom + shift - 1;
912
913
7011
    ox0     = ox0 * (1 << (BIT_DEPTH - 8));
914
7011
    ox1     = ox1 * (1 << (BIT_DEPTH - 8));
915
162283
    for (y = 0; y < height; y++) {
916
4810248
        for (x = 0; x < width; x++)
917
4654976
            dst[x] = av_clip_pixel(((QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
918
                                    ((ox0 + ox1 + 1) * (1 << log2Wd))) >> (log2Wd + 1));
919
155272
        src  += srcstride;
920
155272
        dst  += dststride;
921
155272
        src2 += MAX_PB_SIZE;
922
    }
923
7011
}
924
925
11336
static void FUNC(put_hevc_qpel_uni_w_v)(uint8_t *_dst,  ptrdiff_t _dststride,
926
                                        uint8_t *_src, ptrdiff_t _srcstride,
927
                                        int height, int denom, int wx, int ox,
928
                                        intptr_t mx, intptr_t my, int width)
929
{
930
    int x, y;
931
11336
    pixel        *src       = (pixel*)_src;
932
11336
    ptrdiff_t     srcstride = _srcstride / sizeof(pixel);
933
11336
    pixel *dst          = (pixel *)_dst;
934
11336
    ptrdiff_t dststride = _dststride / sizeof(pixel);
935
11336
    const int8_t *filter    = ff_hevc_qpel_filters[my - 1];
936
11336
    int shift = denom + 14 - BIT_DEPTH;
937
#if BIT_DEPTH < 14
938
11336
    int offset = 1 << (shift - 1);
939
#else
940
    int offset = 0;
941
#endif
942
943
11336
    ox = ox * (1 << (BIT_DEPTH - 8));
944
188644
    for (y = 0; y < height; y++) {
945
4055228
        for (x = 0; x < width; x++)
946
3877920
            dst[x] = av_clip_pixel((((QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
947
177308
        src += srcstride;
948
177308
        dst += dststride;
949
    }
950
11336
}
951
952
6762
static void FUNC(put_hevc_qpel_bi_w_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
953
                                       int16_t *src2,
954
                                       int height, int denom, int wx0, int wx1,
955
                                       int ox0, int ox1, intptr_t mx, intptr_t my, int width)
956
{
957
    int x, y;
958
6762
    pixel        *src       = (pixel*)_src;
959
6762
    ptrdiff_t     srcstride = _srcstride / sizeof(pixel);
960
6762
    pixel *dst          = (pixel *)_dst;
961
6762
    ptrdiff_t dststride = _dststride / sizeof(pixel);
962
963
6762
    const int8_t *filter    = ff_hevc_qpel_filters[my - 1];
964
965
6762
    int shift = 14 + 1 - BIT_DEPTH;
966
6762
    int log2Wd = denom + shift - 1;
967
968
6762
    ox0     = ox0 * (1 << (BIT_DEPTH - 8));
969
6762
    ox1     = ox1 * (1 << (BIT_DEPTH - 8));
970
150550
    for (y = 0; y < height; y++) {
971
4260844
        for (x = 0; x < width; x++)
972
4117056
            dst[x] = av_clip_pixel(((QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
973
                                    ((ox0 + ox1 + 1) * (1 << log2Wd))) >> (log2Wd + 1));
974
143788
        src  += srcstride;
975
143788
        dst  += dststride;
976
143788
        src2 += MAX_PB_SIZE;
977
    }
978
6762
}
979
980
38831
static void FUNC(put_hevc_qpel_uni_w_hv)(uint8_t *_dst,  ptrdiff_t _dststride,
981
                                         uint8_t *_src, ptrdiff_t _srcstride,
982
                                         int height, int denom, int wx, int ox,
983
                                         intptr_t mx, intptr_t my, int width)
984
{
985
    int x, y;
986
    const int8_t *filter;
987
38831
    pixel *src = (pixel*)_src;
988
38831
    ptrdiff_t srcstride = _srcstride / sizeof(pixel);
989
38831
    pixel *dst          = (pixel *)_dst;
990
38831
    ptrdiff_t dststride = _dststride / sizeof(pixel);
991
    int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
992
38831
    int16_t *tmp = tmp_array;
993
38831
    int shift = denom + 14 - BIT_DEPTH;
994
#if BIT_DEPTH < 14
995
38831
    int offset = 1 << (shift - 1);
996
#else
997
    int offset = 0;
998
#endif
999
1000
38831
    src   -= QPEL_EXTRA_BEFORE * srcstride;
1001
38831
    filter = ff_hevc_qpel_filters[mx - 1];
1002
927892
    for (y = 0; y < height + QPEL_EXTRA; y++) {
1003
18625717
        for (x = 0; x < width; x++)
1004
17736656
            tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1005
889061
        src += srcstride;
1006
889061
        tmp += MAX_PB_SIZE;
1007
    }
1008
1009
38831
    tmp    = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1010
38831
    filter = ff_hevc_qpel_filters[my - 1];
1011
1012
38831
    ox = ox * (1 << (BIT_DEPTH - 8));
1013
656075
    for (y = 0; y < height; y++) {
1014
14385180
        for (x = 0; x < width; x++)
1015
13767936
            dst[x] = av_clip_pixel((((QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx + offset) >> shift) + ox);
1016
617244
        tmp += MAX_PB_SIZE;
1017
617244
        dst += dststride;
1018
    }
1019
38831
}
1020
1021
26375
static void FUNC(put_hevc_qpel_bi_w_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1022
                                        int16_t *src2,
1023
                                        int height, int denom, int wx0, int wx1,
1024
                                        int ox0, int ox1, intptr_t mx, intptr_t my, int width)
1025
{
1026
    int x, y;
1027
    const int8_t *filter;
1028
26375
    pixel *src = (pixel*)_src;
1029
26375
    ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1030
26375
    pixel *dst          = (pixel *)_dst;
1031
26375
    ptrdiff_t dststride = _dststride / sizeof(pixel);
1032
    int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
1033
26375
    int16_t *tmp = tmp_array;
1034
26375
    int shift = 14 + 1 - BIT_DEPTH;
1035
26375
    int log2Wd = denom + shift - 1;
1036
1037
26375
    src   -= QPEL_EXTRA_BEFORE * srcstride;
1038
26375
    filter = ff_hevc_qpel_filters[mx - 1];
1039
818280
    for (y = 0; y < height + QPEL_EXTRA; y++) {
1040
24006453
        for (x = 0; x < width; x++)
1041
23214548
            tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1042
791905
        src += srcstride;
1043
791905
        tmp += MAX_PB_SIZE;
1044
    }
1045
1046
26375
    tmp    = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1047
26375
    filter = ff_hevc_qpel_filters[my - 1];
1048
1049
26375
    ox0     = ox0 * (1 << (BIT_DEPTH - 8));
1050
26375
    ox1     = ox1 * (1 << (BIT_DEPTH - 8));
1051
633655
    for (y = 0; y < height; y++) {
1052
19790640
        for (x = 0; x < width; x++)
1053
19183360
            dst[x] = av_clip_pixel(((QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx1 + src2[x] * wx0 +
1054
                                    ((ox0 + ox1 + 1) * (1 << log2Wd))) >> (log2Wd + 1));
1055
607280
        tmp  += MAX_PB_SIZE;
1056
607280
        dst  += dststride;
1057
607280
        src2 += MAX_PB_SIZE;
1058
    }
1059
26375
}
1060
1061
////////////////////////////////////////////////////////////////////////////////
1062
//
1063
////////////////////////////////////////////////////////////////////////////////
1064
#define EPEL_FILTER(src, stride)                                               \
1065
    (filter[0] * src[x - stride] +                                             \
1066
     filter[1] * src[x]          +                                             \
1067
     filter[2] * src[x + stride] +                                             \
1068
     filter[3] * src[x + 2 * stride])
1069
1070
916666
static void FUNC(put_hevc_epel_h)(int16_t *dst,
1071
                                  uint8_t *_src, ptrdiff_t _srcstride,
1072
                                  int height, intptr_t mx, intptr_t my, int width)
1073
{
1074
    int x, y;
1075
916666
    pixel *src = (pixel *)_src;
1076
916666
    ptrdiff_t srcstride  = _srcstride / sizeof(pixel);
1077
916666
    const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1078
11218554
    for (y = 0; y < height; y++) {
1079
184542464
        for (x = 0; x < width; x++)
1080
174240576
            dst[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1081
10301888
        src += srcstride;
1082
10301888
        dst += MAX_PB_SIZE;
1083
    }
1084
916666
}
1085
1086
633152
static void FUNC(put_hevc_epel_v)(int16_t *dst,
1087
                                  uint8_t *_src, ptrdiff_t _srcstride,
1088
                                  int height, intptr_t mx, intptr_t my, int width)
1089
{
1090
    int x, y;
1091
633152
    pixel *src = (pixel *)_src;
1092
633152
    ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1093
633152
    const int8_t *filter = ff_hevc_epel_filters[my - 1];
1094
1095
8054832
    for (y = 0; y < height; y++) {
1096
139309712
        for (x = 0; x < width; x++)
1097
131888032
            dst[x] = EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8);
1098
7421680
        src += srcstride;
1099
7421680
        dst += MAX_PB_SIZE;
1100
    }
1101
633152
}
1102
1103
3825650
static void FUNC(put_hevc_epel_hv)(int16_t *dst,
1104
                                   uint8_t *_src, ptrdiff_t _srcstride,
1105
                                   int height, intptr_t mx, intptr_t my, int width)
1106
{
1107
    int x, y;
1108
3825650
    pixel *src = (pixel *)_src;
1109
3825650
    ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1110
3825650
    const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1111
    int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
1112
3825650
    int16_t *tmp = tmp_array;
1113
1114
3825650
    src -= EPEL_EXTRA_BEFORE * srcstride;
1115
1116
56729008
    for (y = 0; y < height + EPEL_EXTRA; y++) {
1117
847176786
        for (x = 0; x < width; x++)
1118
794273428
            tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1119
52903358
        src += srcstride;
1120
52903358
        tmp += MAX_PB_SIZE;
1121
    }
1122
1123
3825650
    tmp      = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1124
3825650
    filter = ff_hevc_epel_filters[my - 1];
1125
1126
45252058
    for (y = 0; y < height; y++) {
1127
713153352
        for (x = 0; x < width; x++)
1128
671726944
            dst[x] = EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6;
1129
41426408
        tmp += MAX_PB_SIZE;
1130
41426408
        dst += MAX_PB_SIZE;
1131
    }
1132
3825650
}
1133
1134
1180848
static void FUNC(put_hevc_epel_uni_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1135
                                      int height, intptr_t mx, intptr_t my, int width)
1136
{
1137
    int x, y;
1138
1180848
    pixel *src = (pixel *)_src;
1139
1180848
    ptrdiff_t srcstride  = _srcstride / sizeof(pixel);
1140
1180848
    pixel *dst          = (pixel *)_dst;
1141
1180848
    ptrdiff_t dststride = _dststride / sizeof(pixel);
1142
1180848
    const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1143
1180848
    int shift = 14 - BIT_DEPTH;
1144
#if BIT_DEPTH < 14
1145
1180848
    int offset = 1 << (shift - 1);
1146
#else
1147
    int offset = 0;
1148
#endif
1149
1150
9698724
    for (y = 0; y < height; y++) {
1151
100435444
        for (x = 0; x < width; x++)
1152
91917568
            dst[x] = av_clip_pixel(((EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) + offset) >> shift);
1153
8517876
        src += srcstride;
1154
8517876
        dst += dststride;
1155
    }
1156
1180848
}
1157
1158
887226
static void FUNC(put_hevc_epel_bi_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1159
                                     int16_t *src2,
1160
                                     int height, intptr_t mx, intptr_t my, int width)
1161
{
1162
    int x, y;
1163
887226
    pixel *src = (pixel *)_src;
1164
887226
    ptrdiff_t srcstride  = _srcstride / sizeof(pixel);
1165
887226
    pixel *dst          = (pixel *)_dst;
1166
887226
    ptrdiff_t dststride = _dststride / sizeof(pixel);
1167
887226
    const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1168
887226
    int shift = 14 + 1 - BIT_DEPTH;
1169
#if BIT_DEPTH < 14
1170
887226
    int offset = 1 << (shift - 1);
1171
#else
1172
    int offset = 0;
1173
#endif
1174
1175
10804522
    for (y = 0; y < height; y++) {
1176
177008016
        for (x = 0; x < width; x++) {
1177
167090720
            dst[x] = av_clip_pixel(((EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) + src2[x] + offset) >> shift);
1178
        }
1179
9917296
        dst  += dststride;
1180
9917296
        src  += srcstride;
1181
9917296
        src2 += MAX_PB_SIZE;
1182
    }
1183
887226
}
1184
1185
973884
static void FUNC(put_hevc_epel_uni_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1186
                                      int height, intptr_t mx, intptr_t my, int width)
1187
{
1188
    int x, y;
1189
973884
    pixel *src = (pixel *)_src;
1190
973884
    ptrdiff_t srcstride  = _srcstride / sizeof(pixel);
1191
973884
    pixel *dst          = (pixel *)_dst;
1192
973884
    ptrdiff_t dststride = _dststride / sizeof(pixel);
1193
973884
    const int8_t *filter = ff_hevc_epel_filters[my - 1];
1194
973884
    int shift = 14 - BIT_DEPTH;
1195
#if BIT_DEPTH < 14
1196
973884
    int offset = 1 << (shift - 1);
1197
#else
1198
    int offset = 0;
1199
#endif
1200
1201
8285168
    for (y = 0; y < height; y++) {
1202
92516676
        for (x = 0; x < width; x++)
1203
85205392
            dst[x] = av_clip_pixel(((EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) + offset) >> shift);
1204
7311284
        src += srcstride;
1205
7311284
        dst += dststride;
1206
    }
1207
973884
}
1208
1209
608556
static void FUNC(put_hevc_epel_bi_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1210
                                     int16_t *src2,
1211
                                     int height, intptr_t mx, intptr_t my, int width)
1212
{
1213
    int x, y;
1214
608556
    pixel *src = (pixel *)_src;
1215
608556
    ptrdiff_t srcstride  = _srcstride / sizeof(pixel);
1216
608556
    const int8_t *filter = ff_hevc_epel_filters[my - 1];
1217
608556
    pixel *dst          = (pixel *)_dst;
1218
608556
    ptrdiff_t dststride = _dststride / sizeof(pixel);
1219
608556
    int shift = 14 + 1 - BIT_DEPTH;
1220
#if BIT_DEPTH < 14
1221
608556
    int offset = 1 << (shift - 1);
1222
#else
1223
    int offset = 0;
1224
#endif
1225
1226
7554136
    for (y = 0; y < height; y++) {
1227
127116012
        for (x = 0; x < width; x++)
1228
120170432
            dst[x] = av_clip_pixel(((EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) + src2[x] + offset) >> shift);
1229
6945580
        dst  += dststride;
1230
6945580
        src  += srcstride;
1231
6945580
        src2 += MAX_PB_SIZE;
1232
    }
1233
608556
}
1234
1235
5538028
static void FUNC(put_hevc_epel_uni_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1236
                                       int height, intptr_t mx, intptr_t my, int width)
1237
{
1238
    int x, y;
1239
5538028
    pixel *src = (pixel *)_src;
1240
5538028
    ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1241
5538028
    pixel *dst          = (pixel *)_dst;
1242
5538028
    ptrdiff_t dststride = _dststride / sizeof(pixel);
1243
5538028
    const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1244
    int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
1245
5538028
    int16_t *tmp = tmp_array;
1246
5538028
    int shift = 14 - BIT_DEPTH;
1247
#if BIT_DEPTH < 14
1248
5538028
    int offset = 1 << (shift - 1);
1249
#else
1250
    int offset = 0;
1251
#endif
1252
1253
5538028
    src -= EPEL_EXTRA_BEFORE * srcstride;
1254
1255
62332768
    for (y = 0; y < height + EPEL_EXTRA; y++) {
1256
604065104
        for (x = 0; x < width; x++)
1257
547270364
            tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1258
56794740
        src += srcstride;
1259
56794740
        tmp += MAX_PB_SIZE;
1260
    }
1261
1262
5538028
    tmp      = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1263
5538028
    filter = ff_hevc_epel_filters[my - 1];
1264
1265
45718684
    for (y = 0; y < height; y++) {
1266
469720976
        for (x = 0; x < width; x++)
1267
429540320
            dst[x] = av_clip_pixel(((EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) + offset) >> shift);
1268
40180656
        tmp += MAX_PB_SIZE;
1269
40180656
        dst += dststride;
1270
    }
1271
5538028
}
1272
1273
3660520
static void FUNC(put_hevc_epel_bi_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1274
                                      int16_t *src2,
1275
                                      int height, intptr_t mx, intptr_t my, int width)
1276
{
1277
    int x, y;
1278
3660520
    pixel *src = (pixel *)_src;
1279
3660520
    ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1280
3660520
    pixel *dst          = (pixel *)_dst;
1281
3660520
    ptrdiff_t dststride = _dststride / sizeof(pixel);
1282
3660520
    const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1283
    int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
1284
3660520
    int16_t *tmp = tmp_array;
1285
3660520
    int shift = 14 + 1 - BIT_DEPTH;
1286
#if BIT_DEPTH < 14
1287
3660520
    int offset = 1 << (shift - 1);
1288
#else
1289
    int offset = 0;
1290
#endif
1291
1292
3660520
    src -= EPEL_EXTRA_BEFORE * srcstride;
1293
1294
54505056
    for (y = 0; y < height + EPEL_EXTRA; y++) {
1295
820842312
        for (x = 0; x < width; x++)
1296
769997776
            tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1297
50844536
        src += srcstride;
1298
50844536
        tmp += MAX_PB_SIZE;
1299
    }
1300
1301
3660520
    tmp      = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1302
3660520
    filter = ff_hevc_epel_filters[my - 1];
1303
1304
43523496
    for (y = 0; y < height; y++) {
1305
691856448
        for (x = 0; x < width; x++)
1306
651993472
            dst[x] = av_clip_pixel(((EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) + src2[x] + offset) >> shift);
1307
39862976
        tmp  += MAX_PB_SIZE;
1308
39862976
        dst  += dststride;
1309
39862976
        src2 += MAX_PB_SIZE;
1310
    }
1311
3660520
}
1312
1313
17540
static void FUNC(put_hevc_epel_uni_w_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1314
                                        int height, int denom, int wx, int ox, intptr_t mx, intptr_t my, int width)
1315
{
1316
    int x, y;
1317
17540
    pixel *src = (pixel *)_src;
1318
17540
    ptrdiff_t srcstride  = _srcstride / sizeof(pixel);
1319
17540
    pixel *dst          = (pixel *)_dst;
1320
17540
    ptrdiff_t dststride = _dststride / sizeof(pixel);
1321
17540
    const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1322
17540
    int shift = denom + 14 - BIT_DEPTH;
1323
#if BIT_DEPTH < 14
1324
17540
    int offset = 1 << (shift - 1);
1325
#else
1326
    int offset = 0;
1327
#endif
1328
1329
17540
    ox     = ox * (1 << (BIT_DEPTH - 8));
1330
177900
    for (y = 0; y < height; y++) {
1331
2397528
        for (x = 0; x < width; x++) {
1332
2237168
            dst[x] = av_clip_pixel((((EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
1333
        }
1334
160360
        dst += dststride;
1335
160360
        src += srcstride;
1336
    }
1337
17540
}
1338
1339
9846
static void FUNC(put_hevc_epel_bi_w_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1340
                                       int16_t *src2,
1341
                                       int height, int denom, int wx0, int wx1,
1342
                                       int ox0, int ox1, intptr_t mx, intptr_t my, int width)
1343
{
1344
    int x, y;
1345
9846
    pixel *src = (pixel *)_src;
1346
9846
    ptrdiff_t srcstride  = _srcstride / sizeof(pixel);
1347
9846
    pixel *dst          = (pixel *)_dst;
1348
9846
    ptrdiff_t dststride = _dststride / sizeof(pixel);
1349
9846
    const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1350
9846
    int shift = 14 + 1 - BIT_DEPTH;
1351
9846
    int log2Wd = denom + shift - 1;
1352
1353
9846
    ox0     = ox0 * (1 << (BIT_DEPTH - 8));
1354
9846
    ox1     = ox1 * (1 << (BIT_DEPTH - 8));
1355
122402
    for (y = 0; y < height; y++) {
1356
1882924
        for (x = 0; x < width; x++)
1357
1770368
            dst[x] = av_clip_pixel(((EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
1358
                                    ((ox0 + ox1 + 1) * (1 << log2Wd))) >> (log2Wd + 1));
1359
112556
        src  += srcstride;
1360
112556
        dst  += dststride;
1361
112556
        src2 += MAX_PB_SIZE;
1362
    }
1363
9846
}
1364
1365
14494
static void FUNC(put_hevc_epel_uni_w_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1366
                                        int height, int denom, int wx, int ox, intptr_t mx, intptr_t my, int width)
1367
{
1368
    int x, y;
1369
14494
    pixel *src = (pixel *)_src;
1370
14494
    ptrdiff_t srcstride  = _srcstride / sizeof(pixel);
1371
14494
    pixel *dst          = (pixel *)_dst;
1372
14494
    ptrdiff_t dststride = _dststride / sizeof(pixel);
1373
14494
    const int8_t *filter = ff_hevc_epel_filters[my - 1];
1374
14494
    int shift = denom + 14 - BIT_DEPTH;
1375
#if BIT_DEPTH < 14
1376
14494
    int offset = 1 << (shift - 1);
1377
#else
1378
    int offset = 0;
1379
#endif
1380
1381
14494
    ox     = ox * (1 << (BIT_DEPTH - 8));
1382
133242
    for (y = 0; y < height; y++) {
1383
1520012
        for (x = 0; x < width; x++) {
1384
1401264
            dst[x] = av_clip_pixel((((EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
1385
        }
1386
118748
        dst += dststride;
1387
118748
        src += srcstride;
1388
    }
1389
14494
}
1390
1391
8000
static void FUNC(put_hevc_epel_bi_w_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1392
                                       int16_t *src2,
1393
                                       int height, int denom, int wx0, int wx1,
1394
                                       int ox0, int ox1, intptr_t mx, intptr_t my, int width)
1395
{
1396
    int x, y;
1397
8000
    pixel *src = (pixel *)_src;
1398
8000
    ptrdiff_t srcstride  = _srcstride / sizeof(pixel);
1399
8000
    const int8_t *filter = ff_hevc_epel_filters[my - 1];
1400
8000
    pixel *dst          = (pixel *)_dst;
1401
8000
    ptrdiff_t dststride = _dststride / sizeof(pixel);
1402
8000
    int shift = 14 + 1 - BIT_DEPTH;
1403
8000
    int log2Wd = denom + shift - 1;
1404
1405
8000
    ox0     = ox0 * (1 << (BIT_DEPTH - 8));
1406
8000
    ox1     = ox1 * (1 << (BIT_DEPTH - 8));
1407
90468
    for (y = 0; y < height; y++) {
1408
1208516
        for (x = 0; x < width; x++)
1409
1126048
            dst[x] = av_clip_pixel(((EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
1410
                                    ((ox0 + ox1 + 1) * (1 << log2Wd))) >> (log2Wd + 1));
1411
82468
        src  += srcstride;
1412
82468
        dst  += dststride;
1413
82468
        src2 += MAX_PB_SIZE;
1414
    }
1415
8000
}
1416
1417
98738
static void FUNC(put_hevc_epel_uni_w_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1418
                                         int height, int denom, int wx, int ox, intptr_t mx, intptr_t my, int width)
1419
{
1420
    int x, y;
1421
98738
    pixel *src = (pixel *)_src;
1422
98738
    ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1423
98738
    pixel *dst          = (pixel *)_dst;
1424
98738
    ptrdiff_t dststride = _dststride / sizeof(pixel);
1425
98738
    const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1426
    int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
1427
98738
    int16_t *tmp = tmp_array;
1428
98738
    int shift = denom + 14 - BIT_DEPTH;
1429
#if BIT_DEPTH < 14
1430
98738
    int offset = 1 << (shift - 1);
1431
#else
1432
    int offset = 0;
1433
#endif
1434
1435
98738
    src -= EPEL_EXTRA_BEFORE * srcstride;
1436
1437
1165672
    for (y = 0; y < height + EPEL_EXTRA; y++) {
1438
11548998
        for (x = 0; x < width; x++)
1439
10482064
            tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1440
1066934
        src += srcstride;
1441
1066934
        tmp += MAX_PB_SIZE;
1442
    }
1443
1444
98738
    tmp      = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1445
98738
    filter = ff_hevc_epel_filters[my - 1];
1446
1447
98738
    ox     = ox * (1 << (BIT_DEPTH - 8));
1448
869458
    for (y = 0; y < height; y++) {
1449
9132048
        for (x = 0; x < width; x++)
1450
8361328
            dst[x] = av_clip_pixel((((EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx + offset) >> shift) + ox);
1451
770720
        tmp += MAX_PB_SIZE;
1452
770720
        dst += dststride;
1453
    }
1454
98738
}
1455
1456
66112
static void FUNC(put_hevc_epel_bi_w_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1457
                                        int16_t *src2,
1458
                                        int height, int denom, int wx0, int wx1,
1459
                                        int ox0, int ox1, intptr_t mx, intptr_t my, int width)
1460
{
1461
    int x, y;
1462
66112
    pixel *src = (pixel *)_src;
1463
66112
    ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1464
66112
    pixel *dst          = (pixel *)_dst;
1465
66112
    ptrdiff_t dststride = _dststride / sizeof(pixel);
1466
66112
    const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1467
    int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
1468
66112
    int16_t *tmp = tmp_array;
1469
66112
    int shift = 14 + 1 - BIT_DEPTH;
1470
66112
    int log2Wd = denom + shift - 1;
1471
1472
66112
    src -= EPEL_EXTRA_BEFORE * srcstride;
1473
1474
1011728
    for (y = 0; y < height + EPEL_EXTRA; y++) {
1475
14614476
        for (x = 0; x < width; x++)
1476
13668860
            tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1477
945616
        src += srcstride;
1478
945616
        tmp += MAX_PB_SIZE;
1479
    }
1480
1481
66112
    tmp      = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1482
66112
    filter = ff_hevc_epel_filters[my - 1];
1483
1484
66112
    ox0     = ox0 * (1 << (BIT_DEPTH - 8));
1485
66112
    ox1     = ox1 * (1 << (BIT_DEPTH - 8));
1486
813392
    for (y = 0; y < height; y++) {
1487
12294672
        for (x = 0; x < width; x++)
1488
11547392
            dst[x] = av_clip_pixel(((EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx1 + src2[x] * wx0 +
1489
                                    ((ox0 + ox1 + 1) * (1 << log2Wd))) >> (log2Wd + 1));
1490
747280
        tmp  += MAX_PB_SIZE;
1491
747280
        dst  += dststride;
1492
747280
        src2 += MAX_PB_SIZE;
1493
    }
1494
66112
}
1495
1496
// line zero
1497
#define P3 pix[-4 * xstride]
1498
#define P2 pix[-3 * xstride]
1499
#define P1 pix[-2 * xstride]
1500
#define P0 pix[-1 * xstride]
1501
#define Q0 pix[0 * xstride]
1502
#define Q1 pix[1 * xstride]
1503
#define Q2 pix[2 * xstride]
1504
#define Q3 pix[3 * xstride]
1505
1506
// line three. used only for deblocking decision
1507
#define TP3 pix[-4 * xstride + 3 * ystride]
1508
#define TP2 pix[-3 * xstride + 3 * ystride]
1509
#define TP1 pix[-2 * xstride + 3 * ystride]
1510
#define TP0 pix[-1 * xstride + 3 * ystride]
1511
#define TQ0 pix[0  * xstride + 3 * ystride]
1512
#define TQ1 pix[1  * xstride + 3 * ystride]
1513
#define TQ2 pix[2  * xstride + 3 * ystride]
1514
#define TQ3 pix[3  * xstride + 3 * ystride]
1515
1516
31759025
static void FUNC(hevc_loop_filter_luma)(uint8_t *_pix,
1517
                                        ptrdiff_t _xstride, ptrdiff_t _ystride,
1518
                                        int beta, int *_tc,
1519
                                        uint8_t *_no_p, uint8_t *_no_q)
1520
{
1521
    int d, j;
1522
31759025
    pixel *pix        = (pixel *)_pix;
1523
31759025
    ptrdiff_t xstride = _xstride / sizeof(pixel);
1524
31759025
    ptrdiff_t ystride = _ystride / sizeof(pixel);
1525
1526
31759025
    beta <<= BIT_DEPTH - 8;
1527
1528
95277075
    for (j = 0; j < 2; j++) {
1529
63518050
        const int dp0  = abs(P2  - 2 * P1  + P0);
1530
63518050
        const int dq0  = abs(Q2  - 2 * Q1  + Q0);
1531
63518050
        const int dp3  = abs(TP2 - 2 * TP1 + TP0);
1532
63518050
        const int dq3  = abs(TQ2 - 2 * TQ1 + TQ0);
1533
63518050
        const int d0   = dp0 + dq0;
1534
63518050
        const int d3   = dp3 + dq3;
1535
63518050
        const int tc   = _tc[j]   << (BIT_DEPTH - 8);
1536
63518050
        const int no_p = _no_p[j];
1537
63518050
        const int no_q = _no_q[j];
1538
1539
63518050
        if (d0 + d3 >= beta) {
1540
15454132
            pix += 4 * ystride;
1541
15454132
            continue;
1542
        } else {
1543
48063918
            const int beta_3 = beta >> 3;
1544
48063918
            const int beta_2 = beta >> 2;
1545
48063918
            const int tc25   = ((tc * 5 + 1) >> 1);
1546
1547

48063918
            if (abs(P3  -  P0) + abs(Q3  -  Q0) < beta_3 && abs(P0  -  Q0) < tc25 &&
1548

13334940
                abs(TP3 - TP0) + abs(TQ3 - TQ0) < beta_3 && abs(TP0 - TQ0) < tc25 &&
1549

19209396
                                      (d0 << 1) < beta_2 &&      (d3 << 1) < beta_2) {
1550
                // strong filtering
1551
9326326
                const int tc2 = tc << 1;
1552
46631630
                for (d = 0; d < 4; d++) {
1553
37305304
                    const int p3 = P3;
1554
37305304
                    const int p2 = P2;
1555
37305304
                    const int p1 = P1;
1556
37305304
                    const int p0 = P0;
1557
37305304
                    const int q0 = Q0;
1558
37305304
                    const int q1 = Q1;
1559
37305304
                    const int q2 = Q2;
1560
37305304
                    const int q3 = Q3;
1561
37305304
                    if (!no_p) {
1562
37299760
                        P0 = p0 + av_clip(((p2 + 2 * p1 + 2 * p0 + 2 * q0 + q1 + 4) >> 3) - p0, -tc2, tc2);
1563
37299760
                        P1 = p1 + av_clip(((p2 + p1 + p0 + q0 + 2) >> 2) - p1, -tc2, tc2);
1564
37299760
                        P2 = p2 + av_clip(((2 * p3 + 3 * p2 + p1 + p0 + q0 + 4) >> 3) - p2, -tc2, tc2);
1565
                    }
1566
37305304
                    if (!no_q) {
1567
37299632
                        Q0 = q0 + av_clip(((p1 + 2 * p0 + 2 * q0 + 2 * q1 + q2 + 4) >> 3) - q0, -tc2, tc2);
1568
37299632
                        Q1 = q1 + av_clip(((p0 + q0 + q1 + q2 + 2) >> 2) - q1, -tc2, tc2);
1569
37299632
                        Q2 = q2 + av_clip(((2 * q3 + 3 * q2 + q1 + q0 + p0 + 4) >> 3) - q2, -tc2, tc2);
1570
                    }
1571
37305304
                    pix += ystride;
1572
                }
1573
            } else { // normal filtering
1574
38737592
                int nd_p = 1;
1575
38737592
                int nd_q = 1;
1576
38737592
                const int tc_2 = tc >> 1;
1577
38737592
                if (dp0 + dp3 < ((beta + (beta >> 1)) >> 3))
1578
27330012
                    nd_p = 2;
1579
38737592
                if (dq0 + dq3 < ((beta + (beta >> 1)) >> 3))
1580
26619096
                    nd_q = 2;
1581
1582
193687960
                for (d = 0; d < 4; d++) {
1583
154950368
                    const int p2 = P2;
1584
154950368
                    const int p1 = P1;
1585
154950368
                    const int p0 = P0;
1586
154950368
                    const int q0 = Q0;
1587
154950368
                    const int q1 = Q1;
1588
154950368
                    const int q2 = Q2;
1589
154950368
                    int delta0   = (9 * (q0 - p0) - 3 * (q1 - p1) + 8) >> 4;
1590
154950368
                    if (abs(delta0) < 10 * tc) {
1591
153559377
                        delta0 = av_clip(delta0, -tc, tc);
1592
153559377
                        if (!no_p)
1593
153244060
                            P0 = av_clip_pixel(p0 + delta0);
1594
153559377
                        if (!no_q)
1595
153242129
                            Q0 = av_clip_pixel(q0 - delta0);
1596

153559377
                        if (!no_p && nd_p > 1) {
1597
108312611
                            const int deltap1 = av_clip((((p2 + p0 + 1) >> 1) - p1 + delta0) >> 1, -tc_2, tc_2);
1598
108312611
                            P1 = av_clip_pixel(p1 + deltap1);
1599
                        }
1600

153559377
                        if (!no_q && nd_q > 1) {
1601
105495900
                            const int deltaq1 = av_clip((((q2 + q0 + 1) >> 1) - q1 - delta0) >> 1, -tc_2, tc_2);
1602
105495900
                            Q1 = av_clip_pixel(q1 + deltaq1);
1603
                        }
1604
                    }
1605
154950368
                    pix += ystride;
1606
                }
1607
            }
1608
        }
1609
    }
1610
31759025
}
1611
1612
9184178
static void FUNC(hevc_loop_filter_chroma)(uint8_t *_pix, ptrdiff_t _xstride,
1613
                                          ptrdiff_t _ystride, int *_tc,
1614
                                          uint8_t *_no_p, uint8_t *_no_q)
1615
{
1616
    int d, j, no_p, no_q;
1617
9184178
    pixel *pix        = (pixel *)_pix;
1618
9184178
    ptrdiff_t xstride = _xstride / sizeof(pixel);
1619
9184178
    ptrdiff_t ystride = _ystride / sizeof(pixel);
1620
1621
27552534
    for (j = 0; j < 2; j++) {
1622
18368356
        const int tc = _tc[j] << (BIT_DEPTH - 8);
1623
18368356
        if (tc <= 0) {
1624
1040945
            pix += 4 * ystride;
1625
1040945
            continue;
1626
        }
1627
17327411
        no_p = _no_p[j];
1628
17327411
        no_q = _no_q[j];
1629
1630
86637055
        for (d = 0; d < 4; d++) {
1631
            int delta0;
1632
69309644
            const int p1 = P1;
1633
69309644
            const int p0 = P0;
1634
69309644
            const int q0 = Q0;
1635
69309644
            const int q1 = Q1;
1636
69309644
            delta0 = av_clip((((q0 - p0) * 4) + p1 - q1 + 4) >> 3, -tc, tc);
1637
69309644
            if (!no_p)
1638
69047052
                P0 = av_clip_pixel(p0 + delta0);
1639
69309644
            if (!no_q)
1640
69043196
                Q0 = av_clip_pixel(q0 - delta0);
1641
69309644
            pix += ystride;
1642
        }
1643
    }
1644
9184178
}
1645
1646
4550202
static void FUNC(hevc_h_loop_filter_chroma)(uint8_t *pix, ptrdiff_t stride,
1647
                                            int32_t *tc, uint8_t *no_p,
1648
                                            uint8_t *no_q)
1649
{
1650
4550202
    FUNC(hevc_loop_filter_chroma)(pix, stride, sizeof(pixel), tc, no_p, no_q);
1651
4550202
}
1652
1653
4633976
static void FUNC(hevc_v_loop_filter_chroma)(uint8_t *pix, ptrdiff_t stride,
1654
                                            int32_t *tc, uint8_t *no_p,
1655
                                            uint8_t *no_q)
1656
{
1657
4633976
    FUNC(hevc_loop_filter_chroma)(pix, sizeof(pixel), stride, tc, no_p, no_q);
1658
4633976
}
1659
1660
16028149
static void FUNC(hevc_h_loop_filter_luma)(uint8_t *pix, ptrdiff_t stride,
1661
                                          int beta, int32_t *tc, uint8_t *no_p,
1662
                                          uint8_t *no_q)
1663
{
1664
16028149
    FUNC(hevc_loop_filter_luma)(pix, stride, sizeof(pixel),
1665
                                beta, tc, no_p, no_q);
1666
16028149
}
1667
1668
15730876
static void FUNC(hevc_v_loop_filter_luma)(uint8_t *pix, ptrdiff_t stride,
1669
                                          int beta, int32_t *tc, uint8_t *no_p,
1670
                                          uint8_t *no_q)
1671
{
1672
15730876
    FUNC(hevc_loop_filter_luma)(pix, sizeof(pixel), stride,
1673
                                beta, tc, no_p, no_q);
1674
15730876
}
1675
1676
#undef P3
1677
#undef P2
1678
#undef P1
1679
#undef P0
1680
#undef Q0
1681
#undef Q1
1682
#undef Q2
1683
#undef Q3
1684
1685
#undef TP3
1686
#undef TP2
1687
#undef TP1
1688
#undef TP0
1689
#undef TQ0
1690
#undef TQ1
1691
#undef TQ2
1692
#undef TQ3