diff --git a/README.md b/README.md index e5f29fe..63e4310 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,8 @@ func main() { distance, _ = hash1.Distance(hash2) fmt.Printf("Distance between images: %v\n", distance)ls width, height := 8, 8 - hash3, _ = goimagehash.AverageHashExtend(img1, width, height) - hash4, _ = goimagehash.AverageHashExtend(img2, width, height) + hash3, _ = goimagehash.ExtAverageHash(img1, width, height) + hash4, _ = goimagehash.ExtAverageHash(img2, width, height) distance, _ = hash3.Distance(hash4) fmt.Printf("Distance between images: %v\n", distance) fmt.Printf("hash3 bit size: %v\n", hash3.Bits()) @@ -52,7 +52,7 @@ func main() { _ = hash4.Dump(foo) foo.Flush() bar := bufio.NewReader(&b) - hash5, _ := goimagehash.LoadImageHashExtend(bar) + hash5, _ := goimagehash.LoadExtImageHash(bar) } ``` diff --git a/_examples/load_and_dump.go b/_examples/load_and_dump.go index 5acf28d..2d175cd 100644 --- a/_examples/load_and_dump.go +++ b/_examples/load_and_dump.go @@ -20,9 +20,9 @@ func main() { img1, _ := jpeg.Decode(file1) img2, _ := jpeg.Decode(file2) width, height := 15, 15 - hash1, _ := goimagehash.AverageHashExtend(img1, width, height) - hash2, _ := goimagehash.AverageHashExtend(img2, width, height) - hash1024, _ := goimagehash.AverageHashExtend(img2, 32, 32) + hash1, _ := goimagehash.ExtAverageHash(img1, width, height) + hash2, _ := goimagehash.ExtAverageHash(img2, width, height) + hash1024, _ := goimagehash.ExtAverageHash(img2, 32, 32) distance, _ := hash1.Distance(hash2) fmt.Printf("Distance between images: %v\n", distance) err := hash1.Dump(foo) @@ -31,7 +31,7 @@ func main() { } foo.Flush() bar := bufio.NewReader(&b) - hash3, err := goimagehash.LoadImageHashExtend(bar) + hash3, err := goimagehash.LoadExtImageHash(bar) if err != nil { fmt.Println(err) } diff --git a/hashcompute.go b/hashcompute.go index 8b3b69c..30ebdd7 100644 --- a/hashcompute.go +++ b/hashcompute.go @@ -18,7 +18,7 @@ import ( // http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html func AverageHash(img image.Image) (*ImageHash, error) { if img == nil { - return nil, errors.New("Image object can not be nil.") + return nil, errors.New("Image object can not be nil") } // Create 64bits hash. @@ -42,7 +42,7 @@ func AverageHash(img image.Image) (*ImageHash, error) { // http://www.hackerfactor.com/blog/?/archives/529-Kind-of-Like-That.html func DifferenceHash(img image.Image) (*ImageHash, error) { if img == nil { - return nil, errors.New("Image object can not be nil.") + return nil, errors.New("Image object can not be nil") } dhash := NewImageHash(0, DHash) @@ -84,10 +84,10 @@ func PerceptionHash(img image.Image) (*ImageHash, error) { return phash, nil } -// PerceptionHashExtend function returns phash of which the size can be set larger than uint64 +// ExtPerceptionHash function returns phash of which the size can be set larger than uint64 // Some variable name refer to https://github.com/JohannesBuchner/imagehash/blob/master/imagehash/__init__.py // Support 64bits phash (width=8, height=8) and 256bits phash (width=16, height=16) -func PerceptionHashExtend(img image.Image, width, height int) (*ExtImageHash, error) { +func ExtPerceptionHash(img image.Image, width, height int) (*ExtImageHash, error) { if img == nil { return nil, errors.New("Image object can not be nil") } @@ -115,9 +115,9 @@ func PerceptionHashExtend(img image.Image, width, height int) (*ExtImageHash, er return NewExtImageHash(phash, PHash, imgSize), nil } -// AverageHashExtend function returns ahash of which the size can be set larger than uint64 +// ExtAverageHash function returns ahash of which the size can be set larger than uint64 // Support 64bits ahash (width=8, height=8) and 256bits ahash (width=16, height=16) -func AverageHashExtend(img image.Image, width, height int) (*ExtImageHash, error) { +func ExtAverageHash(img image.Image, width, height int) (*ExtImageHash, error) { if img == nil { return nil, errors.New("Image object can not be nil") } @@ -145,9 +145,9 @@ func AverageHashExtend(img image.Image, width, height int) (*ExtImageHash, error return NewExtImageHash(ahash, AHash, imgSize), nil } -// DifferenceHashExtend function returns dhash of which the size can be set larger than uint64 +// ExtDifferenceHash function returns dhash of which the size can be set larger than uint64 // Support 64bits dhash (width=8, height=8) and 256bits dhash (width=16, height=16) -func DifferenceHashExtend(img image.Image, width, height int) (*ExtImageHash, error) { +func ExtDifferenceHash(img image.Image, width, height int) (*ExtImageHash, error) { if img == nil { return nil, errors.New("Image object can not be nil") } diff --git a/hashcompute_test.go b/hashcompute_test.go index f2545a2..c0be3ba 100644 --- a/hashcompute_test.go +++ b/hashcompute_test.go @@ -152,72 +152,72 @@ func TestExtImageHashCompute(t *testing.T) { name string distance int }{ - {"_examples/sample1.jpg", "_examples/sample1.jpg", 8, 8, AverageHashExtend, "AverageHashExtend", 0}, - {"_examples/sample2.jpg", "_examples/sample2.jpg", 8, 8, AverageHashExtend, "AverageHashExtend", 0}, - {"_examples/sample3.jpg", "_examples/sample3.jpg", 8, 8, AverageHashExtend, "AverageHashExtend", 0}, - {"_examples/sample4.jpg", "_examples/sample4.jpg", 8, 8, AverageHashExtend, "AverageHashExtend", 0}, - {"_examples/sample1.jpg", "_examples/sample2.jpg", 8, 8, AverageHashExtend, "AverageHashExtend", 42}, - {"_examples/sample1.jpg", "_examples/sample3.jpg", 8, 8, AverageHashExtend, "AverageHashExtend", 4}, - {"_examples/sample1.jpg", "_examples/sample4.jpg", 8, 8, AverageHashExtend, "AverageHashExtend", 38}, - {"_examples/sample2.jpg", "_examples/sample3.jpg", 8, 8, AverageHashExtend, "AverageHashExtend", 40}, - {"_examples/sample2.jpg", "_examples/sample4.jpg", 8, 8, AverageHashExtend, "AverageHashExtend", 6}, - {"_examples/sample1.jpg", "_examples/sample1.jpg", 16, 16, AverageHashExtend, "AverageHashExtend", 0}, - {"_examples/sample2.jpg", "_examples/sample2.jpg", 16, 16, AverageHashExtend, "AverageHashExtend", 0}, - {"_examples/sample3.jpg", "_examples/sample3.jpg", 16, 16, AverageHashExtend, "AverageHashExtend", 0}, - {"_examples/sample4.jpg", "_examples/sample4.jpg", 16, 16, AverageHashExtend, "AverageHashExtend", 0}, - {"_examples/sample1.jpg", "_examples/sample2.jpg", 16, 16, AverageHashExtend, "AverageHashExtend", 149}, - {"_examples/sample1.jpg", "_examples/sample3.jpg", 16, 16, AverageHashExtend, "AverageHashExtend", 8}, - {"_examples/sample1.jpg", "_examples/sample4.jpg", 16, 16, AverageHashExtend, "AverageHashExtend", 152}, - {"_examples/sample2.jpg", "_examples/sample3.jpg", 16, 16, AverageHashExtend, "AverageHashExtend", 155}, - {"_examples/sample2.jpg", "_examples/sample4.jpg", 16, 16, AverageHashExtend, "AverageHashExtend", 27}, - {"_examples/sample1.jpg", "_examples/sample1.jpg", 17, 17, AverageHashExtend, "AverageHashExtend", 0}, - {"_examples/sample2.jpg", "_examples/sample2.jpg", 17, 17, AverageHashExtend, "AverageHashExtend", 0}, - {"_examples/sample3.jpg", "_examples/sample3.jpg", 17, 17, AverageHashExtend, "AverageHashExtend", 0}, - {"_examples/sample4.jpg", "_examples/sample4.jpg", 17, 17, AverageHashExtend, "AverageHashExtend", 0}, - {"_examples/sample1.jpg", "_examples/sample1.jpg", 8, 8, PerceptionHashExtend, "PerceptionHashExtend", 0}, - {"_examples/sample2.jpg", "_examples/sample2.jpg", 8, 8, PerceptionHashExtend, "PerceptionHashExtend", 0}, - {"_examples/sample3.jpg", "_examples/sample3.jpg", 8, 8, PerceptionHashExtend, "PerceptionHashExtend", 0}, - {"_examples/sample4.jpg", "_examples/sample4.jpg", 8, 8, PerceptionHashExtend, "PerceptionHashExtend", 0}, - {"_examples/sample1.jpg", "_examples/sample2.jpg", 8, 8, PerceptionHashExtend, "PerceptionHashExtend", 32}, - {"_examples/sample1.jpg", "_examples/sample3.jpg", 8, 8, PerceptionHashExtend, "PerceptionHashExtend", 2}, - {"_examples/sample1.jpg", "_examples/sample4.jpg", 8, 8, PerceptionHashExtend, "PerceptionHashExtend", 30}, - {"_examples/sample2.jpg", "_examples/sample3.jpg", 8, 8, PerceptionHashExtend, "PerceptionHashExtend", 34}, - {"_examples/sample2.jpg", "_examples/sample4.jpg", 8, 8, PerceptionHashExtend, "PerceptionHashExtend", 20}, - {"_examples/sample1.jpg", "_examples/sample1.jpg", 16, 16, PerceptionHashExtend, "PerceptionHashExtend", 0}, - {"_examples/sample2.jpg", "_examples/sample2.jpg", 16, 16, PerceptionHashExtend, "PerceptionHashExtend", 0}, - {"_examples/sample3.jpg", "_examples/sample3.jpg", 16, 16, PerceptionHashExtend, "PerceptionHashExtend", 0}, - {"_examples/sample4.jpg", "_examples/sample4.jpg", 16, 16, PerceptionHashExtend, "PerceptionHashExtend", 0}, - {"_examples/sample1.jpg", "_examples/sample2.jpg", 16, 16, PerceptionHashExtend, "PerceptionHashExtend", 122}, - {"_examples/sample1.jpg", "_examples/sample3.jpg", 16, 16, PerceptionHashExtend, "PerceptionHashExtend", 12}, - {"_examples/sample1.jpg", "_examples/sample4.jpg", 16, 16, PerceptionHashExtend, "PerceptionHashExtend", 122}, - {"_examples/sample2.jpg", "_examples/sample3.jpg", 16, 16, PerceptionHashExtend, "PerceptionHashExtend", 118}, - {"_examples/sample2.jpg", "_examples/sample4.jpg", 16, 16, PerceptionHashExtend, "PerceptionHashExtend", 104}, - {"_examples/sample1.jpg", "_examples/sample1.jpg", 17, 17, PerceptionHashExtend, "PerceptionHashExtend", 0}, - {"_examples/sample2.jpg", "_examples/sample2.jpg", 17, 17, PerceptionHashExtend, "PerceptionHashExtend", 0}, - {"_examples/sample3.jpg", "_examples/sample3.jpg", 17, 17, PerceptionHashExtend, "PerceptionHashExtend", 0}, - {"_examples/sample4.jpg", "_examples/sample4.jpg", 17, 17, PerceptionHashExtend, "PerceptionHashExtend", 0}, - {"_examples/sample1.jpg", "_examples/sample1.jpg", 8, 8, DifferenceHashExtend, "DifferenceHashExtend", 0}, - {"_examples/sample2.jpg", "_examples/sample2.jpg", 8, 8, DifferenceHashExtend, "DifferenceHashExtend", 0}, - {"_examples/sample3.jpg", "_examples/sample3.jpg", 8, 8, DifferenceHashExtend, "DifferenceHashExtend", 0}, - {"_examples/sample4.jpg", "_examples/sample4.jpg", 8, 8, DifferenceHashExtend, "DifferenceHashExtend", 0}, - {"_examples/sample1.jpg", "_examples/sample2.jpg", 8, 8, DifferenceHashExtend, "DifferenceHashExtend", 43}, - {"_examples/sample1.jpg", "_examples/sample3.jpg", 8, 8, DifferenceHashExtend, "DifferenceHashExtend", 0}, - {"_examples/sample1.jpg", "_examples/sample4.jpg", 8, 8, DifferenceHashExtend, "DifferenceHashExtend", 37}, - {"_examples/sample2.jpg", "_examples/sample3.jpg", 8, 8, DifferenceHashExtend, "DifferenceHashExtend", 43}, - {"_examples/sample2.jpg", "_examples/sample4.jpg", 8, 8, DifferenceHashExtend, "DifferenceHashExtend", 16}, - {"_examples/sample1.jpg", "_examples/sample1.jpg", 16, 16, DifferenceHashExtend, "DifferenceHashExtend", 0}, - {"_examples/sample2.jpg", "_examples/sample2.jpg", 16, 16, DifferenceHashExtend, "DifferenceHashExtend", 0}, - {"_examples/sample3.jpg", "_examples/sample3.jpg", 16, 16, DifferenceHashExtend, "DifferenceHashExtend", 0}, - {"_examples/sample4.jpg", "_examples/sample4.jpg", 16, 16, DifferenceHashExtend, "DifferenceHashExtend", 0}, - {"_examples/sample1.jpg", "_examples/sample2.jpg", 16, 16, DifferenceHashExtend, "DifferenceHashExtend", 139}, - {"_examples/sample1.jpg", "_examples/sample3.jpg", 16, 16, DifferenceHashExtend, "DifferenceHashExtend", 14}, - {"_examples/sample1.jpg", "_examples/sample4.jpg", 16, 16, DifferenceHashExtend, "DifferenceHashExtend", 130}, - {"_examples/sample2.jpg", "_examples/sample3.jpg", 16, 16, DifferenceHashExtend, "DifferenceHashExtend", 147}, - {"_examples/sample2.jpg", "_examples/sample4.jpg", 16, 16, DifferenceHashExtend, "DifferenceHashExtend", 89}, - {"_examples/sample1.jpg", "_examples/sample1.jpg", 17, 17, DifferenceHashExtend, "DifferenceHashExtend", 0}, - {"_examples/sample2.jpg", "_examples/sample2.jpg", 17, 17, DifferenceHashExtend, "DifferenceHashExtend", 0}, - {"_examples/sample3.jpg", "_examples/sample3.jpg", 17, 17, DifferenceHashExtend, "DifferenceHashExtend", 0}, - {"_examples/sample4.jpg", "_examples/sample4.jpg", 17, 17, DifferenceHashExtend, "DifferenceHashExtend", 0}, + {"_examples/sample1.jpg", "_examples/sample1.jpg", 8, 8, ExtAverageHash, "ExtAverageHash", 0}, + {"_examples/sample2.jpg", "_examples/sample2.jpg", 8, 8, ExtAverageHash, "ExtAverageHash", 0}, + {"_examples/sample3.jpg", "_examples/sample3.jpg", 8, 8, ExtAverageHash, "ExtAverageHash", 0}, + {"_examples/sample4.jpg", "_examples/sample4.jpg", 8, 8, ExtAverageHash, "ExtAverageHash", 0}, + {"_examples/sample1.jpg", "_examples/sample2.jpg", 8, 8, ExtAverageHash, "ExtAverageHash", 42}, + {"_examples/sample1.jpg", "_examples/sample3.jpg", 8, 8, ExtAverageHash, "ExtAverageHash", 4}, + {"_examples/sample1.jpg", "_examples/sample4.jpg", 8, 8, ExtAverageHash, "ExtAverageHash", 38}, + {"_examples/sample2.jpg", "_examples/sample3.jpg", 8, 8, ExtAverageHash, "ExtAverageHash", 40}, + {"_examples/sample2.jpg", "_examples/sample4.jpg", 8, 8, ExtAverageHash, "ExtAverageHash", 6}, + {"_examples/sample1.jpg", "_examples/sample1.jpg", 16, 16, ExtAverageHash, "ExtAverageHash", 0}, + {"_examples/sample2.jpg", "_examples/sample2.jpg", 16, 16, ExtAverageHash, "ExtAverageHash", 0}, + {"_examples/sample3.jpg", "_examples/sample3.jpg", 16, 16, ExtAverageHash, "ExtAverageHash", 0}, + {"_examples/sample4.jpg", "_examples/sample4.jpg", 16, 16, ExtAverageHash, "ExtAverageHash", 0}, + {"_examples/sample1.jpg", "_examples/sample2.jpg", 16, 16, ExtAverageHash, "ExtAverageHash", 149}, + {"_examples/sample1.jpg", "_examples/sample3.jpg", 16, 16, ExtAverageHash, "ExtAverageHash", 8}, + {"_examples/sample1.jpg", "_examples/sample4.jpg", 16, 16, ExtAverageHash, "ExtAverageHash", 152}, + {"_examples/sample2.jpg", "_examples/sample3.jpg", 16, 16, ExtAverageHash, "ExtAverageHash", 155}, + {"_examples/sample2.jpg", "_examples/sample4.jpg", 16, 16, ExtAverageHash, "ExtAverageHash", 27}, + {"_examples/sample1.jpg", "_examples/sample1.jpg", 17, 17, ExtAverageHash, "ExtAverageHash", 0}, + {"_examples/sample2.jpg", "_examples/sample2.jpg", 17, 17, ExtAverageHash, "ExtAverageHash", 0}, + {"_examples/sample3.jpg", "_examples/sample3.jpg", 17, 17, ExtAverageHash, "ExtAverageHash", 0}, + {"_examples/sample4.jpg", "_examples/sample4.jpg", 17, 17, ExtAverageHash, "ExtAverageHash", 0}, + {"_examples/sample1.jpg", "_examples/sample1.jpg", 8, 8, ExtPerceptionHash, "ExtPerceptionHash", 0}, + {"_examples/sample2.jpg", "_examples/sample2.jpg", 8, 8, ExtPerceptionHash, "ExtPerceptionHash", 0}, + {"_examples/sample3.jpg", "_examples/sample3.jpg", 8, 8, ExtPerceptionHash, "ExtPerceptionHash", 0}, + {"_examples/sample4.jpg", "_examples/sample4.jpg", 8, 8, ExtPerceptionHash, "ExtPerceptionHash", 0}, + {"_examples/sample1.jpg", "_examples/sample2.jpg", 8, 8, ExtPerceptionHash, "ExtPerceptionHash", 32}, + {"_examples/sample1.jpg", "_examples/sample3.jpg", 8, 8, ExtPerceptionHash, "ExtPerceptionHash", 2}, + {"_examples/sample1.jpg", "_examples/sample4.jpg", 8, 8, ExtPerceptionHash, "ExtPerceptionHash", 30}, + {"_examples/sample2.jpg", "_examples/sample3.jpg", 8, 8, ExtPerceptionHash, "ExtPerceptionHash", 34}, + {"_examples/sample2.jpg", "_examples/sample4.jpg", 8, 8, ExtPerceptionHash, "ExtPerceptionHash", 20}, + {"_examples/sample1.jpg", "_examples/sample1.jpg", 16, 16, ExtPerceptionHash, "ExtPerceptionHash", 0}, + {"_examples/sample2.jpg", "_examples/sample2.jpg", 16, 16, ExtPerceptionHash, "ExtPerceptionHash", 0}, + {"_examples/sample3.jpg", "_examples/sample3.jpg", 16, 16, ExtPerceptionHash, "ExtPerceptionHash", 0}, + {"_examples/sample4.jpg", "_examples/sample4.jpg", 16, 16, ExtPerceptionHash, "ExtPerceptionHash", 0}, + {"_examples/sample1.jpg", "_examples/sample2.jpg", 16, 16, ExtPerceptionHash, "ExtPerceptionHash", 122}, + {"_examples/sample1.jpg", "_examples/sample3.jpg", 16, 16, ExtPerceptionHash, "ExtPerceptionHash", 12}, + {"_examples/sample1.jpg", "_examples/sample4.jpg", 16, 16, ExtPerceptionHash, "ExtPerceptionHash", 122}, + {"_examples/sample2.jpg", "_examples/sample3.jpg", 16, 16, ExtPerceptionHash, "ExtPerceptionHash", 118}, + {"_examples/sample2.jpg", "_examples/sample4.jpg", 16, 16, ExtPerceptionHash, "ExtPerceptionHash", 104}, + {"_examples/sample1.jpg", "_examples/sample1.jpg", 17, 17, ExtPerceptionHash, "ExtPerceptionHash", 0}, + {"_examples/sample2.jpg", "_examples/sample2.jpg", 17, 17, ExtPerceptionHash, "ExtPerceptionHash", 0}, + {"_examples/sample3.jpg", "_examples/sample3.jpg", 17, 17, ExtPerceptionHash, "ExtPerceptionHash", 0}, + {"_examples/sample4.jpg", "_examples/sample4.jpg", 17, 17, ExtPerceptionHash, "ExtPerceptionHash", 0}, + {"_examples/sample1.jpg", "_examples/sample1.jpg", 8, 8, ExtDifferenceHash, "ExtDifferenceHash", 0}, + {"_examples/sample2.jpg", "_examples/sample2.jpg", 8, 8, ExtDifferenceHash, "ExtDifferenceHash", 0}, + {"_examples/sample3.jpg", "_examples/sample3.jpg", 8, 8, ExtDifferenceHash, "ExtDifferenceHash", 0}, + {"_examples/sample4.jpg", "_examples/sample4.jpg", 8, 8, ExtDifferenceHash, "ExtDifferenceHash", 0}, + {"_examples/sample1.jpg", "_examples/sample2.jpg", 8, 8, ExtDifferenceHash, "ExtDifferenceHash", 43}, + {"_examples/sample1.jpg", "_examples/sample3.jpg", 8, 8, ExtDifferenceHash, "ExtDifferenceHash", 0}, + {"_examples/sample1.jpg", "_examples/sample4.jpg", 8, 8, ExtDifferenceHash, "ExtDifferenceHash", 37}, + {"_examples/sample2.jpg", "_examples/sample3.jpg", 8, 8, ExtDifferenceHash, "ExtDifferenceHash", 43}, + {"_examples/sample2.jpg", "_examples/sample4.jpg", 8, 8, ExtDifferenceHash, "ExtDifferenceHash", 16}, + {"_examples/sample1.jpg", "_examples/sample1.jpg", 16, 16, ExtDifferenceHash, "ExtDifferenceHash", 0}, + {"_examples/sample2.jpg", "_examples/sample2.jpg", 16, 16, ExtDifferenceHash, "ExtDifferenceHash", 0}, + {"_examples/sample3.jpg", "_examples/sample3.jpg", 16, 16, ExtDifferenceHash, "ExtDifferenceHash", 0}, + {"_examples/sample4.jpg", "_examples/sample4.jpg", 16, 16, ExtDifferenceHash, "ExtDifferenceHash", 0}, + {"_examples/sample1.jpg", "_examples/sample2.jpg", 16, 16, ExtDifferenceHash, "ExtDifferenceHash", 139}, + {"_examples/sample1.jpg", "_examples/sample3.jpg", 16, 16, ExtDifferenceHash, "ExtDifferenceHash", 14}, + {"_examples/sample1.jpg", "_examples/sample4.jpg", 16, 16, ExtDifferenceHash, "ExtDifferenceHash", 130}, + {"_examples/sample2.jpg", "_examples/sample3.jpg", 16, 16, ExtDifferenceHash, "ExtDifferenceHash", 147}, + {"_examples/sample2.jpg", "_examples/sample4.jpg", 16, 16, ExtDifferenceHash, "ExtDifferenceHash", 89}, + {"_examples/sample1.jpg", "_examples/sample1.jpg", 17, 17, ExtDifferenceHash, "ExtDifferenceHash", 0}, + {"_examples/sample2.jpg", "_examples/sample2.jpg", 17, 17, ExtDifferenceHash, "ExtDifferenceHash", 0}, + {"_examples/sample3.jpg", "_examples/sample3.jpg", 17, 17, ExtDifferenceHash, "ExtDifferenceHash", 0}, + {"_examples/sample4.jpg", "_examples/sample4.jpg", 17, 17, ExtDifferenceHash, "ExtDifferenceHash", 0}, } { file1, err := os.Open(tt.img1) if err != nil { diff --git a/imagehash.go b/imagehash.go index 4a89550..b8aad76 100644 --- a/imagehash.go +++ b/imagehash.go @@ -212,8 +212,8 @@ func (h *ExtImageHash) Dump(w io.Writer) error { return nil } -// LoadImageHashExtend method loads a ExtImageHash from io.Reader. -func LoadImageHashExtend(b io.Reader) (*ExtImageHash, error) { +// LoadExtImageHash method loads a ExtImageHash from io.Reader. +func LoadExtImageHash(b io.Reader) (*ExtImageHash, error) { type E struct { Hash []uint64 Kind Kind @@ -232,7 +232,7 @@ const extStrFmt = "%1s:%s" // ExtImageHashFromString returns a big hash from a hex representation // -// Deprecated: Use goimagehash.LoadImageHashExtend instead. +// Deprecated: Use goimagehash.LoadExtImageHash instead. func ExtImageHashFromString(s string) (*ExtImageHash, error) { var kindStr string var hashStr string diff --git a/imagehash_test.go b/imagehash_test.go index 5b08a3d..da9dd5b 100644 --- a/imagehash_test.go +++ b/imagehash_test.go @@ -105,13 +105,13 @@ func TestSerialization(t *testing.T) { // test for ExtIExtImageHash sizeList := []int{8, 16} for _, size := range sizeList { - hash, err := PerceptionHashExtend(img, size, size) + hash, err := ExtPerceptionHash(img, size, size) checkErr(err) hex := hash.ToString() // len(kind) == 1, len(":") == 1 if len(hex) != size*size/4+2 { - t.Errorf("Got invalid hex string '%v'; %v of '%v'", hex, "PerceptionHashExtend", ex) + t.Errorf("Got invalid hex string '%v'; %v of '%v'", hex, "ExtPerceptionHash", ex) } reHash, err := ExtImageHashFromString(hex) @@ -121,7 +121,7 @@ func TestSerialization(t *testing.T) { checkErr(err) if distance != 0 { - t.Errorf("Original and unserialized objects should be identical, got distance=%v; %v of '%v'", distance, "PerceptionHashExtend", ex) + t.Errorf("Original and unserialized objects should be identical, got distance=%v; %v of '%v'", distance, "ExtPerceptionHash", ex) } } } @@ -140,13 +140,13 @@ func TestDifferentBitSizeHash(t *testing.T) { img, _, err := image.Decode(file) checkErr(err) - hash1, _ := AverageHashExtend(img, 32, 32) - hash2, _ := DifferenceHashExtend(img, 32, 32) + hash1, _ := ExtAverageHash(img, 32, 32) + hash2, _ := ExtDifferenceHash(img, 32, 32) _, err = hash1.Distance(hash2) if err == nil { t.Errorf("Should got error with different kinds of hashes") } - hash3, _ := AverageHashExtend(img, 31, 31) + hash3, _ := ExtAverageHash(img, 31, 31) _, err = hash1.Distance(hash3) if err == nil { t.Errorf("Should got error with different bits of hashes") @@ -201,7 +201,7 @@ func TestDumpAndLoad(t *testing.T) { // test for ExtIExtImageHash extMethods := []func(img image.Image, width, height int) (*ExtImageHash, error){ - AverageHashExtend, PerceptionHashExtend, DifferenceHashExtend, + ExtAverageHash, ExtPerceptionHash, ExtDifferenceHash, } sizeList := []int{8, 16} @@ -215,7 +215,7 @@ func TestDumpAndLoad(t *testing.T) { checkErr(err) foo.Flush() bar := bufio.NewReader(&b) - reHash, err := LoadImageHashExtend(bar) + reHash, err := LoadExtImageHash(bar) checkErr(err) distance, err := hash.Distance(reHash)