Output the graph in dot form at finalize time.
[movit] / ycbcr_input.h
1 #ifndef _YCBCR_INPUT_H
2 #define _YCBCR_INPUT_H 1
3
4 // YCbCrInput is for handling planar 8-bit Y'CbCr (also sometimes, usually rather
5 // imprecisely, called “YUV”), which is typically what you get from a video decoder.
6 // It upsamples planes as needed, using the default linear upsampling OpenGL gives you.
7
8 #include "input.h"
9
10 struct YCbCrFormat {
11         // Which formula for Y' to use.
12         YCbCrLumaCoefficients luma_coefficients;
13
14         // If true, assume Y'CbCr coefficients are full-range, ie. go from 0 to 255
15         // instead of the limited 220/225 steps in classic MPEG. For instance,
16         // JPEG uses the Rec. 601 luma coefficients, but full range.
17         bool full_range;
18
19         // Sampling factors for chroma components. For no subsampling (4:4:4),
20         // set both to 1.
21         unsigned chroma_subsampling_x, chroma_subsampling_y;
22
23         // Positioning of the chroma samples. MPEG-1 and JPEG is (0.5, 0.5);
24         // MPEG-2 and newer typically are (0.0, 0.5).
25         float chroma_x_position, chroma_y_position;
26 };
27
28 class YCbCrInput : public Input {
29 public:
30         YCbCrInput(const ImageFormat &image_format,
31                    const YCbCrFormat &ycbcr_format,
32                    unsigned width, unsigned height);
33
34         virtual std::string effect_type_id() const { return "YCbCrInput"; }
35
36         // Create the texture itself. We cannot do this in the constructor,
37         // because we don't necessarily know all the settings (sRGB texture,
38         // mipmap generation) at that point.
39         void finalize();
40
41         virtual bool can_output_linear_gamma() const { return false; }
42
43         std::string output_fragment_shader();
44
45         // Uploads the texture if it has changed since last time.
46         void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num);
47
48         ColorSpace get_color_space() const { return image_format.color_space; }
49         GammaCurve get_gamma_curve() const { return image_format.gamma_curve; }
50
51         // Tells the input where to fetch the actual pixel data. Note that if you change
52         // this data, you must either call set_pixel_data() again (using the same pointer
53         // is fine), or invalidate_pixel_data(). Otherwise, the texture won't be re-uploaded
54         // on subsequent frames.
55         void set_pixel_data(unsigned channel, const unsigned char *pixel_data)
56         {
57                 assert(channel >= 0 && channel < 3);
58                 this->pixel_data[channel] = pixel_data;
59                 invalidate_pixel_data();
60         }
61
62         void invalidate_pixel_data()
63         {
64                 needs_update = true;
65         }
66
67         const unsigned char *get_pixel_data(unsigned channel) const
68         {
69                 assert(channel >= 0 && channel < 3);
70                 return pixel_data[channel];
71         }
72
73         void set_pitch(unsigned channel, unsigned pitch) {
74                 assert(channel >= 0 && channel < 3);
75                 if (this->pitch[channel] != pitch) {
76                         this->pitch[channel] = pitch;
77                         needs_pbo_recreate = true;
78                 }
79         }
80
81         unsigned get_pitch(unsigned channel) {
82                 assert(channel >= 0 && channel < 3);
83                 return pitch[channel];
84         }
85
86 private:
87         ImageFormat image_format;
88         YCbCrFormat ycbcr_format;
89         GLuint pbos[3], texture_num[3];
90         bool needs_update, needs_pbo_recreate, finalized;
91
92         int needs_mipmaps;
93
94         unsigned width, height, widths[3], heights[3];
95         const unsigned char *pixel_data[3];
96         unsigned pitch[3];
97 };
98
99 #endif // !defined(_YCBCR_INPUT_H)