Skip to content

Commit

Permalink
jxl-oxide-cli: Apply orientation to reported image dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
tirr-c committed Aug 29, 2023
1 parent c3ba35d commit ea2cf59
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
14 changes: 14 additions & 0 deletions crates/jxl-image/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ impl<Ctx> Bundle<Ctx> for ImageHeader {
}
}

impl ImageHeader {
/// Returns the image width with orientation applied.
#[inline]
pub fn width_with_orientation(&self) -> u32 {
self.metadata.apply_orientation(self.size.width, self.size.height, 0, 0, false).0
}

Check warning on line 74 in crates/jxl-image/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/jxl-image/src/lib.rs#L72-L74

Added lines #L72 - L74 were not covered by tests

/// Returns the image height with orientation applied.
#[inline]
pub fn height_with_orientation(&self) -> u32 {
self.metadata.apply_orientation(self.size.width, self.size.height, 0, 0, false).1
}

Check warning on line 80 in crates/jxl-image/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/jxl-image/src/lib.rs#L78-L80

Added lines #L78 - L80 were not covered by tests
}

define_bundle! {
/// Image size information.
#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion crates/jxl-oxide-cli/src/bin/jxl-dec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn main() {
let mut image = JxlImage::open(&args.input).expect("Failed to open file");
let image_size = &image.image_header().size;
let image_meta = &image.image_header().metadata;
tracing::info!("Image dimension: {}x{}", image_size.width, image_size.height);
tracing::info!("Image dimension: {}x{}", image.width(), image.height());
tracing::debug!(colour_encoding = format_args!("{:?}", image_meta.colour_encoding));

if let Some(icc_path) = &args.icc_output {
Expand Down
18 changes: 17 additions & 1 deletion crates/jxl-oxide-cli/src/bin/jxl-info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,23 @@ fn main() {
let image_meta = &image.image_header().metadata;

println!("JPEG XL image");
println!(" Image dimension: {}x{}", image_size.width, image_size.height);

println!(" Image dimension: {}x{}", image.width(), image.height());

Check warning on line 41 in crates/jxl-oxide-cli/src/bin/jxl-info.rs

View check run for this annotation

Codecov / codecov/patch

crates/jxl-oxide-cli/src/bin/jxl-info.rs#L41

Added line #L41 was not covered by tests
if image_meta.orientation != 1 {
println!(" Encoded image dimension: {}x{}", image_size.width, image_size.height);
print!(" Orientation of encoded image: ");

Check warning on line 44 in crates/jxl-oxide-cli/src/bin/jxl-info.rs

View check run for this annotation

Codecov / codecov/patch

crates/jxl-oxide-cli/src/bin/jxl-info.rs#L43-L44

Added lines #L43 - L44 were not covered by tests
match image_meta.orientation {
2 => println!("flipped horizontally"),
3 => println!("rotated 180 degrees"),
4 => println!("flipped vertically"),
5 => println!("transposed"),
6 => println!("rotated 90 degrees CCW"),
7 => println!("rotated 90 degrees CCW, and then flipped horizontally"),
8 => println!("rotated 90 degrees CW"),

Check warning on line 52 in crates/jxl-oxide-cli/src/bin/jxl-info.rs

View check run for this annotation

Codecov / codecov/patch

crates/jxl-oxide-cli/src/bin/jxl-info.rs#L46-L52

Added lines #L46 - L52 were not covered by tests
_ => {},
}
}

println!(" Bit depth: {} bits", image_meta.bit_depth.bits_per_sample());
if image_meta.xyb_encoded {
println!(" XYB encoded, suggested display color encoding:");
Expand Down
12 changes: 12 additions & 0 deletions crates/jxl-oxide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,18 @@ impl<R> JxlImage<R> {
&self.image_header
}

/// Returns the image width with orientation applied.
#[inline]
pub fn width(&self) -> u32 {
self.image_header.width_with_orientation()
}

Check warning on line 147 in crates/jxl-oxide/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/jxl-oxide/src/lib.rs#L145-L147

Added lines #L145 - L147 were not covered by tests

/// Returns the image height with orientation applied.
#[inline]
pub fn height(&self) -> u32 {
self.image_header.height_with_orientation()
}

Check warning on line 153 in crates/jxl-oxide/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/jxl-oxide/src/lib.rs#L151-L153

Added lines #L151 - L153 were not covered by tests

/// Returns the embedded ICC profile.
#[inline]
pub fn embedded_icc(&self) -> Option<&[u8]> {
Expand Down

0 comments on commit ea2cf59

Please sign in to comment.