ciexyz

package
v0.35.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package ciexyz provides support for the CIE XYZ colour space. This is an intermediate colour space for conversions between RGB colour spaces and to and from CIE Lab, and so this package also provides tools for generating the relevant transforms.

Index

Examples

Constants

This section is empty.

Variables

View Source
var D50 = Color{0.9642, 1.0, 0.8251}
View Source
var D65 = Color{0.95047, 1.0, 1.08883}

Functions

func TransformFromXYZForXYYPrimaries added in v0.15.0

func TransformFromXYZForXYYPrimaries(r, g, b ciexyy.Color, whitePoint ciexyy.Color) matrix.Matrix3

TransformFromXYZForXYYPrimaries generates the column matrix for converting colour values from CIE XYZ to a space defined by three RGB primary chromaticities and a reference white.

Example (GenerateAdobeRGBMatrix)
package main

import (
	"fmt"
	"github.com/mandykoh/prism/adobergb"
	"github.com/mandykoh/prism/ciexyz"
)

func main() {
	transform := ciexyz.TransformFromXYZForXYYPrimaries(
		adobergb.PrimaryRed,
		adobergb.PrimaryGreen,
		adobergb.PrimaryBlue,
		adobergb.StandardWhitePoint)

	fmt.Printf("R = c.X*%f + c.Y*%f + c.Z*%f\n", transform[0][0], transform[1][0], transform[2][0])
	fmt.Printf("G = c.X*%f + c.Y*%f + c.Z*%f\n", transform[0][1], transform[1][1], transform[2][1])
	fmt.Printf("B = c.X*%f + c.Y*%f + c.Z*%f\n", transform[0][2], transform[1][2], transform[2][2])

}
Output:

R = c.X*2.041591 + c.Y*-0.565008 + c.Z*-0.344732
G = c.X*-0.969224 + c.Y*1.875930 + c.Z*0.041554
B = c.X*0.013446 + c.Y*-0.118381 + c.Z*1.015338
Example (GenerateDisplayP3Matrix)
package main

import (
	"fmt"
	"github.com/mandykoh/prism/ciexyz"
	"github.com/mandykoh/prism/displayp3"
)

func main() {
	transform := ciexyz.TransformFromXYZForXYYPrimaries(
		displayp3.PrimaryRed,
		displayp3.PrimaryGreen,
		displayp3.PrimaryBlue,
		displayp3.StandardWhitePoint)

	fmt.Printf("R = c.X*%f + c.Y*%f + c.Z*%f\n", transform[0][0], transform[1][0], transform[2][0])
	fmt.Printf("G = c.X*%f + c.Y*%f + c.Z*%f\n", transform[0][1], transform[1][1], transform[2][1])
	fmt.Printf("B = c.X*%f + c.Y*%f + c.Z*%f\n", transform[0][2], transform[1][2], transform[2][2])

}
Output:

R = c.X*2.493509 + c.Y*-0.931388 + c.Z*-0.402713
G = c.X*-0.829473 + c.Y*1.762631 + c.Z*0.023624
B = c.X*0.035851 + c.Y*-0.076184 + c.Z*0.957030
Example (GenerateProPhotoRGBMatrix)
package main

import (
	"fmt"
	"github.com/mandykoh/prism/ciexyz"
	"github.com/mandykoh/prism/prophotorgb"
)

func main() {
	transform := ciexyz.TransformFromXYZForXYYPrimaries(
		prophotorgb.PrimaryRed,
		prophotorgb.PrimaryGreen,
		prophotorgb.PrimaryBlue,
		prophotorgb.StandardWhitePoint)

	fmt.Printf("R = c.X*%v + c.Y*%v + c.Z*%v\n", transform[0][0], transform[1][0], transform[2][0])
	fmt.Printf("G = c.X*%v + c.Y*%v + c.Z*%v\n", transform[0][1], transform[1][1], transform[2][1])
	fmt.Printf("B = c.X*%v + c.Y*%v + c.Z*%v\n", transform[0][2], transform[1][2], transform[2][2])

}
Output:

R = c.X*1.3459441751995702 + c.Y*-0.255601933365717 + c.Z*-0.05110784199842092
G = c.X*-0.5446048748563069 + c.Y*1.5081763487167865 + c.Z*0.020526475602742393
B = c.X*0 + c.Y*-0 + c.Z*1.2118446483846639
Example (GenerateSRGBMatrix)
package main

import (
	"fmt"
	"github.com/mandykoh/prism/ciexyz"
	"github.com/mandykoh/prism/srgb"
)

func main() {
	transform := ciexyz.TransformFromXYZForXYYPrimaries(
		srgb.PrimaryRed,
		srgb.PrimaryGreen,
		srgb.PrimaryBlue,
		srgb.StandardWhitePoint)

	fmt.Printf("R = c.X*%f + c.Y*%f + c.Z*%f\n", transform[0][0], transform[1][0], transform[2][0])
	fmt.Printf("G = c.X*%f + c.Y*%f + c.Z*%f\n", transform[0][1], transform[1][1], transform[2][1])
	fmt.Printf("B = c.X*%f + c.Y*%f + c.Z*%f\n", transform[0][2], transform[1][2], transform[2][2])

}
Output:

R = c.X*3.241004 + c.Y*-1.537399 + c.Z*-0.498616
G = c.X*-0.969224 + c.Y*1.875930 + c.Z*0.041554
B = c.X*0.055639 + c.Y*-0.204011 + c.Z*1.057149

func TransformToXYZForXYYPrimaries added in v0.15.0

func TransformToXYZForXYYPrimaries(r, g, b ciexyy.Color, whitePoint ciexyy.Color) matrix.Matrix3

TransformToXYZForXYYPrimaries generates the column matrix for converting colour values from a space defined by three primary RGB chromaticities and a reference white to CIE XYZ.

Example (GenerateAdobeRGBMatrix)
package main

import (
	"fmt"
	"github.com/mandykoh/prism/adobergb"
	"github.com/mandykoh/prism/ciexyz"
)

func main() {
	transform := ciexyz.TransformToXYZForXYYPrimaries(
		adobergb.PrimaryRed,
		adobergb.PrimaryGreen,
		adobergb.PrimaryBlue,
		adobergb.StandardWhitePoint)

	fmt.Printf("X = c.R*%f + c.G*%f + c.B*%f\n", transform[0][0], transform[1][0], transform[2][0])
	fmt.Printf("Y = c.R*%f + c.G*%f + c.B*%f\n", transform[0][1], transform[1][1], transform[2][1])
	fmt.Printf("Z = c.R*%f + c.G*%f + c.B*%f\n", transform[0][2], transform[1][2], transform[2][2])

}
Output:

X = c.R*0.576668 + c.G*0.185562 + c.B*0.188199
Y = c.R*0.297344 + c.G*0.627376 + c.B*0.075279
Z = c.R*0.027031 + c.G*0.070690 + c.B*0.991179
Example (GenerateDisplayP3Matrix)
package main

import (
	"fmt"
	"github.com/mandykoh/prism/ciexyz"
	"github.com/mandykoh/prism/displayp3"
)

func main() {
	transform := ciexyz.TransformToXYZForXYYPrimaries(
		displayp3.PrimaryRed,
		displayp3.PrimaryGreen,
		displayp3.PrimaryBlue,
		displayp3.StandardWhitePoint)

	fmt.Printf("X = c.R*%f + c.G*%f + c.B*%f\n", transform[0][0], transform[1][0], transform[2][0])
	fmt.Printf("Y = c.R*%f + c.G*%f + c.B*%f\n", transform[0][1], transform[1][1], transform[2][1])
	fmt.Printf("Z = c.R*%f + c.G*%f + c.B*%f\n", transform[0][2], transform[1][2], transform[2][2])

}
Output:

X = c.R*0.486569 + c.G*0.265673 + c.B*0.198187
Y = c.R*0.228973 + c.G*0.691752 + c.B*0.079275
Z = c.R*0.000000 + c.G*0.045114 + c.B*1.043786
Example (GenerateProPhotoRGBMatrix)
package main

import (
	"fmt"
	"github.com/mandykoh/prism/ciexyz"
	"github.com/mandykoh/prism/prophotorgb"
)

func main() {
	transform := ciexyz.TransformToXYZForXYYPrimaries(
		prophotorgb.PrimaryRed,
		prophotorgb.PrimaryGreen,
		prophotorgb.PrimaryBlue,
		prophotorgb.StandardWhitePoint)

	fmt.Printf("X = c.R*%v + c.G*%v + c.B*%v\n", transform[0][0], transform[1][0], transform[2][0])
	fmt.Printf("Y = c.R*%v + c.G*%v + c.B*%v\n", transform[0][1], transform[1][1], transform[2][1])
	fmt.Printf("Z = c.R*%v + c.G*%v + c.B*%v\n", transform[0][2], transform[1][2], transform[2][2])

}
Output:

X = c.R*0.7976734029450476 + c.G*0.13518768157360342 + c.B*0.03135091585137471
Y = c.R*0.28804113269427045 + c.G*0.7118689212431865 + c.B*8.994606254312391e-05
Z = c.R*0 + c.G*0 + c.B*0.8251882791519165
Example (GenerateSRGBMatrix)
package main

import (
	"fmt"
	"github.com/mandykoh/prism/ciexyz"
	"github.com/mandykoh/prism/srgb"
)

func main() {
	transform := ciexyz.TransformToXYZForXYYPrimaries(
		srgb.PrimaryRed,
		srgb.PrimaryGreen,
		srgb.PrimaryBlue,
		srgb.StandardWhitePoint)

	fmt.Printf("X = c.R*%v + c.G*%v + c.B*%v\n", transform[0][0], transform[1][0], transform[2][0])
	fmt.Printf("Y = c.R*%v + c.G*%v + c.B*%v\n", transform[0][1], transform[1][1], transform[2][1])
	fmt.Printf("Z = c.R*%v + c.G*%v + c.B*%v\n", transform[0][2], transform[1][2], transform[2][2])

}
Output:

X = c.R*0.41238652374145657 + c.G*0.35759149384555927 + c.B*0.18045052788799043
Y = c.R*0.21263680803732615 + c.G*0.7151829876911185 + c.B*0.07218020427155547
Z = c.R*0.019330619488581533 + c.G*0.11919711488225383 + c.B*0.9503727125209493

Types

type ChromaticAdaptation added in v0.13.0

type ChromaticAdaptation matrix.Matrix3

ChromaticAdaptation represents an adaptation from one reference white point to another in XYZ space.

func AdaptBetweenXYYWhitePoints added in v0.15.0

func AdaptBetweenXYYWhitePoints(srcWhite ciexyy.Color, dstWhite ciexyy.Color) ChromaticAdaptation

AdaptBetweenXYYWhitePoints returns a ChromaticAdaptation from the source white point to the destination.

func AdaptBetweenXYZWhitePoints added in v0.15.0

func AdaptBetweenXYZWhitePoints(srcWhite Color, dstWhite Color) ChromaticAdaptation

AdaptBetweenXYZWhitePoints returns a ChromaticAdaptation from the source white point to the destination.

func (ChromaticAdaptation) Apply added in v0.13.0

func (ca ChromaticAdaptation) Apply(c Color) Color

Apply transforms the specified colour using this chromatic adaptation.

type Color

type Color struct {
	X float32
	Y float32
	Z float32
}

Color represents a linear normalised colour in CIE XYZ space.

func ColorFromLAB added in v0.7.0

func ColorFromLAB(lab cielab.Color, whitePoint Color) Color

ColorFromLAB creates a CIE XYZ Color instance from a CIE LAB representation given a reference white point.

func ColorFromV added in v0.11.0

func ColorFromV(v matrix.Vector3) Color

ColorFromV creates a CIE XYZ colour instance from a vector.

func ColorFromXYY added in v0.15.0

func ColorFromXYY(c ciexyy.Color) Color

ColorFromXYY creates a CIE XYZ Color instance from a CIE xyY representation.

func (Color) ToLAB added in v0.7.0

func (c Color) ToLAB(whitePoint Color) cielab.Color

ToLAB converts this colour to a CIE Lab colour given a reference white point.

func (Color) ToV added in v0.11.0

func (c Color) ToV() matrix.Vector3

ToV returns this CIE XYZ colour as a vector.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL