Looking to create a CTL with a colour transform that is de-saturates a pair of opposing colours.
My example below works: but not as expected:
__DEVICE__ float3 squeeze_GM(float percentage, float R, float G, float B) {
float rOut = R - (((percentage/2) / 100) * R);
float gOut = G - ((percentage / 100) * G);
float bOut = B - (((percentage/2) / 100) * B);
return make_float3(rOut, gOut, bOut);
}
__DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p_R, float p_G, float p_B){
float3 result = squeeze_GM(15, p_R, p_G, p_B);
return result;
}
I would like to squeeze the green and magenta, so as to de-saturate these colours by a certain percentage passed to the squeeze_GM
function.
Does anyone have any details how I might get this transform? At the moment I think I am just making the RGB values darker by a certain percentage. Would I need to average my R and B results?
Look at Wiki for HUE
An idea could be:
void HSV(uint8_t rgb[]){
int32_t r,g,b;
int32_t MaxVal,Minim,MedValue,MinValue;
int32_t Huecalc=0;
r=rgb[0];
g=rgb[1];
b=rgb[2];
Minim=255;
if(Minim>r)Minim=r; //if red=128
if(Minim>g)Minim=g; //if green=200
if(Minim>b)Minim=b; //if blue= 254
// Minim = 128;
MaxVal=0;
if(MaxVal<r)MaxVal=r; //if red=128
if(MaxVal<g)MaxVal=g; //if green=200
if(MaxVal<b)MaxVal=b; //if blue= 254
// MaxVal = 254
MedValue=MaxVal-Minim; // MedValue = 254-128 > 0
MinValue=Minim; // MinValue = 128
if(MedValue>0){
if(MaxVal==r)Huecalc=0L*MedValue+(g-b); // Wiki HUE THEORY explain this
if(MaxVal==g)Huecalc=2L*MedValue+(b-r);
if(MaxVal==b)Huecalc=4L*MedValue+(r-g);
HUE=Huecalc*254/6/MedValue; // %254
}
if(MinValue>0){
SAT=MedValue*254/MinValue; // %254
}
}