Struct jpegxl_rs::encode::JxlEncoder

source ·
pub struct JxlEncoder<'prl, 'mm> {
    pub has_alpha: bool,
    pub lossless: 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: ColorEncoding,
    pub parallel_runner: Option<&'prl dyn JxlParallelRunner>,
    /* private fields */
}
Expand description

JPEG XL Encoder

Fields§

§has_alpha: bool

Set alpha channel

Default: false

§lossless: 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 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 recompressing 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: ColorEncoding

Set color encoding

Default: SRGB

§parallel_runner: Option<&'prl dyn JxlParallelRunner>

Set parallel runner

Default: None, indicating single thread execution

Implementations§

source§

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

source

pub fn set_frame_option( &mut self, option: FrameSetting, 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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<'prl, 'mm> !UnwindSafe 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>,

§

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

§

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.