package thumbnail import ( "image/color" ) func Blend(a, b color.Color) color.Color { switch a.(type) { case color.RGBA: return BlendRGBA(a.(color.RGBA), b.(color.RGBA)) // FIXME there's syntax for this case color.YCbCr: return BlendYCbCr(a.(color.YCbCr), b.(color.YCbCr)) default: return a // ??? unknown color format } } func BlendYCbCr(a, b color.YCbCr) color.YCbCr { return color.YCbCr{ Y: uint8((int(a.Y) + int(b.Y)) / 2), Cb: uint8((int(a.Cb) + int(b.Cb)) / 2), Cr: uint8((int(a.Cr) + int(b.Cr)) / 2), } } func BlendRGBA(a, b color.RGBA) color.RGBA { return color.RGBA{ R: uint8((int(a.R) + int(b.R)) / 2), G: uint8((int(a.G) + int(b.G)) / 2), B: uint8((int(a.B) + int(b.B)) / 2), A: uint8((int(a.A) + int(b.A)) / 2), } }