package colorful

import 

// Wide-gamut RGB color spaces from CSS Color Level 4.
// https://www.w3.org/TR/css-color-4/#color-conversion-code

/// Bradford ///
////////////////
// Bradford chromatic adaptation between D50 and D65 illuminants.

func (, ,  float64) (, ,  float64) {
	 = 0.9554734527042182* - 0.023098536874261423* + 0.06325964552894382*
	 = -0.028369706963208136* + 1.0099954580058226* + 0.021041398966943008*
	 = 0.012314001688319899* - 0.020507696433477912* + 1.3303659366080753*
	return
}

func (, ,  float64) (, ,  float64) {
	 = 1.0479298208405488* + 0.022946793341019088* - 0.05019222954313557*
	 = 0.029627815688159344* + 0.990434484573249* - 0.01707382502938514*
	 = -0.009243058152591178* + 0.015055144896577895* + 0.7518742899580008*
	return
}

/// XYZ D50 ///
///////////////

func (, ,  float64) Color {
	return Xyz(D50ToD65(, , ))
}

func ( Color) () (, ,  float64) {
	return D65ToD50(.Xyz())
}

/// Display P3 ///
//////////////////
// Uses the sRGB transfer function with DCI-P3 primaries.

func (, ,  float64) (, ,  float64) {
	 = linearize()
	 = linearize()
	 = linearize()
	return
}

func (, ,  float64) (, ,  float64) {
	 = 0.4865709486482162* + 0.26566769316909306* + 0.1982172852343625*
	 = 0.2289745640697488* + 0.6917385218365064* + 0.079286914093745*
	 = 0.04511338185890264* + 1.043944368900976*
	return
}

func (, ,  float64) (, ,  float64) {
	 = 2.493496911941425* - 0.9313836179191239* - 0.40271078445071684*
	 = -0.8294889695615747* + 1.7626640603183463* + 0.023624685841943577*
	 = 0.035845830243784335* - 0.07617238926804182* + 0.9568845240076872*
	return
}

func (, ,  float64) Color {
	, ,  := DisplayP3ToLinearRgb(, , )
	, ,  := LinearDisplayP3ToXyz(, , )
	return Xyz(, , )
}

func ( Color) () (, ,  float64) {
	, ,  := .Xyz()
	, ,  := XyzToLinearDisplayP3(, , )
	 = delinearize()
	 = delinearize()
	 = delinearize()
	return
}

// BlendDisplayP3 blends two colors in the Display P3 color-space.
// t == 0 results in c1, t == 1 results in c2
func ( Color) ( Color,  float64) Color {
	, ,  := .DisplayP3()
	, ,  := .DisplayP3()
	return DisplayP3(
		+*(-),
		+*(-),
		+*(-))
}

/// A98 RGB ///
///////////////
// Adobe RGB (1998) color space.

func ( float64) float64 {
	 := 1.0
	if  < 0 {
		 = -1.0
		 = -
	}
	return  * math.Pow(, 563.0/256.0)
}

func ( float64) float64 {
	 := 1.0
	if  < 0 {
		 = -1.0
		 = -
	}
	return  * math.Pow(, 256.0/563.0)
}

func (, ,  float64) (, ,  float64) {
	 = linearizeA98()
	 = linearizeA98()
	 = linearizeA98()
	return
}

func (, ,  float64) (, ,  float64) {
	 = 0.5766690429101305* + 0.1855582379065463* + 0.1882286462349947*
	 = 0.29734497525053605* + 0.6273635662554661* + 0.07529145849399788*
	 = 0.02703136138641234* + 0.07068885253582723* + 0.9913375368376388*
	return
}

func (, ,  float64) (, ,  float64) {
	 = 2.0415879038107327* - 0.5650069742788597* - 0.34473135077832956*
	 = -0.9692436362808795* + 1.8759675015077202* + 0.04155505740717559*
	 = 0.013444280632031142* - 0.11836239223101838* + 1.0151749943912054*
	return
}

func (, ,  float64) Color {
	, ,  := A98RgbToLinearRgb(, , )
	, ,  := LinearA98RgbToXyz(, , )
	return Xyz(, , )
}

func ( Color) () (, ,  float64) {
	, ,  := .Xyz()
	, ,  := XyzToLinearA98Rgb(, , )
	 = delinearizeA98()
	 = delinearizeA98()
	 = delinearizeA98()
	return
}

// BlendA98Rgb blends two colors in the A98 RGB color-space.
// t == 0 results in c1, t == 1 results in c2
func ( Color) ( Color,  float64) Color {
	, ,  := .A98Rgb()
	, ,  := .A98Rgb()
	return A98Rgb(
		+*(-),
		+*(-),
		+*(-))
}

/// ProPhoto RGB ///
////////////////////
// ProPhoto RGB (ROMM RGB) uses D50 illuminant.

func ( float64) float64 {
	if  <= 16.0/512.0 {
		return  / 16.0
	}
	return math.Pow(, 1.8)
}

func ( float64) float64 {
	if  < 1.0/512.0 {
		return 16.0 * 
	}
	return math.Pow(, 1.0/1.8)
}

func (, ,  float64) (, ,  float64) {
	 = linearizeProPhoto()
	 = linearizeProPhoto()
	 = linearizeProPhoto()
	return
}

func (, ,  float64) (, ,  float64) {
	 = 0.7977604896723027* + 0.13518583717574031* + 0.0313493495815248*
	 = 0.2880711282292934* + 0.7118432178101014* + 0.00008565396060525902*
	 = 0.8251046025104602 * 
	return
}

func (, ,  float64) (, ,  float64) {
	 = 1.3457989731028281* - 0.25558010007997534* - 0.05110628506753401*
	 = -0.5446224939028347* + 1.5082327413132781* + 0.02053603239147973*
	 = 1.2119675456389454 * 
	return
}

func (, ,  float64) Color {
	, ,  := ProPhotoRgbToLinearRgb(, , )
	, ,  := LinearProPhotoRgbToXyzD50(, , )
	return XyzD50(, , )
}

func ( Color) () (, ,  float64) {
	, ,  := .XyzD50()
	, ,  := XyzD50ToLinearProPhotoRgb(, , )
	 = delinearizeProPhoto()
	 = delinearizeProPhoto()
	 = delinearizeProPhoto()
	return
}

// BlendProPhotoRgb blends two colors in the ProPhoto RGB color-space.
// t == 0 results in c1, t == 1 results in c2
func ( Color) ( Color,  float64) Color {
	, ,  := .ProPhotoRgb()
	, ,  := .ProPhotoRgb()
	return ProPhotoRgb(
		+*(-),
		+*(-),
		+*(-))
}

/// Rec. 2020 ///
/////////////////
// ITU-R BT.2020 color space.

const (
	rec2020Alpha = 1.09929682680944
	rec2020Beta  = 0.018053968510807
)

func ( float64) float64 {
	if  < rec2020Beta*4.5 {
		return  / 4.5
	}
	return math.Pow((+rec2020Alpha-1)/rec2020Alpha, 1.0/0.45)
}

func ( float64) float64 {
	if  < rec2020Beta {
		return 4.5 * 
	}
	return rec2020Alpha*math.Pow(, 0.45) - (rec2020Alpha - 1)
}

func (, ,  float64) (, ,  float64) {
	 = linearizeRec2020()
	 = linearizeRec2020()
	 = linearizeRec2020()
	return
}

func (, ,  float64) (, ,  float64) {
	 = 0.6369580483012914* + 0.14461690358620832* + 0.1688809751641721*
	 = 0.2627002120112671* + 0.6779980715188708* + 0.05930171646986196*
	 = 0.028072693049087428* + 1.0609850577107909*
	return
}

func (, ,  float64) (, ,  float64) {
	 = 1.7166511879712674* - 0.35567078377639233* - 0.25336628137365974*
	 = -0.666684351832489* + 1.616481236634939* + 0.0157685458139402*
	 = 0.017639857445310783* - 0.042770613257808524* + 0.9421031212354738*
	return
}

func (, ,  float64) Color {
	, ,  := Rec2020ToLinearRgb(, , )
	, ,  := LinearRec2020ToXyz(, , )
	return Xyz(, , )
}

func ( Color) () (, ,  float64) {
	, ,  := .Xyz()
	, ,  := XyzToLinearRec2020(, , )
	 = delinearizeRec2020()
	 = delinearizeRec2020()
	 = delinearizeRec2020()
	return
}

// BlendRec2020 blends two colors in the Rec. 2020 color-space.
// t == 0 results in c1, t == 1 results in c2
func ( Color) ( Color,  float64) Color {
	, ,  := .Rec2020()
	, ,  := .Rec2020()
	return Rec2020(
		+*(-),
		+*(-),
		+*(-))
}