Compare commits
No commits in common. "e26a3b6782d013a02df466ddb88d1b032ecb3eef" and "3b3fec80ed3f8272f1a9045ee4282cdfc54840c4" have entirely different histories.
e26a3b6782
...
3b3fec80ed
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@ -16,6 +16,8 @@ jobs:
|
|||||||
archive: zip
|
archive: zip
|
||||||
- target: x86_64-unknown-linux-musl
|
- target: x86_64-unknown-linux-musl
|
||||||
archive: tar.gz tar.xz tar.zst
|
archive: tar.gz tar.xz tar.zst
|
||||||
|
- target: x86_64-apple-darwin
|
||||||
|
archive: zip
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@master
|
- uses: actions/checkout@master
|
||||||
- name: Compile and release
|
- name: Compile and release
|
||||||
|
27
src/main.rs
27
src/main.rs
@ -2,7 +2,6 @@
|
|||||||
use clap::{Args,Parser, Subcommand};
|
use clap::{Args,Parser, Subcommand};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{BufReader, Read};
|
use std::io::{BufReader, Read};
|
||||||
use std::process;
|
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
use colors_transform::{Color, Hsl, Rgb};
|
use colors_transform::{Color, Hsl, Rgb};
|
||||||
@ -101,11 +100,7 @@ fn demo() {
|
|||||||
fn encode(in_path: &str, out_path: &str) {
|
fn encode(in_path: &str, out_path: &str) {
|
||||||
|
|
||||||
//Init png decoder, attempt to decode png into bitmap, throw error if unsuccessful
|
//Init png decoder, attempt to decode png into bitmap, throw error if unsuccessful
|
||||||
let file:File = File::open(in_path).unwrap_or_else(|e| {
|
let decoder = png::Decoder::new(File::open(in_path).unwrap());
|
||||||
println!("Error: {:?}", e.to_string());
|
|
||||||
process::exit(1);
|
|
||||||
});
|
|
||||||
let decoder = png::Decoder::new(file);
|
|
||||||
let mut reader = match decoder.read_info() {
|
let mut reader = match decoder.read_info() {
|
||||||
Ok(reader) => reader,
|
Ok(reader) => reader,
|
||||||
Err(e) => panic!("ERROR: couldn't read file: {e:}"),
|
Err(e) => panic!("ERROR: couldn't read file: {e:}"),
|
||||||
@ -134,13 +129,7 @@ fn encode(in_path: &str, out_path: &str) {
|
|||||||
Err(err) => panic!("Problem generating image: {:?}", err),
|
Err(err) => panic!("Problem generating image: {:?}", err),
|
||||||
};
|
};
|
||||||
|
|
||||||
//in case out_path is erroneously passed with suffix
|
write_to_file(encode_from_image(img), out_path).expect("ERROR: Can't write file.");
|
||||||
let filename = match out_path.strip_suffix(".png") {
|
|
||||||
Some(s) => s,
|
|
||||||
None => out_path
|
|
||||||
};
|
|
||||||
|
|
||||||
write_to_file(encode_from_image(img), filename).expect("ERROR: Can't write file.");
|
|
||||||
info!("Encoding successful!");
|
info!("Encoding successful!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,9 +183,9 @@ fn bench(input: &str, output: Option<String>) {
|
|||||||
}
|
}
|
||||||
match decode(&out_path) {
|
match decode(&out_path) {
|
||||||
Ok(img) => {
|
Ok(img) => {
|
||||||
//Never fails as long as memory does not corrupt thanks to above push_str op.
|
|
||||||
let png_path = out_path.strip_suffix(".qoi").unwrap();
|
let out_buf = img.to_bytes();
|
||||||
img.write_png(&png_path);
|
let _ = write_to_file(out_buf, out_path.strip_suffix(".qoi").unwrap()).expect("whoops!");
|
||||||
},
|
},
|
||||||
Err(e) => panic!("Error: {e:?}")
|
Err(e) => panic!("Error: {e:?}")
|
||||||
}
|
}
|
||||||
@ -300,12 +289,8 @@ fn main() {
|
|||||||
Commands::Encode(args) => {
|
Commands::Encode(args) => {
|
||||||
let out_path = match &args.output {
|
let out_path = match &args.output {
|
||||||
Some(s) => s,
|
Some(s) => s,
|
||||||
None => args.input.strip_suffix(".png").unwrap_or_else(||{
|
None => &args.input
|
||||||
println!("Error: Could not construct output arg from input arg. Please provide explicitly");
|
|
||||||
process::exit(1);
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|
||||||
encode(&args.input, &out_path);
|
encode(&args.input, &out_path);
|
||||||
},
|
},
|
||||||
Commands::Demo { } => demo()
|
Commands::Demo { } => demo()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user