kodi
ShaderFormats.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 "utils/Map.h"
12 
13 #include <fmt/format.h>
14 
15 enum EShaderFormat
16 {
17  SHADER_NONE,
18  SHADER_YV12,
19  SHADER_YV12_9,
20  SHADER_YV12_10,
21  SHADER_YV12_12,
22  SHADER_YV12_14,
23  SHADER_YV12_16,
24  SHADER_NV12,
25  SHADER_YUY2,
26  SHADER_UYVY,
27  SHADER_NV12_RRG,
28  SHADER_MAX,
29 };
30 
31 template<>
32 struct fmt::formatter<EShaderFormat> : fmt::formatter<std::string_view>
33 {
34  template<typename FormatContext>
35  constexpr auto format(const EShaderFormat& shaderFormat, FormatContext& ctx)
36  {
37  const auto it = shaderFormatMap.find(shaderFormat);
38  if (it == shaderFormatMap.cend())
39  throw std::range_error("no shader format string found");
40 
41  return fmt::formatter<string_view>::format(it->second, ctx);
42  }
43 
44 private:
45  static constexpr auto shaderFormatMap = make_map<EShaderFormat, std::string_view>({
46  {SHADER_NONE, "none"},
47  {SHADER_YV12, "YV12"},
48  {SHADER_YV12_9, "YV12 9bit"},
49  {SHADER_YV12_10, "YV12 10bit"},
50  {SHADER_YV12_12, "YV12 12bit"},
51  {SHADER_YV12_14, "YV12 14bit"},
52  {SHADER_YV12_16, "YV12 16bit"},
53  {SHADER_NV12, "NV12"},
54  {SHADER_YUY2, "YUY2"},
55  {SHADER_UYVY, "UYVY"},
56  {SHADER_NV12_RRG, "NV12 red/red/green"},
57  });
58 
59  static_assert(SHADER_MAX == shaderFormatMap.size(),
60  "shaderFormatMap doesn't match the size of EShaderFormat, did you forget to "
61  "add/remove a mapping?");
62 };