diff --git a/src/main/scala/com/sothr/imagetools/hash/HashService.scala b/src/main/scala/com/sothr/imagetools/hash/HashService.scala index 31330e0..c31221f 100644 --- a/src/main/scala/com/sothr/imagetools/hash/HashService.scala +++ b/src/main/scala/com/sothr/imagetools/hash/HashService.scala @@ -1,16 +1,40 @@ package com.sothr.imagetools.hash +import com.sothr.imagetools.dto.ImageHashDTO +import com.sothr.imagetools.image.Image +import com.sothr.imagetools.util.{PropertiesEnum, PropertiesService} + object HashService { - def getAhash(imageData:Array[Array[Integer]]):Long = { + def getImageHashes(image:Image):ImageHashDTO = { + var ahash:Long = 0L + var dhash:Long = 0L + var phash:Long = 0L + + //Get Image Data + var imageData:Array[Array[Int]] = null + + if (PropertiesService.get(PropertiesEnum.UseAhash.toString) == "true") { + ahash = getAhash(imageData) + } + if (PropertiesService.get(PropertiesEnum.UseAhash.toString) == "true") { + dhash = getDhash(imageData) + } + if (PropertiesService.get(PropertiesEnum.UseAhash.toString) == "true") { + phash = getPhash(imageData) + } + return new ImageHashDTO(ahash, dhash, phash) + } + + def getAhash(imageData:Array[Array[Int]]):Long = { return 0L } - def getDhash(imageData:Array[Array[Integer]]):Long = { + def getDhash(imageData:Array[Array[Int]]):Long = { return 0L } - def getPhash(imageData:Array[Array[Integer]]):Long = { + def getPhash(imageData:Array[Array[Int]]):Long = { return 0L } diff --git a/src/main/scala/com/sothr/imagetools/util/Hamming.scala b/src/main/scala/com/sothr/imagetools/util/Hamming.scala new file mode 100644 index 0000000..aa6dac6 --- /dev/null +++ b/src/main/scala/com/sothr/imagetools/util/Hamming.scala @@ -0,0 +1,18 @@ +package com.sothr.imagetools.util + +object Hamming { + + /** + * Calculate the hamming distance between two longs + * + * @param hash1 The first hash to compare + * @param hash2 The second hash to compare + * @return + */ + def getDistance(hash1: Long, hash2: Long): Int = { + //The XOR of hash1 and hash2 is converted to a binary string + //then the number of '1's is counted. This is the hamming distance + (hash1 ^ hash2).toBinaryString.count(_ == '1') + } + +} \ No newline at end of file diff --git a/src/main/scala/com/sothr/imagetools/util/PropertiesEnum.scala b/src/main/scala/com/sothr/imagetools/util/PropertiesEnum.scala new file mode 100644 index 0000000..ef61015 --- /dev/null +++ b/src/main/scala/com/sothr/imagetools/util/PropertiesEnum.scala @@ -0,0 +1,17 @@ +package com.sothr.imagetools.util + +object PropertiesEnum extends Enumeration { + type PropertiesEnum = Value + val Version = Value("version") + //default image settings + val ImageDifferenceThreshold = Value("image.differenceThreshold") + val UseAhash = Value("image.ahash.use") + val AhashWeight = Value("image.ahash.weight") + val UseDhash = Value("image.dhash.use") + val DhashWeight = Value("image.dhash.weight") + val UsePhash = Value("image.phash.use") + val PhashWeight = Value("image.phash.weight") + //Default Thumbnail Settings + val ThumbnailDirectory = Value("thumbnail.directory") + val ThumbnailSize = Value("thumbnail.size") +} \ No newline at end of file