Skip to content

Commit

Permalink
jxl-oxide-cli: Apply orientation to reported image dimension (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
tirr-c authored Aug 29, 2023
1 parent c3ba35d commit a6ad508
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
}

/// 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
}
}

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());
if image_meta.orientation != 1 {
println!(" Encoded image dimension: {}x{}", image_size.width, image_size.height);
print!(" Orientation of encoded image: ");
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"),
_ => {},
}
}

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()
}

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

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

0 comments on commit a6ad508

Please sign in to comment.