X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=deinterlace_effect.h;h=773d6ad2e315716ae26a0bdc922be56500136ae2;hp=793532242aa8d56321d791da02ab06e53bca37f5;hb=refs%2Fheads%2Fmaster;hpb=c06f1c4cc39bbebe13fe8e42a9278a55b5d0a216 diff --git a/deinterlace_effect.h b/deinterlace_effect.h index 7935322..773d6ad 100644 --- a/deinterlace_effect.h +++ b/deinterlace_effect.h @@ -52,19 +52,27 @@ // parity, so all the others are implicit). #include +#include #include #include "effect.h" namespace movit { +class DeinterlaceComputeEffect; + class DeinterlaceEffect : public Effect { public: DeinterlaceEffect(); - virtual std::string effect_type_id() const { return "DeinterlaceEffect"; } - std::string output_fragment_shader(); + std::string effect_type_id() const override { return "DeinterlaceEffect"; } + std::string output_fragment_shader() override; + + // Replaces itself with DeinterlaceComputeEffect if compute shaders are supported. + // Otherwise, does nothing. + void rewrite_graph(EffectChain *graph, Node *self) override; + bool set_int(const std::string &key, int value) override; - void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num); + void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num) override; // First = before previous, second = previous, third = current, // fourth = next, fifth = after next. These are treated symmetrically, @@ -72,19 +80,24 @@ public: // // Note that if you have interlaced _frames_ and not _fields_, you will // need to pull them apart first, for instance with SliceEffect. - virtual unsigned num_inputs() const { return 5; } - virtual bool needs_texture_bounce() const { return true; } - virtual bool changes_output_size() const { return true; } + unsigned num_inputs() const override { return 5; } + bool needs_texture_bounce() const override { return true; } + bool changes_output_size() const override { return true; } - virtual AlphaHandling alpha_handling() const { return INPUT_PREMULTIPLIED_ALPHA_KEEP_BLANK; } + AlphaHandling alpha_handling() const override { return INPUT_PREMULTIPLIED_ALPHA_KEEP_BLANK; } - virtual void inform_input_size(unsigned input_num, unsigned width, unsigned height); - virtual void get_output_size(unsigned *width, unsigned *height, - unsigned *virtual_width, unsigned *virtual_height) const; + void inform_input_size(unsigned input_num, unsigned width, unsigned height) override; + void get_output_size(unsigned *width, unsigned *height, + unsigned *virtual_width, unsigned *virtual_height) const override; enum FieldPosition { TOP = 0, BOTTOM = 1 }; private: + // If compute shaders are supported, contains the actual effect. + // If not, nullptr. + std::unique_ptr compute_effect_owner; + DeinterlaceComputeEffect *compute_effect = nullptr; + unsigned widths[5], heights[5]; // See file-level comment for explanation of this option. @@ -114,6 +127,50 @@ private: float other_offset[3]; }; +// A compute shader implementation of DeinterlaceEffect. It saves a bunch of loads +// since it can share them between neighboring pixels (and also does not need +// texture bounce), so it has the potential to be faster, although exactly how +// much depends on your chain and other factors. DeinterlaceEffect will +// automatically become a proxy to DeinterlaceComputeEffect if your system +// supports compute shaders. +class DeinterlaceComputeEffect : public Effect { +public: + DeinterlaceComputeEffect(); + std::string effect_type_id() const override { return "DeinterlaceComputeEffect"; } + std::string output_fragment_shader() override; + + void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num) override; + + unsigned num_inputs() const override { return 5; } + bool changes_output_size() const override { return true; } + bool is_compute_shader() const override { return true; } + void get_compute_dimensions(unsigned output_width, unsigned output_height, + unsigned *x, unsigned *y, unsigned *z) const override; + + AlphaHandling alpha_handling() const override { return INPUT_PREMULTIPLIED_ALPHA_KEEP_BLANK; } + + void inform_input_size(unsigned input_num, unsigned width, unsigned height) override; + void get_output_size(unsigned *width, unsigned *height, + unsigned *virtual_width, unsigned *virtual_height) const override; + + enum FieldPosition { TOP = 0, BOTTOM = 1 }; + +private: + unsigned widths[5], heights[5]; + + // See file-level comment for explanation of this option. + bool enable_spatial_interlacing_check; + + // Which field the current input (the middle one) is. + FieldPosition current_field_position; + + // Offset for one pixel in the horizontal and verticla direction (1/width, 1/height). + float inv_width, inv_height; + + // For evaluating the low-pass filter (in the current field). Four taps. + float current_field_vertical_offset; +}; + } // namespace movit #endif // !defined(_MOVIT_DEINTERLACE_EFFECT_H)