package d2raster

import 

// COLRv1 gradient stops use byte channels, so their sRGB decoding has only
// 256 possible inputs. Decode each value once instead of evaluating the power
// function for both endpoints of every painted pixel.
var linearSRGBByte = func() [256]float64 {
	var  [256]float64
	for  := range  {
		[] = srgbToLinear(float64() / 255)
	}
	return 
}()

func srgbToLinear( float64) float64 {
	 = math.Max(0, math.Min(1, ))
	if  <= 0.04045 {
		return  / 12.92
	}
	return math.Pow((+0.055)/1.055, 2.4)
}

func premultipliedSRGBByteToLinear(,  uint8) float64 {
	if  == 0 {
		return 0
	}
	if  == 0xff {
		return linearSRGBByte[]
	}
	return srgbToLinear(float64() / float64())
}

func linearToSRGB( float64) float64 {
	 = math.Max(0, math.Min(1, ))
	if  <= 0.0031308 {
		return 12.92 * 
	}
	return 1.055*math.Pow(, 1/2.4) - 0.055
}