y2r_u.h 3.8 KB

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