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

Add -max-width:n and -max-height:n CLI options #52

Merged
merged 2 commits into from
Jan 4, 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
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@ cargo build --release

#### Running

There is an `lepton_jpeg_util.exe` wrapper that is built as part of the project. It can be used to compress/decompress and also to verify the test end-to-end on a given JPEG. If the input file has a `.jpg` extension, it will encode. If the input file has a `.lep` extension, it will decode back to the original`.jpg`.
There is an `lepton_jpeg_util.exe` wrapper that is built as part of the project. It can be used to compress/decompress and also to verify the test end-to-end on a given JPEG. If the input file has a `.jpg` extension, it will encode. If the input file has a `.lep` extension, it will decode back to the original`.jpg`.

It supports the following options:

`lepton_jpeg_util.exe [options] <inputfile> [<outputfile>]`

| Option | Description |
| ---------------- | ------------------------------------------------------------ |
| `-threads:n` | Runs with a maximum of n threads. For encoding, this limits the amount of parallelism that can be gotten out of the decoder. |
| `-dump` | Dumps the contents of a JPG or LEP file, with the -all option, it will also dump the cooefficient image blocks |
| `-noprogressive` | Will cause an error if we encounter a progressive file rather than trying to encode it |
| `-verify` | Reads, encodes and unencodes verifying that there is an exact match. No output file is specified. |
| `-iter:n` | Runs N iterations of the operation. Useful when we are running inside a profiler. |
| Option | Description |
| ----------------------- | ------------------------------------------------------------ |
| `-threads:n` | Runs with a maximum of n threads. For encoding, this limits the amount of parallelism that can be gotten out of the decoder. |
| `-dump` | Dumps the contents of a JPG or LEP file, with the `-all` option, it will also dump the cooefficient image blocks. |
| `-noprogressive` | Will cause an error if we encounter a progressive file rather than trying to encode it. |
| `-acceptdqtswithzeros` | Accept images with DQTs with zeros (may cause divide-by-zero). |
| `-iter:n` | Runs N iterations of the operation. Useful when we are running inside a profiler. |
| `-max-width:n` | Limit the maximum image width to n pixels, instead of the default 16386. Fails with an error if limit is exceeded. |
| `-max-height:n` | Limit the maximum image height to n pixels, instead of the default 16386. Fails with an error il limit is exceeded. |

## Contributing

Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ fn main_with_result() -> anyhow::Result<()> {
num_threads = x;
} else if let Some(x) = parse_numeric_parameter(args[i].as_str(), "-iter:") {
iterations = x;
} else if let Some(x) = parse_numeric_parameter(args[i].as_str(), "-max-width:") {
enabled_features.max_jpeg_width = x;
} else if let Some(x) = parse_numeric_parameter(args[i].as_str(), "-max-height:") {
enabled_features.max_jpeg_height = x;
} else if args[i] == "-dump" {
dump = true;
} else if args[i] == "-all" {
Expand Down
2 changes: 1 addition & 1 deletion src/structs/jpeg_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ impl JPegHeader {

if self.img_height > enabled_features.max_jpeg_height || self.img_width > enabled_features.max_jpeg_width
{
return err_exit_code(ExitCode::UnsupportedJpeg, "image dimensions larger than 16386");
return err_exit_code(ExitCode::UnsupportedJpeg, format!("image dimensions larger than {0}x{1}", enabled_features.max_jpeg_width, enabled_features.max_jpeg_height).as_str());
}

self.cmpc = usize::from(segment[hpos + 5]);
Expand Down