diff options
Diffstat (limited to 'font/src/darwin/byte_order.rs')
-rw-r--r-- | font/src/darwin/byte_order.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/font/src/darwin/byte_order.rs b/font/src/darwin/byte_order.rs index 382caa31..1574cf19 100644 --- a/font/src/darwin/byte_order.rs +++ b/font/src/darwin/byte_order.rs @@ -24,6 +24,27 @@ pub const kCGBitmapByteOrder32Host: u32 = kCGBitmapByteOrder32Little; pub const kCGBitmapByteOrder32Host: u32 = kCGBitmapByteOrder32Big; #[cfg(target_endian = "little")] +pub fn extract_rgba(bytes: &[u8]) -> Vec<u8> { + let pixels = bytes.len() / 4; + let mut rgb = Vec::with_capacity(pixels * 4); + + for i in 0..pixels { + let offset = i * 4; + rgb.push(bytes[offset + 2]); + rgb.push(bytes[offset + 1]); + rgb.push(bytes[offset]); + rgb.push(bytes[offset + 3]); + } + + rgb +} + +#[cfg(target_endian = "big")] +pub fn extract_rgba(bytes: Vec<u8>) -> Vec<u8> { + bytes +} + +#[cfg(target_endian = "little")] pub fn extract_rgb(bytes: &[u8]) -> Vec<u8> { let pixels = bytes.len() / 4; let mut rgb = Vec::with_capacity(pixels * 3); |