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>
impl<'prl, 'mm> JxlEncoder<'prl, 'mm>
sourcepub fn set_frame_option(
&mut self,
option: FrameSetting,
value: i64
) -> Result<(), EncodeError>
pub fn set_frame_option( &mut self, option: FrameSetting, value: i64 ) -> Result<(), EncodeError>
sourcepub fn multiple<'enc, U: PixelType>(
&'enc mut self,
width: u32,
height: u32
) -> Result<MultiFrames<'enc, 'prl, 'mm, U>, EncodeError>
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
sourcepub fn add_metadata(
&mut self,
metadata: &Metadata<'_>,
compress: bool
) -> Result<(), EncodeError>
pub fn add_metadata( &mut self, metadata: &Metadata<'_>, compress: bool ) -> Result<(), EncodeError>
sourcepub fn encode_jpeg(
&mut self,
data: &[u8]
) -> Result<EncoderResult<u8>, EncodeError>
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
sourcepub fn encode<T: PixelType, U: PixelType>(
&mut self,
data: &[T],
width: u32,
height: u32
) -> Result<EncoderResult<U>, EncodeError>
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
sourcepub fn encode_frame<T: PixelType, U: PixelType>(
&mut self,
frame: &EncoderFrame<'_, T>,
width: u32,
height: u32
) -> Result<EncoderResult<U>, EncodeError>
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