Browse Source

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>
pull/3024/head
thomaseliot 1 year ago
committed by GitHub
parent
commit
e82ec74c5c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      crates/epaint/src/image.rs

9
crates/epaint/src/image.rs

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

Loading…
Cancel
Save