Skip to content

Commit

Permalink
Add -max-width:n and -max-height:n CLI options (#52)
Browse files Browse the repository at this point in the history
* lepton_jpeg_util: add -max-width:N and -max-height:N params

* README: update CLI options
  • Loading branch information
m6w6 authored Jan 4, 2024
1 parent 9b353b4 commit 798563c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
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

0 comments on commit 798563c

Please sign in to comment.