diff --git a/cmd/mtwebmapper/main.go b/cmd/mtwebmapper/main.go index 69dc373..50fe0fb 100644 --- a/cmd/mtwebmapper/main.go +++ b/cmd/mtwebmapper/main.go @@ -24,25 +24,23 @@ import ( func blowUp(src image.Image) *image.RGBA { - // TODO: Use fix point arithmetic, fast path for image.RGBA + // TODO: Fast path for image.RGBA dst := image.NewRGBA(image.Rect(0, 0, 256, 256)) - sw, sh := src.Bounds().Dx(), src.Bounds().Dy() + // fix point numbers x:8 + dx, dy := src.Bounds().Dx(), src.Bounds().Dy() - dx := float32(sw) / float32(256) - dy := float32(sh) / float32(256) + bx, by := src.Bounds().Min.X<<8, src.Bounds().Min.Y<<8 - bx, by := src.Bounds().Min.X, src.Bounds().Min.Y - - py := float32(by) + py := by for y := 0; y < 256; y++ { - sy := int(py) + sy := (py >> 8) & 0xff ox := -1 - px := float32(bx) + px := bx var col color.Color for x := 0; x < 256; x++ { - sx := int(px) + sx := (px >> 8) & 0xff if sx != ox { // Minimize interface indirection access. ox = sx col = src.At(sx, sy)