Documentation
¶
Overview ¶
Package oklab implements the Oklab color space, as described at https://bottosson.github.io/posts/oklab/
Example (ConvertOklabToRGB) ¶
package main
import (
"fmt"
"github.com/alltom/oklab"
)
func main() {
oklabc := oklab.Oklab{L: 0.9322421414586456, A: 0.03673270292094283, B: 0.0006123556644819055}
r, g, b, _ := oklabc.RGBA()
fmt.Printf("R: 0x%x, G: 0x%x, B: 0x%x\n", r>>8, g>>8, b>>8)
}
Output: R: 0xff, G: 0xdf, B: 0xe7
Example (ConvertToOklab) ¶
package main
import (
"fmt"
"github.com/alltom/oklab"
"image/color"
)
func main() {
rgbc := color.RGBA{0xff, 0xdf, 0xe7, 0xff}
oklabc := oklab.OklabModel.Convert(rgbc).(oklab.Oklab)
fmt.Printf("L: %.2f, a: %.2f, b: %.2f\n", oklabc.L, oklabc.A, oklabc.B)
}
Output: L: 0.93, a: 0.04, b: 0.00
Example (GradientImage) ¶
package main
import (
"fmt"
"github.com/alltom/oklab"
"image"
"image/color"
"image/png"
"os"
)
func main() {
f, _ := os.Create("gradient.png")
png.Encode(f, GradientImage{})
fmt.Println("err =", f.Close())
}
type GradientImage struct{}
func (g GradientImage) ColorModel() color.Model {
return oklab.OklabModel
}
func (g GradientImage) Bounds() image.Rectangle {
return image.Rect(0, 0, 1200, 600)
}
func (g GradientImage) At(x, y int) color.Color {
a := lerp(float64(x)/float64(g.Bounds().Dx()), -0.233888, 0.276216)
b := lerp(float64(y)/float64(g.Bounds().Dy()), -0.311528, 0.198570)
return oklab.Oklab{0.8, a, b}
}
func lerp(x, min, max float64) float64 {
return x*(max-min) + min
}
Output: err = <nil>
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var OklabModel = color.ModelFunc(oklabModel)
View Source
var OklchModel = color.ModelFunc(oklchModel)
Functions ¶
This section is empty.
Types ¶
type Oklab ¶
type Oklab struct {
L float64 // Perceived lightness
A float64 // How green/red the color is
B float64 // How blue/yellow the color is
}
func (Oklab) LinearSRGB ¶
Convert to linear sRGB. See https://bottosson.github.io/posts/oklab/
Click to show internal directories.
Click to hide internal directories.