annotate libmpcodecs/vf_noise.c @ 8051:1b0d3175ef5f

removed dummy config(), query_format()
author arpi
date Sat, 02 Nov 2002 17:43:42 +0000
parents a894e99c1e51
children e9a2af584986
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);
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
83032783f65d noise generating filter
michael
parents:
diff changeset
46
83032783f65d noise generating filter
michael
parents:
diff changeset
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
83032783f65d noise generating filter
michael
parents:
diff changeset
49
83032783f65d noise generating filter
michael
parents:
diff changeset
50 typedef struct FilterParam{
83032783f65d noise generating filter
michael
parents:
diff changeset
51 int strength;
83032783f65d noise generating filter
michael
parents:
diff changeset
52 int uniform;
83032783f65d noise generating filter
michael
parents:
diff changeset
53 int temporal;
6448
e10e3264c19c higher quality mode
michael
parents: 6447
diff changeset
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
83032783f65d noise generating filter
michael
parents:
diff changeset
58 int8_t *noise;
6964
f35d05c32dd1 film/average noise cleanup
michael
parents: 6963
diff changeset
59 int8_t *prev_shift[MAX_RES][3];
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
60 }FilterParam;
83032783f65d noise generating filter
michael
parents:
diff changeset
61
83032783f65d noise generating filter
michael
parents:
diff changeset
62 struct vf_priv_s {
83032783f65d noise generating filter
michael
parents:
diff changeset
63 FilterParam lumaParam;
83032783f65d noise generating filter
michael
parents:
diff changeset
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 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
66 unsigned int outfmt;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
67 };
83032783f65d noise generating filter
michael
parents:
diff changeset
68
83032783f65d noise generating filter
michael
parents:
diff changeset
69 static int nonTempRandShift[MAX_RES]= {-1};
83032783f65d noise generating filter
michael
parents:
diff changeset
70
6990
857bae3001e8 semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents: 6966
diff changeset
71 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
72 -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
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
857bae3001e8 semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents: 6966
diff changeset
75 #define RAND_N(range) ((int) ((double)range*rand()/(RAND_MAX+1.0)))
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
76 static int8_t *initNoise(FilterParam *fp){
83032783f65d noise generating filter
michael
parents:
diff changeset
77 int strength= fp->strength;
83032783f65d noise generating filter
michael
parents:
diff changeset
78 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
79 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
80 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
81 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
82 int i, j;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
83
83032783f65d noise generating filter
michael
parents:
diff changeset
84 srand(123457);
83032783f65d noise generating filter
michael
parents:
diff changeset
85
6990
857bae3001e8 semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents: 6966
diff changeset
86 for(i=0,j=0; i<MAX_NOISE; i++,j++)
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
87 {
6990
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(uniform) {
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 (averaged) {
857bae3001e8 semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents: 6966
diff changeset
90 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
91 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
92 +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
93 } else {
857bae3001e8 semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents: 6966
diff changeset
94 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
95 }
857bae3001e8 semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents: 6966
diff changeset
96 } else {
857bae3001e8 semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents: 6966
diff changeset
97 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
98 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
99 + 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
100 } else {
857bae3001e8 semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents: 6966
diff changeset
101 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
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 }
857bae3001e8 semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents: 6966
diff changeset
104 } else {
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
105 double x1, x2, w, y1;
83032783f65d noise generating filter
michael
parents:
diff changeset
106 do {
83032783f65d noise generating filter
michael
parents:
diff changeset
107 x1 = 2.0 * rand()/(float)RAND_MAX - 1.0;
83032783f65d noise generating filter
michael
parents:
diff changeset
108 x2 = 2.0 * rand()/(float)RAND_MAX - 1.0;
83032783f65d noise generating filter
michael
parents:
diff changeset
109 w = x1 * x1 + x2 * x2;
83032783f65d noise generating filter
michael
parents:
diff changeset
110 } 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
111
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
112 w = sqrt( (-2.0 * log( w ) ) / w );
83032783f65d noise generating filter
michael
parents:
diff changeset
113 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
114 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
115 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
116 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
117 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
118 }
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
119 if (y1<-128) y1=-128;
83032783f65d noise generating filter
michael
parents:
diff changeset
120 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
121 if (averaged) y1 /= 3.0;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
122 noise[i]= (int)y1;
83032783f65d noise generating filter
michael
parents:
diff changeset
123 }
6990
857bae3001e8 semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents: 6966
diff changeset
124 if (RAND_N(6) == 0) j--;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
125 }
6963
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
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
128 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
129 for (j = 0; j < 3; j++)
6964
f35d05c32dd1 film/average noise cleanup
michael
parents: 6963
diff changeset
130 fp->prev_shift[i][j] = noise + (rand()&(MAX_SHIFT-1));
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
131
83032783f65d noise generating filter
michael
parents:
diff changeset
132 if(nonTempRandShift[0]==-1){
83032783f65d noise generating filter
michael
parents:
diff changeset
133 for(i=0; i<MAX_RES; i++){
83032783f65d noise generating filter
michael
parents:
diff changeset
134 nonTempRandShift[i]= rand()&(MAX_SHIFT-1);
83032783f65d noise generating filter
michael
parents:
diff changeset
135 }
83032783f65d noise generating filter
michael
parents:
diff changeset
136 }
83032783f65d noise generating filter
michael
parents:
diff changeset
137
83032783f65d noise generating filter
michael
parents:
diff changeset
138 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
139 fp->shiftptr= 0;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
140 return noise;
83032783f65d noise generating filter
michael
parents:
diff changeset
141 }
83032783f65d noise generating filter
michael
parents:
diff changeset
142
6963
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
143 /***************************************************************************/
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
144
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
145 #ifdef HAVE_MMX
83032783f65d noise generating filter
michael
parents:
diff changeset
146 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
147 int mmx_len= len&(~7);
83032783f65d noise generating filter
michael
parents:
diff changeset
148 noise+=shift;
83032783f65d noise generating filter
michael
parents:
diff changeset
149
83032783f65d noise generating filter
michael
parents:
diff changeset
150 asm volatile(
83032783f65d noise generating filter
michael
parents:
diff changeset
151 "movl %3, %%eax \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
152 "pcmpeqb %%mm7, %%mm7 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
153 "psllw $15, %%mm7 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
154 "packsswb %%mm7, %%mm7 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
155 ".balign 16 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
156 "1: \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
157 "movq (%0, %%eax), %%mm0 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
158 "movq (%1, %%eax), %%mm1 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
159 "pxor %%mm7, %%mm0 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
160 "paddsb %%mm1, %%mm0 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
161 "pxor %%mm7, %%mm0 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
162 "movq %%mm0, (%2, %%eax) \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
163 "addl $8, %%eax \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
164 " js 1b \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
165 :: "r" (src+mmx_len), "r" (noise+mmx_len), "r" (dst+mmx_len), "g" (-mmx_len)
83032783f65d noise generating filter
michael
parents:
diff changeset
166 : "%eax"
83032783f65d noise generating filter
michael
parents:
diff changeset
167 );
83032783f65d noise generating filter
michael
parents:
diff changeset
168 if(mmx_len!=len)
83032783f65d noise generating filter
michael
parents:
diff changeset
169 lineNoise_C(dst+mmx_len, src+mmx_len, noise+mmx_len, len-mmx_len, 0);
83032783f65d noise generating filter
michael
parents:
diff changeset
170 }
83032783f65d noise generating filter
michael
parents:
diff changeset
171 #endif
83032783f65d noise generating filter
michael
parents:
diff changeset
172
83032783f65d noise generating filter
michael
parents:
diff changeset
173 //duplicate of previous except movntq
83032783f65d noise generating filter
michael
parents:
diff changeset
174 #ifdef HAVE_MMX2
83032783f65d noise generating filter
michael
parents:
diff changeset
175 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
176 int mmx_len= len&(~7);
83032783f65d noise generating filter
michael
parents:
diff changeset
177 noise+=shift;
83032783f65d noise generating filter
michael
parents:
diff changeset
178
83032783f65d noise generating filter
michael
parents:
diff changeset
179 asm volatile(
83032783f65d noise generating filter
michael
parents:
diff changeset
180 "movl %3, %%eax \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
181 "pcmpeqb %%mm7, %%mm7 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
182 "psllw $15, %%mm7 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
183 "packsswb %%mm7, %%mm7 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
184 ".balign 16 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
185 "1: \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
186 "movq (%0, %%eax), %%mm0 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
187 "movq (%1, %%eax), %%mm1 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
188 "pxor %%mm7, %%mm0 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
189 "paddsb %%mm1, %%mm0 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
190 "pxor %%mm7, %%mm0 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
191 "movntq %%mm0, (%2, %%eax) \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
192 "addl $8, %%eax \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
193 " js 1b \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
194 :: "r" (src+mmx_len), "r" (noise+mmx_len), "r" (dst+mmx_len), "g" (-mmx_len)
83032783f65d noise generating filter
michael
parents:
diff changeset
195 : "%eax"
83032783f65d noise generating filter
michael
parents:
diff changeset
196 );
83032783f65d noise generating filter
michael
parents:
diff changeset
197 if(mmx_len!=len)
83032783f65d noise generating filter
michael
parents:
diff changeset
198 lineNoise_C(dst+mmx_len, src+mmx_len, noise+mmx_len, len-mmx_len, 0);
83032783f65d noise generating filter
michael
parents:
diff changeset
199 }
83032783f65d noise generating filter
michael
parents:
diff changeset
200 #endif
83032783f65d noise generating filter
michael
parents:
diff changeset
201
83032783f65d noise generating filter
michael
parents:
diff changeset
202 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
203 int i;
83032783f65d noise generating filter
michael
parents:
diff changeset
204 noise+= shift;
83032783f65d noise generating filter
michael
parents:
diff changeset
205 for(i=0; i<len; i++)
83032783f65d noise generating filter
michael
parents:
diff changeset
206 {
83032783f65d noise generating filter
michael
parents:
diff changeset
207 int v= src[i]+ noise[i];
83032783f65d noise generating filter
michael
parents:
diff changeset
208 if(v>255) dst[i]=255; //FIXME optimize
83032783f65d noise generating filter
michael
parents:
diff changeset
209 else if(v<0) dst[i]=0;
83032783f65d noise generating filter
michael
parents:
diff changeset
210 else dst[i]=v;
83032783f65d noise generating filter
michael
parents:
diff changeset
211 }
83032783f65d noise generating filter
michael
parents:
diff changeset
212 }
83032783f65d noise generating filter
michael
parents:
diff changeset
213
6963
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
214 /***************************************************************************/
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
215
6966
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
216 #ifdef HAVE_MMX
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
217 static inline void lineNoiseAvg_MMX(uint8_t *dst, uint8_t *src, int len, int8_t **shift){
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
218 int mmx_len= len&(~7);
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
219
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
220 asm volatile(
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
221 "movl %5, %%eax \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
222 ".balign 16 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
223 "1: \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
224 "movq (%1, %%eax), %%mm1 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
225 "movq (%0, %%eax), %%mm0 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
226 "paddb (%2, %%eax), %%mm1 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
227 "paddb (%3, %%eax), %%mm1 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
228 "movq %%mm0, %%mm2 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
229 "movq %%mm1, %%mm3 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
230 "punpcklbw %%mm0, %%mm0 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
231 "punpckhbw %%mm2, %%mm2 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
232 "punpcklbw %%mm1, %%mm1 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
233 "punpckhbw %%mm3, %%mm3 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
234 "pmulhw %%mm0, %%mm1 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
235 "pmulhw %%mm2, %%mm3 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
236 "paddw %%mm1, %%mm1 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
237 "paddw %%mm3, %%mm3 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
238 "paddw %%mm0, %%mm1 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
239 "paddw %%mm2, %%mm3 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
240 "psrlw $8, %%mm1 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
241 "psrlw $8, %%mm3 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
242 "packuswb %%mm3, %%mm1 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
243 "movq %%mm1, (%4, %%eax) \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
244 "addl $8, %%eax \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
245 " js 1b \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
246 :: "r" (src+mmx_len), "r" (shift[0]+mmx_len), "r" (shift[1]+mmx_len), "r" (shift[2]+mmx_len),
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
247 "r" (dst+mmx_len), "g" (-mmx_len)
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
248 : "%eax"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
249 );
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
250
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
251 if(mmx_len!=len){
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
252 int8_t *shift2[3]={shift[0]+mmx_len, shift[1]+mmx_len, shift[2]+mmx_len};
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
253 lineNoiseAvg_C(dst+mmx_len, src+mmx_len, len-mmx_len, shift2);
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
254 }
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
255 }
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
256 #endif
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
257
6963
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
258 static inline void lineNoiseAvg_C(uint8_t *dst, uint8_t *src, int len, int8_t **shift){
6965
f8ea0af8edb0 optimization
michael
parents: 6964
diff changeset
259 int i;
f8ea0af8edb0 optimization
michael
parents: 6964
diff changeset
260 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
261
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
262 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
263 {
6965
f8ea0af8edb0 optimization
michael
parents: 6964
diff changeset
264 const int n= shift[0][i] + shift[1][i] + shift[2][i];
f8ea0af8edb0 optimization
michael
parents: 6964
diff changeset
265 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
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 /***************************************************************************/
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
270
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
271 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
272 int8_t *noise= fp->noise;
83032783f65d noise generating filter
michael
parents:
diff changeset
273 int y;
83032783f65d noise generating filter
michael
parents:
diff changeset
274 int shift=0;
83032783f65d noise generating filter
michael
parents:
diff changeset
275
83032783f65d noise generating filter
michael
parents:
diff changeset
276 if(!noise)
83032783f65d noise generating filter
michael
parents:
diff changeset
277 {
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
278 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
279
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
280 if(dstStride==srcStride) memcpy(dst, src, srcStride*height);
83032783f65d noise generating filter
michael
parents:
diff changeset
281 else
83032783f65d noise generating filter
michael
parents:
diff changeset
282 {
83032783f65d noise generating filter
michael
parents:
diff changeset
283 for(y=0; y<height; y++)
83032783f65d noise generating filter
michael
parents:
diff changeset
284 {
83032783f65d noise generating filter
michael
parents:
diff changeset
285 memcpy(dst, src, width);
83032783f65d noise generating filter
michael
parents:
diff changeset
286 dst+= dstStride;
6448
e10e3264c19c higher quality mode
michael
parents: 6447
diff changeset
287 src+= srcStride;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
288 }
83032783f65d noise generating filter
michael
parents:
diff changeset
289 }
83032783f65d noise generating filter
michael
parents:
diff changeset
290 return;
83032783f65d noise generating filter
michael
parents:
diff changeset
291 }
83032783f65d noise generating filter
michael
parents:
diff changeset
292
83032783f65d noise generating filter
michael
parents:
diff changeset
293 for(y=0; y<height; y++)
83032783f65d noise generating filter
michael
parents:
diff changeset
294 {
83032783f65d noise generating filter
michael
parents:
diff changeset
295 if(fp->temporal) shift= rand()&(MAX_SHIFT -1);
83032783f65d noise generating filter
michael
parents:
diff changeset
296 else shift= nonTempRandShift[y];
83032783f65d noise generating filter
michael
parents:
diff changeset
297
6448
e10e3264c19c higher quality mode
michael
parents: 6447
diff changeset
298 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
299 if (fp->averaged) {
6964
f35d05c32dd1 film/average noise cleanup
michael
parents: 6963
diff changeset
300 lineNoiseAvg(dst, src, width, fp->prev_shift[y]);
f35d05c32dd1 film/average noise cleanup
michael
parents: 6963
diff changeset
301 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
302 } else {
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
303 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
304 }
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
305 dst+= dstStride;
83032783f65d noise generating filter
michael
parents:
diff changeset
306 src+= srcStride;
83032783f65d noise generating filter
michael
parents:
diff changeset
307 }
6963
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
308 fp->shiftptr++;
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
309 if (fp->shiftptr == 3) fp->shiftptr = 0;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
310 }
83032783f65d noise generating filter
michael
parents:
diff changeset
311
83032783f65d noise generating filter
michael
parents:
diff changeset
312 static int config(struct vf_instance_s* vf,
83032783f65d noise generating filter
michael
parents:
diff changeset
313 int width, int height, int d_width, int d_height,
83032783f65d noise generating filter
michael
parents:
diff changeset
314 unsigned int flags, unsigned int outfmt){
6448
e10e3264c19c higher quality mode
michael
parents: 6447
diff changeset
315
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
316 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
83032783f65d noise generating filter
michael
parents:
diff changeset
317 }
83032783f65d noise generating filter
michael
parents:
diff changeset
318
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
319 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
320 if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
6962
ba721168ed24 oops forgot to commit that
michael
parents: 6448
diff changeset
321 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
322 // 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
323 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
324 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
325 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
326 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
327 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
328 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
329 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
330 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
331 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
332 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
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 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
335 }
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
7368
a894e99c1e51 changing return type of put_image void->int
arpi
parents: 6990
diff changeset
337 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
338 mp_image_t *dmpi;
83032783f65d noise generating filter
michael
parents:
diff changeset
339
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
340 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
341 // 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
342 vf->priv->dmpi=vf_get_image(vf->next,vf->priv->outfmt,
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
343 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
344 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
345 //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
346 }
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
347 //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
348 dmpi= vf->priv->dmpi;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
349
83032783f65d noise generating filter
michael
parents:
diff changeset
350 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
351 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
352 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
353
83032783f65d noise generating filter
michael
parents:
diff changeset
354 dmpi->qscale=mpi->qscale;
83032783f65d noise generating filter
michael
parents:
diff changeset
355 dmpi->qstride=mpi->qstride;
83032783f65d noise generating filter
michael
parents:
diff changeset
356
83032783f65d noise generating filter
michael
parents:
diff changeset
357 #ifdef HAVE_MMX
83032783f65d noise generating filter
michael
parents:
diff changeset
358 if(gCpuCaps.hasMMX) asm volatile ("emms\n\t");
83032783f65d noise generating filter
michael
parents:
diff changeset
359 #endif
83032783f65d noise generating filter
michael
parents:
diff changeset
360 #ifdef HAVE_MMX2
83032783f65d noise generating filter
michael
parents:
diff changeset
361 if(gCpuCaps.hasMMX2) asm volatile ("sfence\n\t");
83032783f65d noise generating filter
michael
parents:
diff changeset
362 #endif
83032783f65d noise generating filter
michael
parents:
diff changeset
363
7368
a894e99c1e51 changing return type of put_image void->int
arpi
parents: 6990
diff changeset
364 return vf_next_put_image(vf,dmpi);
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
365 }
83032783f65d noise generating filter
michael
parents:
diff changeset
366
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
367 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
368 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
369
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 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
371 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
372
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 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
374 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
375
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 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
377 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
378 }
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
379
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
380 //===========================================================================//
83032783f65d noise generating filter
michael
parents:
diff changeset
381
83032783f65d noise generating filter
michael
parents:
diff changeset
382 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
83032783f65d noise generating filter
michael
parents:
diff changeset
383 switch(fmt)
83032783f65d noise generating filter
michael
parents:
diff changeset
384 {
83032783f65d noise generating filter
michael
parents:
diff changeset
385 case IMGFMT_YV12:
83032783f65d noise generating filter
michael
parents:
diff changeset
386 case IMGFMT_I420:
83032783f65d noise generating filter
michael
parents:
diff changeset
387 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
388 return vf_next_query_format(vf,vf->priv->outfmt);
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
389 }
83032783f65d noise generating filter
michael
parents:
diff changeset
390 return 0;
83032783f65d noise generating filter
michael
parents:
diff changeset
391 }
83032783f65d noise generating filter
michael
parents:
diff changeset
392
83032783f65d noise generating filter
michael
parents:
diff changeset
393 static void parse(FilterParam *fp, char* args){
83032783f65d noise generating filter
michael
parents:
diff changeset
394 char *pos;
83032783f65d noise generating filter
michael
parents:
diff changeset
395 char *max= strchr(args, ':');
83032783f65d noise generating filter
michael
parents:
diff changeset
396
83032783f65d noise generating filter
michael
parents:
diff changeset
397 if(!max) max= args + strlen(args);
83032783f65d noise generating filter
michael
parents:
diff changeset
398
83032783f65d noise generating filter
michael
parents:
diff changeset
399 fp->strength= atoi(args);
83032783f65d noise generating filter
michael
parents:
diff changeset
400 pos= strchr(args, 'u');
83032783f65d noise generating filter
michael
parents:
diff changeset
401 if(pos && pos<max) fp->uniform=1;
83032783f65d noise generating filter
michael
parents:
diff changeset
402 pos= strchr(args, 't');
83032783f65d noise generating filter
michael
parents:
diff changeset
403 if(pos && pos<max) fp->temporal=1;
6448
e10e3264c19c higher quality mode
michael
parents: 6447
diff changeset
404 pos= strchr(args, 'h');
e10e3264c19c higher quality mode
michael
parents: 6447
diff changeset
405 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
406 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
407 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
408 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
409 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
410 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
411 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
412 }
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
413
83032783f65d noise generating filter
michael
parents:
diff changeset
414 if(fp->strength) initNoise(fp);
83032783f65d noise generating filter
michael
parents:
diff changeset
415 }
83032783f65d noise generating filter
michael
parents:
diff changeset
416
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
417 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
418 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
419 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
420 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
421 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
422 };
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
423
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
424 static int open(vf_instance_t *vf, char* args){
83032783f65d noise generating filter
michael
parents:
diff changeset
425 vf->config=config;
83032783f65d noise generating filter
michael
parents:
diff changeset
426 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
427 vf->get_image=get_image;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
428 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
429 vf->uninit=uninit;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
430 vf->priv=malloc(sizeof(struct vf_priv_s));
83032783f65d noise generating filter
michael
parents:
diff changeset
431 memset(vf->priv, 0, sizeof(struct vf_priv_s));
83032783f65d noise generating filter
michael
parents:
diff changeset
432 if(args)
83032783f65d noise generating filter
michael
parents:
diff changeset
433 {
83032783f65d noise generating filter
michael
parents:
diff changeset
434 char *arg2= strchr(args,':');
83032783f65d noise generating filter
michael
parents:
diff changeset
435 if(arg2) parse(&vf->priv->chromaParam, arg2+1);
83032783f65d noise generating filter
michael
parents:
diff changeset
436 parse(&vf->priv->lumaParam, args);
83032783f65d noise generating filter
michael
parents:
diff changeset
437 }
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
438
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 // 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
440 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
441 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
442 {
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 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
444 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
445 }
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
446
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
447
83032783f65d noise generating filter
michael
parents:
diff changeset
448 #ifdef HAVE_MMX
6966
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
449 if(gCpuCaps.hasMMX){
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
450 lineNoise= lineNoise_MMX;
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
451 lineNoiseAvg= lineNoiseAvg_MMX;
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
452 }
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
453 #endif
83032783f65d noise generating filter
michael
parents:
diff changeset
454 #ifdef HAVE_MMX2
83032783f65d noise generating filter
michael
parents:
diff changeset
455 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
456 // if(gCpuCaps.hasMMX) lineNoiseAvg= lineNoiseAvg_MMX2;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
457 #endif
83032783f65d noise generating filter
michael
parents:
diff changeset
458
83032783f65d noise generating filter
michael
parents:
diff changeset
459 return 1;
83032783f65d noise generating filter
michael
parents:
diff changeset
460 }
83032783f65d noise generating filter
michael
parents:
diff changeset
461
83032783f65d noise generating filter
michael
parents:
diff changeset
462 vf_info_t vf_info_noise = {
83032783f65d noise generating filter
michael
parents:
diff changeset
463 "noise genenerator",
83032783f65d noise generating filter
michael
parents:
diff changeset
464 "noise",
83032783f65d noise generating filter
michael
parents:
diff changeset
465 "Michael Niedermayer",
83032783f65d noise generating filter
michael
parents:
diff changeset
466 "",
83032783f65d noise generating filter
michael
parents:
diff changeset
467 open
83032783f65d noise generating filter
michael
parents:
diff changeset
468 };
83032783f65d noise generating filter
michael
parents:
diff changeset
469
83032783f65d noise generating filter
michael
parents:
diff changeset
470 //===========================================================================//