]> git.sesse.net Git - nageru/blob - futatabi/ycbcr_converter.h
Log a warning when we kill a client that is not keeping up.
[nageru] / futatabi / ycbcr_converter.h
1 #ifndef _YCBCR_CONVERTER_H
2 #define _YCBCR_CONVERTER_H 1
3
4 #include <epoxy/gl.h>
5 #include <memory>
6 #include <movit/effect.h>
7 #include <movit/ycbcr_input.h>
8
9 namespace movit {
10
11 class EffectChain;
12 class MixEffect;
13 class ResourcePool;
14 class WhiteBalanceEffect;
15 struct YCbCrFormat;
16
17 }  // namespace movit
18
19 struct Frame;
20
21 class YCbCrConverter {
22 public:
23         enum OutputMode {
24                 OUTPUT_TO_RGBA,         // One texture (bottom-left origin): RGBA
25                 OUTPUT_TO_SEMIPLANAR,   // Two textures (top-left origin):   Y, CbCr
26                 OUTPUT_TO_DUAL_YCBCR    // Two textures (top-left origin):   Y'CbCr, Y'CbCr
27         };
28         YCbCrConverter(OutputMode output_mode, movit::ResourcePool *resource_pool);
29
30         // Returns the appropriate chain for rendering. Fades apply white balance,
31         // straight-up conversion does not.
32         movit::EffectChain *prepare_chain_for_conversion(std::shared_ptr<Frame> frame);
33         movit::EffectChain *prepare_chain_for_fade(std::shared_ptr<Frame> frame, std::shared_ptr<Frame> secondary_frame, float fade_alpha);
34
35         // <tex> must be interleaved Y'CbCr.
36         movit::EffectChain *prepare_chain_for_fade_from_texture(GLuint tex, movit::RGBTriplet neutral_color, unsigned width, unsigned height, std::shared_ptr<Frame> secondary_frame, float fade_alpha);
37
38 private:
39         movit::YCbCrFormat ycbcr_format;
40
41         // Effectively only converts from 4:2:2 to 4:4:4.
42         // TODO: Have a separate version with ResampleEffect, for scaling?
43         std::unique_ptr<movit::EffectChain> planar_chain, semiplanar_chain;
44         movit::YCbCrInput *ycbcr_planar_input, *ycbcr_semiplanar_input;
45
46         // These do fades, parametrized on whether the two inputs are planar
47         // or semiplanar.
48         struct FadeChain {
49                 std::unique_ptr<movit::EffectChain> chain;
50                 movit::YCbCrInput *input[2];
51                 movit::WhiteBalanceEffect *wb_effect[2];
52                 movit::MixEffect *mix_effect;
53         };
54         FadeChain fade_chains[2][2];
55
56         // These do fades, where the first input is interleaved and the second is
57         // either planar or semiplanar.
58         FadeChain interleaved_fade_chains[2];
59 };
60
61 // TODO: make private
62 void setup_input_for_frame(std::shared_ptr<Frame> frame, const movit::YCbCrFormat &ycbcr_format, movit::YCbCrInput *input);
63
64 #endif  // !defined(_YCBCR_CONVERTER_H)