]> git.sesse.net Git - movit/blob - blur_effect.h
Remove some unused members in tests. Found by Clang 7.
[movit] / blur_effect.h
1 #ifndef _MOVIT_BLUR_EFFECT_H
2 #define _MOVIT_BLUR_EFFECT_H 1
3
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).
7 //
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).
11 //
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
15 // even number.
16
17 #include <epoxy/gl.h>
18 #include <assert.h>
19 #include <stddef.h>
20 #include <string>
21
22 #include "effect.h"
23
24 namespace movit {
25
26 class EffectChain;
27 class Node;
28 class SingleBlurPassEffect;
29
30 class BlurEffect : public Effect {
31 public:
32         BlurEffect();
33
34         std::string effect_type_id() const override { return "BlurEffect"; }
35
36         void inform_input_size(unsigned input_num, unsigned width, unsigned height) override;
37
38         std::string output_fragment_shader() override {
39                 assert(false);
40         }
41         void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num) override {
42                 assert(false);
43         }
44
45         void rewrite_graph(EffectChain *graph, Node *self) override;
46         bool set_float(const std::string &key, float value) override;
47         bool set_int(const std::string &key, int value) override;
48         
49 private:
50         void update_radius();
51
52         int num_taps;
53         float radius;
54         SingleBlurPassEffect *hpass, *vpass;
55         unsigned input_width, input_height;
56 };
57
58 class SingleBlurPassEffect : public Effect {
59 public:
60         // If parent is non-nullptr, calls to inform_input_size will be forwarded
61         // so that it can make reasonable decisions for both blur passes.
62         SingleBlurPassEffect(BlurEffect *parent);
63         virtual ~SingleBlurPassEffect();
64         std::string effect_type_id() const override { return "SingleBlurPassEffect"; }
65
66         std::string output_fragment_shader() override;
67
68         // We want this for the same reason as ResizeEffect; we could end up scaling
69         // down quite a lot.
70         bool needs_texture_bounce() const override { return true; }
71         MipmapRequirements needs_mipmaps() const override { return NEEDS_MIPMAPS; }
72         bool needs_srgb_primaries() const override { return false; }
73         AlphaHandling alpha_handling() const override { return INPUT_PREMULTIPLIED_ALPHA_KEEP_BLANK; }
74
75         void inform_input_size(unsigned input_num, unsigned width, unsigned height) override {
76                 if (parent != nullptr) {
77                         parent->inform_input_size(input_num, width, height);
78                 }
79         }
80         bool changes_output_size() const override { return true; }
81         bool sets_virtual_output_size() const override { return true; }
82         bool one_to_one_sampling() const override { return false; }  // Can sample outside the border.
83
84         void get_output_size(unsigned *width, unsigned *height, unsigned *virtual_width, unsigned *virtual_height) const override {
85                 *width = this->width;
86                 *height = this->height;
87                 *virtual_width = this->virtual_width;
88                 *virtual_height = this->virtual_height;
89         }
90
91         void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num) override;
92         void clear_gl_state() override;
93         
94         enum Direction { HORIZONTAL = 0, VERTICAL = 1 };
95
96 private:
97         BlurEffect *parent;
98         int num_taps;
99         float radius;
100         Direction direction;
101         int width, height, virtual_width, virtual_height;
102         float *uniform_samples;
103 };
104
105 }  // namespace movit
106
107 #endif // !defined(_MOVIT_BLUR_EFFECT_H)