42 #define MAX_NOISE 4096
43 #define MAX_SHIFT 1024
44 #define MAX_RES (MAX_NOISE-MAX_SHIFT)
79 #define RAND_N(range) ((int) ((double)range*rand()/(RAND_MAX+1.0)))
95 noise[i]= (
RAND_N(strength) - strength/2)/6
96 +
patt[j%4]*strength*0.25/3;
98 noise[i]= (
RAND_N(strength) - strength/2)/3;
102 noise[i]= (
RAND_N(strength) - strength/2)/2
103 +
patt[j%4]*strength*0.25;
105 noise[i]=
RAND_N(strength) - strength/2;
109 double x1, x2, w, y1;
111 x1 = 2.0 * rand()/(float)RAND_MAX - 1.0;
112 x2 = 2.0 * rand()/(float)RAND_MAX - 1.0;
113 w = x1 * x1 + x2 * x2;
114 }
while ( w >= 1.0 );
116 w = sqrt( (-2.0 * log( w ) ) / w );
118 y1*= strength / sqrt(3.0);
121 y1 +=
patt[j%4]*strength*0.35;
123 if (y1<-128) y1=-128;
124 else if(y1> 127) y1= 127;
125 if (averaged) y1 /= 3.0;
133 for (j = 0; j < 3; j++)
156 "mov %3, %%"REG_a
" \n\t"
157 "pcmpeqb %%mm7, %%mm7 \n\t"
158 "psllw $15, %%mm7 \n\t"
159 "packsswb %%mm7, %%mm7 \n\t"
162 "movq (%0, %%"REG_a
"), %%mm0 \n\t"
163 "movq (%1, %%"REG_a
"), %%mm1 \n\t"
164 "pxor %%mm7, %%mm0 \n\t"
165 "paddsb %%mm1, %%mm0 \n\t"
166 "pxor %%mm7, %%mm0 \n\t"
167 "movq %%mm0, (%2, %%"REG_a
") \n\t"
168 "add $8, %%"REG_a
" \n\t"
170 ::
"r" (src+mmx_len),
"r" (noise+mmx_len),
"r" (dst+mmx_len),
"g" (-mmx_len)
174 lineNoise_C(dst+mmx_len, src+mmx_len, noise+mmx_len, len-mmx_len, 0);
185 "mov %3, %%"REG_a
" \n\t"
186 "pcmpeqb %%mm7, %%mm7 \n\t"
187 "psllw $15, %%mm7 \n\t"
188 "packsswb %%mm7, %%mm7 \n\t"
191 "movq (%0, %%"REG_a
"), %%mm0 \n\t"
192 "movq (%1, %%"REG_a
"), %%mm1 \n\t"
193 "pxor %%mm7, %%mm0 \n\t"
194 "paddsb %%mm1, %%mm0 \n\t"
195 "pxor %%mm7, %%mm0 \n\t"
196 "movntq %%mm0, (%2, %%"REG_a
") \n\t"
197 "add $8, %%"REG_a
" \n\t"
199 ::
"r" (src+mmx_len),
"r" (noise+mmx_len),
"r" (dst+mmx_len),
"g" (-mmx_len)
203 lineNoise_C(dst+mmx_len, src+mmx_len, noise+mmx_len, len-mmx_len, 0);
212 int v= src[i]+ noise[i];
213 if(v>255) dst[i]=255;
214 else if(v<0) dst[i]=0;
226 "mov %5, %%"REG_a
" \n\t"
229 "movq (%1, %%"REG_a
"), %%mm1 \n\t"
230 "movq (%0, %%"REG_a
"), %%mm0 \n\t"
231 "paddb (%2, %%"REG_a
"), %%mm1 \n\t"
232 "paddb (%3, %%"REG_a
"), %%mm1 \n\t"
233 "movq %%mm0, %%mm2 \n\t"
234 "movq %%mm1, %%mm3 \n\t"
235 "punpcklbw %%mm0, %%mm0 \n\t"
236 "punpckhbw %%mm2, %%mm2 \n\t"
237 "punpcklbw %%mm1, %%mm1 \n\t"
238 "punpckhbw %%mm3, %%mm3 \n\t"
239 "pmulhw %%mm0, %%mm1 \n\t"
240 "pmulhw %%mm2, %%mm3 \n\t"
241 "paddw %%mm1, %%mm1 \n\t"
242 "paddw %%mm3, %%mm3 \n\t"
243 "paddw %%mm0, %%mm1 \n\t"
244 "paddw %%mm2, %%mm3 \n\t"
245 "psrlw $8, %%mm1 \n\t"
246 "psrlw $8, %%mm3 \n\t"
247 "packuswb %%mm3, %%mm1 \n\t"
248 "movq %%mm1, (%4, %%"REG_a
") \n\t"
249 "add $8, %%"REG_a
" \n\t"
251 ::
"r" (src+mmx_len),
"r" (shift[0]+mmx_len),
"r" (shift[1]+mmx_len),
"r" (shift[2]+mmx_len),
252 "r" (dst+mmx_len),
"g" (-mmx_len)
257 int8_t *
shift2[3]={shift[0]+mmx_len, shift[1]+mmx_len, shift[2]+mmx_len};
265 int8_t *src2= (int8_t*)src;
269 const int n= shift[0][i] + shift[1][i] + shift[2][i];
270 dst[i]= src2[i]+((n*src2[i])>>7);
277 int8_t *noise= fp->
noise;
285 if(dstStride==srcStride)
fast_memcpy(dst, src, srcStride*height);
308 lineNoise(dst, src, noise, width, shift);
317 static int config(
struct vf_instance *vf,
319 unsigned int flags,
unsigned int outfmt){
326 if(mpi->
imgfmt!=vf->priv->outfmt)
return;
330 mpi->
planes[0]=vf->dmpi->planes[0];
331 mpi->
stride[0]=vf->dmpi->stride[0];
332 mpi->
width=vf->dmpi->width;
334 mpi->
planes[1]=vf->dmpi->planes[1];
335 mpi->
planes[2]=vf->dmpi->planes[2];
336 mpi->
stride[1]=vf->dmpi->stride[1];
337 mpi->
stride[2]=vf->dmpi->stride[2];
371 static void uninit(
struct vf_instance *vf){
372 if(!vf->priv)
return;
374 av_free(vf->priv->chromaParam.noise);
375 vf->priv->chromaParam.noise=
NULL;
377 av_free(vf->priv->lumaParam.noise);
378 vf->priv->lumaParam.noise=
NULL;
399 char *max= strchr(args,
':');
401 if(!max) max= args + strlen(args);
404 pos= strchr(args,
'u');
405 if(pos && pos<max) fp->
uniform=1;
406 pos= strchr(args,
't');
408 pos= strchr(args,
'h');
409 if(pos && pos<max) fp->
quality=1;
410 pos= strchr(args,
'p');
411 if(pos && pos<max) fp->
pattern=1;
412 pos= strchr(args,
'a');
438 char *arg2= strchr(args,
':');
469 "Michael Niedermayer",