Coverage Report

Created: 2024-09-06 07:53

/src/ffmpeg/libavcodec/hq_hqadsp.c
Line
Count
Source
1
/*
2
 * Canopus HQ/HQA decoder
3
 *
4
 * This file is part of FFmpeg.
5
 *
6
 * FFmpeg is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2.1 of the License, or (at your option) any later version.
10
 *
11
 * FFmpeg is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with FFmpeg; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 */
20
21
#include <stdint.h>
22
23
#include "libavutil/attributes.h"
24
#include "libavutil/common.h"
25
26
#include "hq_hqadsp.h"
27
28
#define FIX_1_082 17734
29
#define FIX_1_847 30274
30
#define FIX_1_414 23170
31
#define FIX_2_613 21407 // divided by two to fit the range
32
33
83.1M
#define IDCTMUL(a, b) ((int)((a) * (unsigned)(b)) >> 16)
34
35
static inline void idct_row(int16_t *blk)
36
8.31M
{
37
8.31M
    int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, tmp9, tmpA;
38
8.31M
    int tmpB, tmpC, tmpD, tmpE, tmpF, tmp10, tmp11, tmp12, tmp13, tmp14;
39
40
8.31M
    tmp0 = blk[5] - blk[3];
41
8.31M
    tmp1 = blk[5] + blk[3];
42
8.31M
    tmp2 = blk[1] - blk[7];
43
8.31M
    tmp3 = blk[1] + blk[7];
44
8.31M
    tmp4 = tmp3 - tmp1;
45
8.31M
    tmp5 = IDCTMUL(tmp0 + tmp2, FIX_1_847);
46
8.31M
    tmp6 = IDCTMUL(tmp2,        FIX_1_082) - tmp5;
47
8.31M
    tmp7 = tmp5 - IDCTMUL(tmp0, FIX_2_613) * 2;
48
8.31M
    tmp8 = tmp3 + tmp1;
49
8.31M
    tmp9 = tmp7 * 4 - tmp8;
50
8.31M
    tmpA = IDCTMUL(tmp4, FIX_1_414) * 4 - tmp9;
51
8.31M
    tmpB = tmp6 * 4 + tmpA;
52
8.31M
    tmpC = blk[2] + blk[6];
53
8.31M
    tmpD = blk[2] - blk[6];
54
8.31M
    tmpE = blk[0] - blk[4];
55
8.31M
    tmpF = blk[0] + blk[4];
56
57
8.31M
    tmp10 = IDCTMUL(tmpD, FIX_1_414) * 4 - tmpC;
58
8.31M
    tmp11 = tmpE - tmp10;
59
8.31M
    tmp12 = tmpF - tmpC;
60
8.31M
    tmp13 = tmpE + tmp10;
61
8.31M
    tmp14 = tmpF + tmpC;
62
63
8.31M
    blk[0] = tmp14 + tmp8;
64
8.31M
    blk[1] = tmp13 + tmp9;
65
8.31M
    blk[2] = tmp11 + tmpA;
66
8.31M
    blk[3] = tmp12 - tmpB;
67
8.31M
    blk[4] = tmp12 + tmpB;
68
8.31M
    blk[5] = tmp11 - tmpA;
69
8.31M
    blk[6] = tmp13 - tmp9;
70
8.31M
    blk[7] = tmp14 - tmp8;
71
8.31M
}
72
73
static inline void idct_col(int16_t *blk)
74
8.31M
{
75
8.31M
    int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, tmp9, tmpA;
76
8.31M
    int tmpB, tmpC, tmpD, tmpE, tmpF, tmp10, tmp11, tmp12, tmp13, tmp14;
77
78
8.31M
    tmp0 = blk[5 * 8] - blk[3 * 8];
79
8.31M
    tmp1 = blk[5 * 8] + blk[3 * 8];
80
8.31M
    tmp2 = blk[1 * 8] * 2 - (blk[7 * 8] >> 2);
81
8.31M
    tmp3 = blk[1 * 8] * 2 + (blk[7 * 8] >> 2);
82
8.31M
    tmp4 = tmp3 - tmp1;
83
8.31M
    tmp5 = IDCTMUL(tmp0 + tmp2, FIX_1_847);
84
8.31M
    tmp6 = IDCTMUL(tmp2,        FIX_1_082) - tmp5;
85
8.31M
    tmp7 = tmp5 - IDCTMUL(tmp0, FIX_2_613) * 2;
86
8.31M
    tmp8 = (tmp3 + tmp1) >> 1;
87
8.31M
    tmp9 = tmp7 * 2 - tmp8;
88
8.31M
    tmpA = IDCTMUL(tmp4, FIX_1_414) * 2 - tmp9;
89
8.31M
    tmpB = tmp6 * 2 + tmpA;
90
8.31M
    tmpC =  blk[2 * 8] + (blk[6 * 8] >> 1) >> 1;
91
8.31M
    tmpD =  blk[2 * 8] - (blk[6 * 8] >> 1);
92
8.31M
    tmpE = (blk[0 * 8] >> 1) - (blk[4 * 8] >> 1) + 0x2020;
93
8.31M
    tmpF = (blk[0 * 8] >> 1) + (blk[4 * 8] >> 1) + 0x2020;
94
95
8.31M
    tmp10 = IDCTMUL(tmpD, FIX_1_414) * 2 - tmpC;
96
8.31M
    tmp11 = tmpE - tmp10;
97
8.31M
    tmp12 = tmpF - tmpC;
98
8.31M
    tmp13 = tmpE + tmp10;
99
8.31M
    tmp14 = tmpF + tmpC;
100
101
8.31M
    blk[0 * 8] = (tmp14 + tmp8) >> 6;
102
8.31M
    blk[1 * 8] = (tmp13 + tmp9) >> 6;
103
8.31M
    blk[2 * 8] = (tmp11 + tmpA) >> 6;
104
8.31M
    blk[3 * 8] = (tmp12 - tmpB) >> 6;
105
8.31M
    blk[4 * 8] = (tmp12 + tmpB) >> 6;
106
8.31M
    blk[5 * 8] = (tmp11 - tmpA) >> 6;
107
8.31M
    blk[6 * 8] = (tmp13 - tmp9) >> 6;
108
8.31M
    blk[7 * 8] = (tmp14 - tmp8) >> 6;
109
8.31M
}
110
111
static void hq_idct_put(uint8_t *dst, int stride, int16_t *block)
112
1.03M
{
113
1.03M
    int i, j;
114
115
9.35M
    for (i = 0; i < 8; i++)
116
8.31M
        idct_row(block + i * 8);
117
9.35M
    for (i = 0; i < 8; i++)
118
8.31M
        idct_col(block + i);
119
120
9.35M
    for (i = 0; i < 8; i++) {
121
74.8M
        for (j = 0; j < 8; j++)
122
66.4M
            dst[j] = av_clip_uint8(block[j + i * 8]);
123
8.31M
        dst += stride;
124
8.31M
    }
125
1.03M
}
126
127
av_cold void ff_hqdsp_init(HQDSPContext *c)
128
2.03k
{
129
2.03k
    c->idct_put = hq_idct_put;
130
2.03k
}