RGB to HSL/HSV

\(\begin{align} &M = \max(R,G,B)\\ &m = \min(R,G,B)\\ &V = M\\ &C = M-m\\ &L = \dfrac{M+m}{2}\\ &H' = \begin{cases} 0&\text{if }C = 0\\ \frac{G-B}{C}{\bmod}6&\text{if }V = R\\ \frac{B-R}{C}+2&\text{if }V = G\\ \frac{R-G}{C}+4&\text{if }V = B \end{cases}\\ &H = 60^{\circ}H' \\ &S = \begin{cases} 0&\text{if }V = 0\\ \frac{C}{V}&\text{otherwise} \end{cases} \end{align}\)