mirror of
https://github.com/arsenetar/dupeguru.git
synced 2026-01-25 16:11:39 +00:00
Compare commits
3 Commits
5a4958cff9
...
rust
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f29fe4c756 | ||
|
|
942e5a3c31 | ||
|
|
6be927ed8b |
@@ -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
66
core_pe/rustmodule/Cargo.lock
generated
Normal 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"
|
||||||
|
|
||||||
12
core_pe/rustmodule/Cargo.toml
Normal file
12
core_pe/rustmodule/Cargo.toml
Normal 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 = "*"
|
||||||
|
|
||||||
8
core_pe/rustmodule/foo.py
Normal file
8
core_pe/rustmodule/foo.py
Normal 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)))
|
||||||
|
|
||||||
27
core_pe/rustmodule/src/block.rs
Normal file
27
core_pe/rustmodule/src/block.rs
Normal 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
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user