1 /*
2 * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
3 * Copyright (c) 2014 Arwa Arif <arwaarif1994@gmail.com>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22 /**
23 * @file
24 * Postprocessing filter - 7
25 *
26 * Originally written by Michael Niedermayer for the MPlayer
27 * project, and ported by Arwa Arif for FFmpeg.
28 */
29
36
41
46 };
47
48 #define OFFSET(x) offsetof(PP7Context, x)
49 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
57 };
58
60
62 { 0, 48, 12, 60, 3, 51, 15, 63, },
63 { 32, 16, 44, 28, 35, 19, 47, 31, },
64 { 8, 56, 4, 52, 11, 59, 7, 55, },
65 { 40, 24, 36, 20, 43, 27, 39, 23, },
66 { 2, 50, 14, 62, 1, 49, 13, 61, },
67 { 34, 18, 46, 30, 33, 17, 45, 29, },
68 { 10, 58, 6, 54, 9, 57, 5, 53, },
69 { 42, 26, 38, 22, 41, 25, 37, 21, },
70 };
71
76 #define SN1 2.2360679775
77 #define SN2 3.16227766017
79
85 };
86
88 {
91
92 for (qp = 0; qp < 99; qp++) {
93 for (
i = 0;
i < 16;
i++) {
95 }
96 }
97 }
98
100 {
102
103 for (
i = 0;
i < 4;
i++) {
112 s2 = s2 - s1;
115 dst[1] = 2 * s3 + s2;
116 dst[3] = s3 - 2 * s2;
119 }
120 }
121
123 {
125
126 for (
i = 0;
i < 4;
i++) {
127 int s0 =
src[0 * 4] +
src[6 * 4];
128 int s1 =
src[1 * 4] +
src[5 * 4];
129 int s2 =
src[2 * 4] +
src[4 * 4];
135 s2 = s2 - s1;
138 dst[1 * 4] = 2 * s3 + s2;
139 dst[3 * 4] = s3 - 2 * s2;
142 }
143 }
144
146 {
149
151 for (
i = 1;
i < 16;
i++) {
152 unsigned int threshold1 =
p->thres2[qp][
i];
153 unsigned int threshold2 = threshold1 << 1;
155 if (((
unsigned)(
level + threshold1)) > threshold2)
157 }
158 return (
a + (1 << 11)) >> 12;
159 }
160
162 {
165
167 for (
i = 1;
i < 16;
i++) {
168 unsigned int threshold1 =
p->thres2[qp][
i];
169 unsigned int threshold2 = threshold1 << 1;
171 if (((
unsigned)(
level + threshold1)) > threshold2) {
172 if (((
unsigned)(
level + 2 * threshold1)) > 2 * threshold2)
174 else {
177 else
179 }
180 }
181 }
182 return (
a + (1 << 11)) >> 12;
183 }
184
186 {
189
191 for (
i = 1;
i < 16;
i++) {
192 unsigned int threshold1 =
p->thres2[qp][
i];
193 unsigned int threshold2 = threshold1 << 1;
195 if (((
unsigned)(
level + threshold1)) > threshold2) {
198 else
200 }
201 }
202 return (
a + (1 << 11)) >> 12;
203 }
204
206 int dst_stride, int src_stride,
208 uint8_t *qp_store, int qp_stride, int is_luma)
209 {
210 int x, y;
211 const int stride = is_luma ?
p->temp_stride : ((
width + 16 + 15) & (~15));
212 uint8_t *p_src =
p->src + 8 *
stride;
213 int16_t *
block = (int16_t *)
p->src;
214 int16_t *
temp = (int16_t *)(
p->src + 32);
215
217 for (y = 0; y <
height; y++) {
220 for (x = 0; x < 8; x++) {
223 }
224 }
225 for (y = 0; y < 8; y++) {
228 }
229 //FIXME (try edge emu)
230
231 for (y = 0; y <
height; y++) {
232 for (x = -8; x < 0; x += 4) {
233 const int index = x + y *
stride + (8 - 3) * (1 +
stride) + 8;
//FIXME silly offset
235 int16_t *tp =
temp + 4 * x;
236
238 }
239 for (x = 0; x <
width; ) {
240 const int qps = 3 + is_luma;
241 int qp;
243
246 else {
249 }
250 for (; x < end; x++) {
251 const int index = x + y *
stride + (8 - 3) * (1 +
stride) + 8;
//FIXME silly offset
253 int16_t *tp =
temp + 4 * x;
254 int v;
255
256 if ((x & 3) == 0)
258
260
261 v =
p->requantize(
p,
block, qp);
262 v = (v +
dither[y & 7][x & 7]) >> 6;
263 if ((unsigned)v > 255)
264 v = (-v) >> 31;
265 dst[x + y * dst_stride] = v;
266 }
267 }
268 }
269 }
270
279 };
280
282 {
287
290
293
296
298
302 default:
304 }
305
307
308 #if ARCH_X86
310 #endif
311
312 return 0;
313 }
314
316 {
321
322 int qp_stride = 0;
323 int8_t *qp_table =
NULL;
324
330 }
331 }
332
333 if (!
ctx->is_disabled) {
336
337 /* get a new frame if in-place is not possible or if the dimensions
338 * are not multiple of 8 */
342
348 }
352 }
353
354 if (qp_table || pp7->
qp) {
355
359 cw, ch, qp_table, qp_stride, 0);
361 cw, ch, qp_table, qp_stride, 0);
363 }
364 }
365
372 }
375 }
376
378 {
381 }
382
384 {
389 },
390 };
391
395 .p.priv_class = &pp7_class,
402 };