-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhead.go
45 lines (35 loc) · 1.4 KB
/
head.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package skin
import (
"image"
"math"
)
// RenderHead renders a 3-dimensional image of the head of a Minecraft player's skin.
func RenderHead(img *image.NRGBA, opts Options) *image.NRGBA {
if err := validateSkin(img); err != nil {
panic(err)
}
var (
skin *image.NRGBA = convertToNRGBA(img)
scaleDouble float64 = float64(opts.Scale)
output *image.NRGBA = image.NewNRGBA(image.Rect(0, 0, 13*opts.Scale+int(math.Floor(scaleDouble*0.855)), 16*opts.Scale))
frontHead *image.NRGBA = removeTransparency(extract(skin, HeadFront))
topHead *image.NRGBA = rotate90(flipHorizontal(removeTransparency(extract(skin, HeadTop))))
rightHead *image.NRGBA = removeTransparency(extract(skin, HeadRight))
)
if opts.Overlay {
overlaySkin := fixTransparency(skin)
composite(frontHead, extract(overlaySkin, HeadOverlayFront), 0, 0)
composite(topHead, rotate90(flipHorizontal(extract(overlaySkin, HeadOverlayTop))), 0, 0)
composite(rightHead, extract(overlaySkin, HeadOverlayRight), 0, 0)
}
// Front Head
compositeTransform(output, scale(frontHead, opts.Scale), frontMatrix, 8*scaleDouble, 12*scaleDouble)
// Top Head
compositeTransform(output, scale(topHead, opts.Scale), plantMatrix, 4*scaleDouble, -4*scaleDouble)
// Right Head
compositeTransform(output, scale(rightHead, opts.Scale), sideMatrix, 0, 4*scaleDouble)
if opts.Square {
return squareAndCenter(output)
}
return output
}