Browse Source

Working on caching the DCT/DFT

develop
Drew Short 9 years ago
parent
commit
c853b63827
  1. 1
      .gitignore
  2. 11
      src/cache.rs
  3. 4
      src/hash.rs

1
.gitignore

@ -1,5 +1,6 @@
# System Files
.directory
*.swp
# Compiled files
*.o

11
src/cache.rs

@ -42,7 +42,7 @@ fn get_file_hash(path: &Path) -> Result<String, Error> {
/**
* Put an image buffer in the cache
*/
pub fn put_in_cache(path: &Path, size: u32, image: &ImageBuffer<image::Luma<u8>, Vec<u8>>) {
pub fn put_image_in_cache(path: &Path, size: u32, image: &ImageBuffer<image::Luma<u8>, Vec<u8>>) {
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<image::Luma<u8>,
}
}
/**
* 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<ImageBuffer<image::Luma<u8>, Vec<u8>>> {
pub fn get_image_from_cache(path: &Path, size: u32) -> Option<ImageBuffer<image::Luma<u8>, Vec<u8>>> {
let hash = get_file_hash(&path);
match hash {
Ok(sha1) => {

4
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 }
},
}

Loading…
Cancel
Save