Compare commits
3 Commits
master
...
maptool-go
Author | SHA1 | Date |
---|---|---|
jack77213 | d28c903b10 | |
jack77213 | 3225640d7d | |
jack77213 | 9a21ef6a3d |
|
@ -0,0 +1,5 @@
|
||||||
|
module gitea.hijack.moe/huashui/a3web/maptool
|
||||||
|
|
||||||
|
go 1.13
|
||||||
|
|
||||||
|
require github.com/disintegration/imaging v1.6.2 // indirect
|
|
@ -0,0 +1,5 @@
|
||||||
|
github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c=
|
||||||
|
github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4=
|
||||||
|
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 h1:hVwzHzIUGRjiF7EcUjqNxk3NCfkPxbDKRdnNE1Rpg0U=
|
||||||
|
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|
@ -0,0 +1,91 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"image"
|
||||||
|
"image/color"
|
||||||
|
"image/jpeg"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/disintegration/imaging"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
origMap string
|
||||||
|
maxLevel int
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
flag.StringVar(&origMap, "map", "Enoch.png", "original map file")
|
||||||
|
flag.IntVar(&maxLevel, "level", 3, "resize level")
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
origImgFile, err := os.Open(origMap)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer origImgFile.Close()
|
||||||
|
|
||||||
|
config, format, err := image.DecodeConfig(origImgFile)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Println("Width:", config.Width, "Height:", config.Height, "Format:", format)
|
||||||
|
|
||||||
|
origImgFile.Seek(0, 0)
|
||||||
|
img, _, err := image.Decode(origImgFile)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
//////////////////////
|
||||||
|
width := config.Width
|
||||||
|
dirName := strings.Split(origMap, ".")[0]
|
||||||
|
os.Mkdir(dirName, os.ModeDir)
|
||||||
|
|
||||||
|
for i := 3; i > 0; i-- {
|
||||||
|
log.Println(i)
|
||||||
|
corpImage(img, width, i, dirName)
|
||||||
|
width = width / 2
|
||||||
|
img = imaging.Resize(img, width, 0, imaging.Lanczos)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type subImager interface {
|
||||||
|
SubImage(r image.Rectangle) image.Image
|
||||||
|
}
|
||||||
|
|
||||||
|
func corpImage(img image.Image, width int, level int, dirname string) {
|
||||||
|
lveledirname := fmt.Sprintf("%s/%d", dirname, level)
|
||||||
|
os.Mkdir(lveledirname, os.ModeDir)
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
if img, ok := img.(subImager); ok {
|
||||||
|
for i := 0; i < width; i = i + 1000 {
|
||||||
|
for j := 0; j < width; j = j + 1000 {
|
||||||
|
wg.Add(1)
|
||||||
|
go func(wg *sync.WaitGroup, i, j int, img subImager) {
|
||||||
|
rect := image.Rect(i, j, i+1000, j+1000)
|
||||||
|
imgOut := img.SubImage(rect)
|
||||||
|
imgOut = imaging.Paste(imaging.New(1000, 1000, color.NRGBA{0, 0, 0, 0}), imgOut, image.Pt(0, 0))
|
||||||
|
fileName := fmt.Sprintf("%s/%d/x%d_y%d.jpg", dirname, level, i/1000, j/1000)
|
||||||
|
fileOut, err := os.Create(fileName)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
jpeg.Encode(fileOut, imgOut, &jpeg.Options{Quality: 85})
|
||||||
|
fileOut.Close()
|
||||||
|
wg.Done()
|
||||||
|
}(&wg, i, j, img)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Fatalln("Cannot take a SubImage")
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
}
|
Loading…
Reference in New Issue