mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2025-01-11 09:20:17 +01:00
Added cascading transparent annuation algorithm based on spans.
This commit is contained in:
parent
eaa3949b10
commit
99ff99a8f4
@ -24,10 +24,6 @@ type namedColor struct {
|
|||||||
color color.RGBA
|
color color.RGBA
|
||||||
}
|
}
|
||||||
|
|
||||||
func (colors *Colors) IsTransparent(index int32) bool {
|
|
||||||
return index < colors.NumTransparent
|
|
||||||
}
|
|
||||||
|
|
||||||
type sortByAlpha []namedColor
|
type sortByAlpha []namedColor
|
||||||
|
|
||||||
func (colors sortByAlpha) Less(i, j int) bool {
|
func (colors sortByAlpha) Less(i, j int) bool {
|
||||||
@ -88,3 +84,40 @@ func ParseColors(filename string) (colors *Colors, err error) {
|
|||||||
NumTransparent: numTransparent}
|
NumTransparent: numTransparent}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (colors *Colors) IsTransparent(index int32) bool {
|
||||||
|
return index < colors.NumTransparent
|
||||||
|
}
|
||||||
|
|
||||||
|
func min(a, b int32) int32 {
|
||||||
|
if a < b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func BlendColor(c1, c2 color.RGBA, a float32) color.RGBA {
|
||||||
|
b := float32(1) - a
|
||||||
|
return color.RGBA{
|
||||||
|
R: uint8(float32(c1.R)*a + float32(c2.R)*b),
|
||||||
|
G: uint8(float32(c1.G)*a + float32(c2.G)*b),
|
||||||
|
B: uint8(float32(c1.B)*a + float32(c2.B)*b),
|
||||||
|
A: 0xff}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (colors *Colors) BlendColors(span *Span, col color.RGBA, pos int32) color.RGBA {
|
||||||
|
curr := span
|
||||||
|
// Ignore colors below pos.
|
||||||
|
for ; curr != nil && pos >= curr.To; curr = curr.Next {
|
||||||
|
}
|
||||||
|
if curr == nil {
|
||||||
|
return col
|
||||||
|
}
|
||||||
|
const scale = float32(1) / float32(100)
|
||||||
|
for ; curr != nil; curr = curr.Next {
|
||||||
|
// At least 20% attenuation + 5% extra for each depth meter.
|
||||||
|
factor := float32(min(100, 20+(curr.To-curr.From)*5)) * scale
|
||||||
|
col = BlendColor(colors.Colors[curr.Value], col, factor)
|
||||||
|
}
|
||||||
|
return col
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user