mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 06:10:06 -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:
@@ -110,6 +110,15 @@ impl ColorImage {
|
|||||||
Self { size, pixels }
|
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]`
|
/// A view of the underlying data as `&[u8]`
|
||||||
#[cfg(feature = "bytemuck")]
|
#[cfg(feature = "bytemuck")]
|
||||||
pub fn as_raw(&self) -> &[u8] {
|
pub fn as_raw(&self) -> &[u8] {
|
||||||
|
|||||||
Reference in New Issue
Block a user