annotate libmpcodecs/vf_sab.c @ 28402:c884d17bd005

Convert HAVE_WINSOCK2_H into a 0/1 definition.
author diego
date Sun, 01 Feb 2009 13:42:27 +0000
parents 08d18fe9da52
children df67d03dde3b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8100
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
1 /*
26727
82601a38e2a7 Use standard license headers.
diego
parents: 26069
diff changeset
2 * Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
82601a38e2a7 Use standard license headers.
diego
parents: 26069
diff changeset
3 *
82601a38e2a7 Use standard license headers.
diego
parents: 26069
diff changeset
4 * This file is part of MPlayer.
82601a38e2a7 Use standard license headers.
diego
parents: 26069
diff changeset
5 *
82601a38e2a7 Use standard license headers.
diego
parents: 26069
diff changeset
6 * MPlayer is free software; you can redistribute it and/or modify
82601a38e2a7 Use standard license headers.
diego
parents: 26069
diff changeset
7 * it under the terms of the GNU General Public License as published by
82601a38e2a7 Use standard license headers.
diego
parents: 26069
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
82601a38e2a7 Use standard license headers.
diego
parents: 26069
diff changeset
9 * (at your option) any later version.
82601a38e2a7 Use standard license headers.
diego
parents: 26069
diff changeset
10 *
82601a38e2a7 Use standard license headers.
diego
parents: 26069
diff changeset
11 * MPlayer is distributed in the hope that it will be useful,
82601a38e2a7 Use standard license headers.
diego
parents: 26069
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
82601a38e2a7 Use standard license headers.
diego
parents: 26069
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
82601a38e2a7 Use standard license headers.
diego
parents: 26069
diff changeset
14 * GNU General Public License for more details.
82601a38e2a7 Use standard license headers.
diego
parents: 26069
diff changeset
15 *
82601a38e2a7 Use standard license headers.
diego
parents: 26069
diff changeset
16 * You should have received a copy of the GNU General Public License along
82601a38e2a7 Use standard license headers.
diego
parents: 26069
diff changeset
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
82601a38e2a7 Use standard license headers.
diego
parents: 26069
diff changeset
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
82601a38e2a7 Use standard license headers.
diego
parents: 26069
diff changeset
19 */
8100
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
20
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
21 #include <stdio.h>
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
22 #include <stdlib.h>
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
23 #include <string.h>
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
24 #include <inttypes.h>
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
25 #include <assert.h>
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
26
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 13373
diff changeset
27 #include "config.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 13373
diff changeset
28 #include "mp_msg.h"
8100
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
29
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
30 #ifdef HAVE_MALLOC_H
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
31 #include <malloc.h>
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
32 #endif
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
33
26069
1318e956c092 FFmpeg now uses different (unified) #include paths.
diego
parents: 26006
diff changeset
34 #include "libavutil/avutil.h"
8100
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
35 #include "img_format.h"
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
36 #include "mp_image.h"
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
37 #include "vf.h"
18861
8579acff875e Move postproc ---> libswscale
lucabe
parents: 17906
diff changeset
38 #include "libswscale/swscale.h"
10233
35f52ad860a0 vf_scale.h & related cleanup & some small warning fix by dominik
michael
parents: 9975
diff changeset
39 #include "vf_scale.h"
8100
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
40
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
41
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
42 //===========================================================================//
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
43
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
44 typedef struct FilterParam{
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
45 float radius;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
46 float preFilterRadius;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
47 float strength;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
48 float quality;
9494
543ab3909b78 sws_ prefix, more seperation between internal & external swscaler API
michael
parents: 8100
diff changeset
49 struct SwsContext *preFilterContext;
8100
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
50 uint8_t *preFilterBuf;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
51 int preFilterStride;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
52 int distWidth;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
53 int distStride;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
54 int *distCoeff;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
55 int colorDiffCoeff[512];
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
56 }FilterParam;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
57
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
58 struct vf_priv_s {
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
59 FilterParam luma;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
60 FilterParam chroma;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
61 };
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
62
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
63
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
64 /***************************************************************************/
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
65
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
66 //FIXME stupid code duplication
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
67 static void getSubSampleFactors(int *h, int *v, int format){
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
68 switch(format){
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
69 case IMGFMT_YV12:
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
70 case IMGFMT_I420:
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
71 *h=1;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
72 *v=1;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
73 break;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
74 case IMGFMT_YVU9:
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
75 *h=2;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
76 *v=2;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
77 break;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
78 case IMGFMT_444P:
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
79 *h=0;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
80 *v=0;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
81 break;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
82 case IMGFMT_422P:
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
83 *h=1;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
84 *v=0;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
85 break;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
86 case IMGFMT_411P:
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
87 *h=2;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
88 *v=0;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
89 break;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
90 }
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
91 }
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
92
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
93 static int allocStuff(FilterParam *f, int width, int height){
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
94 int stride= (width+7)&~7;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
95 SwsVector *vec;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
96 SwsFilter swsF;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
97 int i,x,y;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
98 f->preFilterBuf= (uint8_t*)memalign(8, stride*height);
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
99 f->preFilterStride= stride;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
100
9494
543ab3909b78 sws_ prefix, more seperation between internal & external swscaler API
michael
parents: 8100
diff changeset
101 vec = sws_getGaussianVec(f->preFilterRadius, f->quality);
8100
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
102 swsF.lumH= swsF.lumV= vec;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
103 swsF.chrH= swsF.chrV= NULL;
9494
543ab3909b78 sws_ prefix, more seperation between internal & external swscaler API
michael
parents: 8100
diff changeset
104 f->preFilterContext= sws_getContext(
19870
1e5cf11e8b1f Use PIX_FMT_* instead of IMGFMT_* when calling sws_getContext()
lucabe
parents: 18861
diff changeset
105 width, height, PIX_FMT_GRAY8, width, height, PIX_FMT_GRAY8, get_sws_cpuflags(), &swsF, NULL, NULL);
8100
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
106
9494
543ab3909b78 sws_ prefix, more seperation between internal & external swscaler API
michael
parents: 8100
diff changeset
107 sws_freeVec(vec);
543ab3909b78 sws_ prefix, more seperation between internal & external swscaler API
michael
parents: 8100
diff changeset
108 vec = sws_getGaussianVec(f->strength, 5.0);
8100
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
109 for(i=0; i<512; i++){
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
110 double d;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
111 int index= i-256 + vec->length/2;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
112
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
113 if(index<0 || index>=vec->length) d= 0.0;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
114 else d= vec->coeff[index];
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
115
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
116 f->colorDiffCoeff[i]= (int)(d/vec->coeff[vec->length/2]*(1<<12) + 0.5);
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
117 }
9494
543ab3909b78 sws_ prefix, more seperation between internal & external swscaler API
michael
parents: 8100
diff changeset
118 sws_freeVec(vec);
543ab3909b78 sws_ prefix, more seperation between internal & external swscaler API
michael
parents: 8100
diff changeset
119 vec = sws_getGaussianVec(f->radius, f->quality);
8100
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
120 f->distWidth= vec->length;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
121 f->distStride= (vec->length+7)&~7;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
122 f->distCoeff= (int32_t*)memalign(8, f->distWidth*f->distStride*sizeof(int32_t));
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
123
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
124 for(y=0; y<vec->length; y++){
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
125 for(x=0; x<vec->length; x++){
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
126 double d= vec->coeff[x] * vec->coeff[y];
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
127
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
128 f->distCoeff[x + y*f->distStride]= (int)(d*(1<<10) + 0.5);
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
129 // if(y==vec->length/2)
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
130 // printf("%6d ", f->distCoeff[x + y*f->distStride]);
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
131 }
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
132 }
9494
543ab3909b78 sws_ prefix, more seperation between internal & external swscaler API
michael
parents: 8100
diff changeset
133 sws_freeVec(vec);
8100
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
134
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
135 return 0;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
136 }
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
137
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
138 static int config(struct vf_instance_s* vf,
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
139 int width, int height, int d_width, int d_height,
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
140 unsigned int flags, unsigned int outfmt){
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
141
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
142 int sw, sh;
27754
08d18fe9da52 Change all occurrences of asm and __asm to __asm__, same as was done for FFmpeg.
diego
parents: 26727
diff changeset
143 //__asm__ volatile("emms\n\t");
8100
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
144 allocStuff(&vf->priv->luma, width, height);
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
145
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
146 getSubSampleFactors(&sw, &sh, outfmt);
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
147 allocStuff(&vf->priv->chroma, width>>sw, height>>sh);
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
148
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
149 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
150 }
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
151
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
152 static void freeBuffers(FilterParam *f){
9494
543ab3909b78 sws_ prefix, more seperation between internal & external swscaler API
michael
parents: 8100
diff changeset
153 if(f->preFilterContext) sws_freeContext(f->preFilterContext);
8100
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
154 f->preFilterContext=NULL;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
155
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
156 if(f->preFilterBuf) free(f->preFilterBuf);
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
157 f->preFilterBuf=NULL;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
158
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
159 if(f->distCoeff) free(f->distCoeff);
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
160 f->distCoeff=NULL;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
161 }
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
162
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
163 static void uninit(struct vf_instance_s* vf){
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
164 if(!vf->priv) return;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
165
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
166 freeBuffers(&vf->priv->luma);
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
167 freeBuffers(&vf->priv->chroma);
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
168
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
169 free(vf->priv);
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
170 vf->priv=NULL;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
171 }
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
172
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
173 static inline void blur(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride, FilterParam *fp){
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
174 int x, y;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
175 FilterParam f= *fp;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
176 const int radius= f.distWidth/2;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
177 uint8_t *srcArray[3]= {src, NULL, NULL};
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
178 uint8_t *dstArray[3]= {f.preFilterBuf, NULL, NULL};
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
179 int srcStrideArray[3]= {srcStride, 0, 0};
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
180 int dstStrideArray[3]= {f.preFilterStride, 0, 0};
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
181
9494
543ab3909b78 sws_ prefix, more seperation between internal & external swscaler API
michael
parents: 8100
diff changeset
182 // f.preFilterContext->swScale(f.preFilterContext, srcArray, srcStrideArray, 0, h, dstArray, dstStrideArray);
543ab3909b78 sws_ prefix, more seperation between internal & external swscaler API
michael
parents: 8100
diff changeset
183 sws_scale(f.preFilterContext, srcArray, srcStrideArray, 0, h, dstArray, dstStrideArray);
8100
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
184
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
185 for(y=0; y<h; y++){
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
186 for(x=0; x<w; x++){
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
187 int sum=0;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
188 int div=0;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
189 int dy;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
190 const int preVal= f.preFilterBuf[x + y*f.preFilterStride];
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
191 #if 0
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
192 const int srcVal= src[x + y*srcStride];
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
193 if((x/32)&1){
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
194 dst[x + y*dstStride]= srcVal;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
195 if(y%32==0) dst[x + y*dstStride]= 0;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
196 continue;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
197 }
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
198 #endif
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
199 if(x >= radius && x < w - radius){
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
200 for(dy=0; dy<radius*2+1; dy++){
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
201 int dx;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
202 int iy= y+dy - radius;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
203 if (iy<0) iy= -iy;
26006
ac00f0e343df vf_sab mirrors coefficients past the edge of the picture instead of cropping:
diego
parents: 25221
diff changeset
204 else if(iy>=h) iy= h+h-iy-1;
8100
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
205
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
206 for(dx=0; dx<radius*2+1; dx++){
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
207 const int ix= x+dx - radius;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
208 int factor;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
209
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
210 factor= f.colorDiffCoeff[256+preVal - f.preFilterBuf[ix + iy*f.preFilterStride] ]
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
211 *f.distCoeff[dx + dy*f.distStride];
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
212 sum+= src[ix + iy*srcStride] *factor;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
213 div+= factor;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
214 }
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
215 }
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
216 }else{
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
217 for(dy=0; dy<radius*2+1; dy++){
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
218 int dx;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
219 int iy= y+dy - radius;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
220 if (iy<0) iy= -iy;
26006
ac00f0e343df vf_sab mirrors coefficients past the edge of the picture instead of cropping:
diego
parents: 25221
diff changeset
221 else if(iy>=h) iy= h+h-iy-1;
8100
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
222
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
223 for(dx=0; dx<radius*2+1; dx++){
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
224 int ix= x+dx - radius;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
225 int factor;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
226 if (ix<0) ix= -ix;
26006
ac00f0e343df vf_sab mirrors coefficients past the edge of the picture instead of cropping:
diego
parents: 25221
diff changeset
227 else if(ix>=w) ix= w+w-ix-1;
8100
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
228
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
229 factor= f.colorDiffCoeff[256+preVal - f.preFilterBuf[ix + iy*f.preFilterStride] ]
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
230 *f.distCoeff[dx + dy*f.distStride];
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
231 sum+= src[ix + iy*srcStride] *factor;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
232 div+= factor;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
233 }
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
234 }
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
235 }
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
236 dst[x + y*dstStride]= (sum + div/2)/div;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
237 }
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
238 }
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
239 }
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
240
17906
20aca9baf5d8 passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents: 17367
diff changeset
241 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){
8100
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
242 int cw= mpi->w >> mpi->chroma_x_shift;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
243 int ch= mpi->h >> mpi->chroma_y_shift;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
244
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
245 mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt,
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
246 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
247 mpi->w,mpi->h);
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
248
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
249 assert(mpi->flags&MP_IMGFLAG_PLANAR);
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
250
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
251 blur(dmpi->planes[0], mpi->planes[0], mpi->w,mpi->h, dmpi->stride[0], mpi->stride[0], &vf->priv->luma);
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
252 blur(dmpi->planes[1], mpi->planes[1], cw , ch , dmpi->stride[1], mpi->stride[1], &vf->priv->chroma);
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
253 blur(dmpi->planes[2], mpi->planes[2], cw , ch , dmpi->stride[2], mpi->stride[2], &vf->priv->chroma);
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
254
17906
20aca9baf5d8 passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents: 17367
diff changeset
255 return vf_next_put_image(vf,dmpi, pts);
8100
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
256 }
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
257
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
258 //===========================================================================//
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
259
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
260 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
261 switch(fmt)
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
262 {
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
263 case IMGFMT_YV12:
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
264 case IMGFMT_I420:
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
265 case IMGFMT_IYUV:
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
266 case IMGFMT_YVU9:
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
267 case IMGFMT_444P:
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
268 case IMGFMT_422P:
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
269 case IMGFMT_411P:
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
270 return vf_next_query_format(vf, fmt);
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
271 }
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
272 return 0;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
273 }
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
274
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
275 static int open(vf_instance_t *vf, char* args){
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
276 int e;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
277
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
278 vf->config=config;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
279 vf->put_image=put_image;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
280 // vf->get_image=get_image;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
281 vf->query_format=query_format;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
282 vf->uninit=uninit;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
283 vf->priv=malloc(sizeof(struct vf_priv_s));
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
284 memset(vf->priv, 0, sizeof(struct vf_priv_s));
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
285
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
286 if(args==NULL) return 0;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
287
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
288 e=sscanf(args, "%f:%f:%f:%f:%f:%f",
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
289 &vf->priv->luma.radius,
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
290 &vf->priv->luma.preFilterRadius,
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
291 &vf->priv->luma.strength,
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
292 &vf->priv->chroma.radius,
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
293 &vf->priv->chroma.preFilterRadius,
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
294 &vf->priv->chroma.strength
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
295 );
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
296
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
297 vf->priv->luma.quality = vf->priv->chroma.quality= 3.0;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
298
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
299 if(e==3){
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
300 vf->priv->chroma.radius= vf->priv->luma.radius;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
301 vf->priv->chroma.preFilterRadius = vf->priv->luma.preFilterRadius;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
302 vf->priv->chroma.strength= vf->priv->luma.strength;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
303 }else if(e!=6)
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
304 return 0;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
305
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
306 // if(vf->priv->luma.radius < 0) return 0;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
307 // if(vf->priv->chroma.radius < 0) return 0;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
308
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
309 return 1;
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
310 }
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
311
25221
00fff9a3b735 Make all vf_info_t structs const
reimar
parents: 23373
diff changeset
312 const vf_info_t vf_info_sab = {
8100
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
313 "shape adaptive blur",
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
314 "sab",
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
315 "Michael Niedermayer",
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
316 "",
9593
e9a2af584986 Add the new -vf option wich is the same as vop in reverse order.
albeu
parents: 9494
diff changeset
317 open,
e9a2af584986 Add the new -vf option wich is the same as vop in reverse order.
albeu
parents: 9494
diff changeset
318 NULL
8100
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
319 };
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
320
fd0da9a7d2e3 shape adaptive blur (slightly slow though)
michael
parents:
diff changeset
321 //===========================================================================//