X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=deinterlace_effect_test.cpp;h=0c625c519fcd656758831b0228830e78dac40e32;hp=d2045eb478cd976d08f080f10fdce54637fc7de6;hb=c72cd5445d110b4519ac6af2f747832e38c3b829;hpb=0ed2c7fe3876a49d1565e3425e5a491206ffe32d diff --git a/deinterlace_effect_test.cpp b/deinterlace_effect_test.cpp index d2045eb..0c625c5 100644 --- a/deinterlace_effect_test.cpp +++ b/deinterlace_effect_test.cpp @@ -6,6 +6,7 @@ #include #include +#include #include "effect_chain.h" #include "gtest/gtest.h" @@ -33,7 +34,7 @@ TEST(DeinterlaceTest, ConstantColor) { 0.3f, 0.3f, }; float out_data[12]; - EffectChainTester tester(NULL, 2, 6); + EffectChainTester tester(nullptr, 2, 6); Effect *input1 = tester.add_input(data, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR, 2, 3); Effect *input2 = tester.add_input(data, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR, 2, 3); Effect *input3 = tester.add_input(data, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR, 2, 3); @@ -79,7 +80,7 @@ TEST(DeinterlaceTest, VerticalInterpolation) { fill(neg_blowout_data, neg_blowout_data + width * height, -100.0f); fill(pos_blowout_data, pos_blowout_data + width * height, 100.0f); - EffectChainTester tester(NULL, width, height * 2); + EffectChainTester tester(nullptr, width, height * 2); Effect *input1 = tester.add_input(neg_blowout_data, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR, width, height); Effect *input2 = tester.add_input(neg_blowout_data, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR, width, height); Effect *input3 = tester.add_input(data, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR, width, height); @@ -131,7 +132,7 @@ TEST(DeinterlaceTest, DiagonalInterpolation) { fill(neg_blowout_data, neg_blowout_data + width * height, -100.0f); fill(pos_blowout_data, pos_blowout_data + width * height, 100.0f); - EffectChainTester tester(NULL, width, height * 2); + EffectChainTester tester(nullptr, width, height * 2); Effect *input1 = tester.add_input(neg_blowout_data, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR, width, height); Effect *input2 = tester.add_input(neg_blowout_data, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR, width, height); Effect *input3 = tester.add_input(data, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR, width, height); @@ -172,7 +173,7 @@ TEST(DeinterlaceTest, FlickerBox) { float out_data[width * height * 2]; { - EffectChainTester tester(NULL, width, height * 2); + EffectChainTester tester(nullptr, width, height * 2); Effect *white_input = tester.add_input(white_data, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR, width, height); Effect *black_input = tester.add_input(black_data, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR, width, height); Effect *deinterlace_effect = tester.get_chain()->add_effect(new DeinterlaceEffect(), white_input, black_input, white_input, black_input, white_input); @@ -184,7 +185,7 @@ TEST(DeinterlaceTest, FlickerBox) { } { - EffectChainTester tester(NULL, width, height * 2); + EffectChainTester tester(nullptr, width, height * 2); Effect *white_input = tester.add_input(white_data, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR, width, height); Effect *black_input = tester.add_input(black_data, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR, width, height); Effect *deinterlace_effect = tester.get_chain()->add_effect(new DeinterlaceEffect(), white_input, black_input, white_input, black_input, white_input); @@ -197,19 +198,31 @@ TEST(DeinterlaceTest, FlickerBox) { } #ifdef HAVE_BENCHMARK -void BM_DeinterlaceEffect_Gray(benchmark::State &state) +namespace { + +struct TestFormat { + MovitPixelFormat input_format; + GLenum output_format; + size_t bytes_per_pixel; +}; +TestFormat gray_format = { FORMAT_GRAYSCALE, GL_RED, 1 }; +TestFormat bgra_format = { FORMAT_BGRA_PREMULTIPLIED_ALPHA, GL_BGRA, 4 }; + +} // namespace + +void BM_DeinterlaceEffect(benchmark::State &state, TestFormat format, bool spatial_interlacing_check) { unsigned width = state.range(0), height = state.range(1); unsigned field_height = height / 2; - float *field1 = new float[width * field_height]; - float *field2 = new float[width * field_height]; - float *field3 = new float[width * field_height]; - float *field4 = new float[width * field_height]; - float *field5 = new float[width * field_height]; - float *out_data = new float[width * height]; + unique_ptr field1(new float[width * field_height * format.bytes_per_pixel]); + unique_ptr field2(new float[width * field_height * format.bytes_per_pixel]); + unique_ptr field3(new float[width * field_height * format.bytes_per_pixel]); + unique_ptr field4(new float[width * field_height * format.bytes_per_pixel]); + unique_ptr field5(new float[width * field_height * format.bytes_per_pixel]); + unique_ptr out_data(new float[width * height * format.bytes_per_pixel]); - for (unsigned i = 0; i < width * field_height; ++i) { + for (unsigned i = 0; i < width * field_height * format.bytes_per_pixel; ++i) { field1[i] = rand(); field2[i] = rand(); field3[i] = rand(); @@ -217,26 +230,23 @@ void BM_DeinterlaceEffect_Gray(benchmark::State &state) field5[i] = rand(); } - EffectChainTester tester(NULL, width, height); - Effect *input1 = tester.add_input(field1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR, width, field_height); - Effect *input2 = tester.add_input(field2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR, width, field_height); - Effect *input3 = tester.add_input(field3, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR, width, field_height); - Effect *input4 = tester.add_input(field4, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR, width, field_height); - Effect *input5 = tester.add_input(field5, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR, width, field_height); + EffectChainTester tester(nullptr, width, height); + Effect *input1 = tester.add_input(field1.get(), format.input_format, COLORSPACE_sRGB, GAMMA_LINEAR, width, field_height); + Effect *input2 = tester.add_input(field2.get(), format.input_format, COLORSPACE_sRGB, GAMMA_LINEAR, width, field_height); + Effect *input3 = tester.add_input(field3.get(), format.input_format, COLORSPACE_sRGB, GAMMA_LINEAR, width, field_height); + Effect *input4 = tester.add_input(field4.get(), format.input_format, COLORSPACE_sRGB, GAMMA_LINEAR, width, field_height); + Effect *input5 = tester.add_input(field5.get(), format.input_format, COLORSPACE_sRGB, GAMMA_LINEAR, width, field_height); Effect *deinterlace_effect = tester.get_chain()->add_effect(new DeinterlaceEffect(), input1, input2, input3, input4, input5); ASSERT_TRUE(deinterlace_effect->set_int("current_field_position", 0)); + ASSERT_TRUE(deinterlace_effect->set_int("enable_spatial_interlacing_check", spatial_interlacing_check)); - tester.benchmark(state, out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR, OUTPUT_ALPHA_FORMAT_PREMULTIPLIED); - - delete[] field1; - delete[] field2; - delete[] field3; - delete[] field4; - delete[] field5; - delete[] out_data; + tester.benchmark(state, out_data.get(), format.output_format, COLORSPACE_sRGB, GAMMA_LINEAR, OUTPUT_ALPHA_FORMAT_PREMULTIPLIED); } -BENCHMARK(BM_DeinterlaceEffect_Gray)->Args({720, 576})->Args({1280, 720})->Args({1920, 1080})->UseRealTime()->Unit(benchmark::kMicrosecond); +BENCHMARK_CAPTURE(BM_DeinterlaceEffect, Gray, gray_format, true)->Args({720, 576})->Args({1280, 720})->Args({1920, 1080})->UseRealTime()->Unit(benchmark::kMicrosecond); +BENCHMARK_CAPTURE(BM_DeinterlaceEffect, BGRA, bgra_format, true)->Args({720, 576})->Args({1280, 720})->Args({1920, 1080})->UseRealTime()->Unit(benchmark::kMicrosecond); +BENCHMARK_CAPTURE(BM_DeinterlaceEffect, BGRANoSpatialCheck, bgra_format, false)->Args({720, 576})->Args({1280, 720})->Args({1920, 1080})->UseRealTime()->Unit(benchmark::kMicrosecond); + #endif } // namespace movit