GithubHelp home page GithubHelp logo

qoiconv-rs's Introduction

qoiconv-rs

Cli to convert between image formats and qoi. Attempt to port qoi.h to rust-lang.

Usage of qoiconv-rs

$ cargo install qoiconv-rs
$ qoiconv-rs -i input.png -o output.qoi # convert form image to qoi
$ qoiconv-rs -i input.qoi -o output.png # convert from qoi to image 

Usage

Copy qoi.rs to your source file and add it as a mod.

Example of decoding pixels from .qoi file:

use std::fs::File;
use std::io::BufReader;
mod qoi;
use qoi::*;

fn main() {
    // load file and get bytes (use `BufReader` to speed up reads)
    let file = File::open("wikipedia_008.qoi").unwrap();
    let mut bytes = BufReader::new(file);

    // get pixels and descriptor
    let (data, desc) = qoi_decode(bytes, None).unwrap();
}

Example of encoding pixels into .qoi file:

use std::fs::File;
use std::io::Write;
mod qoi;
use qoi::*;
fn main() {
    // get pixels and make valid descriptor
    // pixels must be laid out in order RGB(A)
    let pixels = [255, 0, 0, 15, 1, 255, 255, 255, 191, 255, 0, 0, 15, 1, 74];
    let desc = QoiDescriptor {
        width: pixels.len() / 3,
        height: 1,
        channels: ChanelMode::Rgb,
        colorspace: Colorspace::Linear,
    };

    let bytes = qoi_encode(&pixels, &desc).unwrap();

    let mut f = File::create("example.qoi").unwrap();
    f.write_all(bytes.as_slice()).unwrap();
}

Testing, fuzzing, benches, profile

Use cargo to test and fuzz the program (you'll need to install cargo-fuzz):

cargo test
# install cargo-fuzz with `cargo install cargo-fuzz`
cargo fuzz run qoi-test-pixels

To run benches against c test program run:

TODO implement new benchmark to compare against c

This implementation is 2x slower then c implementation probably due to smaller buffer size of BufReader.

qoiconv-rs's People

Contributors

lexeyok avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

qoiconv-rs's Issues

Change api to work with multiple imgaes, restructure reposetory

  • update cli to look similar to cli provided by https://github.com/GoogleChromeLabs/squoosh
    in multi file mode we sould be able to change from supported image formtats to qoi with maybe --qoi flag
    or just use the same logic we have now
qoiconv-rs image1.png image2.png image3.png -d directory_to_processed_files
qoiconv-rs <...files> --output-dir <path> --suffix <suffix> --jobs 4 # not sure about suffix one
# or 
qoiconv-rs <file> --output <path>

-o will not work in multi file mode
this should be working in parallel using rayon libary in multi file mode (allow to set number of jobs with -j )
also we want some progress bar so will need to probably add console crate

  • add tests for cli
  • revue how cli handles files from different folders
    • should we create output file just by changing Path of input file
    • or should we put output file in the place of execution?
  • remove lib to separate crate or workspace ( monorepo vs separate repos ) alternatively change binary to be associated binary

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.