#jpegxl #decoder #jpeg-xl-decoder

no-std zune-jpegxl

一个简单、快速且完全安全的模块化 jxl 编码器

2 个不稳定版本

0.5.0-rc02024年4月7日
0.4.0 2023年11月16日

#785图像

Download history 66/week @ 2024-04-21 73/week @ 2024-04-28 57/week @ 2024-05-05 84/week @ 2024-05-12 179/week @ 2024-05-19 62/week @ 2024-05-26 431/week @ 2024-06-02 229/week @ 2024-06-09 79/week @ 2024-06-16 25/week @ 2024-06-23 97/week @ 2024-06-30 29/week @ 2024-07-07 15/week @ 2024-07-14 41/week @ 2024-07-21 257/week @ 2024-07-28 164/week @ 2024-08-04

每月483 次下载
用于 2 crate

MIT OR Apache-2.0 OR Zlib

175KB
3K SLoC

zune-jpegxl

一个简单的 jpeg-xl 编码器

该工具具有以下功能的简单 jpeg-xl 无损编码器:

  • 无损编码
  • 8 位和 16 位支持
  • 灰度模式和 RGB{A} 编码
  • 线程能力

用法

首先将最新版本添加到您的 cargo toml 中

使用 cargo add

cargo add zune-jpegxl

或直接添加到您的 Cargo.toml

zune-jpegxl = "0.4"

然后使用 JxlSimpleEncoder 结构体来编码图像

use zune_core::bit_depth::BitDepth;
use zune_core::options::EncoderOptions;
use zune_jpegxl::JxlSimpleEncoder;
// this example won't work
fn main()->Result<(),JxlEncodeErrors> {
    let mut encoder = JxlSimpleEncoder::new(&[255,0,255,0], EncoderOptions::new(2,2,co));
    encoder.encode().unwrap();
}

lib.rs:

Zune-jpegxl

支持纯 Rust 编码 jpeg xl 图像

这是一个基于 libjxl crate 的 POC 编码器,用于 JPEG-XL 格式

它支持以下功能:

  • 无损压缩

  • 最多 16 位深度

  • 最多 4 个图像通道

  • 不支持的功能 -> 调色板支持

与 png 相比,对于非照片内容,它速度较快但压缩效果稍差,在其他情况下则压缩效果更好。

库也是完全安全的

功能

  • std:启用与标准库链接
  • threads:启用使用标准库的线程功能,此功能需要启用 std 功能(no-std 中不存在线程),如果未启用上述功能,则此操作无效果
  • log:启用使用 log 报告编码配置和状态

两个功能默认启用。

16 位数据

  • 16 位数据应重新解释为 native endian 中的 2 个 u8

示例

  • 编码一个 2x2 8 位图像
use zune_core::bit_depth::BitDepth;
use zune_core::colorspace::ColorSpace;
use zune_core::options::EncoderOptions;
use zune_jpegxl::JxlSimpleEncoder;
use zune_jpegxl::JxlEncodeErrors;
// encode a 2x2 image

fn main()->Result<(),JxlEncodeErrors>{
    let mut encoder = JxlSimpleEncoder::new(&[0,0,0,0],EncoderOptions::new(2,2,ColorSpace::Luma,BitDepth::Eight));
let mut write_to = vec![];
    encoder.encode(&mut write_to)?;
    Ok(())
}
  • 编码一个 2x2 16 位图像
use zune_core::bit_depth::BitDepth;
use zune_core::colorspace::ColorSpace;
use zune_core::options::EncoderOptions;
use zune_jpegxl::JxlSimpleEncoder;
use zune_jpegxl::JxlEncodeErrors;
// encode a 2x2 image

fn main()->Result<(),JxlEncodeErrors>{
    // convert a 16 bit input to 8 bit native endian output, each two bytes represent one sample
    let sixteen_bit = [0,u16::MAX,0,u16::MAX].iter().flat_map(|x| x.to_ne_bytes()).collect::<Vec<u8>>();
    let mut encoder = JxlSimpleEncoder::new(&sixteen_bit,EncoderOptions::new(2,2,ColorSpace::Luma,BitDepth::Sixteen));
    let mut write_to = vec![];
    encoder.encode(&mut write_to)?;
    Ok(())
}

依赖项