mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-11-13 05:40:20 +01:00
38 lines
763 B
Go
38 lines
763 B
Go
// Copyright 2016 by Sascha L. Teichmann
|
|
// Use of this source code is governed by the MIT license
|
|
// that can be found in the LICENSE file.
|
|
|
|
package common
|
|
|
|
import (
|
|
"bytes"
|
|
"image"
|
|
"sync"
|
|
)
|
|
|
|
type BaseTileHash struct {
|
|
// XXX: Maybe use some kind of LRU cache instead?
|
|
hashes map[struct{ x, y int }][]byte
|
|
sync.Mutex
|
|
}
|
|
|
|
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)
|
|
key := struct{ x, y int }{x, y}
|
|
bth.Lock()
|
|
defer bth.Unlock()
|
|
if old, found := bth.hashes[key]; found {
|
|
if !bytes.Equal(old, hash) {
|
|
bth.hashes[key] = hash
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
bth.hashes[key] = hash
|
|
return true
|
|
}
|