On this page
RGB and HSL RGB to HSL C references chroma.
V = m a x ( R , G , B ) C = V − m i n ( R , G , B ) L = V − C 2 S = { 0 if L = 0 or L = 1 V − L m i n ( L , 1 − L ) otherwise H = { 0 if C = 0 G − B C if V = R B − R C + 2 if V = G R − G C + 4 if V = B \begin{align*} V &= max(R,G,B) \\ \:\\ C &= V - min(R,G,B) \\ \:\\ L &= V - \frac{C}{2} \:\\ S &= \begin{cases} 0 & \text{ if } L = 0 \text{ or } L = 1 \\ \frac{V-L}{min(L,1-L)} & \text{ otherwise } \end{cases} \\ \:\\ H &= \begin{cases} 0 & \text{ if } C = 0 \\ \frac{G - B}{C} & \text{ if } V = R \\ \frac{B - R}{C} + 2 & \text{ if } V = G \\ \frac{R - G}{C} + 4 & \text{ if } V = B \\ \end{cases} \end{align*} V C L S H = ma x ( R , G , B ) = V − min ( R , G , B ) = V − 2 C = { 0 min ( L , 1 − L ) V − L if L = 0 or L = 1 otherwise = ⎩ ⎨ ⎧ 0 C G − B C B − R + 2 C R − G + 4 if C = 0 if V = R if V = G if V = B HSL to RGB C = ( 1 − ∣ 2 L − 1 ∣ ) ⋅ S x = C ⋅ ( 1 − ∣ H mod 2 − 1 ∣ ) ( R 1 , G 1 , B 1 ) = { ( 0 , 0 , 0 ) if H u n d e f i n e d ( C , x , 0 ) if 0 < H ≤ 1 ( x , C , 0 ) if 1 < H ≤ 2 ( 0 , C , x ) if 2 < H ≤ 3 ( 0 , x , C ) if 3 < H ≤ 4 ( x , 0 , C ) if 4 < H ≤ 5 ( C , 0 , x ) if 5 < H ≤ 6 m = L − C 2 ( R , G , B ) = ( R 1 + m , G 1 + m , B 1 + m ) \begin{align*} C &= (1 - |2L - 1|) \cdot S \\ \:\\ x &= C \cdot (1 - |H \text{ mod } 2-1|) \\ \:\\ (R_{1},G_{1},B_{1}) &= \begin{cases} (0,0,0) & \text{ if } H \: \mathrm{undefined} \\ (C,x,0) & \text{ if } 0 < H \leq 1 \\ (x,C,0) & \text{ if } 1 < H \leq 2 \\ (0,C,x) & \text{ if } 2 < H \leq 3 \\ (0,x,C) & \text{ if } 3 < H \leq 4 \\ (x,0,C) & \text{ if } 4 < H \leq 5 \\ (C,0,x) & \text{ if } 5 < H \leq 6 \\ \end{cases} \\ \:\\ m &= L - \frac{C}{2} \\ \:\\ (R,G,B) &= (R_1 + m, G_1 + m, B_1 + m) \end{align*} C x ( R 1 , G 1 , B 1 ) m ( R , G , B ) = ( 1 − ∣2 L − 1∣ ) ⋅ S = C ⋅ ( 1 − ∣ H mod 2 − 1∣ ) = ⎩ ⎨ ⎧ ( 0 , 0 , 0 ) ( C , x , 0 ) ( x , C , 0 ) ( 0 , C , x ) ( 0 , x , C ) ( x , 0 , C ) ( C , 0 , x ) if H undefined if 0 < H ≤ 1 if 1 < H ≤ 2 if 2 < H ≤ 3 if 3 < H ≤ 4 if 4 < H ≤ 5 if 5 < H ≤ 6 = L − 2 C = ( R 1 + m , G 1 + m , B 1 + m )