Verified Commit 9d26f661 authored by Jenny's avatar Jenny
Browse files

added command line args

parent c67900b2
......@@ -14,6 +14,17 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234"
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "autocfg"
version = "1.0.1"
......@@ -44,6 +55,37 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "3.0.0-beta.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcd70aa5597dbc42f7217a543f9ef2768b2ef823ba29036072d30e1d88e98406"
dependencies = [
"atty",
"bitflags",
"clap_derive",
"indexmap",
"lazy_static",
"os_str_bytes",
"strsim",
"termcolor",
"textwrap",
"vec_map",
]
[[package]]
name = "clap_derive"
version = "3.0.0-beta.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b5bb0d655624a0b8770d1c178fb8ffcb1f91cc722cb08f451e3dc72465421ac"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "color_quant"
version = "1.1.0"
......@@ -129,6 +171,21 @@ dependencies = [
"weezl",
]
[[package]]
name = "hashbrown"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
[[package]]
name = "heck"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
dependencies = [
"unicode-segmentation",
]
[[package]]
name = "hermit-abi"
version = "0.1.19"
......@@ -157,6 +214,16 @@ dependencies = [
"tiff",
]
[[package]]
name = "indexmap"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
dependencies = [
"autocfg",
"hashbrown",
]
[[package]]
name = "jpeg-decoder"
version = "0.1.22"
......@@ -257,10 +324,17 @@ dependencies = [
"libc",
]
[[package]]
name = "os_str_bytes"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6acbef58a60fe69ab50510a55bc8cdd4d6cf2283d27ad338f54cb52747a9cf2d"
[[package]]
name = "pixelspammer"
version = "0.1.0"
version = "1.0.0"
dependencies = [
"clap",
"image",
]
......@@ -276,6 +350,48 @@ dependencies = [
"miniz_oxide 0.3.7",
]
[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn",
"version_check",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]
[[package]]
name = "proc-macro2"
version = "1.0.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rayon"
version = "1.5.1"
......@@ -313,6 +429,41 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "1.0.80"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d010a1623fbd906d51d650a9916aaefc05ffa0e4053ff7fe601167f3e715d194"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "termcolor"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
dependencies = [
"winapi-util",
]
[[package]]
name = "textwrap"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80"
dependencies = [
"unicode-width",
]
[[package]]
name = "tiff"
version = "0.6.1"
......@@ -324,8 +475,69 @@ dependencies = [
"weezl",
]
[[package]]
name = "unicode-segmentation"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
[[package]]
name = "unicode-width"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "version_check"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
[[package]]
name = "weezl"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8b77fdfd5a253be4ab714e4ffa3c49caf146b4de743e97510c0656cf90f1e8e"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[package]
name = "pixelspammer"
version = "0.1.0"
version = "1.0.0"
edition = "2018"
authors = ["Netali <me@netali.de>"]
repository = "https://gitlab.fem-net.de/netali/pixelspammer"
......@@ -9,4 +9,5 @@ license = "AGPL-3.0-or-later"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
image = "0.23.14"
\ No newline at end of file
image = "0.23.14"
clap = "3.0.0-beta.4"
\ No newline at end of file
......@@ -7,10 +7,12 @@ use std::thread::JoinHandle;
use image::GenericImageView;
fn draw_image_slice(image_path: &String, offset_x: u32, offset_y: u32, from_x: u32, from_y: u32, to_x: u32, to_y: u32) {
use clap::{Arg, App};
fn draw_image_slice(image_path: &String, host: &String, offset_x: u32, offset_y: u32, from_x: u32, from_y: u32, to_x: u32, to_y: u32) {
let img = image::open(Path::new(image_path)).expect("Failed to open image!");
let mut stream = TcpStream::connect("127.0.0.1:1234").expect("Failed to connect!");
let mut stream = TcpStream::connect(host).expect("Failed to connect!");
loop {
for x in from_x..=to_x {
......@@ -29,7 +31,7 @@ fn draw_image_slice(image_path: &String, offset_x: u32, offset_y: u32, from_x: u
//stream.shutdown(Shutdown::Both).expect("Failed to shutdown connection!");
}
fn slice_image(image_path: &str, slices: u32, offset_x: u32, offset_y: u32) {
fn slice_image(image_path: &str, host: &str, slices: u32, offset_x: u32, offset_y: u32) {
let img = image::open(Path::new(image_path)).expect("Failed to open image!");
let x_max = img.dimensions().0 - 1;
......@@ -67,9 +69,10 @@ fn slice_image(image_path: &str, slices: u32, offset_x: u32, offset_y: u32) {
};
let path_string = String::from(image_path);
let host_string = String::from(host);
let t = thread::spawn(move || {
draw_image_slice(&path_string, offset_x, offset_y, from_x, from_y, to_x, to_y)
draw_image_slice(&path_string, &host_string, offset_x, offset_y, from_x, from_y, to_x, to_y)
});
threads.push(t);
......@@ -82,6 +85,59 @@ fn slice_image(image_path: &str, slices: u32, offset_x: u32, offset_y: u32) {
}
fn main() {
//TODO: get command line args
slice_image("/home/netali/pixelflut/femlogo.jpg", 4, 350, 350);
let matches = App::new("pixelspammer")
.version("1.0.0")
.author("Netali <me@netali.de>")
.about("A simple, multithreaded pixelflut client")
.arg(Arg::new("host")
.short('h')
.long("host")
.value_name("IP:PORT")
.about("Pixelflut-Server to connect to (IP:Port)")
.takes_value(true)
.required(true)
)
.arg(Arg::new("image")
.short('i')
.long("image")
.value_name("FILE")
.about("Image file to flood")
.takes_value(true)
.required(true)
)
.arg(Arg::new("slices")
.short('s')
.long("slices")
.value_name("SLICES")
.about("Number of parts in that each axis should be sliced")
.takes_value(true)
.required(true)
)
.arg(Arg::new("offset-x")
.short('x')
.long("xoffset")
.value_name("OFFSET")
.about("Offset on the x-axis")
.takes_value(true)
.required(false)
.default_value("0")
)
.arg(Arg::new("offset-y")
.short('y')
.long("yoffset")
.value_name("OFFSET")
.about("Offset on the y-axis")
.takes_value(true)
.required(false)
.default_value("0")
)
.get_matches();
let image_path = matches.value_of("image").unwrap();
let host = matches.value_of("host").unwrap();
let slices: u32 = matches.value_of_t_or_exit("slices");
let offset_x: u32 = matches.value_of_t_or_exit("offset-x");
let offset_y: u32 = matches.value_of_t_or_exit("offset-y");
slice_image(image_path, host, slices, offset_x, offset_y);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment