]> git.sesse.net Git - movit/blob - padding_effect.h
Mark ResampleEffect as not one-to-one sampling.
[movit] / padding_effect.h
1 #ifndef _MOVIT_PADDING_EFFECT_H
2 #define _MOVIT_PADDING_EFFECT_H 1
3
4 // Takes an image and pads it to fit a larger image, or crops it to fit a smaller one
5 // (although the latter is implemented slightly less efficiently, and you cannot both
6 // pad and crop in the same effect).
7 //
8 // The source image is cut off at the texel borders (so there is no interpolation
9 // outside them), and then given a user-specific color; by default, full transparent.
10 //
11 // The border color is taken to be in linear gamma, sRGB, with premultiplied alpha.
12 // You may not change it after calling finalize(), since that could change the
13 // graph (need_linear_light() etc. depend on the border color you choose).
14 //
15 // IntegralPaddingEffect is like PaddingEffect, except that "top" and "left" parameters
16 // are int parameters instead of float. This allows it to guarantee one-to-one sampling,
17 // which can speed up processing by allowing more effect passes to be collapsed.
18
19 #include <epoxy/gl.h>
20 #include <string>
21
22 #include "effect.h"
23
24 namespace movit {
25
26 class PaddingEffect : public Effect {
27 public:
28         PaddingEffect();
29         virtual std::string effect_type_id() const { return "PaddingEffect"; }
30         std::string output_fragment_shader();
31         void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num);
32
33         virtual bool needs_linear_light() const;
34         virtual bool needs_srgb_primaries() const;
35         virtual AlphaHandling alpha_handling() const;
36         
37         virtual bool changes_output_size() const { return true; }
38         virtual bool sets_virtual_output_size() const { return false; }
39         virtual void get_output_size(unsigned *width, unsigned *height, unsigned *virtual_width, unsigned *virtual_height) const;
40         virtual void inform_input_size(unsigned input_num, unsigned width, unsigned height);
41
42 private:
43         RGBATuple border_color;
44         int input_width, input_height;
45         int output_width, output_height;
46         float top, left;
47 };
48
49 class IntegralPaddingEffect : public PaddingEffect {
50 public:
51         IntegralPaddingEffect();
52         virtual std::string effect_type_id() const { return "IntegralPaddingEffect"; }
53         virtual bool one_to_one_sampling() const { return true; }
54         virtual bool set_int(const std::string&, int value);
55         virtual bool set_float(const std::string &key, float value);
56 };
57
58 }  // namespace movit
59
60 #endif // !defined(_MOVIT_PADDING_EFFECT_H)