Crates.io | ezk-image |
lib.rs | ezk-image |
version | 0.1.4 |
source | src |
created_at | 2024-05-14 19:21:51.450569 |
updated_at | 2024-09-27 14:44:57.919645 |
description | Convert pixel and color formats such and RGB, YUV (YCbCr), ICtCp |
homepage | |
repository | https://github.com/kbalt/ezk-image |
max_upload_size | |
id | 1239993 |
size | 252,103 |
ezk-image is a crate to perform conversion between common pixel formats and color spaces.
It uses SIMD and multi threading to accelerate the conversion when available, though multi-threading must
be explicitly called with [convert_multi_thread
].
Any format can be converted to any other format.
Bit depth of up to 16 bit per component is supported.
use ezk_image::*;
let (width, height) = (1920, 1080);
// Our source image, an RGB buffer
let rgb_image = vec![0u8; PixelFormat::RGB.buffer_size(width, height)];
// Our destination image, NV12 is a format that stores the image's luminosity and colors in the YUV space
let mut nv12_image = vec![0u8; PixelFormat::NV12.buffer_size(width, height)];
// Create the image we're converting from
let source = Image::new(
PixelFormat::RGB,
PixelFormatPlanes::RGB(&rgb_image[..]), // RGB only has one plane
width,
height,
ColorInfo::RGB(RgbColorInfo {
transfer: ColorTransfer::Linear,
primaries: ColorPrimaries::BT709,
}),
8, // there's 8 bits per component (R, G or B)
).unwrap();
// Create the image buffer we're converting to
let destination = Image::new(
PixelFormat::NV12, // We're converting to NV12
PixelFormatPlanes::infer_nv12(&mut nv12_image[..], width, height), // NV12 has 2 planes, `PixelFormatPlanes` has convenience functions to calculate them from a single buffer
width,
height,
ColorInfo::YUV(YuvColorInfo {
space: ColorSpace::BT709,
transfer: ColorTransfer::Linear,
primaries: ColorPrimaries::BT709,
full_range: false,
}),
8, // there's 8 bits per component (Y, U or V)
).unwrap();
// Now convert the image data
convert_multi_thread(
source,
destination,
).unwrap();