Try to adjust the mip levels to get box blur for free as needed.
[movit] / effect_chain.h
1 #ifndef _EFFECT_CHAIN_H
2 #define _EFFECT_CHAIN_H 1
3
4 #include <vector>
5
6 #include "effect.h"
7 #include "effect_id.h"
8
9 enum PixelFormat { FORMAT_RGB, FORMAT_RGBA, FORMAT_BGR, FORMAT_BGRA };
10
11 enum ColorSpace {
12         COLORSPACE_sRGB = 0,
13         COLORSPACE_REC_709 = 0,  // Same as sRGB.
14         COLORSPACE_REC_601_525 = 1,
15         COLORSPACE_REC_601_625 = 2,
16 };
17
18 enum GammaCurve {
19         GAMMA_LINEAR = 0,
20         GAMMA_sRGB = 1,
21         GAMMA_REC_601 = 2,
22         GAMMA_REC_709 = 2,  // Same as Rec. 601.
23 };
24
25 struct ImageFormat {
26         PixelFormat pixel_format;
27         ColorSpace color_space;
28         GammaCurve gamma_curve;
29 };
30
31 class EffectChain {
32 public:
33         EffectChain(unsigned width, unsigned height);
34
35         // input, effects, output, finalize need to come in that specific order.
36
37         void add_input(const ImageFormat &format);
38
39         // The returned pointer is owned by EffectChain.
40         Effect *add_effect(EffectId effect);
41
42         void add_output(const ImageFormat &format);
43         void finalize();
44
45         //void render(unsigned char *src, unsigned char *dst);
46         void render_to_screen(unsigned char *src);
47
48 private:
49         struct Phase {
50                 GLint glsl_program_num;
51                 bool input_needs_mipmaps;
52                 unsigned start, end;
53         };
54
55         void normalize_to_linear_gamma();
56         void normalize_to_srgb();
57
58         // Create a GLSL program computing effects [start, end>.
59         Phase compile_glsl_program(unsigned start_index, unsigned end_index);
60
61         unsigned width, height;
62         ImageFormat input_format, output_format;
63         std::vector<Effect *> effects;
64
65         GLuint source_image_num;
66         bool use_srgb_texture_format;
67
68         GLuint fbo;
69         GLuint temp_textures[2];
70
71         std::vector<Phase> phases;
72
73         GLenum format, bytes_per_pixel;
74         bool finalized;
75
76         // Used during the building of the effect chain.
77         ColorSpace current_color_space;
78         GammaCurve current_gamma_curve; 
79 };
80
81
82 #endif // !defined(_EFFECT_CHAIN_H)