#rgb #yuv #convert-images #convert #format-conversion #color

ezk-image

Convert pixel and color formats such and RGB, YUV (YCbCr), ICtCp

10 releases

0.2.4 Nov 27, 2024
0.2.3 Nov 18, 2024
0.1.4 Sep 27, 2024
0.1.0 May 14, 2024

#158 in Images

Download history 267/week @ 2024-09-20 409/week @ 2024-09-27 495/week @ 2024-10-04 310/week @ 2024-10-11 678/week @ 2024-10-18 418/week @ 2024-10-25 570/week @ 2024-11-01 304/week @ 2024-11-08 990/week @ 2024-11-15 697/week @ 2024-11-22 400/week @ 2024-11-29 161/week @ 2024-12-06

2,292 downloads per month
Used in opentalk-compositor

MIT license

230KB
6K SLoC

EZK Image

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.


Supported Pixel formats

Bit depth of up to 16 bit per component is supported.

  • I420
  • I422
  • I444
  • I010, I012
  • I210, I212
  • I410, I412
  • NV12
  • YUYV
  • RGBA, BGRA
  • RGB, BGR

Supported Color Primaries (color gamut)

  • SMTPE ST 240
  • BT.709 (SDR)
  • BT.2020 (HDR)

Supported Color Transfer Functions (opto-electronic transfer characteristics of samples)

  • Linear
  • Gamma of 2.2 and 2.8
  • SRGB
  • SDR (BT.601, BT.709 and BT.2020)
  • BT.2100 perceptual quantization (PQ)
  • BT.2100 hybrid log-gamma (HLG)

Supported Color Spaces

  • RGB
  • YUV BT.601
  • YUV BT.709
  • YUV BT.2020
  • ICtCp with perceptual quantization (PQ)
  • ICtCp with hybrid log-gamma (HLG)

Example

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)];

// Create the image we're converting from
let source = Image::from_buffer(
    PixelFormat::RGB,
    &rgb_image[..], // RGB only has one plane
    None, // No need to define strides if there's no padding between rows
    width,
    height,
    ColorInfo::RGB(RgbColorInfo {
        transfer: ColorTransfer::Linear,
        primaries: ColorPrimaries::BT709,
    }),
).unwrap();

// Create the image buffer we're converting to
let mut destination = Image::blank(
    PixelFormat::NV12, // We're converting to NV12
    width,
    height,
    ColorInfo::YUV(YuvColorInfo {
        space: ColorSpace::BT709,
        transfer: ColorTransfer::Linear,
        primaries: ColorPrimaries::BT709,
        full_range: false,
    }),
);

// Now convert the image data
convert_multi_thread(
    &source,
    &mut destination,
).unwrap();

Dependencies

~0.3–1.3MB
~28K SLoC