@@ -280,12 +280,16 @@ where
280280 /// this plane's `width * height * bytes_per_pixel`
281281 #[ inline]
282282 pub fn copy_from_u8_slice ( & mut self , src : & [ u8 ] ) -> Result < ( ) , Error > {
283- self . copy_from_u8_slice_with_stride ( src, self . width ( ) )
283+ self . copy_from_u8_slice_with_stride (
284+ src,
285+ self . width ( )
286+ . saturating_mul ( NonZeroUsize :: new ( size_of :: < T > ( ) ) . expect ( "size can't be zero" ) ) ,
287+ )
284288 }
285289
286290 /// Copies the data from `src` into this plane's visible pixels.
287291 /// This version accepts inputs where the row stride is longer than the visible data width.
288- /// The `input_stride` must be in pixels .
292+ /// The `input_stride` must be in bytes .
289293 ///
290294 /// # Errors
291295 /// - Returns `Error::Datalength` if the length of `src` does not match
@@ -310,7 +314,7 @@ where
310314 } ) ;
311315 }
312316
313- let byte_count = input_stride. get ( ) * self . height ( ) . get ( ) * byte_width ;
317+ let byte_count = input_stride. get ( ) * self . height ( ) . get ( ) ;
314318 if byte_count != src. len ( ) {
315319 return Err ( Error :: DataLength {
316320 expected : byte_count,
@@ -334,7 +338,7 @@ where
334338 // u16 pixels - need to convert from little-endian bytes
335339 let row_byte_width = width * byte_width;
336340 for ( row_idx, dest_row) in self . rows_mut ( ) . enumerate ( ) {
337- let src_offset = row_idx * stride * byte_width ;
341+ let src_offset = row_idx * stride;
338342 let src_row = & src[ src_offset..src_offset + row_byte_width] ;
339343
340344 for ( dest_pixel, src_chunk) in dest_row. iter_mut ( ) . zip ( src_row. chunks_exact ( 2 ) ) {
0 commit comments