Coverage for colour/notation/css_color_3.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-11-15 19:01 +1300

1""" 

2CSS Color Module Level 3 - Web Colours 

3====================================== 

4 

5Define the conversion utilities for CSS Color Module Level 3 colour keywords 

6to *RGB* colourspace representations. 

7 

8- :attr:`colour.notation.keyword_to_RGB_CSSColor3` 

9 

10References 

11---------- 

12- :cite:`W3C2022` : W3C. (2022). CSS Color Module Level 3. 

13 https://www.w3.org/TR/css-color-3/ 

14""" 

15 

16from __future__ import annotations 

17 

18from colour.hints import Range1 # noqa: TC001 

19from colour.notation import CSS_COLOR_3, HEX_to_RGB 

20from colour.utilities import attest 

21 

22__author__ = "Colour Developers" 

23__copyright__ = "Copyright 2013 Colour Developers" 

24__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause" 

25__maintainer__ = "Colour Developers" 

26__email__ = "colour-developers@colour-science.org" 

27__status__ = "Production" 

28 

29__all__ = [ 

30 "keyword_to_RGB_CSSColor3", 

31] 

32 

33 

34def keyword_to_RGB_CSSColor3(keyword: str) -> Range1: 

35 """ 

36 Convert specified colour keyword to *RGB* colourspace according to 

37 *CSS Color Module Level 3* *W3C Recommendation*. 

38 

39 Parameters 

40 ---------- 

41 keyword 

42 Colour keyword. 

43 

44 Returns 

45 ------- 

46 :class:`numpy.array` 

47 *RGB* colourspace array. 

48 

49 Notes 

50 ----- 

51 +------------+-----------------------+---------------+ 

52 | **Range** | **Scale - Reference** | **Scale - 1** | 

53 +============+=======================+===============+ 

54 | ``RGB`` | 1 | 1 | 

55 +------------+-----------------------+---------------+ 

56 

57 - All the RGB colors are specified in the *IEC 61966-2-1:1999* 

58 *sRGB* colourspace. 

59 

60 Examples 

61 -------- 

62 >>> keyword_to_RGB_CSSColor3("black") 

63 array([ 0., 0., 0.]) 

64 >>> keyword_to_RGB_CSSColor3("white") 

65 array([ 1., 1., 1.]) 

66 >>> keyword_to_RGB_CSSColor3("aliceblue") # doctest: +ELLIPSIS 

67 array([ 0.9411764..., 0.9725490..., 1. ]) 

68 """ 

69 

70 attest(keyword in CSS_COLOR_3, f'{keyword} is not defined in "CSS Color 3"!') 

71 

72 return HEX_to_RGB(CSS_COLOR_3[keyword])