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>
impl<'a> Decoder<'a>
Sourcepub fn inspect(input: &'a [u8]) -> Result<Info, JpegError>
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.
Sourcepub fn inspect_with_options(
input: &'a [u8],
options: DecodeOptions,
) -> Result<Info, JpegError>
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.
Sourcepub fn new_with_options(
input: &'a [u8],
options: DecodeOptions,
) -> Result<Self, JpegError>
pub fn new_with_options( input: &'a [u8], options: DecodeOptions, ) -> Result<Self, JpegError>
Build a decoder with explicit decode options.
Sourcepub fn new(input: &'a [u8]) -> Result<Self, JpegError>
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
- Any parse error encountered before SOS (see
Self::inspect). JpegError::NotImplementedfor SOFs that parse but are not yet decodable for the requested shape (for example Progressive12 or unsupported Lossless predictors).JpegError::MissingHuffmanTableif the scan references a DC/AC table slot that was never defined by a DHT segment.
Sourcepub fn from_view(view: JpegView<'a>) -> Result<Self, JpegError>
pub fn from_view(view: JpegView<'a>) -> Result<Self, JpegError>
Build a decoder from a previously parsed JpegView.
Sourcepub fn from_view_in_context(
view: JpegView<'a>,
ctx: &mut DecoderContext,
) -> Result<Self, JpegError>
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.
Sourcepub fn passthrough_candidate(&self) -> Option<PassthroughCandidate<'a>>
pub fn passthrough_candidate(&self) -> Option<PassthroughCandidate<'a>>
Return a byte-preserving passthrough candidate for this decoded stream.
Sourcepub fn restart_index(&self) -> Result<Option<RestartIndex>, JpegError>
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.
Sourcepub fn decode_into(
&self,
out: &mut [u8],
stride: usize,
fmt: PixelFormat,
) -> Result<DecodeOutcome, JpegError>
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
JpegError::OutputBufferTooSmallorJpegError::InvalidStrideif the provided buffer/stride cannot hold the image atfmt.JpegError::NotImplementediffmtrequests a raw output the current release does not emit (e.g.RawYCbCr8).- Any entropy- or structural-decode error from the scan walker.
Sourcepub fn decode(
&self,
fmt: PixelFormat,
) -> Result<(Vec<u8>, DecodeOutcome), JpegError>
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.
Sourcepub fn decode_scaled_into(
&self,
out: &mut [u8],
stride: usize,
fmt: PixelFormat,
scale: Downscale,
) -> Result<DecodeOutcome, JpegError>
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.
Sourcepub fn decode_scaled(
&self,
fmt: PixelFormat,
scale: Downscale,
) -> Result<(Vec<u8>, DecodeOutcome), JpegError>
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.
Sourcepub fn decode_with_scratch(
&self,
pool: &mut ScratchPool,
fmt: PixelFormat,
) -> Result<(Vec<u8>, DecodeOutcome), JpegError>
pub fn decode_with_scratch( &self, pool: &mut ScratchPool, fmt: PixelFormat, ) -> Result<(Vec<u8>, DecodeOutcome), JpegError>
Self::decode with caller-owned scratch.
Sourcepub fn decode_scaled_with_scratch(
&self,
pool: &mut ScratchPool,
fmt: PixelFormat,
scale: Downscale,
) -> Result<(Vec<u8>, DecodeOutcome), JpegError>
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.
Sourcepub fn decode_into_with_scratch(
&self,
pool: &mut ScratchPool,
out: &mut [u8],
stride: usize,
fmt: PixelFormat,
) -> Result<DecodeOutcome, JpegError>
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.
Sourcepub fn decode_scaled_into_with_scratch(
&self,
pool: &mut ScratchPool,
out: &mut [u8],
stride: usize,
fmt: PixelFormat,
scale: Downscale,
) -> Result<DecodeOutcome, JpegError>
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.
Sourcepub fn decode_rows<S>(&self, sink: &mut S) -> Result<DecodeOutcome, JpegError>
pub fn decode_rows<S>(&self, sink: &mut S) -> Result<DecodeOutcome, 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.
Sourcepub fn decode_rows_with_scratch<S>(
&self,
pool: &mut ScratchPool,
sink: &mut S,
) -> Result<DecodeOutcome, JpegError>
pub fn decode_rows_with_scratch<S>( &self, pool: &mut ScratchPool, sink: &mut S, ) -> Result<DecodeOutcome, JpegError>
Self::decode_rows with caller-owned scratch. See
Self::decode_into_with_scratch for the reuse contract.
Sourcepub fn decode_component_rows_with_scratch<W>(
&self,
pool: &mut ScratchPool,
writer: &mut W,
) -> Result<DecodeOutcome, JpegError>where
W: ComponentRowWriter,
pub fn decode_component_rows_with_scratch<W>(
&self,
pool: &mut ScratchPool,
writer: &mut W,
) -> Result<DecodeOutcome, JpegError>where
W: ComponentRowWriter,
Decode the full image into component rows.
Sourcepub fn decode_region_component_rows_with_scratch<W>(
&self,
pool: &mut ScratchPool,
writer: &mut W,
roi: Rect,
scale: Downscale,
) -> Result<DecodeOutcome, JpegError>where
W: ComponentRowWriter,
pub fn decode_region_component_rows_with_scratch<W>(
&self,
pool: &mut ScratchPool,
writer: &mut W,
roi: Rect,
scale: Downscale,
) -> Result<DecodeOutcome, JpegError>where
W: ComponentRowWriter,
Decode roi into component rows, optionally at a reduced scale.
Sourcepub fn decode_region_into(
&self,
out: &mut [u8],
stride: usize,
fmt: PixelFormat,
roi: Rect,
) -> Result<DecodeOutcome, JpegError>
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.
Sourcepub fn decode_region(
&self,
fmt: PixelFormat,
roi: Rect,
) -> Result<(Vec<u8>, DecodeOutcome), JpegError>
pub fn decode_region( &self, fmt: PixelFormat, roi: Rect, ) -> Result<(Vec<u8>, DecodeOutcome), JpegError>
Decode roi into a freshly allocated tightly-packed buffer.
Sourcepub fn decode_region_scaled(
&self,
fmt: PixelFormat,
roi: Rect,
scale: Downscale,
) -> Result<(Vec<u8>, DecodeOutcome), JpegError>
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.
Sourcepub fn decode_region_with_scratch(
&self,
pool: &mut ScratchPool,
fmt: PixelFormat,
roi: Rect,
) -> Result<(Vec<u8>, DecodeOutcome), JpegError>
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.
Sourcepub fn decode_region_scaled_with_scratch(
&self,
pool: &mut ScratchPool,
fmt: PixelFormat,
roi: Rect,
scale: Downscale,
) -> Result<(Vec<u8>, DecodeOutcome), JpegError>
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.
Sourcepub fn decode_region_into_with_scratch(
&self,
pool: &mut ScratchPool,
out: &mut [u8],
stride: usize,
fmt: PixelFormat,
roi: Rect,
) -> Result<DecodeOutcome, JpegError>
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.
Sourcepub fn decode_region_scaled_into(
&self,
out: &mut [u8],
stride: usize,
fmt: PixelFormat,
roi: Rect,
scale: Downscale,
) -> Result<DecodeOutcome, JpegError>
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.
Sourcepub 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>
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.
Sourcepub fn decode_rgba8_into_with_alpha(
&self,
out: &mut [u8],
stride: usize,
alpha: u8,
) -> Result<DecodeOutcome, JpegError>
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.
Sourcepub fn decode_rgba8_into_with_alpha_with_scratch(
&self,
pool: &mut ScratchPool,
out: &mut [u8],
stride: usize,
alpha: u8,
) -> Result<DecodeOutcome, JpegError>
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.
Sourcepub fn decode_region_rgba8_into_with_alpha(
&self,
out: &mut [u8],
stride: usize,
roi: Rect,
alpha: u8,
) -> Result<DecodeOutcome, JpegError>
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.
Sourcepub 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>
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<'_>
impl Decoder<'_>
Sourcepub fn decode_tile<S>(
bytes: &[u8],
ctx: &mut DecoderContext,
pool: &mut ScratchPool,
sink: &mut S,
) -> Result<DecodeOutcome, JpegError>
pub fn decode_tile<S>( bytes: &[u8], ctx: &mut DecoderContext, pool: &mut ScratchPool, sink: &mut S, ) -> Result<DecodeOutcome, 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 ImageCodec for Decoder<'_>
impl ImageCodec for Decoder<'_>
Source§impl<'a> ImageDecode<'a> for Decoder<'a>
impl<'a> ImageDecode<'a> for Decoder<'a>
Source§fn inspect(input: &'a [u8]) -> Result<Info, Self::Error>
fn inspect(input: &'a [u8]) -> Result<Info, Self::Error>
Source§fn parse(input: &'a [u8]) -> Result<Self::View, Self::Error>
fn parse(input: &'a [u8]) -> Result<Self::View, Self::Error>
Source§fn from_view(view: Self::View) -> Result<Self, Self::Error>
fn from_view(view: Self::View) -> Result<Self, Self::Error>
Source§fn decode_into(
&mut self,
out: &mut [u8],
stride: usize,
fmt: PixelFormat,
) -> Result<CoreDecodeOutcome<Self::Warning>, Self::Error>
fn decode_into( &mut self, out: &mut [u8], stride: usize, fmt: PixelFormat, ) -> Result<CoreDecodeOutcome<Self::Warning>, Self::Error>
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>
fn decode_into_with_scratch( &mut self, pool: &mut Self::Pool, out: &mut [u8], stride: usize, fmt: PixelFormat, ) -> Result<CoreDecodeOutcome<Self::Warning>, Self::Error>
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>
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>
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>
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>
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>
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>
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>
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>
Source§impl<'a> ImageDecodeRows<'a, u8> for Decoder<'a>
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>>
fn decode_rows<R: RowSink<u8>>( &mut self, sink: &mut R, ) -> Result<CoreDecodeOutcome<Self::Warning>, DecodeRowsError<Self::Error, R::Error>>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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