2026-05-23 19:24:07 +01:00

26 lines
780 B
Rust

/// Copies RGBA8888 pixels in canonical RGBA raw order into the `pixels` RGBA8 frame.
pub fn draw_rgba8888_to_rgba8(src: &[u32], dst_rgba: &mut [u8]) {
for (i, &px) in src.iter().enumerate() {
let o = i * 4;
dst_rgba[o] = ((px >> 24) & 0xFF) as u8;
dst_rgba[o + 1] = ((px >> 16) & 0xFF) as u8;
dst_rgba[o + 2] = ((px >> 8) & 0xFF) as u8;
dst_rgba[o + 3] = (px & 0xFF) as u8;
}
}
#[cfg(test)]
mod tests {
use super::draw_rgba8888_to_rgba8;
#[test]
fn draw_rgba8888_to_rgba8_preserves_channel_order_and_alpha() {
let src = [0x12345678, 0xABCDEF01];
let mut dst = [0; 8];
draw_rgba8888_to_rgba8(&src, &mut dst);
assert_eq!(dst, [0x12, 0x34, 0x56, 0x78, 0xAB, 0xCD, 0xEF, 0x01]);
}
}