]> git.sesse.net Git - movit/commitdiff
If all inputs to an effect have the same input size, use that instead of fitting...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 29 Jan 2013 19:11:23 +0000 (20:11 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 29 Jan 2013 19:11:23 +0000 (20:11 +0100)
The common case here is one-input effects on overlays.
Reported by Christophe Thommeret.

effect_chain.cpp
effect_chain_test.cpp

index f6266d741e63c0308ea841952a6ec23816f30406..9aaa74829041028090079ed8d511abe8e4edd2dd 100644 (file)
@@ -666,10 +666,49 @@ void EffectChain::find_output_size(Phase *phase)
                return;
        }
 
                return;
        }
 
+       // If all effects have the same size, use that.
        unsigned output_width = 0, output_height = 0;
        unsigned output_width = 0, output_height = 0;
+       bool all_inputs_same_size = true;
 
 
-       // If not, look at the input phases and textures.
-       // We select the largest one (by fit into the current aspect).
+       for (unsigned i = 0; i < phase->inputs.size(); ++i) {
+               Node *input = phase->inputs[i];
+               assert(input->phase->output_width != 0);
+               assert(input->phase->output_height != 0);
+               if (output_width == 0 && output_height == 0) {
+                       output_width = input->phase->output_width;
+                       output_height = input->phase->output_height;
+               } else if (output_width != input->phase->output_width ||
+                          output_height != input->phase->output_height) {
+                       all_inputs_same_size = false;
+               }
+       }
+       for (unsigned i = 0; i < phase->effects.size(); ++i) {
+               Effect *effect = phase->effects[i]->effect;
+               if (effect->num_inputs() != 0) {
+                       continue;
+               }
+
+               Input *input = static_cast<Input *>(effect);
+               if (output_width == 0 && output_height == 0) {
+                       output_width = input->get_width();
+                       output_height = input->get_height();
+               } else if (output_width != input->get_width() ||
+                          output_height != input->get_height()) {
+                       all_inputs_same_size = false;
+               }
+       }
+
+       if (all_inputs_same_size) {
+               assert(output_width != 0);
+               assert(output_height != 0);
+               phase->output_width = output_width;
+               phase->output_height = output_height;
+               return;
+       }
+
+       // If not, fit all the inputs into the current aspect, and select the largest one. 
+       output_width = 0;
+       output_height = 0;
        for (unsigned i = 0; i < phase->inputs.size(); ++i) {
                Node *input = phase->inputs[i];
                assert(input->phase->output_width != 0);
        for (unsigned i = 0; i < phase->inputs.size(); ++i) {
                Node *input = phase->inputs[i];
                assert(input->phase->output_width != 0);
index 762447aad99018bcb885fc3651fb00a46df89a48..c17ec890ec9a0282dd036fa6ac51afb89c6177e9 100644 (file)
@@ -771,6 +771,37 @@ public:
        int input_width, input_height;
 };
 
        int input_width, input_height;
 };
 
+TEST(EffectChainTest, SameInputsGiveSameOutputs) {
+       float data[2 * 2] = {
+               0.0f, 0.0f,
+               0.0f, 0.0f,
+       };
+       float out_data[2 * 2];
+       
+       EffectChainTester tester(NULL, 4, 3);  // Note non-square aspect.
+
+       ImageFormat format;
+       format.color_space = COLORSPACE_sRGB;
+       format.gamma_curve = GAMMA_LINEAR;
+
+       FlatInput *input1 = new FlatInput(format, FORMAT_GRAYSCALE, GL_FLOAT, 2, 2);
+       input1->set_pixel_data(data);
+       
+       FlatInput *input2 = new FlatInput(format, FORMAT_GRAYSCALE, GL_FLOAT, 2, 2);
+       input2->set_pixel_data(data);
+
+       SizeStoringEffect *input_store = new SizeStoringEffect();
+
+       tester.get_chain()->add_input(input1);
+       tester.get_chain()->add_input(input2);
+       tester.get_chain()->add_effect(new AddEffect(), input1, input2);
+       tester.get_chain()->add_effect(input_store);
+       tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       EXPECT_EQ(2, input_store->input_width);
+       EXPECT_EQ(2, input_store->input_height);
+}
+
 TEST(EffectChainTest, AspectRatioConversion) {
        float data1[4 * 3] = {
                0.0f, 0.0f, 0.0f, 0.0f,
 TEST(EffectChainTest, AspectRatioConversion) {
        float data1[4 * 3] = {
                0.0f, 0.0f, 0.0f, 0.0f,