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