Skip to main content

Jp2Metadata

Struct Jp2Metadata 

Source
#[non_exhaustive]
pub struct Jp2Metadata {
Show 15 fields pub color: ColorSpace, pub channels: Vec<ChannelDefinition>, pub palette_applied: bool, pub channel_definitions: Option<Vec<ChannelDefinitionEntry>>, pub palette: Option<Palette>, pub channel_mapping: Option<Vec<ChannelMapping>>, pub resolution: Resolution, pub xml: Vec<XmlBox>, pub uuid: Vec<UuidBox>, pub ipr: Vec<IprBox>, pub uuid_info: Vec<UuidInfo>, pub image_header: ImageHeader, pub color_specifications: Vec<ColorSpecification>, pub file_type: FileType, pub reader_requirements: Option<ReaderRequirements>,
}
Expand description

What the JP2 wrapper said about the decoded samples.

None on Image::jp2 for a raw codestream. The struct is #[non_exhaustive], so more of the file’s metadata can be added without a breaking change.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§color: ColorSpace

The color space of the color channels.

§channels: Vec<ChannelDefinition>

One entry per Image::components entry, saying what that channel is: its entry in the file’s channel definition (cdef) box, or, without one, color i + 1 for channel i while i is below the color space’s number of colors (3 for sRGB and sYCC, 1 for grayscale, the profile’s for an ICC profile). A channel past that has no meaning in I.5.3.6 and is ChannelType::Unspecified with Association::None. When the count is unknown (the file gives no color space, the enumerated value is not one this decoder knows, or an ICC profile is too short to name its color space) every channel is a color.

§palette_applied: bool

Whether the samples went through the file’s palette. false when the file has no palette (or a pclr without a cmap), or the caller set DecodeOptions::raw_channels.

§channel_definitions: Option<Vec<ChannelDefinitionEntry>>

The file’s channel definition box (cdef) as written, in file order: Some whenever the file has one, whatever the options, and None without one. The entries are checked only when the decode applies them, so under raw_channels a cn may name a channel the file does not have.

The channels an entry’s channel counts are the file’s components after the palette is expanded, in the order channel_mapping gives (the components as coded for a file without a palette). The decode puts them in color order like this. Start with the channels in that order, so channel c is at position c. For each entry in file order whose type is ChannelType::Color and whose association is Association::Color(n), find where its channel is now (earlier swaps may have moved it) and swap it with whatever is at position n - 1. Every other entry moves nothing. The channel a swap moves out of the way keeps its place in later lookups: it is found where it went.

For example, three color entries (channel 0, color 3), (channel 1, color 2), (channel 2, color 1) give the order [2, 1, 0]: the first swap gives [2, 1, 0], the second finds channel 1 already at position 1, and the third finds channel 2 already at position 0. Reading Cn as a position instead would swap 0 and 2, then 1 with itself, then 2 and 0 back, and give [0, 1, 2], which is wrong.

A file with exactly those entries decodes as this example shows: it applies the rule above to the entries the decoder reports, and the default decode is the raw one in that order.

use rust_j2k::{Association, ChannelType, DecodeOptions, decode_with};

let decoded = decode_with(&bytes, &DecodeOptions::default())?;
let coded = decode_with(&bytes, &DecodeOptions::default().with_raw_channels(true))?;
let entries = decoded.jp2.as_ref().unwrap().channel_definitions.as_ref().unwrap();

// The rule: swap each color entry's channel into position `n - 1`.
let mut order: Vec<usize> = (0..coded.components.len()).collect();
for entry in entries {
    if let (ChannelType::Color, Association::Color(n)) =
        (entry.definition.kind, entry.definition.association)
    {
        let at = order.iter().position(|&c| c == usize::from(entry.channel)).unwrap();
        order.swap(at, usize::from(n) - 1);
    }
}
assert_eq!(order, [2, 1, 0]);

// Output position `p` holds the coded channel `order[p]`, and the
// coded channels differ, so the check is not vacuous.
assert_ne!(coded.components[0].samples, coded.components[2].samples);
for (p, &c) in order.iter().enumerate() {
    assert_eq!(decoded.components[p].samples, coded.components[c].samples);
}

A channel’s label on channels is that of the last entry naming it.

channels itself is only relabeled when the cdef applies: under raw_channels every channel keeps its default label.

§palette: Option<Palette>

The file’s palette, from its pclr box. Present when the palette applies, and also when raw_channels left it unapplied (then palette_applied is false). None without a pclr. None too for a pclr without a cmap: the standard requires both or neither, so the file is invalid, and OpenJPEG ignores the palette in that case, as this decoder does.

§channel_mapping: Option<Vec<ChannelMapping>>

The file’s component mapping, set whenever palette is: one entry per output channel of a palettized decode, in the order before any cdef reordering. An entry is Direct for a component used as coded.

It is the mapping the default decode applies, in either mode, including OpenJPEG’s correction for a single-component file (which turns every entry into a lookup in its own column, so it can differ from the box). Only a cmap the default decode refuses is reported as written, and only under raw_channels, which does not check it; an MTYP other than 0 or 1 is then Reserved.

§resolution: Resolution

The capture and default display resolutions from the header’s res box, each None when the file does not give it.

§xml: Vec<XmlBox>

Every top-level xml box, verbatim and in file order, including those after the codestream. Not parsed.

§uuid: Vec<UuidBox>

Every top-level uuid box, in file order, including those after the codestream. Not interpreted.

§ipr: Vec<IprBox>

Every top-level intellectual property box (jp2i), verbatim and in file order, including those after the codestream. The standard leaves the format of these bytes open, so they are not parsed. jp2i boxes inside other superboxes are not collected.

§uuid_info: Vec<UuidInfo>

Every well-formed top-level UUID info box (uinf), in file order, including those after the codestream: a list of UUIDs and a URL where more about them can be found. The URL is not fetched. A malformed uinf is left out and never fails a decode, as OpenJPEG skips the box (see UuidInfo).

§image_header: ImageHeader

The Image Header box’s (I.5.3.1) flags C, UnkC and IPR.

§color_specifications: Vec<ColorSpecification>

Every Colour Specification box (colr, I.5.3.3) in file order, the ignored ones too: those in every jp2h box and those misplaced at the top level after the first jp2h, before the codestream. A colr after the codestream is not reported. Only the first whose method is 1 or 2 sets color; the others are reported here and not applied.

The boxes are reported as stored in the file, whatever DecodeOptions::color is. Under ColorOutput::Srgb the first usable one (METH 1 or 2, not always the first listed) may still hold the original ICC profile while color is ColorSpace::Srgb.

§file_type: FileType

The File Type box (ftyp, I.5.2).

§reader_requirements: Option<ReaderRequirements>

The first top-level Reader Requirements box (rreq, ISO/IEC 15444-2 M.11.1), before or after the codestream. None without one, and when the first is malformed (see ReaderRequirements).

Trait Implementations§

Source§

impl Clone for Jp2Metadata

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Jp2Metadata

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Jp2Metadata

Source§

impl PartialEq for Jp2Metadata

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Jp2Metadata

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.