/src/ffmpeg/libavcodec/h261.c
Line | Count | Source |
1 | | /* |
2 | | * H.261 common code |
3 | | * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> |
4 | | * Copyright (c) 2004 Maarten Daniels |
5 | | * |
6 | | * This file is part of FFmpeg. |
7 | | * |
8 | | * FFmpeg is free software; you can redistribute it and/or |
9 | | * modify it under the terms of the GNU Lesser General Public |
10 | | * License as published by the Free Software Foundation; either |
11 | | * version 2.1 of the License, or (at your option) any later version. |
12 | | * |
13 | | * FFmpeg is distributed in the hope that it will be useful, |
14 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | | * Lesser General Public License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU Lesser General Public |
19 | | * License along with FFmpeg; if not, write to the Free Software |
20 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
21 | | */ |
22 | | |
23 | | /** |
24 | | * @file |
25 | | * H.261 codec |
26 | | */ |
27 | | |
28 | | #include "h261.h" |
29 | | #include "mpegvideo.h" |
30 | | |
31 | 398k | #define IS_FIL(a) ((a) & MB_TYPE_H261_FIL) |
32 | | |
33 | | static void h261_loop_filter(uint8_t *src, ptrdiff_t stride) |
34 | 547k | { |
35 | 547k | int x, y; |
36 | 547k | int temp[64]; |
37 | | |
38 | 4.92M | for (x = 0; x < 8; x++) { |
39 | 4.38M | temp[x] = 4 * src[x]; |
40 | 4.38M | temp[x + 7 * 8] = 4 * src[x + 7 * stride]; |
41 | 4.38M | } |
42 | 3.83M | for (y = 1; y < 7; y++) { |
43 | 29.5M | for (x = 0; x < 8; x++) { |
44 | 26.2M | ptrdiff_t xy = y * stride + x; |
45 | 26.2M | ptrdiff_t yz = y * 8 + x; |
46 | 26.2M | temp[yz] = src[xy - stride] + 2 * src[xy] + src[xy + stride]; |
47 | 26.2M | } |
48 | 3.28M | } |
49 | | |
50 | 4.92M | for (y = 0; y < 8; y++) { |
51 | 4.38M | src[y * stride] = (temp[y * 8] + 2) >> 2; |
52 | 4.38M | src[y * stride + 7] = (temp[y * 8 + 7] + 2) >> 2; |
53 | 30.6M | for (x = 1; x < 7; x++) { |
54 | 26.2M | ptrdiff_t xy = y * stride + x; |
55 | 26.2M | ptrdiff_t yz = y * 8 + x; |
56 | 26.2M | src[xy] = (temp[yz - 1] + 2 * temp[yz] + temp[yz + 1] + 8) >> 4; |
57 | 26.2M | } |
58 | 4.38M | } |
59 | 547k | } |
60 | | |
61 | | void ff_h261_loop_filter(MpegEncContext *s) |
62 | 398k | { |
63 | 398k | H261Context *const h = s->private_ctx; |
64 | 398k | const ptrdiff_t linesize = s->linesize; |
65 | 398k | const ptrdiff_t uvlinesize = s->uvlinesize; |
66 | 398k | uint8_t *dest_y = s->dest[0]; |
67 | 398k | uint8_t *dest_cb = s->dest[1]; |
68 | 398k | uint8_t *dest_cr = s->dest[2]; |
69 | | |
70 | 398k | if (!(IS_FIL(h->mtype))) |
71 | 306k | return; |
72 | | |
73 | 91.2k | h261_loop_filter(dest_y, linesize); |
74 | 91.2k | h261_loop_filter(dest_y + 8, linesize); |
75 | 91.2k | h261_loop_filter(dest_y + 8 * linesize, linesize); |
76 | 91.2k | h261_loop_filter(dest_y + 8 * linesize + 8, linesize); |
77 | 91.2k | h261_loop_filter(dest_cb, uvlinesize); |
78 | 91.2k | h261_loop_filter(dest_cr, uvlinesize); |
79 | 91.2k | } |