Struct zune_jpegxl::JxlSimpleEncoder
source · pub struct JxlSimpleEncoder<'a> { /* private fields */ }
Expand description
A simple jxl encoder
Encoding 16 bit data
- To encode a 16-bit image, each element needs to be re-interpreted as 2
u8
’s in native endian the library will do the appropriate clamping
Multithreading support
Via the thread
feature, the library can use multiple threads to speed up compression, one can
configure how many threads to open or whether the library should use threads at compile time by
enabling or disabling the thread
feature and at runtime via EncodeOptions
Example option two threads
use zune_core::bit_depth::BitDepth;
use zune_core::colorspace::ColorSpace;
use zune_core::options::EncoderOptions;
// set threads to be 2 for encoding
let options = EncoderOptions::new(100,100,ColorSpace::RGB,BitDepth::Eight).set_num_threads(2);
Setting set_num_threads
to 1
forces single threaded execution
Example
- Encode grayscale image
use zune_core::colorspace::ColorSpace;
use zune_core::options::EncoderOptions;
use zune_jpegxl::JxlSimpleEncoder;
use zune_jpegxl::JxlEncodeErrors;
fn main()->Result<(),JxlEncodeErrors>{
// set up options for encoder
let options = EncoderOptions::default()
.set_height(10)
.set_width(10)
.set_colorspace(ColorSpace::Luma);
let image:[u8;100] = std::array::from_fn(|x| x as u8);
let encoder = JxlSimpleEncoder::new(&image,options);
// encode the image
encoder.encode()?;
Ok(())
}
Implementations§
source§impl<'a> JxlSimpleEncoder<'a>
impl<'a> JxlSimpleEncoder<'a>
sourcepub fn new(data: &'a [u8], options: EncoderOptions) -> JxlSimpleEncoder<'a>
pub fn new(data: &'a [u8], options: EncoderOptions) -> JxlSimpleEncoder<'a>
Create a new jpeg xl encoder
Arguments
- data: Raw pixel data
- options: Encoder options for the raw pixels, this include the width, height colorspace, depth etc
sourcepub fn encode_into(&mut self, buf: &mut [u8]) -> Result<usize, JxlEncodeErrors>
pub fn encode_into(&mut self, buf: &mut [u8]) -> Result<usize, JxlEncodeErrors>
Encode a jxl image into a user provided buffer
Arguments
-
buf: The buffer to write bytes into It is difficult to estimate the size of output buffer as many factors influence the size of the final image. A good metric is that the buffer size can be equal to the raw pixel size.
If the buffer is not big enough the library will bail and return an error
Returns
- Ok(size) Number of bytes written into
buf
for the encoded image - Err() An error in case it occurred during encoding
Auto Trait Implementations§
impl<'a> RefUnwindSafe for JxlSimpleEncoder<'a>
impl<'a> Send for JxlSimpleEncoder<'a>
impl<'a> Sync for JxlSimpleEncoder<'a>
impl<'a> Unpin for JxlSimpleEncoder<'a>
impl<'a> UnwindSafe for JxlSimpleEncoder<'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
Mutably borrows from an owned value. Read more