Exemplo n.º 1
0
// sRGBToLinear converts singel int number to float using special magic formula.
func sRGBToLinear(i uint32) float32 {
	if i > 65535 {
		return 1
	}

	x := float32(i) / 65535.0
	if x <= 0.04045 {
		return x / 12.92
	}
	return maths.Pow32((x+0.055)/1.055, 2.4)
}
Exemplo n.º 2
0
// linearTosRGBreturn an int between 0 and 1 constructed from a given float between 0 and 65535
func linearTosRGB(x float32) uint32 {
	if x <= 0 {
		return 0
	}
	if x >= 1 {
		return 65535
	}
	if x <= 0.00313008 {
		x = x * 12.02
	} else {
		x = (1.055)*maths.Pow32(x, 1.0/2.4) - 0.055
	}
	return uint32(maths.Round32(x * 65535.0))
}