From 12cfd32ad5f64e5a9b0aeab8f2751a70c84fe2ef Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Sun, 26 Feb 2017 21:47:50 +0100 Subject: [PATCH] Use blake2b instead of sha1 to check for identical tiles to not regenerate the tiles pyramid. --- common/basetilecreator.go | 2 +- common/image.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/common/basetilecreator.go b/common/basetilecreator.go index 9e02df5..397411e 100644 --- a/common/basetilecreator.go +++ b/common/basetilecreator.go @@ -172,7 +172,7 @@ func (btc *BaseTileCreator) CreateTile(x, z int16, i, j int) (bool, error) { return true, SaveAsPNG(path, image) } - if btc.update(i, j, SHA1Image(image)) { + if btc.update(i, j, HashImage(image)) { log.Printf("Writing (%d, %d) to file %s.\n", x, z, path) return true, SaveAsPNGAtomic(path, image) } diff --git a/common/image.go b/common/image.go index b2feeee..2fed583 100644 --- a/common/image.go +++ b/common/image.go @@ -7,7 +7,6 @@ package common import ( "bufio" "bytes" - "crypto/sha1" "errors" "image" "image/color" @@ -18,6 +17,8 @@ import ( "sync" "time" + "golang.org/x/crypto/blake2b" + "github.com/bamiaux/rez" ) @@ -112,9 +113,9 @@ func LoadPNG(path string, bg color.RGBA) image.Image { return img } -func SHA1Image(img *image.RGBA) []byte { +func HashImage(img *image.RGBA) []byte { - hash := sha1.New() + hash, _ := blake2b.New256(nil) w, h := img.Rect.Dx()*4, img.Rect.Dy() pos := img.PixOffset(img.Rect.Min.X, img.Rect.Min.Y)