comparison libmpcodecs/vf_hqdn3d.c @ 17965:a1dc210f20b3

use shifts instead of division. 15% faster hqdn3d
author lorenm
date Sun, 26 Mar 2006 21:32:52 +0000
parents 20aca9baf5d8
children f8d4f8eff72b
comparison
equal deleted inserted replaced
17964:2a85c470cbd0 17965:a1dc210f20b3
67 } 67 }
68 68
69 static inline unsigned int LowPassMul(unsigned int PrevMul, unsigned int CurrMul, int* Coef){ 69 static inline unsigned int LowPassMul(unsigned int PrevMul, unsigned int CurrMul, int* Coef){
70 // int dMul= (PrevMul&0xFFFFFF)-(CurrMul&0xFFFFFF); 70 // int dMul= (PrevMul&0xFFFFFF)-(CurrMul&0xFFFFFF);
71 int dMul= PrevMul-CurrMul; 71 int dMul= PrevMul-CurrMul;
72 int d=((dMul+0x10007FF)/(65536/16)); 72 int d=((dMul+0x10007FF)>>12);
73 return CurrMul + Coef[d]; 73 return CurrMul + Coef[d];
74 } 74 }
75 75
76 static void deNoiseTemporal( 76 static void deNoiseTemporal(
77 unsigned char *Frame, // mpi->planes[x] 77 unsigned char *Frame, // mpi->planes[x]
79 unsigned short *FrameAnt, 79 unsigned short *FrameAnt,
80 int W, int H, int sStride, int dStride, 80 int W, int H, int sStride, int dStride,
81 int *Temporal) 81 int *Temporal)
82 { 82 {
83 int X, Y; 83 int X, Y;
84 int PixelDst; 84 unsigned int PixelDst;
85 85
86 for (Y = 0; Y < H; Y++){ 86 for (Y = 0; Y < H; Y++){
87 for (X = 0; X < W; X++){ 87 for (X = 0; X < W; X++){
88 PixelDst = LowPassMul(FrameAnt[X]<<8, Frame[X]<<16, Temporal); 88 PixelDst = LowPassMul(FrameAnt[X]<<8, Frame[X]<<16, Temporal);
89 FrameAnt[X] = ((PixelDst+0x1000007F)/256); 89 FrameAnt[X] = ((PixelDst+0x1000007F)>>8);
90 FrameDest[X]= ((PixelDst+0x10007FFF)/65536); 90 FrameDest[X]= ((PixelDst+0x10007FFF)>>16);
91 } 91 }
92 Frame += sStride; 92 Frame += sStride;
93 FrameDest += dStride; 93 FrameDest += dStride;
94 FrameAnt += W; 94 FrameAnt += W;
95 } 95 }
103 int *Horizontal, int *Vertical) 103 int *Horizontal, int *Vertical)
104 { 104 {
105 int X, Y; 105 int X, Y;
106 int sLineOffs = 0, dLineOffs = 0; 106 int sLineOffs = 0, dLineOffs = 0;
107 unsigned int PixelAnt; 107 unsigned int PixelAnt;
108 int PixelDst; 108 unsigned int PixelDst;
109 109
110 /* First pixel has no left nor top neighbor. */ 110 /* First pixel has no left nor top neighbor. */
111 PixelDst = LineAnt[0] = PixelAnt = Frame[0]<<16; 111 PixelDst = LineAnt[0] = PixelAnt = Frame[0]<<16;
112 FrameDest[0]= ((PixelDst+0x10007FFF)/65536); 112 FrameDest[0]= ((PixelDst+0x10007FFF)>>16);
113 113
114 /* First line has no top neighbor, only left. */ 114 /* First line has no top neighbor, only left. */
115 for (X = 1; X < W; X++){ 115 for (X = 1; X < W; X++){
116 PixelDst = LineAnt[X] = LowPassMul(PixelAnt, Frame[X]<<16, Horizontal); 116 PixelDst = LineAnt[X] = LowPassMul(PixelAnt, Frame[X]<<16, Horizontal);
117 FrameDest[X]= ((PixelDst+0x10007FFF)/65536); 117 FrameDest[X]= ((PixelDst+0x10007FFF)>>16);
118 } 118 }
119 119
120 for (Y = 1; Y < H; Y++){ 120 for (Y = 1; Y < H; Y++){
121 unsigned int PixelAnt; 121 unsigned int PixelAnt;
122 sLineOffs += sStride, dLineOffs += dStride; 122 sLineOffs += sStride, dLineOffs += dStride;
123 /* First pixel on each line doesn't have previous pixel */ 123 /* First pixel on each line doesn't have previous pixel */
124 PixelAnt = Frame[sLineOffs]<<16; 124 PixelAnt = Frame[sLineOffs]<<16;
125 PixelDst = LineAnt[0] = LowPassMul(LineAnt[0], PixelAnt, Vertical); 125 PixelDst = LineAnt[0] = LowPassMul(LineAnt[0], PixelAnt, Vertical);
126 FrameDest[dLineOffs]= ((PixelDst+0x10007FFF)/65536); 126 FrameDest[dLineOffs]= ((PixelDst+0x10007FFF)>>16);
127 127
128 for (X = 1; X < W; X++){ 128 for (X = 1; X < W; X++){
129 int PixelDst; 129 unsigned int PixelDst;
130 /* The rest are normal */ 130 /* The rest are normal */
131 PixelAnt = LowPassMul(PixelAnt, Frame[sLineOffs+X]<<16, Horizontal); 131 PixelAnt = LowPassMul(PixelAnt, Frame[sLineOffs+X]<<16, Horizontal);
132 PixelDst = LineAnt[X] = LowPassMul(LineAnt[X], PixelAnt, Vertical); 132 PixelDst = LineAnt[X] = LowPassMul(LineAnt[X], PixelAnt, Vertical);
133 FrameDest[dLineOffs+X]= ((PixelDst+0x10007FFF)/65536); 133 FrameDest[dLineOffs+X]= ((PixelDst+0x10007FFF)>>16);
134 } 134 }
135 } 135 }
136 } 136 }
137 137
138 static void deNoise(unsigned char *Frame, // mpi->planes[x] 138 static void deNoise(unsigned char *Frame, // mpi->planes[x]
143 int *Horizontal, int *Vertical, int *Temporal) 143 int *Horizontal, int *Vertical, int *Temporal)
144 { 144 {
145 int X, Y; 145 int X, Y;
146 int sLineOffs = 0, dLineOffs = 0; 146 int sLineOffs = 0, dLineOffs = 0;
147 unsigned int PixelAnt; 147 unsigned int PixelAnt;
148 int PixelDst; 148 unsigned int PixelDst;
149 unsigned short* FrameAnt=(*FrameAntPtr); 149 unsigned short* FrameAnt=(*FrameAntPtr);
150 150
151 if(!FrameAnt){ 151 if(!FrameAnt){
152 (*FrameAntPtr)=FrameAnt=malloc(W*H*sizeof(unsigned short)); 152 (*FrameAntPtr)=FrameAnt=malloc(W*H*sizeof(unsigned short));
153 for (Y = 0; Y < H; Y++){ 153 for (Y = 0; Y < H; Y++){
169 } 169 }
170 170
171 /* First pixel has no left nor top neighbor. Only previous frame */ 171 /* First pixel has no left nor top neighbor. Only previous frame */
172 LineAnt[0] = PixelAnt = Frame[0]<<16; 172 LineAnt[0] = PixelAnt = Frame[0]<<16;
173 PixelDst = LowPassMul(FrameAnt[0]<<8, PixelAnt, Temporal); 173 PixelDst = LowPassMul(FrameAnt[0]<<8, PixelAnt, Temporal);
174 FrameAnt[0] = ((PixelDst+0x1000007F)/256); 174 FrameAnt[0] = ((PixelDst+0x1000007F)>>8);
175 FrameDest[0]= ((PixelDst+0x10007FFF)/65536); 175 FrameDest[0]= ((PixelDst+0x10007FFF)>>16);
176 176
177 /* First line has no top neighbor. Only left one for each pixel and 177 /* First line has no top neighbor. Only left one for each pixel and
178 * last frame */ 178 * last frame */
179 for (X = 1; X < W; X++){ 179 for (X = 1; X < W; X++){
180 LineAnt[X] = PixelAnt = LowPassMul(PixelAnt, Frame[X]<<16, Horizontal); 180 LineAnt[X] = PixelAnt = LowPassMul(PixelAnt, Frame[X]<<16, Horizontal);
181 PixelDst = LowPassMul(FrameAnt[X]<<8, PixelAnt, Temporal); 181 PixelDst = LowPassMul(FrameAnt[X]<<8, PixelAnt, Temporal);
182 FrameAnt[X] = ((PixelDst+0x1000007F)/256); 182 FrameAnt[X] = ((PixelDst+0x1000007F)>>8);
183 FrameDest[X]= ((PixelDst+0x10007FFF)/65536); 183 FrameDest[X]= ((PixelDst+0x10007FFF)>>16);
184 } 184 }
185 185
186 for (Y = 1; Y < H; Y++){ 186 for (Y = 1; Y < H; Y++){
187 unsigned int PixelAnt; 187 unsigned int PixelAnt;
188 unsigned short* LinePrev=&FrameAnt[Y*W]; 188 unsigned short* LinePrev=&FrameAnt[Y*W];
189 sLineOffs += sStride, dLineOffs += dStride; 189 sLineOffs += sStride, dLineOffs += dStride;
190 /* First pixel on each line doesn't have previous pixel */ 190 /* First pixel on each line doesn't have previous pixel */
191 PixelAnt = Frame[sLineOffs]<<16; 191 PixelAnt = Frame[sLineOffs]<<16;
192 LineAnt[0] = LowPassMul(LineAnt[0], PixelAnt, Vertical); 192 LineAnt[0] = LowPassMul(LineAnt[0], PixelAnt, Vertical);
193 PixelDst = LowPassMul(LinePrev[0]<<8, LineAnt[0], Temporal); 193 PixelDst = LowPassMul(LinePrev[0]<<8, LineAnt[0], Temporal);
194 LinePrev[0] = ((PixelDst+0x1000007F)/256); 194 LinePrev[0] = ((PixelDst+0x1000007F)>>8);
195 FrameDest[dLineOffs]= ((PixelDst+0x10007FFF)/65536); 195 FrameDest[dLineOffs]= ((PixelDst+0x10007FFF)>>16);
196 196
197 for (X = 1; X < W; X++){ 197 for (X = 1; X < W; X++){
198 int PixelDst; 198 unsigned int PixelDst;
199 /* The rest are normal */ 199 /* The rest are normal */
200 PixelAnt = LowPassMul(PixelAnt, Frame[sLineOffs+X]<<16, Horizontal); 200 PixelAnt = LowPassMul(PixelAnt, Frame[sLineOffs+X]<<16, Horizontal);
201 LineAnt[X] = LowPassMul(LineAnt[X], PixelAnt, Vertical); 201 LineAnt[X] = LowPassMul(LineAnt[X], PixelAnt, Vertical);
202 PixelDst = LowPassMul(LinePrev[X]<<8, LineAnt[X], Temporal); 202 PixelDst = LowPassMul(LinePrev[X]<<8, LineAnt[X], Temporal);
203 LinePrev[X] = ((PixelDst+0x1000007F)/256); 203 LinePrev[X] = ((PixelDst+0x1000007F)>>8);
204 FrameDest[dLineOffs+X]= ((PixelDst+0x10007FFF)/65536); 204 FrameDest[dLineOffs+X]= ((PixelDst+0x10007FFF)>>16);
205 } 205 }
206 } 206 }
207 } 207 }
208 208
209 209