1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2026-01-25 08:01:39 +00:00

Compare commits

...

3 Commits
4.0.1 ... rust

Author SHA1 Message Date
Virgil Dupras
f29fe4c756 Playing with Rust and Python 2015-04-20 22:32:22 -04:00
Virgil Dupras
942e5a3c31 Merge branch 'master' into rust 2015-04-20 18:58:01 -04:00
Virgil Dupras
6be927ed8b New rust branch 2014-10-31 17:36:16 -04:00
5 changed files with 120 additions and 0 deletions

View File

@@ -1,3 +1,10 @@
# About the "rust" branch
I'm really excited about Rust and I'm trying out a Rust implementation of dupeGuru's bottlenecks
(PE's image comparison).
For fun.
# dupeGuru # dupeGuru
[dupeGuru][dupeguru] is a cross-platform (Linux, OS X, Windows) GUI tool to find duplicate files in [dupeGuru][dupeguru] is a cross-platform (Linux, OS X, Windows) GUI tool to find duplicate files in

66
core_pe/rustmodule/Cargo.lock generated Normal file
View File

@@ -0,0 +1,66 @@
[root]
name = "block"
version = "0.0.1"
dependencies = [
"image 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "byteorder"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "enum_primitive"
version = "0.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "image"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"enum_primitive 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libc"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "log"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num"
version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustc-serialize"
version = "0.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"

View File

@@ -0,0 +1,12 @@
[package]
name = "block"
version = "0.0.1"
authors = ["Virgil Dupras <hsoft@hardcoded.net>"]
[lib]
name = "block"
crate-type = ["dylib"]
[dependencies]
image = "*"

View File

@@ -0,0 +1,8 @@
import ctypes
p = 'target/release/libblock-b7b66d53f276d597.so'
imgp = b'/home/hsoft/src/dupeguru/images/dgme_logo_128.png'
block = ctypes.CDLL(p)
s = ctypes.create_string_buffer(imgp)
print(repr(block.block(imgp)))

View File

@@ -0,0 +1,27 @@
#![feature(libc)]
extern crate libc;
extern crate image;
use libc::c_char;
use std::ffi::CStr;
use std::str;
use std::path::Path;
use image::GenericImage;
#[no_mangle]
pub extern "C" fn block(value: *const c_char) -> u32 {
let slice = unsafe { CStr::from_ptr(value) };
let path = &Path::new(str::from_utf8(slice.to_bytes()).unwrap());
let image = image::open(path).unwrap().to_rgb();
let mut totr: u32 = 0;
let mut totg: u32 = 0;
let mut totb: u32 = 0;
for pixel in image.pixels() {
let data = pixel.data;
totr += data[0] as u32;
totg += data[1] as u32;
totb += data[2] as u32;
}
println!("foo! {} {} {}", totr, totg, totb);
42
}