You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.3 KiB

  1. package com.sothr.imagetools.image
  2. import com.sothr.imagetools.dto.ImageHashDTO
  3. import com.sothr.imagetools.hash.HashService
  4. import grizzled.slf4j.Logging
  5. class Image(val imagePath:String, val thumbnailPath:String, val imageSize:Tuple2[Int,Int], var hashes:ImageHashDTO = null) extends Serializable with Logging{
  6. var imageType:ImageType = ImageType.SingleFrameImage
  7. def isSimilarTo(otherImage:Image):Boolean = {
  8. debug("Checking {} for similarities with {}",imagePath, otherImage.imagePath)
  9. HashService.areImageHashesSimilar(this.hashes,otherImage.hashes)
  10. }
  11. def getSimilarity(otherImage:Image):Float = {
  12. HashService.getWeightedHashSimilarity(this.hashes, otherImage.hashes)
  13. }
  14. /*def getSimilar(otherImages:Traversable[Image]):Traversable[Image] = {
  15. }*/
  16. def cloneImage:Image = {
  17. return new Image(imagePath,thumbnailPath,imageSize,hashes.cloneHashes)
  18. }
  19. override def toString:String = {
  20. s"Image: $imagePath Thumbnail: $thumbnailPath Image Size: ${imageSize._1}x${imageSize._2} Hashes: $hashes"
  21. }
  22. override def equals(obj:Any) = {
  23. obj match {
  24. case that:Image =>
  25. that.hashCode.equals(this.hashCode)
  26. case _ => false
  27. }
  28. }
  29. override def hashCode:Int = {
  30. var result = 365
  31. result = 37 * result + imagePath.hashCode
  32. result = 41 * result + hashes.hashCode()
  33. result
  34. }
  35. }