From 617a3081b2fe317ca87c3b2eed693817270a459a Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Thu, 18 Sep 2014 11:32:55 +0200 Subject: [PATCH] mtwebmapper: Some code cleanup in sub baseline rendering. --- cmd/mtwebmapper/subbaseline.go | 39 +++++++++++++--------------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/cmd/mtwebmapper/subbaseline.go b/cmd/mtwebmapper/subbaseline.go index cd35be0..b218d00 100644 --- a/cmd/mtwebmapper/subbaseline.go +++ b/cmd/mtwebmapper/subbaseline.go @@ -61,19 +61,6 @@ func (sb *subBaseLine) ServeHTTP(rw http.ResponseWriter, r *http.Request) { return } } - img := common.LoadPNG(baseTile) - - type subImage interface { - SubImage(image.Rectangle) image.Image - } - var si subImage - var ok bool - if si, ok = img.(subImage); !ok { - // Should not happen. - http.Error(rw, - http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) - return - } rx := x & ^(^uint(0) << (z - 8)) ry := y & ^(^uint(0) << (z - 8)) @@ -83,23 +70,27 @@ func (sb *subBaseLine) ServeHTTP(rw http.ResponseWriter, r *http.Request) { w := uint(256) / parts xo := w * rx yo := w * (parts - 1 - ry) - //fmt.Printf("x %d\n", x) - //fmt.Printf("y %d\n", y) - //fmt.Printf("z %d\n", z) - //fmt.Printf("z %d\n", z) - //fmt.Printf("parts %d\n", parts) - //fmt.Printf("w %d\n", w) - //fmt.Printf("xo %d\n", xo) - //fmt.Printf("yo %d\n", yo) - //fmt.Printf("rx %d\n", rx) - //fmt.Printf("ry %d\n", ry) - img = si.SubImage(image.Rect(int(xo), int(yo), int(xo+w), int(yo+w))) + img := common.LoadPNG(baseTile) + + type subImage interface { + SubImage(image.Rectangle) image.Image + } + + if si, ok := img.(subImage); ok { + img = si.SubImage(image.Rect(int(xo), int(yo), int(xo+w), int(yo+w))) + } else { + // Should not happen. + http.Error(rw, + http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + } + img = blowUp(img) rw.Header().Set("Content-Type", "image/png") if etag == "" { if etag, err = createETag(baseTile); err != nil { + // Unlikely log.Printf("Cannot create ETag: %s", baseTile) } else { rw.Header().Set("ETag", etag)