X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=dither_effect.h;h=b1bbbff4168cec94708557c32c2f2f1d93dcef9a;hp=d0f2423c26831c1705475f49052db0eeb7d496d0;hb=dff7a05663a3c9c32cf1d75b928fac3ebe384ffd;hpb=ff9e68a3f5abb179bd7bf9fb84df48327f148583 diff --git a/dither_effect.h b/dither_effect.h index d0f2423..b1bbbff 100644 --- a/dither_effect.h +++ b/dither_effect.h @@ -1,5 +1,5 @@ -#ifndef _DITHER_EFFECT_H -#define _DITHER_EFFECT_H 1 +#ifndef _MOVIT_DITHER_EFFECT_H +#define _MOVIT_DITHER_EFFECT_H 1 // Implements simple rectangular-PDF dither. // @@ -43,25 +43,46 @@ // like many LCD monitors do, but it starts to get very hairy, again, for limited gains.) // The dither is also deterministic across runs. +#include +#include + #include "effect.h" +namespace movit { + class DitherEffect : public Effect { -public: +private: + // Should not be instantiated by end users; + // call EffectChain::set_dither_bits() instead. DitherEffect(); + friend class EffectChain; + +public: ~DitherEffect(); - virtual std::string effect_type_id() const { return "DitherEffect"; } - std::string output_fragment_shader(); + std::string effect_type_id() const override { return "DitherEffect"; } + std::string output_fragment_shader() override; - void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num); + // Note that if we did error diffusion, we'd actually want to diffuse the + // premultiplied error. However, we need to do dithering in the same + // space as quantization, whether that be pre- or postmultiply. + AlphaHandling alpha_handling() const override { return DONT_CARE_ALPHA_TYPE; } + bool strong_one_to_one_sampling() const override { return true; } + + void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num) override; private: void update_texture(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num); int width, height, num_bits; int last_width, last_height, last_num_bits; + int texture_width, texture_height; GLuint texnum; - bool need_texture_update; + float uniform_round_fac, uniform_inv_round_fac; + float uniform_tc_scale[2]; + GLint uniform_dither_tex; }; -#endif // !defined(_DITHER_EFFECT_H) +} // namespace movit + +#endif // !defined(_MOVIT_DITHER_EFFECT_H)