comparison libmpcodecs/vf_noise.c @ 6990:857bae3001e8

semi regular noise pattern patch by (Jindrich Makovicka <makovick at kmlinux dot fjfi dot cvut dot cz>)
author michael
date Tue, 13 Aug 2002 17:53:32 +0000
parents 2994bd73f35d
children a894e99c1e51
comparison
equal deleted inserted replaced
6989:b2ba67f6203e 6990:857bae3001e8
51 int strength; 51 int strength;
52 int uniform; 52 int uniform;
53 int temporal; 53 int temporal;
54 int quality; 54 int quality;
55 int averaged; 55 int averaged;
56 int pattern;
56 int shiftptr; 57 int shiftptr;
57 int8_t *noise; 58 int8_t *noise;
58 int8_t *prev_shift[MAX_RES][3]; 59 int8_t *prev_shift[MAX_RES][3];
59 }FilterParam; 60 }FilterParam;
60 61
65 unsigned int outfmt; 66 unsigned int outfmt;
66 }; 67 };
67 68
68 static int nonTempRandShift[MAX_RES]= {-1}; 69 static int nonTempRandShift[MAX_RES]= {-1};
69 70
71 static int patt[4] = {
72 -1,0,1,0
73 };
74
75 #define RAND_N(range) ((int) ((double)range*rand()/(RAND_MAX+1.0)))
70 static int8_t *initNoise(FilterParam *fp){ 76 static int8_t *initNoise(FilterParam *fp){
71 int strength= fp->strength; 77 int strength= fp->strength;
72 int uniform= fp->uniform; 78 int uniform= fp->uniform;
73 int averaged= fp->averaged; 79 int averaged= fp->averaged;
80 int pattern= fp->pattern;
74 int8_t *noise= memalign(16, MAX_NOISE*sizeof(int8_t)); 81 int8_t *noise= memalign(16, MAX_NOISE*sizeof(int8_t));
75 int i, j; 82 int i, j;
76 83
77 srand(123457); 84 srand(123457);
78 85
79 for(i=0; i<MAX_NOISE; i++) 86 for(i=0,j=0; i<MAX_NOISE; i++,j++)
80 { 87 {
81 if(uniform) { 88 if(uniform) {
82 if (averaged) { 89 if (averaged) {
83 noise[i]= (((rand()/11)%strength) - strength/2)/3; 90 if (pattern) {
84 } else { 91 noise[i]= (RAND_N(strength) - strength/2)/6
85 noise[i]= ((rand()/11)%strength) - strength/2; 92 +patt[j%4]*strength*0.25/3;
86 } 93 } else {
87 } else { 94 noise[i]= (RAND_N(strength) - strength/2)/3;
95 }
96 } else {
97 if (pattern) {
98 noise[i]= (RAND_N(strength) - strength/2)/2
99 + patt[j%4]*strength*0.25;
100 } else {
101 noise[i]= RAND_N(strength) - strength/2;
102 }
103 }
104 } else {
88 double x1, x2, w, y1; 105 double x1, x2, w, y1;
89 do { 106 do {
90 x1 = 2.0 * rand()/(float)RAND_MAX - 1.0; 107 x1 = 2.0 * rand()/(float)RAND_MAX - 1.0;
91 x2 = 2.0 * rand()/(float)RAND_MAX - 1.0; 108 x2 = 2.0 * rand()/(float)RAND_MAX - 1.0;
92 w = x1 * x1 + x2 * x2; 109 w = x1 * x1 + x2 * x2;
93 } while ( w >= 1.0 ); 110 } while ( w >= 1.0 );
94 111
95 w = sqrt( (-2.0 * log( w ) ) / w ); 112 w = sqrt( (-2.0 * log( w ) ) / w );
96 y1= x1 * w; 113 y1= x1 * w;
97
98 y1*= strength / sqrt(3.0); 114 y1*= strength / sqrt(3.0);
115 if (pattern) {
116 y1 /= 2;
117 y1 += patt[j%4]*strength*0.35;
118 }
99 if (y1<-128) y1=-128; 119 if (y1<-128) y1=-128;
100 else if(y1> 127) y1= 127; 120 else if(y1> 127) y1= 127;
101 if (averaged) y1 /= 3.0; 121 if (averaged) y1 /= 3.0;
102 noise[i]= (int)y1; 122 noise[i]= (int)y1;
103 } 123 }
124 if (RAND_N(6) == 0) j--;
104 } 125 }
105 126
106 127
107 for (i = 0; i < MAX_RES; i++) 128 for (i = 0; i < MAX_RES; i++)
108 for (j = 0; j < 3; j++) 129 for (j = 0; j < 3; j++)
380 if(pos && pos<max) fp->uniform=1; 401 if(pos && pos<max) fp->uniform=1;
381 pos= strchr(args, 't'); 402 pos= strchr(args, 't');
382 if(pos && pos<max) fp->temporal=1; 403 if(pos && pos<max) fp->temporal=1;
383 pos= strchr(args, 'h'); 404 pos= strchr(args, 'h');
384 if(pos && pos<max) fp->quality=1; 405 if(pos && pos<max) fp->quality=1;
406 pos= strchr(args, 'p');
407 if(pos && pos<max) fp->pattern=1;
385 pos= strchr(args, 'a'); 408 pos= strchr(args, 'a');
386 if(pos && pos<max) { 409 if(pos && pos<max) {
387 fp->temporal=1; 410 fp->temporal=1;
388 fp->averaged=1; 411 fp->averaged=1;
389 } 412 }