Struct Frame
pub struct Frame<'a> { pub delay: u16, pub dispose: DisposalMethod, pub transparent: Option<u8>, pub needs_user_input: bool, pub top: u16, pub left: u16, pub width: u16, pub height: u16, pub interlaced: bool, pub palette: Option<Vec<u8>>, pub buffer: Cow<'a, [u8]> }
A GIF frame
Fields
delay: u16Frame delay in units of 10 ms.
dispose: DisposalMethodDisposal method.
transparent: Option<u8>Transparent index (if available).
needs_user_input: boolTrue if the frame needs user input to be displayed.
top: u16Offset from the top border of the canvas.
left: u16Offset from the left border of the canvas.
width: u16Width of the frame.
height: u16Height of the frame.
interlaced: boolTrue if the image is interlaced.
palette: Option<Vec<u8>>Frame local color palette if available.
buffer: Cow<'a, [u8]>Buffer containing the image data. Only indices unless configured differently.
Implementations
impl Frame<'_>
fn make_lzw_pre_encoded(&mut self)Replace frame's buffer with a LZW-compressed one for use with
Encoder::write_lzw_pre_encoded_frame.Frames can be compressed in any order, separately from the
Encoder, which can be used to compress frames in parallel.
impl Frame<'static>
fn from_rgba(width: u16, height: u16, pixels: &mut [u8]) -> SelfCreates a frame from pixels in RGBA format.
This is a lossy method. The
gifformat does not support arbitrary alpha but only a 1-bit transparency mask per pixel. Any non-zero alpha value will be interpreted as a fully opaque pixel. Additionally, only 256 colors can appear in a single frame. The palette will be reduced by the NeuQuant algorithm if necessary. Different frames have independent palettes.Note: This method is not optimized for speed.
Panics:
- If the length of pixels does not equal
width * height * 4.
- If the length of pixels does not equal
fn from_rgba_speed(width: u16, height: u16, pixels: &mut [u8], speed: i32) -> SelfCreates a frame from pixels in RGBA format.
speedis a value in the range [1, 30]. The higher the value the faster it runs at the cost of image quality. Aspeedof 10 is a good compromise between speed and quality.This is a lossy method. The
gifformat does not support arbitrary alpha but only a 1-bit transparency mask per pixel. Any non-zero alpha value will be interpreted as a fully opaque pixel. Additionally, only 256 colors can appear in a single frame. The palette will be reduced by the NeuQuant algorithm if necessary. Different frames have independent palettes.Panics:
- If the length of pixels does not equal
width * height * 4. - If
speed < 1orspeed > 30
- If the length of pixels does not equal
fn from_grayscale_with_alpha(width: u16, height: u16, pixels: &[u8]) -> SelfCreates a frame from pixels in LumaAlpha format (grayscale pixels with transparency).
This is a lossy method. The
gifformat does not support arbitrary alpha but only a 1-bit transparency mask per pixel. Any non-zero alpha value will be interpreted as a fully opaque pixel. The least used color will be used to indicate alpha and replace with the closest other color in the image. Different frames have independent palettes.Panics:
- If the length of pixels does not equal
width * height * 2.
- If the length of pixels does not equal
fn from_palette_pixels(width: u16, height: u16, pixels: impl Into<Vec<u8>>, palette: impl Into<Vec<u8>>, transparent: Option<u8>) -> SelfCreates a frame from a palette and indexed pixels.
Panics:
- If the length of pixels does not equal
width * height. - If the length of palette >
256 * 3.
- If the length of pixels does not equal
fn from_indexed_pixels(width: u16, height: u16, pixels: impl Into<Vec<u8>>, transparent: Option<u8>) -> SelfCreates a frame from indexed pixels in the global palette.
Panics:
- If the length of pixels does not equal
width * height.
- If the length of pixels does not equal
fn from_rgb(width: u16, height: u16, pixels: &[u8]) -> SelfCreates a frame from pixels in RGB format.
This is a lossy method. In the
gifformat only 256 colors can appear in a single frame. The palette will be reduced by the NeuQuant algorithm if necessary. Different frames have independent palettes.Note: This method is not optimized for speed.
Panics:
- If the length of pixels does not equal
width * height * 3.
- If the length of pixels does not equal
fn from_rgb_speed(width: u16, height: u16, pixels: &[u8], speed: i32) -> SelfCreates a frame from pixels in RGB format.
speedis a value in the range [1, 30].This is a lossy method. In the
gifformat only 256 colors can appear in a single frame. The palette will be reduced by the NeuQuant algorithm if necessary. Different frames have independent palettes.The higher the value the faster it runs at the cost of image quality. A
speedof 10 is a good compromise between speed and quality.Panics:
- If the length of pixels does not equal
width * height * 3. - If
speed < 1orspeed > 30
- If the length of pixels does not equal
Trait Implementations
impl Default for Frame<'_>
fn default() -> Self
impl<'a> Clone for Frame<'a>
fn clone(&self) -> Self
impl<'a> Debug for Frame<'a>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Auto Trait Implementations
impl<'a> Freeze for Frame<'a>
impl<'a> RefUnwindSafe for Frame<'a>
impl<'a> Send for Frame<'a>
impl<'a> Sync for Frame<'a>
impl<'a> Unpin for Frame<'a>
impl<'a> UnsafeUnpin for Frame<'a>
impl<'a> UnwindSafe for Frame<'a>
Blanket Implementations
impl<T> Any for Frame<'a>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Frame<'a>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Frame<'a>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Frame<'a>
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Frame<'a>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Frame<'a>
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for Frame<'a>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Frame<'a>
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Frame<'a>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>