pub struct ImageWorkspace { /* private fields */ }Expand description
Reusable conversion storage for still-image encoding.
Keeps one PNG row or JPEG final row, WebP’s complete converted image, and downscale sums
at each sample depth. Capacity grows to the largest encode and remains
retained until release or drop. Each concurrent worker
needs its own workspace. Codec state and encoded output are not retained;
lossy WebP still allocates its complete encoded result in the backend.
Eligible RGBA input is borrowed without populating conversion scratch.
Remembers the last successful output size for matching format settings,
retaining no output memory; release resets that hint.
Implementations§
Source§impl ImageWorkspace
impl ImageWorkspace
Sourcepub fn retained_bytes(&self) -> usize
pub fn retained_bytes(&self) -> usize
Bytes retained in wrapper scratch, excluding source, codec and output.
Sourcepub fn encode<F: VideoSource + ?Sized>(
&mut self,
frame: &F,
options: &ImageOptions,
) -> Result<Vec<u8>>
pub fn encode<F: VideoSource + ?Sized>( &mut self, frame: &F, options: &ImageOptions, ) -> Result<Vec<u8>>
Encode a frame into a newly allocated result, reusing conversion scratch.
Uses the same options, validation and errors as frame.encode_image.
All frame types implementing crate::VideoSource are accepted.
Sourcepub fn encode_to<F: VideoSource + ?Sized, W: Write>(
&mut self,
frame: &F,
options: &ImageOptions,
out: W,
) -> Result<()>
pub fn encode_to<F: VideoSource + ?Sized, W: Write>( &mut self, frame: &F, options: &ImageOptions, out: W, ) -> Result<()>
Encode into a writer, reusing conversion scratch. A cleared Vec<u8>
also reuses output capacity. Both WebP formats buffer their complete
encoded result before writing; PNG and JPEG write incrementally.
Success means every byte was written and the writer was flushed.
Validation happens before writing; a codec/writer failure may leave
partial output.
use grafton_ndi::{PixelFormat, VideoFrame, image_encoding::{ImageWorkspace, ImageOptions, ImageFormat}};
let frame = VideoFrame::builder().resolution(2, 2)
.pixel_format(PixelFormat::Bgra).data(vec![255; 16]).build()?;
let mut workspace = ImageWorkspace::new();
let mut output = Vec::new();
for _ in 0..3 {
output.clear();
workspace.encode_to(&frame, &ImageOptions::new(ImageFormat::WebpLossless), &mut output)?;
}
workspace.release();Sourcepub fn encode_data_url<F: VideoSource + ?Sized>(
&mut self,
frame: &F,
options: &ImageOptions,
) -> Result<String>
pub fn encode_data_url<F: VideoSource + ?Sized>( &mut self, frame: &F, options: &ImageOptions, ) -> Result<String>
Encode a frame as a base64 data URL, reusing conversion scratch.
Validation, format and color handling match Self::encode.