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