Code review: Modifying RGB by Manipulating HSV colors

That’s fair. I would expect better performance out of a more Java-based solution, but it’s very likely not going to be enough to actually matter.

For posterity, a reimplementation of your method:

def mulColorV(rgbHex, factV):
	from com.inductiveautomation.ignition.common import TypeUtilities
	from java.awt import Color
	javaColor = TypeUtilities.getColorFromString(rgbHex)
	hsl = Color.RGBtoHSB(javaColor.red, javaColor.green, javaColor.blue, None)
	hsl[2] = max(0.0, min(hsl[2] * factV, 1.0))
	hslColor = Color.getHSBColor(*hsl)
	return "#" + TypeUtilities.colorToHex(hslColor)
	
mulColorV("#100000", 0.2)
mulColorV("#100000", 2.0) 
1 Like