github.com/df-mc/dragonfly@v0.9.13/server/player/skin/cape.go (about) 1 package skin 2 3 import ( 4 "image" 5 "image/color" 6 ) 7 8 // Cape represents the cape that a skin may additionally have. A skin is of a fixed size (always 32x64 bytes) 9 // and may be either empty or of that size. 10 type Cape struct { 11 w, h int 12 13 // Pix holds the colour data of the cape in an RGBA byte array, similarly to the way that the pixels of 14 // a Skin are stored. 15 // The size of Pix is always 32 * 64 * 4 bytes. 16 Pix []uint8 17 } 18 19 // NewCape initialises a new Cape using the width and height passed. The pixels are pre-allocated so that the 20 // Cape may be used immediately. 21 func NewCape(width, height int) Cape { 22 return Cape{w: width, h: height, Pix: make([]uint8, width*height*4)} 23 } 24 25 // ColorModel ... 26 func (c Cape) ColorModel() color.Model { 27 return color.RGBAModel 28 } 29 30 // Bounds returns the bounds of the cape, which is always 32x64 or 0x0, depending on if the cape has any data 31 // in it. 32 func (c Cape) Bounds() image.Rectangle { 33 return image.Rectangle{ 34 Max: image.Point{X: c.w, Y: c.h}, 35 } 36 } 37 38 // At returns the colour at a given position in the cape, provided the X and Y are within the bounds of the 39 // cape passed during construction. 40 // The concrete type returned by At is a color.RGBA value. 41 func (c Cape) At(x, y int) color.Color { 42 if x < 0 || y < 0 || x >= c.w || y >= c.h { 43 panic("pixel coordinates out of bounds") 44 } 45 offset := x*4 + c.w*y*4 46 return color.RGBA{ 47 R: c.Pix[offset], 48 G: c.Pix[offset+1], 49 B: c.Pix[offset+2], 50 A: c.Pix[offset+3], 51 } 52 }