1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-27 07:03:14 -04:00

epaint: Add ColorImage::from_gray (#3166)

* epaint: Add from_gray_unmultiplied function

* Rename to just `from_gray`

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
thomaseliot
2023-08-09 07:46:45 -07:00
committed by GitHub
parent 35027d3ebe
commit e82ec74c5c

View File

@@ -110,6 +110,15 @@ impl ColorImage {
Self { size, pixels }
}
/// Create a [`ColorImage`] from flat opaque gray data.
///
/// Panics if `size[0] * size[1] != gray.len()`.
pub fn from_gray(size: [usize; 2], gray: &[u8]) -> Self {
assert_eq!(size[0] * size[1], gray.len());
let pixels = gray.iter().map(|p| Color32::from_gray(*p)).collect();
Self { size, pixels }
}
/// A view of the underlying data as `&[u8]`
#[cfg(feature = "bytemuck")]
pub fn as_raw(&self) -> &[u8] {