xbmc
YUV2RGBShaderGL.h
1 /*
2  * Copyright (C) 2007-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "ConversionMatrix.h"
12 #include "GLSLOutput.h"
13 #include "ShaderFormats.h"
14 #include "cores/VideoSettings.h"
15 #include "guilib/Shader.h"
16 #include "utils/TransformMatrix.h"
17 
18 #include <memory>
19 
20 extern "C" {
21 #include <libavutil/pixfmt.h>
22 #include <libavutil/mastering_display_metadata.h>
23 }
24 
25 class CConvertMatrix;
26 
27 namespace Shaders {
28 namespace GL
29 {
30 
32 {
33 public:
34  BaseYUV2RGBGLSLShader(bool rect,
35  EShaderFormat format,
36  bool stretch,
37  AVColorPrimaries dst,
38  AVColorPrimaries src,
39  bool toneMap,
40  ETONEMAPMETHOD toneMapMethod,
41  std::shared_ptr<GLSLOutput> output);
42  ~BaseYUV2RGBGLSLShader() override;
43 
44  void SetField(int field) { m_field = field; }
45  void SetWidth(int w) { m_width = w; }
46  void SetHeight(int h) { m_height = h; }
47 
48  void SetColParams(AVColorSpace colSpace, int bits, bool limited, int textureBits);
49  void SetBlack(float black) { m_black = black; }
50  void SetContrast(float contrast) { m_contrast = contrast; }
51  void SetNonLinStretch(float stretch) { m_stretch = stretch; }
52  void SetDisplayMetadata(bool hasDisplayMetadata,
53  const AVMasteringDisplayMetadata& displayMetadata,
54  bool hasLightMetadata,
55  AVContentLightMetadata lightMetadata);
56  void SetToneMapParam(ETONEMAPMETHOD method, float param);
57  float GetLuminanceValue() const;
58 
59  void SetConvertFullColorRange(bool convertFullRange) { m_convertFullRange = convertFullRange; }
60 
61  GLint GetVertexLoc() { return m_hVertex; }
62  GLint GetYcoordLoc() { return m_hYcoord; }
63  GLint GetUcoordLoc() { return m_hUcoord; }
64  GLint GetVcoordLoc() { return m_hVcoord; }
65 
66  void SetMatrices(const GLfloat *p, const GLfloat *m) { m_proj = p; m_model = m; }
67  void SetAlpha(GLfloat alpha) { m_alpha = alpha; }
68 
69 protected:
70 
71  void OnCompiledAndLinked() override;
72  bool OnEnabled() override;
73  void OnDisabled() override;
74  void Free();
75 
76  bool m_convertFullRange;
77  EShaderFormat m_format;
78  int m_width;
79  int m_height;
80  int m_field;
81  bool m_hasDisplayMetadata = false;
82  AVMasteringDisplayMetadata m_displayMetadata;
83  bool m_hasLightMetadata = false;
84  AVContentLightMetadata m_lightMetadata;
85  bool m_toneMapping = false;
86  ETONEMAPMETHOD m_toneMappingMethod = VS_TONEMAPMETHOD_REINHARD;
87  float m_toneMappingParam = 1.0;
88 
89  bool m_colorConversion{false};
90 
91  float m_black;
92  float m_contrast;
93  float m_stretch;
94 
95  const GLfloat *m_proj = nullptr;
96  const GLfloat *m_model = nullptr;
97  GLfloat m_alpha = 1.0f;
98 
99  std::string m_defines;
100 
101  std::shared_ptr<Shaders::GLSLOutput> m_glslOutput;
102  CConvertMatrix m_convMatrix;
103 
104  // pixel shader attribute handles
105  GLint m_hYTex = -1;
106  GLint m_hUTex = -1;
107  GLint m_hVTex = -1;
108  GLint m_hYuvMat = -1;
109  GLint m_hStretch = -1;
110  GLint m_hStep = -1;
111  GLint m_hGammaSrc = -1;
112  GLint m_hGammaDstInv = -1;
113  GLint m_hPrimMat = -1;
114  GLint m_hToneP1 = -1;
115  GLint m_hCoefsDst = -1;
116  GLint m_hLuminance = -1;
117 
118  // vertex shader attribute handles
119  GLint m_hVertex = -1;
120  GLint m_hYcoord = -1;
121  GLint m_hUcoord = -1;
122  GLint m_hVcoord = -1;
123  GLint m_hProj = -1;
124  GLint m_hModel = -1;
125  GLint m_hAlpha = -1;
126 };
127 
129 {
130 public:
131  YUV2RGBProgressiveShader(bool rect,
132  EShaderFormat format,
133  bool stretch,
134  AVColorPrimaries dstPrimaries,
135  AVColorPrimaries srcPrimaries,
136  bool toneMap,
137  ETONEMAPMETHOD toneMapMethod,
138  std::shared_ptr<GLSLOutput> output);
139 };
140 
142 {
143 public:
144  YUV2RGBFilterShader4(bool rect,
145  EShaderFormat format,
146  bool stretch,
147  AVColorPrimaries dstPrimaries,
148  AVColorPrimaries srcPrimaries,
149  bool toneMap,
150  ETONEMAPMETHOD toneMapMethod,
151  ESCALINGMETHOD method,
152  std::shared_ptr<GLSLOutput> output);
153  ~YUV2RGBFilterShader4() override;
154 
155 protected:
156  void OnCompiledAndLinked() override;
157  bool OnEnabled() override;
158 
159  GLuint m_kernelTex = 0;
160  GLint m_hKernTex = -1;
161  ESCALINGMETHOD m_scaling = VS_SCALINGMETHOD_LANCZOS3_FAST;
162 };
163 
164 } // namespace GL
165 } // end namespace
166 
Helper class used for YUV to RGB conversions.
Definition: ConversionMatrix.h:144
Definition: LinuxRendererGL.h:30
Definition: YUV2RGBShaderGL.h:128
Definition: YUV2RGBShaderGL.h:31
Definition: YUV2RGBShaderGL.h:141
Definition: Shader.h:148