Garb converts byte-packed pixel layouts for image decoders, renderers, and GPU uploads. It can reorder channels, convert integer depth, compute weighted luma, and premultiply u8 alpha in contiguous or padded rows. It uses AVX2, NEON, or WASM SIMD128 when available, with a scalar fallback.
[dependencies]
garb = "0.2.9"use garb::bytes::{rgb_to_bgra, rgba_to_bgra_inplace};
let mut rgba = [255, 0, 128, 64];
rgba_to_bgra_inplace(&mut rgba)?;
assert_eq!(rgba, [128, 0, 255, 64]);
let mut bgra = [0; 4];
rgb_to_bgra(&[255, 0, 128], &mut bgra)?;
assert_eq!(bgra, [128, 0, 255, 255]);
# Ok::<(), garb::SizeError>(())For padded rows, call
rgb_to_bgra_strided(src, dst, width, height, src_stride, dst_stride).
Width is in pixels, height is in rows, and strides are in bytes. Each buffer
must reach the last active pixel. Garb leaves row padding intact and fills
new alpha channels with 255. These operations preserve the color space.
The integer byte API works with default-features = false in no_std builds.
Packed RGB565, RGBA4444, and RGBA1010102 use experimental. The rgb and
imgref features provide typed wrappers.
Version 0.2.9 deprecates f32 depth and alpha operations and the
deinterleave module ahead of their planned removal in 0.3.0. See the
changelog for migration paths.
Licensed under either the Apache License, Version 2.0 or the MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Developed with AI coding assistance. Review critical paths for your use case.