From c853b638276600fba779d764c0cb66f2495fb18a Mon Sep 17 00:00:00 2001 From: Drew Short Date: Fri, 18 Sep 2015 22:03:47 -0500 Subject: [PATCH] Working on caching the DCT/DFT --- .gitignore | 1 + src/cache.rs | 11 +++++++++-- src/hash.rs | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 0854752..9369b2a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # System Files .directory +*.swp # Compiled files *.o diff --git a/src/cache.rs b/src/cache.rs index eaa97ce..9b15694 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -42,7 +42,7 @@ fn get_file_hash(path: &Path) -> Result { /** * Put an image buffer in the cache */ -pub fn put_in_cache(path: &Path, size: u32, image: &ImageBuffer, Vec>) { +pub fn put_image_in_cache(path: &Path, size: u32, image: &ImageBuffer, Vec>) { let hash = get_file_hash(&path); match hash { Ok(sha1) => { @@ -58,10 +58,17 @@ pub fn put_in_cache(path: &Path, size: u32, image: &ImageBuffer, } } +/** + * Expects a slice of slices that represents lines in the file + */ +pub fn put_file_in_cache(path: &Path, size: u32, file_contents: &[&[u8]]) { + +} + /** * Get an image buffer out of the cache */ -pub fn get_from_cache(path: &Path, size: u32) -> Option, Vec>> { +pub fn get_image_from_cache(path: &Path, size: u32) -> Option, Vec>> { let hash = get_file_hash(&path); match hash { Ok(sha1) => { diff --git a/src/hash.rs b/src/hash.rs index ab6dea2..6d43a3b 100644 --- a/src/hash.rs +++ b/src/hash.rs @@ -110,7 +110,7 @@ pub fn prepare_image<'a>(path: &'a Path, hash_type: &HashType, precision: &Preci _ => precision.get_size() }; // Check if we have the already converted image in a cache and use that if possible. - match cache::get_from_cache(&path, size) { + match cache::get_image_from_cache(&path, size) { Some(image) => { PreparedImage { orig_path: &*image_path, image: image } }, @@ -119,7 +119,7 @@ pub fn prepare_image<'a>(path: &'a Path, hash_type: &HashType, precision: &Preci let image = image::open(path).unwrap(); let small_image = image.resize_exact(size, size, FilterType::Lanczos3); let grey_image = small_image.to_luma(); - cache::put_in_cache(&path, size, &grey_image); + cache::put_image_in_cache(&path, size, &grey_image); PreparedImage { orig_path: &*image_path, image: grey_image } }, }