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(); effect_type_id()39 std::string effect_type_id() const override { return "PaddingEffect"; } 40 std::string output_fragment_shader() override; 41 void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num) override; 42 43 bool needs_linear_light() const override; 44 bool needs_srgb_primaries() const override; 45 AlphaHandling alpha_handling() const override; 46 changes_output_size()47 bool changes_output_size() const override { return true; } sets_virtual_output_size()48 bool sets_virtual_output_size() const override { return false; } 49 void get_output_size(unsigned *width, unsigned *height, unsigned *virtual_width, unsigned *virtual_height) const override; 50 void inform_input_size(unsigned input_num, unsigned width, unsigned height) override; 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(); effect_type_id()67 std::string effect_type_id() const override { return "IntegralPaddingEffect"; } one_to_one_sampling()68 bool one_to_one_sampling() const override { return true; } 69 bool set_int(const std::string&, int value) override; 70 bool set_float(const std::string &key, float value) override; 71 }; 72 73 } // namespace movit 74 75 #endif // !defined(_MOVIT_PADDING_EFFECT_H) 76