Giter Club home page Giter Club logo

resize's Introduction

resize Build Status crates.io

Image resampling library in pure Rust.

Features

  • Fast, with support for many pixel formats
  • No encoders/decoders, meant to be used with some external library
  • Tuned for resizing to the same dimensions multiple times: uses preallocated buffers and matrixes

Usage

use resize::Pixel::RGB8;
use resize::Type::Lanczos3;

// Downscale by 2x.
let (w1, h1) = (640, 480);
let (w2, h2) = (320, 240);
// Don't forget to fill `src` with image data (RGB8).
// This requires Vec<RGB<u8>>. If you have Vec<u8>, then use .as_rgb()/.as_rgb_mut() to reinterpret it as a slice of pixels.
let src = vec![RGB::new(0,0,0); w1*h1];
// Destination buffer. Must be mutable.
let mut dst = vec![RGB::new(0,0,0); w2*h2];
// Create reusable instance.
let mut resizer = resize::new(w1, h1, w2, h2, RGB8, Lanczos3);
// Do resize without heap allocations.
// Might be executed multiple times for different `src` or `dst`.
resizer.resize(&src, &mut dst);

See API documentation for overview of all available methods. See also this example.

Recommendations

Read this and this great articles on image resizing technics and resampling filters. Tldr; (with built-in filters of this library) use Lanczos3 for downscaling, use Mitchell for upscaling. You may also want to downscale in linear colorspace (but not upscale). Gamma correction routines currently not included to the library, but actually quite simple to accomplish manually, see here for some basic theory.

License

  • Library is licensed under MIT
  • Image used in examples is licensed under CC BY-SA 3.0

resize's People

Contributors

kornelski avatar kagami avatar trueb2 avatar bvssvni avatar sytronik avatar ehfive avatar eclipseo avatar sebastinas avatar

Watchers

James Cloos avatar

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.