]> git.sesse.net Git - movit/blobdiff - resample_effect.cpp
Fix a bug where combined fp16 weights would be horribly wrong.
[movit] / resample_effect.cpp
index 1b74a965c6f60654967f5960fe3e69384256a78f..244a3e2a6081187f19962b531c7fa86dde46203b 100644 (file)
@@ -107,7 +107,7 @@ unsigned combine_samples(const Tap<float> *src, Tap<DestFloat> *dst, float num_s
                float pos2 = src[i + 1].pos;
                assert(pos2 > pos1);
 
-               fp16_int_t pos, total_weight;
+               DestFloat pos, total_weight;
                float sum_sq_error;
                combine_two_samples(w1, w2, pos1, pos2, num_subtexels, inv_num_subtexels, &pos, &total_weight, &sum_sq_error);
 
@@ -142,8 +142,9 @@ void normalize_sum(Tap<T>* vals, unsigned num)
                for (unsigned i = 0; i < num; ++i) {
                        sum += to_fp64(vals[i].weight);
                }
+               double inv_sum = 1.0 / sum;
                for (unsigned i = 0; i < num; ++i) {
-                       vals[i].weight = from_fp64<T>(to_fp64(vals[i].weight) sum);
+                       vals[i].weight = from_fp64<T>(to_fp64(vals[i].weight) * inv_sum);
                }
        }
 }