../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
50 / 50
100.0%
Branches:
24 / 24
100.0%
Functions:
3 / 3
100.0%

libavcodec/apv_dsp.c
Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <assert.h>
20 #include <stdint.h>
21 #include <string.h>
22
23 #include "config.h"
24 #include "libavutil/attributes.h"
25 #include "libavutil/avassert.h"
26 #include "libavutil/common.h"
27
28 #include "apv.h"
29 #include "apv_dsp.h"
30
31
32 static const int8_t apv_trans_matrix[8][8] = {
33 { 64, 64, 64, 64, 64, 64, 64, 64 },
34 { 89, 75, 50, 18, -18, -50, -75, -89 },
35 { 84, 35, -35, -84, -84, -35, 35, 84 },
36 { 75, -18, -89, -50, 50, 89, 18, -75 },
37 { 64, -64, -64, 64, 64, -64, -64, 64 },
38 { 50, -89, 18, 75, -75, -18, 89, -50 },
39 { 35, -84, 84, -35, -35, 84, -84, 35 },
40 { 18, -50, 75, -89, 89, -75, 50, -18 },
41 };
42
43 typedef struct APVConstantsC {
44 int16_t qmatrix[8][8];
45 int bit_depth;
46 int qp_shift;
47 } APVConstantsC;
48
49 static_assert(sizeof(APVConstantsC) <= APV_DSP_CONSTANTS_SIZE,
50 "APV DSP constants buffer too small");
51
52 3108 void ff_apv_prepare_constants_c(void *constants,
53 const int16_t *qmatrix,
54 int bit_depth,
55 int qp_shift)
56 {
57 3108 APVConstantsC *c = constants;
58
59 3108 memcpy(c->qmatrix, qmatrix, sizeof(c->qmatrix));
60 3108 c->bit_depth = bit_depth;
61 3108 c->qp_shift = qp_shift;
62 3108 }
63
64 11728 static void apv_decode_transquant_c(void *output,
65 ptrdiff_t pitch,
66 const int16_t *input_flat,
67 const void *constants)
68 {
69 11728 const APVConstantsC *c = constants;
70 11728 const int16_t (*input)[8] = (const int16_t(*)[8])input_flat;
71 11728 int bit_depth = c->bit_depth;
72
73 int16_t scaled_coeff[8][8];
74 int32_t recon_sample[8][8];
75
76 // Dequant.
77 {
78 // Note that level_scale was already combined into qmatrix
79 // before we got here.
80 11728 int bd_shift = bit_depth + 3 - 5;
81
82
2/2
✓ Branch 7 → 3 taken 93824 times.
✓ Branch 7 → 8 taken 11728 times.
105552 for (int y = 0; y < 8; y++) {
83
2/2
✓ Branch 5 → 4 taken 750592 times.
✓ Branch 5 → 6 taken 93824 times.
844416 for (int x = 0; x < 8; x++) {
84 750592 int coeff = ((int)(input[y][x] *
85 750592 c->qmatrix[y][x] *
86 750592 (1U << c->qp_shift) +
87 750592 (1 << (bd_shift - 1)))) >> bd_shift;
88
89 750592 scaled_coeff[y][x] =
90 750592 av_clip(coeff, APV_MIN_TRANS_COEFF,
91 APV_MAX_TRANS_COEFF);
92 }
93 }
94 }
95
96 // Transform.
97 {
98 int32_t tmp[8][8];
99
100 // Vertical transform of columns.
101
2/2
✓ Branch 16 → 9 taken 93824 times.
✓ Branch 16 → 17 taken 11728 times.
105552 for (int x = 0; x < 8; x++) {
102
2/2
✓ Branch 14 → 10 taken 750592 times.
✓ Branch 14 → 15 taken 93824 times.
844416 for (int i = 0; i < 8; i++) {
103 750592 int sum = 0;
104
2/2
✓ Branch 12 → 11 taken 6004736 times.
✓ Branch 12 → 13 taken 750592 times.
6755328 for (int j = 0; j < 8; j++)
105 6004736 sum += apv_trans_matrix[j][i] * scaled_coeff[j][x];
106 750592 tmp[i][x] = sum;
107 }
108 }
109
110 // Renormalise.
111
2/2
✓ Branch 22 → 18 taken 93824 times.
✓ Branch 22 → 23 taken 11728 times.
105552 for (int x = 0; x < 8; x++) {
112
2/2
✓ Branch 20 → 19 taken 750592 times.
✓ Branch 20 → 21 taken 93824 times.
844416 for (int y = 0; y < 8; y++)
113 750592 tmp[y][x] = (tmp[y][x] + 64) >> 7;
114 }
115
116 // Horizontal transform of rows.
117
2/2
✓ Branch 31 → 24 taken 93824 times.
✓ Branch 31 → 32 taken 11728 times.
105552 for (int y = 0; y < 8; y++) {
118
2/2
✓ Branch 29 → 25 taken 750592 times.
✓ Branch 29 → 30 taken 93824 times.
844416 for (int i = 0; i < 8; i++) {
119 750592 int sum = 0;
120
2/2
✓ Branch 27 → 26 taken 6004736 times.
✓ Branch 27 → 28 taken 750592 times.
6755328 for (int j = 0; j < 8; j++)
121 6004736 sum += apv_trans_matrix[j][i] * tmp[y][j];
122 750592 recon_sample[y][i] = sum;
123 }
124 }
125 }
126
127 // Output.
128 av_assert2(bit_depth > 8 && bit_depth <= 16);
129 11728 uint16_t *ptr = output;
130 11728 int bd_shift = 20 - bit_depth;
131 11728 pitch /= 2; // Pitch was in bytes, 2 bytes per sample.
132
133
2/2
✓ Branch 37 → 33 taken 93824 times.
✓ Branch 37 → 38 taken 11728 times.
105552 for (int y = 0; y < 8; y++) {
134
2/2
✓ Branch 35 → 34 taken 750592 times.
✓ Branch 35 → 36 taken 93824 times.
844416 for (int x = 0; x < 8; x++) {
135 750592 int sample = ((recon_sample[y][x] +
136 750592 (1 << (bd_shift - 1))) >> bd_shift) +
137 750592 (1 << (bit_depth - 1));
138 750592 ptr[x] = av_clip_uintp2(sample, bit_depth);
139 }
140 93824 ptr += pitch;
141 }
142 11728 }
143
144 24 av_cold void ff_apv_dsp_init(APVDSPContext *dsp)
145 {
146 24 dsp->prepare_constants = ff_apv_prepare_constants_c;
147 24 dsp->decode_transquant = apv_decode_transquant_c;
148
149 #if ARCH_X86_64 && HAVE_X86ASM
150 24 ff_apv_dsp_init_x86_64(dsp);
151 #endif
152 #if ARCH_AARCH64
153 ff_apv_dsp_init_aarch64(dsp);
154 #endif
155 24 }
156