mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-24 01:00:18 +01:00
Removed unnecessary general code.
This commit is contained in:
parent
792aae99d7
commit
398c52f8a5
@ -5,7 +5,6 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"image"
|
|
||||||
"image/color"
|
"image/color"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
@ -50,7 +49,7 @@ var tileDepths = [...][2]int16{
|
|||||||
|
|
||||||
var BackgroundColor = color.RGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff}
|
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 {
|
type BaseTileCreator struct {
|
||||||
client *RedisClient
|
client *RedisClient
|
||||||
@ -165,7 +164,7 @@ func (btc *BaseTileCreator) CreateTile(x, z int16, i, j int) (bool, error) {
|
|||||||
return true, SaveAsPNG(path, image)
|
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)
|
log.Printf("Writing (%d, %d) to file %s.\n", x, z, path)
|
||||||
return true, SaveAsPNGAtomic(path, image)
|
return true, SaveAsPNGAtomic(path, image)
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ package common
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"image"
|
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,8 +19,7 @@ func NewBaseTileHash() *BaseTileHash {
|
|||||||
return &BaseTileHash{hashes: map[struct{ x, y int }][]byte{}}
|
return &BaseTileHash{hashes: map[struct{ x, y int }][]byte{}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bth *BaseTileHash) Update(x, y int, img image.Image) bool {
|
func (bth *BaseTileHash) Update(x, y int, hash []byte) bool {
|
||||||
hash := SHA1Image(img)
|
|
||||||
key := struct{ x, y int }{x, y}
|
key := struct{ x, y int }{x, y}
|
||||||
bth.Lock()
|
bth.Lock()
|
||||||
defer bth.Unlock()
|
defer bth.Unlock()
|
||||||
|
@ -112,7 +112,8 @@ func LoadPNG(path string, bg color.RGBA) image.Image {
|
|||||||
return img
|
return img
|
||||||
}
|
}
|
||||||
|
|
||||||
func sha1rgba(img *image.RGBA) []byte {
|
func SHA1Image(img *image.RGBA) []byte {
|
||||||
|
|
||||||
hash := sha1.New()
|
hash := sha1.New()
|
||||||
w, h := img.Rect.Dx()*4, img.Rect.Dy()
|
w, h := img.Rect.Dx()*4, img.Rect.Dy()
|
||||||
|
|
||||||
@ -124,39 +125,3 @@ func sha1rgba(img *image.RGBA) []byte {
|
|||||||
|
|
||||||
return hash.Sum(nil)
|
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