y2r_u.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include <string>
  7. #include "common/common_types.h"
  8. #include "core/hle/result.h"
  9. #include "core/hle/service/service.h"
  10. ////////////////////////////////////////////////////////////////////////////////////////////////////
  11. // Namespace Y2R_U
  12. namespace Y2R_U {
  13. enum class InputFormat : u8 {
  14. /// 8-bit input, with YUV components in separate planes and 4:2:2 subsampling.
  15. YUV422_Indiv8 = 0,
  16. /// 8-bit input, with YUV components in separate planes and 4:2:0 subsampling.
  17. YUV420_Indiv8 = 1,
  18. /// 16-bit input (only LSB used), with YUV components in separate planes and 4:2:2 subsampling.
  19. YUV422_Indiv16 = 2,
  20. /// 16-bit input (only LSB used), with YUV components in separate planes and 4:2:0 subsampling.
  21. YUV420_Indiv16 = 3,
  22. /// 8-bit input, with a single interleaved stream in YUYV format and 4:2:2 subsampling.
  23. YUYV422_Interleaved = 4,
  24. };
  25. enum class OutputFormat : u8 {
  26. RGBA8 = 0,
  27. RGB8 = 1,
  28. RGB5A1 = 2,
  29. RGB565 = 3,
  30. };
  31. enum class Rotation : u8 {
  32. None = 0,
  33. Clockwise_90 = 1,
  34. Clockwise_180 = 2,
  35. Clockwise_270 = 3,
  36. };
  37. enum class BlockAlignment : u8 {
  38. /// Image is output in linear format suitable for use as a framebuffer.
  39. Linear = 0,
  40. /// Image is output in tiled PICA format, suitable for use as a texture.
  41. Block8x8 = 1,
  42. };
  43. enum class StandardCoefficient : u8 {
  44. /// ITU Rec. BT.601 primaries, with PC ranges.
  45. ITU_Rec601 = 0,
  46. /// ITU Rec. BT.709 primaries, with PC ranges.
  47. ITU_Rec709 = 1,
  48. /// ITU Rec. BT.601 primaries, with TV ranges.
  49. ITU_Rec601_Scaling = 2,
  50. /// ITU Rec. BT.709 primaries, with TV ranges.
  51. ITU_Rec709_Scaling = 3,
  52. };
  53. /**
  54. * A set of coefficients configuring the RGB to YUV conversion. Coefficients 0-4 are unsigned 2.8
  55. * fixed pointer numbers representing entries on the conversion matrix, while coefficient 5-7 are
  56. * signed 11.5 fixed point numbers added as offsets to the RGB result.
  57. *
  58. * The overall conversion process formula is:
  59. * ```
  60. * R = trunc((c_0 * Y + c_1 * V) + c_5 + 0.75)
  61. * G = trunc((c_0 * Y - c_3 * U - c_2 * V) + c_6 + 0.75)
  62. * B = trunc((c_0 * Y + c_4 * U ) + c_7 + 0.75)
  63. * ```
  64. */
  65. using CoefficientSet = std::array<s16, 8>;
  66. struct ConversionBuffer {
  67. /// Current reading/writing address of this buffer.
  68. VAddr address;
  69. /// Remaining amount of bytes to be DMAed, does not include the inter-trasfer gap.
  70. u32 image_size;
  71. /// Size of a single DMA transfer.
  72. u16 transfer_unit;
  73. /// Amount of bytes to be skipped between copying each `transfer_unit` bytes.
  74. u16 gap;
  75. };
  76. struct ConversionConfiguration {
  77. InputFormat input_format;
  78. OutputFormat output_format;
  79. Rotation rotation;
  80. BlockAlignment block_alignment;
  81. u16 input_line_width;
  82. u16 input_lines;
  83. CoefficientSet coefficients;
  84. u8 padding;
  85. u16 alpha;
  86. /// Input parameters for the Y (luma) plane
  87. ConversionBuffer src_Y, src_U, src_V, src_YUYV;
  88. /// Output parameters for the conversion results
  89. ConversionBuffer dst;
  90. ResultCode SetInputLineWidth(u16 width);
  91. ResultCode SetInputLines(u16 lines);
  92. ResultCode SetStandardCoefficient(StandardCoefficient standard_coefficient);
  93. };
  94. struct DitheringWeightParams {
  95. u16 w0_xEven_yEven;
  96. u16 w0_xOdd_yEven;
  97. u16 w0_xEven_yOdd;
  98. u16 w0_xOdd_yOdd;
  99. u16 w1_xEven_yEven;
  100. u16 w1_xOdd_yEven;
  101. u16 w1_xEven_yOdd;
  102. u16 w1_xOdd_yOdd;
  103. u16 w2_xEven_yEven;
  104. u16 w2_xOdd_yEven;
  105. u16 w2_xEven_yOdd;
  106. u16 w2_xOdd_yOdd;
  107. u16 w3_xEven_yEven;
  108. u16 w3_xOdd_yEven;
  109. u16 w3_xEven_yOdd;
  110. u16 w3_xOdd_yOdd;
  111. };
  112. class Interface : public Service::Interface {
  113. public:
  114. Interface();
  115. ~Interface() override;
  116. std::string GetPortName() const override {
  117. return "y2r:u";
  118. }
  119. };
  120. } // namespace