]> git.sesse.net Git - movit/blob - ycbcr_input.h
Propagate size correctly across effects that change output size.
[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 <epoxy/gl.h>
9 #include <assert.h>
10 #include <string>
11
12 #include "effect.h"
13 #include "effect_chain.h"
14 #include "image_format.h"
15 #include "input.h"
16 #include "ycbcr.h"
17
18 namespace movit {
19
20 class ResourcePool;
21
22 class YCbCrInput : public Input {
23 public:
24         YCbCrInput(const ImageFormat &image_format,
25                    const YCbCrFormat &ycbcr_format,
26                    unsigned width, unsigned height);
27         ~YCbCrInput();
28
29         virtual std::string effect_type_id() const { return "YCbCrInput"; }
30
31         virtual bool can_output_linear_gamma() const { return false; }
32         virtual AlphaHandling alpha_handling() const { return OUTPUT_BLANK_ALPHA; }
33
34         std::string output_fragment_shader();
35
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);
38
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; }
44
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.
49         //
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)
56         {
57                 assert(channel >= 0 && channel < 3);
58                 this->pixel_data[channel] = pixel_data;
59                 this->pbos[channel] = pbo;
60                 invalidate_pixel_data();
61         }
62
63         void invalidate_pixel_data();
64
65         void set_pitch(unsigned channel, unsigned pitch) {
66                 assert(channel >= 0 && channel < 3);
67                 this->pitch[channel] = pitch;
68                 invalidate_pixel_data();
69         }
70
71         virtual void inform_added(EffectChain *chain)
72         {
73                 resource_pool = chain->get_resource_pool();
74         }
75
76         bool set_int(const std::string& key, int value);
77
78 private:
79         ImageFormat image_format;
80         YCbCrFormat ycbcr_format;
81         GLuint pbos[3], texture_num[3];
82
83         unsigned width, height, widths[3], heights[3];
84         const unsigned char *pixel_data[3];
85         unsigned pitch[3];
86         ResourcePool *resource_pool;
87 };
88
89 }  // namespace movit
90
91 #endif // !defined(_MOVIT_YCBCR_INPUT_H)