Browse Source

Working on a simple caching solution for already processed image buffers

develop
Drew Short 9 years ago
parent
commit
18d715ef1c
  1. 1
      Cargo.toml
  2. 30
      src/cache.rs
  3. 4
      src/hash.rs
  4. 1
      src/lib.rs

1
Cargo.toml

@ -9,3 +9,4 @@ rustc-serialize = "*"
image = "*" image = "*"
complex = "*" complex = "*"
dft = "*" dft = "*"
rust-crypto = "*"

30
src/cache.rs

@ -0,0 +1,30 @@
// Copyright 2015 Drew Short <drew@sothr.com>.
//
// Licensed under the MIT license<LICENSE-MIT or http://opensource.org/licenses/MIT>.
// 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) {
}

4
src/hash.rs

@ -51,6 +51,10 @@ pub struct PerceptualHashes<'a> {
*/ */
pub fn prepare_image(path: &Path, size: u32) -> PreparedImage { pub fn prepare_image(path: &Path, size: u32) -> PreparedImage {
let image_path = path.to_str().unwrap(); 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 image = image::open(path).unwrap();
let small_image = image.resize_exact(size, size, FilterType::Lanczos3); let small_image = image.resize_exact(size, size, FilterType::Lanczos3);
let grey_image = small_image.to_luma(); let grey_image = small_image.to_luma();

1
src/lib.rs

@ -6,6 +6,7 @@
use std::path::Path; use std::path::Path;
mod hash; mod hash;
mod cache;
pub fn get_phashes(path: &Path) -> hash::PerceptualHashes { pub fn get_phashes(path: &Path) -> hash::PerceptualHashes {
hash::get_perceptual_hashes(path, 8) hash::get_perceptual_hashes(path, 8)

Loading…
Cancel
Save