Wrote a paragraph about the color of the article, review the past several articles, do a phased summary. Using the experience of the previous articles, the formula for fast conversion of RGB mode and HSV mode is deduced.
RGB mode: Use R, G, b three color components to represent color, the value range of components is [0,255], Integer
HSV mode: Uses H, S, v three components to represent the color.
Component h: Hue of color, value [0,360], Integer
Component S: The purity of the color, the value [0,1], the floating-point type
Component V: Indicates the brightness of the color, the value [0,1], the floating-point type
For more information, see "Color III--HSV notation on your computer"
1, RGB to HSV
How to quickly convert color (r,g,b) to (H,S,V)
See the article "Colors in your computer iv--solid, hue", "colors in your computer v--quickly calculate the hue value of a color"
Max is the maximum value of three components of R, G, B, and Min is the minimum of three components.
If Max=min, then
H=0
S=0
v=max/255
If Max≠min
When G≥b,
H= (max-r ' +g '-min+b '-min)/(max-min) x60
S=1-min/max
v=max/255
When G
h=360-(max-r ' +g '-min+b '-min)/(max-min) x60
S=1-min/max
v=max/255