NewImageHashFromBytes loads an image from a byte slice and calculates its hash
(data []byte, hashType ImageHashType)
| 56 | |
| 57 | // NewImageHashFromBytes loads an image from a byte slice and calculates its hash |
| 58 | func NewImageHashFromBytes(data []byte, hashType ImageHashType) (*ImageHash, error) { |
| 59 | h := &ImageHash{hashType: hashType} |
| 60 | |
| 61 | switch hashType { |
| 62 | case HashTypeDct: |
| 63 | if err := h.calcDct2Hash(data); err != nil { |
| 64 | return nil, err |
| 65 | } |
| 66 | |
| 67 | case HashTypeSHA256: |
| 68 | if err := h.calcSha256Hash(data); err != nil { |
| 69 | return nil, err |
| 70 | } |
| 71 | |
| 72 | default: |
| 73 | return nil, fmt.Errorf("unsupported hash type: %d", hashType) |
| 74 | } |
| 75 | |
| 76 | return h, nil |
| 77 | } |
| 78 | |
| 79 | // Distance calculates the distance between two hashes |
| 80 | // Returns error if hash types don't match |
no test coverage detected