Mercurial > mplayer.hg
annotate libmpcodecs/vf_noise.c @ 13935:20d243a3c398
keep screensaver off when playing multiple files.
patch by rgselknospam (at) yahoo [dot] com.
author | reimar |
---|---|
date | Sun, 14 Nov 2004 11:36:40 +0000 |
parents | 821f464b4d90 |
children | 6ff3379a0862 |
rev | line source |
---|---|
6424 | 1 /* |
2 Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at> | |
3 | |
4 This program is free software; you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 2 of the License, or | |
7 (at your option) any later version. | |
8 | |
9 This program 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 | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
15 along with this program; if not, write to the Free Software | |
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
17 */ | |
18 | |
19 #include <stdio.h> | |
20 #include <stdlib.h> | |
21 #include <string.h> | |
22 #include <inttypes.h> | |
23 #include <math.h> | |
24 | |
25 #include "../config.h" | |
26 #include "../mp_msg.h" | |
27 #include "../cpudetect.h" | |
28 | |
29 #ifdef HAVE_MALLOC_H | |
30 #include <malloc.h> | |
31 #endif | |
32 | |
33 #include "img_format.h" | |
34 #include "mp_image.h" | |
35 #include "vf.h" | |
36 #include "../libvo/fastmemcpy.h" | |
37 | |
38 #define MAX_NOISE 4096 | |
39 #define MAX_SHIFT 1024 | |
40 #define MAX_RES (MAX_NOISE-MAX_SHIFT) | |
41 | |
42 //===========================================================================// | |
43 | |
44 static inline void lineNoise_C(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift); | |
6963
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
45 static inline void lineNoiseAvg_C(uint8_t *dst, uint8_t *src, int len, int8_t **shift); |
6424 | 46 |
47 static void (*lineNoise)(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift)= lineNoise_C; | |
6963
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
48 static void (*lineNoiseAvg)(uint8_t *dst, uint8_t *src, int len, int8_t **shift)= lineNoiseAvg_C; |
6424 | 49 |
50 typedef struct FilterParam{ | |
51 int strength; | |
52 int uniform; | |
53 int temporal; | |
6448 | 54 int quality; |
6963
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
55 int averaged; |
6990
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
56 int pattern; |
6963
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
57 int shiftptr; |
6424 | 58 int8_t *noise; |
6964 | 59 int8_t *prev_shift[MAX_RES][3]; |
6424 | 60 }FilterParam; |
61 | |
62 struct vf_priv_s { | |
63 FilterParam lumaParam; | |
64 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
|
65 unsigned int outfmt; |
6424 | 66 }; |
67 | |
68 static int nonTempRandShift[MAX_RES]= {-1}; | |
69 | |
6990
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
70 static int patt[4] = { |
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
71 -1,0,1,0 |
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
72 }; |
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
73 |
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
74 #define RAND_N(range) ((int) ((double)range*rand()/(RAND_MAX+1.0))) |
6424 | 75 static int8_t *initNoise(FilterParam *fp){ |
76 int strength= fp->strength; | |
77 int uniform= fp->uniform; | |
6963
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
78 int averaged= fp->averaged; |
6990
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
79 int pattern= fp->pattern; |
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
|
80 int8_t *noise= memalign(16, MAX_NOISE*sizeof(int8_t)); |
6963
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
81 int i, j; |
6424 | 82 |
83 srand(123457); | |
84 | |
6990
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
85 for(i=0,j=0; i<MAX_NOISE; i++,j++) |
6424 | 86 { |
6990
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
87 if(uniform) { |
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
88 if (averaged) { |
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
89 if (pattern) { |
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
90 noise[i]= (RAND_N(strength) - strength/2)/6 |
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
91 +patt[j%4]*strength*0.25/3; |
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
92 } else { |
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
93 noise[i]= (RAND_N(strength) - strength/2)/3; |
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
94 } |
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
95 } else { |
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
96 if (pattern) { |
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
97 noise[i]= (RAND_N(strength) - strength/2)/2 |
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
98 + patt[j%4]*strength*0.25; |
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
99 } else { |
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
100 noise[i]= RAND_N(strength) - strength/2; |
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
101 } |
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
102 } |
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
103 } else { |
6424 | 104 double x1, x2, w, y1; |
105 do { | |
106 x1 = 2.0 * rand()/(float)RAND_MAX - 1.0; | |
107 x2 = 2.0 * rand()/(float)RAND_MAX - 1.0; | |
108 w = x1 * x1 + x2 * x2; | |
109 } while ( w >= 1.0 ); | |
6990
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
110 |
6424 | 111 w = sqrt( (-2.0 * log( w ) ) / w ); |
112 y1= x1 * w; | |
6963
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
113 y1*= strength / sqrt(3.0); |
6990
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
114 if (pattern) { |
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
115 y1 /= 2; |
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
116 y1 += patt[j%4]*strength*0.35; |
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
117 } |
6424 | 118 if (y1<-128) y1=-128; |
119 else if(y1> 127) y1= 127; | |
6963
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
120 if (averaged) y1 /= 3.0; |
6424 | 121 noise[i]= (int)y1; |
122 } | |
6990
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
123 if (RAND_N(6) == 0) j--; |
6424 | 124 } |
6963
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
125 |
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
126 |
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
127 for (i = 0; i < MAX_RES; i++) |
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
128 for (j = 0; j < 3; j++) |
6964 | 129 fp->prev_shift[i][j] = noise + (rand()&(MAX_SHIFT-1)); |
6424 | 130 |
131 if(nonTempRandShift[0]==-1){ | |
132 for(i=0; i<MAX_RES; i++){ | |
133 nonTempRandShift[i]= rand()&(MAX_SHIFT-1); | |
134 } | |
135 } | |
136 | |
137 fp->noise= noise; | |
6963
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
138 fp->shiftptr= 0; |
6424 | 139 return noise; |
140 } | |
141 | |
6963
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
142 /***************************************************************************/ |
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
143 |
6424 | 144 #ifdef HAVE_MMX |
145 static inline void lineNoise_MMX(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift){ | |
13720
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10141
diff
changeset
|
146 long mmx_len= len&(~7); |
6424 | 147 noise+=shift; |
148 | |
149 asm volatile( | |
13720
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10141
diff
changeset
|
150 "mov %3, %%"REG_a" \n\t" |
6424 | 151 "pcmpeqb %%mm7, %%mm7 \n\t" |
152 "psllw $15, %%mm7 \n\t" | |
153 "packsswb %%mm7, %%mm7 \n\t" | |
154 ".balign 16 \n\t" | |
155 "1: \n\t" | |
13720
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10141
diff
changeset
|
156 "movq (%0, %%"REG_a"), %%mm0 \n\t" |
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10141
diff
changeset
|
157 "movq (%1, %%"REG_a"), %%mm1 \n\t" |
6424 | 158 "pxor %%mm7, %%mm0 \n\t" |
159 "paddsb %%mm1, %%mm0 \n\t" | |
160 "pxor %%mm7, %%mm0 \n\t" | |
13720
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10141
diff
changeset
|
161 "movq %%mm0, (%2, %%"REG_a") \n\t" |
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10141
diff
changeset
|
162 "add $8, %%"REG_a" \n\t" |
6424 | 163 " js 1b \n\t" |
164 :: "r" (src+mmx_len), "r" (noise+mmx_len), "r" (dst+mmx_len), "g" (-mmx_len) | |
13720
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10141
diff
changeset
|
165 : "%"REG_a |
6424 | 166 ); |
167 if(mmx_len!=len) | |
168 lineNoise_C(dst+mmx_len, src+mmx_len, noise+mmx_len, len-mmx_len, 0); | |
169 } | |
170 #endif | |
171 | |
172 //duplicate of previous except movntq | |
173 #ifdef HAVE_MMX2 | |
174 static inline void lineNoise_MMX2(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift){ | |
13720
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10141
diff
changeset
|
175 long mmx_len= len&(~7); |
6424 | 176 noise+=shift; |
177 | |
178 asm volatile( | |
13720
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10141
diff
changeset
|
179 "mov %3, %%"REG_a" \n\t" |
6424 | 180 "pcmpeqb %%mm7, %%mm7 \n\t" |
181 "psllw $15, %%mm7 \n\t" | |
182 "packsswb %%mm7, %%mm7 \n\t" | |
183 ".balign 16 \n\t" | |
184 "1: \n\t" | |
13720
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10141
diff
changeset
|
185 "movq (%0, %%"REG_a"), %%mm0 \n\t" |
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10141
diff
changeset
|
186 "movq (%1, %%"REG_a"), %%mm1 \n\t" |
6424 | 187 "pxor %%mm7, %%mm0 \n\t" |
188 "paddsb %%mm1, %%mm0 \n\t" | |
189 "pxor %%mm7, %%mm0 \n\t" | |
13720
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10141
diff
changeset
|
190 "movntq %%mm0, (%2, %%"REG_a") \n\t" |
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10141
diff
changeset
|
191 "add $8, %%"REG_a" \n\t" |
6424 | 192 " js 1b \n\t" |
193 :: "r" (src+mmx_len), "r" (noise+mmx_len), "r" (dst+mmx_len), "g" (-mmx_len) | |
13720
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10141
diff
changeset
|
194 : "%"REG_a |
6424 | 195 ); |
196 if(mmx_len!=len) | |
197 lineNoise_C(dst+mmx_len, src+mmx_len, noise+mmx_len, len-mmx_len, 0); | |
198 } | |
199 #endif | |
200 | |
201 static inline void lineNoise_C(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift){ | |
202 int i; | |
203 noise+= shift; | |
204 for(i=0; i<len; i++) | |
205 { | |
206 int v= src[i]+ noise[i]; | |
207 if(v>255) dst[i]=255; //FIXME optimize | |
208 else if(v<0) dst[i]=0; | |
209 else dst[i]=v; | |
210 } | |
211 } | |
212 | |
6963
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
213 /***************************************************************************/ |
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
214 |
6966 | 215 #ifdef HAVE_MMX |
216 static inline void lineNoiseAvg_MMX(uint8_t *dst, uint8_t *src, int len, int8_t **shift){ | |
13720
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10141
diff
changeset
|
217 long mmx_len= len&(~7); |
6966 | 218 |
219 asm volatile( | |
13720
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10141
diff
changeset
|
220 "mov %5, %%"REG_a" \n\t" |
6966 | 221 ".balign 16 \n\t" |
222 "1: \n\t" | |
13720
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10141
diff
changeset
|
223 "movq (%1, %%"REG_a"), %%mm1 \n\t" |
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10141
diff
changeset
|
224 "movq (%0, %%"REG_a"), %%mm0 \n\t" |
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10141
diff
changeset
|
225 "paddb (%2, %%"REG_a"), %%mm1 \n\t" |
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10141
diff
changeset
|
226 "paddb (%3, %%"REG_a"), %%mm1 \n\t" |
6966 | 227 "movq %%mm0, %%mm2 \n\t" |
228 "movq %%mm1, %%mm3 \n\t" | |
229 "punpcklbw %%mm0, %%mm0 \n\t" | |
230 "punpckhbw %%mm2, %%mm2 \n\t" | |
231 "punpcklbw %%mm1, %%mm1 \n\t" | |
232 "punpckhbw %%mm3, %%mm3 \n\t" | |
233 "pmulhw %%mm0, %%mm1 \n\t" | |
234 "pmulhw %%mm2, %%mm3 \n\t" | |
235 "paddw %%mm1, %%mm1 \n\t" | |
236 "paddw %%mm3, %%mm3 \n\t" | |
237 "paddw %%mm0, %%mm1 \n\t" | |
238 "paddw %%mm2, %%mm3 \n\t" | |
239 "psrlw $8, %%mm1 \n\t" | |
240 "psrlw $8, %%mm3 \n\t" | |
241 "packuswb %%mm3, %%mm1 \n\t" | |
13720
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10141
diff
changeset
|
242 "movq %%mm1, (%4, %%"REG_a") \n\t" |
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10141
diff
changeset
|
243 "add $8, %%"REG_a" \n\t" |
6966 | 244 " js 1b \n\t" |
245 :: "r" (src+mmx_len), "r" (shift[0]+mmx_len), "r" (shift[1]+mmx_len), "r" (shift[2]+mmx_len), | |
246 "r" (dst+mmx_len), "g" (-mmx_len) | |
13720
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10141
diff
changeset
|
247 : "%"REG_a |
6966 | 248 ); |
249 | |
250 if(mmx_len!=len){ | |
251 int8_t *shift2[3]={shift[0]+mmx_len, shift[1]+mmx_len, shift[2]+mmx_len}; | |
252 lineNoiseAvg_C(dst+mmx_len, src+mmx_len, len-mmx_len, shift2); | |
253 } | |
254 } | |
255 #endif | |
256 | |
6963
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
257 static inline void lineNoiseAvg_C(uint8_t *dst, uint8_t *src, int len, int8_t **shift){ |
6965 | 258 int i; |
259 int8_t *src2= (int8_t*)src; | |
6963
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
260 |
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
261 for(i=0; i<len; i++) |
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
262 { |
6965 | 263 const int n= shift[0][i] + shift[1][i] + shift[2][i]; |
264 dst[i]= src2[i]+((n*src2[i])>>7); | |
6963
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
265 } |
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
266 } |
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
267 |
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
268 /***************************************************************************/ |
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
269 |
6424 | 270 static void noise(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int width, int height, FilterParam *fp){ |
271 int8_t *noise= fp->noise; | |
272 int y; | |
273 int shift=0; | |
274 | |
275 if(!noise) | |
276 { | |
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
|
277 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
|
278 |
6424 | 279 if(dstStride==srcStride) memcpy(dst, src, srcStride*height); |
280 else | |
281 { | |
282 for(y=0; y<height; y++) | |
283 { | |
284 memcpy(dst, src, width); | |
285 dst+= dstStride; | |
6448 | 286 src+= srcStride; |
6424 | 287 } |
288 } | |
289 return; | |
290 } | |
291 | |
292 for(y=0; y<height; y++) | |
293 { | |
294 if(fp->temporal) shift= rand()&(MAX_SHIFT -1); | |
295 else shift= nonTempRandShift[y]; | |
296 | |
6448 | 297 if(fp->quality==0) shift&= ~7; |
6963
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
298 if (fp->averaged) { |
6964 | 299 lineNoiseAvg(dst, src, width, fp->prev_shift[y]); |
300 fp->prev_shift[y][fp->shiftptr] = noise + shift; | |
6963
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
301 } else { |
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
302 lineNoise(dst, src, noise, width, shift); |
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
303 } |
6424 | 304 dst+= dstStride; |
305 src+= srcStride; | |
306 } | |
6963
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
307 fp->shiftptr++; |
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
308 if (fp->shiftptr == 3) fp->shiftptr = 0; |
6424 | 309 } |
310 | |
311 static int config(struct vf_instance_s* vf, | |
312 int width, int height, int d_width, int d_height, | |
313 unsigned int flags, unsigned int outfmt){ | |
6448 | 314 |
6424 | 315 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); |
316 } | |
317 | |
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 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
|
319 if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change |
6962 | 320 if(mpi->imgfmt!=vf->priv->outfmt) return; // colorspace differ |
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
|
321 // ok, we can do pp in-place (or pp disabled): |
10141
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9934
diff
changeset
|
322 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, |
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
|
323 mpi->type, mpi->flags, mpi->w, mpi->h); |
10141
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9934
diff
changeset
|
324 mpi->planes[0]=vf->dmpi->planes[0]; |
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9934
diff
changeset
|
325 mpi->stride[0]=vf->dmpi->stride[0]; |
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9934
diff
changeset
|
326 mpi->width=vf->dmpi->width; |
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
|
327 if(mpi->flags&MP_IMGFLAG_PLANAR){ |
10141
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9934
diff
changeset
|
328 mpi->planes[1]=vf->dmpi->planes[1]; |
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9934
diff
changeset
|
329 mpi->planes[2]=vf->dmpi->planes[2]; |
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9934
diff
changeset
|
330 mpi->stride[1]=vf->dmpi->stride[1]; |
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9934
diff
changeset
|
331 mpi->stride[2]=vf->dmpi->stride[2]; |
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
|
332 } |
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 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
|
334 } |
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 |
7368 | 336 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ |
6424 | 337 mp_image_t *dmpi; |
338 | |
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
|
339 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
|
340 // no DR, so get a new image! hope we'll get DR buffer: |
10141
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9934
diff
changeset
|
341 vf->dmpi=vf_get_image(vf->next,vf->priv->outfmt, |
6424 | 342 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
|
343 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
|
344 //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
|
345 } |
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
|
346 //else printf("dr\n"); |
10141
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9934
diff
changeset
|
347 dmpi= vf->dmpi; |
6424 | 348 |
349 noise(dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, &vf->priv->lumaParam); | |
350 noise(dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w/2, mpi->h/2, &vf->priv->chromaParam); | |
351 noise(dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], mpi->w/2, mpi->h/2, &vf->priv->chromaParam); | |
352 | |
9934 | 353 vf_clone_mpi_attributes(dmpi, mpi); |
6424 | 354 |
355 #ifdef HAVE_MMX | |
356 if(gCpuCaps.hasMMX) asm volatile ("emms\n\t"); | |
357 #endif | |
358 #ifdef HAVE_MMX2 | |
359 if(gCpuCaps.hasMMX2) asm volatile ("sfence\n\t"); | |
360 #endif | |
361 | |
7368 | 362 return vf_next_put_image(vf,dmpi); |
6424 | 363 } |
364 | |
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
|
365 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
|
366 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
|
367 |
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
|
368 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
|
369 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
|
370 |
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
|
371 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
|
372 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
|
373 |
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
|
374 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
|
375 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
|
376 } |
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
|
377 |
6424 | 378 //===========================================================================// |
379 | |
380 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ | |
381 switch(fmt) | |
382 { | |
383 case IMGFMT_YV12: | |
384 case IMGFMT_I420: | |
385 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
|
386 return vf_next_query_format(vf,vf->priv->outfmt); |
6424 | 387 } |
388 return 0; | |
389 } | |
390 | |
391 static void parse(FilterParam *fp, char* args){ | |
392 char *pos; | |
393 char *max= strchr(args, ':'); | |
394 | |
395 if(!max) max= args + strlen(args); | |
396 | |
397 fp->strength= atoi(args); | |
398 pos= strchr(args, 'u'); | |
399 if(pos && pos<max) fp->uniform=1; | |
400 pos= strchr(args, 't'); | |
401 if(pos && pos<max) fp->temporal=1; | |
6448 | 402 pos= strchr(args, 'h'); |
403 if(pos && pos<max) fp->quality=1; | |
6990
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
404 pos= strchr(args, 'p'); |
857bae3001e8
semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents:
6966
diff
changeset
|
405 if(pos && pos<max) fp->pattern=1; |
6963
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
406 pos= strchr(args, 'a'); |
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
407 if(pos && pos<max) { |
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
408 fp->temporal=1; |
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
409 fp->averaged=1; |
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
410 } |
6424 | 411 |
412 if(fp->strength) initNoise(fp); | |
413 } | |
414 | |
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
|
415 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
|
416 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
|
417 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
|
418 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
|
419 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
|
420 }; |
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
|
421 |
6424 | 422 static int open(vf_instance_t *vf, char* args){ |
423 vf->config=config; | |
424 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
|
425 vf->get_image=get_image; |
6424 | 426 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
|
427 vf->uninit=uninit; |
6424 | 428 vf->priv=malloc(sizeof(struct vf_priv_s)); |
429 memset(vf->priv, 0, sizeof(struct vf_priv_s)); | |
430 if(args) | |
431 { | |
432 char *arg2= strchr(args,':'); | |
433 if(arg2) parse(&vf->priv->chromaParam, arg2+1); | |
434 parse(&vf->priv->lumaParam, args); | |
435 } | |
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
|
436 |
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
|
437 // 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
|
438 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
|
439 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
|
440 { |
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
|
441 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
|
442 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
|
443 } |
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
|
444 |
6424 | 445 |
446 #ifdef HAVE_MMX | |
6966 | 447 if(gCpuCaps.hasMMX){ |
448 lineNoise= lineNoise_MMX; | |
449 lineNoiseAvg= lineNoiseAvg_MMX; | |
450 } | |
6424 | 451 #endif |
452 #ifdef HAVE_MMX2 | |
453 if(gCpuCaps.hasMMX2) lineNoise= lineNoise_MMX2; | |
6963
76fee64d884a
film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents:
6962
diff
changeset
|
454 // if(gCpuCaps.hasMMX) lineNoiseAvg= lineNoiseAvg_MMX2; |
6424 | 455 #endif |
456 | |
457 return 1; | |
458 } | |
459 | |
460 vf_info_t vf_info_noise = { | |
461 "noise genenerator", | |
462 "noise", | |
463 "Michael Niedermayer", | |
464 "", | |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
7368
diff
changeset
|
465 open, |
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
7368
diff
changeset
|
466 NULL |
6424 | 467 }; |
468 | |
469 //===========================================================================// |