2 #define _YCBCR_INPUT_H 1
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.
11 // Which formula for Y' to use.
12 YCbCrLumaCoefficients luma_coefficients;
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.
19 // Sampling factors for chroma components. For no subsampling (4:4:4),
21 unsigned chroma_subsampling_x, chroma_subsampling_y;
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 cb_x_position, cb_y_position;
26 float cr_x_position, cr_y_position;
29 class YCbCrInput : public Input {
31 YCbCrInput(const ImageFormat &image_format,
32 const YCbCrFormat &ycbcr_format,
33 unsigned width, unsigned height);
36 virtual std::string effect_type_id() const { return "YCbCrInput"; }
38 // Create the texture itself. We cannot do this in the constructor,
39 // because we don't necessarily know all the settings (sRGB texture,
40 // mipmap generation) at that point.
43 virtual bool can_output_linear_gamma() const { return false; }
45 std::string output_fragment_shader();
47 // Uploads the texture if it has changed since last time.
48 void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num);
50 unsigned get_width() const { return width; }
51 unsigned get_height() const { return height; }
52 Colorspace get_color_space() const { return image_format.color_space; }
53 GammaCurve get_gamma_curve() const { return image_format.gamma_curve; }
55 // Tells the input where to fetch the actual pixel data. Note that if you change
56 // this data, you must either call set_pixel_data() again (using the same pointer
57 // is fine), or invalidate_pixel_data(). Otherwise, the texture won't be re-uploaded
58 // on subsequent frames.
59 void set_pixel_data(unsigned channel, const unsigned char *pixel_data)
61 assert(channel >= 0 && channel < 3);
62 this->pixel_data[channel] = pixel_data;
63 invalidate_pixel_data();
66 void invalidate_pixel_data()
71 void set_pitch(unsigned channel, unsigned pitch) {
72 assert(channel >= 0 && channel < 3);
73 if (this->pitch[channel] != pitch) {
74 this->pitch[channel] = pitch;
75 needs_pbo_recreate = true;
80 ImageFormat image_format;
81 YCbCrFormat ycbcr_format;
82 GLuint pbos[3], texture_num[3];
83 bool needs_update, needs_pbo_recreate, finalized;
87 unsigned width, height, widths[3], heights[3];
88 const unsigned char *pixel_data[3];
92 #endif // !defined(_YCBCR_INPUT_H)