]> git.sesse.net Git - movit/blob - ycbcr_input.h
Fix some outdated comments in GammaExpansionEffect.
[movit] / ycbcr_input.h
1 #ifndef _MOVIT_YCBCR_INPUT_H
2 #define _MOVIT_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 <GL/glew.h>
9 #include <assert.h>
10 #include <string>
11
12 #include "effect.h"
13 #include "image_format.h"
14 #include "input.h"
15
16 struct YCbCrFormat {
17         // Which formula for Y' to use.
18         YCbCrLumaCoefficients luma_coefficients;
19
20         // If true, assume Y'CbCr coefficients are full-range, ie. go from 0 to 255
21         // instead of the limited 220/225 steps in classic MPEG. For instance,
22         // JPEG uses the Rec. 601 luma coefficients, but full range.
23         bool full_range;
24
25         // Sampling factors for chroma components. For no subsampling (4:4:4),
26         // set both to 1.
27         unsigned chroma_subsampling_x, chroma_subsampling_y;
28
29         // Positioning of the chroma samples. MPEG-1 and JPEG is (0.5, 0.5);
30         // MPEG-2 and newer typically are (0.0, 0.5).
31         float cb_x_position, cb_y_position;
32         float cr_x_position, cr_y_position;
33 };
34
35 class YCbCrInput : public Input {
36 public:
37         YCbCrInput(const ImageFormat &image_format,
38                    const YCbCrFormat &ycbcr_format,
39                    unsigned width, unsigned height);
40         ~YCbCrInput();
41
42         virtual std::string effect_type_id() const { return "YCbCrInput"; }
43
44         // Create the texture itself. We cannot do this in the constructor,
45         // because we don't necessarily know all the settings (sRGB texture,
46         // mipmap generation) at that point.
47         void finalize();
48
49         virtual bool can_output_linear_gamma() const { return false; }
50         virtual AlphaHandling alpha_handling() const { return OUTPUT_BLANK_ALPHA; }
51
52         std::string output_fragment_shader();
53
54         // Uploads the texture if it has changed since last time.
55         void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num);
56
57         unsigned get_width() const { return width; }
58         unsigned get_height() const { return height; }
59         Colorspace get_color_space() const { return image_format.color_space; }
60         GammaCurve get_gamma_curve() const { return image_format.gamma_curve; }
61
62         // Tells the input where to fetch the actual pixel data. Note that if you change
63         // this data, you must either call set_pixel_data() again (using the same pointer
64         // is fine), or invalidate_pixel_data(). Otherwise, the texture won't be re-uploaded
65         // on subsequent frames.
66         void set_pixel_data(unsigned channel, const unsigned char *pixel_data)
67         {
68                 assert(channel >= 0 && channel < 3);
69                 this->pixel_data[channel] = pixel_data;
70                 invalidate_pixel_data();
71         }
72
73         void invalidate_pixel_data()
74         {
75                 needs_update = true;
76         }
77
78         void set_pitch(unsigned channel, unsigned pitch) {
79                 assert(channel >= 0 && channel < 3);
80                 if (this->pitch[channel] != pitch) {
81                         this->pitch[channel] = pitch;
82                         needs_pbo_recreate = true;
83                 }
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(_MOVIT_YCBCR_INPUT_H)