Coverage Report

Created: 2026-10-17 07:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/contrib/contrib-build/bpg/libavcodec/hevcpred_template.c
Line
Count
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 "libavutil/pixdesc.h"
24
25
#include "bit_depth_template.c"
26
#include "hevcpred.h"
27
28
#ifndef USE_FUNC_PTR
29
static HEVC_INLINE void FUNC(pred_planar)(uint8_t *_src, const uint8_t *_top,
30
                                          const uint8_t *_left, ptrdiff_t stride,
31
                                          int trafo_size);
32
static void FUNC(pred_dc)(uint8_t *_src, const uint8_t *_top,
33
                          const uint8_t *_left,
34
                          ptrdiff_t stride, int log2_size, int c_idx);
35
static HEVC_INLINE void FUNC(pred_angular)(uint8_t *_src,
36
                                           const uint8_t *_top,
37
                                           const uint8_t *_left,
38
                                           ptrdiff_t stride, int c_idx,
39
                                           int mode, int size, 
40
                                           int disable_intra_boundary_filter BIT_DEPTH_PARAM);
41
#endif
42
43
0
#define POS(x, y) src[(x) + stride * (y)]
44
45
#ifdef USE_FUNC_PTR
46
static HEVC_INLINE void FUNC(intra_pred)
47
#else
48
void intra_pred
49
#endif
50
(HEVCContext *s, int x0, int y0, int log2_size, int c_idx)
51
0
{
52
0
#define PU(x) \
53
0
    ((x) >> s->sps->log2_min_pu_size)
54
0
#ifdef USE_PRED
55
0
#define MVF(x, y) \
56
0
    (s->ref->tab_mvf[(x) + (y) * min_pu_width].pred_flag)
57
#else
58
#define MVF(x, y) PF_INTRA
59
#endif
60
0
#define MVF_PU(x, y) \
61
0
    MVF(PU(x0 + ((x) << hshift)), PU(y0 + ((y) << vshift)))
62
0
#define IS_INTRA(x, y) \
63
0
    (MVF_PU(x, y) == PF_INTRA)
64
0
#define MIN_TB_ADDR_ZS(x, y) \
65
0
    s->pps->min_tb_addr_zs[(y) * (s->sps->tb_mask+2) + (x)]
66
0
#define EXTEND(ptr, val, len)         \
67
0
do {                                  \
68
0
    pixel4 pix = PIXEL_SPLAT_X4(val); \
69
0
    for (i = 0; i < (len); i += 4)    \
70
0
        AV_WN4P(ptr + i, pix);        \
71
0
} while (0)
72
73
0
#define EXTEND_RIGHT_CIP(ptr, start, length)                                   \
74
0
        for (i = start; i < (start) + (length); i += 4)                        \
75
0
            if (!IS_INTRA(i, -1))                                              \
76
0
                AV_WN4P(&ptr[i], a);                                           \
77
0
            else                                                               \
78
0
                a = PIXEL_SPLAT_X4(ptr[i+3])
79
0
#define EXTEND_LEFT_CIP(ptr, start, length) \
80
0
        for (i = start; i > (start) - (length); i--) \
81
0
            if (!IS_INTRA(i - 1, -1)) \
82
0
                ptr[i - 1] = ptr[i]
83
0
#define EXTEND_UP_CIP(ptr, start, length)                                      \
84
0
        for (i = (start); i > (start) - (length); i -= 4)                      \
85
0
            if (!IS_INTRA(-1, i - 3))                                          \
86
0
                AV_WN4P(&ptr[i - 3], a);                                       \
87
0
            else                                                               \
88
0
                a = PIXEL_SPLAT_X4(ptr[i - 3])
89
0
#define EXTEND_DOWN_CIP(ptr, start, length)                                    \
90
0
        for (i = start; i < (start) + (length); i += 4)                        \
91
0
            if (!IS_INTRA(-1, i))                                              \
92
0
                AV_WN4P(&ptr[i], a);                                           \
93
0
            else                                                               \
94
0
                a = PIXEL_SPLAT_X4(ptr[i + 3])
95
96
0
    HEVCLocalContext *lc = s->HEVClc;
97
0
#ifdef USE_VAR_BIT_DEPTH
98
0
    int bit_depth = s->sps->bit_depth;
99
0
#endif
100
0
    int i;
101
0
    int hshift = s->sps->hshift[c_idx];
102
0
    int vshift = s->sps->vshift[c_idx];
103
0
    int size = (1 << log2_size);
104
0
    int size_in_luma_h = size << hshift;
105
0
    int size_in_tbs_h  = size_in_luma_h >> s->sps->log2_min_tb_size;
106
0
    int size_in_luma_v = size << vshift;
107
0
    int size_in_tbs_v  = size_in_luma_v >> s->sps->log2_min_tb_size;
108
0
    int x = x0 >> hshift;
109
0
    int y = y0 >> vshift;
110
0
    int x_tb = (x0 >> s->sps->log2_min_tb_size) & s->sps->tb_mask;
111
0
    int y_tb = (y0 >> s->sps->log2_min_tb_size) & s->sps->tb_mask;
112
113
0
    int cur_tb_addr = MIN_TB_ADDR_ZS(x_tb, y_tb);
114
115
0
    ptrdiff_t stride = s->frame->linesize[c_idx] / sizeof(pixel);
116
0
    pixel *src = (pixel*)s->frame->data[c_idx] + x + y * stride;
117
118
0
    int min_pu_width = s->sps->min_pu_width;
119
120
0
    enum IntraPredMode mode = c_idx ? lc->tu.intra_pred_mode_c :
121
0
                              lc->tu.intra_pred_mode;
122
0
    pixel4 a;
123
0
    pixel  left_array[2 * MAX_TB_SIZE + 1];
124
0
    pixel  filtered_left_array[2 * MAX_TB_SIZE + 1];
125
0
    pixel  top_array[2 * MAX_TB_SIZE + 1];
126
0
    pixel  filtered_top_array[2 * MAX_TB_SIZE + 1];
127
128
0
    pixel  *left          = left_array + 1;
129
0
    pixel  *top           = top_array  + 1;
130
0
    pixel  *filtered_left = filtered_left_array + 1;
131
0
    pixel  *filtered_top  = filtered_top_array  + 1;
132
0
    int cand_bottom_left = lc->na.cand_bottom_left && cur_tb_addr > MIN_TB_ADDR_ZS( x_tb - 1, (y_tb + size_in_tbs_v) & s->sps->tb_mask);
133
0
    int cand_left        = lc->na.cand_left;
134
0
    int cand_up_left     = lc->na.cand_up_left;
135
0
    int cand_up          = lc->na.cand_up;
136
0
    int cand_up_right    = lc->na.cand_up_right    && cur_tb_addr > MIN_TB_ADDR_ZS((x_tb + size_in_tbs_h) & s->sps->tb_mask, y_tb - 1);
137
138
0
    int bottom_left_size = (FFMIN(y0 + 2 * size_in_luma_v, s->sps->height) -
139
0
                           (y0 + size_in_luma_v)) >> vshift;
140
0
    int top_right_size   = (FFMIN(x0 + 2 * size_in_luma_h, s->sps->width) -
141
0
                           (x0 + size_in_luma_h)) >> hshift;
142
0
    int disable_intra_boundary_filter;
143
144
0
    if (s->pps->constrained_intra_pred_flag == 1) {
145
0
        int size_in_luma_pu_v = PU(size_in_luma_v);
146
0
        int size_in_luma_pu_h = PU(size_in_luma_h);
147
0
        int on_pu_edge_x    = !(x0 & ((1 << s->sps->log2_min_pu_size) - 1));
148
0
        int on_pu_edge_y    = !(y0 & ((1 << s->sps->log2_min_pu_size) - 1));
149
0
        if (!size_in_luma_pu_h)
150
0
            size_in_luma_pu_h++;
151
0
        if (cand_bottom_left == 1 && on_pu_edge_x) {
152
0
            int x_left_pu   = PU(x0 - 1);
153
0
            int y_bottom_pu = PU(y0 + size_in_luma_v);
154
0
            int max = FFMIN(size_in_luma_pu_v, s->sps->min_pu_height - y_bottom_pu);
155
0
            cand_bottom_left = 0;
156
0
            for (i = 0; i < max; i += 2)
157
0
                cand_bottom_left |= (MVF(x_left_pu, y_bottom_pu + i) == PF_INTRA);
158
0
        }
159
0
        if (cand_left == 1 && on_pu_edge_x) {
160
0
            int x_left_pu   = PU(x0 - 1);
161
0
            int y_left_pu   = PU(y0);
162
0
            int max = FFMIN(size_in_luma_pu_v, s->sps->min_pu_height - y_left_pu);
163
0
            cand_left = 0;
164
0
            for (i = 0; i < max; i += 2)
165
0
                cand_left |= (MVF(x_left_pu, y_left_pu + i) == PF_INTRA);
166
0
        }
167
0
        if (cand_up_left == 1) {
168
0
            int x_left_pu   = PU(x0 - 1);
169
0
            int y_top_pu    = PU(y0 - 1);
170
0
            cand_up_left = MVF(x_left_pu, y_top_pu) == PF_INTRA;
171
0
        }
172
0
        if (cand_up == 1 && on_pu_edge_y) {
173
0
            int x_top_pu    = PU(x0);
174
0
            int y_top_pu    = PU(y0 - 1);
175
0
            int max = FFMIN(size_in_luma_pu_h, s->sps->min_pu_width - x_top_pu);
176
0
            cand_up = 0;
177
0
            for (i = 0; i < max; i += 2)
178
0
                cand_up |= (MVF(x_top_pu + i, y_top_pu) == PF_INTRA);
179
0
        }
180
0
        if (cand_up_right == 1 && on_pu_edge_y) {
181
0
            int y_top_pu    = PU(y0 - 1);
182
0
            int x_right_pu  = PU(x0 + size_in_luma_h);
183
0
            int max = FFMIN(size_in_luma_pu_h, s->sps->min_pu_width - x_right_pu);
184
0
            cand_up_right = 0;
185
0
            for (i = 0; i < max; i += 2)
186
0
                cand_up_right |= (MVF(x_right_pu + i, y_top_pu) == PF_INTRA);
187
0
        }
188
0
        memset(left, 128, 2 * MAX_TB_SIZE*sizeof(pixel));
189
0
        memset(top , 128, 2 * MAX_TB_SIZE*sizeof(pixel));
190
0
        top[-1] = 128;
191
0
    }
192
0
    if (cand_up_left) {
193
0
        left[-1] = POS(-1, -1);
194
0
        top[-1]  = left[-1];
195
0
    }
196
0
    if (cand_up)
197
0
        memcpy(top, src - stride, size * sizeof(pixel));
198
0
    if (cand_up_right) {
199
0
        memcpy(top + size, src - stride + size, size * sizeof(pixel));
200
0
        EXTEND(top + size + top_right_size, POS(size + top_right_size - 1, -1),
201
0
               size - top_right_size);
202
0
    }
203
0
    if (cand_left)
204
0
        for (i = 0; i < size; i++)
205
0
            left[i] = POS(-1, i);
206
0
    if (cand_bottom_left) {
207
0
        for (i = size; i < size + bottom_left_size; i++)
208
0
            left[i] = POS(-1, i);
209
0
        EXTEND(left + size + bottom_left_size, POS(-1, size + bottom_left_size - 1),
210
0
               size - bottom_left_size);
211
0
    }
212
213
0
    if (s->pps->constrained_intra_pred_flag == 1) {
214
0
        if (cand_bottom_left || cand_left || cand_up_left || cand_up || cand_up_right) {
215
0
            int size_max_x = x0 + ((2 * size) << hshift) < s->sps->width ?
216
0
                                    2 * size : (s->sps->width - x0) >> hshift;
217
0
            int size_max_y = y0 + ((2 * size) << vshift) < s->sps->height ?
218
0
                                    2 * size : (s->sps->height - y0) >> vshift;
219
0
            int j = size + (cand_bottom_left? bottom_left_size: 0) -1;
220
0
            if (!cand_up_right) {
221
0
                size_max_x = x0 + ((size) << hshift) < s->sps->width ?
222
0
                                                    size : (s->sps->width - x0) >> hshift;
223
0
            }
224
0
            if (!cand_bottom_left) {
225
0
                size_max_y = y0 + (( size) << vshift) < s->sps->height ?
226
0
                                                     size : (s->sps->height - y0) >> vshift;
227
0
            }
228
0
            if (cand_bottom_left || cand_left || cand_up_left) {
229
0
                while (j > -1 && !IS_INTRA(-1, j))
230
0
                    j--;
231
0
                if (!IS_INTRA(-1, j)) {
232
0
                    j = 0;
233
0
                    while (j < size_max_x && !IS_INTRA(j, -1))
234
0
                        j++;
235
0
                    EXTEND_LEFT_CIP(top, j, j + 1);
236
0
                    left[-1] = top[-1];
237
0
                }
238
0
            } else {
239
0
                j = 0;
240
0
                while (j < size_max_x && !IS_INTRA(j, -1))
241
0
                    j++;
242
0
                if (j > 0)
243
0
                    if (x0 > 0) {
244
0
                        EXTEND_LEFT_CIP(top, j, j + 1);
245
0
                    } else {
246
0
                        EXTEND_LEFT_CIP(top, j, j);
247
0
                        top[-1] = top[0];
248
0
                    }
249
0
                left[-1] = top[-1];
250
0
            }
251
0
            left[-1] = top[-1];
252
0
            if (cand_bottom_left || cand_left) {
253
0
                a = PIXEL_SPLAT_X4(left[-1]);
254
0
                EXTEND_DOWN_CIP(left, 0, size_max_y);
255
0
            }
256
0
            if (!cand_left)
257
0
                EXTEND(left, left[-1], size);
258
0
            if (!cand_bottom_left)
259
0
                EXTEND(left + size, left[size - 1], size);
260
0
            if (x0 != 0 && y0 != 0) {
261
0
                a = PIXEL_SPLAT_X4(left[size_max_y - 1]);
262
0
                EXTEND_UP_CIP(left, size_max_y - 1, size_max_y);
263
0
                if (!IS_INTRA(-1, - 1))
264
0
                    left[-1] = left[0];
265
0
            } else if (x0 == 0) {
266
0
                EXTEND(left, 0, size_max_y);
267
0
            } else {
268
0
                a = PIXEL_SPLAT_X4(left[size_max_y - 1]);
269
0
                EXTEND_UP_CIP(left, size_max_y - 1, size_max_y);
270
0
            }
271
0
            top[-1] = left[-1];
272
0
            if (y0 != 0) {
273
0
                a = PIXEL_SPLAT_X4(left[-1]);
274
0
                EXTEND_RIGHT_CIP(top, 0, size_max_x);
275
0
            }
276
0
        }
277
0
    }
278
    // Infer the unavailable samples
279
0
    if (!cand_bottom_left) {
280
0
        if (cand_left) {
281
0
            EXTEND(left + size, left[size - 1], size);
282
0
        } else if (cand_up_left) {
283
0
            EXTEND(left, left[-1], 2 * size);
284
0
            cand_left = 1;
285
0
        } else if (cand_up) {
286
0
            left[-1] = top[0];
287
0
            EXTEND(left, left[-1], 2 * size);
288
0
            cand_up_left = 1;
289
0
            cand_left    = 1;
290
0
        } else if (cand_up_right) {
291
0
            EXTEND(top, top[size], size);
292
0
            left[-1] = top[size];
293
0
            EXTEND(left, left[-1], 2 * size);
294
0
            cand_up      = 1;
295
0
            cand_up_left = 1;
296
0
            cand_left    = 1;
297
0
        } else { // No samples available
298
0
            left[-1] = (1 << (BIT_DEPTH - 1));
299
0
            EXTEND(top,  left[-1], 2 * size);
300
0
            EXTEND(left, left[-1], 2 * size);
301
0
        }
302
0
    }
303
304
0
    if (!cand_left)
305
0
        EXTEND(left, left[size], size);
306
0
    if (!cand_up_left) {
307
0
        left[-1] = left[0];
308
0
    }
309
0
    if (!cand_up)
310
0
        EXTEND(top, left[-1], size);
311
0
    if (!cand_up_right)
312
0
        EXTEND(top + size, top[size - 1], size);
313
314
0
    top[-1] = left[-1];
315
316
    // Filtering process
317
0
    if (!s->sps->intra_smoothing_disabled_flag && (c_idx == 0  || s->sps->chroma_format_idc == 3)) {
318
0
        if (mode != INTRA_DC && size != 4){
319
0
            int intra_hor_ver_dist_thresh[] = { 7, 1, 0 };
320
0
            int min_dist_vert_hor = FFMIN(FFABS((int)(mode - 26U)),
321
0
                                          FFABS((int)(mode - 10U)));
322
0
            if (min_dist_vert_hor > intra_hor_ver_dist_thresh[log2_size - 3]) {
323
0
                int threshold = 1 << (BIT_DEPTH - 5);
324
0
                if (s->sps->sps_strong_intra_smoothing_enable_flag && c_idx == 0 &&
325
0
                    log2_size == 5 &&
326
0
                    FFABS(top[-1]  + top[63]  - 2 * top[31])  < threshold &&
327
0
                    FFABS(left[-1] + left[63] - 2 * left[31]) < threshold) {
328
                    // We can't just overwrite values in top because it could be
329
                    // a pointer into src
330
0
                    filtered_top[-1] = top[-1];
331
0
                    filtered_top[63] = top[63];
332
0
                    for (i = 0; i < 63; i++)
333
0
                        filtered_top[i] = ((64 - (i + 1)) * top[-1] +
334
0
                                           (i + 1)  * top[63] + 32) >> 6;
335
0
                    for (i = 0; i < 63; i++)
336
0
                        left[i] = ((64 - (i + 1)) * left[-1] +
337
0
                                   (i + 1)  * left[63] + 32) >> 6;
338
0
                    top = filtered_top;
339
0
                } else {
340
0
                    filtered_left[2 * size - 1] = left[2 * size - 1];
341
0
                    filtered_top[2 * size - 1]  = top[2 * size - 1];
342
0
                    for (i = 2 * size - 2; i >= 0; i--)
343
0
                        filtered_left[i] = (left[i + 1] + 2 * left[i] +
344
0
                                            left[i - 1] + 2) >> 2;
345
0
                    filtered_top[-1]  =
346
0
                    filtered_left[-1] = (left[0] + 2 * left[-1] + top[0] + 2) >> 2;
347
0
                    for (i = 2 * size - 2; i >= 0; i--)
348
0
                        filtered_top[i] = (top[i + 1] + 2 * top[i] +
349
0
                                           top[i - 1] + 2) >> 2;
350
0
                    left = filtered_left;
351
0
                    top  = filtered_top;
352
0
                }
353
0
            }
354
0
        }
355
0
    }
356
357
0
    switch (mode) {
358
0
    case INTRA_PLANAR:
359
#ifdef USE_FUNC_PTR
360
        s->hpc.pred_planar[log2_size - 2]((uint8_t *)src, (uint8_t *)top,
361
                                          (uint8_t *)left, stride);
362
#else
363
0
        FUNC(pred_planar)((uint8_t *)src, (uint8_t *)top,
364
0
                          (uint8_t *)left, stride, log2_size);
365
0
#endif
366
0
        break;
367
0
    case INTRA_DC:
368
#ifdef USE_FUNC_PTR
369
        s->hpc.pred_dc((uint8_t *)src, (uint8_t *)top,
370
                       (uint8_t *)left, stride, log2_size, c_idx);
371
#else
372
0
        FUNC(pred_dc)((uint8_t *)src, (uint8_t *)top,
373
0
                      (uint8_t *)left, stride, log2_size, c_idx);
374
0
#endif
375
0
        break;
376
0
    default:
377
0
        disable_intra_boundary_filter = (s->sps->implicit_rdpcm_enabled_flag &&
378
0
                                         lc->cu.cu_transquant_bypass_flag);
379
#ifdef USE_FUNC_PTR
380
        s->hpc.pred_angular[log2_size - 2]((uint8_t *)src, (uint8_t *)top,
381
                                           (uint8_t *)left, stride, c_idx,
382
                                           mode, 
383
                                           disable_intra_boundary_filter BIT_DEPTH_ARG);
384
#else
385
0
        FUNC(pred_angular)((uint8_t *)src, (uint8_t *)top,
386
0
                           (uint8_t *)left, stride, c_idx,
387
0
                           mode, 1 << log2_size,
388
0
                           disable_intra_boundary_filter BIT_DEPTH_ARG);
389
0
#endif
390
0
        break;
391
0
    }
392
0
}
393
394
#ifdef USE_FUNC_PTR
395
396
#define INTRA_PRED(size)                                                            \
397
static void FUNC(intra_pred_ ## size)(HEVCContext *s, int x0, int y0, int c_idx)    \
398
{                                                                                   \
399
    FUNC(intra_pred)(s, x0, y0, size, c_idx);                                       \
400
}
401
402
INTRA_PRED(2)
403
INTRA_PRED(3)
404
INTRA_PRED(4)
405
INTRA_PRED(5)
406
407
#undef INTRA_PRED
408
409
#endif
410
411
static HEVC_INLINE void FUNC(pred_planar)(uint8_t *_src, const uint8_t *_top,
412
                                  const uint8_t *_left, ptrdiff_t stride,
413
                                  int trafo_size)
414
0
{
415
0
    int x, y;
416
0
    pixel *src        = (pixel *)_src;
417
0
    const pixel *top  = (const pixel *)_top;
418
0
    const pixel *left = (const pixel *)_left;
419
0
    int size = 1 << trafo_size;
420
0
    for (y = 0; y < size; y++)
421
0
        for (x = 0; x < size; x++)
422
0
            POS(x, y) = ((size - 1 - x) * left[y] + (x + 1) * top[size]  +
423
0
                         (size - 1 - y) * top[x]  + (y + 1) * left[size] + size) >> (trafo_size + 1);
424
0
}
425
426
#ifdef USE_FUNC_PTR
427
428
#define PRED_PLANAR(size)\
429
static void FUNC(pred_planar_ ## size)(uint8_t *src, const uint8_t *top,        \
430
                                       const uint8_t *left, ptrdiff_t stride)   \
431
{                                                                               \
432
    FUNC(pred_planar)(src, top, left, stride, size + 2);                        \
433
}
434
435
PRED_PLANAR(0)
436
PRED_PLANAR(1)
437
PRED_PLANAR(2)
438
PRED_PLANAR(3)
439
440
#undef PRED_PLANAR
441
442
#endif
443
444
static void FUNC(pred_dc)(uint8_t *_src, const uint8_t *_top,
445
                          const uint8_t *_left,
446
                          ptrdiff_t stride, int log2_size, int c_idx)
447
0
{
448
0
    int i, j, x, y;
449
0
    int size          = (1 << log2_size);
450
0
    pixel *src        = (pixel *)_src;
451
0
    const pixel *top  = (const pixel *)_top;
452
0
    const pixel *left = (const pixel *)_left;
453
0
    int dc            = size;
454
0
    pixel4 a;
455
0
    for (i = 0; i < size; i++)
456
0
        dc += left[i] + top[i];
457
458
0
    dc >>= log2_size + 1;
459
460
0
    a = PIXEL_SPLAT_X4(dc);
461
462
0
    for (i = 0; i < size; i++)
463
0
        for (j = 0; j < size; j+=4)
464
0
            AV_WN4P(&POS(j, i), a);
465
466
0
    if (c_idx == 0 && size < 32) {
467
0
        POS(0, 0) = (left[0] + 2 * dc + top[0] + 2) >> 2;
468
0
        for (x = 1; x < size; x++)
469
0
            POS(x, 0) = (top[x] + 3 * dc + 2) >> 2;
470
0
        for (y = 1; y < size; y++)
471
0
            POS(0, y) = (left[y] + 3 * dc + 2) >> 2;
472
0
    }
473
0
}
474
475
static HEVC_INLINE void FUNC(pred_angular)(uint8_t *_src,
476
                                           const uint8_t *_top,
477
                                           const uint8_t *_left,
478
                                           ptrdiff_t stride, int c_idx,
479
                                           int mode, int size, 
480
                                           int disable_intra_boundary_filter BIT_DEPTH_PARAM)
481
0
{
482
0
    int x, y;
483
0
    pixel *src        = (pixel *)_src;
484
0
    const pixel *top  = (const pixel *)_top;
485
0
    const pixel *left = (const pixel *)_left;
486
487
0
    static const int8_t intra_pred_angle[] = {
488
0
         32,  26,  21,  17, 13,  9,  5, 2, 0, -2, -5, -9, -13, -17, -21, -26, -32,
489
0
        -26, -21, -17, -13, -9, -5, -2, 0, 2,  5,  9, 13,  17,  21,  26,  32
490
0
    };
491
0
    static const int16_t inv_angle[] = {
492
0
        -4096, -1638, -910, -630, -482, -390, -315, -256, -315, -390, -482,
493
0
        -630, -910, -1638, -4096
494
0
    };
495
496
0
    int angle = intra_pred_angle[mode - 2];
497
0
    pixel ref_array[3 * MAX_TB_SIZE + 4];
498
0
    pixel *ref_tmp = ref_array + size;
499
0
    const pixel *ref;
500
0
    int last = (size * angle) >> 5;
501
502
0
    if (mode >= 18) {
503
0
        ref = top - 1;
504
0
        if (angle < 0 && last < -1) {
505
0
            for (x = 0; x <= size; x += 4)
506
0
                AV_WN4P(&ref_tmp[x], AV_RN4P(&top[x - 1]));
507
0
            for (x = last; x <= -1; x++)
508
0
                ref_tmp[x] = left[-1 + ((x * inv_angle[mode - 11] + 128) >> 8)];
509
0
            ref = ref_tmp;
510
0
        }
511
512
0
        for (y = 0; y < size; y++) {
513
0
            int idx  = ((y + 1) * angle) >> 5;
514
0
            int fact = ((y + 1) * angle) & 31;
515
0
            if (fact) {
516
0
                for (x = 0; x < size; x += 4) {
517
0
                    POS(x    , y) = ((32 - fact) * ref[x + idx + 1] +
518
0
                                           fact  * ref[x + idx + 2] + 16) >> 5;
519
0
                    POS(x + 1, y) = ((32 - fact) * ref[x + 1 + idx + 1] +
520
0
                                           fact  * ref[x + 1 + idx + 2] + 16) >> 5;
521
0
                    POS(x + 2, y) = ((32 - fact) * ref[x + 2 + idx + 1] +
522
0
                                           fact  * ref[x + 2 + idx + 2] + 16) >> 5;
523
0
                    POS(x + 3, y) = ((32 - fact) * ref[x + 3 + idx + 1] +
524
0
                                           fact  * ref[x + 3 + idx + 2] + 16) >> 5;
525
0
                }
526
0
            } else {
527
0
                for (x = 0; x < size; x += 4)
528
0
                    AV_WN4P(&POS(x, y), AV_RN4P(&ref[x + idx + 1]));
529
0
            }
530
0
        }
531
0
        if (mode == 26 && c_idx == 0 && size < 32 && 
532
0
            !disable_intra_boundary_filter) {
533
0
            for (y = 0; y < size; y++)
534
0
                POS(0, y) = av_clip_pixel(top[0] + ((left[y] - left[-1]) >> 1));
535
0
        }
536
0
    } else {
537
0
        ref = left - 1;
538
0
        if (angle < 0 && last < -1) {
539
0
            for (x = 0; x <= size; x += 4)
540
0
                AV_WN4P(&ref_tmp[x], AV_RN4P(&left[x - 1]));
541
0
            for (x = last; x <= -1; x++)
542
0
                ref_tmp[x] = top[-1 + ((x * inv_angle[mode - 11] + 128) >> 8)];
543
0
            ref = ref_tmp;
544
0
        }
545
546
0
        for (x = 0; x < size; x++) {
547
0
            int idx  = ((x + 1) * angle) >> 5;
548
0
            int fact = ((x + 1) * angle) & 31;
549
0
            if (fact) {
550
0
                for (y = 0; y < size; y++) {
551
0
                    POS(x, y) = ((32 - fact) * ref[y + idx + 1] +
552
0
                                       fact  * ref[y + idx + 2] + 16) >> 5;
553
0
                }
554
0
            } else {
555
0
                for (y = 0; y < size; y++)
556
0
                    POS(x, y) = ref[y + idx + 1];
557
0
            }
558
0
        }
559
0
        if (mode == 10 && c_idx == 0 && size < 32 && 
560
0
            !disable_intra_boundary_filter) {
561
0
            for (x = 0; x < size; x += 4) {
562
0
                POS(x,     0) = av_clip_pixel(left[0] + ((top[x    ] - top[-1]) >> 1));
563
0
                POS(x + 1, 0) = av_clip_pixel(left[0] + ((top[x + 1] - top[-1]) >> 1));
564
0
                POS(x + 2, 0) = av_clip_pixel(left[0] + ((top[x + 2] - top[-1]) >> 1));
565
0
                POS(x + 3, 0) = av_clip_pixel(left[0] + ((top[x + 3] - top[-1]) >> 1));
566
0
            }
567
0
        }
568
0
    }
569
0
}
570
571
#ifdef USE_FUNC_PTR
572
573
static void FUNC(pred_angular_0)(uint8_t *src, const uint8_t *top,
574
                                 const uint8_t *left,
575
                                 ptrdiff_t stride, int c_idx, int mode,
576
                                 int disable_intra_boundary_filter BIT_DEPTH_PARAM)
577
{
578
    FUNC(pred_angular)(src, top, left, stride, c_idx, mode, 1 << 2,
579
                       disable_intra_boundary_filter BIT_DEPTH_ARG);
580
}
581
582
static void FUNC(pred_angular_1)(uint8_t *src, const uint8_t *top,
583
                                 const uint8_t *left,
584
                                 ptrdiff_t stride, int c_idx, int mode,
585
                                 int disable_intra_boundary_filter BIT_DEPTH_PARAM)
586
{
587
    FUNC(pred_angular)(src, top, left, stride, c_idx, mode, 1 << 3,
588
                       disable_intra_boundary_filter BIT_DEPTH_ARG);
589
}
590
591
static void FUNC(pred_angular_2)(uint8_t *src, const uint8_t *top,
592
                                 const uint8_t *left,
593
                                 ptrdiff_t stride, int c_idx, int mode,
594
                                 int disable_intra_boundary_filter BIT_DEPTH_PARAM)
595
{
596
    FUNC(pred_angular)(src, top, left, stride, c_idx, mode, 1 << 4,
597
                       disable_intra_boundary_filter BIT_DEPTH_ARG);
598
}
599
600
static void FUNC(pred_angular_3)(uint8_t *src, const uint8_t *top,
601
                                 const uint8_t *left,
602
                                 ptrdiff_t stride, int c_idx, int mode,
603
                                 int disable_intra_boundary_filter BIT_DEPTH_PARAM)
604
{
605
    FUNC(pred_angular)(src, top, left, stride, c_idx, mode, 1 << 5,
606
                       disable_intra_boundary_filter BIT_DEPTH_ARG);
607
}
608
#endif
609
610
#undef EXTEND_LEFT_CIP
611
#undef EXTEND_RIGHT_CIP
612
#undef EXTEND_UP_CIP
613
#undef EXTEND_DOWN_CIP
614
#undef IS_INTRA
615
#undef MVF_PU
616
#undef MVF
617
#undef PU
618
#undef EXTEND
619
#undef MIN_TB_ADDR_ZS
620
#undef POS