Browse Source

Added a new enum class for know properties. Started fleshing out the HashService and how it will generate hashes. Added a hamming object to calculate hamming distances between two long values

master
Drew Short 11 years ago
parent
commit
3869f2b302
  1. 30
      src/main/scala/com/sothr/imagetools/hash/HashService.scala
  2. 18
      src/main/scala/com/sothr/imagetools/util/Hamming.scala
  3. 17
      src/main/scala/com/sothr/imagetools/util/PropertiesEnum.scala

30
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
}

18
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')
}
}

17
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")
}
Loading…
Cancel
Save