|
1 |
| -(** Support for 256-color handling on terminals/consoles. Note that the |
2 |
| - functions [of_rgb6_exn] and [of_rgb6] return values within the 6x6x6 |
3 |
| - color-cube space, even though equivalent duplicates exist in the first 16 |
4 |
| - and last 24 colors (a "best-fit-equivalent" function could be added some |
5 |
| - day, if there ever becomes a requirement for it -- see note 2 below). |
| 1 | +(** Support for 256-color handling on terminals/consoles. Note that the functions |
| 2 | + [of_rgb6_exn] and [of_rgb6] return values within the 6x6x6 color-cube space, even |
| 3 | + though equivalent duplicates exist in the first 16 and last 24 colors (a |
| 4 | + "best-fit-equivalent" function could be added some day, if there ever becomes a |
| 5 | + requirement for it -- see note 2 below). |
6 | 6 |
|
7 |
| - NOTE 1: the color-cube is not linear in terms of RGB levels, but is |
8 |
| - "shifted" towards brighter values (as opposed to a logarithmic or other |
9 |
| - mapping). Visually, the "rgb6" values 0 to 5 (used in [of_rgb6_exn] and |
10 |
| - encoded in the 256-color palette values) map into RGB levels as follows: |
| 7 | + NOTE 1: the color-cube is not linear in terms of RGB levels, but is "shifted" towards |
| 8 | + brighter values (as opposed to a logarithmic or other mapping). Visually, the "rgb6" |
| 9 | + values 0 to 5 (used in [of_rgb6_exn] and encoded in the 256-color palette values) map |
| 10 | + into RGB levels as follows: |
11 | 11 |
|
12 | 12 | {v
|
13 | 13 | Cube-val: 0 1 2 3 4 5
|
14 | 14 | v +-----------+----+----+----+----+
|
15 | 15 | RGB: 0 95 135 175 215 255
|
16 | 16 | v}
|
17 | 17 |
|
18 |
| - The floating-point values used in [of_rgb] are {e not} weighted in the same |
19 |
| - way, but are rounded to the nearest cube-value -- a value of 0.5 (50% or |
20 |
| - 127.5/255) would result in a color-cube value of 2, for example. Any level |
21 |
| - less than 0.187 (approx.) maps to 0 (black) and greater than 0.921 to 5 |
22 |
| - (white). |
| 18 | + The floating-point values used in [of_rgb] are {e not} weighted in the same way, but |
| 19 | + are rounded to the nearest cube-value -- a value of 0.5 (50% or 127.5/255) would |
| 20 | + result in a color-cube value of 2, for example. Any level less than 0.187 (approx.) |
| 21 | + maps to 0 (black) and greater than 0.921 to 5 (white). |
23 | 22 |
|
24 |
| - NOTE 2: is is {e not} recommended to use the 256-color palette for |
25 |
| - representing the 16 (8 * 2) 'primary' colors. The standard [`Black], |
26 |
| - [`Blue], etc. attributes are recommended for these. |
27 |
| -*) |
| 23 | + NOTE 2: is is {e not} recommended to use the 256-color palette for representing the 16 |
| 24 | + (8 * 2) 'primary' colors. The standard [`Black], [`Blue], etc. attributes are |
| 25 | + recommended for these. *) |
28 | 26 |
|
29 | 27 | type t [@@deriving sexp_of, compare, hash, equal]
|
30 | 28 |
|
31 | 29 | val to_int : t -> int
|
32 | 30 | val of_int_exn : int -> t
|
33 | 31 |
|
34 |
| -(** Takes an RGB triple with values in the range [0,5] (inclusive) and returns |
35 |
| - the appropriate 256-color palette value. Will throw an exception if any of |
36 |
| - the inputs are out-of-range. Note that the input values are weighted as |
37 |
| - described above. *) |
| 32 | +(** Takes an RGB triple with values in the range [0,5] (inclusive) and returns the |
| 33 | + appropriate 256-color palette value. Will throw an exception if any of the inputs are |
| 34 | + out-of-range. Note that the input values are weighted as described above. *) |
38 | 35 | val of_rgb6_exn : int * int * int -> t
|
39 | 36 |
|
40 |
| -(** Takes an RGB triple with float values in the closed (inclusive) interval |
41 |
| - [0,1] and returns the nearest (rounded) 256-color palette value. |
42 |
| - Out-of-bound values are clamped to the range. The inputs are {e not} |
43 |
| - weighted, unlike [of_rgb6_exn] as described above. *) |
| 37 | +(** Takes an RGB triple with float values in the closed (inclusive) interval [0,1] and |
| 38 | + returns the nearest (rounded) 256-color palette value. Out-of-bound values are clamped |
| 39 | + to the range. The inputs are {e not} weighted, unlike [of_rgb6_exn] as described |
| 40 | + above. *) |
44 | 41 | val of_rgb : float * float * float -> t
|
45 | 42 |
|
46 |
| -(** Takes an RGB triple with integer values in the closed (inclusive) range |
47 |
| - [0,255] and returns the nearest (rounded) 256-color palette color-cube |
48 |
| - value. Out-of-bound values are clamped to the range. The inputs are |
49 |
| - {e not} weighted, unlike [of_rgb6_exn] as described above. *) |
| 43 | +(** Takes an RGB triple with integer values in the closed (inclusive) range [0,255] and |
| 44 | + returns the nearest (rounded) 256-color palette color-cube value. Out-of-bound values |
| 45 | + are clamped to the range. The inputs are {e not} weighted, unlike [of_rgb6_exn] as |
| 46 | + described above. *) |
50 | 47 | val of_rgb_8bit : int * int * int -> t
|
51 | 48 |
|
52 |
| -(** Takes an RGB triple with integer values in the closed (inclusive) range |
53 |
| - [0,1000] and returns the nearest (rounded) 256-color palette color-cube |
54 |
| - value. Out-of-bound values are clamped to the range. The inputs are {e not} |
55 |
| - weighted, unlike [of_rgb6_exn] as described above. *) |
| 49 | +(** Takes an RGB triple with integer values in the closed (inclusive) range [0,1000] and |
| 50 | + returns the nearest (rounded) 256-color palette color-cube value. Out-of-bound values |
| 51 | + are clamped to the range. The inputs are {e not} weighted, unlike [of_rgb6_exn] as |
| 52 | + described above. *) |
56 | 53 | val of_rgb_int1k : int * int * int -> t
|
57 | 54 |
|
58 |
| -(** Takes a grayscale level from [0-23] (inclusive, not-black-to-not-white) |
59 |
| - and returns the appropriate 256-color palette value. Will throw an |
60 |
| - exception if the input value is out-of-range. *) |
| 55 | +(** Takes a grayscale level from [0-23] (inclusive, not-black-to-not-white) and returns |
| 56 | + the appropriate 256-color palette value. Will throw an exception if the input value is |
| 57 | + out-of-range. *) |
61 | 58 | val of_gray24_exn : int -> t
|
62 | 59 |
|
63 |
| -(** Takes a color palette value and returns, for color-cube and grayscale |
64 |
| - palette values, an approximated [`RGB] triple with each component in the |
65 |
| - range [0,1]; for the first 16 values, [`Primary] followed by the specific |
66 |
| - palette index is returned, as these are not consistently defined. *) |
| 60 | +(** Takes a color palette value and returns, for color-cube and grayscale palette values, |
| 61 | + an approximated [`RGB] triple with each component in the range [0,1]; for the first 16 |
| 62 | + values, [`Primary] followed by the specific palette index is returned, as these are |
| 63 | + not consistently defined. *) |
67 | 64 | val to_rgb : t -> [> `Primary of int | `RGB of float * float * float ]
|
68 | 65 |
|
69 |
| -(** Takes a color palette value and returns a hex-encoded RGB 24-bit triplet, |
70 |
| - with a leading '#'. I.e. "#000000" through "#ffffff". The values |
71 |
| - returned for the first 16 (primary) colors follow the Windows Console |
72 |
| - scheme, as documented here: https://en.wikipedia.org/wiki/ANSI_escape_code . |
73 |
| -*) |
| 66 | +(** Takes a color palette value and returns a hex-encoded RGB 24-bit triplet, with a |
| 67 | + leading '#'. I.e. "#000000" through "#ffffff". The values returned for the first 16 |
| 68 | + (primary) colors follow the Windows Console scheme, as documented here: |
| 69 | + https://en.wikipedia.org/wiki/ANSI_escape_code . *) |
74 | 70 | val to_rgb_hex24 : t -> string
|
75 | 71 |
|
76 |
| -(** Takes a color palette value and returns an approximate luminance value |
77 |
| - in the closed interval [0,1]. *) |
| 72 | +(** Takes a color palette value and returns an approximate luminance value in the closed |
| 73 | + interval [0,1]. *) |
78 | 74 | val to_luma : t -> float
|
79 | 75 |
|
80 |
| -(** Takes a color palette value and returns a triple of RGB integers in |
81 |
| - the closed interval [0,255]. *) |
| 76 | +(** Takes a color palette value and returns a triple of RGB integers in the closed |
| 77 | + interval [0,255]. *) |
82 | 78 | val to_rgb_8bit : t -> int * int * int
|
83 | 79 |
|
84 |
| -(** Takes a color palette value and returns a triple of RGB integers in |
85 |
| - the closed interval [0,1000]. *) |
| 80 | +(** Takes a color palette value and returns a triple of RGB integers in the closed |
| 81 | + interval [0,1000]. *) |
86 | 82 | val to_rgb_int1k : t -> int * int * int
|
87 | 83 |
|
88 |
| -(** Takes a color palette value and returns a triple of RGB integers in |
89 |
| - the closed interval [0,5]. For color-cube palette values, this simply |
90 |
| - un-does [of_rgb6_exn]. For others, it will return the closest matching |
91 |
| - value in the color-cube. *) |
| 84 | +(** Takes a color palette value and returns a triple of RGB integers in the closed |
| 85 | + interval [0,5]. For color-cube palette values, this simply un-does [of_rgb6_exn]. For |
| 86 | + others, it will return the closest matching value in the color-cube. *) |
92 | 87 | val to_rgb6 : t -> int * int * int
|
93 | 88 |
|
94 | 89 | module Stable : sig
|
|
0 commit comments