From f658d12641d62a09bacb08d0c833af64e3ff8fe3 Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Fri, 25 Dec 2015 22:07:54 +0100 Subject: [PATCH] Use github.com/bamiaux/rez instead of github.com/nfnt/resize for resampling the pyramid tiles. It is much faster but needs some testing. --- cmd/mtseeder/pyramid.go | 23 +++++++++++++++++++---- cmd/mtwebmapper/tilesupdater.go | 18 ++++++++++-------- common/image.go | 5 +++++ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/cmd/mtseeder/pyramid.go b/cmd/mtseeder/pyramid.go index b462600..ffb0349 100644 --- a/cmd/mtseeder/pyramid.go +++ b/cmd/mtseeder/pyramid.go @@ -18,7 +18,7 @@ import ( "bitbucket.org/s_l_teichmann/mtsatellite/common" - "github.com/nfnt/resize" + "github.com/bamiaux/rez" ) func findMaxDir(files []os.FileInfo) (min, max int) { @@ -155,7 +155,7 @@ var dps = [4]image.Point{ image.Pt(256, 256), image.Pt(256, 0)} -func fuseTile(scratch *image.RGBA, job *pyramidJob) error { +func fuseTile(scratch, resized *image.RGBA, conv rez.Converter, job *pyramidJob) error { for i, path := range job.src { @@ -167,7 +167,9 @@ func fuseTile(scratch *image.RGBA, job *pyramidJob) error { draw.Draw(scratch, r, img, sr.Min, draw.Src) } - resized := resize.Resize(256, 256, scratch, resize.Lanczos3) + if err := conv.Convert(resized, scratch); err != nil { + return err + } log.Printf("Writing pyramid tile '%s'.\n", job.dst) @@ -177,9 +179,22 @@ func fuseTile(scratch *image.RGBA, job *pyramidJob) error { func fuseTiles(jobs chan pyramidJob, done *sync.WaitGroup) { defer done.Done() scratch := image.NewRGBA(image.Rect(0, 0, 512, 512)) + resized := image.NewRGBA(image.Rect(0, 0, 256, 256)) + + cfg, err := rez.PrepareConversion(resized, scratch) + if err != nil { + log.Printf("WARN: cannot prepare rescaling: %s\n", err) + return + } + + conv, err := rez.NewConverter(cfg, common.ResizeFilter) + if err != nil { + log.Printf("WARN: Cannot create image converter: %s\n", err) + return + } for job := range jobs { - if err := fuseTile(scratch, &job); err != nil { + if err := fuseTile(scratch, resized, conv, &job); err != nil { log.Printf("WARN: Writing image failed: %s\n", err) } } diff --git a/cmd/mtwebmapper/tilesupdater.go b/cmd/mtwebmapper/tilesupdater.go index 5023fe0..04ff529 100644 --- a/cmd/mtwebmapper/tilesupdater.go +++ b/cmd/mtwebmapper/tilesupdater.go @@ -6,7 +6,6 @@ package main import ( "encoding/json" - "fmt" "image" "image/draw" "log" @@ -17,7 +16,7 @@ import ( "strings" "sync" - "github.com/nfnt/resize" + "github.com/bamiaux/rez" "bytes" @@ -215,9 +214,10 @@ func (tu *tileUpdater) doUpdates() { func updatePyramidTiles(level int, baseDir string, jobs chan xzm, done *sync.WaitGroup) { defer done.Done() scratch := image.NewRGBA(image.Rect(0, 0, 256, 256)) + resized := image.NewRGBA(image.Rect(0, 0, 128, 128)) for job := range jobs { - if err := updatePyramidTile(scratch, level, baseDir, job); err != nil { + if err := updatePyramidTile(scratch, resized, level, baseDir, job); err != nil { log.Printf("Updating pyramid tile failed: %s\n", err) } } @@ -243,7 +243,7 @@ var ofs = [4][2]int{ var windowSize = image.Pt(128, 128) -func updatePyramidTile(scratch *image.RGBA, level int, baseDir string, j xzm) error { +func updatePyramidTile(scratch, resized *image.RGBA, level int, baseDir string, j xzm) error { var orig image.Image @@ -251,8 +251,9 @@ func updatePyramidTile(scratch *image.RGBA, level int, baseDir string, j xzm) er baseDir, strconv.Itoa(level), strconv.Itoa(int(j.P.X)), - fmt.Sprintf("%d.png", j.P.Z)) + strconv.Itoa(int(j.P.Z))+".png") + sr := resized.Bounds() for i := uint16(0); i < 4; i++ { if j.Mask&(1<