gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

utils.go (480B)


      1 package blurhash
      2 
      3 import "math"
      4 
      5 func linearTosRGB(value float64) int {
      6 	v := math.Max(0, math.Min(1, value))
      7 	if v <= 0.0031308 {
      8 		return int(v*12.92*255 + 0.5)
      9 	}
     10 	return int((1.055*math.Pow(v, 1/2.4)-0.055)*255 + 0.5)
     11 }
     12 
     13 func sRGBToLinear(value int) float64 {
     14 	v := float64(value) / 255
     15 	if v <= 0.04045 {
     16 		return v / 12.92
     17 	}
     18 	return math.Pow((v+0.055)/1.055, 2.4)
     19 }
     20 
     21 func signPow(value, exp float64) float64 {
     22 	return math.Copysign(math.Pow(math.Abs(value), exp), value)
     23 }