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<'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 inspect_with_options( input: &'a [u8], options: DecodeOptions, ) -> Result<Info, JpegError>

Parse headers with explicit decode options, without decoding pixels.

The options are applied to the returned Info exactly as they would be for Self::new_with_options.

Source

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

Build a decoder with explicit decode options.

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.

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.

Source

pub fn info(&self) -> &Info

The parsed header as a public Info.

Source

pub fn passthrough_candidate(&self) -> Option<PassthroughCandidate<'a>>

Return a byte-preserving passthrough candidate for this decoded stream.

Source

pub fn restart_index(&self) -> Result<Option<RestartIndex>, JpegError>

Build a restart-marker byte-offset index for the first scan.

Offsets are absolute byte positions in the original JPEG byte slice. Returns Ok(None) when the stream has no non-zero DRI marker.

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( &self, fmt: PixelFormat, ) -> Result<(Vec<u8>, DecodeOutcome), JpegError>

Decode the full image into a freshly allocated tightly-packed buffer.

This is the owned-output counterpart to Self::decode_into. It avoids pre-zeroing the destination buffer, which matters on WSI-sized RGB outputs where the allocation itself can otherwise dominate the benchmark.

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.

Source

pub fn decode_scaled( &self, fmt: PixelFormat, scale: Downscale, ) -> Result<(Vec<u8>, DecodeOutcome), JpegError>

Decode the full image into a freshly allocated tightly-packed buffer using the core PixelFormat + Downscale contract.

Source

pub fn decode_with_scratch( &self, pool: &mut ScratchPool, fmt: PixelFormat, ) -> Result<(Vec<u8>, DecodeOutcome), JpegError>

Self::decode with caller-owned scratch.

Source

pub fn decode_scaled_with_scratch( &self, pool: &mut ScratchPool, fmt: PixelFormat, scale: Downscale, ) -> Result<(Vec<u8>, DecodeOutcome), JpegError>

Self::decode_scaled with caller-owned scratch.

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.

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.

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.

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.

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.

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.

Source

pub fn decode_region( &self, fmt: PixelFormat, roi: Rect, ) -> Result<(Vec<u8>, DecodeOutcome), JpegError>

Decode roi into a freshly allocated tightly-packed buffer.

Source

pub fn decode_region_scaled( &self, fmt: PixelFormat, roi: Rect, scale: Downscale, ) -> Result<(Vec<u8>, DecodeOutcome), JpegError>

Decode roi into a freshly allocated tightly-packed buffer using the core PixelFormat + Downscale contract.

Source

pub fn decode_region_with_scratch( &self, pool: &mut ScratchPool, fmt: PixelFormat, roi: Rect, ) -> Result<(Vec<u8>, DecodeOutcome), JpegError>

Self::decode_region with caller-owned scratch.

Source

pub fn decode_region_scaled_with_scratch( &self, pool: &mut ScratchPool, fmt: PixelFormat, roi: Rect, scale: Downscale, ) -> Result<(Vec<u8>, DecodeOutcome), JpegError>

Self::decode_region_scaled with caller-owned scratch.

Source

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

Self::decode_region_into with caller-owned scratch.

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.

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.

Source

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

Decode the full image into RGBA with a caller-chosen alpha byte.

Source

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

Self::decode_rgba8_into_with_alpha with caller-owned scratch.

Source

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

Decode a region into RGBA with a caller-chosen alpha byte.

Source

pub fn decode_region_rgba8_into_with_alpha_with_scratch( &self, pool: &mut ScratchPool, out: &mut [u8], stride: usize, roi: Rect, alpha: u8, ) -> Result<DecodeOutcome, JpegError>

Self::decode_region_rgba8_into_with_alpha with caller-owned scratch.

Source§

impl Decoder<'_>

Source

pub fn decode_tile<S>( bytes: &[u8], ctx: &mut DecoderContext, pool: &mut ScratchPool, sink: &mut S, ) -> Result<DecodeOutcome, JpegError>
where S: RowSink<u8, Error = JpegError>,

One-shot parse-plus-row-decode of a JPEG tile using caller-owned shared table context and caller-owned scratch.

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
Source§

impl ImageCodec for Decoder<'_>

Source§

type Error = JpegError

Codec-specific error type.
Source§

type Warning = Warning

Non-fatal warning type returned in successful decode outcomes.
Source§

type Pool = ScratchPool

Caller-owned scratch pool type used to reuse allocations.
Source§

impl<'a> ImageDecode<'a> for Decoder<'a>

Source§

type View = JpegView<'a>

Borrowed parse product that can later construct a decoder.
Source§

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

Inspect metadata without decoding pixels.
Source§

fn parse(input: &'a [u8]) -> Result<Self::View, Self::Error>

Parse compressed bytes into a borrowed view.
Source§

fn from_view(view: Self::View) -> Result<Self, Self::Error>

Build a decoder from a parsed view.
Source§

fn decode_into( &mut self, out: &mut [u8], stride: usize, fmt: PixelFormat, ) -> Result<CoreDecodeOutcome<Self::Warning>, Self::Error>

Decode the full image into caller-owned output.
Source§

fn decode_into_with_scratch( &mut self, pool: &mut Self::Pool, out: &mut [u8], stride: usize, fmt: PixelFormat, ) -> Result<CoreDecodeOutcome<Self::Warning>, Self::Error>

Decode the full image into caller-owned output with reusable scratch.
Source§

fn decode_region_into( &mut self, pool: &mut Self::Pool, out: &mut [u8], stride: usize, fmt: PixelFormat, roi: Rect, ) -> Result<CoreDecodeOutcome<Self::Warning>, Self::Error>

Decode a source-coordinate region into caller-owned output.
Source§

fn decode_scaled_into( &mut self, pool: &mut Self::Pool, out: &mut [u8], stride: usize, fmt: PixelFormat, scale: Downscale, ) -> Result<CoreDecodeOutcome<Self::Warning>, Self::Error>

Decode the full image at reduced resolution into caller-owned output.
Source§

fn decode_region_scaled_into( &mut self, pool: &mut Self::Pool, out: &mut [u8], stride: usize, fmt: PixelFormat, roi: Rect, scale: Downscale, ) -> Result<CoreDecodeOutcome<Self::Warning>, Self::Error>

Decode a source-coordinate region at reduced resolution into caller-owned output.
Source§

fn decode_request_into( &mut self, pool: &mut Self::Pool, out: &mut [u8], stride: usize, fmt: PixelFormat, request: DecodeRequest, ) -> Result<DecodeOutcome<Self::Warning>, Self::Error>

Decode a normalized full/ROI/scaled request into caller-owned output.
Source§

impl<'a> ImageDecodeRows<'a, u8> for Decoder<'a>

Source§

fn decode_rows<R: RowSink<u8>>( &mut self, sink: &mut R, ) -> Result<CoreDecodeOutcome<Self::Warning>, DecodeRowsError<Self::Error, R::Error>>

Decode rows into sink without requiring one contiguous output buffer.

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.