drm_color_mgmt.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
  26. uint degamma_lut_size,
  27. bool has_ctm,
  28. uint gamma_lut_size);
  29. int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
  30. int gamma_size);
  31. /**
  32. * drm_color_lut_extract - clamp&round LUT entries
  33. * @user_input: input value
  34. * @bit_precision: number of bits the hw LUT supports
  35. *
  36. * Extract a degamma/gamma LUT value provided by user (in the form of
  37. * &drm_color_lut entries) and round it to the precision supported by the
  38. * hardware.
  39. */
  40. static inline uint32_t drm_color_lut_extract(uint32_t user_input,
  41. uint32_t bit_precision)
  42. {
  43. uint32_t val = user_input;
  44. uint32_t max = 0xffff >> (16 - bit_precision);
  45. /* Round only if we're not using full precision. */
  46. if (bit_precision < 16) {
  47. val += 1UL << (16 - bit_precision - 1);
  48. val >>= 16 - bit_precision;
  49. }
  50. return clamp_val(val, 0, max);
  51. }
  52. #endif