image.go (726B)
1 package main 2 3 import ( 4 "image" 5 "image/color" 6 ) 7 8 var _ image.Image = ImageStack{} 9 10 // ImageStack implements image.Image as a stack of images that returns the first non-zero color 11 // encountered. 12 type ImageStack struct { 13 Stack []image.Image 14 Config image.Config 15 } 16 17 func (stack ImageStack) At(x, y int) color.Color { 18 for _, img := range stack.Stack { 19 c := img.At(x, y) 20 if r, g, b, a := c.RGBA(); r > 0 || g > 0 || b > 0 || a > 0 { 21 return c 22 } 23 } 24 return color.NRGBA{} 25 } 26 27 func (stack ImageStack) Bounds() image.Rectangle { 28 return image.Rectangle{ 29 Max: image.Point{ 30 X: stack.Config.Width, 31 Y: stack.Config.Height, 32 }, 33 } 34 } 35 36 func (stack ImageStack) ColorModel() color.Model { 37 return stack.Config.ColorModel 38 }