I was trying to find a functional form for saturation but didn't find anything. It can't be that hard but all my guesses don't look quite right (the direction towards desaturation seems easier).
I have the pixel data of the image in RGB format. The final image should also be in RGB format. So, how are these functions defined:
r_n = saturation_r(r,g,b,sat);
g_n = saturation_g(r,g,b,sat);
b_n = saturation_b(r,g,b,sat);