1个不稳定版本
0.1.0 | 2024年5月14日 |
---|
#91 in 视频
220KB
5.5K SLoC
EZK Image
ezk-image是一个crate,用于在常见的像素格式和颜色空间之间进行转换。
它使用SIMD和多线程来加速转换(如果可用),但必须显式调用 convert_multi_thread
来启用多线程。
任何格式都可以转换为任何其他格式。
支持的像素格式
支持每个组件最多16位比特深。
- I420
- I422
- I444
- NV12
- RGBA, BGRA
- RGB, BGR
支持的颜色主色(颜色色域)
- SMTPE ST 240
- BT.709(SDR)
- BT.2020(HDR)
支持的颜色转移函数(样本的光电传输特性)
- 线性
- 伽玛值为2.2和2.8
- SRGB
- SDR(BT.601、BT.709和BT.2020)
- BT.2100感知量化(PQ)
- BT.2100混合对数伽玛(HLG)
支持的颜色空间
- RGB
- YUV BT.601
- YUV BT.709
- YUV BT.2020
- ICtCp带有感知量化(PQ)
- ICtCp带有混合对数伽玛(HLG)
示例
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();
依赖项
~0–660KB
~14K SLoC