This repository has been archived by the owner on Feb 25, 2023. It is now read-only.
/
lrgba.go
58 lines (47 loc) · 1.69 KB
/
lrgba.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) 2013-2018 Laurent Moussault. All rights reserved.
// Licensed under a simplified BSD license (see LICENSE file).
package color
////////////////////////////////////////////////////////////////////////////////
// LRGBA represents a color in alpha-premultiplied linear color space. Each
// value ranges within [0, 1], and can be used directly by GPU shaders.
//
// An alpha-premultiplied color component c has been scaled by alpha (a), so has
// valid values 0 <= c <= a.
//
// Note that additive blending can also be achieved when alpha is set to 0 while
// the color components are non-null.
type LRGBA struct {
R float32
G float32
B float32
A float32
}
////////////////////////////////////////////////////////////////////////////////
// LRGBAof converts any color to alpha-premultiplied, linear color space.
func LRGBAof(c Color) LRGBA {
r, g, b, a := c.Linear()
return LRGBA{r, g, b, a}
}
////////////////////////////////////////////////////////////////////////////////
// Linear implements the Colour interface.
func (c LRGBA) Linear() (r, g, b, a float32) {
return c.R, c.G, c.B, c.A
}
// Standard implements the Colour interface.
func (c LRGBA) Standard() (r, g, b, a float32) {
r = standardOf(c.R)
g = standardOf(c.G)
b = standardOf(c.B)
return r, g, b, c.A
}
////////////////////////////////////////////////////////////////////////////////
// RGBA implements the image.Color interface: it returns the four components
// scaled by 0xFFFF.
func (c LRGBA) RGBA() (r, g, b, a uint32) {
r = uint32(c.R * 0xFFFF)
g = uint32(c.G * 0xFFFF)
b = uint32(c.B * 0xFFFF)
a = uint32(c.A * 0xFFFF)
return r, g, b, a
}
////////////////////////////////////////////////////////////////////////////////