in my c#-application, I use an RGB to HSV (and back) converter for changing a specified color-spectrum to another. In the actual case:
rgb1=5,122,255 to rgb2=22,165,220
similar colors to rgb1 will be changed to the related color, by saving the HSV-difference between hsv1 and hsv2 and aplying these to every similar color.
doing this in HSV was verry helpfull, since in RGB I wasn't able to archive this, but now i get errors, because sometimes an HSV-Value gets negative.
So my question, if an H(0>n>360) S,V(0>n>1) gets beneath or above its value-area, how do i need to change it (and do I also need to change the other two values) for getting the right value?
Calculation Example:
//Value Definition
hsvMainColor = 250/0.5/0.2
hsvSimilarColor = 260/0.6/0.4
hsvDestinationColor = 280/0.8/0.1
hsvMemory = null
hsvOutput = null
//Memorizing Differences
hsvMemory.H = hsvSimilarColor.H - hsvMainColor.H
= 260 - 250
= 10
hsvMemory.S = hsvSimilarColor.S - hsvMainColor.S
= 0.5 - 0.6
= -0.1
hsvMemory.V = hsvSimilarColor.V - hsvMainColor.V
= 0.2 - 0.4
= -0.2
//Creating hsvOutput by applying Differences to hsvDestination
hsvOutput.H = hsvDestination.H + thsvMemory.H
= 280 + 10
= 290
hsvOutput.S = hsvDestination.S + hsvMemory.S
= 0.8 + (-0.1)
= 0.7
hsvOutput.V = hsvDestination.V + hsvMemory.V
= 0.1 + (-0.2)
= (-0.1)
//Now I have a negative Value!
hsvOutput == 30/0.7/(-0.1)