Skip to content

Support reading image print resolutionΒ #1067

@cormacrelf

Description

@cormacrelf

I would like to be able to access image print resolution in image formats which support it.

My specific use case for this functionality is to replace the image decoders in the c2rust-converted XeTeX source code in this Tectonic working group. See crlf0710/tectonic#68. Tectonic is obviously print-oriented, and needs to be able to lay out images on real paper dimensions. It therefore tries to establish how big an image would like to be printed, which it currently does by reading, for example, pixels per metre from a Windows BMP's BITMAPINFOHEADER and converting to pixels per inch as f64. So without this feature essentially all of the image decoding routines have to stay just to get these values, and image doesn't help.

This is more generally applicable to ... any code that intends to display images on screens or on paper. I would expect a GUI image viewer component to need this.

Draft

Different image formats expose this kind of thing differently.

  • The png crate exposes PixelDimensions
  • The jpeg_decoder crate currently just ignores JFIF APP0 blocks which include x/y/units (with units = {cm | in | pixel aspect ratio}
  • The bmp module consumes but ignores those parts of headers that support density information (

    image/src/bmp/decoder.rs

    Lines 710 to 716 in e48d283

    // The next 12 bytes represent data array size in bytes,
    // followed the horizontal and vertical printing resolutions
    // We will calculate the pixel array size using width & height of image
    // We're not interesting the horz or vert printing resolutions
    self.reader.read_u32::<LittleEndian>()?;
    self.reader.read_u32::<LittleEndian>()?;
    self.reader.read_u32::<LittleEndian>()?;
    )
  • ...

I haven't looked at the rest but I couldn't quite say at this stage if there should be a common few enums that can support all formats' density information, or different types for each format. I would say that for Tectonic, I don't think we care about preserving all this information, because however it was represented, we are just going to convert it to PPI. Maybe a simple fn pixels_per_inch(&self) -> Option<(f64, f64)> on the *Decoders which support it would suffice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: new featuresAn operation that does not exist yet, add draft tag if appropriatetopic: meta dataTowards dealing with meta data

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions