]> git.sesse.net Git - movit/blob - resample_effect.h
Add SHELL override from autoconf, since otherwise libtool might break on systems...
[movit] / resample_effect.h
1 #ifndef _MOVIT_RESAMPLE_EFFECT_H
2 #define _MOVIT_RESAMPLE_EFFECT_H 1
3
4 // High-quality image resizing, either up or down.
5 //
6 // The default scaling offered by the GPU (and as used in ResizeEffect)
7 // is bilinear (optionally mipmapped), which is not the highest-quality
8 // choice, especially for upscaling. ResampleEffect offers the three-lobed
9 // Lanczos kernel, which is among the most popular choices in image
10 // processing. While it does have its weaknesses, in particular a certain
11 // ringing/sharpening effect with artifacts that accumulate over several
12 // consecutive resizings, it is generally regarded as the best tradeoff.
13 //
14 // Works in two passes; first horizontal, then vertical (ResampleEffect,
15 // which is what the user is intended to use, instantiates two copies of
16 // SingleResamplePassEffect behind the scenes).
17
18 #include <GL/glew.h>
19 #include <assert.h>
20 #include <stddef.h>
21 #include <string>
22
23 #include "effect.h"
24
25 class EffectChain;
26 class Node;
27 class SingleResamplePassEffect;
28
29 class ResampleEffect : public Effect {
30 public:
31         ResampleEffect();
32
33         virtual std::string effect_type_id() const { return "ResampleEffect"; }
34
35         // We want this for the same reason as ResizeEffect; we could end up scaling
36         // down quite a lot.
37         virtual bool needs_texture_bounce() const { return true; }
38         virtual bool needs_srgb_primaries() const { return false; }
39
40         virtual void inform_input_size(unsigned input_num, unsigned width, unsigned height);
41
42         virtual std::string output_fragment_shader() {
43                 assert(false);
44         }
45         virtual void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num) {
46                 assert(false);
47         }
48
49         virtual void rewrite_graph(EffectChain *graph, Node *self);
50         virtual bool set_float(const std::string &key, float value);
51         
52 private:
53         void update_size();
54         
55         SingleResamplePassEffect *hpass, *vpass;
56         int input_width, input_height, output_width, output_height;
57 };
58
59 class SingleResamplePassEffect : public Effect {
60 public:
61         // If parent is non-NULL, calls to inform_input_size will be forwarded,
62         // so that it can inform both passes about the right input and output
63         // resolutions.
64         SingleResamplePassEffect(ResampleEffect *parent);
65         ~SingleResamplePassEffect();
66         virtual std::string effect_type_id() const { return "SingleResamplePassEffect"; }
67
68         std::string output_fragment_shader();
69
70         virtual bool needs_texture_bounce() const { return true; }
71         virtual bool needs_srgb_primaries() const { return false; }
72         virtual AlphaHandling alpha_handling() const { return INPUT_PREMULTIPLIED_ALPHA_KEEP_BLANK; }
73
74         virtual void inform_input_size(unsigned input_num, unsigned width, unsigned height) {
75                 if (parent != NULL) {
76                         parent->inform_input_size(input_num, width, height);
77                 }
78         }
79         virtual bool changes_output_size() const { return true; }
80
81         virtual void get_output_size(unsigned *width, unsigned *height, unsigned *virtual_width, unsigned *virtual_height) const {
82                 *virtual_width = *width = this->output_width;
83                 *virtual_height = *height = this->output_height;
84         }
85
86         void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num);
87         
88         enum Direction { HORIZONTAL = 0, VERTICAL = 1 };
89
90 private:
91         void update_texture(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num);
92
93         ResampleEffect *parent;
94         Direction direction;
95         GLuint texnum;
96         int input_width, input_height, output_width, output_height;
97         int last_input_width, last_input_height, last_output_width, last_output_height;
98         int src_bilinear_samples, num_loops;
99         float slice_height;
100 };
101
102 #endif // !defined(_MOVIT_RESAMPLE_EFFECT_H)