diff --git a/oklab.go b/oklab.go index 1960066..54c38cc 100644 --- a/oklab.go +++ b/oklab.go @@ -194,5 +194,8 @@ var ( Model = color.ModelFunc(okLabModel) // Type assertions. - _ NRGBAColor = Color{} + _ interface { + color.Color + NRGBAColor + } = Color{} ) diff --git a/oklab_test.go b/oklab_test.go index c3b4210..cdc82cb 100644 --- a/oklab_test.go +++ b/oklab_test.go @@ -76,6 +76,18 @@ func fixedNRGBA64Model(c color.Color) color.Color { return color.NRGBA64Model.Convert(c) } +type testNRGBAColor struct { + color.NRGBA64 +} + +func (c testNRGBAColor) NRGBA() (r, g, b, a uint32) { + return uint32(c.R), uint32(c.G), uint32(c.B), uint32(c.A) +} + +func testNRGBAModel(c color.Color) color.Color { + return testNRGBAColor{fixedNRGBA64Model(c).(color.NRGBA64)} +} + func Test_Model(t *testing.T) { // test to make sure we can reproduce some test colors. // In particular, I want to make sure the colors can be recovered from transparent NRGBA and NRGBA64. @@ -136,6 +148,13 @@ func Test_Model(t *testing.T) { "RGBA: invisible nothing", color.RGBA{R: 0x0, G: 0x0, B: 0x0, A: 0x0}, color.RGBAModel, + }, { + // test the handling of the NRGBAColor interface; as + // all the types that support it have special handling + // that would take precidence. + "testNRGBAColor: invisible Floral White", + testNRGBAColor{color.NRGBA64{R: 0xff, G: 0xfa, B: 0xf0, A: 0x00}}, + color.ModelFunc(testNRGBAModel), }, } { t.Run(tt.name, func(t *testing.T) {