1 #ifndef _MOVIT_BLUR_EFFECT_H
2 #define _MOVIT_BLUR_EFFECT_H 1
4 // A separable 2D blur implemented by a combination of mipmap filtering
5 // and convolution (essentially giving a convolution with a piecewise linear
6 // approximation to the true impulse response).
8 // Works in two passes; first horizontal, then vertical (BlurEffect,
9 // which is what the user is intended to use, instantiates two copies of
10 // SingleBlurPassEffect behind the scenes).
12 // The recommended number of taps is the default (16). Fewer will be faster
13 // but uglier; a tradeoff that might be worth it as part of more complicated
14 // effects. This can be set only before finalization, and must be an
28 class SingleBlurPassEffect;
30 class BlurEffect : public Effect {
34 std::string effect_type_id() const override { return "BlurEffect"; }
36 // We want this for the same reason as ResizeEffect; we could end up scaling
38 bool needs_texture_bounce() const override { return true; }
39 bool needs_mipmaps() const override { return true; }
40 bool needs_srgb_primaries() const override { return false; }
42 void inform_input_size(unsigned input_num, unsigned width, unsigned height) override;
44 std::string output_fragment_shader() override {
47 void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num) override {
51 void rewrite_graph(EffectChain *graph, Node *self) override;
52 bool set_float(const std::string &key, float value) override;
53 bool set_int(const std::string &key, int value) override;
60 SingleBlurPassEffect *hpass, *vpass;
61 unsigned input_width, input_height;
64 class SingleBlurPassEffect : public Effect {
66 // If parent is non-nullptr, calls to inform_input_size will be forwarded
67 // so that it can make reasonable decisions for both blur passes.
68 SingleBlurPassEffect(BlurEffect *parent);
69 virtual ~SingleBlurPassEffect();
70 std::string effect_type_id() const override { return "SingleBlurPassEffect"; }
72 std::string output_fragment_shader() override;
74 bool needs_texture_bounce() const override { return true; }
75 bool needs_mipmaps() const override { return true; }
76 bool needs_srgb_primaries() const override { return false; }
77 AlphaHandling alpha_handling() const override { return INPUT_PREMULTIPLIED_ALPHA_KEEP_BLANK; }
79 void inform_input_size(unsigned input_num, unsigned width, unsigned height) override {
80 if (parent != nullptr) {
81 parent->inform_input_size(input_num, width, height);
84 bool changes_output_size() const override { return true; }
85 bool sets_virtual_output_size() const override { return true; }
86 bool one_to_one_sampling() const override { return false; } // Can sample outside the border.
88 void get_output_size(unsigned *width, unsigned *height, unsigned *virtual_width, unsigned *virtual_height) const override {
90 *height = this->height;
91 *virtual_width = this->virtual_width;
92 *virtual_height = this->virtual_height;
95 void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num) override;
96 void clear_gl_state() override;
98 enum Direction { HORIZONTAL = 0, VERTICAL = 1 };
105 int width, height, virtual_width, virtual_height;
106 float *uniform_samples;
111 #endif // !defined(_MOVIT_BLUR_EFFECT_H)