18 releases (breaking)

0.13.4 Oct 24, 2024
0.13.3 Sep 1, 2023
0.13.2 Jun 1, 2022
0.13.1 Jun 4, 2020
0.6.1 Jul 28, 2019

#81 in Images

Download history 28406/week @ 2024-08-23 20158/week @ 2024-08-30 25295/week @ 2024-09-06 30345/week @ 2024-09-13 29365/week @ 2024-09-20 32428/week @ 2024-09-27 32814/week @ 2024-10-04 21905/week @ 2024-10-11 29732/week @ 2024-10-18 33728/week @ 2024-10-25 38194/week @ 2024-11-01 30056/week @ 2024-11-08 40015/week @ 2024-11-15 52499/week @ 2024-11-22 38299/week @ 2024-11-29 53640/week @ 2024-12-06

191,922 downloads per month
Used in 21 crates (13 directly)

MIT/Apache

205KB
3.5K SLoC

pix

Library for image conversion and compositing.

A raster image can be cheaply converted to and from raw byte buffers, enabling interoperability with other crates.

Many image formats are supported:

  • Bit depth: 8- or 16-bit integer and 32-bit float
  • Alpha: premultiplied or straight
  • Gamma: linear or sRGB
  • Color models:
    • RGB / BGR (red, green, blue)
    • CMY (cyan, magenta, yellow)
    • Gray (luma / relative luminance)
    • HSV (hue, saturation, value)
    • HSL (hue, saturation, lightness)
    • HWB (hue, whiteness, blackness)
    • YCbCr (used by JPEG)
    • Matte (alpha only)
    • OkLab (lightness, green/red, blue/yellow)
    • XYZ (CIE 1931 XYZ)

HWB Color Example

use pix::{hwb::SHwb8, rgb::SRgb8, Raster};

let mut r = Raster::with_clear(256, 256);
for (y, row) in r.rows_mut(()).enumerate() {
    for (x, p) in row.iter_mut().enumerate() {
        let h = ((x + y) >> 1) as u8;
        let w = y.saturating_sub(x) as u8;
        let b = x.saturating_sub(y) as u8;
        *p = SHwb8::new(h, w, b);
    }
}
// Convert to SRgb8 color model
let raster = Raster::<SRgb8>::with_raster(&r);

Colors

Compositing Example

Compositing is supported for premultiplied images with linear gamma.

use pix::{ops::SrcOver, rgb::Rgba8p, Raster};

let mut r0 = Raster::with_clear(100, 100);
let r1 = Raster::with_color(5, 5, Rgba8p::new(80, 0, 80, 200));
r0.composite_raster((40, 40), &r1, (), SrcOver);

Documentation

https://docs.rs/pix

No runtime deps