|
|
@ -17,9 +17,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
|
|
SOFTWARE. |
|
|
|
SOFTWARE. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use clap::Arg; |
|
|
|
use std::io::Write; |
|
|
|
use std::io::Write; |
|
|
|
use std::process::exit; |
|
|
|
use std::process::exit; |
|
|
|
use clap::Arg; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// returns a character from a character set that corresponds to given brightness
|
|
|
|
/// returns a character from a character set that corresponds to given brightness
|
|
|
|
fn get_char(charset: &[char], brightness: &u8) -> char { |
|
|
|
fn get_char(charset: &[char], brightness: &u8) -> char { |
|
|
@ -38,12 +38,11 @@ fn charify(charset: &[char], brightness_map: &image::GrayImage) -> Vec<char> { |
|
|
|
return character_map; |
|
|
|
return character_map; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn main() { |
|
|
|
fn main() { |
|
|
|
let mut charset: Vec<char> = vec![' ', '░', '▒', '▓', '█']; |
|
|
|
let mut charset: Vec<char> = vec![' ', '░', '▒', '▓', '█']; |
|
|
|
|
|
|
|
|
|
|
|
let matches = clap::Command::new("charify") |
|
|
|
let matches = clap::Command::new("charify") |
|
|
|
.version("0.1") |
|
|
|
.version("0.2") |
|
|
|
.author("Kasyanov Nikolay Alexeyevich (Unbewohnte)") |
|
|
|
.author("Kasyanov Nikolay Alexeyevich (Unbewohnte)") |
|
|
|
.arg( |
|
|
|
.arg( |
|
|
|
Arg::new("image") |
|
|
|
Arg::new("image") |
|
|
@ -52,7 +51,7 @@ fn main() { |
|
|
|
.required(true) |
|
|
|
.required(true) |
|
|
|
.long("image") |
|
|
|
.long("image") |
|
|
|
.short('i') |
|
|
|
.short('i') |
|
|
|
.index(1) |
|
|
|
.index(1), |
|
|
|
) |
|
|
|
) |
|
|
|
.arg( |
|
|
|
.arg( |
|
|
|
Arg::new("destination") |
|
|
|
Arg::new("destination") |
|
|
@ -61,7 +60,7 @@ fn main() { |
|
|
|
.required(true) |
|
|
|
.required(true) |
|
|
|
.long("destination") |
|
|
|
.long("destination") |
|
|
|
.short('d') |
|
|
|
.short('d') |
|
|
|
.index(2) |
|
|
|
.index(2), |
|
|
|
) |
|
|
|
) |
|
|
|
.arg( |
|
|
|
.arg( |
|
|
|
Arg::new("new_dimensions") |
|
|
|
Arg::new("new_dimensions") |
|
|
@ -69,7 +68,7 @@ fn main() { |
|
|
|
.takes_value(true) |
|
|
|
.takes_value(true) |
|
|
|
.required(false) |
|
|
|
.required(false) |
|
|
|
.long("new_dimensions") |
|
|
|
.long("new_dimensions") |
|
|
|
.short('r') |
|
|
|
.short('r'), |
|
|
|
) |
|
|
|
) |
|
|
|
.arg( |
|
|
|
.arg( |
|
|
|
Arg::new("charset") |
|
|
|
Arg::new("charset") |
|
|
@ -78,7 +77,7 @@ fn main() { |
|
|
|
.required(false) |
|
|
|
.required(false) |
|
|
|
.long("charset") |
|
|
|
.long("charset") |
|
|
|
.short('c') |
|
|
|
.short('c') |
|
|
|
.default_value(&*format!("{:?}", charset)) |
|
|
|
.default_value(" ░▒▓█"), |
|
|
|
) |
|
|
|
) |
|
|
|
.get_matches(); |
|
|
|
.get_matches(); |
|
|
|
|
|
|
|
|
|
|
@ -123,15 +122,13 @@ fn main() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
match destination_file_path.parent() { |
|
|
|
match destination_file_path.parent() { |
|
|
|
Some(path) => { |
|
|
|
Some(path) => match std::fs::create_dir_all(path) { |
|
|
|
match std::fs::create_dir_all(path) { |
|
|
|
|
|
|
|
Ok(_) => {} |
|
|
|
Ok(_) => {} |
|
|
|
Err(e) => { |
|
|
|
Err(e) => { |
|
|
|
eprintln!("[ERROR] could not create \"{}\": {}", path.display(), e); |
|
|
|
eprintln!("[ERROR] could not create \"{}\": {}", path.display(), e); |
|
|
|
exit(1); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
None => {} |
|
|
|
None => {} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -148,19 +145,20 @@ fn main() { |
|
|
|
|
|
|
|
|
|
|
|
// work with new dimensions if present
|
|
|
|
// work with new dimensions if present
|
|
|
|
match matches.value_of("new_dimensions") { |
|
|
|
match matches.value_of("new_dimensions") { |
|
|
|
Some(new_dimensions) => { |
|
|
|
Some(new_dimensions) => match new_dimensions.split_once('x') { |
|
|
|
match new_dimensions.split_once('x') { |
|
|
|
|
|
|
|
Some((nw_str, nh_str)) => { |
|
|
|
Some((nw_str, nh_str)) => { |
|
|
|
let new_width: u32 = nw_str.parse::<u32>().unwrap(); |
|
|
|
let new_width: u32 = nw_str.parse::<u32>().unwrap(); |
|
|
|
let new_height: u32 = nh_str.parse::<u32>().unwrap(); |
|
|
|
let new_height: u32 = nh_str.parse::<u32>().unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
source_image = image::imageops::resize( |
|
|
|
source_image = image::imageops::resize( |
|
|
|
&source_image, new_width, new_height, |
|
|
|
&source_image, |
|
|
|
image::imageops::FilterType::Lanczos3); |
|
|
|
new_width, |
|
|
|
|
|
|
|
new_height, |
|
|
|
|
|
|
|
image::imageops::FilterType::Lanczos3, |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
None => {} |
|
|
|
None => {} |
|
|
|
} |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
None => {} |
|
|
|
None => {} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -179,7 +177,11 @@ fn main() { |
|
|
|
let character_map = charify(&charset, &source_image); |
|
|
|
let character_map = charify(&charset, &source_image); |
|
|
|
for y in 0..source_image.height() { |
|
|
|
for y in 0..source_image.height() { |
|
|
|
for x in 0..source_image.width() { |
|
|
|
for x in 0..source_image.width() { |
|
|
|
match write!(destination_file, "{}", character_map[(y * source_image.width() + x) as usize]) { |
|
|
|
match write!( |
|
|
|
|
|
|
|
destination_file, |
|
|
|
|
|
|
|
"{}", |
|
|
|
|
|
|
|
character_map[(y * source_image.width() + x) as usize] as char |
|
|
|
|
|
|
|
) { |
|
|
|
Ok(_) => {} |
|
|
|
Ok(_) => {} |
|
|
|
Err(e) => { |
|
|
|
Err(e) => { |
|
|
|
eprintln!("[ERROR] error writing to destination file: {}", e) |
|
|
|
eprintln!("[ERROR] error writing to destination file: {}", e) |
|
|
|