/src/libvpx/vpx_dsp/deblock.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2016 The WebM project authors. All Rights Reserved. |
3 | | * |
4 | | * Use of this source code is governed by a BSD-style license |
5 | | * that can be found in the LICENSE file in the root of the source |
6 | | * tree. An additional intellectual property rights grant can be found |
7 | | * in the file PATENTS. All contributing project authors may |
8 | | * be found in the AUTHORS file in the root of the source tree. |
9 | | */ |
10 | | #include <assert.h> |
11 | | #include <stdlib.h> |
12 | | #include "./vpx_dsp_rtcd.h" |
13 | | #include "vpx/vpx_integer.h" |
14 | | |
15 | | const int16_t vpx_rv[] = { |
16 | | 8, 5, 2, 2, 8, 12, 4, 9, 8, 3, 0, 3, 9, 0, 0, 0, 8, 3, 14, |
17 | | 4, 10, 1, 11, 14, 1, 14, 9, 6, 12, 11, 8, 6, 10, 0, 0, 8, 9, 0, |
18 | | 3, 14, 8, 11, 13, 4, 2, 9, 0, 3, 9, 6, 1, 2, 3, 14, 13, 1, 8, |
19 | | 2, 9, 7, 3, 3, 1, 13, 13, 6, 6, 5, 2, 7, 11, 9, 11, 8, 7, 3, |
20 | | 2, 0, 13, 13, 14, 4, 12, 5, 12, 10, 8, 10, 13, 10, 4, 14, 4, 10, 0, |
21 | | 8, 11, 1, 13, 7, 7, 14, 6, 14, 13, 2, 13, 5, 4, 4, 0, 10, 0, 5, |
22 | | 13, 2, 12, 7, 11, 13, 8, 0, 4, 10, 7, 2, 7, 2, 2, 5, 3, 4, 7, |
23 | | 3, 3, 14, 14, 5, 9, 13, 3, 14, 3, 6, 3, 0, 11, 8, 13, 1, 13, 1, |
24 | | 12, 0, 10, 9, 7, 6, 2, 8, 5, 2, 13, 7, 1, 13, 14, 7, 6, 7, 9, |
25 | | 6, 10, 11, 7, 8, 7, 5, 14, 8, 4, 4, 0, 8, 7, 10, 0, 8, 14, 11, |
26 | | 3, 12, 5, 7, 14, 3, 14, 5, 2, 6, 11, 12, 12, 8, 0, 11, 13, 1, 2, |
27 | | 0, 5, 10, 14, 7, 8, 0, 4, 11, 0, 8, 0, 3, 10, 5, 8, 0, 11, 6, |
28 | | 7, 8, 10, 7, 13, 9, 2, 5, 1, 5, 10, 2, 4, 3, 5, 6, 10, 8, 9, |
29 | | 4, 11, 14, 0, 10, 0, 5, 13, 2, 12, 7, 11, 13, 8, 0, 4, 10, 7, 2, |
30 | | 7, 2, 2, 5, 3, 4, 7, 3, 3, 14, 14, 5, 9, 13, 3, 14, 3, 6, 3, |
31 | | 0, 11, 8, 13, 1, 13, 1, 12, 0, 10, 9, 7, 6, 2, 8, 5, 2, 13, 7, |
32 | | 1, 13, 14, 7, 6, 7, 9, 6, 10, 11, 7, 8, 7, 5, 14, 8, 4, 4, 0, |
33 | | 8, 7, 10, 0, 8, 14, 11, 3, 12, 5, 7, 14, 3, 14, 5, 2, 6, 11, 12, |
34 | | 12, 8, 0, 11, 13, 1, 2, 0, 5, 10, 14, 7, 8, 0, 4, 11, 0, 8, 0, |
35 | | 3, 10, 5, 8, 0, 11, 6, 7, 8, 10, 7, 13, 9, 2, 5, 1, 5, 10, 2, |
36 | | 4, 3, 5, 6, 10, 8, 9, 4, 11, 14, 3, 8, 3, 7, 8, 5, 11, 4, 12, |
37 | | 3, 11, 9, 14, 8, 14, 13, 4, 3, 1, 2, 14, 6, 5, 4, 4, 11, 4, 6, |
38 | | 2, 1, 5, 8, 8, 12, 13, 5, 14, 10, 12, 13, 0, 9, 5, 5, 11, 10, 13, |
39 | | 9, 10, 13, |
40 | | }; |
41 | | |
42 | | void vpx_post_proc_down_and_across_mb_row_c(unsigned char *src, |
43 | | unsigned char *dst, int src_pitch, |
44 | | int dst_pitch, int cols, |
45 | 0 | unsigned char *flimits, int size) { |
46 | 0 | unsigned char *p_src, *p_dst; |
47 | 0 | int row; |
48 | 0 | int col; |
49 | 0 | unsigned char v; |
50 | 0 | unsigned char d[4]; |
51 | |
|
52 | 0 | assert(size >= 8); |
53 | 0 | assert(cols >= 8); |
54 | |
|
55 | 0 | for (row = 0; row < size; row++) { |
56 | | /* post_proc_down for one row */ |
57 | 0 | p_src = src; |
58 | 0 | p_dst = dst; |
59 | |
|
60 | 0 | for (col = 0; col < cols; col++) { |
61 | 0 | unsigned char p_above2 = p_src[col - 2 * src_pitch]; |
62 | 0 | unsigned char p_above1 = p_src[col - src_pitch]; |
63 | 0 | unsigned char p_below1 = p_src[col + src_pitch]; |
64 | 0 | unsigned char p_below2 = p_src[col + 2 * src_pitch]; |
65 | |
|
66 | 0 | v = p_src[col]; |
67 | |
|
68 | 0 | if ((abs(v - p_above2) < flimits[col]) && |
69 | 0 | (abs(v - p_above1) < flimits[col]) && |
70 | 0 | (abs(v - p_below1) < flimits[col]) && |
71 | 0 | (abs(v - p_below2) < flimits[col])) { |
72 | 0 | unsigned char k1, k2, k3; |
73 | 0 | k1 = (p_above2 + p_above1 + 1) >> 1; |
74 | 0 | k2 = (p_below2 + p_below1 + 1) >> 1; |
75 | 0 | k3 = (k1 + k2 + 1) >> 1; |
76 | 0 | v = (k3 + v + 1) >> 1; |
77 | 0 | } |
78 | |
|
79 | 0 | p_dst[col] = v; |
80 | 0 | } |
81 | | |
82 | | /* now post_proc_across */ |
83 | 0 | p_src = dst; |
84 | 0 | p_dst = dst; |
85 | |
|
86 | 0 | p_src[-2] = p_src[-1] = p_src[0]; |
87 | 0 | p_src[cols] = p_src[cols + 1] = p_src[cols - 1]; |
88 | |
|
89 | 0 | for (col = 0; col < cols; col++) { |
90 | 0 | v = p_src[col]; |
91 | |
|
92 | 0 | if ((abs(v - p_src[col - 2]) < flimits[col]) && |
93 | 0 | (abs(v - p_src[col - 1]) < flimits[col]) && |
94 | 0 | (abs(v - p_src[col + 1]) < flimits[col]) && |
95 | 0 | (abs(v - p_src[col + 2]) < flimits[col])) { |
96 | 0 | unsigned char k1, k2, k3; |
97 | 0 | k1 = (p_src[col - 2] + p_src[col - 1] + 1) >> 1; |
98 | 0 | k2 = (p_src[col + 2] + p_src[col + 1] + 1) >> 1; |
99 | 0 | k3 = (k1 + k2 + 1) >> 1; |
100 | 0 | v = (k3 + v + 1) >> 1; |
101 | 0 | } |
102 | |
|
103 | 0 | d[col & 3] = v; |
104 | |
|
105 | 0 | if (col >= 2) p_dst[col - 2] = d[(col - 2) & 3]; |
106 | 0 | } |
107 | | |
108 | | /* handle the last two pixels */ |
109 | 0 | p_dst[col - 2] = d[(col - 2) & 3]; |
110 | 0 | p_dst[col - 1] = d[(col - 1) & 3]; |
111 | | |
112 | | /* next row */ |
113 | 0 | src += src_pitch; |
114 | 0 | dst += dst_pitch; |
115 | 0 | } |
116 | 0 | } |
117 | | |
118 | | void vpx_mbpost_proc_across_ip_c(unsigned char *src, int pitch, int rows, |
119 | 0 | int cols, int flimit) { |
120 | 0 | int r, c, i; |
121 | |
|
122 | 0 | unsigned char *s = src; |
123 | 0 | unsigned char d[16]; |
124 | |
|
125 | 0 | for (r = 0; r < rows; r++) { |
126 | 0 | int sumsq = 16; |
127 | 0 | int sum = 0; |
128 | |
|
129 | 0 | for (i = -8; i < 0; i++) s[i] = s[0]; |
130 | | |
131 | | /* 17 avoids valgrind warning - we buffer values in c in d |
132 | | * and only write them when we've read 8 ahead... |
133 | | */ |
134 | 0 | for (i = 0; i < 17; i++) s[i + cols] = s[cols - 1]; |
135 | |
|
136 | 0 | for (i = -8; i <= 6; i++) { |
137 | 0 | sumsq += s[i] * s[i]; |
138 | 0 | sum += s[i]; |
139 | 0 | d[i + 8] = 0; |
140 | 0 | } |
141 | |
|
142 | 0 | for (c = 0; c < cols + 8; c++) { |
143 | 0 | int x = s[c + 7] - s[c - 8]; |
144 | 0 | int y = s[c + 7] + s[c - 8]; |
145 | |
|
146 | 0 | sum += x; |
147 | 0 | sumsq += x * y; |
148 | |
|
149 | 0 | d[c & 15] = s[c]; |
150 | |
|
151 | 0 | if (sumsq * 15 - sum * sum < flimit) { |
152 | 0 | d[c & 15] = (8 + sum + s[c]) >> 4; |
153 | 0 | } |
154 | |
|
155 | 0 | s[c - 8] = d[(c - 8) & 15]; |
156 | 0 | } |
157 | |
|
158 | 0 | s += pitch; |
159 | 0 | } |
160 | 0 | } |
161 | | |
162 | | void vpx_mbpost_proc_down_c(unsigned char *dst, int pitch, int rows, int cols, |
163 | 0 | int flimit) { |
164 | 0 | int r, c, i; |
165 | |
|
166 | 0 | for (c = 0; c < cols; c++) { |
167 | 0 | unsigned char *s = &dst[c]; |
168 | 0 | int sumsq = 0; |
169 | 0 | int sum = 0; |
170 | 0 | unsigned char d[16]; |
171 | |
|
172 | 0 | for (i = -8; i < 0; i++) s[i * pitch] = s[0]; |
173 | | |
174 | | /* 17 avoids valgrind warning - we buffer values in c in d |
175 | | * and only write them when we've read 8 ahead... |
176 | | */ |
177 | 0 | for (i = 0; i < 17; i++) s[(i + rows) * pitch] = s[(rows - 1) * pitch]; |
178 | |
|
179 | 0 | for (i = -8; i <= 6; i++) { |
180 | 0 | sumsq += s[i * pitch] * s[i * pitch]; |
181 | 0 | sum += s[i * pitch]; |
182 | 0 | } |
183 | |
|
184 | 0 | for (r = 0; r < rows + 8; r++) { |
185 | 0 | sumsq += s[7 * pitch] * s[7 * pitch] - s[-8 * pitch] * s[-8 * pitch]; |
186 | 0 | sum += s[7 * pitch] - s[-8 * pitch]; |
187 | 0 | d[r & 15] = s[0]; |
188 | |
|
189 | 0 | if (sumsq * 15 - sum * sum < flimit) { |
190 | 0 | d[r & 15] = (vpx_rv[(r & 127) + (c & 7)] + sum + s[0]) >> 4; |
191 | 0 | } |
192 | 0 | if (r >= 8) s[-8 * pitch] = d[(r - 8) & 15]; |
193 | 0 | s += pitch; |
194 | 0 | } |
195 | 0 | } |
196 | 0 | } |