From: Steinar H. Gunderson Date: Sat, 6 Oct 2012 13:04:50 +0000 (+0200) Subject: Kill the EffectId enum, on the basis of YAGNI. X-Git-Tag: 1.0~363 X-Git-Url: https://git.sesse.net/?p=movit;a=commitdiff_plain;h=bbf6d754a01960a637e821853cf50a282f2a9163 Kill the EffectId enum, on the basis of YAGNI. --- diff --git a/effect_chain.cpp b/effect_chain.cpp index 31a7c8b..7232dcb 100644 --- a/effect_chain.cpp +++ b/effect_chain.cpp @@ -16,16 +16,7 @@ #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 &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 &inputs) +Effect *EffectChain::add_effect(Effect *effect, const std::vector &inputs) { - Effect *effect = instantiate_effect(effect_id); - assert(inputs.size() == effect->num_inputs()); std::vector normalized_inputs = inputs; diff --git a/effect_chain.h b/effect_chain.h index 91b8e29..f9e1255 100644 --- a/effect_chain.h +++ b/effect_chain.h @@ -5,7 +5,6 @@ #include #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 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 inputs; inputs.push_back(input1); inputs.push_back(input2); return add_effect(effect, inputs); } - Effect *add_effect(EffectId effect, const std::vector &inputs); + Effect *add_effect(Effect *effect, const std::vector &inputs); // Similar to add_effect, but: // diff --git a/main.cpp b/main.cpp index 4e2d303..bc52e1d 100644 --- a/main.cpp +++ b/main.cpp @@ -26,6 +26,10 @@ #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();