Make alpha_ calculation faster.
Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -41,6 +41,7 @@ typedef struct BilateralContext { · 40 unmodified lines | ||
| 41 | 41 | int planewidth[4]; |
| 42 | 42 | int planeheight[4]; |
| 43 | 43 | |
| 44 | + float alpha; | |
| 44 | 45 | float range_table[65536]; |
| 45 | 46 | |
| 46 | 47 | float *img_out_f; |
| @@ -99,10 +100,11 @@ static int config_input(AVFilterLink *inlink) · 52 unmodified lines | ||
| 99 | 100 | |
| 100 | 101 | s->depth = desc->comp[0].depth; |
| 101 | 102 | inv_sigma_range = 1.0f / (s->sigmaR * ((1 << s->depth) - 1)); |
| 103 | + s->alpha = expf(-sqrtf(2.f) / s->sigmaS); | |
| 102 | 104 | |
| 103 | 105 | //compute a lookup table |
| 104 | 106 | for (int i = 0; i < (1 << s->depth); i++) |
| 105 | − s->range_table[i] = expf(-i * inv_sigma_range); | |
| 107 | + s->range_table[i] = s->alpha * expf(-i * inv_sigma_range); | |
| 106 | 108 | |
| 107 | 109 | s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w); |
| 108 | 110 | s->planewidth[0] = s->planewidth[3] = inlink->w; |
| @@ -144,10 +146,10 @@ static void bilateral_##name(BilateralContext *s, const uint8_t *ssrc, uint8_t * · 35 unmodified lines | ||
| 144 | 146 | float *map_factor_a = s->map_factor_a, *map_factor_b = s->map_factor_b; \ |
| 145 | 147 | float *slice_factor_a = s->slice_factor_a, *slice_factor_b = s->slice_factor_b; \ |
| 146 | 148 | float *line_factor_a = s->line_factor_a, *line_factor_b = s->line_factor_b; \ |
| 147 | − float *range_table = s->range_table; \ | |
| 148 | − float alpha = expf(-sqrtf(2.f) / sigma_spatial); \ | |
| 149 | + const float *range_table = s->range_table; \ | |
| 150 | + const float alpha = s->alpha; \ | |
| 149 | 151 | float ypr, ycr, *ycy, *ypy, *xcy, fp, fc; \ |
| 150 | − float inv_alpha_ = 1 - alpha; \ | |
| 152 | + const float inv_alpha_ = 1.f - alpha; \ | |
| 151 | 153 | float *ycf, *ypf, *xcf, *in_factor; \ |
| 152 | 154 | const type *tcy, *tpy; \ |
| 153 | 155 | int h1; \ |
| @@ -165,14 +167,13 @@ static void bilateral_##name(BilateralContext *s, const uint8_t *ssrc, uint8_t * · 11 unmodified lines | ||
| 165 | 167 | *temp_factor_x++ = fp = 1; \ |
| 166 | 168 | \ |
| 167 | 169 | for (int x = 1; x < width; x++) { \ |
| 168 | − float weight, alpha_; \ | |
| 170 | + float alpha_; \ | |
| 169 | 171 | int range_dist; \ |
| 170 | 172 | type tcr = *texture_x++; \ |
| 171 | 173 | type dr = abs(tcr - tpr); \ |
| 172 | 174 | \ |
| 173 | 175 | range_dist = dr; \ |
| 174 | − weight = range_table[range_dist]; \ | |
| 175 | − alpha_ = weight*alpha; \ | |
| 176 | + alpha_ = range_table[range_dist]; \ | |
| 176 | 177 | *temp_x++ = ycr = inv_alpha_*(*in_x++) + alpha_*ypr; \ |
| 177 | 178 | tpr = tcr; \ |
| 178 | 179 | ypr = ycr; \ |
| @@ -190,8 +191,7 @@ static void bilateral_##name(BilateralContext *s, const uint8_t *ssrc, uint8_t * · 11 unmodified lines | ||
| 190 | 191 | type tcr = *--texture_x; \ |
| 191 | 192 | type dr = abs(tcr - tpr); \ |
| 192 | 193 | int range_dist = dr; \ |
| 193 | − float weight = range_table[range_dist]; \ | |
| 194 | − float alpha_ = weight * alpha; \ | |
| 194 | + float alpha_ = range_table[range_dist]; \ | |
| 195 | 195 | \ |
| 196 | 196 | ycr = inv_alpha_ * (*--in_x) + alpha_ * ypr; \ |
| 197 | 197 | --temp_x; *temp_x = 0.5f*((*temp_x) + ycr); \ |
| @@ -206,8 +206,6 @@ static void bilateral_##name(BilateralContext *s, const uint8_t *ssrc, uint8_t * · 8 unmodified lines | ||
| 206 | 206 | } \ |
| 207 | 207 | memcpy(img_out_f, img_temp, sizeof(float) * width); \ |
| 208 | 208 | \ |
| 209 | − alpha = expf(-sqrtf(2.f) / sigma_spatial); \ | |
| 210 | − inv_alpha_ = 1 - alpha; \ | |
| 211 | 209 | in_factor = map_factor_a; \ |
| 212 | 210 | memcpy(map_factor_b, in_factor, sizeof(float) * width); \ |
| 213 | 211 | for (int y = 1; y < height; y++) { \ |
| @@ -223,8 +221,7 @@ static void bilateral_##name(BilateralContext *s, const uint8_t *ssrc, uint8_t * · 9 unmodified lines | ||
| 223 | 221 | for (int x = 0; x < width; x++) { \ |
| 224 | 222 | type dr = abs((*tcy++) - (*tpy++)); \ |
| 225 | 223 | int range_dist = dr; \ |
| 226 | − float weight = range_table[range_dist]; \ | |
| 227 | − float alpha_ = weight*alpha; \ | |
| 224 | + float alpha_ = range_table[range_dist]; \ | |
| 228 | 225 | \ |
| 229 | 226 | *ycy++ = inv_alpha_*(*xcy++) + alpha_*(*ypy++); \ |
| 230 | 227 | *ycf++ = inv_alpha_*(*xcf++) + alpha_*(*ypf++); \ |
| @@ -263,8 +260,7 @@ static void bilateral_##name(BilateralContext *s, const uint8_t *ssrc, uint8_t * · 32 unmodified lines | ||
| 263 | 260 | for (int x = 0; x < width; x++) { \ |
| 264 | 261 | type dr = abs((*tcy++) - (*tpy++)); \ |
| 265 | 262 | int range_dist = dr; \ |
| 266 | − float weight = range_table[range_dist]; \ | |
| 267 | − float alpha_ = weight*alpha; \ | |
| 263 | + float alpha_ = range_table[range_dist]; \ | |
| 268 | 264 | float ycc, fcc = inv_alpha_*(*xcf++) + alpha_*(*ypf_++); \ |
| 269 | 265 | \ |
| 270 | 266 | *ycf_++ = fcc; \ |