FFmpeg
rv60dsp.c
Go to the documentation of this file.
1 /*
2  * RV60 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 "rv60dsp.h"
22 #include "libavutil/common.h"
23 
24 void ff_rv60_idct4x4_add(const int16_t * block, uint8_t * dst, int dst_stride)
25 {
26  int tmp[16];
27 #define IDCT4X4(src, src_stride, src_step, dst, dst_stride, dst_step) \
28  for (int y = 0; y < 4; y++) { \
29  int a = src[y*src_stride + 0*src_step]; \
30  int b = src[y*src_stride + 1*src_step]; \
31  int c = src[y*src_stride + 2*src_step]; \
32  int d = src[y*src_stride + 3*src_step]; \
33  int t0 = 13 * (a + c); \
34  int t1 = 13 * (a - c); \
35  int t2 = 7 * b - 17 * d; \
36  int t3 = 7 * d + 17 * b; \
37  STORE(dst[y*dst_stride + 0*dst_step], (t0 + t3 + 16) >> 5); \
38  STORE(dst[y*dst_stride + 1*dst_step], (t1 + t2 + 16) >> 5); \
39  STORE(dst[y*dst_stride + 2*dst_step], (t1 - t2 + 16) >> 5); \
40  STORE(dst[y*dst_stride + 3*dst_step], (t0 - t3 + 16) >> 5); \
41  }
42 #define STORE(a, b) a = b
43  IDCT4X4(block, 1, 4, tmp, 1, 4)
44 #undef STORE
45 #define STORE(a, b) a = av_clip_uint8(a + (b))
46  IDCT4X4(tmp, 4, 1, dst, dst_stride, 1)
47 #undef STORE
48 }
49 
50 void ff_rv60_idct8x8_add(const int16_t * block, uint8_t * dst, int dst_stride)
51 {
52  int tmp[64];
53 #define IDCT8X8(src, src_stride, src_step, dst, dst_stride, dst_step) \
54  for (int y = 0; y < 8; y++) { \
55  int a = src[y*src_stride + 0*src_step]; \
56  int b = src[y*src_stride + 1*src_step]; \
57  int c = src[y*src_stride + 2*src_step]; \
58  int d = src[y*src_stride + 3*src_step]; \
59  int e = src[y*src_stride + 4*src_step]; \
60  int f = src[y*src_stride + 5*src_step]; \
61  int g = src[y*src_stride + 6*src_step]; \
62  int h = src[y*src_stride + 7*src_step]; \
63  int t0 = 37 * (a + e); \
64  int t1 = 37 * (a - e); \
65  int t2 = 48 * c + 20 * g; \
66  int t3 = 20 * c - 48 * g; \
67  int t4 = t0 + t2; \
68  int t5 = t0 - t2; \
69  int t6 = t1 + t3; \
70  int t7 = t1 - t3; \
71  int t8 = 51 * b + 43 * d + 29 * f + 10 * h; \
72  int t9 = 43 * b - 10 * d - 51 * f - 29 * h; \
73  int ta = 29 * b - 51 * d + 10 * f + 43 * h; \
74  int tb = 10 * b - 29 * d + 43 * f - 51 * h; \
75  STORE(dst[y*dst_stride + 0*dst_step], (t4 + t8 + 64) >> 7); \
76  STORE(dst[y*dst_stride + 1*dst_step], (t6 + t9 + 64) >> 7); \
77  STORE(dst[y*dst_stride + 2*dst_step], (t7 + ta + 64) >> 7); \
78  STORE(dst[y*dst_stride + 3*dst_step], (t5 + tb + 64) >> 7); \
79  STORE(dst[y*dst_stride + 4*dst_step], (t5 - tb + 64) >> 7); \
80  STORE(dst[y*dst_stride + 5*dst_step], (t7 - ta + 64) >> 7); \
81  STORE(dst[y*dst_stride + 6*dst_step], (t6 - t9 + 64) >> 7); \
82  STORE(dst[y*dst_stride + 7*dst_step], (t4 - t8 + 64) >> 7); \
83  }
84 #define STORE(a, b) a = b
85  IDCT8X8(block, 1, 8, tmp, 1, 8)
86 #undef STORE
87 #define STORE(a, b) a = av_clip_uint8(a + (b))
88  IDCT8X8(tmp, 8, 1, dst, dst_stride, 1)
89 #undef STORE
90 }
91 
92 void ff_rv60_idct16x16_add(const int16_t * block, uint8_t * dst, int dst_stride)
93 {
94  int16_t tmp[256];
95 #define IDCT16X16(src, src_stride, src_step, dst, dst_stride, dst_step) \
96  for (int y = 0; y < 16; y++) { \
97  int a = src[y*src_stride + 0*src_step]; \
98  int b = src[y*src_stride + 1*src_step]; \
99  int c = src[y*src_stride + 2*src_step]; \
100  int d = src[y*src_stride + 3*src_step]; \
101  int e = src[y*src_stride + 4*src_step]; \
102  int f = src[y*src_stride + 5*src_step]; \
103  int g = src[y*src_stride + 6*src_step]; \
104  int h = src[y*src_stride + 7*src_step]; \
105  int i = src[y*src_stride + 8*src_step]; \
106  int j = src[y*src_stride + 9*src_step]; \
107  int k = src[y*src_stride + 10*src_step]; \
108  int l = src[y*src_stride + 11*src_step]; \
109  int m = src[y*src_stride + 12*src_step]; \
110  int n = src[y*src_stride + 13*src_step]; \
111  int o = src[y*src_stride + 14*src_step]; \
112  int p = src[y*src_stride + 15*src_step]; \
113  int t0 = 26 * (a + i); \
114  int t1 = 26 * (a - i); \
115  int t2 = 14 * e - 34 * m; \
116  int t3 = 34 * e + 14 * m; \
117  int t4 = t0 + t3; \
118  int t5 = t0 - t3; \
119  int t6 = t1 + t2; \
120  int t7 = t1 - t2; \
121  int tmp00 = 31 * c - 7 * g - 36 * k - 20 * o; \
122  int tmp01 = 36 * c + 31 * g + 20 * k + 7 * o; \
123  int tmp02 = 20 * c - 36 * g + 7 * k + 31 * o; \
124  int tmp03 = 7 * c - 20 * g + 31 * k - 36 * o; \
125  int tm0 = t4 + tmp01; \
126  int tm1 = t4 - tmp01; \
127  int tm2 = t5 + tmp03; \
128  int tm3 = t5 - tmp03; \
129  int tm4 = t6 + tmp00; \
130  int tm5 = t6 - tmp00; \
131  int tm6 = t7 + tmp02; \
132  int tm7 = t7 - tmp02; \
133  int tt0 = 37 * b + 35 * d + 32 * f + 28 * h + 23 * j + 17 * l + 11 * n + 4 * p; \
134  int tt1 = 35 * b + 23 * d + 4 * f - 17 * h - 32 * j - 37 * l - 28 * n - 11 * p; \
135  int tt2 = 32 * b + 4 * d - 28 * f - 35 * h - 11 * j + 23 * l + 37 * n + 17 * p; \
136  int tt3 = 28 * b - 17 * d - 35 * f + 4 * h + 37 * j + 11 * l - 32 * n - 23 * p; \
137  int tt4 = 23 * b - 32 * d - 11 * f + 37 * h - 4 * j - 35 * l + 17 * n + 28 * p; \
138  int tt5 = 17 * b - 37 * d + 23 * f + 11 * h - 35 * j + 28 * l + 4 * n - 32 * p; \
139  int tt6 = 11 * b - 28 * d + 37 * f - 32 * h + 17 * j + 4 * l - 23 * n + 35 * p; \
140  int tt7 = 4 * b - 11 * d + 17 * f - 23 * h + 28 * j - 32 * l + 35 * n - 37 * p; \
141  STORE(dst[y*dst_stride+ 0*dst_step], (tm0 + tt0 + 64) >> 7); \
142  STORE(dst[y*dst_stride+ 1*dst_step], (tm4 + tt1 + 64) >> 7); \
143  STORE(dst[y*dst_stride+ 2*dst_step], (tm6 + tt2 + 64) >> 7); \
144  STORE(dst[y*dst_stride+ 3*dst_step], (tm2 + tt3 + 64) >> 7); \
145  STORE(dst[y*dst_stride+ 4*dst_step], (tm3 + tt4 + 64) >> 7); \
146  STORE(dst[y*dst_stride+ 5*dst_step], (tm7 + tt5 + 64) >> 7); \
147  STORE(dst[y*dst_stride+ 6*dst_step], (tm5 + tt6 + 64) >> 7); \
148  STORE(dst[y*dst_stride+ 7*dst_step], (tm1 + tt7 + 64) >> 7); \
149  STORE(dst[y*dst_stride+ 8*dst_step], (tm1 - tt7 + 64) >> 7); \
150  STORE(dst[y*dst_stride+ 9*dst_step], (tm5 - tt6 + 64) >> 7); \
151  STORE(dst[y*dst_stride+ 10*dst_step], (tm7 - tt5 + 64) >> 7); \
152  STORE(dst[y*dst_stride+ 11*dst_step], (tm3 - tt4 + 64) >> 7); \
153  STORE(dst[y*dst_stride+ 12*dst_step], (tm2 - tt3 + 64) >> 7); \
154  STORE(dst[y*dst_stride+ 13*dst_step], (tm6 - tt2 + 64) >> 7); \
155  STORE(dst[y*dst_stride+ 14*dst_step], (tm4 - tt1 + 64) >> 7); \
156  STORE(dst[y*dst_stride+ 15*dst_step], (tm0 - tt0 + 64) >> 7); \
157  }
158 #define STORE(a, x) a = av_clip_intp2(x, 15)
159  IDCT16X16(block, 1, 16, tmp, 1, 16)
160 #undef STORE
161 #define STORE(a, x) a = av_clip_uint8(a + (x))
162  IDCT16X16(tmp, 16, 1, dst, dst_stride, 1)
163 #undef STORE
164 }
ff_rv60_idct8x8_add
void ff_rv60_idct8x8_add(const int16_t *block, uint8_t *dst, int dst_stride)
Definition: rv60dsp.c:50
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
rv60dsp.h
IDCT8X8
#define IDCT8X8(src, src_stride, src_step, dst, dst_stride, dst_step)
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
common.h
ff_rv60_idct4x4_add
void ff_rv60_idct4x4_add(const int16_t *block, uint8_t *dst, int dst_stride)
Definition: rv60dsp.c:24
IDCT4X4
#define IDCT4X4(src, src_stride, src_step, dst, dst_stride, dst_step)
IDCT16X16
#define IDCT16X16(src, src_stride, src_step, dst, dst_stride, dst_step)
ff_rv60_idct16x16_add
void ff_rv60_idct16x16_add(const int16_t *block, uint8_t *dst, int dst_stride)
Definition: rv60dsp.c:92
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207