This repository has been archived by the owner on Feb 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
lrgbna.go
52 lines (41 loc) · 1.57 KB
/
lrgbna.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
// Copyright (c) 2013-2018 Laurent Moussault. All rights reserved.
// Licensed under a simplified BSD license (see LICENSE file).
package color
////////////////////////////////////////////////////////////////////////////////
// LRGBnA represents a color in *non* alpha-premultiplied linear color
// space. Each value ranges within [0, 1], and can be used directly by GPU
// shaders.
//
// Note: prefer RGBA for use in shaders.
type LRGBnA struct {
R float32
G float32
B float32
A float32
}
////////////////////////////////////////////////////////////////////////////////
// LRGBnAof converts any color to non alpha-premultiplied linear color
// space.
func LRGBnAof(c Color) LRGBnA {
r, g, b, a := c.Linear()
return LRGBnA{r / a, g / a, b / a, a}
}
////////////////////////////////////////////////////////////////////////////////
// Linear implements the Colour interface.
func (c LRGBnA) Linear() (r, g, b, a float32) {
return c.A * c.R, c.A * c.G, c.A * c.B, c.A
}
// Standard implements the Colour interface.
func (c LRGBnA) Standard() (r, g, b, a float32) {
r = standardOf(c.A * c.R)
g = standardOf(c.A * c.G)
b = standardOf(c.A * c.B)
return r, g, b, c.A
}
////////////////////////////////////////////////////////////////////////////////
// RGBA implements the image.Color interface: it returns the four components
// scaled by 0xFFFF.
func (c LRGBnA) RGBA() (r, g, b, a uint32) {
return uint32(c.A * c.R * 0xFFFF), uint32(c.A * c.G * 0xFFFF), uint32(c.A * c.B * 0xFFFF), uint32(c.A * 0xFFFF)
}
////////////////////////////////////////////////////////////////////////////////