Crate photodna

Crate photodna 

Source
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 Hash type 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§

BorderHashResult
The result of a hash computation with border detection.
GeneratorWindows or Linux or macOS
The PhotoDNA hash generator.
GeneratorOptions
Options for configuring the PhotoDNA generator.
Hash
A PhotoDNA perceptual hash.
HashOptions
Options for a single hash computation.

Enums§

PhotoDnaError
Error type for PhotoDNA operations.
PixelFormat
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.