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