drm_color_mgmt.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (c) 2016 Intel Corporation
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software and its
  5. * documentation for any purpose is hereby granted without fee, provided that
  6. * the above copyright notice appear in all copies and that both that copyright
  7. * notice and this permission notice appear in supporting documentation, and
  8. * that the name of the copyright holders not be used in advertising or
  9. * publicity pertaining to distribution of the software without specific,
  10. * written prior permission. The copyright holders make no representations
  11. * about the suitability of this software for any purpose. It is provided "as
  12. * is" without express or implied warranty.
  13. *
  14. * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16. * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  19. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  20. * OF THIS SOFTWARE.
  21. */
  22. #ifndef __DRM_COLOR_MGMT_H__
  23. #define __DRM_COLOR_MGMT_H__
  24. #include <linux/ctype.h>
  25. #include <drm/drm_property.h>
  26. struct drm_crtc;
  27. struct drm_plane;
  28. /**
  29. * drm_color_lut_extract - clamp and round LUT entries
  30. * @user_input: input value
  31. * @bit_precision: number of bits the hw LUT supports
  32. *
  33. * Extract a degamma/gamma LUT value provided by user (in the form of
  34. * &drm_color_lut entries) and round it to the precision supported by the
  35. * hardware.
  36. */
  37. static inline u32 drm_color_lut_extract(u32 user_input, int bit_precision)
  38. {
  39. u32 val = user_input;
  40. u32 max = 0xffff >> (16 - bit_precision);
  41. /* Round only if we're not using full precision. */
  42. if (bit_precision < 16) {
  43. val += 1UL << (16 - bit_precision - 1);
  44. val >>= 16 - bit_precision;
  45. }
  46. return clamp_val(val, 0, max);
  47. }
  48. u64 drm_color_ctm_s31_32_to_qm_n(u64 user_input, u32 m, u32 n);
  49. void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
  50. uint degamma_lut_size,
  51. bool has_ctm,
  52. uint gamma_lut_size);
  53. int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
  54. int gamma_size);
  55. /**
  56. * drm_color_lut_size - calculate the number of entries in the LUT
  57. * @blob: blob containing the LUT
  58. *
  59. * Returns:
  60. * The number of entries in the color LUT stored in @blob.
  61. */
  62. static inline int drm_color_lut_size(const struct drm_property_blob *blob)
  63. {
  64. return blob->length / sizeof(struct drm_color_lut);
  65. }
  66. enum drm_color_encoding {
  67. DRM_COLOR_YCBCR_BT601,
  68. DRM_COLOR_YCBCR_BT709,
  69. DRM_COLOR_YCBCR_BT2020,
  70. DRM_COLOR_ENCODING_MAX,
  71. };
  72. enum drm_color_range {
  73. DRM_COLOR_YCBCR_LIMITED_RANGE,
  74. DRM_COLOR_YCBCR_FULL_RANGE,
  75. DRM_COLOR_RANGE_MAX,
  76. };
  77. int drm_plane_create_color_properties(struct drm_plane *plane,
  78. u32 supported_encodings,
  79. u32 supported_ranges,
  80. enum drm_color_encoding default_encoding,
  81. enum drm_color_range default_range);
  82. /**
  83. * enum drm_color_lut_tests - hw-specific LUT tests to perform
  84. *
  85. * The drm_color_lut_check() function takes a bitmask of the values here to
  86. * determine which tests to apply to a userspace-provided LUT.
  87. */
  88. enum drm_color_lut_tests {
  89. /**
  90. * @DRM_COLOR_LUT_EQUAL_CHANNELS:
  91. *
  92. * Checks whether the entries of a LUT all have equal values for the
  93. * red, green, and blue channels. Intended for hardware that only
  94. * accepts a single value per LUT entry and assumes that value applies
  95. * to all three color components.
  96. */
  97. DRM_COLOR_LUT_EQUAL_CHANNELS = BIT(0),
  98. /**
  99. * @DRM_COLOR_LUT_NON_DECREASING:
  100. *
  101. * Checks whether the entries of a LUT are always flat or increasing
  102. * (never decreasing).
  103. */
  104. DRM_COLOR_LUT_NON_DECREASING = BIT(1),
  105. };
  106. int drm_color_lut_check(const struct drm_property_blob *lut, u32 tests);
  107. #endif