diff --git a/crates/epaint/src/image.rs b/crates/epaint/src/image.rs index fa3f1e5e0c0..454969d75cb 100644 --- a/crates/epaint/src/image.rs +++ b/crates/epaint/src/image.rs @@ -120,6 +120,16 @@ impl ColorImage { Self { size, pixels } } + /// Alternative method to `from_gray`. + /// Create a [`ColorImage`] from iterator over flat opaque gray data. + /// + /// Panics if `size[0] * size[1] != gray_iter.len()`. + pub fn from_gray_iter(size: [usize; 2], gray_iter: impl Iterator) -> Self { + let pixels: Vec<_> = gray_iter.map(Color32::from_gray).collect(); + assert_eq!(size[0] * size[1], pixels.len()); + Self { size, pixels } + } + /// A view of the underlying data as `&[u8]` #[cfg(feature = "bytemuck")] pub fn as_raw(&self) -> &[u8] {