nsCSSColorUtils.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. /* functions that manipulate colors */
  6. #ifndef __nsCSSColorUtils_h
  7. #define __nsCSSColorUtils_h
  8. #include "nsColor.h"
  9. // "Sufficient contrast" is determined by
  10. // "Techniques For Accessibility Evalution And Repair Tools".
  11. // See http://www.w3.org/TR/AERT#color-contrast
  12. #define NS_SUFFICIENT_LUMINOSITY_DIFFERENCE 125000
  13. #define NS_LUMINOSITY_DIFFERENCE(a, b) \
  14. int32_t(mozilla::Abs( \
  15. NS_GetLuminosity(a | 0xff000000) - NS_GetLuminosity(b | 0xff000000)))
  16. // To determine colors based on the background brightness and border color
  17. void NS_GetSpecial3DColors(nscolor aResult[2],
  18. nscolor aBackgroundColor,
  19. nscolor aBorderColor);
  20. // Determins brightness for a specific color
  21. int NS_GetBrightness(uint8_t aRed, uint8_t aGreen, uint8_t aBlue);
  22. // Get Luminosity of a specific color. That is same as Y of YIQ color space.
  23. // The range of return value is 0 to 255000.
  24. int32_t NS_GetLuminosity(nscolor aColor);
  25. // function to convert from RGBA color space to HSVA color space
  26. void NS_RGB2HSV(nscolor aColor, uint16_t &aHue, uint16_t &aSat,
  27. uint16_t &aValue, uint8_t &aAlpha);
  28. // function to convert from HSVA color space to RGBA color space
  29. void NS_HSV2RGB(nscolor &aColor, uint16_t aHue, uint16_t aSat, uint16_t aValue,
  30. uint8_t aAlpha);
  31. #endif