1 package limage 2 3 import ( 4 "image" 5 "image/color" 6 ) 7 8 // Layer represents a single layer of a multilayered image 9 type Layer struct { 10 Name string 11 LayerBounds image.Rectangle // Bounds within the layer group 12 Mode Composite 13 Invisible bool 14 Transparency uint8 15 image.Image 16 } 17 18 // Bounds returns the limits for the dimensions of the layer 19 func (l Layer) Bounds() image.Rectangle { 20 return l.LayerBounds 21 } 22 23 // At returns the colour at the specified coords 24 func (l Layer) At(x, y int) color.Color { 25 return transparency(l.Image.At(x-l.LayerBounds.Min.X, y-l.LayerBounds.Min.Y), 255-l.Transparency) 26 } 27 28 // SubImage returns an image representing the portion of the image p visible 29 // through r. The returned value shares pixels with the original image 30 func (l Layer) SubImage(r image.Rectangle) image.Image { 31 return l.SubImageLayer(r) 32 } 33 34 // SubImageLayer returns an image representing the portion of the image p 35 // visible through r. The returned value shares pixels with the original image 36 func (l Layer) SubImageLayer(r image.Rectangle) Layer { 37 l.LayerBounds = r.Intersect(l.LayerBounds) 38 return l 39 } 40