/
rotate.go
61 lines (55 loc) · 1.82 KB
/
rotate.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package transformation
import (
"image"
"image/color"
"image/draw"
"github.com/disintegration/imaging"
"github.com/jeromelesaux/martine/constants"
ci "github.com/jeromelesaux/martine/convert/image"
"github.com/jeromelesaux/martine/gfx/errors"
)
func Rotate(in *image.NRGBA,
p color.Palette,
size constants.Size,
mode uint8,
rollIteration int,
resizeAlgo imaging.ResampleFilter) ([]*image.NRGBA, error) {
images := make([]*image.NRGBA, 0)
if rollIteration == -1 {
return images, errors.ErrorMissingNumberOfImageToGenerate
}
var indice int
angle := 360. / float64(rollIteration)
var maxSize constants.Size
for i := 0.; i < 360.; i += angle {
rin := imaging.Rotate(in, i, color.Transparent)
if maxSize.Width < rin.Bounds().Max.X {
maxSize.Width = rin.Bounds().Max.X
}
if maxSize.Height < rin.Bounds().Max.Y {
maxSize.Height = rin.Bounds().Max.Y
}
}
background := image.NewRGBA(image.Rectangle{image.Point{X: 0, Y: 0}, image.Point{X: maxSize.Width, Y: maxSize.Height}})
draw.Draw(background, background.Bounds(), &image.Uniform{p[0]}, image.Point{0, 0}, draw.Src)
for i := 0.; i < 360.; i += angle {
rin := imaging.Rotate(in, i, p[0])
if rin.Bounds().Max.X < maxSize.Width || rin.Bounds().Max.Y < maxSize.Height {
rin = imaging.PasteCenter(
background,
rin,
)
}
_, rin = ci.DowngradingWithPalette(rin, p)
images = append(images, rin)
/* newFilename := cont.OsFullPath(filePath, fmt.Sprintf("%.2d", indice)+".png")
if err := file.Png(newFilename, rin); err != nil {
log.GetLogger().Error( "Cannot create image (%s) error :%v\n", newFilename, err)
}
if err := common.ToSpriteAndExport(rin, p, maxSize, mode, newFilename, false, cont); err != nil {
log.GetLogger().Error( "Cannot create sprite image (%s) error %v\n", newFilename, err)
}*/
indice++
}
return images, nil
}