pub struct JpegDecoder<S: Source> { /* private fields */ }Expand description
Decodes a JPEG stream.
Baseline frames are decoded by this crate, one MCU row at a time.
Progressive frames are handed to a wrapped decoder (ADR-0004) and are
internally buffered — the distinction is not visible through Decoder,
which is the point of the trait boundary.
Implementations§
Source§impl<S: Source> JpegDecoder<S>
impl<S: Source> JpegDecoder<S>
Sourcepub fn new(source: S, limits: Limits) -> Result<Self>
pub fn new(source: S, limits: Limits) -> Result<Self>
Read every header up to and including the scan header.
No coefficient is decoded here for a baseline frame, so this is the
probe()/metadata path as well as the start of a decode (SPEC
§Guarantees 3). A progressive frame is decoded in full, because it has
no prefix that yields a finished row.
§Errors
Returns PixelsError::Malformed for a stream that is not a
well-formed JPEG, PixelsError::Unsupported for a variant neither
this crate nor the wrapped decoder handles (arithmetic coding, 12-bit,
CMYK), or PixelsError::LimitExceeded if the frame exceeds limits.
Sourcepub fn with_scale(source: S, limits: Limits, scale: Scale) -> Result<Self>
pub fn with_scale(source: S, limits: Limits, scale: Scale) -> Result<Self>
Read every header, and decode at a reduced resolution.
At M/8 scale the decoder inverse-transforms only the low-frequency
corner of each block, so a thumbnail costs a fraction of the arithmetic
and — the point of it — the full-resolution image is never
materialized. Entropy decoding is unchanged: every coefficient is still
read, because the format gives no way to skip one.
Decoder::descriptor reports the scaled size, so a caller that
asks for a reduced decode is told what it will actually receive.
scale is ignored for a progressive frame, which the wrapped decoder
produces at full size; Decoder::descriptor then reports that size,
so the caller is never misled about what it is getting.
§Errors
As JpegDecoder::new.
Sourcepub const fn scale(&self) -> Scale
pub const fn scale(&self) -> Scale
The resolution this decoder produces, as eighths of full size.
Always Scale::Full for a progressive frame.
Sourcepub const fn is_progressive(&self) -> bool
pub const fn is_progressive(&self) -> bool
Whether this stream was progressive, and so decoded by the wrapped codec rather than by this crate.
Trait Implementations§
Source§impl<S: Source + Debug> Decoder for JpegDecoder<S>
impl<S: Source + Debug> Decoder for JpegDecoder<S>
Source§fn icc_profile(&self) -> Option<&[u8]>
fn icc_profile(&self) -> Option<&[u8]>
The ICC profile, joined from its APP2 segments.
Source§fn orientation(&self) -> Orientation
fn orientation(&self) -> Orientation
The EXIF orientation, from the first EXIF APP1 segment.
Source§fn descriptor(&self) -> ImageDescriptor
fn descriptor(&self) -> ImageDescriptor
Source§fn capability(&self) -> DecodeCapability
fn capability(&self) -> DecodeCapability
Source§fn reduced_descriptor(&self, target: (u32, u32)) -> Option<ImageDescriptor>
fn reduced_descriptor(&self, target: (u32, u32)) -> Option<ImageDescriptor>
target or larger, when
the format lets it reach that size more cheaply than a full decode. Read moreSource§fn read_row(&mut self, out: &mut [u8]) -> Result<()>
fn read_row(&mut self, out: &mut [u8]) -> Result<()>
out. Read moreSource§fn animation(&self) -> Option<Animation>
fn animation(&self) -> Option<Animation>
Source§fn read_region(
&mut self,
region: Region,
out: &mut TileMut<'_>,
) -> Result<(), PixelsError>
fn read_region( &mut self, region: Region, out: &mut TileMut<'_>, ) -> Result<(), PixelsError>
out. Read more