diff --git a/cmd/mtwebmapper/TODO b/cmd/mtwebmapper/TODO index ced3a03..da890db 100644 --- a/cmd/mtwebmapper/TODO +++ b/cmd/mtwebmapper/TODO @@ -1,3 +1 @@ -* Use a scaler that uses the fact that tiles are powers of - two and do _not_ round up/or down nearest neighbor interpolation. * Generate and use ETags to improve caching behavior. diff --git a/cmd/mtwebmapper/main.go b/cmd/mtwebmapper/main.go index 691e097..69dc373 100644 --- a/cmd/mtwebmapper/main.go +++ b/cmd/mtwebmapper/main.go @@ -8,6 +8,7 @@ import ( "flag" "fmt" "image" + "image/color" "image/png" "log" "net/http" @@ -19,9 +20,42 @@ import ( "bitbucket.org/s_l_teichmann/mtredisalize/common" "github.com/gorilla/mux" - "github.com/nfnt/resize" ) +func blowUp(src image.Image) *image.RGBA { + + // TODO: Use fix point arithmetic, fast path for image.RGBA + + dst := image.NewRGBA(image.Rect(0, 0, 256, 256)) + + sw, sh := src.Bounds().Dx(), src.Bounds().Dy() + + dx := float32(sw) / float32(256) + dy := float32(sh) / float32(256) + + bx, by := src.Bounds().Min.X, src.Bounds().Min.Y + + py := float32(by) + for y := 0; y < 256; y++ { + sy := int(py) + ox := -1 + px := float32(bx) + var col color.Color + for x := 0; x < 256; x++ { + sx := int(px) + if sx != ox { // Minimize interface indirection access. + ox = sx + col = src.At(sx, sy) + } + dst.Set(x, y, col) + px += dx + } + py += dy + } + + return dst +} + func toUint(s string) uint { var err error var x int @@ -102,8 +136,7 @@ func main() { } img = si.SubImage(image.Rect(int(xo), int(yo), int(xo+w), int(yo+w))) - //fmt.Printf("%s\n", img.Bounds()) - img = resize.Resize(256, 256, img, resize.NearestNeighbor) + img = blowUp(img) var buf bytes.Buffer if err := png.Encode(&buf, img); err != nil {