From 5feac91af2623e03cad5824c2c9b56ecb36eb1a5 Mon Sep 17 00:00:00 2001 From: chyyran Date: Thu, 7 Mar 2024 01:36:04 -0500 Subject: [PATCH] runtime: add ARGB8 pixel format --- librashader-runtime/src/image.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/librashader-runtime/src/image.rs b/librashader-runtime/src/image.rs index df2e8fd..2621d91 100644 --- a/librashader-runtime/src/image.rs +++ b/librashader-runtime/src/image.rs @@ -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) { + 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 {