13,795,604 members
Alternative Tip/Trick
Add your own
alternative version

#### Stats

4.9K views
Posted 5 Oct 2011
Licenced CPOL

# Random Color Generator

, 5 Oct 2011
Eric, sorry for the confusion, I think I wrote it too quick:Guillaume's library uses sRGB with D65 white ref. If you want to continue using that conversion, then just copy/paste RGBtoXYZ and XYZtoRGB into your code.you get a correct codethe calculation is more precise with the expanded...

Eric, sorry for the confusion, I think I wrote it too quick:

Guillaume's library uses sRGB with D65 white ref. If you want to continue using that conversion, then just copy/paste `RGBtoXYZ` and `XYZtoRGB` into your code.

1. you get a correct code
2. the calculation is more precise with the expanded constants.

If you would like a conversion which is very similar to Adobe's, then you need to do the other proposed changes as well: RGB Bradford at D50.

Here is the ready copy/paste `XYZtoRGB` for RGB Bradford:

```public static RGB XYZtoRGB(double x, double y, double z)
{
// using RGB Bradford Working Space Matrix and D50 Reference White
double[] Clinear = new double[3];
Clinear[0] = x*3.1338561 - y*1.6168667 - z*0.4906146; // red
Clinear[1] = -x*0.9787684 + y*1.9161415 + z*0.0334540; // green
Clinear[2] = x*0.0719453 - y*0.2289914 + z*1.4052427; // blue

for(int i=0; i<3; i++)
{
Clinear[i] = (Clinear[i]<=0.0031308)? 12.92*Clinear[i] :
(1+0.055)* Math.Pow(Clinear[i], (1.0/2.4)) - 0.055;
Clinear[i] *= 255.0;
}
// looks a bit cleaner than before :-)
return new RGB((int)Clinear[0], (int)Clinear[1], (int)Clinear[2]);
}```

If you need help for the rest, just shout.

Rob

BTW, you can make a chicken fly, it all depends on the height of the building...

## License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

## About the Author

 Switzerland
No Biography provided

## Comments and Discussions

 First Prev Next
 Thanks a lot ! I will post my new code in few minutes. (Sean... Eric Ouellet4-Oct-11 10:33 Eric Ouellet 4-Oct-11 10:33
 Last Visit: 11-Dec-18 12:19     Last Update: 11-Dec-18 12:19 Refresh 1

General    News    Suggestion    Question    Bug    Answer    Joke    Praise    Rant    Admin

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06 | 2.8.181207.3 | Last Updated 5 Oct 2011
Article Copyright 2011 by Rob2412
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid