cam16

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Blend

func Blend(pct float32, x, y color.Color) color.RGBA

Blend returns a color that is the given percent blend between the first and second color; 10 = 10% of the first and 90% of the second, etc; blending is done directly on non-premultiplied CAM16-UCS values, and a correctly premultiplied color is returned.

func InCyclicOrder

func InCyclicOrder(a, b, c float32) bool

InCyclicOrder returns true a, b, c are in order around a circle

func InverseChromaticAdapt

func InverseChromaticAdapt(adapted float32) float32

func LMSToOps

func LMSToOps(l, m, s float32, vw *View) (redVgreen, yellowVblue, grey, greyNorm float32)

LMSToOps converts Long, Medium, Short cone-based values to opponent redVgreen (a) and yellowVblue (b), and grey (achromatic) values, that more closely reflect neural responses. greyNorm is a normalizing grey factor used in the CAM16 model. l, m, s values must be in 100-base units. Uses the CIECAM16 color appearance model.

func LMSToXYZ

func LMSToXYZ(l, m, s float32) (x, y, z float32)

LMSToXYZ converts Long, Medium, Short cone-based responses to XYZ using the CAT16 transform from CIECAM16 color appearance model (LiLiWangEtAl17)

func LuminanceAdapt

func LuminanceAdapt(l, m, s float32, vw *View) (lA, mA, sA float32)

LuminanceAdapt performs luminance adaptation and response compression according to the CAM16 model, on given r,g,b components, using equations from HuntLiLuo03 and parameters on given viewing conditions

func LuminanceAdaptComp

func LuminanceAdaptComp(v, d, fl float32) float32

LuminanceAdaptComp performs luminance adaptation and response compression according to the CAM16 model, on one component, using equations from HuntLiLuo03 d = discount factor fl = luminance adaptation factor

func SanitizeDegrees added in v0.0.7

func SanitizeDegrees(deg float32) float32

SanitizeDegrees ensures that degrees is in [0-360) range

func SanitizeRadians

func SanitizeRadians(angle float32) float32

SanitizeRadians sanitizes a small enough angle in radians. Takes an angle in radians; must not deviate too much from 0, and returns a coterminal angle between 0 and 2pi.

func XYZToLMS

func XYZToLMS(x, y, z float32) (l, m, s float32)

XYZToLMS converts XYZ to Long, Medium, Short cone-based responses, using the CAT16 transform from CIECAM16 color appearance model (LiLiWangEtAl17)

Types

type CAM

type CAM struct {

	// hue (h) is the spectral identity of the color (red, green, blue etc) in degrees (0-360)
	Hue float32

	// chroma (C) is the colorfulness or saturation of the color -- greyscale colors have no chroma, and fully saturated ones have high chroma
	Chroma float32

	// colorfulness (M) is the absolute chromatic intensity
	Colorfulness float32

	// saturation (s) is the colorfulness relative to brightness
	Saturation float32

	// brightness (Q) is the apparent amount of light from the color, which is not a simple function of actual light energy emitted
	Brightness float32

	// lightness (J) is the brightness relative to a reference white, which varies as a function of chroma and hue
	Lightness float32
}

CAM represents a point in the cam16 color model along 6 dimensions representing the perceived hue, colorfulness, and brightness, similar to HSL but much more well-calibrated to actual human subjective judgments.

func FromJCH

func FromJCH(j, c, h float32) *CAM

FromJCH returns CAM values from the given lightness (j), chroma (c), and hue (h) values under standard viewing condition

func FromJCHView

func FromJCHView(j, c, h float32, vw *View) *CAM

FromJCHView returns CAM values from the given lightness (j), chroma (c), and hue (h) values under the given viewing conditions

func FromSRGB

func FromSRGB(r, g, b float32) *CAM

FromSRGB returns CAM values from given SRGB color coordinates, under standard viewing conditions. The RGB value range is 0-1, and RGB values have gamma correction.

func FromUCS

func FromUCS(j, a, b float32) *CAM

FromUCS returns CAM values from the given CAM16-UCS coordinates (jstar, astar, and bstar), under standard viewing conditions

func FromUCSView

func FromUCSView(j, a, b float32, vw *View) *CAM

FromUCS returns CAM values from the given CAM16-UCS coordinates (jstar, astar, and bstar), using the given viewing conditions

func FromXYZ

func FromXYZ(x, y, z float32) *CAM

FromXYZ returns CAM values from given XYZ color coordinate, under standard viewing conditions

func FromXYZView

func FromXYZView(x, y, z float32, vw *View) *CAM

FromXYZView returns CAM values from given XYZ color coordinate, under given viewing conditions. Requires 100-base XYZ coordinates.

func (*CAM) AsRGBA

func (cam *CAM) AsRGBA() color.RGBA

AsRGBA returns the color as a color.RGBA.

func (*CAM) RGBA

func (cam *CAM) RGBA() (r, g, b, a uint32)

RGBA implements the color.Color interface.

func (*CAM) UCS

func (cam *CAM) UCS() (j, m, a, b float32)

UCS returns the CAM16-UCS components based on the the CAM values

func (*CAM) XYZ

func (cam *CAM) XYZ() (x, y, z float32)

XYZ returns the CAM color as XYZ coordinates under standard viewing conditions. Returns 100-base XYZ coordinates.

func (*CAM) XYZView

func (cam *CAM) XYZView(vw *View) (x, y, z float32)

XYZ returns the CAM color as XYZ coordinates under the given viewing conditions. Returns 100-base XYZ coordinates.

type View

type View struct {

	// white point illumination -- typically cie.WhiteD65
	WhitePoint math32.Vector3

	// the ambient light strength in lux
	Luminance float32 `default:"200"`

	// the average luminance of 10 degrees around the color in question
	BgLuminance float32 `default:"50"`

	// the brightness of the entire environment
	Surround float32 `default:"2"`

	// whether the person's eyes have adapted to the lighting
	Adapted bool `default:"false"`

	// computed from Luminance
	AdaptingLuminance float32 `view:"-"`

	//
	BgYToWhiteY float32 `view:"-"`

	//
	AW float32 `view:"-"`

	// luminance level induction factor
	NBB float32 `view:"-"`

	// luminance level induction factor
	NCB float32 `view:"-"`

	// exponential nonlinearity
	C float32 `view:"-"`

	// chromatic induction factor
	NC float32 `view:"-"`

	// luminance-level adaptation factor, based on the HuntLiLuo03 equations
	FL float32 `view:"-"`

	// FL to the 1/4 power
	FLRoot float32 `view:"-"`

	// base exponential nonlinearity
	Z float32 `view:"-"`

	// inverse of the RGBD factors
	DRGBInverse math32.Vector3 `view:"-"`

	// cone responses to white point, adjusted for discounting
	RGBD math32.Vector3 `view:"-"`
}

View represents viewing conditions under which a color is being perceived, which greatly affects the subjective perception. Defaults represent the standard defined such conditions, under which the CAM16 computations operate.

var TheStdView *View

TheStdView is the standard viewing conditions view returned by NewStdView if already created.

func NewStdView

func NewStdView() *View

NewStdView returns a new standard viewing conditions model returns TheStdView if already created

func NewView

func NewView(whitePoint math32.Vector3, lum, bgLum, surround float32, adapt bool) *View

NewView returns a new view with all parameters initialized based on given major params

func (*View) Update

func (vw *View) Update()

Update updates all the computed values based on main parameters

Jump to

Keyboard shortcuts

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