pub struct Decoder { /* private fields */ }Expand description
JPEG decoder.
Implementations§
Source§impl Decoder
impl Decoder
Sourcepub fn from_config(config: DecoderConfig) -> Self
pub fn from_config(config: DecoderConfig) -> Self
Creates a decoder from configuration.
Sourcepub fn output_format(self, format: PixelFormat) -> Self
pub fn output_format(self, format: PixelFormat) -> Self
Sets the output pixel format.
Sourcepub fn fancy_upsampling(self, enable: bool) -> Self
pub fn fancy_upsampling(self, enable: bool) -> Self
Enables fancy upsampling.
Sourcepub fn block_smoothing(self, enable: bool) -> Self
pub fn block_smoothing(self, enable: bool) -> Self
Enables block smoothing.
Sourcepub fn apply_icc(self, enable: bool) -> Self
pub fn apply_icc(self, enable: bool) -> Self
Enables ICC profile application.
When enabled, embedded ICC profiles will be applied to convert the image to sRGB. This is required for correct display of XYB-encoded images.
Note: Requires cms-lcms2 or cms-moxcms feature to be enabled.
Without a CMS feature, this setting has no effect.
Sourcepub fn max_pixels(self, pixels: u64) -> Self
pub fn max_pixels(self, pixels: u64) -> Self
Sets the maximum number of pixels allowed (for DoS protection).
Default is 100 megapixels. Set to 0 for unlimited.
Sourcepub fn max_memory(self, bytes: usize) -> Self
pub fn max_memory(self, bytes: usize) -> Self
Sets the maximum memory allowed for allocations during decoding.
Default is 512 MB. Set to usize::MAX for unlimited.
This prevents memory exhaustion attacks from malicious images.
Sourcepub fn decode(&self, data: &[u8]) -> Result<DecodedImage>
pub fn decode(&self, data: &[u8]) -> Result<DecodedImage>
Decodes a JPEG image.
Sourcepub fn decode_f32(&self, data: &[u8]) -> Result<DecodedImageF32>
pub fn decode_f32(&self, data: &[u8]) -> Result<DecodedImageF32>
Decodes a JPEG image to 32-bit floating point pixels.
This preserves the full 12-bit internal precision of jpegli’s decoder without quantization to 8-bit. Values are normalized to range 0.0-1.0.
§Example
use jpegli::decode::Decoder;
let decoder = Decoder::new();
let image = decoder.decode_f32(&jpeg_data)?;
// image.data contains f32 values in range 0.0-1.0Note: ICC profile application is not supported for f32 output. If you need ICC profile transformation, decode to u8 first.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Decoder
impl RefUnwindSafe for Decoder
impl Send for Decoder
impl Sync for Decoder
impl Unpin for Decoder
impl UnwindSafe for Decoder
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