Skip to content

Commit

Permalink
[toimage] Group image output options
Browse files Browse the repository at this point in the history
  • Loading branch information
Enet4 committed Jul 5, 2024
1 parent f43442a commit 79a1c6b
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions toimage/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ struct App {
#[arg(short = 'F', long = "frame", default_value = "0")]
frame_number: u32,

#[clap(flatten)]
image_options: ImageOptions,

/// Print more information about the image and the output file
#[arg(short = 'v', long = "verbose")]
verbose: bool,
}

/// Options related to image output and conversion steps
#[derive(Debug, Copy, Clone, Parser)]
struct ImageOptions {
/// Force output bit depth to 8 bits per sample
#[arg(long = "8bit", conflicts_with = "force_16bit")]
force_8bit: bool,
Expand All @@ -55,12 +66,9 @@ struct App {
conflicts_with = "force_16bit"
)]
unwrap: bool,

/// Print more information about the image and the output file
#[arg(short = 'v', long = "verbose")]
verbose: bool,
}


#[derive(Debug, Snafu)]
enum Error {
#[snafu(display("could not read DICOM file {}", path.display()))]
Expand Down Expand Up @@ -156,9 +164,7 @@ fn run(args: App) -> Result<(), Error> {
output,
ext,
frame_number,
force_8bit,
force_16bit,
unwrap,
image_options,
verbose,
} = args;

Expand All @@ -185,9 +191,7 @@ fn run(args: App) -> Result<(), Error> {
outdir.clone(),
ext.clone(),
frame_number,
force_8bit,
force_16bit,
unwrap,
image_options,
verbose,
)
.unwrap();
Expand All @@ -204,9 +208,7 @@ fn run(args: App) -> Result<(), Error> {
outdir,
ext,
frame_number,
force_8bit,
force_16bit,
unwrap,
image_options,
verbose,
)?;
}
Expand All @@ -223,9 +225,7 @@ fn run(args: App) -> Result<(), Error> {
outdir.clone(),
ext.clone(),
frame_number,
force_8bit,
force_16bit,
unwrap,
image_options,
verbose,
)
.unwrap();
Expand All @@ -242,11 +242,15 @@ fn convert_single_file(
outdir: Option<PathBuf>,
ext: Option<String>,
frame_number: u32,
force_8bit: bool,
force_16bit: bool,
unwrap: bool,
image_options: ImageOptions,
verbose: bool,
) -> Result<(), Error> {
let ImageOptions {
force_8bit,
force_16bit,
unwrap,
} = image_options;

// check if there is a .dcm extension, otherwise, add it
if output.extension() != Some("dcm".as_ref()) && !output_is_set {
let pathstr = output.to_str().unwrap();
Expand Down

0 comments on commit 79a1c6b

Please sign in to comment.