FFmpeg
hqxdsp.c
Go to the documentation of this file.
1 /*
2  * HQX DSP routines
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/common.h"
24 
25 #include "hqxdsp.h"
26 
27 static inline void idct_col(int16_t *blk, const uint8_t *quant)
28 {
29  int t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, tA, tB, tC, tD, tE, tF;
30  int t10, t11, t12, t13;
31  int s0, s1, s2, s3, s4, s5, s6, s7;
32 
33  s0 = (int) blk[0 * 8] * quant[0 * 8];
34  s1 = (int) blk[1 * 8] * quant[1 * 8];
35  s2 = (int) blk[2 * 8] * quant[2 * 8];
36  s3 = (int) blk[3 * 8] * quant[3 * 8];
37  s4 = (int) blk[4 * 8] * quant[4 * 8];
38  s5 = (int) blk[5 * 8] * quant[5 * 8];
39  s6 = (int) blk[6 * 8] * quant[6 * 8];
40  s7 = (int) blk[7 * 8] * quant[7 * 8];
41 
42  t0 = (int)(s3 * 19266U + s5 * 12873U) >> 15;
43  t1 = (int)(s5 * 19266U - s3 * 12873U) >> 15;
44  t2 = ((int)(s7 * 4520U + s1 * 22725U) >> 15) - t0;
45  t3 = ((int)(s1 * 4520U - s7 * 22725U) >> 15) - t1;
46  t4 = t0 * 2 + t2;
47  t5 = t1 * 2 + t3;
48  t6 = t2 - t3;
49  t7 = t3 * 2 + t6;
50  t8 = (int)(t6 * 11585U) >> 14;
51  t9 = (int)(t7 * 11585U) >> 14;
52  tA = (int)(s2 * 8867U - s6 * 21407U) >> 14;
53  tB = (int)(s6 * 8867U + s2 * 21407U) >> 14;
54  tC = (s0 >> 1) - (s4 >> 1);
55  tD = (s4 >> 1) * 2 + tC;
56  tE = tC - (tA >> 1);
57  tF = tD - (tB >> 1);
58  t10 = tF - t5;
59  t11 = tE - t8;
60  t12 = tE + (tA >> 1) * 2 - t9;
61  t13 = tF + (tB >> 1) * 2 - t4;
62 
63  blk[0 * 8] = t13 + t4 * 2;
64  blk[1 * 8] = t12 + t9 * 2;
65  blk[2 * 8] = t11 + t8 * 2;
66  blk[3 * 8] = t10 + t5 * 2;
67  blk[4 * 8] = t10;
68  blk[5 * 8] = t11;
69  blk[6 * 8] = t12;
70  blk[7 * 8] = t13;
71 }
72 
73 static inline void idct_row(int16_t *blk)
74 {
75  int t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, tA, tB, tC, tD, tE, tF;
76  int t10, t11, t12, t13;
77 
78  t0 = (blk[3] * 19266 + blk[5] * 12873) >> 14;
79  t1 = (blk[5] * 19266 - blk[3] * 12873) >> 14;
80  t2 = ((blk[7] * 4520 + blk[1] * 22725) >> 14) - t0;
81  t3 = ((blk[1] * 4520 - blk[7] * 22725) >> 14) - t1;
82  t4 = t0 * 2 + t2;
83  t5 = t1 * 2 + t3;
84  t6 = t2 - t3;
85  t7 = t3 * 2 + t6;
86  t8 = (t6 * 11585) >> 14;
87  t9 = (t7 * 11585) >> 14;
88  tA = (blk[2] * 8867 - blk[6] * 21407) >> 14;
89  tB = (blk[6] * 8867 + blk[2] * 21407) >> 14;
90  tC = blk[0] - blk[4];
91  tD = blk[4] * 2 + tC;
92  tE = tC - tA;
93  tF = tD - tB;
94  t10 = tF - t5;
95  t11 = tE - t8;
96  t12 = tE + tA * 2 - t9;
97  t13 = tF + tB * 2 - t4;
98 
99  blk[0] = (t13 + t4 * 2 + 4) >> 3;
100  blk[1] = (t12 + t9 * 2 + 4) >> 3;
101  blk[2] = (t11 + t8 * 2 + 4) >> 3;
102  blk[3] = (t10 + t5 * 2 + 4) >> 3;
103  blk[4] = (t10 + 4) >> 3;
104  blk[5] = (t11 + 4) >> 3;
105  blk[6] = (t12 + 4) >> 3;
106  blk[7] = (t13 + 4) >> 3;
107 }
108 
109 static void hqx_idct_put(uint16_t *dst, ptrdiff_t stride,
110  int16_t *block, const uint8_t *quant)
111 {
112  int i, j;
113 
114  for (i = 0; i < 8; i++)
115  idct_col(block + i, quant + i);
116  for (i = 0; i < 8; i++)
117  idct_row(block + i * 8);
118 
119  for (i = 0; i < 8; i++) {
120  for (j = 0; j < 8; j++) {
121  int v = av_clip_uintp2(block[j + i * 8] + 0x800, 12);
122  dst[j] = (v << 4) | (v >> 8);
123  }
124  dst += stride >> 1;
125  }
126 }
127 
129 {
130  c->idct_put = hqx_idct_put;
131 }
stride
int stride
Definition: mace.c:144
s5
#define s5
Definition: regdef.h:42
idct_row
static void idct_row(int16_t *blk)
Definition: hqxdsp.c:73
av_clip_uintp2
#define av_clip_uintp2
Definition: common.h:120
t0
#define t0
Definition: regdef.h:28
t1
#define t1
Definition: regdef.h:29
ff_hqxdsp_init
av_cold void ff_hqxdsp_init(HQXDSPContext *c)
Definition: hqxdsp.c:128
t10
#define t10
Definition: regdef.h:55
s3
#define s3
Definition: regdef.h:40
U
#define U(x)
Definition: vp56_arith.h:37
quant
static int quant(float coef, const float Q, const float rounding)
Quantize one coefficient.
Definition: aacenc_utils.h:59
av_cold
#define av_cold
Definition: attributes.h:90
idct_col
static void idct_col(int16_t *blk, const uint8_t *quant)
Definition: hqxdsp.c:27
HQXDSPContext
Definition: hqxdsp.h:32
s1
#define s1
Definition: regdef.h:38
t7
#define t7
Definition: regdef.h:35
blk
#define blk(i)
Definition: sha.c:185
t5
#define t5
Definition: regdef.h:33
s6
#define s6
Definition: regdef.h:43
t6
#define t6
Definition: regdef.h:34
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
t11
#define t11
Definition: regdef.h:56
s2
#define s2
Definition: regdef.h:39
t12
#define t12
Definition: regdef.h:58
hqx_idct_put
static void hqx_idct_put(uint16_t *dst, ptrdiff_t stride, int16_t *block, const uint8_t *quant)
Definition: hqxdsp.c:109
t8
#define t8
Definition: regdef.h:53
hqxdsp.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
t4
#define t4
Definition: regdef.h:32
t3
#define t3
Definition: regdef.h:31
common.h
s4
#define s4
Definition: regdef.h:41
t2
#define t2
Definition: regdef.h:30
t9
#define t9
Definition: regdef.h:54
s0
#define s0
Definition: regdef.h:37
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
int
int
Definition: ffmpeg_filter.c:153