From 18d715ef1c0cac9ee3d39309426b6cf03f7c0e8c Mon Sep 17 00:00:00 2001 From: Drew Short Date: Tue, 15 Sep 2015 14:50:34 -0500 Subject: [PATCH] Working on a simple caching solution for already processed image buffers --- Cargo.toml | 1 + src/cache.rs | 30 ++++++++++++++++++++++++++++++ src/hash.rs | 4 ++++ src/lib.rs | 1 + 4 files changed, 36 insertions(+) create mode 100644 src/cache.rs diff --git a/Cargo.toml b/Cargo.toml index 16eae08..a31c524 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,3 +9,4 @@ rustc-serialize = "*" image = "*" complex = "*" dft = "*" +rust-crypto = "*" diff --git a/src/cache.rs b/src/cache.rs new file mode 100644 index 0000000..1ee76a5 --- /dev/null +++ b/src/cache.rs @@ -0,0 +1,30 @@ +// Copyright 2015 Drew Short . +// +// Licensed under the MIT license. +// This file may not be copied, modified, or distributed except according to those terms. + +extern image; + +use self::image::ImageBuffer; +use std::path::Path; + +/** + * Get the hash of the desired file and return it as a hex string + */ +fn get_file_hash(path: &Path) -> String { + +} + +/** + * Put an image buffer in the cache + */ +pub fn put_in_cache(path: &Path, image: &ImageBuffer) { + +} + +/** + * Get an image buffer out of the cache + */ +pub fn get_from_cache(path: &Path) -> Some(ImageBuffer) { + +} diff --git a/src/hash.rs b/src/hash.rs index f4c3873..a3fb7d6 100644 --- a/src/hash.rs +++ b/src/hash.rs @@ -51,6 +51,10 @@ pub struct PerceptualHashes<'a> { */ pub fn prepare_image(path: &Path, size: u32) -> PreparedImage { let image_path = path.to_str().unwrap(); + // Check if we have the already converted image in a cache and use that if possible. + + + // Otherwise let's do that work now and store it. let image = image::open(path).unwrap(); let small_image = image.resize_exact(size, size, FilterType::Lanczos3); let grey_image = small_image.to_luma(); diff --git a/src/lib.rs b/src/lib.rs index 6b2e675..b54aec8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,6 +6,7 @@ use std::path::Path; mod hash; +mod cache; pub fn get_phashes(path: &Path) -> hash::PerceptualHashes { hash::get_perceptual_hashes(path, 8)