KML allows you to specify a <color>
for an icon.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
<Placemark>
<name>Pin</name>
<Point>
<coordinates>0, 0</coordinates>
</Point>
<Style>
<IconStyle>
<color>ff8c4800</color>
<scale>10</scale>
<Icon>
<href>http://maps.google.com/mapfiles/kml/pushpin/wht-pushpin.png</href>
</Icon>
</IconStyle>
</Style>
</Placemark>
</kml>
I'm trying to do the same thing in Go using the Porter-Duff colour blending method.
// blendColors uses the Porter-Duff over method
// for combing two colors with alpha channels
func blendColors(c1 color.Color, c2 color.Color) color.Color {
r1, g1, b1, a1 := extractComponents(c1)
r2, g2, b2, a2 := extractComponents(c2)
var (
a = a1 + a2*(1.0-a1)
r = (r1*a1 + r2*a2*(1.0-a1)) / a
g = (g1*a1 + g2*a2*(1.0-a1)) / a
b = (b1*a1 + b2*a2*(1.0-a1)) / a
)
return color.RGBA{
R: clampColorValue(int(r)),
G: clampColorValue(int(g)),
B: clampColorValue(int(b)),
A: clampColorValue(int(a * 255)),
}
}
See full code here
Here are some output examples with different opacity levels (from 0 - 255).
0
100
200
255
These are not satisfactory (due to the jagged edges and faded black border) and I want to know what approach I should take to get results more akin to what Google Earth does.