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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

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] {