2 * This file is part of FFmpeg.
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "libavutil/attributes.h"
22 #include "libavutil/common.h"
26 const uint8_t ff_h263_loop_filter_strength[32] = {
27 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7,
28 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12
31 static void h263_h_loop_filter_c(uint8_t *src, int stride, int qscale)
34 const int strength = ff_h263_loop_filter_strength[qscale];
36 for (y = 0; y < 8; y++) {
38 int p0 = src[y * stride - 2];
39 int p1 = src[y * stride - 1];
40 int p2 = src[y * stride + 0];
41 int p3 = src[y * stride + 1];
42 int d = (p0 - p3 + 4 * (p2 - p1)) / 8;
44 if (d < -2 * strength)
46 else if (d < -strength)
47 d1 = -2 * strength - d;
48 else if (d < strength)
50 else if (d < 2 * strength)
51 d1 = 2 * strength - d;
62 src[y * stride - 1] = p1;
63 src[y * stride + 0] = p2;
67 d2 = av_clip((p0 - p3) / 4, -ad1, ad1);
69 src[y * stride - 2] = p0 - d2;
70 src[y * stride + 1] = p3 + d2;
74 static void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale)
77 const int strength = ff_h263_loop_filter_strength[qscale];
79 for (x = 0; x < 8; x++) {
81 int p0 = src[x - 2 * stride];
82 int p1 = src[x - 1 * stride];
83 int p2 = src[x + 0 * stride];
84 int p3 = src[x + 1 * stride];
85 int d = (p0 - p3 + 4 * (p2 - p1)) / 8;
87 if (d < -2 * strength)
89 else if (d < -strength)
90 d1 = -2 * strength - d;
91 else if (d < strength)
93 else if (d < 2 * strength)
94 d1 = 2 * strength - d;
105 src[x - 1 * stride] = p1;
106 src[x + 0 * stride] = p2;
108 ad1 = FFABS(d1) >> 1;
110 d2 = av_clip((p0 - p3) / 4, -ad1, ad1);
112 src[x - 2 * stride] = p0 - d2;
113 src[x + stride] = p3 + d2;
117 av_cold void ff_h263dsp_init(H263DSPContext *ctx)
119 ctx->h263_h_loop_filter = h263_h_loop_filter_c;
120 ctx->h263_v_loop_filter = h263_v_loop_filter_c;
123 ff_h263dsp_init_x86(ctx);
125 ff_h263dsp_init_mips(ctx);