mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-11-15 23:00:19 +01:00
Use github.com/bamiaux/rez instead of github.com/nfnt/resize for resampling the pyramid tiles. It is much faster but needs some testing.
This commit is contained in:
parent
6ae5936de9
commit
f658d12641
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<<i) != 0 {
|
||||
//log.Printf("level %d: modified %d\n", level, i)
|
||||
|
@ -264,10 +265,11 @@ func updatePyramidTile(scratch *image.RGBA, level int, baseDir string, j xzm) er
|
|||
strconv.Itoa(bx+o[0]),
|
||||
strconv.Itoa(bz+o[1])+".png")
|
||||
img := common.LoadPNG(path)
|
||||
img = resize.Resize(128, 128, img, resize.Lanczos3)
|
||||
sr := img.Bounds()
|
||||
if err := rez.Convert(resized, img, common.ResizeFilter); err != nil {
|
||||
return err
|
||||
}
|
||||
r := sr.Sub(sr.Min).Add(dps[i])
|
||||
draw.Draw(scratch, r, img, sr.Min, draw.Src)
|
||||
draw.Draw(scratch, r, resized, sr.Min, draw.Src)
|
||||
} else {
|
||||
// Load lazy
|
||||
if orig == nil {
|
||||
|
|
|
@ -15,8 +15,13 @@ import (
|
|||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/bamiaux/rez"
|
||||
)
|
||||
|
||||
// ResizeFilter is used to scale down the pyramid tiles.
|
||||
var ResizeFilter = rez.NewLanczosFilter(3)
|
||||
|
||||
var rrand uint32
|
||||
var rrandmu sync.Mutex
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user