Skip to main content

JpegDecoder

Struct JpegDecoder 

Source
pub struct JpegDecoder<S>
where 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> JpegDecoder<S>
where S: Source,

Source

pub fn new(source: S, limits: Limits) -> Result<JpegDecoder<S>, PixelsError>

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.

Source

pub fn with_scale( source: S, limits: Limits, scale: Scale, ) -> Result<JpegDecoder<S>, PixelsError>

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.

Source

pub const fn scale(&self) -> Scale

The resolution this decoder produces, as eighths of full size.

Always Scale::Full for a progressive frame.

Source

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> Debug for JpegDecoder<S>
where S: Debug + Source,

Source§

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

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

impl<S> Decoder for JpegDecoder<S>
where S: Source + Debug,

Source§

fn icc_profile(&self) -> Option<&[u8]>

The ICC profile, joined from its APP2 segments.

Source§

fn orientation(&self) -> Orientation

The EXIF orientation, from the first EXIF APP1 segment.

Source§

fn descriptor(&self) -> ImageDescriptor

The shape of the image, known after the header is parsed.
Source§

fn capability(&self) -> DecodeCapability

What this decoder can produce without a full decode.
Source§

fn reduced_descriptor(&self, target: (u32, u32)) -> Option<ImageDescriptor>

What this decoder would produce if asked for target or larger, when the format lets it reach that size more cheaply than a full decode. Read more
Source§

fn reduce_to(&mut self, descriptor: ImageDescriptor) -> Result<(), PixelsError>

Commit to producing descriptor, which Decoder::reduced_descriptor must have returned. Read more
Source§

fn read_row(&mut self, out: &mut [u8]) -> Result<(), PixelsError>

Decode the next row, top to bottom, into out. Read more
Source§

fn animation(&self) -> Option<Animation>

The source’s animation, if it has more than one frame. Read more
Source§

fn read_region( &mut self, region: Region, out: &mut TileMut<'_>, ) -> Result<(), PixelsError>

Decode an arbitrary region into out. Read more

Auto Trait Implementations§

§

impl<S> Freeze for JpegDecoder<S>
where Inner<S>: Freeze,

§

impl<S> RefUnwindSafe for JpegDecoder<S>
where Inner<S>: RefUnwindSafe,

§

impl<S> Send for JpegDecoder<S>
where Inner<S>: Send,

§

impl<S> Sync for JpegDecoder<S>
where Inner<S>: Sync,

§

impl<S> Unpin for JpegDecoder<S>
where Inner<S>: Unpin,

§

impl<S> UnsafeUnpin for JpegDecoder<S>
where Inner<S>: UnsafeUnpin,

§

impl<S> UnwindSafe for JpegDecoder<S>
where Inner<S>: UnwindSafe,

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> 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.