Skip to content

RFE: encoder: add stride & various raw input formats support #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
[package]
name = "qoi"
name = "qoicoubeh"
version = "0.4.1"
description = "VERY fast encoder/decoder for QOI (Quite Okay Image) format"
authors = ["Ivan Smirnov <rust@ivan.smirnov.ie>"]
authors = [
"Ivan Smirnov <rust@ivan.smirnov.ie>",
"Marc-André Lureau <marcandre.lureau@redhat.com>",
]
edition = "2021"
readme = "README.md"
license = "MIT/Apache-2.0"
repository = "https://github.com/aldanor/qoi-rust"
homepage = "https://github.com/aldanor/qoi-rust"
documentation = "https://docs.rs/qoi"
repository = "https://github.com/elmarco/qoi-rust"
homepage = "https://github.com/elmarco/qoi-rust"
documentation = "https://docs.rs/qoicoubeh"
categories = ["multimedia::images", "multimedia::encoding"]
keywords = ["qoi", "graphics", "image", "encoding"]
exclude = [
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# [qoi](https://crates.io/crates/qoi)
# [qoicoubeh](https://crates.io/crates/qoicoubeh)

[![Build](https://github.com/aldanor/qoi-rust/workflows/CI/badge.svg)](https://github.com/aldanor/qoi-rust/actions?query=branch%3Amaster)
[![Latest Version](https://img.shields.io/crates/v/qoi.svg)](https://crates.io/crates/qoi)
[![Documentation](https://img.shields.io/docsrs/qoi)](https://docs.rs/qoi)
[![Build](https://github.com/elmarco/qoi-rust/workflows/CI/badge.svg)](https://github.com/elmarco/qoi-rust/actions?query=branch%3Amaster)
[![Latest Version](https://img.shields.io/crates/v/qoicoubeh.svg)](https://crates.io/crates/qoicoubeh)
[![Documentation](https://img.shields.io/docsrs/qoicoubeh)](https://docs.rs/qoicoubeh)
[![Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance)

> **⚠️ WARNING ⚠️**
> This project is a fork of [qoi-rust](https://github.com/aldanor/qoi-rust) until the maintainer resumes activity.

Fast encoder/decoder for [QOI image format](https://qoiformat.org/), implemented in pure and safe Rust.

- One of the [fastest](#benchmarks) QOI encoders/decoders out there.
Expand Down Expand Up @@ -34,7 +37,7 @@ assert_eq!(decoded, pixels);
```
decode:Mp/s encode:Mp/s decode:MB/s encode:MB/s
qoi.h 282.9 225.3 978.3 778.9
qoi-rust 427.4 290.0 1477.7 1002.9
qoicoubeh 427.4 290.0 1477.7 1002.9
```

- Reference C implementation:
Expand Down
2 changes: 1 addition & 1 deletion bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ publish = false
[dependencies]
# internal
libqoi = { path = "../libqoi" }
qoi = { path = ".." }
qoicoubeh = { path = ".." }
# external
anyhow = "1.0"
bytemuck = "1.7"
Expand Down
6 changes: 3 additions & 3 deletions bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl Codec for CodecQoiRust {
type Output = Vec<u8>;

fn name() -> &'static str {
"qoi-rust"
"qoicoubeh"
}

fn encode(img: &Image) -> Result<Vec<u8>> {
Expand Down Expand Up @@ -215,7 +215,7 @@ impl ImageBench {
let (decoded, t_decode) = timeit(|| C::decode(encoded.as_ref(), img));
let decoded = decoded?;
let roundtrip = decoded.as_ref() == img.data.as_slice();
if C::name() == "qoi-rust" {
if C::name() == "qoicoubeh" {
assert!(roundtrip, "{}: decoded data doesn't roundtrip", C::name());
} else {
ensure!(roundtrip, "{}: decoded data doesn't roundtrip", C::name());
Expand Down Expand Up @@ -405,7 +405,7 @@ struct Args {
#[structopt(short, long)]
average: bool,
/// Simple totals, no fancy tables.
#[structopt(short, long)]
#[structopt(long)]
simple: bool,
}

Expand Down
2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cargo-fuzz = true

[dependencies]
# internal
qoi-fast = { path = ".." }
qoicoubeh = { path = ".." }
# external
libfuzzer-sys = "0.4"

Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fuzz_target!(|input: (u16, u16, bool, &[u8])| {
channels,
0,
];
vec.extend(&*data);
vec.extend(data);
vec.extend(&[0, 0, 0, 0, 0, 0, 0, 1]);

let header_expected = Header {
Expand Down
4 changes: 2 additions & 2 deletions fuzz/fuzz_targets/encode.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![no_main]
use libfuzzer_sys::fuzz_target;

use qoi::{encode_size_limit, encode_to_vec};
use qoi::{encode_max_len, encode_to_vec};

fuzz_target!(|input: (bool, u8, &[u8])| {
let (is_4, w_frac, data) = input;
Expand All @@ -18,7 +18,7 @@ fuzz_target!(|input: (bool, u8, &[u8])| {
let out = encode_to_vec(&data[..(w * h * channels as usize)], w as u32, h as u32);
if w * h != 0 {
let out = out.unwrap();
assert!(out.len() <= encode_size_limit(w as u32, h as u32, channels));
assert!(out.len() <= encode_max_len(w as u32, h as u32, channels));
} else {
assert!(out.is_err());
}
Expand Down
12 changes: 11 additions & 1 deletion src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ where
let mut px = Pixel::<N>::new().with_a(0xff);
let mut px_rgba: Pixel<4>;

if matches!(data, [QOI_OP_RUN..=QOI_OP_RUN_END, ..]) {
px_rgba = px.as_rgba(0xff);
index[px_rgba.hash_index() as usize] = px_rgba;
}

while let [px_out, ptail @ ..] = pixels {
pixels = ptail;
match data {
Expand Down Expand Up @@ -178,6 +183,7 @@ where
let (phead, ptail) = pixels.split_at_mut(run); // can't panic
phead.fill(px.into());
pixels = ptail;
index[px.hash_index() as usize] = px;
continue;
}
QOI_OP_DIFF..=QOI_OP_DIFF_END => {
Expand Down Expand Up @@ -381,7 +387,11 @@ impl<R: Reader> Decoder<R> {
if unlikely(buf.len() < size) {
return Err(Error::OutputBufferTooSmall { size: buf.len(), required: size });
}
self.reader.decode_image(buf, self.channels.as_u8(), self.header.channels.as_u8())?;
self.reader.decode_image(
&mut buf[..size],
self.channels.as_u8(),
self.header.channels.as_u8(),
)?;
Ok(size)
}

Expand Down
Loading