Skip to content

Commit c6fab57

Browse files
authored
Allow pre-allocated pixels vec (#154)
Fixes #99
1 parent bce0536 commit c6fab57

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/common.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,17 @@ impl Frame<'static> {
259259
/// # Panics:
260260
/// * If the length of pixels does not equal `width * height`.
261261
/// * If the length of palette > `256 * 3`.
262-
pub fn from_palette_pixels(width: u16, height: u16, pixels: &[u8], palette: &[u8], transparent: Option<u8>) -> Frame<'static> {
262+
pub fn from_palette_pixels(width: u16, height: u16, pixels: impl Into<Vec<u8>>, palette: impl Into<Vec<u8>>, transparent: Option<u8>) -> Frame<'static> {
263+
let pixels = pixels.into();
264+
let palette = palette.into();
263265
assert_eq!(width as usize * height as usize, pixels.len(), "Too many or too little pixels for the given width and height to create a GIF Frame");
264266
assert!(palette.len() <= 256*3, "Too many palette values to create a GIF Frame");
265267

266268
Frame {
267269
width,
268270
height,
269-
buffer: Cow::Owned(pixels.to_vec()),
270-
palette: Some(palette.to_vec()),
271+
buffer: Cow::Owned(pixels),
272+
palette: Some(palette),
271273
transparent,
272274
..Frame::default()
273275
}
@@ -277,7 +279,8 @@ impl Frame<'static> {
277279
///
278280
/// # Panics:
279281
/// * If the length of pixels does not equal `width * height`.
280-
pub fn from_indexed_pixels(width: u16, height: u16, pixels: &[u8], transparent: Option<u8>) -> Frame<'static> {
282+
pub fn from_indexed_pixels(width: u16, height: u16, pixels: impl Into<Vec<u8>>, transparent: Option<u8>) -> Frame<'static> {
283+
let pixels = pixels.into();
281284
assert_eq!(width as usize * height as usize, pixels.len(), "Too many or too little pixels for the given width and height to create a GIF Frame");
282285

283286
Frame {

0 commit comments

Comments
 (0)