From d39a948bd472da39428d4f267462680463e4ad3c Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Sun, 21 Sep 2014 09:04:59 +0200 Subject: [PATCH] mtseeder: Fixed problem that tiles with missing sub tiles were drawn in white entirely. --- cmd/mtseeder/pyramid.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/cmd/mtseeder/pyramid.go b/cmd/mtseeder/pyramid.go index 0f48bdf..edde0a4 100644 --- a/cmd/mtseeder/pyramid.go +++ b/cmd/mtseeder/pyramid.go @@ -136,6 +136,22 @@ func createParentLevel(oldDir string, jobs chan pyramidJob) (newDir string, err return } +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 dps = [4]image.Point{ image.Pt(0, 256), image.Pt(0, 0), @@ -148,7 +164,7 @@ func fuseTile(scratch *image.RGBA, job *pyramidJob) (err error) { img := common.LoadPNG(path) - sr := img.Bounds() + sr := clipRect(img.Bounds()) r := sr.Sub(sr.Min).Add(dps[i]) draw.Draw(scratch, r, img, sr.Min, draw.Src)