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 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
28 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 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){
33 const int strength= ff_h263_loop_filter_strength[qscale];
37 int p0= src[y*stride-2];
38 int p1= src[y*stride-1];
39 int p2= src[y*stride+0];
40 int p3= src[y*stride+1];
41 int d = (p0 - p3 + 4*(p2 - p1)) / 8;
43 if (d<-2*strength) d1= 0;
44 else if(d<- strength) d1=-2*strength - d;
45 else if(d< strength) d1= d;
46 else if(d< 2*strength) d1= 2*strength - d;
51 if(p1&256) p1= ~(p1>>31);
52 if(p2&256) p2= ~(p2>>31);
59 d2= av_clip((p0-p3)/4, -ad1, ad1);
61 src[y*stride-2] = p0 - d2;
62 src[y*stride+1] = p3 + d2;
66 static void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale){
68 const int strength= ff_h263_loop_filter_strength[qscale];
72 int p0= src[x-2*stride];
73 int p1= src[x-1*stride];
74 int p2= src[x+0*stride];
75 int p3= src[x+1*stride];
76 int d = (p0 - p3 + 4*(p2 - p1)) / 8;
78 if (d<-2*strength) d1= 0;
79 else if(d<- strength) d1=-2*strength - d;
80 else if(d< strength) d1= d;
81 else if(d< 2*strength) d1= 2*strength - d;
86 if(p1&256) p1= ~(p1>>31);
87 if(p2&256) p2= ~(p2>>31);
94 d2= av_clip((p0-p3)/4, -ad1, ad1);
96 src[x-2*stride] = p0 - d2;
97 src[x+ stride] = p3 + d2;
101 av_cold void ff_h263dsp_init(H263DSPContext *ctx)
103 ctx->h263_h_loop_filter = h263_h_loop_filter_c;
104 ctx->h263_v_loop_filter = h263_v_loop_filter_c;
107 ff_h263dsp_init_x86(ctx);