/src/ffmpeg/libavcodec/vvc/dsp.c
Line | Count | Source |
1 | | /* |
2 | | * VVC DSP |
3 | | * |
4 | | * Copyright (C) 2021 Nuo Mi |
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 "dsp.h" |
24 | | #include "ctu.h" |
25 | | #include "itx_1d.h" |
26 | | |
27 | 0 | #define VVC_SIGN(v) (v < 0 ? -1 : !!v) |
28 | | |
29 | | static int vvc_sad(const int16_t *src0, const int16_t *src1, int dx, int dy, |
30 | | const int block_w, const int block_h) |
31 | 12.2k | { |
32 | 12.2k | int sad = 0; |
33 | 12.2k | dx -= 2; |
34 | 12.2k | dy -= 2; |
35 | 12.2k | src0 += (2 + dy) * MAX_PB_SIZE + 2 + dx; |
36 | 12.2k | src1 += (2 - dy) * MAX_PB_SIZE + 2 - dx; |
37 | 108k | for (int y = 0; y < block_h; y += 2) { |
38 | 1.61M | for (int x = 0; x < block_w; x++) { |
39 | 1.51M | sad += FFABS(src0[x] - src1[x]); |
40 | 1.51M | } |
41 | 96.3k | src0 += 2 * MAX_PB_SIZE; |
42 | 96.3k | src1 += 2 * MAX_PB_SIZE; |
43 | 96.3k | } |
44 | 12.2k | return sad; |
45 | 12.2k | } |
46 | | |
47 | | static av_always_inline void unpack_mip_info(int *intra_mip_transposed_flag, |
48 | | int *intra_mip_mode, const uint8_t mip_info) |
49 | 176k | { |
50 | 176k | if (intra_mip_transposed_flag) |
51 | 176k | *intra_mip_transposed_flag = (mip_info >> 1) & 0x1; |
52 | 176k | if (intra_mip_mode) |
53 | 176k | *intra_mip_mode = (mip_info >> 2) & 0xf; |
54 | 176k | } |
55 | | |
56 | | typedef struct IntraEdgeParams { |
57 | | uint8_t* top; |
58 | | uint8_t* left; |
59 | | int filter_flag; |
60 | | |
61 | | uint16_t left_array[6 * MAX_TB_SIZE + 5]; |
62 | | uint16_t filtered_left_array[6 * MAX_TB_SIZE + 5]; |
63 | | uint16_t top_array[6 * MAX_TB_SIZE + 5]; |
64 | | uint16_t filtered_top_array[6 * MAX_TB_SIZE + 5]; |
65 | | } IntraEdgeParams; |
66 | | |
67 | | #define PROF_BORDER_EXT 1 |
68 | | #define PROF_BLOCK_SIZE (AFFINE_MIN_BLOCK_SIZE + PROF_BORDER_EXT * 2) |
69 | | |
70 | 7.00M | #define BDOF_BORDER_EXT 1 |
71 | 0 | #define BDOF_BLOCK_SIZE 16 |
72 | 0 | #define BDOF_MIN_BLOCK_SIZE 4 |
73 | | |
74 | 762M | #define BIT_DEPTH 8 |
75 | | #include "dsp_template.c" |
76 | | #undef BIT_DEPTH |
77 | | |
78 | 20.1G | #define BIT_DEPTH 10 |
79 | | #include "dsp_template.c" |
80 | | #undef BIT_DEPTH |
81 | | |
82 | 5.57G | #define BIT_DEPTH 12 |
83 | | #include "dsp_template.c" |
84 | | #undef BIT_DEPTH |
85 | | |
86 | | void ff_vvc_dsp_init(VVCDSPContext *vvcdsp, int bit_depth) |
87 | 1.92M | { |
88 | 1.92M | #undef FUNC |
89 | 13.4M | #define FUNC(a, depth) a ## _ ## depth |
90 | | |
91 | 1.92M | #define VVC_DSP(depth) \ |
92 | 1.92M | FUNC(ff_vvc_inter_dsp_init, depth)(&vvcdsp->inter); \ |
93 | 1.92M | FUNC(ff_vvc_intra_dsp_init, depth)(&vvcdsp->intra); \ |
94 | 1.92M | FUNC(ff_vvc_itx_dsp_init, depth)(&vvcdsp->itx); \ |
95 | 1.92M | FUNC(ff_vvc_lmcs_dsp_init, depth)(&vvcdsp->lmcs); \ |
96 | 1.92M | FUNC(ff_vvc_lf_dsp_init, depth)(&vvcdsp->lf); \ |
97 | 1.92M | FUNC(ff_vvc_sao_dsp_init, depth)(&vvcdsp->sao); \ |
98 | 1.92M | FUNC(ff_vvc_alf_dsp_init, depth)(&vvcdsp->alf); \ |
99 | 1.92M | |
100 | 1.92M | switch (bit_depth) { |
101 | 620k | case 12: |
102 | 620k | VVC_DSP(12); |
103 | 620k | break; |
104 | 106k | case 10: |
105 | 106k | VVC_DSP(10); |
106 | 106k | break; |
107 | 1.19M | default: |
108 | 1.19M | VVC_DSP(8); |
109 | 1.19M | break; |
110 | 1.92M | } |
111 | | |
112 | | #if ARCH_AARCH64 |
113 | | ff_vvc_dsp_init_aarch64(vvcdsp, bit_depth); |
114 | | #elif ARCH_RISCV |
115 | | ff_vvc_dsp_init_riscv(vvcdsp, bit_depth); |
116 | | #elif ARCH_X86 && HAVE_X86ASM |
117 | | ff_vvc_dsp_init_x86(vvcdsp, bit_depth); |
118 | | #endif |
119 | 1.92M | } |