Welcome Guest Log out

Color conversion math and formulas

These are the formulas used by our Color Calculator.
Each conversion formula is written as a "neutral programming function", easy to be translate in any specific computer language.
If you are searching for more generic information about color, on the Net there are several good sites devoted to color science, physics, psychology, physiology and technology.
Check our Links page or our FAQ page for a list of handy color references.

XYZ > RGB

RGB > XYZ

XYZ > Yxy

Yxy > XYZ

RGB > HSL

HSL > RGB

RGB > HSV

 if ( S == 0 )                       //HSV from 0 to 1{    R = V * 255   G = V * 255   B = V * 255}else{    var_h = H * 6    if ( var_h == 6 ) var_h = 0      //H must be < 1    var_i = int( var_h )             //Or ... var_i = floor( var_h )    var_1 = V * ( 1 - S )    var_2 = V * ( 1 - S * ( var_h - var_i ) )    var_3 = V * ( 1 - S * ( 1 - ( var_h - var_i ) ) )    if      ( var_i == 0 ) { var_r = V     ; var_g = var_3 ; var_b = var_1 }    else if ( var_i == 1 ) { var_r = var_2 ; var_g = V     ; var_b = var_1 }    else if ( var_i == 2 ) { var_r = var_1 ; var_g = V     ; var_b = var_3 }    else if ( var_i == 3 ) { var_r = var_1 ; var_g = var_2 ; var_b = V     }    else if ( var_i == 4 ) { var_r = var_3 ; var_g = var_1 ; var_b = V     }    else                   { var_r = V     ; var_g = var_1 ; var_b = var_2 }    R = var_r * 255                  //RGB results from 0 to 255   G = var_g * 255    B = var_b * 255}

RGB > CMY

CMY > RGB

CMY > CMYK

CMYK > CMY