Expand description
§photodna
Safe, high-level Rust bindings for the Microsoft PhotoDNA Edge Hash Generator.
PhotoDNA is a perceptual hashing technology that creates a compact “fingerprint” of an image, which can be used to identify visually similar images even after modifications like resizing, cropping, or format conversion.
§Features
- Safe API: All unsafe FFI operations are encapsulated behind a safe interface.
- Zero-Copy Hashes: The
Hashtype uses a fixed-size stack array (no heap allocation). - Typed Errors: Comprehensive error handling via
PhotoDnaError. - Platform Agnostic: Works on Windows, Linux, macOS (via native libraries) or other
platforms (via WebAssembly runtime, handled by
photodna-sys).
§Requirements
This crate requires the proprietary Microsoft PhotoDNA SDK. Before building,
you must set the PHOTODNA_SDK_ROOT environment variable to point to the SDK
installation directory. See the photodna-sys crate documentation for details.
§Quick Start
use photodna::{Generator, GeneratorOptions, PixelFormat, Hash, Result};
fn main() -> Result<()> {
// Initialize the generator (loads the PhotoDNA library)
let generator = Generator::new(GeneratorOptions::default())?;
// Load your image as raw RGB pixels
let image_data: &[u8] = &[/* RGB pixel data */];
let width = 100;
let height = 100;
// Compute the hash
let hash: Hash = generator.compute_hash_rgb(image_data, width, height)?;
// Use the hash (e.g., store in database)
println!("Hash: {}", hash.to_hex());
Ok(())
}§Image Data Requirements
- Minimum image size: 50x50 pixels
- Supported pixel formats: RGB, RGBA, BGRA, ARGB, Grayscale, YCbCr, YUV420P
- Images with few gradients (“flat” images) may fail to hash
§Thread Safety
The Generator can be used from multiple threads if the underlying library
supports it. The max_threads option controls the maximum concurrent hash
operations. Calls exceeding this limit will block until a slot is available.
Structs§
- Border
Hash Result - The result of a hash computation with border detection.
- Generator
Windows or Linux or macOS - The PhotoDNA hash generator.
- Generator
Options - Options for configuring the PhotoDNA generator.
- Hash
- A PhotoDNA perceptual hash.
- Hash
Options - Options for a single hash computation.
Enums§
- Photo
DnaError - Error type for PhotoDNA operations.
- Pixel
Format - Pixel format for raw image data.
Constants§
- HASH_
SIZE - Size of PhotoDNA Edge V2 hash in bytes (binary format).
- HASH_
SIZE_ MAX - Maximum possible hash buffer size.
- LIBRARY_
VERSION - Library version string.
Type Aliases§
- Result
- Result type alias for PhotoDNA operations.