kodi
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 
58  void SetConvertFullColorRange(bool convertFullRange) { m_convertFullRange = convertFullRange; }
59 
60  GLint GetVertexLoc() { return m_hVertex; }
61  GLint GetYcoordLoc() { return m_hYcoord; }
62  GLint GetUcoordLoc() { return m_hUcoord; }
63  GLint GetVcoordLoc() { return m_hVcoord; }
64 
65  void SetMatrices(const GLfloat *p, const GLfloat *m) { m_proj = p; m_model = m; }
66  void SetAlpha(GLfloat alpha) { m_alpha = alpha; }
67 
68 protected:
69 
70  void OnCompiledAndLinked() override;
71  bool OnEnabled() override;
72  void OnDisabled() override;
73  void Free();
74 
75  bool m_convertFullRange;
76  EShaderFormat m_format;
77  int m_width;
78  int m_height;
79  int m_field;
80  bool m_hasDisplayMetadata = false;
81  AVMasteringDisplayMetadata m_displayMetadata;
82  bool m_hasLightMetadata = false;
83  AVContentLightMetadata m_lightMetadata;
84  bool m_toneMapping = false;
85  ETONEMAPMETHOD m_toneMappingMethod = VS_TONEMAPMETHOD_OFF;
86  float m_toneMappingParam = 1.0;
87 
88  bool m_colorConversion{false};
89 
90  float m_black;
91  float m_contrast;
92  float m_stretch;
93 
94  const GLfloat *m_proj = nullptr;
95  const GLfloat *m_model = nullptr;
96  GLfloat m_alpha = 1.0f;
97 
98  std::string m_defines;
99 
100  std::shared_ptr<Shaders::GLSLOutput> m_glslOutput;
101  CConvertMatrix m_convMatrix;
102 
103  // pixel shader attribute handles
104  GLint m_hYTex = -1;
105  GLint m_hUTex = -1;
106  GLint m_hVTex = -1;
107  GLint m_hYuvMat = -1;
108  GLint m_hStretch = -1;
109  GLint m_hStep = -1;
110  GLint m_hGammaSrc = -1;
111  GLint m_hGammaDstInv = -1;
112  GLint m_hPrimMat = -1;
113  GLint m_hToneP1 = -1;
114  GLint m_hCoefsDst = -1;
115  GLint m_hLuminance = -1;
116 
117  // vertex shader attribute handles
118  GLint m_hVertex = -1;
119  GLint m_hYcoord = -1;
120  GLint m_hUcoord = -1;
121  GLint m_hVcoord = -1;
122  GLint m_hProj = -1;
123  GLint m_hModel = -1;
124  GLint m_hAlpha = -1;
125 };
126 
128 {
129 public:
130  YUV2RGBProgressiveShader(bool rect,
131  EShaderFormat format,
132  bool stretch,
133  AVColorPrimaries dstPrimaries,
134  AVColorPrimaries srcPrimaries,
135  bool toneMap,
136  ETONEMAPMETHOD toneMapMethod,
137  std::shared_ptr<GLSLOutput> output);
138 };
139 
141 {
142 public:
143  YUV2RGBFilterShader4(bool rect,
144  EShaderFormat format,
145  bool stretch,
146  AVColorPrimaries dstPrimaries,
147  AVColorPrimaries srcPrimaries,
148  bool toneMap,
149  ETONEMAPMETHOD toneMapMethod,
150  ESCALINGMETHOD method,
151  std::shared_ptr<GLSLOutput> output);
152  ~YUV2RGBFilterShader4() override;
153 
154 protected:
155  void OnCompiledAndLinked() override;
156  bool OnEnabled() override;
157 
158  GLuint m_kernelTex = 0;
159  GLint m_hKernTex = -1;
160  ESCALINGMETHOD m_scaling = VS_SCALINGMETHOD_LANCZOS3_FAST;
161 };
162 
163 } // namespace GL
164 } // end namespace
165 
Helper class used for YUV to RGB conversions.
Definition: ConversionMatrix.h:144
Definition: LinuxRendererGL.h:30
Definition: YUV2RGBShaderGL.h:127
Definition: YUV2RGBShaderGL.h:31
Definition: YUV2RGBShaderGL.h:140
Definition: Shader.h:148