1 #ifndef _MOVIT_YCBCR_INPUT_H
2 #define _MOVIT_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.
13 #include "effect_chain.h"
14 #include "image_format.h"
22 class YCbCrInput : public Input {
24 YCbCrInput(const ImageFormat &image_format,
25 const YCbCrFormat &ycbcr_format,
26 unsigned width, unsigned height);
29 virtual std::string effect_type_id() const { return "YCbCrInput"; }
31 virtual bool can_output_linear_gamma() const { return false; }
32 virtual AlphaHandling alpha_handling() const { return OUTPUT_BLANK_ALPHA; }
34 std::string output_fragment_shader();
36 // Uploads the texture if it has changed since last time.
37 void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num);
39 unsigned get_width() const { return width; }
40 unsigned get_height() const { return height; }
41 Colorspace get_color_space() const { return image_format.color_space; }
42 GammaCurve get_gamma_curve() const { return image_format.gamma_curve; }
43 virtual bool can_supply_mipmaps() const { return false; }
45 // Tells the input where to fetch the actual pixel data. Note that if you change
46 // this data, you must either call set_pixel_data() again (using the same pointer
47 // is fine), or invalidate_pixel_data(). Otherwise, the texture won't be re-uploaded
48 // on subsequent frames.
50 // The data can either be a regular pointer (if pbo==0), or a byte offset
51 // into a PBO. The latter will allow you to start uploading the texture data
52 // asynchronously to the GPU, if you have any CPU-intensive work between the
53 // call to set_pixel_data() and the actual rendering. In either case,
54 // the pointer (and PBO, if set) has to be valid at the time of the render call.
55 void set_pixel_data(unsigned channel, const unsigned char *pixel_data, GLuint pbo = 0)
57 assert(channel >= 0 && channel < 3);
58 this->pixel_data[channel] = pixel_data;
59 this->pbos[channel] = pbo;
60 invalidate_pixel_data();
63 void invalidate_pixel_data();
65 void set_pitch(unsigned channel, unsigned pitch) {
66 assert(channel >= 0 && channel < 3);
67 this->pitch[channel] = pitch;
68 invalidate_pixel_data();
71 virtual void inform_added(EffectChain *chain)
73 resource_pool = chain->get_resource_pool();
76 bool set_int(const std::string& key, int value);
79 ImageFormat image_format;
80 YCbCrFormat ycbcr_format;
81 GLuint pbos[3], texture_num[3];
83 unsigned width, height, widths[3], heights[3];
84 const unsigned char *pixel_data[3];
86 ResourcePool *resource_pool;
91 #endif // !defined(_MOVIT_YCBCR_INPUT_H)