Browse Source

Allows creating a `ColorImage` struct without an alpha channel (#2167)

* Added functionality to image.rs that allows for creating an image from rgb instead of just rgba

* remove "unmultiplied"

* remove "unmultiplied"

* rgba -> rgb

Co-authored-by: Mingun <Alexander_Sergey@mail.ru>

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Co-authored-by: Mingun <Alexander_Sergey@mail.ru>
pull/2232/head
Paul Hazen 2 years ago
committed by GitHub
parent
commit
5e44c13b48
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      crates/epaint/src/image.rs

15
crates/epaint/src/image.rs

@ -101,6 +101,21 @@ impl ColorImage {
Self { size, pixels }
}
/// Create a [`ColorImage`] from flat RGB data.
///
/// This is what you want to use after having loaded an image file (and if
/// you are ignoring the alpha channel - considering it to always be 0xff)
///
/// Panics if `size[0] * size[1] * 3 != rgb.len()`.
pub fn from_rgb(size: [usize; 2], rgb: &[u8]) -> Self {
assert_eq!(size[0] * size[1] * 3, rgb.len());
let pixels = rgb
.chunks_exact(3)
.map(|p| Color32::from_rgb(p[0], p[1], p[2]))
.collect();
Self { size, pixels }
}
/// An example color image, useful for tests.
pub fn example() -> Self {
let width = 128;

Loading…
Cancel
Save