runtime: add ARGB8 pixel format

This commit is contained in:
chyyran 2024-03-07 01:36:04 -05:00 committed by Ronny Chan
parent 9c895caa51
commit 5feac91af2

View file

@ -26,6 +26,11 @@ pub struct RGBA8;
/// Every BGR with alpha pixel is represented with 32 bits.
pub struct BGRA8;
/// A8R8G8B8 pixel format.
///
/// Every BGR with alpha pixel is represented with 32 bits.
pub struct ARGB8;
/// Represents an image pixel format to convert images into.
pub trait PixelFormat {
#[doc(hidden)]
@ -45,6 +50,16 @@ impl PixelFormat for BGRA8 {
}
}
impl PixelFormat for ARGB8 {
fn convert(pixels: &mut Vec<u8>) {
assert!(pixels.len() % 4 == 0);
for [r, _g, b, a] in ArrayChunksMut::new(pixels) {
std::mem::swap(r, a); // abgr
std::mem::swap(b, r); // argb
}
}
}
/// The direction of UV coordinates to load the image for.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum UVDirection {