Skip to main content

JxlEncoder

Struct JxlEncoder 

Source
pub struct JxlEncoder<'prl, 'mm> {
    pub has_alpha: bool,
    pub lossless: Option<bool>,
    pub speed: EncoderSpeed,
    pub quality: f32,
    pub use_container: bool,
    pub uses_original_profile: bool,
    pub decoding_speed: i64,
    pub init_buffer_size: usize,
    pub color_encoding: Option<ColorEncoding>,
    pub target_intensity: Option<f32>,
    pub parallel_runner: Option<&'prl dyn ParallelRunner>,
    /* private fields */
}
Expand description

JPEG XL Encoder

Fields§

§has_alpha: bool

Set alpha channel

Default: false

§lossless: Option<bool>

Set lossless

Default: false

§speed: EncoderSpeed

Set speed

Default: Squirrel (7).

§quality: f32

Set quality for lossy compression: target max butteraugli distance, lower = higher quality

Range: 0 .. 15.
0.0 = mathematically lossless (however, use lossless to use true lossless).
1.0 = visually lossless.
Recommended range: 0.5 .. 3.0.
Default value: 1.0.
If lossless is set to true, this value is unused and implied to be 0.

§use_container: bool

Configure the encoder to use the JPEG XL container format

Using the JPEG XL container format allows one to store metadata such as JPEG reconstruction; but it adds a few bytes to the encoded file for container headers even if there is no extra metadata.

§uses_original_profile: bool

Configure the encoder to use the original color profile

If the input image has a color profile, it will be used for the encoded image. Otherwise, an internal fixed color profile is chosen (which should be smaller).

When lossless re-compressing JPEG image, you must set this to true.

Default: false

§decoding_speed: i64

Set the decoding speed tier

Minimum is 0 (highest quality), and maximum is 4 (lowest quality). Default is 0.

§init_buffer_size: usize

Set initial output buffer size in bytes. Anything less than 32 bytes will be rounded up to 32 bytes.

Default: 512 KiB

§color_encoding: Option<ColorEncoding>

Set color encoding

Default: sRGB for int, Linear sRGB for float

§target_intensity: Option<f32>

Set HDR target intensity. Specify the target intensity in nits for 1.0 value

§parallel_runner: Option<&'prl dyn ParallelRunner>

Set parallel runner

Default: None, indicating single thread execution

Implementations§

Source§

impl<'prl, 'mm> JxlEncoder<'prl, 'mm>

Source

pub fn builder() -> JxlEncoderBuilder<'prl, 'mm>

Build a JxlEncoder

§Errors

Return EncodeError::CannotCreateEncoder if it fails to create the encoder

Source§

impl<'prl, 'mm> JxlEncoder<'prl, 'mm>

Source

pub fn set_frame_option( &mut self, option: JxlEncoderFrameSettingId, value: i64, ) -> Result<(), EncodeError>

Set a specific encoder frame setting

§Errors

Return EncodeError if it fails to set frame option

Source

pub fn multiple<'enc, U: PixelType>( &'enc mut self, width: u32, height: u32, ) -> Result<MultiFrames<'enc, 'prl, 'mm, U>, EncodeError>

Return a wrapper type for adding multiple frames to the encoder

§Errors

Return EncodeError if it fails to set up the encoder

Source

pub fn add_metadata( &mut self, metadata: &Metadata<'_>, compress: bool, ) -> Result<(), EncodeError>

Add a metadata box to the encoder

§Errors

Return EncodeError if it fails to add metadata

Source

pub fn encode_jpeg( &mut self, data: &[u8], ) -> Result<EncoderResult<u8>, EncodeError>

Encode a JPEG XL image from existing raw JPEG data

Note: Only support output pixel type of u8. Ignore alpha channel settings

§Errors

Return EncodeError if the internal encoder fails to encode

Source

pub fn encode<T: PixelType, U: PixelType>( &mut self, data: &[T], width: u32, height: u32, ) -> Result<EncoderResult<U>, EncodeError>

Encode a JPEG XL image from pixels

Note: Use RGB(3) channels, native endianness and no alignment. Ignore alpha channel settings

§Errors

Return EncodeError if the internal encoder fails to encode

Source

pub fn encode_frame<T: PixelType, U: PixelType>( &mut self, frame: &EncoderFrame<'_, T>, width: u32, height: u32, ) -> Result<EncoderResult<U>, EncodeError>

Encode a JPEG XL image from a frame. See EncoderFrame for custom options of the original pixels.

§Errors

Return EncodeError if the internal encoder fails to encode

Trait Implementations§

Source§

impl Drop for JxlEncoder<'_, '_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for JxlEncoder<'_, '_>

Auto Trait Implementations§

§

impl<'prl, 'mm> !RefUnwindSafe for JxlEncoder<'prl, 'mm>

§

impl<'prl, 'mm> !Sync for JxlEncoder<'prl, 'mm>

§

impl<'prl, 'mm> !UnwindSafe for JxlEncoder<'prl, 'mm>

§

impl<'prl, 'mm> Freeze for JxlEncoder<'prl, 'mm>

§

impl<'prl, 'mm> Unpin for JxlEncoder<'prl, 'mm>

§

impl<'prl, 'mm> UnsafeUnpin for JxlEncoder<'prl, 'mm>

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, 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.