Color conversion using mathematical formulas gives very poor results without serious application. Color systems are too complex to capture in simple closed mathematical formulas, not to mention linear formulas.
Good results can only be achieved using color profile files. And the conversion basically causes interpolation between the samples stored in these files.
Take a look at Little CMS . He probably does everything you need. Or, if your software runs on Windows, you can use the built-in Windows Color System to convert.
source share