annotate libmpcodecs/vf_noise.c @ 6621:dfb11bf64ea6

delay=0 removed, totally unneeded
author arpi
date Tue, 02 Jul 2002 20:29:27 +0000
parents e10e3264c19c
children ba721168ed24
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
1 /*
83032783f65d noise generating filter
michael
parents:
diff changeset
2 Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
83032783f65d noise generating filter
michael
parents:
diff changeset
3
83032783f65d noise generating filter
michael
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
83032783f65d noise generating filter
michael
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
83032783f65d noise generating filter
michael
parents:
diff changeset
6 the Free Software Foundation; either version 2 of the License, or
83032783f65d noise generating filter
michael
parents:
diff changeset
7 (at your option) any later version.
83032783f65d noise generating filter
michael
parents:
diff changeset
8
83032783f65d noise generating filter
michael
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
83032783f65d noise generating filter
michael
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
83032783f65d noise generating filter
michael
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
83032783f65d noise generating filter
michael
parents:
diff changeset
12 GNU General Public License for more details.
83032783f65d noise generating filter
michael
parents:
diff changeset
13
83032783f65d noise generating filter
michael
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
83032783f65d noise generating filter
michael
parents:
diff changeset
15 along with this program; if not, write to the Free Software
83032783f65d noise generating filter
michael
parents:
diff changeset
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
83032783f65d noise generating filter
michael
parents:
diff changeset
17 */
83032783f65d noise generating filter
michael
parents:
diff changeset
18
83032783f65d noise generating filter
michael
parents:
diff changeset
19 #include <stdio.h>
83032783f65d noise generating filter
michael
parents:
diff changeset
20 #include <stdlib.h>
83032783f65d noise generating filter
michael
parents:
diff changeset
21 #include <string.h>
83032783f65d noise generating filter
michael
parents:
diff changeset
22 #include <inttypes.h>
83032783f65d noise generating filter
michael
parents:
diff changeset
23 #include <math.h>
83032783f65d noise generating filter
michael
parents:
diff changeset
24
83032783f65d noise generating filter
michael
parents:
diff changeset
25 #include "../config.h"
83032783f65d noise generating filter
michael
parents:
diff changeset
26 #include "../mp_msg.h"
83032783f65d noise generating filter
michael
parents:
diff changeset
27 #include "../cpudetect.h"
83032783f65d noise generating filter
michael
parents:
diff changeset
28
83032783f65d noise generating filter
michael
parents:
diff changeset
29 #ifdef HAVE_MALLOC_H
83032783f65d noise generating filter
michael
parents:
diff changeset
30 #include <malloc.h>
83032783f65d noise generating filter
michael
parents:
diff changeset
31 #endif
83032783f65d noise generating filter
michael
parents:
diff changeset
32
83032783f65d noise generating filter
michael
parents:
diff changeset
33 #include "img_format.h"
83032783f65d noise generating filter
michael
parents:
diff changeset
34 #include "mp_image.h"
83032783f65d noise generating filter
michael
parents:
diff changeset
35 #include "vf.h"
83032783f65d noise generating filter
michael
parents:
diff changeset
36 #include "../libvo/fastmemcpy.h"
83032783f65d noise generating filter
michael
parents:
diff changeset
37
83032783f65d noise generating filter
michael
parents:
diff changeset
38 #define MAX_NOISE 4096
83032783f65d noise generating filter
michael
parents:
diff changeset
39 #define MAX_SHIFT 1024
83032783f65d noise generating filter
michael
parents:
diff changeset
40 #define MAX_RES (MAX_NOISE-MAX_SHIFT)
83032783f65d noise generating filter
michael
parents:
diff changeset
41
83032783f65d noise generating filter
michael
parents:
diff changeset
42 //===========================================================================//
83032783f65d noise generating filter
michael
parents:
diff changeset
43
83032783f65d noise generating filter
michael
parents:
diff changeset
44 static inline void lineNoise_C(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift);
83032783f65d noise generating filter
michael
parents:
diff changeset
45
83032783f65d noise generating filter
michael
parents:
diff changeset
46 static void (*lineNoise)(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift)= lineNoise_C;
83032783f65d noise generating filter
michael
parents:
diff changeset
47
83032783f65d noise generating filter
michael
parents:
diff changeset
48 typedef struct FilterParam{
83032783f65d noise generating filter
michael
parents:
diff changeset
49 int strength;
83032783f65d noise generating filter
michael
parents:
diff changeset
50 int uniform;
83032783f65d noise generating filter
michael
parents:
diff changeset
51 int temporal;
6448
e10e3264c19c higher quality mode
michael
parents: 6447
diff changeset
52 int quality;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
53 int8_t *noise;
83032783f65d noise generating filter
michael
parents:
diff changeset
54 }FilterParam;
83032783f65d noise generating filter
michael
parents:
diff changeset
55
83032783f65d noise generating filter
michael
parents:
diff changeset
56 struct vf_priv_s {
83032783f65d noise generating filter
michael
parents:
diff changeset
57 FilterParam lumaParam;
83032783f65d noise generating filter
michael
parents:
diff changeset
58 FilterParam chromaParam;
6447
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
59 mp_image_t *dmpi;
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
60 unsigned int outfmt;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
61 };
83032783f65d noise generating filter
michael
parents:
diff changeset
62
83032783f65d noise generating filter
michael
parents:
diff changeset
63 static int nonTempRandShift[MAX_RES]= {-1};
83032783f65d noise generating filter
michael
parents:
diff changeset
64
83032783f65d noise generating filter
michael
parents:
diff changeset
65 static int8_t *initNoise(FilterParam *fp){
83032783f65d noise generating filter
michael
parents:
diff changeset
66 int strength= fp->strength;
83032783f65d noise generating filter
michael
parents:
diff changeset
67 int uniform= fp->uniform;
6447
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
68 int8_t *noise= memalign(16, MAX_NOISE*sizeof(int8_t));
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
69 int i;
83032783f65d noise generating filter
michael
parents:
diff changeset
70
83032783f65d noise generating filter
michael
parents:
diff changeset
71 srand(123457);
83032783f65d noise generating filter
michael
parents:
diff changeset
72
83032783f65d noise generating filter
michael
parents:
diff changeset
73 for(i=0; i<MAX_NOISE; i++)
83032783f65d noise generating filter
michael
parents:
diff changeset
74 {
83032783f65d noise generating filter
michael
parents:
diff changeset
75 if(uniform)
83032783f65d noise generating filter
michael
parents:
diff changeset
76 noise[i]= ((rand()/11)%strength) - strength/2;
83032783f65d noise generating filter
michael
parents:
diff changeset
77 else
83032783f65d noise generating filter
michael
parents:
diff changeset
78 {
83032783f65d noise generating filter
michael
parents:
diff changeset
79 double x1, x2, w, y1;
83032783f65d noise generating filter
michael
parents:
diff changeset
80 do {
83032783f65d noise generating filter
michael
parents:
diff changeset
81 x1 = 2.0 * rand()/(float)RAND_MAX - 1.0;
83032783f65d noise generating filter
michael
parents:
diff changeset
82 x2 = 2.0 * rand()/(float)RAND_MAX - 1.0;
83032783f65d noise generating filter
michael
parents:
diff changeset
83 w = x1 * x1 + x2 * x2;
83032783f65d noise generating filter
michael
parents:
diff changeset
84 } while ( w >= 1.0 );
83032783f65d noise generating filter
michael
parents:
diff changeset
85
83032783f65d noise generating filter
michael
parents:
diff changeset
86 w = sqrt( (-2.0 * log( w ) ) / w );
83032783f65d noise generating filter
michael
parents:
diff changeset
87 y1= x1 * w;
83032783f65d noise generating filter
michael
parents:
diff changeset
88
83032783f65d noise generating filter
michael
parents:
diff changeset
89 y1*= strength / sqrt(3.0);
83032783f65d noise generating filter
michael
parents:
diff changeset
90 if (y1<-128) y1=-128;
83032783f65d noise generating filter
michael
parents:
diff changeset
91 else if(y1> 127) y1= 127;
83032783f65d noise generating filter
michael
parents:
diff changeset
92 noise[i]= (int)y1;
83032783f65d noise generating filter
michael
parents:
diff changeset
93 }
83032783f65d noise generating filter
michael
parents:
diff changeset
94 }
83032783f65d noise generating filter
michael
parents:
diff changeset
95
83032783f65d noise generating filter
michael
parents:
diff changeset
96 if(nonTempRandShift[0]==-1){
83032783f65d noise generating filter
michael
parents:
diff changeset
97 for(i=0; i<MAX_RES; i++){
83032783f65d noise generating filter
michael
parents:
diff changeset
98 nonTempRandShift[i]= rand()&(MAX_SHIFT-1);
83032783f65d noise generating filter
michael
parents:
diff changeset
99 }
83032783f65d noise generating filter
michael
parents:
diff changeset
100 }
83032783f65d noise generating filter
michael
parents:
diff changeset
101
83032783f65d noise generating filter
michael
parents:
diff changeset
102 fp->noise= noise;
83032783f65d noise generating filter
michael
parents:
diff changeset
103 return noise;
83032783f65d noise generating filter
michael
parents:
diff changeset
104 }
83032783f65d noise generating filter
michael
parents:
diff changeset
105
83032783f65d noise generating filter
michael
parents:
diff changeset
106 #ifdef HAVE_MMX
83032783f65d noise generating filter
michael
parents:
diff changeset
107 static inline void lineNoise_MMX(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift){
83032783f65d noise generating filter
michael
parents:
diff changeset
108 int mmx_len= len&(~7);
83032783f65d noise generating filter
michael
parents:
diff changeset
109 noise+=shift;
83032783f65d noise generating filter
michael
parents:
diff changeset
110
83032783f65d noise generating filter
michael
parents:
diff changeset
111 asm volatile(
83032783f65d noise generating filter
michael
parents:
diff changeset
112 "movl %3, %%eax \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
113 "pcmpeqb %%mm7, %%mm7 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
114 "psllw $15, %%mm7 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
115 "packsswb %%mm7, %%mm7 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
116 ".balign 16 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
117 "1: \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
118 "movq (%0, %%eax), %%mm0 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
119 "movq (%1, %%eax), %%mm1 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
120 "pxor %%mm7, %%mm0 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
121 "paddsb %%mm1, %%mm0 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
122 "pxor %%mm7, %%mm0 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
123 "movq %%mm0, (%2, %%eax) \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
124 "addl $8, %%eax \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
125 " js 1b \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
126 :: "r" (src+mmx_len), "r" (noise+mmx_len), "r" (dst+mmx_len), "g" (-mmx_len)
83032783f65d noise generating filter
michael
parents:
diff changeset
127 : "%eax"
83032783f65d noise generating filter
michael
parents:
diff changeset
128 );
83032783f65d noise generating filter
michael
parents:
diff changeset
129 if(mmx_len!=len)
83032783f65d noise generating filter
michael
parents:
diff changeset
130 lineNoise_C(dst+mmx_len, src+mmx_len, noise+mmx_len, len-mmx_len, 0);
83032783f65d noise generating filter
michael
parents:
diff changeset
131 }
83032783f65d noise generating filter
michael
parents:
diff changeset
132 #endif
83032783f65d noise generating filter
michael
parents:
diff changeset
133
83032783f65d noise generating filter
michael
parents:
diff changeset
134 //duplicate of previous except movntq
83032783f65d noise generating filter
michael
parents:
diff changeset
135 #ifdef HAVE_MMX2
83032783f65d noise generating filter
michael
parents:
diff changeset
136 static inline void lineNoise_MMX2(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift){
83032783f65d noise generating filter
michael
parents:
diff changeset
137 int mmx_len= len&(~7);
83032783f65d noise generating filter
michael
parents:
diff changeset
138 noise+=shift;
83032783f65d noise generating filter
michael
parents:
diff changeset
139
83032783f65d noise generating filter
michael
parents:
diff changeset
140 asm volatile(
83032783f65d noise generating filter
michael
parents:
diff changeset
141 "movl %3, %%eax \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
142 "pcmpeqb %%mm7, %%mm7 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
143 "psllw $15, %%mm7 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
144 "packsswb %%mm7, %%mm7 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
145 ".balign 16 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
146 "1: \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
147 "movq (%0, %%eax), %%mm0 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
148 "movq (%1, %%eax), %%mm1 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
149 "pxor %%mm7, %%mm0 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
150 "paddsb %%mm1, %%mm0 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
151 "pxor %%mm7, %%mm0 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
152 "movntq %%mm0, (%2, %%eax) \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
153 "addl $8, %%eax \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
154 " js 1b \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
155 :: "r" (src+mmx_len), "r" (noise+mmx_len), "r" (dst+mmx_len), "g" (-mmx_len)
83032783f65d noise generating filter
michael
parents:
diff changeset
156 : "%eax"
83032783f65d noise generating filter
michael
parents:
diff changeset
157 );
83032783f65d noise generating filter
michael
parents:
diff changeset
158 if(mmx_len!=len)
83032783f65d noise generating filter
michael
parents:
diff changeset
159 lineNoise_C(dst+mmx_len, src+mmx_len, noise+mmx_len, len-mmx_len, 0);
83032783f65d noise generating filter
michael
parents:
diff changeset
160 }
83032783f65d noise generating filter
michael
parents:
diff changeset
161 #endif
83032783f65d noise generating filter
michael
parents:
diff changeset
162
83032783f65d noise generating filter
michael
parents:
diff changeset
163 static inline void lineNoise_C(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift){
83032783f65d noise generating filter
michael
parents:
diff changeset
164 int i;
83032783f65d noise generating filter
michael
parents:
diff changeset
165 noise+= shift;
83032783f65d noise generating filter
michael
parents:
diff changeset
166 for(i=0; i<len; i++)
83032783f65d noise generating filter
michael
parents:
diff changeset
167 {
83032783f65d noise generating filter
michael
parents:
diff changeset
168 int v= src[i]+ noise[i];
83032783f65d noise generating filter
michael
parents:
diff changeset
169 if(v>255) dst[i]=255; //FIXME optimize
83032783f65d noise generating filter
michael
parents:
diff changeset
170 else if(v<0) dst[i]=0;
83032783f65d noise generating filter
michael
parents:
diff changeset
171 else dst[i]=v;
83032783f65d noise generating filter
michael
parents:
diff changeset
172 }
83032783f65d noise generating filter
michael
parents:
diff changeset
173 }
83032783f65d noise generating filter
michael
parents:
diff changeset
174
83032783f65d noise generating filter
michael
parents:
diff changeset
175 static void noise(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int width, int height, FilterParam *fp){
83032783f65d noise generating filter
michael
parents:
diff changeset
176 int8_t *noise= fp->noise;
83032783f65d noise generating filter
michael
parents:
diff changeset
177 int y;
83032783f65d noise generating filter
michael
parents:
diff changeset
178 int shift=0;
83032783f65d noise generating filter
michael
parents:
diff changeset
179
83032783f65d noise generating filter
michael
parents:
diff changeset
180 if(!noise)
83032783f65d noise generating filter
michael
parents:
diff changeset
181 {
6447
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
182 if(src==dst) return;
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
183
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
184 if(dstStride==srcStride) memcpy(dst, src, srcStride*height);
83032783f65d noise generating filter
michael
parents:
diff changeset
185 else
83032783f65d noise generating filter
michael
parents:
diff changeset
186 {
83032783f65d noise generating filter
michael
parents:
diff changeset
187 for(y=0; y<height; y++)
83032783f65d noise generating filter
michael
parents:
diff changeset
188 {
83032783f65d noise generating filter
michael
parents:
diff changeset
189 memcpy(dst, src, width);
83032783f65d noise generating filter
michael
parents:
diff changeset
190 dst+= dstStride;
6448
e10e3264c19c higher quality mode
michael
parents: 6447
diff changeset
191 src+= srcStride;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
192 }
83032783f65d noise generating filter
michael
parents:
diff changeset
193 }
83032783f65d noise generating filter
michael
parents:
diff changeset
194 return;
83032783f65d noise generating filter
michael
parents:
diff changeset
195 }
83032783f65d noise generating filter
michael
parents:
diff changeset
196
83032783f65d noise generating filter
michael
parents:
diff changeset
197 for(y=0; y<height; y++)
83032783f65d noise generating filter
michael
parents:
diff changeset
198 {
83032783f65d noise generating filter
michael
parents:
diff changeset
199 if(fp->temporal) shift= rand()&(MAX_SHIFT -1);
83032783f65d noise generating filter
michael
parents:
diff changeset
200 else shift= nonTempRandShift[y];
83032783f65d noise generating filter
michael
parents:
diff changeset
201
6448
e10e3264c19c higher quality mode
michael
parents: 6447
diff changeset
202 if(fp->quality==0) shift&= ~7;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
203 lineNoise(dst, src, noise, width, shift);
83032783f65d noise generating filter
michael
parents:
diff changeset
204 dst+= dstStride;
83032783f65d noise generating filter
michael
parents:
diff changeset
205 src+= srcStride;
83032783f65d noise generating filter
michael
parents:
diff changeset
206 }
83032783f65d noise generating filter
michael
parents:
diff changeset
207 }
83032783f65d noise generating filter
michael
parents:
diff changeset
208
83032783f65d noise generating filter
michael
parents:
diff changeset
209 static int config(struct vf_instance_s* vf,
83032783f65d noise generating filter
michael
parents:
diff changeset
210 int width, int height, int d_width, int d_height,
83032783f65d noise generating filter
michael
parents:
diff changeset
211 unsigned int flags, unsigned int outfmt){
6448
e10e3264c19c higher quality mode
michael
parents: 6447
diff changeset
212
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
213 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
83032783f65d noise generating filter
michael
parents:
diff changeset
214 }
83032783f65d noise generating filter
michael
parents:
diff changeset
215
6447
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
216 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
217 if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
218 if(!(mpi->flags&MP_IMGFLAG_ACCEPT_STRIDE) && mpi->imgfmt!=vf->priv->outfmt)
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
219 return; // colorspace differ
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
220 // ok, we can do pp in-place (or pp disabled):
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
221 vf->priv->dmpi=vf_get_image(vf->next,mpi->imgfmt,
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
222 mpi->type, mpi->flags, mpi->w, mpi->h);
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
223 mpi->planes[0]=vf->priv->dmpi->planes[0];
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
224 mpi->stride[0]=vf->priv->dmpi->stride[0];
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
225 mpi->width=vf->priv->dmpi->width;
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
226 if(mpi->flags&MP_IMGFLAG_PLANAR){
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
227 mpi->planes[1]=vf->priv->dmpi->planes[1];
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
228 mpi->planes[2]=vf->priv->dmpi->planes[2];
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
229 mpi->stride[1]=vf->priv->dmpi->stride[1];
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
230 mpi->stride[2]=vf->priv->dmpi->stride[2];
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
231 }
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
232 mpi->flags|=MP_IMGFLAG_DIRECT;
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
233 }
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
234
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
235 static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){
83032783f65d noise generating filter
michael
parents:
diff changeset
236 mp_image_t *dmpi;
83032783f65d noise generating filter
michael
parents:
diff changeset
237
6447
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
238 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
239 // no DR, so get a new image! hope we'll get DR buffer:
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
240 vf->priv->dmpi=vf_get_image(vf->next,vf->priv->outfmt,
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
241 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
6447
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
242 mpi->w,mpi->h);
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
243 //printf("nodr\n");
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
244 }
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
245 //else printf("dr\n");
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
246 dmpi= vf->priv->dmpi;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
247
83032783f65d noise generating filter
michael
parents:
diff changeset
248 noise(dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, &vf->priv->lumaParam);
83032783f65d noise generating filter
michael
parents:
diff changeset
249 noise(dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w/2, mpi->h/2, &vf->priv->chromaParam);
83032783f65d noise generating filter
michael
parents:
diff changeset
250 noise(dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], mpi->w/2, mpi->h/2, &vf->priv->chromaParam);
83032783f65d noise generating filter
michael
parents:
diff changeset
251
83032783f65d noise generating filter
michael
parents:
diff changeset
252 dmpi->qscale=mpi->qscale;
83032783f65d noise generating filter
michael
parents:
diff changeset
253 dmpi->qstride=mpi->qstride;
83032783f65d noise generating filter
michael
parents:
diff changeset
254
83032783f65d noise generating filter
michael
parents:
diff changeset
255 #ifdef HAVE_MMX
83032783f65d noise generating filter
michael
parents:
diff changeset
256 if(gCpuCaps.hasMMX) asm volatile ("emms\n\t");
83032783f65d noise generating filter
michael
parents:
diff changeset
257 #endif
83032783f65d noise generating filter
michael
parents:
diff changeset
258 #ifdef HAVE_MMX2
83032783f65d noise generating filter
michael
parents:
diff changeset
259 if(gCpuCaps.hasMMX2) asm volatile ("sfence\n\t");
83032783f65d noise generating filter
michael
parents:
diff changeset
260 #endif
83032783f65d noise generating filter
michael
parents:
diff changeset
261
83032783f65d noise generating filter
michael
parents:
diff changeset
262 vf_next_put_image(vf,dmpi);
83032783f65d noise generating filter
michael
parents:
diff changeset
263 }
83032783f65d noise generating filter
michael
parents:
diff changeset
264
6447
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
265 static void uninit(struct vf_instance_s* vf){
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
266 if(!vf->priv) return;
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
267
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
268 if(vf->priv->chromaParam.noise) free(vf->priv->chromaParam.noise);
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
269 vf->priv->chromaParam.noise= NULL;
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
270
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
271 if(vf->priv->lumaParam.noise) free(vf->priv->lumaParam.noise);
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
272 vf->priv->lumaParam.noise= NULL;
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
273
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
274 free(vf->priv);
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
275 vf->priv=NULL;
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
276 }
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
277
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
278 //===========================================================================//
83032783f65d noise generating filter
michael
parents:
diff changeset
279
83032783f65d noise generating filter
michael
parents:
diff changeset
280 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
83032783f65d noise generating filter
michael
parents:
diff changeset
281 switch(fmt)
83032783f65d noise generating filter
michael
parents:
diff changeset
282 {
83032783f65d noise generating filter
michael
parents:
diff changeset
283 case IMGFMT_YV12:
83032783f65d noise generating filter
michael
parents:
diff changeset
284 case IMGFMT_I420:
83032783f65d noise generating filter
michael
parents:
diff changeset
285 case IMGFMT_IYUV:
6447
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
286 return vf_next_query_format(vf,vf->priv->outfmt);
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
287 }
83032783f65d noise generating filter
michael
parents:
diff changeset
288 return 0;
83032783f65d noise generating filter
michael
parents:
diff changeset
289 }
83032783f65d noise generating filter
michael
parents:
diff changeset
290
83032783f65d noise generating filter
michael
parents:
diff changeset
291 static void parse(FilterParam *fp, char* args){
83032783f65d noise generating filter
michael
parents:
diff changeset
292 char *pos;
83032783f65d noise generating filter
michael
parents:
diff changeset
293 char *max= strchr(args, ':');
83032783f65d noise generating filter
michael
parents:
diff changeset
294
83032783f65d noise generating filter
michael
parents:
diff changeset
295 if(!max) max= args + strlen(args);
83032783f65d noise generating filter
michael
parents:
diff changeset
296
83032783f65d noise generating filter
michael
parents:
diff changeset
297 fp->strength= atoi(args);
83032783f65d noise generating filter
michael
parents:
diff changeset
298 pos= strchr(args, 'u');
83032783f65d noise generating filter
michael
parents:
diff changeset
299 if(pos && pos<max) fp->uniform=1;
83032783f65d noise generating filter
michael
parents:
diff changeset
300 pos= strchr(args, 't');
83032783f65d noise generating filter
michael
parents:
diff changeset
301 if(pos && pos<max) fp->temporal=1;
6448
e10e3264c19c higher quality mode
michael
parents: 6447
diff changeset
302 pos= strchr(args, 'h');
e10e3264c19c higher quality mode
michael
parents: 6447
diff changeset
303 if(pos && pos<max) fp->quality=1;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
304
83032783f65d noise generating filter
michael
parents:
diff changeset
305 if(fp->strength) initNoise(fp);
83032783f65d noise generating filter
michael
parents:
diff changeset
306 }
83032783f65d noise generating filter
michael
parents:
diff changeset
307
6447
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
308 static unsigned int fmt_list[]={
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
309 IMGFMT_YV12,
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
310 IMGFMT_I420,
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
311 IMGFMT_IYUV,
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
312 0
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
313 };
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
314
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
315 static int open(vf_instance_t *vf, char* args){
83032783f65d noise generating filter
michael
parents:
diff changeset
316 vf->config=config;
83032783f65d noise generating filter
michael
parents:
diff changeset
317 vf->put_image=put_image;
6447
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
318 vf->get_image=get_image;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
319 vf->query_format=query_format;
6447
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
320 vf->uninit=uninit;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
321 vf->priv=malloc(sizeof(struct vf_priv_s));
83032783f65d noise generating filter
michael
parents:
diff changeset
322 memset(vf->priv, 0, sizeof(struct vf_priv_s));
83032783f65d noise generating filter
michael
parents:
diff changeset
323 if(args)
83032783f65d noise generating filter
michael
parents:
diff changeset
324 {
83032783f65d noise generating filter
michael
parents:
diff changeset
325 char *arg2= strchr(args,':');
83032783f65d noise generating filter
michael
parents:
diff changeset
326 if(arg2) parse(&vf->priv->chromaParam, arg2+1);
83032783f65d noise generating filter
michael
parents:
diff changeset
327 parse(&vf->priv->lumaParam, args);
83032783f65d noise generating filter
michael
parents:
diff changeset
328 }
6447
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
329
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
330 // check csp:
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
331 vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12);
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
332 if(!vf->priv->outfmt)
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
333 {
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
334 uninit(vf);
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
335 return 0; // no csp match :(
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
336 }
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
337
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
338
83032783f65d noise generating filter
michael
parents:
diff changeset
339 #ifdef HAVE_MMX
83032783f65d noise generating filter
michael
parents:
diff changeset
340 if(gCpuCaps.hasMMX) lineNoise= lineNoise_MMX;
83032783f65d noise generating filter
michael
parents:
diff changeset
341 #endif
83032783f65d noise generating filter
michael
parents:
diff changeset
342 #ifdef HAVE_MMX2
83032783f65d noise generating filter
michael
parents:
diff changeset
343 if(gCpuCaps.hasMMX2) lineNoise= lineNoise_MMX2;
83032783f65d noise generating filter
michael
parents:
diff changeset
344 #endif
83032783f65d noise generating filter
michael
parents:
diff changeset
345
83032783f65d noise generating filter
michael
parents:
diff changeset
346 return 1;
83032783f65d noise generating filter
michael
parents:
diff changeset
347 }
83032783f65d noise generating filter
michael
parents:
diff changeset
348
83032783f65d noise generating filter
michael
parents:
diff changeset
349 vf_info_t vf_info_noise = {
83032783f65d noise generating filter
michael
parents:
diff changeset
350 "noise genenerator",
83032783f65d noise generating filter
michael
parents:
diff changeset
351 "noise",
83032783f65d noise generating filter
michael
parents:
diff changeset
352 "Michael Niedermayer",
83032783f65d noise generating filter
michael
parents:
diff changeset
353 "",
83032783f65d noise generating filter
michael
parents:
diff changeset
354 open
83032783f65d noise generating filter
michael
parents:
diff changeset
355 };
83032783f65d noise generating filter
michael
parents:
diff changeset
356
83032783f65d noise generating filter
michael
parents:
diff changeset
357 //===========================================================================//