Replace false rounding scaler with self written one.

This commit is contained in:
Sascha L. Teichmann 2014-09-16 15:30:08 +02:00
parent 25c189351c
commit c67739fd77
2 changed files with 36 additions and 5 deletions

View File

@ -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.

View File

@ -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 {