]> git.sesse.net Git - movit/commitdiff
Kill the EffectId enum, on the basis of YAGNI.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 6 Oct 2012 13:04:50 +0000 (15:04 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 6 Oct 2012 13:04:50 +0000 (15:04 +0200)
effect_chain.cpp
effect_chain.h
main.cpp

index 31a7c8b128041c951f99a1624c95e9402bcee0c0..7232dcbbb4004de3a98402cac21361385ab8b2fd 100644 (file)
 #include "effect_chain.h"
 #include "gamma_expansion_effect.h"
 #include "gamma_compression_effect.h"
-#include "lift_gamma_gain_effect.h"
 #include "colorspace_conversion_effect.h"
-#include "sandbox_effect.h"
-#include "saturation_effect.h"
-#include "mirror_effect.h"
-#include "vignette_effect.h"
-#include "blur_effect.h"
-#include "diffusion_effect.h"
-#include "glow_effect.h"
-#include "mix_effect.h"
 #include "input.h"
 
 EffectChain::EffectChain(unsigned width, unsigned height)
@@ -70,37 +61,6 @@ void EffectChain::add_effect_raw(Effect *effect, const std::vector<Effect *> &in
        output_color_space[effect] = output_color_space[last_added_effect()];
 }
 
-Effect *instantiate_effect(EffectId effect)
-{
-       switch (effect) {
-       case EFFECT_GAMMA_EXPANSION:
-               return new GammaExpansionEffect();
-       case EFFECT_GAMMA_COMPRESSION:
-               return new GammaCompressionEffect();
-       case EFFECT_COLOR_SPACE_CONVERSION:
-               return new ColorSpaceConversionEffect();
-       case EFFECT_SANDBOX:
-               return new SandboxEffect();
-       case EFFECT_LIFT_GAMMA_GAIN:
-               return new LiftGammaGainEffect();
-       case EFFECT_SATURATION:
-               return new SaturationEffect();
-       case EFFECT_MIRROR:
-               return new MirrorEffect();
-       case EFFECT_VIGNETTE:
-               return new VignetteEffect();
-       case EFFECT_BLUR:
-               return new BlurEffect();
-       case EFFECT_DIFFUSION:
-               return new DiffusionEffect();
-       case EFFECT_GLOW:
-               return new GlowEffect();
-       case EFFECT_MIX:
-               return new MixEffect();
-       }
-       assert(false);
-}
-
 // Set the "use_srgb_texture_format" option on all inputs that feed into this node,
 // and update the output_gamma_curve[] map as we go.
 //
@@ -160,10 +120,8 @@ Effect *EffectChain::normalize_to_srgb(Effect *input)
        return colorspace_conversion;
 }
 
-Effect *EffectChain::add_effect(EffectId effect_id, const std::vector<Effect *> &inputs)
+Effect *EffectChain::add_effect(Effect *effect, const std::vector<Effect *> &inputs)
 {
-       Effect *effect = instantiate_effect(effect_id);
-
        assert(inputs.size() == effect->num_inputs());
 
        std::vector<Effect *> normalized_inputs = inputs;
index 91b8e29f2c5fe12b5405e9778a3a3c948fab1d01..f9e1255566fbcf5522de9a58d34b2f52a83154af 100644 (file)
@@ -5,7 +5,6 @@
 #include <vector>
 
 #include "effect.h"
-#include "effect_id.h"
 #include "image_format.h"
 #include "input.h"
 
@@ -18,22 +17,23 @@ public:
 
        Input *add_input(const ImageFormat &format);
 
-       // The returned pointer is owned by EffectChain.
-       Effect *add_effect(EffectId effect) {
+       // EffectChain takes ownership of the given effect.
+       // effect is returned back for convenience.
+       Effect *add_effect(Effect *effect) {
                return add_effect(effect, last_added_effect());
        }
-       Effect *add_effect(EffectId effect, Effect *input) {
+       Effect *add_effect(Effect *effect, Effect *input) {
                std::vector<Effect *> inputs;
                inputs.push_back(input);
                return add_effect(effect, inputs);
        }
-       Effect *add_effect(EffectId effect, Effect *input1, Effect *input2) {
+       Effect *add_effect(Effect *effect, Effect *input1, Effect *input2) {
                std::vector<Effect *> inputs;
                inputs.push_back(input1);
                inputs.push_back(input2);
                return add_effect(effect, inputs);
        }
-       Effect *add_effect(EffectId effect, const std::vector<Effect *> &inputs);
+       Effect *add_effect(Effect *effect, const std::vector<Effect *> &inputs);
 
        // Similar to add_effect, but:
        //
index 4e2d303f893fc77525fdf558a70ac9e536a7143f..bc52e1d25b6bb2befb605a2a9e61e6016ac0305c 100644 (file)
--- a/main.cpp
+++ b/main.cpp
 #include "util.h"
 #include "widgets.h"
 
+#include "lift_gamma_gain_effect.h"
+#include "saturation_effect.h"
+#include "diffusion_effect.h"
+
 unsigned char result[WIDTH * HEIGHT * 4];
 
 float lift_theta = 0.0f, lift_rad = 0.0f, lift_v = 0.0f;
@@ -165,13 +169,13 @@ int main(int argc, char **argv)
        inout_format.gamma_curve = GAMMA_sRGB;
 
        Input *input = chain.add_input(inout_format);
-       Effect *lift_gamma_gain_effect = chain.add_effect(EFFECT_LIFT_GAMMA_GAIN);
-       Effect *saturation_effect = chain.add_effect(EFFECT_SATURATION);
-       Effect *diffusion_effect = chain.add_effect(EFFECT_DIFFUSION);
-       //Effect *vignette_effect = chain.add_effect(EFFECT_VIGNETTE);
-       //Effect *sandbox_effect = chain.add_effect(EFFECT_SANDBOX);
+       Effect *lift_gamma_gain_effect = chain.add_effect(new LiftGammaGainEffect());
+       Effect *saturation_effect = chain.add_effect(new SaturationEffect());
+       Effect *diffusion_effect = chain.add_effect(new DiffusionEffect());
+       //Effect *vignette_effect = chain.add_effect(new VignetteEffect());
+       //Effect *sandbox_effect = chain.add_effect(new SandboxEffect());
        //sandbox_effect->set_float("parm", 42.0f);
-       //chain.add_effect(EFFECT_MIRROR);
+       //chain.add_effect(new MirrorEffect());
        chain.add_output(inout_format);
        chain.finalize();