#[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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.color: ColorSpaceThe 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: boolWhether 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: ResolutionThe 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: ImageHeaderThe 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: FileTypeThe 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).