Skip to main content

Decoder

Struct Decoder 

Source
pub struct Decoder<'a> { /* private fields */ }
Expand description

A borrowed view of a JPEG stream ready to decode. Constructed via Decoder::new or Decoder::from_view. Decoder<'a>: Send + Sync.

Implementations§

Source§

impl Decoder<'_>

Source

pub fn decode_request( &self, request: DecodeRequest, ) -> Result<(Vec<u8>, DecodeOutcome), JpegError>

Decode into a freshly allocated tightly packed buffer using a request object instead of a method-name cross-product.

§Errors

Returns an output-geometry, unsupported-format, or scan decode error.

Source§

impl Decoder<'_>

Source

pub fn decode_into( &self, out: &mut [u8], stride: usize, fmt: PixelFormat, ) -> Result<DecodeOutcome, JpegError>

Decode the full image into the caller’s buffer.

§Errors
Source

pub fn decode_scaled_into( &self, out: &mut [u8], stride: usize, fmt: PixelFormat, scale: Downscale, ) -> Result<DecodeOutcome, JpegError>

Decode the full image into the caller’s buffer using the core PixelFormat + Downscale contract.

§Errors

Returns an output-buffer, unsupported-format, or scan decode error.

Source

pub fn decode_into_with_scratch( &self, pool: &mut ScratchPool, out: &mut [u8], stride: usize, fmt: PixelFormat, ) -> Result<DecodeOutcome, JpegError>

Decode the full image into the caller’s buffer, reusing the supplied ScratchPool. On a long-running tile batch this eliminates the per-tile allocation of stripe buffers, the DC predictor, and the chroma upsample rows — the realistic WSI reader shape. The first call against a fresh pool does the allocation; subsequent calls at the same-or-smaller shape reuse the underlying Vecs.

§Errors

Identical to Self::decode_into.

Source

pub fn decode_scaled_into_with_scratch( &self, pool: &mut ScratchPool, out: &mut [u8], stride: usize, fmt: PixelFormat, scale: Downscale, ) -> Result<DecodeOutcome, JpegError>

Self::decode_scaled_into with caller-owned scratch.

§Errors

Returns an output-buffer, unsupported-format, or scan decode error.

Source

pub fn decode_region_into( &self, out: &mut [u8], stride: usize, fmt: PixelFormat, roi: Rect, ) -> Result<DecodeOutcome, JpegError>

Decode a rectangular region of the image into the caller’s buffer.

roi is expressed in source-image coordinates. If fmt requests a downscaled output, the written pixels cover the corresponding bounding box in the scaled image grid.

§Errors

Returns an invalid-region, output-buffer, unsupported-format, or scan decode error.

Source

pub fn decode_region_scaled_into( &self, out: &mut [u8], stride: usize, fmt: PixelFormat, roi: Rect, scale: Downscale, ) -> Result<DecodeOutcome, JpegError>

Decode roi into the caller’s buffer using the core PixelFormat + Downscale contract.

§Errors

Returns an invalid-region, output-buffer, unsupported-format, or scan decode error.

Source

pub fn decode_region_scaled_into_with_scratch( &self, pool: &mut ScratchPool, out: &mut [u8], stride: usize, fmt: PixelFormat, roi: Rect, scale: Downscale, ) -> Result<DecodeOutcome, JpegError>

Self::decode_region_scaled_into with caller-owned scratch.

§Errors

Returns an invalid-region, output-buffer, unsupported-format, or scan decode error.

Source§

impl Decoder<'_>

Source

pub fn decode_rows<S>(&self, sink: &mut S) -> Result<DecodeOutcome, JpegError>
where S: RowSink<u8, Error = JpegError>,

Decode the full image into rows delivered to sink.

DCT-backed and 8-bit lossless color paths emit interleaved RGB8 rows. Lossless 16-bit grayscale SOF3 emits little-endian Gray16 rows, and supported lossless 16-bit color SOF3 emits little-endian Rgb16 rows.

§Errors

Returns a scan decode error or an error reported by sink.

Source

pub fn decode_rows_with_scratch<S>( &self, pool: &mut ScratchPool, sink: &mut S, ) -> Result<DecodeOutcome, JpegError>
where S: RowSink<u8, Error = JpegError>,

Self::decode_rows with caller-owned scratch. See Self::decode_into_with_scratch for the reuse contract.

§Errors

Returns a scan decode error or an error reported by sink.

Source

pub fn decode_component_rows_with_scratch<W>( &self, pool: &mut ScratchPool, writer: &mut W, ) -> Result<DecodeOutcome, JpegError>

Decode the full image into component rows.

§Errors

Returns a scan decode error or an error reported by writer.

Source

pub fn decode_region_component_rows_with_scratch<W>( &self, pool: &mut ScratchPool, writer: &mut W, roi: Rect, scale: Downscale, ) -> Result<DecodeOutcome, JpegError>

Decode roi into component rows, optionally at a reduced scale.

§Errors

Returns an invalid-region or scan error, or an error reported by writer.

Source§

impl<'a> Decoder<'a>

Source

pub fn inspect(input: &'a [u8]) -> Result<Info, JpegError>

Parse the headers without decoding pixels. The parser walks headers up to the first SOS and then performs a lightweight marker scan so Info::scan_count reflects all scans in the file.

§Errors

Returns any structural, unsupported-SOF, or sanity-check error encountered before the Start-of-Scan marker. See JpegError.

Source

pub fn new(input: &'a [u8]) -> Result<Self, JpegError>

Build a decoder ready for decode_into. Parses the full header, pre- builds every referenced Huffman table, and validates that the stream is one of the SOFs this release implements.

§Errors
Source

pub fn from_view(view: JpegView<'a>) -> Result<Self, JpegError>

Build a decoder from a previously parsed JpegView.

§Errors

Returns an error when the view describes an unsupported JPEG shape or references missing or invalid coding tables.

Source

pub fn from_view_in_context( view: JpegView<'a>, ctx: &mut DecoderContext, ) -> Result<Self, JpegError>

Build a decoder from a previously parsed JpegView, reusing shared compiled DHT/DQT state from ctx when table contents repeat.

§Errors

Returns an error when the view describes an unsupported JPEG shape or references missing or invalid coding tables.

Source

pub fn info(&self) -> &Info

The parsed header as a public Info.

Trait Implementations§

Source§

impl<'a> Debug for Decoder<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !Freeze for Decoder<'a>

§

impl<'a> RefUnwindSafe for Decoder<'a>

§

impl<'a> Send for Decoder<'a>

§

impl<'a> Sync for Decoder<'a>

§

impl<'a> Unpin for Decoder<'a>

§

impl<'a> UnsafeUnpin for Decoder<'a>

§

impl<'a> UnwindSafe for Decoder<'a>

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.