]> git.sesse.net Git - movit/blob - padding_effect.h
Add even long convenience overloads for add_effect().
[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 texture border, and then given a user-specific color;
9 // by default, full transparent. You can give a fractional border size (non-integral
10 // "top" or "left" offset) if you wish, which will give you linear interpolation of
11 // both pixel data of and the border. Furthermore, you can offset where the border falls
12 // by using the "border_offset_{top,bottom,left,right}" settings; this is particularly
13 // useful if you use ResampleEffect earlier in the chain for high-quality fractional-pixel
14 // translation and just want PaddingEffect to get the border right.
15 //
16 // The border color is taken to be in linear gamma, sRGB, with premultiplied alpha.
17 // You may not change it after calling finalize(), since that could change the
18 // graph (need_linear_light() etc. depend on the border color you choose).
19 //
20 // IntegralPaddingEffect is like PaddingEffect, except that "top" and "left" parameters
21 // are int parameters instead of float. This allows it to guarantee one-to-one sampling,
22 // which can speed up processing by allowing more effect passes to be collapsed.
23 // border_offset_* are still allowed to be float, although you should beware that if
24 // you set e.g. border_offset_top to a negative value, you will be sampling outside
25 // the edge and will read data that is undefined in one-to-one-mode (could be
26 // edge repeat, could be something else). With regular PaddingEffect, such samples
27 // are guaranteed to be edge repeat.
28
29 #include <epoxy/gl.h>
30 #include <string>
31
32 #include "effect.h"
33
34 namespace movit {
35
36 class PaddingEffect : public Effect {
37 public:
38         PaddingEffect();
39         virtual std::string effect_type_id() const { return "PaddingEffect"; }
40         std::string output_fragment_shader();
41         void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num);
42
43         virtual bool needs_linear_light() const;
44         virtual bool needs_srgb_primaries() const;
45         virtual AlphaHandling alpha_handling() const;
46         
47         virtual bool changes_output_size() const { return true; }
48         virtual bool sets_virtual_output_size() const { return false; }
49         virtual void get_output_size(unsigned *width, unsigned *height, unsigned *virtual_width, unsigned *virtual_height) const;
50         virtual void inform_input_size(unsigned input_num, unsigned width, unsigned height);
51
52 private:
53         RGBATuple border_color;
54         int input_width, input_height;
55         int output_width, output_height;
56         float top, left;
57         float border_offset_top, border_offset_left;
58         float border_offset_bottom, border_offset_right;
59         float uniform_offset[2], uniform_scale[2];
60         float uniform_normalized_coords_to_texels[2];
61         float uniform_offset_bottomleft[2], uniform_offset_topright[2];
62 };
63
64 class IntegralPaddingEffect : public PaddingEffect {
65 public:
66         IntegralPaddingEffect();
67         virtual std::string effect_type_id() const { return "IntegralPaddingEffect"; }
68         virtual bool one_to_one_sampling() const { return true; }
69         virtual bool set_int(const std::string&, int value);
70         virtual bool set_float(const std::string &key, float value);
71 };
72
73 }  // namespace movit
74
75 #endif // !defined(_MOVIT_PADDING_EFFECT_H)