annotate libmpcodecs/vf_noise.c @ 27706:8dec0335f75b

Replace numeric constants by their defines. Fixes icc warning #188: enumerated type mixed with another type
author cehoyos
date Thu, 09 Oct 2008 17:08:47 +0000
parents 82601a38e2a7
children 08d18fe9da52
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
1 /*
26727
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
2 * Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
3 *
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
4 * This file is part of MPlayer.
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
5 *
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
6 * MPlayer is free software; you can redistribute it and/or modify
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
7 * it under the terms of the GNU General Public License as published by
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
9 * (at your option) any later version.
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
10 *
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
11 * MPlayer is distributed in the hope that it will be useful,
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
14 * GNU General Public License for more details.
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
15 *
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
16 * You should have received a copy of the GNU General Public License along
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
19 */
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
20
83032783f65d noise generating filter
michael
parents:
diff changeset
21 #include <stdio.h>
83032783f65d noise generating filter
michael
parents:
diff changeset
22 #include <stdlib.h>
83032783f65d noise generating filter
michael
parents:
diff changeset
23 #include <string.h>
83032783f65d noise generating filter
michael
parents:
diff changeset
24 #include <inttypes.h>
83032783f65d noise generating filter
michael
parents:
diff changeset
25 #include <math.h>
83032783f65d noise generating filter
michael
parents:
diff changeset
26
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 13720
diff changeset
27 #include "config.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 13720
diff changeset
28 #include "mp_msg.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 13720
diff changeset
29 #include "cpudetect.h"
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
30
83032783f65d noise generating filter
michael
parents:
diff changeset
31 #ifdef HAVE_MALLOC_H
83032783f65d noise generating filter
michael
parents:
diff changeset
32 #include <malloc.h>
83032783f65d noise generating filter
michael
parents:
diff changeset
33 #endif
83032783f65d noise generating filter
michael
parents:
diff changeset
34
83032783f65d noise generating filter
michael
parents:
diff changeset
35 #include "img_format.h"
83032783f65d noise generating filter
michael
parents:
diff changeset
36 #include "mp_image.h"
83032783f65d noise generating filter
michael
parents:
diff changeset
37 #include "vf.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 13720
diff changeset
38 #include "libvo/fastmemcpy.h"
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
39
83032783f65d noise generating filter
michael
parents:
diff changeset
40 #define MAX_NOISE 4096
83032783f65d noise generating filter
michael
parents:
diff changeset
41 #define MAX_SHIFT 1024
83032783f65d noise generating filter
michael
parents:
diff changeset
42 #define MAX_RES (MAX_NOISE-MAX_SHIFT)
83032783f65d noise generating filter
michael
parents:
diff changeset
43
83032783f65d noise generating filter
michael
parents:
diff changeset
44 //===========================================================================//
83032783f65d noise generating filter
michael
parents:
diff changeset
45
83032783f65d noise generating filter
michael
parents:
diff changeset
46 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
47 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
48
83032783f65d noise generating filter
michael
parents:
diff changeset
49 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
50 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
51
83032783f65d noise generating filter
michael
parents:
diff changeset
52 typedef struct FilterParam{
83032783f65d noise generating filter
michael
parents:
diff changeset
53 int strength;
83032783f65d noise generating filter
michael
parents:
diff changeset
54 int uniform;
83032783f65d noise generating filter
michael
parents:
diff changeset
55 int temporal;
6448
e10e3264c19c higher quality mode
michael
parents: 6447
diff changeset
56 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
57 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
58 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
59 int shiftptr;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
60 int8_t *noise;
6964
f35d05c32dd1 film/average noise cleanup
michael
parents: 6963
diff changeset
61 int8_t *prev_shift[MAX_RES][3];
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
62 }FilterParam;
83032783f65d noise generating filter
michael
parents:
diff changeset
63
83032783f65d noise generating filter
michael
parents:
diff changeset
64 struct vf_priv_s {
83032783f65d noise generating filter
michael
parents:
diff changeset
65 FilterParam lumaParam;
83032783f65d noise generating filter
michael
parents:
diff changeset
66 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
67 unsigned int outfmt;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
68 };
83032783f65d noise generating filter
michael
parents:
diff changeset
69
18030
ec68026bc1d0 move 12k from data to bss (reduce binary size by 12k)
rfelker
parents: 17906
diff changeset
70 static int nonTempRandShift_init;
ec68026bc1d0 move 12k from data to bss (reduce binary size by 12k)
rfelker
parents: 17906
diff changeset
71 static int nonTempRandShift[MAX_RES];
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
72
6990
857bae3001e8 semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents: 6966
diff changeset
73 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
74 -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
75 };
857bae3001e8 semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents: 6966
diff changeset
76
857bae3001e8 semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents: 6966
diff changeset
77 #define RAND_N(range) ((int) ((double)range*rand()/(RAND_MAX+1.0)))
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
78 static int8_t *initNoise(FilterParam *fp){
83032783f65d noise generating filter
michael
parents:
diff changeset
79 int strength= fp->strength;
83032783f65d noise generating filter
michael
parents:
diff changeset
80 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
81 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
82 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
83 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
84 int i, j;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
85
83032783f65d noise generating filter
michael
parents:
diff changeset
86 srand(123457);
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 for(i=0,j=0; i<MAX_NOISE; i++,j++)
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
89 {
6990
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(uniform) {
857bae3001e8 semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents: 6966
diff changeset
91 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
92 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
93 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
94 +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
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 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
97 }
857bae3001e8 semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents: 6966
diff changeset
98 } else {
857bae3001e8 semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents: 6966
diff changeset
99 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
100 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
101 + 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
102 } else {
857bae3001e8 semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents: 6966
diff changeset
103 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
104 }
857bae3001e8 semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents: 6966
diff changeset
105 }
857bae3001e8 semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents: 6966
diff changeset
106 } else {
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
107 double x1, x2, w, y1;
83032783f65d noise generating filter
michael
parents:
diff changeset
108 do {
83032783f65d noise generating filter
michael
parents:
diff changeset
109 x1 = 2.0 * rand()/(float)RAND_MAX - 1.0;
83032783f65d noise generating filter
michael
parents:
diff changeset
110 x2 = 2.0 * rand()/(float)RAND_MAX - 1.0;
83032783f65d noise generating filter
michael
parents:
diff changeset
111 w = x1 * x1 + x2 * x2;
83032783f65d noise generating filter
michael
parents:
diff changeset
112 } 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
113
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
114 w = sqrt( (-2.0 * log( w ) ) / w );
83032783f65d noise generating filter
michael
parents:
diff changeset
115 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
116 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
117 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
118 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
119 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
120 }
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
121 if (y1<-128) y1=-128;
83032783f65d noise generating filter
michael
parents:
diff changeset
122 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
123 if (averaged) y1 /= 3.0;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
124 noise[i]= (int)y1;
83032783f65d noise generating filter
michael
parents:
diff changeset
125 }
6990
857bae3001e8 semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
michael
parents: 6966
diff changeset
126 if (RAND_N(6) == 0) j--;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
127 }
6963
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
128
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
129
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
130 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
131 for (j = 0; j < 3; j++)
6964
f35d05c32dd1 film/average noise cleanup
michael
parents: 6963
diff changeset
132 fp->prev_shift[i][j] = noise + (rand()&(MAX_SHIFT-1));
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
133
18030
ec68026bc1d0 move 12k from data to bss (reduce binary size by 12k)
rfelker
parents: 17906
diff changeset
134 if(!nonTempRandShift_init){
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
135 for(i=0; i<MAX_RES; i++){
83032783f65d noise generating filter
michael
parents:
diff changeset
136 nonTempRandShift[i]= rand()&(MAX_SHIFT-1);
83032783f65d noise generating filter
michael
parents:
diff changeset
137 }
18030
ec68026bc1d0 move 12k from data to bss (reduce binary size by 12k)
rfelker
parents: 17906
diff changeset
138 nonTempRandShift_init = 1;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
139 }
83032783f65d noise generating filter
michael
parents:
diff changeset
140
83032783f65d noise generating filter
michael
parents:
diff changeset
141 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
142 fp->shiftptr= 0;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
143 return noise;
83032783f65d noise generating filter
michael
parents:
diff changeset
144 }
83032783f65d noise generating filter
michael
parents:
diff changeset
145
6963
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
146 /***************************************************************************/
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
147
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
148 #ifdef HAVE_MMX
83032783f65d noise generating filter
michael
parents:
diff changeset
149 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
150 long mmx_len= len&(~7);
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
151 noise+=shift;
83032783f65d noise generating filter
michael
parents:
diff changeset
152
83032783f65d noise generating filter
michael
parents:
diff changeset
153 asm volatile(
13720
821f464b4d90 adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents: 10141
diff changeset
154 "mov %3, %%"REG_a" \n\t"
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
155 "pcmpeqb %%mm7, %%mm7 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
156 "psllw $15, %%mm7 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
157 "packsswb %%mm7, %%mm7 \n\t"
19372
6334c14b38eb Replace asmalign.h hack by ASMALIGN cpp macros from config.h.
diego
parents: 18684
diff changeset
158 ASMALIGN(4)
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
159 "1: \n\t"
13720
821f464b4d90 adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents: 10141
diff changeset
160 "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
161 "movq (%1, %%"REG_a"), %%mm1 \n\t"
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
162 "pxor %%mm7, %%mm0 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
163 "paddsb %%mm1, %%mm0 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
164 "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
165 "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
166 "add $8, %%"REG_a" \n\t"
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
167 " js 1b \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
168 :: "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
169 : "%"REG_a
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
170 );
83032783f65d noise generating filter
michael
parents:
diff changeset
171 if(mmx_len!=len)
83032783f65d noise generating filter
michael
parents:
diff changeset
172 lineNoise_C(dst+mmx_len, src+mmx_len, noise+mmx_len, len-mmx_len, 0);
83032783f65d noise generating filter
michael
parents:
diff changeset
173 }
83032783f65d noise generating filter
michael
parents:
diff changeset
174 #endif
83032783f65d noise generating filter
michael
parents:
diff changeset
175
83032783f65d noise generating filter
michael
parents:
diff changeset
176 //duplicate of previous except movntq
83032783f65d noise generating filter
michael
parents:
diff changeset
177 #ifdef HAVE_MMX2
83032783f65d noise generating filter
michael
parents:
diff changeset
178 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
179 long mmx_len= len&(~7);
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
180 noise+=shift;
83032783f65d noise generating filter
michael
parents:
diff changeset
181
83032783f65d noise generating filter
michael
parents:
diff changeset
182 asm volatile(
13720
821f464b4d90 adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents: 10141
diff changeset
183 "mov %3, %%"REG_a" \n\t"
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
184 "pcmpeqb %%mm7, %%mm7 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
185 "psllw $15, %%mm7 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
186 "packsswb %%mm7, %%mm7 \n\t"
19372
6334c14b38eb Replace asmalign.h hack by ASMALIGN cpp macros from config.h.
diego
parents: 18684
diff changeset
187 ASMALIGN(4)
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
188 "1: \n\t"
13720
821f464b4d90 adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents: 10141
diff changeset
189 "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
190 "movq (%1, %%"REG_a"), %%mm1 \n\t"
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
191 "pxor %%mm7, %%mm0 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
192 "paddsb %%mm1, %%mm0 \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
193 "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
194 "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
195 "add $8, %%"REG_a" \n\t"
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
196 " js 1b \n\t"
83032783f65d noise generating filter
michael
parents:
diff changeset
197 :: "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
198 : "%"REG_a
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
199 );
83032783f65d noise generating filter
michael
parents:
diff changeset
200 if(mmx_len!=len)
83032783f65d noise generating filter
michael
parents:
diff changeset
201 lineNoise_C(dst+mmx_len, src+mmx_len, noise+mmx_len, len-mmx_len, 0);
83032783f65d noise generating filter
michael
parents:
diff changeset
202 }
83032783f65d noise generating filter
michael
parents:
diff changeset
203 #endif
83032783f65d noise generating filter
michael
parents:
diff changeset
204
83032783f65d noise generating filter
michael
parents:
diff changeset
205 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
206 int i;
83032783f65d noise generating filter
michael
parents:
diff changeset
207 noise+= shift;
83032783f65d noise generating filter
michael
parents:
diff changeset
208 for(i=0; i<len; i++)
83032783f65d noise generating filter
michael
parents:
diff changeset
209 {
83032783f65d noise generating filter
michael
parents:
diff changeset
210 int v= src[i]+ noise[i];
83032783f65d noise generating filter
michael
parents:
diff changeset
211 if(v>255) dst[i]=255; //FIXME optimize
83032783f65d noise generating filter
michael
parents:
diff changeset
212 else if(v<0) dst[i]=0;
83032783f65d noise generating filter
michael
parents:
diff changeset
213 else dst[i]=v;
83032783f65d noise generating filter
michael
parents:
diff changeset
214 }
83032783f65d noise generating filter
michael
parents:
diff changeset
215 }
83032783f65d noise generating filter
michael
parents:
diff changeset
216
6963
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
217 /***************************************************************************/
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
218
6966
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
219 #ifdef HAVE_MMX
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
220 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
221 long mmx_len= len&(~7);
6966
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
222
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
223 asm volatile(
13720
821f464b4d90 adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents: 10141
diff changeset
224 "mov %5, %%"REG_a" \n\t"
19372
6334c14b38eb Replace asmalign.h hack by ASMALIGN cpp macros from config.h.
diego
parents: 18684
diff changeset
225 ASMALIGN(4)
6966
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
226 "1: \n\t"
13720
821f464b4d90 adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents: 10141
diff changeset
227 "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
228 "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
229 "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
230 "paddb (%3, %%"REG_a"), %%mm1 \n\t"
6966
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
231 "movq %%mm0, %%mm2 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
232 "movq %%mm1, %%mm3 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
233 "punpcklbw %%mm0, %%mm0 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
234 "punpckhbw %%mm2, %%mm2 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
235 "punpcklbw %%mm1, %%mm1 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
236 "punpckhbw %%mm3, %%mm3 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
237 "pmulhw %%mm0, %%mm1 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
238 "pmulhw %%mm2, %%mm3 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
239 "paddw %%mm1, %%mm1 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
240 "paddw %%mm3, %%mm3 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
241 "paddw %%mm0, %%mm1 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
242 "paddw %%mm2, %%mm3 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
243 "psrlw $8, %%mm1 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
244 "psrlw $8, %%mm3 \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
245 "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
246 "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
247 "add $8, %%"REG_a" \n\t"
6966
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
248 " js 1b \n\t"
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
249 :: "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
250 "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
251 : "%"REG_a
6966
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
252 );
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
253
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
254 if(mmx_len!=len){
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
255 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
256 lineNoiseAvg_C(dst+mmx_len, src+mmx_len, len-mmx_len, shift2);
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
257 }
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
258 }
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
259 #endif
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
260
6963
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
261 static inline void lineNoiseAvg_C(uint8_t *dst, uint8_t *src, int len, int8_t **shift){
6965
f8ea0af8edb0 optimization
michael
parents: 6964
diff changeset
262 int i;
f8ea0af8edb0 optimization
michael
parents: 6964
diff changeset
263 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
264
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
265 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
266 {
6965
f8ea0af8edb0 optimization
michael
parents: 6964
diff changeset
267 const int n= shift[0][i] + shift[1][i] + shift[2][i];
f8ea0af8edb0 optimization
michael
parents: 6964
diff changeset
268 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
269 }
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
270 }
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
271
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
272 /***************************************************************************/
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
273
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
274 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
275 int8_t *noise= fp->noise;
83032783f65d noise generating filter
michael
parents:
diff changeset
276 int y;
83032783f65d noise generating filter
michael
parents:
diff changeset
277 int shift=0;
83032783f65d noise generating filter
michael
parents:
diff changeset
278
83032783f65d noise generating filter
michael
parents:
diff changeset
279 if(!noise)
83032783f65d noise generating filter
michael
parents:
diff changeset
280 {
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
281 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
282
23457
a124f3abc1ec Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents: 19372
diff changeset
283 if(dstStride==srcStride) fast_memcpy(dst, src, srcStride*height);
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
284 else
83032783f65d noise generating filter
michael
parents:
diff changeset
285 {
83032783f65d noise generating filter
michael
parents:
diff changeset
286 for(y=0; y<height; y++)
83032783f65d noise generating filter
michael
parents:
diff changeset
287 {
23457
a124f3abc1ec Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents: 19372
diff changeset
288 fast_memcpy(dst, src, width);
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
289 dst+= dstStride;
6448
e10e3264c19c higher quality mode
michael
parents: 6447
diff changeset
290 src+= srcStride;
6424
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 return;
83032783f65d noise generating filter
michael
parents:
diff changeset
294 }
83032783f65d noise generating filter
michael
parents:
diff changeset
295
83032783f65d noise generating filter
michael
parents:
diff changeset
296 for(y=0; y<height; y++)
83032783f65d noise generating filter
michael
parents:
diff changeset
297 {
83032783f65d noise generating filter
michael
parents:
diff changeset
298 if(fp->temporal) shift= rand()&(MAX_SHIFT -1);
83032783f65d noise generating filter
michael
parents:
diff changeset
299 else shift= nonTempRandShift[y];
83032783f65d noise generating filter
michael
parents:
diff changeset
300
6448
e10e3264c19c higher quality mode
michael
parents: 6447
diff changeset
301 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
302 if (fp->averaged) {
6964
f35d05c32dd1 film/average noise cleanup
michael
parents: 6963
diff changeset
303 lineNoiseAvg(dst, src, width, fp->prev_shift[y]);
f35d05c32dd1 film/average noise cleanup
michael
parents: 6963
diff changeset
304 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
305 } else {
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
306 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
307 }
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
308 dst+= dstStride;
83032783f65d noise generating filter
michael
parents:
diff changeset
309 src+= srcStride;
83032783f65d noise generating filter
michael
parents:
diff changeset
310 }
6963
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
311 fp->shiftptr++;
76fee64d884a film/average noise patch by (Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>)
michael
parents: 6962
diff changeset
312 if (fp->shiftptr == 3) fp->shiftptr = 0;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
313 }
83032783f65d noise generating filter
michael
parents:
diff changeset
314
83032783f65d noise generating filter
michael
parents:
diff changeset
315 static int config(struct vf_instance_s* vf,
83032783f65d noise generating filter
michael
parents:
diff changeset
316 int width, int height, int d_width, int d_height,
83032783f65d noise generating filter
michael
parents:
diff changeset
317 unsigned int flags, unsigned int outfmt){
6448
e10e3264c19c higher quality mode
michael
parents: 6447
diff changeset
318
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
319 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
83032783f65d noise generating filter
michael
parents:
diff changeset
320 }
83032783f65d noise generating filter
michael
parents:
diff changeset
321
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 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
323 if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
6962
ba721168ed24 oops forgot to commit that
michael
parents: 6448
diff changeset
324 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
325 // 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
326 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
327 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
328 mpi->planes[0]=vf->dmpi->planes[0];
7d6a854a5fe5 cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents: 9934
diff changeset
329 mpi->stride[0]=vf->dmpi->stride[0];
7d6a854a5fe5 cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents: 9934
diff changeset
330 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
331 if(mpi->flags&MP_IMGFLAG_PLANAR){
10141
7d6a854a5fe5 cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents: 9934
diff changeset
332 mpi->planes[1]=vf->dmpi->planes[1];
7d6a854a5fe5 cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents: 9934
diff changeset
333 mpi->planes[2]=vf->dmpi->planes[2];
7d6a854a5fe5 cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents: 9934
diff changeset
334 mpi->stride[1]=vf->dmpi->stride[1];
7d6a854a5fe5 cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents: 9934
diff changeset
335 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
336 }
751a5775ac35 direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
michael
parents: 6424
diff changeset
337 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
338 }
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
17906
20aca9baf5d8 passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents: 17367
diff changeset
340 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
341 mp_image_t *dmpi;
83032783f65d noise generating filter
michael
parents:
diff changeset
342
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 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
344 // 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
345 vf->dmpi=vf_get_image(vf->next,vf->priv->outfmt,
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
346 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
347 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
348 //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
349 }
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
350 //else printf("dr\n");
10141
7d6a854a5fe5 cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents: 9934
diff changeset
351 dmpi= vf->dmpi;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
352
83032783f65d noise generating filter
michael
parents:
diff changeset
353 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
354 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
355 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
356
9934
89da8ec89558 vf_clone_mpi_attributes()
michael
parents: 9593
diff changeset
357 vf_clone_mpi_attributes(dmpi, mpi);
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
358
83032783f65d noise generating filter
michael
parents:
diff changeset
359 #ifdef HAVE_MMX
83032783f65d noise generating filter
michael
parents:
diff changeset
360 if(gCpuCaps.hasMMX) asm volatile ("emms\n\t");
83032783f65d noise generating filter
michael
parents:
diff changeset
361 #endif
83032783f65d noise generating filter
michael
parents:
diff changeset
362 #ifdef HAVE_MMX2
83032783f65d noise generating filter
michael
parents:
diff changeset
363 if(gCpuCaps.hasMMX2) asm volatile ("sfence\n\t");
83032783f65d noise generating filter
michael
parents:
diff changeset
364 #endif
83032783f65d noise generating filter
michael
parents:
diff changeset
365
17906
20aca9baf5d8 passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents: 17367
diff changeset
366 return vf_next_put_image(vf,dmpi, pts);
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
367 }
83032783f65d noise generating filter
michael
parents:
diff changeset
368
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
369 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
370 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
371
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 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
373 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
374
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 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
376 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
377
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 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
379 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
380 }
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
381
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
382 //===========================================================================//
83032783f65d noise generating filter
michael
parents:
diff changeset
383
83032783f65d noise generating filter
michael
parents:
diff changeset
384 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
83032783f65d noise generating filter
michael
parents:
diff changeset
385 switch(fmt)
83032783f65d noise generating filter
michael
parents:
diff changeset
386 {
83032783f65d noise generating filter
michael
parents:
diff changeset
387 case IMGFMT_YV12:
83032783f65d noise generating filter
michael
parents:
diff changeset
388 case IMGFMT_I420:
83032783f65d noise generating filter
michael
parents:
diff changeset
389 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
390 return vf_next_query_format(vf,vf->priv->outfmt);
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
391 }
83032783f65d noise generating filter
michael
parents:
diff changeset
392 return 0;
83032783f65d noise generating filter
michael
parents:
diff changeset
393 }
83032783f65d noise generating filter
michael
parents:
diff changeset
394
83032783f65d noise generating filter
michael
parents:
diff changeset
395 static void parse(FilterParam *fp, char* args){
83032783f65d noise generating filter
michael
parents:
diff changeset
396 char *pos;
83032783f65d noise generating filter
michael
parents:
diff changeset
397 char *max= strchr(args, ':');
83032783f65d noise generating filter
michael
parents:
diff changeset
398
83032783f65d noise generating filter
michael
parents:
diff changeset
399 if(!max) max= args + strlen(args);
83032783f65d noise generating filter
michael
parents:
diff changeset
400
83032783f65d noise generating filter
michael
parents:
diff changeset
401 fp->strength= atoi(args);
83032783f65d noise generating filter
michael
parents:
diff changeset
402 pos= strchr(args, 'u');
83032783f65d noise generating filter
michael
parents:
diff changeset
403 if(pos && pos<max) fp->uniform=1;
83032783f65d noise generating filter
michael
parents:
diff changeset
404 pos= strchr(args, 't');
83032783f65d noise generating filter
michael
parents:
diff changeset
405 if(pos && pos<max) fp->temporal=1;
6448
e10e3264c19c higher quality mode
michael
parents: 6447
diff changeset
406 pos= strchr(args, 'h');
e10e3264c19c higher quality mode
michael
parents: 6447
diff changeset
407 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
408 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
409 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
410 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
411 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
412 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
413 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
414 }
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
415
83032783f65d noise generating filter
michael
parents:
diff changeset
416 if(fp->strength) initNoise(fp);
83032783f65d noise generating filter
michael
parents:
diff changeset
417 }
83032783f65d noise generating filter
michael
parents:
diff changeset
418
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
419 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
420 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
421 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
422 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
423 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
424 };
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
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
426 static int open(vf_instance_t *vf, char* args){
83032783f65d noise generating filter
michael
parents:
diff changeset
427 vf->config=config;
83032783f65d noise generating filter
michael
parents:
diff changeset
428 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
429 vf->get_image=get_image;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
430 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
431 vf->uninit=uninit;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
432 vf->priv=malloc(sizeof(struct vf_priv_s));
83032783f65d noise generating filter
michael
parents:
diff changeset
433 memset(vf->priv, 0, sizeof(struct vf_priv_s));
83032783f65d noise generating filter
michael
parents:
diff changeset
434 if(args)
83032783f65d noise generating filter
michael
parents:
diff changeset
435 {
83032783f65d noise generating filter
michael
parents:
diff changeset
436 char *arg2= strchr(args,':');
83032783f65d noise generating filter
michael
parents:
diff changeset
437 if(arg2) parse(&vf->priv->chromaParam, arg2+1);
83032783f65d noise generating filter
michael
parents:
diff changeset
438 parse(&vf->priv->lumaParam, args);
83032783f65d noise generating filter
michael
parents:
diff changeset
439 }
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
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 // 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
442 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
443 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
444 {
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 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
446 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
447 }
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
448
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
449
83032783f65d noise generating filter
michael
parents:
diff changeset
450 #ifdef HAVE_MMX
6966
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
451 if(gCpuCaps.hasMMX){
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
452 lineNoise= lineNoise_MMX;
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
453 lineNoiseAvg= lineNoiseAvg_MMX;
2994bd73f35d mmx optimized avg/film noise
michael
parents: 6965
diff changeset
454 }
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
455 #endif
83032783f65d noise generating filter
michael
parents:
diff changeset
456 #ifdef HAVE_MMX2
83032783f65d noise generating filter
michael
parents:
diff changeset
457 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
458 // if(gCpuCaps.hasMMX) lineNoiseAvg= lineNoiseAvg_MMX2;
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
459 #endif
83032783f65d noise generating filter
michael
parents:
diff changeset
460
83032783f65d noise generating filter
michael
parents:
diff changeset
461 return 1;
83032783f65d noise generating filter
michael
parents:
diff changeset
462 }
83032783f65d noise generating filter
michael
parents:
diff changeset
463
25221
00fff9a3b735 Make all vf_info_t structs const
reimar
parents: 23457
diff changeset
464 const vf_info_t vf_info_noise = {
18684
c9de3673e299 typo noticed by Alexander Monakov monoid$$at$$fds-net$$dot$$ru
diego
parents: 18104
diff changeset
465 "noise generator",
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
466 "noise",
83032783f65d noise generating filter
michael
parents:
diff changeset
467 "Michael Niedermayer",
83032783f65d noise generating filter
michael
parents:
diff changeset
468 "",
9593
e9a2af584986 Add the new -vf option wich is the same as vop in reverse order.
albeu
parents: 7368
diff changeset
469 open,
e9a2af584986 Add the new -vf option wich is the same as vop in reverse order.
albeu
parents: 7368
diff changeset
470 NULL
6424
83032783f65d noise generating filter
michael
parents:
diff changeset
471 };
83032783f65d noise generating filter
michael
parents:
diff changeset
472
83032783f65d noise generating filter
michael
parents:
diff changeset
473 //===========================================================================//