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>
This commit is contained in:
parent
3d36a20376
commit
5e44c13b48
|
|
@ -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…
Reference in New Issue