Created
September 16, 2016 04:56
-
-
Save ipetepete/d5caf1a40bca98befee8d12f182f3a35 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define Pr .299 | |
#define Pg .587 | |
#define Pb .114 | |
// public-domain function by Darel Rex Finley | |
// | |
// The passed-in RGB values can be on any desired scale, such as 0 to | |
// to 1, or 0 to 255. (But use the same scale for all three!) | |
// | |
// The "change" parameter works like this: | |
// 0.0 creates a black-and-white image. | |
// 0.5 reduces the color saturation by half. | |
// 1.0 causes no change. | |
// 2.0 doubles the color saturation. | |
// Note: A "change" value greater than 1.0 may project your RGB values | |
// beyond their normal range, in which case you probably should truncate | |
// them to the desired range before trying to use them in an image. | |
void changeSaturation(double *R, double *G, double *B, double change) { | |
double P=sqrt( | |
(*R)*(*R)*Pr+ | |
(*G)*(*G)*Pg+ | |
(*B)*(*B)*Pb ) ; | |
*R=P+((*R)-P)*change; | |
*G=P+((*G)-P)*change; | |
*B=P+((*B)-P)*change; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment