mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-23 16:50:18 +01:00
Removed unnecessary general code.
This commit is contained in:
parent
792aae99d7
commit
398c52f8a5
@ -5,7 +5,6 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
@ -50,7 +49,7 @@ var tileDepths = [...][2]int16{
|
||||
|
||||
var BackgroundColor = color.RGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff}
|
||||
|
||||
type BaseTileUpdateFunc func(x, y int, img image.Image) bool
|
||||
type BaseTileUpdateFunc func(x, y int, hash []byte) bool
|
||||
|
||||
type BaseTileCreator struct {
|
||||
client *RedisClient
|
||||
@ -165,7 +164,7 @@ func (btc *BaseTileCreator) CreateTile(x, z int16, i, j int) (bool, error) {
|
||||
return true, SaveAsPNG(path, image)
|
||||
}
|
||||
|
||||
if btc.update(i, j, image) {
|
||||
if btc.update(i, j, SHA1Image(image)) {
|
||||
log.Printf("Writing (%d, %d) to file %s.\n", x, z, path)
|
||||
return true, SaveAsPNGAtomic(path, image)
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ package common
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"image"
|
||||
"sync"
|
||||
)
|
||||
|
||||
@ -20,8 +19,7 @@ func NewBaseTileHash() *BaseTileHash {
|
||||
return &BaseTileHash{hashes: map[struct{ x, y int }][]byte{}}
|
||||
}
|
||||
|
||||
func (bth *BaseTileHash) Update(x, y int, img image.Image) bool {
|
||||
hash := SHA1Image(img)
|
||||
func (bth *BaseTileHash) Update(x, y int, hash []byte) bool {
|
||||
key := struct{ x, y int }{x, y}
|
||||
bth.Lock()
|
||||
defer bth.Unlock()
|
||||
|
@ -112,7 +112,8 @@ func LoadPNG(path string, bg color.RGBA) image.Image {
|
||||
return img
|
||||
}
|
||||
|
||||
func sha1rgba(img *image.RGBA) []byte {
|
||||
func SHA1Image(img *image.RGBA) []byte {
|
||||
|
||||
hash := sha1.New()
|
||||
w, h := img.Rect.Dx()*4, img.Rect.Dy()
|
||||
|
||||
@ -124,39 +125,3 @@ func sha1rgba(img *image.RGBA) []byte {
|
||||
|
||||
return hash.Sum(nil)
|
||||
}
|
||||
|
||||
func sha1uniform(img *image.Uniform) []byte {
|
||||
r, g, b, a := img.C.RGBA()
|
||||
return sha1.New().Sum([]byte{
|
||||
byte(r >> 16),
|
||||
byte(g >> 16),
|
||||
byte(b >> 16),
|
||||
byte(a >> 16)})
|
||||
}
|
||||
|
||||
func SHA1Image(img image.Image) []byte {
|
||||
|
||||
switch i := img.(type) {
|
||||
case *image.RGBA:
|
||||
return sha1rgba(i)
|
||||
case *image.Uniform:
|
||||
return sha1uniform(i)
|
||||
}
|
||||
|
||||
log.Println("WARN: slow path for SHA1Image")
|
||||
|
||||
hash := sha1.New()
|
||||
bounds := img.Bounds()
|
||||
var pix [4]byte
|
||||
for x := bounds.Min.X; x <= bounds.Max.X; x++ {
|
||||
for y := bounds.Min.Y; y <= bounds.Max.Y; y++ {
|
||||
r, g, b, a := img.At(x, y).RGBA()
|
||||
pix[0] = byte(r >> 16)
|
||||
pix[1] = byte(g >> 16)
|
||||
pix[2] = byte(b >> 16)
|
||||
pix[3] = byte(a >> 16)
|
||||
hash.Write(pix[:])
|
||||
}
|
||||
}
|
||||
return hash.Sum(nil)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user