Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve command line utility #119

Merged
merged 6 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
targets: wasm32-wasi,aarch64-unknown-linux-musl,x86_64-pc-windows-msvc,x86_64-unknown-linux-gnu
targets: wasm32-wasip1,aarch64-unknown-linux-musl,x86_64-pc-windows-msvc,x86_64-unknown-linux-gnu
components: rustfmt,clippy

- name: Build default target
run: cargo build --locked
- name: Build wasm32-wasi
run: cargo build --locked --target wasm32-wasi --lib
- name: Build wasm32-wasip1
run: cargo build --locked --target wasm32-wasip1 --lib
- name: Build aarch64-unknown-linux-musl
run: cargo build --locked --target aarch64-unknown-linux-musl --lib
- name: Build x86_64-pc-windows-msvc
run: cargo build --locked --target x86_64-pc-windows-msvc --lib
- name: Run tests
run: cargo test --locked
- name: Run tests (use_rayon)
run: cargo test --locked --features use_rayon
- name: Check formatting
run: cargo fmt --check

81 changes: 44 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ simple_logger ="5.0"
unroll = "0.1"
rayon-core = { version = "1", optional = true }
git-version = "0.3"
pico-args = "0.5"

[target.'cfg(windows)'.dependencies]
[target.'cfg(target_os = "windows")'.dependencies]
cpu-time = "1.0"
thread-priority = "1.0.0"
thread-priority = "1.0"

[target.'cfg(target_os = "linux")'.dependencies]
cpu-time = "1.0"
thread-priority = "1.0"

[dev-dependencies]
rstest = "0.22"
Expand Down
2 changes: 1 addition & 1 deletion src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub const MAX_THREADS: usize = 8;
pub const RESIDUAL_NOISE_FLOOR: usize = 7;

pub const LEPTON_VERSION: u8 = 1; // Lepton version, same as used by Lepton C++ since we support the same format
pub const MAX_FILE_SIZE_BYTES: i32 = 128 * 1024 * 1024;

//pub const LogMaxNumerator : i32 = 18;
//pub const DefaultEncodingThreads : usize = 8;
pub const SMALL_FILE_BYTES_PER_ENCDOING_THREAD: usize = 125000;
Expand Down
6 changes: 6 additions & 0 deletions src/enabled_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ pub struct EnabledFeatures {

/// number of threads used for encoding/decoding
pub max_threads: u32,

/// maximum size of a jpeg file
pub max_jpeg_file_size: u32,
}

impl EnabledFeatures {
Expand All @@ -39,6 +42,7 @@ impl EnabledFeatures {
use_16bit_adv_predict: true,
accept_invalid_dht: false,
max_threads: 8,
max_jpeg_file_size: 128 * 1024 * 1024,
}
}

Expand All @@ -55,6 +59,7 @@ impl EnabledFeatures {
use_16bit_adv_predict: false,
accept_invalid_dht: true,
max_threads: 8,
max_jpeg_file_size: 128 * 1024 * 1024,
}
}

Expand All @@ -71,6 +76,7 @@ impl EnabledFeatures {
use_16bit_adv_predict: true,
accept_invalid_dht: true,
max_threads: 8,
max_jpeg_file_size: 128 * 1024 * 1024,
}
}
}
9 changes: 9 additions & 0 deletions src/lepton_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ impl From<TryFromIntError> for LeptonError {
}
}

impl From<pico_args::Error> for LeptonError {
#[track_caller]
fn from(e: pico_args::Error) -> Self {
let mut e = LeptonError::new(ExitCode::SyntaxError, e.to_string().as_str());
e.add_context();
e
}
}

impl<T> From<std::sync::mpsc::SendError<T>> for LeptonError {
#[track_caller]
fn from(e: std::sync::mpsc::SendError<T>) -> Self {
Expand Down
15 changes: 15 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ pub use metrics::Metrics;

use crate::lepton_error::{AddContext, Result};

#[cfg(not(feature = "use_rayon"))]
pub fn set_thread_priority(priority: i32) {
#[cfg(any(target_os = "windows", target_os = "linux"))]
{
let p = match priority {
100 => thread_priority::ThreadPriority::Max,
0 => thread_priority::ThreadPriority::Min,
_ => panic!("Unsupported thread priority value: {}", priority),
};

thread_priority::set_current_thread_priority(p).unwrap();
crate::structs::simple_threadpool::set_thread_priority(p);
}
}

/// Decodes Lepton container and recreates the original JPEG file
pub fn decode_lepton<R: BufRead, W: Write>(
reader: &mut R,
Expand Down
Loading
Loading