int base_src_y = lrintf(center_src_y);
// Now sample <int_radius> pixels on each side around that point.
+ double sum = 0.0;
for (int i = 0; i < src_samples; ++i) {
int src_y = base_src_y + i - int_radius;
float weight = lanczos_weight(radius_scaling_factor * (src_y - center_src_y), LANCZOS_RADIUS);
weights[(y * src_samples + i) * 2 + 0] = weight * radius_scaling_factor;
weights[(y * src_samples + i) * 2 + 1] = (src_y + 0.5) / float(src_size);
+ sum += weights[(y * src_samples + i) * 2 + 0];
+ }
+
+ // Normalize so that the sum becomes one.
+ for (int i = 0; i < src_samples; ++i) {
+ weights[(y * src_samples + i) * 2 + 0] /= sum;
}
}
}
}
}
+
+TEST(ResampleEffectTest, HeavyResampleGetsSumRight) {
+ const int swidth = 1280, sheight = 720;
+ const int dwidth = 36, dheight = 20;
+
+ float data[swidth * sheight], out_data[dwidth * dheight], expected_data[dwidth * dheight];
+ for (int y = 0; y < sheight; ++y) {
+ for (int x = 0; x < swidth; ++x) {
+ data[y * swidth + x] = 0.5f;
+ }
+ }
+ for (int y = 0; y < dheight; ++y) {
+ for (int x = 0; x < dwidth; ++x) {
+ expected_data[y * dwidth + x] = 0.5f;
+ }
+ }
+
+ EffectChainTester tester(NULL, dwidth, dheight, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+ ImageFormat format;
+ format.color_space = COLORSPACE_sRGB;
+ format.gamma_curve = GAMMA_LINEAR;
+
+ FlatInput *input = new FlatInput(format, FORMAT_GRAYSCALE, GL_FLOAT, swidth, sheight);
+ input->set_pixel_data(data);
+
+ tester.get_chain()->add_input(input);
+ Effect *resample_effect = tester.get_chain()->add_effect(new ResampleEffect());
+ ASSERT_TRUE(resample_effect->set_int("width", dwidth));
+ ASSERT_TRUE(resample_effect->set_int("height", dheight));
+ tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+ expect_equal(expected_data, out_data, dwidth, dheight, 0.001);
+}
+