Test and fix ValueColor.RGBA
This commit is contained in:
parent
f42dee22f5
commit
90072d8a9e
17
internal/style/tss/color_test.go
Normal file
17
internal/style/tss/color_test.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package tss
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestValueColor (test *testing.T) {
|
||||||
|
testValueColorRGBA(test, 0xFB380CFF, 0xFBFB, 0x3838, 0x0C0C, 0xFFFF)
|
||||||
|
testValueColorRGBA(test, 0xFB380C00, 0x0000, 0x0000, 0x0000, 0x0000)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testValueColorRGBA (test *testing.T, col ValueColor, r, g, b, a uint32) {
|
||||||
|
gr, gg, gb, ga := col.RGBA()
|
||||||
|
test.Logf("testing RGBA for color #%08X", col)
|
||||||
|
if gr != r { test.Errorf("r component inequal (%04X != %04X)", gr, r) }
|
||||||
|
if gg != g { test.Errorf("g component inequal (%04X != %04X)", gg, g) }
|
||||||
|
if gb != b { test.Errorf("b component inequal (%04X != %04X)", gb, b) }
|
||||||
|
if ga != a { test.Errorf("a component inequal (%04X != %04X)", ga, a) }
|
||||||
|
}
|
@ -35,19 +35,19 @@ func (ValueColor) value () { }
|
|||||||
func (value ValueColor) RGBA () (r, g, b, a uint32) {
|
func (value ValueColor) RGBA () (r, g, b, a uint32) {
|
||||||
// extract components
|
// extract components
|
||||||
bits := uint32(value)
|
bits := uint32(value)
|
||||||
r = (bits & 0xF000) >> 24
|
r = (bits & 0xFF000000) >> 24
|
||||||
g = (bits & 0x0F00) >> 16
|
g = (bits & 0x00FF0000) >> 16
|
||||||
b = (bits & 0x00F0) >> 8
|
b = (bits & 0x0000FF00) >> 8
|
||||||
a = (bits & 0x000A)
|
a = (bits & 0x000000FF)
|
||||||
// extend to 16 bits per channel
|
// extend to 16 bits per channel
|
||||||
r = r << 8 | r
|
r = r << 8 | r
|
||||||
g = g << 8 | g
|
g = g << 8 | g
|
||||||
b = b << 8 | b
|
b = b << 8 | b
|
||||||
a = a << 8 | a
|
a = a << 8 | a
|
||||||
// alpha premultiply
|
// alpha premultiply
|
||||||
r = (r * a) / 256
|
r = (r * a) / 0xFFFF
|
||||||
g = (g * a) / 256
|
g = (g * a) / 0xFFFF
|
||||||
b = (b * a) / 256
|
b = (b * a) / 0xFFFF
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user