// Copyright (c) the JPEG XL Project Authors. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file.
usesuper::{JxlBasicInfo, JxlColorProfile, JxlDecoderOptions, JxlPixelFormat}; usecrate::container::frame_index::FrameIndexBox; use box_parser::BoxParser; use codestream_parser::CodestreamParser;
mod box_parser; mod codestream_parser; mod process;
/// Obtains the image's basic information, if available. /// /// Keep this aligned with typed `WithImageInfo` transitions: image info is /// not observable until the embedded profile has been parsed. pubfn basic_info(&self) -> Option<&JxlBasicInfo> { self.codestream_parser.embedded_color_profile.as_ref()?; self.codestream_parser.basic_info.as_ref()
}
/// Retrieves the file's color profile, if available. pubfn embedded_color_profile(&self) -> Option<&JxlColorProfile> { self.codestream_parser.embedded_color_profile.as_ref()
}
/// Retrieves the current output color profile, if available. pubfn output_color_profile(&self) -> Option<&JxlColorProfile> { self.codestream_parser.output_color_profile.as_ref()
}
/// Specifies the preferred color profile to be used for outputting data. /// Same semantics as JxlDecoderSetOutputColorProfile. pubfn set_output_color_profile(&mutself, profile: JxlColorProfile) -> Result<()> { iflet (JxlColorProfile::Icc(_), None) = (&profile, &self.options.cms) { return Err(Error::ICCOutputNoCMS);
} self.codestream_parser.output_color_profile = Some(profile); self.codestream_parser.output_color_profile_set_by_user = true;
Ok(())
}
pubfn set_pixel_format(&mutself, pixel_format: JxlPixelFormat) { // TODO(veluca): return an error if we are asking for both planar and // interleaved-in-color alpha. self.codestream_parser.pixel_format = Some(pixel_format); self.codestream_parser.update_default_output_color_profile();
}
pubfn frame_header(&self) -> Option<JxlFrameHeader> { let frame_header = self.codestream_parser.frame.as_ref()?.header(); // The render pipeline always adds ExtendToImageDimensionsStage which extends // frames to the full image size. So the output size is always the image size, // not the frame's upsampled size. let size = self.codestream_parser.basic_info.as_ref()?.size;
Some(JxlFrameHeader {
name: frame_header.name.clone(),
duration: self
.codestream_parser
.animation
.as_ref()
.map(|anim| frame_header.duration(anim)),
size,
})
}
/// Number of passes we have full data for. /// Returns the minimum number of passes completed across all groups. pubfn num_completed_passes(&self) -> Option<usize> {
Some(self.codestream_parser.num_completed_passes())
}
/// Fully resets the decoder to its initial state. /// /// This clears all state including pixel_format. For animation loop playback, /// consider using [`rewind`](Self::rewind) instead which preserves pixel_format. /// /// After calling this, the caller should provide input from the beginning of the file. pubfn reset(&mutself) { // TODO(veluca): keep track of frame offsets for skipping. self.box_parser = BoxParser::new(); self.codestream_parser = CodestreamParser::new();
}
/// Rewinds for animation loop replay, keeping pixel_format setting. /// /// This resets the decoder but preserves the pixel_format configuration, /// so the caller doesn't need to re-set it after rewinding. /// /// After calling this, the caller should provide input from the beginning of the file. /// Headers will be re-parsed, then frames can be decoded again. /// /// Returns `true` if pixel_format was preserved, `false` if none was set. pubfn rewind(&mutself) -> bool { self.box_parser = BoxParser::new(); self.codestream_parser.rewind().is_some()
}
/// Returns the parsed frame index box, if the file contained one. pubfn frame_index(&self) -> Option<&FrameIndexBox> { self.box_parser.frame_index.as_ref()
}
/// Returns visible frame info entries collected during parsing. pubfn scanned_frames(&self) -> &[VisibleFrameInfo] {
&self.codestream_parser.scanned_frames
}
/// Resets frame-level state to prepare for decoding a new frame. /// /// Preserves image-level state (file header, decoder state including /// reference frames, color profiles, pixel format). Clears frame header, /// TOC, section buffers, and restores the box parser to the correct /// state so the next `process()` call parses a new frame header. /// /// The `seek_target` comes from `VisibleFrameInfo::seek_target`. It tells /// the decoder which container box position to seek to and how many visible /// frames to skip before the target frame. The caller must provide raw file /// input starting from `seek_target.decode_start_file_offset`. /// /// After seeking the first time, scanned frame information will no longer /// be updated. If you seek before having completed decoding once, the scanned /// frames might be incomplete. pubfn start_new_frame(&mutself, seek_target: VisibleFrameSeekTarget) { self.box_parser
.reset_for_codestream_seek(seek_target.remaining_in_box); self.codestream_parser
.start_new_frame(seek_target.visible_frames_to_skip);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.