From: Steinar H. Gunderson Date: Mon, 5 Oct 2015 21:08:35 +0000 (+0200) Subject: Call init_lanczos_table() once instead of checking for it all the time. X-Git-Tag: 1.3.0~33 X-Git-Url: https://git.sesse.net/?p=movit;a=commitdiff_plain;h=3c2ad5e6496cc518f6abd23a5a5332314e8dab80;hp=831150846e1e79b53b02b07fbf12ec7cae289a3a Call init_lanczos_table() once instead of checking for it all the time. --- diff --git a/resample_effect.cpp b/resample_effect.cpp index 958ed25..95f5575 100644 --- a/resample_effect.cpp +++ b/resample_effect.cpp @@ -74,6 +74,9 @@ float lanczos_weight(float x) // // Solve for e = 1e-6 yields a step size of 0.0027, which to cover the range // 0..3 needs 1109 steps. We round up to the next power of two, just to be sure. +// +// You need to call lanczos_table_init_done before the first call to +// lanczos_weight_cached. #define LANCZOS_TABLE_SIZE 2048 bool lanczos_table_init_done = false; float lanczos_table[LANCZOS_TABLE_SIZE + 2]; @@ -88,11 +91,6 @@ void init_lanczos_table() float lanczos_weight_cached(float x) { - if (!lanczos_table_init_done) { - // Could in theory race between two threads if we are unlucky, - // but that is harmless, since they'll write the same data. - init_lanczos_table(); - } x = fabs(x); if (x > LANCZOS_RADIUS) { return 0.0f; @@ -461,6 +459,12 @@ SingleResamplePassEffect::SingleResamplePassEffect(ResampleEffect *parent) register_uniform_float("whole_pixel_offset", &uniform_whole_pixel_offset); glGenTextures(1, &texnum); + + if (!lanczos_table_init_done) { + // Could in theory race between two threads if we are unlucky, + // but that is harmless, since they'll write the same data. + init_lanczos_table(); + } } SingleResamplePassEffect::~SingleResamplePassEffect()