mtwebmapper: Reduced the amount of copying from old tile. Code still reads a bit clumpsy.

This commit is contained in:
Sascha L. Teichmann 2014-09-22 00:56:29 +02:00
parent 8b6470fc9c
commit 11a4b9f471

View File

@ -194,38 +194,20 @@ var ofs = [4][2]int{
{0, 1}, {0, 1},
{1, 1}} {1, 1}}
/* var windowSize = image.Pt(128, 128)
func clip8(x int) int {
switch {
case x < 0:
return 0
case x > 256:
return 256
}
return x
}
func clipRect(r image.Rectangle) image.Rectangle {
return image.Rectangle{
Min: image.Point{X: clip8(r.Min.X), Y: clip8(r.Min.Y)},
Max: image.Point{X: clip8(r.Max.X), Y: clip8(r.Max.Y)}}
}
*/
//var windowSize = image.Pt(128, 128)
func updatePyramidTile(scratch *image.RGBA, level int, baseDir string, j xzm) error { func updatePyramidTile(scratch *image.RGBA, level int, baseDir string, j xzm) error {
var orig image.Image var orig image.Image
origPath := filepath.Join( origPath := filepath.Join(
baseDir, strconv.Itoa(level), strconv.Itoa(int(j.P.X)), fmt.Sprintf("%d.png", j.P.Z)) baseDir,
strconv.Itoa(level),
strconv.Itoa(int(j.P.X)),
fmt.Sprintf("%d.png", j.P.Z))
if j.numChanges() < 4 { if j.numChanges() < 4 {
orig = common.LoadPNG(origPath) orig = common.LoadPNG(origPath)
sr := orig.Bounds()
r := sr.Sub(sr.Min)
draw.Draw(scratch, r, orig, sr.Min, draw.Src)
} }
for i := uint16(0); i < 4; i++ { for i := uint16(0); i < 4; i++ {
@ -234,19 +216,20 @@ func updatePyramidTile(scratch *image.RGBA, level int, baseDir string, j xzm) er
o := ofs[i] o := ofs[i]
bx, bz := int(2*j.P.X), int(2*j.P.Z) bx, bz := int(2*j.P.X), int(2*j.P.Z)
path := filepath.Join( path := filepath.Join(
baseDir, strconv.Itoa(level+1), strconv.Itoa(bx+o[0]), fmt.Sprintf("%d.png", bz+o[1])) baseDir,
strconv.Itoa(level+1),
strconv.Itoa(bx+o[0]),
fmt.Sprintf("%d.png", bz+o[1]))
img := common.LoadPNG(path) img := common.LoadPNG(path)
img = resize.Resize(128, 128, img, resize.Lanczos3) img = resize.Resize(128, 128, img, resize.Lanczos3)
sr := img.Bounds() sr := img.Bounds()
r := sr.Sub(sr.Min).Add(dps[i]) r := sr.Sub(sr.Min).Add(dps[i])
draw.Draw(scratch, r, img, sr.Min, draw.Src) draw.Draw(scratch, r, img, sr.Min, draw.Src)
} else { } else {
/* //log.Printf("level %d: copied %d", level, i)
log.Printf("level %d: copied %d", level, i) min := orig.Bounds().Min.Add(dps[i])
dp := dps[i].Add(scratch.Bounds().Min) r := image.Rectangle{min, min.Add(windowSize)}
r := image.Rectangle{dp, dp.Add(windowSize)}
draw.Draw(scratch, r, orig, orig.Bounds().Min.Add(dps[i]), draw.Src) draw.Draw(scratch, r, orig, orig.Bounds().Min.Add(dps[i]), draw.Src)
*/
} }
} }