Compare commits
5 Commits
v0.3.0
...
0f903cc8ec
| Author | SHA1 | Date | |
|---|---|---|---|
| 0f903cc8ec | |||
| 19fcdb4a7d | |||
| 6bfa97e6aa | |||
| f647b544e2 | |||
| 1911987c59 |
@@ -22,9 +22,9 @@ func ToRGBA (c color.Color) color.RGBA {
|
||||
// Premultiply applies alpha-premultiplication that colors must apply as per
|
||||
// color.Color.RGBA. This is an intrinsically lossy proccess.
|
||||
func Premultiply (ur, ug, ub, ua uint32) (r, g, b, a uint32) {
|
||||
return (ur * a) / 0xFFFF,
|
||||
(ug * a) / 0xFFFF,
|
||||
(ub * a) / 0xFFFF,
|
||||
return (ur * ua) / 0xFFFF,
|
||||
(ug * ua) / 0xFFFF,
|
||||
(ub * ua) / 0xFFFF,
|
||||
ua
|
||||
}
|
||||
|
||||
|
||||
34
image/color/color_test.go
Normal file
34
image/color/color_test.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package ucolor
|
||||
|
||||
import "testing"
|
||||
import "image/color"
|
||||
|
||||
func TestTransparent (test *testing.T) {
|
||||
if Transparent(color.NRGBA { A: 255 }) {
|
||||
test.Fatal("false positive")
|
||||
}
|
||||
if !Transparent(color.NRGBA { A: 0 }) {
|
||||
test.Fatal("false negative")
|
||||
}
|
||||
}
|
||||
|
||||
func TestToRGBA (test *testing.T) {
|
||||
rgba := ToRGBA(color.NRGBA { R: 123, G: 100, B: 23, A: 230 })
|
||||
if rgba != (color.RGBA { R: 111, G: 90, B: 20, A: 230 }) {
|
||||
test.Fatalf("wrong value: %v", rgba)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPremultiply (test *testing.T) {
|
||||
r, g, b, a := Premultiply(0xFFFF, 0xFFFF, 0xFFFF, 0x8888)
|
||||
if r != 0x8888 || g != 0x8888 || b != 0x8888 || a != 0x8888 {
|
||||
test.Fatalf("wrong value: %08x %08x %08x %08x", r, g, b, a)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnpremultiply (test *testing.T) {
|
||||
r, g, b, a := Unpremultiply(0x8888, 0x8888, 0x8888, 0x8888)
|
||||
if r != 0xFFFF || g != 0xFFFF || b != 0xFFFF || a != 0x8888 {
|
||||
test.Fatalf("wrong value: %08x %08x %08x %08x", r, g, b, a)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user