I also read the post you linked above and worked very well for me. If you still don't understand it, here I leave you the translation to pseudo-code:
//Given a string with the hexadecimal RGB color,
//separate it in its three components in integer
Integer red = fromHexaToInt(RGB_string.Substring(0,2));
Integer green = fromHexaToInt(RGB_string.Substring(2,4));
Integer blue = fromHexaToInt(RGB_string.Substring(4,6));
//Convert each integer to a proportion of the maximum value (255)
Double dRed = red / 255;
Double dGreen = green / 255;
Double dBlue = blue / 255;
//Apply the conversion function for each one
dRed = sRGB_to_scRGB(dRed);
dGreen = sRGB_to_scRGB(dGreen);
dBlue = sRGB_to_scRGB(dBlue);
//Apply to each one the shade (must be a number between 0 and 1), let's say 0.4
//NOTE: if you want to use tint, just call that function instead of shade
Double level = 0.4;
dRed = shade(dRed, level);
dGreen = shade(dGreen, level);
dBlue = shade(dBlue, level);
//Apply the inverse of the conversion function
dRed = scRGB_to_sRGB(dRed);
dGreen = scRGB_to_sRGB(dGreen);
dBlue = scRGB_to_sRGB(dBlue);
//Recover the integer value from the converted new color by multiplying and rounding it
red = round(dRed * 255)
green = round(dGreen * 255)
blue = round(dBlue * 255)
//Transform the integers back to hexadecimal
String strRed = fromIntToHexa(red);
String strGreen = fromIntToHexa(green);
String strBlue = fromIntToHexa(blue);
//Concatenate them all
String newColor = strRed + strGreen + strBlue;
And the functions you call may be like this:
//Conversion function
function sRGB_to_scRGB(value){
if (value < 0){
return 0;
}
if(value <= 0.04045){
return value / 12.92;
}
if (value <= 1){
return ((value + 0.055) / 1.055) ^ 2.4);
}
return 1;
}
//Function to shade the color
function shade(color, shade){
if(color * shade < 0){
return 0;
}
else{
if(color * shade > 1){
return 1;
}
else{
return color * shade;
}
}
}
//Function to tint color
function tint(color, tint){
if(tint > 0){
return color * (1-tint)+tint;
}
else{
return color * (1 + tint);
}
}
//Reconversion function
function scRGB_to_sRGB(value){
if(value < 0){
return 0;
}
if (value <= 0.0031308){
return value * 12.92;
}
if(value < 1){
return 1.055 * (value ^ (1 / 2.4)) - 0.055;
}
return 1;
}
Hope it will be useful.