]> git.sesse.net Git - nageru/blob - futatabi/ycbcr_converter.h
Merge remote-tracking branch 'futatabi/master'
[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/ycbcr_input.h>
7
8 namespace movit {
9
10 class EffectChain;
11 class MixEffect;
12 class ResourcePool;
13 struct YCbCrFormat;
14
15 }  // namespace movit
16
17 struct Frame;
18
19 class YCbCrConverter {
20 public:
21         enum OutputMode {
22                 OUTPUT_TO_RGBA,         // One texture (bottom-left origin): RGBA
23                 OUTPUT_TO_SEMIPLANAR,   // Two textures (top-left origin):   Y, CbCr
24                 OUTPUT_TO_DUAL_YCBCR    // Two textures (top-left origin):   Y'CbCr, Y'CbCr
25         };
26         YCbCrConverter(OutputMode output_mode, movit::ResourcePool *resource_pool);
27
28         // Returns the appropriate chain for rendering.
29         movit::EffectChain *prepare_chain_for_conversion(std::shared_ptr<Frame> frame);
30         movit::EffectChain *prepare_chain_for_fade(std::shared_ptr<Frame> frame, std::shared_ptr<Frame> secondary_frame, float fade_alpha);
31
32         // <tex> must be interleaved Y'CbCr.
33         movit::EffectChain *prepare_chain_for_fade_from_texture(GLuint tex, std::shared_ptr<Frame> secondary_frame, float fade_alpha);
34
35 private:
36         movit::YCbCrFormat ycbcr_format;
37
38         // Effectively only converts from 4:2:2 to 4:4:4.
39         // TODO: Have a separate version with ResampleEffect, for scaling?
40         std::unique_ptr<movit::EffectChain> planar_chain, semiplanar_chain;
41         movit::YCbCrInput *ycbcr_planar_input, *ycbcr_semiplanar_input;
42
43         // These do fades, parametrized on whether the two inputs are planar
44         // or semiplanar.
45         struct FadeChain {
46                 std::unique_ptr<movit::EffectChain> chain;
47                 movit::YCbCrInput *input[2];
48                 movit::MixEffect *mix_effect;
49         };
50         FadeChain fade_chains[2][2];
51
52         // These do fades, where the first input is interleaved and the second is
53         // either planar or semiplanar.
54         FadeChain interleaved_fade_chains[2];
55 };
56
57 // TODO: make private
58 void setup_input_for_frame(std::shared_ptr<Frame> frame, const movit::YCbCrFormat &ycbcr_format, movit::YCbCrInput *input);
59
60 #endif  // !defined(_YCBCR_CONVERTER_H)